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

Commit 7e9249d6 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Rename featureId to attributionTag"

parents d820a953 f29d7766
Loading
Loading
Loading
Loading
+14 −14
Original line number Diff line number Diff line
@@ -45,17 +45,17 @@ import com.android.internal.location.ProviderProperties;
 */
interface ILocationManager
{
    Location getLastLocation(in LocationRequest request, String packageName, String featureId);
    Location getLastLocation(in LocationRequest request, String packageName, String attributionTag);
    boolean getCurrentLocation(in LocationRequest request,
            in ICancellationSignal cancellationSignal, in ILocationListener listener,
            String packageName, String featureId);
            String packageName, String attributionTag);

    void requestLocationUpdates(in LocationRequest request, in ILocationListener listener,
            in PendingIntent intent, String packageName, String featureId);
            in PendingIntent intent, String packageName, String attributionTag);
    void removeUpdates(in ILocationListener listener, in PendingIntent intent);

    void requestGeofence(in LocationRequest request, in Geofence geofence,
            in PendingIntent intent, String packageName, String featureId);
            in PendingIntent intent, String packageName, String attributionTag);
    void removeGeofence(in Geofence fence, in PendingIntent intent, String packageName);

    boolean geocoderIsPresent();
@@ -70,24 +70,24 @@ interface ILocationManager
    int getGnssYearOfHardware();
    String getGnssHardwareModelName();

    void registerGnssStatusCallback(in IGnssStatusListener callback, String packageName, String featureId);
    void registerGnssStatusCallback(in IGnssStatusListener callback, String packageName, String attributionTag);
    void unregisterGnssStatusCallback(in IGnssStatusListener callback);

    void addGnssMeasurementsListener(in GnssRequest request, in IGnssMeasurementsListener listener, String packageName, String featureId);
    void addGnssMeasurementsListener(in GnssRequest request, in IGnssMeasurementsListener listener, String packageName, String attributionTag);
    void removeGnssMeasurementsListener(in IGnssMeasurementsListener listener);

    void addGnssAntennaInfoListener(in IGnssAntennaInfoListener listener, String packageName, String featureId);
    void addGnssAntennaInfoListener(in IGnssAntennaInfoListener listener, String packageName, String attributionTag);
    void removeGnssAntennaInfoListener(in IGnssAntennaInfoListener listener);

    void addGnssNavigationMessageListener(in IGnssNavigationMessageListener listener, String packageName, String featureId);
    void addGnssNavigationMessageListener(in IGnssNavigationMessageListener listener, String packageName, String attributionTag);
    void removeGnssNavigationMessageListener(in IGnssNavigationMessageListener listener);

    void injectGnssMeasurementCorrections(in GnssMeasurementCorrections corrections, String packageName);

    int getGnssBatchSize(String packageName);
    void addGnssBatchingCallback(in IBatchedLocationCallback callback, String packageName, String featureId);
    void addGnssBatchingCallback(in IBatchedLocationCallback callback, String packageName, String attributionTag);
    void removeGnssBatchingCallback();
    void startGnssBatch(long periodNanos, boolean wakeOnFifoFull, String packageName, String featureId);
    void startGnssBatch(long periodNanos, boolean wakeOnFifoFull, String packageName, String attributionTag);
    void flushGnssBatch(String packageName);
    void stopGnssBatch();
    void injectLocation(in Location location);
@@ -107,10 +107,10 @@ interface ILocationManager
    boolean isProviderEnabledForUser(String provider, int userId);
    boolean isLocationEnabledForUser(int userId);
    void setLocationEnabledForUser(boolean enabled, int userId);
    void addTestProvider(String name, in ProviderProperties properties, String packageName, String featureId);
    void removeTestProvider(String provider, String packageName, String featureId);
    void setTestProviderLocation(String provider, in Location location, String packageName, String featureId);
    void setTestProviderEnabled(String provider, boolean enabled, String packageName, String featureId);
    void addTestProvider(String name, in ProviderProperties properties, String packageName, String attributionTag);
    void removeTestProvider(String provider, String packageName, String attributionTag);
    void setTestProviderLocation(String provider, in Location location, String packageName, String attributionTag);
    void setTestProviderEnabled(String provider, boolean enabled, String packageName, String attributionTag);
    List<LocationRequest> getTestProviderCurrentRequests(String provider);
    LocationTime getGnssTimeMillis();

+18 −18
Original line number Diff line number Diff line
@@ -84,9 +84,9 @@ public final class CallerIdentity {
     */
    @VisibleForTesting
    public static CallerIdentity forTest(int uid, int pid, String packageName,
            @Nullable String featureId, @PermissionLevel int permissionLevel) {
            @Nullable String attributionTag, @PermissionLevel int permissionLevel) {

        return new CallerIdentity(uid, pid, packageName, featureId,
        return new CallerIdentity(uid, pid, packageName, attributionTag,
                permissionLevel);
    }

@@ -105,13 +105,13 @@ public final class CallerIdentity {
     * security exception will be thrown if it is invalid.
     */
    public static CallerIdentity fromBinder(Context context, String packageName,
            @Nullable String featureId) {
            @Nullable String attributionTag) {
        int uid = Binder.getCallingUid();
        if (!ArrayUtils.contains(context.getPackageManager().getPackagesForUid(uid), packageName)) {
            throw new SecurityException("invalid package \"" + packageName + "\" for uid " + uid);
        }

        return fromBinderUnsafe(context, packageName, featureId);
        return fromBinderUnsafe(context, packageName, attributionTag);
    }

    /**
@@ -121,9 +121,9 @@ public final class CallerIdentity {
     * an appops call.
     */
    public static CallerIdentity fromBinderUnsafe(Context context, String packageName,
            @Nullable String featureId) {
            @Nullable String attributionTag) {
        return new CallerIdentity(Binder.getCallingUid(), Binder.getCallingPid(),
                packageName, featureId,
                packageName, attributionTag,
                getPermissionLevel(context, Binder.getCallingPid(), Binder.getCallingUid()));
    }

@@ -190,8 +190,8 @@ public final class CallerIdentity {
    /** The calling package name. */
    public final String packageName;

    /** The calling feature id. */
    public final @Nullable String featureId;
    /** The calling attribution tag. */
    public final @Nullable String attributionTag;

    /**
     * The calling location permission level. This field should only be used for validating
@@ -201,12 +201,12 @@ public final class CallerIdentity {
    public final @PermissionLevel int permissionLevel;

    private CallerIdentity(int uid, int pid, String packageName,
            @Nullable String featureId, @PermissionLevel int permissionLevel) {
            @Nullable String attributionTag, @PermissionLevel int permissionLevel) {
        this.uid = uid;
        this.pid = pid;
        this.userId = UserHandle.getUserId(uid);
        this.packageName = Objects.requireNonNull(packageName);
        this.featureId = featureId;
        this.attributionTag = attributionTag;
        this.permissionLevel = Preconditions.checkArgumentInRange(permissionLevel, PERMISSION_NONE,
                PERMISSION_FINE, "permissionLevel");
    }
@@ -221,18 +221,18 @@ public final class CallerIdentity {
    @Override
    public String toString() {
        int length = 10 + packageName.length();
        if (featureId != null) {
            length += featureId.length();
        if (attributionTag != null) {
            length += attributionTag.length();
        }

        StringBuilder builder = new StringBuilder(length);
        builder.append(pid).append("/").append(packageName);
        if (featureId != null) {
        if (attributionTag != null) {
            builder.append("[");
            if (featureId.startsWith(packageName)) {
                builder.append(featureId.substring(packageName.length()));
            if (attributionTag.startsWith(packageName)) {
                builder.append(attributionTag.substring(packageName.length()));
            } else {
                builder.append(featureId);
                builder.append(attributionTag);
            }
            builder.append("]");
        }
@@ -251,11 +251,11 @@ public final class CallerIdentity {
        return uid == that.uid
                && pid == that.pid
                && packageName.equals(that.packageName)
                && Objects.equals(featureId, that.featureId);
                && Objects.equals(attributionTag, that.attributionTag);
    }

    @Override
    public int hashCode() {
        return Objects.hash(uid, pid, packageName, featureId);
        return Objects.hash(uid, pid, packageName, attributionTag);
    }
}
+4 −4
Original line number Diff line number Diff line
@@ -191,7 +191,7 @@ public class AppOpsHelper {
                    AppOpsManager.OP_MOCK_LOCATION,
                    callerIdentity.uid,
                    callerIdentity.packageName,
                    callerIdentity.featureId,
                    callerIdentity.attributionTag,
                    null) == AppOpsManager.MODE_ALLOWED;
        } finally {
            Binder.restoreCallingIdentity(identity);
@@ -210,7 +210,7 @@ public class AppOpsHelper {
                    callerIdentity.uid,
                    callerIdentity.packageName,
                    false,
                    callerIdentity.featureId,
                    callerIdentity.attributionTag,
                    null) == AppOpsManager.MODE_ALLOWED;
        } finally {
            Binder.restoreCallingIdentity(identity);
@@ -228,7 +228,7 @@ public class AppOpsHelper {
                    appOp,
                    callerIdentity.uid,
                    callerIdentity.packageName,
                    callerIdentity.featureId);
                    callerIdentity.attributionTag);
        } finally {
            Binder.restoreCallingIdentity(identity);
        }
@@ -245,7 +245,7 @@ public class AppOpsHelper {
                    appOp,
                    callerIdentity.uid,
                    callerIdentity.packageName,
                    callerIdentity.featureId,
                    callerIdentity.attributionTag,
                    null) == AppOpsManager.MODE_ALLOWED;
        } finally {
            Binder.restoreCallingIdentity(identity);
+1 −1
Original line number Diff line number Diff line
@@ -254,7 +254,7 @@ public class GeofenceManager implements LocationListener, PendingIntent.OnFinish
                int op = CallerIdentity.asAppOp(identity.permissionLevel);
                if (op >= 0) {
                    if (mAppOps.noteOpNoThrow(AppOpsManager.OP_FINE_LOCATION, identity.uid,
                            identity.packageName, identity.featureId, null)
                            identity.packageName, identity.attributionTag, null)
                            != AppOpsManager.MODE_ALLOWED) {
                        continue;
                    }
+41 −32
Original line number Diff line number Diff line
@@ -1343,9 +1343,9 @@ public class LocationManagerService extends ILocationManager.Stub {

    @Override
    public void addGnssBatchingCallback(IBatchedLocationCallback callback, String packageName,
            String featureId) {
            String attributionTag) {
        if (mGnssManagerService != null) {
            mGnssManagerService.addGnssBatchingCallback(callback, packageName, featureId);
            mGnssManagerService.addGnssBatchingCallback(callback, packageName, attributionTag);
        }
    }

@@ -1358,9 +1358,10 @@ public class LocationManagerService extends ILocationManager.Stub {

    @Override
    public void startGnssBatch(long periodNanos, boolean wakeOnFifoFull, String packageName,
            String featureId) {
            String attributionTag) {
        if (mGnssManagerService != null) {
            mGnssManagerService.startGnssBatch(periodNanos, wakeOnFifoFull, packageName, featureId);
            mGnssManagerService.startGnssBatch(periodNanos, wakeOnFifoFull, packageName,
                    attributionTag);
        }
    }

@@ -1687,7 +1688,7 @@ public class LocationManagerService extends ILocationManager.Stub {

            // Update statistics for historical location requests by package/provider
            mRequestStatistics.startRequesting(
                    mReceiver.mCallerIdentity.packageName, mReceiver.mCallerIdentity.featureId,
                    mReceiver.mCallerIdentity.packageName, mReceiver.mCallerIdentity.attributionTag,
                    provider, request.getInterval(), mIsForegroundUid);
        }

@@ -1697,7 +1698,7 @@ public class LocationManagerService extends ILocationManager.Stub {
        private void updateForeground(boolean isForeground) {
            mIsForegroundUid = isForeground;
            mRequestStatistics.updateForeground(
                    mReceiver.mCallerIdentity.packageName, mReceiver.mCallerIdentity.featureId,
                    mReceiver.mCallerIdentity.packageName, mReceiver.mCallerIdentity.attributionTag,
                    mProvider, isForeground);
        }

@@ -1706,7 +1707,8 @@ public class LocationManagerService extends ILocationManager.Stub {
         */
        private void disposeLocked(boolean removeReceiver) {
            CallerIdentity identity = mReceiver.mCallerIdentity;
            mRequestStatistics.stopRequesting(identity.packageName, identity.featureId, mProvider);
            mRequestStatistics.stopRequesting(identity.packageName, identity.attributionTag,
                    mProvider);

            mLocationUsageLogger.logLocationApiUsage(
                    LocationStatsEnums.USAGE_ENDED,
@@ -1827,12 +1829,12 @@ public class LocationManagerService extends ILocationManager.Stub {

    @Override
    public void requestLocationUpdates(LocationRequest request, ILocationListener listener,
            PendingIntent intent, String packageName, String featureId) {
            PendingIntent intent, String packageName, String attributionTag) {
        if (request == null) {
            request = DEFAULT_LOCATION_REQUEST;
        }

        CallerIdentity identity = CallerIdentity.fromBinder(mContext, packageName, featureId);
        CallerIdentity identity = CallerIdentity.fromBinder(mContext, packageName, attributionTag);
        identity.enforceLocationPermission(PERMISSION_COARSE);

        WorkSource workSource = request.getWorkSource();
@@ -1978,13 +1980,15 @@ public class LocationManagerService extends ILocationManager.Stub {
    }

    @Override
    public Location getLastLocation(LocationRequest request, String packageName, String featureId) {
    public Location getLastLocation(LocationRequest request, String packageName,
            String attributionTag) {
        if (request == null) {
            request = DEFAULT_LOCATION_REQUEST;
        }

        // unsafe is ok because app ops will verify the package name
        CallerIdentity identity = CallerIdentity.fromBinderUnsafe(mContext, packageName, featureId);
        CallerIdentity identity = CallerIdentity.fromBinderUnsafe(mContext, packageName,
                attributionTag);
        identity.enforceLocationPermission(PERMISSION_COARSE);

        if (mSettingsHelper.isLocationPackageBlacklisted(identity.userId, identity.packageName)) {
@@ -2018,9 +2022,9 @@ public class LocationManagerService extends ILocationManager.Stub {
    @Override
    public boolean getCurrentLocation(LocationRequest locationRequest,
            ICancellationSignal remoteCancellationSignal, ILocationListener listener,
            String packageName, String featureId) {
            String packageName, String attributionTag) {
        // side effect of validating locationRequest and packageName
        Location lastLocation = getLastLocation(locationRequest, packageName, featureId);
        Location lastLocation = getLastLocation(locationRequest, packageName, attributionTag);
        if (lastLocation != null) {
            long locationAgeMs = NANOSECONDS.toMillis(
                    SystemClock.elapsedRealtimeNanos() - lastLocation.getElapsedRealtimeNanos());
@@ -2043,7 +2047,7 @@ public class LocationManagerService extends ILocationManager.Stub {
            }
        }

        requestLocationUpdates(locationRequest, listener, null, packageName, featureId);
        requestLocationUpdates(locationRequest, listener, null, packageName, attributionTag);
        CancellationSignal cancellationSignal = CancellationSignal.fromTransport(
                remoteCancellationSignal);
        if (cancellationSignal != null) {
@@ -2091,12 +2095,12 @@ public class LocationManagerService extends ILocationManager.Stub {

    @Override
    public void requestGeofence(LocationRequest request, Geofence geofence, PendingIntent intent,
            String packageName, String featureId) {
            String packageName, String attributionTag) {
        if (request == null) {
            request = DEFAULT_LOCATION_REQUEST;
        }

        CallerIdentity identity = CallerIdentity.fromBinder(mContext, packageName, featureId);
        CallerIdentity identity = CallerIdentity.fromBinder(mContext, packageName, attributionTag);
        identity.enforceLocationPermission(PERMISSION_COARSE);

        Objects.requireNonNull(intent);
@@ -2159,9 +2163,9 @@ public class LocationManagerService extends ILocationManager.Stub {

    @Override
    public void registerGnssStatusCallback(IGnssStatusListener listener, String packageName,
            String featureId) {
            String attributionTag) {
        if (mGnssManagerService != null) {
            mGnssManagerService.registerGnssStatusCallback(listener, packageName, featureId);
            mGnssManagerService.registerGnssStatusCallback(listener, packageName, attributionTag);
        }
    }

@@ -2174,10 +2178,10 @@ public class LocationManagerService extends ILocationManager.Stub {

    @Override
    public void addGnssMeasurementsListener(@Nullable GnssRequest request,
            IGnssMeasurementsListener listener, String packageName, String featureId) {
            IGnssMeasurementsListener listener, String packageName, String attributionTag) {
        if (mGnssManagerService != null) {
            mGnssManagerService.addGnssMeasurementsListener(request, listener, packageName,
                    featureId);
                    attributionTag);
        }
    }

@@ -2206,9 +2210,9 @@ public class LocationManagerService extends ILocationManager.Stub {

    @Override
    public void addGnssAntennaInfoListener(IGnssAntennaInfoListener listener,
            String packageName, String featureId) {
            String packageName, String attributionTag) {
        if (mGnssManagerService != null) {
            mGnssManagerService.addGnssAntennaInfoListener(listener, packageName, featureId);
            mGnssManagerService.addGnssAntennaInfoListener(listener, packageName, attributionTag);
        }
    }

@@ -2221,9 +2225,10 @@ public class LocationManagerService extends ILocationManager.Stub {

    @Override
    public void addGnssNavigationMessageListener(IGnssNavigationMessageListener listener,
            String packageName, String featureId) {
            String packageName, String attributionTag) {
        if (mGnssManagerService != null) {
            mGnssManagerService.addGnssNavigationMessageListener(listener, packageName, featureId);
            mGnssManagerService.addGnssNavigationMessageListener(listener, packageName,
                    attributionTag);
        }
    }

@@ -2547,9 +2552,10 @@ public class LocationManagerService extends ILocationManager.Stub {

    @Override
    public void addTestProvider(String provider, ProviderProperties properties,
            String packageName, String featureId) {
            String packageName, String attributionTag) {
        // unsafe is ok because app ops will verify the package name
        CallerIdentity identity = CallerIdentity.fromBinderUnsafe(mContext, packageName, featureId);
        CallerIdentity identity = CallerIdentity.fromBinderUnsafe(mContext, packageName,
                attributionTag);
        if (!mAppOpsHelper.noteMockLocationAccess(identity)) {
            return;
        }
@@ -2566,9 +2572,10 @@ public class LocationManagerService extends ILocationManager.Stub {
    }

    @Override
    public void removeTestProvider(String provider, String packageName, String featureId) {
    public void removeTestProvider(String provider, String packageName, String attributionTag) {
        // unsafe is ok because app ops will verify the package name
        CallerIdentity identity = CallerIdentity.fromBinderUnsafe(mContext, packageName, featureId);
        CallerIdentity identity = CallerIdentity.fromBinderUnsafe(mContext, packageName,
                attributionTag);
        if (!mAppOpsHelper.noteMockLocationAccess(identity)) {
            return;
        }
@@ -2588,9 +2595,10 @@ public class LocationManagerService extends ILocationManager.Stub {

    @Override
    public void setTestProviderLocation(String provider, Location location, String packageName,
            String featureId) {
            String attributionTag) {
        // unsafe is ok because app ops will verify the package name
        CallerIdentity identity = CallerIdentity.fromBinderUnsafe(mContext, packageName, featureId);
        CallerIdentity identity = CallerIdentity.fromBinderUnsafe(mContext, packageName,
                attributionTag);
        if (!mAppOpsHelper.noteMockLocationAccess(identity)) {
            return;
        }
@@ -2608,9 +2616,10 @@ public class LocationManagerService extends ILocationManager.Stub {

    @Override
    public void setTestProviderEnabled(String provider, boolean enabled, String packageName,
            String featureId) {
            String attributionTag) {
        // unsafe is ok because app ops will verify the package name
        CallerIdentity identity = CallerIdentity.fromBinderUnsafe(mContext, packageName, featureId);
        CallerIdentity identity = CallerIdentity.fromBinderUnsafe(mContext, packageName,
                attributionTag);
        if (!mAppOpsHelper.noteMockLocationAccess(identity)) {
            return;
        }
Loading