Merge changes If4a471e2,I5ed1713d into main
* changes:
[Temp bonding] Clean up old guest device logic as requirements changed
[Temp bonding] Move audio sharing settings up
diff --git a/res/drawable-v35/expressive_battery_hints_chip_bg.xml b/res/drawable-v35/expressive_battery_hints_chip_bg.xml
new file mode 100644
index 0000000..86e9f6a
--- /dev/null
+++ b/res/drawable-v35/expressive_battery_hints_chip_bg.xml
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ ~ 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.
+ -->
+
+<shape xmlns:android="http://schemas.android.com/apk/res/android"
+ android:shape="rectangle">
+ <corners android:radius="@dimen/settingslib_expressive_radius_medium" />
+ <stroke android:width="1dp" android:color="@color/settingslib_materialColorOutline" />
+</shape>
\ No newline at end of file
diff --git a/res/drawable-v35/expressive_battery_hints_chip_bg_ripple.xml b/res/drawable-v35/expressive_battery_hints_chip_bg_ripple.xml
new file mode 100644
index 0000000..542a40c
--- /dev/null
+++ b/res/drawable-v35/expressive_battery_hints_chip_bg_ripple.xml
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ ~ 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.
+ -->
+
+<ripple xmlns:android="http://schemas.android.com/apk/res/android"
+ android:color="?android:attr/colorControlHighlight">
+ <item android:drawable="@drawable/expressive_battery_hints_chip_bg"/>
+</ripple>
\ No newline at end of file
diff --git a/res/layout-v35/expressive_warning_frame_preference.xml b/res/layout-v35/expressive_warning_frame_preference.xml
new file mode 100644
index 0000000..ba11044
--- /dev/null
+++ b/res/layout-v35/expressive_warning_frame_preference.xml
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="UTF-8"?><!--
+ ~ 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.
+ -->
+
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:minHeight="?android:attr/listPreferredItemHeightSmall"
+ android:orientation="vertical">
+
+ <include layout="@layout/settingslib_expressive_preference"
+ android:id="@+id/preference_frame"/>
+
+ <LinearLayout
+ android:id="@+id/warning_chip_frame"
+ android:visibility="gone"
+ android:clickable="false"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_marginBottom="@dimen/settingslib_expressive_space_small1"
+ android:layout_marginTop="-8dp">
+ <Space
+ android:id="@+id/warning_padding_placeholder"
+ android:layout_width="@dimen/settingslib_expressive_space_medium3"
+ android:layout_height="1px"
+ android:layout_marginEnd="@dimen/settingslib_expressive_space_extrasmall6"/>
+
+ <include layout="@layout/power_anomaly_hints"/>
+ </LinearLayout>
+
+</LinearLayout>
\ No newline at end of file
diff --git a/res/layout/locale_order_list.xml b/res/layout/locale_order_list.xml
index da1eb62..36bb06d 100644
--- a/res/layout/locale_order_list.xml
+++ b/res/layout/locale_order_list.xml
@@ -44,7 +44,8 @@
android:textAlignment="textStart"
android:text="@string/add_a_language"
style="@style/Base.Widget.AppCompat.Button.Borderless"
- android:textAppearance="?android:attr/textAppearanceListItem"/>
+ android:textAppearance="?android:attr/textAppearanceListItem"
+ android:visibility="gone"/>
</LinearLayout>
diff --git a/res/layout/power_anomaly_hints.xml b/res/layout/power_anomaly_hints.xml
index 7ee419e..9498523 100644
--- a/res/layout/power_anomaly_hints.xml
+++ b/res/layout/power_anomaly_hints.xml
@@ -17,13 +17,12 @@
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:androidprv="http://schemas.android.com/apk/prv/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center_vertical|start"
- android:padding="8dp"
- android:background="@drawable/battery_hints_chip_bg_ripple">
+ android:id="@+id/warning_chip"
+ android:padding="8dp">
<ImageView
android:layout_width="16dp"
diff --git a/res/layout/power_usage_time.xml b/res/layout/power_usage_time.xml
deleted file mode 100644
index bad68f4..0000000
--- a/res/layout/power_usage_time.xml
+++ /dev/null
@@ -1,49 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
- Copyright (C) 2023 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.
--->
-
-<LinearLayout
- xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:paddingStart="?android:attr/listPreferredItemPaddingStart"
- android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
- android:orientation="vertical">
-
- <TextView
- android:id="@+id/time_title"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:paddingTop="20dp"
- android:textAlignment="viewStart"
- android:textAppearance="?android:attr/textAppearanceLarge"
- android:textColor="?android:attr/textColorPrimary" />
-
- <TextView
- android:id="@+id/time_summary"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_marginVertical="4dp"
- android:textAlignment="viewStart"
- android:textAppearance="?android:attr/textAppearanceSmall"
- android:textColor="?android:attr/textColorSecondary" />
-
- <include layout="@layout/power_anomaly_hints"
- android:visibility="gone"
- android:id="@+id/anomaly_hints"
- android:paddingBottom="20dp"/>
-
-</LinearLayout>
\ No newline at end of file
diff --git a/res/layout/preference_volume_slider.xml b/res/layout/preference_volume_slider.xml
index 50095f4..1d9a848 100644
--- a/res/layout/preference_volume_slider.xml
+++ b/res/layout/preference_volume_slider.xml
@@ -66,6 +66,8 @@
android:layout_gravity="center_vertical"
android:paddingStart="0dp"
android:paddingEnd="12dp"
+ android:progressBackgroundTint="@color/settingslib_materialColorOutline"
+ android:progressTint="@color/settingslib_materialColorPrimaryFixed"
android:layout_width="match_parent"
android:layout_height="48dp"/>
diff --git a/res/layout/anomaly_app_item_preference.xml b/res/layout/warning_frame_preference.xml
similarity index 88%
rename from res/layout/anomaly_app_item_preference.xml
rename to res/layout/warning_frame_preference.xml
index 681fe68..4e624ce 100644
--- a/res/layout/anomaly_app_item_preference.xml
+++ b/res/layout/warning_frame_preference.xml
@@ -22,7 +22,7 @@
<include layout="@layout/preference_app"/>
<LinearLayout
- android:id="@+id/warning_chip"
+ android:id="@+id/warning_chip_frame"
android:visibility="gone"
android:clickable="false"
android:layout_width="match_parent"
@@ -32,13 +32,12 @@
android:orientation="horizontal"
android:paddingStart="?android:attr/listPreferredItemPaddingStart"
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd">
-
<Space
+ android:id="@+id/warning_padding_placeholder"
android:layout_width="@dimen/secondary_app_icon_size"
- android:layout_height="wrap_content"
+ android:layout_height="1px"
android:layout_marginEnd="16dp"/>
- <include layout="@layout/power_anomaly_hints" />
-
+ <include layout="@layout/power_anomaly_hints"/>
</LinearLayout>
</LinearLayout>
\ No newline at end of file
diff --git a/res/values/strings.xml b/res/values/strings.xml
index c6b8210..6f328a3 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -13973,13 +13973,15 @@
<string name="audio_sharing_share_with_button_label">Share with <xliff:g example="My buds" id="device_name">%1$s</xliff:g></string>
<!-- Text for audio sharing close button [CHAR LIMIT=none]-->
<string name="audio_sharing_close_button_label">Close</string>
- <!-- Content for audio sharing share dialog with no device, ask users to connect device [CHAR LIMIT=none]-->
+ <!-- Content for audio sharing share dialog with no second device, ask users to connect device [CHAR LIMIT=none]-->
<string name="audio_sharing_dialog_connect_device_content">Connect another pair of compatible headphones, or share your stream\'s name and password with the other person</string>
- <!-- Content for audio sharing share dialog with no device, ask users to scan qr code [CHAR LIMIT=none]-->
+ <!-- Content for audio sharing share dialog with no second device, ask users to scan qr code [CHAR LIMIT=none]-->
<string name="audio_sharing_dialog_qr_code_content">Let others scan this code and listen to your audio\n\nStream name: <xliff:g example="Pixel 8" id="stream_name">%1$s</xliff:g>\nPassword: <xliff:g example="123456" id="password">%2$s</xliff:g></string>
- <!-- Content for audio sharing share dialog with no device, ask users to pair new device [CHAR LIMIT=none]-->
+ <!-- Content for audio sharing share dialog with no second device and no password, ask users to scan qr code [CHAR LIMIT=none]-->
+ <string name="audio_sharing_dialog_qr_code_content_no_password">Let others scan this code and listen to your audio\n\nStream name: <xliff:g example="Pixel 8" id="stream_name">%1$s</xliff:g></string>
+ <!-- Content for audio sharing share dialog with no second device, ask users to pair new device [CHAR LIMIT=none]-->
<string name="audio_sharing_dialog_pair_new_device_content">or pair another set of compatible headphones</string>
- <!-- Content for audio sharing share dialog with no device, ask users to pair device [CHAR LIMIT=none]-->
+ <!-- Content for audio sharing share dialog with no second device, ask users to pair device [CHAR LIMIT=none]-->
<string name="audio_sharing_dialog_pair_device_content">Pair another set of compatible headphones, or share your audio stream QR code with the other person</string>
<!-- Text for sharing audio sharing state [CHAR LIMIT=none]-->
<string name="audio_sharing_sharing_label">Sharing audio</string>
diff --git a/res/xml/languages.xml b/res/xml/languages.xml
index d478aa1..1fb6368 100644
--- a/res/xml/languages.xml
+++ b/res/xml/languages.xml
@@ -31,6 +31,13 @@
<com.android.settingslib.widget.LayoutPreference
android:key="languages_picker"
android:layout="@layout/locale_order_list" />
+
+ <Preference
+ android:key="add_a_language"
+ android:title="@string/add_a_language"
+ android:icon="@drawable/ic_add_24dp"
+ settings:isPreferenceVisible="false"
+ settings:fragment="com.android.settings.localepicker.SystemLocalePickerFragment"/>
</PreferenceCategory>
<PreferenceCategory
diff --git a/src/com/android/settings/connecteddevice/audiosharing/AudioSharingDialogFragment.java b/src/com/android/settings/connecteddevice/audiosharing/AudioSharingDialogFragment.java
index cf71d5f..14a5590 100644
--- a/src/com/android/settings/connecteddevice/audiosharing/AudioSharingDialogFragment.java
+++ b/src/com/android/settings/connecteddevice/audiosharing/AudioSharingDialogFragment.java
@@ -186,14 +186,17 @@
Drawable qrCodeDrawable = metadata == null ? null : getQrCodeDrawable(metadata,
getContext()).orElse(null);
if (qrCodeDrawable != null) {
+ String broadcastName =
+ metadata.getBroadcastName() == null ? "" : metadata.getBroadcastName();
+ boolean hasPassword = metadata.getBroadcastCode() != null
+ && metadata.getBroadcastCode().length > 0;
+ String message = hasPassword ? getString(
+ R.string.audio_sharing_dialog_qr_code_content, broadcastName,
+ new String(metadata.getBroadcastCode(), StandardCharsets.UTF_8)) :
+ getString(R.string.audio_sharing_dialog_qr_code_content_no_password,
+ broadcastName);
builder.setCustomImage(qrCodeDrawable)
- .setCustomMessage(
- getString(
- R.string.audio_sharing_dialog_qr_code_content,
- metadata.getBroadcastName(),
- new String(
- metadata.getBroadcastCode(),
- StandardCharsets.UTF_8)))
+ .setCustomMessage(message)
.setCustomMessage2(R.string.audio_sharing_dialog_pair_new_device_content)
.setCustomNegativeButton(R.string.audio_streams_dialog_close,
v -> onCancelClick());
diff --git a/src/com/android/settings/development/DesktopExperiencePreferenceController.java b/src/com/android/settings/development/DesktopExperiencePreferenceController.java
index f6173a9..28e92fc 100644
--- a/src/com/android/settings/development/DesktopExperiencePreferenceController.java
+++ b/src/com/android/settings/development/DesktopExperiencePreferenceController.java
@@ -98,7 +98,7 @@
@Override
public CharSequence getSummary() {
- if (DesktopModeStatus.isInternalDisplayEligibleToHostDesktops(mContext)
+ if (DesktopModeStatus.isDeviceEligibleForDesktopMode(mContext)
&& !DesktopModeFlags.ENABLE_DESKTOP_WINDOWING_MODE.isTrue()) {
return mContext.getString(
R.string.enable_desktop_experience_features_summary_with_desktop);
diff --git a/src/com/android/settings/deviceinfo/PhoneNumberPreferenceController.java b/src/com/android/settings/deviceinfo/PhoneNumberPreferenceController.java
index 421963e..b49d62d 100644
--- a/src/com/android/settings/deviceinfo/PhoneNumberPreferenceController.java
+++ b/src/com/android/settings/deviceinfo/PhoneNumberPreferenceController.java
@@ -17,6 +17,7 @@
package com.android.settings.deviceinfo;
import android.content.Context;
+import android.os.UserManager;
import android.telephony.SubscriptionInfo;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
@@ -30,6 +31,7 @@
import com.android.settings.R;
import com.android.settings.core.BasePreferenceController;
import com.android.settings.network.SubscriptionUtil;
+import com.android.settingslib.Utils;
import java.util.ArrayList;
import java.util.List;
@@ -51,8 +53,13 @@
@Override
public int getAvailabilityStatus() {
- return SubscriptionUtil.isSimHardwareVisible(mContext) ?
- AVAILABLE : UNSUPPORTED_ON_DEVICE;
+ if (!SubscriptionUtil.isSimHardwareVisible(mContext) || Utils.isWifiOnly(mContext)) {
+ return UNSUPPORTED_ON_DEVICE;
+ }
+ if (!mContext.getSystemService(UserManager.class).isAdminUser()) {
+ return DISABLED_FOR_USER;
+ }
+ return AVAILABLE;
}
@Override
diff --git a/src/com/android/settings/fuelgauge/PowerUsageTimeController.java b/src/com/android/settings/fuelgauge/PowerUsageTimeController.java
index 0dfdd5d..e01a95c 100644
--- a/src/com/android/settings/fuelgauge/PowerUsageTimeController.java
+++ b/src/com/android/settings/fuelgauge/PowerUsageTimeController.java
@@ -93,10 +93,10 @@
|| (summaryTimeMs == 0 && !TextUtils.equals(anomalyHintKey, preference.getKey()))) {
return false;
}
- preference.setTimeTitle(mContext.getString(titleResId));
- preference.setTimeSummary(getPowerUsageTimeInfo(summaryTimeMs));
+ preference.setTitle(mContext.getString(titleResId));
+ preference.setSummary(getPowerUsageTimeInfo(summaryTimeMs));
if (TextUtils.equals(anomalyHintKey, preference.getKey())) {
- preference.setAnomalyHint(anomalyHintText);
+ preference.setHint(anomalyHintText);
}
preference.setVisible(true);
return true;
diff --git a/src/com/android/settings/fuelgauge/PowerUsageTimePreference.java b/src/com/android/settings/fuelgauge/PowerUsageTimePreference.java
index 16c7770..d2f39ff 100644
--- a/src/com/android/settings/fuelgauge/PowerUsageTimePreference.java
+++ b/src/com/android/settings/fuelgauge/PowerUsageTimePreference.java
@@ -17,74 +17,17 @@
package com.android.settings.fuelgauge;
import android.content.Context;
-import android.text.TextUtils;
import android.util.AttributeSet;
-import android.view.View;
-import android.widget.TextView;
-import androidx.annotation.VisibleForTesting;
-import androidx.preference.Preference;
-import androidx.preference.PreferenceViewHolder;
-
-import com.android.settings.R;
+import com.android.settingslib.widget.GroupSectionDividerMixin;
/** Custom preference for displaying the app power usage time. */
-public class PowerUsageTimePreference extends Preference {
+public class PowerUsageTimePreference extends WarningFramePreference implements
+ GroupSectionDividerMixin {
private static final String TAG = "PowerUsageTimePreference";
- @VisibleForTesting CharSequence mTimeTitle;
- @VisibleForTesting CharSequence mTimeSummary;
- @VisibleForTesting CharSequence mAnomalyHintText;
-
public PowerUsageTimePreference(Context context, AttributeSet attrs) {
super(context, attrs);
- setLayoutResource(R.layout.power_usage_time);
- }
-
- void setTimeTitle(CharSequence timeTitle) {
- if (!TextUtils.equals(mTimeTitle, timeTitle)) {
- mTimeTitle = timeTitle;
- notifyChanged();
- }
- }
-
- void setTimeSummary(CharSequence timeSummary) {
- if (!TextUtils.equals(mTimeSummary, timeSummary)) {
- mTimeSummary = timeSummary;
- notifyChanged();
- }
- }
-
- void setAnomalyHint(CharSequence anomalyHintText) {
- if (!TextUtils.equals(mAnomalyHintText, anomalyHintText)) {
- mAnomalyHintText = anomalyHintText;
- notifyChanged();
- }
- }
-
- private void showAnomalyHint(PreferenceViewHolder view) {
- if (TextUtils.isEmpty(mAnomalyHintText)) {
- return;
- }
- final View anomalyHintView = view.findViewById(R.id.anomaly_hints);
- if (anomalyHintView == null) {
- return;
- }
- final TextView warningInfo = anomalyHintView.findViewById(R.id.warning_info);
- if (warningInfo == null) {
- return;
- }
- warningInfo.setText(mAnomalyHintText);
- anomalyHintView.setVisibility(View.VISIBLE);
- }
-
- @Override
- public void onBindViewHolder(PreferenceViewHolder view) {
- super.onBindViewHolder(view);
-
- ((TextView) view.findViewById(R.id.time_title)).setText(mTimeTitle);
- ((TextView) view.findViewById(R.id.time_summary)).setText(mTimeSummary);
-
- showAnomalyHint(view);
+ setSelectable(false);
}
}
diff --git a/src/com/android/settings/fuelgauge/WarningFramePreference.java b/src/com/android/settings/fuelgauge/WarningFramePreference.java
new file mode 100644
index 0000000..fef03a5
--- /dev/null
+++ b/src/com/android/settings/fuelgauge/WarningFramePreference.java
@@ -0,0 +1,97 @@
+/*
+ * 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.fuelgauge;
+
+import android.annotation.Nullable;
+import android.content.Context;
+import android.text.TextUtils;
+import android.util.AttributeSet;
+import android.view.View;
+import android.widget.TextView;
+
+import androidx.preference.Preference;
+import androidx.preference.PreferenceViewHolder;
+
+import com.android.settings.R;
+import com.android.settingslib.Utils;
+import com.android.settingslib.widget.SettingsThemeHelper;
+
+/**
+ * Custom preference for displaying the {@link Preference} with an optional hint chip.
+ */
+public class WarningFramePreference extends Preference {
+ private final int mTitleColorNormal;
+ private final int mSummaryColorNormal;
+ private final int mWarningChipBackgroundResId;
+ private final boolean mIsExpressiveTheme;
+
+ @Nullable private CharSequence mHintText;
+
+ public WarningFramePreference(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ mIsExpressiveTheme = SettingsThemeHelper.isExpressiveTheme(context);
+ int layoutResId =
+ mIsExpressiveTheme
+ ? R.layout.expressive_warning_frame_preference
+ : R.layout.warning_frame_preference;
+ setLayoutResource(layoutResId);
+ mWarningChipBackgroundResId =
+ mIsExpressiveTheme
+ ? R.drawable.expressive_battery_hints_chip_bg_ripple
+ : R.drawable.battery_hints_chip_bg_ripple;
+ mTitleColorNormal =
+ Utils.getColorAttrDefaultColor(context, android.R.attr.textColorPrimary);
+ mSummaryColorNormal =
+ Utils.getColorAttrDefaultColor(context, android.R.attr.textColorSecondary);
+ }
+
+ /** Sets the text of hint to show. */
+ public void setHint(@Nullable CharSequence hintText) {
+ if (!TextUtils.equals(mHintText, hintText)) {
+ mHintText = hintText;
+ notifyChanged();
+ }
+ }
+
+ @Override
+ public void onBindViewHolder(PreferenceViewHolder view) {
+ super.onBindViewHolder(view);
+
+ if (mIsExpressiveTheme) {
+ final View preferenceFrame = view.findViewById(R.id.preference_frame);
+ preferenceFrame.setBackground(null);
+ preferenceFrame.setPadding(0, 0, 0, 0);
+ }
+
+ final View warningChipFrame = view.findViewById(R.id.warning_chip_frame);
+ warningChipFrame
+ .findViewById(R.id.warning_padding_placeholder)
+ .setVisibility(getIcon() != null ? View.VISIBLE : View.GONE);
+ if (!TextUtils.isEmpty(mHintText)) {
+ ((TextView) warningChipFrame.findViewById(R.id.warning_info)).setText(mHintText);
+ warningChipFrame.setVisibility(View.VISIBLE);
+ warningChipFrame
+ .findViewById(R.id.warning_chip)
+ .setBackgroundResource(mWarningChipBackgroundResId);
+ } else {
+ warningChipFrame.setVisibility(View.GONE);
+ }
+ ((TextView) view.findViewById(android.R.id.title)).setTextColor(mTitleColorNormal);
+ ((TextView) view.findViewById(android.R.id.summary)).setTextColor(mSummaryColorNormal);
+ }
+}
+
diff --git a/src/com/android/settings/fuelgauge/batteryusage/AnomalyAppItemPreference.java b/src/com/android/settings/fuelgauge/batteryusage/AnomalyAppItemPreference.java
deleted file mode 100644
index 592d308..0000000
--- a/src/com/android/settings/fuelgauge/batteryusage/AnomalyAppItemPreference.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * Copyright (C) 2023 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.fuelgauge.batteryusage;
-
-import android.annotation.Nullable;
-import android.content.Context;
-import android.text.TextUtils;
-import android.view.View;
-import android.widget.LinearLayout;
-import android.widget.TextView;
-
-import androidx.preference.PreferenceViewHolder;
-
-import com.android.settings.R;
-
-class AnomalyAppItemPreference extends PowerGaugePreference {
-
- private static final String TAG = "AnomalyAppItemPreference";
-
- private CharSequence mAnomalyHintText;
-
- AnomalyAppItemPreference(Context context) {
- super(context, /* attrs */ null);
- setLayoutResource(R.layout.anomaly_app_item_preference);
- }
-
- void setAnomalyHint(@Nullable CharSequence anomalyHintText) {
- if (!TextUtils.equals(mAnomalyHintText, anomalyHintText)) {
- mAnomalyHintText = anomalyHintText;
- notifyChanged();
- }
- }
-
- @Override
- public void onBindViewHolder(PreferenceViewHolder viewHolder) {
- super.onBindViewHolder(viewHolder);
- final LinearLayout warningChipView =
- (LinearLayout) viewHolder.findViewById(R.id.warning_chip);
-
- if (!TextUtils.isEmpty(mAnomalyHintText)) {
- ((TextView) warningChipView.findViewById(R.id.warning_info)).setText(mAnomalyHintText);
- warningChipView.setVisibility(View.VISIBLE);
- } else {
- warningChipView.setVisibility(View.GONE);
- }
- }
-}
diff --git a/src/com/android/settings/fuelgauge/batteryusage/BatteryUsageBreakdownController.java b/src/com/android/settings/fuelgauge/batteryusage/BatteryUsageBreakdownController.java
index 6fd4eb5..280fa18 100644
--- a/src/com/android/settings/fuelgauge/batteryusage/BatteryUsageBreakdownController.java
+++ b/src/com/android/settings/fuelgauge/batteryusage/BatteryUsageBreakdownController.java
@@ -381,15 +381,15 @@
continue;
}
final String prefKey = entry.getKey();
- AnomalyAppItemPreference preference = mRootPreferenceGroup.findPreference(prefKey);
+ PowerGaugePreference preference = mRootPreferenceGroup.findPreference(prefKey);
if (preference != null) {
isAdded = true;
} else {
- preference = (AnomalyAppItemPreference) mPreferenceCache.get(prefKey);
+ preference = (PowerGaugePreference) mPreferenceCache.get(prefKey);
}
// Creates new instance if cached preference is not found.
if (preference == null) {
- preference = new AnomalyAppItemPreference(mPrefContext);
+ preference = new PowerGaugePreference(mPrefContext);
preference.setKey(prefKey);
mPreferenceCache.put(prefKey, preference);
}
@@ -398,7 +398,7 @@
preference.setOrder(++preferenceOrder);
preference.setSingleLineTitle(true);
// Updates App item preference style
- preference.setAnomalyHint(isAnomalyBatteryDiffEntry(entry) ? mAnomalyHintString : null);
+ preference.setHint(isAnomalyBatteryDiffEntry(entry) ? mAnomalyHintString : null);
// Sets the BatteryDiffEntry to preference for launching detailed page.
preference.setBatteryDiffEntry(entry);
preference.setSelectable(entry.validForRestriction());
diff --git a/src/com/android/settings/fuelgauge/batteryusage/PowerGaugePreference.java b/src/com/android/settings/fuelgauge/batteryusage/PowerGaugePreference.java
index 1fc9abd..866b9ae 100644
--- a/src/com/android/settings/fuelgauge/batteryusage/PowerGaugePreference.java
+++ b/src/com/android/settings/fuelgauge/batteryusage/PowerGaugePreference.java
@@ -28,7 +28,7 @@
import com.android.settings.R;
import com.android.settings.Utils;
-import com.android.settingslib.widget.AppPreference;
+import com.android.settings.fuelgauge.WarningFramePreference;
/**
* Custom preference for displaying battery usage info as a bar and an icon on the left for the
@@ -37,7 +37,7 @@
* <p>The battery usage info could be usage percentage or usage time. The preference won't show any
* icon if it is null.
*/
-public class PowerGaugePreference extends AppPreference {
+public class PowerGaugePreference extends WarningFramePreference {
// Please see go/battery-usage-app-list-alpha
private static final float SELECTABLE_ALPHA = 1f;
@@ -51,7 +51,6 @@
private CharSequence mContentDescription;
private CharSequence mProgress;
private CharSequence mProgressContentDescription;
- private boolean mShowAnomalyIcon;
public PowerGaugePreference(
Context context, Drawable icon, CharSequence contentDescription, BatteryEntry info) {
@@ -79,7 +78,6 @@
setWidgetLayoutResource(R.layout.preference_widget_summary);
mInfo = info;
mContentDescription = contentDescription;
- mShowAnomalyIcon = false;
mTitleColorNormal =
Utils.getColorAttrDefaultColor(context, android.R.attr.textColorPrimary);
}
@@ -108,17 +106,6 @@
return mProgress.toString();
}
- /** Sets whether to show anomaly icon */
- public void shouldShowAnomalyIcon(boolean showAnomalyIcon) {
- mShowAnomalyIcon = showAnomalyIcon;
- notifyChanged();
- }
-
- /** Gets whether to show anomaly icon */
- public boolean showAnomalyIcon() {
- return mShowAnomalyIcon;
- }
-
public void setBatteryDiffEntry(BatteryDiffEntry entry) {
mBatteryDiffEntry = entry;
}
@@ -149,12 +136,6 @@
if (!TextUtils.isEmpty(mProgressContentDescription)) {
subtitle.setContentDescription(mProgressContentDescription);
}
- if (mShowAnomalyIcon) {
- subtitle.setCompoundDrawablesRelativeWithIntrinsicBounds(
- R.drawable.ic_warning_24dp, 0, 0, 0);
- } else {
- subtitle.setCompoundDrawablesRelativeWithIntrinsicBounds(0, 0, 0, 0);
- }
if (mContentDescription != null) {
final TextView titleView = (TextView) view.findViewById(android.R.id.title);
titleView.setContentDescription(mContentDescription);
diff --git a/src/com/android/settings/localepicker/LocaleListEditor.java b/src/com/android/settings/localepicker/LocaleListEditor.java
index 461ea65..b1f005a 100644
--- a/src/com/android/settings/localepicker/LocaleListEditor.java
+++ b/src/com/android/settings/localepicker/LocaleListEditor.java
@@ -46,6 +46,7 @@
import androidx.annotation.NonNull;
import androidx.annotation.VisibleForTesting;
import androidx.fragment.app.FragmentManager;
+import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
import androidx.recyclerview.widget.RecyclerView;
@@ -53,6 +54,7 @@
import com.android.internal.app.LocaleStore;
import com.android.settings.R;
import com.android.settings.RestrictedSettingsFragment;
+import com.android.settings.flags.Flags;
import com.android.settings.overlay.FeatureFactory;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settingslib.search.SearchIndexable;
@@ -84,6 +86,7 @@
private static final String INDEX_KEY_ADD_LANGUAGE = "add_language";
private static final String KEY_LANGUAGES_PICKER = "languages_picker";
private static final String KEY_CATEGORY_TERMS_OF_ADDRESS = "key_category_terms_of_address";
+ private static final String KEY_ADD_A_LANGUAGE = "add_a_language";
private static final String TAG_DIALOG_CONFIRM_SYSTEM_DEFAULT = "dialog_confirm_system_default";
private static final String TAG_DIALOG_NOT_AVAILABLE = "dialog_not_available_locale";
private static final String TAG_DIALOG_ADD_SYSTEM_LOCALE = "dialog_add_system_locale";
@@ -92,6 +95,7 @@
private LocaleDragAndDropAdapter mAdapter;
private Menu mMenu;
private View mAddLanguage;
+ private Preference mAddLanguagePreference;
private boolean mRemoveMode;
private boolean mShowingRemoveDialog;
private boolean mLocaleAdditionMode = false;
@@ -282,7 +286,11 @@
private void setRemoveMode(boolean mRemoveMode) {
this.mRemoveMode = mRemoveMode;
mAdapter.setRemoveMode(mRemoveMode);
- mAddLanguage.setVisibility(mRemoveMode ? View.INVISIBLE : View.VISIBLE);
+ if (Flags.settingsExpressiveDesignEnabled()) {
+ mAddLanguagePreference.setVisible(!mRemoveMode);
+ } else {
+ mAddLanguage.setVisibility(mRemoveMode ? View.INVISIBLE : View.VISIBLE);
+ }
updateVisibilityOfRemoveMenu();
}
@@ -489,19 +497,23 @@
list.setAdapter(mAdapter);
list.setOnTouchListener(this);
list.requestFocus();
- mAddLanguage = layout.findViewById(R.id.add_language);
- mAddLanguage.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- FeatureFactory.getFeatureFactory().getMetricsFeatureProvider()
- .logSettingsTileClick(INDEX_KEY_ADD_LANGUAGE, getMetricsCategory());
+ if (Flags.settingsExpressiveDesignEnabled()) {
+ mAddLanguagePreference = getPreferenceScreen().findPreference(KEY_ADD_A_LANGUAGE);
+ } else {
+ mAddLanguage = layout.findViewById(R.id.add_language);
+ mAddLanguage.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(@NonNull View v) {
+ FeatureFactory.getFeatureFactory().getMetricsFeatureProvider()
+ .logSettingsTileClick(INDEX_KEY_ADD_LANGUAGE, getMetricsCategory());
- final Intent intent = new Intent(getActivity(),
- LocalePickerWithRegionActivity.class);
- intent.putExtras(getActivity().getIntent().getExtras());
- startActivityForResult(intent, REQUEST_LOCALE_PICKER);
- }
- });
+ final Intent intent = new Intent(getActivity(),
+ LocalePickerWithRegionActivity.class);
+ intent.putExtras(getActivity().getIntent().getExtras());
+ startActivityForResult(intent, REQUEST_LOCALE_PICKER);
+ }
+ });
+ }
}
@Override
diff --git a/src/com/android/settings/localepicker/LocalePickerBaseListPreferenceController.java b/src/com/android/settings/localepicker/LocalePickerBaseListPreferenceController.java
index c65382f..8bcbe31 100644
--- a/src/com/android/settings/localepicker/LocalePickerBaseListPreferenceController.java
+++ b/src/com/android/settings/localepicker/LocalePickerBaseListPreferenceController.java
@@ -75,9 +75,6 @@
public LocalePickerBaseListPreferenceController(@NonNull Context context,
@NonNull String preferenceKey) {
super(context, preferenceKey);
- mLocaleList = getLocaleCollectorController(context).getSupportedLocaleList(null,
- false, false);
- mLocaleOptions = new ArrayList<>(mLocaleList.size());
mPreferences = new ArrayMap<>();
mMetricsFeatureProvider = FeatureFactory.getFeatureFactory().getMetricsFeatureProvider();
}
@@ -246,7 +243,7 @@
private void setupLocaleList() {
mLocaleList = getLocaleCollectorController(mContext).getSupportedLocaleList(
mParentLocale, false, mIsCountryMode);
- mLocaleOptions.clear();
+ mLocaleOptions = new ArrayList<>(mLocaleList.size());
}
private List<LocaleStore.LocaleInfo> getSortedLocaleList(
@@ -262,7 +259,9 @@
boolean shouldShowLocaleEditor = shouldShowLocaleEditor(localeInfo);
if (shouldShowLocaleEditor) {
List<LocaleStore.LocaleInfo> feedItemList = getUserLocaleList();
- feedItemList.add(localeInfo);
+ for (LocaleStore.LocaleInfo locale : mLocaleList) {
+ feedItemList.add(locale);
+ }
LocaleList localeList = new LocaleList(feedItemList.stream()
.map(LocaleStore.LocaleInfo::getLocale)
.toArray(Locale[]::new));
diff --git a/src/com/android/settings/network/telephony/MobileNetworkPhoneNumberPreferenceController.kt b/src/com/android/settings/network/telephony/MobileNetworkPhoneNumberPreferenceController.kt
index db16acd..40cb6f9 100644
--- a/src/com/android/settings/network/telephony/MobileNetworkPhoneNumberPreferenceController.kt
+++ b/src/com/android/settings/network/telephony/MobileNetworkPhoneNumberPreferenceController.kt
@@ -25,6 +25,8 @@
import com.android.settings.flags.Flags
import com.android.settings.network.SubscriptionUtil
import com.android.settingslib.spa.framework.util.collectLatestWithLifecycle
+import com.android.settingslib.spaprivileged.framework.common.userManager
+import com.android.settingslib.Utils
/** Preference controller for "Phone number" */
class MobileNetworkPhoneNumberPreferenceController
@@ -41,13 +43,14 @@
mSubId = subId
}
- override fun getAvailabilityStatus(subId: Int): Int =
- when {
- !Flags.isDualSimOnboardingEnabled() -> CONDITIONALLY_UNAVAILABLE
- SubscriptionManager.isValidSubscriptionId(subId) &&
- SubscriptionUtil.isSimHardwareVisible(mContext) -> AVAILABLE
- else -> CONDITIONALLY_UNAVAILABLE
- }
+ override fun getAvailabilityStatus(subId: Int): Int = when {
+ !Flags.isDualSimOnboardingEnabled()
+ || !SubscriptionManager.isValidSubscriptionId(subId)
+ || !SubscriptionUtil.isSimHardwareVisible(mContext)
+ || Utils.isWifiOnly(mContext) -> CONDITIONALLY_UNAVAILABLE
+ !mContext.userManager.isAdminUser -> DISABLED_FOR_USER
+ else -> AVAILABLE
+ }
override fun displayPreference(screen: PreferenceScreen) {
super.displayPreference(screen)
diff --git a/tests/robotests/src/com/android/settings/connecteddevice/audiosharing/AudioSharingDialogFragmentTest.java b/tests/robotests/src/com/android/settings/connecteddevice/audiosharing/AudioSharingDialogFragmentTest.java
index 145a5c7..d964b9c 100644
--- a/tests/robotests/src/com/android/settings/connecteddevice/audiosharing/AudioSharingDialogFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/connecteddevice/audiosharing/AudioSharingDialogFragmentTest.java
@@ -93,8 +93,14 @@
private static final String METADATA_STR =
"BLUETOOTH:UUID:184F;BN:VGVzdA==;AT:1;AD:00A1A1A1A1A1;BI:1E240;BC:VGVzdENvZGU=;"
+ "MD:BgNwVGVzdA==;AS:1;PI:A0;NS:1;BS:3;NB:2;SM:BQNUZXN0BARlbmc=;;";
+ private static final String METADATA_STR_NO_PASSWORD =
+ "BLUETOOTH:UUID:184F;BN:SG9ja2V5;AT:0;AD:AABBCC001122;BI:DE51E9;SQ:1;AS:1;PI:FFFF;"
+ + "NS:1;BS:1;NB:1;;";
private static final BluetoothLeBroadcastMetadata METADATA =
BluetoothLeBroadcastMetadataExt.INSTANCE.convertToBroadcastMetadata(METADATA_STR);
+ private static final BluetoothLeBroadcastMetadata METADATA_NO_PASSWORD =
+ BluetoothLeBroadcastMetadataExt.INSTANCE.convertToBroadcastMetadata(
+ METADATA_STR_NO_PASSWORD);
private Fragment mParent;
private FakeFeatureFactory mFeatureFactory;
@@ -291,6 +297,50 @@
}
@Test
+ public void onCreateDialog_noExtraConnectedDevice_hasMetadataNoPassword_showCancelButton() {
+ mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
+ AtomicBoolean isCancelBtnClicked = new AtomicBoolean(false);
+ AudioSharingDialogFragment.show(
+ mParent,
+ new ArrayList<>(),
+ METADATA_NO_PASSWORD,
+ new AudioSharingDialogFragment.DialogEventListener() {
+ @Override
+ public void onCancelClick() {
+ isCancelBtnClicked.set(true);
+ }
+ },
+ TEST_EVENT_DATA_LIST);
+ shadowMainLooper().idle();
+ AlertDialog dialog = ShadowAlertDialogCompat.getLatestAlertDialog();
+ assertThat(dialog).isNotNull();
+ ImageView image = dialog.findViewById(R.id.description_image);
+ assertThat(image).isNotNull();
+ TextView text = dialog.findViewById(R.id.description_text);
+ assertThat(text).isNotNull();
+ assertThat(METADATA_NO_PASSWORD).isNotNull();
+ assertThat(text.getText().toString()).isEqualTo(
+ mParent.getString(R.string.audio_sharing_dialog_qr_code_content_no_password,
+ METADATA_NO_PASSWORD.getBroadcastName()));
+ TextView textBottom = dialog.findViewById(R.id.description_text_2);
+ assertThat(textBottom).isNotNull();
+ assertThat(textBottom.getText().toString()).isEqualTo(
+ mParent.getString(R.string.audio_sharing_dialog_pair_new_device_content));
+ Button cancelBtn = dialog.findViewById(R.id.negative_btn);
+ assertThat(cancelBtn).isNotNull();
+ cancelBtn.performClick();
+ shadowMainLooper().idle();
+
+ verify(mFeatureFactory.metricsFeatureProvider)
+ .action(
+ any(Context.class),
+ eq(SettingsEnums.ACTION_AUDIO_SHARING_DIALOG_NEGATIVE_BTN_CLICKED),
+ eq(TEST_EVENT_DATA));
+ assertThat(isCancelBtnClicked.get()).isTrue();
+ assertThat(dialog.isShowing()).isFalse();
+ }
+
+ @Test
public void onCreateDialog_flagOn_singleExtraConnectedDevice() {
mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
ArrayList<AudioSharingDeviceItem> list = new ArrayList<>();
diff --git a/tests/robotests/src/com/android/settings/development/DesktopExperiencePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/development/DesktopExperiencePreferenceControllerTest.java
index 6296626..388e9b2 100644
--- a/tests/robotests/src/com/android/settings/development/DesktopExperiencePreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/development/DesktopExperiencePreferenceControllerTest.java
@@ -102,7 +102,8 @@
// Set desktop mode available
when(mResources.getBoolean(com.android.internal.R.bool.config_isDesktopModeSupported))
.thenReturn(true);
- when(mResources.getBoolean(com.android.internal.R.bool.config_canInternalDisplayHostDesktops))
+ when(mResources
+ .getBoolean(com.android.internal.R.bool.config_canInternalDisplayHostDesktops))
.thenReturn(true);
ShadowSystemProperties.override("persist.wm.debug.desktop_mode_enforce_device_restrictions",
"false");
diff --git a/tests/robotests/src/com/android/settings/development/DesktopModePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/development/DesktopModePreferenceControllerTest.java
index 02aa872..9f718f9 100644
--- a/tests/robotests/src/com/android/settings/development/DesktopModePreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/development/DesktopModePreferenceControllerTest.java
@@ -104,7 +104,8 @@
// Set desktop mode available
when(mResources.getBoolean(R.bool.config_isDesktopModeSupported))
.thenReturn(true);
- when(mResources.getBoolean(com.android.internal.R.bool.config_canInternalDisplayHostDesktops))
+ when(mResources
+ .getBoolean(com.android.internal.R.bool.config_canInternalDisplayHostDesktops))
.thenReturn(true);
ShadowSystemProperties.override("persist.wm.debug.desktop_mode_enforce_device_restrictions",
"false");
diff --git a/tests/robotests/src/com/android/settings/development/DesktopModeSecondaryDisplayPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/development/DesktopModeSecondaryDisplayPreferenceControllerTest.java
index f3b96a4..2284d92 100644
--- a/tests/robotests/src/com/android/settings/development/DesktopModeSecondaryDisplayPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/development/DesktopModeSecondaryDisplayPreferenceControllerTest.java
@@ -97,7 +97,8 @@
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
mController.displayPreference(mScreen);
when(mResources.getBoolean(R.bool.config_isDesktopModeSupported)).thenReturn(false);
- when(mResources.getBoolean(com.android.internal.R.bool.config_canInternalDisplayHostDesktops))
+ when(mResources
+ .getBoolean(com.android.internal.R.bool.config_canInternalDisplayHostDesktops))
.thenReturn(false);
}
diff --git a/tests/robotests/src/com/android/settings/development/FreeformWindowsPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/development/FreeformWindowsPreferenceControllerTest.java
index cf32ae8..b4b0bcc 100644
--- a/tests/robotests/src/com/android/settings/development/FreeformWindowsPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/development/FreeformWindowsPreferenceControllerTest.java
@@ -91,6 +91,7 @@
doReturn(mFragmentManager).when(mActivity).getSupportFragmentManager();
doReturn(mActivity).when(mFragment).getActivity();
doReturn(true).when(mResources).getBoolean(R.bool.config_isDesktopModeSupported);
+ doReturn(true).when(mResources).getBoolean(R.bool.config_canInternalDisplayHostDesktops);
mController = new FreeformWindowsPreferenceController(mContext, mFragment);
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
when(mContext.getPackageManager()).thenReturn(mPackageManager);
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageTimeControllerTest.java b/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageTimeControllerTest.java
index e8eb126..60ece9d 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageTimeControllerTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageTimeControllerTest.java
@@ -99,9 +99,9 @@
/* anomalyHintText= */ null);
verifyOnePreferenceInvisible(mBackgroundTimePreference);
- verify(mScreenTimePreference).setTimeTitle("Screen time");
- verify(mScreenTimePreference).setTimeSummary("1 min");
- verify(mScreenTimePreference, never()).setAnomalyHint(anyString());
+ verify(mScreenTimePreference).setTitle("Screen time");
+ verify(mScreenTimePreference).setSummary("1 min");
+ verify(mScreenTimePreference, never()).setHint(anyString());
}
@Test
@@ -117,9 +117,9 @@
/* anomalyHintText= */ null);
verifyOnePreferenceInvisible(mScreenTimePreference);
- verify(mBackgroundTimePreference).setTimeTitle("Background time");
- verify(mBackgroundTimePreference).setTimeSummary("2 min");
- verify(mBackgroundTimePreference, never()).setAnomalyHint(anyString());
+ verify(mBackgroundTimePreference).setTitle("Background time");
+ verify(mBackgroundTimePreference).setSummary("2 min");
+ verify(mBackgroundTimePreference, never()).setHint(anyString());
}
@Test
@@ -135,12 +135,12 @@
/* anomalyHintText= */ null);
verifyAllPreferencesVisible(true);
- verify(mScreenTimePreference).setTimeTitle("Screen time");
- verify(mScreenTimePreference).setTimeSummary("1 min");
- verify(mScreenTimePreference, never()).setAnomalyHint(anyString());
- verify(mBackgroundTimePreference).setTimeTitle("Background time");
- verify(mBackgroundTimePreference).setTimeSummary("2 min");
- verify(mBackgroundTimePreference, never()).setAnomalyHint(anyString());
+ verify(mScreenTimePreference).setTitle("Screen time");
+ verify(mScreenTimePreference).setSummary("1 min");
+ verify(mScreenTimePreference, never()).setHint(anyString());
+ verify(mBackgroundTimePreference).setTitle("Background time");
+ verify(mBackgroundTimePreference).setSummary("2 min");
+ verify(mBackgroundTimePreference, never()).setHint(anyString());
verify(mPowerUsageTimeCategory).setTitle("App usage for 12 am-2 am");
}
@@ -173,8 +173,8 @@
/* anomalyHintText= */ null);
verifyAllPreferencesVisible(true);
- verify(mScreenTimePreference).setTimeSummary("1 min");
- verify(mBackgroundTimePreference).setTimeSummary("Less than a minute");
+ verify(mScreenTimePreference).setSummary("1 min");
+ verify(mBackgroundTimePreference).setSummary("Less than a minute");
}
@Test
@@ -190,8 +190,8 @@
/* anomalyHintText= */ null);
verifyAllPreferencesVisible(true);
- verify(mScreenTimePreference).setTimeSummary("Less than a minute");
- verify(mBackgroundTimePreference).setTimeSummary("2 min");
+ verify(mScreenTimePreference).setSummary("Less than a minute");
+ verify(mBackgroundTimePreference).setSummary("2 min");
}
@Test
@@ -207,8 +207,8 @@
/* anomalyHintText= */ null);
verifyAllPreferencesVisible(true);
- verify(mScreenTimePreference).setTimeSummary("Less than a minute");
- verify(mBackgroundTimePreference).setTimeSummary("Less than a minute");
+ verify(mScreenTimePreference).setSummary("Less than a minute");
+ verify(mBackgroundTimePreference).setSummary("Less than a minute");
}
@Test
@@ -224,8 +224,8 @@
TEST_ANOMALY_HINT_TEXT);
verifyAllPreferencesVisible(true);
- verify(mScreenTimePreference).setAnomalyHint(TEST_ANOMALY_HINT_TEXT);
- verify(mBackgroundTimePreference, never()).setAnomalyHint(anyString());
+ verify(mScreenTimePreference).setHint(TEST_ANOMALY_HINT_TEXT);
+ verify(mBackgroundTimePreference, never()).setHint(anyString());
}
@Test
@@ -241,8 +241,8 @@
TEST_ANOMALY_HINT_TEXT);
verifyAllPreferencesVisible(true);
- verify(mScreenTimePreference, never()).setAnomalyHint(anyString());
- verify(mBackgroundTimePreference).setAnomalyHint(TEST_ANOMALY_HINT_TEXT);
+ verify(mScreenTimePreference, never()).setHint(anyString());
+ verify(mBackgroundTimePreference).setHint(TEST_ANOMALY_HINT_TEXT);
}
@Test
@@ -258,9 +258,9 @@
TEST_ANOMALY_HINT_TEXT);
verifyAllPreferencesVisible(true);
- verify(mScreenTimePreference).setTimeSummary("Less than a minute");
- verify(mScreenTimePreference).setAnomalyHint(TEST_ANOMALY_HINT_TEXT);
- verify(mBackgroundTimePreference, never()).setAnomalyHint(anyString());
+ verify(mScreenTimePreference).setSummary("Less than a minute");
+ verify(mScreenTimePreference).setHint(TEST_ANOMALY_HINT_TEXT);
+ verify(mBackgroundTimePreference, never()).setHint(anyString());
}
private void verifySetPrefToVisible(Preference pref, boolean isVisible) {
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/batteryusage/BatteryUsageBreakdownControllerTest.java b/tests/robotests/src/com/android/settings/fuelgauge/batteryusage/BatteryUsageBreakdownControllerTest.java
index c4cbb98..7ad7c49 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/batteryusage/BatteryUsageBreakdownControllerTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/batteryusage/BatteryUsageBreakdownControllerTest.java
@@ -67,7 +67,7 @@
@Mock private PreferenceGroup mRootPreferenceGroup;
@Mock private Drawable mDrawable;
@Mock private BatteryHistEntry mBatteryHistEntry;
- @Mock private AnomalyAppItemPreference mAnomalyAppItemPreference;
+ @Mock private PowerGaugePreference mPowerGaugePreference;
private Context mContext;
private FakeFeatureFactory mFeatureFactory;
@@ -131,13 +131,13 @@
BatteryDiffEntry.sResourceCache.put(
"fakeBatteryDiffEntryKey",
new BatteryEntry.NameAndIcon("fakeName", /* icon= */ null, /* iconId= */ 1));
- doReturn(mAnomalyAppItemPreference).when(mRootPreferenceGroup).findPreference(PREF_KEY);
+ doReturn(mPowerGaugePreference).when(mRootPreferenceGroup).findPreference(PREF_KEY);
}
@Test
public void onDestroy_clearPreferenceCacheAndPreferenceGroupRemoveAll() {
// Ensures the testing environment is correct.
- mBatteryUsageBreakdownController.mPreferenceCache.put(PREF_KEY, mAnomalyAppItemPreference);
+ mBatteryUsageBreakdownController.mPreferenceCache.put(PREF_KEY, mPowerGaugePreference);
assertThat(mBatteryUsageBreakdownController.mPreferenceCache).hasSize(1);
mBatteryUsageBreakdownController.onDestroy();
@@ -204,25 +204,25 @@
@Test
public void removeAndCacheAllUnusedPreferences_removePref_buildCacheAndRemoveAllPreference() {
doReturn(1).when(mRootPreferenceGroup).getPreferenceCount();
- doReturn(mAnomalyAppItemPreference).when(mRootPreferenceGroup).getPreference(0);
+ doReturn(mPowerGaugePreference).when(mRootPreferenceGroup).getPreference(0);
doReturn(PREF_KEY2).when(mBatteryHistEntry).getKey();
- doReturn(PREF_KEY).when(mAnomalyAppItemPreference).getKey();
+ doReturn(PREF_KEY).when(mPowerGaugePreference).getKey();
// Ensures the testing data is correct.
assertThat(mBatteryUsageBreakdownController.mPreferenceCache).isEmpty();
mBatteryUsageBreakdownController.removeAndCacheAllUnusedPreferences();
assertThat(mBatteryUsageBreakdownController.mPreferenceCache.get(PREF_KEY))
- .isEqualTo(mAnomalyAppItemPreference);
- verify(mRootPreferenceGroup).removePreference(mAnomalyAppItemPreference);
+ .isEqualTo(mPowerGaugePreference);
+ verify(mRootPreferenceGroup).removePreference(mPowerGaugePreference);
}
@Test
public void removeAndCacheAllUnusedPreferences_keepPref_KeepAllPreference() {
doReturn(1).when(mRootPreferenceGroup).getPreferenceCount();
- doReturn(mAnomalyAppItemPreference).when(mRootPreferenceGroup).getPreference(0);
+ doReturn(mPowerGaugePreference).when(mRootPreferenceGroup).getPreference(0);
doReturn(PREF_KEY).when(mBatteryDiffEntry).getKey();
- doReturn(PREF_KEY).when(mAnomalyAppItemPreference).getKey();
+ doReturn(PREF_KEY).when(mPowerGaugePreference).getKey();
// Ensures the testing data is correct.
assertThat(mBatteryUsageBreakdownController.mPreferenceCache).isEmpty();
@@ -246,11 +246,11 @@
@Test
public void handlePreferenceTreeClick_forAppEntry_returnTrue() {
mBatteryDiffEntry.mConsumerType = ConvertUtils.CONSUMER_TYPE_SYSTEM_BATTERY;
- doReturn(mBatteryDiffEntry).when(mAnomalyAppItemPreference).getBatteryDiffEntry();
+ doReturn(mBatteryDiffEntry).when(mPowerGaugePreference).getBatteryDiffEntry();
assertThat(
mBatteryUsageBreakdownController.handlePreferenceTreeClick(
- mAnomalyAppItemPreference))
+ mPowerGaugePreference))
.isTrue();
verify(mMetricsFeatureProvider)
.action(
@@ -264,11 +264,11 @@
@Test
public void handlePreferenceTreeClick_forSystemEntry_returnTrue() {
mBatteryDiffEntry.mConsumerType = ConvertUtils.CONSUMER_TYPE_UID_BATTERY;
- doReturn(mBatteryDiffEntry).when(mAnomalyAppItemPreference).getBatteryDiffEntry();
+ doReturn(mBatteryDiffEntry).when(mPowerGaugePreference).getBatteryDiffEntry();
assertThat(
mBatteryUsageBreakdownController.handlePreferenceTreeClick(
- mAnomalyAppItemPreference))
+ mPowerGaugePreference))
.isTrue();
verify(mMetricsFeatureProvider)
.action(
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/batteryusage/PowerGaugePreferenceTest.java b/tests/robotests/src/com/android/settings/fuelgauge/batteryusage/PowerGaugePreferenceTest.java
index f64ef49..0bad0a0 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/batteryusage/PowerGaugePreferenceTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/batteryusage/PowerGaugePreferenceTest.java
@@ -19,19 +19,20 @@
import android.content.Context;
import android.graphics.drawable.Drawable;
-import android.graphics.drawable.VectorDrawable;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
-import android.widget.TextView;
+import android.widget.Space;
import androidx.preference.PreferenceViewHolder;
import com.android.settings.R;
+import com.android.settingslib.widget.SettingsThemeHelper;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
+import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
@@ -48,17 +49,17 @@
private View mWidgetView;
private PreferenceViewHolder mPreferenceViewHolder;
+ @Mock Drawable mMockIcon;
+
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = RuntimeEnvironment.application;
+ mPowerGaugePreference = new PowerGaugePreference(mContext);
mRootView =
LayoutInflater.from(mContext)
- .inflate(
- com.android.settingslib.widget.preference.app.R.layout
- .preference_app,
- null);
+ .inflate(mPowerGaugePreference.getLayoutResource(), null);
mWidgetView =
LayoutInflater.from(mContext).inflate(R.layout.preference_widget_summary, null);
final LinearLayout widgetFrame = mRootView.findViewById(android.R.id.widget_frame);
@@ -66,31 +67,56 @@
widgetFrame.addView(mWidgetView);
mPreferenceViewHolder = PreferenceViewHolder.createInstanceForTests(mRootView);
- mPowerGaugePreference = new PowerGaugePreference(mContext);
assertThat(mPowerGaugePreference.getLayoutResource())
- .isEqualTo(com.android.settingslib.widget.preference.app.R.layout.preference_app);
+ .isEqualTo(
+ SettingsThemeHelper.isExpressiveTheme(mContext)
+ ? R.layout.expressive_warning_frame_preference
+ : R.layout.warning_frame_preference);
}
@Test
- public void testOnBindViewHolder_showAnomaly_bindAnomalyIcon() {
- mPowerGaugePreference.shouldShowAnomalyIcon(true);
+ public void testOnBindViewHolder_showHint_hasHintChip() {
+ mPowerGaugePreference.setHint("Hint Text");
+ mPowerGaugePreference.setIcon(mMockIcon);
mPowerGaugePreference.onBindViewHolder(mPreferenceViewHolder);
- TextView widgetSummary = (TextView) mPreferenceViewHolder.findViewById(R.id.widget_summary);
- final Drawable[] drawables = widgetSummary.getCompoundDrawablesRelative();
+ final LinearLayout warningChipFrame =
+ (LinearLayout) mPreferenceViewHolder.findViewById(R.id.warning_chip_frame);
+ final Space warningPaddingPlaceHolder =
+ warningChipFrame.findViewById(R.id.warning_padding_placeholder);
- assertThat(drawables[0]).isInstanceOf(VectorDrawable.class);
+ assertThat(warningChipFrame.getVisibility()).isEqualTo(View.VISIBLE);
+ assertThat(warningPaddingPlaceHolder.getVisibility()).isEqualTo(View.VISIBLE);
}
@Test
- public void testOnBindViewHolder_notShowAnomaly_bindAnomalyIcon() {
- mPowerGaugePreference.shouldShowAnomalyIcon(false);
+ public void testOnBindViewHolder_emptyHintText_withoutHintChip() {
+ mPowerGaugePreference.setHint("");
+ mPowerGaugePreference.setIcon(mMockIcon);
mPowerGaugePreference.onBindViewHolder(mPreferenceViewHolder);
- TextView widgetSummary = (TextView) mPreferenceViewHolder.findViewById(R.id.widget_summary);
- final Drawable[] drawables = widgetSummary.getCompoundDrawablesRelative();
+ final LinearLayout warningChipFrame =
+ (LinearLayout) mPreferenceViewHolder.findViewById(R.id.warning_chip_frame);
+ final Space warningPaddingPlaceholder =
+ warningChipFrame.findViewById(R.id.warning_padding_placeholder);
- assertThat(drawables[0]).isNull();
+ assertThat(warningChipFrame.getVisibility()).isEqualTo(View.GONE);
+ assertThat(warningPaddingPlaceholder.getVisibility()).isEqualTo(View.VISIBLE);
+ }
+
+ @Test
+ public void testOnBindViewHolder_noAppIconWithHintText_hasChipWithoutPaddingPlaceholder() {
+ mPowerGaugePreference.setHint("Anomaly Hint Text");
+ mPowerGaugePreference.setIcon(null);
+ mPowerGaugePreference.onBindViewHolder(mPreferenceViewHolder);
+
+ final LinearLayout warningChipFrame =
+ (LinearLayout) mPreferenceViewHolder.findViewById(R.id.warning_chip_frame);
+ final Space warningPaddingPlaceHolder =
+ warningChipFrame.findViewById(R.id.warning_padding_placeholder);
+
+ assertThat(warningChipFrame.getVisibility()).isEqualTo(View.VISIBLE);
+ assertThat(warningPaddingPlaceHolder.getVisibility()).isEqualTo(View.GONE);
}
@Test
diff --git a/tests/robotests/src/com/android/settings/localepicker/LocaleListEditorTest.java b/tests/robotests/src/com/android/settings/localepicker/LocaleListEditorTest.java
index 0d5a952..4272afe 100644
--- a/tests/robotests/src/com/android/settings/localepicker/LocaleListEditorTest.java
+++ b/tests/robotests/src/com/android/settings/localepicker/LocaleListEditorTest.java
@@ -57,6 +57,7 @@
import androidx.fragment.app.FragmentActivity;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;
+import androidx.preference.Preference;
import androidx.test.core.app.ApplicationProvider;
import com.android.internal.app.LocaleStore;
@@ -145,6 +146,8 @@
private ImageView mDragHandle;
@Mock
private NotificationController mNotificationController;
+ @Mock
+ private Preference mAddLanguagePreference;
@Rule
public final CheckFlagsRule mCheckFlagsRule =
@@ -168,6 +171,8 @@
context.getSystemService(Context.USER_SERVICE));
ReflectionHelpers.setField(mLocaleListEditor, "mAdapter", mAdapter);
ReflectionHelpers.setField(mLocaleListEditor, "mAddLanguage", mAddLanguage);
+ ReflectionHelpers.setField(mLocaleListEditor, "mAddLanguagePreference",
+ mAddLanguagePreference);
ReflectionHelpers.setField(mLocaleListEditor, "mFragmentManager", mFragmentManager);
ReflectionHelpers.setField(mLocaleListEditor, "mMetricsFeatureProvider",
mMetricsFeatureProvider);
diff --git a/tests/spa_unit/src/com/android/settings/deviceinfo/PhoneNumberPreferenceControllerTest.kt b/tests/spa_unit/src/com/android/settings/deviceinfo/PhoneNumberPreferenceControllerTest.kt
index 8524ef4..ed40a8c 100644
--- a/tests/spa_unit/src/com/android/settings/deviceinfo/PhoneNumberPreferenceControllerTest.kt
+++ b/tests/spa_unit/src/com/android/settings/deviceinfo/PhoneNumberPreferenceControllerTest.kt
@@ -17,6 +17,7 @@
package com.android.settings.deviceinfo
import android.content.Context
+import android.os.UserManager
import android.telephony.SubscriptionInfo
import android.telephony.SubscriptionManager
import android.telephony.TelephonyManager
@@ -25,30 +26,39 @@
import androidx.preference.PreferenceManager
import androidx.test.core.app.ApplicationProvider
import androidx.test.ext.junit.runners.AndroidJUnit4
+import com.android.dx.mockito.inline.extended.ExtendedMockito
import com.android.settings.R
+import com.android.settings.core.BasePreferenceController
+import com.android.settings.network.SubscriptionUtil
+import com.android.settingslib.Utils
import com.google.common.truth.Truth.assertThat
+import org.junit.After
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
+import org.mockito.MockitoSession
import org.mockito.kotlin.any
import org.mockito.kotlin.doReturn
import org.mockito.kotlin.mock
import org.mockito.kotlin.spy
+import org.mockito.kotlin.stub
import org.mockito.kotlin.verify
import org.mockito.kotlin.whenever
+import org.mockito.quality.Strictness
@RunWith(AndroidJUnit4::class)
class PhoneNumberPreferenceControllerTest {
+ private lateinit var mockSession: MockitoSession
+ private val mockUserManager = mock<UserManager>()
private val mockTelephonyManager = mock<TelephonyManager>()
private val mockSubscriptionManager = mock<SubscriptionManager>()
private val context: Context =
spy(ApplicationProvider.getApplicationContext()) {
- on { getSystemService(SubscriptionManager::class.java) } doReturn
- mockSubscriptionManager
-
+ on { getSystemService(SubscriptionManager::class.java) } doReturn mockSubscriptionManager
on { getSystemService(TelephonyManager::class.java) } doReturn mockTelephonyManager
+ on { getSystemService(UserManager::class.java) } doReturn mockUserManager
}
private val subscriptionInfo = mock<SubscriptionInfo>()
@@ -61,6 +71,20 @@
@Before
fun setup() {
+ mockSession =
+ ExtendedMockito.mockitoSession()
+ .mockStatic(SubscriptionUtil::class.java)
+ .mockStatic(Utils::class.java)
+ .strictness(Strictness.LENIENT)
+ .startMocking()
+
+ // By default, available
+ whenever(SubscriptionUtil.isSimHardwareVisible(context)).thenReturn(true)
+ whenever(Utils.isWifiOnly(context)).thenReturn(false)
+ mockUserManager.stub {
+ on { isAdminUser } doReturn true
+ }
+
preference.setKey(controller.preferenceKey)
preference.isVisible = true
preferenceScreen.addPreference(preference)
@@ -70,6 +94,11 @@
doReturn(secondPreference).whenever(controller).createNewPreference(context)
}
+ @After
+ fun teardown() {
+ mockSession.finishMocking()
+ }
+
@Test
fun displayPreference_multiSim_shouldAddSecondPreference() {
whenever(mockTelephonyManager.phoneCount).thenReturn(2)
@@ -132,4 +161,37 @@
verify(preference).summary = context.getString(R.string.device_info_not_available)
}
+
+ @Test
+ fun getAvailabilityStatus_simHardwareVisible_userAdmin_notWifiOnly_displayed() {
+ // Use defaults from setup()
+ val availabilityStatus = controller.availabilityStatus
+ assertThat(availabilityStatus).isEqualTo(BasePreferenceController.AVAILABLE)
+ }
+
+ @Test
+ fun getAvailabilityStatus_notSimHardwareVisible_userAdmin_notWifiOnly_notDisplayed() {
+ whenever(SubscriptionUtil.isSimHardwareVisible(context)).thenReturn(false)
+
+ val availabilityStatus = controller.availabilityStatus
+ assertThat(availabilityStatus).isEqualTo(BasePreferenceController.UNSUPPORTED_ON_DEVICE)
+ }
+
+ @Test
+ fun getAvailabilityStatus_simHardwareVisible_notUserAdmin_notWifiOnly_notDisplayed() {
+ mockUserManager.stub {
+ on { isAdminUser } doReturn false
+ }
+
+ val availabilityStatus = controller.availabilityStatus
+ assertThat(availabilityStatus).isEqualTo(BasePreferenceController.DISABLED_FOR_USER)
+ }
+
+ @Test
+ fun getAvailabilityStatus_simHardwareVisible_userAdmin_wifiOnly_notDisplayed() {
+ whenever(Utils.isWifiOnly(context)).thenReturn(true)
+
+ val availabilityStatus = controller.availabilityStatus
+ assertThat(availabilityStatus).isEqualTo(BasePreferenceController.UNSUPPORTED_ON_DEVICE)
+ }
}
diff --git a/tests/spa_unit/src/com/android/settings/network/telephony/MobileNetworkPhoneNumberPreferenceControllerTest.kt b/tests/spa_unit/src/com/android/settings/network/telephony/MobileNetworkPhoneNumberPreferenceControllerTest.kt
index f56c0c4..a46b710 100644
--- a/tests/spa_unit/src/com/android/settings/network/telephony/MobileNetworkPhoneNumberPreferenceControllerTest.kt
+++ b/tests/spa_unit/src/com/android/settings/network/telephony/MobileNetworkPhoneNumberPreferenceControllerTest.kt
@@ -17,6 +17,7 @@
package com.android.settings.network.telephony
import android.content.Context
+import android.os.UserManager
import androidx.lifecycle.testing.TestLifecycleOwner
import androidx.preference.Preference
import androidx.preference.PreferenceManager
@@ -26,6 +27,7 @@
import com.android.settings.R
import com.android.settings.core.BasePreferenceController
import com.android.settings.network.SubscriptionUtil
+import com.android.settingslib.Utils
import com.google.common.truth.Truth.assertThat
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.flowOf
@@ -37,6 +39,7 @@
import org.mockito.MockitoSession
import org.mockito.kotlin.doReturn
import org.mockito.kotlin.mock
+import org.mockito.kotlin.spy
import org.mockito.kotlin.stub
import org.mockito.kotlin.whenever
import org.mockito.quality.Strictness
@@ -45,9 +48,14 @@
class MobileNetworkPhoneNumberPreferenceControllerTest {
private lateinit var mockSession: MockitoSession
- private val context: Context = ApplicationProvider.getApplicationContext()
+ private val mockUserManager = mock<UserManager>()
private val mockSubscriptionRepository = mock<SubscriptionRepository>()
+ private val context: Context =
+ spy(ApplicationProvider.getApplicationContext()) {
+ on { getSystemService(UserManager::class.java) } doReturn mockUserManager
+ }
+
private val controller =
MobileNetworkPhoneNumberPreferenceController(context, TEST_KEY, mockSubscriptionRepository)
private val preference = Preference(context).apply { key = TEST_KEY }
@@ -58,9 +66,17 @@
mockSession =
ExtendedMockito.mockitoSession()
.mockStatic(SubscriptionUtil::class.java)
+ .mockStatic(Utils::class.java)
.strictness(Strictness.LENIENT)
.startMocking()
+ // By default, available
+ whenever(SubscriptionUtil.isSimHardwareVisible(context)).thenReturn(true)
+ whenever(Utils.isWifiOnly(context)).thenReturn(false)
+ mockUserManager.stub {
+ on { isAdminUser } doReturn true
+ }
+
preferenceScreen.addPreference(preference)
controller.init(SUB_ID)
controller.displayPreference(preferenceScreen)
@@ -73,7 +89,6 @@
@Test
fun onViewCreated_cannotGetPhoneNumber_displayUnknown() = runBlocking {
- whenever(SubscriptionUtil.isSimHardwareVisible(context)).thenReturn(true)
mockSubscriptionRepository.stub {
on { phoneNumberFlow(SUB_ID) } doReturn flowOf(null)
}
@@ -86,7 +101,6 @@
@Test
fun onViewCreated_canGetPhoneNumber_displayPhoneNumber() = runBlocking {
- whenever(SubscriptionUtil.isSimHardwareVisible(context)).thenReturn(true)
mockSubscriptionRepository.stub {
on { phoneNumberFlow(SUB_ID) } doReturn flowOf(PHONE_NUMBER)
}
@@ -98,11 +112,35 @@
}
@Test
- fun getAvailabilityStatus_notSimHardwareVisible() {
+ fun getAvailabilityStatus_simHardwareVisible_userAdmin_notWifiOnly_displayed() {
+ // Use defaults from setup()
+ val availabilityStatus = controller.availabilityStatus
+ assertThat(availabilityStatus).isEqualTo(BasePreferenceController.AVAILABLE)
+ }
+
+ @Test
+ fun getAvailabilityStatus_notSimHardwareVisible_userAdmin_notWifiOnly_notDisplayed() {
whenever(SubscriptionUtil.isSimHardwareVisible(context)).thenReturn(false)
val availabilityStatus = controller.availabilityStatus
+ assertThat(availabilityStatus).isEqualTo(BasePreferenceController.CONDITIONALLY_UNAVAILABLE)
+ }
+ @Test
+ fun getAvailabilityStatus_simHardwareVisible_notUserAdmin_notWifiOnly_notDisplayed() {
+ mockUserManager.stub {
+ on { isAdminUser } doReturn false
+ }
+
+ val availabilityStatus = controller.availabilityStatus
+ assertThat(availabilityStatus).isEqualTo(BasePreferenceController.DISABLED_FOR_USER)
+ }
+
+ @Test
+ fun getAvailabilityStatus_simHardwareVisible_userAdmin_wifiOnly_notDisplayed() {
+ whenever(Utils.isWifiOnly(context)).thenReturn(true)
+
+ val availabilityStatus = controller.availabilityStatus
assertThat(availabilityStatus).isEqualTo(BasePreferenceController.CONDITIONALLY_UNAVAILABLE)
}