• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2020 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 
17 package com.android.settings.network.telephony;
18 
19 import android.app.FragmentManager;
20 import android.app.PendingIntent;
21 import android.telephony.SubscriptionInfo;
22 import android.telephony.euicc.EuiccManager;
23 import android.util.Log;
24 
25 import com.android.settings.SidecarFragment;
26 
27 import java.util.ArrayList;
28 import java.util.List;
29 
30 /** A headless fragment encapsulating long-running eSIM erasing operations. */
31 public class DeleteEuiccSubscriptionSidecar extends EuiccOperationSidecar {
32     private static final String TAG = "DeleteEuiccSubscriptionSidecar";
33     private static final String ACTION_DELETE_SUBSCRIPTION =
34             "com.android.settings.network.DELETE_SUBSCRIPTION";
35 
36     private List<SubscriptionInfo> mSubscriptions;
37 
38     @Override
getReceiverAction()39     public String getReceiverAction() {
40         return ACTION_DELETE_SUBSCRIPTION;
41     }
42 
43     /** Returns a DeleteEuiccSubscriptionSidecar sidecar instance. */
get(FragmentManager fm)44     public static DeleteEuiccSubscriptionSidecar get(FragmentManager fm) {
45         return SidecarFragment.get(fm, TAG, DeleteEuiccSubscriptionSidecar.class, null /* args */);
46     }
47 
48     /** Starts calling EuiccManager#deleteSubscription to delete the eSIM profile. */
run(List<SubscriptionInfo> subscriptions)49     public void run(List<SubscriptionInfo> subscriptions) {
50         if (subscriptions == null || subscriptions.isEmpty()) {
51             throw new IllegalArgumentException("Subscriptions cannot be empty.");
52         }
53 
54         setState(State.RUNNING, Substate.UNUSED);
55 
56         mSubscriptions = new ArrayList<>(subscriptions);
57         deleteSubscription();
58     }
59 
60     @Override
onActionReceived()61     protected void onActionReceived() {
62         if (getResultCode() == EuiccManager.EMBEDDED_SUBSCRIPTION_RESULT_OK
63                 && !mSubscriptions.isEmpty()) {
64             // Continue to delete remaining subscriptions.
65             deleteSubscription();
66         } else {
67             super.onActionReceived();
68         }
69     }
70 
deleteSubscription()71     private void deleteSubscription() {
72         SubscriptionInfo subscription = mSubscriptions.remove(0);
73         PendingIntent intent = createCallbackIntent();
74         Log.i(TAG, "Deleting subscription ID: " + subscription.getSubscriptionId());
75         mEuiccManager.deleteSubscription(subscription.getSubscriptionId(), intent);
76     }
77 }
78