Update the sensor use dialog if more sensors are accessed
If another sensor is accessed after the dialog has been shown we now
update the dialog to reflect all accessed sensors.
Test: Wrote app which opens mic/cam at different times
Fixes: 187139024
Fixes: 187132341
Change-Id: I178bb4f6ea1913e3ee0e2153cf8ac3b2f24e4623
diff --git a/core/java/android/hardware/ISensorPrivacyManager.aidl b/core/java/android/hardware/ISensorPrivacyManager.aidl
index 6105c26..debc074 100644
--- a/core/java/android/hardware/ISensorPrivacyManager.aidl
+++ b/core/java/android/hardware/ISensorPrivacyManager.aidl
@@ -46,6 +46,6 @@
void setIndividualSensorPrivacyForProfileGroup(int userId, int source, int sensor, boolean enable);
// =============== End of transactions used on native side as well ============================
- void suppressIndividualSensorPrivacyReminders(int userId, String packageName, IBinder token,
+ void suppressIndividualSensorPrivacyReminders(int userId, int sensor, IBinder token,
boolean suppress);
}
\ No newline at end of file
diff --git a/core/java/android/hardware/SensorPrivacyManager.java b/core/java/android/hardware/SensorPrivacyManager.java
index c392fbb..b7d95e7 100644
--- a/core/java/android/hardware/SensorPrivacyManager.java
+++ b/core/java/android/hardware/SensorPrivacyManager.java
@@ -461,9 +461,9 @@
* @hide
*/
@RequiresPermission(Manifest.permission.MANAGE_SENSOR_PRIVACY)
- public void suppressSensorPrivacyReminders(@NonNull String packageName,
+ public void suppressSensorPrivacyReminders(int sensor,
boolean suppress) {
- suppressSensorPrivacyReminders(packageName, suppress, mContext.getUserId());
+ suppressSensorPrivacyReminders(sensor, suppress, mContext.getUserId());
}
/**
@@ -476,10 +476,10 @@
* @hide
*/
@RequiresPermission(Manifest.permission.MANAGE_SENSOR_PRIVACY)
- public void suppressSensorPrivacyReminders(@NonNull String packageName,
+ public void suppressSensorPrivacyReminders(int sensor,
boolean suppress, @UserIdInt int userId) {
try {
- mService.suppressIndividualSensorPrivacyReminders(userId, packageName,
+ mService.suppressIndividualSensorPrivacyReminders(userId, sensor,
token, suppress);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
diff --git a/packages/SystemUI/AndroidManifest.xml b/packages/SystemUI/AndroidManifest.xml
index 8963dda..1b2aefc 100644
--- a/packages/SystemUI/AndroidManifest.xml
+++ b/packages/SystemUI/AndroidManifest.xml
@@ -451,6 +451,7 @@
<!-- started from SensoryPrivacyService -->
<activity android:name=".sensorprivacy.SensorUseStartedActivity"
android:exported="true"
+ android:launchMode="singleTop"
android:permission="android.permission.MANAGE_SENSOR_PRIVACY"
android:theme="@style/Theme.SystemUI.Dialog.Alert"
android:finishOnCloseSystemDialogs="true">
diff --git a/packages/SystemUI/src/com/android/systemui/sensorprivacy/SensorUseStartedActivity.kt b/packages/SystemUI/src/com/android/systemui/sensorprivacy/SensorUseStartedActivity.kt
index 2477534..7d0fdd6 100644
--- a/packages/SystemUI/src/com/android/systemui/sensorprivacy/SensorUseStartedActivity.kt
+++ b/packages/SystemUI/src/com/android/systemui/sensorprivacy/SensorUseStartedActivity.kt
@@ -17,6 +17,7 @@
package com.android.systemui.sensorprivacy
import android.content.DialogInterface
+import android.content.Intent
import android.content.Intent.EXTRA_PACKAGE_NAME
import android.content.pm.PackageManager
import android.content.res.Resources
@@ -174,7 +175,7 @@
override fun onStart() {
super.onStart()
- sensorPrivacyController.suppressSensorPrivacyReminders(sensorUsePackageName, true)
+ setSuppressed(true)
unsuppressImmediately = false
}
@@ -205,12 +206,10 @@
super.onStop()
if (unsuppressImmediately) {
- sensorPrivacyController
- .suppressSensorPrivacyReminders(sensorUsePackageName, false)
+ setSuppressed(false)
} else {
bgHandler.postDelayed({
- sensorPrivacyController
- .suppressSensorPrivacyReminders(sensorUsePackageName, false)
+ setSuppressed(false)
}, SUPPRESS_REMINDERS_REMOVAL_DELAY_MILLIS)
}
}
@@ -224,6 +223,11 @@
// do not allow backing out
}
+ override fun onNewIntent(intent: Intent?) {
+ setIntent(intent)
+ recreate()
+ }
+
private fun disableSensorPrivacy() {
if (sensor == ALL_SENSORS) {
sensorPrivacyController.setSensorBlocked(DIALOG, MICROPHONE, false)
@@ -234,4 +238,16 @@
unsuppressImmediately = true
setResult(RESULT_OK)
}
+
+ private fun setSuppressed(suppressed: Boolean) {
+ if (sensor == ALL_SENSORS) {
+ sensorPrivacyController
+ .suppressSensorPrivacyReminders(MICROPHONE, suppressed)
+ sensorPrivacyController
+ .suppressSensorPrivacyReminders(CAMERA, suppressed)
+ } else {
+ sensorPrivacyController
+ .suppressSensorPrivacyReminders(sensor, suppressed)
+ }
+ }
}
\ No newline at end of file
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/IndividualSensorPrivacyController.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/IndividualSensorPrivacyController.java
index acfdda4..e01b95e 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/IndividualSensorPrivacyController.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/IndividualSensorPrivacyController.java
@@ -29,7 +29,7 @@
void setSensorBlocked(@Source int source, @Sensor int sensor, boolean blocked);
- void suppressSensorPrivacyReminders(String packageName, boolean suppress);
+ void suppressSensorPrivacyReminders(int sensor, boolean suppress);
interface Callback {
void onSensorBlockedChanged(@Sensor int sensor, boolean blocked);
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/IndividualSensorPrivacyControllerImpl.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/IndividualSensorPrivacyControllerImpl.java
index 9807165..1d71301 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/IndividualSensorPrivacyControllerImpl.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/IndividualSensorPrivacyControllerImpl.java
@@ -68,8 +68,8 @@
}
@Override
- public void suppressSensorPrivacyReminders(String packageName, boolean suppress) {
- mSensorPrivacyManager.suppressSensorPrivacyReminders(packageName, suppress);
+ public void suppressSensorPrivacyReminders(int sensor, boolean suppress) {
+ mSensorPrivacyManager.suppressSensorPrivacyReminders(sensor, suppress);
}
@Override
diff --git a/services/core/java/com/android/server/SensorPrivacyService.java b/services/core/java/com/android/server/SensorPrivacyService.java
index 4f3a38b..feddc31 100644
--- a/services/core/java/com/android/server/SensorPrivacyService.java
+++ b/services/core/java/com/android/server/SensorPrivacyService.java
@@ -256,7 +256,7 @@
* <Package, User> -> list of suppressor tokens
*/
@GuardedBy("mLock")
- private ArrayMap<Pair<String, UserHandle>, ArrayList<IBinder>> mSuppressReminders =
+ private ArrayMap<Pair<Integer, UserHandle>, ArrayList<IBinder>> mSuppressReminders =
new ArrayMap<>();
private final ArrayMap<SensorUseReminderDialogInfo, ArraySet<Integer>>
@@ -391,7 +391,7 @@
}
synchronized (mLock) {
- if (mSuppressReminders.containsKey(new Pair<>(packageName, user))) {
+ if (mSuppressReminders.containsKey(new Pair<>(sensor, user))) {
Log.d(TAG,
"Suppressed sensor privacy reminder for " + packageName + "/" + user);
return;
@@ -418,14 +418,22 @@
for (int taskNum = 0; taskNum < numTasks; taskNum++) {
RunningTaskInfo task = tasks.get(taskNum);
- if (task.isVisible && task.topActivity.getPackageName().equals(packageName)) {
- if (task.isFocused) {
- // There is the one focused activity
- enqueueSensorUseReminderDialogAsync(task.taskId, user, packageName, sensor);
- return;
- }
+ if (task.isVisible) {
+ if (task.topActivity.getPackageName().equals(packageName)) {
+ if (task.isFocused) {
+ // There is the one focused activity
+ enqueueSensorUseReminderDialogAsync(task.taskId, user, packageName,
+ sensor);
+ return;
+ }
- tasksOfPackageUsingSensor.add(task);
+ tasksOfPackageUsingSensor.add(task);
+ } else if (task.topActivity.flattenToString().equals(mContext.getResources()
+ .getString(R.string.config_sensorUseStartedActivity))
+ && task.isFocused) {
+ enqueueSensorUseReminderDialogAsync(task.taskId, user, packageName,
+ sensor);
+ }
}
}
@@ -518,8 +526,15 @@
SensorUseReminderDialogInfo info =
new SensorUseReminderDialogInfo(taskId, user, packageName);
if (!mQueuedSensorUseReminderDialogs.containsKey(info)) {
- ArraySet<Integer> sensors = new ArraySet<Integer>();
- sensors.add(sensor);
+ ArraySet<Integer> sensors = new ArraySet<>();
+ if (sensor == MICROPHONE && mSuppressReminders.containsKey(new Pair<>(CAMERA, user))
+ || sensor == CAMERA && mSuppressReminders
+ .containsKey(new Pair<>(MICROPHONE, user))) {
+ sensors.add(MICROPHONE);
+ sensors.add(CAMERA);
+ } else {
+ sensors.add(sensor);
+ }
mQueuedSensorUseReminderDialogs.put(info, sensors);
mHandler.sendMessageDelayed(
PooledLambda.obtainMessage(this::showSensorUserReminderDialog, info),
@@ -1100,13 +1115,12 @@
}
@Override
- public void suppressIndividualSensorPrivacyReminders(int userId, String packageName,
+ public void suppressIndividualSensorPrivacyReminders(int userId, int sensor,
IBinder token, boolean suppress) {
enforceManageSensorPrivacyPermission();
- Objects.requireNonNull(packageName);
Objects.requireNonNull(token);
- Pair<String, UserHandle> key = new Pair<>(packageName, UserHandle.of(userId));
+ Pair<Integer, UserHandle> key = new Pair<>(sensor, UserHandle.of(userId));
synchronized (mLock) {
if (suppress) {
@@ -1136,7 +1150,7 @@
* @param key Key the token is in
* @param token The token to remove
*/
- private void removeSuppressPackageReminderToken(@NonNull Pair<String, UserHandle> key,
+ private void removeSuppressPackageReminderToken(@NonNull Pair<Integer, UserHandle> key,
@NonNull IBinder token) {
synchronized (mLock) {
ArrayList<IBinder> suppressPackageReminderTokens =
@@ -1168,7 +1182,7 @@
@Override
public void binderDied(@NonNull IBinder token) {
synchronized (mLock) {
- for (Pair<String, UserHandle> key : mSuppressReminders.keySet()) {
+ for (Pair<Integer, UserHandle> key : mSuppressReminders.keySet()) {
removeSuppressPackageReminderToken(key, token);
}
}
@@ -1495,7 +1509,7 @@
listeners.finishBroadcast();
}
- public void removeSuppressPackageReminderToken(Pair<String, UserHandle> key,
+ public void removeSuppressPackageReminderToken(Pair<Integer, UserHandle> key,
IBinder token) {
sendMessage(PooledLambda.obtainMessage(
SensorPrivacyServiceImpl::removeSuppressPackageReminderToken,