candidates = new ArrayList<>();
final long maxTimeout = getMaxScreenTimeout(getContext());
if (mInitialValues != null) {
for (int i = 0; i < mInitialValues.length; ++i) {
+ // Truncate mInitialEntries/Values so that they do not exceed maxTimeout
if (Long.parseLong(mInitialValues[i].toString()) <= maxTimeout) {
candidates.add(
new TimeoutCandidateInfo(
@@ -211,7 +213,7 @@ public class ScreenTimeoutSettings extends RadioButtonPickerFragment
for (CandidateInfo info : candidateList) {
ProtectedSelectorWithWidgetPreference pref =
new ProtectedSelectorWithWidgetPreference(
- getPrefContext(), info.getKey(), this);
+ getContext(), info.getKey(), this);
bindPreference(pref, info.getKey(), info, defaultKey);
screen.addPreference(pref);
}
@@ -219,12 +221,17 @@ public class ScreenTimeoutSettings extends RadioButtonPickerFragment
final long selectedTimeout = getTimeoutFromKey(defaultKey);
final long maxTimeout = getMaxScreenTimeout(getContext());
if (!candidateList.isEmpty() && (selectedTimeout > maxTimeout)) {
- // The selected time out value is longer than the max timeout allowed by the admin.
- // Select the largest value from the list by default.
+ // The selected time out value is longer than the max timeout allowed by the
+ // admin/configuration. The list of candidates is already truncated so that
+ // no value exceeds the max timeout value.
+ // Select the largest value from the candidates list by default.
+ int lastIndex = candidateList.size() - 1;
final ProtectedSelectorWithWidgetPreference preferenceWithLargestTimeout =
(ProtectedSelectorWithWidgetPreference)
- screen.getPreference(candidateList.size() - 1);
+ screen.getPreference(lastIndex);
preferenceWithLargestTimeout.setChecked(true);
+ // Update the system screen timeout setting to match the UI
+ setCurrentSystemScreenTimeout(getContext(), candidateList.get(lastIndex).getKey());
}
mPrivacyPreference = new FooterPreference(mContext);
@@ -338,7 +345,11 @@ public class ScreenTimeoutSettings extends RadioButtonPickerFragment
return R.string.help_url_adaptive_sleep;
}
+ // Get the maximum screen timeout as governed by admin and/or configuration.
+ // Returns the lowest timeout (admin/config) or Long.MAX_VALUE.
private Long getMaxScreenTimeout(Context context) {
+ Long adminMaxTimeout = Long.MAX_VALUE;
+ Long configMaxTimeout = Long.MAX_VALUE;
if (context == null) {
return Long.MAX_VALUE;
}
@@ -346,11 +357,21 @@ public class ScreenTimeoutSettings extends RadioButtonPickerFragment
if (dpm == null) {
return Long.MAX_VALUE;
}
- mAdmin = RestrictedLockUtilsInternal.checkIfMaximumTimeToLockIsSet(context);
+ if (mAdmin == null) { // Don't overwrite mocked mAdmin
+ mAdmin = RestrictedLockUtilsInternal.checkIfMaximumTimeToLockIsSet(context);
+ }
if (mAdmin != null) {
- return dpm.getMaximumTimeToLock(null /* admin */, UserHandle.myUserId());
+ // Get the admin max screen timeout
+ adminMaxTimeout = dpm.getMaximumTimeToLock(null /* admin */, UserHandle.myUserId());
+ }
+ try {
+ // Get the configurable max screen timeout
+ configMaxTimeout = Long.valueOf(
+ context.getResources().getInteger(R.integer.config_max_screen_timeout));
+ } catch (Resources.NotFoundException e) {
+ // Do nothing
}
- return Long.MAX_VALUE;
+ return Math.min(adminMaxTimeout, configMaxTimeout);
}
private String getCurrentSystemScreenTimeout(Context context) {
diff --git a/src/com/android/settings/homepage/contextualcards/slices/LowStorageSlice.java b/src/com/android/settings/homepage/contextualcards/slices/LowStorageSlice.java
index 92fa0122e4fc9d114cff67a5d215f314816dda75..22e3431770261c25a1004cb9cf30ea16e1382bae 100644
--- a/src/com/android/settings/homepage/contextualcards/slices/LowStorageSlice.java
+++ b/src/com/android/settings/homepage/contextualcards/slices/LowStorageSlice.java
@@ -64,9 +64,7 @@ public class LowStorageSlice implements CustomSliceable {
// Generate Low storage Slice.
final String percentageString = NumberFormat.getPercentInstance().format(usedPercentage);
- final String[] freeSizeString =
- Formatter.formatFileSize(mContext, info.freeBytes).split("\\s");
-
+ final String freeSizeString = Formatter.formatFileSize(mContext, info.freeBytes);
final ListBuilder listBuilder = new ListBuilder(mContext,
CustomSliceRegistry.LOW_STORAGE_SLICE_URI, ListBuilder.INFINITY).setAccentColor(
Utils.getColorAccentDefaultColor(mContext));
@@ -76,7 +74,7 @@ public class LowStorageSlice implements CustomSliceable {
// For clients that ignore error checking, a generic storage slice will be given.
final CharSequence titleStorage = mContext.getText(R.string.storage_settings);
final String summaryStorage = mContext.getString(R.string.storage_summary,
- percentageString, freeSizeString[0], freeSizeString[1]);
+ percentageString, freeSizeString);
return listBuilder
.addRow(buildRowBuilder(titleStorage, summaryStorage, icon))
diff --git a/src/com/android/settings/inputmethod/NewKeyboardLayoutPickerController.java b/src/com/android/settings/inputmethod/NewKeyboardLayoutPickerController.java
index d3b23a7128ab49844ecf0945f97b74f279616992..a5f08651603e68f80d9a09b6be811b96b92d11d7 100644
--- a/src/com/android/settings/inputmethod/NewKeyboardLayoutPickerController.java
+++ b/src/com/android/settings/inputmethod/NewKeyboardLayoutPickerController.java
@@ -26,6 +26,7 @@ import android.os.Bundle;
import android.view.inputmethod.InputMethodInfo;
import android.view.inputmethod.InputMethodSubtype;
+import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
@@ -58,7 +59,7 @@ public class NewKeyboardLayoutPickerController extends BasePreferenceController
private PreferenceScreen mScreen;
private String mPreviousSelection;
private String mFinalSelectedLayoutDescriptor;
- private String mSelectedLayoutDescriptor;
+ @Nullable private String mSelectedLayoutDescriptor;
private MetricsFeatureProvider mMetricsFeatureProvider;
private KeyboardLayoutSelectedCallback mKeyboardLayoutSelectedCallback;
@@ -186,7 +187,8 @@ public class NewKeyboardLayoutPickerController extends BasePreferenceController
pref = new TickButtonPreference(mScreen.getContext());
pref.setTitle(layout.getLabel());
- if (mSelectedLayoutDescriptor.equals(layout.getDescriptor())) {
+ if (mSelectedLayoutDescriptor != null && mSelectedLayoutDescriptor.equals(
+ layout.getDescriptor())) {
if (mKeyboardLayoutSelectedCallback != null) {
mKeyboardLayoutSelectedCallback.onSelected(layout);
}
@@ -197,6 +199,12 @@ public class NewKeyboardLayoutPickerController extends BasePreferenceController
mScreen.addPreference(pref);
mPreferenceMap.put(pref, layout);
}
+
+ if (mSelectedLayoutDescriptor == null && mKeyboardLayoutSelectedCallback != null) {
+ // Pass null here since getKeyboardLayoutPreview() accept null layout, which will
+ // return default preview image
+ mKeyboardLayoutSelectedCallback.onSelected(null);
+ }
}
private void setLayout(TickButtonPreference preference) {
@@ -233,6 +241,6 @@ public class NewKeyboardLayoutPickerController extends BasePreferenceController
/**
* Called when KeyboardLayout been selected.
*/
- void onSelected(KeyboardLayout keyboardLayout);
+ void onSelected(@Nullable KeyboardLayout keyboardLayout);
}
}
diff --git a/src/com/android/settings/inputmethod/NewKeyboardLayoutPickerFragment.java b/src/com/android/settings/inputmethod/NewKeyboardLayoutPickerFragment.java
index ccf2b2658f9306608202cec8711a7c76e3571f41..972fbb5aacd9802fb129adcc5ac62e33a9bd95a3 100644
--- a/src/com/android/settings/inputmethod/NewKeyboardLayoutPickerFragment.java
+++ b/src/com/android/settings/inputmethod/NewKeyboardLayoutPickerFragment.java
@@ -31,6 +31,7 @@ import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
+import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import com.android.settings.R;
@@ -48,10 +49,10 @@ public class NewKeyboardLayoutPickerFragment extends Fragment {
mKeyboardLayoutSelectedCallback =
new NewKeyboardLayoutPickerController.KeyboardLayoutSelectedCallback() {
@Override
- public void onSelected(KeyboardLayout keyboardLayout) {
+ public void onSelected(@Nullable KeyboardLayout keyboardLayout) {
if (mInputManager != null
&& mKeyboardLayoutPreview != null
- && mKeyboardLayoutPreviewText != null && keyboardLayout != null) {
+ && mKeyboardLayoutPreviewText != null) {
Drawable previewDrawable = mInputManager.getKeyboardLayoutPreview(
keyboardLayout,
DEFAULT_KEYBOARD_PREVIEW_WIDTH, DEFAULT_KEYBOARD_PREVIEW_HEIGHT);
@@ -60,9 +61,12 @@ public class NewKeyboardLayoutPickerFragment extends Fragment {
mKeyboardLayoutPreviewText.setVisibility(
previewDrawable == null ? GONE : VISIBLE);
if (previewDrawable != null) {
- mKeyboardLayoutPreviewText.setText(keyboardLayout.getLabel());
mKeyboardLayoutPreview.setImageDrawable(previewDrawable);
}
+ mKeyboardLayoutPreviewText.setText(
+ keyboardLayout != null ? keyboardLayout.getLabel()
+ : requireContext().getString(
+ R.string.keyboard_default_layout));
}
}
};
diff --git a/src/com/android/settings/network/telephony/Enable2gPreferenceController.java b/src/com/android/settings/network/telephony/Enable2gPreferenceController.java
index 13120a3c90788db45a26aea31ee67da6e6bf69d5..230d5d9b0b646ccfc3960956c62f8d4e208d2df5 100644
--- a/src/com/android/settings/network/telephony/Enable2gPreferenceController.java
+++ b/src/com/android/settings/network/telephony/Enable2gPreferenceController.java
@@ -173,7 +173,7 @@ public class Enable2gPreferenceController extends TelephonyTogglePreferenceContr
}
/**
- * Return {@code true} if 2g is currently enabled.
+ * Return {@code true} if only 3G and higher is currently enabled.
*
* NOTE: This method returns the active state of the preference controller and is not
* the parameter passed into {@link #setChecked(boolean)}, which is instead the requested future
@@ -181,12 +181,12 @@ public class Enable2gPreferenceController extends TelephonyTogglePreferenceContr
*/
@Override
public boolean isChecked() {
- // If an enterprise admin has disabled 2g, we show the toggle as not checked to avoid
- // user confusion of seeing a checked toggle, but having 2g actually disabled.
+ // If an enterprise admin has disabled 2g, we show the toggle as checked to avoid
+ // user confusion of seeing a unchecked toggle, but having 3G and higher actually enable.
// The RestrictedSwitchPreference will take care of transparently informing the user that
// the setting was disabled by their admin
if (isDisabledByAdmin()) {
- return false;
+ return true;
}
if (mTelephonyManager == null) {
@@ -195,7 +195,7 @@ public class Enable2gPreferenceController extends TelephonyTogglePreferenceContr
}
long currentlyAllowedNetworkTypes = mTelephonyManager.getAllowedNetworkTypesForReason(
mTelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G);
- return (currentlyAllowedNetworkTypes & BITMASK_2G) != 0;
+ return (currentlyAllowedNetworkTypes & BITMASK_2G) == 0;
}
/**
@@ -206,7 +206,7 @@ public class Enable2gPreferenceController extends TelephonyTogglePreferenceContr
* details.
*
* @param isChecked The toggle value that we're being requested to enforce. A value of {@code
- * false} denotes that 2g will be disabled by the modem after this function
+ * true} denotes that 2g will be disabled by the modem after this function
* completes, if it is not already.
*/
@Override
@@ -227,21 +227,21 @@ public class Enable2gPreferenceController extends TelephonyTogglePreferenceContr
long currentlyAllowedNetworkTypes = mTelephonyManager.getAllowedNetworkTypesForReason(
mTelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G);
boolean enabled = (currentlyAllowedNetworkTypes & BITMASK_2G) != 0;
- if (enabled == isChecked) {
+ if (enabled != isChecked) {
return false;
}
long newAllowedNetworkTypes = currentlyAllowedNetworkTypes;
if (isChecked) {
- newAllowedNetworkTypes = currentlyAllowedNetworkTypes | BITMASK_2G;
- Log.i(LOG_TAG, "Enabling 2g. Allowed network types: " + newAllowedNetworkTypes);
- } else {
newAllowedNetworkTypes = currentlyAllowedNetworkTypes & ~BITMASK_2G;
Log.i(LOG_TAG, "Disabling 2g. Allowed network types: " + newAllowedNetworkTypes);
+ } else {
+ newAllowedNetworkTypes = currentlyAllowedNetworkTypes | BITMASK_2G;
+ Log.i(LOG_TAG, "Enabling 2g. Allowed network types: " + newAllowedNetworkTypes);
}
mTelephonyManager.setAllowedNetworkTypesForReason(
mTelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G, newAllowedNetworkTypes);
mMetricsFeatureProvider.action(
- mContext, SettingsEnums.ACTION_2G_ENABLED, isChecked);
+ mContext, SettingsEnums.ACTION_2G_ENABLED, !isChecked);
return true;
}
diff --git a/src/com/android/settings/network/telephony/MobileNetworkSettings.java b/src/com/android/settings/network/telephony/MobileNetworkSettings.java
index e1272a8b82a0637d845dcbec71ce91a8e2cd724e..ba4b22b1e0c165a046dd95c2e863272a8454dfec 100644
--- a/src/com/android/settings/network/telephony/MobileNetworkSettings.java
+++ b/src/com/android/settings/network/telephony/MobileNetworkSettings.java
@@ -58,6 +58,8 @@ import com.android.settings.network.telephony.cdma.CdmaSubscriptionPreferenceCon
import com.android.settings.network.telephony.cdma.CdmaSystemSelectPreferenceController;
import com.android.settings.network.telephony.gsm.AutoSelectPreferenceController;
import com.android.settings.network.telephony.gsm.OpenNetworkSelectPagePreferenceController;
+import com.android.settings.network.telephony.satellite.SatelliteSettingPreferenceController;
+import com.android.settings.network.telephony.satellite.SatelliteSettingsPreferenceCategoryController;
import com.android.settings.network.telephony.wificalling.CrossSimCallingViewModel;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settings.wifi.WifiPickerTrackerHelper;
diff --git a/src/com/android/settings/network/telephony/SatelliteAppListCategoryController.java b/src/com/android/settings/network/telephony/satellite/SatelliteAppListCategoryController.java
similarity index 98%
rename from src/com/android/settings/network/telephony/SatelliteAppListCategoryController.java
rename to src/com/android/settings/network/telephony/satellite/SatelliteAppListCategoryController.java
index 4afa7f245ffebf477633a77aaf1a40d5566de2db..a29a388579aafd95540a5e814d7a4933fd8698df 100644
--- a/src/com/android/settings/network/telephony/SatelliteAppListCategoryController.java
+++ b/src/com/android/settings/network/telephony/satellite/SatelliteAppListCategoryController.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package com.android.settings.network.telephony;
+package com.android.settings.network.telephony.satellite;
import android.content.Context;
import android.content.pm.ApplicationInfo;
diff --git a/src/com/android/settings/network/telephony/SatelliteAppListFragment.java b/src/com/android/settings/network/telephony/satellite/SatelliteAppListFragment.java
similarity index 96%
rename from src/com/android/settings/network/telephony/SatelliteAppListFragment.java
rename to src/com/android/settings/network/telephony/satellite/SatelliteAppListFragment.java
index 97f70bb2652bbd83d2e117b8f44346fd250c36f3..c4428e929ad42c1cd9dee1c3e90c9645c1e92a4e 100644
--- a/src/com/android/settings/network/telephony/SatelliteAppListFragment.java
+++ b/src/com/android/settings/network/telephony/satellite/SatelliteAppListFragment.java
@@ -14,9 +14,9 @@
* limitations under the License.
*/
-package com.android.settings.network.telephony;
+package com.android.settings.network.telephony.satellite;
-import static com.android.settings.network.telephony.SatelliteAppListCategoryController.getApplicationInfo;
+import static com.android.settings.network.telephony.satellite.SatelliteAppListCategoryController.getApplicationInfo;
import android.app.settings.SettingsEnums;
import android.content.Context;
diff --git a/src/com/android/settings/network/telephony/SatelliteSetting.java b/src/com/android/settings/network/telephony/satellite/SatelliteSetting.java
similarity index 94%
rename from src/com/android/settings/network/telephony/SatelliteSetting.java
rename to src/com/android/settings/network/telephony/satellite/SatelliteSetting.java
index 88e89d479b830542f0e31ec57a142f9ad7e01d2d..851038a7a459291482eca5c042f77ef07fa777d8 100644
--- a/src/com/android/settings/network/telephony/SatelliteSetting.java
+++ b/src/com/android/settings/network/telephony/satellite/SatelliteSetting.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2024 The Android Open Source Project
+ * Copyright (C) 2025 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package com.android.settings.network.telephony;
+package com.android.settings.network.telephony.satellite;
import static android.telephony.CarrierConfigManager.CARRIER_ROAMING_NTN_CONNECT_AUTOMATIC;
import static android.telephony.CarrierConfigManager.CARRIER_ROAMING_NTN_CONNECT_MANUAL;
@@ -61,8 +61,6 @@ import java.util.Set;
/** Handle Satellite Setting Preference Layout. */
public class SatelliteSetting extends RestrictedDashboardFragment {
private static final String TAG = "SatelliteSetting";
- private static final String PREF_KEY_ABOUT_SATELLITE_MESSAGING =
- "key_about_satellite_messaging";
private static final String PREF_KEY_CATEGORY_YOUR_SATELLITE_PLAN =
"key_category_your_satellite_plan";
private static final String PREF_KEY_YOUR_SATELLITE_PLAN = "key_your_satellite_plan";
@@ -98,14 +96,17 @@ public class SatelliteSetting extends RestrictedDashboardFragment {
@Override
public void onAttach(Context context) {
super.onAttach(context);
+ mActivity = getActivity();
+ mSubId = mActivity.getIntent().getIntExtra(SUB_ID,
+ SubscriptionManager.INVALID_SUBSCRIPTION_ID);
+
use(SatelliteAppListCategoryController.class).init();
+ use(SatelliteSettingAboutContentController.class).init(mSubId);
}
@Override
public void onCreate(@NonNull Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- mActivity = getActivity();
-
mSatelliteManager = mActivity.getSystemService(SatelliteManager.class);
if (mSatelliteManager == null) {
Log.d(TAG, "SatelliteManager is null, do nothing.");
@@ -113,8 +114,6 @@ public class SatelliteSetting extends RestrictedDashboardFragment {
return;
}
- mSubId = mActivity.getIntent().getIntExtra(SUB_ID,
- SubscriptionManager.INVALID_SUBSCRIPTION_ID);
mConfigBundle = fetchCarrierConfigData(mSubId);
if (!isSatelliteAttachSupported(mSubId)) {
@@ -135,7 +134,6 @@ public class SatelliteSetting extends RestrictedDashboardFragment {
super.onViewCreated(view, savedInstanceState);
boolean isSatelliteEligible = isSatelliteEligible();
updateTitle();
- updateAboutSatelliteContent();
updateMobilePlan(isSatelliteEligible);
updateHowItWorksContent(isSatelliteEligible);
updateFooterContent();
@@ -155,18 +153,6 @@ public class SatelliteSetting extends RestrictedDashboardFragment {
findPreference("satellite_setting").setTitle(getSubjectString());
}
- // About satellite content
- private void updateAboutSatelliteContent() {
- Preference categoryTitle = findPreference(PREF_KEY_CATEGORY_ABOUT_SATELLITE);
- categoryTitle.setTitle(
- getString(R.string.category_name_about_satellite_messaging,
- getDescriptionString()));
-
- Preference preference = findPreference(PREF_KEY_ABOUT_SATELLITE_MESSAGING);
- preference.setTitle(
- getResources().getString(R.string.title_about_satellite_setting, mSimOperatorName));
- }
-
private void updateMobilePlan(boolean isSatelliteEligible) {
PreferenceCategory prefCategory = findPreference(PREF_KEY_CATEGORY_YOUR_SATELLITE_PLAN);
if (prefCategory == null || !mConfigBundle.getBoolean(
diff --git a/src/com/android/settings/network/telephony/satellite/SatelliteSettingAboutContentController.kt b/src/com/android/settings/network/telephony/satellite/SatelliteSettingAboutContentController.kt
new file mode 100644
index 0000000000000000000000000000000000000000..68c916faf315226c6061d82fdac9204c2493d649
--- /dev/null
+++ b/src/com/android/settings/network/telephony/satellite/SatelliteSettingAboutContentController.kt
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2025 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.network.telephony.satellite
+
+import android.content.Context
+import android.telephony.TelephonyManager
+import androidx.preference.PreferenceScreen
+import com.android.settings.network.telephony.TelephonyBasePreferenceController
+import com.android.settingslib.widget.TopIntroPreference
+import com.android.settings.R;
+
+/** A controller to show the introduction of satellite connectivity. */
+class SatelliteSettingAboutContentController(context: Context, key: String) :
+ TelephonyBasePreferenceController(context, key) {
+ private lateinit var simOperatorName: String
+
+ fun init(subId: Int) {
+ mSubId = subId
+ simOperatorName =
+ mContext.getSystemService(TelephonyManager::class.java)?.getSimOperatorName(mSubId) ?: ""
+ }
+
+ override fun displayPreference(screen: PreferenceScreen?) {
+ super.displayPreference(screen)
+ val preference: TopIntroPreference? =
+ screen?.findPreference(PREF_KEY_ABOUT_SATELLITE_CONNECTIVITY)
+ preference?.title =
+ mContext.getString(R.string.description_about_satellite_setting, simOperatorName)
+ }
+
+ override fun getAvailabilityStatus(subId: Int): Int {
+ return AVAILABLE
+ }
+
+ companion object {
+ const val PREF_KEY_ABOUT_SATELLITE_CONNECTIVITY = "key_about_satellite_connectivity";
+ }
+}
\ No newline at end of file
diff --git a/src/com/android/settings/network/telephony/SatelliteSettingPreferenceController.java b/src/com/android/settings/network/telephony/satellite/SatelliteSettingPreferenceController.java
similarity index 98%
rename from src/com/android/settings/network/telephony/SatelliteSettingPreferenceController.java
rename to src/com/android/settings/network/telephony/satellite/SatelliteSettingPreferenceController.java
index c81129708ec77101933bd864a0392559f2ae5de7..18217fd5d6242614f0454b44196edbd914469758 100644
--- a/src/com/android/settings/network/telephony/SatelliteSettingPreferenceController.java
+++ b/src/com/android/settings/network/telephony/satellite/SatelliteSettingPreferenceController.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2024 The Android Open Source Project
+ * Copyright (C) 2025 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package com.android.settings.network.telephony;
+package com.android.settings.network.telephony.satellite;
import static android.telephony.CarrierConfigManager.CARRIER_ROAMING_NTN_CONNECT_AUTOMATIC;
import static android.telephony.CarrierConfigManager.KEY_CARRIER_ROAMING_NTN_CONNECT_TYPE_INT;
@@ -44,6 +44,7 @@ import androidx.preference.PreferenceScreen;
import com.android.settings.R;
import com.android.settings.SettingsActivity;
import com.android.settings.network.CarrierConfigCache;
+import com.android.settings.network.telephony.TelephonyBasePreferenceController;
import java.util.Arrays;
import java.util.List;
diff --git a/src/com/android/settings/network/telephony/SatelliteSettingsPreferenceCategoryController.java b/src/com/android/settings/network/telephony/satellite/SatelliteSettingsPreferenceCategoryController.java
similarity index 97%
rename from src/com/android/settings/network/telephony/SatelliteSettingsPreferenceCategoryController.java
rename to src/com/android/settings/network/telephony/satellite/SatelliteSettingsPreferenceCategoryController.java
index 38285d454be6966ff6ef92592d1ea8d3754a68c2..f2fb347852ce2686f130b785f0f01e01440a8066 100644
--- a/src/com/android/settings/network/telephony/SatelliteSettingsPreferenceCategoryController.java
+++ b/src/com/android/settings/network/telephony/satellite/SatelliteSettingsPreferenceCategoryController.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2024 The Android Open Source Project
+ * Copyright (C) 2025 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package com.android.settings.network.telephony;
+package com.android.settings.network.telephony.satellite;
import static android.telephony.CarrierConfigManager.CARRIER_ROAMING_NTN_CONNECT_AUTOMATIC;
import static android.telephony.CarrierConfigManager.KEY_CARRIER_ROAMING_NTN_CONNECT_TYPE_INT;
@@ -39,6 +39,7 @@ import androidx.preference.PreferenceScreen;
import com.android.settings.flags.Flags;
import com.android.settings.network.CarrierConfigCache;
+import com.android.settings.network.telephony.TelephonyBasePreferenceController;
import java.util.Arrays;
import java.util.List;
diff --git a/src/com/android/settings/wifi/AddNetworkFragment.java b/src/com/android/settings/wifi/AddNetworkFragment.java
index aa8e840e38dfc6fad9b636782cb8600d31419e9c..af12c5803bb5e9d6e236b0d37228eeeac6c25898 100644
--- a/src/com/android/settings/wifi/AddNetworkFragment.java
+++ b/src/com/android/settings/wifi/AddNetworkFragment.java
@@ -206,7 +206,7 @@ public class AddNetworkFragment extends InstrumentedFragment implements WifiConf
@VisibleForTesting
void handleSubmitAction() {
- if (!mUIController.canFinish()) {
+ if (!mUIController.getValidator().validate()) {
return;
}
successfullyFinish(mUIController.getConfig());
diff --git a/src/com/android/settings/wifi/ConfigureWifiEntryFragment.java b/src/com/android/settings/wifi/ConfigureWifiEntryFragment.java
index 652d318b4f904c6054e3a555dc1ac7f91f3d7cbb..77254302819ef7769dd282fc6cc38dd15d51bc06 100644
--- a/src/com/android/settings/wifi/ConfigureWifiEntryFragment.java
+++ b/src/com/android/settings/wifi/ConfigureWifiEntryFragment.java
@@ -203,6 +203,9 @@ public class ConfigureWifiEntryFragment extends InstrumentedFragment implements
@VisibleForTesting
void handleSubmitAction() {
+ if (!mUiController.getValidator().validate()) {
+ return;
+ }
final Intent intent = new Intent();
final Activity activity = getActivity();
intent.putExtra(NETWORK_CONFIG_KEY, mUiController.getConfig());
diff --git a/src/com/android/settings/wifi/WifiConfigController.java b/src/com/android/settings/wifi/WifiConfigController.java
index 003c2afed49c9e8045370123606417ac69b957cc..192cc5b03708fd547ca8b88ffeb29c5d5a6edbf9 100644
--- a/src/com/android/settings/wifi/WifiConfigController.java
+++ b/src/com/android/settings/wifi/WifiConfigController.java
@@ -296,7 +296,7 @@ public class WifiConfigController implements TextWatcher,
mSsidInput = new TextInputGroup(mView, R.id.ssid_layout, R.id.ssid,
R.string.wifi_ssid_hint);
- mPasswordInput = new WifiPasswordInput(mView);
+ mPasswordInput = new WifiPasswordInput(mView, mAccessPointSecurity);
mValidator.addTextInput(mSsidInput);
mValidator.addTextInput(mPasswordInput);
diff --git a/src/com/android/settings/wifi/WifiConfigController2.java b/src/com/android/settings/wifi/WifiConfigController2.java
index a080fc8c5bce6ea6df1d003b6a60977fa4a8965d..7ba91ada316af17e5a396586db14ea980b61ae69 100644
--- a/src/com/android/settings/wifi/WifiConfigController2.java
+++ b/src/com/android/settings/wifi/WifiConfigController2.java
@@ -78,6 +78,8 @@ import com.android.settings.wifi.details2.WifiPrivacyPreferenceController;
import com.android.settings.wifi.details2.WifiPrivacyPreferenceController2;
import com.android.settings.wifi.dpp.WifiDppUtils;
import com.android.settings.wifi.utils.TextInputGroup;
+import com.android.settings.wifi.utils.TextInputValidator;
+import com.android.settings.wifi.utils.WifiPasswordInput;
import com.android.settingslib.Utils;
import com.android.settingslib.utils.ThreadUtils;
import com.android.wifi.flags.Flags;
@@ -229,7 +231,10 @@ public class WifiConfigController2 implements TextWatcher,
private final boolean mHideMeteredAndPrivacy;
private final WifiManager mWifiManager;
private final AndroidKeystoreAliasLoader mAndroidKeystoreAliasLoader;
+
+ private TextInputValidator mValidator = new TextInputValidator();
private TextInputGroup mSsidInputGroup;
+ private WifiPasswordInput mPasswordInput;
private final Context mContext;
@@ -301,6 +306,10 @@ public class WifiConfigController2 implements TextWatcher,
mSsidInputGroup = new TextInputGroup(mView, R.id.ssid_layout, R.id.ssid,
R.string.wifi_ssid_hint);
+ mPasswordInput = new WifiPasswordInput(mView, mWifiEntrySecurity);
+ mValidator.addTextInput(mSsidInputGroup);
+ mValidator.addTextInput(mPasswordInput);
+
mSsidScanButton = (ImageButton) mView.findViewById(R.id.ssid_scanner_button);
mIpSettingsSpinner = (Spinner) mView.findViewById(R.id.ip_settings);
mIpSettingsSpinner.setOnItemSelectedListener(this);
@@ -519,45 +528,8 @@ public class WifiConfigController2 implements TextWatcher,
submit.setEnabled(isSubmittable());
}
- boolean isValidPsk(String password) {
- if (password.length() == 64 && password.matches("[0-9A-Fa-f]{64}")) {
- return true;
- } else if (password.length() >= 8 && password.length() <= 63) {
- return true;
- }
- return false;
- }
-
- boolean isValidSaePassword(String password) {
- if (password.length() >= 1 && password.length() <= 128) {
- return true;
- }
- return false;
- }
-
boolean isSubmittable() {
- boolean enabled = false;
- boolean passwordInvalid = false;
- if (mPasswordView != null
- && ((mWifiEntrySecurity == WifiEntry.SECURITY_WEP
- && mPasswordView.length() == 0)
- || (mWifiEntrySecurity == WifiEntry.SECURITY_PSK
- && !isValidPsk(mPasswordView.getText().toString()))
- || (mWifiEntrySecurity == WifiEntry.SECURITY_SAE
- && !isValidSaePassword(mPasswordView.getText().toString())))) {
- passwordInvalid = true;
- }
- if ((mWifiEntry == null || !mWifiEntry.isSaved()) && passwordInvalid) {
- // If WifiEntry is not saved, apply passwordInvalid check
- enabled = false;
- } else if (mWifiEntry != null && mWifiEntry.isSaved() && passwordInvalid
- && mPasswordView.length() > 0) {
- // If WifiEntry is saved (modifying network) and password is changed, apply
- // Invalid password check
- enabled = false;
- } else {
- enabled = ipAndProxyFieldsAreValid();
- }
+ boolean enabled = ipAndProxyFieldsAreValid();
if ((mWifiEntrySecurity == WifiEntry.SECURITY_EAP
|| mWifiEntrySecurity == WifiEntry.SECURITY_EAP_WPA3_ENTERPRISE
|| mWifiEntrySecurity == WifiEntry.SECURITY_EAP_SUITE_B)
@@ -589,14 +561,6 @@ public class WifiConfigController2 implements TextWatcher,
return enabled;
}
- boolean canFinish() {
- if (!mSsidInputGroup.validate()) {
- Log.w(TAG, "Can't finish because SSID is invalid!");
- return false;
- }
- return true;
- }
-
void showWarningMessagesIfAppropriate() {
mView.findViewById(R.id.no_user_cert_warning).setVisibility(View.GONE);
mView.findViewById(R.id.no_domain_warning).setVisibility(View.GONE);
@@ -1050,7 +1014,9 @@ public class WifiConfigController2 implements TextWatcher,
.setOnCheckedChangeListener(this);
if (mWifiEntry != null && mWifiEntry.isSaved()) {
- mPasswordView.setHint(R.string.wifi_unchanged);
+ mPasswordInput.setCanBeEmpty(true);
+ mPasswordInput.getLayout().setHint(R.string.wifi_password_optional);
+ mPasswordInput.setHelperText(mContext.getString(R.string.wifi_unchanged));
}
}
@@ -1763,6 +1729,7 @@ public class WifiConfigController2 implements TextWatcher,
// Convert menu position to actual Wi-Fi security type
mWifiEntrySecurity = mSecurityInPosition[position];
showSecurityFields(/* refreshEapMethods */ true, /* refreshCertificates */ true);
+ mPasswordInput.setSecurity(mWifiEntrySecurity);
if (WifiDppUtils.isSupportEnrolleeQrCodeScanner(mContext, mWifiEntrySecurity)) {
mSsidScanButton.setVisibility(View.VISIBLE);
@@ -2013,4 +1980,11 @@ public class WifiConfigController2 implements TextWatcher,
spinner.setAdapter(getSpinnerAdapter(stringArray));
return spinner;
}
+
+ /**
+ * Provides a validator to verify that the Wi-Fi configuration is ready.
+ */
+ public TextInputValidator getValidator() {
+ return mValidator;
+ }
}
diff --git a/src/com/android/settings/wifi/WifiDialog.java b/src/com/android/settings/wifi/WifiDialog.java
index 2fd3ce1ea93bd65a168eff793b0479309cbac1ca..6d0fca2017534aa30550cf5efa49b1e544d0099f 100644
--- a/src/com/android/settings/wifi/WifiDialog.java
+++ b/src/com/android/settings/wifi/WifiDialog.java
@@ -118,7 +118,7 @@ public class WifiDialog extends AlertDialog implements WifiConfigUiBase,
mController.hideForgetButton();
}
- mDialogHelper = new WifiDialogHelper(this, mController.getValidator());
+ mDialogHelper = new WifiDialogHelper(this, this, mController.getValidator());
}
@SuppressWarnings("MissingSuperCall") // TODO: Fix me
@@ -159,6 +159,9 @@ public class WifiDialog extends AlertDialog implements WifiConfigUiBase,
public void onClick(DialogInterface dialogInterface, int id) {
if (mListener != null) {
switch (id) {
+ case BUTTON_SUBMIT:
+ mListener.onSubmit(this);
+ break;
case BUTTON_FORGET:
if (WifiUtils.isNetworkLockedDown(getContext(), mAccessPoint.getConfig())) {
RestrictedLockUtils.sendShowAdminSupportDetailsIntent(getContext(),
@@ -171,11 +174,6 @@ public class WifiDialog extends AlertDialog implements WifiConfigUiBase,
}
}
- /** Return true to tell the parent activity to call onSubmit before onDismiss. */
- public boolean shouldSubmitBeforeFinish() {
- return mDialogHelper.isPositive();
- }
-
@Override
public int getMode() {
return mMode;
diff --git a/src/com/android/settings/wifi/WifiDialog2.kt b/src/com/android/settings/wifi/WifiDialog2.kt
index 2b89e4bb41a4fe100b073c05458cdc8fd7eae8ea..c9476e4d9e71e013a51f98e9c66d993038b4c0be 100644
--- a/src/com/android/settings/wifi/WifiDialog2.kt
+++ b/src/com/android/settings/wifi/WifiDialog2.kt
@@ -28,6 +28,7 @@ import android.widget.TextView
import androidx.annotation.OpenForTesting
import androidx.appcompat.app.AlertDialog
import com.android.settings.R
+import com.android.settings.wifi.utils.WifiDialogHelper
import com.android.settingslib.RestrictedLockUtils
import com.android.settingslib.RestrictedLockUtilsInternal
import com.android.wifitrackerlib.WifiEntry
@@ -68,6 +69,7 @@ open class WifiDialog2 @JvmOverloads constructor(
private lateinit var view: View
private lateinit var controller: WifiConfigController2
+ private lateinit var dialogHelper: WifiDialogHelper
override fun getController(): WifiConfigController2 = controller
@@ -89,6 +91,7 @@ open class WifiDialog2 @JvmOverloads constructor(
if (wifiEntry == null) {
controller.hideForgetButton()
}
+ dialogHelper = WifiDialogHelper(this, this, controller.validator)
}
private fun setWindowsOverlay() {
diff --git a/src/com/android/settings/wifi/WifiDialogActivity.java b/src/com/android/settings/wifi/WifiDialogActivity.java
index 1d431753f324c8d6762d3e6adafcce9e9dc2e5a9..951277aa9cfa27b50e65c71983ca1f08699e0c25 100644
--- a/src/com/android/settings/wifi/WifiDialogActivity.java
+++ b/src/com/android/settings/wifi/WifiDialogActivity.java
@@ -346,9 +346,6 @@ public class WifiDialogActivity extends ObservableActivity implements WifiDialog
@Override
public void onDismiss(DialogInterface dialogInterface) {
mDialog2 = null;
- if (mDialog != null && mDialog.shouldSubmitBeforeFinish()) {
- onSubmit(mDialog);
- }
mDialog = null;
finish();
}
diff --git a/src/com/android/settings/wifi/utils/AlertDialogHelper.kt b/src/com/android/settings/wifi/utils/AlertDialogHelper.kt
index c50323220b76e59adc410652df4e5c5a88c4b463..e2307fbfdc7112b6223b7ac8f14c5b0c0cd4c8c1 100644
--- a/src/com/android/settings/wifi/utils/AlertDialogHelper.kt
+++ b/src/com/android/settings/wifi/utils/AlertDialogHelper.kt
@@ -17,16 +17,18 @@
package com.android.settings.wifi.utils
import android.content.DialogInterface
+import android.content.DialogInterface.BUTTON_POSITIVE
import android.util.Log
import androidx.appcompat.app.AlertDialog
-open class AlertDialogHelper(val alertDialog: AlertDialog) {
-
- var isPositive = false
+open class AlertDialogHelper(
+ val alertDialog: AlertDialog,
+ val onClickListener: DialogInterface.OnClickListener? = null,
+) {
init {
alertDialog.setOnShowListener {
- alertDialog.getButton(DialogInterface.BUTTON_POSITIVE)?.setOnClickListener {
+ alertDialog.getButton(BUTTON_POSITIVE)?.setOnClickListener {
onPositiveButtonClicked()
} ?: Log.e(TAG, "Can't get the positive button!")
}
@@ -37,7 +39,7 @@ open class AlertDialogHelper(val alertDialog: AlertDialog) {
Log.w(TAG, "Can't dismiss dialog!")
return
}
- isPositive = true
+ onClickListener?.onClick(alertDialog, BUTTON_POSITIVE)
alertDialog.dismiss()
}
diff --git a/src/com/android/settings/wifi/utils/TextInputGroup.kt b/src/com/android/settings/wifi/utils/TextInputGroup.kt
index 3fe2d9d08a4f32a3ec2f9c3ed32d32284250636d..37d7356d3d76c137e3e476d3a4209ebf65027318 100644
--- a/src/com/android/settings/wifi/utils/TextInputGroup.kt
+++ b/src/com/android/settings/wifi/utils/TextInputGroup.kt
@@ -75,6 +75,7 @@ open class TextInputGroup(
get() = layout.helperText?.toString() ?: ""
set(value) {
layout.setHelperText(value)
+ if (value.isEmpty()) layout.isHelperTextEnabled = false
}
var error: String
@@ -85,6 +86,8 @@ open class TextInputGroup(
}
open fun validate(): Boolean {
+ if (!editText.isShown) return true
+
val isValid = text.isNotEmpty()
if (!isValid) {
Log.w(TAG, "validate failed in ${layout.hint ?: "unknown"}")
diff --git a/src/com/android/settings/wifi/utils/WifiDialogHelper.kt b/src/com/android/settings/wifi/utils/WifiDialogHelper.kt
index f4c3327e3bf37969ef363959bda0699e438d3577..5607fdf15986c00ef2aa042a8e3652a5612c53bc 100644
--- a/src/com/android/settings/wifi/utils/WifiDialogHelper.kt
+++ b/src/com/android/settings/wifi/utils/WifiDialogHelper.kt
@@ -16,13 +16,14 @@
package com.android.settings.wifi.utils
-import android.util.Log
+import android.content.DialogInterface
import androidx.appcompat.app.AlertDialog
class WifiDialogHelper(
alertDialog: AlertDialog,
+ onClickListener: DialogInterface.OnClickListener?,
private val validator: TextInputValidator,
-) : AlertDialogHelper(alertDialog) {
+) : AlertDialogHelper(alertDialog, onClickListener) {
override fun canDismiss(): Boolean = validator.validate()
diff --git a/src/com/android/settings/wifi/utils/WifiPasswordInput.kt b/src/com/android/settings/wifi/utils/WifiPasswordInput.kt
index 19ebdd9658bf0fdff3ab918586fa01d364e47537..084e8bf71313d4f61ab11f4cd44f98d2060979a9 100644
--- a/src/com/android/settings/wifi/utils/WifiPasswordInput.kt
+++ b/src/com/android/settings/wifi/utils/WifiPasswordInput.kt
@@ -27,13 +27,16 @@ import com.android.wifitrackerlib.WifiEntry.SECURITY_WEP
/**
* The Wi-Fi password {@code TextInputGroup} that supports input validation.
*/
-class WifiPasswordInput(view: View) :
- TextInputGroup(view, R.id.password_input_layout, R.id.password, R.string.wifi_field_required) {
+class WifiPasswordInput(
+ view: View,
+ var security: Int = SECURITY_NONE,
+) : TextInputGroup(view, R.id.password_input_layout, R.id.password, R.string.wifi_field_required) {
- var security: Int = SECURITY_NONE
+ var canBeEmpty: Boolean = false
override fun validate(): Boolean {
if (!editText.isShown) return true
+ if (canBeEmpty && text.isEmpty()) return true
return when (security) {
SECURITY_WEP -> super.validate()
diff --git a/tests/Enable16KbTests/src/com/android/test/Enable16KbTest.java b/tests/Enable16KbTests/src/com/android/test/Enable16KbTest.java
index 75e29a1d15e83d126936856c60b12b5be9da4bc5..5af6cbbce624c1c6050a642fdd7c307fd67f4135 100644
--- a/tests/Enable16KbTests/src/com/android/test/Enable16KbTest.java
+++ b/tests/Enable16KbTests/src/com/android/test/Enable16KbTest.java
@@ -115,9 +115,9 @@ public class Enable16KbTest extends BaseHostJUnit4Test {
private void prepareDevice() throws Exception {
// Verify that device is online before running test and enable root
- getDevice().waitForDeviceOnline(DEVICE_WAIT_TIMEOUT);
+ getDevice().waitForDeviceAvailable(DEVICE_WAIT_TIMEOUT);
getDevice().enableAdbRoot();
- getDevice().waitForDeviceOnline(DEVICE_WAIT_TIMEOUT);
+ getDevice().waitForDeviceAvailable(DEVICE_WAIT_TIMEOUT);
getDevice().executeShellCommand("input keyevent KEYCODE_WAKEUP");
getDevice().executeShellCommand("wm dismiss-keyguard");
diff --git a/tests/robotests/src/com/android/settings/accessibility/ToggleScreenMagnificationPreferenceFragmentTest.java b/tests/robotests/src/com/android/settings/accessibility/ToggleScreenMagnificationPreferenceFragmentTest.java
index 6407c081aeaaffc5ee91db1ace65d0f5ca2015b1..0fd374b5000a6f44d8d3c932e7b0cd8cc514744e 100644
--- a/tests/robotests/src/com/android/settings/accessibility/ToggleScreenMagnificationPreferenceFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/accessibility/ToggleScreenMagnificationPreferenceFragmentTest.java
@@ -546,6 +546,45 @@ public class ToggleScreenMagnificationPreferenceFragmentTest {
assertThat(switchPreference).isNull();
}
+ @Test
+ @DisableFlags(com.android.settings.accessibility.Flags
+ .FLAG_ENABLE_MAGNIFICATION_CURSOR_FOLLOWING_DIALOG)
+ @Config(shadows = ShadowInputDevice.class)
+ public void onCreateView_cursorFollowingModeDisabled_settingsPreferenceIsNull() {
+ addMouseDevice();
+
+ mFragController.create(R.id.main_content, /* bundle= */null).start().resume().get();
+
+ final Preference preference = mFragController.get().findPreference(
+ MagnificationCursorFollowingModePreferenceController.PREF_KEY);
+ assertThat(preference).isNull();
+ }
+
+ @Test
+ @EnableFlags(com.android.settings.accessibility.Flags
+ .FLAG_ENABLE_MAGNIFICATION_CURSOR_FOLLOWING_DIALOG)
+ public void onCreateView_cursorFollowingModeEnabled_settingsPreferenceIsNullWithoutMouse() {
+ mFragController.create(R.id.main_content, /* bundle= */null).start().resume().get();
+
+ final Preference preference = mFragController.get().findPreference(
+ MagnificationCursorFollowingModePreferenceController.PREF_KEY);
+ assertThat(preference).isNull();
+ }
+
+ @Test
+ @EnableFlags(com.android.settings.accessibility.Flags
+ .FLAG_ENABLE_MAGNIFICATION_CURSOR_FOLLOWING_DIALOG)
+ @Config(shadows = ShadowInputDevice.class)
+ public void onCreateView_cursorFollowingModeEnabled_settingsPreferenceIsNotNullWithMouse() {
+ addMouseDevice();
+
+ mFragController.create(R.id.main_content, /* bundle= */null).start().resume().get();
+
+ final Preference preference = mFragController.get().findPreference(
+ MagnificationCursorFollowingModePreferenceController.PREF_KEY);
+ assertThat(preference).isNotNull();
+ }
+
@Test
public void onCreateView_setDialogDelegateAndAddTheControllerToLifeCycleObserver() {
Correspondence instanceOf = Correspondence.transforming(
@@ -903,11 +942,13 @@ public class ToggleScreenMagnificationPreferenceFragmentTest {
Flags.FLAG_ENABLE_LOW_VISION_HATS,
com.android.settings.accessibility.Flags
.FLAG_ENABLE_MAGNIFICATION_CURSOR_FOLLOWING_DIALOG})
+ @Config(shadows = ShadowInputDevice.class)
public void getNonIndexableKeys_hasShortcutAndAllFeaturesEnabled_allItemsSearchable() {
mShadowAccessibilityManager.setAccessibilityShortcutTargets(
TRIPLETAP, List.of(MAGNIFICATION_CONTROLLER_NAME));
setAlwaysOnSupported(true);
setJoystickSupported(true);
+ addMouseDevice();
final List niks = ToggleScreenMagnificationPreferenceFragment
.SEARCH_INDEX_DATA_PROVIDER.getNonIndexableKeys(mContext);
@@ -1026,6 +1067,14 @@ public class ToggleScreenMagnificationPreferenceFragmentTest {
enabled ? ON : OFF);
}
+ private void addMouseDevice() {
+ int deviceId = 1;
+ ShadowInputDevice.sDeviceIds = new int[]{deviceId};
+ InputDevice device = ShadowInputDevice.makeInputDevicebyIdWithSources(deviceId,
+ InputDevice.SOURCE_MOUSE);
+ ShadowInputDevice.addDevice(deviceId, device);
+ }
+
private String getStringFromSettings(String key) {
return Settings.Secure.getString(mContext.getContentResolver(), key);
}
diff --git a/tests/robotests/src/com/android/settings/bluetooth/BluetoothKeyMissingDialogTest.java b/tests/robotests/src/com/android/settings/bluetooth/BluetoothKeyMissingDialogTest.java
index 14e263c0fb22eeac9cce2a7c7b5d6062b79adbbe..a2bf43a9fdd4a406279dc0769e5bc375644a4f79 100644
--- a/tests/robotests/src/com/android/settings/bluetooth/BluetoothKeyMissingDialogTest.java
+++ b/tests/robotests/src/com/android/settings/bluetooth/BluetoothKeyMissingDialogTest.java
@@ -17,16 +17,18 @@ package com.android.settings.bluetooth;
import static com.google.common.truth.Truth.assertThat;
-import static org.mockito.Mockito.never;
-import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
+import static org.robolectric.Shadows.shadowOf;
import static org.robolectric.shadows.ShadowLooper.shadowMainLooper;
import android.bluetooth.BluetoothDevice;
+import android.content.Intent;
import androidx.appcompat.app.AlertDialog;
import androidx.fragment.app.FragmentActivity;
+import com.android.settings.SettingsActivity;
+import com.android.settings.SubSettings;
import com.android.settings.testutils.shadow.ShadowAlertDialogCompat;
import com.android.settings.testutils.shadow.ShadowBluetoothUtils;
import com.android.settingslib.bluetooth.LocalBluetoothManager;
@@ -40,6 +42,7 @@ import org.mockito.MockitoAnnotations;
import org.robolectric.Robolectric;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config;
+import org.robolectric.shadows.ShadowIntent;
@RunWith(RobolectricTestRunner.class)
@Config(shadows = {ShadowAlertDialogCompat.class, ShadowBluetoothUtils.class})
@@ -71,18 +74,23 @@ public class BluetoothKeyMissingDialogTest {
}
@Test
- public void clickForgetDevice_removeBond() {
+ public void clickDeviceSettings_launchDeviceDetails() {
mFragment.onClick(mFragment.getDialog(), AlertDialog.BUTTON_POSITIVE);
- verify(mBluetoothDevice).removeBond();
+ Intent startedIntent = shadowOf(mActivity).getNextStartedActivity();
+ ShadowIntent shadowIntent = shadowOf(startedIntent);
+ assertThat(shadowIntent.getIntentClass()).isEqualTo(SubSettings.class);
+ assertThat(startedIntent.getStringExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT))
+ .isEqualTo(BluetoothDeviceDetailsFragment.class.getName());
assertThat(mActivity.isFinishing()).isTrue();
}
@Test
- public void clickCancel_notRemoveBond() {
+ public void clickCancel_notLaunchDeviceDetails() {
mFragment.onClick(mFragment.getDialog(), AlertDialog.BUTTON_NEGATIVE);
- verify(mBluetoothDevice, never()).removeBond();
+ Intent startedIntent = shadowOf(mActivity).getNextStartedActivity();
+ assertThat(startedIntent).isNull();
assertThat(mActivity.isFinishing()).isTrue();
}
}
diff --git a/tests/robotests/src/com/android/settings/dashboard/DashboardFeatureProviderImplTest.java b/tests/robotests/src/com/android/settings/dashboard/DashboardFeatureProviderImplTest.java
index 0799eaff7c469e2503df4c7825ea1aa3ae86a663..45a3ecda4dca85384d47ff7f10dc96f45c53557a 100644
--- a/tests/robotests/src/com/android/settings/dashboard/DashboardFeatureProviderImplTest.java
+++ b/tests/robotests/src/com/android/settings/dashboard/DashboardFeatureProviderImplTest.java
@@ -22,6 +22,7 @@ import static com.android.settingslib.drawer.SwitchesProvider.EXTRA_SWITCH_SET_C
import static com.android.settingslib.drawer.TileUtils.META_DATA_KEY_ORDER;
import static com.android.settingslib.drawer.TileUtils.META_DATA_KEY_PROFILE;
import static com.android.settingslib.drawer.TileUtils.META_DATA_PREFERENCE_ICON;
+import static com.android.settingslib.drawer.TileUtils.META_DATA_PREFERENCE_ICON_COLOR_SCHEME;
import static com.android.settingslib.drawer.TileUtils.META_DATA_PREFERENCE_ICON_URI;
import static com.android.settingslib.drawer.TileUtils.META_DATA_PREFERENCE_KEYHINT;
import static com.android.settingslib.drawer.TileUtils.META_DATA_PREFERENCE_SUMMARY;
@@ -822,6 +823,135 @@ public class DashboardFeatureProviderImplTest {
verify(mActivity, never()).getSupportFragmentManager();
}
+ @Test
+ public void getSchemedColors_schemeNotSpecified_returnNull() {
+ Tile tile = new ActivityTile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE);
+
+ Pair colors = mImpl.getSchemedColors(tile);
+
+ assertThat(colors).isNull();
+ }
+
+ @Test
+ public void getSchemedColors_undefinedScheme_returnNull() {
+ Tile tile = new ActivityTile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE);
+ mActivityInfo.metaData.putString(META_DATA_PREFERENCE_ICON_COLOR_SCHEME, "abc");
+
+ Pair colors = mImpl.getSchemedColors(tile);
+
+ assertThat(colors).isNull();
+ }
+
+ @Test
+ public void getSchemedColors_blueVariantScheme_returnCorrectColors() {
+ Tile tile = new ActivityTile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE);
+ mActivityInfo.metaData.putString(META_DATA_PREFERENCE_ICON_COLOR_SCHEME, "blue_variant");
+
+ Pair colors = mImpl.getSchemedColors(tile);
+
+ assertThat(colors.first).isEqualTo(R.color.homepage_blue_variant_fg);
+ assertThat(colors.second).isEqualTo(R.color.homepage_blue_variant_bg);
+ }
+
+ @Test
+ public void getSchemedColors_blueScheme_returnCorrectColors() {
+ Tile tile = new ActivityTile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE);
+ mActivityInfo.metaData.putString(META_DATA_PREFERENCE_ICON_COLOR_SCHEME, "blue");
+
+ Pair colors = mImpl.getSchemedColors(tile);
+
+ assertThat(colors.first).isEqualTo(R.color.homepage_blue_fg);
+ assertThat(colors.second).isEqualTo(R.color.homepage_blue_bg);
+ }
+
+ @Test
+ public void getSchemedColors_pinkScheme_returnCorrectColors() {
+ Tile tile = new ActivityTile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE);
+ mActivityInfo.metaData.putString(META_DATA_PREFERENCE_ICON_COLOR_SCHEME, "pink");
+
+ Pair colors = mImpl.getSchemedColors(tile);
+
+ assertThat(colors.first).isEqualTo(R.color.homepage_pink_fg);
+ assertThat(colors.second).isEqualTo(R.color.homepage_pink_bg);
+ }
+
+ @Test
+ public void getSchemedColors_orangeScheme_returnCorrectColors() {
+ Tile tile = new ActivityTile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE);
+ mActivityInfo.metaData.putString(META_DATA_PREFERENCE_ICON_COLOR_SCHEME, "orange");
+
+ Pair colors = mImpl.getSchemedColors(tile);
+
+ assertThat(colors.first).isEqualTo(R.color.homepage_orange_fg);
+ assertThat(colors.second).isEqualTo(R.color.homepage_orange_bg);
+ }
+
+ @Test
+ public void getSchemedColors_yellowScheme_returnCorrectColors() {
+ Tile tile = new ActivityTile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE);
+ mActivityInfo.metaData.putString(META_DATA_PREFERENCE_ICON_COLOR_SCHEME, "yellow");
+
+ Pair colors = mImpl.getSchemedColors(tile);
+
+ assertThat(colors.first).isEqualTo(R.color.homepage_yellow_fg);
+ assertThat(colors.second).isEqualTo(R.color.homepage_yellow_bg);
+ }
+
+ @Test
+ public void getSchemedColors_greenScheme_returnCorrectColors() {
+ Tile tile = new ActivityTile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE);
+ mActivityInfo.metaData.putString(META_DATA_PREFERENCE_ICON_COLOR_SCHEME, "green");
+
+ Pair colors = mImpl.getSchemedColors(tile);
+
+ assertThat(colors.first).isEqualTo(R.color.homepage_green_fg);
+ assertThat(colors.second).isEqualTo(R.color.homepage_green_bg);
+ }
+
+ @Test
+ public void getSchemedColors_greyScheme_returnCorrectColors() {
+ Tile tile = new ActivityTile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE);
+ mActivityInfo.metaData.putString(META_DATA_PREFERENCE_ICON_COLOR_SCHEME, "grey");
+
+ Pair colors = mImpl.getSchemedColors(tile);
+
+ assertThat(colors.first).isEqualTo(R.color.homepage_grey_fg);
+ assertThat(colors.second).isEqualTo(R.color.homepage_grey_bg);
+ }
+
+ @Test
+ public void getSchemedColors_cyanScheme_returnCorrectColors() {
+ Tile tile = new ActivityTile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE);
+ mActivityInfo.metaData.putString(META_DATA_PREFERENCE_ICON_COLOR_SCHEME, "cyan");
+
+ Pair colors = mImpl.getSchemedColors(tile);
+
+ assertThat(colors.first).isEqualTo(R.color.homepage_cyan_fg);
+ assertThat(colors.second).isEqualTo(R.color.homepage_cyan_bg);
+ }
+
+ @Test
+ public void getSchemedColors_redScheme_returnCorrectColors() {
+ Tile tile = new ActivityTile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE);
+ mActivityInfo.metaData.putString(META_DATA_PREFERENCE_ICON_COLOR_SCHEME, "red");
+
+ Pair colors = mImpl.getSchemedColors(tile);
+
+ assertThat(colors.first).isEqualTo(R.color.homepage_red_fg);
+ assertThat(colors.second).isEqualTo(R.color.homepage_red_bg);
+ }
+
+ @Test
+ public void getSchemedColors_purpleScheme_returnCorrectColors() {
+ Tile tile = new ActivityTile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE);
+ mActivityInfo.metaData.putString(META_DATA_PREFERENCE_ICON_COLOR_SCHEME, "purple");
+
+ Pair colors = mImpl.getSchemedColors(tile);
+
+ assertThat(colors.first).isEqualTo(R.color.homepage_purple_fg);
+ assertThat(colors.second).isEqualTo(R.color.homepage_purple_bg);
+ }
+
private static class TestFragment extends DashboardFragment {
@Override
diff --git a/tests/robotests/src/com/android/settings/display/ScreenTimeoutSettingsTest.java b/tests/robotests/src/com/android/settings/display/ScreenTimeoutSettingsTest.java
index 1a6a1128068a811867ebfa18821e183d834f756d..c50547dbb0b3ccfa4d66a308185780bbc835b165 100644
--- a/tests/robotests/src/com/android/settings/display/ScreenTimeoutSettingsTest.java
+++ b/tests/robotests/src/com/android/settings/display/ScreenTimeoutSettingsTest.java
@@ -28,6 +28,7 @@ import static org.mockito.ArgumentMatchers.isA;
import static org.mockito.Mockito.atLeast;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
@@ -80,8 +81,10 @@ public class ScreenTimeoutSettingsTest {
@Rule
public final CheckFlagsRule mCheckFlagsRule = DeviceFlagsValueProvider.createCheckFlagsRule();
- private static final String[] TIMEOUT_ENTRIES = new String[]{"15 secs", "30 secs"};
- private static final String[] TIMEOUT_VALUES = new String[]{"15000", "30000"};
+ private static final String[] TIMEOUT_ENTRIES =
+ new String[]{"15 secs", "30 secs", "1 min", "2 min", "5 min"};
+ private static final String[] TIMEOUT_VALUES =
+ new String[]{"15000", "30000", "60000", "120000", "300000"};
private ScreenTimeoutSettings mSettings;
private Context mContext;
@@ -109,6 +112,9 @@ public class ScreenTimeoutSettingsTest {
@Mock
FooterPreference mPowerConsumptionPreference;
+ @Mock
+ DevicePolicyManager mDevicePolicyManager;
+
@Mock
private PackageManager mPackageManager;
@@ -132,7 +138,7 @@ public class ScreenTimeoutSettingsTest {
attentionServiceResolveInfo);
doReturn(TIMEOUT_ENTRIES).when(mResources).getStringArray(R.array.screen_timeout_entries);
- doReturn(TIMEOUT_VALUES).when(mResources).getStringArray(R.array.screen_timeout_entries);
+ doReturn(TIMEOUT_VALUES).when(mResources).getStringArray(R.array.screen_timeout_values);
doReturn(true).when(mResources).getBoolean(
com.android.internal.R.bool.config_adaptive_sleep_available);
@@ -223,6 +229,79 @@ public class ScreenTimeoutSettingsTest {
verify(mPreferenceScreen, atLeast(1)).addPreference(mPowerConsumptionPreference);
}
+ @Test
+ public void getCandidates_enforcedAdmin_timeoutIsLimited() {
+ mSettings.mAdmin = new RestrictedLockUtils.EnforcedAdmin();
+ mSettings.mDisableOptionsPreference = mDisableOptionsPreference;
+ doNothing().when(mSettings).setupDisabledFooterPreference();
+ doReturn(mDevicePolicyManager).when(mContext).getSystemService(DevicePolicyManager.class);
+ // Admin-enforced max timeout of 30000
+ when(mDevicePolicyManager.getMaximumTimeToLock(any(), anyInt())).thenReturn(30000L);
+ // No configured max timeout
+ doThrow(new Resources.NotFoundException("Invalid resource")).when(mResources)
+ .getInteger(R.integer.config_max_screen_timeout);
+
+ List extends CandidateInfo> candidates = mSettings.getCandidates();
+
+ // Assert that candidates are truncated at the admin-controlled timeout
+ assertThat(candidates.size()).isEqualTo(2);
+ assertThat(candidates.get(candidates.size() - 1).getKey()).isEqualTo(TIMEOUT_VALUES[1]);
+ }
+
+ @Test
+ public void getCandidates_configuredMaxTimeout_65000_timeoutIsLimited() {
+ when(mContext.getSystemService(DevicePolicyManager.class)).thenCallRealMethod();
+ doReturn(65000).when(mResources).getInteger(R.integer.config_max_screen_timeout);
+
+ List extends CandidateInfo> candidates = mSettings.getCandidates();
+
+ // Assert that candidates are truncated at the highest timeout that is below the max timeout
+ assertThat(candidates.size()).isEqualTo(3);
+ assertThat(candidates.get(candidates.size() - 1).getKey()).isEqualTo(TIMEOUT_VALUES[2]);
+ }
+
+ @Test
+ public void getCandidates_configuredAndAdminEnforcedMaxTimeout_lowestTimeoutIsApplied() {
+ mSettings.mAdmin = new RestrictedLockUtils.EnforcedAdmin();
+ mSettings.mDisableOptionsPreference = mDisableOptionsPreference;
+ doNothing().when(mSettings).setupDisabledFooterPreference();
+ doReturn(mDevicePolicyManager).when(mContext).getSystemService(DevicePolicyManager.class);
+ // Admin-enforced max timeout of 30000
+ when(mDevicePolicyManager.getMaximumTimeToLock(any(), anyInt())).thenReturn(30000L);
+ // Configured max timeout of 120000
+ doReturn(120000).when(mResources).getInteger(R.integer.config_max_screen_timeout);
+
+ List extends CandidateInfo> candidates = mSettings.getCandidates();
+
+ // Assert that candidates are truncated at the lowest of the two timeouts
+ assertThat(candidates.size()).isEqualTo(2);
+ assertThat(candidates.get(candidates.size() - 1).getKey()).isEqualTo(TIMEOUT_VALUES[1]);
+ }
+
+ @Test
+ public void getCandidates_configuredMaxTimeout_300000_timeoutIsNotLimited() {
+ when(mContext.getSystemService(DevicePolicyManager.class)).thenCallRealMethod();
+ doReturn(300000).when(mResources).getInteger(R.integer.config_max_screen_timeout);
+
+ List extends CandidateInfo> candidates = mSettings.getCandidates();
+
+ // Assert that candidates are not truncated if configured max timeout is higher than the
+ // highest available timeout
+ assertThat(candidates.size()).isEqualTo(TIMEOUT_VALUES.length);
+ }
+
+ @Test
+ public void getCandidates_configuredMaxTimeout_notSet_timeoutIsNotLimited() {
+ when(mContext.getSystemService(DevicePolicyManager.class)).thenCallRealMethod();
+ doThrow(new Resources.NotFoundException("Invalid resource")).when(mResources)
+ .getInteger(R.integer.config_max_screen_timeout);
+
+ List extends CandidateInfo> candidates = mSettings.getCandidates();
+
+ // Assert that candidates are not truncated if there is no configured max timeout
+ assertThat(candidates.size()).isEqualTo(TIMEOUT_VALUES.length);
+ }
+
@Test
public void setDefaultKey_controlCurrentScreenTimeout() {
mSettings.setDefaultKey(TIMEOUT_VALUES[0]);
diff --git a/tests/robotests/src/com/android/settings/wifi/WifiConfigController2Test.java b/tests/robotests/src/com/android/settings/wifi/WifiConfigController2Test.java
index 99b3acc0db2b38cff5070a837ff35df6e3b222c0..3112a4d0f36ff2c45e0642b86ad2c53cdbd223cf 100644
--- a/tests/robotests/src/com/android/settings/wifi/WifiConfigController2Test.java
+++ b/tests/robotests/src/com/android/settings/wifi/WifiConfigController2Test.java
@@ -193,52 +193,6 @@ public class WifiConfigController2Test {
.isEqualTo(View.GONE);
}
- @Test
- public void isSubmittable_longPsk_shouldReturnFalse() {
- createController(mWifiEntry, WifiConfigUiBase2.MODE_CONNECT, false);
- final TextView password = mView.findViewById(R.id.password);
- assertThat(password).isNotNull();
- password.setText(LONG_PSK);
- assertThat(mController.isSubmittable()).isFalse();
- }
-
- @Test
- public void isSubmittable_shortPsk_shouldReturnFalse() {
- createController(mWifiEntry, WifiConfigUiBase2.MODE_CONNECT, false);
- final TextView password = mView.findViewById(R.id.password);
- assertThat(password).isNotNull();
- password.setText(SHORT_PSK);
- assertThat(mController.isSubmittable()).isFalse();
- }
-
- @Test
- public void isSubmittable_goodPsk_shouldReturnTrue() {
- createController(mWifiEntry, WifiConfigUiBase2.MODE_CONNECT, false);
- final TextView password = mView.findViewById(R.id.password);
- assertThat(password).isNotNull();
- password.setText(GOOD_PSK);
- assertThat(mController.isSubmittable()).isTrue();
- }
-
- @Test
- public void isSubmittable_hexPsk_shouldReturnTrue() {
- createController(mWifiEntry, WifiConfigUiBase2.MODE_CONNECT, false);
- final TextView password = mView.findViewById(R.id.password);
- assertThat(password).isNotNull();
- password.setText(HEX_PSK);
- assertThat(mController.isSubmittable()).isTrue();
- }
-
- @Test
- public void isSubmittable_savedConfigZeroLengthPassword_shouldReturnTrue() {
- createController(mWifiEntry, WifiConfigUiBase2.MODE_CONNECT, false);
- final TextView password = mView.findViewById(R.id.password);
- assertThat(password).isNotNull();
- password.setText("");
- when(mWifiEntry.isSaved()).thenReturn(true);
- assertThat(mController.isSubmittable()).isTrue();
- }
-
@Test
public void isSubmittable_nullWifiEntry_noException() {
createController(null, WifiConfigUiBase2.MODE_CONNECT, false);
@@ -1039,24 +993,6 @@ public class WifiConfigController2Test {
verify(mController.mEapAnonymousView, never()).setText(any(String.class));
}
- @Test
- public void canFinish_ssidIsEmpty_returnFalse() {
- createController(null, WifiConfigUiBase2.MODE_CONNECT, false);
- TextView ssid = mView.findViewById(R.id.ssid);
- ssid.setText("");
-
- assertThat(mController.canFinish()).isFalse();
- }
-
- @Test
- public void canFinish_ssidIsGood_returnTrue() {
- createController(null, WifiConfigUiBase2.MODE_CONNECT, false);
- TextView ssid = mView.findViewById(R.id.ssid);
- ssid.setText(GOOD_SSID);
-
- assertThat(mController.canFinish()).isTrue();
- }
-
private void setUpModifyingSavedCertificateConfigController(String savedCaCertificate,
String savedUserCertificate) {
final WifiConfiguration mockWifiConfig = spy(new WifiConfiguration());
diff --git a/tests/robotests/src/com/android/settings/wifi/WifiDialogActivityTest.java b/tests/robotests/src/com/android/settings/wifi/WifiDialogActivityTest.java
index 159d97acd15c8af4443ac5c201c40b1dd73bbe6e..d1cbd0ee1b77482a2d3574052e5e87317e1128c1 100644
--- a/tests/robotests/src/com/android/settings/wifi/WifiDialogActivityTest.java
+++ b/tests/robotests/src/com/android/settings/wifi/WifiDialogActivityTest.java
@@ -349,14 +349,4 @@ public class WifiDialogActivityTest {
verify(mActivity).dismissDialog();
}
-
- @Test
- public void onDismiss_shouldSubmitBeforeFinish_callOnSubmit() {
- mActivity.mDialog = mWifiDialog;
- when(mWifiDialog.shouldSubmitBeforeFinish()).thenReturn(true);
-
- mActivity.onDismiss(mWifiDialog);
-
- verify(mActivity).onSubmit(mWifiDialog);
- }
}
diff --git a/tests/spa_unit/src/com/android/settings/network/telephony/CarrierConfigRepositoryTest.kt b/tests/spa_unit/src/com/android/settings/network/telephony/CarrierConfigRepositoryTest.kt
index 12bbcaf49e5efbb221e7b4848a4f26425e5bcb24..72d5aba806691bae466eea1761e8cdcd760fe74f 100644
--- a/tests/spa_unit/src/com/android/settings/network/telephony/CarrierConfigRepositoryTest.kt
+++ b/tests/spa_unit/src/com/android/settings/network/telephony/CarrierConfigRepositoryTest.kt
@@ -25,7 +25,6 @@ import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.kotlin.any
-import org.mockito.kotlin.anyVararg
import org.mockito.kotlin.doReturn
import org.mockito.kotlin.doThrow
import org.mockito.kotlin.eq
@@ -106,7 +105,7 @@ class CarrierConfigRepositoryTest {
@Test
fun transformConfig_managerThrowIllegalStateException_returnDefaultValue() {
mockCarrierConfigManager.stub {
- on { getConfigForSubId(any(), anyVararg()) } doThrow IllegalStateException()
+ on { getConfigForSubId(any(), any()) } doThrow IllegalStateException()
}
val carrierName =
@@ -132,7 +131,7 @@ class CarrierConfigRepositoryTest {
repository.transformConfig(SUB_ID) { getString(key) }
repository.transformConfig(SUB_ID) { getString(key) }
- verify(mockCarrierConfigManager, times(1)).getConfigForSubId(any(), anyVararg())
+ verify(mockCarrierConfigManager, times(1)).getConfigForSubId(any(), any())
}
@Test
diff --git a/tests/unit/src/com/android/settings/deviceinfo/TopLevelStoragePreferenceControllerTest.java b/tests/unit/src/com/android/settings/deviceinfo/TopLevelStoragePreferenceControllerTest.java
index 7b6eb5bf20cb42a1e54b23fa1b8b85f287212ca5..6318c9c69144c79e1ad5ec3ca5841b6a17e4709a 100644
--- a/tests/unit/src/com/android/settings/deviceinfo/TopLevelStoragePreferenceControllerTest.java
+++ b/tests/unit/src/com/android/settings/deviceinfo/TopLevelStoragePreferenceControllerTest.java
@@ -86,7 +86,7 @@ public class TopLevelStoragePreferenceControllerTest {
when(mController.getStorageManagerVolumeProvider())
.thenReturn(mStorageManagerVolumeProvider);
final String percentage = NumberFormat.getPercentInstance().format(1);
- final String[] freeSpace = Formatter.formatFileSize(mContext, 0).split("\\s");
+ final String freeSpace = Formatter.formatFileSize(mContext, 0);
final Preference preference = new Preference(mContext);
// Wait for asynchronous thread to finish, otherwise test will flake.
@@ -103,6 +103,6 @@ public class TopLevelStoragePreferenceControllerTest {
// the background thread.
TimeUnit.SECONDS.sleep(5);
assertThat(preference.getSummary()).isEqualTo(ResourcesUtils.getResourcesString(
- mContext, "storage_summary", percentage, freeSpace[0], freeSpace[1]));
+ mContext, "storage_summary", percentage, freeSpace));
}
}
diff --git a/tests/unit/src/com/android/settings/display/ScreenResolutionFragmentTest.java b/tests/unit/src/com/android/settings/display/ScreenResolutionFragmentTest.java
index 84095317e175fb4303bb8ceae1def3c5bea68142..8a8a681c884a9920c4b179ab4d6a8d98bd45417f 100644
--- a/tests/unit/src/com/android/settings/display/ScreenResolutionFragmentTest.java
+++ b/tests/unit/src/com/android/settings/display/ScreenResolutionFragmentTest.java
@@ -110,4 +110,28 @@ public class ScreenResolutionFragmentTest {
assertThat(preference.getSummary().toString().contentEquals(summary)).isTrue();
}
+
+ @Test
+ public void testResolutionString_widthAndHeightAboveThreshold() {
+ String result = ScreenResolutionFragment.getResolutionString(1080, 1280);
+ assertThat(result).isEqualTo("1\u00A0080\u00A0x\u00A01\u00A0280");
+ }
+
+ @Test
+ public void testResolutionString_widthAboveThreshold_heightBelowThreshold() {
+ String result = ScreenResolutionFragment.getResolutionString(1080, 980);
+ assertThat(result).isEqualTo("1\u00A0080\u00A0x\u00A0980");
+ }
+
+ @Test
+ public void testResolutionString_widthBelowThreshold_heightBelowThreshold() {
+ String result = ScreenResolutionFragment.getResolutionString(980, 980);
+ assertThat(result).isEqualTo("980\u00A0x\u00A0980");
+ }
+
+ @Test
+ public void testResolutionString_widthBelowThreshold_heightAboveThreshold() {
+ String result = ScreenResolutionFragment.getResolutionString(980, 1080);
+ assertThat(result).isEqualTo("980\u00A0x\u00A01\u00A0080");
+ }
}
diff --git a/tests/unit/src/com/android/settings/network/telephony/Enable2gPreferenceControllerTest.java b/tests/unit/src/com/android/settings/network/telephony/Enable2gPreferenceControllerTest.java
index 962a33b07aed2cc88fb3836225e377974f41e349..4b83bc72203b3c7b4777a4d454d3f655d2d730a1 100644
--- a/tests/unit/src/com/android/settings/network/telephony/Enable2gPreferenceControllerTest.java
+++ b/tests/unit/src/com/android/settings/network/telephony/Enable2gPreferenceControllerTest.java
@@ -147,7 +147,7 @@ public final class Enable2gPreferenceControllerTest {
when2gIsEnabledForReasonEnable2g();
// Disable 2G
- boolean changed = mController.setChecked(false);
+ boolean changed = mController.setChecked(true);
assertThat(changed).isEqualTo(true);
verify(mTelephonyManager, times(1)).setAllowedNetworkTypesForReason(
@@ -159,7 +159,7 @@ public final class Enable2gPreferenceControllerTest {
public void disabledByAdmin_toggleUnchecked() {
when2gIsEnabledForReasonEnable2g();
when2gIsDisabledByAdmin(true);
- assertThat(mController.isChecked()).isFalse();
+ assertThat(mController.isChecked()).isTrue();
}
@Test
@@ -167,15 +167,15 @@ public final class Enable2gPreferenceControllerTest {
// Initially, 2g is enabled
when2gIsEnabledForReasonEnable2g();
when2gIsDisabledByAdmin(false);
- assertThat(mController.isChecked()).isTrue();
+ assertThat(mController.isChecked()).isFalse();
// When we disable the preference by an admin, the preference should be unchecked
when2gIsDisabledByAdmin(true);
- assertThat(mController.isChecked()).isFalse();
+ assertThat(mController.isChecked()).isTrue();
// If the preference is re-enabled by an admin, former state should hold
when2gIsDisabledByAdmin(false);
- assertThat(mController.isChecked()).isTrue();
+ assertThat(mController.isChecked()).isFalse();
}
@Test
diff --git a/tests/unit/src/com/android/settings/network/telephony/SatelliteAppListCategoryControllerTest.java b/tests/unit/src/com/android/settings/network/telephony/satellite/SatelliteAppListCategoryControllerTest.java
similarity index 96%
rename from tests/unit/src/com/android/settings/network/telephony/SatelliteAppListCategoryControllerTest.java
rename to tests/unit/src/com/android/settings/network/telephony/satellite/SatelliteAppListCategoryControllerTest.java
index 74797ae69d33e1c72afc297e60eff406d7b21c1e..56d4b9fe1838056976875baccc187416c192f9df 100644
--- a/tests/unit/src/com/android/settings/network/telephony/SatelliteAppListCategoryControllerTest.java
+++ b/tests/unit/src/com/android/settings/network/telephony/satellite/SatelliteAppListCategoryControllerTest.java
@@ -14,11 +14,11 @@
* limitations under the License.
*/
-package com.android.settings.network.telephony;
+package com.android.settings.network.telephony.satellite;
import static com.android.settings.core.BasePreferenceController.AVAILABLE;
import static com.android.settings.core.BasePreferenceController.CONDITIONALLY_UNAVAILABLE;
-import static com.android.settings.network.telephony.SatelliteAppListCategoryController.MAXIMUM_OF_PREFERENCE_AMOUNT;
+import static com.android.settings.network.telephony.satellite.SatelliteAppListCategoryController.MAXIMUM_OF_PREFERENCE_AMOUNT;
import static com.google.common.truth.Truth.assertThat;
diff --git a/tests/unit/src/com/android/settings/network/telephony/SatelliteAppListFragmentTest.java b/tests/unit/src/com/android/settings/network/telephony/satellite/SatelliteAppListFragmentTest.java
similarity index 98%
rename from tests/unit/src/com/android/settings/network/telephony/SatelliteAppListFragmentTest.java
rename to tests/unit/src/com/android/settings/network/telephony/satellite/SatelliteAppListFragmentTest.java
index ba91d179f99ebbd6ed0874010bd466c99281a61e..7ed0f72acfc7bef1eaf4c650cb6f0446f9215881 100644
--- a/tests/unit/src/com/android/settings/network/telephony/SatelliteAppListFragmentTest.java
+++ b/tests/unit/src/com/android/settings/network/telephony/satellite/SatelliteAppListFragmentTest.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package com.android.settings.network.telephony;
+package com.android.settings.network.telephony.satellite;
import static com.google.common.truth.Truth.assertThat;
diff --git a/tests/unit/src/com/android/settings/network/telephony/satellite/SatelliteSettingAboutContentControllerTest.kt b/tests/unit/src/com/android/settings/network/telephony/satellite/SatelliteSettingAboutContentControllerTest.kt
new file mode 100644
index 0000000000000000000000000000000000000000..d070811c3b9ed3f9b401b3ce98c62a46be931b83
--- /dev/null
+++ b/tests/unit/src/com/android/settings/network/telephony/satellite/SatelliteSettingAboutContentControllerTest.kt
@@ -0,0 +1,77 @@
+/*
+ * Copyright (C) 2025 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.network.telephony.satellite
+
+import android.content.Context
+import android.telephony.TelephonyManager
+import androidx.preference.PreferenceManager
+import androidx.preference.PreferenceScreen
+import androidx.test.core.app.ApplicationProvider
+import com.android.settings.R
+import com.android.settings.network.telephony.satellite.SatelliteSettingAboutContentController.Companion.PREF_KEY_ABOUT_SATELLITE_CONNECTIVITY
+import com.android.settingslib.widget.TopIntroPreference
+import com.google.common.truth.Truth.assertThat
+import org.junit.Before
+import org.junit.Test
+import org.mockito.kotlin.doReturn
+import org.mockito.kotlin.mock
+import org.mockito.kotlin.spy
+
+class SatelliteSettingAboutContentControllerTest {
+ private val mockTelephonyManager: TelephonyManager = mock {
+ on { getSimOperatorName(TEST_SUB_ID) } doReturn TEST_SIM_OPERATOR_NAME
+ }
+
+ private var context: Context = spy(ApplicationProvider.getApplicationContext()) {
+ on { getSystemService(TelephonyManager::class.java) } doReturn mockTelephonyManager
+ }
+
+ private val controller = SatelliteSettingAboutContentController(
+ context = context,
+ key = PREF_KEY_ABOUT_SATELLITE_CONNECTIVITY,
+ )
+
+ private lateinit var screen: PreferenceScreen
+ private lateinit var preference: TopIntroPreference
+
+ @Before
+ fun setUp() {
+ preference =
+ TopIntroPreference(context).apply { key = PREF_KEY_ABOUT_SATELLITE_CONNECTIVITY }
+ screen = PreferenceManager(context).createPreferenceScreen(context)
+ screen.addPreference(preference)
+ }
+
+ @Test
+ fun displayPreference_preferenceTitle_hasSimOperatorName() {
+ controller.init(TEST_SUB_ID)
+
+ controller.displayPreference(screen)
+
+ assertThat(preference.title).isEqualTo(
+ context.getString(
+ R.string.description_about_satellite_setting,
+ TEST_SIM_OPERATOR_NAME
+ )
+ )
+ }
+
+ private companion object {
+ const val TEST_SUB_ID = 1
+ const val TEST_SIM_OPERATOR_NAME = "Test Carrier"
+ }
+}
\ No newline at end of file
diff --git a/tests/unit/src/com/android/settings/network/telephony/SatelliteSettingsPreferenceCategoryControllerTest.java b/tests/unit/src/com/android/settings/network/telephony/satellite/SatelliteSettingsPreferenceCategoryControllerTest.java
similarity index 98%
rename from tests/unit/src/com/android/settings/network/telephony/SatelliteSettingsPreferenceCategoryControllerTest.java
rename to tests/unit/src/com/android/settings/network/telephony/satellite/SatelliteSettingsPreferenceCategoryControllerTest.java
index f9c0f16ac9f339658ef528e249bfa28ba0f56c91..ef44b928afeb22cf7c479569cc282e53eac0ddbe 100644
--- a/tests/unit/src/com/android/settings/network/telephony/SatelliteSettingsPreferenceCategoryControllerTest.java
+++ b/tests/unit/src/com/android/settings/network/telephony/satellite/SatelliteSettingsPreferenceCategoryControllerTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2024 The Android Open Source Project
+ * Copyright (C) 2025 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package com.android.settings.network.telephony;
+package com.android.settings.network.telephony.satellite;
import static android.telephony.CarrierConfigManager.CARRIER_ROAMING_NTN_CONNECT_AUTOMATIC;
import static android.telephony.CarrierConfigManager.CARRIER_ROAMING_NTN_CONNECT_MANUAL;
diff --git a/tests/unit/src/com/android/settings/network/telephony/SatelliteSettingsPreferenceControllerTest.java b/tests/unit/src/com/android/settings/network/telephony/satellite/SatelliteSettingsPreferenceControllerTest.java
similarity index 99%
rename from tests/unit/src/com/android/settings/network/telephony/SatelliteSettingsPreferenceControllerTest.java
rename to tests/unit/src/com/android/settings/network/telephony/satellite/SatelliteSettingsPreferenceControllerTest.java
index 16a22cdb937874f792f33aa445aa2d28310e0a40..c67f0aca6a173171de5cbf87b93d1e5539dd40f3 100644
--- a/tests/unit/src/com/android/settings/network/telephony/SatelliteSettingsPreferenceControllerTest.java
+++ b/tests/unit/src/com/android/settings/network/telephony/satellite/SatelliteSettingsPreferenceControllerTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2024 The Android Open Source Project
+ * Copyright (C) 2025 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package com.android.settings.network.telephony;
+package com.android.settings.network.telephony.satellite;
import static android.telephony.CarrierConfigManager.CARRIER_ROAMING_NTN_CONNECT_AUTOMATIC;
import static android.telephony.CarrierConfigManager.CARRIER_ROAMING_NTN_CONNECT_MANUAL;
diff --git a/tests/unit/src/com/android/settings/wifi/tether/WifiHotspotSwitchPreferenceTest.kt b/tests/unit/src/com/android/settings/wifi/tether/WifiHotspotSwitchPreferenceTest.kt
index fad8025d71b8718a258d9309a6a55719a564d204..5ef0097508405b50f7cb0b6b9911457c5c25dcfa 100644
--- a/tests/unit/src/com/android/settings/wifi/tether/WifiHotspotSwitchPreferenceTest.kt
+++ b/tests/unit/src/com/android/settings/wifi/tether/WifiHotspotSwitchPreferenceTest.kt
@@ -30,7 +30,7 @@ import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.ArgumentMatchers.eq
import org.mockito.Mockito.verify
-import org.mockito.kotlin.anyVararg
+import org.mockito.kotlin.any
import org.mockito.kotlin.doReturn
import org.mockito.kotlin.mock
import org.mockito.kotlin.stub
@@ -77,7 +77,7 @@ class WifiHotspotSwitchPreferenceTest {
fun setValue_valueOn_startTethering() {
preference.storage(context).setBoolean(WifiHotspotSwitchPreference.KEY, true)
- verify(mockTetheringManager).startTethering(eq(TETHERING_WIFI), anyVararg(), anyVararg())
+ verify(mockTetheringManager).startTethering(eq(TETHERING_WIFI), any(), any())
}
@Test