To call device owner SDK methods, you have two options:
- Sign your app by the same keys as Headwind MDM and run as the same shared user ID;
- Extend the Headwind MDM library.
Using the device owner shared user
The easiest method to call SDK methods available to the device owner app only is to use the same shared user ID as the device owner app.
1. Sign your application with the same keys as the Headwind MDM mobile agent
2. Add the following attribute to the manifest tag of your app's AndroidManifest.xml:
android:sharedUserId="com.hmdm"
3. Use methods of DevicePolicyManager to perform privileged actions. Note: DevicePolicyManager uses the ComponentName object, which should be an AdminReceiver class of Headwind MDM launcher. The method to retrieve this object can be found in this sample project.
Extending the Headwind MDM library
Another approach is to extend the mobile API of Headwind MDM.
Example: retrieving the device IMEI.
IMEI is collected in util/DeviceInfoProvider.java, TelephonyManager.getDeviceId() method. This SDK method can only be called by the Device Owner, so third party apps can't call this method.
Here are the steps to extend the Headwind MDM library.
1. Add a new method getImei() in the AIDL interface (app/src/main/aidl/com/hmdm/IMdmApi.aidl).
2. Implement the method in the implementation service class (app/src/main/java/com/hmdm/launcher/service/PluginApiService.java)
3. Add a new library method getImei() in the Headwind MDM library by modifying the library code (lib directory in the Headwind MDM source code). New methods need to be added in MDMService and HeadwindMDM classes.
4. Build the new versions of Headwind MDM APK (application) and AAR (library).
5. Use the updated AAR library in your application as described here: https://h-mdm.com/headwind-mdm-api/