summaryrefslogtreecommitdiffstats
path: root/core/java/android/os/UserId.java
diff options
context:
space:
mode:
authorAmith Yamasani <yamasani@google.com>2011-05-04 14:49:28 -0700
committerAmith Yamasani <yamasani@google.com>2012-02-03 12:01:47 -0800
commit742a67127366c376fdf188ff99ba30b27d3bf90c (patch)
tree4a801b0b2e9ee10fb322e3b450e2af9eb6e3002f /core/java/android/os/UserId.java
parent8ca8a69d5801ad4b809e7b9dbf53bd728820924b (diff)
downloadframeworks_base-742a67127366c376fdf188ff99ba30b27d3bf90c.zip
frameworks_base-742a67127366c376fdf188ff99ba30b27d3bf90c.tar.gz
frameworks_base-742a67127366c376fdf188ff99ba30b27d3bf90c.tar.bz2
Multi-user - 1st major checkin
Switching activity stacks Cache ContentProvider per user Long-press power to switch users (on phone) Added ServiceMap for separating services by user Launch PendingIntents on the correct user's uid Fix task switching from Recents list AppWidgetService is mostly working. Commands added to pm and am to allow creating and switching profiles. Change-Id: I15810e8cfbe50a04bd3323a7ef5a8ff4230870ed
Diffstat (limited to 'core/java/android/os/UserId.java')
-rw-r--r--core/java/android/os/UserId.java90
1 files changed, 90 insertions, 0 deletions
diff --git a/core/java/android/os/UserId.java b/core/java/android/os/UserId.java
new file mode 100644
index 0000000..4124d51
--- /dev/null
+++ b/core/java/android/os/UserId.java
@@ -0,0 +1,90 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.os;
+
+/**
+ * @hide
+ */
+public final class UserId {
+ /**
+ * Range of IDs allocated for a user.
+ *
+ * @hide
+ */
+ public static final int PER_USER_RANGE = 100000;
+
+ public static final int USER_ALL = -1;
+
+ /**
+ * Enable multi-user related side effects. Set this to false if there are problems with single
+ * user usecases.
+ * */
+ public static final boolean MU_ENABLED = true;
+
+ /**
+ * Checks to see if the user id is the same for the two uids, i.e., they belong to the same
+ * user.
+ * @hide
+ */
+ public static final boolean isSameUser(int uid1, int uid2) {
+ return getUserId(uid1) == getUserId(uid2);
+ }
+
+ /**
+ * Checks to see if both uids are referring to the same app id, ignoring the user id part of the
+ * uids.
+ * @param uid1 uid to compare
+ * @param uid2 other uid to compare
+ * @return whether the appId is the same for both uids
+ * @hide
+ */
+ public static final boolean isSameApp(int uid1, int uid2) {
+ return getAppId(uid1) == getAppId(uid2);
+ }
+
+ /**
+ * Returns the user id for a given uid.
+ * @hide
+ */
+ public static final int getUserId(int uid) {
+ if (MU_ENABLED) {
+ return uid / PER_USER_RANGE;
+ } else {
+ return 0;
+ }
+ }
+
+ /**
+ * Returns the uid that is composed from the userId and the appId.
+ * @hide
+ */
+ public static final int getUid(int userId, int appId) {
+ if (MU_ENABLED) {
+ return userId * PER_USER_RANGE + (appId % PER_USER_RANGE);
+ } else {
+ return appId;
+ }
+ }
+
+ /**
+ * Returns the app id (or base uid) for a given uid, stripping out the user id from it.
+ * @hide
+ */
+ public static final int getAppId(int uid) {
+ return uid % PER_USER_RANGE;
+ }
+}