1 /*
2  * Copyright (C) 2022 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.settingslib.mobile.dataservice;
18 
19 import android.telephony.SubscriptionInfo;
20 import android.telephony.SubscriptionManager;
21 import android.telephony.UiccCardInfo;
22 import android.telephony.UiccPortInfo;
23 import android.telephony.UiccSlotInfo;
24 import android.telephony.UiccSlotMapping;
25 
26 import java.util.List;
27 
28 public class DataServiceUtils {
29 
shouldUpdateEntityList(List<T> oldList, List<T> newList)30     public static <T> boolean shouldUpdateEntityList(List<T> oldList, List<T> newList) {
31         if ((oldList != null &&
32                 (newList.isEmpty() || !newList.equals(oldList)))
33                 || (!newList.isEmpty() && oldList == null)) {
34             return true;
35         }
36         return false;
37     }
38 
39     /**
40      * Represents columns of the MobileNetworkInfoData table, define these columns from
41      * {@see MobileNetworkUtils} or relevant common APIs.
42      */
43     public static final class MobileNetworkInfoData {
44 
45         /** The name of the MobileNetworkInfoData table. */
46         public static final String TABLE_NAME = "MobileNetworkInfo";
47 
48         /**
49          * The name of the ID column, set the {@link SubscriptionInfo#getSubscriptionId()}
50          * as the primary key.
51          */
52         public static final String COLUMN_ID = "subId";
53 
54         /**
55          * The name of the contact discovery enabled state column,
56          * {@see MobileNetworkUtils#isContactDiscoveryEnabled(Context, int)}.
57          */
58         public static final String COLUMN_IS_CONTACT_DISCOVERY_ENABLED =
59                 "isContactDiscoveryEnabled";
60 
61         /**
62          * The name of the contact discovery visible state column,
63          * {@see MobileNetworkUtils#isContactDiscoveryEnabled(Context, int)}.
64          */
65         public static final String COLUMN_IS_CONTACT_DISCOVERY_VISIBLE =
66                 "isContactDiscoveryVisible";
67 
68         /**
69          * The name of the mobile network data state column,
70          * {@see MobileNetworkUtils#isMobileDataEnabled(Context)}.
71          */
72         public static final String COLUMN_IS_MOBILE_DATA_ENABLED = "isMobileDataEnabled";
73 
74         /**
75          * The name of the CDMA option state column,
76          * {@see MobileNetworkUtils#isCdmaOptions(Context, int)}.
77          */
78         public static final String COLUMN_IS_CDMA_OPTIONS = "isCdmaOptions";
79 
80         /**
81          * The name of the GSM option state column,
82          * {@see MobileNetworkUtils#isGsmOptions(Context, int)}.
83          */
84         public static final String COLUMN_IS_GSM_OPTIONS = "isGsmOptions";
85 
86         /**
87          * The name of the world mode state column,
88          * {@see MobileNetworkUtils#isWorldMode(Context, int)}.
89          */
90         public static final String COLUMN_IS_WORLD_MODE = "isWorldMode";
91 
92         /**
93          * The name of the display network select options state column,
94          * {@see MobileNetworkUtils#shouldDisplayNetworkSelectOptions(Context, int)}.
95          */
96         public static final String COLUMN_SHOULD_DISPLAY_NETWORK_SELECT_OPTIONS =
97                 "shouldDisplayNetworkSelectOptions";
98 
99         /**
100          * The name of the TDSCDMA supported state column,
101          * {@see MobileNetworkUtils#isTdscdmaSupported(Context, int)}.
102          */
103         public static final String COLUMN_IS_TDSCDMA_SUPPORTED = "isTdscdmaSupported";
104 
105         /**
106          * The name of the active network is cellular state column,
107          * {@see MobileNetworkUtils#activeNetworkIsCellular(Context)}.
108          */
109         public static final String COLUMN_ACTIVE_NETWORK_IS_CELLULAR = "activeNetworkIsCellular";
110 
111         /**
112          * The name of the show toggle for physicalSim state column,
113          * {@see SubscriptionUtil#showToggleForPhysicalSim(SubscriptionManager)}.
114          */
115         public static final String COLUMN_SHOW_TOGGLE_FOR_PHYSICAL_SIM = "showToggleForPhysicalSim";
116 
117         /**
118          * The name of the subscription's data roaming state column,
119          * {@see TelephonyManager#isDataRoamingEnabled()}.
120          */
121         public static final String COLUMN_IS_DATA_ROAMING_ENABLED = "isDataRoamingEnabled";
122     }
123 
124     /**
125      * Represents columns of the UiccInfoData table, define these columns from
126      * {@link android.telephony.UiccSlotInfo}, {@link android.telephony.UiccCardInfo},
127      * {@link UiccSlotMapping} and {@link android.telephony.UiccPortInfo}.If columns of these 4
128      * classes are changed, we should also update the table except PII data.
129      */
130     public static final class UiccInfoData {
131 
132         /** The name of the UiccInfoData table. */
133         public static final String TABLE_NAME = "uiccInfo";
134 
135         /**
136          * The name of the ID column, set the {@link SubscriptionInfo#getSubscriptionId()}
137          * as the primary key.
138          */
139         public static final String COLUMN_ID = "sudId";
140 
141         /**
142          * The name of the physical slot index column, see
143          * {@link UiccSlotMapping#getPhysicalSlotIndex()}.
144          */
145         public static final String COLUMN_PHYSICAL_SLOT_INDEX = "physicalSlotIndex";
146 
147         /**
148          * The name of the logical slot index column, see
149          * {@link UiccSlotMapping#getLogicalSlotIndex()}.
150          */
151         public static final String COLUMN_LOGICAL_SLOT_INDEX = "logicalSlotIndex";
152 
153         /**
154          * The name of the card ID column, see {@link UiccCardInfo#getCardId()}.
155          */
156         public static final String COLUMN_CARD_ID = "cardId";
157 
158         /**
159          * The name of the eUICC state column, see {@link UiccCardInfo#isEuicc()}.
160          */
161         public static final String COLUMN_IS_EUICC = "isEuicc";
162 
163         /**
164          * The name of the multiple enabled profiles supported state column, see
165          * {@link UiccCardInfo#isMultipleEnabledProfilesSupported()}.
166          */
167         public static final String COLUMN_IS_MULTIPLE_ENABLED_PROFILES_SUPPORTED =
168                 "isMultipleEnabledProfilesSupported";
169 
170         /**
171          * The name of the card state column, see {@link UiccSlotInfo#getCardStateInfo()}.
172          */
173         public static final String COLUMN_CARD_STATE = "cardState";
174 
175         /**
176          * The name of the extended APDU supported state column, see
177          * {@link UiccSlotInfo#getIsExtendedApduSupported()}.
178          */
179         public static final String COLUMN_IS_EXTENDED_APDU_SUPPORTED = "isExtendedApduSupported";
180 
181         /**
182          * The name of the removable state column, see {@link UiccSlotInfo#isRemovable()}.
183          */
184         public static final String COLUMN_IS_REMOVABLE = "isRemovable";
185 
186         /**
187          * The name of the active state column, see {@link UiccPortInfo#isActive()}.
188          */
189         public static final String COLUMN_IS_ACTIVE = "isActive";
190 
191         /**
192          * The name of the port index column, see {@link UiccPortInfo#getPortIndex()}.
193          */
194         public static final String COLUMN_PORT_INDEX = "portIndex";
195     }
196 
197     /**
198      * Represents columns of the SubscriptionInfoData table, define these columns from
199      * {@link SubscriptionInfo}, {@see SubscriptionUtil} and
200      * {@link SubscriptionManager} or relevant common APIs. If columns of the
201      * {@link SubscriptionInfo} are changed, we should also update the table except PII data.
202      */
203     public static final class SubscriptionInfoData {
204 
205         /** The name of the SubscriptionInfoData table. */
206         public static final String TABLE_NAME = "subscriptionInfo";
207 
208         /**
209          * The name of the ID column, set the {@link SubscriptionInfo#getSubscriptionId()}
210          * as the primary key.
211          */
212         public static final String COLUMN_ID = "sudId";
213 
214         /**
215          * The name of the sim slot index column, see
216          * {@link SubscriptionInfo#getSimSlotIndex()}.
217          */
218         public static final String COLUMN_SIM_SLOT_INDEX = "simSlotIndex";
219 
220         /**
221          * The name of the carrier ID column, see {@link SubscriptionInfo#getCarrierId()}.
222          */
223         public static final String COLUMN_CARRIER_ID = "carrierId";
224 
225         /**
226          * The name of the display name column, see {@link SubscriptionInfo#getDisplayName()}.
227          */
228         public static final String COLUMN_DISPLAY_NAME = "displayName";
229 
230         /**
231          * The name of the carrier name column, see {@link SubscriptionInfo#getCarrierName()}.
232          */
233         public static final String COLUMN_CARRIER_NAME = "carrierName";
234 
235         /**
236          * The name of the data roaming state column, see
237          * {@link SubscriptionInfo#getDataRoaming()}.
238          */
239         public static final String COLUMN_DATA_ROAMING = "dataRoaming";
240 
241         /**
242          * The name of the mcc column, see {@link SubscriptionInfo#getMccString()}.
243          */
244         public static final String COLUMN_MCC = "mcc";
245 
246         /**
247          * The name of the mnc column, see {@link SubscriptionInfo#getMncString()}.
248          */
249         public static final String COLUMN_MNC = "mnc";
250 
251         /**
252          * The name of the country ISO column, see {@link SubscriptionInfo#getCountryIso()}.
253          */
254         public static final String COLUMN_COUNTRY_ISO = "countryIso";
255 
256         /**
257          * The name of the embedded state column, see {@link SubscriptionInfo#isEmbedded()}.
258          */
259         public static final String COLUMN_IS_EMBEDDED = "isEmbedded";
260 
261         /**
262          * The name of the card ID column, see {@link SubscriptionInfo#getCardId()}.
263          */
264         public static final String COLUMN_CARD_ID = "cardId";
265 
266         /**
267          * The name of the port index column, see {@link SubscriptionInfo#getPortIndex()}.
268          */
269         public static final String COLUMN_PORT_INDEX = "portIndex";
270 
271         /**
272          * The name of the opportunistic state column, see
273          * {@link SubscriptionInfo#isOpportunistic()}.
274          */
275         public static final String COLUMN_IS_OPPORTUNISTIC = "isOpportunistic";
276 
277         /**
278          * The name of the groupUUID column, see {@link SubscriptionInfo#getGroupUuid()}.
279          */
280         public static final String COLUMN_GROUP_UUID = "groupUUID";
281 
282         /**
283          * The name of the subscription type column, see
284          * {@link SubscriptionInfo#getSubscriptionType()}}.
285          */
286         public static final String COLUMN_SUBSCRIPTION_TYPE = "subscriptionType";
287 
288         /**
289          * The name of the uniqueName column,
290          * {@see SubscriptionUtil#getUniqueSubscriptionDisplayName(SubscriptionInfo, Context)}.
291          */
292         public static final String COLUMN_UNIQUE_NAME = "uniqueName";
293 
294         /**
295          * The name of the subscription visible state column,
296          * {@see SubscriptionUtil#isSubscriptionVisible(SubscriptionManager, Context,
297          * SubscriptionInfo)}.
298          */
299         public static final String COLUMN_IS_SUBSCRIPTION_VISIBLE = "isSubscriptionVisible";
300 
301         /**
302          * The name of the formatted phone number column,
303          * {@see SubscriptionUtil#getFormattedPhoneNumber(Context, SubscriptionInfo)}.
304          */
305         public static final String COLUMN_FORMATTED_PHONE_NUMBER = "getFormattedPhoneNumber";
306 
307         /**
308          * The name of the first removable subscription state column,
309          * {@see SubscriptionUtil#getFirstRemovableSubscription(Context)}.
310          */
311         public static final String COLUMN_IS_FIRST_REMOVABLE_SUBSCRIPTION =
312                 "isFirstRemovableSubscription";
313 
314         /**
315          * The name of the default subscription selection column,
316          * {@see SubscriptionUtil#getSubscriptionOrDefault(Context, int)}.
317          */
318         public static final String COLUMN_IS_DEFAULT_SUBSCRIPTION_SELECTION =
319                 "isDefaultSubscriptionSelection";
320 
321         /**
322          * The name of the valid subscription column,
323          * {@link SubscriptionManager#isValidSubscriptionId(int)}.
324          */
325         public static final String COLUMN_IS_VALID_SUBSCRIPTION = "isValidSubscription";
326 
327         /**
328          * The name of the usable subscription column,
329          * {@link SubscriptionManager#isUsableSubscriptionId(int)}.
330          */
331         public static final String COLUMN_IS_USABLE_SUBSCRIPTION = "isUsableSubscription";
332 
333         /**
334          * The name of the active subscription column,
335          * {@link SubscriptionManager#isActiveSubscriptionId(int)}.
336          */
337         public static final String COLUMN_IS_ACTIVE_SUBSCRIPTION_ID = "isActiveSubscription";
338 
339         /**
340          * The name of the available subscription column,
341          * {@see SubscriptionUtil#getAvailableSubscription(Context, ProxySubscriptionManager, int)}.
342          */
343         public static final String COLUMN_IS_AVAILABLE_SUBSCRIPTION = "isAvailableSubscription";
344 
345         /**
346          * The name of the active data subscription state column, see
347          * {@link SubscriptionManager#getActiveDataSubscriptionId()}.
348          */
349         public static final String COLUMN_IS_ACTIVE_DATA_SUBSCRIPTION =
350                 "isActiveDataSubscriptionId";
351     }
352 }
353