Welcome to Headwind MDM Q&A, where you can ask questions and receive answers from other members of the community.

Please do not post bug reports, missing feature requests, or demo inquiries. If you have such an inquiry, submit a contact form.

0 votes

There are some functions which are available for the device owner application only, for example, getting the device IMEI, or changing the device time zone. 

More methods only allowed to the device owner are available in the DevicePolicyManager class.

If we would like to get the device IMEI , how would we implement that?

by (36.8k points)
edited by

1 Answer

0 votes

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/

by (36.8k points)
edited by
...