Merge "Added --user option to 'dumpsys activity $ActivityName'." into tm-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
2bb1846570
@@ -9176,6 +9176,7 @@ public class ActivityManagerService extends IActivityManager.Stub
|
||||
boolean dumpVisibleStacksOnly = false;
|
||||
boolean dumpFocusedStackOnly = false;
|
||||
String dumpPackage = null;
|
||||
int dumpUserId = UserHandle.USER_ALL;
|
||||
|
||||
int opti = 0;
|
||||
while (opti < args.length) {
|
||||
@@ -9207,6 +9208,17 @@ public class ActivityManagerService extends IActivityManager.Stub
|
||||
dumpCheckinFormat = true;
|
||||
} else if ("--normal-priority".equals(opt)) {
|
||||
dumpNormalPriority = true;
|
||||
} else if ("--user".equals(opt)) {
|
||||
if (opti < args.length) {
|
||||
dumpUserId = UserHandle.parseUserArg(args[opti]);
|
||||
if (dumpUserId == UserHandle.USER_CURRENT) {
|
||||
dumpUserId = mUserController.getCurrentUserId();
|
||||
}
|
||||
opti++;
|
||||
} else {
|
||||
pw.println("Error: --user option requires user id argument");
|
||||
return;
|
||||
}
|
||||
} else if ("-h".equals(opt)) {
|
||||
ActivityManagerShellCommand.dumpHelp(pw, true);
|
||||
return;
|
||||
@@ -9397,29 +9409,17 @@ public class ActivityManagerService extends IActivityManager.Stub
|
||||
} else if ("service".equals(cmd)) {
|
||||
String[] newArgs;
|
||||
String name;
|
||||
int[] users = null;
|
||||
if (opti >= args.length) {
|
||||
name = null;
|
||||
newArgs = EMPTY_STRING_ARRAY;
|
||||
} else {
|
||||
name = args[opti];
|
||||
opti++;
|
||||
if ("--user".equals(name) && opti < args.length) {
|
||||
int userId = UserHandle.parseUserArg(args[opti]);
|
||||
opti++;
|
||||
if (userId != UserHandle.USER_ALL) {
|
||||
if (userId == UserHandle.USER_CURRENT) {
|
||||
userId = getCurrentUser().id;
|
||||
}
|
||||
users = new int[] { userId };
|
||||
}
|
||||
name = args[opti];
|
||||
opti++;
|
||||
}
|
||||
newArgs = new String[args.length - opti];
|
||||
if (args.length > 2) System.arraycopy(args, opti, newArgs, 0,
|
||||
args.length - opti);
|
||||
}
|
||||
int[] users = dumpUserId == UserHandle.USER_ALL ? null : new int[] { dumpUserId };
|
||||
if (!mServices.dumpService(fd, pw, name, users, newArgs, 0, dumpAll)) {
|
||||
pw.println("No services match: " + name);
|
||||
pw.println("Use -h for help.");
|
||||
@@ -9480,7 +9480,7 @@ public class ActivityManagerService extends IActivityManager.Stub
|
||||
} else {
|
||||
// Dumping a single activity?
|
||||
if (!mAtmInternal.dumpActivity(fd, pw, cmd, args, opti, dumpAll,
|
||||
dumpVisibleStacksOnly, dumpFocusedStackOnly)) {
|
||||
dumpVisibleStacksOnly, dumpFocusedStackOnly, dumpUserId)) {
|
||||
ActivityManagerShellCommand shell = new ActivityManagerShellCommand(this, true);
|
||||
int res = shell.exec(this, null, fd, null, args, null,
|
||||
new ResultReceiver(null));
|
||||
|
||||
@@ -471,7 +471,7 @@ public abstract class ActivityTaskManagerInternal {
|
||||
/** Dump the current activities state. */
|
||||
public abstract boolean dumpActivity(FileDescriptor fd, PrintWriter pw, String name,
|
||||
String[] args, int opti, boolean dumpAll, boolean dumpVisibleRootTasksOnly,
|
||||
boolean dumpFocusedRootTaskOnly);
|
||||
boolean dumpFocusedRootTaskOnly, @UserIdInt int userId);
|
||||
|
||||
/** Dump the current state for inclusion in oom dump. */
|
||||
public abstract void dumpForOom(PrintWriter pw);
|
||||
|
||||
@@ -4062,12 +4062,12 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
|
||||
*/
|
||||
protected boolean dumpActivity(FileDescriptor fd, PrintWriter pw, String name, String[] args,
|
||||
int opti, boolean dumpAll, boolean dumpVisibleRootTasksOnly,
|
||||
boolean dumpFocusedRootTaskOnly) {
|
||||
boolean dumpFocusedRootTaskOnly, @UserIdInt int userId) {
|
||||
ArrayList<ActivityRecord> activities;
|
||||
|
||||
synchronized (mGlobalLock) {
|
||||
activities = mRootWindowContainer.getDumpActivities(name, dumpVisibleRootTasksOnly,
|
||||
dumpFocusedRootTaskOnly);
|
||||
dumpFocusedRootTaskOnly, userId);
|
||||
}
|
||||
|
||||
if (activities.size() <= 0) {
|
||||
@@ -6410,9 +6410,9 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
|
||||
@Override
|
||||
public boolean dumpActivity(FileDescriptor fd, PrintWriter pw, String name,
|
||||
String[] args, int opti, boolean dumpAll, boolean dumpVisibleRootTasksOnly,
|
||||
boolean dumpFocusedRootTaskOnly) {
|
||||
boolean dumpFocusedRootTaskOnly, @UserIdInt int userId) {
|
||||
return ActivityTaskManagerService.this.dumpActivity(fd, pw, name, args, opti, dumpAll,
|
||||
dumpVisibleRootTasksOnly, dumpFocusedRootTaskOnly);
|
||||
dumpVisibleRootTasksOnly, dumpFocusedRootTaskOnly, userId);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -3434,11 +3434,11 @@ class RootWindowContainer extends WindowContainer<DisplayContent>
|
||||
* or all visible root tasks if {@param dumpVisibleRootTasksOnly} is true.
|
||||
*/
|
||||
ArrayList<ActivityRecord> getDumpActivities(String name, boolean dumpVisibleRootTasksOnly,
|
||||
boolean dumpFocusedRootTaskOnly) {
|
||||
boolean dumpFocusedRootTaskOnly, @UserIdInt int userId) {
|
||||
if (dumpFocusedRootTaskOnly) {
|
||||
final Task topFocusedRootTask = getTopDisplayFocusedRootTask();
|
||||
if (topFocusedRootTask != null) {
|
||||
return topFocusedRootTask.getDumpActivitiesLocked(name);
|
||||
return topFocusedRootTask.getDumpActivitiesLocked(name, userId);
|
||||
} else {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
@@ -3446,7 +3446,7 @@ class RootWindowContainer extends WindowContainer<DisplayContent>
|
||||
final ArrayList<ActivityRecord> activities = new ArrayList<>();
|
||||
forAllRootTasks(rootTask -> {
|
||||
if (!dumpVisibleRootTasksOnly || rootTask.shouldBeVisible(null)) {
|
||||
activities.addAll(rootTask.getDumpActivitiesLocked(name));
|
||||
activities.addAll(rootTask.getDumpActivitiesLocked(name, userId));
|
||||
}
|
||||
});
|
||||
return activities;
|
||||
|
||||
@@ -137,6 +137,7 @@ import static java.lang.Integer.MAX_VALUE;
|
||||
import android.annotation.IntDef;
|
||||
import android.annotation.NonNull;
|
||||
import android.annotation.Nullable;
|
||||
import android.annotation.UserIdInt;
|
||||
import android.app.Activity;
|
||||
import android.app.ActivityManager;
|
||||
import android.app.ActivityManager.RecentTaskInfo.PersistedTaskSnapshotData;
|
||||
@@ -5691,7 +5692,7 @@ class Task extends TaskFragment {
|
||||
}
|
||||
}
|
||||
|
||||
ArrayList<ActivityRecord> getDumpActivitiesLocked(String name) {
|
||||
ArrayList<ActivityRecord> getDumpActivitiesLocked(String name, @UserIdInt int userId) {
|
||||
ArrayList<ActivityRecord> activities = new ArrayList<>();
|
||||
|
||||
if ("all".equals(name)) {
|
||||
@@ -5711,7 +5712,13 @@ class Task extends TaskFragment {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (userId != UserHandle.USER_ALL) {
|
||||
for (int i = activities.size() - 1; i >= 0; --i) {
|
||||
if (activities.get(i).mUserId != userId) {
|
||||
activities.remove(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
return activities;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user