Update ManageExternalStorageDetailsTest setUidMode
We previously changed ManageExternalStorageDetails to use AppOpsManager#setUidMode instead of AppOpsManager#setMode, but forgot to update the relevant unittest. This CL changes that unittest. Test: make RunSettingsRoboTests ROBOTEST_FILTER=ManageExternalStorageDetailsTest Fix: 150914062 Change-Id: I2cfe7e7a19f2422474d11fb946089a6847b36b12
This commit is contained in:
@@ -69,7 +69,7 @@ public class AppStateManageExternalStorageBridge extends AppStateAppOpsBridge {
|
||||
|
||||
/**
|
||||
* Returns the MANAGE_EXTERNAL_STORAGE {@link AppStateAppOpsBridge.PermissionState} object
|
||||
* associated with the given package and user.
|
||||
* associated with the given package and UID.
|
||||
*/
|
||||
public PermissionState getManageExternalStoragePermState(String pkg, int uid) {
|
||||
return getPermissionInfo(pkg, uid);
|
||||
|
@@ -64,13 +64,11 @@ public class ManageExternalStorageDetailsTest {
|
||||
|
||||
private ManageExternalStorageDetails mFragment;
|
||||
|
||||
private final HashMap<String, Integer> mPkgToOpModeMap = new HashMap<>();
|
||||
private final HashMap<Integer, Integer> mUidToOpModeMap = new HashMap<>();
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
// Reset the global trackers
|
||||
mPkgToOpModeMap.clear();
|
||||
mUidToOpModeMap.clear();
|
||||
|
||||
//Start the mockin'
|
||||
@@ -106,8 +104,7 @@ public class ManageExternalStorageDetailsTest {
|
||||
|
||||
// Verify that mAppOpsManager was called to allow the app-op
|
||||
verify(mAppOpsManager, times(1))
|
||||
.setMode(anyInt(), anyInt(), nullable(String.class), anyInt());
|
||||
assertThat(mPkgToOpModeMap).containsExactly(mockPkgName, AppOpsManager.MODE_ALLOWED);
|
||||
.setUidMode(anyInt(), anyInt(), anyInt());
|
||||
assertThat(mUidToOpModeMap).containsExactly(mockUid, AppOpsManager.MODE_ALLOWED);
|
||||
|
||||
// Verify the mSwitchPref was enabled
|
||||
@@ -141,8 +138,7 @@ public class ManageExternalStorageDetailsTest {
|
||||
|
||||
// Verify that mAppOpsManager was called to deny the app-op
|
||||
verify(mAppOpsManager, times(1))
|
||||
.setMode(anyInt(), anyInt(), nullable(String.class), anyInt());
|
||||
assertThat(mPkgToOpModeMap).containsExactly(mockPkgName, AppOpsManager.MODE_ERRORED);
|
||||
.setUidMode(anyInt(), anyInt(), anyInt());
|
||||
assertThat(mUidToOpModeMap).containsExactly(mockUid, AppOpsManager.MODE_ERRORED);
|
||||
|
||||
// Verify the mSwitchPref was enabled
|
||||
@@ -164,33 +160,32 @@ public class ManageExternalStorageDetailsTest {
|
||||
}
|
||||
|
||||
private void mockAppOpsOperations() {
|
||||
Answer<Void> answerSetMode = invocation -> {
|
||||
Answer<Void> answerSetUidMode = invocation -> {
|
||||
int code = invocation.getArgument(0);
|
||||
int uid = invocation.getArgument(1);
|
||||
String packageName = invocation.getArgument(2);
|
||||
int mode = invocation.getArgument(3);
|
||||
int mode = invocation.getArgument(2);
|
||||
|
||||
if (code != AppOpsManager.OP_MANAGE_EXTERNAL_STORAGE) {
|
||||
return null;
|
||||
}
|
||||
|
||||
mPkgToOpModeMap.put(packageName, mode);
|
||||
mUidToOpModeMap.put(uid, mode);
|
||||
|
||||
return null;
|
||||
};
|
||||
|
||||
doAnswer(answerSetMode).when(mAppOpsManager)
|
||||
.setMode(anyInt(), anyInt(), nullable(String.class), anyInt());
|
||||
doAnswer(answerSetUidMode).when(mAppOpsManager)
|
||||
.setUidMode(anyInt(), anyInt(), anyInt());
|
||||
|
||||
Answer<PermissionState> answerPermState = invocation -> {
|
||||
String packageName = invocation.getArgument(0);
|
||||
int uid = invocation.getArgument(1);
|
||||
PermissionState res = new PermissionState(packageName, null);
|
||||
res.permissionDeclared = false;
|
||||
|
||||
if (mPkgToOpModeMap.containsKey(packageName)) {
|
||||
if (mUidToOpModeMap.containsKey(uid)) {
|
||||
res.permissionDeclared = true;
|
||||
res.appOpMode = mPkgToOpModeMap.get(packageName);
|
||||
res.appOpMode = mUidToOpModeMap.get(uid);
|
||||
}
|
||||
return res;
|
||||
};
|
||||
|
Reference in New Issue
Block a user