Make the authentication requirement configurable for toggles
Test: Manual && CtsSensorPrivacyTestCases Fixes: 227517111 Change-Id: Id7ee5d8ca9ee264c18d2f7e1975e0d4fcb6210ab
This commit is contained in:
@@ -50,5 +50,7 @@ interface ISensorPrivacyManager {
|
||||
void suppressToggleSensorPrivacyReminders(int userId, int sensor, IBinder token,
|
||||
boolean suppress);
|
||||
|
||||
boolean requiresAuthentication();
|
||||
|
||||
void showSensorUseDialog(int sensor);
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -5444,6 +5444,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"/>
|
||||
|
||||
@@ -4662,6 +4662,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" />
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user