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

Commit 705c7539 authored by Evan Severson's avatar Evan Severson Committed by Android (Google) Code Review
Browse files

Merge "Check the current user in the system server for SensorPrivacyManager" into sc-dev

parents 14a3d4f5 6abae2a0
Loading
Loading
Loading
Loading
+5 −13
Original line number Diff line number Diff line
@@ -24,12 +24,12 @@ import android.annotation.SystemApi;
import android.annotation.SystemService;
import android.annotation.TestApi;
import android.annotation.UserIdInt;
import android.app.ActivityManager;
import android.content.Context;
import android.os.Binder;
import android.os.IBinder;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.UserHandle;
import android.service.SensorPrivacyIndividualEnabledSensorProto;
import android.service.SensorPrivacyToggleSourceProto;
import android.util.ArrayMap;
@@ -379,7 +379,7 @@ public final class SensorPrivacyManager {
    @SystemApi
    @RequiresPermission(Manifest.permission.OBSERVE_SENSOR_PRIVACY)
    public boolean isSensorPrivacyEnabled(@Sensors.Sensor int sensor) {
        return isSensorPrivacyEnabled(sensor, getCurrentUserId());
        return isSensorPrivacyEnabled(sensor, UserHandle.USER_CURRENT);
    }

    /**
@@ -410,7 +410,7 @@ public final class SensorPrivacyManager {
    @RequiresPermission(Manifest.permission.MANAGE_SENSOR_PRIVACY)
    public void setSensorPrivacy(@Sources.Source int source, @Sensors.Sensor int sensor,
            boolean enable) {
        setSensorPrivacy(source, sensor, enable, getCurrentUserId());
        setSensorPrivacy(source, sensor, enable, UserHandle.USER_CURRENT);
    }

    /**
@@ -446,7 +446,7 @@ public final class SensorPrivacyManager {
    @RequiresPermission(Manifest.permission.MANAGE_SENSOR_PRIVACY)
    public void setSensorPrivacyForProfileGroup(@Sources.Source int source,
            @Sensors.Sensor int sensor, boolean enable) {
        setSensorPrivacyForProfileGroup(source , sensor, enable, getCurrentUserId());
        setSensorPrivacyForProfileGroup(source , sensor, enable, UserHandle.USER_CURRENT);
    }

    /**
@@ -481,7 +481,7 @@ public final class SensorPrivacyManager {
    @RequiresPermission(Manifest.permission.MANAGE_SENSOR_PRIVACY)
    public void suppressSensorPrivacyReminders(int sensor,
            boolean suppress) {
        suppressSensorPrivacyReminders(sensor, suppress, getCurrentUserId());
        suppressSensorPrivacyReminders(sensor, suppress, UserHandle.USER_CURRENT);
    }

    /**
@@ -609,12 +609,4 @@ public final class SensorPrivacyManager {
        }
    }

    private int getCurrentUserId() {
        try {
            return ActivityManager.getService().getCurrentUserId();
        } catch (RemoteException e) {
            e.rethrowFromSystemServer();
        }
        return 0;
    }
}
+15 −4
Original line number Diff line number Diff line
@@ -21,7 +21,6 @@ import static android.app.ActivityManager.PROCESS_CAPABILITY_FOREGROUND_CAMERA;
import static android.app.ActivityManager.PROCESS_CAPABILITY_FOREGROUND_MICROPHONE;
import static android.app.ActivityManager.RunningServiceInfo;
import static android.app.ActivityManager.RunningTaskInfo;
import static android.app.ActivityManager.getCurrentUser;
import static android.app.AppOpsManager.MODE_ALLOWED;
import static android.app.AppOpsManager.MODE_IGNORED;
import static android.app.AppOpsManager.OP_CAMERA;
@@ -718,6 +717,9 @@ public final class SensorPrivacyService extends SystemService {
        public void setIndividualSensorPrivacy(@UserIdInt int userId,
                @SensorPrivacyManager.Sources.Source int source, int sensor, boolean enable) {
            enforceManageSensorPrivacyPermission();
            if (userId == UserHandle.USER_CURRENT) {
                userId = mCurrentUser;
            }
            if (!canChangeIndividualSensorPrivacy(userId, sensor)) {
                return;
            }
@@ -843,6 +845,9 @@ public final class SensorPrivacyService extends SystemService {
        public void setIndividualSensorPrivacyForProfileGroup(@UserIdInt int userId,
                @SensorPrivacyManager.Sources.Source int source, int sensor, boolean enable) {
            enforceManageSensorPrivacyPermission();
            if (userId == UserHandle.USER_CURRENT) {
                userId = mCurrentUser;
            }
            int parentId = mUserManagerInternal.getProfileParentId(userId);
            forAllUsers(userId2 -> {
                if (parentId == mUserManagerInternal.getProfileParentId(userId2)) {
@@ -896,6 +901,9 @@ public final class SensorPrivacyService extends SystemService {
        @Override
        public boolean isIndividualSensorPrivacyEnabled(@UserIdInt int userId, int sensor) {
            enforceObserveSensorPrivacyPermission();
            if (userId == UserHandle.USER_CURRENT) {
                userId = mCurrentUser;
            }
            synchronized (mLock) {
                return isIndividualSensorPrivacyEnabledLocked(userId, sensor);
            }
@@ -1213,6 +1221,9 @@ public final class SensorPrivacyService extends SystemService {
        public void suppressIndividualSensorPrivacyReminders(int userId, int sensor,
                IBinder token, boolean suppress) {
            enforceManageSensorPrivacyPermission();
            if (userId == UserHandle.USER_CURRENT) {
                userId = mCurrentUser;
            }
            Objects.requireNonNull(token);

            Pair<Integer, UserHandle> key = new Pair<>(sensor, UserHandle.of(userId));
@@ -1898,9 +1909,9 @@ public final class SensorPrivacyService extends SystemService {
                if (!mIsInEmergencyCall) {
                    mIsInEmergencyCall = true;
                    if (mSensorPrivacyServiceImpl
                            .isIndividualSensorPrivacyEnabled(getCurrentUser(), MICROPHONE)) {
                            .isIndividualSensorPrivacyEnabled(mCurrentUser, MICROPHONE)) {
                        mSensorPrivacyServiceImpl.setIndividualSensorPrivacyUnchecked(
                                getCurrentUser(), OTHER, MICROPHONE, false);
                                mCurrentUser, OTHER, MICROPHONE, false);
                        mMicUnmutedForEmergencyCall = true;
                    } else {
                        mMicUnmutedForEmergencyCall = false;
@@ -1915,7 +1926,7 @@ public final class SensorPrivacyService extends SystemService {
                    mIsInEmergencyCall = false;
                    if (mMicUnmutedForEmergencyCall) {
                        mSensorPrivacyServiceImpl.setIndividualSensorPrivacyUnchecked(
                                getCurrentUser(), OTHER, MICROPHONE, true);
                                mCurrentUser, OTHER, MICROPHONE, true);
                        mMicUnmutedForEmergencyCall = false;
                    }
                }