Loading core/java/android/app/ActivityManager.java +7 −1 Original line number Diff line number Diff line Loading @@ -18,12 +18,14 @@ package android.app; import android.annotation.NonNull; import android.annotation.Nullable; import android.annotation.SystemApi; import android.graphics.Canvas; import android.graphics.Matrix; import android.graphics.Point; import android.os.BatteryStats; import android.os.IBinder; import android.os.ParcelFileDescriptor; import com.android.internal.app.ProcessStats; import com.android.internal.os.TransferPipe; import com.android.internal.util.FastPrintWriter; Loading Loading @@ -2464,7 +2466,11 @@ public class ActivityManager { } } /** @hide */ /** * Gets the userId of the current foreground user. Requires system permissions. * @hide */ @SystemApi public static int getCurrentUser() { UserInfo ui; try { Loading core/java/android/os/UserHandle.java +6 −1 Original line number Diff line number Diff line Loading @@ -234,6 +234,7 @@ public final class UserHandle implements Parcelable { * @return user id of the current process * @hide */ @SystemApi public static final int myUserId() { return getUserId(Process.myUid()); } Loading @@ -253,7 +254,11 @@ public final class UserHandle implements Parcelable { mHandle = h; } /** @hide */ /** * Returns the userId stored in this UserHandle. * @hide */ @SystemApi public int getIdentifier() { return mHandle; } Loading core/java/android/os/UserManager.java +14 −0 Original line number Diff line number Diff line Loading @@ -15,6 +15,7 @@ */ package android.os; import android.annotation.SystemApi; import android.app.ActivityManager; import android.app.ActivityManagerNative; import android.content.Context; Loading Loading @@ -423,6 +424,19 @@ public class UserManager { return user != null ? user.isGuest() : false; } /** * Checks if the calling app is running in a managed profile. * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. * * @return whether the caller is in a managed profile. * @hide */ @SystemApi public boolean isManagedProfile() { UserInfo user = getUserInfo(UserHandle.myUserId()); return user != null ? user.isManagedProfile() : false; } /** * Return whether the given user is actively running. This means that * the user is in the "started" state, not "stopped" -- it is currently Loading services/tests/servicestests/src/com/android/server/pm/UserManagerTest.java +2 −1 Original line number Diff line number Diff line Loading @@ -125,7 +125,8 @@ public class UserManagerTest extends AndroidTestCase { UserInfo.FLAG_MANAGED_PROFILE, UserHandle.USER_OWNER); assertNotNull(userInfo1); assertNull(userInfo2); // Verify that current user is not a managed profile assertFalse(mUserManager.isManagedProfile()); // Cleanup removeUser(userInfo1.id); } Loading Loading
core/java/android/app/ActivityManager.java +7 −1 Original line number Diff line number Diff line Loading @@ -18,12 +18,14 @@ package android.app; import android.annotation.NonNull; import android.annotation.Nullable; import android.annotation.SystemApi; import android.graphics.Canvas; import android.graphics.Matrix; import android.graphics.Point; import android.os.BatteryStats; import android.os.IBinder; import android.os.ParcelFileDescriptor; import com.android.internal.app.ProcessStats; import com.android.internal.os.TransferPipe; import com.android.internal.util.FastPrintWriter; Loading Loading @@ -2464,7 +2466,11 @@ public class ActivityManager { } } /** @hide */ /** * Gets the userId of the current foreground user. Requires system permissions. * @hide */ @SystemApi public static int getCurrentUser() { UserInfo ui; try { Loading
core/java/android/os/UserHandle.java +6 −1 Original line number Diff line number Diff line Loading @@ -234,6 +234,7 @@ public final class UserHandle implements Parcelable { * @return user id of the current process * @hide */ @SystemApi public static final int myUserId() { return getUserId(Process.myUid()); } Loading @@ -253,7 +254,11 @@ public final class UserHandle implements Parcelable { mHandle = h; } /** @hide */ /** * Returns the userId stored in this UserHandle. * @hide */ @SystemApi public int getIdentifier() { return mHandle; } Loading
core/java/android/os/UserManager.java +14 −0 Original line number Diff line number Diff line Loading @@ -15,6 +15,7 @@ */ package android.os; import android.annotation.SystemApi; import android.app.ActivityManager; import android.app.ActivityManagerNative; import android.content.Context; Loading Loading @@ -423,6 +424,19 @@ public class UserManager { return user != null ? user.isGuest() : false; } /** * Checks if the calling app is running in a managed profile. * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. * * @return whether the caller is in a managed profile. * @hide */ @SystemApi public boolean isManagedProfile() { UserInfo user = getUserInfo(UserHandle.myUserId()); return user != null ? user.isManagedProfile() : false; } /** * Return whether the given user is actively running. This means that * the user is in the "started" state, not "stopped" -- it is currently Loading
services/tests/servicestests/src/com/android/server/pm/UserManagerTest.java +2 −1 Original line number Diff line number Diff line Loading @@ -125,7 +125,8 @@ public class UserManagerTest extends AndroidTestCase { UserInfo.FLAG_MANAGED_PROFILE, UserHandle.USER_OWNER); assertNotNull(userInfo1); assertNull(userInfo2); // Verify that current user is not a managed profile assertFalse(mUserManager.isManagedProfile()); // Cleanup removeUser(userInfo1.id); } Loading