aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYing Zheng <yizheng@google.com>2018-06-25 20:09:05 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2018-06-25 20:09:05 +0000
commitd50321314e309f0062850733a6e7b5f582af5f8c (patch)
tree97446164589c82ce954b16aa76e9761427839333
parentd2335e6a0cf7c47a3dd276ce8f95ab9ae64b494e (diff)
parentcf20f44f515ca802baad7d73f86cbd829e1a2183 (diff)
downloadCar-d50321314e309f0062850733a6e7b5f582af5f8c.tar.gz
Merge "Update last active user." into pi-dev
-rw-r--r--car-lib/src/android/car/user/CarUserManagerHelper.java19
-rw-r--r--service/src/com/android/car/user/CarUserService.java15
-rw-r--r--tests/carservice_unit_test/src/com/android/car/user/CarUserServiceTest.java6
3 files changed, 22 insertions, 18 deletions
diff --git a/car-lib/src/android/car/user/CarUserManagerHelper.java b/car-lib/src/android/car/user/CarUserManagerHelper.java
index a0f4e15d7b..db28d21cba 100644
--- a/car-lib/src/android/car/user/CarUserManagerHelper.java
+++ b/car-lib/src/android/car/user/CarUserManagerHelper.java
@@ -34,7 +34,6 @@ import android.os.UserManager;
import android.provider.Settings;
import android.util.Log;
-import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.util.UserIcons;
import com.google.android.collect.Sets;
@@ -109,9 +108,7 @@ public class CarUserManagerHelper {
* Set default boot into user.
*
* @param userId default user id to boot into.
- * @deprecated Setting default user is obsolete
*/
- @Deprecated
public void setDefaultBootUser(int userId) {
Settings.Global.putInt(
mContext.getContentResolver(),
@@ -136,9 +133,7 @@ public class CarUserManagerHelper {
* Get user id for the default boot into user.
*
* @return user id of the default boot into user
- * @deprecated Use {@link #getLastActiveUser()} instead.
*/
- @Deprecated
public int getDefaultBootUser() {
// Make user 10 the original default boot user.
return Settings.Global.getInt(
@@ -371,10 +366,7 @@ public class CarUserManagerHelper {
*
* @param userInfo User to check against system user.
* @return {@code true} if is default user, {@code false} otherwise.
- *
- * @deprecated Default user is obsolete
*/
- @Deprecated
public boolean isDefaultUser(UserInfo userInfo) {
return userInfo.id == getDefaultBootUser();
}
@@ -426,6 +418,17 @@ public class CarUserManagerHelper {
}
/**
+ * Checks if the given user is non-ephemeral.
+ *
+ * @param userId User to check
+ * @return {@code true} if given user is persistent user.
+ */
+ public boolean isPersistentUser(int userId) {
+ UserInfo user = mUserManager.getUserInfo(userId);
+ return !user.isEphemeral();
+ }
+
+ /**
* Returns whether this user can be removed from the system.
*
* @param userInfo User to be removed
diff --git a/service/src/com/android/car/user/CarUserService.java b/service/src/com/android/car/user/CarUserService.java
index bc5f2025f7..cc30588284 100644
--- a/service/src/com/android/car/user/CarUserService.java
+++ b/service/src/com/android/car/user/CarUserService.java
@@ -23,6 +23,7 @@ import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.UserInfo;
+import android.os.UserHandle;
import android.os.UserManager;
import android.util.Log;
@@ -88,7 +89,7 @@ public class CarUserService extends BroadcastReceiver implements CarServiceBase
Log.d(TAG, "onReceive " + intent);
}
- if (intent.getAction() == Intent.ACTION_LOCKED_BOOT_COMPLETED) {
+ if (Intent.ACTION_LOCKED_BOOT_COMPLETED.equals(intent.getAction())) {
if (mCarUserManagerHelper.getAllUsers().size() == 0) {
// Disable adding accounts for user 0.
mCarUserManagerHelper.setUserRestriction(mCarUserManagerHelper.getSystemUserInfo(),
@@ -101,13 +102,13 @@ public class CarUserService extends BroadcastReceiver implements CarServiceBase
} else {
mCarUserManagerHelper.switchToUserId(mCarUserManagerHelper.getInitialUser());
}
- }
- if (intent.getAction() == Intent.ACTION_USER_SWITCHED) {
- // Update last active user if foreground user is not ephemeral.
- if (!mCarUserManagerHelper.isForegroundUserEphemeral()) {
+ } else if (Intent.ACTION_USER_SWITCHED.equals(intent.getAction())) {
+ // Update last active user if the switched-to user is a persistent, non-system user.
+ int currentUser = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, -1);
+ if (currentUser > UserHandle.USER_SYSTEM
+ && mCarUserManagerHelper.isPersistentUser(currentUser)) {
mCarUserManagerHelper.setLastActiveUser(
- mCarUserManagerHelper.getCurrentForegroundUserId(),
- /* skipGlobalSettings= */ false);
+ currentUser, /* skipGlobalSetting= */ false);
}
}
}
diff --git a/tests/carservice_unit_test/src/com/android/car/user/CarUserServiceTest.java b/tests/carservice_unit_test/src/com/android/car/user/CarUserServiceTest.java
index 132a7ba9f5..03a692f43b 100644
--- a/tests/carservice_unit_test/src/com/android/car/user/CarUserServiceTest.java
+++ b/tests/carservice_unit_test/src/com/android/car/user/CarUserServiceTest.java
@@ -181,10 +181,10 @@ public class CarUserServiceTest {
int lastActiveUserId = 11;
doReturn(false).when(mCarUserManagerHelper).isForegroundUserEphemeral();
- doReturn(lastActiveUserId).when(mCarUserManagerHelper).getCurrentForegroundUserId();
- mCarUserService.onReceive(mMockContext,
- new Intent(Intent.ACTION_USER_SWITCHED));
+ Intent intent = new Intent(Intent.ACTION_USER_SWITCHED);
+ intent.putExtra(Intent.EXTRA_USER_HANDLE, lastActiveUserId);
+ mCarUserService.onReceive(mMockContext, intent);
verify(mCarUserManagerHelper).setLastActiveUser(
lastActiveUserId, /* skipGlobalSetting= */ false);