diff --git a/core/java/android/hardware/ISensorPrivacyManager.aidl b/core/java/android/hardware/ISensorPrivacyManager.aidl index 6105c26dc651e..debc074ea21a3 100644 --- a/core/java/android/hardware/ISensorPrivacyManager.aidl +++ b/core/java/android/hardware/ISensorPrivacyManager.aidl @@ -46,6 +46,6 @@ interface ISensorPrivacyManager { 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 c392fbb52de0b..b7d95e7dea745 100644 --- a/core/java/android/hardware/SensorPrivacyManager.java +++ b/core/java/android/hardware/SensorPrivacyManager.java @@ -461,9 +461,9 @@ public final class SensorPrivacyManager { * @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 @@ public final class SensorPrivacyManager { * @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 8963ddaece35f..1b2aefcd6ff0c 100644 --- a/packages/SystemUI/AndroidManifest.xml +++ b/packages/SystemUI/AndroidManifest.xml @@ -451,6 +451,7 @@ diff --git a/packages/SystemUI/src/com/android/systemui/sensorprivacy/SensorUseStartedActivity.kt b/packages/SystemUI/src/com/android/systemui/sensorprivacy/SensorUseStartedActivity.kt index ef18df5706ad0..f0fb5ebf9e1d3 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 @@ -178,7 +179,7 @@ class SensorUseStartedActivity @Inject constructor( override fun onStart() { super.onStart() - sensorPrivacyController.suppressSensorPrivacyReminders(sensorUsePackageName, true) + setSuppressed(true) unsuppressImmediately = false } @@ -218,12 +219,10 @@ class SensorUseStartedActivity @Inject constructor( super.onStop() if (unsuppressImmediately) { - sensorPrivacyController - .suppressSensorPrivacyReminders(sensorUsePackageName, false) + setSuppressed(false) } else { bgHandler.postDelayed({ - sensorPrivacyController - .suppressSensorPrivacyReminders(sensorUsePackageName, false) + setSuppressed(false) }, SUPPRESS_REMINDERS_REMOVAL_DELAY_MILLIS) } } @@ -237,6 +236,11 @@ class SensorUseStartedActivity @Inject constructor( // 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) @@ -247,4 +251,16 @@ class SensorUseStartedActivity @Inject constructor( 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 acfdda4cea491..e01b95e81da87 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 @@ public interface IndividualSensorPrivacyController extends 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 9807165f69d01..1d71301c74545 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 @@ public class IndividualSensorPrivacyControllerImpl implements IndividualSensorPr } @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 f06b4674feb13..ac43fbd4f976b 100644 --- a/services/core/java/com/android/server/SensorPrivacyService.java +++ b/services/core/java/com/android/server/SensorPrivacyService.java @@ -261,7 +261,7 @@ public final class SensorPrivacyService extends SystemService { * -> list of suppressor tokens */ @GuardedBy("mLock") - private ArrayMap, ArrayList> mSuppressReminders = + private ArrayMap, ArrayList> mSuppressReminders = new ArrayMap<>(); private final ArrayMap> @@ -424,7 +424,7 @@ public final class SensorPrivacyService extends SystemService { } 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; @@ -451,14 +451,22 @@ public final class SensorPrivacyService extends SystemService { 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); + } } } @@ -551,8 +559,15 @@ public final class SensorPrivacyService extends SystemService { SensorUseReminderDialogInfo info = new SensorUseReminderDialogInfo(taskId, user, packageName); if (!mQueuedSensorUseReminderDialogs.containsKey(info)) { - ArraySet sensors = new ArraySet(); - sensors.add(sensor); + ArraySet 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), @@ -1165,13 +1180,12 @@ public final class SensorPrivacyService extends SystemService { } @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 key = new Pair<>(packageName, UserHandle.of(userId)); + Pair key = new Pair<>(sensor, UserHandle.of(userId)); synchronized (mLock) { if (suppress) { @@ -1201,7 +1215,7 @@ public final class SensorPrivacyService extends SystemService { * @param key Key the token is in * @param token The token to remove */ - private void removeSuppressPackageReminderToken(@NonNull Pair key, + private void removeSuppressPackageReminderToken(@NonNull Pair key, @NonNull IBinder token) { synchronized (mLock) { ArrayList suppressPackageReminderTokens = @@ -1233,7 +1247,7 @@ public final class SensorPrivacyService extends SystemService { @Override public void binderDied(@NonNull IBinder token) { synchronized (mLock) { - for (Pair key : mSuppressReminders.keySet()) { + for (Pair key : mSuppressReminders.keySet()) { removeSuppressPackageReminderToken(key, token); } } @@ -1561,7 +1575,7 @@ public final class SensorPrivacyService extends SystemService { listeners.finishBroadcast(); } - public void removeSuppressPackageReminderToken(Pair key, + public void removeSuppressPackageReminderToken(Pair key, IBinder token) { sendMessage(PooledLambda.obtainMessage( SensorPrivacyServiceImpl::removeSuppressPackageReminderToken,