Merge "Make the authentication requirement configurable for toggles" into tm-dev

This commit is contained in:
Evan Severson
2022-05-05 16:28:13 +00:00
committed by Android (Google) Code Review
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, void suppressToggleSensorPrivacyReminders(int userId, int sensor, IBinder token,
boolean suppress); boolean suppress);
boolean requiresAuthentication();
void showSensorUseDialog(int sensor); void showSensorUseDialog(int sensor);
} }

View File

@@ -327,6 +327,8 @@ public final class SensorPrivacyManager {
@NonNull @NonNull
private boolean mToggleListenerRegistered = false; private boolean mToggleListenerRegistered = false;
private Boolean mRequiresAuthentication = null;
/** /**
* Private constructor to ensure only a single instance is created. * 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 * 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 * dialog which is shown when an application attempts to use that sensor. If privacy isn't

View File

@@ -5451,6 +5451,8 @@
<bool name="config_supportsHardwareCamToggle">false</bool> <bool name="config_supportsHardwareCamToggle">false</bool>
<!-- Whether a camera intent is launched when the lens cover is toggled --> <!-- Whether a camera intent is launched when the lens cover is toggled -->
<bool name="config_launchCameraOnCameraLensCoverToggle">true</bool> <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. --> <!-- List containing the allowed install sources for accessibility service. -->
<string-array name="config_accessibility_allowed_install_source" translatable="false"/> <string-array name="config_accessibility_allowed_install_source" translatable="false"/>

View File

@@ -4661,6 +4661,7 @@
<java-symbol type="bool" name="config_supportsHardwareMicToggle" /> <java-symbol type="bool" name="config_supportsHardwareMicToggle" />
<java-symbol type="bool" name="config_supportsHardwareCamToggle" /> <java-symbol type="bool" name="config_supportsHardwareCamToggle" />
<java-symbol type="bool" name="config_launchCameraOnCameraLensCoverToggle" /> <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_icon_size" />
<java-symbol type="dimen" name="starting_surface_default_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 @Override
protected void handleClick(@Nullable View view) { protected void handleClick(@Nullable View view) {
if (mKeyguard.isMethodSecure() && mKeyguard.isShowing()) { boolean blocked = mSensorPrivacyController.isSensorBlocked(getSensorId());
mActivityStarter.postQSRunnableDismissingKeyguard(() -> { if (mSensorPrivacyController.requiresAuthentication()
mSensorPrivacyController.setSensorBlocked(QS_TILE, getSensorId(), && mKeyguard.isMethodSecure()
!mSensorPrivacyController.isSensorBlocked(getSensorId())); && mKeyguard.isShowing()) {
}); mActivityStarter.postQSRunnableDismissingKeyguard(() ->
mSensorPrivacyController.setSensorBlocked(QS_TILE, getSensorId(), !blocked));
return; return;
} }
mSensorPrivacyController.setSensorBlocked(QS_TILE, getSensorId(), mSensorPrivacyController.setSensorBlocked(QS_TILE, getSensorId(), !blocked);
!mSensorPrivacyController.isSensorBlocked(getSensorId()));
} }
@Override @Override

View File

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

View File

@@ -37,6 +37,11 @@ public interface IndividualSensorPrivacyController extends
void suppressSensorPrivacyReminders(int sensor, boolean suppress); void suppressSensorPrivacyReminders(int sensor, boolean suppress);
/**
* @return whether lock screen authentication is required to change the toggle state
*/
boolean requiresAuthentication();
interface Callback { interface Callback {
void onSensorBlockedChanged(@Sensor int sensor, boolean blocked); 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 @NonNull SensorPrivacyManager mSensorPrivacyManager;
private final SparseBooleanArray mSoftwareToggleState = new SparseBooleanArray(); private final SparseBooleanArray mSoftwareToggleState = new SparseBooleanArray();
private final SparseBooleanArray mHardwareToggleState = new SparseBooleanArray(); private final SparseBooleanArray mHardwareToggleState = new SparseBooleanArray();
private Boolean mRequiresAuthentication;
private final Set<Callback> mCallbacks = new ArraySet<>(); private final Set<Callback> mCallbacks = new ArraySet<>();
public IndividualSensorPrivacyControllerImpl( public IndividualSensorPrivacyControllerImpl(
@@ -95,6 +96,11 @@ public class IndividualSensorPrivacyControllerImpl implements IndividualSensorPr
mSensorPrivacyManager.suppressSensorPrivacyReminders(sensor, suppress); mSensorPrivacyManager.suppressSensorPrivacyReminders(sensor, suppress);
} }
@Override
public boolean requiresAuthentication() {
return mSensorPrivacyManager.requiresAuthentication();
}
@Override @Override
public void addCallback(@NonNull Callback listener) { public void addCallback(@NonNull Callback listener) {
mCallbacks.add(listener); mCallbacks.add(listener);

View File

@@ -727,7 +727,8 @@ public final class SensorPrivacyService extends SystemService {
return false; 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"); Log.i(TAG, "Can't change mic/cam toggle while device is locked");
return false; 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 @Override
public void showSensorUseDialog(int sensor) { public void showSensorUseDialog(int sensor) {
if (Binder.getCallingUid() != Process.SYSTEM_UID) { if (Binder.getCallingUid() != Process.SYSTEM_UID) {