Merge "Add Private Space settings page" into main
diff --git a/TEST_MAPPING b/TEST_MAPPING
index 4e85cb8..9722a85 100644
--- a/TEST_MAPPING
+++ b/TEST_MAPPING
@@ -28,6 +28,14 @@
]
},
{
+ "name": "SettingsUITests",
+ "options": [
+ {
+ "exclude-annotation": "org.junit.Ignore"
+ }
+ ]
+ },
+ {
"name": "SettingsPerfTests"
}
]
diff --git a/res/layout/data_usage_summary_preference.xml b/res/layout/data_usage_summary_preference.xml
index 856d146..24399ac 100644
--- a/res/layout/data_usage_summary_preference.xml
+++ b/res/layout/data_usage_summary_preference.xml
@@ -121,14 +121,5 @@
</LinearLayout>
- <Button
- android:id="@+id/launch_mdp_app_button"
- android:layout_marginTop="12dp"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_gravity="start"
- android:text="@string/launch_mdp_app_text"
- style="@style/ActionPrimaryButton" />
-
</LinearLayout>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 9942534..e9a547c 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -9765,9 +9765,6 @@
<!-- Informational text about recent update time only, without carrier [CHAR LIMIT=30] -->
<string name="no_carrier_update_now_text">Updated just now</string>
- <!-- Button to launch external data plan app [CHAR LIMIT=30] -->
- <string name="launch_mdp_app_text">View plan</string>
-
<!-- Alternate launch button text for Wi-Fi only mode [CHAR LIMIT=30] -->
<string name="launch_wifi_text">View details</string>
@@ -10740,6 +10737,8 @@
<!-- Title for preference showing the primary account on the device [CHAR LIMIT=60]-->
<string name="my_device_info_account_preference_title">Account</string>
+ <!-- Summary for preference showing the number of the accounts. [CHAR LIMIT=NONE]-->
+ <string name="my_device_info_account_preference_summary">%d accounts</string>
<!-- Title for preference showing the name of the device. [CHAR LIMIT=60]-->
<string name="my_device_info_device_name_preference_title">Device name</string>
diff --git a/src/com/android/settings/applications/appcompat/UserAspectRatioDetails.java b/src/com/android/settings/applications/appcompat/UserAspectRatioDetails.java
index fd831cd..68ebf8a 100644
--- a/src/com/android/settings/applications/appcompat/UserAspectRatioDetails.java
+++ b/src/com/android/settings/applications/appcompat/UserAspectRatioDetails.java
@@ -37,10 +37,14 @@
import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;
+import androidx.preference.Preference;
import com.android.internal.annotations.VisibleForTesting;
import com.android.settings.R;
-import com.android.settings.applications.AppInfoWithHeader;
+import com.android.settings.Utils;
+import com.android.settings.applications.AppInfoBase;
+import com.android.settings.widget.EntityHeaderController;
+import com.android.settingslib.applications.AppUtils;
import com.android.settingslib.widget.ActionButtonsPreference;
import java.util.ArrayList;
@@ -49,7 +53,7 @@
/**
* App specific activity to show aspect ratio overrides
*/
-public class UserAspectRatioDetails extends AppInfoWithHeader implements
+public class UserAspectRatioDetails extends AppInfoBase implements
RadioWithImagePreference.OnClickListener {
private static final String TAG = UserAspectRatioDetails.class.getSimpleName();
@@ -178,6 +182,24 @@
}
}
+ @Override
+ public void onActivityCreated(Bundle savedInstanceState) {
+ super.onActivityCreated(savedInstanceState);
+ final Preference pref = EntityHeaderController
+ .newInstance(getActivity(), this, null /* header */)
+ .setIcon(Utils.getBadgedIcon(getContext(), mPackageInfo.applicationInfo))
+ .setLabel(mPackageInfo.applicationInfo.loadLabel(mPm))
+ .setIsInstantApp(AppUtils.isInstant(mPackageInfo.applicationInfo))
+ .setPackageName(mPackageName)
+ .setUid(mPackageInfo.applicationInfo.uid)
+ .setHasAppInfoLink(true)
+ .setButtonActions(EntityHeaderController.ActionType.ACTION_NONE,
+ EntityHeaderController.ActionType.ACTION_NONE)
+ .done(getPrefContext());
+
+ getPreferenceScreen().addPreference(pref);
+ }
+
private void initPreferences() {
addPreferencesFromResource(R.xml.user_aspect_ratio_details);
diff --git a/src/com/android/settings/applications/credentials/CredentialManagerPreferenceController.java b/src/com/android/settings/applications/credentials/CredentialManagerPreferenceController.java
index f704ca8..4ba634c 100644
--- a/src/com/android/settings/applications/credentials/CredentialManagerPreferenceController.java
+++ b/src/com/android/settings/applications/credentials/CredentialManagerPreferenceController.java
@@ -47,6 +47,8 @@
import android.text.TextUtils;
import android.util.IconDrawableFactory;
import android.util.Log;
+import android.view.View;
+import android.widget.Switch;
import androidx.appcompat.app.AlertDialog;
import androidx.core.content.ContextCompat;
@@ -58,7 +60,7 @@
import androidx.preference.Preference;
import androidx.preference.PreferenceGroup;
import androidx.preference.PreferenceScreen;
-import androidx.preference.SwitchPreference;
+import androidx.preference.PreferenceViewHolder;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.content.PackageMonitor;
@@ -67,6 +69,7 @@
import com.android.settings.core.BasePreferenceController;
import com.android.settings.dashboard.DashboardFragment;
import com.android.settingslib.utils.ThreadUtils;
+import com.android.settingslib.widget.TwoTargetPreference;
import java.util.ArrayList;
import java.util.HashMap;
@@ -100,7 +103,7 @@
private final Set<String> mEnabledPackageNames;
private final @Nullable CredentialManager mCredentialManager;
private final Executor mExecutor;
- private final Map<String, SwitchPreference> mPrefs = new HashMap<>(); // key is package name
+ private final Map<String, CombiPreference> mPrefs = new HashMap<>(); // key is package name
private final List<ServiceInfo> mPendingServiceInfos = new ArrayList<>();
private final Handler mHandler = new Handler();
private final SettingContentObserver mSettingsContentObserver;
@@ -389,7 +392,7 @@
/** Aggregates the list of services and builds a list of UI prefs to show. */
@VisibleForTesting
- public Map<String, SwitchPreference> buildPreferenceList(
+ public Map<String, CombiPreference> buildPreferenceList(
Context context, PreferenceGroup group) {
// Get the selected autofill provider. If it is the placeholder then replace it with an
// empty string.
@@ -415,7 +418,7 @@
return new HashMap<>();
}
- Map<String, SwitchPreference> output = new HashMap<>();
+ Map<String, CombiPreference> output = new HashMap<>();
for (CombinedProviderInfo combinedInfo : providers) {
final String packageName = combinedInfo.getApplicationInfo().packageName;
@@ -434,7 +437,7 @@
CharSequence title = combinedInfo.getAppName(context);
// Build the pref and add it to the output & group.
- SwitchPreference pref =
+ CombiPreference pref =
addProviderPreference(
context, title, icon, packageName, combinedInfo.getSettingsSubtitle());
output.put(packageName, pref);
@@ -449,7 +452,7 @@
/** Creates a preference object based on the provider info. */
@VisibleForTesting
- public SwitchPreference createPreference(Context context, CredentialProviderInfo service) {
+ public CombiPreference createPreference(Context context, CredentialProviderInfo service) {
CharSequence label = service.getLabel(context);
return addProviderPreference(
context,
@@ -510,15 +513,15 @@
return enabledServices;
}
- private SwitchPreference addProviderPreference(
+ private CombiPreference addProviderPreference(
@NonNull Context prefContext,
@NonNull CharSequence title,
@Nullable Drawable icon,
@NonNull String packageName,
@Nullable CharSequence subtitle) {
- final SwitchPreference pref = new SwitchPreference(prefContext);
+ final CombiPreference pref =
+ new CombiPreference(prefContext, mEnabledPackageNames.contains(packageName));
pref.setTitle(title);
- pref.setChecked(mEnabledPackageNames.contains(packageName));
if (icon != null) {
pref.setIcon(Utils.getSafeIcon(icon));
@@ -528,10 +531,8 @@
pref.setSummary(subtitle);
}
- pref.setOnPreferenceClickListener(
- p -> {
- boolean isChecked = pref.isChecked();
-
+ pref.setPreferenceListener(
+ (p, isChecked) -> {
if (isChecked) {
if (mEnabledPackageNames.size() >= MAX_SELECTABLE_PROVIDERS) {
// Show the error if too many enabled.
@@ -539,11 +540,11 @@
final DialogFragment fragment = newErrorDialogFragment();
if (fragment == null || mFragmentManager == null) {
- return true;
+ return;
}
fragment.show(mFragmentManager, ErrorDialogFragment.TAG);
- return true;
+ return;
}
togglePackageNameEnabled(packageName);
@@ -552,12 +553,9 @@
if (mPrefs.containsKey(packageName)) {
mPrefs.get(packageName).setChecked(true);
}
- return true;
} else {
togglePackageNameDisabled(packageName);
}
-
- return true;
});
return pref;
@@ -836,4 +834,80 @@
updateFromExternal();
}
}
-}
\ No newline at end of file
+
+ /** CombiPreference is a combination of TwoTargetPreference and SwitchPreference. */
+ public static class CombiPreference extends TwoTargetPreference {
+
+ private final Listener mListener = new Listener();
+
+ private class Listener implements View.OnClickListener {
+ @Override
+ public void onClick(View buttonView) {
+ // Forward the event.
+ if (mSwitch != null) {
+ mOnClickListener.onCheckChanged(CombiPreference.this, mSwitch.isChecked());
+ }
+ }
+ }
+
+ // Stores a reference to the switch view.
+ private @Nullable Switch mSwitch;
+
+ // Switch text for on and off states
+ private @NonNull boolean mChecked = false;
+ private @Nullable OnCombiPreferenceClickListener mOnClickListener = null;
+
+ public interface OnCombiPreferenceClickListener {
+ /** Called when the check is updated */
+ void onCheckChanged(CombiPreference p, boolean isChecked);
+ }
+
+ public CombiPreference(Context context, boolean initialValue) {
+ super(context);
+ mChecked = initialValue;
+ }
+
+ /** Set the new checked value */
+ public void setChecked(boolean isChecked) {
+ // Don't update if we don't need too.
+ if (mChecked == isChecked) {
+ return;
+ }
+
+ mChecked = isChecked;
+
+ if (mSwitch != null) {
+ mSwitch.setChecked(isChecked);
+ }
+ }
+
+ public boolean isChecked() {
+ return mChecked;
+ }
+
+ public void setPreferenceListener(OnCombiPreferenceClickListener onClickListener) {
+ mOnClickListener = onClickListener;
+ }
+
+ @Override
+ protected int getSecondTargetResId() {
+ return R.layout.preference_widget_primary_switch;
+ }
+
+ @Override
+ public void onBindViewHolder(PreferenceViewHolder view) {
+ super.onBindViewHolder(view);
+
+ // Setup the switch.
+ View checkableView = view.itemView.findViewById(R.id.switchWidget);
+ if (checkableView != null && checkableView instanceof Switch) {
+ final Switch switchView = (Switch) checkableView;
+ switchView.setChecked(mChecked);
+ switchView.setOnClickListener(mListener);
+
+ // Store this for later.
+ mSwitch = switchView;
+ }
+ }
+ }
+}
diff --git a/src/com/android/settings/core/FeatureFlags.java b/src/com/android/settings/core/FeatureFlags.java
index fb552d7..3c17e6e 100644
--- a/src/com/android/settings/core/FeatureFlags.java
+++ b/src/com/android/settings/core/FeatureFlags.java
@@ -22,14 +22,10 @@
public class FeatureFlags {
public static final String AUDIO_SWITCHER_SETTINGS = "settings_audio_switcher";
public static final String HEARING_AID_SETTINGS = "settings_bluetooth_hearing_aid";
- public static final String WIFI_DETAILS_DATAUSAGE_HEADER =
- "settings_wifi_details_datausage_header";
public static final String CONTROLLER_ENHANCEMENT = "settings_controller_loading_enhancement";
public static final String CONDITIONAL_CARDS = "settings_conditionals";
public static final String TETHER_ALL_IN_ONE = "settings_tether_all_in_one";
public static final String CONTEXTUAL_HOME = "settings_contextual_home";
public static final String SETTINGS_SEARCH_ALWAYS_EXPAND =
"settings_search_always_expand";
- public static final String PRESS_HOLD_NAV_HANDLE_TO_SEARCH =
- "settings_press_hold_nav_handle_to_search";
}
diff --git a/src/com/android/settings/core/SettingsUIDeviceConfig.java b/src/com/android/settings/core/SettingsUIDeviceConfig.java
index 4d96385..2401ff5 100644
--- a/src/com/android/settings/core/SettingsUIDeviceConfig.java
+++ b/src/com/android/settings/core/SettingsUIDeviceConfig.java
@@ -48,6 +48,11 @@
public static final String BT_LE_AUDIO_DEVICE_DETAIL_ENABLED =
"bt_le_audio_device_detail_enabled";
/**
+ * {@code true} if press and hold nav handle to search is enabled.
+ */
+ public static final String PRESS_HOLD_NAV_HANDLE_TO_SEARCH =
+ "press_hold_nav_handle_to_search";
+ /**
* {@code true} if long press home button to search is enabled.
*/
public static final String LONG_PRESS_HOME_BUTTON_TO_SEARCH =
diff --git a/src/com/android/settings/datausage/DataUsageSummaryPreference.java b/src/com/android/settings/datausage/DataUsageSummaryPreference.java
index a14fce3..f2fcddd 100644
--- a/src/com/android/settings/datausage/DataUsageSummaryPreference.java
+++ b/src/com/android/settings/datausage/DataUsageSummaryPreference.java
@@ -17,14 +17,10 @@
package com.android.settings.datausage;
import android.annotation.AttrRes;
-import android.app.settings.SettingsEnums;
import android.content.Context;
-import android.content.Intent;
import android.graphics.Typeface;
import android.icu.text.MessageFormat;
-import android.net.ConnectivityManager;
import android.net.NetworkTemplate;
-import android.os.Bundle;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.TextUtils;
@@ -32,7 +28,6 @@
import android.text.style.AbsoluteSizeSpan;
import android.util.AttributeSet;
import android.view.View;
-import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;
@@ -42,7 +37,6 @@
import androidx.preference.PreferenceViewHolder;
import com.android.settings.R;
-import com.android.settings.core.SubSettingLauncher;
import com.android.settingslib.Utils;
import com.android.settingslib.net.DataUsageController;
import com.android.settingslib.utils.StringUtil;
@@ -77,7 +71,6 @@
/** Name of carrier, or null if not available */
private CharSequence mCarrierName;
private CharSequence mLimitInfoText;
- private Intent mLaunchIntent;
/** Progress to display on ProgressBar */
private float mProgress;
@@ -92,11 +85,6 @@
/** The number of bytes used since the start of the cycle. */
private long mDataplanUse;
- /** WiFi only mode */
- private boolean mWifiMode;
- private String mUsagePeriod;
- private boolean mSingleWifi; // Shows only one specified WiFi network usage
-
public DataUsageSummaryPreference(Context context, AttributeSet attrs) {
super(context, attrs);
setLayoutResource(R.layout.data_usage_summary_preference);
@@ -115,12 +103,11 @@
}
public void setUsageInfo(long cycleEnd, long snapshotTime, CharSequence carrierName,
- int numPlans, Intent launchIntent) {
+ int numPlans) {
mCycleEndTimeMs = cycleEnd;
mSnapshotTimeMs = snapshotTime;
mCarrierName = carrierName;
mNumPlans = numPlans;
- mLaunchIntent = launchIntent;
notifyChanged();
}
@@ -144,13 +131,6 @@
notifyChanged();
}
- void setWifiMode(boolean isWifiMode, String usagePeriod, boolean isSingleWifi) {
- mWifiMode = isWifiMode;
- mUsagePeriod = usagePeriod;
- mSingleWifi = isSingleWifi;
- notifyChanged();
- }
-
@Override
public void onBindViewHolder(PreferenceViewHolder holder) {
super.onBindViewHolder(holder);
@@ -171,66 +151,13 @@
TextView usageTitle = getUsageTitle(holder);
TextView carrierInfo = getCarrierInfo(holder);
- Button launchButton = getLaunchButton(holder);
TextView limitInfo = getDataLimits(holder);
- if (mWifiMode && mSingleWifi) {
- updateCycleTimeText(holder);
-
- usageTitle.setVisibility(View.GONE);
- launchButton.setVisibility(View.GONE);
- carrierInfo.setVisibility(View.GONE);
-
- limitInfo.setVisibility(TextUtils.isEmpty(mLimitInfoText) ? View.GONE : View.VISIBLE);
- limitInfo.setText(mLimitInfoText);
- } else if (mWifiMode) {
- usageTitle.setText(R.string.data_usage_wifi_title);
- usageTitle.setVisibility(View.VISIBLE);
- TextView cycleTime = getCycleTime(holder);
- cycleTime.setText(mUsagePeriod);
- carrierInfo.setVisibility(View.GONE);
- limitInfo.setVisibility(View.GONE);
-
- final long usageLevel = getHistoricalUsageLevel();
- if (usageLevel > 0L) {
- launchButton.setOnClickListener((view) -> {
- launchWifiDataUsage(getContext());
- });
- } else {
- launchButton.setEnabled(false);
- }
- launchButton.setText(R.string.launch_wifi_text);
- launchButton.setVisibility(View.VISIBLE);
- } else {
- usageTitle.setVisibility(mNumPlans > 1 ? View.VISIBLE : View.GONE);
- updateCycleTimeText(holder);
- updateCarrierInfo(carrierInfo);
- if (mLaunchIntent != null) {
- launchButton.setOnClickListener((view) -> {
- getContext().startActivity(mLaunchIntent);
- });
- launchButton.setVisibility(View.VISIBLE);
- } else {
- launchButton.setVisibility(View.GONE);
- }
- limitInfo.setVisibility(
- TextUtils.isEmpty(mLimitInfoText) ? View.GONE : View.VISIBLE);
- limitInfo.setText(mLimitInfoText);
- }
- }
-
- @VisibleForTesting
- static void launchWifiDataUsage(Context context) {
- final Bundle args = new Bundle(1);
- args.putParcelable(DataUsageList.EXTRA_NETWORK_TEMPLATE,
- new NetworkTemplate.Builder(NetworkTemplate.MATCH_WIFI).build());
- args.putInt(DataUsageList.EXTRA_NETWORK_TYPE, ConnectivityManager.TYPE_WIFI);
- final SubSettingLauncher launcher = new SubSettingLauncher(context)
- .setArguments(args)
- .setDestination(DataUsageList.class.getName())
- .setSourceMetricsCategory(SettingsEnums.PAGE_UNKNOWN);
- launcher.setTitleRes(R.string.wifi_data_usage);
- launcher.launch();
+ usageTitle.setVisibility(mNumPlans > 1 ? View.VISIBLE : View.GONE);
+ updateCycleTimeText(holder);
+ updateCarrierInfo(carrierInfo);
+ limitInfo.setVisibility(TextUtils.isEmpty(mLimitInfoText) ? View.GONE : View.VISIBLE);
+ limitInfo.setText(mLimitInfoText);
}
private void updateDataUsageLabels(PreferenceViewHolder holder) {
@@ -404,11 +331,6 @@
}
@VisibleForTesting
- protected Button getLaunchButton(PreferenceViewHolder holder) {
- return (Button) holder.findViewById(R.id.launch_mdp_app_button);
- }
-
- @VisibleForTesting
protected LinearLayout getLabelBar(PreferenceViewHolder holder) {
return (LinearLayout) holder.findViewById(R.id.label_bar);
}
diff --git a/src/com/android/settings/datausage/DataUsageSummaryPreferenceController.java b/src/com/android/settings/datausage/DataUsageSummaryPreferenceController.java
index 3948a38..35f5931 100644
--- a/src/com/android/settings/datausage/DataUsageSummaryPreferenceController.java
+++ b/src/com/android/settings/datausage/DataUsageSummaryPreferenceController.java
@@ -18,13 +18,8 @@
import android.app.Activity;
import android.content.Context;
-import android.content.Intent;
-import android.content.pm.PackageManager;
-import android.net.INetworkPolicyManager;
import android.net.NetworkTemplate;
-import android.os.ServiceManager;
import android.telephony.SubscriptionInfo;
-import android.telephony.SubscriptionManager;
import android.telephony.SubscriptionPlan;
import android.text.TextUtils;
import android.util.Log;
@@ -83,8 +78,6 @@
/** The ending time of the billing cycle in ms since the epoch */
private long mCycleEnd;
- private Intent mManageSubscriptionIntent;
-
private Future<Long> mHistoricalUsageLevel;
public DataUsageSummaryPreferenceController(Activity activity, int subscriptionId) {
@@ -111,10 +104,6 @@
if (subInfo != null) {
mDefaultTemplate = DataUsageLib.getMobileTemplate(context, subscriptionId);
- } else if (DataUsageUtils.hasWifiRadio(context)) {
- mDefaultTemplate = new NetworkTemplate.Builder(NetworkTemplate.MATCH_WIFI).build();
- } else {
- mDefaultTemplate = DataUsageUtils.getDefaultTemplate(context, subscriptionId);
}
}
@@ -154,8 +143,7 @@
@Override
public int getAvailabilityStatus(int subId) {
- return (getSubscriptionInfo(subId) != null)
- || DataUsageUtils.hasWifiRadio(mContext) ? AVAILABLE : CONDITIONALLY_UNAVAILABLE;
+ return getSubscriptionInfo(subId) != null ? AVAILABLE : CONDITIONALLY_UNAVAILABLE;
}
@Override
@@ -163,6 +151,9 @@
DataUsageSummaryPreference summaryPreference = (DataUsageSummaryPreference) preference;
final SubscriptionInfo subInfo = getSubscriptionInfo(mSubId);
+ if (subInfo == null) {
+ return;
+ }
if (mDataUsageController == null) {
updateConfiguration(mContext, mSubId, subInfo);
}
@@ -175,25 +166,6 @@
long usageLevel = info.usageLevel;
- if (subInfo != null) {
- summaryPreference.setWifiMode(/* isWifiMode */ false,
- /* usagePeriod */ null, /* isSingleWifi */ false);
- } else {
- summaryPreference.setWifiMode(/* isWifiMode */ true, /* usagePeriod */
- info.period, /* isSingleWifi */ false);
- summaryPreference.setLimitInfo(null);
- summaryPreference.setUsageNumbers(displayUsageLevel(usageLevel),
- /* dataPlanSize */ -1L,
- /* hasMobileData */ true);
- summaryPreference.setChartEnabled(false);
- summaryPreference.setUsageInfo(info.cycleEnd,
- /* snapshotTime */ -1L,
- /* carrierName */ null,
- /* numPlans */ 0,
- /* launchIntent */ null);
- return;
- }
-
refreshDataplanInfo(info, subInfo);
if (info.warningLevel > 0 && info.limitLevel > 0) {
@@ -229,8 +201,7 @@
DataUsageUtils.formatDataUsage(mContext, mDataBarSize));
summaryPreference.setProgress(mDataplanUse / (float) mDataBarSize);
}
- summaryPreference.setUsageInfo(mCycleEnd, mSnapshotTime, mCarrierName,
- mDataplanCount, mManageSubscriptionIntent);
+ summaryPreference.setUsageInfo(mCycleEnd, mSnapshotTime, mCarrierName, mDataplanCount);
}
private long displayUsageLevel(long usageLevel) {
@@ -278,53 +249,7 @@
mSnapshotTime = primaryPlan.getDataUsageTime();
}
}
- // Temporarily return null, since no current users of SubscriptionPlan have this intent set.
- // TODO (b/170330084): Remove after refactoring 5G SubscriptionPlan logic.
- // mManageSubscriptionIntent = createManageSubscriptionIntent(mSubId);
- mManageSubscriptionIntent = null;
- Log.i(TAG, "Have " + mDataplanCount + " plans, dflt sub-id " + mSubId
- + ", intent " + mManageSubscriptionIntent);
- }
-
- /**
- * Create an {@link Intent} that can be launched towards the carrier app
- * that is currently defining the billing relationship plan through
- * {@link INetworkPolicyManager#setSubscriptionPlans(int, SubscriptionPlan [], String)}.
- *
- * @return ready to launch Intent targeted towards the carrier app, or
- * {@code null} if no carrier app is defined, or if the defined
- * carrier app provides no management activity.
- */
- @VisibleForTesting
- Intent createManageSubscriptionIntent(int subId) {
- final INetworkPolicyManager iNetPolicyManager = INetworkPolicyManager.Stub.asInterface(
- ServiceManager.getService(Context.NETWORK_POLICY_SERVICE));
- String owner = "";
- try {
- owner = iNetPolicyManager.getSubscriptionPlansOwner(subId);
- } catch (Exception ex) {
- Log.w(TAG, "Fail to get subscription plan owner for subId " + subId, ex);
- }
-
- if (TextUtils.isEmpty(owner)) {
- return null;
- }
-
- final List<SubscriptionPlan> plans = getSubscriptionPlans(subId);
- if (plans.isEmpty()) {
- return null;
- }
-
- final Intent intent = new Intent(SubscriptionManager.ACTION_MANAGE_SUBSCRIPTION_PLANS);
- intent.setPackage(owner);
- intent.putExtra(SubscriptionManager.EXTRA_SUBSCRIPTION_INDEX, subId);
-
- if (mContext.getPackageManager().queryIntentActivities(intent,
- PackageManager.MATCH_DEFAULT_ONLY).isEmpty()) {
- return null;
- }
-
- return intent;
+ Log.i(TAG, "Have " + mDataplanCount + " plans, dflt sub-id " + mSubId);
}
private static SubscriptionPlan getPrimaryPlan(List<SubscriptionPlan> plans) {
diff --git a/src/com/android/settings/datausage/WifiDataUsageSummaryPreferenceController.java b/src/com/android/settings/datausage/WifiDataUsageSummaryPreferenceController.java
deleted file mode 100644
index 782ce01..0000000
--- a/src/com/android/settings/datausage/WifiDataUsageSummaryPreferenceController.java
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * Copyright (C) 2019 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.app.Activity;
-import android.net.NetworkTemplate;
-import android.telephony.SubscriptionManager;
-
-import androidx.preference.Preference;
-
-import com.android.settingslib.net.DataUsageController;
-
-import java.util.HashSet;
-import java.util.Set;
-
-/**
- * The controller displays a data usage chart for the specified Wi-Fi network.
- */
-public class WifiDataUsageSummaryPreferenceController extends DataUsageSummaryPreferenceController {
- final Set<String> mAllNetworkKeys;
-
- public WifiDataUsageSummaryPreferenceController(Activity activity, Set<String> allNetworkKeys) {
- super(activity, SubscriptionManager.INVALID_SUBSCRIPTION_ID);
- mAllNetworkKeys = new HashSet<>(allNetworkKeys);
- }
-
- @Override
- public void updateState(Preference preference) {
- if (preference == null) {
- return;
- }
-
- final DataUsageSummaryPreference mPreference = (DataUsageSummaryPreference) preference;
- final NetworkTemplate template = new NetworkTemplate.Builder(NetworkTemplate.MATCH_WIFI)
- .setWifiNetworkKeys(mAllNetworkKeys).build();
- if (mDataUsageController == null) {
- updateConfiguration(mContext, mSubId, getSubscriptionInfo(mSubId));
- }
- final DataUsageController.DataUsageInfo info = mDataUsageController.getDataUsageInfo(
- template);
-
- mPreference.setWifiMode(/* isWifiMode */ true, /* usagePeriod */
- info.period, /* isSingleWifi */ true);
- mPreference.setChartEnabled(true);
- // Treats Wi-Fi network as unlimited network, which has same usage level and limited level.
- mPreference.setUsageNumbers(info.usageLevel, info.usageLevel, /* hasMobileData */ false);
-
- // TODO(b/126142293): Passpoint Wi-Fi should have limit of data usage and time remaining
- mPreference.setProgress(100);
- mPreference.setLabels(DataUsageUtils.formatDataUsage(mContext, /* sizeBytes */ 0),
- DataUsageUtils.formatDataUsage(mContext, info.usageLevel));
- }
-}
diff --git a/src/com/android/settings/deviceinfo/BrandedAccountPreferenceController.java b/src/com/android/settings/deviceinfo/BrandedAccountPreferenceController.java
index 9daa43d..13aac5c 100644
--- a/src/com/android/settings/deviceinfo/BrandedAccountPreferenceController.java
+++ b/src/com/android/settings/deviceinfo/BrandedAccountPreferenceController.java
@@ -19,14 +19,13 @@
import android.accounts.Account;
import android.app.settings.SettingsEnums;
import android.content.Context;
-import android.os.Bundle;
import android.text.TextUtils;
import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
import com.android.settings.R;
-import com.android.settings.accounts.AccountDetailDashboardFragment;
+import com.android.settings.accounts.AccountDashboardFragment;
import com.android.settings.accounts.AccountFeatureProvider;
import com.android.settings.core.BasePreferenceController;
import com.android.settings.core.SubSettingLauncher;
@@ -63,7 +62,11 @@
return;
}
- accountPreference.setSummary(mAccounts[0].name);
+ if (mAccounts.length == 1) {
+ accountPreference.setSummary(mAccounts[0].name);
+ } else {
+ accountPreference.setSummary(getAccountSummary(mAccounts.length));
+ }
}
@Override
@@ -72,18 +75,9 @@
return false;
}
- final Bundle args = new Bundle();
- args.putParcelable(AccountDetailDashboardFragment.KEY_ACCOUNT,
- mAccounts[0]);
- args.putParcelable(AccountDetailDashboardFragment.KEY_USER_HANDLE,
- android.os.Process.myUserHandle());
- args.putString(AccountDetailDashboardFragment.KEY_ACCOUNT_TYPE,
- mAccountFeatureProvider.getAccountType());
-
new SubSettingLauncher(mContext)
- .setDestination(AccountDetailDashboardFragment.class.getName())
- .setTitleRes(R.string.account_sync_title)
- .setArguments(args)
+ .setDestination(AccountDashboardFragment.class.getName())
+ .setTitleRes(R.string.account_dashboard_title)
.setSourceMetricsCategory(SettingsEnums.DEVICEINFO)
.launch();
return true;
@@ -97,4 +91,9 @@
preference.setVisible(false);
}
}
+
+ private String getAccountSummary(int accountNo) {
+ return mContext.getResources()
+ .getString(R.string.my_device_info_account_preference_summary, accountNo);
+ }
}
diff --git a/src/com/android/settings/network/NetworkProviderSettings.java b/src/com/android/settings/network/NetworkProviderSettings.java
index 47dc0ef..ee398a4 100644
--- a/src/com/android/settings/network/NetworkProviderSettings.java
+++ b/src/com/android/settings/network/NetworkProviderSettings.java
@@ -40,7 +40,6 @@
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.util.EventLog;
-import android.util.FeatureFlagUtils;
import android.util.Log;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
@@ -62,7 +61,6 @@
import com.android.settings.AirplaneModeEnabler;
import com.android.settings.R;
import com.android.settings.RestrictedSettingsFragment;
-import com.android.settings.core.FeatureFlags;
import com.android.settings.core.SubSettingLauncher;
import com.android.settings.datausage.DataUsagePreference;
import com.android.settings.datausage.DataUsageUtils;
@@ -1047,17 +1045,13 @@
@VisibleForTesting
void launchNetworkDetailsFragment(LongPressWifiEntryPreference pref) {
final WifiEntry wifiEntry = pref.getWifiEntry();
- final Context context = getContext();
- final CharSequence title =
- FeatureFlagUtils.isEnabled(context, FeatureFlags.WIFI_DETAILS_DATAUSAGE_HEADER)
- ? wifiEntry.getTitle()
- : context.getText(R.string.pref_title_network_details);
+ final Context context = requireContext();
final Bundle bundle = new Bundle();
bundle.putString(WifiNetworkDetailsFragment.KEY_CHOSEN_WIFIENTRY_KEY, wifiEntry.getKey());
new SubSettingLauncher(context)
- .setTitleText(title)
+ .setTitleText(context.getText(R.string.pref_title_network_details))
.setDestination(WifiNetworkDetailsFragment.class.getName())
.setArguments(bundle)
.setSourceMetricsCategory(getMetricsCategory())
diff --git a/src/com/android/settings/password/SetNewPasswordActivity.java b/src/com/android/settings/password/SetNewPasswordActivity.java
index bb3c6df..c02e23b 100644
--- a/src/com/android/settings/password/SetNewPasswordActivity.java
+++ b/src/com/android/settings/password/SetNewPasswordActivity.java
@@ -121,9 +121,7 @@
@Override
public void launchChooseLock(Bundle chooseLockFingerprintExtras) {
- final boolean isInSetupWizard = WizardManagerHelper.isAnySetupWizard(getIntent());
- Intent intent = isInSetupWizard ? new Intent(this, SetupChooseLockGeneric.class)
- : new Intent(this, ChooseLockGeneric.class);
+ Intent intent = new Intent(this, SetupChooseLockGeneric.class);
intent.setAction(mNewPasswordAction);
intent.putExtras(chooseLockFingerprintExtras);
if (mCallerAppName != null) {
diff --git a/src/com/android/settings/password/SetupChooseLockGeneric.java b/src/com/android/settings/password/SetupChooseLockGeneric.java
index 7c0769e..eade7cf 100644
--- a/src/com/android/settings/password/SetupChooseLockGeneric.java
+++ b/src/com/android/settings/password/SetupChooseLockGeneric.java
@@ -256,6 +256,12 @@
return InternalSetupChooseLockGenericFragment.class;
}
+ @Override
+ protected boolean isToolbarEnabled() {
+ // Hide the action bar from this page.
+ return false;
+ }
+
public static class InternalSetupChooseLockGenericFragment
extends ChooseLockGenericFragment {
@Override
diff --git a/src/com/android/settings/users/MultiUserSwitchBarController.java b/src/com/android/settings/users/MultiUserSwitchBarController.java
index 3697bb0..33651c3 100644
--- a/src/com/android/settings/users/MultiUserSwitchBarController.java
+++ b/src/com/android/settings/users/MultiUserSwitchBarController.java
@@ -46,18 +46,13 @@
MultiUserSwitchBarController(Context context, SwitchWidgetController switchBar,
- boolean canUserSwitchToggle, OnMultiUserSwitchChangedListener listener) {
+ OnMultiUserSwitchChangedListener listener) {
mContext = context;
mSwitchBar = switchBar;
mListener = listener;
mUserCapabilities = UserCapabilities.create(context);
mSwitchBar.setChecked(mUserCapabilities.mUserSwitcherEnabled);
- setToggleEnabled(canUserSwitchToggle);
- mSwitchBar.setListener(this);
- }
-
- void setToggleEnabled(boolean canUserSwitchToggle) {
if (mUserCapabilities.mDisallowSwitchUser) {
mSwitchBar.setDisabledByAdmin(RestrictedLockUtilsInternal
.checkIfRestrictionEnforced(mContext, UserManager.DISALLOW_USER_SWITCH,
@@ -69,8 +64,9 @@
UserHandle.myUserId()));
} else {
mSwitchBar.setEnabled(!mUserCapabilities.mDisallowSwitchUser
- && !mUserCapabilities.mIsGuest && canUserSwitchToggle);
+ && !mUserCapabilities.mIsGuest && mUserCapabilities.isAdmin());
}
+ mSwitchBar.setListener(this);
}
@Override
diff --git a/src/com/android/settings/users/UserSettings.java b/src/com/android/settings/users/UserSettings.java
index c63517d..64699ff 100644
--- a/src/com/android/settings/users/UserSettings.java
+++ b/src/com/android/settings/users/UserSettings.java
@@ -290,9 +290,8 @@
} else {
switchBar.hide();
}
- boolean isToggleEnabled = mUserManager.getFullUserCount() == 1;
mSwitchBarController = new MultiUserSwitchBarController(activity,
- new MainSwitchBarController(switchBar), isToggleEnabled, this /* listener */);
+ new MainSwitchBarController(switchBar), this /* listener */);
getSettingsLifecycle().addObserver(mSwitchBarController);
boolean openUserEditDialog = getIntent().getBooleanExtra(
EXTRA_OPEN_DIALOG_USER_PROFILE_EDITOR, false);
@@ -423,9 +422,6 @@
mRemoveGuestOnExitPreferenceController.getPreferenceKey()));
if (mShouldUpdateUserList) {
updateUI();
- // Update state of "Allow multiple users" toggle when list of users updates
- boolean isToggleEnabled = mUserManager.getFullUserCount() == 1;
- mSwitchBarController.setToggleEnabled(isToggleEnabled);
}
}
diff --git a/src/com/android/settings/wifi/details2/WifiDetailPreferenceController2.java b/src/com/android/settings/wifi/details2/WifiDetailPreferenceController2.java
index ac0e149..cacd448 100644
--- a/src/com/android/settings/wifi/details2/WifiDetailPreferenceController2.java
+++ b/src/com/android/settings/wifi/details2/WifiDetailPreferenceController2.java
@@ -20,7 +20,6 @@
import static android.net.NetworkCapabilities.NET_CAPABILITY_VALIDATED;
import static android.net.NetworkCapabilities.TRANSPORT_WIFI;
import static android.telephony.TelephonyManager.UNKNOWN_CARRIER_ID;
-
import static com.android.settingslib.wifi.WifiUtils.getHotspotIconResource;
import android.app.Activity;
@@ -41,7 +40,6 @@
import android.net.LinkProperties;
import android.net.Network;
import android.net.NetworkCapabilities;
-import android.net.NetworkInfo;
import android.net.NetworkRequest;
import android.net.RouteInfo;
import android.net.Uri;
@@ -53,7 +51,6 @@
import android.telephony.SubscriptionInfo;
import android.telephony.SubscriptionManager;
import android.text.TextUtils;
-import android.util.FeatureFlagUtils;
import android.util.Log;
import android.widget.ImageView;
import android.widget.Toast;
@@ -69,9 +66,7 @@
import com.android.net.module.util.Inet4AddressUtils;
import com.android.settings.R;
import com.android.settings.Utils;
-import com.android.settings.core.FeatureFlags;
import com.android.settings.core.PreferenceControllerMixin;
-import com.android.settings.datausage.WifiDataUsageSummaryPreferenceController;
import com.android.settings.network.SubscriptionUtil;
import com.android.settings.widget.EntityHeaderController;
import com.android.settings.wifi.WifiDialog2;
@@ -164,12 +159,10 @@
private final Handler mHandler;
private LinkProperties mLinkProperties;
private Network mNetwork;
- private NetworkInfo mNetworkInfo;
private NetworkCapabilities mNetworkCapabilities;
private int mRssiSignalLevel = -1;
@VisibleForTesting boolean mShowX; // Shows the Wi-Fi signal icon of Pie+x when it's true.
private String[] mSignalStr;
- private WifiInfo mWifiInfo;
private final WifiManager mWifiManager;
private final MetricsFeatureProvider mMetricsFeatureProvider;
@@ -192,10 +185,6 @@
private Preference mTypePref;
private PreferenceCategory mIpv6Category;
private Preference mIpv6AddressPref;
- private Lifecycle mLifecycle;
- Preference mDataUsageSummaryPref;
- WifiDataUsageSummaryPreferenceController mSummaryHeaderController;
-
private final IconInjector mIconInjector;
private final Clock mClock;
@@ -337,7 +326,6 @@
mIconInjector = injector;
mClock = clock;
- mLifecycle = lifecycle;
lifecycle.addObserver(this);
}
@@ -432,16 +420,6 @@
private void setupEntityHeader(PreferenceScreen screen) {
LayoutPreference headerPref = screen.findPreference(KEY_HEADER);
- if (usingDataUsageHeader(mContext)) {
- headerPref.setVisible(false);
- mDataUsageSummaryPref = screen.findPreference(KEY_DATA_USAGE_HEADER);
- mDataUsageSummaryPref.setVisible(true);
- mSummaryHeaderController =
- new WifiDataUsageSummaryPreferenceController(mFragment.getActivity(),
- mWifiEntry.getWifiConfiguration().getAllNetworkKeys());
- return;
- }
-
mEntityHeaderController =
EntityHeaderController.newInstance(
mFragment.getActivity(), mFragment,
@@ -486,14 +464,10 @@
}
private void refreshEntityHeader() {
- if (usingDataUsageHeader(mContext)) {
- mSummaryHeaderController.updateState(mDataUsageSummaryPref);
- } else {
- mEntityHeaderController
- .setSummary(mWifiEntry.getSummary())
- .setSecondSummary(getExpiryTimeSummary())
- .done(true /* rebind */);
- }
+ mEntityHeaderController
+ .setSummary(mWifiEntry.getSummary())
+ .setSecondSummary(getExpiryTimeSummary())
+ .done(true /* rebind */);
}
@VisibleForTesting
@@ -502,14 +476,10 @@
mNetwork = mWifiManager.getCurrentNetwork();
mLinkProperties = mConnectivityManager.getLinkProperties(mNetwork);
mNetworkCapabilities = mConnectivityManager.getNetworkCapabilities(mNetwork);
- mNetworkInfo = mConnectivityManager.getNetworkInfo(mNetwork);
- mWifiInfo = mWifiManager.getConnectionInfo();
} else {
mNetwork = null;
mLinkProperties = null;
mNetworkCapabilities = null;
- mNetworkInfo = null;
- mWifiInfo = null;
}
}
@@ -1059,10 +1029,6 @@
}
}
- private boolean usingDataUsageHeader(Context context) {
- return FeatureFlagUtils.isEnabled(context, FeatureFlags.WIFI_DETAILS_DATAUSAGE_HEADER);
- }
-
@VisibleForTesting
void connectDisconnectNetwork() {
if (mWifiEntry.getConnectedState() == WifiEntry.CONNECTED_STATE_DISCONNECTED) {
diff --git a/tests/robotests/src/com/android/settings/datausage/DataUsageSummaryPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/datausage/DataUsageSummaryPreferenceControllerTest.java
index 3f41c3f..a929873 100644
--- a/tests/robotests/src/com/android/settings/datausage/DataUsageSummaryPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/datausage/DataUsageSummaryPreferenceControllerTest.java
@@ -16,21 +16,16 @@
package com.android.settings.datausage;
-import static android.content.pm.PackageManager.FEATURE_WIFI;
-
import static com.android.settings.core.BasePreferenceController.AVAILABLE;
-
+import static com.android.settings.core.BasePreferenceController.CONDITIONALLY_UNAVAILABLE;
import static com.google.common.truth.Truth.assertThat;
-
import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.content.Context;
-import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.NetworkTemplate;
import android.telephony.SubscriptionInfo;
@@ -128,7 +123,6 @@
doReturn(mTelephonyManager).when(mTelephonyManager)
.createForSubscriptionId(mDefaultSubscriptionId);
doReturn(mPm).when(mActivity).getPackageManager();
- doReturn(false).when(mPm).hasSystemFeature(eq(FEATURE_WIFI));
doReturn(TelephonyManager.SIM_STATE_READY).when(mTelephonyManager).getSimState();
mController = spy(new DataUsageSummaryPreferenceController(
@@ -156,12 +150,9 @@
final long now = System.currentTimeMillis();
final DataUsageController.DataUsageInfo info = createTestDataUsageInfo(now);
- final Intent intent = new Intent();
-
doReturn(info).when(mDataUsageController).getDataUsageInfo(any());
setupTestDataUsage(LIMIT1, USAGE1, now - UPDATE_BACKOFF_MS);
createTestDataPlan(info.cycleStart, info.cycleEnd);
- doReturn(intent).when(mController).createManageSubscriptionIntent(mDefaultSubscriptionId);
mController.updateState(mSummaryPreference);
@@ -173,10 +164,8 @@
// TODO (b/170330084): return intent instead of null for mSummaryPreference
verify(mSummaryPreference).setUsageInfo((info.cycleEnd / 1000) * 1000,
now - UPDATE_BACKOFF_MS,
- CARRIER_NAME, 1 /* numPlans */, null /* launchIntent */);
+ CARRIER_NAME, 1 /* numPlans */);
verify(mSummaryPreference).setChartEnabled(true);
- verify(mSummaryPreference).setWifiMode(false /* isWifiMode */, null /* usagePeriod */,
- false /* isSingleWifi */);
}
@Test
@@ -184,8 +173,6 @@
final long now = System.currentTimeMillis();
final DataUsageController.DataUsageInfo info = createTestDataUsageInfo(now);
- final Intent intent = new Intent();
-
doReturn(info).when(mDataUsageController).getDataUsageInfo(any());
setupTestDataUsage(LIMIT1, USAGE1, now - UPDATE_BACKOFF_MS);
@@ -200,11 +187,8 @@
info.cycleEnd,
-1L /* snapshotTime */,
CARRIER_NAME,
- 0 /* numPlans */,
- null /* launchIntent */);
+ 0 /* numPlans */);
verify(mSummaryPreference).setChartEnabled(true);
- verify(mSummaryPreference).setWifiMode(false /* isWifiMode */, null /* usagePeriod */,
- false /* isSingleWifi */);
}
@Test
@@ -227,11 +211,8 @@
info.cycleEnd,
-1L /* snapshotTime */,
null /* carrierName */,
- 0 /* numPlans */,
- null /* launchIntent */);
+ 0 /* numPlans */);
verify(mSummaryPreference).setChartEnabled(true);
- verify(mSummaryPreference).setWifiMode(false /* isWifiMode */, null /* usagePeriod */,
- false /* isSingleWifi */);
}
@Test
@@ -254,11 +235,8 @@
info.cycleEnd,
-1L /* snapshotTime */,
null /* carrierName */,
- 0 /* numPlans */,
- null /* launchIntent */);
+ 0 /* numPlans */);
verify(mSummaryPreference).setChartEnabled(false);
- verify(mSummaryPreference).setWifiMode(false /* isWifiMode */, null /* usagePeriod */,
- false /* isSingleWifi */);
}
@Test
@@ -268,8 +246,6 @@
info.warningLevel = 0L;
info.limitLevel = 0L;
- final Intent intent = new Intent();
-
doReturn(info).when(mDataUsageController).getDataUsageInfo(any());
setupTestDataUsage(LIMIT1, USAGE1, now - UPDATE_BACKOFF_MS);
@@ -284,8 +260,6 @@
info.warningLevel = BillingCycleSettings.MIB_IN_BYTES;
info.limitLevel = 0L;
- final Intent intent = new Intent();
-
doReturn(info).when(mDataUsageController).getDataUsageInfo(any());
setupTestDataUsage(LIMIT1, USAGE1, now - UPDATE_BACKOFF_MS);
@@ -304,8 +278,6 @@
info.warningLevel = 0L;
info.limitLevel = BillingCycleSettings.MIB_IN_BYTES;
- final Intent intent = new Intent();
-
doReturn(info).when(mDataUsageController).getDataUsageInfo(any());
setupTestDataUsage(LIMIT1, USAGE1, now - UPDATE_BACKOFF_MS);
@@ -324,8 +296,6 @@
info.warningLevel = BillingCycleSettings.MIB_IN_BYTES;
info.limitLevel = BillingCycleSettings.MIB_IN_BYTES;
- final Intent intent = new Intent();
-
doReturn(info).when(mDataUsageController).getDataUsageInfo(any());
setupTestDataUsage(LIMIT1, USAGE1, now - UPDATE_BACKOFF_MS);
@@ -335,8 +305,6 @@
verify(mSummaryPreference).setLimitInfo(captor.capture());
CharSequence value = captor.getValue();
assertThat(value.toString()).isEqualTo("1.00 MB data warning / 1.00 MB data limit");
- verify(mSummaryPreference).setWifiMode(false /* isWifiMode */, null /* usagePeriod */,
- false /* isSingleWifi */);
}
@Test
@@ -345,12 +313,11 @@
}
@Test
- public void testMobileData_noSimWifi_preferenceDisabled() {
+ public void testMobileData_noSim_preferenceDisabled() {
final int subscriptionId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
mController.init(subscriptionId);
mController.mDataUsageController = mDataUsageController;
- doReturn(true).when(mPm).hasSystemFeature(eq(FEATURE_WIFI));
- assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(CONDITIONALLY_UNAVAILABLE);
}
private DataUsageController.DataUsageInfo createTestDataUsageInfo(long now) {
diff --git a/tests/robotests/src/com/android/settings/datausage/WifiDataUsageSummaryPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/datausage/WifiDataUsageSummaryPreferenceControllerTest.java
deleted file mode 100644
index a8ac29f..0000000
--- a/tests/robotests/src/com/android/settings/datausage/WifiDataUsageSummaryPreferenceControllerTest.java
+++ /dev/null
@@ -1,85 +0,0 @@
-/*
- * Copyright (C) 2022 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 static org.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.anyBoolean;
-import static org.mockito.ArgumentMatchers.anyString;
-import static org.mockito.Mockito.doNothing;
-import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.spy;
-
-import android.content.Context;
-import android.telephony.TelephonyManager;
-
-import androidx.fragment.app.FragmentActivity;
-import androidx.test.core.app.ApplicationProvider;
-
-import com.android.settingslib.net.DataUsageController;
-
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.mockito.Spy;
-import org.mockito.junit.MockitoJUnit;
-import org.mockito.junit.MockitoRule;
-import org.robolectric.RobolectricTestRunner;
-
-import java.util.HashSet;
-import java.util.Set;
-
-@RunWith(RobolectricTestRunner.class)
-public class WifiDataUsageSummaryPreferenceControllerTest {
-
- @Rule
- public final MockitoRule mMockitoRule = MockitoJUnit.rule();
- @Spy
- Context mContext = ApplicationProvider.getApplicationContext();
- @Mock
- FragmentActivity mActivity;
- @Mock
- TelephonyManager mTelephonyManager;
- @Mock
- DataUsageSummaryPreference mSummaryPreference;
- @Mock
- DataUsageController mDataUsageController;
- @Mock
- DataUsageController.DataUsageInfo mDataUsageInfo;
-
- WifiDataUsageSummaryPreferenceController mController;
- Set<String> mAllNetworkKeys = new HashSet<>();
-
- @Before
- public void setUp() {
- doReturn(mContext.getResources()).when(mActivity).getResources();
- doReturn(mTelephonyManager).when(mActivity).getSystemService(TelephonyManager.class);
- doNothing().when(mSummaryPreference).setWifiMode(anyBoolean(), anyString(), anyBoolean());
- doReturn(mDataUsageInfo).when(mDataUsageController).getDataUsageInfo(any());
-
- mController = spy(new WifiDataUsageSummaryPreferenceController(mActivity, mAllNetworkKeys));
- doReturn(mDataUsageController).when(mController).createDataUsageController(any());
- }
-
- @Test
- public void updateState_nullOfDataUsageController_shouldNotCrash() {
- mController.mDataUsageController = null;
-
- mController.updateState(mSummaryPreference);
- }
-}
diff --git a/tests/robotests/src/com/android/settings/users/MultiUserSwitchBarControllerTest.java b/tests/robotests/src/com/android/settings/users/MultiUserSwitchBarControllerTest.java
index 89319c4..718e01b 100644
--- a/tests/robotests/src/com/android/settings/users/MultiUserSwitchBarControllerTest.java
+++ b/tests/robotests/src/com/android/settings/users/MultiUserSwitchBarControllerTest.java
@@ -65,7 +65,7 @@
UserManager.DISALLOW_USER_SWITCH, true);
final MultiUserSwitchBarController controller = new MultiUserSwitchBarController(mContext,
- mSwitchBarController, true, null);
+ mSwitchBarController, null);
verify(mSwitchBarController).setDisabledByAdmin(any());
}
@@ -76,32 +76,8 @@
UserManager.DISALLOW_USER_SWITCH, false);
final MultiUserSwitchBarController controller = new MultiUserSwitchBarController(mContext,
- mSwitchBarController, true, null);
+ mSwitchBarController, null);
verify(mSwitchBarController, never()).setDisabledByAdmin(any());
}
-
- @Test
- public void onStart_allowUserSwitch_setDisabledAfterInitialization_shouldBeDisabled() {
- mUserManager.setUserRestriction(UserHandle.of(UserHandle.myUserId()),
- UserManager.DISALLOW_USER_SWITCH, false);
-
- final MultiUserSwitchBarController controller = new MultiUserSwitchBarController(mContext,
- mSwitchBarController, true, null);
- verify(mSwitchBarController).setEnabled(true);
- controller.setToggleEnabled(false);
- verify(mSwitchBarController).setEnabled(false);
- }
-
- @Test
- public void onStart_allowUserSwitch_setEnabledAfterInitialization_shouldBeEnabled() {
- mUserManager.setUserRestriction(UserHandle.of(UserHandle.myUserId()),
- UserManager.DISALLOW_USER_SWITCH, false);
-
- final MultiUserSwitchBarController controller = new MultiUserSwitchBarController(mContext,
- mSwitchBarController, false, null);
- verify(mSwitchBarController).setEnabled(false);
- controller.setToggleEnabled(true);
- verify(mSwitchBarController).setEnabled(true);
- }
}
diff --git a/tests/spa_unit/Android.bp b/tests/spa_unit/Android.bp
index 0bd5613..28a2667 100644
--- a/tests/spa_unit/Android.bp
+++ b/tests/spa_unit/Android.bp
@@ -27,7 +27,7 @@
srcs: [
"src/**/*.kt",
],
-
+ use_resource_processor: true,
static_libs: [
"Settings-core",
"SpaLibTestUtils",
diff --git a/tests/uitests/src/com/android/settings/biometrics2/utils/LockScreenUtil.java b/tests/uitests/src/com/android/settings/biometrics2/utils/LockScreenUtil.java
index 23606e5..3505afa 100644
--- a/tests/uitests/src/com/android/settings/biometrics2/utils/LockScreenUtil.java
+++ b/tests/uitests/src/com/android/settings/biometrics2/utils/LockScreenUtil.java
@@ -22,10 +22,10 @@
import android.app.KeyguardManager;
import android.content.Context;
import android.os.SystemClock;
-import android.support.test.uiautomator.UiDevice;
import android.util.Log;
import androidx.test.InstrumentationRegistry;
+import androidx.test.uiautomator.UiDevice;
import org.junit.Assert;
diff --git a/tests/uitests/src/com/android/settings/ui/AboutPhoneSettingsTests.java b/tests/uitests/src/com/android/settings/ui/AboutPhoneSettingsTests.java
deleted file mode 100644
index 225b415..0000000
--- a/tests/uitests/src/com/android/settings/ui/AboutPhoneSettingsTests.java
+++ /dev/null
@@ -1,155 +0,0 @@
-/*
- * Copyright (C) 2018 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.ui;
-
-import static com.android.settings.ui.testutils.SettingsTestUtils.SETTINGS_PACKAGE;
-import static com.google.common.truth.Truth.assertThat;
-import static com.google.common.truth.Truth.assertWithMessage;
-
-import android.app.Instrumentation;
-import android.content.Intent;
-import android.os.RemoteException;
-import android.provider.Settings;
-import android.text.TextUtils;
-
-import androidx.test.InstrumentationRegistry;
-import androidx.test.filters.SmallTest;
-import androidx.test.runner.AndroidJUnit4;
-import androidx.test.uiautomator.By;
-import androidx.test.uiautomator.Direction;
-import androidx.test.uiautomator.UiDevice;
-import androidx.test.uiautomator.UiObject2;
-import androidx.test.uiautomator.Until;
-
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Iterator;
-
-/** Verifies basic functionality of the About Phone screen */
-@RunWith(AndroidJUnit4.class)
-@SmallTest
-public class AboutPhoneSettingsTests {
- private static final int TIMEOUT = 2000;
-
- // TODO: retrieve using name/ids from com.android.settings package
- private static final String[] sResourceTexts = {
- "Phone number",
- "Legal information",
- "Regulatory labels"
- };
-
- private UiDevice mDevice;
- private Instrumentation mInstrumentation;
-
- @Before
- public void setUp() throws Exception {
- mInstrumentation = InstrumentationRegistry.getInstrumentation();
- mDevice = UiDevice.getInstance(mInstrumentation);
- try {
- mDevice.setOrientationNatural();
- } catch (RemoteException e) {
- throw new RuntimeException("Failed to freeze device orientaion", e);
- }
-
- // make sure we are in a clean state before starting the test
- mDevice.pressHome();
- Thread.sleep(TIMEOUT * 2);
- launchAboutPhoneSettings(Settings.ACTION_DEVICE_INFO_SETTINGS);
- // TODO: make sure we are always at the top of the app
- // currently this will fail if the user has navigated into submenus
- UiObject2 view =
- mDevice.wait(
- Until.findObject(By.res(SETTINGS_PACKAGE + ":id/main_content")), TIMEOUT);
- assertThat(view).isNotNull();
- view.scroll(Direction.UP, 1.0f);
- }
-
- @After
- public void tearDown() throws Exception {
- // Adding an extra pressBack so we exit About Phone Settings
- // and finish the test cleanly
- mDevice.pressBack();
- mDevice.pressHome(); // finish settings activity
- mDevice.waitForIdle(TIMEOUT * 2); // give UI time to finish animating
- }
-
- @Test
- public void testAllMenuEntriesExist() {
- searchForItemsAndTakeAction(mDevice, sResourceTexts);
- }
-
- private void launchAboutPhoneSettings(String aboutSetting) {
- Intent aboutIntent = new Intent(aboutSetting);
- aboutIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- InstrumentationRegistry.getTargetContext().startActivity(aboutIntent);
- }
-
- /**
- * Removes items found in the view and optionally takes some action.
- */
- private void removeItemsAndTakeAction(UiDevice device, ArrayList<String> itemsLeftToFind) {
- for (Iterator<String> iterator = itemsLeftToFind.iterator(); iterator.hasNext(); ) {
- String itemText = iterator.next();
- UiObject2 item = device.wait(Until.findObject(By.text(itemText)), TIMEOUT);
- if (item != null) {
- iterator.remove();
- }
- }
- }
-
- /**
- * Searches for UI elements in the current view and optionally takes some action.
- *
- * <p>Will scroll down the screen until it has found all elements or reached the bottom.
- * This allows elements to be found and acted on even if they change order.
- */
- private void searchForItemsAndTakeAction(UiDevice device, String[] itemsToFind) {
-
- ArrayList<String> itemsLeftToFind = new ArrayList<>(Arrays.asList(itemsToFind));
- assertWithMessage("There must be at least one item to search for on the screen!")
- .that(itemsLeftToFind)
- .isNotEmpty();
-
- boolean canScrollDown = true;
- while (canScrollDown && !itemsLeftToFind.isEmpty()) {
- removeItemsAndTakeAction(device, itemsLeftToFind);
-
- // when we've finished searching the current view, scroll down
- UiObject2 view =
- device.wait(
- Until.findObject(By.res(SETTINGS_PACKAGE + ":id/main_content")),
- TIMEOUT * 2);
- if (view != null) {
- canScrollDown = view.scroll(Direction.DOWN, 1.0f);
- } else {
- canScrollDown = false;
- }
- }
- // check the last items once we have reached the bottom of the view
- removeItemsAndTakeAction(device, itemsLeftToFind);
-
- assertWithMessage("The following items were not found on the screen: "
- + TextUtils.join(", ", itemsLeftToFind))
- .that(itemsLeftToFind)
- .isEmpty();
- }
-}
diff --git a/tests/uitests/src/com/android/settings/ui/AboutPhoneSettingsTests.kt b/tests/uitests/src/com/android/settings/ui/AboutPhoneSettingsTests.kt
new file mode 100644
index 0000000..5350bd8
--- /dev/null
+++ b/tests/uitests/src/com/android/settings/ui/AboutPhoneSettingsTests.kt
@@ -0,0 +1,52 @@
+/*
+ * 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.ui
+
+import android.provider.Settings
+import androidx.test.ext.junit.runners.AndroidJUnit4
+import androidx.test.filters.SmallTest
+import androidx.test.uiautomator.UiDevice
+import com.android.settings.ui.testutils.SettingsTestUtils.assertHasTexts
+import com.android.settings.ui.testutils.SettingsTestUtils.startMainActivityFromHomeScreen
+import org.junit.Before
+import org.junit.Test
+import org.junit.runner.RunWith
+
+/** Verifies basic functionality of the About Phone screen */
+@RunWith(AndroidJUnit4::class)
+@SmallTest
+class AboutPhoneSettingsTests {
+ private lateinit var device: UiDevice
+
+ @Before
+ fun setUp() {
+ device = startMainActivityFromHomeScreen(Settings.ACTION_DEVICE_INFO_SETTINGS)
+ }
+
+ @Test
+ fun testAllMenuEntriesExist() {
+ device.assertHasTexts(ON_SCREEN_TEXTS)
+ }
+
+ private companion object {
+ val ON_SCREEN_TEXTS = listOf(
+ "Device name",
+ "Legal information",
+ "Regulatory labels"
+ )
+ }
+}
diff --git a/tests/uitests/src/com/android/settings/ui/AppsSettingsRetainFilterTests.java b/tests/uitests/src/com/android/settings/ui/AppsSettingsRetainFilterTests.java
deleted file mode 100644
index b830b30..0000000
--- a/tests/uitests/src/com/android/settings/ui/AppsSettingsRetainFilterTests.java
+++ /dev/null
@@ -1,123 +0,0 @@
-/*
- * Copyright (C) 2018 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.ui;
-
-import static com.google.common.truth.Truth.assertThat;
-
-import android.content.Intent;
-import android.os.RemoteException;
-import android.provider.Settings;
-import android.system.helpers.ActivityHelper;
-
-import androidx.test.InstrumentationRegistry;
-import androidx.test.runner.AndroidJUnit4;
-import androidx.test.uiautomator.By;
-import androidx.test.uiautomator.UiDevice;
-import androidx.test.uiautomator.UiObject2;
-import androidx.test.uiautomator.Until;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-
-@RunWith(AndroidJUnit4.class)
-public class AppsSettingsRetainFilterTests {
- private static final int TIMEOUT = 2000;
- private UiDevice mDevice;
- private ActivityHelper mActivityHelper = null;
-
- @Before
- public void setUp() throws Exception {
- mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
- mActivityHelper = ActivityHelper.getInstance();
-
- try {
- mDevice.setOrientationNatural();
- } catch (RemoteException e) {
- throw new RuntimeException("failed to freeze device orientation", e);
- }
-
- mDevice.pressHome();
- mDevice.waitForIdle(TIMEOUT);
- }
-
- @Test
- public void testDisablingSystemAppAndRotateDevice() throws Exception {
- launchAppsSettings();
-
- UiObject2 calculator = mDevice.wait(
- Until.findObject(By.text("Calculator")), TIMEOUT);
- assertThat(calculator).isNotNull();
- calculator.click();
- mDevice.waitForIdle(TIMEOUT);
-
- UiObject2 disableButton = mDevice.wait(
- Until.findObject(By.text("DISABLE")), TIMEOUT);
- assertThat(disableButton).isNotNull();
- disableButton.click();
- mDevice.waitForIdle(TIMEOUT);
-
- // Click on "Disable App" on dialog.
- UiObject2 dialogDisableButton = mDevice.wait(
- Until.findObject(By.text("DISABLE APP")), TIMEOUT);
- assertThat(dialogDisableButton).isNotNull();
- dialogDisableButton.click();
- mDevice.waitForIdle(TIMEOUT);
-
- UiObject2 enableButton = mDevice.wait(
- Until.findObject(By.text("ENABLE")), TIMEOUT);
- assertThat(enableButton).isNotNull();
-
- mDevice.pressBack();
- mDevice.waitForIdle(TIMEOUT);
-
- UiObject2 spinnerHeader = mDevice.wait(
- Until.findObject(By.text("All apps")), TIMEOUT);
- assertThat(spinnerHeader).isNotNull();
- spinnerHeader.click();
-
- UiObject2 optionDisabledApps = mDevice.wait(
- Until.findObject(By.text("Disabled apps")), TIMEOUT);
- assertThat(optionDisabledApps).isNotNull();
- optionDisabledApps.click();
- mDevice.waitForIdle(TIMEOUT);
-
- try {
- mDevice.setOrientationLeft();
- mDevice.waitForIdle(TIMEOUT);
- } catch (RemoteException e) {
- throw new RuntimeException("Failed to freeze device orientation", e);
- }
-
- try {
- mDevice.unfreezeRotation();
- mDevice.waitForIdle(TIMEOUT);
- } catch (RemoteException e) {
- throw new RuntimeException("Failed to un-freeze device orientation", e);
- }
-
- UiObject2 spinnerDisabledApps = mDevice.wait(
- Until.findObject(By.text("Disabled apps")), TIMEOUT);
- assertThat(spinnerDisabledApps).isNotNull();
- }
-
- private void launchAppsSettings() throws Exception {
- Intent appsSettingsIntent = new
- Intent(Settings.ACTION_MANAGE_APPLICATIONS_SETTINGS);
- mActivityHelper.launchIntent(appsSettingsIntent);
- }
-}
diff --git a/tests/uitests/src/com/android/settings/ui/AppsSettingsRetainFilterTests.kt b/tests/uitests/src/com/android/settings/ui/AppsSettingsRetainFilterTests.kt
new file mode 100644
index 0000000..23d5384
--- /dev/null
+++ b/tests/uitests/src/com/android/settings/ui/AppsSettingsRetainFilterTests.kt
@@ -0,0 +1,66 @@
+/*
+ * 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.ui
+
+import android.os.RemoteException
+import android.provider.Settings
+import androidx.test.ext.junit.runners.AndroidJUnit4
+import androidx.test.uiautomator.By
+import androidx.test.uiautomator.UiDevice
+import com.android.settings.ui.testutils.SettingsTestUtils.clickObject
+import com.android.settings.ui.testutils.SettingsTestUtils.startMainActivityFromHomeScreen
+import com.android.settings.ui.testutils.SettingsTestUtils.waitObject
+import com.google.common.truth.Truth.assertThat
+import org.junit.Before
+import org.junit.Test
+import org.junit.runner.RunWith
+
+@RunWith(AndroidJUnit4::class)
+class AppsSettingsRetainFilterTests {
+ private lateinit var device: UiDevice
+
+ @Before
+ fun setUp() {
+ device = startMainActivityFromHomeScreen(Settings.ACTION_MANAGE_APPLICATIONS_SETTINGS)
+ }
+
+ @Test
+ fun testDisablingSystemAppAndRotateDevice() {
+ device.clickObject(By.text("Calculator"))
+ device.clickObject(By.text("Disable"))
+
+ // Click on "Disable App" on dialog.
+ device.clickObject(By.text("Disable app"))
+ assertThat(device.waitObject(By.text("Enable"))).isNotNull()
+ device.pressBack()
+ device.clickObject(By.text("All apps"))
+ device.clickObject(By.text("Disabled apps"))
+ try {
+ device.setOrientationLeft()
+ } catch (e: RemoteException) {
+ throw RuntimeException("Failed to freeze device orientation", e)
+ }
+ try {
+ device.unfreezeRotation()
+ } catch (e: RemoteException) {
+ throw RuntimeException("Failed to un-freeze device orientation", e)
+ }
+ assertThat(device.waitObject(By.text("Disabled apps"))).isNotNull()
+ device.clickObject(By.text("Calculator"))
+ device.clickObject(By.text("Enable"))
+ }
+}
diff --git a/tests/uitests/src/com/android/settings/ui/AppsSettingsTests.java b/tests/uitests/src/com/android/settings/ui/AppsSettingsTests.java
deleted file mode 100644
index 777ade6..0000000
--- a/tests/uitests/src/com/android/settings/ui/AppsSettingsTests.java
+++ /dev/null
@@ -1,132 +0,0 @@
-/*
- * Copyright (C) 2018 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.ui;
-
-import android.content.Intent;
-import android.os.RemoteException;
-import android.provider.Settings;
-import android.system.helpers.ActivityHelper;
-import android.test.InstrumentationTestCase;
-import android.test.suitebuilder.annotation.MediumTest;
-import android.util.Log;
-
-import androidx.test.uiautomator.By;
-import androidx.test.uiautomator.Direction;
-import androidx.test.uiautomator.UiDevice;
-import androidx.test.uiautomator.UiObject2;
-import androidx.test.uiautomator.Until;
-
-/** Verifies basic functionality of the About Phone screen */
-public class AppsSettingsTests extends InstrumentationTestCase {
- private static final boolean LOCAL_LOGV = false;
- private static final String SETTINGS_PACKAGE = "com.android.settings";
- private static final String TAG = "AboutPhoneSettingsTest";
- private static final int TIMEOUT = 2000;
- private ActivityHelper mActivityHelper = null;
-
- private UiDevice mDevice;
-
- private static final String[] sResourceTexts = {
- "Storage",
- "Data usage",
- "Permissions",
- "App notifications",
- "Open by default",
- "Battery",
- "Memory"
- };
-
- @Override
- public void setUp() throws Exception {
- if (LOCAL_LOGV) {
- Log.d(TAG, "-------");
- }
- super.setUp();
- mDevice = UiDevice.getInstance(getInstrumentation());
- mActivityHelper = ActivityHelper.getInstance();
- try {
- mDevice.setOrientationNatural();
- } catch (RemoteException e) {
- throw new RuntimeException("Failed to freeze device orientaion", e);
- }
-
- // make sure we are in a clean state before starting the test
- mDevice.pressHome();
- Thread.sleep(TIMEOUT * 2);
- launchAppsSettings();
- UiObject2 view =
- mDevice.wait(
- Until.findObject(By.text("All apps")), TIMEOUT);
- assertNotNull("Could not find Settings > Apps screen", view);
- }
-
- @Override
- protected void tearDown() throws Exception {
- mDevice.pressBack();
- mDevice.pressHome(); // finish settings activity
- mDevice.waitForIdle(TIMEOUT * 2); // give UI time to finish animating
- super.tearDown();
- }
-
- @MediumTest
- public void testAppSettingsListForCalculator() {
- UiObject2 calculator = mDevice.wait(
- Until.findObject(By.text("Calculator")), TIMEOUT);
- calculator.click();
- for (String setting : sResourceTexts) {
- UiObject2 appSetting =
- mDevice.wait(
- Until.findObject(By.text(setting)), TIMEOUT);
- assertNotNull("Missing setting for Calculator: " + setting, appSetting);
- appSetting.scroll(Direction.DOWN, 10.0f);
- }
- }
-
- @MediumTest
- public void testDisablingAndEnablingSystemApp() throws Exception {
- launchAppsSettings();
- UiObject2 calculator = mDevice.wait(
- Until.findObject(By.text("Calculator")), TIMEOUT);
- calculator.click();
- mDevice.waitForIdle(TIMEOUT);
- UiObject2 appInfoList = mDevice.wait(
- Until.findObject(By.res(SETTINGS_PACKAGE, "list")), TIMEOUT);
- appInfoList.scroll(Direction.DOWN, 100.0f);
- UiObject2 disableButton = mDevice.wait(
- Until.findObject(By.text("DISABLE")), TIMEOUT);
- disableButton.click();
- mDevice.waitForIdle(TIMEOUT);
- // Click on "Disable App" on dialog.
- mDevice.wait(
- Until.findObject(By.text("DISABLE APP")), TIMEOUT).click();
- mDevice.waitForIdle(TIMEOUT);
- UiObject2 enableButton = mDevice.wait(
- Until.findObject(By.text("ENABLE")), TIMEOUT);
- assertNotNull("App not disabled successfully", enableButton);
- enableButton.click();
- mDevice.waitForIdle(TIMEOUT);
- disableButton = mDevice.wait(
- Until.findObject(By.text("DISABLE")), TIMEOUT);
- assertNotNull("App not enabled successfully", disableButton);
- }
-
- private void launchAppsSettings() throws Exception {
- Intent appsSettingsIntent = new
- Intent(Settings.ACTION_MANAGE_APPLICATIONS_SETTINGS);
- mActivityHelper.launchIntent(appsSettingsIntent);
- }
-}
diff --git a/tests/uitests/src/com/android/settings/ui/AppsSettingsTests.kt b/tests/uitests/src/com/android/settings/ui/AppsSettingsTests.kt
new file mode 100644
index 0000000..0ba6b8d
--- /dev/null
+++ b/tests/uitests/src/com/android/settings/ui/AppsSettingsTests.kt
@@ -0,0 +1,70 @@
+/*
+ * 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.ui
+
+import android.provider.Settings
+import androidx.test.uiautomator.By
+import androidx.test.uiautomator.UiDevice
+import com.android.settings.ui.testutils.SettingsTestUtils.assertHasTexts
+import com.android.settings.ui.testutils.SettingsTestUtils.clickObject
+import com.android.settings.ui.testutils.SettingsTestUtils.startMainActivityFromHomeScreen
+import com.android.settings.ui.testutils.SettingsTestUtils.waitObject
+import com.google.common.truth.Truth.assertWithMessage
+import org.junit.Before
+import org.junit.Test
+
+/** Verifies basic functionality of the About Phone screen */
+class AppsSettingsTests {
+ private lateinit var device: UiDevice
+
+ @Before
+ fun setUp() {
+ device = startMainActivityFromHomeScreen(Settings.ACTION_MANAGE_APPLICATIONS_SETTINGS)
+ val title = device.waitObject(By.text("All apps"))
+ assertWithMessage("Could not find Settings > Apps screen").that(title).isNotNull()
+ }
+
+ @Test
+ fun testAppSettingsListForCalculator() {
+ device.clickObject(By.text("Calculator"))
+ device.waitObject(By.text("Open"))
+ device.assertHasTexts(ON_SCREEN_TEXTS)
+ }
+
+ @Test
+ fun testDisablingAndEnablingSystemApp() {
+ device.clickObject(By.text("Calculator"))
+ device.clickObject(By.text("Disable"))
+ device.clickObject(By.text("Disable app")) // Click on "Disable app" on dialog.
+ device.clickObject(By.text("Enable"))
+ val disableButton = device.waitObject(By.text("Disable"))
+ assertWithMessage("App not enabled successfully").that(disableButton).isNotNull()
+ }
+
+ private companion object {
+ val ON_SCREEN_TEXTS = listOf(
+ "Notifications",
+ "Permissions",
+ "Storage & cache",
+ "Mobile data & Wi‑Fi",
+ "Screen time",
+ "App battery usage",
+ "Language",
+ "Unused app settings",
+ )
+ }
+}
diff --git a/tests/uitests/src/com/android/settings/ui/BatterySettingsTest.kt b/tests/uitests/src/com/android/settings/ui/BatterySettingsTest.kt
new file mode 100644
index 0000000..fbdd2e5
--- /dev/null
+++ b/tests/uitests/src/com/android/settings/ui/BatterySettingsTest.kt
@@ -0,0 +1,51 @@
+/*
+ * 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.ui
+
+import android.content.Intent
+import androidx.test.ext.junit.runners.AndroidJUnit4
+import androidx.test.uiautomator.UiDevice
+import com.android.settings.ui.testutils.SettingsTestUtils.assertHasTexts
+import com.android.settings.ui.testutils.SettingsTestUtils.startMainActivityFromHomeScreen
+import org.junit.Before
+import org.junit.Test
+import org.junit.runner.RunWith
+
+@RunWith(AndroidJUnit4::class)
+class BatterySettingsTest {
+ private lateinit var device: UiDevice
+
+ @Before
+ fun setUp() {
+ device = startMainActivityFromHomeScreen(Intent.ACTION_POWER_USAGE_SUMMARY)
+ }
+
+ @Test
+ fun hasTexts() {
+ device.assertHasTexts(ON_SCREEN_TEXTS)
+ }
+
+ private companion object {
+ // Items we really want to always show
+ val ON_SCREEN_TEXTS = listOf(
+ "Battery usage",
+ "Battery Saver",
+ "Battery percentage",
+ "Remaining battery life is approximate and can change based on usage"
+ )
+ }
+}
diff --git a/tests/uitests/src/com/android/settings/ui/BatterySettingsUITest.java b/tests/uitests/src/com/android/settings/ui/BatterySettingsUITest.java
deleted file mode 100644
index e23239e..0000000
--- a/tests/uitests/src/com/android/settings/ui/BatterySettingsUITest.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * Copyright (C) 2018 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.ui;
-
-import android.content.Intent;
-import android.os.RemoteException;
-import android.system.helpers.SettingsHelper;
-
-import androidx.test.InstrumentationRegistry;
-import androidx.test.filters.MediumTest;
-import androidx.test.runner.AndroidJUnit4;
-import androidx.test.uiautomator.UiDevice;
-
-import com.android.settings.ui.testutils.SettingsTestUtils;
-
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-
-@MediumTest
-@RunWith(AndroidJUnit4.class)
-public class BatterySettingsUITest {
- // Items we really want to always show
- private static final String[] CATEGORIES = new String[] {
- "Battery Saver",
- "Battery percentage",
- "Battery usage data is approximate and can change based on usage",
- };
-
- private UiDevice mDevice;
- private SettingsHelper mHelper;
-
- @Before
- public void setUp() throws Exception {
- mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
- mHelper = SettingsHelper.getInstance();
- try {
- mDevice.setOrientationNatural();
- } catch (RemoteException e) {
- throw new RuntimeException("failed to freeze device orientaion", e);
- }
- }
-
- @After
- public void tearDown() throws Exception {
- // Go back to home for next test.
- mDevice.pressHome();
- }
-
- @Test
- public void launchSecuritySettings() throws Exception {
- // Launch Settings
- SettingsHelper.launchSettingsPage(
- InstrumentationRegistry.getTargetContext(), Intent.ACTION_POWER_USAGE_SUMMARY);
- mHelper.scrollVert(false);
- for (String category : CATEGORIES) {
- SettingsTestUtils.assertTitleMatch(mDevice, category);
- }
- }
-}
diff --git a/tests/uitests/src/com/android/settings/ui/ConnectedDeviceTests.java b/tests/uitests/src/com/android/settings/ui/ConnectedDeviceTests.java
index 4fa9857..36beb90 100644
--- a/tests/uitests/src/com/android/settings/ui/ConnectedDeviceTests.java
+++ b/tests/uitests/src/com/android/settings/ui/ConnectedDeviceTests.java
@@ -35,9 +35,11 @@
import org.junit.After;
import org.junit.Before;
+import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
+@Ignore
@MediumTest
@RunWith(AndroidJUnit4.class)
public class ConnectedDeviceTests {
diff --git a/tests/uitests/src/com/android/settings/ui/DataSaverSettingsTest.kt b/tests/uitests/src/com/android/settings/ui/DataSaverSettingsTest.kt
new file mode 100644
index 0000000..2312291
--- /dev/null
+++ b/tests/uitests/src/com/android/settings/ui/DataSaverSettingsTest.kt
@@ -0,0 +1,43 @@
+/*
+ * 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.ui
+
+import android.provider.Settings
+import androidx.test.ext.junit.runners.AndroidJUnit4
+import androidx.test.uiautomator.By
+import androidx.test.uiautomator.UiDevice
+import com.android.settings.ui.testutils.SettingsTestUtils.startMainActivityFromHomeScreen
+import com.android.settings.ui.testutils.SettingsTestUtils.waitObject
+import com.google.common.truth.Truth.assertThat
+import org.junit.Before
+import org.junit.Test
+import org.junit.runner.RunWith
+
+@RunWith(AndroidJUnit4::class)
+class DataSaverSettingsTest {
+ private lateinit var device: UiDevice
+
+ @Before
+ fun setUp() {
+ device = startMainActivityFromHomeScreen(Settings.ACTION_DATA_SAVER_SETTINGS)
+ }
+
+ @Test
+ fun hasSwitchBar() {
+ assertThat(device.waitObject(By.text("Use Data Saver"))).isNotNull()
+ }
+}
diff --git a/tests/uitests/src/com/android/settings/ui/DataUsageSettingsTests.java b/tests/uitests/src/com/android/settings/ui/DataUsageSettingsTests.java
index b990f75..3befca3 100644
--- a/tests/uitests/src/com/android/settings/ui/DataUsageSettingsTests.java
+++ b/tests/uitests/src/com/android/settings/ui/DataUsageSettingsTests.java
@@ -26,6 +26,9 @@
import androidx.test.uiautomator.UiDevice;
import androidx.test.uiautomator.Until;
+import org.junit.Ignore;
+
+@Ignore
public class DataUsageSettingsTests extends InstrumentationTestCase {
private static final String SETTINGS_PACKAGE = "com.android.settings";
diff --git a/tests/uitests/src/com/android/settings/ui/DevelopmentSettingsTest.kt b/tests/uitests/src/com/android/settings/ui/DevelopmentSettingsTest.kt
new file mode 100644
index 0000000..1ef940e
--- /dev/null
+++ b/tests/uitests/src/com/android/settings/ui/DevelopmentSettingsTest.kt
@@ -0,0 +1,53 @@
+/*
+ * 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.ui
+
+import android.provider.Settings
+import androidx.test.ext.junit.runners.AndroidJUnit4
+import androidx.test.filters.SmallTest
+import androidx.test.uiautomator.UiDevice
+import com.android.settings.ui.testutils.SettingsTestUtils.assertHasTexts
+import com.android.settings.ui.testutils.SettingsTestUtils.startMainActivityFromHomeScreen
+import org.junit.Before
+import org.junit.Test
+import org.junit.runner.RunWith
+
+@RunWith(AndroidJUnit4::class)
+@SmallTest
+class DevelopmentSettingsTest {
+ private lateinit var device: UiDevice
+
+ @Before
+ fun setUp() {
+ device = startMainActivityFromHomeScreen(Settings.ACTION_APPLICATION_DEVELOPMENT_SETTINGS)
+ }
+
+ @Test
+ fun hasTexts() {
+ device.assertHasTexts(ON_SCREEN_TEXTS)
+ }
+
+ private companion object {
+ val ON_SCREEN_TEXTS = listOf(
+ "Use developer options",
+ "Memory",
+ "Stay awake",
+ "USB debugging",
+ "App Compatibility Changes",
+ )
+ }
+}
diff --git a/tests/uitests/src/com/android/settings/ui/HomepageDisplayTests.java b/tests/uitests/src/com/android/settings/ui/HomepageDisplayTests.java
deleted file mode 100644
index 01cfbd4..0000000
--- a/tests/uitests/src/com/android/settings/ui/HomepageDisplayTests.java
+++ /dev/null
@@ -1,99 +0,0 @@
-/*
- * Copyright (C) 2018 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.ui;
-
-import static com.android.settings.ui.testutils.SettingsTestUtils.SETTINGS_PACKAGE;
-import static com.android.settings.ui.testutils.SettingsTestUtils.TIMEOUT;
-
-import android.os.RemoteException;
-import android.platform.test.annotations.Presubmit;
-import android.provider.Settings;
-import android.system.helpers.SettingsHelper;
-
-import androidx.test.InstrumentationRegistry;
-import androidx.test.filters.MediumTest;
-import androidx.test.runner.AndroidJUnit4;
-import androidx.test.uiautomator.By;
-import androidx.test.uiautomator.Direction;
-import androidx.test.uiautomator.UiDevice;
-import androidx.test.uiautomator.UiObject2;
-import androidx.test.uiautomator.Until;
-
-import com.android.settings.ui.testutils.SettingsTestUtils;
-
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-
-@MediumTest
-@RunWith(AndroidJUnit4.class)
-public class HomepageDisplayTests {
-
- private static final String[] HOMEPAGE_ITEMS = {
- "Network & internet",
- "Connected devices",
- "Apps & notifications",
- "Battery",
- "Display",
- "Sound",
- "Storage",
- "Security",
- "Location",
- "Privacy",
- "Accounts",
- "Accessibility",
- "System"
- };
-
- private UiDevice mDevice;
-
- @Before
- public void setUp() throws Exception {
- mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
- try {
- mDevice.setOrientationNatural();
- } catch (RemoteException e) {
- throw new RuntimeException("failed to freeze device orientaion", e);
- }
- }
-
- @After
- public void tearDown() throws Exception {
- // Need to finish settings activity
- mDevice.pressHome();
- }
-
- @Presubmit
- @Test
- public void testHomepageCategory() throws Exception {
- // Launch Settings
- SettingsHelper.launchSettingsPage(
- InstrumentationRegistry.getContext(), Settings.ACTION_SETTINGS);
-
- // Scroll to top
- final UiObject2 view = mDevice.wait(
- Until.findObject(By.res(SETTINGS_PACKAGE, "main_content")),
- TIMEOUT);
- view.scroll(Direction.UP, 100f);
-
- // Inspect each item
- for (String item : HOMEPAGE_ITEMS) {
- SettingsTestUtils.assertTitleMatch(mDevice, item);
- }
- }
-}
diff --git a/tests/uitests/src/com/android/settings/ui/HomepageDisplayTests.kt b/tests/uitests/src/com/android/settings/ui/HomepageDisplayTests.kt
new file mode 100644
index 0000000..e3ee159
--- /dev/null
+++ b/tests/uitests/src/com/android/settings/ui/HomepageDisplayTests.kt
@@ -0,0 +1,59 @@
+/*
+ * 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.ui
+
+import android.provider.Settings
+import androidx.test.ext.junit.runners.AndroidJUnit4
+import androidx.test.uiautomator.UiDevice
+import com.android.settings.ui.testutils.SettingsTestUtils.assertHasTexts
+import com.android.settings.ui.testutils.SettingsTestUtils.startMainActivityFromHomeScreen
+import org.junit.Before
+import org.junit.Test
+import org.junit.runner.RunWith
+
+@RunWith(AndroidJUnit4::class)
+class HomepageDisplayTests {
+ private lateinit var device: UiDevice
+
+ @Before
+ fun setUp() {
+ device = startMainActivityFromHomeScreen(Settings.ACTION_SETTINGS)
+ }
+
+ @Test
+ fun hasHomepageItems() {
+ device.assertHasTexts(HOMEPAGE_ITEMS)
+ }
+
+ private companion object {
+ val HOMEPAGE_ITEMS = listOf(
+ "Network & internet",
+ "Connected devices",
+ "Apps",
+ "Notifications",
+ "Battery",
+ "Storage",
+ "Sound & vibration",
+ "Display",
+ "Accessibility",
+ "Security & privacy",
+ "Location",
+ "Passwords & accounts",
+ "System",
+ )
+ }
+}
diff --git a/tests/uitests/src/com/android/settings/ui/LocationSettingsTests.java b/tests/uitests/src/com/android/settings/ui/LocationSettingsTests.java
index 35b5742..3a9fa08 100644
--- a/tests/uitests/src/com/android/settings/ui/LocationSettingsTests.java
+++ b/tests/uitests/src/com/android/settings/ui/LocationSettingsTests.java
@@ -29,7 +29,9 @@
import androidx.test.uiautomator.UiObject2;
import androidx.test.uiautomator.Until;
+import org.junit.Ignore;
+@Ignore
public class LocationSettingsTests extends InstrumentationTestCase {
private static final String SETTINGS_PACKAGE = "com.android.settings";
diff --git a/tests/uitests/src/com/android/settings/ui/MoreWirelessSettingsTest2.java b/tests/uitests/src/com/android/settings/ui/MoreWirelessSettingsTest2.java
index 5ed2ca9..4bd3cfb 100644
--- a/tests/uitests/src/com/android/settings/ui/MoreWirelessSettingsTest2.java
+++ b/tests/uitests/src/com/android/settings/ui/MoreWirelessSettingsTest2.java
@@ -35,9 +35,12 @@
import androidx.test.uiautomator.UiObject2;
import androidx.test.uiautomator.Until;
+import org.junit.Ignore;
+
/**
* Additional tests for Wifi Settings.
*/
+@Ignore
public class MoreWirelessSettingsTest2 extends InstrumentationTestCase {
// These back button presses are performed in tearDown() to exit Wifi
// Settings sub-menus that a test might finish in. This number should be
diff --git a/tests/uitests/src/com/android/settings/ui/NotificationSettingsTests.java b/tests/uitests/src/com/android/settings/ui/NotificationSettingsTests.java
index 6ab2828..c1fd4de 100644
--- a/tests/uitests/src/com/android/settings/ui/NotificationSettingsTests.java
+++ b/tests/uitests/src/com/android/settings/ui/NotificationSettingsTests.java
@@ -33,8 +33,11 @@
import androidx.test.uiautomator.UiObject2;
import androidx.test.uiautomator.Until;
+import org.junit.Ignore;
+
/** Verifies that you can get to the notification app listing page from the apps & notifications
* page */
+@Ignore
public class NotificationSettingsTests extends InstrumentationTestCase {
private static final boolean LOCAL_LOGV = false;
private static final String TAG = "NotifiSettingsTests";
diff --git a/tests/uitests/src/com/android/settings/ui/SecuritySettingsLaunchTest.java b/tests/uitests/src/com/android/settings/ui/SecuritySettingsLaunchTest.java
deleted file mode 100644
index bae4c59..0000000
--- a/tests/uitests/src/com/android/settings/ui/SecuritySettingsLaunchTest.java
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- * Copyright (C) 2018 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.ui;
-
-import android.os.RemoteException;
-import android.provider.Settings;
-import android.system.helpers.SettingsHelper;
-
-import androidx.test.InstrumentationRegistry;
-import androidx.test.filters.MediumTest;
-import androidx.test.runner.AndroidJUnit4;
-import androidx.test.uiautomator.UiDevice;
-
-import com.android.settings.ui.testutils.SettingsTestUtils;
-
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-
-@MediumTest
-@RunWith(AndroidJUnit4.class)
-public class SecuritySettingsLaunchTest {
-
- // Items we really want to always show
- private static final String[] CATEGORIES = new String[]{
- "Security status",
- "Device security",
- "Privacy",
- };
-
- private UiDevice mDevice;
- private SettingsHelper mHelper;
-
- @Before
- public void setUp() throws Exception {
- mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
- mHelper = SettingsHelper.getInstance();
- try {
- mDevice.setOrientationNatural();
- } catch (RemoteException e) {
- throw new RuntimeException("failed to freeze device orientaion", e);
- }
- }
-
- @After
- public void tearDown() throws Exception {
- // Go back to home for next test.
- mDevice.pressHome();
- }
-
- @Test
- public void launchSecuritySettings() throws Exception {
- // Launch Settings
- SettingsHelper.launchSettingsPage(
- InstrumentationRegistry.getTargetContext(), Settings.ACTION_SECURITY_SETTINGS);
- mHelper.scrollVert(false);
- for (String category : CATEGORIES) {
- SettingsTestUtils.assertTitleMatch(mDevice, category);
- }
- }
-}
diff --git a/tests/uitests/src/com/android/settings/ui/SecuritySettingsTest.kt b/tests/uitests/src/com/android/settings/ui/SecuritySettingsTest.kt
new file mode 100644
index 0000000..1fb1a54
--- /dev/null
+++ b/tests/uitests/src/com/android/settings/ui/SecuritySettingsTest.kt
@@ -0,0 +1,50 @@
+/*
+ * 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.ui
+
+import android.provider.Settings
+import androidx.test.ext.junit.runners.AndroidJUnit4
+import androidx.test.uiautomator.UiDevice
+import com.android.settings.ui.testutils.SettingsTestUtils.assertHasTexts
+import com.android.settings.ui.testutils.SettingsTestUtils.startMainActivityFromHomeScreen
+import org.junit.Before
+import org.junit.Test
+import org.junit.runner.RunWith
+
+@RunWith(AndroidJUnit4::class)
+class SecuritySettingsTest {
+ private lateinit var device: UiDevice
+
+ @Before
+ fun setUp() {
+ device = startMainActivityFromHomeScreen(Settings.ACTION_SECURITY_SETTINGS)
+ }
+
+ @Test
+ fun hasTexts() {
+ device.assertHasTexts(ON_SCREEN_TEXTS)
+ }
+
+ private companion object {
+ // Items we really want to always show
+ val ON_SCREEN_TEXTS = listOf(
+ "Device unlock",
+ "Privacy",
+ "More security & privacy",
+ )
+ }
+}
diff --git a/tests/uitests/src/com/android/settings/ui/SoundSettingsTest.java b/tests/uitests/src/com/android/settings/ui/SoundSettingsTest.java
index 29f7eec..3582a1d 100644
--- a/tests/uitests/src/com/android/settings/ui/SoundSettingsTest.java
+++ b/tests/uitests/src/com/android/settings/ui/SoundSettingsTest.java
@@ -30,8 +30,11 @@
import androidx.test.uiautomator.UiObject2;
import androidx.test.uiautomator.Until;
+import org.junit.Ignore;
+
import java.util.Map;
+@Ignore
public class SoundSettingsTest extends InstrumentationTestCase {
private static final String PAGE = Settings.ACTION_SOUND_SETTINGS;
private static final int TIMEOUT = 2000;
diff --git a/tests/uitests/src/com/android/settings/ui/StorageSettingsTest.kt b/tests/uitests/src/com/android/settings/ui/StorageSettingsTest.kt
new file mode 100644
index 0000000..db0472d
--- /dev/null
+++ b/tests/uitests/src/com/android/settings/ui/StorageSettingsTest.kt
@@ -0,0 +1,53 @@
+/*
+ * 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.ui
+
+import android.provider.Settings
+import androidx.test.ext.junit.runners.AndroidJUnit4
+import androidx.test.uiautomator.UiDevice
+import com.android.settings.ui.testutils.SettingsTestUtils.assertHasTexts
+import com.android.settings.ui.testutils.SettingsTestUtils.startMainActivityFromHomeScreen
+import org.junit.Before
+import org.junit.Test
+import org.junit.runner.RunWith
+
+@RunWith(AndroidJUnit4::class)
+class StorageSettingsTest {
+ private lateinit var device: UiDevice
+
+ @Before
+ fun setUp() {
+ device = startMainActivityFromHomeScreen(Settings.ACTION_INTERNAL_STORAGE_SETTINGS)
+ }
+
+ @Test
+ fun hasTexts() {
+ device.assertHasTexts(ON_SCREEN_TEXTS)
+ }
+
+ private companion object {
+ val ON_SCREEN_TEXTS = listOf(
+ "System",
+ "Documents & other",
+ "Games",
+ "Apps",
+ "Audio",
+ "Videos",
+ "Images",
+ )
+ }
+}
diff --git a/tests/uitests/src/com/android/settings/ui/StorageSettingsUITest.java b/tests/uitests/src/com/android/settings/ui/StorageSettingsUITest.java
deleted file mode 100644
index 63b87ba..0000000
--- a/tests/uitests/src/com/android/settings/ui/StorageSettingsUITest.java
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
- * Copyright (C) 2018 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.ui;
-
-import android.os.RemoteException;
-import android.provider.Settings;
-import android.system.helpers.SettingsHelper;
-import android.test.suitebuilder.annotation.MediumTest;
-
-import androidx.test.InstrumentationRegistry;
-import androidx.test.runner.AndroidJUnit4;
-import androidx.test.uiautomator.UiDevice;
-
-import com.android.settings.ui.testutils.SettingsTestUtils;
-
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-
-@RunWith(AndroidJUnit4.class)
-@MediumTest
-public class StorageSettingsUITest {
-
- private static final String[] TITLES = {
- "Photos & videos",
- "Music & audio",
- "Games",
- "Movie & TV apps",
- "Other apps",
- "Files",
- "System",
- };
- private UiDevice mDevice;
- private SettingsHelper mHelper;
-
-
- @Before
- public void setUp() throws Exception {
- mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
- mHelper = SettingsHelper.getInstance();
-
- try {
- mDevice.setOrientationNatural();
- } catch (RemoteException e) {
- throw new RuntimeException("failed to freeze device orientation", e);
- }
- }
-
- @After
- public void tearDown() {
- mDevice.pressHome();
- }
-
- @Test
- public void launchStorageSettings() throws Exception {
- // Launch Settings
- SettingsHelper.launchSettingsPage(
- InstrumentationRegistry.getTargetContext(),
- Settings.ACTION_INTERNAL_STORAGE_SETTINGS);
- mHelper.scrollVert(false);
- for (String category : TITLES) {
- SettingsTestUtils.assertTitleMatch(mDevice, category);
- }
- }
-}
diff --git a/tests/uitests/src/com/android/settings/ui/StorageWizardTest.java b/tests/uitests/src/com/android/settings/ui/StorageWizardTest.java
index 501515f..9d5c28b 100644
--- a/tests/uitests/src/com/android/settings/ui/StorageWizardTest.java
+++ b/tests/uitests/src/com/android/settings/ui/StorageWizardTest.java
@@ -32,6 +32,7 @@
import org.junit.After;
import org.junit.Before;
+import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -42,6 +43,7 @@
* Verify storage wizard flows. Temporarily enables a virtual disk which enables
* testing on all devices, regardless of physical SD card support.
*/
+@Ignore
@RunWith(AndroidJUnit4.class)
public class StorageWizardTest {
private static final String ANDROID_PACKAGE = "android";
diff --git a/tests/uitests/src/com/android/settings/ui/SyncSettingsTest.java b/tests/uitests/src/com/android/settings/ui/SyncSettingsTest.java
deleted file mode 100644
index 41a3829..0000000
--- a/tests/uitests/src/com/android/settings/ui/SyncSettingsTest.java
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * Copyright (C) 2018 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.ui;
-
-import static junit.framework.Assert.assertTrue;
-
-import android.os.RemoteException;
-import android.provider.Settings;
-import android.system.helpers.SettingsHelper;
-
-import androidx.test.InstrumentationRegistry;
-import androidx.test.filters.MediumTest;
-import androidx.test.runner.AndroidJUnit4;
-import androidx.test.uiautomator.By;
-import androidx.test.uiautomator.UiDevice;
-import androidx.test.uiautomator.UiObject2;
-import androidx.test.uiautomator.Until;
-
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-
-@MediumTest
-@RunWith(AndroidJUnit4.class)
-public class SyncSettingsTest {
- private static final int TIMEOUT = 2000;
-
- private UiDevice mDevice;
-
- @Before
- public void setUp() throws Exception {
- mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
-
- try {
- mDevice.setOrientationNatural();
- } catch (RemoteException e) {
- throw new RuntimeException("failed to freeze device orientaion", e);
- }
- }
-
- @After
- public void tearDown() throws Exception {
- // Need to finish settings activity
- mDevice.pressHome();
- }
-
- @Test
- public void syncPageShouldHaveAddAccountButton() throws Exception {
- // Launch Settings
- SettingsHelper.launchSettingsPage(
- InstrumentationRegistry.getContext(), Settings.ACTION_SYNC_SETTINGS);
- UiObject2 addAccount = mDevice.wait(
- Until.findObject(By.text("Add account")), TIMEOUT);
- assertTrue(addAccount != null);
- }
-}
diff --git a/tests/uitests/src/com/android/settings/ui/SyncSettingsTest.kt b/tests/uitests/src/com/android/settings/ui/SyncSettingsTest.kt
new file mode 100644
index 0000000..384b386
--- /dev/null
+++ b/tests/uitests/src/com/android/settings/ui/SyncSettingsTest.kt
@@ -0,0 +1,45 @@
+/*
+ * 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.ui
+
+import android.provider.Settings
+import androidx.test.ext.junit.runners.AndroidJUnit4
+import androidx.test.uiautomator.UiDevice
+import com.android.settings.ui.testutils.SettingsTestUtils.assertHasTexts
+import com.android.settings.ui.testutils.SettingsTestUtils.startMainActivityFromHomeScreen
+import org.junit.Before
+import org.junit.Test
+import org.junit.runner.RunWith
+
+@RunWith(AndroidJUnit4::class)
+class SyncSettingsTest {
+ private lateinit var device: UiDevice
+
+ @Before
+ fun setUp() {
+ device = startMainActivityFromHomeScreen(Settings.ACTION_SYNC_SETTINGS)
+ }
+
+ @Test
+ fun hasTexts() {
+ device.assertHasTexts(ON_SCREEN_TEXTS)
+ }
+
+ private companion object {
+ val ON_SCREEN_TEXTS = listOf("Add account")
+ }
+}
diff --git a/tests/uitests/src/com/android/settings/ui/WirelessNetworkSettingsTests.java b/tests/uitests/src/com/android/settings/ui/WirelessNetworkSettingsTests.java
index 49b602e..d320e08 100644
--- a/tests/uitests/src/com/android/settings/ui/WirelessNetworkSettingsTests.java
+++ b/tests/uitests/src/com/android/settings/ui/WirelessNetworkSettingsTests.java
@@ -37,12 +37,14 @@
import org.junit.After;
import org.junit.Before;
+import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
/**
* Core tests for Wifi Settings.
*/
+@Ignore
@RunWith(AndroidJUnit4.class)
@MediumTest
public class WirelessNetworkSettingsTests {
diff --git a/tests/uitests/src/com/android/settings/ui/ZonePickerSettingsTest.java b/tests/uitests/src/com/android/settings/ui/ZonePickerSettingsTest.java
index 16a5f84..bf13dfc 100644
--- a/tests/uitests/src/com/android/settings/ui/ZonePickerSettingsTest.java
+++ b/tests/uitests/src/com/android/settings/ui/ZonePickerSettingsTest.java
@@ -43,11 +43,13 @@
import org.junit.After;
import org.junit.Before;
+import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import java.util.TimeZone;
+@Ignore
@MediumTest
@RunWith(AndroidJUnit4.class)
public class ZonePickerSettingsTest {
diff --git a/tests/uitests/src/com/android/settings/ui/inputmethods/DataSaverSummaryUITest.java b/tests/uitests/src/com/android/settings/ui/inputmethods/DataSaverSummaryUITest.java
deleted file mode 100644
index fa857bd..0000000
--- a/tests/uitests/src/com/android/settings/ui/inputmethods/DataSaverSummaryUITest.java
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * Copyright (C) 2018 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.ui.inputmethods;
-
-import static com.android.settings.ui.testutils.SettingsTestUtils.TIMEOUT;
-import static com.google.common.truth.Truth.assertThat;
-
-import android.app.Instrumentation;
-import android.content.Intent;
-
-import androidx.test.InstrumentationRegistry;
-import androidx.test.runner.AndroidJUnit4;
-import androidx.test.uiautomator.By;
-import androidx.test.uiautomator.UiDevice;
-import androidx.test.uiautomator.UiObject2;
-import androidx.test.uiautomator.Until;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-
-@RunWith(AndroidJUnit4.class)
-public class DataSaverSummaryUITest {
-
- private Instrumentation mInstrumentation;
- private Intent mIntent;
- private UiDevice mUiDevice;
-
- @Before
- public void setUp() {
- mInstrumentation = InstrumentationRegistry.getInstrumentation();
- mUiDevice = UiDevice.getInstance(mInstrumentation);
- mIntent = new Intent().setClassName("com.android.settings",
- "com.android.settings.Settings$DataUsageSummaryActivity")
- .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- }
-
- @Test
- public void launchSettings_hasSwitchBar() throws Exception {
- launchDataSaverSettings();
- final UiObject2 switchBar =
- mUiDevice.wait(Until.findObject(By.text("Use Data Saver")), TIMEOUT);
-
- assertThat(switchBar).isNotNull();
- }
-
- private void launchDataSaverSettings() throws InterruptedException {
- mInstrumentation.getContext().startActivity(mIntent);
- final UiObject2 prefDataSaver =
- mUiDevice.wait(Until.findObject(By.text("Data Saver")), TIMEOUT);
-
- assertThat(prefDataSaver).isNotNull();
- prefDataSaver.click();
- Thread.sleep(TIMEOUT * 2);
- }
-}
diff --git a/tests/uitests/src/com/android/settings/ui/testutils/SettingsTestUtils.java b/tests/uitests/src/com/android/settings/ui/testutils/SettingsTestUtils.java
deleted file mode 100644
index eb8e33c..0000000
--- a/tests/uitests/src/com/android/settings/ui/testutils/SettingsTestUtils.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * Copyright (C) 2018 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.ui.testutils;
-
-import static org.junit.Assert.assertNotNull;
-
-import androidx.test.uiautomator.By;
-import androidx.test.uiautomator.Direction;
-import androidx.test.uiautomator.UiDevice;
-import androidx.test.uiautomator.UiObject2;
-import androidx.test.uiautomator.Until;
-
-public class SettingsTestUtils {
-
- public static final String SETTINGS_PACKAGE = "com.android.settings";
- public static final int TIMEOUT = 2000;
-
- private void scrollToTop(UiDevice device) throws Exception {
- int count = 5;
- UiObject2 view = null;
- while (count >= 0) {
- view = device.wait(
- Until.findObject(By.res(SETTINGS_PACKAGE, "main_content")),
- TIMEOUT);
- view.scroll(Direction.UP, 1.0f);
- count--;
- }
- }
-
- public static void assertTitleMatch(UiDevice device, String title) {
- int maxAttempt = 5;
- UiObject2 item = null;
- UiObject2 view = null;
- while (maxAttempt-- > 0) {
- item = device.wait(Until.findObject(By.res("android:id/title").text(title)), TIMEOUT);
- if (item == null) {
- view = device.wait(
- Until.findObject(By.res(SETTINGS_PACKAGE, "main_content")),
- TIMEOUT);
- view.scroll(Direction.DOWN, 1.0f);
- } else {
- return;
- }
- }
- assertNotNull(String.format("%s in Setting has not been loaded correctly", title), item);
- }
-}
diff --git a/tests/uitests/src/com/android/settings/ui/testutils/SettingsTestUtils.kt b/tests/uitests/src/com/android/settings/ui/testutils/SettingsTestUtils.kt
new file mode 100644
index 0000000..f647b3c
--- /dev/null
+++ b/tests/uitests/src/com/android/settings/ui/testutils/SettingsTestUtils.kt
@@ -0,0 +1,80 @@
+/*
+ * 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.ui.testutils
+
+import android.content.Context
+import android.content.Intent
+import android.view.KeyEvent
+import androidx.test.core.app.ApplicationProvider
+import androidx.test.platform.app.InstrumentationRegistry
+import androidx.test.uiautomator.By
+import androidx.test.uiautomator.BySelector
+import androidx.test.uiautomator.Direction
+import androidx.test.uiautomator.UiDevice
+import androidx.test.uiautomator.UiObject2
+import androidx.test.uiautomator.Until
+import com.google.common.truth.Truth.assertThat
+import com.google.common.truth.Truth.assertWithMessage
+
+object SettingsTestUtils {
+ const val SETTINGS_PACKAGE = "com.android.settings"
+ const val TIMEOUT = 2000L
+
+ fun UiDevice.waitObject(bySelector: BySelector): UiObject2? =
+ wait(Until.findObject(bySelector), TIMEOUT)
+
+ fun UiDevice.clickObject(bySelector: BySelector) = checkNotNull(waitObject(bySelector)).click()
+
+ fun startMainActivityFromHomeScreen(action: String): UiDevice {
+ // Initialize UiDevice instance
+ val device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
+ device.pressKeyCodes(intArrayOf(KeyEvent.KEYCODE_MENU, KeyEvent.KEYCODE_MENU)) // unlock
+
+ // Start from the home screen
+ device.pressHome()
+
+ // Wait for launcher
+ val launcherPackage: String = device.launcherPackageName
+ assertThat(launcherPackage).isNotNull()
+ device.waitObject(By.pkg(launcherPackage).depth(0))
+
+ // Launch the app
+ val context = ApplicationProvider.getApplicationContext<Context>()
+ val intent = Intent(action).apply {
+ addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK)
+ addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
+ }
+ context.startActivity(intent)
+
+ // Wait for the app to appear
+ device.waitObject(By.pkg(SETTINGS_PACKAGE).depth(0))
+
+ return device
+ }
+
+ fun UiDevice.assertHasTexts(texts: List<String>) {
+ val scrollableObj = findObject(By.scrollable(true))
+ for (text in texts) {
+ val selector = By.text(text)
+ assertWithMessage("Missing text: $text").that(
+ findObject(selector)
+ ?: scrollableObj.scrollUntil(Direction.DOWN, Until.findObject(selector))
+ ?: waitObject(selector)
+ ).isNotNull()
+ }
+ }
+}
diff --git a/tests/unit/Android.bp b/tests/unit/Android.bp
index f6a9583..cc003ea 100644
--- a/tests/unit/Android.bp
+++ b/tests/unit/Android.bp
@@ -25,8 +25,6 @@
"androidx.test.core",
"androidx.test.rules",
"androidx.test.espresso.core",
- "androidx.test.espresso.contrib-nodeps",
- "androidx.test.espresso.intents-nodeps",
"androidx.test.ext.junit",
"androidx.preference_preference",
"mockito-target-minus-junit4",
@@ -46,7 +44,7 @@
"src/**/*.java",
"src/**/*.kt",
],
-
+ use_resource_processor: true,
platform_apis: true,
test_suites: ["device-tests"],
diff --git a/tests/unit/src/com/android/settings/applications/credentials/CredentialManagerPreferenceControllerTest.java b/tests/unit/src/com/android/settings/applications/credentials/CredentialManagerPreferenceControllerTest.java
index d520364..7d400ad 100644
--- a/tests/unit/src/com/android/settings/applications/credentials/CredentialManagerPreferenceControllerTest.java
+++ b/tests/unit/src/com/android/settings/applications/credentials/CredentialManagerPreferenceControllerTest.java
@@ -18,10 +18,7 @@
import static com.android.settings.core.BasePreferenceController.AVAILABLE;
import static com.android.settings.core.BasePreferenceController.CONDITIONALLY_UNAVAILABLE;
-
import static com.google.common.truth.Truth.assertThat;
-
-import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import android.app.Activity;
@@ -33,15 +30,12 @@
import android.credentials.CredentialProviderInfo;
import android.net.Uri;
import android.os.Looper;
-import android.os.UserHandle;
import android.provider.Settings;
-import androidx.lifecycle.Lifecycle;
import androidx.preference.Preference;
import androidx.preference.PreferenceCategory;
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;
@@ -86,12 +80,14 @@
mCredentialsPreferenceCategory.setKey("credentials_test");
mScreen.addPreference(mCredentialsPreferenceCategory);
mReceivedResultCode = Optional.empty();
- mDelegate = new CredentialManagerPreferenceController.Delegate() {
- public void setActivityResult(int resultCode) {
- mReceivedResultCode = Optional.of(resultCode);
- }
- public void forceDelegateRefresh() {}
- };
+ mDelegate =
+ new CredentialManagerPreferenceController.Delegate() {
+ public void setActivityResult(int resultCode) {
+ mReceivedResultCode = Optional.of(resultCode);
+ }
+
+ public void forceDelegateRefresh() {}
+ };
}
@Test
@@ -134,7 +130,7 @@
}
@Test
- public void buildSwitchPreference() {
+ public void buildPreference() {
CredentialProviderInfo providerInfo1 =
createCredentialProviderInfoWithSubtitle(
"com.android.provider1", "ClassA", "Service Title", null);
@@ -158,13 +154,15 @@
assertThat(enabledProviders.contains("com.android.provider1")).isTrue();
// Create the pref (checked).
- SwitchPreference pref = controller.createPreference(mContext, providerInfo1);
+ CredentialManagerPreferenceController.CombiPreference pref =
+ controller.createPreference(mContext, providerInfo1);
assertThat(pref.getTitle().toString()).isEqualTo("Service Title");
assertThat(pref.isChecked()).isTrue();
assertThat(pref.getSummary()).isNull();
// Create the pref (not checked).
- SwitchPreference pref2 = controller.createPreference(mContext, providerInfo2);
+ CredentialManagerPreferenceController.CombiPreference pref2 =
+ controller.createPreference(mContext, providerInfo2);
assertThat(pref2.getTitle().toString()).isEqualTo("Service Title");
assertThat(pref2.isChecked()).isFalse();
assertThat(pref2.getSummary().toString()).isEqualTo("Summary Text");
@@ -311,7 +309,7 @@
assertThat(controller.isConnected()).isFalse();
assertThat(mCredentialsPreferenceCategory.getPreferenceCount()).isEqualTo(3);
- Map<String, SwitchPreference> prefs =
+ Map<String, CredentialManagerPreferenceController.CombiPreference> prefs =
controller.buildPreferenceList(mContext, mCredentialsPreferenceCategory);
assertThat(prefs.keySet())
.containsExactly(TEST_PACKAGE_NAME_A, TEST_PACKAGE_NAME_B, TEST_PACKAGE_NAME_C);
@@ -349,7 +347,8 @@
Intent intent = new Intent(PRIMARY_INTENT);
intent.setData(Uri.parse("package:" + packageName));
assertThat(controller.verifyReceivedIntent(intent)).isTrue();
- controller.completeEnableProviderDialogBox(DialogInterface.BUTTON_POSITIVE, packageName, true);
+ controller.completeEnableProviderDialogBox(
+ DialogInterface.BUTTON_POSITIVE, packageName, true);
assertThat(mReceivedResultCode.get()).isEqualTo(Activity.RESULT_OK);
}
@@ -364,7 +363,8 @@
Intent intent = new Intent(PRIMARY_INTENT);
intent.setData(Uri.parse("package:" + packageName));
assertThat(controller.verifyReceivedIntent(intent)).isTrue();
- controller.completeEnableProviderDialogBox(DialogInterface.BUTTON_NEGATIVE, packageName, true);
+ controller.completeEnableProviderDialogBox(
+ DialogInterface.BUTTON_NEGATIVE, packageName, true);
assertThat(mReceivedResultCode.get()).isEqualTo(Activity.RESULT_CANCELED);
}
@@ -390,7 +390,8 @@
Intent intent = new Intent(ALTERNATE_INTENT);
intent.setData(Uri.parse("package:" + packageName));
assertThat(controller.verifyReceivedIntent(intent)).isTrue();
- controller.completeEnableProviderDialogBox(DialogInterface.BUTTON_POSITIVE, packageName, true);
+ controller.completeEnableProviderDialogBox(
+ DialogInterface.BUTTON_POSITIVE, packageName, true);
assertThat(mReceivedResultCode.get()).isEqualTo(Activity.RESULT_OK);
}
@@ -405,7 +406,8 @@
Intent intent = new Intent(ALTERNATE_INTENT);
intent.setData(Uri.parse("package:" + packageName));
assertThat(controller.verifyReceivedIntent(intent)).isTrue();
- controller.completeEnableProviderDialogBox(DialogInterface.BUTTON_NEGATIVE, packageName, true);
+ controller.completeEnableProviderDialogBox(
+ DialogInterface.BUTTON_NEGATIVE, packageName, true);
assertThat(mReceivedResultCode.get()).isEqualTo(Activity.RESULT_CANCELED);
}
@@ -502,4 +504,4 @@
return new CredentialProviderInfo.Builder(si).setOverrideLabel(serviceLabel);
}
-}
\ No newline at end of file
+}
diff --git a/tests/unit/src/com/android/settings/datausage/DataUsageSummaryPreferenceTest.java b/tests/unit/src/com/android/settings/datausage/DataUsageSummaryPreferenceTest.java
index b27591e..fe7759d 100644
--- a/tests/unit/src/com/android/settings/datausage/DataUsageSummaryPreferenceTest.java
+++ b/tests/unit/src/com/android/settings/datausage/DataUsageSummaryPreferenceTest.java
@@ -17,40 +17,28 @@
package com.android.settings.datausage;
import static com.google.common.truth.Truth.assertThat;
-
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.spy;
-import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.content.Context;
-import android.content.Intent;
import android.content.res.Resources;
import android.graphics.Typeface;
-import android.net.ConnectivityManager;
-import android.net.NetworkTemplate;
-import android.os.Bundle;
-import android.telephony.SubscriptionManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.MeasureSpec;
import android.widget.TextView;
import androidx.preference.PreferenceViewHolder;
-import androidx.test.annotation.UiThreadTest;
import androidx.test.core.app.ApplicationProvider;
import androidx.test.ext.junit.runners.AndroidJUnit4;
-import com.android.settings.SettingsActivity;
import com.android.settings.testutils.ResourcesUtils;
import com.android.settingslib.Utils;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
-import org.mockito.ArgumentCaptor;
import org.mockito.MockitoAnnotations;
import java.util.concurrent.TimeUnit;
@@ -91,31 +79,9 @@
mUpdateTime = now - UPDATE_LAG_MILLIS;
}
- @UiThreadTest
- @Test
- public void testSetUsageInfo_withLaunchIntent_launchButtonShown() {
- mSummaryPreference.setUsageInfo(mCycleEnd, mUpdateTime, FAKE_CARRIER, 0 /* numPlans */,
- new Intent());
-
- mSummaryPreference.onBindViewHolder(mHolder);
- assertThat(mSummaryPreference.getLaunchButton(mHolder).getVisibility())
- .isEqualTo(View.VISIBLE);
- }
-
- @Test
- public void testSetUsageInfo_withoutLaunchIntent_launchButtonNotShown() {
- mSummaryPreference.setUsageInfo(mCycleEnd, mUpdateTime, FAKE_CARRIER, 0 /* numPlans */,
- null /* launchIntent */);
-
- mSummaryPreference.onBindViewHolder(mHolder);
- assertThat(mSummaryPreference.getLaunchButton(mHolder).getVisibility())
- .isEqualTo(View.GONE);
- }
-
@Test
public void testSetUsageInfo_withDataPlans_carrierInfoShown() {
- mSummaryPreference.setUsageInfo(mCycleEnd, mUpdateTime, FAKE_CARRIER, 1 /* numPlans */,
- new Intent());
+ mSummaryPreference.setUsageInfo(mCycleEnd, mUpdateTime, FAKE_CARRIER, 1 /* numPlans */);
mSummaryPreference.onBindViewHolder(mHolder);
assertThat(mSummaryPreference.getCarrierInfo(mHolder).getVisibility())
@@ -124,8 +90,7 @@
@Test
public void testSetUsageInfo_withNoDataPlans_carrierInfoNotShown() {
- mSummaryPreference.setUsageInfo(mCycleEnd, mUpdateTime, FAKE_CARRIER, 0 /* numPlans */,
- new Intent());
+ mSummaryPreference.setUsageInfo(mCycleEnd, mUpdateTime, FAKE_CARRIER, 0 /* numPlans */);
mSummaryPreference.onBindViewHolder(mHolder);
assertThat(mSummaryPreference.getCarrierInfo(mHolder).getVisibility())
@@ -138,8 +103,7 @@
int smudge = 6;
final long updateTime = System.currentTimeMillis()
- TimeUnit.DAYS.toMillis(baseUnit) - TimeUnit.HOURS.toMillis(smudge);
- mSummaryPreference.setUsageInfo(mCycleEnd, updateTime, FAKE_CARRIER, 1 /* numPlans */,
- new Intent());
+ mSummaryPreference.setUsageInfo(mCycleEnd, updateTime, FAKE_CARRIER, 1 /* numPlans */);
mSummaryPreference.onBindViewHolder(mHolder);
assertThat(mSummaryPreference.getCarrierInfo(mHolder).getText().toString())
@@ -152,8 +116,7 @@
int smudge = 6;
final long updateTime = System.currentTimeMillis()
- TimeUnit.HOURS.toMillis(baseUnit) - TimeUnit.MINUTES.toMillis(smudge);
- mSummaryPreference.setUsageInfo(mCycleEnd, updateTime, FAKE_CARRIER, 1 /* numPlans */,
- new Intent());
+ mSummaryPreference.setUsageInfo(mCycleEnd, updateTime, FAKE_CARRIER, 1 /* numPlans */);
mSummaryPreference.onBindViewHolder(mHolder);
assertThat(mSummaryPreference.getCarrierInfo(mHolder).getText().toString())
@@ -166,8 +129,7 @@
int smudge = 6;
final long updateTime = System.currentTimeMillis()
- TimeUnit.MINUTES.toMillis(baseUnit) - TimeUnit.SECONDS.toMillis(smudge);
- mSummaryPreference.setUsageInfo(mCycleEnd, updateTime, FAKE_CARRIER, 1 /* numPlans */,
- new Intent());
+ mSummaryPreference.setUsageInfo(mCycleEnd, updateTime, FAKE_CARRIER, 1 /* numPlans */);
mSummaryPreference.onBindViewHolder(mHolder);
assertThat(mSummaryPreference.getCarrierInfo(mHolder).getText().toString())
@@ -177,8 +139,7 @@
@Test
public void testCarrierUpdateTime_shouldFormatLessThanMinuteCorrectly() {
final long updateTime = System.currentTimeMillis() - TimeUnit.SECONDS.toMillis(45);
- mSummaryPreference.setUsageInfo(mCycleEnd, updateTime, FAKE_CARRIER, 1 /* numPlans */,
- new Intent());
+ mSummaryPreference.setUsageInfo(mCycleEnd, updateTime, FAKE_CARRIER, 1 /* numPlans */);
mSummaryPreference.onBindViewHolder(mHolder);
assertThat(mSummaryPreference.getCarrierInfo(mHolder).getText().toString())
@@ -189,7 +150,7 @@
public void testCarrierUpdateTimeWithNoCarrier_shouldSayJustNow() {
final long updateTime = System.currentTimeMillis() - TimeUnit.SECONDS.toMillis(45);
mSummaryPreference.setUsageInfo(mCycleEnd, updateTime, null /* carrier */,
- 1 /* numPlans */, new Intent());
+ 1 /* numPlans */);
mSummaryPreference.onBindViewHolder(mHolder);
assertThat(mSummaryPreference.getCarrierInfo(mHolder).getText().toString())
@@ -200,7 +161,7 @@
public void testCarrierUpdateTimeWithNoCarrier_shouldFormatTime() {
final long updateTime = System.currentTimeMillis() - TimeUnit.MINUTES.toMillis(2);
mSummaryPreference.setUsageInfo(mCycleEnd, updateTime, null /* carrier */,
- 1 /* numPlans */, new Intent());
+ 1 /* numPlans */);
mSummaryPreference.onBindViewHolder(mHolder);
assertThat(mSummaryPreference.getCarrierInfo(mHolder).getText().toString())
@@ -210,8 +171,7 @@
@Test
public void setUsageInfo_withRecentCarrierUpdate_doesNotSetCarrierInfoWarningColorAndFont() {
final long updateTime = System.currentTimeMillis() - TimeUnit.HOURS.toMillis(1);
- mSummaryPreference.setUsageInfo(mCycleEnd, updateTime, FAKE_CARRIER, 1 /* numPlans */,
- new Intent());
+ mSummaryPreference.setUsageInfo(mCycleEnd, updateTime, FAKE_CARRIER, 1 /* numPlans */);
mSummaryPreference.onBindViewHolder(mHolder);
TextView carrierInfo = mSummaryPreference.getCarrierInfo(mHolder);
@@ -224,8 +184,7 @@
@Test
public void testSetUsageInfo_withStaleCarrierUpdate_setsCarrierInfoWarningColorAndFont() {
final long updateTime = System.currentTimeMillis() - TimeUnit.HOURS.toMillis(7);
- mSummaryPreference.setUsageInfo(mCycleEnd, updateTime, FAKE_CARRIER, 1 /* numPlans */,
- new Intent());
+ mSummaryPreference.setUsageInfo(mCycleEnd, updateTime, FAKE_CARRIER, 1 /* numPlans */);
mSummaryPreference.onBindViewHolder(mHolder);
TextView carrierInfo = mSummaryPreference.getCarrierInfo(mHolder);
@@ -238,8 +197,7 @@
@Test
public void testSetUsageInfo_withNoDataPlans_usageTitleNotShown() {
- mSummaryPreference.setUsageInfo(mCycleEnd, mUpdateTime, FAKE_CARRIER, 0 /* numPlans */,
- new Intent());
+ mSummaryPreference.setUsageInfo(mCycleEnd, mUpdateTime, FAKE_CARRIER, 0 /* numPlans */);
mSummaryPreference.onBindViewHolder(mHolder);
assertThat(mSummaryPreference.getUsageTitle(mHolder).getVisibility()).isEqualTo(View.GONE);
@@ -247,8 +205,7 @@
@Test
public void testSetUsageInfo_withMultipleDataPlans_usageTitleShown() {
- mSummaryPreference.setUsageInfo(mCycleEnd, mUpdateTime, FAKE_CARRIER, 2 /* numPlans */,
- new Intent());
+ mSummaryPreference.setUsageInfo(mCycleEnd, mUpdateTime, FAKE_CARRIER, 2 /* numPlans */);
mSummaryPreference.onBindViewHolder(mHolder);
assertThat(mSummaryPreference.getUsageTitle(mHolder).getVisibility())
@@ -259,8 +216,7 @@
public void testSetUsageInfo_cycleRemainingTimeIsLessOneDay() {
// just under one day
final long cycleEnd = System.currentTimeMillis() + TimeUnit.HOURS.toMillis(23);
- mSummaryPreference.setUsageInfo(cycleEnd, mUpdateTime, FAKE_CARRIER, 0 /* numPlans */,
- new Intent());
+ mSummaryPreference.setUsageInfo(cycleEnd, mUpdateTime, FAKE_CARRIER, 0 /* numPlans */);
mSummaryPreference.onBindViewHolder(mHolder);
assertThat(mSummaryPreference.getCycleTime(mHolder).getVisibility())
@@ -273,8 +229,7 @@
@Test
public void testSetUsageInfo_cycleRemainingTimeNegativeDaysLeft_shouldDisplayNoneLeft() {
final long cycleEnd = System.currentTimeMillis() - 1L;
- mSummaryPreference.setUsageInfo(cycleEnd, mUpdateTime, FAKE_CARRIER, 0 /* numPlans */,
- new Intent());
+ mSummaryPreference.setUsageInfo(cycleEnd, mUpdateTime, FAKE_CARRIER, 0 /* numPlans */);
mSummaryPreference.onBindViewHolder(mHolder);
assertThat(mSummaryPreference.getCycleTime(mHolder).getVisibility())
@@ -288,8 +243,7 @@
final int daysLeft = 3;
final long cycleEnd = System.currentTimeMillis() + TimeUnit.DAYS.toMillis(daysLeft)
+ TimeUnit.HOURS.toMillis(1);
- mSummaryPreference.setUsageInfo(cycleEnd, mUpdateTime, FAKE_CARRIER, 0 /* numPlans */,
- new Intent());
+ mSummaryPreference.setUsageInfo(cycleEnd, mUpdateTime, FAKE_CARRIER, 0 /* numPlans */);
mSummaryPreference.onBindViewHolder(mHolder);
assertThat(mSummaryPreference.getCycleTime(mHolder).getVisibility())
@@ -372,8 +326,7 @@
@Test
public void testSetUsageAndRemainingInfo_withUsageInfo_dataUsageAndRemainingShown() {
- mSummaryPreference.setUsageInfo(mCycleEnd, mUpdateTime, FAKE_CARRIER, 1 /* numPlans */,
- new Intent());
+ mSummaryPreference.setUsageInfo(mCycleEnd, mUpdateTime, FAKE_CARRIER, 1 /* numPlans */);
mSummaryPreference.setUsageNumbers(
BillingCycleSettings.MIB_IN_BYTES,
10 * BillingCycleSettings.MIB_IN_BYTES,
@@ -393,8 +346,7 @@
@Test
public void testSetUsageInfo_withDataOverusage() {
- mSummaryPreference.setUsageInfo(mCycleEnd, mUpdateTime, FAKE_CARRIER, 1 /* numPlans */,
- new Intent());
+ mSummaryPreference.setUsageInfo(mCycleEnd, mUpdateTime, FAKE_CARRIER, 1 /* numPlans */);
mSummaryPreference.setUsageNumbers(
11 * BillingCycleSettings.MIB_IN_BYTES,
10 * BillingCycleSettings.MIB_IN_BYTES,
@@ -412,8 +364,7 @@
@Test
public void testSetUsageInfo_withUsageInfo_dataUsageShown() {
- mSummaryPreference.setUsageInfo(mCycleEnd, mUpdateTime, FAKE_CARRIER, 0 /* numPlans */,
- new Intent());
+ mSummaryPreference.setUsageInfo(mCycleEnd, mUpdateTime, FAKE_CARRIER, 0 /* numPlans */);
mSummaryPreference.setUsageNumbers(
BillingCycleSettings.MIB_IN_BYTES, -1L, true /* hasMobileData */);
@@ -424,42 +375,12 @@
}
@Test
- public void testSetAppIntent_toMdpApp_intentCorrect() {
- final Intent intent = new Intent(SubscriptionManager.ACTION_MANAGE_SUBSCRIPTION_PLANS);
- intent.setPackage("test-owner.example.com");
- intent.putExtra(SubscriptionManager.EXTRA_SUBSCRIPTION_INDEX, 42);
-
- mSummaryPreference.setUsageInfo(mCycleEnd, mUpdateTime, FAKE_CARRIER, 0 /* numPlans */,
- intent);
-
- mSummaryPreference.onBindViewHolder(mHolder);
- assertThat(mSummaryPreference.getLaunchButton(mHolder).getVisibility())
- .isEqualTo(View.VISIBLE);
- assertThat(mSummaryPreference.getLaunchButton(mHolder).getText())
- .isEqualTo(ResourcesUtils.getResourcesString(mContext, "launch_mdp_app_text"));
-
- doNothing().when(mContext).startActivity(any(Intent.class));
- mSummaryPreference.getLaunchButton(mHolder).callOnClick();
- final ArgumentCaptor<Intent> intentCaptor = ArgumentCaptor.forClass(
- Intent.class);
- verify(mContext).startActivity(intentCaptor.capture());
- final Intent startedIntent = intentCaptor.getValue();
-
- assertThat(startedIntent.getAction())
- .isEqualTo(SubscriptionManager.ACTION_MANAGE_SUBSCRIPTION_PLANS);
- assertThat(startedIntent.getPackage()).isEqualTo("test-owner.example.com");
- assertThat(startedIntent.getIntExtra(SubscriptionManager.EXTRA_SUBSCRIPTION_INDEX, -1))
- .isEqualTo(42);
- }
-
- @Test
public void testSetUsageInfo_withOverflowStrings_dataRemainingNotShown() {
LayoutInflater inflater = LayoutInflater.from(mContext);
View view = inflater.inflate(mSummaryPreference.getLayoutResource(), null /* root */,
false /* attachToRoot */);
- mSummaryPreference.setUsageInfo(mCycleEnd, mUpdateTime, FAKE_CARRIER, 1 /* numPlans */,
- new Intent());
+ mSummaryPreference.setUsageInfo(mCycleEnd, mUpdateTime, FAKE_CARRIER, 1 /* numPlans */);
mSummaryPreference.setUsageNumbers(
BillingCycleSettings.MIB_IN_BYTES,
10 * BillingCycleSettings.MIB_IN_BYTES,
@@ -493,79 +414,4 @@
// TODO(b/175389659): re-enable this line once cuttlefish device specs are verified.
// assertThat(dataRemaining.getVisibility()).isEqualTo(View.GONE);
}
-
- @Test
- public void testSetWifiMode_withUsageInfo_dataUsageShown() {
- final int daysLeft = 3;
- final long cycleEnd = System.currentTimeMillis() + TimeUnit.DAYS.toMillis(daysLeft)
- + TimeUnit.HOURS.toMillis(1);
- mSummaryPreference.setUsageInfo(cycleEnd, mUpdateTime, FAKE_CARRIER, 0 /* numPlans */,
- new Intent());
- mSummaryPreference.setUsageNumbers(1000000L, -1L, true);
- final String cycleText = "The quick fox";
- mSummaryPreference.setWifiMode(true /* isWifiMode */, cycleText, false /* isSingleWifi */);
- doReturn(200L).when(mSummaryPreference).getHistoricalUsageLevel();
-
- mSummaryPreference.onBindViewHolder(mHolder);
- assertThat(mSummaryPreference.getUsageTitle(mHolder).getText().toString())
- .isEqualTo(ResourcesUtils.getResourcesString(mContext, "data_usage_wifi_title"));
- assertThat(mSummaryPreference.getUsageTitle(mHolder).getVisibility())
- .isEqualTo(View.VISIBLE);
- assertThat(mSummaryPreference.getCycleTime(mHolder).getVisibility())
- .isEqualTo(View.VISIBLE);
- assertThat(mSummaryPreference.getCycleTime(mHolder).getText()).isEqualTo(cycleText);
- assertThat(mSummaryPreference.getCarrierInfo(mHolder).getVisibility()).isEqualTo(View.GONE);
- assertThat(mSummaryPreference.getDataLimits(mHolder).getVisibility()).isEqualTo(View.GONE);
- assertThat(mSummaryPreference.getLaunchButton(mHolder).getVisibility())
- .isEqualTo(View.VISIBLE);
- assertThat(mSummaryPreference.getLaunchButton(mHolder).getText())
- .isEqualTo(ResourcesUtils.getResourcesString(mContext, "launch_wifi_text"));
-
- doNothing().when(mContext).startActivity(any(Intent.class));
- mSummaryPreference.getLaunchButton(mHolder).callOnClick();
-
- final ArgumentCaptor<Intent> intentCaptor = ArgumentCaptor.forClass(
- Intent.class);
- verify(mContext).startActivity(intentCaptor.capture());
- final Intent startedIntent = intentCaptor.getValue();
-
- final Bundle expect = new Bundle(1);
- expect.putParcelable(DataUsageList.EXTRA_NETWORK_TEMPLATE,
- new NetworkTemplate.Builder(NetworkTemplate.MATCH_WIFI).build());
- final Bundle actual = startedIntent
- .getBundleExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_ARGUMENTS);
- assertThat((NetworkTemplate) actual.getParcelable(DataUsageList.EXTRA_NETWORK_TEMPLATE))
- .isEqualTo(new NetworkTemplate.Builder(NetworkTemplate.MATCH_WIFI).build());
-
- assertThat(startedIntent.getIntExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_TITLE_RESID, 0))
- .isEqualTo(ResourcesUtils.getResourcesId(mContext, "string", "wifi_data_usage"));
- }
-
- @UiThreadTest
- @Test
- public void testSetWifiMode_noUsageInfo_shouldDisableLaunchButton() {
- mSummaryPreference.setWifiMode(true /* isWifiMode */, "Test cycle text",
- false /* isSingleWifi */);
- doReturn(0L).when(mSummaryPreference).getHistoricalUsageLevel();
-
- mSummaryPreference.onBindViewHolder(mHolder);
-
- assertThat(mSummaryPreference.getLaunchButton(mHolder).isEnabled()).isFalse();
- }
-
- @Test
- public void launchWifiDataUsage_shouldSetWifiNetworkTypeInIntentExtra() {
- doNothing().when(mContext).startActivity(any(Intent.class));
- mSummaryPreference.launchWifiDataUsage(mContext);
-
- final ArgumentCaptor<Intent> intentCaptor = ArgumentCaptor.forClass(
- Intent.class);
- verify(mContext).startActivity(intentCaptor.capture());
- final Intent launchIntent = intentCaptor.getValue();
- final Bundle args =
- launchIntent.getBundleExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_ARGUMENTS);
-
- assertThat(args.getInt(DataUsageList.EXTRA_NETWORK_TYPE))
- .isEqualTo(ConnectivityManager.TYPE_WIFI);
- }
}
diff --git a/tests/unit/src/com/android/settings/deviceinfo/BrandedAccountPreferenceControllerTest.java b/tests/unit/src/com/android/settings/deviceinfo/BrandedAccountPreferenceControllerTest.java
index 6e78d05..0c57400 100644
--- a/tests/unit/src/com/android/settings/deviceinfo/BrandedAccountPreferenceControllerTest.java
+++ b/tests/unit/src/com/android/settings/deviceinfo/BrandedAccountPreferenceControllerTest.java
@@ -17,7 +17,6 @@
package com.android.settings.deviceinfo;
import static com.google.common.truth.Truth.assertThat;
-
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
@@ -26,6 +25,9 @@
import android.content.Context;
import android.content.res.Resources;
+import androidx.preference.Preference;
+import androidx.preference.PreferenceManager;
+import androidx.preference.PreferenceScreen;
import androidx.test.core.app.ApplicationProvider;
import androidx.test.ext.junit.runners.AndroidJUnit4;
@@ -46,17 +48,21 @@
private Context mContext;
private FakeFeatureFactory mFakeFeatureFactory;
+ private PreferenceScreen mScreen;
+ private Preference mPreference;
+
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = spy(ApplicationProvider.getApplicationContext());
- when(mContext.getResources()).thenReturn(mResources);
mFakeFeatureFactory = FakeFeatureFactory.setupForTest();
-
+ mScreen = new PreferenceManager(mContext).createPreferenceScreen(mContext);
+ mPreference = new Preference(mContext);
}
@Test
public void isAvailable_configOn_noAccount_off() {
+ when(mContext.getResources()).thenReturn(mResources);
final int boolId = ResourcesUtils.getResourcesId(
ApplicationProvider.getApplicationContext(), "bool",
"config_show_branded_account_in_device_info");
@@ -69,6 +75,7 @@
@Test
public void isAvailable_accountIsAvailable_on() {
+ when(mContext.getResources()).thenReturn(mResources);
final int boolId = ResourcesUtils.getResourcesId(
ApplicationProvider.getApplicationContext(), "bool",
"config_show_branded_account_in_device_info");
@@ -84,6 +91,7 @@
@Test
public void isAvailable_configOff_hasAccount_off() {
+ when(mContext.getResources()).thenReturn(mResources);
final int boolId = ResourcesUtils.getResourcesId(
ApplicationProvider.getApplicationContext(), "bool",
"config_show_branded_account_in_device_info");
@@ -96,4 +104,42 @@
assertThat(controller.isAvailable()).isFalse();
}
+
+ /**
+ * Test displayPreference has one account.
+ */
+ @Test
+ public void displayPreference_hasOneAccount_showAccount() {
+ when(mFakeFeatureFactory.mAccountFeatureProvider.getAccounts(any(Context.class)))
+ .thenReturn(new Account[]{new Account("teresaikeda@gmail.com",
+ "com.google")});
+
+ mPreference.setKey("test_key");
+ mScreen.addPreference(mPreference);
+ final BrandedAccountPreferenceController controller =
+ new BrandedAccountPreferenceController(mContext, "test_key");
+
+ controller.displayPreference(mScreen);
+
+ assertThat(mPreference.getSummary()).isEqualTo("teresaikeda@gmail.com");
+ }
+
+ /**
+ * Test displayPreference has two accounts.
+ */
+ @Test
+ public void displayPreference_hasTwoAccounts_showTwoAccountSummary() {
+ when(mFakeFeatureFactory.mAccountFeatureProvider.getAccounts(any(Context.class)))
+ .thenReturn(new Account[]{new Account("teresa@gmail.com", "com.google"),
+ new Account("reno@gmail.com", "com.google") });
+
+ mPreference.setKey("test_key");
+ mScreen.addPreference(mPreference);
+ final BrandedAccountPreferenceController controller =
+ new BrandedAccountPreferenceController(mContext, "test_key");
+
+ controller.displayPreference(mScreen);
+
+ assertThat(mPreference.getSummary()).isEqualTo("2 accounts");
+ }
}