summaryrefslogtreecommitdiffstats
path: root/location/java/com
diff options
context:
space:
mode:
authorMike Lockwood <lockwood@android.com>2009-04-17 08:24:10 -0400
committerMike Lockwood <lockwood@android.com>2009-04-17 17:00:32 -0400
commit2f82c4eb0b4d315481ad79725ad6f52c5ec69685 (patch)
treeef64e238443565b8f3e39a5079e4db27e8cd64b5 /location/java/com
parent21b5817aaa2f0a61edff8752ed85130aa8cf7def (diff)
downloadframeworks_base-2f82c4eb0b4d315481ad79725ad6f52c5ec69685.zip
frameworks_base-2f82c4eb0b4d315481ad79725ad6f52c5ec69685.tar.gz
frameworks_base-2f82c4eb0b4d315481ad79725ad6f52c5ec69685.tar.bz2
location: Generalize support for location provider usage tracking.
This replaces two different mechanisms that were used for GPS and Netork location provider tracking. Move BatteryStats logging of GPS usage from LocationManagerService to GpsLocationProvider. Clean up tracking of location listeners in LocationManagerService and remove some HashMaps that are no longer needed. Signed-off-by: Mike Lockwood <lockwood@android.com>
Diffstat (limited to 'location/java/com')
-rw-r--r--location/java/com/android/internal/location/GpsLocationProvider.java49
-rw-r--r--location/java/com/android/internal/location/LocationProviderProxy.java8
2 files changed, 52 insertions, 5 deletions
diff --git a/location/java/com/android/internal/location/GpsLocationProvider.java b/location/java/com/android/internal/location/GpsLocationProvider.java
index d56594e..f133b4f 100644
--- a/location/java/com/android/internal/location/GpsLocationProvider.java
+++ b/location/java/com/android/internal/location/GpsLocationProvider.java
@@ -33,10 +33,13 @@ import android.net.SntpClient;
import android.os.Bundle;
import android.os.IBinder;
import android.os.RemoteException;
+import android.os.ServiceManager;
import android.os.SystemClock;
import android.util.Config;
import android.util.Log;
+import android.util.SparseIntArray;
+import com.android.internal.app.IBatteryStats;
import com.android.internal.telephony.Phone;
import com.android.internal.telephony.TelephonyIntents;
@@ -192,7 +195,10 @@ public class GpsLocationProvider extends LocationProviderImpl {
private boolean mSetSuplServer;
private String mSuplApn;
private int mSuplDataConnectionState;
- private ConnectivityManager mConnMgr;
+ private final ConnectivityManager mConnMgr;
+
+ private final IBatteryStats mBatteryStats;
+ private final SparseIntArray mClientUids = new SparseIntArray();
// how often to request NTP time, in milliseconds
// current setting 4 hours
@@ -241,6 +247,9 @@ public class GpsLocationProvider extends LocationProviderImpl {
mConnMgr = (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
+ // Battery statistics service to be notified when GPS turns on or off
+ mBatteryStats = IBatteryStats.Stub.asInterface(ServiceManager.getService("batteryinfo"));
+
mProperties = new Properties();
try {
File file = new File(PROPERTIES_FILE);
@@ -568,6 +577,30 @@ public class GpsLocationProvider extends LocationProviderImpl {
}
@Override
+ public void addListener(int uid) {
+ mClientUids.put(uid, 0);
+ if (mNavigating) {
+ try {
+ mBatteryStats.noteStartGps(uid);
+ } catch (RemoteException e) {
+ Log.w(TAG, "RemoteException in addListener");
+ }
+ }
+ }
+
+ @Override
+ public void removeListener(int uid) {
+ mClientUids.delete(uid);
+ if (mNavigating) {
+ try {
+ mBatteryStats.noteStopGps(uid);
+ } catch (RemoteException e) {
+ Log.w(TAG, "RemoteException in removeListener");
+ }
+ }
+ }
+
+ @Override
public boolean sendExtraCommand(String command, Bundle extras) {
if ("delete_aiding_data".equals(command)) {
@@ -746,6 +779,20 @@ public class GpsLocationProvider extends LocationProviderImpl {
}
}
+ try {
+ // update battery stats
+ for (int i=mClientUids.size() - 1; i >= 0; i--) {
+ int uid = mClientUids.keyAt(i);
+ if (mNavigating) {
+ mBatteryStats.noteStartGps(uid);
+ } else {
+ mBatteryStats.noteStopGps(uid);
+ }
+ }
+ } catch (RemoteException e) {
+ Log.w(TAG, "RemoteException in reportStatus");
+ }
+
// send an intent to notify that the GPS has been enabled or disabled.
Intent intent = new Intent(GPS_ENABLED_CHANGE_ACTION);
intent.putExtra(EXTRA_ENABLED, mNavigating);
diff --git a/location/java/com/android/internal/location/LocationProviderProxy.java b/location/java/com/android/internal/location/LocationProviderProxy.java
index 5b5b27a..84462b2 100644
--- a/location/java/com/android/internal/location/LocationProviderProxy.java
+++ b/location/java/com/android/internal/location/LocationProviderProxy.java
@@ -230,17 +230,17 @@ public class LocationProviderProxy extends LocationProviderImpl {
}
}
- public void addListener(String[] applications) {
+ public void addListener(int uid) {
try {
- mProvider.addListener(applications);
+ mProvider.addListener(uid);
} catch (RemoteException e) {
Log.e(TAG, "addListener failed", e);
}
}
- public void removeListener(String[] applications) {
+ public void removeListener(int uid) {
try {
- mProvider.removeListener(applications);
+ mProvider.removeListener(uid);
} catch (RemoteException e) {
Log.e(TAG, "removeListener failed", e);
}