Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0e80140e authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Fixed bmgr so it supports --user cur" into main

parents 74b083ad c93afac3
Loading
Loading
Loading
Loading
+14 −3
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.commands.bmgr;

import android.annotation.IntDef;
import android.annotation.UserIdInt;
import android.app.ActivityManager;
import android.app.backup.BackupManager;
import android.app.backup.BackupManagerMonitor;
import android.app.backup.BackupProgress;
@@ -73,6 +74,8 @@ public class Bmgr {
            "Error: Could not access the backup transport.  Is the system running?";
    private static final String PM_NOT_RUNNING_ERR =
            "Error: Could not access the Package Manager.  Is the system running?";
    private static final String INVALID_USER_ID_ERR_TEMPLATE =
            "Error: Invalid user id (%d).\n";

    private String[] mArgs;
    private int mNextArg;
@@ -104,6 +107,11 @@ public class Bmgr {
        mArgs = args;
        mNextArg = 0;
        int userId = parseUserId();
        if (userId < 0) {
            System.err.printf(INVALID_USER_ID_ERR_TEMPLATE, userId);
            return;
        }

        String op = nextArg();
        Slog.v(TAG, "Running " + op + " for user:" + userId);

@@ -955,12 +963,15 @@ public class Bmgr {

    private int parseUserId() {
        String arg = nextArg();
        if ("--user".equals(arg)) {
            return UserHandle.parseUserArg(nextArg());
        } else {
        if (!"--user".equals(arg)) {
            mNextArg--;
            return UserHandle.USER_SYSTEM;
        }
        int userId = UserHandle.parseUserArg(nextArg());
        if (userId == UserHandle.USER_CURRENT) {
            userId = ActivityManager.getCurrentUser();
        }
        return userId;
    }

    private static void showUsage() {