summaryrefslogtreecommitdiff
path: root/libraries/car-helpers/multiuser-helper/src/android/platform/helpers/MultiUserHelper.java
diff options
context:
space:
mode:
Diffstat (limited to 'libraries/car-helpers/multiuser-helper/src/android/platform/helpers/MultiUserHelper.java')
-rw-r--r--libraries/car-helpers/multiuser-helper/src/android/platform/helpers/MultiUserHelper.java17
1 files changed, 17 insertions, 0 deletions
diff --git a/libraries/car-helpers/multiuser-helper/src/android/platform/helpers/MultiUserHelper.java b/libraries/car-helpers/multiuser-helper/src/android/platform/helpers/MultiUserHelper.java
index bf48642cc..35b75f832 100644
--- a/libraries/car-helpers/multiuser-helper/src/android/platform/helpers/MultiUserHelper.java
+++ b/libraries/car-helpers/multiuser-helper/src/android/platform/helpers/MultiUserHelper.java
@@ -24,12 +24,15 @@ import android.car.user.UserSwitchResult;
import android.car.util.concurrent.AsyncFuture;
import android.content.Context;
import android.content.pm.UserInfo;
+import android.os.Build;
import android.os.SystemClock;
import android.os.UserManager;
import android.support.test.uiautomator.UiDevice;
import androidx.test.InstrumentationRegistry;
+import com.android.compatibility.common.util.SystemUtil;
+
import java.io.IOException;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
@@ -42,6 +45,8 @@ public class MultiUserHelper {
/** For testing purpose we allow a wide range of switching time. */
private static final int USER_SWITCH_TIMEOUT_SECOND = 300;
+ private static final String SWITCH_USER_COMMAND = "cmd car_service switch-user ";
+
private static MultiUserHelper sMultiUserHelper;
private CarUserManager mCarUserManager;
private UserManager mUserManager;
@@ -102,6 +107,11 @@ public class MultiUserHelper {
* @param id Id of the user to switch to
*/
public void switchToUserId(int id) throws Exception {
+ if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) {
+ switchUserUsingShell(id);
+ return;
+ }
+
final CountDownLatch latch = new CountDownLatch(1);
// A UserLifeCycleListener to wait for user switch event. It is equivalent to
// UserSwitchObserver#onUserSwitchComplete callback
@@ -177,4 +187,11 @@ public class MultiUserHelper {
.findFirst()
.orElse(null);
}
+
+ private void switchUserUsingShell(int userId) throws Exception {
+ String retStr = SystemUtil.runShellCommand(SWITCH_USER_COMMAND + userId);
+ if (!retStr.contains("STATUS_SUCCESSFUL")) {
+ throw new Exception("failed to switch to user: " + userId);
+ }
+ }
}