Android esim Activation Using EuiccManager

354 Views Asked by At

I need to have a complete stable code or review for the below code to handle esim activation on Android platform, I used the code and adjusted it, which was shared from Google Docs, but again no result, Can someone pass by the same issue, and tell me what is wrong with the below code, Issue is: calling the subscription function to download the esim profile, using the activation code, always Operation code and Error code returned as null, and I don't know where is the error.

public class MainActivity extends AppCompatActivity {

String results = "Init";
String googleTestActivationCode = "1$prod.smdp-plus.rsp.goog$3TD6-8L82-HUE1-LVN6";
String realeSimActivationCode = "LPA:1$consumer.rsp.world$I5JCY6O2BQT5NTAE";
String activationCode = realeSimActivationCode;
TextView txtViewResult ;
Button btn_activate ;
EuiccManager euiccManager ;
private static final String TAG = "EsimInstallationReceiver";
private static final String LPA_INSTALL_ACTION = "com.android.lpa.action.PROVISION";
//Register Receiver for Callback,
static final String ACTION_DOWNLOAD_SUBSCRIPTION = "download_subscription";
static final String LPA_DECLARED_PERMISSION = "com.plixera.esim.lpa.permission.BROADCAST";
BroadcastReceiver receiver ;

private static final int PERMISSION_REQUEST_CODE = 1;
private BroadcastReceiver downloadProgressReceiver;
private static final String ACTION_DOWNLOAD_PROGRESS = "com.example.esim.DOWNLOAD_PROGRESS";
private Button btn_activate_lpa;
private EditText et_activation_code;
private static final int ACTIVATE_ESIM_REQUEST_CODE = 1;
//Register Receiver for Callback,
static final String ACTION_DOWNLOAD_SUBSCRIPTION = "download_subscription";
static final String LPA_DECLARED_PERMISSION = "com.plixera.esim.lpa.permission.BROADCAST";
BroadcastReceiver receiver ;

private static final int PERMISSION_REQUEST_CODE = 1;
private BroadcastReceiver downloadProgressReceiver;
private static final String ACTION_DOWNLOAD_PROGRESS = "com.example.esim.DOWNLOAD_PROGRESS";
private Button btn_activate_lpa;
private EditText et_activation_code;
private static final int ACTIVATE_ESIM_REQUEST_CODE = 1;
  @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        findViews();
        startActivationProcess();

    }

}
private void findViews(){
    txtViewResult = (TextView) findViewById(R.id.result);
    btn_activate = (Button) findViewById(R.id.btn_activate);
    btn_activate_lpa = (Button) findViewById(R.id.btn_activate_lpa);
    et_activation_code = (EditText) findViewById(R.id.et_activation_code);
}

public void startActivationProcess(){
        btn_activate.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if(!et_activation_code.getText().toString().equals(""))
                    activationCode = et_activation_code.getText().toString().trim();
                Log.d(TAG,"Activation Code:"+activationCode);
                initiateEsimInstallation();
            }
        });
    }

  private void initiateEsimInstallation() {
        checkESimAvailability(this);
        getEuiCCInfo();
        Intent intent = new Intent();
        intent.setAction(LPA_INSTALL_ACTION);
        intent.putExtra("activationCode", activationCode);
        //sendBroadcast(intent);
        //activateESim();
        registerReceiver();
    }

   public void registerReceiver(){
        BroadcastReceiver receiver =
                new BroadcastReceiver() {
                    @Override
                    public void onReceive(Context context, Intent intent) {
                        Log.d(TAG,"onReceive");
                        if (!LPA_INSTALL_ACTION.equals(intent.getAction())) {
                            return;
                        }
                        int resultCode = getResultCode();
                        Log.d(TAG,"resultCode:"+resultCode);
                        int operationCode = intent.getIntExtra(EXTRA_EMBEDDED_SUBSCRIPTION_OPERATION_CODE,-1);
                        int errorCode = intent.getIntExtra(EXTRA_EMBEDDED_SUBSCRIPTION_ERROR_CODE,-1);
                        String smdxSubjectCode = intent.getStringExtra(EXTRA_EMBEDDED_SUBSCRIPTION_SMDX_SUBJECT_CODE);
                        String smdxReasonCode = intent.getStringExtra(EXTRA_EMBEDDED_SUBSCRIPTION_SMDX_REASON_CODE);




                        if (operationCode == OPERATION_DOWNLOAD && errorCode == ERROR_CARRIER_LOCKED) {
                            // handle specific error i.e tries to download but the device is carrier locked
                            Log.d(TAG,"Final Result:"+"to download but the device is carrier locked");
                        } else if (operationCode == OPERATION_SMDX) {
                            // handle all SM-DP+/SM-DS errors
                            Log.d(TAG,"Final Result:"+"handle all SM-DP+/SM-DS errors");
                        } else if (errorCode == ERROR_TIME_OUT) {
                            // handle all types of time out issues, regardless of operation.
                            Log.d(TAG,"Final Result:"+"regardless of operation.");
                        } else if ("8.1".equals(smdxSubjectCode) && "3.1".equals(smdxReasonCode)) {
                            // handle specific subject code and reason code: 8.1 and 4.1 means insufficient memory.
                            Log.d(TAG,"Final Result:"+"8.1 and 4.1 means insufficient memory.");
                        }
                        else   if (errorCode == ERROR_INVALID_ACTIVATION_CODE) {
                            // handle specific subject code and reason code: 8.1 and 4.1 means insufficient memory.
                            Log.d(TAG,"Final Result:"+"ERROR_INVALID_ACTIVATION_CODE");
                        }
                        else   if (errorCode == EMBEDDED_SUBSCRIPTION_RESULT_ERROR) {
                            // handle specific subject code and reason code: 8.1 and 4.1 means insufficient memory.
                            Log.d(TAG,"Final Result:"+"ERROR_INVALID_ACTIVATION_CODE");
                        }
                        Log.d(TAG,"Operation Code:"+operationCode);
                        Log.d(TAG,"Error Code:"+errorCode);

                        Intent resultIntent = intent;
                    }
                };
        this.registerReceiver(
                receiver,
                new IntentFilter(LPA_INSTALL_ACTION), null, null /* handler */);
        Log.d(TAG,"registerReceiver");
        // Download subscription asynchronously.
        DownloadableSubscription sub =
                DownloadableSubscription.forActivationCode(activationCode );
        Log.d(TAG,"forActivationCode");

        Intent intent = new Intent(LPA_INSTALL_ACTION);

        PendingIntent callbackIntent = PendingIntent.getBroadcast(
                this, Activity.RESULT_OK, intent, PendingIntent.FLAG_MUTABLE);

        euiccManager.downloadSubscription(sub, true , callbackIntent);
        String activationCode = sub.getConfirmationCode();
        Log.d(TAG,"downloadSubscription:"+activationCode);

    }

    public void checkESimAvailability(Context context){
        euiccManager = (EuiccManager)context.getSystemService(Context.EUICC_SERVICE);
        boolean isEnabled = euiccManager.isEnabled();
        if (!isEnabled) {
            return;       //always isEnabled is false
        }
        results = results.concat("\nDevice Support eSIM:"+isEnabled);
        txtViewResult.setText(results);
    }

    public void getEuiCCInfo(){
        EuiccInfo info = euiccManager.getEuiccInfo();
        String osVer = info.getOsVersion();
        results =  results.concat("\n"+osVer);
        txtViewResult.setText(results);
    }
0

There are 0 best solutions below