Merge "An API to check if running in a demo user" into nyc-mr1-dev

This commit is contained in:
Amith Yamasani
2016-06-29 15:18:33 +00:00
committed by Android (Google) Code Review
6 changed files with 26 additions and 7 deletions

View File

@@ -29362,6 +29362,7 @@ package android.os {
method public android.os.Bundle getUserRestrictions();
method public android.os.Bundle getUserRestrictions(android.os.UserHandle);
method public boolean hasUserRestriction(java.lang.String);
method public boolean isDemoUser();
method public boolean isQuietModeEnabled(android.os.UserHandle);
method public boolean isSystemUser();
method public boolean isUserAGoat();

View File

@@ -31887,6 +31887,7 @@ package android.os {
method public android.os.Bundle getUserRestrictions();
method public android.os.Bundle getUserRestrictions(android.os.UserHandle);
method public boolean hasUserRestriction(java.lang.String);
method public boolean isDemoUser();
method public boolean isManagedProfile();
method public boolean isManagedProfile(int);
method public boolean isQuietModeEnabled(android.os.UserHandle);

View File

@@ -29433,6 +29433,7 @@ package android.os {
method public android.os.Bundle getUserRestrictions();
method public android.os.Bundle getUserRestrictions(android.os.UserHandle);
method public boolean hasUserRestriction(java.lang.String);
method public boolean isDemoUser();
method public boolean isQuietModeEnabled(android.os.UserHandle);
method public boolean isSystemUser();
method public boolean isUserAGoat();

View File

@@ -81,4 +81,5 @@ interface IUserManager {
void clearSeedAccountData();
boolean someUserHasSeedAccount(in String accountName, in String accountType);
boolean isManagedProfile(int userId);
boolean isDemoUser(int userId);
}

View File

@@ -859,15 +859,17 @@ public class UserManager {
}
/**
* Checks if the calling app is running in a demo user.
* <p>
* Caller must hold the MANAGE_USERS permission.
* Checks if the calling app is running in a demo user. When running in a demo user,
* apps can be more helpful to the user, or explain their features in more detail.
*
* @return whether the caller is a demo user.
* @hide
*/
public boolean isDemoUser() {
UserInfo user = getUserInfo(UserHandle.myUserId());
return user != null && user.isDemo();
try {
return mService.isDemoUser(UserHandle.myUserId());
} catch (RemoteException re) {
throw re.rethrowFromSystemServer();
}
}
/**

View File

@@ -868,11 +868,24 @@ public class UserManagerService extends IUserManager.Stub {
}
}
synchronized (mUsersLock) {
UserInfo userInfo = getUserInfoLU(userId);
UserInfo userInfo = getUserInfoLU(userId);
return userInfo != null && userInfo.isManagedProfile();
}
}
@Override
public boolean isDemoUser(int userId) {
int callingUserId = UserHandle.getCallingUserId();
if (callingUserId != userId && !hasManageUsersPermission()) {
throw new SecurityException("You need MANAGE_USERS permission to query if u=" + userId
+ " is a demo user");
}
synchronized (mUsersLock) {
UserInfo userInfo = getUserInfoLU(userId);
return userInfo != null && userInfo.isDemo();
}
}
@Override
public boolean isRestricted() {
synchronized (mUsersLock) {