Merge "Fix IllegalArgumentException" into main
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index a15b4ea..7c4aa48 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -1568,7 +1568,7 @@
<activity android:name="Settings$UserAspectRatioAppListActivity"
android:exported="true"
- android:label="@string/aspect_ratio_title">
+ android:label="@string/aspect_ratio_experimental_title">
<intent-filter android:priority="1">
<action android:name="android.settings.MANAGE_USER_ASPECT_RATIO_SETTINGS"/>
<category android:name="android.intent.category.DEFAULT" />
@@ -1581,7 +1581,7 @@
<activity android:name="Settings$UserAspectRatioAppActivity"
android:exported="true"
- android:label="@string/aspect_ratio_title">
+ android:label="@string/aspect_ratio_experimental_title">
<intent-filter>
<action android:name="android.settings.MANAGE_USER_ASPECT_RATIO_SETTINGS" />
<category android:name="android.intent.category.DEFAULT" />
@@ -4568,6 +4568,22 @@
</activity>
<activity
+ android:name=".Settings$PreviouslyConnectedDeviceActivity"
+ android:label="@string/connected_device_saved_title"
+ android:exported="true"
+ android:permission="android.permission.BLUETOOTH_CONNECT"
+ android:icon="@drawable/ic_homepage_connected_device">
+ <intent-filter android:priority="1">
+ <action android:name="com.android.settings.PREVIOUSLY_CONNECTED_DEVICE" />
+ <category android:name="android.intent.category.DEFAULT" />
+ </intent-filter>
+ <meta-data android:name="com.android.settings.FRAGMENT_CLASS"
+ android:value="com.android.settings.connecteddevice.PreviouslyConnectedDeviceDashboardFragment"/>
+ <meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED"
+ android:value="true" />
+ </activity>
+
+ <activity
android:name="Settings$StylusUsiDetailsActivity"
android:label="@string/stylus_device_details_title"
android:exported="true">
diff --git a/res/drawable/ic_battery_full.xml b/res/drawable/ic_battery_full.xml
new file mode 100644
index 0000000..5dfac55
--- /dev/null
+++ b/res/drawable/ic_battery_full.xml
@@ -0,0 +1,25 @@
+<!--
+ 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.
+-->
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="24dp"
+ android:height="24dp"
+ android:viewportWidth="960"
+ android:viewportHeight="960"
+ android:tint="?android:attr/colorControlNormal">
+ <path
+ android:fillColor="@android:color/white"
+ android:pathData="M320,880Q303,880 291.5,868.5Q280,857 280,840L280,200Q280,183 291.5,171.5Q303,160 320,160L400,160L400,80L560,80L560,160L640,160Q657,160 668.5,171.5Q680,183 680,200L680,840Q680,857 668.5,868.5Q657,880 640,880L320,880Z"/>
+</vector>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 025bbf7..2cd7806 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -2119,6 +2119,8 @@
<string name="internet_source_mobile_data">Mobile data</string>
<!-- Ethernet summary in Internet source preference [CHAR LIMIT=NONE]-->
<string name="internet_source_ethernet">Ethernet</string>
+ <!-- Hotspot device details battery charging summary [CHAR LIMIT=NONE]-->
+ <string name="hotspot_battery_charging_summary"><xliff:g id="battery_percentage" example="80%">%1$s</xliff:g> \u2011 Charging</string>
<!-- Hotspot device details preference category title in Network details [CHAR LIMIT=NONE]-->
<string name="hotspot_connection_category">Hotspot connection</string>
<!-- Connection strength preference in Hotspot connection preference category [CHAR LIMIT=NONE]-->
@@ -11422,15 +11424,6 @@
<!-- Summary for Wi-Fi calling to explain this feature [CHAR LIMIT=NONE] -->
<string name="wifi_calling_summary">Use Wi\u2011Fi for calls to improve quality</string>
- <!-- Mobile network settings screen, title of Backup calling setting. [CHAR LIMIT=NONE] -->
- <string name="backup_calling_settings_title">Backup calling</string>
-
- <!-- Backup calling summary. [CHAR LIMIT=100] -->
- <string name="backup_calling_setting_summary">If <xliff:g id="backup_calling_operator_text" example="Google Fi">%1$s</xliff:g> is unavailable or roaming, use your mobile data SIM for <xliff:g id="backup_calling_carrier_text" example="Google Fi">%1$s</xliff:g> calls.</string>
-
- <!-- List of synonyms for the cross SIM calling titles, used to match in settings search [CHAR LIMIT=NONE] -->
- <string name="keywords_backup_calling">backup calling</string>
-
<!-- Title for enable MMS notification when trying to receive MMS. [CHAR LIMIT=40] -->
<string name="enable_receiving_mms_notification_title">Incoming MMS message</string>
<!-- Title for enable MMS notification when trying to send MMS. [CHAR LIMIT=40] -->
diff --git a/res/xml/wifi_network_details_fragment2.xml b/res/xml/wifi_network_details_fragment2.xml
index e3464c2..0062474 100644
--- a/res/xml/wifi_network_details_fragment2.xml
+++ b/res/xml/wifi_network_details_fragment2.xml
@@ -52,6 +52,7 @@
settings:enableCopying="true"/>
<Preference
android:key="hotspot_device_details_battery"
+ android:icon="@drawable/ic_battery_full"
android:title="@string/power_usage_summary_title"
android:selectable="false"
settings:enableCopying="true"/>
diff --git a/src/com/android/settings/Settings.java b/src/com/android/settings/Settings.java
index ab55bec..7ea4be4 100644
--- a/src/com/android/settings/Settings.java
+++ b/src/com/android/settings/Settings.java
@@ -514,4 +514,6 @@
* Activity for OneHandedSettings
*/
public static class OneHandedSettingsActivity extends SettingsActivity { /* empty */ }
+
+ public static class PreviouslyConnectedDeviceActivity extends SettingsActivity { /* empty */ }
}
diff --git a/src/com/android/settings/accessibility/FlashNotificationsPreviewPreference.java b/src/com/android/settings/accessibility/FlashNotificationsPreviewPreference.java
index 79534d8..5b669fa 100644
--- a/src/com/android/settings/accessibility/FlashNotificationsPreviewPreference.java
+++ b/src/com/android/settings/accessibility/FlashNotificationsPreviewPreference.java
@@ -63,7 +63,7 @@
private void init() {
setLayoutResource(R.layout.flash_notification_preview_preference);
mBackgroundEnabled = getContext().getDrawable(
- com.android.settingslib.widget.R.drawable.settingslib_switch_bar_bg_on);
+ com.android.settingslib.widget.mainswitch.R.drawable.settingslib_switch_bar_bg_on);
mBackgroundDisabled = getContext().getDrawable(R.drawable.switch_bar_bg_disabled);
mTextColorDisabled = Utils.getColorAttrDefaultColor(getContext(),
android.R.attr.textColorPrimary);
diff --git a/src/com/android/settings/accessibility/VibrationSettings.java b/src/com/android/settings/accessibility/VibrationSettings.java
index e7a249b..53592a7 100644
--- a/src/com/android/settings/accessibility/VibrationSettings.java
+++ b/src/com/android/settings/accessibility/VibrationSettings.java
@@ -81,7 +81,7 @@
R.integer.config_vibration_supported_intensity_levels);
if (rv != null && supportedIntensities > 1) {
final int bottom_padding = res.getDimensionPixelSize(
- com.android.settingslib.widget.R.dimen.settingslib_listPreferredItemPaddingEnd);
+ com.android.settingslib.widget.theme.R.dimen.settingslib_listPreferredItemPaddingEnd);
rv.setPaddingRelative(rv.getPaddingStart(), rv.getPaddingTop(), rv.getPaddingEnd(),
rv.getPaddingBottom() + bottom_padding);
}
diff --git a/src/com/android/settings/accounts/AccountTypePreferenceLoader.java b/src/com/android/settings/accounts/AccountTypePreferenceLoader.java
index ddf92f5..72366d4 100644
--- a/src/com/android/settings/accounts/AccountTypePreferenceLoader.java
+++ b/src/com/android/settings/accounts/AccountTypePreferenceLoader.java
@@ -93,7 +93,7 @@
desc.packageName, 0, mUserHandle);
final Theme baseTheme = mFragment.getResources().newTheme();
baseTheme.applyStyle(
- com.android.settingslib.widget.R.style.Theme_SettingsBase, true);
+ com.android.settingslib.widget.theme.R.style.Theme_SettingsBase, true);
final Context themedCtx =
new LocalClassLoaderContextThemeWrapper(getClass(), targetCtx, 0);
themedCtx.getTheme().setTo(baseTheme);
diff --git a/src/com/android/settings/applications/appinfo/ExternalSourcesDetails.java b/src/com/android/settings/applications/appinfo/ExternalSourcesDetails.java
index 2d1375c..9a41f25 100644
--- a/src/com/android/settings/applications/appinfo/ExternalSourcesDetails.java
+++ b/src/com/android/settings/applications/appinfo/ExternalSourcesDetails.java
@@ -88,7 +88,7 @@
UserManager.DISALLOW_INSTALL_UNKNOWN_SOURCES_GLOBALLY,
userHandle);
if ((userRestrictionSource & UserManager.RESTRICTION_SOURCE_SYSTEM) != 0) {
- return context.getString(com.android.settingslib.widget.R.string.disabled_by_admin);
+ return context.getString(com.android.settingslib.widget.restricted.R.string.disabled_by_admin);
} else if (userRestrictionSource != 0) {
return context.getString(com.android.settingslib.R.string.disabled);
}
diff --git a/src/com/android/settings/applications/manageapplications/ApplicationViewHolder.java b/src/com/android/settings/applications/manageapplications/ApplicationViewHolder.java
index b8f1b4c..1f15aec 100644
--- a/src/com/android/settings/applications/manageapplications/ApplicationViewHolder.java
+++ b/src/com/android/settings/applications/manageapplications/ApplicationViewHolder.java
@@ -73,7 +73,7 @@
mAppName = itemView.findViewById(android.R.id.title);
mAppIcon = itemView.findViewById(android.R.id.icon);
mSummary = itemView.findViewById(android.R.id.summary);
- mDisabled = itemView.findViewById(com.android.settingslib.widget.R.id.appendix);
+ mDisabled = itemView.findViewById(com.android.settingslib.widget.preference.app.R.id.appendix);
mSwitch = itemView.findViewById(R.id.switchWidget);
mWidgetContainer = itemView.findViewById(android.R.id.widget_frame);
mAddIcon = itemView.findViewById(R.id.add_preference_widget);
@@ -86,7 +86,7 @@
static View newView(ViewGroup parent, boolean twoTarget, int listType) {
ViewGroup view = (ViewGroup) LayoutInflater.from(parent.getContext())
- .inflate(com.android.settingslib.widget.R.layout.preference_app, parent, false);
+ .inflate(com.android.settingslib.widget.preference.app.R.layout.preference_app, parent, false);
ViewGroup widgetFrame = view.findViewById(android.R.id.widget_frame);
if (twoTarget) {
if (widgetFrame != null) {
@@ -98,7 +98,7 @@
.inflate(R.layout.preference_widget_primary_switch, widgetFrame, true);
}
View divider = LayoutInflater.from(parent.getContext()).inflate(
- com.android.settingslib.widget.R.layout.preference_two_target_divider,
+ com.android.settingslib.widget.preference.twotarget.R.layout.preference_two_target_divider,
view, false);
// second to last, before widget frame
view.addView(divider, view.getChildCount() - 1);
@@ -111,7 +111,7 @@
static View newHeader(ViewGroup parent, int resText) {
ViewGroup view = (ViewGroup) LayoutInflater.from(parent.getContext())
- .inflate(com.android.settingslib.widget.R.layout.preference_app_header,
+ .inflate(com.android.settingslib.widget.preference.app.R.layout.preference_app_header,
parent, false);
TextView textView = view.findViewById(R.id.apps_top_intro_text);
textView.setText(resText);
diff --git a/src/com/android/settings/applications/specialaccess/interactacrossprofiles/InteractAcrossProfilesDetails.java b/src/com/android/settings/applications/specialaccess/interactacrossprofiles/InteractAcrossProfilesDetails.java
index 42d2db2..faa1b51 100644
--- a/src/com/android/settings/applications/specialaccess/interactacrossprofiles/InteractAcrossProfilesDetails.java
+++ b/src/com/android/settings/applications/specialaccess/interactacrossprofiles/InteractAcrossProfilesDetails.java
@@ -209,7 +209,7 @@
}
final ImageView personalIconView = mHeader.findViewById(
- com.android.settingslib.widget.R.id.entity_header_icon_personal);
+ com.android.settingslib.widget.preference.layout.R.id.entity_header_icon_personal);
if (personalIconView != null) {
Drawable icon = IconDrawableFactory.newInstance(mContext)
.getBadgedIcon(mPackageInfo.applicationInfo, personalProfile.getIdentifier())
@@ -221,7 +221,7 @@
}
final ImageView workIconView = mHeader.findViewById(
- com.android.settingslib.widget.R.id.entity_header_icon_work);
+ com.android.settingslib.widget.preference.layout.R.id.entity_header_icon_work);
if (workIconView != null) {
Drawable icon = IconDrawableFactory.newInstance(mContext)
.getBadgedIcon(mPackageInfo.applicationInfo, workProfile.getIdentifier())
@@ -502,11 +502,11 @@
mSwitchPref.setChecked(true);
mSwitchPref.setTitle(R.string.interact_across_profiles_switch_enabled);
final ImageView horizontalArrowIcon =
- mHeader.findViewById(com.android.settingslib.widget.R.id.entity_header_swap_horiz);
+ mHeader.findViewById(com.android.settingslib.widget.preference.layout.R.id.entity_header_swap_horiz);
if (horizontalArrowIcon != null) {
horizontalArrowIcon.setImageDrawable(
mContext.getDrawable(
- com.android.settingslib.widget.R.drawable.ic_swap_horiz_blue));
+ com.android.settingslib.widget.preference.layout.R.drawable.ic_swap_horiz_blue));
}
}
@@ -514,11 +514,11 @@
mSwitchPref.setChecked(false);
mSwitchPref.setTitle(R.string.interact_across_profiles_switch_disabled);
final ImageView horizontalArrowIcon =
- mHeader.findViewById(com.android.settingslib.widget.R.id.entity_header_swap_horiz);
+ mHeader.findViewById(com.android.settingslib.widget.preference.layout.R.id.entity_header_swap_horiz);
if (horizontalArrowIcon != null) {
horizontalArrowIcon.setImageDrawable(
mContext.getDrawable(
- com.android.settingslib.widget.R.drawable.ic_swap_horiz_grey));
+ com.android.settingslib.widget.preference.layout.R.drawable.ic_swap_horiz_grey));
}
}
diff --git a/src/com/android/settings/bluetooth/BluetoothBroadcastDialog.java b/src/com/android/settings/bluetooth/BluetoothBroadcastDialog.java
index 13f056d..2914cf4 100644
--- a/src/com/android/settings/bluetooth/BluetoothBroadcastDialog.java
+++ b/src/com/android/settings/bluetooth/BluetoothBroadcastDialog.java
@@ -113,7 +113,7 @@
});
mAlertDialog = new AlertDialog.Builder(mContext,
- com.android.settingslib.widget.R.style.Theme_AlertDialog_SettingsLib)
+ com.android.settingslib.widget.theme.R.style.Theme_AlertDialog_SettingsLib)
.setView(layout)
.create();
diff --git a/src/com/android/settings/bluetooth/BluetoothBroadcastSourcePreference.java b/src/com/android/settings/bluetooth/BluetoothBroadcastSourcePreference.java
index 6ec356e..d0fabc6 100644
--- a/src/com/android/settings/bluetooth/BluetoothBroadcastSourcePreference.java
+++ b/src/com/android/settings/bluetooth/BluetoothBroadcastSourcePreference.java
@@ -60,7 +60,7 @@
@Override
public void onBindViewHolder(final PreferenceViewHolder view) {
super.onBindViewHolder(view);
- view.findViewById(com.android.settingslib.widget.R.id.two_target_divider)
+ view.findViewById(com.android.settingslib.widget.preference.twotarget.R.id.two_target_divider)
.setVisibility(View.INVISIBLE);
final ImageButton imageButton =
(ImageButton) view.findViewById(com.android.settingslib.R.id.icon_button);
diff --git a/src/com/android/settings/core/SettingsBaseActivity.java b/src/com/android/settings/core/SettingsBaseActivity.java
index d5b3103..e43772e 100644
--- a/src/com/android/settings/core/SettingsBaseActivity.java
+++ b/src/com/android/settings/core/SettingsBaseActivity.java
@@ -111,9 +111,9 @@
if (isToolbarEnabled() && !isAnySetupWizard) {
super.setContentView(
- com.android.settingslib.widget.R.layout.collapsing_toolbar_base_layout);
+ com.android.settingslib.collapsingtoolbar.R.layout.collapsing_toolbar_base_layout);
mCollapsingToolbarLayout =
- findViewById(com.android.settingslib.widget.R.id.collapsing_toolbar);
+ findViewById(com.android.settingslib.collapsingtoolbar.R.id.collapsing_toolbar);
mAppBarLayout = findViewById(R.id.app_bar);
if (mCollapsingToolbarLayout != null) {
mCollapsingToolbarLayout.setLineSpacingMultiplier(TOOLBAR_LINE_SPACING_MULTIPLIER);
diff --git a/src/com/android/settings/datausage/AppDataUsage.java b/src/com/android/settings/datausage/AppDataUsage.java
index 1645586..c3be0aa 100644
--- a/src/com/android/settings/datausage/AppDataUsage.java
+++ b/src/com/android/settings/datausage/AppDataUsage.java
@@ -310,7 +310,7 @@
private void initCycle() {
mCycle = findPreference(KEY_CYCLE);
- mCycleAdapter = new CycleAdapter(mContext, mCycle, mCycleListener);
+ mCycleAdapter = new CycleAdapter(mContext, mCycle);
if (mCycles != null) {
// If coming from a page like DataUsageList where already has a selected cycle, display
// that before loading to reduce flicker.
@@ -435,7 +435,7 @@
return SettingsEnums.APP_DATA_USAGE;
}
- private AdapterView.OnItemSelectedListener mCycleListener =
+ private final AdapterView.OnItemSelectedListener mCycleListener =
new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
@@ -471,6 +471,7 @@
public void onLoadFinished(@NonNull Loader<List<NetworkCycleDataForUid>> loader,
List<NetworkCycleDataForUid> data) {
mUsageData = data;
+ mCycle.setOnItemSelectedListener(mCycleListener);
mCycleAdapter.updateCycleList(data);
if (mSelectedCycle > 0L) {
final int numCycles = data.size();
diff --git a/src/com/android/settings/datausage/ChartDataUsagePreference.java b/src/com/android/settings/datausage/ChartDataUsagePreference.java
index e2a103e..fa467d2 100644
--- a/src/com/android/settings/datausage/ChartDataUsagePreference.java
+++ b/src/com/android/settings/datausage/ChartDataUsagePreference.java
@@ -294,14 +294,6 @@
notifyChanged();
}
- public long getInspectStart() {
- return mStart;
- }
-
- public long getInspectEnd() {
- return mEnd;
- }
-
public void setNetworkCycleData(NetworkCycleChartData data) {
mNetworkCycleChartData = data;
mStart = data.getStartTime();
diff --git a/src/com/android/settings/datausage/CycleAdapter.java b/src/com/android/settings/datausage/CycleAdapter.java
index 2af4012..90a2035 100644
--- a/src/com/android/settings/datausage/CycleAdapter.java
+++ b/src/com/android/settings/datausage/CycleAdapter.java
@@ -14,7 +14,6 @@
package com.android.settings.datausage;
import android.content.Context;
-import android.widget.AdapterView;
import com.android.settings.Utils;
import com.android.settingslib.net.NetworkCycleData;
@@ -25,13 +24,10 @@
public class CycleAdapter extends SettingsSpinnerAdapter<CycleAdapter.CycleItem> {
private final SpinnerInterface mSpinner;
- private final AdapterView.OnItemSelectedListener mListener;
- public CycleAdapter(Context context, SpinnerInterface spinner,
- AdapterView.OnItemSelectedListener listener) {
+ public CycleAdapter(Context context, SpinnerInterface spinner) {
super(context);
mSpinner = spinner;
- mListener = listener;
mSpinner.setAdapter(this);
}
@@ -67,7 +63,6 @@
* updating the inspection range on chartData.
*/
public void updateCycleList(List<? extends NetworkCycleData> cycleData) {
- mSpinner.setOnItemSelectedListener(mListener);
// stash away currently selected cycle to try restoring below
final CycleAdapter.CycleItem previousItem = (CycleAdapter.CycleItem)
mSpinner.getSelectedItem();
@@ -122,8 +117,6 @@
public interface SpinnerInterface {
void setAdapter(CycleAdapter cycleAdapter);
- void setOnItemSelectedListener(AdapterView.OnItemSelectedListener listener);
-
Object getSelectedItem();
void setSelection(int position);
diff --git a/src/com/android/settings/datausage/DataUsageList.java b/src/com/android/settings/datausage/DataUsageList.java
index 15a5603..e7345ab 100644
--- a/src/com/android/settings/datausage/DataUsageList.java
+++ b/src/com/android/settings/datausage/DataUsageList.java
@@ -18,7 +18,6 @@
import android.app.settings.SettingsEnums;
import android.content.Context;
import android.content.Intent;
-import android.net.ConnectivityManager;
import android.net.NetworkPolicy;
import android.net.NetworkTemplate;
import android.os.Bundle;
@@ -28,11 +27,6 @@
import android.util.EventLog;
import android.util.Log;
import android.view.View;
-import android.view.View.AccessibilityDelegate;
-import android.view.accessibility.AccessibilityEvent;
-import android.widget.AdapterView;
-import android.widget.AdapterView.OnItemSelectedListener;
-import android.widget.Spinner;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
@@ -43,8 +37,6 @@
import androidx.preference.Preference;
import com.android.settings.R;
-import com.android.settings.core.SubSettingLauncher;
-import com.android.settings.datausage.CycleAdapter.SpinnerInterface;
import com.android.settings.datausage.lib.BillingCycleRepository;
import com.android.settings.network.MobileDataEnabledListener;
import com.android.settings.network.MobileNetworkRepository;
@@ -58,6 +50,8 @@
import java.util.Objects;
import java.util.Optional;
+import kotlin.Unit;
+
/**
* Panel showing data usage history across various networks, including options
* to inspect based on usage cycle and control through {@link NetworkPolicy}.
@@ -67,7 +61,6 @@
static final String EXTRA_SUB_ID = "sub_id";
static final String EXTRA_NETWORK_TEMPLATE = "network_template";
- static final String EXTRA_NETWORK_TYPE = "network_type";
private static final String TAG = "DataUsageList";
private static final boolean LOGD = false;
@@ -88,10 +81,6 @@
@VisibleForTesting
int mSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
@VisibleForTesting
- int mNetworkType;
- @VisibleForTesting
- Spinner mCycleSpinner;
- @VisibleForTesting
LoadingViewController mLoadingViewController;
private ChartDataUsagePreference mChart;
@@ -102,13 +91,15 @@
// Spinner will keep the selected cycle even after paused, this only keeps the displayed cycle,
// which need be cleared when resumed.
private CycleAdapter.CycleItem mLastDisplayedCycle;
- private CycleAdapter mCycleAdapter;
private Preference mUsageAmount;
- private View mHeader;
private MobileNetworkRepository mMobileNetworkRepository;
private SubscriptionInfoEntity mSubscriptionInfoEntity;
private DataUsageListAppsController mDataUsageListAppsController;
private BillingCycleRepository mBillingCycleRepository;
+ @VisibleForTesting
+ DataUsageListHeaderController mDataUsageListHeaderController;
+
+ private boolean mIsBillingCycleModifiable = false;
@Override
public int getMetricsCategory() {
@@ -158,50 +149,15 @@
public void onViewCreated(@NonNull View v, Bundle savedInstanceState) {
super.onViewCreated(v, savedInstanceState);
- mHeader = setPinnedHeaderView(R.layout.apps_filter_spinner);
- mHeader.findViewById(R.id.filter_settings).setOnClickListener(btn -> {
- final Bundle args = new Bundle();
- args.putParcelable(DataUsageList.EXTRA_NETWORK_TEMPLATE, mTemplate);
- new SubSettingLauncher(getContext())
- .setDestination(BillingCycleSettings.class.getName())
- .setTitleRes(R.string.billing_cycle)
- .setSourceMetricsCategory(getMetricsCategory())
- .setArguments(args)
- .launch();
- });
- mCycleSpinner = mHeader.findViewById(R.id.filter_spinner);
- mCycleSpinner.setVisibility(View.GONE);
- mCycleAdapter = new CycleAdapter(mCycleSpinner.getContext(), new SpinnerInterface() {
- @Override
- public void setAdapter(CycleAdapter cycleAdapter) {
- mCycleSpinner.setAdapter(cycleAdapter);
- }
-
- @Override
- public void setOnItemSelectedListener(OnItemSelectedListener listener) {
- mCycleSpinner.setOnItemSelectedListener(listener);
- }
-
- @Override
- public Object getSelectedItem() {
- return mCycleSpinner.getSelectedItem();
- }
-
- @Override
- public void setSelection(int position) {
- mCycleSpinner.setSelection(position);
- }
- }, mCycleListener);
- mCycleSpinner.setAccessibilityDelegate(new AccessibilityDelegate() {
- @Override
- public void sendAccessibilityEvent(View host, int eventType) {
- if (eventType == AccessibilityEvent.TYPE_VIEW_SELECTED) {
- // Ignore TYPE_VIEW_SELECTED or TalkBack will speak for it at onResume.
- return;
+ mDataUsageListHeaderController = new DataUsageListHeaderController(
+ setPinnedHeaderView(R.layout.apps_filter_spinner),
+ mTemplate,
+ getMetricsCategory(),
+ (cycle, position) -> {
+ updateSelectedCycle(cycle, position);
+ return Unit.INSTANCE;
}
- super.sendAccessibilityEvent(host, eventType);
- }
- });
+ );
mLoadingViewController = new LoadingViewController(
getView().findViewById(R.id.loading_container), getListView());
@@ -213,6 +169,7 @@
mLoadingViewController.showLoadingViewDelayed();
mDataStateListener.start(mSubId);
mLastDisplayedCycle = null;
+ updatePolicy();
// kick off loader for network history
// TODO: consider chaining two loaders together instead of reloading
@@ -244,7 +201,6 @@
if (args != null) {
mSubId = args.getInt(EXTRA_SUB_ID, SubscriptionManager.INVALID_SUBSCRIPTION_ID);
mTemplate = args.getParcelable(EXTRA_NETWORK_TEMPLATE);
- mNetworkType = args.getInt(EXTRA_NETWORK_TYPE, ConnectivityManager.TYPE_MOBILE);
}
if (mTemplate == null && mSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
final Intent intent = getIntent();
@@ -291,36 +247,31 @@
*/
@VisibleForTesting
void updatePolicy() {
- final NetworkPolicy policy = services.mPolicyEditor.getPolicy(mTemplate);
- final View configureButton = mHeader.findViewById(R.id.filter_settings);
- //SUB SELECT
- if (policy != null && isMobileDataAvailable()) {
- mChart.setNetworkPolicy(policy);
- configureButton.setVisibility(View.VISIBLE);
+ mIsBillingCycleModifiable = isBillingCycleModifiable();
+ if (mIsBillingCycleModifiable) {
+ mChart.setNetworkPolicy(services.mPolicyEditor.getPolicy(mTemplate));
} else {
- // controls are disabled; don't bind warning/limit sweeps
- mChart.setNetworkPolicy(null);
- configureButton.setVisibility(View.GONE);
+ mChart.setNetworkPolicy(null); // don't bind warning / limit sweeps
}
-
- // generate cycle list based on policy and available history
- if (mCycleData != null) {
- mCycleAdapter.updateCycleList(mCycleData);
- }
- mDataUsageListAppsController.setCycleData(mCycleData);
- updateSelectedCycle();
+ updateConfigButtonVisibility();
}
- private boolean isMobileDataAvailable() {
+ @VisibleForTesting
+ boolean isBillingCycleModifiable() {
return mBillingCycleRepository.isModifiable(mSubId)
&& SubscriptionManager.from(requireContext())
.getActiveSubscriptionInfo(mSubId) != null;
}
+ private void updateConfigButtonVisibility() {
+ mDataUsageListHeaderController.setConfigButtonVisible(
+ mIsBillingCycleModifiable && mCycleData != null);
+ }
+
/**
* Updates the chart and detail data when initial loaded or selected cycle changed.
*/
- private void updateSelectedCycle() {
+ private void updateSelectedCycle(CycleAdapter.CycleItem cycle, int position) {
// Avoid from updating UI after #onStop.
if (!getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED)) {
return;
@@ -332,11 +283,6 @@
return;
}
- final int position = mCycleSpinner.getSelectedItemPosition();
- if (mCycleAdapter.getCount() == 0 || position < 0) {
- return;
- }
- final CycleAdapter.CycleItem cycle = mCycleAdapter.getItem(position);
if (Objects.equals(cycle, mLastDisplayedCycle)) {
// Avoid duplicate update to avoid page flash.
return;
@@ -350,9 +296,10 @@
// update chart to show selected cycle, and update detail data
// to match updated sweep bounds.
- mChart.setNetworkCycleData(mCycleData.get(position));
+ NetworkCycleChartData cycleChartData = mCycleData.get(position);
+ mChart.setNetworkCycleData(cycleChartData);
- updateDetailData();
+ updateDetailData(cycleChartData);
}
/**
@@ -360,34 +307,21 @@
* current mode. Updates {@link #mAdapter} with sorted list
* of applications data usage.
*/
- private void updateDetailData() {
+ private void updateDetailData(NetworkCycleChartData cycleChartData) {
if (LOGD) Log.d(TAG, "updateDetailData()");
// kick off loader for detailed stats
mDataUsageListAppsController.update(
mSubscriptionInfoEntity == null ? null : mSubscriptionInfoEntity.carrierId,
- mChart.getInspectStart(),
- mChart.getInspectEnd()
+ cycleChartData.getStartTime(),
+ cycleChartData.getEndTime()
);
- final long totalBytes = mCycleData != null && !mCycleData.isEmpty()
- ? mCycleData.get(mCycleSpinner.getSelectedItemPosition()).getTotalUsage() : 0;
+ final long totalBytes = cycleChartData.getTotalUsage();
final CharSequence totalPhrase = DataUsageUtils.formatDataUsage(getActivity(), totalBytes);
mUsageAmount.setTitle(getString(R.string.data_used_template, totalPhrase));
}
- private final OnItemSelectedListener mCycleListener = new OnItemSelectedListener() {
- @Override
- public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
- updateSelectedCycle();
- }
-
- @Override
- public void onNothingSelected(AdapterView<?> parent) {
- // ignored
- }
- };
-
@VisibleForTesting
final LoaderCallbacks<List<NetworkCycleChartData>> mNetworkCycleDataCallbacks =
new LoaderCallbacks<>() {
@@ -404,9 +338,9 @@
List<NetworkCycleChartData> data) {
mLoadingViewController.showContent(false /* animate */);
mCycleData = data;
- // calculate policy cycles based on available data
- updatePolicy();
- mCycleSpinner.setVisibility(View.VISIBLE);
+ mDataUsageListHeaderController.updateCycleData(mCycleData);
+ updateConfigButtonVisibility();
+ mDataUsageListAppsController.setCycleData(mCycleData);
}
@Override
diff --git a/src/com/android/settings/datausage/DataUsageListHeaderController.kt b/src/com/android/settings/datausage/DataUsageListHeaderController.kt
new file mode 100644
index 0000000..e295a4c
--- /dev/null
+++ b/src/com/android/settings/datausage/DataUsageListHeaderController.kt
@@ -0,0 +1,103 @@
+/*
+ * 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.datausage
+
+import android.net.NetworkTemplate
+import android.os.Bundle
+import android.view.View
+import android.view.accessibility.AccessibilityEvent
+import android.widget.AdapterView
+import android.widget.Spinner
+import androidx.annotation.OpenForTesting
+import com.android.settings.R
+import com.android.settings.core.SubSettingLauncher
+import com.android.settings.datausage.CycleAdapter.CycleItem
+import com.android.settings.datausage.CycleAdapter.SpinnerInterface
+import com.android.settingslib.net.NetworkCycleChartData
+
+@OpenForTesting
+open class DataUsageListHeaderController(
+ header: View,
+ template: NetworkTemplate,
+ sourceMetricsCategory: Int,
+ private val onItemSelected: (cycleItem: CycleItem, position: Int) -> Unit,
+) {
+ private val context = header.context
+ private val configureButton: View = header.requireViewById(R.id.filter_settings)
+ private val cycleSpinner: Spinner = header.requireViewById(R.id.filter_spinner)
+ private val cycleAdapter = CycleAdapter(context, object : SpinnerInterface {
+ override fun setAdapter(cycleAdapter: CycleAdapter) {
+ cycleSpinner.adapter = cycleAdapter
+ }
+
+ override fun getSelectedItem() = cycleSpinner.selectedItem
+
+ override fun setSelection(position: Int) {
+ cycleSpinner.setSelection(position)
+ }
+ })
+
+ private val cycleListener = object : AdapterView.OnItemSelectedListener {
+ override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) {
+ if (0 <= position && position < cycleAdapter.count) {
+ cycleAdapter.getItem(position)?.let { cycleItem ->
+ onItemSelected(cycleItem, position)
+ }
+ }
+ }
+
+ override fun onNothingSelected(parent: AdapterView<*>?) {
+ // ignored
+ }
+ }
+
+ init {
+ configureButton.setOnClickListener {
+ val args = Bundle().apply {
+ putParcelable(DataUsageList.EXTRA_NETWORK_TEMPLATE, template)
+ }
+ SubSettingLauncher(context).apply {
+ setDestination(BillingCycleSettings::class.java.name)
+ setTitleRes(R.string.billing_cycle)
+ setSourceMetricsCategory(sourceMetricsCategory)
+ setArguments(args)
+ }.launch()
+ }
+ cycleSpinner.visibility = View.GONE
+ cycleSpinner.accessibilityDelegate = object : View.AccessibilityDelegate() {
+ override fun sendAccessibilityEvent(host: View, eventType: Int) {
+ if (eventType == AccessibilityEvent.TYPE_VIEW_SELECTED) {
+ // Ignore TYPE_VIEW_SELECTED or TalkBack will speak for it at onResume.
+ return
+ }
+ super.sendAccessibilityEvent(host, eventType)
+ }
+ }
+ }
+
+ open fun setConfigButtonVisible(visible: Boolean) {
+ configureButton.visibility = if (visible) View.VISIBLE else View.GONE
+ }
+
+ open fun updateCycleData(cycleData: List<NetworkCycleChartData>) {
+ cycleSpinner.onItemSelectedListener = cycleListener
+ // calculate policy cycles based on available data
+ // generate cycle list based on policy and available history
+ cycleAdapter.updateCycleList(cycleData)
+ cycleSpinner.visibility = View.VISIBLE
+ }
+}
diff --git a/src/com/android/settings/datausage/DataUsagePreference.java b/src/com/android/settings/datausage/DataUsagePreference.java
index 0f7bf58..07368c7 100644
--- a/src/com/android/settings/datausage/DataUsagePreference.java
+++ b/src/com/android/settings/datausage/DataUsagePreference.java
@@ -18,7 +18,6 @@
import android.content.Context;
import android.content.Intent;
import android.content.res.TypedArray;
-import android.net.ConnectivityManager;
import android.net.NetworkTemplate;
import android.os.Bundle;
import android.util.AttributeSet;
@@ -78,9 +77,6 @@
final SubSettingLauncher launcher;
args.putParcelable(DataUsageList.EXTRA_NETWORK_TEMPLATE, mTemplate);
args.putInt(DataUsageList.EXTRA_SUB_ID, mSubId);
- args.putInt(DataUsageList.EXTRA_NETWORK_TYPE, mTemplate.getMatchRule()
- == NetworkTemplate.MATCH_MOBILE
- ? ConnectivityManager.TYPE_MOBILE : ConnectivityManager.TYPE_WIFI);
launcher = new SubSettingLauncher(getContext())
.setArguments(args)
.setDestination(DataUsageList.class.getName())
diff --git a/src/com/android/settings/datausage/SpinnerPreference.java b/src/com/android/settings/datausage/SpinnerPreference.java
index c6b5f9f..a705079 100644
--- a/src/com/android/settings/datausage/SpinnerPreference.java
+++ b/src/com/android/settings/datausage/SpinnerPreference.java
@@ -47,7 +47,6 @@
notifyChanged();
}
- @Override
public void setOnItemSelectedListener(AdapterView.OnItemSelectedListener listener) {
mListener = listener;
}
diff --git a/src/com/android/settings/datausage/UnrestrictedDataAccessPreference.java b/src/com/android/settings/datausage/UnrestrictedDataAccessPreference.java
index 4921a339..347c237 100644
--- a/src/com/android/settings/datausage/UnrestrictedDataAccessPreference.java
+++ b/src/com/android/settings/datausage/UnrestrictedDataAccessPreference.java
@@ -176,7 +176,7 @@
if (mDataUsageState != null) {
setChecked(mDataUsageState.isDataSaverAllowlisted);
if (isDisabledByAdmin()) {
- setSummary(com.android.settingslib.widget.R.string.disabled_by_admin);
+ setSummary(com.android.settingslib.widget.restricted.R.string.disabled_by_admin);
} else if (mDataUsageState.isDataSaverDenylisted) {
setSummary(R.string.restrict_background_blocklisted);
} else {
diff --git a/src/com/android/settings/development/AppViewHolder.java b/src/com/android/settings/development/AppViewHolder.java
index 3e34275..6bdf454 100644
--- a/src/com/android/settings/development/AppViewHolder.java
+++ b/src/com/android/settings/development/AppViewHolder.java
@@ -36,7 +36,7 @@
static public AppViewHolder createOrRecycle(LayoutInflater inflater, View convertView) {
if (convertView == null) {
convertView =
- inflater.inflate(com.android.settingslib.widget.R.layout.preference_app, null);
+ inflater.inflate(com.android.settingslib.widget.preference.app.R.layout.preference_app, null);
// Creates a ViewHolder and store references to the two children views
// we want to bind data to.
@@ -46,7 +46,7 @@
holder.appIcon = convertView.findViewById(android.R.id.icon);
holder.summary = convertView.findViewById(android.R.id.summary);
holder.disabled =
- convertView.findViewById(com.android.settingslib.widget.R.id.appendix);
+ convertView.findViewById(com.android.settingslib.widget.preference.app.R.id.appendix);
holder.widget = convertView.findViewById(android.R.id.widget_frame);
convertView.setTag(holder);
return holder;
diff --git a/src/com/android/settings/display/ScreenResolutionFragment.java b/src/com/android/settings/display/ScreenResolutionFragment.java
index bb1d910..622e665 100644
--- a/src/com/android/settings/display/ScreenResolutionFragment.java
+++ b/src/com/android/settings/display/ScreenResolutionFragment.java
@@ -108,7 +108,7 @@
footerPreference.setTitle(R.string.screen_resolution_footer);
footerPreference.setSelectable(false);
footerPreference.setLayoutResource(
- com.android.settingslib.widget.R.layout.preference_footer);
+ com.android.settingslib.widget.preference.footer.R.layout.preference_footer);
screen.addPreference(footerPreference);
}
diff --git a/src/com/android/settings/display/ScreenTimeoutSettings.java b/src/com/android/settings/display/ScreenTimeoutSettings.java
index fb6ddb8..43dd31c 100644
--- a/src/com/android/settings/display/ScreenTimeoutSettings.java
+++ b/src/com/android/settings/display/ScreenTimeoutSettings.java
@@ -129,7 +129,7 @@
mPrivacyPreference.setTitle(R.string.adaptive_sleep_privacy);
mPrivacyPreference.setSelectable(false);
mPrivacyPreference.setLayoutResource(
- com.android.settingslib.widget.R.layout.preference_footer);
+ com.android.settingslib.widget.preference.footer.R.layout.preference_footer);
mPrivacyManager = SensorPrivacyManager.getInstance(context);
mPrivacyChangedListener = (sensor, enabled) -> mAdaptiveSleepController.updatePreference();
}
@@ -203,7 +203,7 @@
mPrivacyPreference.setTitle(R.string.adaptive_sleep_privacy);
mPrivacyPreference.setSelectable(false);
mPrivacyPreference.setLayoutResource(
- com.android.settingslib.widget.R.layout.preference_footer);
+ com.android.settingslib.widget.preference.footer.R.layout.preference_footer);
if (isScreenAttentionAvailable(getContext())) {
mAdaptiveSleepPermissionController.addToScreen(screen);
diff --git a/src/com/android/settings/network/NetworkProviderSettings.java b/src/com/android/settings/network/NetworkProviderSettings.java
index f2688c6..eb50cea 100644
--- a/src/com/android/settings/network/NetworkProviderSettings.java
+++ b/src/com/android/settings/network/NetworkProviderSettings.java
@@ -271,7 +271,7 @@
return;
}
- setPinnedHeaderView(com.android.settingslib.widget.R.layout.progress_header);
+ setPinnedHeaderView(com.android.settingslib.widget.progressbar.R.layout.progress_header);
setProgressBarVisible(false);
if (hasWifiManager()) {
diff --git a/src/com/android/settings/network/telephony/BackupCallingPreferenceController.java b/src/com/android/settings/network/telephony/BackupCallingPreferenceController.java
deleted file mode 100644
index 4f64399..0000000
--- a/src/com/android/settings/network/telephony/BackupCallingPreferenceController.java
+++ /dev/null
@@ -1,197 +0,0 @@
-/*
- * Copyright (C) 2020 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;
-
-import android.content.Context;
-import android.os.PersistableBundle;
-import android.telephony.CarrierConfigManager;
-import android.telephony.SubscriptionInfo;
-import android.telephony.SubscriptionManager;
-import android.telephony.ims.ImsException;
-import android.telephony.ims.ImsManager;
-import android.telephony.ims.ImsMmTelManager;
-import android.util.Log;
-
-import androidx.preference.Preference;
-import androidx.preference.SwitchPreference;
-
-import com.android.settings.R;
-import com.android.settings.network.SubscriptionUtil;
-import com.android.settings.network.ims.WifiCallingQueryImsState;
-
-import java.util.List;
-import java.util.Objects;
-
-/**
- * Preference controller for "Backup Calling"
- **/
-public class BackupCallingPreferenceController extends TelephonyTogglePreferenceController {
-
- private static final String LOG_TAG = "BackupCallingPrefCtrl";
-
- private Preference mPreference;
-
- /**
- * Class constructor of backup calling.
- *
- * @param context of settings
- * @param key assigned within UI entry of XML file
- **/
- public BackupCallingPreferenceController(Context context, String key) {
- super(context, key);
- }
-
- /**
- * Initialization based on given subscription id.
- *
- * @param subId is the subscription id
- * @return this instance after initialization
- **/
- public BackupCallingPreferenceController init(int subId) {
- mSubId = subId;
- return this;
- }
-
- @Override
- public int getAvailabilityStatus(int subId) {
- if (!hasBackupCallingFeature(subId)) {
- return CONDITIONALLY_UNAVAILABLE;
- }
- List<SubscriptionInfo> subIdList = getActiveSubscriptionList();
- SubscriptionInfo subInfo = getSubscriptionInfoFromList(subIdList, subId);
- if (subInfo == null) { // given subId is not actives
- return CONDITIONALLY_UNAVAILABLE;
- }
- return (subIdList.size() > 1) ? AVAILABLE : CONDITIONALLY_UNAVAILABLE;
- }
-
- /**
- * Implementation of abstract methods
- **/
- public boolean setChecked(boolean isChecked) {
- ImsMmTelManager imsMmTelMgr = getImsMmTelManager(mSubId);
- if (imsMmTelMgr == null) {
- return false;
- }
- try {
- imsMmTelMgr.setCrossSimCallingEnabled(isChecked);
- } catch (ImsException exception) {
- Log.w(LOG_TAG, "fail to change cross SIM calling configuration: " + isChecked,
- exception);
- return false;
- }
- return true;
- }
-
- /**
- * Implementation of abstract methods
- **/
- public boolean isChecked() {
- ImsMmTelManager imsMmTelMgr = getImsMmTelManager(mSubId);
- if (imsMmTelMgr == null) {
- return false;
- }
- try {
- return imsMmTelMgr.isCrossSimCallingEnabled();
- } catch (ImsException exception) {
- Log.w(LOG_TAG, "fail to get cross SIM calling configuration", exception);
- }
- return false;
- }
-
- @Override
- public void updateState(Preference preference) {
- super.updateState(preference);
- if ((preference == null) || (!(preference instanceof SwitchPreference))) {
- return;
- }
- SubscriptionInfo subInfo = getSubscriptionInfoFromActiveList(mSubId);
-
- mPreference = preference;
-
- final SwitchPreference switchPreference = (SwitchPreference) preference;
- switchPreference.setChecked((subInfo != null) ? isChecked() : false);
-
- updateSummary(getLatestSummary(subInfo));
- }
-
- private String getLatestSummary(SubscriptionInfo subInfo) {
- return Objects.toString((subInfo == null) ? null
- : SubscriptionUtil.getUniqueSubscriptionDisplayName(subInfo, mContext), "");
- }
-
- private void updateSummary(String displayName) {
- Preference preference = mPreference;
- if (preference == null) {
- return;
- }
- String summary = displayName;
- String finalText = String.format(
- getResourcesForSubId().getString(R.string.backup_calling_setting_summary),
- summary)
- .toString();
- preference.setSummary(finalText);
- }
-
- private boolean hasBackupCallingFeature(int subscriptionId) {
- return isCrossSimEnabledByPlatform(mContext, subscriptionId);
- }
-
- protected boolean isCrossSimEnabledByPlatform(Context context, int subscriptionId) {
- // TODO : Change into API which created for accessing
- // com.android.ims.ImsManager#isCrossSimEnabledByPlatform()
- if ((new WifiCallingQueryImsState(context, subscriptionId)).isWifiCallingSupported()) {
- PersistableBundle bundle = getCarrierConfigForSubId(subscriptionId);
- return (bundle != null) && bundle.getBoolean(
- CarrierConfigManager.KEY_CARRIER_CROSS_SIM_IMS_AVAILABLE_BOOL,
- false /*default*/);
- }
- Log.d(LOG_TAG, "Not supported by framework. subId = " + subscriptionId);
- return false;
- }
-
- private ImsMmTelManager getImsMmTelManager(int subId) {
- if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
- return null;
- }
- ImsManager imsMgr = mContext.getSystemService(ImsManager.class);
- return (imsMgr == null) ? null : imsMgr.getImsMmTelManager(subId);
- }
-
- private List<SubscriptionInfo> getActiveSubscriptionList() {
- SubscriptionManager subscriptionManager =
- mContext.getSystemService(SubscriptionManager.class);
- return SubscriptionUtil.getActiveSubscriptions(subscriptionManager);
- }
-
- private SubscriptionInfo getSubscriptionInfoFromList(
- List<SubscriptionInfo> subInfoList, int subId) {
- for (SubscriptionInfo subInfo : subInfoList) {
- if ((subInfo != null) && (subInfo.getSubscriptionId() == subId)) {
- return subInfo;
- }
- }
- return null;
- }
-
- private SubscriptionInfo getSubscriptionInfoFromActiveList(int subId) {
- if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
- return null;
- }
- return getSubscriptionInfoFromList(getActiveSubscriptionList(), subId);
- }
-}
diff --git a/src/com/android/settings/network/telephony/NetworkProviderBackupCallingGroup.java b/src/com/android/settings/network/telephony/NetworkProviderBackupCallingGroup.java
deleted file mode 100644
index 58dd18f..0000000
--- a/src/com/android/settings/network/telephony/NetworkProviderBackupCallingGroup.java
+++ /dev/null
@@ -1,289 +0,0 @@
-/*
- * Copyright (C) 2021 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;
-
-import static androidx.lifecycle.Lifecycle.Event;
-
-import android.content.Context;
-import android.os.PersistableBundle;
-import android.telephony.CarrierConfigManager;
-import android.telephony.SubscriptionInfo;
-import android.telephony.SubscriptionManager;
-import android.telephony.TelephonyManager;
-import android.telephony.ims.ImsException;
-import android.telephony.ims.ImsManager;
-import android.telephony.ims.ImsMmTelManager;
-import android.util.ArrayMap;
-import android.util.Log;
-
-import androidx.annotation.VisibleForTesting;
-import androidx.lifecycle.LifecycleObserver;
-import androidx.lifecycle.OnLifecycleEvent;
-import androidx.preference.Preference;
-import androidx.preference.PreferenceGroup;
-import androidx.preference.PreferenceScreen;
-import androidx.preference.SwitchPreference;
-
-import com.android.settings.R;
-import com.android.settings.network.SubscriptionUtil;
-import com.android.settings.network.SubscriptionsChangeListener;
-import com.android.settings.network.ims.WifiCallingQueryImsState;
-import com.android.settingslib.core.lifecycle.Lifecycle;
-
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-/**
- * Preference controller for "Backup Calling"
- **/
-public class NetworkProviderBackupCallingGroup extends
- TelephonyTogglePreferenceController implements LifecycleObserver,
- SubscriptionsChangeListener.SubscriptionsChangeListenerClient {
- private static final String TAG = "NetworkProviderBackupCallingGroup";
- private static final String KEY_PREFERENCE_BACKUPCALLING_GROUP =
- "provider_model_backup_call_group";
- private static final int PREF_START_ORDER = 10;
-
- private String mPreferenceGroupKey;
- private PreferenceGroup mPreferenceGroup;
- private Map<Integer, SwitchPreference> mBackupCallingForSubPreferences;
- private List<SubscriptionInfo> mSubInfoListForBackupCall;
- private Map<Integer, TelephonyManager> mTelephonyManagerList = new HashMap<>();
- private SubscriptionsChangeListener mSubscriptionsChangeListener;
-
- public NetworkProviderBackupCallingGroup(Context context, Lifecycle lifecycle,
- List<SubscriptionInfo> subscriptionList, String preferenceGroupKey) {
- super(context, preferenceGroupKey);
- mPreferenceGroupKey = preferenceGroupKey;
- mSubInfoListForBackupCall = subscriptionList;
- mBackupCallingForSubPreferences = new ArrayMap<>();
- setSubscriptionInfoList(context);
- lifecycle.addObserver(this);
- }
-
- @OnLifecycleEvent(Event.ON_RESUME)
- public void onResume() {
- if (mSubscriptionsChangeListener == null) {
- mSubscriptionsChangeListener = new SubscriptionsChangeListener(mContext, this);
- }
- mSubscriptionsChangeListener.start();
- }
-
- @OnLifecycleEvent(Event.ON_PAUSE)
- public void onPause() {
- if (mSubscriptionsChangeListener != null) {
- mSubscriptionsChangeListener.stop();
- }
- }
-
- @Override
- public int getAvailabilityStatus(int subId) {
- if (mSubInfoListForBackupCall == null
- || getSubscriptionInfoFromList(mSubInfoListForBackupCall, subId) == null) {
- return CONDITIONALLY_UNAVAILABLE;
- }
-
- return (mSubInfoListForBackupCall.size() > 1) ? AVAILABLE : CONDITIONALLY_UNAVAILABLE;
- }
-
- private boolean setCrossSimCallingEnabled(int subId, boolean checked) {
- ImsMmTelManager imsMmTelMgr = getImsMmTelManager(subId);
- if (imsMmTelMgr == null) {
- Log.d(TAG, "setCrossSimCallingEnabled(), ImsMmTelManager is null");
- return false;
- }
-
- try {
- imsMmTelMgr.setCrossSimCallingEnabled(checked);
- } catch (ImsException exception) {
- Log.w(TAG, "fail to get cross SIM calling configuration", exception);
- return false;
- }
- return true;
- }
-
- @Override
- public boolean setChecked(boolean checked) {
- return false;
- }
-
- private boolean isCrossSimCallingEnabled(int subId) {
- ImsMmTelManager imsMmTelMgr = getImsMmTelManager(subId);
- if (imsMmTelMgr == null) {
- Log.d(TAG, "isCrossSimCallingEnabled(), ImsMmTelManager is null");
- return false;
- }
- try {
- return imsMmTelMgr.isCrossSimCallingEnabled();
- } catch (ImsException exception) {
- Log.w(TAG, "fail to get cross SIM calling configuration", exception);
- }
- return false;
- }
-
- @Override
- public boolean isChecked() {
- return false;
- }
-
- @Override
- public void displayPreference(PreferenceScreen screen) {
- mPreferenceGroup = screen.findPreference(mPreferenceGroupKey);
- update();
- }
-
- @Override
- public void updateState(Preference preference) {
- super.updateState(preference);
- // Do nothing in this case since preference is invisible
- if (preference == null) {
- return;
- }
- update();
- }
-
- private void update() {
- if (mPreferenceGroup == null) {
- return;
- }
-
- setSubscriptionInfoList(mContext);
- if (mSubInfoListForBackupCall == null || mSubInfoListForBackupCall.size() < 2) {
- for (SwitchPreference pref : mBackupCallingForSubPreferences.values()) {
- mPreferenceGroup.removePreference(pref);
- }
- mBackupCallingForSubPreferences.clear();
- return;
- }
-
- Map<Integer, SwitchPreference> toRemovePreferences = mBackupCallingForSubPreferences;
- mBackupCallingForSubPreferences = new ArrayMap<>();
- setSubscriptionInfoForPreference(toRemovePreferences);
- }
-
- private void setSubscriptionInfoForPreference(
- Map<Integer, SwitchPreference> toRemovePreferences) {
- int order = PREF_START_ORDER;
- for (SubscriptionInfo subInfo : mSubInfoListForBackupCall) {
- final int subId = subInfo.getSubscriptionId();
-
- SwitchPreference pref = toRemovePreferences.remove(subId);
- if (pref == null) {
- pref = new SwitchPreference(mPreferenceGroup.getContext());
- mPreferenceGroup.addPreference(pref);
- }
-
- CharSequence displayName = (subInfo == null) ? ""
- : SubscriptionUtil.getUniqueSubscriptionDisplayName(subInfo, mContext);
- pref.setTitle(displayName);
- pref.setOrder(order++);
- pref.setSummary(getSummary(displayName));
- boolean enabled = isCrossSimCallingEnabled(subId);
- pref.setChecked(enabled);
- pref.setOnPreferenceClickListener(clickedPref -> {
- setCrossSimCallingEnabled(subId, !enabled);
- return true;
- });
- mBackupCallingForSubPreferences.put(subId, pref);
- }
- }
-
- private String getSummary(CharSequence displayName) {
- String summary = String.format(
- getResourcesForSubId().getString(R.string.backup_calling_setting_summary),
- displayName)
- .toString();
- return summary;
- }
-
- private void setSubscriptionInfoList(Context context) {
- if (mSubInfoListForBackupCall != null) {
- mSubInfoListForBackupCall.removeIf(info -> {
- int subId = info.getSubscriptionId();
- setTelephonyManagerForSubscriptionId(context, subId);
- if (!hasBackupCallingFeature(subId) && mSubInfoListForBackupCall.contains(info)) {
- return true;
- }
- return false;
- });
- } else {
- Log.d(TAG, "No active subscriptions");
- }
- }
-
- private void setTelephonyManagerForSubscriptionId(Context context, int subId) {
- TelephonyManager telephonyManager = context.getSystemService(TelephonyManager.class)
- .createForSubscriptionId(subId);
- mTelephonyManagerList.put(subId, telephonyManager);
- }
-
- @VisibleForTesting
- protected boolean hasBackupCallingFeature(int subscriptionId) {
- return isCrossSimEnabledByPlatform(mContext, subscriptionId);
- }
-
- /**
- * Copied from {@link BackupCallingPreferenceController}
- **/
- @VisibleForTesting
- protected boolean isCrossSimEnabledByPlatform(Context context, int subscriptionId) {
- // TODO : Change into API which created for accessing
- // com.android.ims.ImsManager#isCrossSimEnabledByPlatform()
- if ((new WifiCallingQueryImsState(context, subscriptionId)).isWifiCallingSupported()) {
- PersistableBundle bundle = getCarrierConfigForSubId(subscriptionId);
- return (bundle != null) && bundle.getBoolean(
- CarrierConfigManager.KEY_CARRIER_CROSS_SIM_IMS_AVAILABLE_BOOL,
- false /*default*/);
- }
- Log.d(TAG, "WifiCalling is not supported by framework. subId = " + subscriptionId);
- return false;
- }
-
- private ImsMmTelManager getImsMmTelManager(int subId) {
- if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
- return null;
- }
- ImsManager imsMgr = mContext.getSystemService(ImsManager.class);
- return (imsMgr == null) ? null : imsMgr.getImsMmTelManager(subId);
- }
-
- private SubscriptionInfo getSubscriptionInfoFromList(
- List<SubscriptionInfo> subInfoList, int subId) {
- for (SubscriptionInfo subInfo : subInfoList) {
- if ((subInfo != null) && (subInfo.getSubscriptionId() == subId)) {
- return subInfo;
- }
- }
- return null;
- }
-
- @Override
- public String getPreferenceKey() {
- return KEY_PREFERENCE_BACKUPCALLING_GROUP;
- }
-
- @Override
- public void onAirplaneModeChanged(boolean airplaneModeEnabled) {}
-
- @Override
- public void onSubscriptionsChanged() {
- SubscriptionManager subscriptionManager =
- mContext.getSystemService(SubscriptionManager.class);
- mSubInfoListForBackupCall = SubscriptionUtil.getActiveSubscriptions(subscriptionManager);
- update();
- }
-}
diff --git a/src/com/android/settings/network/telephony/NetworkProviderBackupCallingPreferenceController.java b/src/com/android/settings/network/telephony/NetworkProviderBackupCallingPreferenceController.java
deleted file mode 100644
index 5c336ef..0000000
--- a/src/com/android/settings/network/telephony/NetworkProviderBackupCallingPreferenceController.java
+++ /dev/null
@@ -1,96 +0,0 @@
-/*
- * Copyright (C) 2020 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;
-
-import android.content.Context;
-import android.telephony.SubscriptionInfo;
-import android.telephony.SubscriptionManager;
-
-import androidx.preference.PreferenceCategory;
-import androidx.preference.PreferenceScreen;
-
-import com.android.settings.core.BasePreferenceController;
-import com.android.settings.network.SubscriptionUtil;
-import com.android.settingslib.core.lifecycle.Lifecycle;
-import com.android.settingslib.core.lifecycle.LifecycleObserver;
-
-import java.util.List;
-
-/**
- * Preference controller for "Backup Calling" summary list
- */
-public class NetworkProviderBackupCallingPreferenceController extends
- BasePreferenceController implements LifecycleObserver {
-
- private static final String TAG = "NetProvBackupCallingCtrl";
- private static final String KEY_PREFERENCE_CATEGORY = "provider_model_backup_calling_category";
-
- private PreferenceCategory mPreferenceCategory;
- private PreferenceScreen mPreferenceScreen;
- private NetworkProviderBackupCallingGroup mNetworkProviderBackupCallingGroup;
- private List<SubscriptionInfo> mSubscriptionList;
-
- /**
- * Preference controller for "Backup Calling" summary list
- */
- public NetworkProviderBackupCallingPreferenceController(Context context, String key) {
- super(context, key);
- }
-
- protected NetworkProviderBackupCallingGroup createBackupCallingControllerForSub(
- Lifecycle lifecycle, List<SubscriptionInfo> subscriptionList) {
- return new NetworkProviderBackupCallingGroup(mContext, lifecycle, subscriptionList,
- KEY_PREFERENCE_CATEGORY);
- }
-
- /**
- * Initialize the binding with Lifecycle
- *
- * @param lifecycle Lifecycle of UI which owns this Preference
- */
- public void init(Lifecycle lifecycle) {
- mSubscriptionList = getActiveSubscriptionList();
- mNetworkProviderBackupCallingGroup = createBackupCallingControllerForSub(lifecycle,
- mSubscriptionList);
- }
-
- private List<SubscriptionInfo> getActiveSubscriptionList() {
- SubscriptionManager subscriptionManager =
- mContext.getSystemService(SubscriptionManager.class);
- return SubscriptionUtil.getActiveSubscriptions(subscriptionManager);
- }
-
- @Override
- public int getAvailabilityStatus() {
- if (mNetworkProviderBackupCallingGroup == null
- || mSubscriptionList == null
- || mSubscriptionList.size() < 2) {
- return CONDITIONALLY_UNAVAILABLE;
- } else {
- return AVAILABLE;
- }
- }
-
- @Override
- public void displayPreference(PreferenceScreen screen) {
- super.displayPreference(screen);
- mPreferenceScreen = screen;
- mPreferenceCategory = screen.findPreference(KEY_PREFERENCE_CATEGORY);
- mPreferenceCategory.setVisible(isAvailable());
- mNetworkProviderBackupCallingGroup.displayPreference(screen);
- }
-}
diff --git a/src/com/android/settings/network/telephony/NetworkSelectSettings.java b/src/com/android/settings/network/telephony/NetworkSelectSettings.java
index a7623a2..1cfa043 100644
--- a/src/com/android/settings/network/telephony/NetworkSelectSettings.java
+++ b/src/com/android/settings/network/telephony/NetworkSelectSettings.java
@@ -195,8 +195,8 @@
final Activity activity = getActivity();
if (activity != null) {
mProgressHeader = setPinnedHeaderView(
- com.android.settingslib.widget.R.layout.progress_header)
- .findViewById(com.android.settingslib.widget.R.id.progress_bar_animation);
+ com.android.settingslib.widget.progressbar.R.layout.progress_header)
+ .findViewById(com.android.settingslib.widget.progressbar.R.id.progress_bar_animation);
setProgressBarVisible(false);
}
forceUpdateConnectedPreferenceCategory();
diff --git a/src/com/android/settings/nfc/AndroidBeam.java b/src/com/android/settings/nfc/AndroidBeam.java
index d10873c..9df24a5 100644
--- a/src/com/android/settings/nfc/AndroidBeam.java
+++ b/src/com/android/settings/nfc/AndroidBeam.java
@@ -85,7 +85,7 @@
return new View(getContext());
}
mView = inflater.inflate(
- com.android.settingslib.widget.R.layout.preference_footer, container, false);
+ com.android.settingslib.widget.preference.footer.R.layout.preference_footer, container, false);
ImageView iconInfo = mView.findViewById(android.R.id.icon);
iconInfo.setImageResource(R.drawable.ic_info_outline_24dp);
diff --git a/src/com/android/settings/search/actionbar/SearchMenuController.java b/src/com/android/settings/search/actionbar/SearchMenuController.java
index 8d0c89a..453832d 100644
--- a/src/com/android/settings/search/actionbar/SearchMenuController.java
+++ b/src/com/android/settings/search/actionbar/SearchMenuController.java
@@ -86,8 +86,8 @@
return;
}
final MenuItem searchItem = menu.add(Menu.NONE, MENU_SEARCH, 0 /* order */,
- com.android.settingslib.search.R.string.search_menu);
- searchItem.setIcon(com.android.settingslib.search.R.drawable.ic_search_24dp);
+ com.android.settingslib.search.widget.R.string.search_menu);
+ searchItem.setIcon(com.android.settingslib.search.widget.R.drawable.ic_search_24dp);
searchItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
searchItem.setOnMenuItemClickListener(target -> {
diff --git a/src/com/android/settings/security/CredentialManagementAppHeaderController.java b/src/com/android/settings/security/CredentialManagementAppHeaderController.java
index 693857e..03720e6 100644
--- a/src/com/android/settings/security/CredentialManagementAppHeaderController.java
+++ b/src/com/android/settings/security/CredentialManagementAppHeaderController.java
@@ -83,7 +83,7 @@
TextView titleView = headerPref.findViewById(R.id.entity_header_title);
TextView summary1 = headerPref.findViewById(R.id.entity_header_summary);
TextView summary2 = headerPref.findViewById(
- com.android.settingslib.widget.R.id.entity_header_second_summary);
+ com.android.settingslib.widget.preference.layout.R.id.entity_header_second_summary);
summary2.setVisibility(View.GONE);
try {
diff --git a/src/com/android/settings/slices/SettingsSliceProvider.java b/src/com/android/settings/slices/SettingsSliceProvider.java
index f9e0091..fdae1d0 100644
--- a/src/com/android/settings/slices/SettingsSliceProvider.java
+++ b/src/com/android/settings/slices/SettingsSliceProvider.java
@@ -227,7 +227,7 @@
final boolean nightMode = Utils.isNightMode(getContext());
if (mNightMode == null) {
mNightMode = nightMode;
- getContext().setTheme(com.android.settingslib.widget.R.style.Theme_SettingsBase);
+ getContext().setTheme(com.android.settingslib.widget.theme.R.style.Theme_SettingsBase);
} else if (mNightMode != nightMode) {
Log.d(TAG, "Night mode changed, reload theme");
mNightMode = nightMode;
diff --git a/src/com/android/settings/vpn2/VpnInfoPreference.java b/src/com/android/settings/vpn2/VpnInfoPreference.java
index 2a1b495..9e70a5d 100644
--- a/src/com/android/settings/vpn2/VpnInfoPreference.java
+++ b/src/com/android/settings/vpn2/VpnInfoPreference.java
@@ -71,7 +71,7 @@
// Hide the divider from view
final View divider =
- holder.findViewById(com.android.settingslib.widget.R.id.two_target_divider);
+ holder.findViewById(com.android.settingslib.widget.preference.twotarget.R.id.two_target_divider);
divider.setVisibility(View.GONE);
}
diff --git a/src/com/android/settings/widget/AppCheckBoxPreference.java b/src/com/android/settings/widget/AppCheckBoxPreference.java
index 7cf31b8..aa7e0e5 100644
--- a/src/com/android/settings/widget/AppCheckBoxPreference.java
+++ b/src/com/android/settings/widget/AppCheckBoxPreference.java
@@ -25,26 +25,27 @@
import androidx.preference.CheckBoxPreference;
import androidx.preference.PreferenceViewHolder;
+import com.android.settings.R;
+
/**
* {@link CheckBoxPreference} that used only to display app
*/
public class AppCheckBoxPreference extends CheckBoxPreference {
public AppCheckBoxPreference(Context context, AttributeSet attrs) {
super(context, attrs);
- setLayoutResource(com.android.settingslib.widget.R.layout.preference_app);
+ setLayoutResource(com.android.settingslib.widget.preference.app.R.layout.preference_app);
}
public AppCheckBoxPreference(Context context) {
super(context);
- setLayoutResource(com.android.settingslib.widget.R.layout.preference_app);
+ setLayoutResource(com.android.settingslib.widget.preference.app.R.layout.preference_app);
}
@Override
public void onBindViewHolder(PreferenceViewHolder holder) {
super.onBindViewHolder(holder);
- final LinearLayout layout = (LinearLayout) holder
- .findViewById(com.android.settingslib.widget.R.id.summary_container);
+ final LinearLayout layout = (LinearLayout) holder.findViewById(R.id.summary_container);
if (layout != null) {
// If summary doesn't exist, make it gone
layout.setVisibility(TextUtils.isEmpty(getSummary()) ? View.GONE : View.VISIBLE);
diff --git a/src/com/android/settings/widget/EntityHeaderController.java b/src/com/android/settings/widget/EntityHeaderController.java
index 376bd22..c89b7bb 100644
--- a/src/com/android/settings/widget/EntityHeaderController.java
+++ b/src/com/android/settings/widget/EntityHeaderController.java
@@ -110,7 +110,7 @@
mHeader = header;
} else {
mHeader = LayoutInflater.from(fragment.getContext())
- .inflate(com.android.settingslib.widget.R.layout.settings_entity_header,
+ .inflate(com.android.settingslib.widget.preference.layout.R.layout.settings_entity_header,
null /* root */);
}
}
@@ -236,9 +236,9 @@
}
setText(R.id.entity_header_title, mLabel);
setText(R.id.entity_header_summary, mSummary);
- setText(com.android.settingslib.widget.R.id.entity_header_second_summary, mSecondSummary);
+ setText(com.android.settingslib.widget.preference.layout.R.id.entity_header_second_summary, mSecondSummary);
if (mIsInstantApp) {
- setText(com.android.settingslib.widget.R.id.install_type,
+ setText(com.android.settingslib.widget.preference.layout.R.id.install_type,
mHeader.getResources().getString(R.string.install_type_instant));
}
@@ -254,7 +254,7 @@
*/
public EntityHeaderController bindHeaderButtons() {
final View entityHeaderContent = mHeader.findViewById(
- com.android.settingslib.widget.R.id.entity_header_content);
+ com.android.settingslib.widget.preference.layout.R.id.entity_header_content);
final ImageButton button1 = mHeader.findViewById(android.R.id.button1);
final ImageButton button2 = mHeader.findViewById(android.R.id.button2);
bindAppInfoLink(entityHeaderContent);
diff --git a/src/com/android/settings/widget/SingleTargetGearPreference.java b/src/com/android/settings/widget/SingleTargetGearPreference.java
index 2cc5508..e6a833d 100644
--- a/src/com/android/settings/widget/SingleTargetGearPreference.java
+++ b/src/com/android/settings/widget/SingleTargetGearPreference.java
@@ -59,7 +59,7 @@
public void onBindViewHolder(PreferenceViewHolder holder) {
super.onBindViewHolder(holder);
final View divider = holder.findViewById(
- com.android.settingslib.widget.R.id.two_target_divider);
+ com.android.settingslib.widget.preference.twotarget.R.id.two_target_divider);
if (divider != null) {
divider.setVisibility(View.INVISIBLE);
}
diff --git a/src/com/android/settings/wifi/ConnectedWifiEntryPreference.java b/src/com/android/settings/wifi/ConnectedWifiEntryPreference.java
index 1dea591..cd0dad1 100644
--- a/src/com/android/settings/wifi/ConnectedWifiEntryPreference.java
+++ b/src/com/android/settings/wifi/ConnectedWifiEntryPreference.java
@@ -56,7 +56,7 @@
holder.findViewById(R.id.settings_button_no_background).setVisibility(
canSignIn ? View.INVISIBLE : View.VISIBLE);
gear.setVisibility(canSignIn ? View.VISIBLE : View.INVISIBLE);
- holder.findViewById(com.android.settingslib.widget.R.id.two_target_divider).setVisibility(
+ holder.findViewById(com.android.settingslib.widget.preference.twotarget.R.id.two_target_divider).setVisibility(
canSignIn ? View.VISIBLE : View.INVISIBLE);
}
diff --git a/src/com/android/settings/wifi/LinkablePreference.java b/src/com/android/settings/wifi/LinkablePreference.java
index 8f95917..adcfe32 100644
--- a/src/com/android/settings/wifi/LinkablePreference.java
+++ b/src/com/android/settings/wifi/LinkablePreference.java
@@ -49,7 +49,7 @@
public LinkablePreference(Context ctx, AttributeSet attrs) {
this(ctx, attrs, TypedArrayUtils.getAttr(
- ctx, com.android.settingslib.widget.R.attr.footerPreferenceStyle,
+ ctx, com.android.settingslib.widget.theme.R.attr.footerPreferenceStyle,
android.R.attr.preferenceStyle));
}
diff --git a/src/com/android/settings/wifi/NetworkRequestDialogFragment.java b/src/com/android/settings/wifi/NetworkRequestDialogFragment.java
index cf4bbcb..d1c3cac 100644
--- a/src/com/android/settings/wifi/NetworkRequestDialogFragment.java
+++ b/src/com/android/settings/wifi/NetworkRequestDialogFragment.java
@@ -326,7 +326,7 @@
view = mInflater.inflate(mResourceId, parent, false);
final View divider = view.findViewById(
- com.android.settingslib.widget.R.id.two_target_divider);
+ com.android.settingslib.widget.preference.twotarget.R.id.two_target_divider);
divider.setVisibility(View.GONE);
}
diff --git a/src/com/android/settings/wifi/WifiEntryPreference.java b/src/com/android/settings/wifi/WifiEntryPreference.java
index e63e942..c78f28c 100644
--- a/src/com/android/settings/wifi/WifiEntryPreference.java
+++ b/src/com/android/settings/wifi/WifiEntryPreference.java
@@ -122,7 +122,7 @@
view.itemView.setContentDescription(mContentDescription);
// Turn off divider
- view.findViewById(com.android.settingslib.widget.R.id.two_target_divider)
+ view.findViewById(com.android.settingslib.widget.preference.twotarget.R.id.two_target_divider)
.setVisibility(View.INVISIBLE);
// Enable the icon button when the help string in this WifiEntry is not null.
diff --git a/src/com/android/settings/wifi/addappnetworks/AddAppNetworksFragment.java b/src/com/android/settings/wifi/addappnetworks/AddAppNetworksFragment.java
index b98d5cd..f4873cf 100644
--- a/src/com/android/settings/wifi/addappnetworks/AddAppNetworksFragment.java
+++ b/src/com/android/settings/wifi/addappnetworks/AddAppNetworksFragment.java
@@ -550,7 +550,7 @@
}
final View divider = view.findViewById(
- com.android.settingslib.widget.R.id.two_target_divider);
+ com.android.settingslib.widget.preference.twotarget.R.id.two_target_divider);
if (divider != null) {
divider.setVisibility(View.GONE);
}
diff --git a/src/com/android/settings/wifi/details/WifiNetworkDetailsFragment.java b/src/com/android/settings/wifi/details/WifiNetworkDetailsFragment.java
index 65f2705..0384f0d 100644
--- a/src/com/android/settings/wifi/details/WifiNetworkDetailsFragment.java
+++ b/src/com/android/settings/wifi/details/WifiNetworkDetailsFragment.java
@@ -23,7 +23,6 @@
import android.app.admin.DevicePolicyManager;
import android.app.settings.SettingsEnums;
import android.content.Context;
-import android.graphics.ColorFilter;
import android.graphics.drawable.Drawable;
import android.net.ConnectivityManager;
import android.net.wifi.WifiManager;
@@ -67,7 +66,6 @@
import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
import com.android.settingslib.RestrictedLockUtilsInternal;
import com.android.settingslib.core.AbstractPreferenceController;
-import com.android.settingslib.graph.ThemedBatteryDrawable;
import com.android.wifitrackerlib.NetworkDetailsTracker;
import com.android.wifitrackerlib.WifiEntry;
@@ -441,23 +439,8 @@
@VisibleForTesting
void updateBattery(boolean isChanging, int percentage) {
Preference battery = getPreferenceScreen().findPreference(KEY_HOTSPOT_DEVICE_BATTERY);
- battery.setSummary(formatPercentage(percentage));
- ThemedBatteryDrawable drawable = getBatteryDrawable();
- if (drawable != null) {
- drawable.setCharging(isChanging);
- drawable.setBatteryLevel(percentage);
- }
- battery.setIcon(drawable);
- }
-
- @VisibleForTesting
- ThemedBatteryDrawable getBatteryDrawable() {
- int frameColor = getContext()
- .getColor(com.android.settingslib.R.color.meter_background_color);
- ThemedBatteryDrawable drawable = new ThemedBatteryDrawable(getContext(), frameColor);
- ColorFilter colorFilter = Utils.getAlphaInvariantColorFilterForColor(
- Utils.getColorAttrDefaultColor(getContext(), android.R.attr.colorControlNormal));
- drawable.setColorFilter(colorFilter);
- return drawable;
+ battery.setSummary((isChanging)
+ ? getString(R.string.hotspot_battery_charging_summary, formatPercentage(percentage))
+ : formatPercentage(percentage));
}
}
diff --git a/src/com/android/settings/wifi/tether/WifiTetherSsidPreference.java b/src/com/android/settings/wifi/tether/WifiTetherSsidPreference.java
index a9487a5..e5d3b3d 100644
--- a/src/com/android/settings/wifi/tether/WifiTetherSsidPreference.java
+++ b/src/com/android/settings/wifi/tether/WifiTetherSsidPreference.java
@@ -68,7 +68,7 @@
private void initialize() {
// TODO(b/129019971): use methods of divider line in parent object
- setLayoutResource(com.android.settingslib.widget.R.layout.preference_two_target);
+ setLayoutResource(com.android.settingslib.widget.preference.twotarget.R.layout.preference_two_target);
setWidgetLayoutResource(R.layout.wifi_button_preference_widget);
mShareIconDrawable = getDrawable(R.drawable.ic_qrcode_24dp);
@@ -80,7 +80,7 @@
final ImageButton shareButton = (ImageButton) holder.findViewById(R.id.button_icon);
final View dividerView = holder.findViewById(
- com.android.settingslib.widget.R.id.two_target_divider);
+ com.android.settingslib.widget.preference.twotarget.R.id.two_target_divider);
if (mVisible) {
shareButton.setOnClickListener(mClickListener);
diff --git a/tests/robotests/src/com/android/settings/accessibility/AccessibilityFooterPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/accessibility/AccessibilityFooterPreferenceControllerTest.java
index 111f634..5cf4d94 100644
--- a/tests/robotests/src/com/android/settings/accessibility/AccessibilityFooterPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/accessibility/AccessibilityFooterPreferenceControllerTest.java
@@ -73,7 +73,7 @@
final LayoutInflater inflater = LayoutInflater.from(mContext);
final View view = inflater.inflate(
- com.android.settingslib.widget.R.layout.preference_footer, null);
+ com.android.settingslib.widget.preference.footer.R.layout.preference_footer, null);
mPreferenceViewHolder = PreferenceViewHolder.createInstanceForTests(view);
mPreference.onBindViewHolder(mPreferenceViewHolder);
@@ -117,7 +117,7 @@
mPreference.onBindViewHolder(mPreferenceViewHolder);
final TextView learnMoreView = (TextView) mPreferenceViewHolder
- .findViewById(com.android.settingslib.widget.R.id.settingslib_learn_more);
+ .findViewById(com.android.settingslib.widget.preference.footer.R.id.settingslib_learn_more);
assertThat(learnMoreView.getContentDescription()).isNull();
assertThat(learnMoreView.getVisibility()).isEqualTo(View.GONE);
assertThat(mPreference.isLinkEnabled()).isFalse();
diff --git a/tests/robotests/src/com/android/settings/accessibility/AccessibilityFooterPreferenceTest.java b/tests/robotests/src/com/android/settings/accessibility/AccessibilityFooterPreferenceTest.java
index 6b55607..c4476769 100644
--- a/tests/robotests/src/com/android/settings/accessibility/AccessibilityFooterPreferenceTest.java
+++ b/tests/robotests/src/com/android/settings/accessibility/AccessibilityFooterPreferenceTest.java
@@ -46,7 +46,7 @@
final LayoutInflater inflater = LayoutInflater.from(context);
final View view =
- inflater.inflate(com.android.settingslib.widget.R.layout.preference_footer, null);
+ inflater.inflate(com.android.settingslib.widget.preference.footer.R.layout.preference_footer, null);
mPreferenceViewHolder = PreferenceViewHolder.createInstanceForTests(view);
}
diff --git a/tests/robotests/src/com/android/settings/accessibility/AccessibilityQuickSettingsPrimarySwitchPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/accessibility/AccessibilityQuickSettingsPrimarySwitchPreferenceControllerTest.java
index 63243f2..b13d0e4 100644
--- a/tests/robotests/src/com/android/settings/accessibility/AccessibilityQuickSettingsPrimarySwitchPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/accessibility/AccessibilityQuickSettingsPrimarySwitchPreferenceControllerTest.java
@@ -112,7 +112,7 @@
mPreference.setTitle(TEST_TITLE);
LayoutInflater inflater = LayoutInflater.from(mContext);
mHolder = PreferenceViewHolder.createInstanceForTests(inflater.inflate(
- com.android.settingslib.widget.R.layout.preference_two_target, null));
+ com.android.settingslib.widget.preference.twotarget.R.layout.preference_two_target, null));
LinearLayout mWidgetView = mHolder.itemView.findViewById(android.R.id.widget_frame);
inflater.inflate(R.layout.preference_widget_primary_switch, mWidgetView, true);
mPreference.onBindViewHolder(mHolder);
diff --git a/tests/robotests/src/com/android/settings/accessibility/FlashNotificationsPreviewPreferenceTest.java b/tests/robotests/src/com/android/settings/accessibility/FlashNotificationsPreviewPreferenceTest.java
index e960008..fac467d 100644
--- a/tests/robotests/src/com/android/settings/accessibility/FlashNotificationsPreviewPreferenceTest.java
+++ b/tests/robotests/src/com/android/settings/accessibility/FlashNotificationsPreviewPreferenceTest.java
@@ -69,7 +69,7 @@
final View frame = mPreferenceViewHolder.findViewById(R.id.frame);
final int backgroundResId = Shadows.shadowOf(frame.getBackground()).getCreatedFromResId();
assertThat(backgroundResId).isEqualTo(
- com.android.settingslib.widget.R.drawable.settingslib_switch_bar_bg_on);
+ com.android.settingslib.widget.mainswitch.R.drawable.settingslib_switch_bar_bg_on);
final TextView title = (TextView) mPreferenceViewHolder.findViewById(android.R.id.title);
assertThat(title.getAlpha()).isEqualTo(1f);
assertThat(title.getCurrentTextColor()).isEqualTo(textColorEnabled);
diff --git a/tests/robotests/src/com/android/settings/accounts/AccountHeaderPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/accounts/AccountHeaderPreferenceControllerTest.java
index b3d1ff7..94d150d 100644
--- a/tests/robotests/src/com/android/settings/accounts/AccountHeaderPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/accounts/AccountHeaderPreferenceControllerTest.java
@@ -73,7 +73,7 @@
FakeFeatureFactory.setupForTest();
mHeaderPreference = new LayoutPreference(
RuntimeEnvironment.application,
- com.android.settingslib.widget.R.layout.settings_entity_header);
+ com.android.settingslib.widget.preference.layout.R.layout.settings_entity_header);
doReturn(RuntimeEnvironment.application).when(mActivity).getApplicationContext();
mLifecycleOwner = () -> mLifecycle;
mLifecycle = new Lifecycle(mLifecycleOwner);
diff --git a/tests/robotests/src/com/android/settings/applications/appinfo/AppHeaderViewPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/applications/appinfo/AppHeaderViewPreferenceControllerTest.java
index 46eac83..922e2e8 100644
--- a/tests/robotests/src/com/android/settings/applications/appinfo/AppHeaderViewPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/applications/appinfo/AppHeaderViewPreferenceControllerTest.java
@@ -80,7 +80,7 @@
mLifecycleOwner = () -> mLifecycle;
mLifecycle = new Lifecycle(mLifecycleOwner);
mHeader = LayoutInflater.from(mContext).inflate(
- com.android.settingslib.widget.R.layout.settings_entity_header, null);
+ com.android.settingslib.widget.preference.layout.R.layout.settings_entity_header, null);
when(mFragment.getActivity()).thenReturn(mActivity);
when(mScreen.findPreference(anyString())).thenReturn(mPreference);
diff --git a/tests/robotests/src/com/android/settings/applications/managedomainurls/DomainAppPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/applications/managedomainurls/DomainAppPreferenceControllerTest.java
index aeef8ec..af13fa2 100644
--- a/tests/robotests/src/com/android/settings/applications/managedomainurls/DomainAppPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/applications/managedomainurls/DomainAppPreferenceControllerTest.java
@@ -72,7 +72,7 @@
final DomainAppPreference pref = new DomainAppPreference(mContext, mAppEntry);
assertThat(pref.getLayoutResource())
- .isEqualTo(com.android.settingslib.widget.R.layout.preference_app);
+ .isEqualTo(com.android.settingslib.widget.preference.app.R.layout.preference_app);
}
private ApplicationInfo createApplicationInfo(String packageName) {
diff --git a/tests/robotests/src/com/android/settings/bluetooth/BluetoothDetailsButtonsControllerTest.java b/tests/robotests/src/com/android/settings/bluetooth/BluetoothDetailsButtonsControllerTest.java
index a048f88..74a5bc9 100644
--- a/tests/robotests/src/com/android/settings/bluetooth/BluetoothDetailsButtonsControllerTest.java
+++ b/tests/robotests/src/com/android/settings/bluetooth/BluetoothDetailsButtonsControllerTest.java
@@ -55,10 +55,10 @@
super.setUp();
final View buttons = View.inflate(
RuntimeEnvironment.application,
- com.android.settingslib.widget.R.layout.settingslib_action_buttons,
+ com.android.settingslib.widget.preference.actionbuttons.R.layout.settingslib_action_buttons,
null /* parent */);
- mConnectButton = buttons.findViewById(com.android.settingslib.widget.R.id.button2);
- mForgetButton = buttons.findViewById(com.android.settingslib.widget.R.id.button1);
+ mConnectButton = buttons.findViewById(com.android.settingslib.widget.preference.actionbuttons.R.id.button2);
+ mForgetButton = buttons.findViewById(com.android.settingslib.widget.preference.actionbuttons.R.id.button1);
mController =
new BluetoothDetailsButtonsController(mContext, mFragment, mCachedDevice,
mLifecycle);
diff --git a/tests/robotests/src/com/android/settings/bluetooth/BluetoothDetailsHeaderControllerTest.java b/tests/robotests/src/com/android/settings/bluetooth/BluetoothDetailsHeaderControllerTest.java
index fcfe84b..cf9bf09 100644
--- a/tests/robotests/src/com/android/settings/bluetooth/BluetoothDetailsHeaderControllerTest.java
+++ b/tests/robotests/src/com/android/settings/bluetooth/BluetoothDetailsHeaderControllerTest.java
@@ -72,7 +72,7 @@
mController =
new BluetoothDetailsHeaderController(mContext, mFragment, mCachedDevice, mLifecycle);
mPreference = new LayoutPreference(
- mContext, com.android.settingslib.widget.R.layout.settings_entity_header);
+ mContext, com.android.settingslib.widget.preference.layout.R.layout.settings_entity_header);
mPreference.setKey(mController.getPreferenceKey());
mScreen.addPreference(mPreference);
setupDevice(mDeviceConfig);
diff --git a/tests/robotests/src/com/android/settings/connecteddevice/usb/UsbDetailsHeaderControllerTest.java b/tests/robotests/src/com/android/settings/connecteddevice/usb/UsbDetailsHeaderControllerTest.java
index 43bf657..4fb78fb 100644
--- a/tests/robotests/src/com/android/settings/connecteddevice/usb/UsbDetailsHeaderControllerTest.java
+++ b/tests/robotests/src/com/android/settings/connecteddevice/usb/UsbDetailsHeaderControllerTest.java
@@ -94,7 +94,7 @@
ShadowEntityHeaderController.setUseMock(mHeaderController);
mDetailsHeaderController = new UsbDetailsHeaderController(mContext, mFragment, mUsbBackend);
mPreference = new LayoutPreference(
- mContext, com.android.settingslib.widget.R.layout.settings_entity_header);
+ mContext, com.android.settingslib.widget.preference.layout.R.layout.settings_entity_header);
mPreference.setKey(mDetailsHeaderController.getPreferenceKey());
mScreen.addPreference(mPreference);
}
diff --git a/tests/robotests/src/com/android/settings/datausage/AppDataUsagePreferenceTest.java b/tests/robotests/src/com/android/settings/datausage/AppDataUsagePreferenceTest.java
index 0b182b8..7e6d314 100644
--- a/tests/robotests/src/com/android/settings/datausage/AppDataUsagePreferenceTest.java
+++ b/tests/robotests/src/com/android/settings/datausage/AppDataUsagePreferenceTest.java
@@ -91,7 +91,7 @@
mPreference = new AppDataUsagePreference(RuntimeEnvironment.application, mAppItem,
50 /* percent */, mUidDetailProvider);
final View view = LayoutInflater.from(RuntimeEnvironment.application).inflate(
- com.android.settingslib.widget.R.layout.preference_app, null);
+ com.android.settingslib.widget.preference.app.R.layout.preference_app, null);
final PreferenceViewHolder preferenceViewHolder =
PreferenceViewHolder.createInstanceForTests(view);
final ProgressBar progressBar = (ProgressBar) preferenceViewHolder.findViewById(
diff --git a/tests/robotests/src/com/android/settings/datausage/DataUsageListTest.java b/tests/robotests/src/com/android/settings/datausage/DataUsageListTest.java
index 5eee615..1268032 100644
--- a/tests/robotests/src/com/android/settings/datausage/DataUsageListTest.java
+++ b/tests/robotests/src/com/android/settings/datausage/DataUsageListTest.java
@@ -29,22 +29,16 @@
import android.app.Activity;
import android.content.Intent;
-import android.net.ConnectivityManager;
import android.net.NetworkTemplate;
import android.os.Bundle;
import android.os.UserManager;
import android.provider.Settings;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.widget.FrameLayout;
-import android.widget.Spinner;
import androidx.annotation.NonNull;
-import androidx.fragment.app.FragmentActivity;
import androidx.loader.app.LoaderManager;
+import androidx.preference.Preference;
import androidx.preference.PreferenceManager;
-import com.android.settings.R;
import com.android.settings.datausage.lib.BillingCycleRepository;
import com.android.settings.network.MobileDataEnabledListener;
import com.android.settings.testutils.FakeFeatureFactory;
@@ -52,6 +46,7 @@
import com.android.settingslib.NetworkPolicyEditor;
import com.android.settingslib.core.AbstractPreferenceController;
import com.android.settingslib.core.instrumentation.VisibilityLoggerMixin;
+import com.android.settingslib.net.NetworkCycleChartData;
import org.junit.Before;
import org.junit.Rule;
@@ -69,7 +64,11 @@
import org.robolectric.annotation.Implements;
import org.robolectric.util.ReflectionHelpers;
+import java.util.Collections;
+import java.util.List;
+
@RunWith(RobolectricTestRunner.class)
+@Config(shadows = DataUsageListTest.ShadowDataUsageBaseFragment.class)
public class DataUsageListTest {
@Rule
public MockitoRule mMockitoRule = MockitoJUnit.rule();
@@ -84,6 +83,8 @@
private UserManager mUserManager;
@Mock
private BillingCycleRepository mBillingCycleRepository;
+ @Mock
+ private DataUsageListHeaderController mDataUsageListHeaderController;
private Activity mActivity;
@@ -98,7 +99,6 @@
mActivity = spy(mActivityController.get());
mNetworkServices.mPolicyEditor = mock(NetworkPolicyEditor.class);
mDataUsageList.mDataStateListener = mMobileDataEnabledListener;
- mDataUsageList.mTemplate = mock(NetworkTemplate.class);
doReturn(mActivity).when(mDataUsageList).getContext();
doReturn(mUserManager).when(mActivity).getSystemService(UserManager.class);
@@ -110,11 +110,12 @@
mDataUsageList.mLoadingViewController = mock(LoadingViewController.class);
doNothing().when(mDataUsageList).updateSubscriptionInfoEntity();
when(mBillingCycleRepository.isBandwidthControlEnabled()).thenReturn(true);
+ mDataUsageList.mDataUsageListHeaderController = mDataUsageListHeaderController;
}
@Test
- @Config(shadows = ShadowDataUsageBaseFragment.class)
public void onCreate_isNotGuestUser_shouldNotFinish() {
+ mDataUsageList.mTemplate = mock(NetworkTemplate.class);
doReturn(false).when(mUserManager).isGuestUser();
doNothing().when(mDataUsageList).processArgument();
@@ -124,7 +125,6 @@
}
@Test
- @Config(shadows = ShadowDataUsageBaseFragment.class)
public void onCreate_isGuestUser_shouldFinish() {
doReturn(true).when(mUserManager).isGuestUser();
@@ -135,6 +135,7 @@
@Test
public void resume_shouldListenDataStateChange() {
+ mDataUsageList.onCreate(null);
ReflectionHelpers.setField(
mDataUsageList, "mVisibilityLoggerMixin", mock(VisibilityLoggerMixin.class));
ReflectionHelpers.setField(
@@ -149,6 +150,7 @@
@Test
public void pause_shouldUnlistenDataStateChange() {
+ mDataUsageList.onCreate(null);
ReflectionHelpers.setField(
mDataUsageList, "mVisibilityLoggerMixin", mock(VisibilityLoggerMixin.class));
ReflectionHelpers.setField(
@@ -174,25 +176,11 @@
}
@Test
- public void processArgument_shouldGetNetworkTypeFromArgument() {
- final Bundle args = new Bundle();
- args.putInt(DataUsageList.EXTRA_NETWORK_TYPE, ConnectivityManager.TYPE_WIFI);
- args.putInt(DataUsageList.EXTRA_SUB_ID, 3);
- mDataUsageList.setArguments(args);
-
- mDataUsageList.processArgument();
-
- assertThat(mDataUsageList.mNetworkType).isEqualTo(ConnectivityManager.TYPE_WIFI);
- }
-
- @Test
public void processArgument_fromIntent_shouldGetTemplateFromIntent() {
- final FragmentActivity activity = mock(FragmentActivity.class);
final Intent intent = new Intent();
intent.putExtra(Settings.EXTRA_NETWORK_TEMPLATE, mock(NetworkTemplate.class));
intent.putExtra(Settings.EXTRA_SUB_ID, 3);
- when(activity.getIntent()).thenReturn(intent);
- doReturn(activity).when(mDataUsageList).getActivity();
+ doReturn(intent).when(mDataUsageList).getIntent();
mDataUsageList.processArgument();
@@ -201,30 +189,16 @@
}
@Test
- public void onViewCreated_shouldHideCycleSpinner() {
- final View view = new View(mActivity);
- final View header = getHeader();
- final Spinner spinner = getSpinner(header);
- spinner.setVisibility(View.VISIBLE);
- doReturn(header).when(mDataUsageList).setPinnedHeaderView(anyInt());
- doReturn(view).when(mDataUsageList).getView();
-
- mDataUsageList.onViewCreated(view, null);
-
- assertThat(spinner.getVisibility()).isEqualTo(View.GONE);
- }
-
- @Test
public void onLoadFinished_networkCycleDataCallback_shouldShowCycleSpinner() {
- final Spinner spinner = getSpinner(getHeader());
- spinner.setVisibility(View.INVISIBLE);
- mDataUsageList.mCycleSpinner = spinner;
- assertThat(spinner.getVisibility()).isEqualTo(View.INVISIBLE);
- doNothing().when(mDataUsageList).updatePolicy();
+ mDataUsageList.mTemplate = mock(NetworkTemplate.class);
+ mDataUsageList.onCreate(null);
+ mDataUsageList.updatePolicy();
+ List<NetworkCycleChartData> mockData = Collections.emptyList();
- mDataUsageList.mNetworkCycleDataCallbacks.onLoadFinished(null, null);
+ mDataUsageList.mNetworkCycleDataCallbacks.onLoadFinished(null, mockData);
- assertThat(spinner.getVisibility()).isEqualTo(View.VISIBLE);
+ verify(mDataUsageListHeaderController).updateCycleData(mockData);
+ verify(mDataUsageListHeaderController).setConfigButtonVisible(true);
}
@Test
@@ -234,19 +208,6 @@
verify(mLoaderManager).destroyLoader(DataUsageList.LOADER_CHART_DATA);
}
- private View getHeader() {
- final View rootView = LayoutInflater.from(mActivity)
- .inflate(R.layout.preference_list_fragment, null, false);
- final FrameLayout pinnedHeader = rootView.findViewById(R.id.pinned_header);
-
- return mActivity.getLayoutInflater()
- .inflate(R.layout.apps_filter_spinner, pinnedHeader, false);
- }
-
- private Spinner getSpinner(View header) {
- return header.findViewById(R.id.filter_spinner);
- }
-
@Implements(DataUsageBaseFragment.class)
public static class ShadowDataUsageBaseFragment {
@Implementation
@@ -261,10 +222,28 @@
return mock(clazz);
}
+ @Override
+ public <T extends Preference> T findPreference(CharSequence key) {
+ if (key.toString().equals("chart_data")) {
+ return (T) mock(ChartDataUsagePreference.class);
+ }
+ return (T) mock(Preference.class);
+ }
+
+ @Override
+ public Intent getIntent() {
+ return new Intent();
+ }
+
@NonNull
@Override
BillingCycleRepository createBillingCycleRepository() {
return mBillingCycleRepository;
}
+
+ @Override
+ boolean isBillingCycleModifiable() {
+ return true;
+ }
}
}
diff --git a/tests/robotests/src/com/android/settings/datausage/UnrestrictedDataAccessPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/datausage/UnrestrictedDataAccessPreferenceControllerTest.java
index 48b57a1..8aa2e5a 100644
--- a/tests/robotests/src/com/android/settings/datausage/UnrestrictedDataAccessPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/datausage/UnrestrictedDataAccessPreferenceControllerTest.java
@@ -141,7 +141,7 @@
assertThat(preference.isDisabledByAdmin()).isTrue();
assertThat(preference.getSummary()).isEqualTo(
mContext.getString(
- com.android.settingslib.widget.R.string.disabled_by_admin));
+ com.android.settingslib.widget.restricted.R.string.disabled_by_admin));
}
assertThat(preference.isChecked()).isFalse();
preference.performClick();
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 b25b845..22509de 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/batteryusage/PowerGaugePreferenceTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/batteryusage/PowerGaugePreferenceTest.java
@@ -54,7 +54,7 @@
mContext = RuntimeEnvironment.application;
mRootView = LayoutInflater.from(mContext)
- .inflate(com.android.settingslib.widget.R.layout.preference_app, null);
+ .inflate(com.android.settingslib.widget.preference.app.R.layout.preference_app, null);
mWidgetView =
LayoutInflater.from(mContext).inflate(R.layout.preference_widget_summary, null);
final LinearLayout widgetFrame = mRootView.findViewById(android.R.id.widget_frame);
@@ -64,7 +64,7 @@
mPowerGaugePreference = new PowerGaugePreference(mContext);
assertThat(mPowerGaugePreference.getLayoutResource())
- .isEqualTo(com.android.settingslib.widget.R.layout.preference_app);
+ .isEqualTo(com.android.settingslib.widget.preference.app.R.layout.preference_app);
}
@Test
diff --git a/tests/robotests/src/com/android/settings/location/RecentLocationAccessPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/location/RecentLocationAccessPreferenceControllerTest.java
index 2955c88..e9284ee 100644
--- a/tests/robotests/src/com/android/settings/location/RecentLocationAccessPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/location/RecentLocationAccessPreferenceControllerTest.java
@@ -80,7 +80,7 @@
mController.init(mDashboardFragment);
final String key = mController.getPreferenceKey();
mAppEntitiesHeaderView = LayoutInflater.from(mContext).inflate(
- com.android.settingslib.widget.R.layout.app_entities_header, null /* root */);
+ com.android.settingslib.widget.entityheader.R.layout.app_entities_header, null /* root */);
when(mScreen.findPreference(key)).thenReturn(mLayoutPreference);
when(mLayoutPreference.getKey()).thenReturn(key);
when(mLayoutPreference.getContext()).thenReturn(mContext);
@@ -109,7 +109,7 @@
assertThat(title.getText()).isEqualTo(
mContext.getText(R.string.location_category_recent_location_access));
final TextView details = mAppEntitiesHeaderView
- .findViewById(com.android.settingslib.widget.R.id.header_details);
+ .findViewById(com.android.settingslib.widget.entityheader.R.id.header_details);
assertThat(details.getText()).isEqualTo(
mContext.getText(R.string.location_recent_location_access_view_details));
assertThat(details.hasOnClickListeners()).isTrue();
diff --git a/tests/robotests/src/com/android/settings/search/actionbar/SearchMenuControllerTest.java b/tests/robotests/src/com/android/settings/search/actionbar/SearchMenuControllerTest.java
index 4dbd9eb..aecb3e7 100644
--- a/tests/robotests/src/com/android/settings/search/actionbar/SearchMenuControllerTest.java
+++ b/tests/robotests/src/com/android/settings/search/actionbar/SearchMenuControllerTest.java
@@ -74,7 +74,7 @@
when(mHost.getActivity()).thenReturn(mActivity);
when(mMenu.add(Menu.NONE, MENU_SEARCH, 0 /* order */,
- com.android.settingslib.search.R.string.search_menu))
+ com.android.settingslib.search.widget.R.string.search_menu))
.thenReturn(mock(MenuItem.class));
}
@@ -84,7 +84,7 @@
mHost.getSettingsLifecycle().onCreateOptionsMenu(mMenu, null /* inflater */);
verify(mMenu).add(Menu.NONE, MENU_SEARCH, 0 /* order */,
- com.android.settingslib.search.R.string.search_menu);
+ com.android.settingslib.search.widget.R.string.search_menu);
}
@Test
diff --git a/tests/robotests/src/com/android/settings/widget/AppCheckBoxPreferenceTest.java b/tests/robotests/src/com/android/settings/widget/AppCheckBoxPreferenceTest.java
index 5637b20..9c4e080 100644
--- a/tests/robotests/src/com/android/settings/widget/AppCheckBoxPreferenceTest.java
+++ b/tests/robotests/src/com/android/settings/widget/AppCheckBoxPreferenceTest.java
@@ -45,15 +45,15 @@
mAttrPreference = new AppCheckBoxPreference(mContext, null /* attrs */);
mPreferenceViewHolder = PreferenceViewHolder.createInstanceForTests(
LayoutInflater.from(mContext)
- .inflate(com.android.settingslib.widget.R.layout.preference_app, null));
+ .inflate(com.android.settingslib.widget.preference.app.R.layout.preference_app, null));
}
@Test
public void testGetLayoutResource() {
assertThat(mPreference.getLayoutResource())
- .isEqualTo(com.android.settingslib.widget.R.layout.preference_app);
+ .isEqualTo(com.android.settingslib.widget.preference.app.R.layout.preference_app);
assertThat(mAttrPreference.getLayoutResource())
- .isEqualTo(com.android.settingslib.widget.R.layout.preference_app);
+ .isEqualTo(com.android.settingslib.widget.preference.app.R.layout.preference_app);
}
@Test
@@ -61,7 +61,7 @@
mPreference.onBindViewHolder(mPreferenceViewHolder);
View appendix =
- mPreferenceViewHolder.findViewById(com.android.settingslib.widget.R.id.appendix);
+ mPreferenceViewHolder.findViewById(com.android.settingslib.widget.preference.app.R.id.appendix);
assertThat(appendix.getVisibility()).isEqualTo(View.GONE);
}
}
diff --git a/tests/robotests/src/com/android/settings/widget/EntityHeaderControllerTest.java b/tests/robotests/src/com/android/settings/widget/EntityHeaderControllerTest.java
index 834f3d1..06b99a4 100644
--- a/tests/robotests/src/com/android/settings/widget/EntityHeaderControllerTest.java
+++ b/tests/robotests/src/com/android/settings/widget/EntityHeaderControllerTest.java
@@ -100,7 +100,7 @@
@Test
public void testBuildView_constructedWithView_shouldReturnSameView() {
View inputView = mLayoutInflater.inflate(
- com.android.settingslib.widget.R.layout.settings_entity_header, null /* root */);
+ com.android.settingslib.widget.preference.layout.R.layout.settings_entity_header, null /* root */);
mController = EntityHeaderController.newInstance(mActivity, mFragment, inputView);
View view = mController.done();
@@ -111,11 +111,11 @@
public void bindViews_shouldBindAllData() {
final String testString = "test";
final View header = mLayoutInflater.inflate(
- com.android.settingslib.widget.R.layout.settings_entity_header, null /* root */);
+ com.android.settingslib.widget.preference.layout.R.layout.settings_entity_header, null /* root */);
final TextView label = header.findViewById(R.id.entity_header_title);
final TextView summary = header.findViewById(R.id.entity_header_summary);
final TextView secondSummary = header.findViewById(
- com.android.settingslib.widget.R.id.entity_header_second_summary);
+ com.android.settingslib.widget.preference.layout.R.id.entity_header_second_summary);
mController = EntityHeaderController.newInstance(mActivity, mFragment, header);
mController.setLabel(testString);
@@ -139,7 +139,7 @@
info.activityInfo.packageName = "123";
info.activityInfo.name = "321";
final View view = mLayoutInflater.inflate(
- com.android.settingslib.widget.R.layout.settings_entity_header, null /* root */);
+ com.android.settingslib.widget.preference.layout.R.layout.settings_entity_header, null /* root */);
when(mActivity.getApplicationContext()).thenReturn(mContext);
mController = EntityHeaderController.newInstance(mActivity, mFragment, view);
@@ -163,7 +163,7 @@
info.activityInfo.packageName = "123";
info.activityInfo.name = "321";
final View view = mLayoutInflater.inflate(
- com.android.settingslib.widget.R.layout.settings_entity_header, null /* root */);
+ com.android.settingslib.widget.preference.layout.R.layout.settings_entity_header, null /* root */);
when(mActivity.getApplicationContext()).thenReturn(mContext);
mController = EntityHeaderController.newInstance(mActivity, mFragment, view);
@@ -180,7 +180,7 @@
@Test
public void bindButton_noAppInfo_shouldNotAttachClickListener() {
final View appLinks = mLayoutInflater.inflate(
- com.android.settingslib.widget.R.layout.settings_entity_header, null /* root */);
+ com.android.settingslib.widget.preference.layout.R.layout.settings_entity_header, null /* root */);
final FragmentActivity activity = mock(FragmentActivity.class);
when(mFragment.getActivity()).thenReturn(activity);
@@ -197,7 +197,7 @@
assertThat(appLinks.findViewById(android.R.id.button2).getVisibility())
.isEqualTo(View.GONE);
- appLinks.findViewById(com.android.settingslib.widget.R.id.entity_header_content)
+ appLinks.findViewById(com.android.settingslib.widget.preference.layout.R.id.entity_header_content)
.performClick();
verify(mFragment, never()).getActivity();
verify(activity, never()).startActivity(any(Intent.class));
@@ -206,7 +206,7 @@
@Test
public void bindButton_hasAppInfo_shouldAttachClickListener() {
final View appLinks = mLayoutInflater.inflate(
- com.android.settingslib.widget.R.layout.settings_entity_header, null /* root */);
+ com.android.settingslib.widget.preference.layout.R.layout.settings_entity_header, null /* root */);
final FragmentActivity activity = mock(FragmentActivity.class);
when(mFragment.getActivity()).thenReturn(activity);
when(mContext.getString(eq(R.string.application_info_label))).thenReturn("App Info");
@@ -220,7 +220,7 @@
EntityHeaderController.ActionType.ACTION_NONE);
mController.done();
- appLinks.findViewById(com.android.settingslib.widget.R.id.entity_header_content)
+ appLinks.findViewById(com.android.settingslib.widget.preference.layout.R.id.entity_header_content)
.performClick();
verify(activity)
.startActivityForResultAsUser(any(Intent.class), anyInt(), any(UserHandle.class));
@@ -229,7 +229,7 @@
@Test
public void iconContentDescription_shouldWorkWithSetIcon() {
final View view = mLayoutInflater.inflate(
- com.android.settingslib.widget.R.layout.settings_entity_header, null /* root */);
+ com.android.settingslib.widget.preference.layout.R.layout.settings_entity_header, null /* root */);
when(mFragment.getActivity()).thenReturn(mock(FragmentActivity.class));
mController = EntityHeaderController.newInstance(mActivity, mFragment, view);
String description = "Fake Description";
@@ -243,7 +243,7 @@
@Test
public void iconContentDescription_shouldWorkWithoutSetIcon() {
final View view = mLayoutInflater.inflate(
- com.android.settingslib.widget.R.layout.settings_entity_header, null /* root */);
+ com.android.settingslib.widget.preference.layout.R.layout.settings_entity_header, null /* root */);
when(mFragment.getActivity()).thenReturn(mock(FragmentActivity.class));
mController = EntityHeaderController.newInstance(mActivity, mFragment, view);
String description = "Fake Description";
@@ -256,7 +256,7 @@
@Test
public void bindButton_hasAppNotifIntent_shouldShowButton() {
final View appLinks = mLayoutInflater.inflate(
- com.android.settingslib.widget.R.layout.settings_entity_header, null /* root */);
+ com.android.settingslib.widget.preference.layout.R.layout.settings_entity_header, null /* root */);
mController = EntityHeaderController.newInstance(mActivity, mFragment, appLinks);
mController.setAppNotifPrefIntent(new Intent())
@@ -276,11 +276,11 @@
@Test
public void instantApps_normalAppsDontGetLabel() {
final View header = mLayoutInflater.inflate(
- com.android.settingslib.widget.R.layout.settings_entity_header, null /* root */);
+ com.android.settingslib.widget.preference.layout.R.layout.settings_entity_header, null /* root */);
mController = EntityHeaderController.newInstance(mActivity, mFragment, header);
mController.done();
- View installType = header.findViewById(com.android.settingslib.widget.R.id.install_type);
+ View installType = header.findViewById(com.android.settingslib.widget.preference.layout.R.id.install_type);
assertThat(installType.getVisibility()).isEqualTo(View.GONE);
}
@@ -288,11 +288,11 @@
@Test
public void instantApps_expectedHeaderItem() {
final View header = mLayoutInflater.inflate(
- com.android.settingslib.widget.R.layout.settings_entity_header, null /* root */);
+ com.android.settingslib.widget.preference.layout.R.layout.settings_entity_header, null /* root */);
mController = EntityHeaderController.newInstance(mActivity, mFragment, header);
mController.setIsInstantApp(true);
mController.done();
- TextView label = header.findViewById(com.android.settingslib.widget.R.id.install_type);
+ TextView label = header.findViewById(com.android.settingslib.widget.preference.layout.R.id.install_type);
assertThat(label.getVisibility()).isEqualTo(View.VISIBLE);
assertThat(label.getText()).isEqualTo(
diff --git a/tests/robotests/src/com/android/settings/widget/PrimaryCheckBoxPreferenceTest.java b/tests/robotests/src/com/android/settings/widget/PrimaryCheckBoxPreferenceTest.java
index f3fa61e..2ed80e8 100644
--- a/tests/robotests/src/com/android/settings/widget/PrimaryCheckBoxPreferenceTest.java
+++ b/tests/robotests/src/com/android/settings/widget/PrimaryCheckBoxPreferenceTest.java
@@ -126,7 +126,7 @@
final LayoutInflater inflater = LayoutInflater.from(mContext);
final PreferenceViewHolder holder = PreferenceViewHolder.createInstanceForTests(
inflater.inflate(
- com.android.settingslib.widget.R.layout.preference_two_target, null));
+ com.android.settingslib.widget.preference.twotarget.R.layout.preference_two_target, null));
final LinearLayout widgetView = holder.itemView.findViewById(android.R.id.widget_frame);
assertThat(widgetView).isNotNull();
@@ -146,7 +146,7 @@
final LayoutInflater inflater = LayoutInflater.from(mContext);
final PreferenceViewHolder holder = PreferenceViewHolder.createInstanceForTests(
inflater.inflate(
- com.android.settingslib.widget.R.layout.preference_two_target, null));
+ com.android.settingslib.widget.preference.twotarget.R.layout.preference_two_target, null));
final LinearLayout widgetView = holder.itemView.findViewById(android.R.id.widget_frame);
assertThat(widgetView).isNotNull();
@@ -163,7 +163,7 @@
public void clickWidgetView_shouldNotifyPreferenceChanged() {
final PreferenceViewHolder holder = PreferenceViewHolder.createInstanceForTests(
LayoutInflater.from(mContext).inflate(
- com.android.settingslib.widget.R.layout.preference_two_target, null));
+ com.android.settingslib.widget.preference.twotarget.R.layout.preference_two_target, null));
final View widgetView = holder.findViewById(android.R.id.widget_frame);
final OnPreferenceChangeListener listener = mock(OnPreferenceChangeListener.class);
mPreference.setOnPreferenceChangeListener(listener);
diff --git a/tests/robotests/src/com/android/settings/widget/SettingsMainSwitchPreferenceTest.java b/tests/robotests/src/com/android/settings/widget/SettingsMainSwitchPreferenceTest.java
index c079029..d64d237 100644
--- a/tests/robotests/src/com/android/settings/widget/SettingsMainSwitchPreferenceTest.java
+++ b/tests/robotests/src/com/android/settings/widget/SettingsMainSwitchPreferenceTest.java
@@ -53,7 +53,7 @@
mPreference = new SettingsMainSwitchPreference(context);
ReflectionHelpers.setField(mPreference, "mEnforcedAdmin", mEnforcedAdmin);
ReflectionHelpers.setField(mPreference, "mMainSwitchBar", switchBar);
- final View rootView = View.inflate(context, R.layout.preference_widget_main_switch,
+ final View rootView = View.inflate(context, com.android.settings.R.layout.preference_widget_main_switch,
null /* parent */);
mHolder = PreferenceViewHolder.createInstanceForTests(rootView);
}
@@ -64,7 +64,7 @@
final SettingsMainSwitchBar switchBar = mPreference.getSwitchBar();
final ImageView restrictedIcon = switchBar.findViewById(
- com.android.settingslib.widget.R.id.restricted_icon);
+ com.android.settingslib.widget.restricted.R.id.restricted_icon);
assertThat(restrictedIcon.getVisibility() == View.VISIBLE).isTrue();
}
diff --git a/tests/robotests/src/com/android/settings/wifi/details/WifiNetworkDetailsFragmentTest.java b/tests/robotests/src/com/android/settings/wifi/details/WifiNetworkDetailsFragmentTest.java
index ad4aebf..8f96e27 100644
--- a/tests/robotests/src/com/android/settings/wifi/details/WifiNetworkDetailsFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/wifi/details/WifiNetworkDetailsFragmentTest.java
@@ -58,7 +58,6 @@
import com.android.settings.wifi.WifiUtils;
import com.android.settings.wifi.details2.WifiDetailPreferenceController2;
import com.android.settingslib.core.AbstractPreferenceController;
-import com.android.settingslib.graph.ThemedBatteryDrawable;
import com.android.wifitrackerlib.NetworkDetailsTracker;
import com.android.wifitrackerlib.WifiEntry;
@@ -67,7 +66,6 @@
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Answers;
-import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.Spy;
import org.mockito.junit.MockitoJUnit;
@@ -112,8 +110,6 @@
FakeFragment mFragment;
PreferenceScreen mScreen;
- ArgumentCaptor<ThemedBatteryDrawable> mThemedBatteryDrawableCaptor =
- ArgumentCaptor.forClass(ThemedBatteryDrawable.class);
@Before
public void setUp() {
@@ -290,25 +286,20 @@
}
@Test
- public void updateBattery_hiPercentageNoCharging_setResourceCorrect() {
+ public void updateBattery_hiPercentageNoCharging_setSummaryCorrect() {
mFragment.updateBattery(false /* isChanging */, BATTERY_PERCENTAGE_MAX);
verify(mBattery).setSummary(formatPercentage(BATTERY_PERCENTAGE_MAX));
- verify(mBattery).setIcon(mThemedBatteryDrawableCaptor.capture());
- ThemedBatteryDrawable drawable = mThemedBatteryDrawableCaptor.getValue();
- assertThat(drawable.getCharging()).isFalse();
- assertThat(drawable.getBatteryLevel()).isEqualTo(BATTERY_PERCENTAGE_MAX);
}
@Test
- public void updateBattery_lowPercentageWithCharging_setResourceCorrect() {
+ public void updateBattery_lowPercentageWithCharging_setSummaryCorrect() {
+ String summary = mContext.getString(R.string.hotspot_battery_charging_summary,
+ formatPercentage(0));
+
mFragment.updateBattery(true /* isChanging */, 0 /* percentage */);
- verify(mBattery).setSummary(formatPercentage(0));
- verify(mBattery).setIcon(mThemedBatteryDrawableCaptor.capture());
- ThemedBatteryDrawable drawable = mThemedBatteryDrawableCaptor.getValue();
- assertThat(drawable.getCharging()).isTrue();
- assertThat(drawable.getBatteryLevel()).isEqualTo(0);
+ verify(mBattery).setSummary(summary);
}
// Fake WifiNetworkDetailsFragment to override the protected method as public.
diff --git a/tests/spa_unit/src/com/android/settings/datausage/DataUsageListHeaderControllerTest.kt b/tests/spa_unit/src/com/android/settings/datausage/DataUsageListHeaderControllerTest.kt
new file mode 100644
index 0000000..a1eebe7
--- /dev/null
+++ b/tests/spa_unit/src/com/android/settings/datausage/DataUsageListHeaderControllerTest.kt
@@ -0,0 +1,82 @@
+/*
+ * 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.datausage
+
+import android.content.Context
+import android.net.NetworkTemplate
+import android.view.LayoutInflater
+import android.view.View
+import android.widget.Spinner
+import androidx.test.core.app.ApplicationProvider
+import androidx.test.ext.junit.runners.AndroidJUnit4
+import com.android.settings.R
+import com.google.common.truth.Truth.assertThat
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.mockito.kotlin.any
+import org.mockito.kotlin.doNothing
+import org.mockito.kotlin.mock
+import org.mockito.kotlin.spy
+import org.mockito.kotlin.whenever
+
+@RunWith(AndroidJUnit4::class)
+class DataUsageListHeaderControllerTest {
+
+ private val context: Context = spy(ApplicationProvider.getApplicationContext()) {
+ doNothing().whenever(mock).startActivity(any())
+ }
+
+ private val header =
+ LayoutInflater.from(context).inflate(R.layout.apps_filter_spinner, null, false)
+
+ private val configureButton: View = header.requireViewById(R.id.filter_settings)
+
+ private val spinner: Spinner = header.requireViewById(R.id.filter_spinner)
+
+ private val controller = DataUsageListHeaderController(
+ header = header,
+ template = mock<NetworkTemplate>(),
+ sourceMetricsCategory = 0,
+ onItemSelected = { _, _ -> },
+ )
+
+ @Test
+ fun onViewCreated_shouldHideCycleSpinner() {
+ assertThat(spinner.visibility).isEqualTo(View.GONE)
+ }
+
+ @Test
+ fun updateCycleData_shouldShowCycleSpinner() {
+ controller.updateCycleData(emptyList())
+
+ assertThat(spinner.visibility).isEqualTo(View.VISIBLE)
+ }
+
+ @Test
+ fun setConfigButtonVisible_setToTrue_shouldShowConfigureButton() {
+ controller.setConfigButtonVisible(true)
+
+ assertThat(configureButton.visibility).isEqualTo(View.VISIBLE)
+ }
+
+ @Test
+ fun setConfigButtonVisible_setToFalse_shouldHideConfigureButton() {
+ controller.setConfigButtonVisible(false)
+
+ assertThat(configureButton.visibility).isEqualTo(View.GONE)
+ }
+}
diff --git a/tests/unit/src/com/android/settings/network/telephony/BackupCallingPreferenceControllerTest.java b/tests/unit/src/com/android/settings/network/telephony/BackupCallingPreferenceControllerTest.java
deleted file mode 100644
index 4e110f0..0000000
--- a/tests/unit/src/com/android/settings/network/telephony/BackupCallingPreferenceControllerTest.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Copyright (C) 2020 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;
-
-import static com.google.common.truth.Truth.assertThat;
-
-import static org.mockito.Mockito.spy;
-
-import android.content.Context;
-
-import androidx.test.core.app.ApplicationProvider;
-import androidx.test.ext.junit.runners.AndroidJUnit4;
-
-import com.android.settings.core.BasePreferenceController;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-
-@RunWith(AndroidJUnit4.class)
-public class BackupCallingPreferenceControllerTest {
- private static final int SUB_ID = 2;
-
- private BackupCallingPreferenceController mController;
- private Context mContext;
-
- @Before
- public void setUp() {
- mContext = spy(ApplicationProvider.getApplicationContext());
-
- mController = new BackupCallingPreferenceController(mContext, "backup_calling_key");
- mController.init(SUB_ID);
- }
-
- @Test
- public void controller_isUnavailable() {
- assertThat(mController.getAvailabilityStatus())
- .isEqualTo(BasePreferenceController.CONDITIONALLY_UNAVAILABLE);
- }
-}
diff --git a/tests/unit/src/com/android/settings/network/telephony/NetworkProviderBackupCallingGroupTest.java b/tests/unit/src/com/android/settings/network/telephony/NetworkProviderBackupCallingGroupTest.java
deleted file mode 100644
index a5717ef..0000000
--- a/tests/unit/src/com/android/settings/network/telephony/NetworkProviderBackupCallingGroupTest.java
+++ /dev/null
@@ -1,168 +0,0 @@
-/*
- * Copyright (C) 2021 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;
-
-import static com.google.common.truth.Truth.assertThat;
-
-import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.spy;
-import static org.mockito.Mockito.when;
-
-import android.content.Context;
-import android.os.Looper;
-import android.os.PersistableBundle;
-import android.telephony.CarrierConfigManager;
-import android.telephony.SubscriptionInfo;
-import android.telephony.SubscriptionManager;
-import android.telephony.TelephonyManager;
-
-import androidx.preference.PreferenceGroup;
-import androidx.preference.PreferenceManager;
-import androidx.preference.PreferenceScreen;
-import androidx.preference.SwitchPreference;
-import androidx.test.core.app.ApplicationProvider;
-import androidx.test.ext.junit.runners.AndroidJUnit4;
-
-import com.android.settings.network.CarrierConfigCache;
-import com.android.settingslib.core.lifecycle.Lifecycle;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
-
-import java.util.List;
-
-@RunWith(AndroidJUnit4.class)
-public class NetworkProviderBackupCallingGroupTest {
-
- private static final int SUB_ID_1 = 1;
- private static final int SUB_ID_2 = 2;
-
- private static final String KEY_PREFERENCE_CATEGORY_BACKUP_CALLING =
- "provider_model_backup_calling_category";
- private static final String DISPLAY_NAME_1 = "Test Display Name 1";
- private static final String DISPLAY_NAME_2 = "Test Display Name 2";
-
- @Mock
- private PreferenceGroup mPreferenceGroup;
- @Mock
- private CarrierConfigCache mCarrierConfigCache;
- @Mock
- private Lifecycle mLifecycle;
- @Mock
- private SubscriptionManager mSubscriptionManager;
- @Mock
- private SubscriptionInfo mSubscriptionInfo1;
- @Mock
- private SubscriptionInfo mSubscriptionInfo2;
- @Mock
- private List<SubscriptionInfo> mSubscriptionInfoList;
- @Mock
- private TelephonyManager mTelephonyManager1;
- @Mock
- private TelephonyManager mTelephonyManager2;
-
- @Mock
- private NetworkProviderBackupCallingGroup mNetworkProviderBackupCallingGroup;
- private Context mContext;
- private PersistableBundle mCarrierConfig;
- private PreferenceManager mPreferenceManager;
- private PreferenceScreen mPreferenceScreen;
- private SwitchPreference mSwitchPreference1;
- private SwitchPreference mSwitchPreference2;
-
- @Before
- public void setUp() throws Exception {
- MockitoAnnotations.initMocks(this);
- mContext = spy(ApplicationProvider.getApplicationContext());
- when(mContext.getSystemService(TelephonyManager.class)).thenReturn(mTelephonyManager1);
- when(mTelephonyManager1.createForSubscriptionId(SUB_ID_1)).thenReturn(mTelephonyManager1);
- when(mContext.getSystemService(TelephonyManager.class)).thenReturn(mTelephonyManager2);
- when(mTelephonyManager2.createForSubscriptionId(SUB_ID_2)).thenReturn(mTelephonyManager2);
- when(mContext.getSystemService(SubscriptionManager.class)).thenReturn(mSubscriptionManager);
- when(mSubscriptionInfo1.getSubscriptionId()).thenReturn(SUB_ID_1);
- when(mSubscriptionInfo1.getDisplayName()).thenReturn(DISPLAY_NAME_1);
- doReturn(true).when(mNetworkProviderBackupCallingGroup).isCrossSimEnabledByPlatform(
- mContext, SUB_ID_1);
- mSubscriptionInfoList.add(mSubscriptionInfo1);
- when(mSubscriptionInfo2.getSubscriptionId()).thenReturn(SUB_ID_2);
- when(mSubscriptionInfo2.getDisplayName()).thenReturn(DISPLAY_NAME_2);
- doReturn(true).when(mNetworkProviderBackupCallingGroup).isCrossSimEnabledByPlatform(
- mContext, SUB_ID_2);
- mSubscriptionInfoList.add(mSubscriptionInfo2);
- when(mSubscriptionManager.getActiveSubscriptionInfoList()).thenReturn(
- mSubscriptionInfoList);
-
- CarrierConfigCache.setTestInstance(mContext, mCarrierConfigCache);
- mCarrierConfig = new PersistableBundle();
- doReturn(mCarrierConfig).when(mCarrierConfigCache).getConfigForSubId(SUB_ID_1);
- mCarrierConfig.putBoolean(CarrierConfigManager.KEY_CARRIER_CROSS_SIM_IMS_AVAILABLE_BOOL,
- true);
- doReturn(mCarrierConfig).when(mCarrierConfigCache).getConfigForSubId(SUB_ID_2);
- mCarrierConfig.putBoolean(CarrierConfigManager.KEY_CARRIER_CROSS_SIM_IMS_AVAILABLE_BOOL,
- true);
-
- if (Looper.myLooper() == null) {
- Looper.prepare();
- }
-
- mPreferenceManager = new PreferenceManager(mContext);
- mPreferenceScreen = mPreferenceManager.createPreferenceScreen(mContext);
- when(mPreferenceGroup.getKey()).thenReturn(KEY_PREFERENCE_CATEGORY_BACKUP_CALLING);
- when(mPreferenceGroup.getPreferenceCount()).thenReturn(2);
- mPreferenceScreen.addPreference(mPreferenceGroup);
-
- mNetworkProviderBackupCallingGroup = spy(new NetworkProviderBackupCallingGroup(
- mContext, mLifecycle, mSubscriptionInfoList,
- KEY_PREFERENCE_CATEGORY_BACKUP_CALLING));
- }
-
- @Test
- public void shouldShowBackupCallingForSub_invalidSubId_returnFalse() {
- assertThat(mNetworkProviderBackupCallingGroup.hasBackupCallingFeature(
- SubscriptionManager.INVALID_SUBSCRIPTION_ID)).isEqualTo(false);
- }
-
- @Test
- public void shouldShowBackupCallingForSub_carrierConfigIsUnavailable_returnFalse() {
- mCarrierConfig.putBoolean(CarrierConfigManager.KEY_CARRIER_CROSS_SIM_IMS_AVAILABLE_BOOL,
- false);
-
- assertThat(mNetworkProviderBackupCallingGroup.hasBackupCallingFeature(SUB_ID_1))
- .isEqualTo(false);
- }
-
- @Test
- public void
- shouldShowBackupCallingForSub_crossSimDisabled_returnFalse() {
- doReturn(false).when(mNetworkProviderBackupCallingGroup).isCrossSimEnabledByPlatform(
- mContext, SUB_ID_1);
-
- assertThat(mNetworkProviderBackupCallingGroup.hasBackupCallingFeature(SUB_ID_1))
- .isEqualTo(false);
- }
-
- @Test
- public void shouldBackupCallingForSub_crossSimEnabled_returnTrue() {
- doReturn(true).when(mNetworkProviderBackupCallingGroup).isCrossSimEnabledByPlatform(
- mContext, SUB_ID_1);
-
- assertThat(mNetworkProviderBackupCallingGroup.hasBackupCallingFeature(SUB_ID_1))
- .isEqualTo(true);
- }
-}