location: Add support for location providers outside of the system process.
Also added new permissions android.permission.INSTALL_LOCATION_PROVIDER and android.permission.INSTALL_LOCATION_COLLECTOR to the public API. Signed-off-by: Mike Lockwood <lockwood@android.com>
This commit is contained in:
@@ -529,6 +529,28 @@
|
|||||||
visibility="public"
|
visibility="public"
|
||||||
>
|
>
|
||||||
</field>
|
</field>
|
||||||
|
<field name="INSTALL_LOCATION_COLLECTOR"
|
||||||
|
type="java.lang.String"
|
||||||
|
transient="false"
|
||||||
|
volatile="false"
|
||||||
|
value=""android.permission.INSTALL_LOCATION_COLLECTOR""
|
||||||
|
static="true"
|
||||||
|
final="true"
|
||||||
|
deprecated="not deprecated"
|
||||||
|
visibility="public"
|
||||||
|
>
|
||||||
|
</field>
|
||||||
|
<field name="INSTALL_LOCATION_PROVIDER"
|
||||||
|
type="java.lang.String"
|
||||||
|
transient="false"
|
||||||
|
volatile="false"
|
||||||
|
value=""android.permission.INSTALL_LOCATION_PROVIDER""
|
||||||
|
static="true"
|
||||||
|
final="true"
|
||||||
|
deprecated="not deprecated"
|
||||||
|
visibility="public"
|
||||||
|
>
|
||||||
|
</field>
|
||||||
<field name="INSTALL_PACKAGES"
|
<field name="INSTALL_PACKAGES"
|
||||||
type="java.lang.String"
|
type="java.lang.String"
|
||||||
transient="false"
|
transient="false"
|
||||||
|
|||||||
@@ -214,6 +214,18 @@
|
|||||||
android:label="@string/permlab_accessLocationExtraCommands"
|
android:label="@string/permlab_accessLocationExtraCommands"
|
||||||
android:description="@string/permdesc_accessLocationExtraCommands" />
|
android:description="@string/permdesc_accessLocationExtraCommands" />
|
||||||
|
|
||||||
|
<!-- Allows an application to install a location provider into the Location Manager -->
|
||||||
|
<permission android:name="android.permission.INSTALL_LOCATION_PROVIDER"
|
||||||
|
android:protectionLevel="signatureOrSystem"
|
||||||
|
android:label="@string/permlab_installLocationProvider"
|
||||||
|
android:description="@string/permdesc_installLocationProvider" />
|
||||||
|
|
||||||
|
<!-- Allows an application to install a location collector into the Location Manager -->
|
||||||
|
<permission android:name="android.permission.INSTALL_LOCATION_COLLECTOR"
|
||||||
|
android:protectionLevel="signatureOrSystem"
|
||||||
|
android:label="@string/permlab_installLocationCollector"
|
||||||
|
android:description="@string/permdesc_installLocationCollector" />
|
||||||
|
|
||||||
<!-- ======================================= -->
|
<!-- ======================================= -->
|
||||||
<!-- Permissions for accessing networks -->
|
<!-- Permissions for accessing networks -->
|
||||||
<!-- ======================================= -->
|
<!-- ======================================= -->
|
||||||
@@ -921,7 +933,7 @@
|
|||||||
<permission android:name="android.permission.CONTROL_LOCATION_UPDATES"
|
<permission android:name="android.permission.CONTROL_LOCATION_UPDATES"
|
||||||
android:label="@string/permlab_locationUpdates"
|
android:label="@string/permlab_locationUpdates"
|
||||||
android:description="@string/permdesc_locationUpdates"
|
android:description="@string/permdesc_locationUpdates"
|
||||||
android:protectionLevel="signature" />
|
android:protectionLevel="signatureOrSystem" />
|
||||||
|
|
||||||
<!-- Allows read/write access to the "properties" table in the checkin
|
<!-- Allows read/write access to the "properties" table in the checkin
|
||||||
database, to change values that get uploaded. -->
|
database, to change values that get uploaded. -->
|
||||||
|
|||||||
@@ -752,6 +752,19 @@
|
|||||||
Malicious applications could use this to interfere with the operation of the GPS
|
Malicious applications could use this to interfere with the operation of the GPS
|
||||||
or other location sources.</string>
|
or other location sources.</string>
|
||||||
|
|
||||||
|
<!-- Title of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
|
||||||
|
<string name="permlab_installLocationProvider">permission to install a location provider</string>
|
||||||
|
<!-- Description of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
|
||||||
|
<string name="permdesc_installLocationProvider">Create mock location sources for testing.
|
||||||
|
Malicious applications can use this to override the location and/or status returned by real
|
||||||
|
location sources such as GPS or Network providers.</string>
|
||||||
|
|
||||||
|
<!-- Title of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
|
||||||
|
<string name="permlab_installLocationCollector">permission to install a location collector</string>
|
||||||
|
<!-- Description of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
|
||||||
|
<string name="permdesc_installLocationCollector">Create mock location sources for testing.
|
||||||
|
Malicious applications can use this to monitor and report your location to an external source.</string>
|
||||||
|
|
||||||
<!-- Title of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
|
<!-- Title of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
|
||||||
<string name="permlab_accessFineLocation">fine (GPS) location</string>
|
<string name="permlab_accessFineLocation">fine (GPS) location</string>
|
||||||
<!-- Description of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
|
<!-- Description of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
|
||||||
|
|||||||
@@ -59,9 +59,9 @@ interface ILocationManager
|
|||||||
boolean isProviderEnabled(String provider);
|
boolean isProviderEnabled(String provider);
|
||||||
|
|
||||||
Location getLastKnownLocation(String provider);
|
Location getLastKnownLocation(String provider);
|
||||||
|
|
||||||
/* used by location providers to tell the location manager when it has a new location */
|
/* used by location providers to tell the location manager when it has a new location */
|
||||||
void setLocation(in Location location);
|
void reportLocation(in Location location);
|
||||||
|
|
||||||
String getFromLocation(double latitude, double longitude, int maxResults,
|
String getFromLocation(double latitude, double longitude, int maxResults,
|
||||||
String language, String country, String variant, String appName, out List<Address> addrs);
|
String language, String country, String variant, String appName, out List<Address> addrs);
|
||||||
@@ -82,7 +82,7 @@ interface ILocationManager
|
|||||||
void clearTestProviderStatus(String provider);
|
void clearTestProviderStatus(String provider);
|
||||||
|
|
||||||
/* for installing external Location Providers */
|
/* for installing external Location Providers */
|
||||||
void setNetworkLocationProvider(ILocationProvider provider);
|
void installLocationProvider(String name, ILocationProvider provider);
|
||||||
void setLocationCollector(ILocationCollector collector);
|
void installLocationCollector(ILocationCollector collector);
|
||||||
void setGeocodeProvider(IGeocodeProvider provider);
|
void installGeocodeProvider(IGeocodeProvider provider);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1255,4 +1255,85 @@ public class LocationManager {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Installs a network location provider.
|
||||||
|
*
|
||||||
|
* @param name of the location provider
|
||||||
|
* @param provider Binder interface for the location provider
|
||||||
|
*
|
||||||
|
* @return true if the command succeeds.
|
||||||
|
*
|
||||||
|
* Requires the android.permission.INSTALL_LOCATION_PROVIDER permission.
|
||||||
|
*
|
||||||
|
* {@hide}
|
||||||
|
*/
|
||||||
|
public boolean installLocationProvider(String name, ILocationProvider provider) {
|
||||||
|
try {
|
||||||
|
mService.installLocationProvider(name, provider);
|
||||||
|
return true;
|
||||||
|
} catch (RemoteException e) {
|
||||||
|
Log.e(TAG, "RemoteException in installLocationProvider: ", e);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Installs a location collector.
|
||||||
|
*
|
||||||
|
* @param provider Binder interface for the location collector
|
||||||
|
*
|
||||||
|
* @return true if the command succeeds.
|
||||||
|
*
|
||||||
|
* Requires the android.permission.INSTALL_LOCATION_COLLECTOR permission.
|
||||||
|
*
|
||||||
|
* {@hide}
|
||||||
|
*/
|
||||||
|
public boolean installLocationCollector(ILocationCollector collector) {
|
||||||
|
try {
|
||||||
|
mService.installLocationCollector(collector);
|
||||||
|
return true;
|
||||||
|
} catch (RemoteException e) {
|
||||||
|
Log.e(TAG, "RemoteException in setLocationCollector: ", e);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Installs a geocoder server.
|
||||||
|
*
|
||||||
|
* @param provider Binder interface for the geocoder provider
|
||||||
|
*
|
||||||
|
* @return true if the command succeeds.
|
||||||
|
*
|
||||||
|
* Requires the android.permission.INSTALL_LOCATION_PROVIDER permission.
|
||||||
|
*
|
||||||
|
* {@hide}
|
||||||
|
*/
|
||||||
|
public boolean installGeocodeProvider(IGeocodeProvider provider) {
|
||||||
|
try {
|
||||||
|
mService.installGeocodeProvider(provider);
|
||||||
|
return true;
|
||||||
|
} catch (RemoteException e) {
|
||||||
|
Log.e(TAG, "RemoteException in setGeocodeProvider: ", e);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used by location providers to report new locations.
|
||||||
|
*
|
||||||
|
* @param location new Location to report
|
||||||
|
*
|
||||||
|
* Requires the android.permission.INSTALL_LOCATION_PROVIDER permission.
|
||||||
|
*
|
||||||
|
* {@hide}
|
||||||
|
*/
|
||||||
|
public void reportLocation(Location location) {
|
||||||
|
try {
|
||||||
|
mService.reportLocation(location);
|
||||||
|
} catch (RemoteException e) {
|
||||||
|
Log.e(TAG, "RemoteException in reportLocation: ", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -708,7 +708,7 @@ public class GpsLocationProvider extends ILocationProvider.Stub {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
mLocationManager.setLocation(mLocation);
|
mLocationManager.reportLocation(mLocation);
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
Log.e(TAG, "RemoteException calling reportLocation");
|
Log.e(TAG, "RemoteException calling reportLocation");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -138,7 +138,7 @@ public class MockProvider extends ILocationProvider.Stub {
|
|||||||
mLocation.set(l);
|
mLocation.set(l);
|
||||||
mHasLocation = true;
|
mHasLocation = true;
|
||||||
try {
|
try {
|
||||||
mLocationManager.setLocation(mLocation);
|
mLocationManager.reportLocation(mLocation);
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
Log.e(TAG, "RemoteException calling reportLocation");
|
Log.e(TAG, "RemoteException calling reportLocation");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -106,6 +106,10 @@ public class LocationManagerService extends ILocationManager.Stub implements Run
|
|||||||
android.Manifest.permission.ACCESS_MOCK_LOCATION;
|
android.Manifest.permission.ACCESS_MOCK_LOCATION;
|
||||||
private static final String ACCESS_LOCATION_EXTRA_COMMANDS =
|
private static final String ACCESS_LOCATION_EXTRA_COMMANDS =
|
||||||
android.Manifest.permission.ACCESS_LOCATION_EXTRA_COMMANDS;
|
android.Manifest.permission.ACCESS_LOCATION_EXTRA_COMMANDS;
|
||||||
|
private static final String INSTALL_LOCATION_PROVIDER =
|
||||||
|
android.Manifest.permission.INSTALL_LOCATION_PROVIDER;
|
||||||
|
private static final String INSTALL_LOCATION_COLLECTOR =
|
||||||
|
android.Manifest.permission.INSTALL_LOCATION_COLLECTOR;
|
||||||
|
|
||||||
// Set of providers that are explicitly enabled
|
// Set of providers that are explicitly enabled
|
||||||
private final Set<String> mEnabledProviders = new HashSet<String>();
|
private final Set<String> mEnabledProviders = new HashSet<String>();
|
||||||
@@ -626,36 +630,39 @@ public class LocationManagerService extends ILocationManager.Stub implements Run
|
|||||||
Looper.loop();
|
Looper.loop();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setNetworkLocationProvider(ILocationProvider provider) {
|
public void installLocationProvider(String name, ILocationProvider provider) {
|
||||||
if (Binder.getCallingUid() != Process.SYSTEM_UID) {
|
if (mContext.checkCallingOrSelfPermission(INSTALL_LOCATION_PROVIDER)
|
||||||
throw new SecurityException(
|
!= PackageManager.PERMISSION_GRANTED) {
|
||||||
"Installing location providers outside of the system is not supported");
|
throw new SecurityException("Requires INSTALL_LOCATION_PROVIDER permission");
|
||||||
}
|
}
|
||||||
|
|
||||||
synchronized (mLock) {
|
synchronized (mLock) {
|
||||||
mNetworkLocationProvider =
|
// FIXME - only network location provider supported for now
|
||||||
new LocationProviderProxy(LocationManager.NETWORK_PROVIDER, provider);
|
if (LocationManager.NETWORK_PROVIDER.equals(name)) {
|
||||||
addProvider(mNetworkLocationProvider);
|
mNetworkLocationProvider = new LocationProviderProxy(name, provider);
|
||||||
updateProvidersLocked();
|
addProvider(mNetworkLocationProvider);
|
||||||
|
updateProvidersLocked();
|
||||||
// notify NetworkLocationProvider of any events it might have missed
|
|
||||||
mNetworkLocationProvider.updateNetworkState(mNetworkState);
|
// notify NetworkLocationProvider of any events it might have missed
|
||||||
|
mNetworkLocationProvider.updateNetworkState(mNetworkState);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLocationCollector(ILocationCollector collector) {
|
public void installLocationCollector(ILocationCollector collector) {
|
||||||
if (Binder.getCallingUid() != Process.SYSTEM_UID) {
|
if (mContext.checkCallingOrSelfPermission(INSTALL_LOCATION_COLLECTOR)
|
||||||
throw new SecurityException(
|
!= PackageManager.PERMISSION_GRANTED) {
|
||||||
"Installing location collectors outside of the system is not supported");
|
throw new SecurityException("Requires INSTALL_LOCATION_COLLECTOR permission");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FIXME - only support one collector
|
||||||
mCollector = collector;
|
mCollector = collector;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setGeocodeProvider(IGeocodeProvider provider) {
|
public void installGeocodeProvider(IGeocodeProvider provider) {
|
||||||
if (Binder.getCallingUid() != Process.SYSTEM_UID) {
|
if (mContext.checkCallingOrSelfPermission(INSTALL_LOCATION_PROVIDER)
|
||||||
throw new SecurityException(
|
!= PackageManager.PERMISSION_GRANTED) {
|
||||||
"Installing location providers outside of the system is not supported");
|
throw new SecurityException("Requires INSTALL_LOCATION_PROVIDER permission");
|
||||||
}
|
}
|
||||||
|
|
||||||
mGeocodeProvider = provider;
|
mGeocodeProvider = provider;
|
||||||
@@ -1472,7 +1479,12 @@ public class LocationManagerService extends ILocationManager.Stub implements Run
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLocation(Location location) {
|
public void reportLocation(Location location) {
|
||||||
|
if (mContext.checkCallingOrSelfPermission(INSTALL_LOCATION_PROVIDER)
|
||||||
|
!= PackageManager.PERMISSION_GRANTED) {
|
||||||
|
throw new SecurityException("Requires INSTALL_LOCATION_PROVIDER permission");
|
||||||
|
}
|
||||||
|
|
||||||
mLocationHandler.removeMessages(MESSAGE_LOCATION_CHANGED, location);
|
mLocationHandler.removeMessages(MESSAGE_LOCATION_CHANGED, location);
|
||||||
Message m = Message.obtain(mLocationHandler, MESSAGE_LOCATION_CHANGED, location);
|
Message m = Message.obtain(mLocationHandler, MESSAGE_LOCATION_CHANGED, location);
|
||||||
mLocationHandler.sendMessageAtFrontOfQueue(m);
|
mLocationHandler.sendMessageAtFrontOfQueue(m);
|
||||||
|
|||||||
@@ -189,7 +189,7 @@ public class TestLocationProvider extends ILocationProvider.Stub {
|
|||||||
mLocation.setExtras(extras);
|
mLocation.setExtras(extras);
|
||||||
mLocation.setTime(time);
|
mLocation.setTime(time);
|
||||||
try {
|
try {
|
||||||
mLocationManager.setLocation(mLocation);
|
mLocationManager.reportLocation(mLocation);
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
Log.e(TAG, "RemoteException calling updateLocation");
|
Log.e(TAG, "RemoteException calling updateLocation");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user