1 /*
2  * Copyright (C) 2019 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.internal.telephony.cdnr;
18 
19 import android.text.TextUtils;
20 
21 import com.android.internal.telephony.uicc.IccRecords;
22 import com.android.internal.telephony.uicc.IccRecords.OperatorPlmnInfo;
23 import com.android.internal.telephony.uicc.IccRecords.PlmnNetworkName;
24 import com.android.internal.telephony.uicc.SIMRecords;
25 
26 import java.util.Arrays;
27 import java.util.List;
28 
29 /** Ef data from Usim. */
30 public final class UsimEfData implements EfData {
31     private final SIMRecords mUsim;
32 
UsimEfData(SIMRecords usim)33     public UsimEfData(SIMRecords usim) {
34         mUsim = usim;
35     }
36 
37     @Override
getServiceProviderName()38     public String getServiceProviderName() {
39         String spn = mUsim.getServiceProviderName();
40         if (TextUtils.isEmpty(spn)) spn = null;
41         return spn;
42     }
43 
44     @Override
getServiceProviderNameDisplayCondition(boolean isRoaming)45     public int getServiceProviderNameDisplayCondition(boolean isRoaming) {
46         if (isRoaming) {
47             // Show PLMN on roaming.
48             return IccRecords.CARRIER_NAME_DISPLAY_CONDITION_BITMASK_PLMN
49                     | mUsim.getCarrierNameDisplayCondition();
50         } else {
51             // Show SPN on non-roaming.
52             return IccRecords.CARRIER_NAME_DISPLAY_CONDITION_BITMASK_SPN
53                     | mUsim.getCarrierNameDisplayCondition();
54         }
55     }
56 
57     @Override
getServiceProviderDisplayInformation()58     public List<String> getServiceProviderDisplayInformation() {
59         String[] spdi = mUsim.getServiceProviderDisplayInformation();
60         return spdi != null ? Arrays.asList(spdi) : null;
61     }
62 
63     @Override
getEhplmnList()64     public List<String> getEhplmnList() {
65         String[] ehplmns = mUsim.getEhplmns();
66         return ehplmns != null ? Arrays.asList(ehplmns) : null;
67     }
68 
69     @Override
getPlmnNetworkNameList()70     public List<PlmnNetworkName> getPlmnNetworkNameList() {
71         String pnnHomeName = mUsim.getPnnHomeName();
72         if (!TextUtils.isEmpty(pnnHomeName)) {
73             // TODO: Update the whole list rather than the pnn home name when IccRecords can
74             // read all pnn records.
75             return Arrays.asList(new PlmnNetworkName(pnnHomeName, "" /* shortName */));
76         }
77         return null;
78     }
79 
80     @Override
getOperatorPlmnList()81     public List<OperatorPlmnInfo> getOperatorPlmnList() {
82         // TODO: update the OPL when SIMRecords supports it.
83         return null;
84     }
85 }
86