Exposed some testAPIs in ActivityManager

- Added the following testAPIs to replace the usage
of adb shell commands in tests:
* stopUser and ACTION_USER_STOPPED
* waitForBroadcastIdle

- Changed the documentation for switchUser to correctly
reflect that it accepts CREATE_USERS

Test: verfied that tests can access the APIs
Bug: 181030374
Change-Id: I92b92471a18cf97a118d3f1946d6e06c277a76f1
This commit is contained in:
kholoud mohamed
2021-03-15 14:38:02 +00:00
parent 51755dc698
commit 23c36dbe21
6 changed files with 64 additions and 8 deletions

View File

@@ -31,6 +31,7 @@ import android.annotation.RequiresPermission;
import android.annotation.SystemApi;
import android.annotation.SystemService;
import android.annotation.TestApi;
import android.annotation.UserIdInt;
import android.compat.annotation.ChangeId;
import android.compat.annotation.EnabledSince;
import android.compat.annotation.UnsupportedAppUsage;
@@ -4048,7 +4049,8 @@ public class ActivityManager {
* @hide
*/
@SystemApi
@RequiresPermission(android.Manifest.permission.MANAGE_USERS)
@RequiresPermission(anyOf = {android.Manifest.permission.MANAGE_USERS,
android.Manifest.permission.CREATE_USERS})
public boolean switchUser(@NonNull UserHandle user) {
if (user == null) {
throw new IllegalArgumentException("UserHandle cannot be null.");
@@ -4144,6 +4146,25 @@ public class ActivityManager {
}
}
/**
* Stops the given {@code userId}.
*
* @hide
*/
@TestApi
@RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS_FULL)
public boolean stopUser(@UserIdInt int userId, boolean force) {
if (userId == UserHandle.USER_SYSTEM) {
return false;
}
try {
return USER_OP_SUCCESS == getService().stopUser(
userId, force, /* callback= */ null);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/** {@hide} */
public static final int FLAG_OR_STOPPED = 1 << 0;
/** {@hide} */
@@ -4810,6 +4831,21 @@ public class ActivityManager {
}
}
/**
* Blocks until all broadcast queues become idle.
*
* @hide
*/
@TestApi
@RequiresPermission(android.Manifest.permission.DUMP)
public void waitForBroadcastIdle() {
try {
getService().waitForBroadcastIdle();
} catch (RemoteException e) {
e.rethrowFromSystemServer();
}
}
/**
* A subset of immutable pending intent information suitable for caching on the client side.
*

View File

@@ -709,4 +709,7 @@ interface IActivityManager {
ParceledListSlice queryIntentComponentsForIntentSender(in IIntentSender sender, int matchFlags);
int getUidProcessCapabilities(int uid, in String callingPackage);
/** Blocks until all broadcast queues become idle. */
void waitForBroadcastIdle();
}