• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 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.internal.telephony.subscription;
18 
19 import static com.google.common.truth.Truth.assertThat;
20 import static com.google.common.truth.Truth.assertWithMessage;
21 
22 import static org.junit.Assert.assertThrows;
23 import static org.mockito.ArgumentMatchers.any;
24 import static org.mockito.ArgumentMatchers.anyInt;
25 import static org.mockito.ArgumentMatchers.eq;
26 import static org.mockito.Mockito.doAnswer;
27 import static org.mockito.Mockito.doReturn;
28 import static org.mockito.Mockito.never;
29 import static org.mockito.Mockito.times;
30 import static org.mockito.Mockito.verify;
31 import static org.mockito.Mockito.when;
32 
33 import android.annotation.NonNull;
34 import android.annotation.Nullable;
35 import android.content.ContentUris;
36 import android.content.ContentValues;
37 import android.database.Cursor;
38 import android.database.MatrixCursor;
39 import android.net.Uri;
40 import android.os.Bundle;
41 import android.os.Looper;
42 import android.provider.Telephony;
43 import android.provider.Telephony.SimInfo;
44 import android.telephony.SubscriptionManager;
45 import android.telephony.UiccAccessRule;
46 import android.telephony.ims.ImsMmTelManager;
47 import android.test.mock.MockContentProvider;
48 import android.test.mock.MockContentResolver;
49 import android.testing.AndroidTestingRunner;
50 import android.testing.TestableLooper;
51 
52 import com.android.internal.telephony.TelephonyTest;
53 import com.android.internal.telephony.flags.FeatureFlags;
54 import com.android.internal.telephony.subscription.SubscriptionDatabaseManager.SubscriptionDatabaseManagerCallback;
55 
56 import org.junit.After;
57 import org.junit.Before;
58 import org.junit.Test;
59 import org.junit.runner.RunWith;
60 import org.mockito.Mockito;
61 
62 import java.lang.reflect.Field;
63 import java.lang.reflect.Modifier;
64 import java.util.ArrayList;
65 import java.util.Arrays;
66 import java.util.List;
67 import java.util.Map;
68 import java.util.concurrent.CountDownLatch;
69 import java.util.concurrent.Executor;
70 
71 @RunWith(AndroidTestingRunner.class)
72 @TestableLooper.RunWithLooper
73 public class SubscriptionDatabaseManagerTest extends TelephonyTest {
74 
75     static final String FAKE_DEFAULT_CARD_NAME = "CARD %d";
76     static final String FAKE_ICCID1 = "123456";
77     static final String FAKE_ICCID2 = "456789";
78     static final String FAKE_PHONE_NUMBER1 = "9995551234";
79     static final String FAKE_PHONE_NUMBER2 = "9998887777";
80     static final String FAKE_CARRIER_NAME1 = "A-Mobile";
81     static final String FAKE_CARRIER_NAME2 = "B-Mobile";
82     static final int FAKE_COLOR1 = 1;
83     static final int FAKE_COLOR2 = 3;
84     static final int FAKE_CARRIER_ID1 = 1234;
85     static final int FAKE_CARRIER_ID2 = 5678;
86     static final String FAKE_COUNTRY_CODE1 = "TW";
87     static final String FAKE_COUNTRY_CODE2 = "US";
88     static final String FAKE_MCC1 = "466";
89     static final String FAKE_MCC2 = "310";
90     static final String FAKE_MNC1 = "01";
91     static final String FAKE_MNC2 = "410";
92     static final String FAKE_EHPLMNS1 = "46602,46603";
93     static final String FAKE_EHPLMNS2 = "310411,310412";
94     static final String FAKE_HPLMNS1 = "46601,46604";
95     static final String FAKE_HPLMNS2 = "310410,310413";
96     static final byte[] FAKE_NATIVE_ACCESS_RULES1 = UiccAccessRule.encodeRules(
97             new UiccAccessRule[]{new UiccAccessRule(new byte[] {}, "package1", 12345L)});
98     static final byte[] FAKE_NATIVE_ACCESS_RULES2 = UiccAccessRule.encodeRules(
99             new UiccAccessRule[]{new UiccAccessRule(new byte[] {}, "package2", 45678L)});
100     static final byte[] FAKE_CARRIER_CONFIG_ACCESS_RULES1 = UiccAccessRule.encodeRules(
101             new UiccAccessRule[]{new UiccAccessRule(new byte[] {}, "package1", 54321L)});
102     static final byte[] FAKE_CARRIER_CONFIG_ACCESS_RULES2 = UiccAccessRule.encodeRules(
103             new UiccAccessRule[]{new UiccAccessRule(new byte[] {}, "package2", 84954L)});
104     static final String FAKE_UUID1 = "a684e31a-5998-4670-abdd-0561252c58a5";
105     static final String FAKE_UUID2 = "cf6d7a9d-e712-4b3c-a600-7a2d4961b5b9";
106     static final String FAKE_OWNER1 = "owner1";
107     static final String FAKE_OWNER2 = "owner2";
108     static final String FAKE_MOBILE_DATA_POLICY1 = "1,2";
109     static final String FAKE_MOBILE_DATA_POLICY2 = "1";
110     static final String FAKE_IMSI1 = "1234";
111     static final String FAKE_IMSI2 = "5678";
112     static final byte[] FAKE_RCS_CONFIG1 = new byte[]{0x01, 0x02, 0x03};
113     static final byte[] FAKE_RCS_CONFIG2 = new byte[]{0x04, 0x05, 0x06};
114     static final String FAKE_ALLOWED_NETWORK_TYPES_FOR_REASONS1 = "carrier=123456, power=3";
115     static final String FAKE_ALLOWED_NETWORK_TYPES_FOR_REASONS2 = "user=1256, enable_2g=3";
116     static final String FAKE_CONTACT1 = "John Smith, Tesla Forrest";
117     static final String FAKE_CONTACT2 = "Mary Jane, Teresa Mill";
118     static final int FAKE_TP_MESSAGE_REFERENCE1 = 123;
119     static final int FAKE_TP_MESSAGE_REFERENCE2 = 456;
120     static final int FAKE_USER_ID1 = 10;
121     static final int FAKE_USER_ID2 = 11;
122     static final int FAKE_SATELLITE_ATTACH_FOR_CARRIER_ENABLED = 1;
123     static final int FAKE_SATELLITE_ATTACH_FOR_CARRIER_DISABLED = 0;
124     static final int FAKE_SATELLITE_IS_ONLY_NTN_ENABLED = 1;
125     static final int FAKE_SATELLITE_IS_ONLY_NTN_DISABLED = 0;
126     static final int FAKE_SERVICE_CAPABILITIES_1 =
127             SubscriptionManager.SERVICE_CAPABILITY_DATA_BITMASK;
128     static final int FAKE_SERVICE_CAPABILITIES_2 =
129             SubscriptionManager.SERVICE_CAPABILITY_SMS_BITMASK;
130     static final int FAKE_SATELLITE_ENTITLEMENT_STATUS_ENABLED = 1;
131     static final int FAKE_SATELLITE_ENTITLEMENT_STATUS_DISABLED = 0;
132     static final String FAKE_SATELLITE_ENTITLEMENT_PLMNS1 = "123123,12310";
133     static final String FAKE_SATELLITE_ENTITLEMENT_PLMNS2 = "";
134     static final int FAKE_SATELLITE_ESOS_SUPPORTED_ENABLED = 1;
135     static final int FAKE_SATELLITE_ESOS_SUPPORTED_DISABLED = 0;
136     static final String FAKE_SATELLITE_ENTITLEMENT_BARRED_PLMNS1 = "321321,32101";
137     static final String FAKE_SATELLITE_ENTITLEMENT_BARRED_PLMNS2 = "";
138     static final String FAKE_SATELLITE_ENTITLEMENT_DATA_PLAN_PLMNS1 =
139             "{\"302820\":0,\"31026\":1,\"40445\":0}";
140     static final String FAKE_SATELLITE_ENTITLEMENT_DATA_PLAN_PLMNS2 = "";
141     static final String FAKE_SATELLITE_ENTITLEMENT_SERVICE_TYPE_MAP1 =
142             "{\"302820\":[1,3],\"31026\":[2,3],\"40445\":[1,3]}";
143     static final String FAKE_SATELLITE_ENTITLEMENT_SERVICE_TYPE_MAP2 = "";
144     static final String FAKE_SATELLITE_ENTITLEMENT_DATA_SERVICE_POLICY1 = "{\"31026\":1}";
145     static final String FAKE_SATELLITE_ENTITLEMENT_DATA_SERVICE_POLICY2 = "";
146     static final String FAKE_SATELLITE_ENTITLEMENT_VOICE_SERVICE_POLICY1 = "{\"31234\":2}";
147     static final String FAKE_SATELLITE_ENTITLEMENT_VOICE_SERVICE_POLICY2 = "";
148 
149     static final String FAKE_MAC_ADDRESS1 = "DC:E5:5B:38:7D:40";
150     static final String FAKE_MAC_ADDRESS2 = "DC:B5:4F:47:F3:4C";
151 
152     private FeatureFlags mFeatureFlags;
153 
154     static final int FAKE_TRANSFER_STATUS_TRANSFERRED_OUT = 1;
155     static final int FAKE_TRANSFER_STATUS_CONVERTED = 2;
156 
157     static final int FAKE_SATELLITE_PROVISIONED = 1;
158     static final int FAKE_SATELLITE_NOT_PROVISIONED = 0;
159 
160     static final SubscriptionInfoInternal FAKE_SUBSCRIPTION_INFO1 =
161             new SubscriptionInfoInternal.Builder()
162                     .setId(1)
163                     .setIccId(FAKE_ICCID1)
164                     .setSimSlotIndex(0)
165                     .setDisplayName(FAKE_CARRIER_NAME1)
166                     .setCarrierName(FAKE_CARRIER_NAME1)
167                     .setDisplayNameSource(SubscriptionManager.NAME_SOURCE_SIM_SPN)
168                     .setIconTint(FAKE_COLOR1)
169                     .setNumber(FAKE_PHONE_NUMBER1)
170                     .setDataRoaming(SubscriptionManager.DATA_ROAMING_ENABLE)
171                     .setMcc(FAKE_MCC1)
172                     .setMnc(FAKE_MNC1)
173                     .setEhplmns(FAKE_EHPLMNS1)
174                     .setHplmns(FAKE_HPLMNS1)
175                     .setEmbedded(1)
176                     .setCardString(FAKE_ICCID1)
177                     .setCardId(1)
178                     .setNativeAccessRules(FAKE_NATIVE_ACCESS_RULES1)
179                     .setCarrierConfigAccessRules(FAKE_CARRIER_CONFIG_ACCESS_RULES1)
180                     .setRemovableEmbedded(0)
181                     .setCellBroadcastExtremeThreatAlertEnabled(1)
182                     .setCellBroadcastSevereThreatAlertEnabled(1)
183                     .setCellBroadcastAmberAlertEnabled(1)
184                     .setCellBroadcastEmergencyAlertEnabled(1)
185                     .setCellBroadcastAlertSoundDuration(4)
186                     .setCellBroadcastAlertReminderInterval(1)
187                     .setCellBroadcastAlertVibrationEnabled(1)
188                     .setCellBroadcastAlertSpeechEnabled(1)
189                     .setCellBroadcastEtwsTestAlertEnabled(1)
190                     .setCellBroadcastAreaInfoMessageEnabled(1)
191                     .setCellBroadcastTestAlertEnabled(1)
192                     .setCellBroadcastOptOutDialogEnabled(1)
193                     .setEnhanced4GModeEnabled(1)
194                     .setVideoTelephonyEnabled(1)
195                     .setWifiCallingEnabled(1)
196                     .setWifiCallingMode(ImsMmTelManager.WIFI_MODE_CELLULAR_PREFERRED)
197                     .setWifiCallingModeForRoaming(ImsMmTelManager.WIFI_MODE_WIFI_PREFERRED)
198                     .setWifiCallingEnabledForRoaming(1)
199                     .setOpportunistic(0)
200                     .setGroupUuid(FAKE_UUID1)
201                     .setCountryIso(FAKE_COUNTRY_CODE1)
202                     .setCarrierId(FAKE_CARRIER_ID1)
203                     .setProfileClass(SubscriptionManager.PROFILE_CLASS_OPERATIONAL)
204                     .setType(SubscriptionManager.SUBSCRIPTION_TYPE_LOCAL_SIM)
205                     .setGroupOwner(FAKE_OWNER1)
206                     .setEnabledMobileDataPolicies(FAKE_MOBILE_DATA_POLICY1)
207                     .setImsi(FAKE_IMSI1)
208                     .setUiccApplicationsEnabled(1)
209                     .setRcsUceEnabled(1)
210                     .setCrossSimCallingEnabled(1)
211                     .setRcsConfig(FAKE_RCS_CONFIG1)
212                     .setAllowedNetworkTypesForReasons(FAKE_ALLOWED_NETWORK_TYPES_FOR_REASONS1)
213                     .setDeviceToDeviceStatusSharingPreference(
214                             SubscriptionManager.D2D_SHARING_ALL_CONTACTS)
215                     .setVoImsOptInEnabled(1)
216                     .setDeviceToDeviceStatusSharingContacts(FAKE_CONTACT1)
217                     .setNrAdvancedCallingEnabled(1)
218                     .setNumberFromCarrier(FAKE_PHONE_NUMBER1)
219                     .setNumberFromIms(FAKE_PHONE_NUMBER1)
220                     .setPortIndex(0)
221                     .setUsageSetting(SubscriptionManager.USAGE_SETTING_DEFAULT)
222                     .setLastUsedTPMessageReference(FAKE_TP_MESSAGE_REFERENCE1)
223                     .setUserId(FAKE_USER_ID1)
224                     .setSatelliteEnabled(0)
225                     .setSatelliteAttachEnabledForCarrier(
226                             FAKE_SATELLITE_ATTACH_FOR_CARRIER_DISABLED)
227                     .setOnlyNonTerrestrialNetwork(FAKE_SATELLITE_IS_ONLY_NTN_DISABLED)
228                     .setGroupDisabled(false)
229                     .setServiceCapabilities(FAKE_SERVICE_CAPABILITIES_1)
230                     .setTransferStatus(FAKE_TRANSFER_STATUS_TRANSFERRED_OUT)
231                     .setSatelliteEntitlementStatus(FAKE_SATELLITE_ENTITLEMENT_STATUS_DISABLED)
232                     .setSatelliteEntitlementPlmns(FAKE_SATELLITE_ENTITLEMENT_PLMNS2)
233                     .setSatelliteESOSSupported(FAKE_SATELLITE_ESOS_SUPPORTED_DISABLED)
234                     .setIsSatelliteProvisionedForNonIpDatagram(FAKE_SATELLITE_NOT_PROVISIONED)
235                     .build();
236 
237     static final SubscriptionInfoInternal FAKE_SUBSCRIPTION_INFO2 =
238             new SubscriptionInfoInternal.Builder()
239                     .setId(2)
240                     .setIccId(FAKE_ICCID2)
241                     .setSimSlotIndex(1)
242                     .setDisplayName(FAKE_CARRIER_NAME2)
243                     .setCarrierName(FAKE_CARRIER_NAME2)
244                     .setDisplayNameSource(SubscriptionManager.NAME_SOURCE_CARRIER)
245                     .setIconTint(FAKE_COLOR2)
246                     .setNumber(FAKE_PHONE_NUMBER2)
247                     .setDataRoaming(SubscriptionManager.DATA_ROAMING_DISABLE)
248                     .setMcc(FAKE_MCC2)
249                     .setMnc(FAKE_MNC2)
250                     .setEhplmns(FAKE_EHPLMNS2)
251                     .setHplmns(FAKE_HPLMNS2)
252                     .setEmbedded(0)
253                     .setCardString(FAKE_ICCID2)
254                     .setCardId(2)
255                     .setNativeAccessRules(FAKE_NATIVE_ACCESS_RULES2)
256                     .setCarrierConfigAccessRules(FAKE_CARRIER_CONFIG_ACCESS_RULES2)
257                     .setRemovableEmbedded(1)
258                     .setCellBroadcastExtremeThreatAlertEnabled(0)
259                     .setCellBroadcastSevereThreatAlertEnabled(0)
260                     .setCellBroadcastAmberAlertEnabled(0)
261                     .setCellBroadcastEmergencyAlertEnabled(0)
262                     .setCellBroadcastAlertSoundDuration(0)
263                     .setCellBroadcastAlertReminderInterval(0)
264                     .setCellBroadcastAlertVibrationEnabled(0)
265                     .setCellBroadcastAlertSpeechEnabled(0)
266                     .setCellBroadcastEtwsTestAlertEnabled(0)
267                     .setCellBroadcastAreaInfoMessageEnabled(0)
268                     .setCellBroadcastTestAlertEnabled(0)
269                     .setCellBroadcastOptOutDialogEnabled(0)
270                     .setEnhanced4GModeEnabled(0)
271                     .setVideoTelephonyEnabled(0)
272                     .setWifiCallingEnabled(0)
273                     .setWifiCallingMode(ImsMmTelManager.WIFI_MODE_WIFI_PREFERRED)
274                     .setWifiCallingModeForRoaming(ImsMmTelManager.WIFI_MODE_CELLULAR_PREFERRED)
275                     .setWifiCallingEnabledForRoaming(0)
276                     .setOpportunistic(1)
277                     .setGroupUuid(FAKE_UUID2)
278                     .setCountryIso(FAKE_COUNTRY_CODE2)
279                     .setCarrierId(FAKE_CARRIER_ID2)
280                     .setProfileClass(SubscriptionManager.PROFILE_CLASS_PROVISIONING)
281                     .setType(SubscriptionManager.SUBSCRIPTION_TYPE_LOCAL_SIM)
282                     .setGroupOwner(FAKE_OWNER2)
283                     .setEnabledMobileDataPolicies(FAKE_MOBILE_DATA_POLICY2)
284                     .setImsi(FAKE_IMSI2)
285                     .setUiccApplicationsEnabled(0)
286                     .setRcsUceEnabled(0)
287                     .setCrossSimCallingEnabled(0)
288                     .setRcsConfig(FAKE_RCS_CONFIG2)
289                     .setAllowedNetworkTypesForReasons(FAKE_ALLOWED_NETWORK_TYPES_FOR_REASONS2)
290                     .setDeviceToDeviceStatusSharingPreference(
291                             SubscriptionManager.D2D_SHARING_SELECTED_CONTACTS)
292                     .setVoImsOptInEnabled(0)
293                     .setDeviceToDeviceStatusSharingContacts(FAKE_CONTACT2)
294                     .setNrAdvancedCallingEnabled(0)
295                     .setNumberFromCarrier(FAKE_PHONE_NUMBER2)
296                     .setNumberFromIms(FAKE_PHONE_NUMBER2)
297                     .setPortIndex(1)
298                     .setUsageSetting(SubscriptionManager.USAGE_SETTING_DATA_CENTRIC)
299                     .setLastUsedTPMessageReference(FAKE_TP_MESSAGE_REFERENCE2)
300                     .setUserId(FAKE_USER_ID2)
301                     .setSatelliteEnabled(1)
302                     .setSatelliteAttachEnabledForCarrier(
303                             FAKE_SATELLITE_ATTACH_FOR_CARRIER_ENABLED)
304                     .setOnlyNonTerrestrialNetwork(FAKE_SATELLITE_IS_ONLY_NTN_ENABLED)
305                     .setGroupDisabled(false)
306                     .setServiceCapabilities(FAKE_SERVICE_CAPABILITIES_2)
307                     .setTransferStatus(FAKE_TRANSFER_STATUS_CONVERTED)
308                     .setSatelliteEntitlementStatus(FAKE_SATELLITE_ENTITLEMENT_STATUS_ENABLED)
309                     .setSatelliteEntitlementPlmns(FAKE_SATELLITE_ENTITLEMENT_PLMNS1)
310                     .setSatelliteESOSSupported(FAKE_SATELLITE_ESOS_SUPPORTED_ENABLED)
311                     .setIsSatelliteProvisionedForNonIpDatagram(FAKE_SATELLITE_PROVISIONED)
312                     .setSatelliteEntitlementBarredPlmnsList(
313                             FAKE_SATELLITE_ENTITLEMENT_BARRED_PLMNS1)
314                     .setSatelliteEntitlementDataPlanForPlmns(
315                             FAKE_SATELLITE_ENTITLEMENT_DATA_PLAN_PLMNS1)
316                     .setSatelliteEntitlementPlmnServiceTypes(
317                             FAKE_SATELLITE_ENTITLEMENT_SERVICE_TYPE_MAP1)
318                     .setSatellitePlmnsDataServicePolicy(
319                             FAKE_SATELLITE_ENTITLEMENT_DATA_SERVICE_POLICY1)
320                     .setSatellitePlmnsVoiceServicePolicy(
321                             FAKE_SATELLITE_ENTITLEMENT_VOICE_SERVICE_POLICY1)
322                     .build();
323 
324     private SubscriptionDatabaseManager mDatabaseManagerUT;
325 
326     private final SubscriptionProvider mSubscriptionProvider = new SubscriptionProvider();
327 
328     //mock
329     private SubscriptionDatabaseManagerCallback mSubscriptionDatabaseManagerCallback;
330 
331     static class SubscriptionProvider extends MockContentProvider {
332         private final List<ContentValues> mDatabase = new ArrayList<>();
333 
334         private final List<String> mAllColumns;
335 
336         private boolean mDatabaseChanged;
337 
SubscriptionProvider()338         SubscriptionProvider() {
339             mAllColumns = SimInfo.getAllColumns();
340         }
341 
342         @Override
query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder)343         public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs,
344                 String sortOrder) {
345             logd("SubscriptionProvider: query. uri=" + uri);
346             if (!SimInfo.CONTENT_URI.equals(uri)) {
347                 throw new UnsupportedOperationException("Unsupported uri=" + uri);
348             }
349             if (projection != null || selection != null || selectionArgs != null) {
350                 throw new UnsupportedOperationException("Only support full database query. "
351                         + "projection=" + Arrays.toString(projection) + ", selection=" + selection
352                         + ", selectionArgs=" + Arrays.toString(selectionArgs));
353             }
354 
355             MatrixCursor mc = new MatrixCursor(mAllColumns.toArray(new String[0]));
356 
357             // Only support full database query
358             for (int row = 0; row < mDatabase.size(); row++) {
359                 List<Object> values = new ArrayList<>();
360                 for (String column : mAllColumns) {
361                     values.add(mDatabase.get(row).get(column));
362                 }
363                 mc.addRow(values);
364             }
365 
366             return mc;
367         }
368 
369         @Override
update(Uri uri, ContentValues values, String where, String[] whereArgs)370         public int update(Uri uri, ContentValues values, String where, String[] whereArgs) {
371             if (!uri.isPathPrefixMatch(SimInfo.CONTENT_URI)) {
372                 throw new UnsupportedOperationException("Unsupported uri=" + uri);
373             }
374 
375             int subId = Integer.parseInt(uri.getLastPathSegment());
376             logd("update: subId=" + subId + ", contentValues=" + values);
377 
378             ContentValues existingValues = mDatabase.stream()
379                     .filter(contentValues -> contentValues.get(
380                             SimInfo.COLUMN_UNIQUE_KEY_SUBSCRIPTION_ID).equals(subId))
381                     .findFirst()
382                     .orElse(null);
383             if (existingValues == null) {
384                 throw new IllegalArgumentException("Invalid sub id " + subId);
385             }
386 
387             for (Map.Entry<String, Object> entry : values.valueSet()) {
388                 String column = entry.getKey();
389                 Object value = entry.getValue();
390                 if (!mAllColumns.contains(column)) {
391                     throw new IllegalArgumentException("Update with unknown column " + column);
392                 }
393                 existingValues.putObject(column, value);
394             }
395             return 1;
396         }
397 
398         @Override
delete(Uri uri, String selection, String[] selectionArgs)399         public int delete(Uri uri, String selection, String[] selectionArgs) {
400             if (!uri.isPathPrefixMatch(SimInfo.CONTENT_URI)) {
401                 throw new UnsupportedOperationException("Unsupported uri=" + uri);
402             }
403 
404             logd("delete: uri=" + uri + ", selection=" + selection + ", selectionArgs="
405                     + Arrays.toString(selectionArgs));
406             if (!selection.equals(SimInfo.COLUMN_UNIQUE_KEY_SUBSCRIPTION_ID + "=?")) {
407                 throw new UnsupportedOperationException("Only support delete by sub id.");
408             }
409 
410             int rowsRemoved = 0;
411             for (String selectionArg : selectionArgs) {
412                 int subId = Integer.parseInt(selectionArg);
413                 // Clear it to null instead of removing it.
414                 rowsRemoved += mDatabase.removeIf(contentValues -> contentValues.get(
415                         SimInfo.COLUMN_UNIQUE_KEY_SUBSCRIPTION_ID).equals(subId)) ? 1 : 0;
416             }
417             return rowsRemoved;
418         }
419 
420         @Override
insert(Uri uri, ContentValues values)421         public Uri insert(Uri uri, ContentValues values) {
422             logd("SubscriptionProvider: insert. uri=" + uri + ", values=" + values);
423             if (!SimInfo.CONTENT_URI.equals(uri)) {
424                 throw new UnsupportedOperationException("Unsupported uri=" + uri);
425             }
426 
427             for (String column : values.keySet()) {
428                 if (!mAllColumns.contains(column)) {
429                     throw new IllegalArgumentException("Insert with unknown column " + column);
430                 }
431             }
432             // The last row's subId + 1
433             int subId;
434             if (mDatabase.isEmpty()) {
435                 subId = 1;
436             } else {
437                 subId = (int) mDatabase.get(mDatabase.size() - 1)
438                         .get(SimInfo.COLUMN_UNIQUE_KEY_SUBSCRIPTION_ID) + 1;
439             }
440             values.put(SimInfo.COLUMN_UNIQUE_KEY_SUBSCRIPTION_ID, subId);
441             mDatabase.add(values);
442             return ContentUris.withAppendedId(SimInfo.CONTENT_URI, subId);
443         }
444 
445         @Override
call(String method, @Nullable String args, @Nullable Bundle bundle)446         public Bundle call(String method, @Nullable String args, @Nullable Bundle bundle) {
447             Bundle result = new Bundle();
448             if (method.equals(SubscriptionManager.RESTORE_SIM_SPECIFIC_SETTINGS_METHOD_NAME)) {
449                 result.putBoolean(
450                         SubscriptionManager.RESTORE_SIM_SPECIFIC_SETTINGS_DATABASE_UPDATED,
451                         mDatabaseChanged);
452             }
453             return result;
454         }
455 
setRestoreDatabaseChanged(boolean changed)456         public void setRestoreDatabaseChanged(boolean changed) {
457             mDatabaseChanged = changed;
458         }
459     }
460 
461     @Before
setUp()462     public void setUp() throws Exception {
463         logd("SubscriptionDatabaseManagerTest +Setup!");
464         super.setUp(getClass().getSimpleName());
465         mContextFixture.putBooleanResource(com.android.internal.R.bool
466                 .config_subscription_database_async_update, true);
467         mSubscriptionDatabaseManagerCallback =
468                 Mockito.mock(SubscriptionDatabaseManagerCallback.class);
469         doAnswer(invocation -> {
470             ((Runnable) invocation.getArguments()[0]).run();
471             return null;
472         }).when(mSubscriptionDatabaseManagerCallback).invokeFromExecutor(any(Runnable.class));
473         mFeatureFlags = Mockito.mock(FeatureFlags.class);
474 
475         ((MockContentResolver) mContext.getContentResolver()).addProvider(
476                 Telephony.Carriers.CONTENT_URI.getAuthority(), mSubscriptionProvider);
477 
478         doReturn(1).when(mUiccController).convertToPublicCardId(eq(FAKE_ICCID1));
479         doReturn(2).when(mUiccController).convertToPublicCardId(eq(FAKE_ICCID2));
480         when(mFeatureFlags.supportPsimToEsimConversion()).thenReturn(true);
481         when(mFeatureFlags.carrierRoamingNbIotNtn()).thenReturn(true);
482         mDatabaseManagerUT = new SubscriptionDatabaseManager(mContext, Looper.myLooper(),
483                 mFeatureFlags, mSubscriptionDatabaseManagerCallback);
484         logd("SubscriptionDatabaseManagerTest -Setup!");
485     }
486 
487     @After
tearDown()488     public void tearDown() throws Exception {
489         super.tearDown();
490     }
491 
492     /**
493      * Verify the subscription from the cache and database is same as the provided one.
494      *
495      * @param subInfo The subscription to compare.
496      */
verifySubscription(@onNull SubscriptionInfoInternal subInfo)497     private void verifySubscription(@NonNull SubscriptionInfoInternal subInfo) throws Exception {
498         int subId = subInfo.getSubscriptionId();
499         // Verify the cache value is same as the inserted one.
500         assertWithMessage("Subscription info cache value is different.")
501                 .that(mDatabaseManagerUT.getSubscriptionInfoInternal(subId)).isEqualTo(subInfo);
502 
503         // Load subscription info from the database.
504         mDatabaseManagerUT.reloadDatabaseSync();
505         processAllMessages();
506 
507         // Verify the database value is same as the inserted one.
508         assertWithMessage("Subscription info database value is different.")
509                 .that(mDatabaseManagerUT.getSubscriptionInfoInternal(subId)).isEqualTo(subInfo);
510     }
511 
512     /**
513      * Insert a subscription info into the database and verify it's in the cache and database.
514      *
515      * @param subInfo The subscription info to insert.
516      * @return The inserted subscription info.
517      */
insertSubscriptionAndVerify( @onNull SubscriptionInfoInternal subInfo)518     private SubscriptionInfoInternal insertSubscriptionAndVerify(
519             @NonNull SubscriptionInfoInternal subInfo) throws Exception {
520         int subId = mDatabaseManagerUT.insertSubscriptionInfo(
521                 new SubscriptionInfoInternal.Builder(subInfo)
522                         .setId(SubscriptionManager.INVALID_SUBSCRIPTION_ID)
523                         .build());
524         assertThat(SubscriptionManager.isValidSubscriptionId(subId)).isTrue();
525 
526         subInfo = new SubscriptionInfoInternal.Builder(subInfo).setId(subId).build();
527         verifySubscription(subInfo);
528         return subInfo;
529     }
530 
531     @Test
testGetAllColumns()532     public void testGetAllColumns() throws Exception {
533         Field[] declaredFields = SimInfo.class.getDeclaredFields();
534         List<String> columnNames = new ArrayList<>();
535         for (Field field : declaredFields) {
536             if (Modifier.isStatic(field.getModifiers()) && field.getName().startsWith("COLUMN_")) {
537                 columnNames.add((String) field.get(null));
538             }
539         }
540         // When you add a new column in Telephony.SimInfo, did you remember to modify
541         // Telephony.SimInfo.getAllColumns() as well?
542         assertThat(SimInfo.getAllColumns()).containsExactlyElementsIn(columnNames);
543     }
544 
545     @Test
testInsertSubscription()546     public void testInsertSubscription() throws Exception {
547         assertThat(insertSubscriptionAndVerify(FAKE_SUBSCRIPTION_INFO1).getSubscriptionId())
548                 .isEqualTo(1);
549         processAllMessages();
550         verify(mSubscriptionDatabaseManagerCallback).onSubscriptionChanged(eq(1));
551         Mockito.clearInvocations(mSubscriptionDatabaseManagerCallback);
552 
553         assertThat(insertSubscriptionAndVerify(FAKE_SUBSCRIPTION_INFO2).getSubscriptionId())
554                 .isEqualTo(2);
555         processAllMessages();
556         verify(mSubscriptionDatabaseManagerCallback).onSubscriptionChanged(eq(2));
557     }
558 
559     @Test
testUpdateSubscription()560     public void testUpdateSubscription() throws Exception {
561         SubscriptionInfoInternal subInfo = new SubscriptionInfoInternal
562                 .Builder(FAKE_SUBSCRIPTION_INFO2)
563                 .setId(1)
564                 .build();
565 
566         // exception is expected if there is nothing in the database.
567         assertThrows(IllegalArgumentException.class,
568                 () -> mDatabaseManagerUT.updateSubscription(subInfo));
569 
570         assertThat(insertSubscriptionAndVerify(FAKE_SUBSCRIPTION_INFO1).getSubscriptionId())
571                 .isEqualTo(1);
572         mDatabaseManagerUT.updateSubscription(subInfo);
573         processAllMessages();
574         verifySubscription(subInfo);
575         verify(mSubscriptionDatabaseManagerCallback, times(2)).onSubscriptionChanged(eq(1));
576         Mockito.clearInvocations(mSubscriptionDatabaseManagerCallback);
577 
578         // Same sub info again. Should not trigger callback
579         mDatabaseManagerUT.updateSubscription(subInfo);
580         verify(mSubscriptionDatabaseManagerCallback, never()).onSubscriptionChanged(anyInt());
581     }
582 
583     @Test
testUpdateSubscriptionSync()584     public void testUpdateSubscriptionSync() throws Exception {
585         mContextFixture.putBooleanResource(com.android.internal.R.bool
586                 .config_subscription_database_async_update, false);
587         mDatabaseManagerUT = new SubscriptionDatabaseManager(mContext, Looper.myLooper(),
588                 mFeatureFlags, mSubscriptionDatabaseManagerCallback);
589 
590         assertThat(insertSubscriptionAndVerify(FAKE_SUBSCRIPTION_INFO1).getSubscriptionId())
591                 .isEqualTo(1);
592         SubscriptionInfoInternal subInfo = new SubscriptionInfoInternal
593                 .Builder(FAKE_SUBSCRIPTION_INFO2)
594                 .setId(1)
595                 .build();
596         mDatabaseManagerUT.updateSubscription(subInfo);
597 
598         verifySubscription(subInfo);
599         verify(mSubscriptionDatabaseManagerCallback, times(2)).onSubscriptionChanged(eq(1));
600         Mockito.clearInvocations(mSubscriptionDatabaseManagerCallback);
601 
602         // Same sub info again. Should not trigger callback
603         mDatabaseManagerUT.updateSubscription(subInfo);
604         verify(mSubscriptionDatabaseManagerCallback, never()).onSubscriptionChanged(anyInt());
605     }
606 
607     @Test
testUpdateIccId()608     public void testUpdateIccId() throws Exception {
609         // exception is expected if there is nothing in the database.
610         assertThrows(IllegalArgumentException.class,
611                 () -> mDatabaseManagerUT.setIccId(1, FAKE_ICCID2));
612 
613         SubscriptionInfoInternal subInfo = insertSubscriptionAndVerify(FAKE_SUBSCRIPTION_INFO1);
614         mDatabaseManagerUT.setIccId(subInfo.getSubscriptionId(), FAKE_ICCID2);
615         processAllMessages();
616 
617         subInfo = new SubscriptionInfoInternal.Builder(subInfo).setIccId(FAKE_ICCID2).build();
618         verifySubscription(subInfo);
619         verify(mSubscriptionDatabaseManagerCallback, times(2)).onSubscriptionChanged(eq(1));
620 
621         assertThat(mDatabaseManagerUT.getSubscriptionProperty(
622                 1, SimInfo.COLUMN_ICC_ID)).isEqualTo(FAKE_ICCID2);
623         mDatabaseManagerUT.setSubscriptionProperty(1, SimInfo.COLUMN_ICC_ID, FAKE_ICCID1);
624         assertThat(mDatabaseManagerUT.getSubscriptionInfoInternal(1).getIccId())
625                 .isEqualTo(FAKE_ICCID1);
626     }
627 
628     @Test
testUpdateSimSlotIndex()629     public void testUpdateSimSlotIndex() throws Exception {
630         // exception is expected if there is nothing in the database.
631         assertThrows(IllegalArgumentException.class,
632                 () -> mDatabaseManagerUT.setSimSlotIndex(1,
633                         SubscriptionManager.INVALID_SIM_SLOT_INDEX));
634 
635         SubscriptionInfoInternal subInfo = insertSubscriptionAndVerify(FAKE_SUBSCRIPTION_INFO1);
636         mDatabaseManagerUT.setSimSlotIndex(subInfo.getSubscriptionId(),
637                 SubscriptionManager.INVALID_SIM_SLOT_INDEX);
638         processAllMessages();
639 
640         subInfo = new SubscriptionInfoInternal.Builder(subInfo).setSimSlotIndex(
641                 SubscriptionManager.INVALID_SIM_SLOT_INDEX).build();
642         verifySubscription(subInfo);
643         verify(mSubscriptionDatabaseManagerCallback, times(2)).onSubscriptionChanged(eq(1));
644 
645         assertThat(mDatabaseManagerUT.getSubscriptionProperty(
646                 1, SimInfo.COLUMN_SIM_SLOT_INDEX))
647                 .isEqualTo(SubscriptionManager.INVALID_SIM_SLOT_INDEX);
648         mDatabaseManagerUT.setSubscriptionProperty(1, SimInfo.COLUMN_SIM_SLOT_INDEX, 123);
649         assertThat(mDatabaseManagerUT.getSubscriptionInfoInternal(1).getSimSlotIndex())
650                 .isEqualTo(123);
651     }
652 
653     @Test
testUpdateDisplayName()654     public void testUpdateDisplayName() throws Exception {
655         // exception is expected if there is nothing in the database.
656         assertThrows(IllegalArgumentException.class,
657                 () -> mDatabaseManagerUT.setDisplayName(1, FAKE_CARRIER_NAME2));
658 
659         SubscriptionInfoInternal subInfo = insertSubscriptionAndVerify(FAKE_SUBSCRIPTION_INFO1);
660         mDatabaseManagerUT.setDisplayName(subInfo.getSubscriptionId(), FAKE_CARRIER_NAME2);
661         processAllMessages();
662 
663         subInfo = new SubscriptionInfoInternal.Builder(subInfo).setDisplayName(
664                 FAKE_CARRIER_NAME2).build();
665         verifySubscription(subInfo);
666         verify(mSubscriptionDatabaseManagerCallback, times(2)).onSubscriptionChanged(eq(1));
667 
668         assertThat(mDatabaseManagerUT.getSubscriptionProperty(1, SimInfo.COLUMN_DISPLAY_NAME))
669                 .isEqualTo(FAKE_CARRIER_NAME2);
670         mDatabaseManagerUT.setSubscriptionProperty(
671                 1, SimInfo.COLUMN_DISPLAY_NAME, FAKE_CARRIER_NAME1);
672         assertThat(mDatabaseManagerUT.getSubscriptionInfoInternal(1).getDisplayName())
673                 .isEqualTo(FAKE_CARRIER_NAME1);
674     }
675 
676     @Test
testUpdateCarrierName()677     public void testUpdateCarrierName() throws Exception {
678         // exception is expected if there is nothing in the database.
679         assertThrows(IllegalArgumentException.class,
680                 () -> mDatabaseManagerUT.setCarrierName(1, FAKE_CARRIER_NAME2));
681 
682         SubscriptionInfoInternal subInfo = insertSubscriptionAndVerify(FAKE_SUBSCRIPTION_INFO1);
683         mDatabaseManagerUT.setCarrierName(subInfo.getSubscriptionId(), FAKE_CARRIER_NAME2);
684         processAllMessages();
685 
686         subInfo = new SubscriptionInfoInternal.Builder(subInfo).setCarrierName(
687                 FAKE_CARRIER_NAME2).build();
688         verifySubscription(subInfo);
689         verify(mSubscriptionDatabaseManagerCallback, times(2)).onSubscriptionChanged(eq(1));
690 
691         assertThat(mDatabaseManagerUT.getSubscriptionProperty(1, SimInfo.COLUMN_CARRIER_NAME))
692                 .isEqualTo(FAKE_CARRIER_NAME2);
693         mDatabaseManagerUT.setSubscriptionProperty(
694                 1, SimInfo.COLUMN_CARRIER_NAME, FAKE_CARRIER_NAME1);
695         assertThat(mDatabaseManagerUT.getSubscriptionInfoInternal(1).getCarrierName())
696                 .isEqualTo(FAKE_CARRIER_NAME1);
697     }
698 
699     @Test
testUpdateDisplayNameSource()700     public void testUpdateDisplayNameSource() throws Exception {
701         // exception is expected if there is nothing in the database.
702         assertThrows(IllegalArgumentException.class,
703                 () -> mDatabaseManagerUT.setDisplayNameSource(1,
704                         SubscriptionManager.NAME_SOURCE_USER_INPUT));
705 
706         SubscriptionInfoInternal subInfo = insertSubscriptionAndVerify(FAKE_SUBSCRIPTION_INFO1);
707         mDatabaseManagerUT.setDisplayNameSource(subInfo.getSubscriptionId(),
708                 SubscriptionManager.NAME_SOURCE_USER_INPUT);
709         processAllMessages();
710 
711         subInfo = new SubscriptionInfoInternal.Builder(subInfo).setDisplayNameSource(
712                 SubscriptionManager.NAME_SOURCE_USER_INPUT).build();
713         verifySubscription(subInfo);
714         verify(mSubscriptionDatabaseManagerCallback, times(2)).onSubscriptionChanged(eq(1));
715 
716         assertThat(mDatabaseManagerUT.getSubscriptionProperty(1, SimInfo.COLUMN_NAME_SOURCE))
717                 .isEqualTo(SubscriptionManager.NAME_SOURCE_USER_INPUT);
718         mDatabaseManagerUT.setSubscriptionProperty(
719                 1, SimInfo.COLUMN_NAME_SOURCE, SubscriptionManager.NAME_SOURCE_SIM_PNN);
720         assertThat(mDatabaseManagerUT.getSubscriptionInfoInternal(1).getDisplayNameSource())
721                 .isEqualTo(SubscriptionManager.NAME_SOURCE_SIM_PNN);
722     }
723 
724     @Test
testUpdateIconTint()725     public void testUpdateIconTint() throws Exception {
726         // exception is expected if there is nothing in the database.
727         assertThrows(IllegalArgumentException.class,
728                 () -> mDatabaseManagerUT.setIconTint(1, FAKE_COLOR2));
729 
730         SubscriptionInfoInternal subInfo = insertSubscriptionAndVerify(FAKE_SUBSCRIPTION_INFO1);
731         mDatabaseManagerUT.setIconTint(subInfo.getSubscriptionId(), FAKE_COLOR2);
732         processAllMessages();
733 
734         subInfo = new SubscriptionInfoInternal.Builder(subInfo).setIconTint(FAKE_COLOR2).build();
735         verifySubscription(subInfo);
736         verify(mSubscriptionDatabaseManagerCallback, times(2)).onSubscriptionChanged(eq(1));
737 
738         assertThat(mDatabaseManagerUT.getSubscriptionProperty(1, SimInfo.COLUMN_COLOR))
739                 .isEqualTo(FAKE_COLOR2);
740         mDatabaseManagerUT.setSubscriptionProperty(
741                 1, SimInfo.COLUMN_COLOR, FAKE_COLOR1);
742         assertThat(mDatabaseManagerUT.getSubscriptionInfoInternal(1).getIconTint())
743                 .isEqualTo(FAKE_COLOR1);
744     }
745 
746     @Test
testUpdateNumber()747     public void testUpdateNumber() throws Exception {
748         // exception is expected if there is nothing in the database.
749         assertThrows(IllegalArgumentException.class,
750                 () -> mDatabaseManagerUT.setNumber(1, FAKE_PHONE_NUMBER2));
751 
752         // Prevent the carrier number from overriding the display number
753         SubscriptionInfoInternal subInfo = insertSubscriptionAndVerify(
754                 new SubscriptionInfoInternal.Builder(FAKE_SUBSCRIPTION_INFO1)
755                         .setNumberFromCarrier("").build());
756         mDatabaseManagerUT.setNumber(subInfo.getSubscriptionId(), FAKE_PHONE_NUMBER2);
757         processAllMessages();
758 
759         subInfo = new SubscriptionInfoInternal.Builder(subInfo)
760                 .setNumber(FAKE_PHONE_NUMBER2).build();
761         verifySubscription(subInfo);
762         verify(mSubscriptionDatabaseManagerCallback, times(2)).onSubscriptionChanged(eq(1));
763 
764         assertThat(mDatabaseManagerUT.getSubscriptionProperty(1, SimInfo.COLUMN_NUMBER))
765                 .isEqualTo(FAKE_PHONE_NUMBER2);
766         mDatabaseManagerUT.setSubscriptionProperty(
767                 1, SimInfo.COLUMN_NUMBER, FAKE_PHONE_NUMBER1);
768         assertThat(mDatabaseManagerUT.getSubscriptionInfoInternal(1).getNumber())
769                 .isEqualTo(FAKE_PHONE_NUMBER1);
770     }
771 
772     @Test
testUpdateDataRoaming()773     public void testUpdateDataRoaming() throws Exception {
774         // exception is expected if there is nothing in the database.
775         assertThrows(IllegalArgumentException.class,
776                 () -> mDatabaseManagerUT.setDataRoaming(1,
777                         SubscriptionManager.DATA_ROAMING_DISABLE));
778 
779         SubscriptionInfoInternal subInfo = insertSubscriptionAndVerify(FAKE_SUBSCRIPTION_INFO1);
780         mDatabaseManagerUT.setDataRoaming(subInfo.getSubscriptionId(),
781                 SubscriptionManager.DATA_ROAMING_DISABLE);
782         processAllMessages();
783 
784         subInfo = new SubscriptionInfoInternal.Builder(subInfo)
785                 .setDataRoaming(SubscriptionManager.DATA_ROAMING_DISABLE).build();
786         verifySubscription(subInfo);
787         verify(mSubscriptionDatabaseManagerCallback, times(2)).onSubscriptionChanged(eq(1));
788 
789         assertThat(mDatabaseManagerUT.getSubscriptionProperty(1, SimInfo.COLUMN_DATA_ROAMING))
790                 .isEqualTo(SubscriptionManager.DATA_ROAMING_DISABLE);
791         mDatabaseManagerUT.setSubscriptionProperty(
792                 1, SimInfo.COLUMN_DATA_ROAMING, SubscriptionManager.DATA_ROAMING_ENABLE);
793         assertThat(mDatabaseManagerUT.getSubscriptionInfoInternal(1).getDataRoaming())
794                 .isEqualTo(SubscriptionManager.DATA_ROAMING_ENABLE);
795     }
796 
797     @Test
testUpdateMcc()798     public void testUpdateMcc() throws Exception {
799         // exception is expected if there is nothing in the database.
800         assertThrows(IllegalArgumentException.class,
801                 () -> mDatabaseManagerUT.setMcc(1, FAKE_MCC2));
802 
803         SubscriptionInfoInternal subInfo = insertSubscriptionAndVerify(FAKE_SUBSCRIPTION_INFO1);
804         mDatabaseManagerUT.setMcc(subInfo.getSubscriptionId(), FAKE_MCC2);
805         processAllMessages();
806 
807         subInfo = new SubscriptionInfoInternal.Builder(subInfo).setMcc(FAKE_MCC2).build();
808         verifySubscription(subInfo);
809         verify(mSubscriptionDatabaseManagerCallback, times(2)).onSubscriptionChanged(eq(1));
810 
811         assertThat(mDatabaseManagerUT.getSubscriptionProperty(1, SimInfo.COLUMN_MCC_STRING))
812                 .isEqualTo(FAKE_MCC2);
813         mDatabaseManagerUT.setSubscriptionProperty(
814                 1, SimInfo.COLUMN_MCC_STRING, FAKE_MCC1);
815         assertThat(mDatabaseManagerUT.getSubscriptionInfoInternal(1).getMcc())
816                 .isEqualTo(FAKE_MCC1);
817     }
818 
819     @Test
testUpdateMnc()820     public void testUpdateMnc() throws Exception {
821         // exception is expected if there is nothing in the database.
822         assertThrows(IllegalArgumentException.class,
823                 () -> mDatabaseManagerUT.setMnc(1, FAKE_MNC2));
824 
825         SubscriptionInfoInternal subInfo = insertSubscriptionAndVerify(FAKE_SUBSCRIPTION_INFO1);
826         mDatabaseManagerUT.setMnc(subInfo.getSubscriptionId(), FAKE_MNC2);
827         processAllMessages();
828 
829         subInfo = new SubscriptionInfoInternal.Builder(subInfo).setMnc(FAKE_MNC2).build();
830         verifySubscription(subInfo);
831         verify(mSubscriptionDatabaseManagerCallback, times(2)).onSubscriptionChanged(eq(1));
832 
833         assertThat(mDatabaseManagerUT.getSubscriptionProperty(1, SimInfo.COLUMN_MNC_STRING))
834                 .isEqualTo(FAKE_MNC2);
835         mDatabaseManagerUT.setSubscriptionProperty(
836                 1, SimInfo.COLUMN_MNC_STRING, FAKE_MNC1);
837         assertThat(mDatabaseManagerUT.getSubscriptionInfoInternal(1).getMnc())
838                 .isEqualTo(FAKE_MNC1);
839     }
840 
841     @Test
testUpdateEhplmns()842     public void testUpdateEhplmns() throws Exception {
843         // exception is expected if there is nothing in the database.
844         assertThrows(IllegalArgumentException.class,
845                 () -> mDatabaseManagerUT.setEhplmns(1, FAKE_EHPLMNS2));
846 
847         SubscriptionInfoInternal subInfo = insertSubscriptionAndVerify(FAKE_SUBSCRIPTION_INFO1);
848         mDatabaseManagerUT.setEhplmns(subInfo.getSubscriptionId(), FAKE_EHPLMNS2);
849         processAllMessages();
850 
851         subInfo = new SubscriptionInfoInternal.Builder(subInfo).setEhplmns(FAKE_EHPLMNS2).build();
852         verifySubscription(subInfo);
853         verify(mSubscriptionDatabaseManagerCallback, times(2)).onSubscriptionChanged(eq(1));
854 
855         assertThat(mDatabaseManagerUT.getSubscriptionProperty(1, SimInfo.COLUMN_EHPLMNS))
856                 .isEqualTo(FAKE_EHPLMNS2);
857         mDatabaseManagerUT.setSubscriptionProperty(
858                 1, SimInfo.COLUMN_EHPLMNS, FAKE_EHPLMNS1);
859         assertThat(mDatabaseManagerUT.getSubscriptionInfoInternal(1).getEhplmns())
860                 .isEqualTo(FAKE_EHPLMNS1);
861     }
862 
863     @Test
testUpdateHplmns()864     public void testUpdateHplmns() throws Exception {
865         // exception is expected if there is nothing in the database.
866         assertThrows(IllegalArgumentException.class,
867                 () -> mDatabaseManagerUT.setHplmns(1, FAKE_HPLMNS2));
868 
869         SubscriptionInfoInternal subInfo = insertSubscriptionAndVerify(FAKE_SUBSCRIPTION_INFO1);
870         mDatabaseManagerUT.setHplmns(subInfo.getSubscriptionId(), FAKE_HPLMNS2);
871         processAllMessages();
872 
873         subInfo = new SubscriptionInfoInternal.Builder(subInfo).setHplmns(FAKE_HPLMNS2).build();
874         verifySubscription(subInfo);
875         verify(mSubscriptionDatabaseManagerCallback, times(2)).onSubscriptionChanged(eq(1));
876 
877         assertThat(mDatabaseManagerUT.getSubscriptionProperty(1, SimInfo.COLUMN_HPLMNS))
878                 .isEqualTo(FAKE_HPLMNS2);
879         mDatabaseManagerUT.setSubscriptionProperty(
880                 1, SimInfo.COLUMN_HPLMNS, FAKE_HPLMNS1);
881         assertThat(mDatabaseManagerUT.getSubscriptionInfoInternal(1).getHplmns())
882                 .isEqualTo(FAKE_HPLMNS1);
883     }
884 
885     @Test
testUpdateEmbedded()886     public void testUpdateEmbedded() throws Exception {
887         // exception is expected if there is nothing in the database.
888         assertThrows(IllegalArgumentException.class,
889                 () -> mDatabaseManagerUT.setEmbedded(1, false));
890 
891         SubscriptionInfoInternal subInfo = insertSubscriptionAndVerify(FAKE_SUBSCRIPTION_INFO1);
892         mDatabaseManagerUT.setEmbedded(subInfo.getSubscriptionId(), false);
893         processAllMessages();
894 
895         subInfo = new SubscriptionInfoInternal.Builder(subInfo).setEmbedded(0).build();
896         verifySubscription(subInfo);
897         verify(mSubscriptionDatabaseManagerCallback, times(2)).onSubscriptionChanged(eq(1));
898 
899         assertThat(mDatabaseManagerUT.getSubscriptionProperty(1, SimInfo.COLUMN_IS_EMBEDDED))
900                 .isEqualTo(0);
901         mDatabaseManagerUT.setSubscriptionProperty(
902                 1, SimInfo.COLUMN_IS_EMBEDDED, 1);
903         assertThat(mDatabaseManagerUT.getSubscriptionInfoInternal(1).getEmbedded())
904                 .isEqualTo(1);
905     }
906 
907     @Test
testUpdateCardString()908     public void testUpdateCardString() throws Exception {
909         // exception is expected if there is nothing in the database.
910         assertThrows(IllegalArgumentException.class,
911                 () -> mDatabaseManagerUT.setCardString(1, FAKE_ICCID2));
912 
913         SubscriptionInfoInternal subInfo = insertSubscriptionAndVerify(FAKE_SUBSCRIPTION_INFO1);
914         mDatabaseManagerUT.setCardString(subInfo.getSubscriptionId(), FAKE_ICCID2);
915         processAllMessages();
916 
917         subInfo = new SubscriptionInfoInternal.Builder(subInfo)
918                 .setCardString(FAKE_ICCID2)
919                 .setCardId(2)
920                 .build();
921         verifySubscription(subInfo);
922         verify(mSubscriptionDatabaseManagerCallback, times(2)).onSubscriptionChanged(eq(1));
923 
924         assertThat(mDatabaseManagerUT.getSubscriptionProperty(1, SimInfo.COLUMN_CARD_ID))
925                 .isEqualTo(FAKE_ICCID2);
926         mDatabaseManagerUT.setSubscriptionProperty(
927                 1, SimInfo.COLUMN_CARD_ID, FAKE_ICCID1);
928         assertThat(mDatabaseManagerUT.getSubscriptionInfoInternal(1).getCardString())
929                 .isEqualTo(FAKE_ICCID1);
930     }
931 
932     @Test
testUpdateNativeAccessRules()933     public void testUpdateNativeAccessRules() throws Exception {
934         // exception is expected if there is nothing in the database.
935         assertThrows(IllegalArgumentException.class,
936                 () -> mDatabaseManagerUT.setNativeAccessRules(1, FAKE_NATIVE_ACCESS_RULES2));
937 
938         SubscriptionInfoInternal subInfo = insertSubscriptionAndVerify(FAKE_SUBSCRIPTION_INFO1);
939         mDatabaseManagerUT.setNativeAccessRules(subInfo.getSubscriptionId(),
940                 FAKE_NATIVE_ACCESS_RULES2);
941         processAllMessages();
942 
943         subInfo = new SubscriptionInfoInternal.Builder(subInfo)
944                 .setNativeAccessRules(FAKE_NATIVE_ACCESS_RULES2).build();
945         verifySubscription(subInfo);
946         verify(mSubscriptionDatabaseManagerCallback, times(2)).onSubscriptionChanged(eq(1));
947 
948         assertThat(mDatabaseManagerUT.getSubscriptionProperty(1, SimInfo.COLUMN_ACCESS_RULES))
949                 .isEqualTo(FAKE_NATIVE_ACCESS_RULES2);
950         mDatabaseManagerUT.setSubscriptionProperty(
951                 1, SimInfo.COLUMN_ACCESS_RULES, FAKE_NATIVE_ACCESS_RULES1);
952         assertThat(mDatabaseManagerUT.getSubscriptionInfoInternal(1).getNativeAccessRules())
953                 .isEqualTo(FAKE_NATIVE_ACCESS_RULES1);
954     }
955 
956     @Test
testUpdateCarrierConfigAccessRules()957     public void testUpdateCarrierConfigAccessRules() throws Exception {
958         // exception is expected if there is nothing in the database.
959         assertThrows(IllegalArgumentException.class,
960                 () -> mDatabaseManagerUT.setCarrierConfigAccessRules(1,
961                         FAKE_CARRIER_CONFIG_ACCESS_RULES2));
962 
963         SubscriptionInfoInternal subInfo = insertSubscriptionAndVerify(FAKE_SUBSCRIPTION_INFO1);
964         mDatabaseManagerUT.setCarrierConfigAccessRules(subInfo.getSubscriptionId(),
965                 FAKE_CARRIER_CONFIG_ACCESS_RULES2);
966         processAllMessages();
967 
968         subInfo = new SubscriptionInfoInternal.Builder(subInfo)
969                 .setCarrierConfigAccessRules(FAKE_CARRIER_CONFIG_ACCESS_RULES2).build();
970         verifySubscription(subInfo);
971         verify(mSubscriptionDatabaseManagerCallback, times(2)).onSubscriptionChanged(eq(1));
972 
973         assertThat(mDatabaseManagerUT.getSubscriptionProperty(
974                 1, SimInfo.COLUMN_ACCESS_RULES_FROM_CARRIER_CONFIGS))
975                 .isEqualTo(FAKE_CARRIER_CONFIG_ACCESS_RULES2);
976         mDatabaseManagerUT.setSubscriptionProperty(1,
977                 SimInfo.COLUMN_ACCESS_RULES_FROM_CARRIER_CONFIGS,
978                 FAKE_CARRIER_CONFIG_ACCESS_RULES2);
979         assertThat(mDatabaseManagerUT.getSubscriptionInfoInternal(1).getCarrierConfigAccessRules())
980                 .isEqualTo(FAKE_CARRIER_CONFIG_ACCESS_RULES2);
981     }
982 
983     @Test
testUpdateRemovableEmbedded()984     public void testUpdateRemovableEmbedded() throws Exception {
985         // exception is expected if there is nothing in the database.
986         assertThrows(IllegalArgumentException.class,
987                 () -> mDatabaseManagerUT.setRemovableEmbedded(1, 1));
988 
989         SubscriptionInfoInternal subInfo = insertSubscriptionAndVerify(FAKE_SUBSCRIPTION_INFO1);
990         mDatabaseManagerUT.setRemovableEmbedded(subInfo.getSubscriptionId(), 1);
991         processAllMessages();
992 
993         subInfo = new SubscriptionInfoInternal.Builder(subInfo).setRemovableEmbedded(1).build();
994         verifySubscription(subInfo);
995         verify(mSubscriptionDatabaseManagerCallback, times(2)).onSubscriptionChanged(eq(1));
996 
997         assertThat(mDatabaseManagerUT.getSubscriptionProperty(1, SimInfo.COLUMN_IS_REMOVABLE))
998                 .isEqualTo(1);
999         mDatabaseManagerUT.setSubscriptionProperty(1, SimInfo.COLUMN_IS_REMOVABLE, 0);
1000         assertThat(mDatabaseManagerUT.getSubscriptionInfoInternal(1).getRemovableEmbedded())
1001                 .isEqualTo(0);
1002     }
1003 
1004     @Test
testUpdateCellBroadcastExtremeThreatAlertEnabled()1005     public void testUpdateCellBroadcastExtremeThreatAlertEnabled() throws Exception {
1006         // exception is expected if there is nothing in the database.
1007         assertThrows(IllegalArgumentException.class,
1008                 () -> mDatabaseManagerUT.setCellBroadcastExtremeThreatAlertEnabled(1, 1));
1009 
1010         SubscriptionInfoInternal subInfo = insertSubscriptionAndVerify(FAKE_SUBSCRIPTION_INFO1);
1011         mDatabaseManagerUT.setCellBroadcastExtremeThreatAlertEnabled(
1012                 subInfo.getSubscriptionId(), 0);
1013         processAllMessages();
1014 
1015         subInfo = new SubscriptionInfoInternal.Builder(subInfo)
1016                 .setCellBroadcastExtremeThreatAlertEnabled(0).build();
1017         verifySubscription(subInfo);
1018         verify(mSubscriptionDatabaseManagerCallback, times(2)).onSubscriptionChanged(eq(1));
1019 
1020         assertThat(mDatabaseManagerUT.getSubscriptionProperty(
1021                 1, SimInfo.COLUMN_CB_EXTREME_THREAT_ALERT))
1022                 .isEqualTo(0);
1023         mDatabaseManagerUT.setSubscriptionProperty(1, SimInfo.COLUMN_CB_EXTREME_THREAT_ALERT, 1);
1024         assertThat(mDatabaseManagerUT.getSubscriptionInfoInternal(1)
1025                 .getCellBroadcastExtremeThreatAlertEnabled()).isEqualTo(1);
1026     }
1027 
1028     @Test
testUpdateCellBroadcastSevereThreatAlertEnabled()1029     public void testUpdateCellBroadcastSevereThreatAlertEnabled() throws Exception {
1030         // exception is expected if there is nothing in the database.
1031         assertThrows(IllegalArgumentException.class,
1032                 () -> mDatabaseManagerUT.setCellBroadcastSevereThreatAlertEnabled(1, 1));
1033 
1034         SubscriptionInfoInternal subInfo = insertSubscriptionAndVerify(FAKE_SUBSCRIPTION_INFO1);
1035         mDatabaseManagerUT.setCellBroadcastSevereThreatAlertEnabled(
1036                 subInfo.getSubscriptionId(), 0);
1037         processAllMessages();
1038 
1039         subInfo = new SubscriptionInfoInternal.Builder(subInfo)
1040                 .setCellBroadcastSevereThreatAlertEnabled(0).build();
1041         verifySubscription(subInfo);
1042         verify(mSubscriptionDatabaseManagerCallback, times(2)).onSubscriptionChanged(eq(1));
1043 
1044         assertThat(mDatabaseManagerUT.getSubscriptionProperty(
1045                 1, SimInfo.COLUMN_CB_SEVERE_THREAT_ALERT))
1046                 .isEqualTo(0);
1047         mDatabaseManagerUT.setSubscriptionProperty(1, SimInfo.COLUMN_CB_SEVERE_THREAT_ALERT, 1);
1048         assertThat(mDatabaseManagerUT.getSubscriptionInfoInternal(1)
1049                 .getCellBroadcastSevereThreatAlertEnabled()).isEqualTo(1);
1050     }
1051 
1052     @Test
testUpdateCellBroadcastAmberAlertEnabled()1053     public void testUpdateCellBroadcastAmberAlertEnabled() throws Exception {
1054         // exception is expected if there is nothing in the database.
1055         assertThrows(IllegalArgumentException.class,
1056                 () -> mDatabaseManagerUT.setCellBroadcastAmberAlertEnabled(1, 1));
1057 
1058         SubscriptionInfoInternal subInfo = insertSubscriptionAndVerify(FAKE_SUBSCRIPTION_INFO1);
1059         mDatabaseManagerUT.setCellBroadcastAmberAlertEnabled(
1060                 subInfo.getSubscriptionId(), 0);
1061         processAllMessages();
1062 
1063         subInfo = new SubscriptionInfoInternal.Builder(subInfo)
1064                 .setCellBroadcastAmberAlertEnabled(0).build();
1065         verifySubscription(subInfo);
1066         verify(mSubscriptionDatabaseManagerCallback, times(2)).onSubscriptionChanged(eq(1));
1067 
1068         assertThat(mDatabaseManagerUT.getSubscriptionProperty(
1069                 1, SimInfo.COLUMN_CB_AMBER_ALERT))
1070                 .isEqualTo(0);
1071         mDatabaseManagerUT.setSubscriptionProperty(1, SimInfo.COLUMN_CB_AMBER_ALERT, 1);
1072         assertThat(mDatabaseManagerUT.getSubscriptionInfoInternal(1)
1073                 .getCellBroadcastAmberAlertEnabled()).isEqualTo(1);
1074     }
1075 
1076     @Test
testUpdateCellBroadcastEmergencyAlertEnabled()1077     public void testUpdateCellBroadcastEmergencyAlertEnabled() throws Exception {
1078         // exception is expected if there is nothing in the database.
1079         assertThrows(IllegalArgumentException.class,
1080                 () -> mDatabaseManagerUT.setCellBroadcastEmergencyAlertEnabled(1, 1));
1081 
1082         SubscriptionInfoInternal subInfo = insertSubscriptionAndVerify(FAKE_SUBSCRIPTION_INFO1);
1083         mDatabaseManagerUT.setCellBroadcastEmergencyAlertEnabled(
1084                 subInfo.getSubscriptionId(), 0);
1085         processAllMessages();
1086 
1087         subInfo = new SubscriptionInfoInternal.Builder(subInfo)
1088                 .setCellBroadcastEmergencyAlertEnabled(0).build();
1089         verifySubscription(subInfo);
1090         verify(mSubscriptionDatabaseManagerCallback, times(2)).onSubscriptionChanged(eq(1));
1091 
1092         assertThat(mDatabaseManagerUT.getSubscriptionProperty(
1093                 1, SimInfo.COLUMN_CB_EMERGENCY_ALERT))
1094                 .isEqualTo(0);
1095         mDatabaseManagerUT.setSubscriptionProperty(1, SimInfo.COLUMN_CB_EMERGENCY_ALERT, 1);
1096         assertThat(mDatabaseManagerUT.getSubscriptionInfoInternal(1)
1097                 .getCellBroadcastEmergencyAlertEnabled()).isEqualTo(1);
1098     }
1099 
1100     @Test
testUpdateCellBroadcastAlertSoundDuration()1101     public void testUpdateCellBroadcastAlertSoundDuration() throws Exception {
1102         // exception is expected if there is nothing in the database.
1103         assertThrows(IllegalArgumentException.class,
1104                 () -> mDatabaseManagerUT.setCellBroadcastAlertSoundDuration(1, 1));
1105 
1106         SubscriptionInfoInternal subInfo = insertSubscriptionAndVerify(FAKE_SUBSCRIPTION_INFO1);
1107         mDatabaseManagerUT.setCellBroadcastAlertSoundDuration(
1108                 subInfo.getSubscriptionId(), 0);
1109         processAllMessages();
1110 
1111         subInfo = new SubscriptionInfoInternal.Builder(subInfo)
1112                 .setCellBroadcastAlertSoundDuration(0).build();
1113         verifySubscription(subInfo);
1114         verify(mSubscriptionDatabaseManagerCallback, times(2)).onSubscriptionChanged(eq(1));
1115 
1116         assertThat(mDatabaseManagerUT.getSubscriptionProperty(
1117                 1, SimInfo.COLUMN_CB_ALERT_SOUND_DURATION))
1118                 .isEqualTo(0);
1119         mDatabaseManagerUT.setSubscriptionProperty(1, SimInfo.COLUMN_CB_ALERT_SOUND_DURATION, 1);
1120         assertThat(mDatabaseManagerUT.getSubscriptionInfoInternal(1)
1121                 .getCellBroadcastAlertSoundDuration()).isEqualTo(1);
1122     }
1123 
1124     @Test
testUpdateCellBroadcastAlertReminderInterval()1125     public void testUpdateCellBroadcastAlertReminderInterval() throws Exception {
1126         // exception is expected if there is nothing in the database.
1127         assertThrows(IllegalArgumentException.class,
1128                 () -> mDatabaseManagerUT.setCellBroadcastAlertReminderInterval(1, 1));
1129 
1130         SubscriptionInfoInternal subInfo = insertSubscriptionAndVerify(FAKE_SUBSCRIPTION_INFO1);
1131         mDatabaseManagerUT.setCellBroadcastAlertReminderInterval(
1132                 subInfo.getSubscriptionId(), 0);
1133         processAllMessages();
1134 
1135         subInfo = new SubscriptionInfoInternal.Builder(subInfo)
1136                 .setCellBroadcastAlertReminderInterval(0).build();
1137         verifySubscription(subInfo);
1138         verify(mSubscriptionDatabaseManagerCallback, times(2)).onSubscriptionChanged(eq(1));
1139 
1140         assertThat(mDatabaseManagerUT.getSubscriptionProperty(
1141                 1, SimInfo.COLUMN_CB_ALERT_REMINDER_INTERVAL))
1142                 .isEqualTo(0);
1143         mDatabaseManagerUT.setSubscriptionProperty(1, SimInfo.COLUMN_CB_ALERT_REMINDER_INTERVAL, 1);
1144         assertThat(mDatabaseManagerUT.getSubscriptionInfoInternal(1)
1145                 .getCellBroadcastAlertReminderInterval()).isEqualTo(1);
1146     }
1147 
1148     @Test
testUpdateCellBroadcastAlertVibrationEnabled()1149     public void testUpdateCellBroadcastAlertVibrationEnabled() throws Exception {
1150         // exception is expected if there is nothing in the database.
1151         assertThrows(IllegalArgumentException.class,
1152                 () -> mDatabaseManagerUT.setCellBroadcastAlertVibrationEnabled(1, 1));
1153 
1154         SubscriptionInfoInternal subInfo = insertSubscriptionAndVerify(FAKE_SUBSCRIPTION_INFO1);
1155         mDatabaseManagerUT.setCellBroadcastAlertVibrationEnabled(
1156                 subInfo.getSubscriptionId(), 0);
1157         processAllMessages();
1158 
1159         subInfo = new SubscriptionInfoInternal.Builder(subInfo)
1160                 .setCellBroadcastAlertVibrationEnabled(0).build();
1161         verifySubscription(subInfo);
1162         verify(mSubscriptionDatabaseManagerCallback, times(2)).onSubscriptionChanged(eq(1));
1163 
1164         assertThat(mDatabaseManagerUT.getSubscriptionProperty(
1165                 1, SimInfo.COLUMN_CB_ALERT_VIBRATE))
1166                 .isEqualTo(0);
1167         mDatabaseManagerUT.setSubscriptionProperty(1, SimInfo.COLUMN_CB_ALERT_VIBRATE, 1);
1168         assertThat(mDatabaseManagerUT.getSubscriptionInfoInternal(1)
1169                 .getCellBroadcastAlertVibrationEnabled()).isEqualTo(1);
1170     }
1171 
1172     @Test
testUpdateCellBroadcastAlertSpeechEnabled()1173     public void testUpdateCellBroadcastAlertSpeechEnabled() throws Exception {
1174         // exception is expected if there is nothing in the database.
1175         assertThrows(IllegalArgumentException.class,
1176                 () -> mDatabaseManagerUT.setCellBroadcastAlertSpeechEnabled(1, 1));
1177 
1178         SubscriptionInfoInternal subInfo = insertSubscriptionAndVerify(FAKE_SUBSCRIPTION_INFO1);
1179         mDatabaseManagerUT.setCellBroadcastAlertSpeechEnabled(
1180                 subInfo.getSubscriptionId(), 0);
1181         processAllMessages();
1182 
1183         subInfo = new SubscriptionInfoInternal.Builder(subInfo)
1184                 .setCellBroadcastAlertSpeechEnabled(0).build();
1185         verifySubscription(subInfo);
1186         verify(mSubscriptionDatabaseManagerCallback, times(2)).onSubscriptionChanged(eq(1));
1187 
1188         assertThat(mDatabaseManagerUT.getSubscriptionProperty(
1189                 1, SimInfo.COLUMN_CB_ALERT_SPEECH))
1190                 .isEqualTo(0);
1191         mDatabaseManagerUT.setSubscriptionProperty(1, SimInfo.COLUMN_CB_ALERT_SPEECH, 1);
1192         assertThat(mDatabaseManagerUT.getSubscriptionInfoInternal(1)
1193                 .getCellBroadcastAlertSpeechEnabled()).isEqualTo(1);
1194     }
1195 
1196     @Test
testUpdateCellBroadcastEtwsTestAlertEnabled()1197     public void testUpdateCellBroadcastEtwsTestAlertEnabled() throws Exception {
1198         // exception is expected if there is nothing in the database.
1199         assertThrows(IllegalArgumentException.class,
1200                 () -> mDatabaseManagerUT.setCellBroadcastEtwsTestAlertEnabled(1, 1));
1201 
1202         SubscriptionInfoInternal subInfo = insertSubscriptionAndVerify(FAKE_SUBSCRIPTION_INFO1);
1203         mDatabaseManagerUT.setCellBroadcastEtwsTestAlertEnabled(
1204                 subInfo.getSubscriptionId(), 0);
1205         processAllMessages();
1206 
1207         subInfo = new SubscriptionInfoInternal.Builder(subInfo)
1208                 .setCellBroadcastEtwsTestAlertEnabled(0).build();
1209         verifySubscription(subInfo);
1210         verify(mSubscriptionDatabaseManagerCallback, times(2)).onSubscriptionChanged(eq(1));
1211 
1212         assertThat(mDatabaseManagerUT.getSubscriptionProperty(
1213                 1, SimInfo.COLUMN_CB_ETWS_TEST_ALERT))
1214                 .isEqualTo(0);
1215         mDatabaseManagerUT.setSubscriptionProperty(1, SimInfo.COLUMN_CB_ETWS_TEST_ALERT, 1);
1216         assertThat(mDatabaseManagerUT.getSubscriptionInfoInternal(1)
1217                 .getCellBroadcastEtwsTestAlertEnabled()).isEqualTo(1);
1218     }
1219 
1220     @Test
testUpdateCellBroadcastAreaInfoMessageEnabled()1221     public void testUpdateCellBroadcastAreaInfoMessageEnabled() throws Exception {
1222         // exception is expected if there is nothing in the database.
1223         assertThrows(IllegalArgumentException.class,
1224                 () -> mDatabaseManagerUT.setCellBroadcastAreaInfoMessageEnabled(1, 1));
1225 
1226         SubscriptionInfoInternal subInfo = insertSubscriptionAndVerify(FAKE_SUBSCRIPTION_INFO1);
1227         mDatabaseManagerUT.setCellBroadcastAreaInfoMessageEnabled(
1228                 subInfo.getSubscriptionId(), 0);
1229         processAllMessages();
1230 
1231         subInfo = new SubscriptionInfoInternal.Builder(subInfo)
1232                 .setCellBroadcastAreaInfoMessageEnabled(0).build();
1233         verifySubscription(subInfo);
1234         verify(mSubscriptionDatabaseManagerCallback, times(2)).onSubscriptionChanged(eq(1));
1235 
1236         assertThat(mDatabaseManagerUT.getSubscriptionProperty(
1237                 1, SimInfo.COLUMN_CB_CHANNEL_50_ALERT))
1238                 .isEqualTo(0);
1239         mDatabaseManagerUT.setSubscriptionProperty(1, SimInfo.COLUMN_CB_CHANNEL_50_ALERT, 1);
1240         assertThat(mDatabaseManagerUT.getSubscriptionInfoInternal(1)
1241                 .getCellBroadcastAreaInfoMessageEnabled()).isEqualTo(1);
1242     }
1243 
1244     @Test
testUpdateCellBroadcastTestAlertEnabled()1245     public void testUpdateCellBroadcastTestAlertEnabled() throws Exception {
1246         // exception is expected if there is nothing in the database.
1247         assertThrows(IllegalArgumentException.class,
1248                 () -> mDatabaseManagerUT.setCellBroadcastTestAlertEnabled(1, 1));
1249 
1250         SubscriptionInfoInternal subInfo = insertSubscriptionAndVerify(FAKE_SUBSCRIPTION_INFO1);
1251         mDatabaseManagerUT.setCellBroadcastTestAlertEnabled(
1252                 subInfo.getSubscriptionId(), 0);
1253         processAllMessages();
1254 
1255         subInfo = new SubscriptionInfoInternal.Builder(subInfo)
1256                 .setCellBroadcastTestAlertEnabled(0).build();
1257         verifySubscription(subInfo);
1258         verify(mSubscriptionDatabaseManagerCallback, times(2)).onSubscriptionChanged(eq(1));
1259 
1260         assertThat(mDatabaseManagerUT.getSubscriptionProperty(
1261                 1, SimInfo.COLUMN_CB_CMAS_TEST_ALERT))
1262                 .isEqualTo(0);
1263         mDatabaseManagerUT.setSubscriptionProperty(1, SimInfo.COLUMN_CB_CMAS_TEST_ALERT, 1);
1264         assertThat(mDatabaseManagerUT.getSubscriptionInfoInternal(1)
1265                 .getCellBroadcastTestAlertEnabled()).isEqualTo(1);
1266     }
1267 
1268     @Test
testUpdateCellBroadcastOptOutDialogEnabled()1269     public void testUpdateCellBroadcastOptOutDialogEnabled() throws Exception {
1270         // exception is expected if there is nothing in the database.
1271         assertThrows(IllegalArgumentException.class,
1272                 () -> mDatabaseManagerUT.setCellBroadcastOptOutDialogEnabled(1, 1));
1273 
1274         SubscriptionInfoInternal subInfo = insertSubscriptionAndVerify(FAKE_SUBSCRIPTION_INFO1);
1275         mDatabaseManagerUT.setCellBroadcastOptOutDialogEnabled(
1276                 subInfo.getSubscriptionId(), 0);
1277         processAllMessages();
1278 
1279         subInfo = new SubscriptionInfoInternal.Builder(subInfo)
1280                 .setCellBroadcastOptOutDialogEnabled(0).build();
1281         verifySubscription(subInfo);
1282         verify(mSubscriptionDatabaseManagerCallback, times(2)).onSubscriptionChanged(eq(1));
1283 
1284         assertThat(mDatabaseManagerUT.getSubscriptionProperty(
1285                 1, SimInfo.COLUMN_CB_OPT_OUT_DIALOG))
1286                 .isEqualTo(0);
1287         mDatabaseManagerUT.setSubscriptionProperty(1, SimInfo.COLUMN_CB_OPT_OUT_DIALOG, 1);
1288         assertThat(mDatabaseManagerUT.getSubscriptionInfoInternal(1)
1289                 .getCellBroadcastOptOutDialogEnabled()).isEqualTo(1);
1290     }
1291 
1292     @Test
testUpdateEnhanced4GModeEnabled()1293     public void testUpdateEnhanced4GModeEnabled() throws Exception {
1294         // exception is expected if there is nothing in the database.
1295         assertThrows(IllegalArgumentException.class,
1296                 () -> mDatabaseManagerUT.setEnhanced4GModeEnabled(1, 0));
1297 
1298         SubscriptionInfoInternal subInfo = insertSubscriptionAndVerify(FAKE_SUBSCRIPTION_INFO1);
1299         mDatabaseManagerUT.setEnhanced4GModeEnabled(subInfo.getSubscriptionId(), 0);
1300         processAllMessages();
1301 
1302         subInfo = new SubscriptionInfoInternal.Builder(subInfo).setEnhanced4GModeEnabled(0).build();
1303         verifySubscription(subInfo);
1304         verify(mSubscriptionDatabaseManagerCallback, times(2)).onSubscriptionChanged(eq(1));
1305 
1306         assertThat(mDatabaseManagerUT.getSubscriptionProperty(
1307                 1, SimInfo.COLUMN_ENHANCED_4G_MODE_ENABLED)).isEqualTo(0);
1308         mDatabaseManagerUT.setSubscriptionProperty(1, SimInfo.COLUMN_ENHANCED_4G_MODE_ENABLED, 1);
1309         assertThat(mDatabaseManagerUT.getSubscriptionInfoInternal(1).getEnhanced4GModeEnabled())
1310                 .isEqualTo(1);
1311         assertThat(mDatabaseManagerUT.getSubscriptionInfoInternal(1).isEnhanced4GModeEnabled())
1312                 .isTrue();
1313     }
1314 
1315     @Test
testUpdateVideoTelephonyEnabled()1316     public void testUpdateVideoTelephonyEnabled() throws Exception {
1317         // exception is expected if there is nothing in the database.
1318         assertThrows(IllegalArgumentException.class,
1319                 () -> mDatabaseManagerUT.setVideoTelephonyEnabled(1, 0));
1320 
1321         SubscriptionInfoInternal subInfo = insertSubscriptionAndVerify(FAKE_SUBSCRIPTION_INFO1);
1322         mDatabaseManagerUT.setVideoTelephonyEnabled(subInfo.getSubscriptionId(), 0);
1323         processAllMessages();
1324 
1325         subInfo = new SubscriptionInfoInternal.Builder(subInfo).setVideoTelephonyEnabled(0).build();
1326         verifySubscription(subInfo);
1327         verify(mSubscriptionDatabaseManagerCallback, times(2)).onSubscriptionChanged(eq(1));
1328 
1329         assertThat(mDatabaseManagerUT.getSubscriptionProperty(
1330                 1, SimInfo.COLUMN_VT_IMS_ENABLED)).isEqualTo(0);
1331         mDatabaseManagerUT.setSubscriptionProperty(1, SimInfo.COLUMN_VT_IMS_ENABLED, 1);
1332         assertThat(mDatabaseManagerUT.getSubscriptionInfoInternal(1).getVideoTelephonyEnabled())
1333                 .isEqualTo(1);
1334         assertThat(mDatabaseManagerUT.getSubscriptionInfoInternal(1).isVideoTelephonyEnabled())
1335                 .isTrue();
1336     }
1337 
1338     @Test
testUpdateWifiCallingEnabled()1339     public void testUpdateWifiCallingEnabled() throws Exception {
1340         // exception is expected if there is nothing in the database.
1341         assertThrows(IllegalArgumentException.class,
1342                 () -> mDatabaseManagerUT.setWifiCallingEnabled(1, 0));
1343 
1344         SubscriptionInfoInternal subInfo = insertSubscriptionAndVerify(FAKE_SUBSCRIPTION_INFO1);
1345         mDatabaseManagerUT.setWifiCallingEnabled(subInfo.getSubscriptionId(), 0);
1346         processAllMessages();
1347 
1348         subInfo = new SubscriptionInfoInternal.Builder(subInfo).setWifiCallingEnabled(0).build();
1349         verifySubscription(subInfo);
1350         verify(mSubscriptionDatabaseManagerCallback, times(2)).onSubscriptionChanged(eq(1));
1351 
1352         assertThat(mDatabaseManagerUT.getSubscriptionProperty(1, SimInfo.COLUMN_WFC_IMS_ENABLED))
1353                 .isEqualTo(0);
1354         mDatabaseManagerUT.setSubscriptionProperty(1, SimInfo.COLUMN_WFC_IMS_ENABLED, 1);
1355         assertThat(mDatabaseManagerUT.getSubscriptionInfoInternal(1).getWifiCallingEnabled())
1356                 .isEqualTo(1);
1357     }
1358 
1359     @Test
testUpdateWifiCallingMode()1360     public void testUpdateWifiCallingMode() throws Exception {
1361         // exception is expected if there is nothing in the database.
1362         assertThrows(IllegalArgumentException.class,
1363                 () -> mDatabaseManagerUT.setWifiCallingMode(
1364                         1, ImsMmTelManager.WIFI_MODE_WIFI_ONLY));
1365 
1366         SubscriptionInfoInternal subInfo = insertSubscriptionAndVerify(FAKE_SUBSCRIPTION_INFO1);
1367         mDatabaseManagerUT.setWifiCallingMode(subInfo.getSubscriptionId(),
1368                 ImsMmTelManager.WIFI_MODE_WIFI_ONLY);
1369         processAllMessages();
1370 
1371         subInfo = new SubscriptionInfoInternal.Builder(subInfo)
1372                 .setWifiCallingMode(ImsMmTelManager.WIFI_MODE_WIFI_ONLY).build();
1373         verifySubscription(subInfo);
1374         verify(mSubscriptionDatabaseManagerCallback, times(2)).onSubscriptionChanged(eq(1));
1375 
1376         assertThat(mDatabaseManagerUT.getSubscriptionProperty(1, SimInfo.COLUMN_WFC_IMS_MODE))
1377                 .isEqualTo(ImsMmTelManager.WIFI_MODE_WIFI_ONLY);
1378         mDatabaseManagerUT.setSubscriptionProperty(1, SimInfo.COLUMN_WFC_IMS_MODE,
1379                 ImsMmTelManager.WIFI_MODE_CELLULAR_PREFERRED);
1380         assertThat(mDatabaseManagerUT.getSubscriptionInfoInternal(1).getWifiCallingMode())
1381                 .isEqualTo(ImsMmTelManager.WIFI_MODE_CELLULAR_PREFERRED);
1382     }
1383 
1384     @Test
testUpdateWifiCallingModeForRoaming()1385     public void testUpdateWifiCallingModeForRoaming() throws Exception {
1386         // exception is expected if there is nothing in the database.
1387         assertThrows(IllegalArgumentException.class,
1388                 () -> mDatabaseManagerUT.setWifiCallingModeForRoaming(
1389                         1, ImsMmTelManager.WIFI_MODE_WIFI_ONLY));
1390 
1391         SubscriptionInfoInternal subInfo = insertSubscriptionAndVerify(FAKE_SUBSCRIPTION_INFO1);
1392         mDatabaseManagerUT.setWifiCallingModeForRoaming(subInfo.getSubscriptionId(),
1393                 ImsMmTelManager.WIFI_MODE_WIFI_ONLY);
1394         processAllMessages();
1395 
1396         subInfo = new SubscriptionInfoInternal.Builder(subInfo)
1397                 .setWifiCallingModeForRoaming(ImsMmTelManager.WIFI_MODE_WIFI_ONLY).build();
1398         verifySubscription(subInfo);
1399         verify(mSubscriptionDatabaseManagerCallback, times(2)).onSubscriptionChanged(eq(1));
1400 
1401         assertThat(mDatabaseManagerUT.getSubscriptionProperty(
1402                 1, SimInfo.COLUMN_WFC_IMS_ROAMING_MODE))
1403                 .isEqualTo(ImsMmTelManager.WIFI_MODE_WIFI_ONLY);
1404         mDatabaseManagerUT.setSubscriptionProperty(1, SimInfo.COLUMN_WFC_IMS_ROAMING_MODE,
1405                 ImsMmTelManager.WIFI_MODE_CELLULAR_PREFERRED);
1406         assertThat(mDatabaseManagerUT.getSubscriptionInfoInternal(1).getWifiCallingModeForRoaming())
1407                 .isEqualTo(ImsMmTelManager.WIFI_MODE_CELLULAR_PREFERRED);
1408     }
1409 
1410     @Test
testUpdateWifiCallingEnabledForRoaming()1411     public void testUpdateWifiCallingEnabledForRoaming() throws Exception {
1412         // exception is expected if there is nothing in the database.
1413         assertThrows(IllegalArgumentException.class,
1414                 () -> mDatabaseManagerUT.setWifiCallingEnabledForRoaming(1, 0));
1415 
1416         SubscriptionInfoInternal subInfo = insertSubscriptionAndVerify(FAKE_SUBSCRIPTION_INFO1);
1417         mDatabaseManagerUT.setWifiCallingEnabledForRoaming(subInfo.getSubscriptionId(), 0);
1418         processAllMessages();
1419 
1420         subInfo = new SubscriptionInfoInternal.Builder(subInfo)
1421                 .setWifiCallingEnabledForRoaming(0).build();
1422         verifySubscription(subInfo);
1423         verify(mSubscriptionDatabaseManagerCallback, times(2)).onSubscriptionChanged(eq(1));
1424 
1425         assertThat(mDatabaseManagerUT.getSubscriptionProperty(
1426                 1, SimInfo.COLUMN_WFC_IMS_ROAMING_ENABLED)).isEqualTo(0);
1427         mDatabaseManagerUT.setSubscriptionProperty(1, SimInfo.COLUMN_WFC_IMS_ROAMING_ENABLED, 1);
1428         assertThat(mDatabaseManagerUT.getSubscriptionInfoInternal(1)
1429                 .getWifiCallingEnabledForRoaming()).isEqualTo(1);
1430     }
1431 
1432     @Test
testUpdateVoImsOptInEnabled()1433     public void testUpdateVoImsOptInEnabled() throws Exception {
1434         // exception is expected if there is nothing in the database.
1435         assertThrows(IllegalArgumentException.class,
1436                 () -> mDatabaseManagerUT.setVoImsOptInEnabled(1, 0));
1437 
1438         SubscriptionInfoInternal subInfo = insertSubscriptionAndVerify(FAKE_SUBSCRIPTION_INFO1);
1439         mDatabaseManagerUT.setVoImsOptInEnabled(subInfo.getSubscriptionId(), 0);
1440         processAllMessages();
1441 
1442         subInfo = new SubscriptionInfoInternal.Builder(subInfo)
1443                 .setVoImsOptInEnabled(0).build();
1444         verifySubscription(subInfo);
1445         verify(mSubscriptionDatabaseManagerCallback, times(2)).onSubscriptionChanged(eq(1));
1446 
1447         assertThat(mDatabaseManagerUT.getSubscriptionProperty(
1448                 1, SimInfo.COLUMN_VOIMS_OPT_IN_STATUS)).isEqualTo(0);
1449         mDatabaseManagerUT.setSubscriptionProperty(1, SimInfo.COLUMN_VOIMS_OPT_IN_STATUS, 1);
1450         assertThat(mDatabaseManagerUT.getSubscriptionInfoInternal(1)
1451                 .getVoImsOptInEnabled()).isEqualTo(1);
1452         assertThat(mDatabaseManagerUT.getSubscriptionInfoInternal(1).isVoImsOptInEnabled())
1453                 .isTrue();
1454     }
1455 
1456 
1457     @Test
testUpdateOpportunistic()1458     public void testUpdateOpportunistic() throws Exception {
1459         // exception is expected if there is nothing in the database.
1460         assertThrows(IllegalArgumentException.class,
1461                 () -> mDatabaseManagerUT.setOpportunistic(1, 1));
1462 
1463         SubscriptionInfoInternal subInfo = insertSubscriptionAndVerify(FAKE_SUBSCRIPTION_INFO1);
1464         mDatabaseManagerUT.setOpportunistic(subInfo.getSubscriptionId(), 1);
1465         processAllMessages();
1466 
1467         subInfo = new SubscriptionInfoInternal.Builder(subInfo).setOpportunistic(1).build();
1468         verifySubscription(subInfo);
1469         verify(mSubscriptionDatabaseManagerCallback, times(2)).onSubscriptionChanged(eq(1));
1470 
1471         assertThat(mDatabaseManagerUT.getSubscriptionProperty(
1472                 1, SimInfo.COLUMN_IS_OPPORTUNISTIC)).isEqualTo(1);
1473         mDatabaseManagerUT.setSubscriptionProperty(1, SimInfo.COLUMN_IS_OPPORTUNISTIC, 0);
1474         assertThat(mDatabaseManagerUT.getSubscriptionInfoInternal(1)
1475                 .getOpportunistic()).isEqualTo(0);
1476     }
1477 
1478     @Test
testUpdateGroupUuid()1479     public void testUpdateGroupUuid() throws Exception {
1480         // exception is expected if there is nothing in the database.
1481         assertThrows(IllegalArgumentException.class,
1482                 () -> mDatabaseManagerUT.setGroupUuid(1, FAKE_UUID2));
1483 
1484         SubscriptionInfoInternal subInfo = insertSubscriptionAndVerify(FAKE_SUBSCRIPTION_INFO1);
1485         mDatabaseManagerUT.setGroupUuid(subInfo.getSubscriptionId(), FAKE_UUID2);
1486         processAllMessages();
1487 
1488         subInfo = new SubscriptionInfoInternal.Builder(subInfo).setGroupUuid(FAKE_UUID2).build();
1489         verifySubscription(subInfo);
1490         verify(mSubscriptionDatabaseManagerCallback, times(2)).onSubscriptionChanged(eq(1));
1491 
1492         assertThat(mDatabaseManagerUT.getSubscriptionProperty(
1493                 1, SimInfo.COLUMN_GROUP_UUID)).isEqualTo(FAKE_UUID2);
1494         mDatabaseManagerUT.setSubscriptionProperty(1, SimInfo.COLUMN_GROUP_UUID, FAKE_UUID1);
1495         assertThat(mDatabaseManagerUT.getSubscriptionInfoInternal(1)
1496                 .getGroupUuid()).isEqualTo(FAKE_UUID1);
1497     }
1498 
1499     @Test
testUpdateCountryIso()1500     public void testUpdateCountryIso() throws Exception {
1501         // exception is expected if there is nothing in the database.
1502         assertThrows(IllegalArgumentException.class,
1503                 () -> mDatabaseManagerUT.setCountryIso(1, FAKE_COUNTRY_CODE2));
1504 
1505         SubscriptionInfoInternal subInfo = insertSubscriptionAndVerify(FAKE_SUBSCRIPTION_INFO1);
1506         mDatabaseManagerUT.setCountryIso(subInfo.getSubscriptionId(), FAKE_COUNTRY_CODE2);
1507         processAllMessages();
1508 
1509         subInfo = new SubscriptionInfoInternal.Builder(subInfo)
1510                 .setCountryIso(FAKE_COUNTRY_CODE2).build();
1511         verifySubscription(subInfo);
1512         verify(mSubscriptionDatabaseManagerCallback, times(2)).onSubscriptionChanged(eq(1));
1513 
1514         assertThat(mDatabaseManagerUT.getSubscriptionProperty(
1515                 1, SimInfo.COLUMN_ISO_COUNTRY_CODE)).isEqualTo(FAKE_COUNTRY_CODE2);
1516         mDatabaseManagerUT.setSubscriptionProperty(
1517                 1, SimInfo.COLUMN_ISO_COUNTRY_CODE, FAKE_COUNTRY_CODE1);
1518         assertThat(mDatabaseManagerUT.getSubscriptionInfoInternal(1)
1519                 .getCountryIso()).isEqualTo(FAKE_COUNTRY_CODE1);
1520     }
1521 
1522     @Test
testUpdateCarrierId()1523     public void testUpdateCarrierId() throws Exception {
1524         // exception is expected if there is nothing in the database.
1525         assertThrows(IllegalArgumentException.class,
1526                 () -> mDatabaseManagerUT.setCarrierId(1, FAKE_CARRIER_ID2));
1527 
1528         SubscriptionInfoInternal subInfo = insertSubscriptionAndVerify(FAKE_SUBSCRIPTION_INFO1);
1529         mDatabaseManagerUT.setCarrierId(subInfo.getSubscriptionId(), FAKE_CARRIER_ID2);
1530         processAllMessages();
1531 
1532         subInfo = new SubscriptionInfoInternal.Builder(subInfo)
1533                 .setCarrierId(FAKE_CARRIER_ID2).build();
1534         verifySubscription(subInfo);
1535         verify(mSubscriptionDatabaseManagerCallback, times(2)).onSubscriptionChanged(eq(1));
1536 
1537         assertThat(mDatabaseManagerUT.getSubscriptionProperty(1, SimInfo.COLUMN_CARRIER_ID))
1538                 .isEqualTo(FAKE_CARRIER_ID2);
1539         mDatabaseManagerUT.setSubscriptionProperty(1, SimInfo.COLUMN_CARRIER_ID, FAKE_CARRIER_ID1);
1540         assertThat(mDatabaseManagerUT.getSubscriptionInfoInternal(1).getCarrierId())
1541                 .isEqualTo(FAKE_CARRIER_ID1);
1542     }
1543 
1544     @Test
testUpdateProfileClass()1545     public void testUpdateProfileClass() throws Exception {
1546         // exception is expected if there is nothing in the database.
1547         assertThrows(IllegalArgumentException.class,
1548                 () -> mDatabaseManagerUT.setProfileClass(
1549                         1, SubscriptionManager.PROFILE_CLASS_TESTING));
1550 
1551         SubscriptionInfoInternal subInfo = insertSubscriptionAndVerify(FAKE_SUBSCRIPTION_INFO1);
1552         mDatabaseManagerUT.setProfileClass(subInfo.getSubscriptionId(),
1553                 SubscriptionManager.PROFILE_CLASS_TESTING);
1554         processAllMessages();
1555 
1556         subInfo = new SubscriptionInfoInternal.Builder(subInfo)
1557                 .setProfileClass(SubscriptionManager.PROFILE_CLASS_TESTING).build();
1558         verifySubscription(subInfo);
1559         verify(mSubscriptionDatabaseManagerCallback, times(2)).onSubscriptionChanged(eq(1));
1560 
1561         assertThat(mDatabaseManagerUT.getSubscriptionProperty(1, SimInfo.COLUMN_PROFILE_CLASS))
1562                 .isEqualTo(SubscriptionManager.PROFILE_CLASS_TESTING);
1563         mDatabaseManagerUT.setSubscriptionProperty(1, SimInfo.COLUMN_PROFILE_CLASS,
1564                 SubscriptionManager.PROFILE_CLASS_PROVISIONING);
1565         assertThat(mDatabaseManagerUT.getSubscriptionInfoInternal(1).getProfileClass())
1566                 .isEqualTo(SubscriptionManager.PROFILE_CLASS_PROVISIONING);
1567     }
1568 
1569     @Test
testUpdateSubscriptionType()1570     public void testUpdateSubscriptionType() throws Exception {
1571         // exception is expected if there is nothing in the database.
1572         assertThrows(IllegalArgumentException.class,
1573                 () -> mDatabaseManagerUT.setSubscriptionType(
1574                         1, SubscriptionManager.SUBSCRIPTION_TYPE_REMOTE_SIM));
1575 
1576         SubscriptionInfoInternal subInfo = insertSubscriptionAndVerify(FAKE_SUBSCRIPTION_INFO1);
1577         mDatabaseManagerUT.setSubscriptionType(subInfo.getSubscriptionId(),
1578                 SubscriptionManager.SUBSCRIPTION_TYPE_REMOTE_SIM);
1579         processAllMessages();
1580 
1581         subInfo = new SubscriptionInfoInternal.Builder(subInfo)
1582                 .setType(SubscriptionManager.SUBSCRIPTION_TYPE_REMOTE_SIM).build();
1583         verifySubscription(subInfo);
1584         verify(mSubscriptionDatabaseManagerCallback, times(2)).onSubscriptionChanged(eq(1));
1585 
1586         assertThat(mDatabaseManagerUT.getSubscriptionProperty(1, SimInfo.COLUMN_SUBSCRIPTION_TYPE))
1587                 .isEqualTo(SubscriptionManager.SUBSCRIPTION_TYPE_REMOTE_SIM);
1588         mDatabaseManagerUT.setSubscriptionProperty(1, SimInfo.COLUMN_SUBSCRIPTION_TYPE,
1589                 SubscriptionManager.SUBSCRIPTION_TYPE_LOCAL_SIM);
1590         assertThat(mDatabaseManagerUT.getSubscriptionInfoInternal(1).getSubscriptionType())
1591                 .isEqualTo(SubscriptionManager.SUBSCRIPTION_TYPE_LOCAL_SIM);
1592     }
1593 
1594     @Test
testUpdateGroupOwner()1595     public void testUpdateGroupOwner() throws Exception {
1596         // exception is expected if there is nothing in the database.
1597         assertThrows(IllegalArgumentException.class,
1598                 () -> mDatabaseManagerUT.setGroupOwner(1, FAKE_OWNER2));
1599 
1600         SubscriptionInfoInternal subInfo = insertSubscriptionAndVerify(FAKE_SUBSCRIPTION_INFO1);
1601         mDatabaseManagerUT.setGroupOwner(subInfo.getSubscriptionId(), FAKE_OWNER2);
1602         processAllMessages();
1603 
1604         subInfo = new SubscriptionInfoInternal.Builder(subInfo)
1605                 .setGroupOwner(FAKE_OWNER2).build();
1606         verifySubscription(subInfo);
1607         verify(mSubscriptionDatabaseManagerCallback, times(2)).onSubscriptionChanged(eq(1));
1608 
1609         assertThat(mDatabaseManagerUT.getSubscriptionProperty(1, SimInfo.COLUMN_GROUP_OWNER))
1610                 .isEqualTo(FAKE_OWNER2);
1611         mDatabaseManagerUT.setSubscriptionProperty(1, SimInfo.COLUMN_GROUP_OWNER, FAKE_OWNER1);
1612         assertThat(mDatabaseManagerUT.getSubscriptionInfoInternal(1).getGroupOwner())
1613                 .isEqualTo(FAKE_OWNER1);
1614     }
1615 
1616     @Test
testUpdateEnabledMobileDataPolicies()1617     public void testUpdateEnabledMobileDataPolicies() throws Exception {
1618         // exception is expected if there is nothing in the database.
1619         assertThrows(IllegalArgumentException.class,
1620                 () -> mDatabaseManagerUT.setEnabledMobileDataPolicies(1, FAKE_MOBILE_DATA_POLICY2));
1621 
1622         SubscriptionInfoInternal subInfo = insertSubscriptionAndVerify(FAKE_SUBSCRIPTION_INFO1);
1623         mDatabaseManagerUT.setEnabledMobileDataPolicies(subInfo.getSubscriptionId(),
1624                 FAKE_MOBILE_DATA_POLICY2);
1625         processAllMessages();
1626 
1627         subInfo = new SubscriptionInfoInternal.Builder(subInfo)
1628                 .setEnabledMobileDataPolicies(FAKE_MOBILE_DATA_POLICY2).build();
1629         verifySubscription(subInfo);
1630         verify(mSubscriptionDatabaseManagerCallback, times(2)).onSubscriptionChanged(eq(1));
1631 
1632         assertThat(mDatabaseManagerUT.getSubscriptionProperty(1,
1633                 SimInfo.COLUMN_ENABLED_MOBILE_DATA_POLICIES)).isEqualTo(FAKE_MOBILE_DATA_POLICY2);
1634         mDatabaseManagerUT.setSubscriptionProperty(
1635                 1, SimInfo.COLUMN_ENABLED_MOBILE_DATA_POLICIES, FAKE_MOBILE_DATA_POLICY1);
1636         assertThat(mDatabaseManagerUT.getSubscriptionInfoInternal(1).getEnabledMobileDataPolicies())
1637                 .isEqualTo(FAKE_MOBILE_DATA_POLICY1);
1638     }
1639 
1640     @Test
testUpdateImsi()1641     public void testUpdateImsi() throws Exception {
1642         // exception is expected if there is nothing in the database.
1643         assertThrows(IllegalArgumentException.class,
1644                 () -> mDatabaseManagerUT.setImsi(1, FAKE_IMSI2));
1645 
1646         SubscriptionInfoInternal subInfo = insertSubscriptionAndVerify(FAKE_SUBSCRIPTION_INFO1);
1647         mDatabaseManagerUT.setImsi(subInfo.getSubscriptionId(), FAKE_IMSI2);
1648         processAllMessages();
1649 
1650         subInfo = new SubscriptionInfoInternal.Builder(subInfo)
1651                 .setImsi(FAKE_IMSI2).build();
1652         verifySubscription(subInfo);
1653         verify(mSubscriptionDatabaseManagerCallback, times(2)).onSubscriptionChanged(eq(1));
1654 
1655         assertThat(mDatabaseManagerUT.getSubscriptionProperty(1, SimInfo.COLUMN_IMSI))
1656                 .isEqualTo(FAKE_IMSI2);
1657         mDatabaseManagerUT.setSubscriptionProperty(1, SimInfo.COLUMN_IMSI, FAKE_IMSI1);
1658         assertThat(mDatabaseManagerUT.getSubscriptionInfoInternal(1).getImsi())
1659                 .isEqualTo(FAKE_IMSI1);
1660     }
1661 
1662     @Test
testUpdateUiccApplicationsEnabled()1663     public void testUpdateUiccApplicationsEnabled() throws Exception {
1664         // exception is expected if there is nothing in the database.
1665         assertThrows(IllegalArgumentException.class,
1666                 () -> mDatabaseManagerUT.setUiccApplicationsEnabled(1, 0));
1667 
1668         SubscriptionInfoInternal subInfo = insertSubscriptionAndVerify(FAKE_SUBSCRIPTION_INFO1);
1669         mDatabaseManagerUT.setUiccApplicationsEnabled(subInfo.getSubscriptionId(), 0);
1670         processAllMessages();
1671 
1672         subInfo = new SubscriptionInfoInternal.Builder(subInfo)
1673                 .setUiccApplicationsEnabled(0).build();
1674         verifySubscription(subInfo);
1675         verify(mSubscriptionDatabaseManagerCallback, times(2)).onSubscriptionChanged(eq(1));
1676 
1677         assertThat(mDatabaseManagerUT.getSubscriptionProperty(
1678                 1, SimInfo.COLUMN_UICC_APPLICATIONS_ENABLED)).isEqualTo(0);
1679         mDatabaseManagerUT.setSubscriptionProperty(1, SimInfo.COLUMN_UICC_APPLICATIONS_ENABLED, 1);
1680         assertThat(mDatabaseManagerUT.getSubscriptionInfoInternal(1).getUiccApplicationsEnabled())
1681                 .isEqualTo(1);
1682     }
1683 
1684     @Test
testUpdateRcsUceEnabled()1685     public void testUpdateRcsUceEnabled() throws Exception {
1686         // exception is expected if there is nothing in the database.
1687         assertThrows(IllegalArgumentException.class,
1688                 () -> mDatabaseManagerUT.setRcsUceEnabled(1, 0));
1689 
1690         SubscriptionInfoInternal subInfo = insertSubscriptionAndVerify(FAKE_SUBSCRIPTION_INFO1);
1691         mDatabaseManagerUT.setRcsUceEnabled(subInfo.getSubscriptionId(), 0);
1692         processAllMessages();
1693 
1694         subInfo = new SubscriptionInfoInternal.Builder(subInfo)
1695                 .setRcsUceEnabled(0).build();
1696         verifySubscription(subInfo);
1697         verify(mSubscriptionDatabaseManagerCallback, times(2)).onSubscriptionChanged(eq(1));
1698 
1699         assertThat(mDatabaseManagerUT.getSubscriptionProperty(
1700                 1, SimInfo.COLUMN_IMS_RCS_UCE_ENABLED)).isEqualTo(0);
1701         mDatabaseManagerUT.setSubscriptionProperty(1, SimInfo.COLUMN_IMS_RCS_UCE_ENABLED, 1);
1702         assertThat(mDatabaseManagerUT.getSubscriptionInfoInternal(1).getRcsUceEnabled())
1703                 .isEqualTo(1);
1704         assertThat(mDatabaseManagerUT.getSubscriptionInfoInternal(1).isRcsUceEnabled())
1705                 .isTrue();
1706     }
1707 
1708     @Test
testUpdateCrossSimCallingEnabled()1709     public void testUpdateCrossSimCallingEnabled() throws Exception {
1710         // exception is expected if there is nothing in the database.
1711         assertThrows(IllegalArgumentException.class,
1712                 () -> mDatabaseManagerUT.setCrossSimCallingEnabled(1, 0));
1713 
1714         SubscriptionInfoInternal subInfo = insertSubscriptionAndVerify(FAKE_SUBSCRIPTION_INFO1);
1715         mDatabaseManagerUT.setCrossSimCallingEnabled(subInfo.getSubscriptionId(), 0);
1716         processAllMessages();
1717 
1718         subInfo = new SubscriptionInfoInternal.Builder(subInfo)
1719                 .setCrossSimCallingEnabled(0).build();
1720         verifySubscription(subInfo);
1721         verify(mSubscriptionDatabaseManagerCallback, times(2)).onSubscriptionChanged(eq(1));
1722 
1723         assertThat(mDatabaseManagerUT.getSubscriptionProperty(
1724                 1, SimInfo.COLUMN_CROSS_SIM_CALLING_ENABLED)).isEqualTo(0);
1725         mDatabaseManagerUT.setSubscriptionProperty(1, SimInfo.COLUMN_CROSS_SIM_CALLING_ENABLED, 1);
1726         assertThat(mDatabaseManagerUT.getSubscriptionInfoInternal(1).getCrossSimCallingEnabled())
1727                 .isEqualTo(1);
1728         assertThat(mDatabaseManagerUT.getSubscriptionInfoInternal(1).isCrossSimCallingEnabled())
1729                 .isTrue();
1730     }
1731 
1732     @Test
testUpdateRcsConfig()1733     public void testUpdateRcsConfig() throws Exception {
1734         // exception is expected if there is nothing in the database.
1735         assertThrows(IllegalArgumentException.class,
1736                 () -> mDatabaseManagerUT.setRcsConfig(1, FAKE_RCS_CONFIG2));
1737 
1738         SubscriptionInfoInternal subInfo = insertSubscriptionAndVerify(FAKE_SUBSCRIPTION_INFO1);
1739         mDatabaseManagerUT.setRcsConfig(subInfo.getSubscriptionId(), FAKE_RCS_CONFIG2);
1740         processAllMessages();
1741 
1742         subInfo = new SubscriptionInfoInternal.Builder(subInfo)
1743                 .setRcsConfig(FAKE_RCS_CONFIG2).build();
1744         verifySubscription(subInfo);
1745         verify(mSubscriptionDatabaseManagerCallback, times(2)).onSubscriptionChanged(eq(1));
1746 
1747         assertThat(mDatabaseManagerUT.getSubscriptionProperty(
1748                 1, SimInfo.COLUMN_RCS_CONFIG)).isEqualTo(FAKE_RCS_CONFIG2);
1749         mDatabaseManagerUT.setSubscriptionProperty(1, SimInfo.COLUMN_RCS_CONFIG, FAKE_RCS_CONFIG1);
1750         assertThat(mDatabaseManagerUT.getSubscriptionInfoInternal(1).getRcsConfig())
1751                 .isEqualTo(FAKE_RCS_CONFIG1);
1752     }
1753 
1754     @Test
testUpdateAllowedNetworkTypesForReasons()1755     public void testUpdateAllowedNetworkTypesForReasons() throws Exception {
1756         // exception is expected if there is nothing in the database.
1757         assertThrows(IllegalArgumentException.class,
1758                 () -> mDatabaseManagerUT.setAllowedNetworkTypesForReasons(
1759                         1, FAKE_ALLOWED_NETWORK_TYPES_FOR_REASONS2));
1760 
1761         SubscriptionInfoInternal subInfo = insertSubscriptionAndVerify(FAKE_SUBSCRIPTION_INFO1);
1762         mDatabaseManagerUT.setAllowedNetworkTypesForReasons(subInfo.getSubscriptionId(),
1763                 FAKE_ALLOWED_NETWORK_TYPES_FOR_REASONS2);
1764         processAllMessages();
1765 
1766         subInfo = new SubscriptionInfoInternal.Builder(subInfo)
1767                 .setAllowedNetworkTypesForReasons(FAKE_ALLOWED_NETWORK_TYPES_FOR_REASONS2).build();
1768         verifySubscription(subInfo);
1769         verify(mSubscriptionDatabaseManagerCallback, times(2)).onSubscriptionChanged(eq(1));
1770 
1771         assertThat(mDatabaseManagerUT.getSubscriptionProperty(
1772                 1, SimInfo.COLUMN_ALLOWED_NETWORK_TYPES_FOR_REASONS))
1773                 .isEqualTo(FAKE_ALLOWED_NETWORK_TYPES_FOR_REASONS2);
1774         mDatabaseManagerUT.setSubscriptionProperty(1,
1775                 SimInfo.COLUMN_ALLOWED_NETWORK_TYPES_FOR_REASONS,
1776                 FAKE_ALLOWED_NETWORK_TYPES_FOR_REASONS1);
1777         assertThat(mDatabaseManagerUT.getSubscriptionInfoInternal(1)
1778                 .getAllowedNetworkTypesForReasons())
1779                 .isEqualTo(FAKE_ALLOWED_NETWORK_TYPES_FOR_REASONS1);
1780     }
1781 
1782     @Test
testUpdateDeviceToDeviceStatusSharingPreference()1783     public void testUpdateDeviceToDeviceStatusSharingPreference() throws Exception {
1784         // exception is expected if there is nothing in the database.
1785         assertThrows(IllegalArgumentException.class,
1786                 () -> mDatabaseManagerUT.setDeviceToDeviceStatusSharingPreference(
1787                         1, SubscriptionManager.D2D_SHARING_DISABLED));
1788 
1789         SubscriptionInfoInternal subInfo = insertSubscriptionAndVerify(FAKE_SUBSCRIPTION_INFO1);
1790         mDatabaseManagerUT.setDeviceToDeviceStatusSharingPreference(subInfo.getSubscriptionId(),
1791                 SubscriptionManager.D2D_SHARING_DISABLED);
1792         processAllMessages();
1793 
1794         subInfo = new SubscriptionInfoInternal.Builder(subInfo)
1795                 .setDeviceToDeviceStatusSharingPreference(
1796                         SubscriptionManager.D2D_SHARING_DISABLED).build();
1797         verifySubscription(subInfo);
1798         verify(mSubscriptionDatabaseManagerCallback, times(2)).onSubscriptionChanged(eq(1));
1799 
1800         assertThat(mDatabaseManagerUT.getSubscriptionProperty(
1801                 1, SimInfo.COLUMN_D2D_STATUS_SHARING))
1802                 .isEqualTo(SubscriptionManager.D2D_SHARING_DISABLED);
1803         mDatabaseManagerUT.setSubscriptionProperty(1, SimInfo.COLUMN_D2D_STATUS_SHARING,
1804                 SubscriptionManager.D2D_SHARING_ALL);
1805         assertThat(mDatabaseManagerUT.getSubscriptionInfoInternal(1)
1806                 .getDeviceToDeviceStatusSharingPreference())
1807                 .isEqualTo(SubscriptionManager.D2D_SHARING_ALL);
1808     }
1809 
1810     @Test
testUpdateNrAdvancedCallingEnabled()1811     public void testUpdateNrAdvancedCallingEnabled() throws Exception {
1812         // exception is expected if there is nothing in the database.
1813         assertThrows(IllegalArgumentException.class,
1814                 () -> mDatabaseManagerUT.setNrAdvancedCallingEnabled(1, 0));
1815 
1816         SubscriptionInfoInternal subInfo = insertSubscriptionAndVerify(FAKE_SUBSCRIPTION_INFO1);
1817         mDatabaseManagerUT.setNrAdvancedCallingEnabled(subInfo.getSubscriptionId(), 0);
1818         processAllMessages();
1819 
1820         subInfo = new SubscriptionInfoInternal.Builder(subInfo)
1821                 .setNrAdvancedCallingEnabled(0).build();
1822         verifySubscription(subInfo);
1823         verify(mSubscriptionDatabaseManagerCallback, times(2)).onSubscriptionChanged(eq(1));
1824 
1825         assertThat(mDatabaseManagerUT.getSubscriptionProperty(
1826                 1, SimInfo.COLUMN_NR_ADVANCED_CALLING_ENABLED)).isEqualTo(0);
1827         mDatabaseManagerUT.setSubscriptionProperty(
1828                 1, SimInfo.COLUMN_NR_ADVANCED_CALLING_ENABLED, 1);
1829         assertThat(mDatabaseManagerUT.getSubscriptionInfoInternal(1)
1830                 .getNrAdvancedCallingEnabled()).isEqualTo(1);
1831         assertThat(mDatabaseManagerUT.getSubscriptionInfoInternal(1)
1832                 .isNrAdvancedCallingEnabled()).isTrue();
1833     }
1834 
1835     @Test
testUpdateNumberFromCarrier()1836     public void testUpdateNumberFromCarrier() throws Exception {
1837         // exception is expected if there is nothing in the database.
1838         assertThrows(IllegalArgumentException.class,
1839                 () -> mDatabaseManagerUT.setNumberFromCarrier(1, FAKE_PHONE_NUMBER2));
1840 
1841         SubscriptionInfoInternal subInfo = insertSubscriptionAndVerify(FAKE_SUBSCRIPTION_INFO1);
1842         mDatabaseManagerUT.setNumberFromCarrier(subInfo.getSubscriptionId(), FAKE_PHONE_NUMBER2);
1843         processAllMessages();
1844 
1845         subInfo = new SubscriptionInfoInternal.Builder(subInfo)
1846                 .setNumberFromCarrier(FAKE_PHONE_NUMBER2).build();
1847         verifySubscription(subInfo);
1848         verify(mSubscriptionDatabaseManagerCallback, times(2)).onSubscriptionChanged(eq(1));
1849 
1850         assertThat(mDatabaseManagerUT.getSubscriptionProperty(
1851                 1, SimInfo.COLUMN_PHONE_NUMBER_SOURCE_CARRIER)).isEqualTo(FAKE_PHONE_NUMBER2);
1852         mDatabaseManagerUT.setSubscriptionProperty(
1853                 1, SimInfo.COLUMN_PHONE_NUMBER_SOURCE_CARRIER, FAKE_PHONE_NUMBER1);
1854         assertThat(mDatabaseManagerUT.getSubscriptionInfoInternal(1)
1855                 .getNumberFromCarrier()).isEqualTo(FAKE_PHONE_NUMBER1);
1856     }
1857 
1858     @Test
testUpdateNumberFromIms()1859     public void testUpdateNumberFromIms() throws Exception {
1860         // exception is expected if there is nothing in the database.
1861         assertThrows(IllegalArgumentException.class,
1862                 () -> mDatabaseManagerUT.setNumberFromIms(1, FAKE_PHONE_NUMBER2));
1863 
1864         SubscriptionInfoInternal subInfo = insertSubscriptionAndVerify(FAKE_SUBSCRIPTION_INFO1);
1865         mDatabaseManagerUT.setNumberFromIms(subInfo.getSubscriptionId(), FAKE_PHONE_NUMBER2);
1866         processAllMessages();
1867 
1868         subInfo = new SubscriptionInfoInternal.Builder(subInfo)
1869                 .setNumberFromIms(FAKE_PHONE_NUMBER2).build();
1870         verifySubscription(subInfo);
1871         verify(mSubscriptionDatabaseManagerCallback, times(2)).onSubscriptionChanged(eq(1));
1872 
1873         assertThat(mDatabaseManagerUT.getSubscriptionProperty(
1874                 1, SimInfo.COLUMN_PHONE_NUMBER_SOURCE_IMS)).isEqualTo(FAKE_PHONE_NUMBER2);
1875         mDatabaseManagerUT.setSubscriptionProperty(
1876                 1, SimInfo.COLUMN_PHONE_NUMBER_SOURCE_IMS, FAKE_PHONE_NUMBER1);
1877         assertThat(mDatabaseManagerUT.getSubscriptionInfoInternal(1)
1878                 .getNumberFromIms()).isEqualTo(FAKE_PHONE_NUMBER1);
1879     }
1880 
1881     @Test
testUpdatePortIndex()1882     public void testUpdatePortIndex() throws Exception {
1883         // exception is expected if there is nothing in the database.
1884         assertThrows(IllegalArgumentException.class,
1885                 () -> mDatabaseManagerUT.setPortIndex(1, 1));
1886 
1887         SubscriptionInfoInternal subInfo = insertSubscriptionAndVerify(FAKE_SUBSCRIPTION_INFO1);
1888         mDatabaseManagerUT.setPortIndex(subInfo.getSubscriptionId(), 1);
1889         processAllMessages();
1890 
1891         subInfo = new SubscriptionInfoInternal.Builder(subInfo)
1892                 .setPortIndex(1).build();
1893         verifySubscription(subInfo);
1894         verify(mSubscriptionDatabaseManagerCallback, times(2)).onSubscriptionChanged(eq(1));
1895 
1896         assertThat(mDatabaseManagerUT.getSubscriptionProperty(1, SimInfo.COLUMN_PORT_INDEX))
1897                 .isEqualTo(1);
1898         mDatabaseManagerUT.setSubscriptionProperty(1, SimInfo.COLUMN_PORT_INDEX, 2);
1899         assertThat(mDatabaseManagerUT.getSubscriptionInfoInternal(1).getPortIndex())
1900                 .isEqualTo(2);
1901     }
1902 
1903     @Test
testUpdateUsageSetting()1904     public void testUpdateUsageSetting() throws Exception {
1905         // exception is expected if there is nothing in the database.
1906         assertThrows(IllegalArgumentException.class,
1907                 () -> mDatabaseManagerUT.setUsageSetting(
1908                         1, SubscriptionManager.USAGE_SETTING_VOICE_CENTRIC));
1909 
1910         SubscriptionInfoInternal subInfo = insertSubscriptionAndVerify(FAKE_SUBSCRIPTION_INFO1);
1911         mDatabaseManagerUT.setUsageSetting(subInfo.getSubscriptionId(),
1912                 SubscriptionManager.USAGE_SETTING_VOICE_CENTRIC);
1913         processAllMessages();
1914 
1915         subInfo = new SubscriptionInfoInternal.Builder(subInfo)
1916                 .setUsageSetting(SubscriptionManager.USAGE_SETTING_VOICE_CENTRIC).build();
1917         verifySubscription(subInfo);
1918         verify(mSubscriptionDatabaseManagerCallback, times(2)).onSubscriptionChanged(eq(1));
1919 
1920         assertThat(mDatabaseManagerUT.getSubscriptionProperty(1, SimInfo.COLUMN_USAGE_SETTING))
1921                 .isEqualTo(SubscriptionManager.USAGE_SETTING_VOICE_CENTRIC);
1922         mDatabaseManagerUT.setSubscriptionProperty(
1923                 1, SimInfo.COLUMN_USAGE_SETTING, SubscriptionManager.USAGE_SETTING_DATA_CENTRIC);
1924         assertThat(mDatabaseManagerUT.getSubscriptionInfoInternal(1).getUsageSetting())
1925                 .isEqualTo(SubscriptionManager.USAGE_SETTING_DATA_CENTRIC);
1926     }
1927 
1928     @Test
testUpdateLastUsedTPMessageReference()1929     public void testUpdateLastUsedTPMessageReference() throws Exception {
1930         // exception is expected if there is nothing in the database.
1931         assertThrows(IllegalArgumentException.class,
1932                 () -> mDatabaseManagerUT.setLastUsedTPMessageReference(
1933                         1, FAKE_TP_MESSAGE_REFERENCE2));
1934 
1935         SubscriptionInfoInternal subInfo = insertSubscriptionAndVerify(FAKE_SUBSCRIPTION_INFO1);
1936         mDatabaseManagerUT.setLastUsedTPMessageReference(subInfo.getSubscriptionId(),
1937                 FAKE_TP_MESSAGE_REFERENCE2);
1938         processAllMessages();
1939 
1940         subInfo = new SubscriptionInfoInternal.Builder(subInfo)
1941                 .setLastUsedTPMessageReference(FAKE_TP_MESSAGE_REFERENCE2).build();
1942         verifySubscription(subInfo);
1943         verify(mSubscriptionDatabaseManagerCallback, times(2)).onSubscriptionChanged(eq(1));
1944 
1945         assertThat(mDatabaseManagerUT.getSubscriptionProperty(1, SimInfo.COLUMN_TP_MESSAGE_REF))
1946                 .isEqualTo(FAKE_TP_MESSAGE_REFERENCE2);
1947         mDatabaseManagerUT.setSubscriptionProperty(
1948                 1, SimInfo.COLUMN_TP_MESSAGE_REF, FAKE_TP_MESSAGE_REFERENCE1);
1949         assertThat(mDatabaseManagerUT.getSubscriptionInfoInternal(1)
1950                 .getLastUsedTPMessageReference()).isEqualTo(FAKE_TP_MESSAGE_REFERENCE1);
1951     }
1952 
1953     @Test
testUpdateUserId()1954     public void testUpdateUserId() throws Exception {
1955         // exception is expected if there is nothing in the database.
1956         assertThrows(IllegalArgumentException.class,
1957                 () -> mDatabaseManagerUT.setUserId(1, FAKE_USER_ID2));
1958 
1959         SubscriptionInfoInternal subInfo = insertSubscriptionAndVerify(FAKE_SUBSCRIPTION_INFO1);
1960         mDatabaseManagerUT.setUserId(subInfo.getSubscriptionId(), FAKE_USER_ID2);
1961         processAllMessages();
1962 
1963         subInfo = new SubscriptionInfoInternal.Builder(subInfo)
1964                 .setUserId(FAKE_USER_ID2).build();
1965         verifySubscription(subInfo);
1966         verify(mSubscriptionDatabaseManagerCallback, times(2)).onSubscriptionChanged(eq(1));
1967 
1968         assertThat(mDatabaseManagerUT.getSubscriptionProperty(1, SimInfo.COLUMN_USER_HANDLE))
1969                 .isEqualTo(FAKE_USER_ID2);
1970         mDatabaseManagerUT.setSubscriptionProperty(1, SimInfo.COLUMN_USER_HANDLE, FAKE_USER_ID1);
1971         assertThat(mDatabaseManagerUT.getSubscriptionInfoInternal(1)
1972                 .getUserId()).isEqualTo(FAKE_USER_ID1);
1973     }
1974 
1975     @Test
testUpdateSatelliteEnabled()1976     public void testUpdateSatelliteEnabled() throws Exception {
1977         // exception is expected if there is nothing in the database.
1978         assertThrows(IllegalArgumentException.class, () -> mDatabaseManagerUT.setSatelliteEnabled(
1979                 FAKE_SUBSCRIPTION_INFO1.getSubscriptionId(), 1));
1980 
1981         SubscriptionInfoInternal subInfo = insertSubscriptionAndVerify(FAKE_SUBSCRIPTION_INFO1);
1982         mDatabaseManagerUT.setSatelliteEnabled(FAKE_SUBSCRIPTION_INFO1.getSubscriptionId(),
1983                 1);
1984         processAllMessages();
1985 
1986         subInfo = new SubscriptionInfoInternal.Builder(subInfo)
1987                 .setSatelliteEnabled(1).build();
1988         verifySubscription(subInfo);
1989         verify(mSubscriptionDatabaseManagerCallback, times(2)).onSubscriptionChanged(eq(1));
1990 
1991         assertThat(mDatabaseManagerUT.getSubscriptionProperty(
1992                 FAKE_SUBSCRIPTION_INFO1.getSubscriptionId(), SimInfo.COLUMN_SATELLITE_ENABLED))
1993                 .isEqualTo(1);
1994 
1995         mDatabaseManagerUT.setSubscriptionProperty(FAKE_SUBSCRIPTION_INFO1.getSubscriptionId(),
1996                 SimInfo.COLUMN_SATELLITE_ENABLED, 0);
1997         assertThat(mDatabaseManagerUT.getSubscriptionInfoInternal(
1998                 FAKE_SUBSCRIPTION_INFO1.getSubscriptionId()).getSatelliteEnabled())
1999                 .isEqualTo(0);
2000     }
2001 
2002     @Test
testUpdateCarrierHandoverToSatelliteEnabled()2003     public void testUpdateCarrierHandoverToSatelliteEnabled() throws Exception {
2004         // exception is expected if there is nothing in the database.
2005         assertThrows(IllegalArgumentException.class,
2006                 () -> mDatabaseManagerUT.setSatelliteAttachEnabledForCarrier(
2007                         FAKE_SUBSCRIPTION_INFO1.getSubscriptionId(),
2008                         FAKE_SATELLITE_ATTACH_FOR_CARRIER_ENABLED));
2009 
2010         SubscriptionInfoInternal subInfo = insertSubscriptionAndVerify(FAKE_SUBSCRIPTION_INFO1);
2011         mDatabaseManagerUT.setSatelliteAttachEnabledForCarrier(
2012                 FAKE_SUBSCRIPTION_INFO1.getSubscriptionId(),
2013                 FAKE_SATELLITE_ATTACH_FOR_CARRIER_ENABLED);
2014         processAllMessages();
2015 
2016         subInfo = new SubscriptionInfoInternal.Builder(subInfo)
2017                 .setSatelliteAttachEnabledForCarrier(
2018                         FAKE_SATELLITE_ATTACH_FOR_CARRIER_ENABLED)
2019                 .build();
2020         verifySubscription(subInfo);
2021         verify(mSubscriptionDatabaseManagerCallback, times(2)).onSubscriptionChanged(eq(1));
2022 
2023         assertThat(mDatabaseManagerUT.getSubscriptionProperty(
2024                 FAKE_SUBSCRIPTION_INFO1.getSubscriptionId(),
2025                 SimInfo.COLUMN_SATELLITE_ATTACH_ENABLED_FOR_CARRIER))
2026                 .isEqualTo(FAKE_SATELLITE_ATTACH_FOR_CARRIER_ENABLED);
2027 
2028         mDatabaseManagerUT.setSubscriptionProperty(FAKE_SUBSCRIPTION_INFO1.getSubscriptionId(),
2029                 SimInfo.COLUMN_SATELLITE_ATTACH_ENABLED_FOR_CARRIER,
2030                 FAKE_SATELLITE_ATTACH_FOR_CARRIER_DISABLED);
2031         assertThat(mDatabaseManagerUT.getSubscriptionInfoInternal(
2032                 FAKE_SUBSCRIPTION_INFO1.getSubscriptionId())
2033                 .getSatelliteAttachEnabledForCarrier())
2034                 .isEqualTo(FAKE_SATELLITE_ATTACH_FOR_CARRIER_DISABLED);
2035     }
2036 
2037     @Test
testUpdateSatelliteNtn()2038     public void testUpdateSatelliteNtn() throws Exception {
2039         // exception is expected if there is nothing in the database.
2040         assertThrows(IllegalArgumentException.class,
2041                 () -> mDatabaseManagerUT.setNtn(FAKE_SUBSCRIPTION_INFO1.getSubscriptionId(),
2042                         FAKE_SATELLITE_IS_ONLY_NTN_ENABLED));
2043 
2044         SubscriptionInfoInternal subInfo = insertSubscriptionAndVerify(FAKE_SUBSCRIPTION_INFO1);
2045         mDatabaseManagerUT.setNtn(FAKE_SUBSCRIPTION_INFO1.getSubscriptionId(),
2046                 FAKE_SATELLITE_IS_ONLY_NTN_ENABLED);
2047         processAllMessages();
2048 
2049         subInfo = new SubscriptionInfoInternal.Builder(subInfo)
2050                 .setOnlyNonTerrestrialNetwork(FAKE_SATELLITE_IS_ONLY_NTN_ENABLED)
2051                 .build();
2052         verifySubscription(subInfo);
2053         verify(mSubscriptionDatabaseManagerCallback, times(2)).onSubscriptionChanged(eq(1));
2054 
2055         assertThat(mDatabaseManagerUT.getSubscriptionProperty(
2056                 FAKE_SUBSCRIPTION_INFO1.getSubscriptionId(),
2057                 SimInfo.COLUMN_IS_ONLY_NTN)).isEqualTo(FAKE_SATELLITE_IS_ONLY_NTN_ENABLED);
2058 
2059         mDatabaseManagerUT.setSubscriptionProperty(FAKE_SUBSCRIPTION_INFO1.getSubscriptionId(),
2060                 SimInfo.COLUMN_IS_ONLY_NTN, FAKE_SATELLITE_IS_ONLY_NTN_DISABLED);
2061         assertThat(mDatabaseManagerUT.getSubscriptionInfoInternal(
2062                         FAKE_SUBSCRIPTION_INFO1.getSubscriptionId()).getOnlyNonTerrestrialNetwork())
2063                 .isEqualTo(FAKE_SATELLITE_IS_ONLY_NTN_DISABLED);
2064     }
2065 
2066     @Test
testSetGroupDisabled()2067     public void testSetGroupDisabled() throws Exception {
2068         assertThrows(IllegalArgumentException.class,
2069                 () -> mDatabaseManagerUT.setGroupDisabled(
2070                         FAKE_SUBSCRIPTION_INFO1.getSubscriptionId(), true));
2071 
2072         insertSubscriptionAndVerify(FAKE_SUBSCRIPTION_INFO1);
2073         mDatabaseManagerUT.setGroupDisabled(FAKE_SUBSCRIPTION_INFO1.getSubscriptionId(), true);
2074         processAllMessages();
2075 
2076         assertThat(mDatabaseManagerUT.getSubscriptionInfoInternal(
2077             FAKE_SUBSCRIPTION_INFO1.getSubscriptionId()).isGroupDisabled()).isTrue();
2078 
2079         verify(mSubscriptionDatabaseManagerCallback, times(2)).onSubscriptionChanged(eq(1));
2080         Mockito.clearInvocations(mSubscriptionDatabaseManagerCallback);
2081 
2082         mDatabaseManagerUT.setGroupDisabled(FAKE_SUBSCRIPTION_INFO1.getSubscriptionId(), true);
2083         processAllMessages();
2084         verify(mSubscriptionDatabaseManagerCallback, never()).onSubscriptionChanged(eq(1));
2085 
2086         assertThat(mDatabaseManagerUT.getSubscriptionInfoInternal(
2087             FAKE_SUBSCRIPTION_INFO1.getSubscriptionId()).isGroupDisabled()).isTrue();
2088 
2089         mDatabaseManagerUT.setGroupDisabled(FAKE_SUBSCRIPTION_INFO1.getSubscriptionId(), false);
2090         processAllMessages();
2091         verify(mSubscriptionDatabaseManagerCallback, times(1)).onSubscriptionChanged(eq(1));
2092         assertThat(mDatabaseManagerUT.getSubscriptionInfoInternal(
2093                 FAKE_SUBSCRIPTION_INFO1.getSubscriptionId()).isGroupDisabled()).isFalse();
2094     }
2095 
2096     @Test
testUpdateSubscriptionsInGroup()2097     public void testUpdateSubscriptionsInGroup() throws Exception {
2098         insertSubscriptionAndVerify(FAKE_SUBSCRIPTION_INFO1);
2099         insertSubscriptionAndVerify(FAKE_SUBSCRIPTION_INFO2);
2100         // Two subs are now in the same group
2101         mDatabaseManagerUT.setGroupUuid(2, FAKE_UUID1);
2102 
2103         mDatabaseManagerUT.setWifiCallingEnabled(1, 1);
2104         assertThat(mDatabaseManagerUT.getSubscriptionInfoInternal(1)
2105                 .isWifiCallingEnabled()).isTrue();
2106         assertThat(mDatabaseManagerUT.getSubscriptionInfoInternal(2)
2107                 .isWifiCallingEnabled()).isTrue();
2108 
2109         mDatabaseManagerUT.setWifiCallingEnabled(1, 0);
2110         assertThat(mDatabaseManagerUT.getSubscriptionInfoInternal(1)
2111                 .isWifiCallingEnabled()).isFalse();
2112         assertThat(mDatabaseManagerUT.getSubscriptionInfoInternal(2)
2113                 .isWifiCallingEnabled()).isFalse();
2114 
2115         mDatabaseManagerUT.setUserId(1, 5678);
2116         assertThat(mDatabaseManagerUT.getSubscriptionInfoInternal(1)
2117                 .getUserId()).isEqualTo(5678);
2118         assertThat(mDatabaseManagerUT.getSubscriptionInfoInternal(2)
2119                 .getUserId()).isEqualTo(5678);
2120 
2121         mDatabaseManagerUT.setWifiCallingEnabledForRoaming(1, 0);
2122         assertThat(mDatabaseManagerUT.getSubscriptionInfoInternal(1)
2123                 .isWifiCallingEnabledForRoaming()).isFalse();
2124         assertThat(mDatabaseManagerUT.getSubscriptionInfoInternal(2)
2125                 .isWifiCallingEnabledForRoaming()).isFalse();
2126 
2127         mDatabaseManagerUT.setDisplayName(1, "Pokemon");
2128         assertThat(mDatabaseManagerUT.getSubscriptionInfoInternal(1)
2129                 .getDisplayName()).isEqualTo("Pokemon");
2130         assertThat(mDatabaseManagerUT.getSubscriptionInfoInternal(2)
2131                 .getDisplayName()).isEqualTo("Pokemon");
2132 
2133         // ICCID is not the field that will be synced to all subs in the group.
2134         mDatabaseManagerUT.setIccId(1, "0987");
2135         assertThat(mDatabaseManagerUT.getSubscriptionInfoInternal(1)
2136                 .getIccId()).isEqualTo("0987");
2137         assertThat(mDatabaseManagerUT.getSubscriptionInfoInternal(2)
2138                 .getIccId()).isEqualTo(FAKE_ICCID2);
2139     }
2140 
2141     @Test
testRemoveSubscriptionInfo()2142     public void testRemoveSubscriptionInfo() throws Exception {
2143         insertSubscriptionAndVerify(FAKE_SUBSCRIPTION_INFO1);
2144         insertSubscriptionAndVerify(FAKE_SUBSCRIPTION_INFO2);
2145         Mockito.clearInvocations(mSubscriptionDatabaseManagerCallback);
2146 
2147         mDatabaseManagerUT.removeSubscriptionInfo(1);
2148         assertThat(mDatabaseManagerUT.getSubscriptionInfoInternal(1)).isNull();
2149         assertThat(mDatabaseManagerUT.getSubscriptionInfoInternal(2))
2150                 .isEqualTo(FAKE_SUBSCRIPTION_INFO2);
2151         verify(mSubscriptionDatabaseManagerCallback).onSubscriptionChanged(eq(1));
2152 
2153         // Insert a new one. Should become sub 3.
2154         Mockito.clearInvocations(mSubscriptionDatabaseManagerCallback);
2155         insertSubscriptionAndVerify(FAKE_SUBSCRIPTION_INFO1);
2156         assertThat(mDatabaseManagerUT.getSubscriptionInfoInternal(1)).isNull();
2157         assertThat(mDatabaseManagerUT.getSubscriptionInfoInternal(2))
2158                 .isEqualTo(FAKE_SUBSCRIPTION_INFO2);
2159         assertThat(mDatabaseManagerUT.getSubscriptionInfoInternal(3))
2160                 .isEqualTo(new SubscriptionInfoInternal.Builder(FAKE_SUBSCRIPTION_INFO1)
2161                         .setId(3).build());
2162         verify(mSubscriptionDatabaseManagerCallback).onSubscriptionChanged(eq(3));
2163 
2164         Mockito.clearInvocations(mSubscriptionDatabaseManagerCallback);
2165         mDatabaseManagerUT.removeSubscriptionInfo(2);
2166         assertThat(mDatabaseManagerUT.getSubscriptionInfoInternal(1)).isNull();
2167         assertThat(mDatabaseManagerUT.getSubscriptionInfoInternal(2)).isNull();
2168         assertThat(mDatabaseManagerUT.getSubscriptionInfoInternal(3))
2169                 .isEqualTo(new SubscriptionInfoInternal.Builder(FAKE_SUBSCRIPTION_INFO1)
2170                         .setId(3).build());
2171         verify(mSubscriptionDatabaseManagerCallback).onSubscriptionChanged(eq(2));
2172 
2173         Mockito.clearInvocations(mSubscriptionDatabaseManagerCallback);
2174         mDatabaseManagerUT.removeSubscriptionInfo(3);
2175         assertThat(mDatabaseManagerUT.getSubscriptionInfoInternal(1)).isNull();
2176         assertThat(mDatabaseManagerUT.getSubscriptionInfoInternal(2)).isNull();
2177         assertThat(mDatabaseManagerUT.getSubscriptionInfoInternal(3)).isNull();
2178         verify(mSubscriptionDatabaseManagerCallback).onSubscriptionChanged(eq(3));
2179     }
2180 
2181     @Test
testCallback()2182     public void testCallback() {
2183         CountDownLatch latch = new CountDownLatch(2);
2184         Executor executor = Runnable::run;
2185         SubscriptionDatabaseManagerCallback callback =
2186                 new SubscriptionDatabaseManagerCallback(executor) {
2187                     @Override
2188                     public void onInitialized() {
2189                         latch.countDown();
2190                         logd("onInitialized");
2191                     }
2192 
2193                     @Override
2194                     public void onSubscriptionChanged(int subId) {
2195                         latch.countDown();
2196                         logd("onSubscriptionChanged");
2197                     }
2198                 };
2199         assertThat(callback.getExecutor()).isEqualTo(executor);
2200         mDatabaseManagerUT = new SubscriptionDatabaseManager(mContext, Looper.myLooper(),
2201                 mFeatureFlags, callback);
2202         processAllMessages();
2203 
2204         assertThat(latch.getCount()).isEqualTo(1);
2205 
2206         mDatabaseManagerUT.insertSubscriptionInfo(
2207                 new SubscriptionInfoInternal.Builder()
2208                         .setId(SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2209                         .setIccId(FAKE_ICCID1)
2210                         .setSimSlotIndex(0)
2211                         .build());
2212         processAllMessages();
2213         assertThat(latch.getCount()).isEqualTo(0);
2214     }
2215 
2216     @Test
testUpdateServiceCapabilities()2217     public void testUpdateServiceCapabilities() throws Exception {
2218         // exception is expected if there is nothing in the database.
2219         assertThrows(IllegalArgumentException.class,
2220                 () -> mDatabaseManagerUT.setServiceCapabilities(1,
2221                         FAKE_SERVICE_CAPABILITIES_2));
2222 
2223         SubscriptionInfoInternal subInfo = insertSubscriptionAndVerify(FAKE_SUBSCRIPTION_INFO1);
2224         mDatabaseManagerUT.setServiceCapabilities(subInfo.getSubscriptionId(),
2225                 FAKE_SERVICE_CAPABILITIES_2);
2226         processAllMessages();
2227 
2228         subInfo = new SubscriptionInfoInternal.Builder(subInfo).setServiceCapabilities(
2229                 FAKE_SERVICE_CAPABILITIES_2).build();
2230         verifySubscription(subInfo);
2231         verify(mSubscriptionDatabaseManagerCallback, times(2)).onSubscriptionChanged(eq(1));
2232 
2233         assertThat(mDatabaseManagerUT.getSubscriptionProperty(1,
2234                 SimInfo.COLUMN_SERVICE_CAPABILITIES))
2235                 .isEqualTo(FAKE_SERVICE_CAPABILITIES_2);
2236         mDatabaseManagerUT.setSubscriptionProperty(
2237                 1, SimInfo.COLUMN_SERVICE_CAPABILITIES,
2238                 FAKE_SERVICE_CAPABILITIES_1);
2239         assertThat(
2240                 mDatabaseManagerUT.getSubscriptionInfoInternal(1).getServiceCapabilities())
2241                 .isEqualTo(FAKE_SERVICE_CAPABILITIES_1);
2242     }
2243 
2244     @Test
testSetTransferStatus()2245     public void testSetTransferStatus() throws Exception {
2246         // exception is expected if there is nothing in the database.
2247         assertThrows(IllegalArgumentException.class,
2248                 () -> mDatabaseManagerUT.setTransferStatus(
2249                         FAKE_SUBSCRIPTION_INFO1.getSubscriptionId(),
2250                         FAKE_TRANSFER_STATUS_TRANSFERRED_OUT));
2251 
2252         SubscriptionInfoInternal subInfo = insertSubscriptionAndVerify(FAKE_SUBSCRIPTION_INFO1);
2253         mDatabaseManagerUT.setTransferStatus(FAKE_SUBSCRIPTION_INFO1.getSubscriptionId(),
2254                 FAKE_TRANSFER_STATUS_TRANSFERRED_OUT);
2255         processAllMessages();
2256 
2257         subInfo = new SubscriptionInfoInternal.Builder(subInfo)
2258                 .setTransferStatus(FAKE_TRANSFER_STATUS_TRANSFERRED_OUT)
2259                 .build();
2260         verifySubscription(subInfo);
2261         verify(mSubscriptionDatabaseManagerCallback, times(1)).onSubscriptionChanged(eq(1));
2262 
2263         assertThat(mDatabaseManagerUT.getSubscriptionProperty(
2264                 FAKE_SUBSCRIPTION_INFO1.getSubscriptionId(),
2265                 SimInfo.COLUMN_TRANSFER_STATUS)).isEqualTo(FAKE_TRANSFER_STATUS_TRANSFERRED_OUT);
2266 
2267         mDatabaseManagerUT.setSubscriptionProperty(FAKE_SUBSCRIPTION_INFO1.getSubscriptionId(),
2268                 SimInfo.COLUMN_TRANSFER_STATUS, FAKE_TRANSFER_STATUS_CONVERTED);
2269         assertThat(mDatabaseManagerUT.getSubscriptionInfoInternal(
2270                 FAKE_SUBSCRIPTION_INFO1.getSubscriptionId()).getTransferStatus())
2271                 .isEqualTo(FAKE_TRANSFER_STATUS_CONVERTED);
2272         assertThat(mDatabaseManagerUT.getSubscriptionInfoInternal(
2273                 FAKE_SUBSCRIPTION_INFO1.getSubscriptionId()).getTransferStatus())
2274                 .isNotEqualTo(FAKE_TRANSFER_STATUS_TRANSFERRED_OUT);
2275     }
2276 
2277     @Test
testUpdateSatelliteEntitlementStatus()2278     public void testUpdateSatelliteEntitlementStatus() throws Exception {
2279         // exception is expected if there is nothing in the database.
2280         assertThrows(IllegalArgumentException.class,
2281                 () -> mDatabaseManagerUT.setSatelliteEntitlementStatus(
2282                         FAKE_SUBSCRIPTION_INFO1.getSubscriptionId(),
2283                         FAKE_SATELLITE_ENTITLEMENT_STATUS_ENABLED));
2284 
2285         SubscriptionInfoInternal subInfo = insertSubscriptionAndVerify(FAKE_SUBSCRIPTION_INFO1);
2286         mDatabaseManagerUT.setSatelliteEntitlementStatus(
2287                 FAKE_SUBSCRIPTION_INFO1.getSubscriptionId(),
2288                 FAKE_SATELLITE_ENTITLEMENT_STATUS_ENABLED);
2289         processAllMessages();
2290 
2291         subInfo = new SubscriptionInfoInternal.Builder(subInfo)
2292                 .setSatelliteEntitlementStatus(FAKE_SATELLITE_ENTITLEMENT_STATUS_ENABLED)
2293                 .build();
2294         verifySubscription(subInfo);
2295         verify(mSubscriptionDatabaseManagerCallback, times(2)).onSubscriptionChanged(eq(1));
2296 
2297         assertThat(mDatabaseManagerUT.getSubscriptionProperty(
2298                 FAKE_SUBSCRIPTION_INFO1.getSubscriptionId(),
2299                 SimInfo.COLUMN_SATELLITE_ENTITLEMENT_STATUS))
2300                 .isEqualTo(FAKE_SATELLITE_ENTITLEMENT_STATUS_ENABLED);
2301 
2302         mDatabaseManagerUT.setSubscriptionProperty(FAKE_SUBSCRIPTION_INFO1.getSubscriptionId(),
2303                 SimInfo.COLUMN_SATELLITE_ENTITLEMENT_STATUS,
2304                 FAKE_SATELLITE_ENTITLEMENT_STATUS_DISABLED);
2305         assertThat(mDatabaseManagerUT.getSubscriptionInfoInternal(
2306                         FAKE_SUBSCRIPTION_INFO1.getSubscriptionId())
2307                 .getSatelliteEntitlementStatus())
2308                 .isEqualTo(FAKE_SATELLITE_ENTITLEMENT_STATUS_DISABLED);
2309     }
2310 
2311     @Test
testUpdateSatelliteEntitlementPlmns()2312     public void testUpdateSatelliteEntitlementPlmns() throws Exception {
2313         // exception is expected if there is nothing in the database.
2314         assertThrows(IllegalArgumentException.class,
2315                 () -> mDatabaseManagerUT.setSatelliteEntitlementPlmns(
2316                         FAKE_SUBSCRIPTION_INFO1.getSubscriptionId(),
2317                         FAKE_SATELLITE_ENTITLEMENT_PLMNS1));
2318 
2319         SubscriptionInfoInternal subInfo = insertSubscriptionAndVerify(FAKE_SUBSCRIPTION_INFO1);
2320         mDatabaseManagerUT.setSatelliteEntitlementPlmns(
2321                 FAKE_SUBSCRIPTION_INFO1.getSubscriptionId(),
2322                 FAKE_SATELLITE_ENTITLEMENT_PLMNS1);
2323         processAllMessages();
2324 
2325         subInfo = new SubscriptionInfoInternal.Builder(subInfo)
2326                 .setSatelliteEntitlementPlmns(FAKE_SATELLITE_ENTITLEMENT_PLMNS1)
2327                 .build();
2328         verifySubscription(subInfo);
2329         verify(mSubscriptionDatabaseManagerCallback, times(2)).onSubscriptionChanged(eq(1));
2330 
2331         assertThat(mDatabaseManagerUT.getSubscriptionProperty(
2332                 FAKE_SUBSCRIPTION_INFO1.getSubscriptionId(),
2333                 SimInfo.COLUMN_SATELLITE_ENTITLEMENT_PLMNS))
2334                 .isEqualTo(FAKE_SATELLITE_ENTITLEMENT_PLMNS1);
2335 
2336         mDatabaseManagerUT.setSubscriptionProperty(FAKE_SUBSCRIPTION_INFO1.getSubscriptionId(),
2337                 SimInfo.COLUMN_SATELLITE_ENTITLEMENT_PLMNS,
2338                 FAKE_SATELLITE_ENTITLEMENT_PLMNS2);
2339         assertThat(mDatabaseManagerUT.getSubscriptionInfoInternal(
2340                         FAKE_SUBSCRIPTION_INFO1.getSubscriptionId())
2341                 .getSatelliteEntitlementPlmns())
2342                 .isEqualTo(FAKE_SATELLITE_ENTITLEMENT_PLMNS2);
2343     }
2344 
2345     @Test
testUpdateSatelliteESOSSupported()2346     public void testUpdateSatelliteESOSSupported() throws Exception {
2347         // exception is expected if there is nothing in the database.
2348         assertThrows(IllegalArgumentException.class,
2349                 () -> mDatabaseManagerUT.setSatelliteESOSSupported(
2350                         FAKE_SUBSCRIPTION_INFO1.getSubscriptionId(),
2351                         FAKE_SATELLITE_ESOS_SUPPORTED_ENABLED));
2352 
2353         SubscriptionInfoInternal subInfo = insertSubscriptionAndVerify(FAKE_SUBSCRIPTION_INFO1);
2354         mDatabaseManagerUT.setSatelliteESOSSupported(FAKE_SUBSCRIPTION_INFO1.getSubscriptionId(),
2355                 FAKE_SATELLITE_ESOS_SUPPORTED_ENABLED);
2356         processAllMessages();
2357 
2358         subInfo = new SubscriptionInfoInternal.Builder(subInfo)
2359                 .setSatelliteESOSSupported(FAKE_SATELLITE_ESOS_SUPPORTED_ENABLED)
2360                 .build();
2361         verifySubscription(subInfo);
2362         verify(mSubscriptionDatabaseManagerCallback, times(2)).onSubscriptionChanged(eq(1));
2363 
2364         assertThat(mDatabaseManagerUT.getSubscriptionProperty(
2365                 FAKE_SUBSCRIPTION_INFO1.getSubscriptionId(),
2366                 SimInfo.COLUMN_SATELLITE_ESOS_SUPPORTED)).isEqualTo(
2367                 FAKE_SATELLITE_ESOS_SUPPORTED_ENABLED);
2368 
2369         mDatabaseManagerUT.setSubscriptionProperty(FAKE_SUBSCRIPTION_INFO1.getSubscriptionId(),
2370                 SimInfo.COLUMN_SATELLITE_ESOS_SUPPORTED, FAKE_SATELLITE_ESOS_SUPPORTED_DISABLED);
2371         assertThat(mDatabaseManagerUT.getSubscriptionInfoInternal(
2372                         FAKE_SUBSCRIPTION_INFO1.getSubscriptionId())
2373                 .getSatelliteESOSSupported()).isEqualTo(FAKE_SATELLITE_ESOS_SUPPORTED_DISABLED);
2374     }
2375 
2376     @Test
testUpdateSatelliteProvisionedStatus()2377     public void testUpdateSatelliteProvisionedStatus() throws Exception {
2378         // exception is expected if there is nothing in the database.
2379         assertThrows(IllegalArgumentException.class,
2380                 () -> mDatabaseManagerUT.setIsSatelliteProvisionedForNonIpDatagram(
2381                         FAKE_SUBSCRIPTION_INFO1.getSubscriptionId(),
2382                         FAKE_SATELLITE_PROVISIONED));
2383 
2384         SubscriptionInfoInternal subInfo = insertSubscriptionAndVerify(FAKE_SUBSCRIPTION_INFO1);
2385         mDatabaseManagerUT.setIsSatelliteProvisionedForNonIpDatagram(
2386                 FAKE_SUBSCRIPTION_INFO1.getSubscriptionId(),
2387                 FAKE_SATELLITE_PROVISIONED);
2388         processAllMessages();
2389 
2390         subInfo = new SubscriptionInfoInternal.Builder(subInfo)
2391                 .setIsSatelliteProvisionedForNonIpDatagram(FAKE_SATELLITE_PROVISIONED)
2392                 .build();
2393         verifySubscription(subInfo);
2394         verify(mSubscriptionDatabaseManagerCallback, times(2)).onSubscriptionChanged(eq(1));
2395 
2396         assertThat(mDatabaseManagerUT.getSubscriptionProperty(
2397                 FAKE_SUBSCRIPTION_INFO1.getSubscriptionId(),
2398                 SimInfo.COLUMN_IS_SATELLITE_PROVISIONED_FOR_NON_IP_DATAGRAM))
2399                 .isEqualTo(FAKE_SATELLITE_PROVISIONED);
2400 
2401         mDatabaseManagerUT.setSubscriptionProperty(FAKE_SUBSCRIPTION_INFO1.getSubscriptionId(),
2402                 SimInfo.COLUMN_IS_SATELLITE_PROVISIONED_FOR_NON_IP_DATAGRAM,
2403                 FAKE_SATELLITE_NOT_PROVISIONED);
2404         assertThat(mDatabaseManagerUT.getSubscriptionInfoInternal(
2405                         FAKE_SUBSCRIPTION_INFO1.getSubscriptionId())
2406                 .getIsSatelliteProvisionedForNonIpDatagram())
2407                 .isEqualTo(FAKE_SATELLITE_NOT_PROVISIONED);
2408     }
2409 
2410     @Test
testUpdateSatelliteEntitlementBarredPlmns()2411     public void testUpdateSatelliteEntitlementBarredPlmns() throws Exception {
2412         // exception is expected if there is nothing in the database.
2413         assertThrows(IllegalArgumentException.class,
2414                 () -> mDatabaseManagerUT.setSatelliteEntitlementBarredPlmns(
2415                         FAKE_SUBSCRIPTION_INFO1.getSubscriptionId(),
2416                         FAKE_SATELLITE_ENTITLEMENT_BARRED_PLMNS1));
2417 
2418         SubscriptionInfoInternal subInfo = insertSubscriptionAndVerify(FAKE_SUBSCRIPTION_INFO1);
2419         mDatabaseManagerUT.setSatelliteEntitlementBarredPlmns(
2420                 FAKE_SUBSCRIPTION_INFO1.getSubscriptionId(),
2421                 FAKE_SATELLITE_ENTITLEMENT_BARRED_PLMNS1);
2422         processAllMessages();
2423 
2424         subInfo = new SubscriptionInfoInternal.Builder(
2425                 subInfo).setSatelliteEntitlementBarredPlmnsList(
2426                 FAKE_SATELLITE_ENTITLEMENT_BARRED_PLMNS1).build();
2427         verifySubscription(subInfo);
2428         verify(mSubscriptionDatabaseManagerCallback, times(2)).onSubscriptionChanged(eq(1));
2429 
2430         assertThat(mDatabaseManagerUT.getSubscriptionProperty(
2431                 FAKE_SUBSCRIPTION_INFO1.getSubscriptionId(),
2432                 SimInfo.COLUMN_SATELLITE_ENTITLEMENT_BARRED_PLMNS)).isEqualTo(
2433                 FAKE_SATELLITE_ENTITLEMENT_BARRED_PLMNS1);
2434 
2435         mDatabaseManagerUT.setSubscriptionProperty(FAKE_SUBSCRIPTION_INFO1.getSubscriptionId(),
2436                 SimInfo.COLUMN_SATELLITE_ENTITLEMENT_BARRED_PLMNS,
2437                 FAKE_SATELLITE_ENTITLEMENT_BARRED_PLMNS2);
2438         assertThat(mDatabaseManagerUT.getSubscriptionInfoInternal(
2439                 FAKE_SUBSCRIPTION_INFO1.getSubscriptionId())
2440                 .getSatelliteEntitlementBarredPlmnsList()).isEqualTo(
2441                 FAKE_SATELLITE_ENTITLEMENT_BARRED_PLMNS2);
2442     }
2443 
2444     @Test
testUpdateSatelliteEntitlementDataPlanForPlmns()2445     public void testUpdateSatelliteEntitlementDataPlanForPlmns() throws Exception {
2446         // exception is expected if there is nothing in the database.
2447         assertThrows(IllegalArgumentException.class,
2448                 () -> mDatabaseManagerUT.setSatelliteEntitlementDataPlanForPlmns(
2449                         FAKE_SUBSCRIPTION_INFO1.getSubscriptionId(),
2450                         FAKE_SATELLITE_ENTITLEMENT_DATA_PLAN_PLMNS1));
2451 
2452         SubscriptionInfoInternal subInfo = insertSubscriptionAndVerify(FAKE_SUBSCRIPTION_INFO1);
2453         mDatabaseManagerUT.setSatelliteEntitlementDataPlanForPlmns(
2454                 FAKE_SUBSCRIPTION_INFO1.getSubscriptionId(),
2455                 FAKE_SATELLITE_ENTITLEMENT_DATA_PLAN_PLMNS1);
2456         processAllMessages();
2457 
2458         subInfo = new SubscriptionInfoInternal.Builder(
2459                 subInfo).setSatelliteEntitlementDataPlanForPlmns(
2460                 FAKE_SATELLITE_ENTITLEMENT_DATA_PLAN_PLMNS1).build();
2461         verifySubscription(subInfo);
2462         verify(mSubscriptionDatabaseManagerCallback, times(2)).onSubscriptionChanged(eq(1));
2463 
2464         assertThat(mDatabaseManagerUT.getSubscriptionProperty(
2465                 FAKE_SUBSCRIPTION_INFO1.getSubscriptionId(),
2466                 SimInfo.COLUMN_SATELLITE_ENTITLEMENT_DATA_PLAN_PLMNS)).isEqualTo(
2467                 FAKE_SATELLITE_ENTITLEMENT_DATA_PLAN_PLMNS1);
2468 
2469         mDatabaseManagerUT.setSubscriptionProperty(FAKE_SUBSCRIPTION_INFO1.getSubscriptionId(),
2470                 SimInfo.COLUMN_SATELLITE_ENTITLEMENT_DATA_PLAN_PLMNS,
2471                 FAKE_SATELLITE_ENTITLEMENT_DATA_PLAN_PLMNS2);
2472         assertThat(mDatabaseManagerUT.getSubscriptionInfoInternal(
2473                 FAKE_SUBSCRIPTION_INFO1.getSubscriptionId())
2474                 .getSatelliteEntitlementDataPlanForPlmns()).isEqualTo(
2475                 FAKE_SATELLITE_ENTITLEMENT_DATA_PLAN_PLMNS2);
2476     }
2477 
2478     @Test
testUpdateSatelliteEntitlementPlmnServiceTypeMap()2479     public void testUpdateSatelliteEntitlementPlmnServiceTypeMap() throws Exception {
2480         // exception is expected if there is nothing in the database.
2481         assertThrows(IllegalArgumentException.class,
2482                 () -> mDatabaseManagerUT.setSatelliteEntitlementPlmnServiceTypeMap(
2483                         FAKE_SUBSCRIPTION_INFO1.getSubscriptionId(),
2484                         FAKE_SATELLITE_ENTITLEMENT_SERVICE_TYPE_MAP1));
2485 
2486         SubscriptionInfoInternal subInfo = insertSubscriptionAndVerify(FAKE_SUBSCRIPTION_INFO1);
2487         mDatabaseManagerUT.setSatelliteEntitlementPlmnServiceTypeMap(
2488                 FAKE_SUBSCRIPTION_INFO1.getSubscriptionId(),
2489                 FAKE_SATELLITE_ENTITLEMENT_SERVICE_TYPE_MAP1);
2490         processAllMessages();
2491 
2492         subInfo = new SubscriptionInfoInternal.Builder(
2493                 subInfo).setSatelliteEntitlementPlmnServiceTypes(
2494                 FAKE_SATELLITE_ENTITLEMENT_SERVICE_TYPE_MAP1).build();
2495         verifySubscription(subInfo);
2496         verify(mSubscriptionDatabaseManagerCallback, times(2)).onSubscriptionChanged(eq(1));
2497 
2498         assertThat(mDatabaseManagerUT.getSubscriptionProperty(
2499                 FAKE_SUBSCRIPTION_INFO1.getSubscriptionId(),
2500                 SimInfo.COLUMN_SATELLITE_ENTITLEMENT_SERVICE_TYPE_MAP)).isEqualTo(
2501                 FAKE_SATELLITE_ENTITLEMENT_SERVICE_TYPE_MAP1);
2502 
2503         mDatabaseManagerUT.setSubscriptionProperty(FAKE_SUBSCRIPTION_INFO1.getSubscriptionId(),
2504                 SimInfo.COLUMN_SATELLITE_ENTITLEMENT_SERVICE_TYPE_MAP,
2505                 FAKE_SATELLITE_ENTITLEMENT_SERVICE_TYPE_MAP2);
2506         assertThat(mDatabaseManagerUT.getSubscriptionInfoInternal(
2507                 FAKE_SUBSCRIPTION_INFO1.getSubscriptionId())
2508                 .getSatelliteEntitlementPlmnsServiceTypes()).isEqualTo(
2509                 FAKE_SATELLITE_ENTITLEMENT_SERVICE_TYPE_MAP2);
2510     }
2511 
2512     @Test
testUpdateSatelliteEntitlementPlmnDataServicePolicy()2513     public void testUpdateSatelliteEntitlementPlmnDataServicePolicy() throws Exception {
2514         // exception is expected if there is nothing in the database.
2515         assertThrows(IllegalArgumentException.class,
2516                 () -> mDatabaseManagerUT.setSatelliteEntitlementPlmnDataServicePolicy(
2517                         FAKE_SUBSCRIPTION_INFO1.getSubscriptionId(),
2518                         FAKE_SATELLITE_ENTITLEMENT_DATA_SERVICE_POLICY1));
2519 
2520         SubscriptionInfoInternal subInfo = insertSubscriptionAndVerify(FAKE_SUBSCRIPTION_INFO1);
2521         mDatabaseManagerUT.setSatelliteEntitlementPlmnDataServicePolicy(
2522                 FAKE_SUBSCRIPTION_INFO1.getSubscriptionId(),
2523                 FAKE_SATELLITE_ENTITLEMENT_DATA_SERVICE_POLICY1);
2524         processAllMessages();
2525 
2526         subInfo = new SubscriptionInfoInternal.Builder(subInfo).setSatellitePlmnsDataServicePolicy(
2527                 FAKE_SATELLITE_ENTITLEMENT_DATA_SERVICE_POLICY1).build();
2528         verifySubscription(subInfo);
2529         verify(mSubscriptionDatabaseManagerCallback, times(2)).onSubscriptionChanged(eq(1));
2530 
2531         assertThat(mDatabaseManagerUT.getSubscriptionProperty(
2532                 FAKE_SUBSCRIPTION_INFO1.getSubscriptionId(),
2533                 SimInfo.COLUMN_SATELLITE_ENTITLEMENT_DATA_SERVICE_POLICY)).isEqualTo(
2534                 FAKE_SATELLITE_ENTITLEMENT_DATA_SERVICE_POLICY1);
2535 
2536         mDatabaseManagerUT.setSubscriptionProperty(FAKE_SUBSCRIPTION_INFO1.getSubscriptionId(),
2537                 SimInfo.COLUMN_SATELLITE_ENTITLEMENT_DATA_SERVICE_POLICY,
2538                 FAKE_SATELLITE_ENTITLEMENT_DATA_SERVICE_POLICY2);
2539         assertThat(mDatabaseManagerUT.getSubscriptionInfoInternal(
2540                 FAKE_SUBSCRIPTION_INFO1.getSubscriptionId())
2541                 .getSatellitePlmnsDataServicePolicy()).isEqualTo(
2542                 FAKE_SATELLITE_ENTITLEMENT_DATA_SERVICE_POLICY2);
2543     }
2544 
2545     @Test
testUpdateSatelliteEntitlementPlmnVoiceServicePolicy()2546     public void testUpdateSatelliteEntitlementPlmnVoiceServicePolicy() throws Exception {
2547         // exception is expected if there is nothing in the database.
2548         assertThrows(IllegalArgumentException.class,
2549                 () -> mDatabaseManagerUT.setSatelliteEntitlementPlmnVoiceServicePolicy(
2550                         FAKE_SUBSCRIPTION_INFO1.getSubscriptionId(),
2551                         FAKE_SATELLITE_ENTITLEMENT_VOICE_SERVICE_POLICY1));
2552 
2553         SubscriptionInfoInternal subInfo = insertSubscriptionAndVerify(FAKE_SUBSCRIPTION_INFO1);
2554         mDatabaseManagerUT.setSatelliteEntitlementPlmnVoiceServicePolicy(
2555                 FAKE_SUBSCRIPTION_INFO1.getSubscriptionId(),
2556                 FAKE_SATELLITE_ENTITLEMENT_VOICE_SERVICE_POLICY1);
2557         processAllMessages();
2558 
2559         subInfo = new SubscriptionInfoInternal.Builder(subInfo).setSatellitePlmnsVoiceServicePolicy(
2560                 FAKE_SATELLITE_ENTITLEMENT_VOICE_SERVICE_POLICY1).build();
2561         verifySubscription(subInfo);
2562         verify(mSubscriptionDatabaseManagerCallback, times(2)).onSubscriptionChanged(eq(1));
2563 
2564         assertThat(mDatabaseManagerUT.getSubscriptionProperty(
2565                 FAKE_SUBSCRIPTION_INFO1.getSubscriptionId(),
2566                 SimInfo.COLUMN_SATELLITE_ENTITLEMENT_VOICE_SERVICE_POLICY)).isEqualTo(
2567                 FAKE_SATELLITE_ENTITLEMENT_VOICE_SERVICE_POLICY1);
2568 
2569         mDatabaseManagerUT.setSubscriptionProperty(FAKE_SUBSCRIPTION_INFO1.getSubscriptionId(),
2570                 SimInfo.COLUMN_SATELLITE_ENTITLEMENT_VOICE_SERVICE_POLICY,
2571                 FAKE_SATELLITE_ENTITLEMENT_VOICE_SERVICE_POLICY2);
2572         assertThat(mDatabaseManagerUT.getSubscriptionInfoInternal(
2573                 FAKE_SUBSCRIPTION_INFO1.getSubscriptionId())
2574                 .getSatellitePlmnsVoiceServicePolicy()).isEqualTo(
2575                 FAKE_SATELLITE_ENTITLEMENT_VOICE_SERVICE_POLICY2);
2576     }
2577 }
2578