Merge "Do not show 2nd FingerprintErrorDialog" into tm-qpr-dev
diff --git a/src/com/android/settings/biometrics/fingerprint/FingerprintSettings.java b/src/com/android/settings/biometrics/fingerprint/FingerprintSettings.java
index 44b3a40..c031fe6 100644
--- a/src/com/android/settings/biometrics/fingerprint/FingerprintSettings.java
+++ b/src/com/android/settings/biometrics/fingerprint/FingerprintSettings.java
@@ -669,6 +669,14 @@
                 mLaunchedConfirm = false;
                 if (resultCode == RESULT_FINISHED || resultCode == RESULT_OK) {
                     if (data != null && BiometricUtils.containsGatekeeperPasswordHandle(data)) {
+                        if (!mHasFirstEnrolled && !mIsEnrolling) {
+                            final Activity activity = getActivity();
+                            if (activity != null) {
+                                // Apply pending transition for auto adding first fingerprint case
+                                activity.overridePendingTransition(R.anim.sud_slide_next_in,
+                                        R.anim.sud_slide_next_out);
+                            }
+                        }
                         mFingerprintManager.generateChallenge(mUserId,
                                 (sensorId, userId, challenge) -> {
                                     mToken = BiometricUtils.requestGatekeeperHat(getActivity(),
diff --git a/src/com/android/settings/development/BluetoothA2dpHwOffloadPreferenceController.java b/src/com/android/settings/development/BluetoothA2dpHwOffloadPreferenceController.java
index 793b7fb..e47048a 100644
--- a/src/com/android/settings/development/BluetoothA2dpHwOffloadPreferenceController.java
+++ b/src/com/android/settings/development/BluetoothA2dpHwOffloadPreferenceController.java
@@ -102,7 +102,7 @@
         final boolean offloadDisabled =
                 SystemProperties.getBoolean(A2DP_OFFLOAD_DISABLED_PROPERTY, false);
         SystemProperties.set(A2DP_OFFLOAD_DISABLED_PROPERTY, Boolean.toString(!offloadDisabled));
-        if (offloadDisabled) {
+        if (!offloadDisabled) {
             SystemProperties.set(LE_AUDIO_OFFLOAD_DISABLED_PROPERTY,
                     Boolean.toString(!offloadDisabled));
         }
diff --git a/src/com/android/settings/development/BluetoothLeAudioHwOffloadPreferenceController.java b/src/com/android/settings/development/BluetoothLeAudioHwOffloadPreferenceController.java
index 751ddce..904f828 100644
--- a/src/com/android/settings/development/BluetoothLeAudioHwOffloadPreferenceController.java
+++ b/src/com/android/settings/development/BluetoothLeAudioHwOffloadPreferenceController.java
@@ -16,7 +16,8 @@
 
 package com.android.settings.development;
 
-import static com.android.settings.development.BluetoothA2dpHwOffloadPreferenceController.A2DP_OFFLOAD_SUPPORTED_PROPERTY;
+import static com.android.settings.development.BluetoothA2dpHwOffloadPreferenceController.A2DP_OFFLOAD_DISABLED_PROPERTY;
+
 
 import android.bluetooth.BluetoothAdapter;
 import android.bluetooth.BluetoothManager;
@@ -79,11 +80,11 @@
 
         final boolean leAudioEnabled =
                 (mBluetoothAdapter.isLeAudioSupported() == BluetoothStatusCodes.FEATURE_SUPPORTED);
-
-        final boolean offloadSupported =
-                SystemProperties.getBoolean(A2DP_OFFLOAD_SUPPORTED_PROPERTY, false)
-                && SystemProperties.getBoolean(LE_AUDIO_OFFLOAD_SUPPORTED_PROPERTY, false);
-        if (leAudioEnabled && offloadSupported) {
+        final boolean leAudioOffloadSupported =
+                SystemProperties.getBoolean(LE_AUDIO_OFFLOAD_SUPPORTED_PROPERTY, false);
+        final boolean a2dpOffloadDisabled =
+                SystemProperties.getBoolean(A2DP_OFFLOAD_DISABLED_PROPERTY, false);
+        if (leAudioEnabled && leAudioOffloadSupported && !a2dpOffloadDisabled) {
             final boolean offloadDisabled =
                     SystemProperties.getBoolean(LE_AUDIO_OFFLOAD_DISABLED_PROPERTY, true);
             ((SwitchPreference) mPreference).setChecked(offloadDisabled);
@@ -102,10 +103,11 @@
 
         final boolean leAudioEnabled =
                 (mBluetoothAdapter.isLeAudioSupported() == BluetoothStatusCodes.FEATURE_SUPPORTED);
-        final boolean offloadSupported =
-                SystemProperties.getBoolean(A2DP_OFFLOAD_SUPPORTED_PROPERTY, false)
-                && SystemProperties.getBoolean(LE_AUDIO_OFFLOAD_SUPPORTED_PROPERTY, false);
-        if (leAudioEnabled && offloadSupported) {
+        final boolean leAudioOffloadSupported =
+                SystemProperties.getBoolean(LE_AUDIO_OFFLOAD_SUPPORTED_PROPERTY, false);
+        final boolean a2dpOffloadDisabled =
+                SystemProperties.getBoolean(A2DP_OFFLOAD_DISABLED_PROPERTY, false);
+        if (leAudioEnabled && leAudioOffloadSupported && !a2dpOffloadDisabled) {
             ((SwitchPreference) mPreference).setChecked(true);
             SystemProperties.set(LE_AUDIO_OFFLOAD_DISABLED_PROPERTY, "true");
         } else {
@@ -118,7 +120,7 @@
      */
     public boolean isDefaultValue() {
         final boolean offloadSupported =
-                SystemProperties.getBoolean(A2DP_OFFLOAD_SUPPORTED_PROPERTY, false)
+                !SystemProperties.getBoolean(A2DP_OFFLOAD_DISABLED_PROPERTY, false)
                 && SystemProperties.getBoolean(LE_AUDIO_OFFLOAD_SUPPORTED_PROPERTY, false);
         final boolean offloadDisabled =
                     SystemProperties.getBoolean(LE_AUDIO_OFFLOAD_DISABLED_PROPERTY, false);
@@ -133,11 +135,11 @@
             return;
         }
 
-        final boolean offloadDisabled =
+        final boolean leaudioOffloadDisabled =
                 SystemProperties.getBoolean(LE_AUDIO_OFFLOAD_DISABLED_PROPERTY,
                 false);
         SystemProperties.set(LE_AUDIO_OFFLOAD_DISABLED_PROPERTY,
-                Boolean.toString(!offloadDisabled));
+                Boolean.toString(!leaudioOffloadDisabled));
     }
 
     /**
diff --git a/src/com/android/settings/network/CarrierConfigChangedReceiver.java b/src/com/android/settings/network/CarrierConfigChangedReceiver.java
index 8a6d47d..d9ff03e 100644
--- a/src/com/android/settings/network/CarrierConfigChangedReceiver.java
+++ b/src/com/android/settings/network/CarrierConfigChangedReceiver.java
@@ -32,9 +32,20 @@
             CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED;
 
     private final CountDownLatch mLatch;
+    private final boolean mIsWaitingForValidSubId;
 
-    public CarrierConfigChangedReceiver(CountDownLatch latch) {
+    /**
+     * This is the CarrierConfigChanged receiver. If it receives the carrier config changed, then it
+     * call the CountDownLatch.countDown().
+     * If the "isWaitingForValidSubId" is true, then the receiver skip the carrier config changed
+     * with the subId = -1. The receiver executes the countDown when the CarrierConfigChanged
+     * with valid subId.
+     * If the "isWaitingForValidSubId" is false, then the receiver executes the countDown when
+     * receiving any CarrierConfigChanged.
+     */
+    public CarrierConfigChangedReceiver(CountDownLatch latch, boolean isWaitingForValidSubId) {
         mLatch = latch;
+        mIsWaitingForValidSubId = isWaitingForValidSubId;
     }
 
     public void registerOn(Context context) {
@@ -53,7 +64,8 @@
     }
 
     private void checkSubscriptionIndex(Intent intent) {
-        if (intent.hasExtra(CarrierConfigManager.EXTRA_SUBSCRIPTION_INDEX)) {
+        if (intent.hasExtra(CarrierConfigManager.EXTRA_SUBSCRIPTION_INDEX)
+                || !mIsWaitingForValidSubId) {
             int subId = intent.getIntExtra(CarrierConfigManager.EXTRA_SUBSCRIPTION_INDEX, -1);
             Log.i(TAG, "subId from config changed: " + subId);
             mLatch.countDown();
diff --git a/src/com/android/settings/network/UiccSlotUtil.java b/src/com/android/settings/network/UiccSlotUtil.java
index 7ba2e0f..7d8295b 100644
--- a/src/com/android/settings/network/UiccSlotUtil.java
+++ b/src/com/android/settings/network/UiccSlotUtil.java
@@ -141,7 +141,8 @@
                         inactiveRemovableSlot,
                         /*removable sim's port Id*/ TelephonyManager.DEFAULT_PORT_INDEX,
                         excludedLogicalSlotIndex),
-                context);
+                context,
+                /*isWaitingForValidSubId=*/ true);
     }
 
     /**
@@ -179,7 +180,8 @@
         performSwitchToSlot(telMgr,
                 prepareUiccSlotMappings(uiccSlotMappings, /*slot is not psim*/ false,
                         physicalSlotId, port, excludedLogicalSlotIndex),
-                context);
+                context,
+                /*isWaitingForValidSubId=*/ false);
     }
 
     /**
@@ -231,7 +233,8 @@
     }
 
     private static void performSwitchToSlot(TelephonyManager telMgr,
-            Collection<UiccSlotMapping> uiccSlotMappings, Context context)
+            Collection<UiccSlotMapping> uiccSlotMappings, Context context,
+            boolean isWaitingForValidSubId)
             throws UiccSlotsException {
         CarrierConfigChangedReceiver receiver = null;
         long waitingTimeMillis =
@@ -241,7 +244,7 @@
                         DEFAULT_WAIT_AFTER_SWITCH_TIMEOUT_MILLIS);
         try {
             CountDownLatch latch = new CountDownLatch(1);
-            receiver = new CarrierConfigChangedReceiver(latch);
+            receiver = new CarrierConfigChangedReceiver(latch, isWaitingForValidSubId);
             receiver.registerOn(context);
             telMgr.setSimSlotMapping(uiccSlotMappings);
             latch.await(waitingTimeMillis, TimeUnit.MILLISECONDS);
diff --git a/tests/robotests/src/com/android/settings/development/BluetoothA2dpHwOffloadPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/development/BluetoothA2dpHwOffloadPreferenceControllerTest.java
index 660c8f1..94d6f1f 100644
--- a/tests/robotests/src/com/android/settings/development/BluetoothA2dpHwOffloadPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/development/BluetoothA2dpHwOffloadPreferenceControllerTest.java
@@ -65,18 +65,18 @@
 
     @Test
     public void onA2dpHwDialogConfirmedAsA2dpOffloadDisabled_shouldChangeProperty() {
-        SystemProperties.set(A2DP_OFFLOAD_DISABLED_PROPERTY, Boolean.toString(false));
+        SystemProperties.set(A2DP_OFFLOAD_DISABLED_PROPERTY, Boolean.toString(true));
         mController.mChanged = true;
 
         mController.onRebootDialogConfirmed();
         final boolean mode = SystemProperties.getBoolean(A2DP_OFFLOAD_DISABLED_PROPERTY, false);
-        assertThat(mode).isTrue();
+        assertThat(mode).isFalse();
     }
 
     @Test
     public void onA2dpHwDialogConfirmedAsA2dpOffloadEnabled_shouldChangeProperty() {
-        SystemProperties.set(A2DP_OFFLOAD_DISABLED_PROPERTY, Boolean.toString(true));
-        SystemProperties.set(LE_AUDIO_OFFLOAD_DISABLED_PROPERTY, Boolean.toString(true));
+        SystemProperties.set(A2DP_OFFLOAD_DISABLED_PROPERTY, Boolean.toString(false));
+        SystemProperties.set(LE_AUDIO_OFFLOAD_DISABLED_PROPERTY, Boolean.toString(false));
 
         mController.mChanged = true;
 
@@ -84,8 +84,8 @@
         final boolean a2dpMode = SystemProperties.getBoolean(A2DP_OFFLOAD_DISABLED_PROPERTY, true);
         final boolean leAudioMode = SystemProperties
                 .getBoolean(LE_AUDIO_OFFLOAD_DISABLED_PROPERTY, true);
-        assertThat(a2dpMode).isFalse();
-        assertThat(leAudioMode).isFalse();
+        assertThat(a2dpMode).isTrue();
+        assertThat(leAudioMode).isTrue();
     }
 
     @Test
diff --git a/tests/robotests/src/com/android/settings/development/BluetoothLeAudioHwOffloadPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/development/BluetoothLeAudioHwOffloadPreferenceControllerTest.java
index ec64fe3..aa05f62 100644
--- a/tests/robotests/src/com/android/settings/development/BluetoothLeAudioHwOffloadPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/development/BluetoothLeAudioHwOffloadPreferenceControllerTest.java
@@ -16,14 +16,21 @@
 
 package com.android.settings.development;
 
+import static android.bluetooth.BluetoothStatusCodes.FEATURE_SUPPORTED;
+
+import static com.android.settings.development.BluetoothA2dpHwOffloadPreferenceController
+        .A2DP_OFFLOAD_DISABLED_PROPERTY;
 import static com.android.settings.development.BluetoothLeAudioHwOffloadPreferenceController
         .LE_AUDIO_OFFLOAD_DISABLED_PROPERTY;
+import static com.android.settings.development.BluetoothLeAudioHwOffloadPreferenceController
+        .LE_AUDIO_OFFLOAD_SUPPORTED_PROPERTY;
 
 import static com.google.common.truth.Truth.assertThat;
 
 import static org.mockito.Mockito.spy;
 import static org.mockito.Mockito.when;
 
+import android.bluetooth.BluetoothAdapter;
 import android.content.Context;
 import android.os.SystemProperties;
 
@@ -45,6 +52,8 @@
     private PreferenceScreen mPreferenceScreen;
     @Mock
     private DevelopmentSettingsDashboardFragment mFragment;
+    @Mock
+    private BluetoothAdapter mBluetoothAdapter;
 
     private Context mContext;
     private SwitchPreference mPreference;
@@ -59,6 +68,9 @@
         when(mPreferenceScreen.findPreference(mController.getPreferenceKey()))
             .thenReturn(mPreference);
         mController.displayPreference(mPreferenceScreen);
+        mController.mBluetoothAdapter = mBluetoothAdapter;
+        when(mBluetoothAdapter.isLeAudioSupported())
+            .thenReturn(FEATURE_SUPPORTED);
     }
 
     @Test
@@ -91,4 +103,21 @@
         final boolean mode = SystemProperties.getBoolean(LE_AUDIO_OFFLOAD_DISABLED_PROPERTY, false);
         assertThat(mode).isFalse();
     }
+
+    @Test
+    public void asA2dpOffloadDisabled_shouldNotSwitchLeAudioOffloadStatus() {
+        SystemProperties.set(LE_AUDIO_OFFLOAD_SUPPORTED_PROPERTY, Boolean.toString(true));
+        SystemProperties.set(A2DP_OFFLOAD_DISABLED_PROPERTY, Boolean.toString(true));
+
+        SystemProperties.set(LE_AUDIO_OFFLOAD_DISABLED_PROPERTY, Boolean.toString(false));
+        mController.updateState(null);
+        boolean leAueioDisabled =
+                SystemProperties.getBoolean(LE_AUDIO_OFFLOAD_DISABLED_PROPERTY, false);
+        assertThat(leAueioDisabled).isFalse();
+
+        SystemProperties.set(LE_AUDIO_OFFLOAD_DISABLED_PROPERTY, Boolean.toString(true));
+        mController.updateState(null);
+        leAueioDisabled = SystemProperties.getBoolean(LE_AUDIO_OFFLOAD_DISABLED_PROPERTY, false);
+        assertThat(leAueioDisabled).isTrue();
+    }
 }