Merge "Make the authentication requirement configurable for toggles" into tm-dev am: 7935bf8b27 am: 2f067d2f62

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/17769812

Change-Id: I6b5deca27bc01816cc6e09a164a3440b01394c29
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Evan Severson
2022-05-06 15:43:48 +00:00
committed by Automerger Merge Worker
9 changed files with 54 additions and 9 deletions

View File

@@ -50,5 +50,7 @@ interface ISensorPrivacyManager {
void suppressToggleSensorPrivacyReminders(int userId, int sensor, IBinder token,
boolean suppress);
boolean requiresAuthentication();
void showSensorUseDialog(int sensor);
}

View File

@@ -327,6 +327,8 @@ public final class SensorPrivacyManager {
@NonNull
private boolean mToggleListenerRegistered = false;
private Boolean mRequiresAuthentication = null;
/**
* Private constructor to ensure only a single instance is created.
*/
@@ -760,6 +762,23 @@ public final class SensorPrivacyManager {
}
}
/**
* @return whether the device is required to be unlocked to change software state.
*
* @hide
*/
@RequiresPermission(Manifest.permission.OBSERVE_SENSOR_PRIVACY)
public boolean requiresAuthentication() {
if (mRequiresAuthentication == null) {
try {
mRequiresAuthentication = mService.requiresAuthentication();
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
return mRequiresAuthentication;
}
/**
* If sensor privacy for the provided sensor is enabled then this call will show the user the
* dialog which is shown when an application attempts to use that sensor. If privacy isn't

View File

@@ -5454,6 +5454,8 @@
<bool name="config_supportsHardwareCamToggle">false</bool>
<!-- Whether a camera intent is launched when the lens cover is toggled -->
<bool name="config_launchCameraOnCameraLensCoverToggle">true</bool>
<!-- Whether changing sensor privacy SW setting requires device to be unlocked -->
<bool name="config_sensorPrivacyRequiresAuthentication">true</bool>
<!-- List containing the allowed install sources for accessibility service. -->
<string-array name="config_accessibility_allowed_install_source" translatable="false"/>

View File

@@ -4667,6 +4667,7 @@
<java-symbol type="bool" name="config_supportsHardwareMicToggle" />
<java-symbol type="bool" name="config_supportsHardwareCamToggle" />
<java-symbol type="bool" name="config_launchCameraOnCameraLensCoverToggle" />
<java-symbol type="bool" name="config_sensorPrivacyRequiresAuthentication" />
<java-symbol type="dimen" name="starting_surface_icon_size" />
<java-symbol type="dimen" name="starting_surface_default_icon_size" />

View File

@@ -92,15 +92,15 @@ public abstract class SensorPrivacyToggleTile extends QSTileImpl<QSTile.BooleanS
@Override
protected void handleClick(@Nullable View view) {
if (mKeyguard.isMethodSecure() && mKeyguard.isShowing()) {
mActivityStarter.postQSRunnableDismissingKeyguard(() -> {
mSensorPrivacyController.setSensorBlocked(QS_TILE, getSensorId(),
!mSensorPrivacyController.isSensorBlocked(getSensorId()));
});
boolean blocked = mSensorPrivacyController.isSensorBlocked(getSensorId());
if (mSensorPrivacyController.requiresAuthentication()
&& mKeyguard.isMethodSecure()
&& mKeyguard.isShowing()) {
mActivityStarter.postQSRunnableDismissingKeyguard(() ->
mSensorPrivacyController.setSensorBlocked(QS_TILE, getSensorId(), !blocked));
return;
}
mSensorPrivacyController.setSensorBlocked(QS_TILE, getSensorId(),
!mSensorPrivacyController.isSensorBlocked(getSensorId()));
mSensorPrivacyController.setSensorBlocked(QS_TILE, getSensorId(), !blocked);
}
@Override

View File

@@ -134,7 +134,9 @@ class SensorUseStartedActivity @Inject constructor(
override fun onClick(dialog: DialogInterface?, which: Int) {
when (which) {
BUTTON_POSITIVE -> {
if (keyguardStateController.isMethodSecure && keyguardStateController.isShowing) {
if (sensorPrivacyController.requiresAuthentication() &&
keyguardStateController.isMethodSecure &&
keyguardStateController.isShowing) {
keyguardDismissUtil.executeWhenUnlocked({
bgHandler.postDelayed({
disableSensorPrivacy()

View File

@@ -37,6 +37,11 @@ public interface IndividualSensorPrivacyController extends
void suppressSensorPrivacyReminders(int sensor, boolean suppress);
/**
* @return whether lock screen authentication is required to change the toggle state
*/
boolean requiresAuthentication();
interface Callback {
void onSensorBlockedChanged(@Sensor int sensor, boolean blocked);
}

View File

@@ -37,6 +37,7 @@ public class IndividualSensorPrivacyControllerImpl implements IndividualSensorPr
private final @NonNull SensorPrivacyManager mSensorPrivacyManager;
private final SparseBooleanArray mSoftwareToggleState = new SparseBooleanArray();
private final SparseBooleanArray mHardwareToggleState = new SparseBooleanArray();
private Boolean mRequiresAuthentication;
private final Set<Callback> mCallbacks = new ArraySet<>();
public IndividualSensorPrivacyControllerImpl(
@@ -95,6 +96,11 @@ public class IndividualSensorPrivacyControllerImpl implements IndividualSensorPr
mSensorPrivacyManager.suppressSensorPrivacyReminders(sensor, suppress);
}
@Override
public boolean requiresAuthentication() {
return mSensorPrivacyManager.requiresAuthentication();
}
@Override
public void addCallback(@NonNull Callback listener) {
mCallbacks.add(listener);

View File

@@ -727,7 +727,8 @@ public final class SensorPrivacyService extends SystemService {
return false;
}
if (mKeyguardManager != null && mKeyguardManager.isDeviceLocked(userId)) {
if (requiresAuthentication() && mKeyguardManager != null
&& mKeyguardManager.isDeviceLocked(userId)) {
Log.i(TAG, "Can't change mic/cam toggle while device is locked");
return false;
}
@@ -992,6 +993,13 @@ public final class SensorPrivacyService extends SystemService {
}
}
@Override
public boolean requiresAuthentication() {
enforceObserveSensorPrivacyPermission();
return mContext.getResources()
.getBoolean(R.bool.config_sensorPrivacyRequiresAuthentication);
}
@Override
public void showSensorUseDialog(int sensor) {
if (Binder.getCallingUid() != Process.SYSTEM_UID) {