Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit caa670fa authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Disable the mic/cam toggles when admin disallows" into sc-dev

parents cf1f67e5 2a5dd0e2
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -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"
+7 −0
Original line number Diff line number Diff line
@@ -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;
    }
}
+6 −0
Original line number Diff line number Diff line
@@ -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;
    }
}
+14 −0
Original line number Diff line number Diff line
@@ -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)),