Scenario

You can also call an AIDL API provided by HUAWEI Ads Kit to obtain OAID information from Huawei devices, without integrating any Huawei SDK. The OAID information obtained from a device in either mode (SDK or AIDL) is the same.

Call Process

Development Procedure

1. Create AIDL file for the OpenDeviceIdentifierService API and save the file under the com.uodis.opendevice.aidl package, as shown in the following figure.


2. Copy the following content to the AIDL file.

  1. package com.uodis.opendevice.aidl;
  2. /** Note: Please do not modify the method order of this AIDL file. */
  3. interface OpenDeviceIdentifierService {
  4.    /** Obtain OAID information. */
  5.    String getOaid();
  6.    /** Obtain the setting of Disable personalized ads. The options are true and false. */
  7.    boolean isOaidTrackLimited();
  8. }


3. Create a class to implement the Android-native ServiceConnection.

Step 1: Implement the onServiceConnected method of ServiceConnection.
Step 2: Call the Android-native OpenDeviceIdentifierService.Stub.asInterface method to obtain OpenDeviceIdentifierService.
Step 3: Call the getOaid and isOaidTrackLimited methods to obtain the OAID and the Disable Ads Personalization switch value.

  1. private final class IdentifierServiceConnection implements ServiceConnection {
  2.    private IdentifierServiceConnection() {
  3.    }
  4.    @Override
  5.    public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
  6.        Log.i(TAG, "onServiceConnected");
  7.        OpenDeviceIdentifierService service = OpenDeviceIdentifierService.Stub.asInterface(iBinder);
  8.        if (null != service) {
  9.            try {
  10.                String oaid = service.getOaid();
  11.                boolean isDisable = service.isOaidTrackLimited();
  12.                AdvertisingIdClient.Info info = new AdvertisingIdClient.Info(oaid, isDisable);
  13.                updateAdIdInfo(info);
  14.            } catch (RemoteException e) {
  15.                Log.e(TAG, "getChannelInfo Exception");
  16.            } finally {
  17.                mContext.unbindService(this);
  18.            }
  19.        }
  20.    }
  21.    @Override
  22.    public void onServiceDisconnected(ComponentName componentName) {
  23.        Log.i(TAG, "onServiceDisconnected");
  24.    }
  25. }

4. Connect to the AIDL service for obtaining the OAID.
Step 1: Create an InstallReferrerServiceConnection instance.
Step 2: Create an Intent with Action being com.uodis.opendevice.OPENIDS_SERVICE.
Step 3: Set the name of the Intent package to com.huawei.hwid.
Step 4: Call the AIDL service of the bindService for IdentifierService.

  1. private boolean bindService() {
  2.    IdentifierServiceConnection serviceConnection = new IdentifierServiceConnection();
  3.    Intent intent = new Intent("com.uodis.opendevice.OPENIDS_SERVICE");
  4.    intent.setPackage("com.huawei.hwid");
  5.    boolean result = bindService(intent, serviceConnection, Context.BIND_AUTO_CREATE);
  6.    Log.i(TAG, "bindService result: " + result);
  7.    return result;
  8. }
  9. private void unbindService() {
  10.    // unbind the service.
  11. }