Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2f82c4eb authored by Mike Lockwood's avatar Mike Lockwood
Browse files

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: default avatarMike Lockwood <lockwood@android.com>
parent 21b5817a
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -46,9 +46,9 @@ interface ILocationProvider {
    void setMinTime(long minTime);
    void updateNetworkState(int state);
    boolean sendExtraCommand(String command, inout Bundle extras);
    void addListener(int uid);
    void removeListener(int uid);

    /* the following are only used for NetworkLocationProvider */
    /* the following is used only for NetworkLocationProvider */
    void updateCellLockStatus(boolean acquired);
    void addListener(in String[] applications);
    void removeListener(in String[] applications);
}
+16 −0
Original line number Diff line number Diff line
@@ -249,4 +249,20 @@ public abstract class LocationProviderImpl extends LocationProvider {
    public boolean sendExtraCommand(String command, Bundle extras) {
        return false;
    }

    /**
     * Informs the location provider when a new client is listening for location information
     *
     * @param uid the uid of the client proces
     */
    public void addListener(int uid) {
    }

    /**
     * Informs the location provider when a client is no longerlistening for location information
     *
     * @param uid the uid of the client proces
     */
    public void removeListener(int uid) {
    }
}
+48 −1
Original line number Diff line number Diff line
@@ -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);
@@ -567,6 +576,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) {
        
@@ -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);
+4 −4
Original line number Diff line number Diff line
@@ -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);
        }
+131 −274

File changed.

Preview size limit exceeded, changes collapsed.