Merge "Expose SensorPrivacy as SystemApi" into sc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
445abca30e
@@ -19,6 +19,7 @@ package android.hardware;
|
||||
import android.annotation.IntDef;
|
||||
import android.annotation.NonNull;
|
||||
import android.annotation.RequiresPermission;
|
||||
import android.annotation.SystemApi;
|
||||
import android.annotation.SystemService;
|
||||
import android.annotation.TestApi;
|
||||
import android.content.Context;
|
||||
@@ -33,6 +34,7 @@ import com.android.internal.annotations.GuardedBy;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
/**
|
||||
* This class provides access to the sensor privacy services; sensor privacy allows the
|
||||
@@ -42,9 +44,21 @@ import java.lang.annotation.RetentionPolicy;
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
@SystemApi
|
||||
@TestApi
|
||||
@SystemService(Context.SENSOR_PRIVACY_SERVICE)
|
||||
public final class SensorPrivacyManager {
|
||||
|
||||
/**
|
||||
* @hide
|
||||
*/
|
||||
public static final boolean USE_MICROPHONE_TOGGLE = true;
|
||||
|
||||
/**
|
||||
* @hide
|
||||
*/
|
||||
public static final boolean USE_CAMERA_TOGGLE = true;
|
||||
|
||||
/**
|
||||
* Unique Id of this manager to identify to the service
|
||||
* @hide
|
||||
@@ -58,28 +72,39 @@ public final class SensorPrivacyManager {
|
||||
public static final String EXTRA_SENSOR = SensorPrivacyManager.class.getName()
|
||||
+ ".extra.sensor";
|
||||
|
||||
/** Microphone
|
||||
* @hide */
|
||||
@TestApi
|
||||
public static final int INDIVIDUAL_SENSOR_MICROPHONE =
|
||||
SensorPrivacyIndividualEnabledSensorProto.MICROPHONE;
|
||||
|
||||
/** Camera
|
||||
* @hide */
|
||||
@TestApi
|
||||
public static final int INDIVIDUAL_SENSOR_CAMERA =
|
||||
SensorPrivacyIndividualEnabledSensorProto.CAMERA;
|
||||
|
||||
/**
|
||||
* Individual sensors not listed in {@link Sensor}
|
||||
* Individual sensors not listed in {@link Sensors}
|
||||
* @hide
|
||||
*/
|
||||
@IntDef(prefix = "INDIVIDUAL_SENSOR_", value = {
|
||||
INDIVIDUAL_SENSOR_MICROPHONE,
|
||||
INDIVIDUAL_SENSOR_CAMERA
|
||||
})
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
public @interface IndividualSensor {}
|
||||
@SystemApi
|
||||
@TestApi
|
||||
public static class Sensors {
|
||||
|
||||
private Sensors() {}
|
||||
|
||||
/** Microphone
|
||||
* @hide */
|
||||
@SystemApi
|
||||
@TestApi
|
||||
public static final int MICROPHONE = SensorPrivacyIndividualEnabledSensorProto.MICROPHONE;
|
||||
/** Camera
|
||||
* @hide */
|
||||
@SystemApi
|
||||
@TestApi
|
||||
public static final int CAMERA = SensorPrivacyIndividualEnabledSensorProto.CAMERA;
|
||||
|
||||
/**
|
||||
* Individual sensors not listed in {@link Sensors}
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
@IntDef(value = {
|
||||
MICROPHONE,
|
||||
CAMERA
|
||||
})
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
public @interface Sensor {}
|
||||
}
|
||||
|
||||
/**
|
||||
* A class implementing this interface can register with the {@link
|
||||
@@ -88,6 +113,8 @@ public final class SensorPrivacyManager {
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
@SystemApi
|
||||
@TestApi
|
||||
public interface OnSensorPrivacyChangedListener {
|
||||
/**
|
||||
* Callback invoked when the sensor privacy state changes.
|
||||
@@ -165,7 +192,8 @@ public final class SensorPrivacyManager {
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
public void addSensorPrivacyListener(final OnSensorPrivacyChangedListener listener) {
|
||||
@RequiresPermission(android.Manifest.permission.OBSERVE_SENSOR_PRIVACY)
|
||||
public void addSensorPrivacyListener(@NonNull final OnSensorPrivacyChangedListener listener) {
|
||||
synchronized (mListeners) {
|
||||
ISensorPrivacyListener iListener = mListeners.get(listener);
|
||||
if (iListener == null) {
|
||||
@@ -196,15 +224,37 @@ public final class SensorPrivacyManager {
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
public void addSensorPrivacyListener(@IndividualSensor int sensor,
|
||||
final OnSensorPrivacyChangedListener listener) {
|
||||
@SystemApi
|
||||
@TestApi
|
||||
@RequiresPermission(android.Manifest.permission.OBSERVE_SENSOR_PRIVACY)
|
||||
public void addSensorPrivacyListener(@Sensors.Sensor int sensor,
|
||||
@NonNull OnSensorPrivacyChangedListener listener) {
|
||||
addSensorPrivacyListener(sensor, mContext.getMainExecutor(), listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a new listener to receive notification when the state of sensor privacy
|
||||
* changes.
|
||||
*
|
||||
* @param sensor the sensor to listen to changes to
|
||||
* @param executor the executor to dispatch the callback on
|
||||
* @param listener the OnSensorPrivacyChangedListener to be notified when the state of sensor
|
||||
* privacy changes.
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
@SystemApi
|
||||
@TestApi
|
||||
@RequiresPermission(android.Manifest.permission.OBSERVE_SENSOR_PRIVACY)
|
||||
public void addSensorPrivacyListener(@Sensors.Sensor int sensor, @NonNull Executor executor,
|
||||
@NonNull 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);
|
||||
executor.execute(() -> listener.onSensorPrivacyChanged(enabled));
|
||||
}
|
||||
};
|
||||
mListeners.put(listener, iListener);
|
||||
@@ -228,7 +278,10 @@ public final class SensorPrivacyManager {
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
public void removeSensorPrivacyListener(OnSensorPrivacyChangedListener listener) {
|
||||
@SystemApi
|
||||
@TestApi
|
||||
@RequiresPermission(android.Manifest.permission.OBSERVE_SENSOR_PRIVACY)
|
||||
public void removeSensorPrivacyListener(@NonNull OnSensorPrivacyChangedListener listener) {
|
||||
synchronized (mListeners) {
|
||||
ISensorPrivacyListener iListener = mListeners.get(listener);
|
||||
if (iListener != null) {
|
||||
@@ -249,6 +302,7 @@ public final class SensorPrivacyManager {
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
@RequiresPermission(android.Manifest.permission.OBSERVE_SENSOR_PRIVACY)
|
||||
public boolean isSensorPrivacyEnabled() {
|
||||
try {
|
||||
return mService.isSensorPrivacyEnabled();
|
||||
@@ -264,8 +318,10 @@ public final class SensorPrivacyManager {
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
@SystemApi
|
||||
@TestApi
|
||||
public boolean isIndividualSensorPrivacyEnabled(@IndividualSensor int sensor) {
|
||||
@RequiresPermission(android.Manifest.permission.OBSERVE_SENSOR_PRIVACY)
|
||||
public boolean isSensorPrivacyEnabled(@Sensors.Sensor int sensor) {
|
||||
try {
|
||||
return mService.isIndividualSensorPrivacyEnabled(mContext.getUserId(), sensor);
|
||||
} catch (RemoteException e) {
|
||||
@@ -283,8 +339,7 @@ public final class SensorPrivacyManager {
|
||||
*/
|
||||
@TestApi
|
||||
@RequiresPermission(android.Manifest.permission.MANAGE_SENSOR_PRIVACY)
|
||||
public void setIndividualSensorPrivacy(@IndividualSensor int sensor,
|
||||
boolean enable) {
|
||||
public void setSensorPrivacy(@Sensors.Sensor int sensor, boolean enable) {
|
||||
try {
|
||||
mService.setIndividualSensorPrivacy(mContext.getUserId(), sensor, enable);
|
||||
} catch (RemoteException e) {
|
||||
@@ -303,7 +358,7 @@ public final class SensorPrivacyManager {
|
||||
*/
|
||||
@TestApi
|
||||
@RequiresPermission(android.Manifest.permission.MANAGE_SENSOR_PRIVACY)
|
||||
public void setIndividualSensorPrivacyForProfileGroup(@IndividualSensor int sensor,
|
||||
public void setSensorPrivacyForProfileGroup(@Sensors.Sensor int sensor,
|
||||
boolean enable) {
|
||||
try {
|
||||
mService.setIndividualSensorPrivacyForProfileGroup(mContext.getUserId(), sensor,
|
||||
@@ -321,7 +376,8 @@ public final class SensorPrivacyManager {
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
public void suppressIndividualSensorPrivacyReminders(@NonNull String packageName,
|
||||
@RequiresPermission(android.Manifest.permission.MANAGE_SENSOR_PRIVACY)
|
||||
public void suppressSensorPrivacyReminders(@NonNull String packageName,
|
||||
boolean suppress) {
|
||||
try {
|
||||
mService.suppressIndividualSensorPrivacyReminders(mContext.getUserId(), packageName,
|
||||
|
||||
Reference in New Issue
Block a user