Install APK in Work Profile via ADB in Android

20.7k Views Asked by At

Let's say we have a Work Profile (Android For Work) enabled in Android device. Does anyone know how to install an APK via ADB in Work Profile rather than personal profile.

I have seen the ADB documentation and there's a way to get the User ID but using the same ID I am unable to install an APK.

To get ID : adb shell pm list users Install command : adb install -r --user 12 app_name.apk

Error message :

Performing Streamed Install
adb: failed to install app-prodDebug.apk: Security exception: Shell does not have permission to access user 12
 com.android.server.am.ActivityManagerService.handleIncomingUser:22541 android.app.ActivityManager.handleIncomingUser:3989 com.android.server.pm.PackageManagerShellCommand.translateUserId:2434

java.lang.SecurityException: Shell does not have permission to access user 12
 com.android.server.am.ActivityManagerService.handleIncomingUser:22541 android.app.ActivityManager.handleIncomingUser:3989 com.android.server.pm.PackageManagerShellComma

Any way to get around this ? My use case here is to replace an App with debug option enabled so that I can troubleshoot any issue that is happening with that specific app which is installed in work profile.

4

There are 4 best solutions below

6
jtmcdole On BEST ANSWER
adb push android.apk /data/local/tmp
adb shell pm install --user 12 /data/local/tmp/android.apk
1
vijayan007 On
  • Above solution from @jtmcodle works fine.

  • But to findout userid please use below command

  • adb shell dumpsys user

  • In my case above command gave following output

  • UserInfo{11:10100030} serialNo=11

  • So I ran below command to make it work

  • adb shell pm install --user 12 /data/local/tmp/android.apk

2
Faux Pas On

If the accepted answer (https://stackoverflow.com/a/59148545/1667216) doesn't work, then invoke the following command from your DPC before you run those 2 steps:

devicePolicyManager.clearUserRestriction(componentName,UserManager.DISALLOW_DEBUGGING_FEATURES

where 'componentName' is the ComponentName of the class that extends DeviceAdminReceiver.

0
Pablo Lopes On

According Android Developer site, if you install an app via usb with adb command, it will be installed in both profiles:

Android Developer Site

If you manually install an app over a USB cable to a device which has a work profile, the app is installed on both the personal and the work profile. Once you have installed the app, you can test the app under the following conditions: