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

Commit c11a7e61 authored by Zhentao Sun's avatar Zhentao Sun Committed by Android Git Automerger
Browse files

am 04375db6: am c5fc9988: Made it easier to disable overlay mechanism of location components.

* commit '04375db6':
  Made it easier to disable overlay mechanism of location components.
parents d93776f3 04375db6
Loading
Loading
Loading
Loading
+54 −0
Original line number Original line Diff line number Diff line
@@ -633,6 +633,60 @@
    <!-- True if WallpaperService is enabled -->
    <!-- True if WallpaperService is enabled -->
    <bool name="config_enableWallpaperService">true</bool>
    <bool name="config_enableWallpaperService">true</bool>


    <!-- Whether to enable network location overlay which allows network
         location provider to be replaced by an app at run-time. When disabled,
         only the config_networkLocationProviderPackageName package will be
         searched for network location provider, otherwise packages whose
         signature matches the signatures of config_locationProviderPackageNames
         will be searched, and the service with the highest version number will
         be picked. Anyone who wants to disable the overlay mechanism can set it
         to false.
         -->
    <bool name="config_enableNetworkLocationOverlay" translatable="false">true</bool>
    <!-- Package name providing network location support. Used only when
         config_enableNetworkLocationOverlay is false. -->
    <string name="config_networkLocationProviderPackageName" translatable="false">@null</string>

    <!-- Whether to enable fused location provider overlay which allows fused
         location provider to be replaced by an app at run-time. When disabled,
         only the config_fusedLocationProviderPackageName package will be
         searched for fused location provider, otherwise packages whose
         signature matches the signatures of config_locationProviderPackageNames
         will be searched, and the service with the highest version number will
         be picked. Anyone who wants to disable the overlay mechanism can set it
         to false.
         -->
    <bool name="config_enableFusedLocationOverlay" translatable="false">true</bool>
    <!-- Package name providing fused location support. Used only when
         config_enableFusedLocationOverlay is false. -->
    <string name="config_fusedLocationProviderPackageName" translatable="false">com.android.location.fused</string>

    <!-- Whether to enable geocoder overlay which allows geocoder to be replaced
         by an app at run-time. When disabled, only the
         config_geocoderProviderPackageName package will be searched for
         geocoder, otherwise packages whose signature matches the signatures of
         config_locationProviderPackageNames will be searched, and the service
         with the highest version number will be picked. Anyone who wants to
         disable the overlay mechanism can set it to false.
         -->
    <bool name="config_enableGeocoderOverlay" translatable="false">true</bool>
    <!-- Package name providing geocoder API support. Used only when
         config_enableGeocoderOverlay is false. -->
    <string name="config_geocoderProviderPackageName" translatable="false">@null</string>

    <!-- Whether to enable geofence overlay which allows geofence to be replaced
         by an app at run-time. When disabled, only the
         config_geofenceProviderPackageName package will be searched for
         geofence implementation, otherwise packages whose signature matches the
         signatures of config_locationProviderPackageNames will be searched, and
         the service with the highest version number will be picked. Anyone who
         wants to disable the overlay mechanism can set it to false.
         -->
    <bool name="config_enableGeofenceOverlay" translatable="false">true</bool>
    <!-- Package name providing geofence API support. Used only when
         config_enableGeofenceOverlay is false. -->
    <string name="config_geofenceProviderPackageName" translatable="false">@null</string>

    <!-- Package name(s) containing location provider support.
    <!-- Package name(s) containing location provider support.
         These packages can contain services implementing location providers,
         These packages can contain services implementing location providers,
         such as the Geocode Provider, Network Location Provider, and
         such as the Geocode Provider, Network Location Provider, and
+8 −0
Original line number Original line Diff line number Diff line
@@ -1335,6 +1335,10 @@
  <java-symbol type="array" name="config_notificationFallbackVibePattern" />
  <java-symbol type="array" name="config_notificationFallbackVibePattern" />
  <java-symbol type="bool" name="config_animateScreenLights" />
  <java-symbol type="bool" name="config_animateScreenLights" />
  <java-symbol type="bool" name="config_automatic_brightness_available" />
  <java-symbol type="bool" name="config_automatic_brightness_available" />
  <java-symbol type="bool" name="config_enableFusedLocationOverlay" />
  <java-symbol type="bool" name="config_enableGeocoderOverlay" />
  <java-symbol type="bool" name="config_enableGeofenceOverlay" />
  <java-symbol type="bool" name="config_enableNetworkLocationOverlay" />
  <java-symbol type="bool" name="config_sf_limitedAlpha" />
  <java-symbol type="bool" name="config_sf_limitedAlpha" />
  <java-symbol type="bool" name="config_unplugTurnsOnScreen" />
  <java-symbol type="bool" name="config_unplugTurnsOnScreen" />
  <java-symbol type="bool" name="config_wifi_background_scan_support" />
  <java-symbol type="bool" name="config_wifi_background_scan_support" />
@@ -1419,6 +1423,10 @@
  <java-symbol type="string" name="car_mode_disable_notification_title" />
  <java-symbol type="string" name="car_mode_disable_notification_title" />
  <java-symbol type="string" name="chooser_wallpaper" />
  <java-symbol type="string" name="chooser_wallpaper" />
  <java-symbol type="string" name="config_datause_iface" />
  <java-symbol type="string" name="config_datause_iface" />
  <java-symbol type="string" name="config_fusedLocationProviderPackageName" />
  <java-symbol type="string" name="config_geocoderProviderPackageName" />
  <java-symbol type="string" name="config_geofenceProviderPackageName" />
  <java-symbol type="string" name="config_networkLocationProviderPackageName" />
  <java-symbol type="string" name="config_wimaxManagerClassname" />
  <java-symbol type="string" name="config_wimaxManagerClassname" />
  <java-symbol type="string" name="config_wimaxNativeLibLocation" />
  <java-symbol type="string" name="config_wimaxNativeLibLocation" />
  <java-symbol type="string" name="config_wimaxServiceClassname" />
  <java-symbol type="string" name="config_wimaxServiceClassname" />
+21 −8
Original line number Original line Diff line number Diff line
@@ -380,7 +380,10 @@ public class LocationManagerService extends ILocationManager.Stub {
                mContext,
                mContext,
                LocationManager.NETWORK_PROVIDER,
                LocationManager.NETWORK_PROVIDER,
                NETWORK_LOCATION_SERVICE_ACTION,
                NETWORK_LOCATION_SERVICE_ACTION,
                providerPackageNames, mLocationHandler);
                com.android.internal.R.bool.config_enableNetworkLocationOverlay,
                com.android.internal.R.string.config_networkLocationProviderPackageName,
                com.android.internal.R.array.config_locationProviderPackageNames,
                mLocationHandler);
        if (networkProvider != null) {
        if (networkProvider != null) {
            mRealProviders.put(LocationManager.NETWORK_PROVIDER, networkProvider);
            mRealProviders.put(LocationManager.NETWORK_PROVIDER, networkProvider);
            mProxyProviders.add(networkProvider);
            mProxyProviders.add(networkProvider);
@@ -394,7 +397,10 @@ public class LocationManagerService extends ILocationManager.Stub {
                mContext,
                mContext,
                LocationManager.FUSED_PROVIDER,
                LocationManager.FUSED_PROVIDER,
                FUSED_LOCATION_SERVICE_ACTION,
                FUSED_LOCATION_SERVICE_ACTION,
                providerPackageNames, mLocationHandler);
                com.android.internal.R.bool.config_enableFusedLocationOverlay,
                com.android.internal.R.string.config_fusedLocationProviderPackageName,
                com.android.internal.R.array.config_locationProviderPackageNames,
                mLocationHandler);
        if (fusedLocationProvider != null) {
        if (fusedLocationProvider != null) {
            addProviderLocked(fusedLocationProvider);
            addProviderLocked(fusedLocationProvider);
            mProxyProviders.add(fusedLocationProvider);
            mProxyProviders.add(fusedLocationProvider);
@@ -406,15 +412,22 @@ public class LocationManagerService extends ILocationManager.Stub {
        }
        }


        // bind to geocoder provider
        // bind to geocoder provider
        mGeocodeProvider = GeocoderProxy.createAndBind(mContext, providerPackageNames,
        mGeocodeProvider = GeocoderProxy.createAndBind(mContext,
                com.android.internal.R.bool.config_enableGeocoderOverlay,
                com.android.internal.R.string.config_geocoderProviderPackageName,
                com.android.internal.R.array.config_locationProviderPackageNames,
                mLocationHandler);
                mLocationHandler);
        if (mGeocodeProvider == null) {
        if (mGeocodeProvider == null) {
            Slog.e(TAG,  "no geocoder provider found");
            Slog.e(TAG,  "no geocoder provider found");
        }
        }


        // bind to geofence provider
        // bind to geofence provider
        GeofenceProxy provider = GeofenceProxy.createAndBind(mContext, providerPackageNames,
        GeofenceProxy provider = GeofenceProxy.createAndBind(mContext,
                mLocationHandler, gpsProvider.getGpsGeofenceProxy());
                com.android.internal.R.bool.config_enableGeofenceOverlay,
                com.android.internal.R.string.config_geofenceProviderPackageName,
                com.android.internal.R.array.config_locationProviderPackageNames,
                mLocationHandler,
                gpsProvider.getGpsGeofenceProxy());
        if (provider == null) {
        if (provider == null) {
            Slog.e(TAG,  "no geofence provider found");
            Slog.e(TAG,  "no geofence provider found");
        }
        }
@@ -1290,14 +1303,14 @@ public class LocationManagerService extends ILocationManager.Stub {
        if (name == null) {
        if (name == null) {
            throw new IllegalArgumentException("provider name must not be null");
            throw new IllegalArgumentException("provider name must not be null");
        }
        }

        if (D) Log.d(TAG, "request " + Integer.toHexString(System.identityHashCode(receiver))
                + " " + name + " " + request + " from " + packageName + "(" + uid + ")");
        LocationProviderInterface provider = mProvidersByName.get(name);
        LocationProviderInterface provider = mProvidersByName.get(name);
        if (provider == null) {
        if (provider == null) {
            throw new IllegalArgumentException("provider doesn't exisit: " + provider);
            throw new IllegalArgumentException("provider doesn't exisit: " + provider);
        }
        }


        if (D) Log.d(TAG, "request " + Integer.toHexString(System.identityHashCode(receiver))
                + " " + name + " " + request + " from " + packageName + "(" + uid + ")");

        UpdateRecord record = new UpdateRecord(name, request, receiver);
        UpdateRecord record = new UpdateRecord(name, request, receiver);
        UpdateRecord oldRecord = receiver.mUpdateRecords.put(name, record);
        UpdateRecord oldRecord = receiver.mUpdateRecords.put(name, record);
        if (oldRecord != null) {
        if (oldRecord != null) {
+93 −41
Original line number Original line Diff line number Diff line
@@ -27,6 +27,7 @@ import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.ResolveInfo;
import android.content.pm.ResolveInfo;
import android.content.pm.Signature;
import android.content.pm.Signature;
import android.content.res.Resources;
import android.os.Handler;
import android.os.Handler;
import android.os.IBinder;
import android.os.IBinder;
import android.os.UserHandle;
import android.os.UserHandle;
@@ -36,6 +37,7 @@ import com.android.internal.content.PackageMonitor;


import java.util.ArrayList;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.HashSet;
import java.util.List;
import java.util.List;


@@ -53,6 +55,13 @@ public class ServiceWatcher implements ServiceConnection {
    private final PackageManager mPm;
    private final PackageManager mPm;
    private final List<HashSet<Signature>> mSignatureSets;
    private final List<HashSet<Signature>> mSignatureSets;
    private final String mAction;
    private final String mAction;

    /**
     * If mServicePackageName is not null, only this package will be searched for the service that
     * implements mAction. When null, all packages in the system that matches one of the signature
     * in mSignatureSets are searched.
     */
    private final String mServicePackageName;
    private final Runnable mNewServiceWork;
    private final Runnable mNewServiceWork;
    private final Handler mHandler;
    private final Handler mHandler;


@@ -87,19 +96,40 @@ public class ServiceWatcher implements ServiceConnection {
    }
    }


    public ServiceWatcher(Context context, String logTag, String action,
    public ServiceWatcher(Context context, String logTag, String action,
            List<String> initialPackageNames, Runnable newServiceWork, Handler handler) {
            int overlaySwitchResId, int defaultServicePackageNameResId,
            int initialPackageNamesResId, Runnable newServiceWork,
            Handler handler) {
        mContext = context;
        mContext = context;
        mTag = logTag;
        mTag = logTag;
        mAction = action;
        mAction = action;
        mPm = mContext.getPackageManager();
        mPm = mContext.getPackageManager();
        mNewServiceWork = newServiceWork;
        mNewServiceWork = newServiceWork;
        mHandler = handler;
        mHandler = handler;
        Resources resources = context.getResources();

        // Whether to enable service overlay.
        boolean enableOverlay = resources.getBoolean(overlaySwitchResId);
        ArrayList<String>  initialPackageNames = new ArrayList<String>();
        if (enableOverlay) {
            // A list of package names used to create the signatures.
            String[] pkgs = resources.getStringArray(initialPackageNamesResId);
            if (pkgs != null) initialPackageNames.addAll(Arrays.asList(pkgs));
            mServicePackageName = null;
            if (D) Log.d(mTag, "Overlay enabled, packages=" + Arrays.toString(pkgs));
        } else {
            // The default package name that is searched for service implementation when overlay is
            // disabled.
            String servicePackageName = resources.getString(defaultServicePackageNameResId);
            if (servicePackageName != null) initialPackageNames.add(servicePackageName);
            mServicePackageName = servicePackageName;
            if (D) Log.d(mTag, "Overlay disabled, default package=" + servicePackageName);
        }
        mSignatureSets = getSignatureSets(context, initialPackageNames);
        mSignatureSets = getSignatureSets(context, initialPackageNames);
    }
    }


    public boolean start() {
    public boolean start() {
        synchronized (mLock) {
        synchronized (mLock) {
            if (!bindBestPackageLocked(null)) return false;
            if (!bindBestPackageLocked(mServicePackageName)) return false;
        }
        }


        // listen for user change
        // listen for user change
@@ -115,8 +145,10 @@ public class ServiceWatcher implements ServiceConnection {
            }
            }
        }, UserHandle.ALL, intentFilter, null, mHandler);
        }, UserHandle.ALL, intentFilter, null, mHandler);


        // listen for relevant package changes
        // listen for relevant package changes if service overlay is enabled.
        if (mServicePackageName == null) {
            mPackageMonitor.register(mContext, null, UserHandle.ALL, true);
            mPackageMonitor.register(mContext, null, UserHandle.ALL, true);
        }


        return true;
        return true;
    }
    }
@@ -133,11 +165,12 @@ public class ServiceWatcher implements ServiceConnection {
        if (justCheckThisPackage != null) {
        if (justCheckThisPackage != null) {
            intent.setPackage(justCheckThisPackage);
            intent.setPackage(justCheckThisPackage);
        }
        }
        List<ResolveInfo> rInfos = mPm.queryIntentServicesAsUser(new Intent(mAction),
        List<ResolveInfo> rInfos = mPm.queryIntentServicesAsUser(intent,
                PackageManager.GET_META_DATA, UserHandle.USER_OWNER);
                PackageManager.GET_META_DATA, UserHandle.USER_OWNER);
        int bestVersion = Integer.MIN_VALUE;
        int bestVersion = Integer.MIN_VALUE;
        String bestPackage = null;
        String bestPackage = null;
        boolean bestIsMultiuser = false;
        boolean bestIsMultiuser = false;
        if (rInfos != null) {
            for (ResolveInfo rInfo : rInfos) {
            for (ResolveInfo rInfo : rInfos) {
                String packageName = rInfo.serviceInfo.packageName;
                String packageName = rInfo.serviceInfo.packageName;


@@ -146,8 +179,8 @@ public class ServiceWatcher implements ServiceConnection {
                    PackageInfo pInfo;
                    PackageInfo pInfo;
                    pInfo = mPm.getPackageInfo(packageName, PackageManager.GET_SIGNATURES);
                    pInfo = mPm.getPackageInfo(packageName, PackageManager.GET_SIGNATURES);
                    if (!isSignatureMatch(pInfo.signatures)) {
                    if (!isSignatureMatch(pInfo.signatures)) {
                    Log.w(mTag, packageName + " resolves service " + mAction +
                        Log.w(mTag, packageName + " resolves service " + mAction
                            ", but has wrong signature, ignoring");
                                + ", but has wrong signature, ignoring");
                        continue;
                        continue;
                    }
                    }
                } catch (NameNotFoundException e) {
                } catch (NameNotFoundException e) {
@@ -159,8 +192,8 @@ public class ServiceWatcher implements ServiceConnection {
                int version = Integer.MIN_VALUE;
                int version = Integer.MIN_VALUE;
                boolean isMultiuser = false;
                boolean isMultiuser = false;
                if (rInfo.serviceInfo.metaData != null) {
                if (rInfo.serviceInfo.metaData != null) {
                version = rInfo.serviceInfo.metaData.getInt(EXTRA_SERVICE_VERSION,
                    version = rInfo.serviceInfo.metaData.getInt(
                        Integer.MIN_VALUE);
                            EXTRA_SERVICE_VERSION, Integer.MIN_VALUE);
                    isMultiuser = rInfo.serviceInfo.metaData.getBoolean(EXTRA_SERVICE_IS_MULTIUSER);
                    isMultiuser = rInfo.serviceInfo.metaData.getBoolean(EXTRA_SERVICE_IS_MULTIUSER);
                }
                }


@@ -171,12 +204,16 @@ public class ServiceWatcher implements ServiceConnection {
                }
                }
            }
            }


        if (D) Log.d(mTag, String.format("bindBestPackage for %s : %s found %d, %s", mAction,
            if (D) {
                (justCheckThisPackage == null ? "" : "(" + justCheckThisPackage + ") "),
                Log.d(mTag, String.format("bindBestPackage for %s : %s found %d, %s", mAction,
                rInfos.size(),
                        (justCheckThisPackage == null ? ""
                (bestPackage == null ? "no new best package" : "new best package: "
                                : "(" + justCheckThisPackage + ") "), rInfos.size(),
                + bestPackage)));
                        (bestPackage == null ? "no new best package"

                                : "new best package: " + bestPackage)));
            }
        } else {
            if (D) Log.d(mTag, "Unable to query intent services for action: " + mAction);
        }
        if (bestPackage != null) {
        if (bestPackage != null) {
            bindToPackageLocked(bestPackage, bestVersion, bestIsMultiuser);
            bindToPackageLocked(bestPackage, bestVersion, bestIsMultiuser);
            return true;
            return true;
@@ -243,8 +280,9 @@ public class ServiceWatcher implements ServiceConnection {
                    // package updated, make sure to rebind
                    // package updated, make sure to rebind
                    unbindLocked();
                    unbindLocked();
                }
                }
                // check the updated package in case it is better
                // Need to check all packages because this method is also called when a
                bindBestPackageLocked(packageName);
                // system app is uninstalled and the stock version in reinstalled.
                bindBestPackageLocked(null);
            }
            }
        }
        }


@@ -256,7 +294,7 @@ public class ServiceWatcher implements ServiceConnection {
                    unbindLocked();
                    unbindLocked();
                }
                }
                // check the new package is case it is better
                // check the new package is case it is better
                bindBestPackageLocked(packageName);
                bindBestPackageLocked(null);
            }
            }
        }
        }


@@ -271,6 +309,20 @@ public class ServiceWatcher implements ServiceConnection {
                }
                }
            }
            }
        }
        }

        @Override
        public boolean onPackageChanged(String packageName, int uid, String[] components) {
            synchronized (mLock) {
                if (packageName.equals(mPackageName)) {
                    // service enabled or disabled, make sure to rebind
                    unbindLocked();
                }
                // the service might be disabled, need to search for a new
                // package
                bindBestPackageLocked(null);
            }
            return super.onPackageChanged(packageName, uid, components);
        }
    };
    };


    @Override
    @Override
@@ -323,7 +375,7 @@ public class ServiceWatcher implements ServiceConnection {
        synchronized (mLock) {
        synchronized (mLock) {
            if (!mIsMultiuser) {
            if (!mIsMultiuser) {
                unbindLocked();
                unbindLocked();
                bindBestPackageLocked(null);
                bindBestPackageLocked(mServicePackageName);
            }
            }
        }
        }
    }
    }
+9 −5
Original line number Original line Diff line number Diff line
@@ -40,8 +40,10 @@ public class GeocoderProxy {
    private final ServiceWatcher mServiceWatcher;
    private final ServiceWatcher mServiceWatcher;


    public static GeocoderProxy createAndBind(Context context,
    public static GeocoderProxy createAndBind(Context context,
            List<String> initialPackageNames, Handler handler) {
            int overlaySwitchResId, int defaultServicePackageNameResId,
        GeocoderProxy proxy = new GeocoderProxy(context, initialPackageNames, handler);
            int initialPackageNamesResId, Handler handler) {
        GeocoderProxy proxy = new GeocoderProxy(context, overlaySwitchResId,
            defaultServicePackageNameResId, initialPackageNamesResId, handler);
        if (proxy.bind()) {
        if (proxy.bind()) {
            return proxy;
            return proxy;
        } else {
        } else {
@@ -49,11 +51,13 @@ public class GeocoderProxy {
        }
        }
    }
    }


    public GeocoderProxy(Context context, List<String> initialPackageNames, Handler handler) {
    private GeocoderProxy(Context context,
            int overlaySwitchResId, int defaultServicePackageNameResId,
            int initialPackageNamesResId, Handler handler) {
        mContext = context;
        mContext = context;


        mServiceWatcher = new ServiceWatcher(mContext, TAG, SERVICE_ACTION, initialPackageNames,
        mServiceWatcher = new ServiceWatcher(mContext, TAG, SERVICE_ACTION, overlaySwitchResId,
                null, handler);
            defaultServicePackageNameResId, initialPackageNamesResId, null, handler);
    }
    }


    private boolean bind () {
    private boolean bind () {
Loading