Merge "Check the current user in the system server for SensorPrivacyManager" into sc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
705c7539eb
@@ -24,12 +24,12 @@ import android.annotation.SystemApi;
|
|||||||
import android.annotation.SystemService;
|
import android.annotation.SystemService;
|
||||||
import android.annotation.TestApi;
|
import android.annotation.TestApi;
|
||||||
import android.annotation.UserIdInt;
|
import android.annotation.UserIdInt;
|
||||||
import android.app.ActivityManager;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.Binder;
|
import android.os.Binder;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
import android.os.ServiceManager;
|
import android.os.ServiceManager;
|
||||||
|
import android.os.UserHandle;
|
||||||
import android.service.SensorPrivacyIndividualEnabledSensorProto;
|
import android.service.SensorPrivacyIndividualEnabledSensorProto;
|
||||||
import android.service.SensorPrivacyToggleSourceProto;
|
import android.service.SensorPrivacyToggleSourceProto;
|
||||||
import android.util.ArrayMap;
|
import android.util.ArrayMap;
|
||||||
@@ -379,7 +379,7 @@ public final class SensorPrivacyManager {
|
|||||||
@SystemApi
|
@SystemApi
|
||||||
@RequiresPermission(Manifest.permission.OBSERVE_SENSOR_PRIVACY)
|
@RequiresPermission(Manifest.permission.OBSERVE_SENSOR_PRIVACY)
|
||||||
public boolean isSensorPrivacyEnabled(@Sensors.Sensor int sensor) {
|
public boolean isSensorPrivacyEnabled(@Sensors.Sensor int sensor) {
|
||||||
return isSensorPrivacyEnabled(sensor, getCurrentUserId());
|
return isSensorPrivacyEnabled(sensor, UserHandle.USER_CURRENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -410,7 +410,7 @@ public final class SensorPrivacyManager {
|
|||||||
@RequiresPermission(Manifest.permission.MANAGE_SENSOR_PRIVACY)
|
@RequiresPermission(Manifest.permission.MANAGE_SENSOR_PRIVACY)
|
||||||
public void setSensorPrivacy(@Sources.Source int source, @Sensors.Sensor int sensor,
|
public void setSensorPrivacy(@Sources.Source int source, @Sensors.Sensor int sensor,
|
||||||
boolean enable) {
|
boolean enable) {
|
||||||
setSensorPrivacy(source, sensor, enable, getCurrentUserId());
|
setSensorPrivacy(source, sensor, enable, UserHandle.USER_CURRENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -446,7 +446,7 @@ public final class SensorPrivacyManager {
|
|||||||
@RequiresPermission(Manifest.permission.MANAGE_SENSOR_PRIVACY)
|
@RequiresPermission(Manifest.permission.MANAGE_SENSOR_PRIVACY)
|
||||||
public void setSensorPrivacyForProfileGroup(@Sources.Source int source,
|
public void setSensorPrivacyForProfileGroup(@Sources.Source int source,
|
||||||
@Sensors.Sensor int sensor, boolean enable) {
|
@Sensors.Sensor int sensor, boolean enable) {
|
||||||
setSensorPrivacyForProfileGroup(source , sensor, enable, getCurrentUserId());
|
setSensorPrivacyForProfileGroup(source , sensor, enable, UserHandle.USER_CURRENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -481,7 +481,7 @@ public final class SensorPrivacyManager {
|
|||||||
@RequiresPermission(Manifest.permission.MANAGE_SENSOR_PRIVACY)
|
@RequiresPermission(Manifest.permission.MANAGE_SENSOR_PRIVACY)
|
||||||
public void suppressSensorPrivacyReminders(int sensor,
|
public void suppressSensorPrivacyReminders(int sensor,
|
||||||
boolean suppress) {
|
boolean suppress) {
|
||||||
suppressSensorPrivacyReminders(sensor, suppress, getCurrentUserId());
|
suppressSensorPrivacyReminders(sensor, suppress, UserHandle.USER_CURRENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -609,12 +609,4 @@ public final class SensorPrivacyManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getCurrentUserId() {
|
|
||||||
try {
|
|
||||||
return ActivityManager.getService().getCurrentUserId();
|
|
||||||
} catch (RemoteException e) {
|
|
||||||
e.rethrowFromSystemServer();
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,7 +21,6 @@ import static android.app.ActivityManager.PROCESS_CAPABILITY_FOREGROUND_CAMERA;
|
|||||||
import static android.app.ActivityManager.PROCESS_CAPABILITY_FOREGROUND_MICROPHONE;
|
import static android.app.ActivityManager.PROCESS_CAPABILITY_FOREGROUND_MICROPHONE;
|
||||||
import static android.app.ActivityManager.RunningServiceInfo;
|
import static android.app.ActivityManager.RunningServiceInfo;
|
||||||
import static android.app.ActivityManager.RunningTaskInfo;
|
import static android.app.ActivityManager.RunningTaskInfo;
|
||||||
import static android.app.ActivityManager.getCurrentUser;
|
|
||||||
import static android.app.AppOpsManager.MODE_ALLOWED;
|
import static android.app.AppOpsManager.MODE_ALLOWED;
|
||||||
import static android.app.AppOpsManager.MODE_IGNORED;
|
import static android.app.AppOpsManager.MODE_IGNORED;
|
||||||
import static android.app.AppOpsManager.OP_CAMERA;
|
import static android.app.AppOpsManager.OP_CAMERA;
|
||||||
@@ -718,6 +717,9 @@ public final class SensorPrivacyService extends SystemService {
|
|||||||
public void setIndividualSensorPrivacy(@UserIdInt int userId,
|
public void setIndividualSensorPrivacy(@UserIdInt int userId,
|
||||||
@SensorPrivacyManager.Sources.Source int source, int sensor, boolean enable) {
|
@SensorPrivacyManager.Sources.Source int source, int sensor, boolean enable) {
|
||||||
enforceManageSensorPrivacyPermission();
|
enforceManageSensorPrivacyPermission();
|
||||||
|
if (userId == UserHandle.USER_CURRENT) {
|
||||||
|
userId = mCurrentUser;
|
||||||
|
}
|
||||||
if (!canChangeIndividualSensorPrivacy(userId, sensor)) {
|
if (!canChangeIndividualSensorPrivacy(userId, sensor)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -843,6 +845,9 @@ public final class SensorPrivacyService extends SystemService {
|
|||||||
public void setIndividualSensorPrivacyForProfileGroup(@UserIdInt int userId,
|
public void setIndividualSensorPrivacyForProfileGroup(@UserIdInt int userId,
|
||||||
@SensorPrivacyManager.Sources.Source int source, int sensor, boolean enable) {
|
@SensorPrivacyManager.Sources.Source int source, int sensor, boolean enable) {
|
||||||
enforceManageSensorPrivacyPermission();
|
enforceManageSensorPrivacyPermission();
|
||||||
|
if (userId == UserHandle.USER_CURRENT) {
|
||||||
|
userId = mCurrentUser;
|
||||||
|
}
|
||||||
int parentId = mUserManagerInternal.getProfileParentId(userId);
|
int parentId = mUserManagerInternal.getProfileParentId(userId);
|
||||||
forAllUsers(userId2 -> {
|
forAllUsers(userId2 -> {
|
||||||
if (parentId == mUserManagerInternal.getProfileParentId(userId2)) {
|
if (parentId == mUserManagerInternal.getProfileParentId(userId2)) {
|
||||||
@@ -896,6 +901,9 @@ public final class SensorPrivacyService extends SystemService {
|
|||||||
@Override
|
@Override
|
||||||
public boolean isIndividualSensorPrivacyEnabled(@UserIdInt int userId, int sensor) {
|
public boolean isIndividualSensorPrivacyEnabled(@UserIdInt int userId, int sensor) {
|
||||||
enforceObserveSensorPrivacyPermission();
|
enforceObserveSensorPrivacyPermission();
|
||||||
|
if (userId == UserHandle.USER_CURRENT) {
|
||||||
|
userId = mCurrentUser;
|
||||||
|
}
|
||||||
synchronized (mLock) {
|
synchronized (mLock) {
|
||||||
return isIndividualSensorPrivacyEnabledLocked(userId, sensor);
|
return isIndividualSensorPrivacyEnabledLocked(userId, sensor);
|
||||||
}
|
}
|
||||||
@@ -1213,6 +1221,9 @@ public final class SensorPrivacyService extends SystemService {
|
|||||||
public void suppressIndividualSensorPrivacyReminders(int userId, int sensor,
|
public void suppressIndividualSensorPrivacyReminders(int userId, int sensor,
|
||||||
IBinder token, boolean suppress) {
|
IBinder token, boolean suppress) {
|
||||||
enforceManageSensorPrivacyPermission();
|
enforceManageSensorPrivacyPermission();
|
||||||
|
if (userId == UserHandle.USER_CURRENT) {
|
||||||
|
userId = mCurrentUser;
|
||||||
|
}
|
||||||
Objects.requireNonNull(token);
|
Objects.requireNonNull(token);
|
||||||
|
|
||||||
Pair<Integer, UserHandle> key = new Pair<>(sensor, UserHandle.of(userId));
|
Pair<Integer, UserHandle> key = new Pair<>(sensor, UserHandle.of(userId));
|
||||||
@@ -1898,9 +1909,9 @@ public final class SensorPrivacyService extends SystemService {
|
|||||||
if (!mIsInEmergencyCall) {
|
if (!mIsInEmergencyCall) {
|
||||||
mIsInEmergencyCall = true;
|
mIsInEmergencyCall = true;
|
||||||
if (mSensorPrivacyServiceImpl
|
if (mSensorPrivacyServiceImpl
|
||||||
.isIndividualSensorPrivacyEnabled(getCurrentUser(), MICROPHONE)) {
|
.isIndividualSensorPrivacyEnabled(mCurrentUser, MICROPHONE)) {
|
||||||
mSensorPrivacyServiceImpl.setIndividualSensorPrivacyUnchecked(
|
mSensorPrivacyServiceImpl.setIndividualSensorPrivacyUnchecked(
|
||||||
getCurrentUser(), OTHER, MICROPHONE, false);
|
mCurrentUser, OTHER, MICROPHONE, false);
|
||||||
mMicUnmutedForEmergencyCall = true;
|
mMicUnmutedForEmergencyCall = true;
|
||||||
} else {
|
} else {
|
||||||
mMicUnmutedForEmergencyCall = false;
|
mMicUnmutedForEmergencyCall = false;
|
||||||
@@ -1915,7 +1926,7 @@ public final class SensorPrivacyService extends SystemService {
|
|||||||
mIsInEmergencyCall = false;
|
mIsInEmergencyCall = false;
|
||||||
if (mMicUnmutedForEmergencyCall) {
|
if (mMicUnmutedForEmergencyCall) {
|
||||||
mSensorPrivacyServiceImpl.setIndividualSensorPrivacyUnchecked(
|
mSensorPrivacyServiceImpl.setIndividualSensorPrivacyUnchecked(
|
||||||
getCurrentUser(), OTHER, MICROPHONE, true);
|
mCurrentUser, OTHER, MICROPHONE, true);
|
||||||
mMicUnmutedForEmergencyCall = false;
|
mMicUnmutedForEmergencyCall = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user