Test DPC Logo

Exporting Managed Configurations of an app with TestDPC

Daniel Neamtu -
4 MIN READ
414
0

Overview

As you might know, TestDPC is an important Device Policy Controller (DPC) sample application used to test different policies and functions of Android Enterprise, developed and recommended by Google.
TestDPC allows EMMs, ISVs and OEMs to easily test their applications and platforms in an Android Enterprise Managed Profile.
At the same time, TestDPC also serves as an excellent tool for developers to test how their application will behave in a managed context, such as a Device Owner or within a managed profile.

Right now, TestDPC is popular because it's the only way to test managed configurations for a specific application without using a 3rd party EMM client, however, TestDPC is limited in the fact that you cannot test bulk configurations, which can make testing cumbersome. Given that TestDPC is open sourced by Google, we decided to modify it so that managed configs can be exported to a JSON file, in bulk. For example, using our modified version of TestDPC you can add new configurations, export them as a back-up and then re-import them as & when you need them. In addition to this, we've also implemented another feature which allows you to Broadcast intents to TestDPC to update managed configurations programmatically by passing the path of the exported JSON file. Finally, TestDPC does not even need to be in the foreground for this to work - you can call the app directly from any Terminal using adb shell and TestDPC will launch from the background and perform the aforementioned steps.

Installation

If you're interested in using this modified version of TestDPC to perform your own tests, just follow these short steps:

Note: If you already have the original TestDPC app installed, you will need to decativate the Device Owner by going through the application preferences and then uninstalling it afterwards. This must be done because otherwise you will get a signature mismatch error while attempting to install the modded version with ADB.

  • Head over to my forked repository on GitHub and clone it
  • Import the project in Android Studio
  • Build the APK (Do not run it but build the debug apk)
  • Install generated APK (app/outputs/apk/debug) using the -t flag:
adb install -t $ApkPath

The -t flag in the above command is required when installing applications that have been compiled with testOnly set to true in the AndroidManifest - this means that the application cannot be installed with any method other than ADB, and should only be used for debugging purposes.

The final step is to configure TestDPC as the Device Owner, by running this ADB command:

adb shell dpm set-device-owner "com.afwsamples.testdpc/.DeviceAdminReceiver”

If you wish to release/ distribute this sample, you can create release versions in the usual way from Android Studio which this will also deactivate the testOnly attribute from the AndroidManifest, allowing you to install the application in the usual way or to use it in a StageNow profile.

And with this, you're all set!

Note: The original repository used Bazel instead of Gradle as it's build system, which may be unfamiliar for some developers. Given this, we have modified the sample to use Gradle to make things easier.

Usage

By going now in the managed configurations screen you will notice that 2 new buttons have appeared at the bottom of the screen: import & export. Once you load the managed configurations of any application that supports them, you'll have the ability to export / re-import them as and when required.

To test that Broadcast feature we mentioned in the introduction, You will need to enable the Manage External Storage permission for TestDPC so that the app can access the JSON file from the file-system. Once done, you can use the following ADB command to import managed configs via a JSON file:

adb shell am broadcast\
-a com.afwsamples.testdpc.IMPORT_ACTION\
--es file_path "/sdcard/Download/WorkstationConnect_managed_configs.json"\
--es package_name "com.zebra.workstationconnect.release"\
-n com.afwsamples.testdpc/.ManagedConfigurationsBatchImporterReceiver

There are two parameters required in this command:

  • file_path : The full file path on the external storage of the device of the JSON file that contains the managed configs
  • package_name: The package name of the application you want to apply the modified managed configurations to

Once you run the broadcast you should see a new notification on the device which will let you know if the operation succeeded or failed.

If you want to know more about TestDPC, you can also have a look at this article.

Happy testing!

profile

Daniel Neamtu

Please Register or Login to post a reply

0 Replies