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

Commit 2e3ba7cd authored by Evan Severson's avatar Evan Severson
Browse files

Make the sensor privacy state per user

For the spaceship mode this is purely an internal refactorization since
all the apis remain the same and the state is kept in sync across users.
For the individual controls there's new calls to set the state of the
toggle per user or per profile group.

Test: Manually change state with `adb shell cmd sensor_privacy enable 0
          microphone`
      Manually upgrade from old persistence to new persistence form
      Manually check that the persisted state remains when rebooted.
Bug: 162549680

Change-Id: I0a5eac7a5c3beb272a456790d999a0282d77bf09
parent b26f2017
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -34,10 +34,11 @@ interface ISensorPrivacyManager {
    // =============== End of transactions used on native side as well ============================

    // TODO(evanseverson) add to native interface
    boolean isIndividualSensorPrivacyEnabled(int sensor);
    boolean isIndividualSensorPrivacyEnabled(int userId, int sensor);

    // TODO(evanseverson) add to native interface
    void setIndividualSensorPrivacy(int sensor, boolean enable);
    void setIndividualSensorPrivacy(int userId, int sensor, boolean enable);
    void setIndividualSensorPrivacyForProfileGroup(int userId, int sensor, boolean enable);

    // TODO(evanseverson) listeners
}
 No newline at end of file
+23 −4
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.RequiresPermission;
import android.annotation.SystemService;
import android.annotation.UserIdInt;
import android.content.Context;
import android.os.IBinder;
import android.os.RemoteException;
@@ -198,9 +199,10 @@ public final class SensorPrivacyManager {
     *
     * @return true if sensor privacy is currently enabled, false otherwise.
     */
    public boolean isIndividualSensorPrivacyEnabled(@IndividualSensor int sensor) {
    public boolean isIndividualSensorPrivacyEnabled(@UserIdInt int userId,
            @IndividualSensor int sensor) {
        try {
            return mService.isIndividualSensorPrivacyEnabled(sensor);
            return mService.isIndividualSensorPrivacyEnabled(userId, sensor);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
@@ -212,9 +214,26 @@ public final class SensorPrivacyManager {
     * @param enable the state to which sensor privacy should be set.
     */
    @RequiresPermission(android.Manifest.permission.MANAGE_SENSOR_PRIVACY)
    public void setIndividualSensorPrivacy(@IndividualSensor int sensor, boolean enable) {
    public void setIndividualSensorPrivacy(@UserIdInt int userId, @IndividualSensor int sensor,
            boolean enable) {
        try {
            mService.setIndividualSensorPrivacy(sensor, enable);
            mService.setIndividualSensorPrivacy(userId, sensor, enable);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    /**
     * Sets sensor privacy to the specified state for an individual sensor for the profile group of
     * the given user.
     *
     * @param enable the state to which sensor privacy should be set.
     */
    @RequiresPermission(android.Manifest.permission.MANAGE_SENSOR_PRIVACY)
    public void setIndividualSensorPrivacyForProfileGroup(@UserIdInt int userId,
            @IndividualSensor int sensor, boolean enable) {
        try {
            mService.setIndividualSensorPrivacyForProfileGroup(userId, sensor, enable);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
+18 −0
Original line number Diff line number Diff line
@@ -25,11 +25,29 @@ import "frameworks/base/core/proto/android/privacy.proto";
message SensorPrivacyServiceDumpProto {
    option (android.msg_privacy).dest = DEST_AUTOMATIC;

    // DEPRECATED
    // Is global sensor privacy enabled
    optional bool is_enabled = 1;

    // DEPRECATED
    // Per sensor privacy enabled
    repeated SensorPrivacyIndividualEnabledSensorProto individual_enabled_sensor = 2;

    // Per user settings for sensor privacy
    repeated SensorPrivacyUserProto user = 3;
}

message SensorPrivacyUserProto {
    option (android.msg_privacy).dest = DEST_AUTOMATIC;

    // User id
    optional int32 user_id = 1;

    // Is global sensor privacy enabled
    optional bool is_enabled = 2;

    // Per sensor privacy enabled
    repeated SensorPrivacyIndividualEnabledSensorProto individual_enabled_sensor = 3;
}

message SensorPrivacyIndividualEnabledSensorProto {
+284 −72

File changed.

Preview size limit exceeded, changes collapsed.