Merge "Added isUserNameSet" into oc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
a9154ab391
@@ -93,4 +93,5 @@ interface IUserManager {
|
||||
int getManagedProfileBadge(int userId);
|
||||
boolean isUserUnlocked(int userId);
|
||||
boolean isUserRunning(int userId);
|
||||
boolean isUserNameSet(int userHandle);
|
||||
}
|
||||
|
||||
@@ -905,6 +905,20 @@ public class UserManager {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether user name has been set.
|
||||
* <p>This method can be used to check that the value returned by {@link #getUserName()} was
|
||||
* set by the user and is not a placeholder string provided by the system.
|
||||
* @hide
|
||||
*/
|
||||
public boolean isUserNameSet() {
|
||||
try {
|
||||
return mService.isUserNameSet(getUserHandle());
|
||||
} catch (RemoteException re) {
|
||||
throw re.rethrowFromSystemServer();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to determine whether the user making this call is subject to
|
||||
* teleportations.
|
||||
|
||||
@@ -3068,6 +3068,14 @@ public class UserManagerService extends IUserManager.Stub {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUserNameSet(int userHandle) {
|
||||
synchronized (mUsersLock) {
|
||||
UserInfo userInfo = getUserInfoLU(userHandle);
|
||||
return userInfo != null && userInfo.name != null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getUserHandle(int userSerialNumber) {
|
||||
synchronized (mUsersLock) {
|
||||
|
||||
@@ -24,6 +24,7 @@ import android.os.UserHandle;
|
||||
import android.support.test.InstrumentationRegistry;
|
||||
import android.support.test.runner.AndroidJUnit4;
|
||||
import android.support.test.filters.MediumTest;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.android.server.LocalServices;
|
||||
import com.android.server.pm.UserManagerService.UserData;
|
||||
@@ -38,6 +39,8 @@ import java.io.DataOutputStream;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* <p>Run with:<pre>
|
||||
@@ -100,6 +103,23 @@ public class UserManagerServiceUserInfoTest {
|
||||
assertUserInfoEquals(info, read);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetUserName() throws Exception {
|
||||
assertFalse("System user name shouldn't be set",
|
||||
mUserManagerService.isUserNameSet(UserHandle.USER_SYSTEM));
|
||||
UserInfo userInfo = mUserManagerService.getUserInfo(UserHandle.USER_SYSTEM);
|
||||
assertFalse("A system provided name should be returned for primary user",
|
||||
TextUtils.isEmpty(userInfo.name));
|
||||
|
||||
userInfo = createUser();
|
||||
userInfo.partial = false;
|
||||
final int TEST_ID = 100;
|
||||
userInfo.id = TEST_ID;
|
||||
mUserManagerService.putUserInfo(userInfo);
|
||||
assertTrue("Test user name must be set", mUserManagerService.isUserNameSet(TEST_ID));
|
||||
assertEquals("A Name", mUserManagerService.getUserInfo(TEST_ID).name);
|
||||
}
|
||||
|
||||
private UserInfo createUser() {
|
||||
UserInfo user = new UserInfo(/*id*/ 21, "A Name", "A path", /*flags*/ 0x0ff0ff);
|
||||
user.serialNumber = 5;
|
||||
|
||||
Reference in New Issue
Block a user