4

Following the Android Management API reference, we've configured our Android Companion app to be able to : enable system apps, hide and unhide packages.

We've added the following information in our policy configuration:

{
  '
  '
  '
  "applications": [
    {
      "packageName": "com.domain.app",
      "installType": "REQUIRED_FOR_SETUP",
      "defaultPermissionPolicy": "GRANT",
      "delegatedScopes": [
        "ENABLE_SYSTEM_APP",
        "PACKAGE_ACCESS"
      ]
    }
  ],
  '
  '
  '
}

Then, in our Android Companion app, we've added the following lines of code in compliance with Google documentation here and here :

DevicePolicyManager dpm = (DevicePolicyManager) mContext.getSystemService(Context.DEVICE_POLICY_SERVICE);
ComponentName admin = new ComponentName(mContext, DeviceAdminReceiver.class);

// Iterate through system application package names list
for (String packageName : systemAppsList) {
  if (packageName != null && !packageName.equals("")) {
    try {
      // Re-enable a system app that was disabled by default when the user was initialized
      dpm.enableSystemApp(admin, packageName);

      // Unhide a package (it could be any app : system, managed, etc...)
      dpm.setApplicationHidden(admin, packageName, false);
    } catch (SecurityException e) {
      e.printStackTrace();
      Log.e(TAG, e.getMessage());
    }
  }
}

We expect the Android launcher to show the enabled system apps, but Android catches a SecurityException and prints the following error log :

No active admin ComponentInfo{com.domain.app/android.app.admin.DeviceAdminReceiver}

Do you have any idea about what could be wrong ?

  • Hey, I know this is an old question, but I would like to know how did manage to set your app as admin while using Android Managment API. We have tried to check if our kiosk app is the device owner (btw, we may be mixing concepts), but our app is not. Thanks a lot! – pitazzo Oct 30 '20 at 20:41

1 Answers1

6

in your method call , set admin param to null if you are using delegated scope as explained in Android Documentation

ComponentName: Which DeviceAdminReceiver this request is associated with, or null if the caller is a package access delegate. This value must never be null.

a bit confusing,admin param can be set to null if using delegated scope and in the same time just after ... this value must never be null , (Great Google)

issamux
  • 1,336
  • 1
  • 19
  • 35
  • lol Google just fix there documentation error "... This value may be null. " – issamux May 17 '19 at 15:31
  • 1
    Thank you @issamux ! I've set the ComponentName parameter to null in both of the methods calls and now it works. And yes, the Google documentation seems to be a bit confusing and contradictory to me too on this point. – Andrew Wizzard May 20 '19 at 11:52
  • Hi @issamux, I was wondering if you could give a look to the comment I just added to the question. If you prefer, I may ask a new question and link it – pitazzo Oct 30 '20 at 20:47
  • Hi @pitazzo ... yep, please ask a new question and provide context and some code so we can help u :) – issamux Nov 01 '20 at 00:05
  • 1
    Hi again @issamux, we have just posted the question, Hope it provides enough context. Please, feel free to comment for any further clarification. https://stackoverflow.com/questions/64634738/make-phone-call-while-app-is-in-kiosk-mode – pitazzo Nov 01 '20 at 17:25