Implementing eSIM, LPA Example

1.6k views Asked by At

I'm trying to write a test example of code for implementing eSim on a device using examples from the documentation https://source.android.com/devices/tech/connect/esim-overview?hl=en . The device supports eSim and the verification method mgr.isEnabled() returns true. But when I try to call the public load method downloadSubscription nothing happens, the onReceive method is not called.

static final String ACTION_DOWNLOAD_SUBSCRIPTION = "download_subscription";
static final String LPA_DECLARED_PERMISSION
    = "com.your.company.lpa.permission.BROADCAST";
BroadcastReceiver receiver =
        new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                if (!action.equals(intent.getAction())) {
                    return;
                }
                resultCode = getResultCode();
                detailedCode = intent.getIntExtra(
                    EuiccManager.EXTRA_EMBEDDED_SUBSCRIPTION_DETAILED_CODE,
                    0 /* defaultValue*/);
                resultIntent = intent;
            }
        };
context.registerReceiver(receiver,
        new IntentFilter(ACTION_DOWNLOAD_SUBSCRIPTION),
        LPA_DECLARED_PERMISSION /* broadcastPermission*/,
        null /* handler */);

// Download subscription asynchronously.
DownloadableSubscription sub = DownloadableSubscription
        .forActivationCode(code /* encodedActivationCode*/);
Intent intent = new Intent(action);
PendingIntent callbackIntent = PendingIntent.getBroadcast(
        getContext(), 0 /* requestCode */, intent,
        PendingIntent.FLAG_UPDATE_CURRENT);
mgr.downloadSubscription(sub, true /* switchAfterDownload */,
        callbackIntent);

And I don't quite understand what exactly needs to be specified here "com.your.company.lpa.permission.BROADCAST" I tried changing "com.your.company" to my package name but it doesn't work

1

There are 1 answers

1
Rodrigo Martins On

I was facing the same problem as you, what actually fix the problem was:

When you create a new intent like this, to pass as parameter to PendingIntent:

Intent intent = new Intent(action);

the action value should be the same as ACTION_DOWNLOAD_SUBSCRIPTION, I was passing different values on them, and you do not need to set up the LPA_DECLARED_PERMISSION, you can pass null, to the registerBroadcast.