Add QUERY_ALL_PACKAGES permission to getInterventionList
To guard query information from apps and only allow system and shell command. Bug: 249056757 Test: atest GameManagerServiceTests Change-Id: I5855b887d99b5fae0471bda98dcd2d86134032ba
This commit is contained in:
@@ -1762,7 +1762,9 @@ public final class GameManagerService extends IGameManagerService.Stub {
|
||||
/**
|
||||
* Returns the string listing all the interventions currently set to a game.
|
||||
*/
|
||||
@RequiresPermission(Manifest.permission.QUERY_ALL_PACKAGES)
|
||||
public String getInterventionList(String packageName, int userId) {
|
||||
checkPermission(Manifest.permission.QUERY_ALL_PACKAGES);
|
||||
final GamePackageConfiguration packageConfig = getConfig(packageName, userId);
|
||||
final StringBuilder listStrSb = new StringBuilder();
|
||||
if (packageConfig == null) {
|
||||
|
||||
@@ -262,6 +262,16 @@ public class GameManagerServiceTests {
|
||||
mTestLooper.dispatchAll();
|
||||
}
|
||||
|
||||
private void mockQueryAllPackageGranted() {
|
||||
mMockContext.setPermission(Manifest.permission.QUERY_ALL_PACKAGES,
|
||||
PackageManager.PERMISSION_GRANTED);
|
||||
}
|
||||
|
||||
private void mockQueryAllPackageDenied() {
|
||||
mMockContext.setPermission(Manifest.permission.QUERY_ALL_PACKAGES,
|
||||
PackageManager.PERMISSION_DENIED);
|
||||
}
|
||||
|
||||
private void mockManageUsersGranted() {
|
||||
mMockContext.setPermission(Manifest.permission.MANAGE_USERS,
|
||||
PackageManager.PERMISSION_GRANTED);
|
||||
@@ -2180,4 +2190,22 @@ public class GameManagerServiceTests {
|
||||
verify(mMockPowerManager, never()).setPowerMode(anyInt(), anyBoolean());
|
||||
assertFalse(gameManagerService.mHandler.hasMessages(CANCEL_GAME_LOADING_MODE));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetInterventionList_permissionDenied() throws Exception {
|
||||
String configString = "mode=2,downscaleFactor=0.5";
|
||||
when(DeviceConfig.getProperty(anyString(), anyString()))
|
||||
.thenReturn(configString);
|
||||
mockQueryAllPackageDenied();
|
||||
GameManagerService gameManagerService = createServiceAndStartUser(USER_ID_1);
|
||||
assertThrows(SecurityException.class,
|
||||
() -> gameManagerService.getInterventionList(mPackageName, USER_ID_1));
|
||||
|
||||
mockQueryAllPackageGranted();
|
||||
String expectedInterventionListOutput = "\n[Name:" + mPackageName
|
||||
+ " Modes: {2=[Game Mode:2,Scaling:0.5,Use Angle:false,"
|
||||
+ "Fps:,Loading Boost Duration:-1]}]";
|
||||
assertEquals(expectedInterventionListOutput,
|
||||
gameManagerService.getInterventionList(mPackageName, USER_ID_1));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user