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