• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package com.android.phone.euicc;
17 
18 import android.annotation.Nullable;
19 import android.app.PendingIntent;
20 import android.content.Intent;
21 import android.service.euicc.EuiccService;
22 import android.telephony.euicc.EuiccManager;
23 import android.util.Log;
24 
25 /**
26  * Trampoline activity to forward eUICC intents for error resolutions to the active UI
27  * implementation.
28  *
29  * <p>Unlike {@link EuiccUiDispatcherActivity}, this activity is started with extras that must not
30  * be tampered with, because they are used to resume the operation after the error is resolved. We
31  * thus declare it as a separate activity which requires a locked-down permission to start.
32  */
33 public class EuiccResolutionUiDispatcherActivity extends EuiccUiDispatcherActivity {
34     private static final String TAG = "EuiccResUiDispatcher";
35 
36     @Override
37     @Nullable
getEuiccUiIntent()38     protected Intent getEuiccUiIntent() {
39         String action = getIntent().getAction();
40         if (!EuiccManager.ACTION_RESOLVE_ERROR.equals(action)) {
41             Log.w(TAG, "Unsupported action: " + action);
42             return null;
43         }
44 
45         String euiccUiAction =
46                 getIntent().getStringExtra(
47                         EuiccManager.EXTRA_EMBEDDED_SUBSCRIPTION_RESOLUTION_ACTION);
48         if (!EuiccService.RESOLUTION_ACTIONS.contains(euiccUiAction)) {
49             Log.w(TAG, "Unknown resolution action: " + euiccUiAction);
50             return null;
51         }
52 
53         Intent euiccUiIntent = new Intent(euiccUiAction);
54         // Propagate the extras from the original Intent.
55         euiccUiIntent.putExtras(getIntent());
56         return euiccUiIntent;
57     }
58 
59     @Override
onDispatchFailure()60     protected void onDispatchFailure() {
61         // Attempt to dispatch the callback so the caller knows the operation has failed.
62         PendingIntent callbackIntent =
63                 getIntent().getParcelableExtra(
64                         EuiccManager.EXTRA_EMBEDDED_SUBSCRIPTION_RESOLUTION_CALLBACK_INTENT);
65         if (callbackIntent != null) {
66             try {
67                 callbackIntent.send(EuiccManager.EMBEDDED_SUBSCRIPTION_RESULT_ERROR);
68             } catch (PendingIntent.CanceledException e) {
69                 // Caller canceled the callback; do nothing.
70             }
71         }
72     }
73 }
74