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
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 @@
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 @@
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 @@
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.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 @@
verifyInitBootUserCalled();
verifySendLifecycleEventCalled(USER_LIFECYCLE_EVENT_TYPE_SWITCHING);
- verifyOnUserRemovedCalled();
+ verifyLifecycleEventCalledForUserRemoval();
}
@Test
@@ -124,14 +126,14 @@
callOnUserRemoved();
- verifyOnUserRemovedCalled();
+ verifyLifecycleEventCalledForUserRemoval();
}
@Test
public void testOnUserRemoved_CarServiceNull() throws RemoteException {
callOnUserRemoved();
- verifyOnUserRemovedNeverCalled();
+ verifySendLifecycleEventNeverCalled();
}
@Test
@@ -203,10 +205,13 @@
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 {