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

Commit 1f141c1c authored by David Christie's avatar David Christie
Browse files

Fix bug where location provider fails on secondary users.

Bug: 12592045

Change-Id: I196b8621c7f61c3492ad29ae90b608304dc29d66
parent 92ddeeab
Loading
Loading
Loading
Loading
+14 −10
Original line number Diff line number Diff line
@@ -1847,10 +1847,10 @@ public class LocationManagerService extends ILocationManager.Stub {
            return true;
        }
        if (mGeocodeProvider != null) {
            if (doesPackageHaveUid(uid, mGeocodeProvider.getConnectedPackageName())) return true;
            if (doesUidHavePackage(uid, mGeocodeProvider.getConnectedPackageName())) return true;
        }
        for (LocationProviderProxy proxy : mProxyProviders) {
            if (doesPackageHaveUid(uid, proxy.getConnectedPackageName())) return true;
            if (doesUidHavePackage(uid, proxy.getConnectedPackageName())) return true;
        }
        return false;
    }
@@ -1876,20 +1876,24 @@ public class LocationManagerService extends ILocationManager.Stub {
                "or UID of a currently bound location provider");
    }

    private boolean doesPackageHaveUid(int uid, String packageName) {
    /**
     * Returns true if the given package belongs to the given uid.
     */
    private boolean doesUidHavePackage(int uid, String packageName) {
        if (packageName == null) {
            return false;
        }
        try {
            ApplicationInfo appInfo = mPackageManager.getApplicationInfo(packageName, 0);
            if (appInfo.uid != uid) {
                return false;
            }
        } catch (NameNotFoundException e) {
        String[] packageNames = mPackageManager.getPackagesForUid(uid);
        if (packageNames == null) {
            return false;
        }
        for (String name : packageNames) {
            if (packageName.equals(name)) {
                return true;
            }
        }
        return false;
    }

    @Override
    public void reportLocation(Location location, boolean passive) {