diff options
| author | 2015-10-02 23:17:36 +0000 | |
|---|---|---|
| committer | 2015-10-02 23:17:36 +0000 | |
| commit | 4a305c95e1669222f2b835a3b85fee77d72fab57 (patch) | |
| tree | 73bff6b1d4b935fee9468a1127b44c11c03cc250 | |
| parent | f3854aceb57f5bf1a7e316ef5f67543a3e81ae72 (diff) | |
| parent | 0df68cd13b8121aa4e582d8fb59c7589079d6ff9 (diff) | |
Merge "Do now allow current user to be removed"
| -rw-r--r-- | cmds/am/src/com/android/commands/am/Am.java | 15 | ||||
| -rw-r--r-- | services/core/java/com/android/server/pm/UserManagerService.java | 5 |
2 files changed, 19 insertions, 1 deletions
diff --git a/cmds/am/src/com/android/commands/am/Am.java b/cmds/am/src/com/android/commands/am/Am.java index 5c9fd51d606d..4a13136fa8d9 100644 --- a/cmds/am/src/com/android/commands/am/Am.java +++ b/cmds/am/src/com/android/commands/am/Am.java @@ -44,6 +44,7 @@ import android.content.Intent; import android.content.pm.IPackageManager; import android.content.pm.ParceledListSlice; import android.content.pm.ResolveInfo; +import android.content.pm.UserInfo; import android.content.res.Configuration; import android.graphics.Rect; import android.net.Uri; @@ -63,6 +64,7 @@ import android.util.ArrayMap; import android.view.IWindowManager; import com.android.internal.os.BaseCommand; +import com.android.internal.util.Preconditions; import java.io.BufferedReader; import java.io.File; @@ -168,6 +170,7 @@ public class Am extends BaseCommand { " am get-inactive [--user <USER_ID>] <PACKAGE>\n" + " am send-trim-memory [--user <USER_ID>] <PROCESS>\n" + " [HIDDEN|RUNNING_MODERATE|BACKGROUND|RUNNING_LOW|MODERATE|RUNNING_CRITICAL|COMPLETE]\n" + + " am get-current-user\n" + "\n" + "am start: start an Activity. Options are:\n" + " -D: enable debugging\n" + @@ -334,7 +337,9 @@ public class Am extends BaseCommand { "\n" + "am get-inactive: returns the inactive state of an app.\n" + "\n" + - "am send-trim-memory: Send a memory trim event to a <PROCESS>.\n" + + "am send-trim-memory: send a memory trim event to a <PROCESS>.\n" + + "\n" + + "am get-current-user: returns id of the current foreground user.\n" + "\n" + "<INTENT> specifications include these flags and arguments:\n" + " [-a <ACTION>] [-d <DATA_URI>] [-t <MIME_TYPE>]\n" + @@ -464,6 +469,8 @@ public class Am extends BaseCommand { runGetInactive(); } else if (op.equals("send-trim-memory")) { runSendTrimMemory(); + } else if (op.equals("get-current-user")) { + runGetCurrentUser(); } else { showError("Error: unknown command '" + op + "'"); } @@ -2712,6 +2719,12 @@ public class Am extends BaseCommand { } } + private void runGetCurrentUser() throws Exception { + UserInfo currentUser = Preconditions.checkNotNull(mAm.getCurrentUser(), + "Current user not set"); + System.out.println(currentUser.id); + } + /** * Open the given file for sending into the system process. This verifies * with SELinux that the system will have access to the file. diff --git a/services/core/java/com/android/server/pm/UserManagerService.java b/services/core/java/com/android/server/pm/UserManagerService.java index bdc84d5405ee..31fc24bef4f9 100644 --- a/services/core/java/com/android/server/pm/UserManagerService.java +++ b/services/core/java/com/android/server/pm/UserManagerService.java @@ -1520,6 +1520,11 @@ public class UserManagerService extends IUserManager.Stub { long ident = Binder.clearCallingIdentity(); try { final UserInfo user; + int currentUser = ActivityManager.getCurrentUser(); + if (currentUser == userHandle) { + Log.w(LOG_TAG, "Current user cannot be removed"); + return false; + } synchronized (mPackagesLock) { user = mUsers.get(userHandle); if (userHandle == 0 || user == null || mRemovingUserIds.get(userHandle)) { |