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

Commit cd40c740 authored by Pyuli Naithani's avatar Pyuli Naithani Committed by Android (Google) Code Review
Browse files

Merge "Add statsd logs for Sensor Privacy." into sc-dev

parents 88931609 76be38c0
Loading
Loading
Loading
Loading
+10 −2
Original line number Diff line number Diff line
@@ -1050,8 +1050,16 @@ package android.graphics.fonts {
package android.hardware {

  public final class SensorPrivacyManager {
    method @RequiresPermission(android.Manifest.permission.MANAGE_SENSOR_PRIVACY) public void setSensorPrivacy(int, boolean);
    method @RequiresPermission(android.Manifest.permission.MANAGE_SENSOR_PRIVACY) public void setSensorPrivacyForProfileGroup(int, boolean);
    method @RequiresPermission(android.Manifest.permission.MANAGE_SENSOR_PRIVACY) public void setSensorPrivacy(int, int, boolean);
    method @RequiresPermission(android.Manifest.permission.MANAGE_SENSOR_PRIVACY) public void setSensorPrivacyForProfileGroup(int, int, boolean);
  }

  public static class SensorPrivacyManager.Sources {
    field public static final int DIALOG = 3; // 0x3
    field public static final int OTHER = 5; // 0x5
    field public static final int QS_TILE = 1; // 0x1
    field public static final int SETTINGS = 2; // 0x2
    field public static final int SHELL = 4; // 0x4
  }

}
+2 −2
Original line number Diff line number Diff line
@@ -41,9 +41,9 @@ interface ISensorPrivacyManager {

    void setSensorPrivacy(boolean enable);

    void setIndividualSensorPrivacy(int userId, int sensor, boolean enable);
    void setIndividualSensorPrivacy(int userId, int source, int sensor, boolean enable);

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

    void suppressIndividualSensorPrivacyReminders(int userId, String packageName, IBinder token,
+65 −12
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ import android.os.IBinder;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.service.SensorPrivacyIndividualEnabledSensorProto;
import android.service.SensorPrivacyToggleSourceProto;
import android.util.ArrayMap;
import android.util.Pair;
import android.util.SparseArray;
@@ -98,6 +99,56 @@ public final class SensorPrivacyManager {
        public @interface Sensor {}
    }

    /**
     * Source through which Privacy Sensor was toggled.
     * @hide
     */
    @TestApi
    public static class Sources {
        private Sources() {}

        /**
         * Constant for the Quick Setting Tile.
         */
        public static final int QS_TILE = SensorPrivacyToggleSourceProto.QS_TILE;

        /**
         * Constant for the Settings.
         */
        public static final int SETTINGS = SensorPrivacyToggleSourceProto.SETTINGS;

        /**
         * Constant for Dialog.
         */
        public static final int DIALOG = SensorPrivacyToggleSourceProto.DIALOG;

        /**
         * Constant for SHELL.
         */
        public static final int SHELL = SensorPrivacyToggleSourceProto.SHELL;

        /**
         * Constant for OTHER.
         */
        public static final int OTHER = SensorPrivacyToggleSourceProto.OTHER;

        /**
         * Source for toggling sensors
         *
         * @hide
         */
        @IntDef(value = {
                QS_TILE,
                SETTINGS,
                DIALOG,
                SHELL,
                OTHER
        })
        @Retention(RetentionPolicy.SOURCE)
        public @interface Source {}

    }

    /**
     * A class implementing this interface can register with the {@link
     * android.hardware.SensorPrivacyManager} to receive notification when the sensor privacy
@@ -339,8 +390,9 @@ public final class SensorPrivacyManager {
     */
    @TestApi
    @RequiresPermission(Manifest.permission.MANAGE_SENSOR_PRIVACY)
    public void setSensorPrivacy(@Sensors.Sensor int sensor, boolean enable) {
        setSensorPrivacy(sensor, enable, mContext.getUserId());
    public void setSensorPrivacy(@Sources.Source int source, @Sensors.Sensor int sensor,
            boolean enable) {
        setSensorPrivacy(source, sensor, enable, mContext.getUserId());
    }

    /**
@@ -353,10 +405,10 @@ public final class SensorPrivacyManager {
     * @hide
     */
    @RequiresPermission(Manifest.permission.MANAGE_SENSOR_PRIVACY)
    public void setSensorPrivacy(@Sensors.Sensor int sensor, boolean enable,
            @UserIdInt int userId) {
    public void setSensorPrivacy(@Sources.Source int source, @Sensors.Sensor int sensor,
            boolean enable, @UserIdInt int userId) {
        try {
            mService.setIndividualSensorPrivacy(userId, sensor, enable);
            mService.setIndividualSensorPrivacy(userId, source, sensor, enable);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
@@ -366,6 +418,7 @@ public final class SensorPrivacyManager {
     * Sets sensor privacy to the specified state for an individual sensor for the profile group of
     * context's user.
     *
     * @param source the source using which the sensor is toggled.
     * @param sensor the sensor which to change the state for
     * @param enable the state to which sensor privacy should be set.
     *
@@ -373,15 +426,16 @@ public final class SensorPrivacyManager {
     */
    @TestApi
    @RequiresPermission(Manifest.permission.MANAGE_SENSOR_PRIVACY)
    public void setSensorPrivacyForProfileGroup(@Sensors.Sensor int sensor,
            boolean enable) {
        setSensorPrivacyForProfileGroup(sensor, enable, mContext.getUserId());
    public void setSensorPrivacyForProfileGroup(@Sources.Source int source,
            @Sensors.Sensor int sensor, boolean enable) {
        setSensorPrivacyForProfileGroup(source , sensor, enable, mContext.getUserId());
    }

    /**
     * Sets sensor privacy to the specified state for an individual sensor for the profile group of
     * context's user.
     *
     * @param source the source using which the sensor is toggled.
     * @param sensor the sensor which to change the state for
     * @param enable the state to which sensor privacy should be set.
     * @param userId the user's id
@@ -389,11 +443,10 @@ public final class SensorPrivacyManager {
     * @hide
     */
    @RequiresPermission(Manifest.permission.MANAGE_SENSOR_PRIVACY)
    public void setSensorPrivacyForProfileGroup(@Sensors.Sensor int sensor,
            boolean enable, @UserIdInt int userId) {
    public void setSensorPrivacyForProfileGroup(@Sources.Source int source,
            @Sensors.Sensor int sensor, boolean enable, @UserIdInt int userId) {
        try {
            mService.setIndividualSensorPrivacyForProfileGroup(userId, sensor,
                    enable);
            mService.setIndividualSensorPrivacyForProfileGroup(userId, source, sensor, enable);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
+18 −0
Original line number Diff line number Diff line
@@ -66,3 +66,21 @@ message SensorPrivacyIndividualEnabledSensorProto {
    // If sensor privacy is enabled for this sensor
    optional bool is_enabled = 2;
}

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

    enum Source {
        UNKNOWN = 0;

        QS_TILE = 1;
        SETTINGS = 2;
        DIALOG = 3;
        SHELL = 4;
        OTHER = 5;
    }

    // Source for which sensor privacy was toggled.
    optional Source source = 1;

}
 No newline at end of file
+4 −2
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package com.android.systemui.qs.tiles;

import static android.hardware.SensorPrivacyManager.Sources.QS_TILE;

import android.content.Intent;
import android.hardware.SensorPrivacyManager.Sensors.Sensor;
import android.os.Handler;
@@ -87,12 +89,12 @@ public abstract class SensorPrivacyToggleTile extends QSTileImpl<QSTile.BooleanS
    protected void handleClick(@Nullable View view) {
        if (mKeyguard.isMethodSecure() && mKeyguard.isShowing()) {
            mActivityStarter.postQSRunnableDismissingKeyguard(() -> {
                mSensorPrivacyController.setSensorBlocked(getSensorId(),
                mSensorPrivacyController.setSensorBlocked(QS_TILE, getSensorId(),
                        !mSensorPrivacyController.isSensorBlocked(getSensorId()));
            });
            return;
        }
        mSensorPrivacyController.setSensorBlocked(getSensorId(),
        mSensorPrivacyController.setSensorBlocked(QS_TILE, getSensorId(),
                !mSensorPrivacyController.isSensorBlocked(getSensorId()));
    }

Loading