Merge "Disable the mic/cam toggles when admin disallows" into sc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
caa670fad4
@@ -64,14 +64,14 @@
|
||||
</Preference>
|
||||
|
||||
<!-- Camera toggle -->
|
||||
<SwitchPreference
|
||||
<com.android.settingslib.RestrictedSwitchPreference
|
||||
android:key="privacy_camera_toggle"
|
||||
android:title="@string/camera_toggle_title"
|
||||
android:summary="@string/sensor_toggle_description"
|
||||
settings:controller="com.android.settings.privacy.CameraToggleController"/>
|
||||
|
||||
<!-- Microphone toggle -->
|
||||
<SwitchPreference
|
||||
<com.android.settingslib.RestrictedSwitchPreference
|
||||
android:key="privacy_mic_toggle"
|
||||
android:title="@string/mic_toggle_title"
|
||||
android:summary="@string/sensor_toggle_description"
|
||||
|
@@ -16,6 +16,8 @@
|
||||
|
||||
package com.android.settings.privacy;
|
||||
|
||||
import static android.os.UserManager.DISALLOW_CAMERA_TOGGLE;
|
||||
|
||||
import static com.android.settings.utils.SensorPrivacyManagerHelper.CAMERA;
|
||||
|
||||
import android.content.Context;
|
||||
@@ -40,4 +42,9 @@ public class CameraToggleController extends SensorToggleController {
|
||||
&& DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_PRIVACY, "camera_toggle_enabled",
|
||||
true) ? AVAILABLE_UNSEARCHABLE : UNSUPPORTED_ON_DEVICE;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getRestriction() {
|
||||
return DISALLOW_CAMERA_TOGGLE;
|
||||
}
|
||||
}
|
||||
|
@@ -16,6 +16,8 @@
|
||||
|
||||
package com.android.settings.privacy;
|
||||
|
||||
import static android.os.UserManager.DISALLOW_MICROPHONE_TOGGLE;
|
||||
|
||||
import static com.android.settings.utils.SensorPrivacyManagerHelper.MICROPHONE;
|
||||
|
||||
import android.content.Context;
|
||||
@@ -41,4 +43,8 @@ public class MicToggleController extends SensorToggleController {
|
||||
true) ? AVAILABLE_UNSEARCHABLE : UNSUPPORTED_ON_DEVICE;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getRestriction() {
|
||||
return DISALLOW_MICROPHONE_TOGGLE;
|
||||
}
|
||||
}
|
||||
|
@@ -24,6 +24,8 @@ import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.core.TogglePreferenceController;
|
||||
import com.android.settings.utils.SensorPrivacyManagerHelper;
|
||||
import com.android.settingslib.RestrictedLockUtilsInternal;
|
||||
import com.android.settingslib.RestrictedSwitchPreference;
|
||||
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
@@ -46,6 +48,10 @@ public abstract class SensorToggleController extends TogglePreferenceController
|
||||
*/
|
||||
public abstract int getSensor();
|
||||
|
||||
protected String getRestriction() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isChecked() {
|
||||
return !mSensorPrivacyManagerHelper.isSensorBlocked(getSensor());
|
||||
@@ -60,6 +66,14 @@ public abstract class SensorToggleController extends TogglePreferenceController
|
||||
@Override
|
||||
public void displayPreference(PreferenceScreen screen) {
|
||||
super.displayPreference(screen);
|
||||
|
||||
RestrictedSwitchPreference preference =
|
||||
(RestrictedSwitchPreference) screen.findPreference(getPreferenceKey());
|
||||
if (preference != null) {
|
||||
preference.setDisabledByAdmin(RestrictedLockUtilsInternal
|
||||
.checkIfRestrictionEnforced(mContext, getRestriction(), mContext.getUserId()));
|
||||
}
|
||||
|
||||
mSensorPrivacyManagerHelper.addSensorBlockedListener(
|
||||
getSensor(),
|
||||
(sensor, blocked) -> updateState(screen.findPreference(mPreferenceKey)),
|
||||
|
Reference in New Issue
Block a user