Don't show sensor use dialog for system uid

If the system uid is being noted for mic or camera op, it will have to
be explicitely accounted for to show the user any sort of UI to unmute
the mic or camera.

Test: Add some logcat statements to verify the correct code paths are
          being hit when placing and answering phone calls and when
	  trying to trigger hotword.
Bug: 195122900
Change-Id: I601458ea2dd7557e4a557eab32c2da15828ae4a7
This commit is contained in:
Evan Severson
2021-08-03 16:58:40 -07:00
parent 308cc9919e
commit f1de4ee934
3 changed files with 42 additions and 5 deletions

View File

@@ -52,4 +52,6 @@ interface ISensorPrivacyManager {
void addUserGlobalIndividualSensorPrivacyListener(int sensor, in ISensorPrivacyListener listener);
void removeUserGlobalIndividualSensorPrivacyListener(int sensor, in ISensorPrivacyListener listener);
void showSensorUseDialog(int sensor);
}

View File

@@ -33,6 +33,7 @@ import android.os.UserHandle;
import android.service.SensorPrivacyIndividualEnabledSensorProto;
import android.service.SensorPrivacyToggleSourceProto;
import android.util.ArrayMap;
import android.util.Log;
import android.util.Pair;
import android.util.SparseArray;
@@ -48,6 +49,8 @@ import java.util.concurrent.Executor;
@SystemService(Context.SENSOR_PRIVACY_SERVICE)
public final class SensorPrivacyManager {
private static final String LOG_TAG = SensorPrivacyManager.class.getSimpleName();
/**
* Unique Id of this manager to identify to the service
* @hide
@@ -504,6 +507,25 @@ public final class SensorPrivacyManager {
}
}
/**
* If sensor privacy for the provided sensor is enabled then this call will show the user the
* dialog which is shown when an application attempts to use that sensor. If privacy isn't
* enabled then this does nothing.
*
* This call can only be made by the system uid.
*
* @throws SecurityException when called by someone other than system uid.
*
* @hide
*/
public void showSensorUseDialog(int sensor) {
try {
mService.showSensorUseDialog(sensor);
} catch (RemoteException e) {
Log.e(LOG_TAG, "Received exception while trying to show sensor use dialog", e);
}
}
/**
* A class implementing this interface can register with the {@link
* android.hardware.SensorPrivacyManager} to receive notification when the all-sensor privacy

View File

@@ -413,6 +413,12 @@ public final class SensorPrivacyService extends SystemService {
return;
}
if (uid == Process.SYSTEM_UID) {
// If the system uid is being blamed for sensor access, the ui must be shown
// explicitly using SensorPrivacyManager#showSensorUseDialog
return;
}
synchronized (mLock) {
if (mSuppressReminders.containsKey(new Pair<>(sensor, user))) {
Log.d(TAG,
@@ -421,11 +427,6 @@ public final class SensorPrivacyService extends SystemService {
}
}
if (uid == Process.SYSTEM_UID) {
enqueueSensorUseReminderDialogAsync(-1, user, packageName, sensor);
return;
}
// TODO: Handle reminders with multiple sensors
// - If we have a likely activity that triggered the sensor use overlay a dialog over
@@ -1241,6 +1242,18 @@ public final class SensorPrivacyService extends SystemService {
}
}
@Override
public void showSensorUseDialog(int sensor) {
if (Binder.getCallingUid() != Process.SYSTEM_UID) {
throw new SecurityException("Can only be called by the system uid");
}
if (!isIndividualSensorPrivacyEnabled(mCurrentUser, sensor)) {
return;
}
enqueueSensorUseReminderDialogAsync(
-1, UserHandle.of(mCurrentUser), "android", sensor);
}
private void userSwitching(int from, int to) {
boolean micState;
boolean camState;