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; 18 19 import android.app.FragmentManager; 20 import android.app.PendingIntent; 21 22 import com.android.settings.SidecarFragment; 23 import com.android.settings.network.telephony.EuiccOperationSidecar; 24 25 /** A headless fragment encapsulating long-running eSIM enabling/disabling operations. */ 26 public class SwitchToEuiccSubscriptionSidecar extends EuiccOperationSidecar { 27 private static final String TAG = "SwitchToEuiccSubscriptionSidecar"; 28 private static final String ACTION_SWITCH_TO_SUBSCRIPTION = 29 "com.android.settings.network.SWITCH_TO_SUBSCRIPTION"; 30 31 private PendingIntent mCallbackIntent; 32 33 /** Returns a SwitchToEuiccSubscriptionSidecar sidecar instance. */ get(FragmentManager fm)34 public static SwitchToEuiccSubscriptionSidecar get(FragmentManager fm) { 35 return SidecarFragment.get( 36 fm, TAG, SwitchToEuiccSubscriptionSidecar.class, null /* args */); 37 } 38 39 @Override getReceiverAction()40 public String getReceiverAction() { 41 return ACTION_SWITCH_TO_SUBSCRIPTION; 42 } 43 44 /** Returns the pendingIntent of the eSIM operations. */ getCallbackIntent()45 public PendingIntent getCallbackIntent() { 46 return mCallbackIntent; 47 } 48 49 /** Starts calling EuiccManager#switchToSubscription to enable/disable the eSIM profile. */ run(int subscriptionId)50 public void run(int subscriptionId) { 51 setState(State.RUNNING, Substate.UNUSED); 52 mCallbackIntent = createCallbackIntent(); 53 mEuiccManager.switchToSubscription(subscriptionId, mCallbackIntent); 54 } 55 } 56