Test DPC

repository·master·Indexed 19 days ago

https://github.com/googlesamples/android-testdpc

A sample Device Policy Controller (DPC) and testing application for EMMs, ISVs, and OEMs to test Android enterprise managed profiles and APIs. Supports devices from Android 5.0 Lollipop onwards. Includes instructions for provisioning as Device Owner (DO), Profile Owner (PO), and Device Management Role Holder, as well as build guides using Bazel and Android Studio.

Tokens
1K
Snippets
5
Records
6
Agent score
27%

What's inside android-testdpc

  1. Provision Test DPC as Device Owner (DO)

    master

    To set up Test DPC as the Device Owner, use one of the following methods:

    AFW# code provisioning (Android M+)

    1. Factory reset your device.
    2. Set up Wi-Fi.
    3. When prompted to sign in, enter afw#testdpc.
    4. Follow onscreen instructions. Choose 'Use for work only' for a fully managed setup.

    QR code provisioning (Android N+)

    1. Factory reset your device and tap the welcome screen in the setup wizard 6 times.
    2. Generate a QR code containing the following JSON payload:
      {
       "android.app.extra.PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME": "com.afwsamples.testdpc/com.afwsamples.testdpc.DeviceAdminReceiver",
       "android.app.extra.PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM": "gJD2YwtOiWJHkSMkkIfLRlj-quNqG1fb6v100QmzM9w=",
       "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION": "https://testdpc-latest-apk.appspot.com"
      }
    3. Scan the QR code and follow onscreen instructions.

    Note: If the device hangs on the configuring screen, it may be unable to connect to the appspot.com domain. You can host the APK on your own server and update the PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION key in the JSON before generating the QR code.

    ADB command

    Run the following command via ADB:

    adb shell dpm set-device-owner com.afwsamples.testdpc/.DeviceAdminReceiver
    adb shell dpm set-device-owner com.afwsamples.testdpc/.DeviceAdminReceiver
  2. Set up Test DPC as Device Management Role Holder

    master

    Test DPC (v9.0.5+) can be configured as a Device Management Role Holder using ADB. Note that this change is not persistent; you must re-run these commands if the device reboots.

    Run the following commands:

    adb shell cmd role set-bypassing-role-qualification true
    adb shell cmd role add-role-holder android.app.role.DEVICE_POLICY_MANAGEMENT com.afwsamples.testdpc
    adb shell cmd role set-bypassing-role-qualification true
    adb shell cmd role add-role-holder android.app.role.DEVICE_POLICY_MANAGEMENT com.afwsamples.testdpc
  3. Build Test DPC with Bazel

    master

    This project uses the Bazel build system. To build the application, use the bazel build command.

    Prerequisites

    • ANDROID_HOME: You must set the ANDROID_HOME environment variable to the path of your Android SDK.
    • ed utility: The build process uses the ed command-line utility to patch the setupdesign library dynamically. Ensure ed is available in your PATH.

    Build Command

    bazel build testdpc
    bazel build testdpc
  4. Provision Test DPC as Profile Owner (PO)

    master

    To set up Test DPC as a Profile Owner (for BYOD or COPE scenarios):

    Profile Owner - Personal device (PO - BYOD)

    1. Launch the "Set up TestDPC" app on the device.
    2. Create a managed profile.
    3. Skip adding an account at the end of the flow.

    Profile Owner - Corporate-owned device (PO - COPE)

    1. Launch the "Set up TestDPC" app on the device.
    2. Create a managed profile.
    3. Skip adding an account at the end of the flow.
    4. Run the following ADB command to mark the profile owner on the organization-owned device:
    adb shell dpm mark-profile-owner-on-organization-owned-device --user 10 com.afwsamples.testdpc/.DeviceAdminReceiver
    adb shell dpm mark-profile-owner-on-organization-owned-device --user 10 com.afwsamples.testdpc/.DeviceAdminReceiver
  5. Import Test DPC into Android Studio

    master

    To work on this project in Android Studio, you must use the Bazel for Android Studio plugin.

    Import Steps

    1. Open the project and select the folder containing the Bazel BUILD file.
    2. When prompted for a "project view", select "Copy external" and choose the scripts/ij.bazelproject file from this repository.
    3. Wait for the Bazel import and initial sync to complete.

    Running the Project

    1. Create a new Run Configuration.
    2. Set the Configuration type to "Bazel Command".
    3. Set the "target expression" to //:testdpc.
    4. Run the configuration.