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

Commit 17762821 authored by Evan Severson's avatar Evan Severson
Browse files

Unsuppress the sensor privacy dialog immediately positive action

This helps in the case that the user needs to disable privacy back to
back for both  camera and microphone. Also this is helpful for testing
so that we don't need to put a sleep between testing both variants of
the dialog.

Also put the logic for delaying the suppression with the UI since this
impacts user experience.

Test: Use GoogleCamera to get it to request mic immediately after
          allowing camera
Bug: 162549680
Change-Id: I63282f1bb5297d5134f1b993d994b5b5a703d624
parent 7e24b8be
Loading
Loading
Loading
Loading
+25 −6
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import android.hardware.SensorPrivacyManager.EXTRA_SENSOR
import android.hardware.SensorPrivacyManager.INDIVIDUAL_SENSOR_CAMERA
import android.hardware.SensorPrivacyManager.INDIVIDUAL_SENSOR_MICROPHONE
import android.os.Bundle
import android.os.Handler
import android.text.Html
import android.util.Log
import com.android.internal.app.AlertActivity
@@ -43,10 +44,13 @@ class SensorUseStartedActivity : AlertActivity(), DialogInterface.OnClickListene

    companion object {
        private val LOG_TAG = SensorUseStartedActivity::class.java.simpleName

        private const val SUPPRESS_REMINDERS_REMOVAL_DELAY_MILLIS = 2000L
    }

    private var sensor = -1
    private lateinit var sensorUsePackageName: String
    private var unsuppressImmediately = false

    private lateinit var sensorPrivacyManager: SensorPrivacyManager
    private lateinit var appOpsManager: AppOpsManager
@@ -118,6 +122,7 @@ class SensorUseStartedActivity : AlertActivity(), DialogInterface.OnClickListene
        super.onStart()

        sensorPrivacyManager.suppressIndividualSensorPrivacyReminders(sensorUsePackageName, true)
        unsuppressImmediately = false
    }

    override fun onClick(dialog: DialogInterface?, which: Int) {
@@ -131,15 +136,15 @@ class SensorUseStartedActivity : AlertActivity(), DialogInterface.OnClickListene
                        }

                        override fun onDismissSucceeded() {
                            sensorPrivacyManager
                                    .setIndividualSensorPrivacyForProfileGroup(sensor, false)
                            setResult(RESULT_OK)
                            disableSensorPrivacy()
                        }
                    })
                } else {
                    sensorPrivacyManager.setIndividualSensorPrivacyForProfileGroup(sensor, false)
                    setResult(RESULT_OK)
                    disableSensorPrivacy()
                }
            }
            BUTTON_NEGATIVE -> {
                unsuppressImmediately = false
            }
        }

@@ -149,10 +154,24 @@ class SensorUseStartedActivity : AlertActivity(), DialogInterface.OnClickListene
    override fun onStop() {
        super.onDestroy()

        sensorPrivacyManager.suppressIndividualSensorPrivacyReminders(sensorUsePackageName, false)
        if (unsuppressImmediately) {
            sensorPrivacyManager
                    .suppressIndividualSensorPrivacyReminders(sensorUsePackageName, false)
        } else {
            Handler(mainLooper).postDelayed({
                sensorPrivacyManager
                        .suppressIndividualSensorPrivacyReminders(sensorUsePackageName, false)
            }, SUPPRESS_REMINDERS_REMOVAL_DELAY_MILLIS)
        }
    }

    override fun onBackPressed() {
        // do not allow backing out
    }

    private fun disableSensorPrivacy() {
        sensorPrivacyManager.setIndividualSensorPrivacyForProfileGroup(sensor, false)
        unsuppressImmediately = true
        setResult(RESULT_OK)
    }
}
 No newline at end of file
+8 −6
Original line number Diff line number Diff line
@@ -105,8 +105,6 @@ public final class SensorPrivacyService extends SystemService {

    private static final String TAG = "SensorPrivacyService";

    private static final int SUPPRESS_REMINDERS_REMOVAL_DELAY_MILLIS = 2000;

    /** Version number indicating compatibility parsing the persisted file */
    private static final int CURRENT_PERSISTENCE_VERSION = 1;
    /** Version number indicating the persisted data needs upgraded to match new internal data
@@ -756,10 +754,7 @@ public final class SensorPrivacyService extends SystemService {

                    suppressPackageReminderTokens.add(token);
                } else {
                    mHandler.postDelayed(PooledLambda.obtainRunnable(
                            SensorPrivacyServiceImpl::removeSuppressPackageReminderToken,
                            this, key, token),
                            SUPPRESS_REMINDERS_REMOVAL_DELAY_MILLIS);
                    mHandler.removeSuppressPackageReminderToken(key, token);
                }
            }
        }
@@ -1110,6 +1105,13 @@ public final class SensorPrivacyService extends SystemService {
            }
            listeners.finishBroadcast();
        }

        public void removeSuppressPackageReminderToken(Pair<String, UserHandle> key,
                IBinder token) {
            sendMessage(PooledLambda.obtainMessage(
                    SensorPrivacyServiceImpl::removeSuppressPackageReminderToken,
                    mSensorPrivacyServiceImpl, key, token));
        }
    }

    private final class DeathRecipient implements IBinder.DeathRecipient {