summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXiang Wang <xiangw@google.com>2022-08-16 21:25:12 +0000
committerXiang Wang <xiangw@google.com>2022-08-16 21:25:12 +0000
commitf9a115f1331c1fd2328fafd979ae60f6a8ed04fd (patch)
tree65100d1acc5362bae5a35f728bcaa97196c43c6f
parent894787ae5129180f82128f446d5d598bf0b11cfe (diff)
downloadservices-f9a115f1331c1fd2328fafd979ae60f6a8ed04fd.tar.gz
Support user removed lifecycle event in CarServiceProxy.
This plumbs through the generic onUserLifecycleEvent to support sending life cycle event for user removed. Bug: 235524989 Test: atest CarServiceProxyTest Change-Id: Idfbc1ee4e06e6e6f88b6476c4f841547ded468e7
-rw-r--r--updatableServices/src/com/android/internal/car/updatable/CarServiceProxy.java18
-rw-r--r--updatableServices/tests/src/com/android/internal/car/updatable/CarServiceProxyTest.java19
2 files changed, 27 insertions, 10 deletions
diff --git a/updatableServices/src/com/android/internal/car/updatable/CarServiceProxy.java b/updatableServices/src/com/android/internal/car/updatable/CarServiceProxy.java
index 49ee2b5..da3db22 100644
--- a/updatableServices/src/com/android/internal/car/updatable/CarServiceProxy.java
+++ b/updatableServices/src/com/android/internal/car/updatable/CarServiceProxy.java
@@ -17,6 +17,7 @@
package com.android.internal.car.updatable;
import static com.android.car.internal.common.CommonConstants.USER_LIFECYCLE_EVENT_TYPE_CREATED;
+import static com.android.car.internal.common.CommonConstants.USER_LIFECYCLE_EVENT_TYPE_REMOVED;
import static com.android.car.internal.common.CommonConstants.USER_LIFECYCLE_EVENT_TYPE_STARTING;
import static com.android.car.internal.common.CommonConstants.USER_LIFECYCLE_EVENT_TYPE_STOPPED;
import static com.android.car.internal.common.CommonConstants.USER_LIFECYCLE_EVENT_TYPE_STOPPING;
@@ -229,8 +230,8 @@ final class CarServiceProxy {
Slogf.d(TAG, "sendAllLifecycleToUser, user:" + userId + " lifecycle:" + lifecycle);
}
- // User created is unrelated to the user switching/unlocking flow.
- // Return early here to prevent it from going into the following logic
+ // User created and user removed are unrelated to the user switching/unlocking flow.
+ // Return early to prevent them from going into the following logic
// that makes assumptions about the sequence of lifecycle event types
// following numerical order.
if (lifecycle == USER_LIFECYCLE_EVENT_TYPE_CREATED) {
@@ -239,6 +240,14 @@ final class CarServiceProxy {
return;
}
+ if (lifecycle == USER_LIFECYCLE_EVENT_TYPE_REMOVED) {
+ sendUserLifecycleEventInternal(USER_LIFECYCLE_EVENT_TYPE_REMOVED,
+ UserManagerHelper.USER_NULL, userId);
+ return;
+ }
+
+ // The following logic makes assumptions about the sequence of lifecycle event types
+ // following numerical order.
if (lifecycle >= USER_LIFECYCLE_EVENT_TYPE_STARTING) {
sendUserLifecycleEventInternal(USER_LIFECYCLE_EVENT_TYPE_STARTING,
UserManagerHelper.USER_NULL, userId);
@@ -413,8 +422,11 @@ final class CarServiceProxy {
Preconditions.checkArgument((value instanceof UserHandle),
"Invalid value for ON_USER_REMOVED: %s", value);
UserHandle user = (UserHandle) value;
+ // TODO(235524989): Consolidating logging with other lifecycle events,
+ // including user metrics.
if (DBG) Slogf.d(TAG, "Sending onUserRemoved(): " + user);
- mCarService.onUserRemoved(user);
+ mCarService.onUserLifecycleEvent(USER_LIFECYCLE_EVENT_TYPE_REMOVED,
+ UserManagerHelper.USER_NULL, user.getIdentifier());
}
/**
diff --git a/updatableServices/tests/src/com/android/internal/car/updatable/CarServiceProxyTest.java b/updatableServices/tests/src/com/android/internal/car/updatable/CarServiceProxyTest.java
index 714cf55..39781c5 100644
--- a/updatableServices/tests/src/com/android/internal/car/updatable/CarServiceProxyTest.java
+++ b/updatableServices/tests/src/com/android/internal/car/updatable/CarServiceProxyTest.java
@@ -15,6 +15,7 @@
*/
package com.android.internal.car.updatable;
+import static com.android.car.internal.common.CommonConstants.USER_LIFECYCLE_EVENT_TYPE_REMOVED;
import static com.android.car.internal.common.CommonConstants.USER_LIFECYCLE_EVENT_TYPE_SWITCHING;
import static org.mockito.Mockito.any;
@@ -27,6 +28,7 @@ import android.car.test.mocks.AbstractExtendedMockitoTestCase;
import android.car.test.util.UserTestingHelper.UserInfoBuilder;
import android.content.pm.UserInfo;
import android.os.RemoteException;
+import android.os.UserHandle;
import com.android.car.internal.ICarSystemServerClient;
import com.android.server.SystemService.TargetUser;
@@ -115,7 +117,7 @@ public class CarServiceProxyTest extends AbstractExtendedMockitoTestCase {
verifyInitBootUserCalled();
verifySendLifecycleEventCalled(USER_LIFECYCLE_EVENT_TYPE_SWITCHING);
- verifyOnUserRemovedCalled();
+ verifyLifecycleEventCalledForUserRemoval();
}
@Test
@@ -124,14 +126,14 @@ public class CarServiceProxyTest extends AbstractExtendedMockitoTestCase {
callOnUserRemoved();
- verifyOnUserRemovedCalled();
+ verifyLifecycleEventCalledForUserRemoval();
}
@Test
public void testOnUserRemoved_CarServiceNull() throws RemoteException {
callOnUserRemoved();
- verifyOnUserRemovedNeverCalled();
+ verifySendLifecycleEventNeverCalled();
}
@Test
@@ -203,10 +205,13 @@ public class CarServiceProxyTest extends AbstractExtendedMockitoTestCase {
verify(mCarService, never()).onUserLifecycleEvent(anyInt(), anyInt(), anyInt());
}
- private void verifyOnUserRemovedCalled() throws RemoteException {
- verify(mCarService).onUserRemoved(mRemovedUser1.getUserHandle());
- verify(mCarService).onUserRemoved(mRemovedUser2.getUserHandle());
- verify(mCarService).onUserRemoved(mRemovedUser3.getUserHandle());
+ private void verifyLifecycleEventCalledForUserRemoval() throws RemoteException {
+ verify(mCarService).onUserLifecycleEvent(USER_LIFECYCLE_EVENT_TYPE_REMOVED,
+ UserHandle.USER_NULL, mRemovedUser1.getUserHandle().getIdentifier());
+ verify(mCarService).onUserLifecycleEvent(USER_LIFECYCLE_EVENT_TYPE_REMOVED,
+ UserHandle.USER_NULL, mRemovedUser2.getUserHandle().getIdentifier());
+ verify(mCarService).onUserLifecycleEvent(USER_LIFECYCLE_EVENT_TYPE_REMOVED,
+ UserHandle.USER_NULL, mRemovedUser3.getUserHandle().getIdentifier());
}
private void verifyOnUserRemovedNeverCalled() throws RemoteException {