diff options
Diffstat (limited to 'services/java/com/android/server/location/LocationProviderProxy.java')
-rw-r--r-- | services/java/com/android/server/location/LocationProviderProxy.java | 29 |
1 files changed, 15 insertions, 14 deletions
diff --git a/services/java/com/android/server/location/LocationProviderProxy.java b/services/java/com/android/server/location/LocationProviderProxy.java index 0bc1664..a227ab6 100644 --- a/services/java/com/android/server/location/LocationProviderProxy.java +++ b/services/java/com/android/server/location/LocationProviderProxy.java @@ -42,12 +42,15 @@ public class LocationProviderProxy implements LocationProviderInterface { private static final String TAG = "LocationProviderProxy"; + public static final String SERVICE_ACTION = + "com.android.location.service.NetworkLocationProvider"; + private final Context mContext; private final String mName; private final Intent mIntent; private final Handler mHandler; private final Object mMutex = new Object(); // synchronizes access to non-final members - private Connection mServiceConnection = new Connection(); // never null + private Connection mServiceConnection; // never null after ctor // cached values set by the location manager private boolean mLocationTracking = false; @@ -58,28 +61,26 @@ public class LocationProviderProxy implements LocationProviderInterface { private NetworkInfo mNetworkInfo; // constructor for proxying location providers implemented in a separate service - public LocationProviderProxy(Context context, String name, String serviceName, + public LocationProviderProxy(Context context, String name, String packageName, Handler handler) { mContext = context; mName = name; - mIntent = new Intent(serviceName); + mIntent = new Intent(SERVICE_ACTION); mHandler = handler; - mContext.bindService(mIntent, mServiceConnection, - Context.BIND_AUTO_CREATE | Context.BIND_NOT_FOREGROUND - | Context.BIND_ALLOW_OOM_MANAGEMENT); + reconnect(packageName); } - /** - * When unbundled NetworkLocationService package is updated, we - * need to unbind from the old version and re-bind to the new one. - */ - public void reconnect() { + /** Bind to service. Will reconnect if already connected */ + public void reconnect(String packageName) { synchronized (mMutex) { - mContext.unbindService(mServiceConnection); + if (mServiceConnection != null) { + mContext.unbindService(mServiceConnection); + } mServiceConnection = new Connection(); + mIntent.setPackage(packageName); mContext.bindService(mIntent, mServiceConnection, - Context.BIND_AUTO_CREATE | Context.BIND_NOT_FOREGROUND - | Context.BIND_ALLOW_OOM_MANAGEMENT); + Context.BIND_AUTO_CREATE | Context.BIND_NOT_FOREGROUND | + Context.BIND_ALLOW_OOM_MANAGEMENT); } } |