1

Thanks to such so answers I was able to setup a device-owner App on my smartphone. This is a very basic test app just made to enable / disable screen pinning mode...

Anyway, at the end it works but with a very, very bad drawback : I've lost all access to the phone capabilities

  • No more phone icon, except in the Settings > Applications > All
  • If I call it, it's ringing on the caller side, but the phone does not react at all...
  • However the status cellular icon indicates that it has 3G network.

All of those symptoms are pretty weird and leads me to wonder if my tiny device-owner app is locking something somewhere : Would anyone have any thoughts or experience about this ?

Community
  • 1
  • 1
JBA
  • 2,889
  • 1
  • 21
  • 38
  • After some search it looks like it's the DeviceAdministrator feature side that could prevent the installation of the default system apps... For example there is some information about enableSystemApp() api but that doesn't help me much... – JBA Jan 29 '15 at 09:21
  • Could you make a test by setting your device owner app with the dpm command line tool? see [this answer](http://stackoverflow.com/questions/21183328/how-to-make-my-app-a-device-owner/27909315#27909315). Using `dpm` doesn't disable system apps when the device owner app is set. – Florent Dupont Jan 29 '15 at 10:33
  • Florent, thanks for this input. Before investigating NFC-direct-install (needed for production mode) I already tried your solution, but it's telling me that the device is already provisionned: `java.lang.IllegalStateException: Trying to set device owner but device is already provisioned.` As the provisionning occurs at installation time I don't see any solution to get rid of this... – JBA Jan 29 '15 at 14:45
  • 1
    from the source : "Device owner can only be set on an unprovisioned device, unless it was initiated by "adb", in which case we allow it if no account is associated with the device". So, make sure you don't have any account set before using the `dpm` command. – Florent Dupont Jan 29 '15 at 15:00
  • Ok, good catch Florent: resetting the phone, restarted without any account, reinstalling the test app + issuing the dpm command-line device-owner thing = works! The test App is device-owner, and all of the phone default system apps (i.e. the phone itself) are kept safe. Thank you for this big step. So now, what is the issue when installing this app at provision-time, with the NFC transfer... – JBA Jan 29 '15 at 19:35

1 Answers1

2

I found my own answer.

The key thing is to re-enable the default system applications with the DevicePolicyManager.enableSystemApp method, because for some reason when provisioning device with your NFC-triggered-device-owner-app at install time, it prevents further installation of all the default apps (at least on my Nexus 6).

So, once provisioned etc. I listed all the uninstalled apps and re-enabled them with the code below:

        DevicePolicyManager mDPM = (DevicePolicyManager) this.getSystemService(Context.DEVICE_POLICY_SERVICE);
        ComponentName mDeviceAdminRcvr = new ComponentName(this, DeviceAdminRcvr.class);

        List<PackageInfo> packs = getPackageManager().getInstalledPackages(PackageManager.GET_UNINSTALLED_PACKAGES);
        for (int i=0; i<packs.size(); i++) 
        {
            PackageInfo p = packs.get(i);
            try {
                mDPM.enableSystemApp(mDeviceAdminRcvr, p.packageName);
            } catch (Exception e) {
                // TODO: handle exception
            }
        }
JBA
  • 2,889
  • 1
  • 21
  • 38