From 17762821ed32d72cad2f25e0d2070eeb5d4bfbb1 Mon Sep 17 00:00:00 2001 From: Evan Severson Date: Tue, 16 Feb 2021 15:22:05 -0800 Subject: [PATCH] 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 --- .../sensorprivacy/SensorUseStartedActivity.kt | 31 +++++++++++++++---- .../android/server/SensorPrivacyService.java | 14 +++++---- 2 files changed, 33 insertions(+), 12 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/sensorprivacy/SensorUseStartedActivity.kt b/packages/SystemUI/src/com/android/systemui/sensorprivacy/SensorUseStartedActivity.kt index d707bca0383eb..9f182e19efaf5 100644 --- a/packages/SystemUI/src/com/android/systemui/sensorprivacy/SensorUseStartedActivity.kt +++ b/packages/SystemUI/src/com/android/systemui/sensorprivacy/SensorUseStartedActivity.kt @@ -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,16 +136,16 @@ 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 + } } dismiss() @@ -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 diff --git a/services/core/java/com/android/server/SensorPrivacyService.java b/services/core/java/com/android/server/SensorPrivacyService.java index 0aee78050929e..1085a4fd1541b 100644 --- a/services/core/java/com/android/server/SensorPrivacyService.java +++ b/services/core/java/com/android/server/SensorPrivacyService.java @@ -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 key, + IBinder token) { + sendMessage(PooledLambda.obtainMessage( + SensorPrivacyServiceImpl::removeSuppressPackageReminderToken, + mSensorPrivacyServiceImpl, key, token)); + } } private final class DeathRecipient implements IBinder.DeathRecipient {