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

Commit e54bdfb4 authored by Jyoti Bhayana's avatar Jyoti Bhayana Committed by Android (Google) Code Review
Browse files

Merge "Implement API changes for camera privacy allowlist" into main

parents f22a50b4 c63d3dc5
Loading
Loading
Loading
Loading
+7 −1
Original line number Diff line number Diff line
@@ -4821,7 +4821,7 @@ package android.hardware {
    method @RequiresPermission(android.Manifest.permission.OBSERVE_SENSOR_PRIVACY) public void addSensorPrivacyListener(@NonNull android.hardware.SensorPrivacyManager.OnSensorPrivacyChangedListener);
    method @RequiresPermission(android.Manifest.permission.OBSERVE_SENSOR_PRIVACY) public void addSensorPrivacyListener(@NonNull java.util.concurrent.Executor, @NonNull android.hardware.SensorPrivacyManager.OnSensorPrivacyChangedListener);
    method @RequiresPermission(android.Manifest.permission.OBSERVE_SENSOR_PRIVACY) public boolean areAnySensorPrivacyTogglesEnabled(int);
    method @FlaggedApi("com.android.internal.camera.flags.camera_privacy_allowlist") @NonNull @RequiresPermission(android.Manifest.permission.OBSERVE_SENSOR_PRIVACY) public java.util.Map<java.lang.String,java.lang.Boolean> getCameraPrivacyAllowlist();
    method @FlaggedApi("com.android.internal.camera.flags.camera_privacy_allowlist") @NonNull @RequiresPermission(android.Manifest.permission.OBSERVE_SENSOR_PRIVACY) public java.util.List<java.lang.String> getCameraPrivacyAllowlist();
    method @FlaggedApi("com.android.internal.camera.flags.camera_privacy_allowlist") @RequiresPermission(android.Manifest.permission.OBSERVE_SENSOR_PRIVACY) public int getSensorPrivacyState(int, int);
    method @FlaggedApi("com.android.internal.camera.flags.camera_privacy_allowlist") @RequiresPermission(android.Manifest.permission.OBSERVE_SENSOR_PRIVACY) public boolean isCameraPrivacyEnabled(@NonNull String);
    method @Deprecated @RequiresPermission(android.Manifest.permission.OBSERVE_SENSOR_PRIVACY) public boolean isSensorPrivacyEnabled(int);
@@ -4844,6 +4844,12 @@ package android.hardware {
    method public boolean isEnabled();
  }
  @FlaggedApi("com.android.internal.camera.flags.camera_privacy_allowlist") public static class SensorPrivacyManager.StateTypes {
    field public static final int DISABLED = 2; // 0x2
    field public static final int ENABLED = 1; // 0x1
    field public static final int ENABLED_EXCEPT_ALLOWLISTED_APPS = 3; // 0x3
  }
}
package android.hardware.biometrics {
+1 −0
Original line number Diff line number Diff line
@@ -1519,6 +1519,7 @@ package android.graphics.fonts {
package android.hardware {

  public final class SensorPrivacyManager {
    method @FlaggedApi("com.android.internal.camera.flags.camera_privacy_allowlist") @RequiresPermission(android.Manifest.permission.MANAGE_SENSOR_PRIVACY) public void setCameraPrivacyAllowlist(@NonNull java.util.List<java.lang.String>);
    method @RequiresPermission(android.Manifest.permission.MANAGE_SENSOR_PRIVACY) public void setSensorPrivacy(int, int, boolean);
    method @FlaggedApi("com.android.internal.camera.flags.camera_privacy_allowlist") @RequiresPermission(android.Manifest.permission.MANAGE_SENSOR_PRIVACY) public void setSensorPrivacyState(int, int, int);
  }
+0 −24
Original line number Diff line number Diff line
/**
 * Copyright (c) 2024, The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.hardware;

/** @hide */
parcelable CameraPrivacyAllowlistEntry {
    String packageName;
    boolean isMandatory;
}
+5 −2
Original line number Diff line number Diff line
@@ -16,7 +16,6 @@

package android.hardware;

import android.hardware.CameraPrivacyAllowlistEntry;
import android.hardware.ISensorPrivacyListener;

/** @hide */
@@ -48,7 +47,7 @@ interface ISensorPrivacyManager {
    void setToggleSensorPrivacyForProfileGroup(int userId, int source, int sensor, boolean enable);

    @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.OBSERVE_SENSOR_PRIVACY)")
    List<CameraPrivacyAllowlistEntry> getCameraPrivacyAllowlist();
    List<String> getCameraPrivacyAllowlist();

    @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.OBSERVE_SENSOR_PRIVACY)")
    int getToggleSensorPrivacyState(int toggleType, int sensor);
@@ -62,6 +61,10 @@ interface ISensorPrivacyManager {
    @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.OBSERVE_SENSOR_PRIVACY)")
    boolean isCameraPrivacyEnabled(String packageName);

    /** @hide */
    @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.MANAGE_SENSOR_PRIVACY)")
    void setCameraPrivacyAllowlist(in List<String> allowlist);

    // =============== End of transactions used on native side as well ============================

    void suppressToggleSensorPrivacyReminders(int userId, int sensor, IBinder token,
+40 −44
Original line number Diff line number Diff line
@@ -43,7 +43,7 @@ import com.android.internal.camera.flags.Flags;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.Map;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.Executor;

@@ -204,6 +204,8 @@ public final class SensorPrivacyManager {
     * Types of state which can exist for the sensor privacy toggle
     * @hide
     */
    @SystemApi
    @FlaggedApi(Flags.FLAG_CAMERA_PRIVACY_ALLOWLIST)
    public static class StateTypes {
        private StateTypes() {}

@@ -217,30 +219,12 @@ public final class SensorPrivacyManager {
         */
        public static final int DISABLED = SensorPrivacyIndividualEnabledSensorProto.DISABLED;

        /**
         * Constant indicating privacy is enabled except for the automotive driver assistance apps
         * which are helpful for driving.
         */
        @FlaggedApi(Flags.FLAG_CAMERA_PRIVACY_ALLOWLIST)
        public static final int AUTOMOTIVE_DRIVER_ASSISTANCE_HELPFUL_APPS =
                SensorPrivacyIndividualEnabledSensorProto.AUTO_DRIVER_ASSISTANCE_HELPFUL_APPS;

         /**
         * Constant indicating privacy is enabled except for the automotive driver assistance apps
         * which are required by car manufacturer for driving.
         */
        @FlaggedApi(Flags.FLAG_CAMERA_PRIVACY_ALLOWLIST)
        public static final int AUTOMOTIVE_DRIVER_ASSISTANCE_REQUIRED_APPS =
                SensorPrivacyIndividualEnabledSensorProto.AUTO_DRIVER_ASSISTANCE_REQUIRED_APPS;

        /**
         * Constant indicating privacy is enabled except for the automotive driver assistance apps
         * which are both helpful for driving and also apps required by car manufacturer for
         * driving.
         */
        @FlaggedApi(Flags.FLAG_CAMERA_PRIVACY_ALLOWLIST)
        public static final int AUTOMOTIVE_DRIVER_ASSISTANCE_APPS =
                SensorPrivacyIndividualEnabledSensorProto.AUTO_DRIVER_ASSISTANCE_APPS;
        public static final int ENABLED_EXCEPT_ALLOWLISTED_APPS =
                SensorPrivacyIndividualEnabledSensorProto.ENABLED_EXCEPT_ALLOWLISTED_APPS;

        /**
         * Types of state which can exist for a sensor privacy toggle
@@ -250,9 +234,7 @@ public final class SensorPrivacyManager {
        @IntDef(value = {
                ENABLED,
                DISABLED,
                AUTOMOTIVE_DRIVER_ASSISTANCE_HELPFUL_APPS,
                AUTOMOTIVE_DRIVER_ASSISTANCE_REQUIRED_APPS,
                AUTOMOTIVE_DRIVER_ASSISTANCE_APPS
                ENABLED_EXCEPT_ALLOWLISTED_APPS
        })
        @Retention(RetentionPolicy.SOURCE)
        public @interface StateType {}
@@ -369,9 +351,6 @@ public final class SensorPrivacyManager {
    private final ArrayMap<Pair<Integer, OnSensorPrivacyChangedListener>,
            OnSensorPrivacyChangedListener> mLegacyToggleListeners = new ArrayMap<>();

    @GuardedBy("mLock")
    private ArrayMap<String, Boolean> mCameraPrivacyAllowlist = null;

    /** The singleton ISensorPrivacyListener for IPC which will be used to dispatch to local
     * listeners */
    @NonNull
@@ -397,7 +376,8 @@ public final class SensorPrivacyManager {

        @Override
        @FlaggedApi(Flags.FLAG_CAMERA_PRIVACY_ALLOWLIST)
        public void onSensorPrivacyStateChanged(int toggleType, int sensor, int state) {
        public void onSensorPrivacyStateChanged(@ToggleType int toggleType,
                @Sensors.Sensor int sensor, @StateTypes.StateType int state) {
            synchronized (mLock) {
                for (int i = 0; i < mToggleListeners.size(); i++) {
                    OnSensorPrivacyChangedListener listener = mToggleListeners.keyAt(i);
@@ -725,6 +705,8 @@ public final class SensorPrivacyManager {
    /**
     * Returns sensor privacy state for a specific sensor.
     *
     * @param toggleType The type of toggle to use
     * @param sensor The sensor to check
     * @return int sensor privacy state.
     *
     * @hide
@@ -744,6 +726,7 @@ public final class SensorPrivacyManager {
   /**
     * Returns if camera privacy is enabled for a specific package.
     *
     * @param packageName The package to check
     * @return boolean sensor privacy state.
     *
     * @hide
@@ -763,29 +746,41 @@ public final class SensorPrivacyManager {
     * Returns camera privacy allowlist.
     *
     * @return List of automotive driver assistance packages for
     * privacy allowlisting. The returned map includes the package
     * name as key and the value is a Boolean which tells if that package
     * is required by the car manufacturer as mandatory package for driving.
     * privacy allowlisting.
     *
     * @hide
     */
    @SystemApi
    @RequiresPermission(Manifest.permission.OBSERVE_SENSOR_PRIVACY)
    @FlaggedApi(Flags.FLAG_CAMERA_PRIVACY_ALLOWLIST)
    public @NonNull Map<String, Boolean>  getCameraPrivacyAllowlist() {
    public @NonNull List<String>  getCameraPrivacyAllowlist() {
        synchronized (mLock) {
            if (mCameraPrivacyAllowlist == null) {
                mCameraPrivacyAllowlist = new ArrayMap<>();
            try {
                    for (CameraPrivacyAllowlistEntry entry :
                            mService.getCameraPrivacyAllowlist()) {
                        mCameraPrivacyAllowlist.put(entry.packageName, entry.isMandatory);
                    }
                return mService.getCameraPrivacyAllowlist();
            } catch (RemoteException e) {
                throw e.rethrowFromSystemServer();
            }
        }
            return mCameraPrivacyAllowlist;
    }

    /**
     * Sets camera privacy allowlist.
     *
     * @param allowlist List of automotive driver assistance packages for
     * privacy allowlisting.
     *
     * @hide
     */
    @TestApi
    @RequiresPermission(Manifest.permission.MANAGE_SENSOR_PRIVACY)
    @FlaggedApi(Flags.FLAG_CAMERA_PRIVACY_ALLOWLIST)
    public void setCameraPrivacyAllowlist(@NonNull List<String> allowlist) {
        synchronized (mLock) {
            try {
                mService.setCameraPrivacyAllowlist(allowlist);
            } catch (RemoteException e) {
                throw e.rethrowFromSystemServer();
            }
        }
    }

@@ -867,6 +862,7 @@ public final class SensorPrivacyManager {
    /**
     * Sets sensor privacy to the specified state for an individual sensor.
     *
     * @param source the source using which the sensor is toggled
     * @param sensor the sensor which to change the state for
     * @param state the state to which sensor privacy should be set.
     *
Loading