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

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

Merge changes from topic "CameraMicToggleListeners"

* changes:
  Add listeners for individual camera and microphone toggles
  Make the sensor privacy state per user
parents 73979a88 1f1e8d72
Loading
Loading
Loading
Loading
+8 −7
Original line number Diff line number Diff line
@@ -26,18 +26,19 @@ interface ISensorPrivacyManager {
    // =============== Beginning of transactions used on native side as well ======================
    void addSensorPrivacyListener(in ISensorPrivacyListener listener);

    void addIndividualSensorPrivacyListener(int userId, int sensor,
            in ISensorPrivacyListener listener);

    void removeSensorPrivacyListener(in ISensorPrivacyListener listener);

    boolean isSensorPrivacyEnabled();

    void setSensorPrivacy(boolean enable);
    // =============== End of transactions used on native side as well ============================
    boolean isIndividualSensorPrivacyEnabled(int userId, int sensor);

    // TODO(evanseverson) add to native interface
    boolean isIndividualSensorPrivacyEnabled(int sensor);
    void setSensorPrivacy(boolean enable);

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

    // TODO(evanseverson) listeners
    void setIndividualSensorPrivacyForProfileGroup(int userId, int sensor, boolean enable);
    // =============== End of transactions used on native side as well ============================
}
 No newline at end of file
+54 −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;
@@ -159,6 +160,37 @@ public final class SensorPrivacyManager {
        }
    }

    /**
     * Registers a new listener to receive notification when the state of sensor privacy
     * changes.
     *
     * @param userId the user's id
     * @param sensor the sensor to listen to changes to
     * @param listener the OnSensorPrivacyChangedListener to be notified when the state of sensor
     *                 privacy changes.
     */
    public void addSensorPrivacyListener(@UserIdInt int userId, @IndividualSensor int sensor,
            final OnSensorPrivacyChangedListener listener) {
        synchronized (mListeners) {
            ISensorPrivacyListener iListener = mListeners.get(listener);
            if (iListener == null) {
                iListener = new ISensorPrivacyListener.Stub() {
                    @Override
                    public void onSensorPrivacyChanged(boolean enabled) {
                        listener.onSensorPrivacyChanged(enabled);
                    }
                };
                mListeners.put(listener, iListener);
            }

            try {
                mService.addIndividualSensorPrivacyListener(userId, sensor, iListener);
            } catch (RemoteException e) {
                throw e.rethrowFromSystemServer();
            }
        }
    }

    /**
     * Unregisters the specified listener from receiving notifications when the state of sensor
     * privacy changes.
@@ -198,9 +230,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 +245,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(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.setIndividualSensorPrivacy(sensor, enable);
            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 {
+355 −72

File changed.

Preview size limit exceeded, changes collapsed.