Third-party software programming

After achieving ownership of the device, I try to implement a method that allows the device to block any given application in kiosk mode (or screen pinning mode). Since I have ownership of the device, the user does not need permission to do so.

On the developer's website, a short description tells me that what I am trying to do is:

http://developer.android.com/about/versions/android-5.0.html#ScreenPinning

Programmatically: to programmatically activate screen shielding, call startLockTask () from your application. If the requesting application is not the device owner, the user will be asked to confirm. The device owner’s application can call the setLockTaskPackages () method to enable applications for suspension without user confirmation.

This means that as the device owner’s application, I can connect other applications without user confirmation ... but I have no idea how to do this.

I was able to place my application in fixed mode.

Any help would be appreciated.

+12
android android-5.0-lollipop device-policy-manager android-screen-pinning device-owner
Jan 29 '15 at 0:06
source share
3 answers

In setLockTaskPackages() used to specify which applications (through their package names) will be programmatically fixed without user confirmation . setLockTaskPackages() is called from the device owner’s application (most likely in your DeviceAdminReceiver onEnabled() method).

So, in your owner device app, you will have something like:

 mDPM.setLockTaskPackages("com.foo.myapp"); 

and then in your application “com.foo.myapp” you will be authorized to call:

 startLockTask(); 

Your application will immediately enter Pinning mode without user confirmation.

If you are not the first to register your application with setLockTaskPackages , the application will be pinned, but first the user will have to confirm.

Also note that when an application is registered with setLockTaskPackages() , it has several different types of behavior than manual output:

  • user cannot manually disable the application by tapping Back + Recent Apps. You will have to programmatically disable your application using stopLockTask() ;
  • The Home and Recent Apps buttons are invisible (not displayed)
  • When the application is disconnected (via stopLockTask ()), the user will immediately return to Home: the screen lock will not be displayed, even if Keyguard is installed (template, code, or any Keyguard screen).
+9
Jan 29 '15 at 11:03
source share

I don’t have enough reputation for comment, I’ll just point out that for devices with physical buttons (for example, Samsung Galaxy Tab A mentioned by @chairman), one of the ways to control the forced cancellation of your application is to implement in your DeviceAdminReceiver Class:

@Override public void onLockTaskModeExiting (context context, intent Intention)

So, if your user wants you to disconnect, you can always reassign your application;)

+3
Feb 17 '16 at 8:05
source share

Here is a snippet of code that should catch you:

 DevicePolicyManager myDevicePolicyManager = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE); mDeviceAdminSample = new ComponentName(this, DeviceAdminSample.class); if (myDevicePolicyManager.isDeviceOwnerApp(this.getPackageName())) { // Device owner String[] packages = {this.getPackageName()}; myDevicePolicyManager.setLockTaskPackages(mDeviceAdminSample, packages); } else { // Not a device owner - prompt user or show error } if (myDevicePolicyManager.isLockTaskPermitted(this.getPackageName())) { // Lock allowed startLockTask(); } else { // Lock not allowed - show error or something useful here } 
0
Jan 29 '15 at 0:14
source share



All Articles