1 /* 2 * Copyright (C) 2010 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.server.location; 18 19 import android.content.Context; 20 import android.location.Location; 21 import android.location.LocationProvider; 22 import android.os.Bundle; 23 import android.os.WorkSource; 24 25 import com.android.internal.location.ProviderProperties; 26 import com.android.internal.location.ProviderRequest; 27 28 import java.io.FileDescriptor; 29 import java.io.PrintWriter; 30 import java.util.Collections; 31 import java.util.List; 32 33 /** 34 * Location Manager's interface for location providers. Always starts as disabled. 35 * 36 * @hide 37 */ 38 public abstract class AbstractLocationProvider { 39 40 /** 41 * Interface for communicating from a location provider back to the location service. 42 */ 43 public interface LocationProviderManager { 44 45 /** 46 * May be called to inform the location service of a change in this location provider's 47 * enabled/disabled state. 48 */ onSetEnabled(boolean enabled)49 void onSetEnabled(boolean enabled); 50 51 /** 52 * May be called to inform the location service of a change in this location provider's 53 * properties. 54 */ onSetProperties(ProviderProperties properties)55 void onSetProperties(ProviderProperties properties); 56 57 /** 58 * May be called to inform the location service that this provider has a new location 59 * available. 60 */ onReportLocation(Location location)61 void onReportLocation(Location location); 62 63 /** 64 * May be called to inform the location service that this provider has a new location 65 * available. 66 */ onReportLocation(List<Location> locations)67 void onReportLocation(List<Location> locations); 68 } 69 70 protected final Context mContext; 71 private final LocationProviderManager mLocationProviderManager; 72 AbstractLocationProvider( Context context, LocationProviderManager locationProviderManager)73 protected AbstractLocationProvider( 74 Context context, LocationProviderManager locationProviderManager) { 75 mContext = context; 76 mLocationProviderManager = locationProviderManager; 77 } 78 79 /** 80 * Call this method to report a new location. May be called from any thread. 81 */ reportLocation(Location location)82 protected void reportLocation(Location location) { 83 mLocationProviderManager.onReportLocation(location); 84 } 85 86 /** 87 * Call this method to report a new location. May be called from any thread. 88 */ reportLocation(List<Location> locations)89 protected void reportLocation(List<Location> locations) { 90 mLocationProviderManager.onReportLocation(locations); 91 } 92 93 /** 94 * Call this method to report a change in provider enabled/disabled status. May be called from 95 * any thread. 96 */ setEnabled(boolean enabled)97 protected void setEnabled(boolean enabled) { 98 mLocationProviderManager.onSetEnabled(enabled); 99 } 100 101 /** 102 * Call this method to report a change in provider properties. May be called from 103 * any thread. 104 */ setProperties(ProviderProperties properties)105 protected void setProperties(ProviderProperties properties) { 106 mLocationProviderManager.onSetProperties(properties); 107 } 108 109 /** Returns list of packages currently associated with this provider. */ getProviderPackages()110 public List<String> getProviderPackages() { 111 return Collections.singletonList(mContext.getPackageName()); 112 } 113 114 /** 115 * Called when the location service delivers a new request for fulfillment to the provider. 116 * Replaces any previous requests completely. 117 */ setRequest(ProviderRequest request, WorkSource source)118 public abstract void setRequest(ProviderRequest request, WorkSource source); 119 120 /** 121 * Called to dump debug or log information. 122 */ dump(FileDescriptor fd, PrintWriter pw, String[] args)123 public abstract void dump(FileDescriptor fd, PrintWriter pw, String[] args); 124 125 /** 126 * Retrieves the current status of the provider. 127 * 128 * @deprecated Will be removed in a future release. 129 */ 130 @Deprecated getStatus(Bundle extras)131 public int getStatus(Bundle extras) { 132 return LocationProvider.AVAILABLE; 133 } 134 135 /** 136 * Retrieves the last update time of the status of the provider. 137 * 138 * @deprecated Will be removed in a future release. 139 */ 140 @Deprecated getStatusUpdateTime()141 public long getStatusUpdateTime() { 142 return 0; 143 } 144 145 /** Sends a custom command to this provider. */ sendExtraCommand(String command, Bundle extras)146 public abstract void sendExtraCommand(String command, Bundle extras); 147 } 148