Merge "Update the sensor use dialog if more sensors are accessed" into sc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
41ff39a156
@@ -46,6 +46,6 @@ interface ISensorPrivacyManager {
|
|||||||
void setIndividualSensorPrivacyForProfileGroup(int userId, int source, int sensor, boolean enable);
|
void setIndividualSensorPrivacyForProfileGroup(int userId, int source, int sensor, boolean enable);
|
||||||
// =============== End of transactions used on native side as well ============================
|
// =============== 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);
|
boolean suppress);
|
||||||
}
|
}
|
||||||
@@ -461,9 +461,9 @@ public final class SensorPrivacyManager {
|
|||||||
* @hide
|
* @hide
|
||||||
*/
|
*/
|
||||||
@RequiresPermission(Manifest.permission.MANAGE_SENSOR_PRIVACY)
|
@RequiresPermission(Manifest.permission.MANAGE_SENSOR_PRIVACY)
|
||||||
public void suppressSensorPrivacyReminders(@NonNull String packageName,
|
public void suppressSensorPrivacyReminders(int sensor,
|
||||||
boolean suppress) {
|
boolean suppress) {
|
||||||
suppressSensorPrivacyReminders(packageName, suppress, mContext.getUserId());
|
suppressSensorPrivacyReminders(sensor, suppress, mContext.getUserId());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -476,10 +476,10 @@ public final class SensorPrivacyManager {
|
|||||||
* @hide
|
* @hide
|
||||||
*/
|
*/
|
||||||
@RequiresPermission(Manifest.permission.MANAGE_SENSOR_PRIVACY)
|
@RequiresPermission(Manifest.permission.MANAGE_SENSOR_PRIVACY)
|
||||||
public void suppressSensorPrivacyReminders(@NonNull String packageName,
|
public void suppressSensorPrivacyReminders(int sensor,
|
||||||
boolean suppress, @UserIdInt int userId) {
|
boolean suppress, @UserIdInt int userId) {
|
||||||
try {
|
try {
|
||||||
mService.suppressIndividualSensorPrivacyReminders(userId, packageName,
|
mService.suppressIndividualSensorPrivacyReminders(userId, sensor,
|
||||||
token, suppress);
|
token, suppress);
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
throw e.rethrowFromSystemServer();
|
throw e.rethrowFromSystemServer();
|
||||||
|
|||||||
@@ -451,6 +451,7 @@
|
|||||||
<!-- started from SensoryPrivacyService -->
|
<!-- started from SensoryPrivacyService -->
|
||||||
<activity android:name=".sensorprivacy.SensorUseStartedActivity"
|
<activity android:name=".sensorprivacy.SensorUseStartedActivity"
|
||||||
android:exported="true"
|
android:exported="true"
|
||||||
|
android:launchMode="singleTop"
|
||||||
android:permission="android.permission.MANAGE_SENSOR_PRIVACY"
|
android:permission="android.permission.MANAGE_SENSOR_PRIVACY"
|
||||||
android:theme="@style/Theme.SystemUI.Dialog.Alert"
|
android:theme="@style/Theme.SystemUI.Dialog.Alert"
|
||||||
android:finishOnCloseSystemDialogs="true">
|
android:finishOnCloseSystemDialogs="true">
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
package com.android.systemui.sensorprivacy
|
package com.android.systemui.sensorprivacy
|
||||||
|
|
||||||
import android.content.DialogInterface
|
import android.content.DialogInterface
|
||||||
|
import android.content.Intent
|
||||||
import android.content.Intent.EXTRA_PACKAGE_NAME
|
import android.content.Intent.EXTRA_PACKAGE_NAME
|
||||||
import android.content.pm.PackageManager
|
import android.content.pm.PackageManager
|
||||||
import android.content.res.Resources
|
import android.content.res.Resources
|
||||||
@@ -178,7 +179,7 @@ class SensorUseStartedActivity @Inject constructor(
|
|||||||
override fun onStart() {
|
override fun onStart() {
|
||||||
super.onStart()
|
super.onStart()
|
||||||
|
|
||||||
sensorPrivacyController.suppressSensorPrivacyReminders(sensorUsePackageName, true)
|
setSuppressed(true)
|
||||||
unsuppressImmediately = false
|
unsuppressImmediately = false
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -218,12 +219,10 @@ class SensorUseStartedActivity @Inject constructor(
|
|||||||
super.onStop()
|
super.onStop()
|
||||||
|
|
||||||
if (unsuppressImmediately) {
|
if (unsuppressImmediately) {
|
||||||
sensorPrivacyController
|
setSuppressed(false)
|
||||||
.suppressSensorPrivacyReminders(sensorUsePackageName, false)
|
|
||||||
} else {
|
} else {
|
||||||
bgHandler.postDelayed({
|
bgHandler.postDelayed({
|
||||||
sensorPrivacyController
|
setSuppressed(false)
|
||||||
.suppressSensorPrivacyReminders(sensorUsePackageName, false)
|
|
||||||
}, SUPPRESS_REMINDERS_REMOVAL_DELAY_MILLIS)
|
}, SUPPRESS_REMINDERS_REMOVAL_DELAY_MILLIS)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -237,6 +236,11 @@ class SensorUseStartedActivity @Inject constructor(
|
|||||||
// do not allow backing out
|
// do not allow backing out
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onNewIntent(intent: Intent?) {
|
||||||
|
setIntent(intent)
|
||||||
|
recreate()
|
||||||
|
}
|
||||||
|
|
||||||
private fun disableSensorPrivacy() {
|
private fun disableSensorPrivacy() {
|
||||||
if (sensor == ALL_SENSORS) {
|
if (sensor == ALL_SENSORS) {
|
||||||
sensorPrivacyController.setSensorBlocked(DIALOG, MICROPHONE, false)
|
sensorPrivacyController.setSensorBlocked(DIALOG, MICROPHONE, false)
|
||||||
@@ -247,4 +251,16 @@ class SensorUseStartedActivity @Inject constructor(
|
|||||||
unsuppressImmediately = true
|
unsuppressImmediately = true
|
||||||
setResult(RESULT_OK)
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -29,7 +29,7 @@ public interface IndividualSensorPrivacyController extends
|
|||||||
|
|
||||||
void setSensorBlocked(@Source int source, @Sensor int sensor, boolean blocked);
|
void setSensorBlocked(@Source int source, @Sensor int sensor, boolean blocked);
|
||||||
|
|
||||||
void suppressSensorPrivacyReminders(String packageName, boolean suppress);
|
void suppressSensorPrivacyReminders(int sensor, boolean suppress);
|
||||||
|
|
||||||
interface Callback {
|
interface Callback {
|
||||||
void onSensorBlockedChanged(@Sensor int sensor, boolean blocked);
|
void onSensorBlockedChanged(@Sensor int sensor, boolean blocked);
|
||||||
|
|||||||
@@ -68,8 +68,8 @@ public class IndividualSensorPrivacyControllerImpl implements IndividualSensorPr
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void suppressSensorPrivacyReminders(String packageName, boolean suppress) {
|
public void suppressSensorPrivacyReminders(int sensor, boolean suppress) {
|
||||||
mSensorPrivacyManager.suppressSensorPrivacyReminders(packageName, suppress);
|
mSensorPrivacyManager.suppressSensorPrivacyReminders(sensor, suppress);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -261,7 +261,7 @@ public final class SensorPrivacyService extends SystemService {
|
|||||||
* <Package, User> -> list of suppressor tokens
|
* <Package, User> -> list of suppressor tokens
|
||||||
*/
|
*/
|
||||||
@GuardedBy("mLock")
|
@GuardedBy("mLock")
|
||||||
private ArrayMap<Pair<String, UserHandle>, ArrayList<IBinder>> mSuppressReminders =
|
private ArrayMap<Pair<Integer, UserHandle>, ArrayList<IBinder>> mSuppressReminders =
|
||||||
new ArrayMap<>();
|
new ArrayMap<>();
|
||||||
|
|
||||||
private final ArrayMap<SensorUseReminderDialogInfo, ArraySet<Integer>>
|
private final ArrayMap<SensorUseReminderDialogInfo, ArraySet<Integer>>
|
||||||
@@ -424,7 +424,7 @@ public final class SensorPrivacyService extends SystemService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
synchronized (mLock) {
|
synchronized (mLock) {
|
||||||
if (mSuppressReminders.containsKey(new Pair<>(packageName, user))) {
|
if (mSuppressReminders.containsKey(new Pair<>(sensor, user))) {
|
||||||
Log.d(TAG,
|
Log.d(TAG,
|
||||||
"Suppressed sensor privacy reminder for " + packageName + "/" + user);
|
"Suppressed sensor privacy reminder for " + packageName + "/" + user);
|
||||||
return;
|
return;
|
||||||
@@ -451,14 +451,22 @@ public final class SensorPrivacyService extends SystemService {
|
|||||||
for (int taskNum = 0; taskNum < numTasks; taskNum++) {
|
for (int taskNum = 0; taskNum < numTasks; taskNum++) {
|
||||||
RunningTaskInfo task = tasks.get(taskNum);
|
RunningTaskInfo task = tasks.get(taskNum);
|
||||||
|
|
||||||
if (task.isVisible && task.topActivity.getPackageName().equals(packageName)) {
|
if (task.isVisible) {
|
||||||
if (task.isFocused) {
|
if (task.topActivity.getPackageName().equals(packageName)) {
|
||||||
// There is the one focused activity
|
if (task.isFocused) {
|
||||||
enqueueSensorUseReminderDialogAsync(task.taskId, user, packageName, sensor);
|
// There is the one focused activity
|
||||||
return;
|
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 =
|
SensorUseReminderDialogInfo info =
|
||||||
new SensorUseReminderDialogInfo(taskId, user, packageName);
|
new SensorUseReminderDialogInfo(taskId, user, packageName);
|
||||||
if (!mQueuedSensorUseReminderDialogs.containsKey(info)) {
|
if (!mQueuedSensorUseReminderDialogs.containsKey(info)) {
|
||||||
ArraySet<Integer> sensors = new ArraySet<Integer>();
|
ArraySet<Integer> sensors = new ArraySet<>();
|
||||||
sensors.add(sensor);
|
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);
|
mQueuedSensorUseReminderDialogs.put(info, sensors);
|
||||||
mHandler.sendMessageDelayed(
|
mHandler.sendMessageDelayed(
|
||||||
PooledLambda.obtainMessage(this::showSensorUserReminderDialog, info),
|
PooledLambda.obtainMessage(this::showSensorUserReminderDialog, info),
|
||||||
@@ -1165,13 +1180,12 @@ public final class SensorPrivacyService extends SystemService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void suppressIndividualSensorPrivacyReminders(int userId, String packageName,
|
public void suppressIndividualSensorPrivacyReminders(int userId, int sensor,
|
||||||
IBinder token, boolean suppress) {
|
IBinder token, boolean suppress) {
|
||||||
enforceManageSensorPrivacyPermission();
|
enforceManageSensorPrivacyPermission();
|
||||||
Objects.requireNonNull(packageName);
|
|
||||||
Objects.requireNonNull(token);
|
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) {
|
synchronized (mLock) {
|
||||||
if (suppress) {
|
if (suppress) {
|
||||||
@@ -1201,7 +1215,7 @@ public final class SensorPrivacyService extends SystemService {
|
|||||||
* @param key Key the token is in
|
* @param key Key the token is in
|
||||||
* @param token The token to remove
|
* @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) {
|
@NonNull IBinder token) {
|
||||||
synchronized (mLock) {
|
synchronized (mLock) {
|
||||||
ArrayList<IBinder> suppressPackageReminderTokens =
|
ArrayList<IBinder> suppressPackageReminderTokens =
|
||||||
@@ -1233,7 +1247,7 @@ public final class SensorPrivacyService extends SystemService {
|
|||||||
@Override
|
@Override
|
||||||
public void binderDied(@NonNull IBinder token) {
|
public void binderDied(@NonNull IBinder token) {
|
||||||
synchronized (mLock) {
|
synchronized (mLock) {
|
||||||
for (Pair<String, UserHandle> key : mSuppressReminders.keySet()) {
|
for (Pair<Integer, UserHandle> key : mSuppressReminders.keySet()) {
|
||||||
removeSuppressPackageReminderToken(key, token);
|
removeSuppressPackageReminderToken(key, token);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1561,7 +1575,7 @@ public final class SensorPrivacyService extends SystemService {
|
|||||||
listeners.finishBroadcast();
|
listeners.finishBroadcast();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeSuppressPackageReminderToken(Pair<String, UserHandle> key,
|
public void removeSuppressPackageReminderToken(Pair<Integer, UserHandle> key,
|
||||||
IBinder token) {
|
IBinder token) {
|
||||||
sendMessage(PooledLambda.obtainMessage(
|
sendMessage(PooledLambda.obtainMessage(
|
||||||
SensorPrivacyServiceImpl::removeSuppressPackageReminderToken,
|
SensorPrivacyServiceImpl::removeSuppressPackageReminderToken,
|
||||||
|
|||||||
Reference in New Issue
Block a user