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