Merge "Expose SatelliteWarningDialogActivity" into main
diff --git a/res/layout/bluetooth_device_picker.xml b/res/layout/bluetooth_device_picker.xml
index 4db252b..0e50d11 100755
--- a/res/layout/bluetooth_device_picker.xml
+++ b/res/layout/bluetooth_device_picker.xml
@@ -18,6 +18,7 @@
         android:gravity="center"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
+        android:fitsSystemWindows="true"
         android:orientation="vertical">
 
         <fragment android:id="@+id/bluetooth_fragment_settings"
diff --git a/src/com/android/settings/bluetooth/BluetoothEnabler.java b/src/com/android/settings/bluetooth/BluetoothEnabler.java
index eaa0b96..df5cc72 100644
--- a/src/com/android/settings/bluetooth/BluetoothEnabler.java
+++ b/src/com/android/settings/bluetooth/BluetoothEnabler.java
@@ -16,6 +16,9 @@
 
 package com.android.settings.bluetooth;
 
+import static com.android.settings.network.SatelliteWarningDialogActivity.EXTRA_TYPE_OF_SATELLITE_WARNING_DIALOG;
+import static com.android.settings.network.SatelliteWarningDialogActivity.TYPE_IS_BLUETOOTH;
+
 import android.bluetooth.BluetoothAdapter;
 import android.content.BroadcastReceiver;
 import android.content.Context;
@@ -23,22 +26,32 @@
 import android.content.IntentFilter;
 import android.os.UserManager;
 import android.provider.Settings;
+import android.util.Log;
 import android.widget.Toast;
 
 import androidx.annotation.VisibleForTesting;
 
 import com.android.settings.R;
+import com.android.settings.network.SatelliteRepository;
+import com.android.settings.network.SatelliteWarningDialogActivity;
 import com.android.settings.widget.SwitchWidgetController;
 import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
 import com.android.settingslib.WirelessUtils;
 import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
 
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+import java.util.concurrent.atomic.AtomicBoolean;
+
 /**
  * BluetoothEnabler is a helper to manage the Bluetooth on/off checkbox
  * preference. It turns on/off Bluetooth and ensures the summary of the
  * preference reflects the current state.
  */
 public final class BluetoothEnabler implements SwitchWidgetController.OnSwitchChangeListener {
+    private static final String TAG = BluetoothEnabler.class.getSimpleName();
     private final SwitchWidgetController mSwitchController;
     private final MetricsFeatureProvider mMetricsFeatureProvider;
     private Context mContext;
@@ -51,6 +64,9 @@
     private static final String EVENT_DATA_IS_BT_ON = "is_bluetooth_on";
     private static final int EVENT_UPDATE_INDEX = 0;
     private final int mMetricsEvent;
+    private SatelliteRepository mSatelliteRepository;
+    @VisibleForTesting
+    AtomicBoolean mIsSatelliteOn = new AtomicBoolean(false);
 
     private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
         @Override
@@ -81,6 +97,7 @@
         }
         mIntentFilter = new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED);
         mRestrictionUtils = restrictionUtils;
+        mSatelliteRepository = new SatelliteRepository(context);
     }
 
     public void setupSwitchController() {
@@ -112,6 +129,15 @@
         mContext.registerReceiver(mReceiver, mIntentFilter,
                 Context.RECEIVER_EXPORTED_UNAUDITED);
         mValidListener = true;
+
+        new Thread(() -> {
+            try {
+                mIsSatelliteOn.set(mSatelliteRepository.requestIsEnabled(
+                        Executors.newSingleThreadExecutor()).get(3000, TimeUnit.MILLISECONDS));
+            } catch (InterruptedException | ExecutionException | TimeoutException e) {
+                Log.e(TAG, "Error to get satellite status : " + e);
+            }
+        }).start();
     }
 
     public void pause() {
@@ -168,6 +194,17 @@
             return true;
         }
 
+        if (mIsSatelliteOn.get()) {
+            mContext.startActivity(
+                    new Intent(mContext, SatelliteWarningDialogActivity.class)
+                            .putExtra(
+                                    EXTRA_TYPE_OF_SATELLITE_WARNING_DIALOG,
+                                    TYPE_IS_BLUETOOTH)
+            );
+            mSwitchController.setChecked(!isChecked);
+            return false;
+        }
+
         // Show toast message if Bluetooth is not allowed in airplane mode
         if (isChecked &&
                 !WirelessUtils.isRadioAllowed(mContext, Settings.Global.RADIO_BLUETOOTH)) {
diff --git a/src/com/android/settings/bluetooth/BluetoothPairingDetail.java b/src/com/android/settings/bluetooth/BluetoothPairingDetail.java
index 234d6d2..ca53854 100644
--- a/src/com/android/settings/bluetooth/BluetoothPairingDetail.java
+++ b/src/com/android/settings/bluetooth/BluetoothPairingDetail.java
@@ -16,10 +16,15 @@
 
 package com.android.settings.bluetooth;
 
+import static com.android.settings.network.SatelliteWarningDialogActivity.EXTRA_TYPE_OF_SATELLITE_WARNING_DIALOG;
+import static com.android.settings.network.SatelliteWarningDialogActivity.TYPE_IS_BLUETOOTH;
+
 import android.app.settings.SettingsEnums;
 import android.bluetooth.BluetoothAdapter;
 import android.content.Context;
+import android.content.Intent;
 import android.os.Bundle;
+import android.util.Log;
 import android.view.View;
 
 import androidx.annotation.NonNull;
@@ -27,10 +32,17 @@
 import androidx.annotation.VisibleForTesting;
 
 import com.android.settings.R;
+import com.android.settings.network.SatelliteRepository;
+import com.android.settings.network.SatelliteWarningDialogActivity;
 import com.android.settingslib.bluetooth.BluetoothDeviceFilter;
 import com.android.settingslib.search.Indexable;
 import com.android.settingslib.widget.FooterPreference;
 
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+
 /**
  * BluetoothPairingDetail is a page to scan bluetooth devices and pair them.
  */
@@ -55,9 +67,35 @@
     @Override
     public void onAttach(Context context) {
         super.onAttach(context);
+        if (mayStartSatelliteWarningDialog()) {
+            finish();
+            return;
+        }
         use(BluetoothDeviceRenamePreferenceController.class).setFragment(this);
     }
 
+    private boolean mayStartSatelliteWarningDialog() {
+        SatelliteRepository satelliteRepository = new SatelliteRepository(this.getContext());
+        boolean isSatelliteOn = true;
+        try {
+            isSatelliteOn =
+                    satelliteRepository.requestIsEnabled(
+                            Executors.newSingleThreadExecutor()).get(3000, TimeUnit.MILLISECONDS);
+        } catch (InterruptedException | ExecutionException | TimeoutException e) {
+            Log.e(TAG, "Error to get satellite status : " + e);
+        }
+        if (!isSatelliteOn) {
+            return false;
+        }
+        startActivity(
+                new Intent(getContext(), SatelliteWarningDialogActivity.class)
+                        .putExtra(
+                                EXTRA_TYPE_OF_SATELLITE_WARNING_DIALOG,
+                                TYPE_IS_BLUETOOTH)
+        );
+        return true;
+    }
+
     @Override
     public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
         super.onViewCreated(view, savedInstanceState);
diff --git a/src/com/android/settings/spa/network/NetworkCellularGroupProvider.kt b/src/com/android/settings/spa/network/NetworkCellularGroupProvider.kt
index 7b7c85d..28b7a9e 100644
--- a/src/com/android/settings/spa/network/NetworkCellularGroupProvider.kt
+++ b/src/com/android/settings/spa/network/NetworkCellularGroupProvider.kt
@@ -410,11 +410,22 @@
     enabled: Boolean,
 ): Unit =
     withContext(Dispatchers.Default) {
-        Log.d(NetworkCellularGroupProvider.fileName, "setMobileData: $enabled")
+        Log.d(NetworkCellularGroupProvider.fileName, "setMobileData[$subId]: $enabled")
+
+        var targetSubId = subId
+        val activeSubIdList = subscriptionManager?.activeSubscriptionIdList
+        if (activeSubIdList?.size == 1) {
+            targetSubId = activeSubIdList[0]
+            Log.d(
+                NetworkCellularGroupProvider.fileName,
+                "There is only one sim in the device, correct dds as $targetSubId"
+            )
+        }
+
         if (enabled) {
-            Log.d(NetworkCellularGroupProvider.fileName, "setDefaultData: [$subId]")
-            subscriptionManager?.setDefaultDataSubId(subId)
+            Log.d(NetworkCellularGroupProvider.fileName, "setDefaultData: [$targetSubId]")
+            subscriptionManager?.setDefaultDataSubId(targetSubId)
         }
         TelephonyRepository(context)
-            .setMobileData(subId, enabled, wifiPickerTrackerHelper)
+            .setMobileData(targetSubId, enabled, wifiPickerTrackerHelper)
     }
\ No newline at end of file
diff --git a/src/com/android/settings/wifi/WifiConfigController2.java b/src/com/android/settings/wifi/WifiConfigController2.java
index 1606469..1e40568 100644
--- a/src/com/android/settings/wifi/WifiConfigController2.java
+++ b/src/com/android/settings/wifi/WifiConfigController2.java
@@ -514,12 +514,6 @@
         submit.setEnabled(isSubmittable());
     }
 
-    boolean isValidWepPassword(String password) {
-        // Checks for WEP40 and WEP104 password lengths (5 and 13 bytes)
-        int passwordLen = (password != null) ? password.length() : -1;
-        return passwordLen == 5 || passwordLen == 13;
-    }
-
     boolean isValidPsk(String password) {
         if (password.length() == 64 && password.matches("[0-9A-Fa-f]{64}")) {
             return true;
@@ -541,7 +535,7 @@
         boolean passwordInvalid = false;
         if (mPasswordView != null
                 && ((mWifiEntrySecurity == WifiEntry.SECURITY_WEP
-                        && !isValidWepPassword(mPasswordView.getText().toString()))
+                        && mPasswordView.length() == 0)
                     || (mWifiEntrySecurity == WifiEntry.SECURITY_PSK
                            && !isValidPsk(mPasswordView.getText().toString()))
                     || (mWifiEntrySecurity == WifiEntry.SECURITY_SAE
diff --git a/tests/robotests/src/com/android/settings/bluetooth/BluetoothEnablerTest.java b/tests/robotests/src/com/android/settings/bluetooth/BluetoothEnablerTest.java
index 4b82782..9052268 100644
--- a/tests/robotests/src/com/android/settings/bluetooth/BluetoothEnablerTest.java
+++ b/tests/robotests/src/com/android/settings/bluetooth/BluetoothEnablerTest.java
@@ -34,6 +34,7 @@
 import android.content.IntentFilter;
 import android.os.UserHandle;
 import android.os.UserManager;
+import android.util.AndroidRuntimeException;
 import android.view.View;
 
 import androidx.preference.PreferenceViewHolder;
@@ -102,6 +103,19 @@
     }
 
     @Test
+    public void onSwitchToggled_satelliteOn_showWarningDialog() {
+        mBluetoothEnabler.mIsSatelliteOn.set(true);
+
+        try {
+            mBluetoothEnabler.onSwitchToggled(true);
+        } catch (AndroidRuntimeException e) {
+            // Catch exception of starting activity .
+        }
+
+        verify(mContext).startActivity(any());
+    }
+
+    @Test
     public void onSwitchToggled_shouldLogActionWithSuppliedEvent() {
         // WHEN the switch is toggled...
         mBluetoothEnabler.onSwitchToggled(false);
diff --git a/tests/robotests/src/com/android/settings/wifi/WifiConfigController2Test.java b/tests/robotests/src/com/android/settings/wifi/WifiConfigController2Test.java
index a531e3f..7d96496 100644
--- a/tests/robotests/src/com/android/settings/wifi/WifiConfigController2Test.java
+++ b/tests/robotests/src/com/android/settings/wifi/WifiConfigController2Test.java
@@ -203,39 +203,6 @@
     }
 
     @Test
-    public void isSubmittable_wepPasswordLength5_returnTrue() {
-        when(mWifiEntry.getSecurity()).thenReturn(WifiEntry.SECURITY_WEP);
-        createController(mWifiEntry, WifiConfigUiBase2.MODE_CONNECT, false);
-        final TextView password = mView.findViewById(R.id.password);
-        assertThat(password).isNotNull();
-        password.setText("12345");
-
-        assertThat(mController.isSubmittable()).isTrue();
-    }
-
-    @Test
-    public void isSubmittable_wepPasswordLength13_returnTrue() {
-        when(mWifiEntry.getSecurity()).thenReturn(WifiEntry.SECURITY_WEP);
-        createController(mWifiEntry, WifiConfigUiBase2.MODE_CONNECT, false);
-        final TextView password = mView.findViewById(R.id.password);
-        assertThat(password).isNotNull();
-        password.setText("1234567890123");
-
-        assertThat(mController.isSubmittable()).isTrue();
-    }
-
-    @Test
-    public void isSubmittable_wepPasswordLength1_returnFalse() {
-        when(mWifiEntry.getSecurity()).thenReturn(WifiEntry.SECURITY_WEP);
-        createController(mWifiEntry, WifiConfigUiBase2.MODE_CONNECT, false);
-        final TextView password = mView.findViewById(R.id.password);
-        assertThat(password).isNotNull();
-        password.setText("1");
-
-        assertThat(mController.isSubmittable()).isFalse();
-    }
-
-    @Test
     public void isSubmittable_longPsk_shouldReturnFalse() {
         createController(mWifiEntry, WifiConfigUiBase2.MODE_CONNECT, false);
         final TextView password = mView.findViewById(R.id.password);