1 /*
2  * Copyright (C) 2018 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.content.Context;
20 import android.content.Intent;
21 import android.telephony.TelephonyManager;
22 import android.telephony.euicc.EuiccManager;
23 import android.text.TextUtils;
24 
25 import androidx.preference.Preference;
26 
27 import com.android.settings.Utils;
28 
29 /**
30  * Preference controller for "Euicc preference"
31  */
32 public class EuiccPreferenceController extends TelephonyBasePreferenceController {
33 
34     private TelephonyManager mTelephonyManager;
35 
EuiccPreferenceController(Context context, String key)36     public EuiccPreferenceController(Context context, String key) {
37         super(context, key);
38         mTelephonyManager = context.getSystemService(TelephonyManager.class);
39     }
40 
41     @Override
getAvailabilityStatus(int subId)42     public int getAvailabilityStatus(int subId) {
43         return MobileNetworkUtils.showEuiccSettings(mContext)
44                 ? AVAILABLE
45                 : CONDITIONALLY_UNAVAILABLE;
46     }
47 
48     @Override
getSummary()49     public CharSequence getSummary() {
50         return mTelephonyManager.getSimOperatorName();
51     }
52 
init(int subId)53     public void init(int subId) {
54         mSubId = subId;
55         mTelephonyManager = mContext.getSystemService(TelephonyManager.class)
56                 .createForSubscriptionId(mSubId);
57     }
58 
59     @Override
handlePreferenceTreeClick(Preference preference)60     public boolean handlePreferenceTreeClick(Preference preference) {
61         if (TextUtils.equals(preference.getKey(), getPreferenceKey())) {
62             Intent intent = new Intent(EuiccManager.ACTION_MANAGE_EMBEDDED_SUBSCRIPTIONS)
63                     .setPackage(Utils.PHONE_PACKAGE_NAME);
64             mContext.startActivity(intent);
65             return true;
66         }
67 
68         return false;
69     }
70 }
71