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