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

Commit 4c588a34 authored by Nate Myren's avatar Nate Myren Committed by Automerger Merge Worker
Browse files

Merge "Correct SensorPrivacyState if needed, prevent state from going bad"...

Merge "Correct SensorPrivacyState if needed, prevent state from going bad" into udc-dev am: cc17b636 am: 317245bf

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



Change-Id: I2d5983956e4ceb98de3b9f70a90bba3e7e3b0332
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 3c9067fd 317245bf
Loading
Loading
Loading
Loading
+31 −1
Original line number Diff line number Diff line
@@ -274,13 +274,14 @@ public final class SensorPrivacyService extends SystemService {
            mHandler = new SensorPrivacyHandler(FgThread.get().getLooper(), mContext);
            mSensorPrivacyStateController = SensorPrivacyStateController.getInstance();

            correctStateIfNeeded();

            int[] micAndCameraOps = new int[]{OP_RECORD_AUDIO, OP_PHONE_CALL_MICROPHONE,
                    OP_CAMERA, OP_PHONE_CALL_CAMERA, OP_RECEIVE_EXPLICIT_USER_INTERACTION_AUDIO};
            mAppOpsManager.startWatchingNoted(micAndCameraOps, this);
            mAppOpsManager.startWatchingStarted(micAndCameraOps, this);



            mContext.registerReceiver(new BroadcastReceiver() {
                @Override
                public void onReceive(Context context, Intent intent) {
@@ -313,6 +314,20 @@ public final class SensorPrivacyService extends SystemService {
                            userId, toggleType, sensor, state.isEnabled()));
        }

        // If sensor privacy is enabled for a sensor, but the device doesn't support sensor privacy
        // for that sensor, then disable privacy
        private void correctStateIfNeeded() {
            mSensorPrivacyStateController.forEachState((type, user, sensor, state) -> {
                if (type != TOGGLE_TYPE_SOFTWARE) {
                    return;
                }
                if (!supportsSensorToggle(TOGGLE_TYPE_SOFTWARE, sensor) && state.isEnabled()) {
                    setToggleSensorPrivacyUnchecked(
                            TOGGLE_TYPE_SOFTWARE, user, OTHER, sensor, false);
                }
            });
        }

        @Override
        public void onUserRestrictionsChanged(int userId, Bundle newRestrictions,
                Bundle prevRestrictions) {
@@ -721,15 +736,30 @@ public final class SensorPrivacyService extends SystemService {
            if (userId == UserHandle.USER_CURRENT) {
                userId = mCurrentUser;
            }

            if (!canChangeToggleSensorPrivacy(userId, sensor)) {
                return;
            }
            if (enable && !supportsSensorToggle(TOGGLE_TYPE_SOFTWARE, sensor)) {
                // Do not enable sensor privacy if the device doesn't support it
                return;
            }

            setToggleSensorPrivacyUnchecked(TOGGLE_TYPE_SOFTWARE, userId, source, sensor, enable);
        }

        private void setToggleSensorPrivacyUnchecked(int toggleType, int userId, int source,
                int sensor, boolean enable) {
            if (DEBUG) {
                Log.d(TAG, "callingUid=" + Binder.getCallingUid()
                        + " callingPid=" + Binder.getCallingPid()
                        + " setToggleSensorPrivacyUnchecked("
                        + "userId=" + userId
                        + " source=" + source
                        + " sensor=" + sensor
                        + " enable=" + enable
                        + ")");
            }
            final long[] lastChange = new long[1];
            mSensorPrivacyStateController.atomic(() -> {
                SensorState sensorState = mSensorPrivacyStateController