Merge "Fix boot loop when upgrading sensor privacy file" into sc-dev am: 66d5c60581 am: 3e7436fc30
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/15529225 Change-Id: Ib88fdf8b520fee89c7564a9b2775129a3602d734
This commit is contained in:
@@ -1021,7 +1021,15 @@ public final class SensorPrivacyService extends SystemService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return upgradeAndInit(version, map);
|
try {
|
||||||
|
return upgradeAndInit(version, map);
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.wtf(TAG, "Failed to upgrade and set sensor privacy state,"
|
||||||
|
+ " resetting to default.", e);
|
||||||
|
mEnabled = new SparseBooleanArray();
|
||||||
|
mIndividualEnabled = new SparseArray<>();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean upgradeAndInit(int version, SparseArray map) {
|
private boolean upgradeAndInit(int version, SparseArray map) {
|
||||||
@@ -1037,22 +1045,22 @@ public final class SensorPrivacyService extends SystemService {
|
|||||||
final int[] users = getLocalService(UserManagerInternal.class).getUserIds();
|
final int[] users = getLocalService(UserManagerInternal.class).getUserIds();
|
||||||
if (version == 0) {
|
if (version == 0) {
|
||||||
final boolean enabled = (boolean) map.get(VER0_ENABLED);
|
final boolean enabled = (boolean) map.get(VER0_ENABLED);
|
||||||
final SparseBooleanArray individualEnabled =
|
final SparseArray<SensorState> individualEnabled =
|
||||||
(SparseBooleanArray) map.get(VER0_INDIVIDUAL_ENABLED);
|
(SparseArray<SensorState>) map.get(VER0_INDIVIDUAL_ENABLED);
|
||||||
|
|
||||||
final SparseBooleanArray perUserEnabled = new SparseBooleanArray();
|
final SparseBooleanArray perUserEnabled = new SparseBooleanArray();
|
||||||
final SparseArray<SparseBooleanArray> perUserIndividualEnabled =
|
final SparseArray<SparseArray<SensorState>> perUserIndividualEnabled =
|
||||||
new SparseArray<>();
|
new SparseArray<>();
|
||||||
|
|
||||||
// Copy global state to each user
|
// Copy global state to each user
|
||||||
for (int i = 0; i < users.length; i++) {
|
for (int i = 0; i < users.length; i++) {
|
||||||
int user = users[i];
|
int user = users[i];
|
||||||
perUserEnabled.put(user, enabled);
|
perUserEnabled.put(user, enabled);
|
||||||
SparseBooleanArray userIndividualSensorEnabled = new SparseBooleanArray();
|
SparseArray<SensorState> userIndividualSensorEnabled = new SparseArray<>();
|
||||||
perUserIndividualEnabled.put(user, userIndividualSensorEnabled);
|
perUserIndividualEnabled.put(user, userIndividualSensorEnabled);
|
||||||
for (int j = 0; j < individualEnabled.size(); j++) {
|
for (int j = 0; j < individualEnabled.size(); j++) {
|
||||||
final int sensor = individualEnabled.keyAt(j);
|
final int sensor = individualEnabled.keyAt(j);
|
||||||
final boolean isSensorEnabled = individualEnabled.valueAt(j);
|
final SensorState isSensorEnabled = individualEnabled.valueAt(j);
|
||||||
userIndividualSensorEnabled.put(sensor, isSensorEnabled);
|
userIndividualSensorEnabled.put(sensor, isSensorEnabled);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
<?xml version='1.0' encoding='UTF-8' standalone='yes' ?>
|
||||||
|
<sensor-privacy enabled="false">
|
||||||
|
</sensor-privacy>
|
||||||
@@ -60,6 +60,8 @@ public class SensorPrivacyServiceMockingTest {
|
|||||||
String.format(PERSISTENCE_FILE_PATHS_TEMPLATE, 4);
|
String.format(PERSISTENCE_FILE_PATHS_TEMPLATE, 4);
|
||||||
public static final String PERSISTENCE_FILE5 =
|
public static final String PERSISTENCE_FILE5 =
|
||||||
String.format(PERSISTENCE_FILE_PATHS_TEMPLATE, 5);
|
String.format(PERSISTENCE_FILE_PATHS_TEMPLATE, 5);
|
||||||
|
public static final String PERSISTENCE_FILE6 =
|
||||||
|
String.format(PERSISTENCE_FILE_PATHS_TEMPLATE, 6);
|
||||||
|
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
@Mock
|
@Mock
|
||||||
@@ -111,6 +113,7 @@ public class SensorPrivacyServiceMockingTest {
|
|||||||
initServiceWithPersistenceFile(onDeviceFile, PERSISTENCE_FILE3);
|
initServiceWithPersistenceFile(onDeviceFile, PERSISTENCE_FILE3);
|
||||||
initServiceWithPersistenceFile(onDeviceFile, PERSISTENCE_FILE4);
|
initServiceWithPersistenceFile(onDeviceFile, PERSISTENCE_FILE4);
|
||||||
initServiceWithPersistenceFile(onDeviceFile, PERSISTENCE_FILE5);
|
initServiceWithPersistenceFile(onDeviceFile, PERSISTENCE_FILE5);
|
||||||
|
initServiceWithPersistenceFile(onDeviceFile, PERSISTENCE_FILE6);
|
||||||
|
|
||||||
// Try all files with two known users
|
// Try all files with two known users
|
||||||
doReturn(new int[]{0, 10}).when(mMockedUserManagerInternal).getUserIds();
|
doReturn(new int[]{0, 10}).when(mMockedUserManagerInternal).getUserIds();
|
||||||
@@ -124,6 +127,7 @@ public class SensorPrivacyServiceMockingTest {
|
|||||||
initServiceWithPersistenceFile(onDeviceFile, PERSISTENCE_FILE3);
|
initServiceWithPersistenceFile(onDeviceFile, PERSISTENCE_FILE3);
|
||||||
initServiceWithPersistenceFile(onDeviceFile, PERSISTENCE_FILE4);
|
initServiceWithPersistenceFile(onDeviceFile, PERSISTENCE_FILE4);
|
||||||
initServiceWithPersistenceFile(onDeviceFile, PERSISTENCE_FILE5);
|
initServiceWithPersistenceFile(onDeviceFile, PERSISTENCE_FILE5);
|
||||||
|
initServiceWithPersistenceFile(onDeviceFile, PERSISTENCE_FILE6);
|
||||||
|
|
||||||
} finally {
|
} finally {
|
||||||
mockitoSession.finishMocking();
|
mockitoSession.finishMocking();
|
||||||
|
|||||||
Reference in New Issue
Block a user