简体   繁体   中英

Is there a way to whitelist apps for lock task mode using ADB commands instead of Device policy manager?

I am using startLockTask(); method in my application which locks my current task/activity. My application is also a Device owner and using the following code I whitelist my app package for lock task mode before calling startLockTask();

try
{
   String PLAYER_PACKAGE = this.getPackageName();
   String[] APP_PACKAGES = {PLAYER_PACKAGE};

   DevicePolicyManager dpm = (DevicePolicyManager) this.getSystemService(Context.DEVICE_POLICY_SERVICE);
   ComponentName mDeviceAdmin = new ComponentName(this, DeviceAdminSampleReceiver.class);

   if(!dpm.isDeviceOwnerApp(this.getPackageName())){
       return;
   }

   // Whitelist app package for LockTask mode
   dpm.setLockTaskPackages(mDeviceAdmin, APP_PACKAGES);

   // First, confirm that this package is whitelisted to run in lock task mode.
   if (dpm.isLockTaskPermitted(this.getPackageName())) {
         this.startLockTask();

         // Enable the Home and Overview buttons so that our custom launcher can respond
         // using our custom activities. Implicitly disables all other features.
         dpm.setLockTaskFeatures(mDeviceAdmin,
                        DevicePolicyManager.LOCK_TASK_FEATURE_HOME |
                                DevicePolicyManager.LOCK_TASK_FEATURE_KEYGUARD |
                                DevicePolicyManager.LOCK_TASK_FEATURE_OVERVIEW);
    }
}catch (Exception e){}

The problem is that sometime there are cases when my app is not a device owner resulting I am unable to run:

dpm.setLockTaskPackages(mDeviceAdmin, APP_PACKAGES);

So, I am wondering if there is an equivalent method to achieve the same behavior as "dpm.setLockTaskPackages" using some ADB commands.

Thanks.

I am using startLockTask(); method in my application which locks my current task/activity. My application is also a Device owner and using the following code I whitelist my app package for lock task mode before calling startLockTask();

try
{
   String PLAYER_PACKAGE = this.getPackageName();
   String[] APP_PACKAGES = {PLAYER_PACKAGE};

   DevicePolicyManager dpm = (DevicePolicyManager) this.getSystemService(Context.DEVICE_POLICY_SERVICE);
   ComponentName mDeviceAdmin = new ComponentName(this, DeviceAdminSampleReceiver.class);

   if(!dpm.isDeviceOwnerApp(this.getPackageName())){
       return;
   }

   // Whitelist app package for LockTask mode
   dpm.setLockTaskPackages(mDeviceAdmin, APP_PACKAGES);

   // First, confirm that this package is whitelisted to run in lock task mode.
   if (dpm.isLockTaskPermitted(this.getPackageName())) {
         this.startLockTask();

         // Enable the Home and Overview buttons so that our custom launcher can respond
         // using our custom activities. Implicitly disables all other features.
         dpm.setLockTaskFeatures(mDeviceAdmin,
                        DevicePolicyManager.LOCK_TASK_FEATURE_HOME |
                                DevicePolicyManager.LOCK_TASK_FEATURE_KEYGUARD |
                                DevicePolicyManager.LOCK_TASK_FEATURE_OVERVIEW);
    }
}catch (Exception e){}

The problem is that sometime there are cases when my app is not a device owner resulting I am unable to run:

dpm.setLockTaskPackages(mDeviceAdmin, APP_PACKAGES);

So, I am wondering if there is an equivalent method to achieve the same behavior as "dpm.setLockTaskPackages" using some ADB commands.

Thanks.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM