Merge "Improve the number on "Label SIM" page" into main
diff --git a/src/com/android/settings/accessibility/HearingDevicePairingFragment.java b/src/com/android/settings/accessibility/HearingDevicePairingFragment.java
index 0b762f3..c797559 100644
--- a/src/com/android/settings/accessibility/HearingDevicePairingFragment.java
+++ b/src/com/android/settings/accessibility/HearingDevicePairingFragment.java
@@ -192,7 +192,7 @@
     public void onDeviceBondStateChanged(@NonNull CachedBluetoothDevice cachedDevice,
             int bondState) {
         if (DEBUG) {
-            Log.d(TAG, "onDeviceBondStateChanged: " + cachedDevice.getDevice() + ", state = "
+            Log.d(TAG, "onDeviceBondStateChanged: " + cachedDevice + ", state = "
                     + bondState);
         }
         if (bondState == BluetoothDevice.BOND_BONDED) {
@@ -276,13 +276,13 @@
         }
         mDevicePreferenceMap.put(cachedDevice, preference);
         if (DEBUG) {
-            Log.d(TAG, "Add device. device: " + cachedDevice.getDevice());
+            Log.d(TAG, "Add device. device: " + cachedDevice);
         }
     }
 
     void removeDevice(CachedBluetoothDevice cachedDevice) {
         if (DEBUG) {
-            Log.d(TAG, "removeDevice: " + cachedDevice.getDevice());
+            Log.d(TAG, "removeDevice: " + cachedDevice);
         }
         BluetoothDevicePreference preference = mDevicePreferenceMap.remove(cachedDevice);
         if (mAvailableHearingDeviceGroup != null && preference != null) {
@@ -331,13 +331,13 @@
             cachedDevice = mCachedDeviceManager.addDevice(device);
         } else if (cachedDevice.getBondState() == BluetoothDevice.BOND_BONDED) {
             if (DEBUG) {
-                Log.d(TAG, "Skip this device, already bonded: " + cachedDevice.getDevice());
+                Log.d(TAG, "Skip this device, already bonded: " + cachedDevice);
             }
             return;
         }
         if (cachedDevice.getHearingAidInfo() == null) {
             if (DEBUG) {
-                Log.d(TAG, "Set hearing aid info on device: " + cachedDevice.getDevice());
+                Log.d(TAG, "Set hearing aid info on device: " + cachedDevice);
             }
             cachedDevice.setHearingAidInfo(new HearingAidInfo.Builder().build());
         }
@@ -455,7 +455,7 @@
 
     void discoverServices(CachedBluetoothDevice cachedDevice) {
         if (DEBUG) {
-            Log.d(TAG, "connectGattToCheckCompatibility, device: " + cachedDevice.getDevice());
+            Log.d(TAG, "connectGattToCheckCompatibility, device: " + cachedDevice);
         }
         BluetoothGatt gatt = cachedDevice.getDevice().connectGatt(getContext(), false,
                 new BluetoothGattCallback() {
@@ -465,7 +465,7 @@
                         super.onConnectionStateChange(gatt, status, newState);
                         if (DEBUG) {
                             Log.d(TAG, "onConnectionStateChange, status: " + status + ", newState: "
-                                    + newState + ", device: " + cachedDevice.getDevice());
+                                    + newState + ", device: " + cachedDevice);
                         }
                         if (status == GATT_SUCCESS
                                 && newState == BluetoothProfile.STATE_CONNECTED) {
@@ -481,14 +481,14 @@
                         super.onServicesDiscovered(gatt, status);
                         if (DEBUG) {
                             Log.d(TAG, "onServicesDiscovered, status: " + status + ", device: "
-                                    + cachedDevice.getDevice());
+                                    + cachedDevice);
                         }
                         if (status == GATT_SUCCESS) {
                             if (gatt.getService(BluetoothUuid.HEARING_AID.getUuid()) != null
                                     || gatt.getService(BluetoothUuid.HAS.getUuid()) != null) {
                                 if (DEBUG) {
                                     Log.d(TAG, "compatible with Android, device: "
-                                            + cachedDevice.getDevice());
+                                            + cachedDevice);
                                 }
                                 addDevice(cachedDevice);
                             }
diff --git a/src/com/android/settings/accessibility/KeyboardVibrationTogglePreferenceController.java b/src/com/android/settings/accessibility/KeyboardVibrationTogglePreferenceController.java
index 58aa0cc..21800b9 100644
--- a/src/com/android/settings/accessibility/KeyboardVibrationTogglePreferenceController.java
+++ b/src/com/android/settings/accessibility/KeyboardVibrationTogglePreferenceController.java
@@ -22,6 +22,7 @@
 import static com.android.settings.accessibility.AccessibilityUtil.State.ON;
 
 import android.app.settings.SettingsEnums;
+import android.content.ContentResolver;
 import android.content.Context;
 import android.database.ContentObserver;
 import android.net.Uri;
@@ -159,8 +160,11 @@
     }
 
     private boolean updateKeyboardVibrationSetting(boolean enable) {
-        final boolean success = Settings.System.putInt(mContext.getContentResolver(),
-                    KEYBOARD_VIBRATION_ENABLED, enable ? ON : OFF);
+        final ContentResolver contentResolver = mContext.getContentResolver();
+        final boolean success = Settings.System.putInt(contentResolver,
+                KEYBOARD_VIBRATION_ENABLED, enable ? ON : OFF);
+        contentResolver.notifyChange(Settings.System.getUriFor(KEYBOARD_VIBRATION_ENABLED),
+                null /* observer */, ContentResolver.NOTIFY_NO_DELAY);
         if (!success) {
             Log.w(TAG, "Update settings database error!");
         }
diff --git a/src/com/android/settings/network/telephony/MobileNetworkEidPreferenceController.kt b/src/com/android/settings/network/telephony/MobileNetworkEidPreferenceController.kt
index 907bab1..1e635a5 100644
--- a/src/com/android/settings/network/telephony/MobileNetworkEidPreferenceController.kt
+++ b/src/com/android/settings/network/telephony/MobileNetworkEidPreferenceController.kt
@@ -84,6 +84,13 @@
     }
 
     override fun onViewCreated(viewLifecycleOwner: LifecycleOwner) {
+        if (!this::lazyViewModel.isInitialized) {
+            Log.e(
+                this.javaClass.simpleName,
+                "lateinit property lazyViewModel has not been initialized"
+            )
+            return
+        }
         preference.isVisible = false
 
         val viewModel by lazyViewModel
diff --git a/src/com/android/settings/network/telephony/MobileNetworkImeiPreferenceController.kt b/src/com/android/settings/network/telephony/MobileNetworkImeiPreferenceController.kt
index 8ec313b..e134681 100644
--- a/src/com/android/settings/network/telephony/MobileNetworkImeiPreferenceController.kt
+++ b/src/com/android/settings/network/telephony/MobileNetworkImeiPreferenceController.kt
@@ -78,6 +78,13 @@
     }
 
     override fun onViewCreated(viewLifecycleOwner: LifecycleOwner) {
+        if (!this::lazyViewModel.isInitialized) {
+            Log.e(
+                this.javaClass.simpleName,
+                "lateinit property lazyViewModel has not been initialized"
+            )
+            return
+        }
         val viewModel by lazyViewModel
         val coroutineScope = viewLifecycleOwner.lifecycleScope
 
diff --git a/src/com/android/settings/network/telephony/MobileNetworkPhoneNumberPreferenceController.kt b/src/com/android/settings/network/telephony/MobileNetworkPhoneNumberPreferenceController.kt
index 65a4b7e..10a8b53 100644
--- a/src/com/android/settings/network/telephony/MobileNetworkPhoneNumberPreferenceController.kt
+++ b/src/com/android/settings/network/telephony/MobileNetworkPhoneNumberPreferenceController.kt
@@ -19,6 +19,7 @@
 import android.content.Context
 import android.telephony.SubscriptionInfo
 import android.telephony.SubscriptionManager
+import android.util.Log
 import androidx.annotation.VisibleForTesting
 import androidx.fragment.app.Fragment
 import androidx.fragment.app.viewModels
@@ -66,6 +67,13 @@
     }
 
     override fun onViewCreated(viewLifecycleOwner: LifecycleOwner) {
+        if (!this::lazyViewModel.isInitialized) {
+            Log.e(
+                this.javaClass.simpleName,
+                "lateinit property lazyViewModel has not been initialized"
+            )
+            return
+        }
         val viewModel by lazyViewModel
         val coroutineScope = viewLifecycleOwner.lifecycleScope
 
diff --git a/src/com/android/settings/network/telephony/MobileNetworkSpnPreferenceController.kt b/src/com/android/settings/network/telephony/MobileNetworkSpnPreferenceController.kt
index ac055b0..4736eb7 100644
--- a/src/com/android/settings/network/telephony/MobileNetworkSpnPreferenceController.kt
+++ b/src/com/android/settings/network/telephony/MobileNetworkSpnPreferenceController.kt
@@ -19,6 +19,7 @@
 import android.content.Context
 import android.telephony.SubscriptionInfo
 import android.telephony.SubscriptionManager
+import android.util.Log
 import androidx.annotation.VisibleForTesting
 import androidx.fragment.app.Fragment
 import androidx.fragment.app.viewModels
@@ -26,6 +27,7 @@
 import androidx.preference.Preference
 import androidx.preference.PreferenceScreen
 import com.android.settings.flags.Flags
+import com.android.settings.network.SimOnboardingActivity
 import com.android.settings.network.SubscriptionInfoListViewModel
 import com.android.settingslib.spa.framework.util.collectLatestWithLifecycle
 
@@ -57,6 +59,14 @@
     }
 
     override fun onViewCreated(viewLifecycleOwner: LifecycleOwner) {
+        if (!this::lazyViewModel.isInitialized) {
+            Log.e(
+                this.javaClass.simpleName,
+                "lateinit property lazyViewModel has not been initialized"
+            )
+            return
+        }
+
         val viewModel by lazyViewModel
 
         viewModel.subscriptionInfoListFlow
diff --git a/src/com/android/settings/network/telephony/WifiCallingPreferenceController.kt b/src/com/android/settings/network/telephony/WifiCallingPreferenceController.kt
index 0ee1d87..f184092 100644
--- a/src/com/android/settings/network/telephony/WifiCallingPreferenceController.kt
+++ b/src/com/android/settings/network/telephony/WifiCallingPreferenceController.kt
@@ -22,6 +22,7 @@
 import android.telephony.SubscriptionManager
 import android.telephony.TelephonyManager
 import android.telephony.ims.ImsMmTelManager
+import android.util.Log
 import androidx.lifecycle.LifecycleOwner
 import androidx.preference.Preference
 import androidx.preference.PreferenceScreen
@@ -76,6 +77,13 @@
     }
 
     override fun onViewCreated(viewLifecycleOwner: LifecycleOwner) {
+        if(mSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID){
+            Log.e(
+                this.javaClass.simpleName,
+                "mSubId is INVALID_SUBSCRIPTION_ID"
+            )
+            return
+        }
         wifiCallingRepositoryFactory(mSubId).wifiCallingReadyFlow()
             .collectLatestWithLifecycle(viewLifecycleOwner) { isReady ->
                 preference.isVisible = isReady
diff --git a/src/com/android/settings/network/telephony/gsm/AutoSelectPreferenceController.kt b/src/com/android/settings/network/telephony/gsm/AutoSelectPreferenceController.kt
index d709574..67a2356 100644
--- a/src/com/android/settings/network/telephony/gsm/AutoSelectPreferenceController.kt
+++ b/src/com/android/settings/network/telephony/gsm/AutoSelectPreferenceController.kt
@@ -23,6 +23,7 @@
 import android.provider.Settings
 import android.telephony.CarrierConfigManager
 import android.telephony.ServiceState
+import android.telephony.SubscriptionManager
 import android.telephony.TelephonyManager
 import androidx.annotation.VisibleForTesting
 import androidx.compose.runtime.Composable
@@ -80,7 +81,7 @@
     @VisibleForTesting
     var progressDialog: ProgressDialog? = null
 
-    private var subId by notNull<Int>()
+    private var subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID
 
     /**
      * Initialization based on given subscription id.
diff --git a/tests/robotests/src/com/android/settings/accessibility/HearingDevicePairingFragmentTest.java b/tests/robotests/src/com/android/settings/accessibility/HearingDevicePairingFragmentTest.java
index e14686e..db82be6 100644
--- a/tests/robotests/src/com/android/settings/accessibility/HearingDevicePairingFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/accessibility/HearingDevicePairingFragmentTest.java
@@ -178,7 +178,7 @@
     }
 
     @Test
-    public void handleLeScanResult_isNotAndroidCompatible_() {
+    public void handleLeScanResult_isNotAndroidCompatible_discoverServices() {
         ScanResult scanResult = mock(ScanResult.class);
         doReturn(mDevice).when(scanResult).getDevice();
         doReturn(mCachedDevice).when(mCachedDeviceManager).findDevice(mDevice);
@@ -190,6 +190,19 @@
     }
 
     @Test
+    public void handleLeScanResult_alreadyBonded_doNothing() {
+        ScanResult scanResult = mock(ScanResult.class);
+        doReturn(mDevice).when(scanResult).getDevice();
+        doReturn(mCachedDevice).when(mCachedDeviceManager).findDevice(mDevice);
+        doReturn(BluetoothDevice.BOND_BONDED).when(mCachedDevice).getBondState();
+
+        mFragment.handleLeScanResult(scanResult);
+
+        verify(mFragment, never()).addDevice(mCachedDevice);
+        verify(mFragment, never()).discoverServices(mCachedDevice);
+    }
+
+    @Test
     public void onProfileConnectionStateChanged_deviceConnected_inSelectedList_finish() {
         doReturn(true).when(mCachedDevice).isConnected();
         mFragment.mSelectedDeviceList.add(mDevice);
diff --git a/tests/robotests/src/com/android/settings/accessibility/KeyboardVibrationTogglePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/accessibility/KeyboardVibrationTogglePreferenceControllerTest.java
index 2d5905e..832a313 100644
--- a/tests/robotests/src/com/android/settings/accessibility/KeyboardVibrationTogglePreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/accessibility/KeyboardVibrationTogglePreferenceControllerTest.java
@@ -30,6 +30,7 @@
 import static org.mockito.Mockito.verify;
 
 import android.app.settings.SettingsEnums;
+import android.content.ContentResolver;
 import android.content.Context;
 import android.content.res.Resources;
 import android.os.vibrator.Flags;
@@ -60,6 +61,9 @@
     @Mock
     private PreferenceScreen mPreferenceScreen;
 
+    @Mock
+    private ContentResolver mContentResolver;
+
     private Context mContext;
     private Resources mResources;
     private KeyboardVibrationTogglePreferenceController mController;
@@ -72,6 +76,7 @@
         mContext = spy(ApplicationProvider.getApplicationContext());
         mResources = spy(mContext.getResources());
         when(mContext.getResources()).thenReturn(mResources);
+        when(mContext.getContentResolver()).thenReturn(mContentResolver);
         mFeatureFactory = FakeFeatureFactory.setupForTest();
         mController = new KeyboardVibrationTogglePreferenceController(mContext, "preferenceKey");
         mPreference = new SwitchPreference(mContext);