Merge "Add support to configure double line clock in lockscreen [2/2]" into main
diff --git a/res/layout/bluetooth_find_broadcast_password_dialog.xml b/res/layout/bluetooth_find_broadcast_password_dialog.xml
index f9df3f5..938f103 100644
--- a/res/layout/bluetooth_find_broadcast_password_dialog.xml
+++ b/res/layout/bluetooth_find_broadcast_password_dialog.xml
@@ -31,6 +31,7 @@
         android:id="@+id/broadcast_edit_text"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
+        android:maxLength="16"
         android:minHeight="48dp"
         android:textAlignment="viewStart"/>
     <TextView
diff --git a/res/xml/connected_devices_advanced.xml b/res/xml/connected_devices_advanced.xml
index 152446c..191c86d 100644
--- a/res/xml/connected_devices_advanced.xml
+++ b/res/xml/connected_devices_advanced.xml
@@ -33,7 +33,9 @@
         android:icon="@drawable/ic_nfc"
         android:order="-7"
         settings:searchable="false"
-        settings:controller="com.android.settings.connecteddevice.NfcAndPaymentFragmentController"/>
+        settings:controller="com.android.settings.connecteddevice.NfcAndPaymentFragmentController"
+        settings:userRestriction="no_near_field_communication_radio"
+        settings:useAdminDisabledSummary="true"/>
 
     <Preference
         android:fragment="com.android.settings.wfd.WifiDisplaySettings"
diff --git a/src/com/android/settings/bluetooth/BluetoothFindBroadcastsFragment.java b/src/com/android/settings/bluetooth/BluetoothFindBroadcastsFragment.java
index b84654d..ffe5b61 100644
--- a/src/com/android/settings/bluetooth/BluetoothFindBroadcastsFragment.java
+++ b/src/com/android/settings/bluetooth/BluetoothFindBroadcastsFragment.java
@@ -30,10 +30,16 @@
 import android.content.Context;
 import android.content.Intent;
 import android.os.Bundle;
+import android.text.Editable;
+import android.text.InputFilter;
+import android.text.InputType;
+import android.text.Spanned;
+import android.text.TextWatcher;
 import android.util.Log;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.WindowManager;
+import android.widget.Button;
 import android.widget.EditText;
 import android.widget.TextView;
 import android.widget.Toast;
@@ -468,9 +474,64 @@
                 .create();
 
         alertDialog.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG);
+        addTextWatcher(alertDialog, editText);
         alertDialog.show();
+        updateBtnState(alertDialog, false);
     }
 
+    private void addTextWatcher(AlertDialog alertDialog, EditText editText) {
+        if (alertDialog == null || editText == null) {
+            return;
+        }
+        final InputFilter[] filter = new InputFilter[] {mInputFilter};
+        editText.setFilters(filter);
+        editText.setInputType(InputType.TYPE_CLASS_TEXT
+                | InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);
+        TextWatcher bCodeTextWatcher = new TextWatcher() {
+            @Override
+            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
+                // Do nothing
+            }
+
+            @Override
+            public void onTextChanged(CharSequence s, int start, int before, int count) {
+                // Do nothing
+            }
+
+            @Override
+            public void afterTextChanged(Editable s) {
+                boolean breakBroadcastCodeRuleTextLengthLessThanMin =
+                        s.length() > 0 && s.toString().getBytes().length < 4;
+                boolean breakBroadcastCodeRuleTextLengthMoreThanMax =
+                        s.toString().getBytes().length > 16;
+                boolean breakRule = breakBroadcastCodeRuleTextLengthLessThanMin
+                        || breakBroadcastCodeRuleTextLengthMoreThanMax;
+                updateBtnState(alertDialog, !breakRule);
+            }
+        };
+        editText.addTextChangedListener(bCodeTextWatcher);
+    }
+
+    private void updateBtnState(AlertDialog alertDialog, boolean isEnable) {
+        Button positiveBtn = alertDialog.getButton(AlertDialog.BUTTON_POSITIVE);
+        if (positiveBtn != null) {
+            positiveBtn.setEnabled(isEnable ? true : false);
+        }
+    }
+
+    private InputFilter mInputFilter = new InputFilter() {
+        @Override
+        public CharSequence filter(CharSequence source, int start, int end,
+                Spanned dest, int dstart, int dend) {
+            byte[] bytes = source.toString().getBytes(StandardCharsets.UTF_8);
+            if (bytes.length == source.length()) {
+                return source;
+            } else {
+                return "";
+            }
+        }
+    };
+
     private void handleSearchStarted() {
         cacheRemoveAllPrefs(mBroadcastSourceListCategory);
         addConnectedSourcePreference();
diff --git a/src/com/android/settings/bluetooth/OWNERS b/src/com/android/settings/bluetooth/OWNERS
index 4b79652..0a3dec9 100644
--- a/src/com/android/settings/bluetooth/OWNERS
+++ b/src/com/android/settings/bluetooth/OWNERS
@@ -5,5 +5,7 @@
 robertluo@google.com
 yiyishen@google.com
 yqian@google.com
+chelseahao@google.com
+hahong@google.com
 
 # Emergency approvers in case the above are not available
diff --git a/src/com/android/settings/connecteddevice/OWNERS b/src/com/android/settings/connecteddevice/OWNERS
index 3179a05..5215a8f 100644
--- a/src/com/android/settings/connecteddevice/OWNERS
+++ b/src/com/android/settings/connecteddevice/OWNERS
@@ -4,5 +4,7 @@
 robertluo@google.com
 yiyishen@google.com
 yqian@google.com
+chelseahao@google.com
+hahong@google.com
 
 # Emergency approvers in case the above are not available
diff --git a/src/com/android/settings/security/screenlock/PinPrivacyPreferenceController.kt b/src/com/android/settings/security/screenlock/PinPrivacyPreferenceController.kt
index 176183e..78656e8 100644
--- a/src/com/android/settings/security/screenlock/PinPrivacyPreferenceController.kt
+++ b/src/com/android/settings/security/screenlock/PinPrivacyPreferenceController.kt
@@ -45,7 +45,7 @@
         return PREF_KEY
     }
 
-    override fun onPreferenceChange(preference: Preference?, value: Any?): Boolean {
+    override fun onPreferenceChange(preference: Preference, value: Any): Boolean {
         lockPatternUtils.setPinEnhancedPrivacyEnabled((value as Boolean), userId)
         return true
     }
diff --git a/tests/robotests/resources/META-INF/services/androidx.test.internal.platform.ThreadChecker b/tests/robotests/resources/META-INF/services/androidx.test.internal.platform.ThreadChecker
index 55104ea..341f4d9 100644
--- a/tests/robotests/resources/META-INF/services/androidx.test.internal.platform.ThreadChecker
+++ b/tests/robotests/resources/META-INF/services/androidx.test.internal.platform.ThreadChecker
@@ -1 +1 @@
-org.robolectric.android.internal.NoOpThreadChecker
+org.robolectric.android.internal.RobolectricThreadChecker