wifiScanResults = mWifiManager.getScanResults();
- if (wifiScanResults != null && wifiScanResults.size() > 0) {
- mHandlerInjector.postDelay(mHideProgressBarRunnable);
- } else if (!mIsScanningSubTitleShownOnce) {
- mHandlerInjector.postDelay(mHideScanningSubTitleRunnable);
- }
- }
-
- protected void setProgressBarVisible(boolean visible) {
- if (mIsProgressBarVisible == visible) {
- return;
- }
- mIsProgressBarVisible = visible;
-
- if (mCallback == null) {
- return;
- }
- mCallback.onProgressBarVisibleChanged();
- updatePanelTitle();
- }
-
- private class NetworkProviderTelephonyCallback extends TelephonyCallback implements
- TelephonyCallback.DataConnectionStateListener,
- TelephonyCallback.ServiceStateListener {
- @Override
- public void onServiceStateChanged(ServiceState state) {
- log("onServiceStateChanged voiceState=" + state.getState()
- + " dataState=" + state.getDataRegistrationState());
- updatePanelTitle();
- }
-
- @Override
- public void onDataConnectionStateChanged(int state, int networkType) {
- log("onDataConnectionStateChanged: networkType=" + networkType + " state=" + state);
- updatePanelTitle();
- }
- }
-
- private static void log(String s) {
- Log.d(TAG, s);
- }
-}
diff --git a/src/com/android/settings/panel/PanelFeatureProviderImpl.java b/src/com/android/settings/panel/PanelFeatureProviderImpl.java
index ca30952a72d..a73881b4cc1 100644
--- a/src/com/android/settings/panel/PanelFeatureProviderImpl.java
+++ b/src/com/android/settings/panel/PanelFeatureProviderImpl.java
@@ -17,11 +17,14 @@
package com.android.settings.panel;
import android.content.Context;
+import android.content.Intent;
import android.os.Bundle;
import android.provider.Settings;
public class PanelFeatureProviderImpl implements PanelFeatureProvider {
+ private static final String SYSTEMUI_PACKAGE_NAME = "com.android.systemui";
+
@Override
public PanelContent getPanel(Context context, Bundle bundle) {
if (context == null) {
@@ -35,7 +38,12 @@ public class PanelFeatureProviderImpl implements PanelFeatureProvider {
switch (panelType) {
case Settings.Panel.ACTION_INTERNET_CONNECTIVITY:
- return InternetConnectivityPanel.create(context);
+ // Redirect to the internet dialog in SystemUI.
+ Intent intent = new Intent(Settings.Panel.ACTION_INTERNET_CONNECTIVITY);
+ intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND)
+ .setPackage(SYSTEMUI_PACKAGE_NAME);
+ context.sendBroadcast(intent);
+ return null;
case Settings.Panel.ACTION_NFC:
return NfcPanel.create(context);
case Settings.Panel.ACTION_WIFI:
diff --git a/src/com/android/settings/password/ChooseLockGenericController.java b/src/com/android/settings/password/ChooseLockGenericController.java
index 1b951d4f968..cd9eb2fd44d 100644
--- a/src/com/android/settings/password/ChooseLockGenericController.java
+++ b/src/com/android/settings/password/ChooseLockGenericController.java
@@ -190,7 +190,8 @@ public class ChooseLockGenericController {
* requirements. The lock's visibility ({@link #isScreenLockVisible}) is not considered here.
*/
public boolean isScreenLockEnabled(ScreenLockType type) {
- return type.maxQuality >= upgradeQuality(PASSWORD_QUALITY_UNSPECIFIED);
+ return !mLockPatternUtils.isCredentialsDisabledForUser(mUserId)
+ && type.maxQuality >= upgradeQuality(PASSWORD_QUALITY_UNSPECIFIED);
}
/**
diff --git a/src/com/android/settings/password/ChooseLockPassword.java b/src/com/android/settings/password/ChooseLockPassword.java
index ae178c88883..c03362510d0 100644
--- a/src/com/android/settings/password/ChooseLockPassword.java
+++ b/src/com/android/settings/password/ChooseLockPassword.java
@@ -499,13 +499,7 @@ public class ChooseLockPassword extends SettingsActivity {
mNextButton = mixin.getPrimaryButton();
mMessage = view.findViewById(R.id.sud_layout_description);
- if (mForFingerprint) {
- mLayout.setIcon(getActivity().getDrawable(R.drawable.ic_fingerprint_header));
- } else if (mForFace) {
- mLayout.setIcon(getActivity().getDrawable(R.drawable.ic_face_header));
- } else if (mForBiometrics) {
- mLayout.setIcon(getActivity().getDrawable(R.drawable.ic_lock));
- }
+ mLayout.setIcon(getActivity().getDrawable(R.drawable.ic_lock));
mIsAlphaMode = DevicePolicyManager.PASSWORD_QUALITY_ALPHABETIC == mPasswordType
|| DevicePolicyManager.PASSWORD_QUALITY_ALPHANUMERIC == mPasswordType
diff --git a/src/com/android/settings/password/ChooseLockPattern.java b/src/com/android/settings/password/ChooseLockPattern.java
index e85ce60c6c4..8464a2ffd7c 100644
--- a/src/com/android/settings/password/ChooseLockPattern.java
+++ b/src/com/android/settings/password/ChooseLockPattern.java
@@ -505,13 +505,7 @@ public class ChooseLockPattern extends SettingsActivity {
layout.getMixin(IconMixin.class).setVisibility(View.GONE);
}
} else {
- if (mForFingerprint) {
- layout.setIcon(getActivity().getDrawable(R.drawable.ic_fingerprint_header));
- } else if (mForFace) {
- layout.setIcon(getActivity().getDrawable(R.drawable.ic_face_header));
- } else if (mForBiometrics) {
- layout.setIcon(getActivity().getDrawable(R.drawable.ic_lock));
- }
+ layout.setIcon(getActivity().getDrawable(R.drawable.ic_lock));
}
final FooterBarMixin mixin = layout.getMixin(FooterBarMixin.class);
diff --git a/src/com/android/settings/security/ConfirmSimDeletionPreferenceController.java b/src/com/android/settings/security/ConfirmSimDeletionPreferenceController.java
index bf807a19715..a7185e3f207 100644
--- a/src/com/android/settings/security/ConfirmSimDeletionPreferenceController.java
+++ b/src/com/android/settings/security/ConfirmSimDeletionPreferenceController.java
@@ -26,6 +26,7 @@ import androidx.preference.TwoStatePreference;
import com.android.settings.R;
import com.android.settings.core.BasePreferenceController;
+import com.android.settings.network.helper.ConfirmationSimDeletionPredicate;
import com.android.settings.network.telephony.MobileNetworkUtils;
import com.android.settings.overlay.FeatureFactory;
import com.android.settings.wifi.dpp.WifiDppUtils;
@@ -34,7 +35,8 @@ import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
/** Enable/disable user confirmation before deleting an eSim */
public class ConfirmSimDeletionPreferenceController extends BasePreferenceController implements
Preference.OnPreferenceChangeListener{
- public static final String KEY_CONFIRM_SIM_DELETION = "confirm_sim_deletion";
+ public static final String KEY_CONFIRM_SIM_DELETION =
+ ConfirmationSimDeletionPredicate.KEY_CONFIRM_SIM_DELETION;
private boolean mConfirmationDefaultOn;
private MetricsFeatureProvider mMetricsFeatureProvider;
diff --git a/src/com/android/settings/sim/SimDialogActivity.java b/src/com/android/settings/sim/SimDialogActivity.java
index 252b6c06e25..e5457ae3459 100644
--- a/src/com/android/settings/sim/SimDialogActivity.java
+++ b/src/com/android/settings/sim/SimDialogActivity.java
@@ -24,6 +24,7 @@ import android.telecom.TelecomManager;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
import android.util.Log;
+import android.view.WindowManager;
import android.widget.Toast;
import androidx.fragment.app.Fragment;
@@ -59,6 +60,8 @@ public class SimDialogActivity extends FragmentActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
+ getWindow().addSystemFlags(
+ WindowManager.LayoutParams.SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS);
showOrUpdateDialog();
}
diff --git a/src/com/android/settings/sim/smartForwarding/DisableSmartForwardingTask.java b/src/com/android/settings/sim/smartForwarding/DisableSmartForwardingTask.java
index 45333ec7bcb..d483dd12ed2 100644
--- a/src/com/android/settings/sim/smartForwarding/DisableSmartForwardingTask.java
+++ b/src/com/android/settings/sim/smartForwarding/DisableSmartForwardingTask.java
@@ -19,6 +19,7 @@ package com.android.settings.sim.smartForwarding;
import static com.android.settings.sim.smartForwarding.SmartForwardingUtils.TAG;
import android.telephony.CallForwardingInfo;
+import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
import android.util.Log;
@@ -37,17 +38,29 @@ public class DisableSmartForwardingTask implements Runnable {
@Override
public void run() {
for (int i = 0; i < tm.getActiveModemCount(); i++) {
- if (callWaitingStatus != null) {
+ int subId = getSubId(i);
+ if (callWaitingStatus != null
+ && subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
Log.d(TAG, "Restore call waiting to " + callWaitingStatus[i]);
- tm.setCallWaitingEnabled(callWaitingStatus[i], null, null);
+ tm.createForSubscriptionId(subId)
+ .setCallWaitingEnabled(callWaitingStatus[i], null, null);
}
if (callForwardingInfo != null
&& callForwardingInfo[i] != null
- && callForwardingInfo[i].getTimeoutSeconds() > 0) {
- Log.d(TAG, "Restore call waiting to " + callForwardingInfo);
- tm.setCallForwarding(callForwardingInfo[i], null, null);
+ && subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
+ Log.d(TAG, "Restore call forwarding to " + callForwardingInfo[i]);
+ tm.createForSubscriptionId(subId)
+ .setCallForwarding(callForwardingInfo[i], null, null);
}
}
}
+
+ private int getSubId(int slotIndex) {
+ int[] subId = SubscriptionManager.getSubId(slotIndex);
+ if (subId != null && subId.length > 0) {
+ return subId[0];
+ }
+ return SubscriptionManager.INVALID_SUBSCRIPTION_ID;
+ }
}
diff --git a/src/com/android/settings/uwb/UwbPreferenceController.java b/src/com/android/settings/uwb/UwbPreferenceController.java
index 15979b510cf..877c9f2f2b4 100644
--- a/src/com/android/settings/uwb/UwbPreferenceController.java
+++ b/src/com/android/settings/uwb/UwbPreferenceController.java
@@ -57,7 +57,9 @@ public class UwbPreferenceController extends TogglePreferenceController implemen
public UwbPreferenceController(Context context, String key) {
super(context, key);
mExecutor = Executors.newSingleThreadExecutor();
- mUwbManager = context.getSystemService(UwbManager.class);
+ if (isUwbSupportedOnDevice()) {
+ mUwbManager = context.getSystemService(UwbManager.class);
+ }
mAirplaneModeOn = Settings.Global.getInt(mContext.getContentResolver(),
Settings.Global.AIRPLANE_MODE_ON, 0) == 1;
mAirplaneModeChangedReceiver = new BroadcastReceiver() {
diff --git a/src/com/android/settings/widget/LabeledSeekBarPreference.java b/src/com/android/settings/widget/LabeledSeekBarPreference.java
index 3a9ac18beb0..b34ea1946f9 100644
--- a/src/com/android/settings/widget/LabeledSeekBarPreference.java
+++ b/src/com/android/settings/widget/LabeledSeekBarPreference.java
@@ -20,9 +20,11 @@ import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
+import android.view.View;
import android.widget.SeekBar;
import android.widget.TextView;
+import androidx.annotation.Nullable;
import androidx.core.content.res.TypedArrayUtils;
import androidx.preference.PreferenceViewHolder;
@@ -35,6 +37,8 @@ public class LabeledSeekBarPreference extends SeekBarPreference {
private final int mTextEndId;
private final int mTickMarkId;
private OnPreferenceChangeListener mStopListener;
+ @Nullable
+ private CharSequence mSummary;
public LabeledSeekBarPreference(Context context, AttributeSet attrs, int defStyleAttr,
int defStyleRes) {
@@ -52,6 +56,7 @@ public class LabeledSeekBarPreference extends SeekBarPreference {
R.string.summary_placeholder);
mTickMarkId = styledAttrs.getResourceId(
R.styleable.LabeledSeekBarPreference_tickMark, /* defValue= */ 0);
+ mSummary = styledAttrs.getText(R.styleable.Preference_android_summary);
styledAttrs.recycle();
}
@@ -76,6 +81,15 @@ public class LabeledSeekBarPreference extends SeekBarPreference {
com.android.internal.R.id.seekbar);
seekBar.setTickMark(tickMark);
}
+
+ final TextView summary = (TextView) holder.findViewById(android.R.id.summary);
+ if (mSummary != null) {
+ summary.setText(mSummary);
+ summary.setVisibility(View.VISIBLE);
+ } else {
+ summary.setText(null);
+ summary.setVisibility(View.GONE);
+ }
}
public void setOnPreferenceChangeStopListener(OnPreferenceChangeListener listener) {
@@ -90,5 +104,24 @@ public class LabeledSeekBarPreference extends SeekBarPreference {
mStopListener.onPreferenceChange(this, seekBar.getProgress());
}
}
+
+ @Override
+ public void setSummary(CharSequence summary) {
+ super.setSummary(summary);
+ mSummary = summary;
+ notifyChanged();
+ }
+
+ @Override
+ public void setSummary(int summaryResId) {
+ super.setSummary(summaryResId);
+ mSummary = getContext().getText(summaryResId);
+ notifyChanged();
+ }
+
+ @Override
+ public CharSequence getSummary() {
+ return mSummary;
+ }
}
diff --git a/src/com/android/settings/wifi/ConfigureWifiEntryFragment.java b/src/com/android/settings/wifi/ConfigureWifiEntryFragment.java
index d2f50903698..469ca1dd9e7 100644
--- a/src/com/android/settings/wifi/ConfigureWifiEntryFragment.java
+++ b/src/com/android/settings/wifi/ConfigureWifiEntryFragment.java
@@ -38,7 +38,7 @@ import androidx.annotation.VisibleForTesting;
import com.android.settings.R;
import com.android.settings.core.InstrumentedFragment;
import com.android.settings.overlay.FeatureFactory;
-import com.android.settings.wifi.details2.WifiNetworkDetailsFragment2;
+import com.android.settings.wifi.details.WifiNetworkDetailsFragment;
import com.android.wifitrackerlib.NetworkDetailsTracker;
import com.android.wifitrackerlib.WifiEntry;
@@ -238,6 +238,6 @@ public class ConfigureWifiEntryFragment extends InstrumentedFragment implements
MAX_SCAN_AGE_MILLIS,
SCAN_INTERVAL_MILLIS,
getArguments().getString(
- WifiNetworkDetailsFragment2.KEY_CHOSEN_WIFIENTRY_KEY));
+ WifiNetworkDetailsFragment.KEY_CHOSEN_WIFIENTRY_KEY));
}
}
diff --git a/src/com/android/settings/wifi/NetworkRequestDialogFragment.java b/src/com/android/settings/wifi/NetworkRequestDialogFragment.java
index cbc89ae7720..5fe156c3dbf 100644
--- a/src/com/android/settings/wifi/NetworkRequestDialogFragment.java
+++ b/src/com/android/settings/wifi/NetworkRequestDialogFragment.java
@@ -330,7 +330,7 @@ public class NetworkRequestDialogFragment extends NetworkRequestDialogBaseFragme
final PreferenceImageView imageView = view.findViewById(android.R.id.icon);
final int level = wifiEntry.getLevel();
- if (imageView != null) {
+ if (imageView != null && level != WifiEntry.WIFI_LEVEL_UNREACHABLE) {
final Drawable drawable = getContext().getDrawable(
Utils.getWifiIconResource(level));
drawable.setTintList(
diff --git a/src/com/android/settings/wifi/WifiConfigController2.java b/src/com/android/settings/wifi/WifiConfigController2.java
index e8f2384d5cd..011c9709c00 100644
--- a/src/com/android/settings/wifi/WifiConfigController2.java
+++ b/src/com/android/settings/wifi/WifiConfigController2.java
@@ -484,7 +484,7 @@ public class WifiConfigController2 implements TextWatcher,
}
boolean isValidSaePassword(String password) {
- if (password.length() >= 1 && password.length() <= 63) {
+ if (password.length() >= 1 && password.length() <= 128) {
return true;
}
return false;
diff --git a/src/com/android/settings/wifi/WifiConnectionPreferenceController.java b/src/com/android/settings/wifi/WifiConnectionPreferenceController.java
index 3b2669cefda..fc2f8f15415 100644
--- a/src/com/android/settings/wifi/WifiConnectionPreferenceController.java
+++ b/src/com/android/settings/wifi/WifiConnectionPreferenceController.java
@@ -34,7 +34,7 @@ import androidx.preference.PreferenceScreen;
import com.android.settings.R;
import com.android.settings.core.SubSettingLauncher;
import com.android.settings.overlay.FeatureFactory;
-import com.android.settings.wifi.details2.WifiNetworkDetailsFragment2;
+import com.android.settings.wifi.details.WifiNetworkDetailsFragment;
import com.android.settingslib.core.AbstractPreferenceController;
import com.android.settingslib.core.lifecycle.Lifecycle;
import com.android.settingslib.wifi.WifiEntryPreference;
@@ -165,11 +165,11 @@ public class WifiConnectionPreferenceController extends AbstractPreferenceContro
mPreference.setOrder(order);
mPreference.setOnPreferenceClickListener(pref -> {
final Bundle args = new Bundle();
- args.putString(WifiNetworkDetailsFragment2.KEY_CHOSEN_WIFIENTRY_KEY,
+ args.putString(WifiNetworkDetailsFragment.KEY_CHOSEN_WIFIENTRY_KEY,
wifiEntry.getKey());
new SubSettingLauncher(mPrefContext)
.setTitleRes(R.string.pref_title_network_details)
- .setDestination(WifiNetworkDetailsFragment2.class.getName())
+ .setDestination(WifiNetworkDetailsFragment.class.getName())
.setArguments(args)
.setSourceMetricsCategory(mMetricsCategory)
.launch();
diff --git a/src/com/android/settings/wifi/WifiDialog2.java b/src/com/android/settings/wifi/WifiDialog2.java
index dc546f3c231..05dad3f1b96 100644
--- a/src/com/android/settings/wifi/WifiDialog2.java
+++ b/src/com/android/settings/wifi/WifiDialog2.java
@@ -21,6 +21,8 @@ import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
+import android.view.Window;
+import android.view.WindowManager;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.TextView;
@@ -108,6 +110,8 @@ public class WifiDialog2 extends AlertDialog implements WifiConfigUiBase2,
@Override
protected void onCreate(Bundle savedInstanceState) {
+ setWindowsOverlay();
+
mView = getLayoutInflater().inflate(R.layout.wifi_dialog, /* root */ null);
setView(mView);
mController = new WifiConfigController2(this, mView, mWifiEntry, mMode);
@@ -126,6 +130,13 @@ public class WifiDialog2 extends AlertDialog implements WifiConfigUiBase2,
}
}
+ private void setWindowsOverlay() {
+ final Window window = getWindow();
+ final WindowManager.LayoutParams lp = window.getAttributes();
+ window.setType(WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG);
+ window.setAttributes(lp);
+ }
+
@Override
protected void onStart() {
final ImageButton ssidScannerButton = findViewById(R.id.ssid_scanner_button);
diff --git a/src/com/android/settings/wifi/WifiDialogActivity.java b/src/com/android/settings/wifi/WifiDialogActivity.java
index 4514b0d19f0..877933edafe 100644
--- a/src/com/android/settings/wifi/WifiDialogActivity.java
+++ b/src/com/android/settings/wifi/WifiDialogActivity.java
@@ -16,12 +16,8 @@
package com.android.settings.wifi;
-import static android.Manifest.permission.ACCESS_COARSE_LOCATION;
-import static android.Manifest.permission.ACCESS_FINE_LOCATION;
-
import android.content.DialogInterface;
import android.content.Intent;
-import android.content.pm.PackageManager;
import android.net.NetworkInfo;
import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiManager;
@@ -33,7 +29,6 @@ import android.os.Process;
import android.os.SimpleClock;
import android.os.SystemClock;
import android.text.TextUtils;
-import android.util.EventLog;
import android.util.Log;
import androidx.annotation.VisibleForTesting;
@@ -83,12 +78,10 @@ public class WifiDialogActivity extends ObservableActivity implements WifiDialog
public static final String KEY_WIFI_CONFIGURATION = "wifi_configuration";
- @VisibleForTesting
- static final int RESULT_CONNECTED = RESULT_FIRST_USER;
+ private static final int RESULT_CONNECTED = RESULT_FIRST_USER;
private static final int RESULT_FORGET = RESULT_FIRST_USER + 1;
- @VisibleForTesting
- static final int REQUEST_CODE_WIFI_DPP_ENROLLEE_QR_CODE_SCANNER = 0;
+ private static final int REQUEST_CODE_WIFI_DPP_ENROLLEE_QR_CODE_SCANNER = 0;
// Max age of tracked WifiEntries.
private static final long MAX_SCAN_AGE_MILLIS = 15_000;
@@ -265,7 +258,10 @@ public class WifiDialogActivity extends ObservableActivity implements WifiDialog
}
}
- Intent resultData = hasPermissionForResult() ? createResultData(config, null) : null;
+ final Intent resultData = new Intent();
+ if (config != null) {
+ resultData.putExtra(KEY_WIFI_CONFIGURATION, config);
+ }
setResult(RESULT_CONNECTED, resultData);
finish();
}
@@ -293,22 +289,17 @@ public class WifiDialogActivity extends ObservableActivity implements WifiDialog
}
}
- Intent resultData = hasPermissionForResult() ? createResultData(config, accessPoint) : null;
- setResult(RESULT_CONNECTED, resultData);
- finish();
- }
-
- protected Intent createResultData(WifiConfiguration config, AccessPoint accessPoint) {
- Intent result = new Intent();
+ Intent resultData = new Intent();
if (accessPoint != null) {
Bundle accessPointState = new Bundle();
accessPoint.saveWifiState(accessPointState);
- result.putExtra(KEY_ACCESS_POINT_STATE, accessPointState);
+ resultData.putExtra(KEY_ACCESS_POINT_STATE, accessPointState);
}
if (config != null) {
- result.putExtra(KEY_WIFI_CONFIGURATION, config);
+ resultData.putExtra(KEY_WIFI_CONFIGURATION, config);
}
- return result;
+ setResult(RESULT_CONNECTED, resultData);
+ finish();
}
@Override
@@ -344,44 +335,9 @@ public class WifiDialogActivity extends ObservableActivity implements WifiDialog
if (resultCode != RESULT_OK) {
return;
}
- if (hasPermissionForResult()) {
- setResult(RESULT_CONNECTED, data);
- } else {
- setResult(RESULT_CONNECTED);
- }
+
+ setResult(RESULT_CONNECTED, data);
finish();
}
}
-
- protected boolean hasPermissionForResult() {
- final String callingPackage = getCallingPackage();
- if (callingPackage == null) {
- Log.d(TAG, "Failed to get the calling package, don't return the result.");
- EventLog.writeEvent(0x534e4554, "185126813", -1 /* UID */, "no calling package");
- return false;
- }
-
- if (getPackageManager().checkPermission(ACCESS_COARSE_LOCATION, callingPackage)
- == PackageManager.PERMISSION_GRANTED) {
- Log.d(TAG, "The calling package has ACCESS_COARSE_LOCATION permission for result.");
- return true;
- }
-
- if (getPackageManager().checkPermission(ACCESS_FINE_LOCATION, callingPackage)
- == PackageManager.PERMISSION_GRANTED) {
- Log.d(TAG, "The calling package has ACCESS_FINE_LOCATION permission for result.");
- return true;
- }
-
- Log.d(TAG, "The calling package does not have the necessary permissions for result.");
- try {
- EventLog.writeEvent(0x534e4554, "185126813",
- getPackageManager().getPackageUid(callingPackage, 0 /* flags */),
- "no permission");
- } catch (PackageManager.NameNotFoundException e) {
- EventLog.writeEvent(0x534e4554, "185126813", -1 /* UID */, "no permission");
- Log.w(TAG, "Cannot find the UID, calling package: " + callingPackage, e);
- }
- return false;
- }
}
diff --git a/src/com/android/settings/wifi/WifiSettings.java b/src/com/android/settings/wifi/WifiSettings.java
index 59f65041c6e..c4b4d5928d1 100644
--- a/src/com/android/settings/wifi/WifiSettings.java
+++ b/src/com/android/settings/wifi/WifiSettings.java
@@ -67,7 +67,7 @@ import com.android.settings.location.WifiScanningFragment;
import com.android.settings.overlay.FeatureFactory;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settings.widget.MainSwitchBarController;
-import com.android.settings.wifi.details2.WifiNetworkDetailsFragment2;
+import com.android.settings.wifi.details.WifiNetworkDetailsFragment;
import com.android.settings.wifi.dpp.WifiDppUtils;
import com.android.settingslib.HelpUtils;
import com.android.settingslib.RestrictedLockUtils;
@@ -844,11 +844,11 @@ public class WifiSettings extends RestrictedSettingsFragment
: context.getText(R.string.pref_title_network_details);
final Bundle bundle = new Bundle();
- bundle.putString(WifiNetworkDetailsFragment2.KEY_CHOSEN_WIFIENTRY_KEY, wifiEntry.getKey());
+ bundle.putString(WifiNetworkDetailsFragment.KEY_CHOSEN_WIFIENTRY_KEY, wifiEntry.getKey());
new SubSettingLauncher(context)
.setTitleText(title)
- .setDestination(WifiNetworkDetailsFragment2.class.getName())
+ .setDestination(WifiNetworkDetailsFragment.class.getName())
.setArguments(bundle)
.setSourceMetricsCategory(getMetricsCategory())
.launch();
@@ -1121,7 +1121,7 @@ public class WifiSettings extends RestrictedSettingsFragment
private void launchConfigNewNetworkFragment(WifiEntry wifiEntry) {
final Bundle bundle = new Bundle();
- bundle.putString(WifiNetworkDetailsFragment2.KEY_CHOSEN_WIFIENTRY_KEY,
+ bundle.putString(WifiNetworkDetailsFragment.KEY_CHOSEN_WIFIENTRY_KEY,
wifiEntry.getKey());
new SubSettingLauncher(getContext())
.setTitleText(wifiEntry.getTitle())
diff --git a/src/com/android/settings/wifi/details2/WifiNetworkDetailsFragment2.java b/src/com/android/settings/wifi/details/WifiNetworkDetailsFragment.java
similarity index 93%
rename from src/com/android/settings/wifi/details2/WifiNetworkDetailsFragment2.java
rename to src/com/android/settings/wifi/details/WifiNetworkDetailsFragment.java
index 6bc510d6b16..dd0c20a4765 100644
--- a/src/com/android/settings/wifi/details2/WifiNetworkDetailsFragment2.java
+++ b/src/com/android/settings/wifi/details/WifiNetworkDetailsFragment.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2019 The Android Open Source Project
+ * Copyright (C) 2021 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.android.settings.wifi.details2;
+package com.android.settings.wifi.details;
import static com.android.settings.wifi.WifiSettings.WIFI_DIALOG_ID;
@@ -45,6 +45,13 @@ import com.android.settings.dashboard.RestrictedDashboardFragment;
import com.android.settings.overlay.FeatureFactory;
import com.android.settings.wifi.WifiConfigUiBase2;
import com.android.settings.wifi.WifiDialog2;
+import com.android.settings.wifi.details2.AddDevicePreferenceController2;
+import com.android.settings.wifi.details2.WifiAutoConnectPreferenceController2;
+import com.android.settings.wifi.details2.WifiDetailPreferenceController2;
+import com.android.settings.wifi.details2.WifiMeteredPreferenceController2;
+import com.android.settings.wifi.details2.WifiPrivacyPreferenceController2;
+import com.android.settings.wifi.details2.WifiSecondSummaryController2;
+import com.android.settings.wifi.details2.WifiSubscriptionDetailPreferenceController2;
import com.android.settingslib.RestrictedLockUtils;
import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
import com.android.settingslib.RestrictedLockUtilsInternal;
@@ -63,10 +70,10 @@ import java.util.List;
* The key of {@link WifiEntry} should be saved to the intent Extras when launching this class
* in order to properly render this page.
*/
-public class WifiNetworkDetailsFragment2 extends RestrictedDashboardFragment implements
+public class WifiNetworkDetailsFragment extends RestrictedDashboardFragment implements
WifiDialog2.WifiDialog2Listener {
- private static final String TAG = "WifiNetworkDetailsFrg2";
+ private static final String TAG = "WifiNetworkDetailsFrg";
// Key of a Bundle to save/restore the selected WifiEntry
public static final String KEY_CHOSEN_WIFIENTRY_KEY = "key_chosen_wifientry_key";
@@ -86,7 +93,7 @@ public class WifiNetworkDetailsFragment2 extends RestrictedDashboardFragment imp
@VisibleForTesting
List mControllers;
- public WifiNetworkDetailsFragment2() {
+ public WifiNetworkDetailsFragment() {
super(UserManager.DISALLOW_CONFIG_WIFI);
}
diff --git a/src/com/android/settings/wifi/details2/WifiDetailPreferenceController2.java b/src/com/android/settings/wifi/details2/WifiDetailPreferenceController2.java
index 7bf680da103..f9d0db07b25 100644
--- a/src/com/android/settings/wifi/details2/WifiDetailPreferenceController2.java
+++ b/src/com/android/settings/wifi/details2/WifiDetailPreferenceController2.java
@@ -76,6 +76,7 @@ import com.android.settings.widget.EntityHeaderController;
import com.android.settings.wifi.WifiDialog2;
import com.android.settings.wifi.WifiDialog2.WifiDialog2Listener;
import com.android.settings.wifi.WifiUtils;
+import com.android.settings.wifi.details.WifiNetworkDetailsFragment;
import com.android.settings.wifi.dpp.WifiDppUtils;
import com.android.settingslib.core.AbstractPreferenceController;
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
@@ -1099,7 +1100,7 @@ public class WifiDetailPreferenceController2 extends AbstractPreferenceControlle
refreshPage();
// Refresh the Preferences in fragment.
- ((WifiNetworkDetailsFragment2) mFragment).refreshPreferences();
+ ((WifiNetworkDetailsFragment) mFragment).refreshPreferences();
}
/**
diff --git a/src/com/android/settings/wifi/dpp/WifiDppBaseActivity.java b/src/com/android/settings/wifi/dpp/WifiDppBaseActivity.java
index 499f66cb3c8..f55960be5e0 100644
--- a/src/com/android/settings/wifi/dpp/WifiDppBaseActivity.java
+++ b/src/com/android/settings/wifi/dpp/WifiDppBaseActivity.java
@@ -26,7 +26,7 @@ import com.android.settings.R;
import com.android.settings.SetupWizardUtils;
import com.android.settings.core.InstrumentedActivity;
-abstract class WifiDppBaseActivity extends InstrumentedActivity {
+public abstract class WifiDppBaseActivity extends InstrumentedActivity {
protected FragmentManager mFragmentManager;
protected abstract void handleIntent(Intent intent);
diff --git a/src/com/android/settings/wifi/savedaccesspoints2/SavedAccessPointsWifiSettings2.java b/src/com/android/settings/wifi/savedaccesspoints2/SavedAccessPointsWifiSettings2.java
index e579ad73dbb..1443e3247cf 100644
--- a/src/com/android/settings/wifi/savedaccesspoints2/SavedAccessPointsWifiSettings2.java
+++ b/src/com/android/settings/wifi/savedaccesspoints2/SavedAccessPointsWifiSettings2.java
@@ -39,7 +39,7 @@ import com.android.settings.R;
import com.android.settings.core.SubSettingLauncher;
import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.wifi.WifiSettings;
-import com.android.settings.wifi.details2.WifiNetworkDetailsFragment2;
+import com.android.settings.wifi.details.WifiNetworkDetailsFragment;
import com.android.wifitrackerlib.SavedNetworkTracker;
import java.time.Clock;
@@ -126,7 +126,7 @@ public class SavedAccessPointsWifiSettings2 extends DashboardFragment
}
/**
- * Shows {@link WifiNetworkDetailsFragment2} for assigned key of {@link WifiEntry}.
+ * Shows {@link WifiNetworkDetailsFragment} for assigned key of {@link WifiEntry}.
*/
public void showWifiPage(@NonNull String key, CharSequence title) {
removeDialog(WifiSettings.WIFI_DIALOG_ID);
@@ -137,11 +137,11 @@ public class SavedAccessPointsWifiSettings2 extends DashboardFragment
}
final Bundle bundle = new Bundle();
- bundle.putString(WifiNetworkDetailsFragment2.KEY_CHOSEN_WIFIENTRY_KEY, key);
+ bundle.putString(WifiNetworkDetailsFragment.KEY_CHOSEN_WIFIENTRY_KEY, key);
new SubSettingLauncher(getContext())
.setTitleText(title)
- .setDestination(WifiNetworkDetailsFragment2.class.getName())
+ .setDestination(WifiNetworkDetailsFragment.class.getName())
.setArguments(bundle)
.setSourceMetricsCategory(getMetricsCategory())
.launch();
diff --git a/src/com/android/settings/wifi/slice/WifiSlice.java b/src/com/android/settings/wifi/slice/WifiSlice.java
index 75d2c669954..f6604dd6f6e 100644
--- a/src/com/android/settings/wifi/slice/WifiSlice.java
+++ b/src/com/android/settings/wifi/slice/WifiSlice.java
@@ -50,7 +50,7 @@ import com.android.settings.slices.SliceBuilderUtils;
import com.android.settings.wifi.WifiDialogActivity;
import com.android.settings.wifi.WifiSettings;
import com.android.settings.wifi.WifiUtils;
-import com.android.settings.wifi.details2.WifiNetworkDetailsFragment2;
+import com.android.settings.wifi.details.WifiNetworkDetailsFragment;
import com.android.wifitrackerlib.WifiEntry;
import java.util.Arrays;
@@ -200,11 +200,11 @@ public class WifiSlice implements CustomSliceable {
if (wifiSliceItem.getConnectedState() != WifiEntry.CONNECTED_STATE_DISCONNECTED) {
final Bundle bundle = new Bundle();
- bundle.putString(WifiNetworkDetailsFragment2.KEY_CHOSEN_WIFIENTRY_KEY,
+ bundle.putString(WifiNetworkDetailsFragment.KEY_CHOSEN_WIFIENTRY_KEY,
wifiSliceItem.getKey());
final Intent intent = new SubSettingLauncher(mContext)
.setTitleRes(R.string.pref_title_network_details)
- .setDestination(WifiNetworkDetailsFragment2.class.getName())
+ .setDestination(WifiNetworkDetailsFragment.class.getName())
.setArguments(bundle)
.setSourceMetricsCategory(SettingsEnums.WIFI)
.toIntent();
diff --git a/tests/robotests/src/com/android/settings/connecteddevice/usb/UsbDefaultFragmentTest.java b/tests/robotests/src/com/android/settings/connecteddevice/usb/UsbDefaultFragmentTest.java
index eee63980753..2317c97513b 100644
--- a/tests/robotests/src/com/android/settings/connecteddevice/usb/UsbDefaultFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/connecteddevice/usb/UsbDefaultFragmentTest.java
@@ -183,7 +183,7 @@ public class UsbDefaultFragmentTest {
@Test
public void onTetheringStarted_currentFunctionsIsRndis_setsRndisAsDefaultUsbFunctions() {
- mFragment.mCurrentFunctions = UsbManager.FUNCTION_RNDIS;
+ when(mUsbBackend.getCurrentFunctions()).thenReturn(UsbManager.FUNCTION_RNDIS);
mFragment.mOnStartTetheringCallback.onTetheringStarted();
@@ -192,7 +192,7 @@ public class UsbDefaultFragmentTest {
@Test
public void onTetheringStarted_currentFunctionsIsNcm_setsNcmAsDefaultUsbFunctions() {
- mFragment.mCurrentFunctions = UsbManager.FUNCTION_NCM;
+ when(mUsbBackend.getCurrentFunctions()).thenReturn(UsbManager.FUNCTION_NCM);
mFragment.mOnStartTetheringCallback.onTetheringStarted();
diff --git a/tests/robotests/src/com/android/settings/display/BrightnessLevelPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/display/BrightnessLevelPreferenceControllerTest.java
index 49489865049..c2de51050e8 100644
--- a/tests/robotests/src/com/android/settings/display/BrightnessLevelPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/display/BrightnessLevelPreferenceControllerTest.java
@@ -152,7 +152,8 @@ public class BrightnessLevelPreferenceControllerTest {
System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC);
when(mDisplay.getBrightnessInfo()).thenReturn(
- new BrightnessInfo(0.1f, 0.0f, 1.0f, BrightnessInfo.HIGH_BRIGHTNESS_MODE_OFF));
+ new BrightnessInfo(0.1f, 0.0f, 1.0f, BrightnessInfo.HIGH_BRIGHTNESS_MODE_OFF,
+ 0.5f));
mController.updateState(mPreference);
@@ -166,7 +167,8 @@ public class BrightnessLevelPreferenceControllerTest {
System.SCREEN_BRIGHTNESS_MODE_MANUAL);
when(mDisplay.getBrightnessInfo()).thenReturn(
- new BrightnessInfo(0.5f, 0.0f, 1.0f, BrightnessInfo.HIGH_BRIGHTNESS_MODE_OFF));
+ new BrightnessInfo(0.5f, 0.0f, 1.0f, BrightnessInfo.HIGH_BRIGHTNESS_MODE_OFF,
+ 0.5f));
mController.updateState(mPreference);
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/BatteryChartPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/fuelgauge/BatteryChartPreferenceControllerTest.java
index fd4e82d4b23..43fbe81a3a1 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/BatteryChartPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/BatteryChartPreferenceControllerTest.java
@@ -50,7 +50,6 @@ import com.android.settings.testutils.FakeFeatureFactory;
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
import org.junit.Before;
-import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
@@ -65,7 +64,6 @@ import java.util.HashMap;
import java.util.Locale;
import java.util.List;
import java.util.Map;
-import java.util.TimeZone;
@RunWith(RobolectricTestRunner.class)
public final class BatteryChartPreferenceControllerTest {
@@ -125,37 +123,6 @@ public final class BatteryChartPreferenceControllerTest {
createBatteryHistoryMap());
}
- @Ignore
- @Test
- public void testOnResume_uiModeIsChanged_clearBatteryDiffEntryCache() {
- doReturn(mResources).when(mContext).getResources();
- doReturn(mConfiguration).when(mResources).getConfiguration();
- mConfiguration.uiMode = Configuration.UI_MODE_NIGHT_UNDEFINED;
- // Ensures the testing environment is correct.
- assertThat(BatteryDiffEntry.sResourceCache).hasSize(1);
- mBatteryChartPreferenceController.onResume();
- // Changes the uiMode in the configuration.
- mConfiguration.uiMode = Configuration.UI_MODE_NIGHT_YES;
-
- mBatteryChartPreferenceController.onResume();
- assertThat(BatteryDiffEntry.sResourceCache).isEmpty();
- }
-
- @Ignore
- @Test
- public void testOnResume_uiModeIsNotChanged_notClearBatteryDiffEntryCache() {
- doReturn(mResources).when(mContext).getResources();
- doReturn(mConfiguration).when(mResources).getConfiguration();
- mConfiguration.uiMode = Configuration.UI_MODE_NIGHT_UNDEFINED;
- // Ensures the testing environment is correct.
- assertThat(BatteryDiffEntry.sResourceCache).hasSize(1);
-
- mBatteryChartPreferenceController.onResume();
- assertThat(BatteryDiffEntry.sResourceCache).isNotEmpty();
- verify(mMetricsFeatureProvider)
- .action(mContext, SettingsEnums.OPEN_BATTERY_USAGE);
- }
-
@Test
public void testOnDestroy_activityIsChanging_clearBatteryEntryCache() {
doReturn(true).when(mSettingsActivity).isChangingConfigurations();
@@ -579,12 +546,12 @@ public final class BatteryChartPreferenceControllerTest {
// Verifies the title in the preference group.
verify(mBatteryChartPreferenceController.mAppListPrefGroup)
.setTitle(captor.capture());
- assertThat(captor.getValue()).isEqualTo("App usage for 4 - 7");
+ assertThat(captor.getValue()).isNotEqualTo("App usage for past 24 hr");
// Verifies the title in the expandable divider.
captor = ArgumentCaptor.forClass(String.class);
verify(mBatteryChartPreferenceController.mExpandDividerPreference)
.setTitle(captor.capture());
- assertThat(captor.getValue()).isEqualTo("System usage for 4 - 7");
+ assertThat(captor.getValue()).isNotEqualTo("System usage for past 24 hr");
}
@Test
@@ -722,9 +689,6 @@ public final class BatteryChartPreferenceControllerTest {
new long[] {1619196786769L, 0L, 1619247636826L};
ConvertUtils.utcToLocalTimeHour(
mContext, /*timestamp=*/ 0, /*is24HourFormat=*/ false);
- // Simulates the locale in GMT.
- ConvertUtils.sSimpleDateFormatForHour
- .setTimeZone(TimeZone.getTimeZone("GMT"));
}
private BatteryChartPreferenceController createController() {
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/BatteryChartViewTest.java b/tests/robotests/src/com/android/settings/fuelgauge/BatteryChartViewTest.java
index d19a012812e..0b75e798423 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/BatteryChartViewTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/BatteryChartViewTest.java
@@ -33,7 +33,6 @@ import android.view.accessibility.AccessibilityManager;
import com.android.settings.testutils.FakeFeatureFactory;
import org.junit.Before;
-import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
@@ -44,7 +43,6 @@ import org.robolectric.RuntimeEnvironment;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.Locale;
-import java.util.TimeZone;
@RunWith(RobolectricTestRunner.class)
public final class BatteryChartViewTest {
@@ -233,21 +231,4 @@ public final class BatteryChartViewTest {
verify(mBatteryChartView.mHandler)
.postDelayed(mBatteryChartView.mUpdateClickableStateRun, 500L);
}
-
- @Ignore
- @Test
- public void testSetLatestTimestamp_generateExpectedTimestamps() {
- final long timestamp = 1619196786769L;
- ConvertUtils.sSimpleDateFormatForHour = null;
- // Invokes the method first to create the SimpleDateFormat.
- ConvertUtils.utcToLocalTimeHour(
- mContext, /*timestamp=*/ 0, /*is24HourFormat=*/ false);
- ConvertUtils.sSimpleDateFormatForHour
- .setTimeZone(TimeZone.getTimeZone("America/Los_Angeles"));
- final String[] expectedTimestamps = new String[] {"00", "06", "12", "18", "00"};
-
- mBatteryChartView.setLatestTimestamp(timestamp);
-
- assertThat(mBatteryChartView.mTimestamps).isEqualTo(expectedTimestamps);
- }
}
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/ConvertUtilsTest.java b/tests/robotests/src/com/android/settings/fuelgauge/ConvertUtilsTest.java
index 1b9e05b63b6..b04f053624a 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/ConvertUtilsTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/ConvertUtilsTest.java
@@ -30,7 +30,6 @@ import android.os.UserHandle;
import com.android.settings.testutils.FakeFeatureFactory;
import org.junit.Before;
-import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
@@ -320,71 +319,6 @@ public final class ConvertUtilsTest {
.isEqualTo(entry.mConsumePower * ratio);
}
- @Ignore
- @Test
- public void testUtcToLocalTime_returnExpectedResult() {
- ConvertUtils.sZoneId = null;
- ConvertUtils.sLocale = null;
- final long timestamp = 1619196786769L;
- final String expectedZoneId = "America/Los_Angeles";
- ConvertUtils.sSimpleDateFormat = null;
- // Invokes the method first to create the SimpleDateFormat.
- ConvertUtils.utcToLocalTime(mContext, /*timestamp=*/ 0);
- ConvertUtils.sSimpleDateFormat
- .setTimeZone(TimeZone.getTimeZone(expectedZoneId));
- mContext.getResources().getConfiguration().setLocales(
- new LocaleList(new Locale("en_US")));
-
- assertThat(ConvertUtils.utcToLocalTime(mContext, timestamp))
- .isEqualTo("Apr 24,2021 00:53:06");
- assertThat(ConvertUtils.sZoneId).isNotEqualTo(expectedZoneId);
- assertThat(ConvertUtils.sLocale).isEqualTo(new Locale("en_US"));
- }
-
- @Ignore
- @Test
- public void testUtcToLocalTimeHour_12HourFormat_returnExpectedResult() {
- ConvertUtils.sZoneIdForHour = null;
- ConvertUtils.sLocaleForHour = null;
- final long timestamp = 1619000086769L;
- final String expectedZoneId = "America/Los_Angeles";
- ConvertUtils.sSimpleDateFormatForHour = null;
- // Invokes the method first to create the SimpleDateFormat.
- ConvertUtils.utcToLocalTimeHour(
- mContext, /*timestamp=*/ 0, /*is24HourFormat=*/ false);
- ConvertUtils.sSimpleDateFormatForHour
- .setTimeZone(TimeZone.getTimeZone(expectedZoneId));
- mContext.getResources().getConfiguration().setLocales(
- new LocaleList(new Locale("en_US")));
-
- assertThat(ConvertUtils.utcToLocalTimeHour(
- mContext, timestamp, /*is24HourFormat=*/ false)).isEqualTo("6");
- assertThat(ConvertUtils.sZoneIdForHour).isNotEqualTo(expectedZoneId);
- assertThat(ConvertUtils.sLocaleForHour).isEqualTo(new Locale("en_US"));
- }
-
- @Ignore
- @Test
- public void testUtcToLocalTimeHour_24HourFormat_returnExpectedResult() {
- ConvertUtils.sZoneIdForHour = null;
- ConvertUtils.sLocaleForHour = null;
- final long timestamp = 1619000086769L;
- final String expectedZoneId = "America/Los_Angeles";
- ConvertUtils.sSimpleDateFormatForHour = null;
- // Invokes the method first to create the SimpleDateFormat.
- ConvertUtils.utcToLocalTimeHour(
- mContext, /*timestamp=*/ 0, /*is24HourFormat=*/ false);
- ConvertUtils.sSimpleDateFormatForHour
- .setTimeZone(TimeZone.getTimeZone(expectedZoneId));
- mContext.getResources().getConfiguration().setLocales(
- new LocaleList(new Locale("en_US")));
-
- assertThat(ConvertUtils.utcToLocalTimeHour(
- mContext, timestamp, /*is24HourFormat=*/ true)).isEqualTo("18");
- assertThat(ConvertUtils.sZoneIdForHour).isNotEqualTo(expectedZoneId);
- assertThat(ConvertUtils.sLocaleForHour).isEqualTo(new Locale("en_US"));
- }
-
@Test
public void testGetIndexedUsageMap_hideBackgroundUsageTime_returnsExpectedResult() {
final long[] batteryHistoryKeys = new long[] {101L, 102L, 103L};
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageFeatureProviderImplTest.java b/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageFeatureProviderImplTest.java
index e8a9c5cb05a..c0b566a5f4b 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageFeatureProviderImplTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageFeatureProviderImplTest.java
@@ -155,4 +155,9 @@ public class PowerUsageFeatureProviderImplTest {
assertThat(mPowerFeatureProvider.isSmartBatterySupported()).isFalse();
}
+
+ @Test
+ public void testGetResumeChargeIntent_returnNull() {
+ assertThat(mPowerFeatureProvider.getResumeChargeIntent()).isNull();
+ }
}
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/batterytip/BatteryTipDialogFragmentTest.java b/tests/robotests/src/com/android/settings/fuelgauge/batterytip/BatteryTipDialogFragmentTest.java
index 331fb343d43..99fbaf3c812 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/batterytip/BatteryTipDialogFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/batterytip/BatteryTipDialogFragmentTest.java
@@ -31,6 +31,7 @@ import androidx.appcompat.app.AlertDialog;
import androidx.fragment.app.FragmentActivity;
import com.android.settings.R;
+import com.android.settings.fuelgauge.batterytip.tips.BatteryDefenderTip;
import com.android.settings.fuelgauge.batterytip.tips.BatteryTip;
import com.android.settings.fuelgauge.batterytip.tips.HighUsageTip;
import com.android.settings.fuelgauge.batterytip.tips.RestrictAppTip;
@@ -74,6 +75,7 @@ public class BatteryTipDialogFragmentTest {
private RestrictAppTip mRestrictTwoAppsTip;
private UnrestrictAppTip mUnrestrictAppTip;
private SummaryTip mSummaryTip;
+ private BatteryDefenderTip mDefenderTip;
private AppInfo mAppInfo;
private ShadowPackageManager mPackageManager;
@@ -116,6 +118,7 @@ public class BatteryTipDialogFragmentTest {
mUnrestrictAppTip = new UnrestrictAppTip(BatteryTip.StateType.NEW, mAppInfo);
mSummaryTip = spy(new SummaryTip(BatteryTip.StateType.NEW,
EstimateKt.AVERAGE_TIME_TO_DISCHARGE_UNKNOWN));
+ mDefenderTip = new BatteryDefenderTip(BatteryTip.StateType.NEW);
}
@After
@@ -243,4 +246,20 @@ public class BatteryTipDialogFragmentTest {
+ "your phone will suggest actions you can take.\n\nYou can always turn"
+ " on Battery Saver if you’re running low on battery.");
}
+
+ @Test
+ public void testOnCreateDialog_defenderTip_fireDialog() {
+ mDialogFragment = BatteryTipDialogFragment.newInstance(mDefenderTip, METRICS_KEY);
+
+ FragmentController.setupFragment(mDialogFragment, FragmentActivity.class,
+ 0 /* containerViewId */, null /* bundle */);
+
+ final AlertDialog dialog = ShadowAlertDialogCompat.getLatestAlertDialog();
+ ShadowAlertDialogCompat shadowDialog = ShadowAlertDialogCompat.shadowOf(dialog);
+
+ assertThat(shadowDialog.getTitle()).isEqualTo(
+ mContext.getString(R.string.battery_tip_limited_temporarily_title));
+ assertThat(shadowDialog.getMessage()).isEqualTo(
+ mContext.getString(R.string.battery_tip_limited_temporarily_dialog_msg, "80%"));
+ }
}
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/batterytip/actions/BatteryDefenderActionTest.java b/tests/robotests/src/com/android/settings/fuelgauge/batterytip/actions/BatteryDefenderActionTest.java
deleted file mode 100644
index ad5dc54ca9b..00000000000
--- a/tests/robotests/src/com/android/settings/fuelgauge/batterytip/actions/BatteryDefenderActionTest.java
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * Copyright (C) 2021 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.android.settings.fuelgauge.batterytip.actions;
-
-
-import static com.google.common.truth.Truth.assertThat;
-
-import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.spy;
-import static org.mockito.Mockito.verify;
-
-import android.app.settings.SettingsEnums;
-import android.content.Context;
-
-import com.android.settings.R;
-import com.android.settings.SettingsActivity;
-import com.android.settings.testutils.FakeFeatureFactory;
-import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
-import org.robolectric.RobolectricTestRunner;
-import org.robolectric.RuntimeEnvironment;
-
-@RunWith(RobolectricTestRunner.class)
-public final class BatteryDefenderActionTest {
-
- private Context mContext;
- private FakeFeatureFactory mFeatureFactory;
- private BatteryDefenderAction mBatteryDefenderAction;
- private MetricsFeatureProvider mMetricsFeatureProvider;
-
- @Mock private SettingsActivity mSettingsActivity;
-
- @Before
- public void setUp() {
- MockitoAnnotations.initMocks(this);
-
- mFeatureFactory = FakeFeatureFactory.setupForTest();
- mMetricsFeatureProvider = mFeatureFactory.metricsFeatureProvider;
- mContext = spy(RuntimeEnvironment.application);
- doReturn(mContext).when(mSettingsActivity).getApplicationContext();
- mBatteryDefenderAction = new BatteryDefenderAction(mSettingsActivity);
- }
-
- @Test
- public void testHandlePositiveAction_logMetric() {
- final int metricKey = 10;
- mBatteryDefenderAction.handlePositiveAction(metricKey);
-
- verify(mMetricsFeatureProvider).action(mContext,
- SettingsEnums.ACTION_TIP_BATTERY_DEFENDER, metricKey);
- }
-}
diff --git a/tests/robotests/src/com/android/settings/gestures/LabeledSeekBarPreferenceTest.java b/tests/robotests/src/com/android/settings/gestures/LabeledSeekBarPreferenceTest.java
index 4fb94f8cad5..3d83d58141b 100644
--- a/tests/robotests/src/com/android/settings/gestures/LabeledSeekBarPreferenceTest.java
+++ b/tests/robotests/src/com/android/settings/gestures/LabeledSeekBarPreferenceTest.java
@@ -16,6 +16,8 @@
package com.android.settings.gestures;
+import static com.google.common.truth.Truth.assertThat;
+
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
@@ -24,9 +26,12 @@ import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.SeekBar;
+import android.widget.TextView;
import androidx.preference.Preference;
+import androidx.preference.PreferenceViewHolder;
+import com.android.internal.R;
import com.android.settings.widget.LabeledSeekBarPreference;
import org.junit.Before;
@@ -41,7 +46,9 @@ import org.robolectric.RuntimeEnvironment;
public class LabeledSeekBarPreferenceTest {
private Context mContext;
+ private PreferenceViewHolder mViewHolder;
private SeekBar mSeekBar;
+ private TextView mSummary;
private LabeledSeekBarPreference mSeekBarPreference;
@Mock
@@ -57,7 +64,9 @@ public class LabeledSeekBarPreferenceTest {
final View view =
inflater.inflate(mSeekBarPreference.getLayoutResource(),
new LinearLayout(mContext), false);
- mSeekBar = view.findViewById(com.android.internal.R.id.seekbar);
+ mViewHolder = PreferenceViewHolder.createInstanceForTests(view);
+ mSeekBar = (SeekBar) mViewHolder.findViewById(R.id.seekbar);
+ mSummary = (TextView) mViewHolder.findViewById(R.id.summary);
}
@Test
@@ -69,4 +78,23 @@ public class LabeledSeekBarPreferenceTest {
verify(mListener, times(1)).onPreferenceChange(mSeekBarPreference, 2);
}
+
+ @Test
+ public void seekBarPreferenceSummarySet_returnsValue() {
+ final String summary = "this is a summary";
+ mSeekBarPreference.setSummary(summary);
+ mSeekBarPreference.onBindViewHolder(mViewHolder);
+
+ assertThat(mSeekBarPreference.getSummary()).isEqualTo(summary);
+ assertThat(mSummary.getText()).isEqualTo(summary);
+ }
+
+ @Test
+ public void seekBarPreferenceSummaryNull_hidesView() {
+ mSeekBarPreference.setSummary(null);
+ mSeekBarPreference.onBindViewHolder(mViewHolder);
+
+ assertThat(mSummary.getText()).isEqualTo("");
+ assertThat(mSummary.getVisibility()).isEqualTo(View.GONE);
+ }
}
diff --git a/tests/robotests/src/com/android/settings/gestures/LongPressPowerButtonPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/gestures/LongPressPowerButtonPreferenceControllerTest.java
index 053fa5a12d7..fa97754491c 100644
--- a/tests/robotests/src/com/android/settings/gestures/LongPressPowerButtonPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/gestures/LongPressPowerButtonPreferenceControllerTest.java
@@ -137,7 +137,7 @@ public class LongPressPowerButtonPreferenceControllerTest {
when(mResources.getInteger(
com.android.internal.R.integer.config_keyChordPowerVolumeUp))
.thenReturn(
- LongPressPowerButtonPreferenceController.KEY_CHORD_POWER_VOLUME_UP_NO_ACTION);
+ LongPressPowerButtonPreferenceController.KEY_CHORD_POWER_VOLUME_UP_NO_ACTION);
verify(mController.mFooterHint).setVisible(false);
}
@@ -148,7 +148,7 @@ public class LongPressPowerButtonPreferenceControllerTest {
assertThat(Settings.Global.getInt(mContext.getContentResolver(),
Settings.Global.POWER_BUTTON_LONG_PRESS, -1)).isEqualTo(
- LongPressPowerButtonPreferenceController.LONG_PRESS_POWER_ASSISTANT_VALUE);
+ PowerMenuSettingsUtils.LONG_PRESS_POWER_ASSISTANT_VALUE);
assertThat(Settings.Global.getInt(mContext.getContentResolver(),
Settings.Global.KEY_CHORD_POWER_VOLUME_UP, -1)).isEqualTo(
LongPressPowerButtonPreferenceController.KEY_CHORD_POWER_VOLUME_UP_GLOBAL_ACTIONS);
@@ -162,19 +162,19 @@ public class LongPressPowerButtonPreferenceControllerTest {
when(mResources.getInteger(
com.android.internal.R.integer.config_longPressOnPowerBehavior))
.thenReturn(
- LongPressPowerButtonPreferenceController.LONG_PRESS_POWER_GLOBAL_ACTIONS);
+ PowerMenuSettingsUtils.LONG_PRESS_POWER_GLOBAL_ACTIONS);
mController.onPreferenceChange(null, false);
assertThat(Settings.Global.getInt(mContext.getContentResolver(),
Settings.Global.POWER_BUTTON_LONG_PRESS, -1)).isEqualTo(
- LongPressPowerButtonPreferenceController.LONG_PRESS_POWER_GLOBAL_ACTIONS);
+ PowerMenuSettingsUtils.LONG_PRESS_POWER_GLOBAL_ACTIONS);
assertThat(Settings.Global.getInt(mContext.getContentResolver(),
Settings.Global.KEY_CHORD_POWER_VOLUME_UP, -1)).isEqualTo(
LongPressPowerButtonPreferenceController.KEY_CHORD_POWER_VOLUME_UP_NO_ACTION);
verify(mController.mAssistSwitch).setSummary(
getString(
- R.string.power_menu_summary_long_press_for_assist_disabled_with_power_menu));
+ R.string.power_menu_summary_long_press_for_assist_disabled_with_power_menu));
}
@Test
@@ -199,23 +199,22 @@ public class LongPressPowerButtonPreferenceControllerTest {
@Test
public void preferenceUnchecked_assistDefault_setNoAction() {
- // Value out of range chosen deliberately.
+ // Ensure that the Assistant is the default behavior for LPP.
when(mResources.getInteger(
com.android.internal.R.integer.config_longPressOnPowerBehavior))
.thenReturn(
- LongPressPowerButtonPreferenceController.LONG_PRESS_POWER_ASSISTANT_VALUE);
+ PowerMenuSettingsUtils.LONG_PRESS_POWER_ASSISTANT_VALUE);
mController.onPreferenceChange(null, false);
assertThat(Settings.Global.getInt(mContext.getContentResolver(),
Settings.Global.POWER_BUTTON_LONG_PRESS, -1)).isEqualTo(
- LongPressPowerButtonPreferenceController.LONG_PRESS_POWER_NO_ACTION);
+ PowerMenuSettingsUtils.LONG_PRESS_POWER_GLOBAL_ACTIONS);
assertThat(Settings.Global.getInt(mContext.getContentResolver(),
Settings.Global.KEY_CHORD_POWER_VOLUME_UP, -1)).isEqualTo(
LongPressPowerButtonPreferenceController.KEY_CHORD_POWER_VOLUME_UP_NO_ACTION);
- verify(mController.mAssistSwitch).setSummary(
- getString(
- R.string.power_menu_summary_long_press_for_assist_disabled_no_action));
+ verify(mController.mAssistSwitch).setSummary(getString(
+ R.string.power_menu_summary_long_press_for_assist_disabled_with_power_menu));
}
private String getString(@StringRes int id) {
diff --git a/tests/robotests/src/com/android/settings/gestures/LongPressPowerSensitivityPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/gestures/LongPressPowerSensitivityPreferenceControllerTest.java
new file mode 100644
index 00000000000..9c99092849d
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/gestures/LongPressPowerSensitivityPreferenceControllerTest.java
@@ -0,0 +1,143 @@
+/*
+ * Copyright (C) 2021 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.gestures;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.when;
+
+import android.app.Application;
+import android.content.res.Resources;
+import android.provider.Settings;
+
+import androidx.test.core.app.ApplicationProvider;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.robolectric.RobolectricTestRunner;
+
+@RunWith(RobolectricTestRunner.class)
+public class LongPressPowerSensitivityPreferenceControllerTest {
+
+ private static final String KEY_LONG_PRESS_SENSITIVITY =
+ "gesture_power_menu_long_press_for_assist_sensitivity";
+
+ private static final int[] SENSITIVITY_VALUES = {250, 350, 500, 750, 850};
+
+ private Application mContext;
+ private Resources mResources;
+ private LongPressPowerSensitivityPreferenceController mController;
+
+ @Before
+ public void setUp() {
+ mContext = spy(ApplicationProvider.getApplicationContext());
+ mResources = mock(Resources.class);
+ when(mContext.getResources()).thenReturn(mResources);
+
+ when(mResources.getIntArray(
+ com.android.internal.R.array.config_longPressOnPowerDurationSettings))
+ .thenReturn(SENSITIVITY_VALUES);
+
+ mController = new LongPressPowerSensitivityPreferenceController(mContext,
+ KEY_LONG_PRESS_SENSITIVITY);
+ }
+
+ @Test
+ public void getSliderPosition_returnsDefaultValue() {
+ when(mResources.getInteger(
+ com.android.internal.R.integer.config_longPressOnPowerDurationMs))
+ .thenReturn(750);
+ assertThat(mController.getSliderPosition()).isEqualTo(3);
+ }
+
+ @Test
+ public void getSliderPosition_returnsSetValue() {
+ Settings.Global.putInt(mContext.getContentResolver(),
+ Settings.Global.POWER_BUTTON_LONG_PRESS_DURATION_MS, 350);
+ assertThat(mController.getSliderPosition()).isEqualTo(1);
+ }
+
+ @Test
+ public void setSliderPosition_setsValue() {
+ mController.setSliderPosition(4);
+ assertThat(Settings.Global.getInt(mContext.getContentResolver(),
+ Settings.Global.POWER_BUTTON_LONG_PRESS_DURATION_MS, 0)).isEqualTo(850);
+ }
+
+ @Test
+ public void setSliderPositionOutOfBounds_returnsFalse() {
+ assertThat(mController.setSliderPosition(-1)).isFalse();
+ assertThat(mController.setSliderPosition(10)).isFalse();
+ }
+
+ @Test
+ public void getMin_isZero() {
+ assertThat(mController.getMin()).isEqualTo(0);
+ }
+
+ @Test
+ public void getMax_isEqualToLastValueIndex() {
+ assertThat(mController.getMax()).isEqualTo(4);
+ }
+
+ @Test
+ public void longPressForAssistEnabled_isAvailable() {
+ Settings.Global.putInt(mContext.getContentResolver(),
+ Settings.Global.POWER_BUTTON_LONG_PRESS,
+ PowerMenuSettingsUtils.LONG_PRESS_POWER_ASSISTANT_VALUE);
+
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(
+ LongPressPowerSensitivityPreferenceController.AVAILABLE);
+ }
+
+ @Test
+ public void longPressForAssistDisabled_isNotAvailableDueToDependentSetting() {
+ Settings.Global.putInt(mContext.getContentResolver(),
+ Settings.Global.POWER_BUTTON_LONG_PRESS,
+ PowerMenuSettingsUtils.LONG_PRESS_POWER_NO_ACTION);
+
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(
+ LongPressPowerSensitivityPreferenceController.DISABLED_DEPENDENT_SETTING);
+ }
+
+ @Test
+ public void sensitivityValuesAreNull_notAvailable() {
+ when(mResources.getIntArray(
+ com.android.internal.R.array.config_longPressOnPowerDurationSettings))
+ .thenReturn(null);
+ mController = new LongPressPowerSensitivityPreferenceController(mContext,
+ KEY_LONG_PRESS_SENSITIVITY);
+
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(
+ LongPressPowerSensitivityPreferenceController.UNSUPPORTED_ON_DEVICE);
+ }
+
+ @Test
+ public void sensitivityValuesArrayTooShort_notAvailable() {
+ when(mResources.getIntArray(
+ com.android.internal.R.array.config_longPressOnPowerDurationSettings))
+ .thenReturn(new int[]{200});
+ mController = new LongPressPowerSensitivityPreferenceController(mContext,
+ KEY_LONG_PRESS_SENSITIVITY);
+
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(
+ LongPressPowerSensitivityPreferenceController.UNSUPPORTED_ON_DEVICE);
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/gestures/PowerMenuSettingsUtilsTest.java b/tests/robotests/src/com/android/settings/gestures/PowerMenuSettingsUtilsTest.java
new file mode 100644
index 00000000000..25f03207284
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/gestures/PowerMenuSettingsUtilsTest.java
@@ -0,0 +1,91 @@
+/*
+ * Copyright (C) 2021 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.gestures;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.when;
+
+import android.content.Context;
+import android.content.res.Resources;
+import android.provider.Settings;
+
+import androidx.test.core.app.ApplicationProvider;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.robolectric.RobolectricTestRunner;
+
+@RunWith(RobolectricTestRunner.class)
+public class PowerMenuSettingsUtilsTest {
+
+ private Context mContext;
+ private Resources mResources;
+
+ @Before
+ public void setUp() {
+ mContext = spy(ApplicationProvider.getApplicationContext());
+ mResources = mock(Resources.class);
+ when(mContext.getResources()).thenReturn(mResources);
+ }
+
+ @Test
+ public void longPressBehaviourValuePresent_returnsValue() {
+ when(mResources.getInteger(
+ com.android.internal.R.integer.config_longPressOnPowerBehavior))
+ .thenReturn(0);
+ Settings.Global.putInt(mContext.getContentResolver(),
+ Settings.Global.POWER_BUTTON_LONG_PRESS, 1);
+
+ assertThat(PowerMenuSettingsUtils.getPowerButtonSettingValue(mContext)).isEqualTo(1);
+ }
+
+ @Test
+ public void longPressBehaviourValueNotPresent_returnsDefault() {
+ when(mResources.getInteger(
+ com.android.internal.R.integer.config_longPressOnPowerBehavior))
+ .thenReturn(2);
+
+ assertThat(PowerMenuSettingsUtils.getPowerButtonSettingValue(mContext)).isEqualTo(2);
+ }
+
+ @Test
+ public void longPressBehaviourValueSetToAssistant_isAssistEnabledReturnsTrue() {
+ Settings.Global.putInt(mContext.getContentResolver(),
+ Settings.Global.POWER_BUTTON_LONG_PRESS, 5);
+ assertThat(PowerMenuSettingsUtils.isLongPressPowerForAssistEnabled(mContext)).isTrue();
+ }
+
+ @Test
+ public void longPressBehaviourValueNotSetToAssistant_isAssistEnabledReturnsFalse() {
+ Settings.Global.putInt(mContext.getContentResolver(),
+ Settings.Global.POWER_BUTTON_LONG_PRESS, 3);
+ assertThat(PowerMenuSettingsUtils.isLongPressPowerForAssistEnabled(mContext)).isFalse();
+ }
+
+ @Test
+ public void longPressBehaviourDefaultSetToAssistant_isAssistEnabledReturnsFalse() {
+ when(mResources.getInteger(
+ com.android.internal.R.integer.config_longPressOnPowerBehavior))
+ .thenReturn(3);
+
+ assertThat(PowerMenuSettingsUtils.isLongPressPowerForAssistEnabled(mContext)).isFalse();
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/network/telephony/RenameMobileNetworkDialogFragmentTest.java b/tests/robotests/src/com/android/settings/network/telephony/RenameMobileNetworkDialogFragmentTest.java
index d0df92ec8a7..70b05981370 100644
--- a/tests/robotests/src/com/android/settings/network/telephony/RenameMobileNetworkDialogFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/network/telephony/RenameMobileNetworkDialogFragmentTest.java
@@ -159,7 +159,7 @@ public class RenameMobileNetworkDialogFragmentTest {
eq(SubscriptionManager.NAME_SOURCE_USER_INPUT));
assertThat(captor.getValue()).isEqualTo("test2");
verify(mSubscriptionMgr)
- .setIconTint(eq(Color.parseColor("#ff00796b" /* teal */)), eq(mSubscriptionId));
+ .setIconTint(eq(Color.parseColor("#ff006D74" /* cyan */)), eq(mSubscriptionId));
}
@Test
@@ -174,6 +174,34 @@ public class RenameMobileNetworkDialogFragmentTest {
assertThat(view.findViewById(R.id.number_label).getVisibility()).isEqualTo(View.GONE);
}
+ @Test
+ public void populateView_getPreviousSimColor_setCorrectSelection() {
+ final View view = LayoutInflater.from(mActivity).inflate(
+ R.layout.dialog_mobile_network_rename, null);
+ when(mSubscriptionInfo.getIconTint())
+ .thenReturn(Color.parseColor("#ff3367d6"/* blue700 */));
+
+ startDialog();
+ mFragment.populateView(view);
+
+ final Spinner colorSpinnerView = mFragment.getColorSpinnerView();
+ assertThat(colorSpinnerView.getSelectedItemPosition()).isEqualTo(1);
+ }
+
+ @Test
+ public void populateView_getUpdatedSimColor_setCorrectSelection() {
+ final View view = LayoutInflater.from(mActivity).inflate(
+ R.layout.dialog_mobile_network_rename, null);
+ when(mSubscriptionInfo.getIconTint())
+ .thenReturn(Color.parseColor("#ff137333"/* Green800 */));
+
+ startDialog();
+ mFragment.populateView(view);
+
+ final Spinner colorSpinnerView = mFragment.getColorSpinnerView();
+ assertThat(colorSpinnerView.getSelectedItemPosition()).isEqualTo(2);
+ }
+
/**
* Helper method to start the dialog
*/
diff --git a/tests/robotests/src/com/android/settings/notification/app/RecentConversationsPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/app/RecentConversationsPreferenceControllerTest.java
index f0ae7ab376d..1688d63ec52 100644
--- a/tests/robotests/src/com/android/settings/notification/app/RecentConversationsPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/notification/app/RecentConversationsPreferenceControllerTest.java
@@ -36,6 +36,7 @@ import android.content.pm.ShortcutInfo;
import android.os.Bundle;
import android.os.UserHandle;
import android.provider.Settings;
+import android.text.SpannedString;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
@@ -338,4 +339,36 @@ public class RecentConversationsPreferenceControllerTest {
// one for the preference, none for 'clear all'
verify(outerContainer, times(1)).addPreference(any());
}
+
+ @Test
+ public void testSpans() {
+ ShortcutInfo si = mock(ShortcutInfo.class);
+ when(si.getLabel()).thenReturn(new SpannedString("hello"));
+ ConversationChannel ccw = new ConversationChannel(si, 6,
+ new NotificationChannel("hi", "hi", 4),
+ null, 7,
+ true /* hasactivenotifs */);
+ ShortcutInfo si2 = mock(ShortcutInfo.class);
+ when(si2.getLabel()).thenReturn("hello");
+ ConversationChannel ccw2 = new ConversationChannel(si2, 6,
+ new NotificationChannel("hi2", "hi2", 4),
+ null, 7,
+ true /* hasactivenotifs */);
+ // no crash
+ mController.mConversationComparator.compare(ccw, ccw2);
+ }
+
+ @Test
+ public void testNullSpans() {
+ ConversationChannel ccw = new ConversationChannel(mock(ShortcutInfo.class), 6,
+ new NotificationChannel("hi", "hi", 4),
+ null, 7,
+ true /* hasactivenotifs */);
+ ConversationChannel ccw2 = new ConversationChannel(mock(ShortcutInfo.class), 6,
+ new NotificationChannel("hi2", "hi2", 4),
+ null, 7,
+ true /* hasactivenotifs */);
+ // no crash
+ mController.mConversationComparator.compare(ccw, ccw2);
+ }
}
diff --git a/tests/robotests/src/com/android/settings/password/ChooseLockGenericControllerTest.java b/tests/robotests/src/com/android/settings/password/ChooseLockGenericControllerTest.java
index 049a34969c1..996d5722693 100644
--- a/tests/robotests/src/com/android/settings/password/ChooseLockGenericControllerTest.java
+++ b/tests/robotests/src/com/android/settings/password/ChooseLockGenericControllerTest.java
@@ -22,6 +22,7 @@ import static android.app.admin.DevicePolicyManager.PASSWORD_COMPLEXITY_MEDIUM;
import static android.app.admin.DevicePolicyManager.PASSWORD_COMPLEXITY_NONE;
import static android.app.admin.DevicePolicyManager.PASSWORD_QUALITY_ALPHABETIC;
import static android.app.admin.DevicePolicyManager.PASSWORD_QUALITY_COMPLEX;
+import static android.app.admin.DevicePolicyManager.PASSWORD_QUALITY_MANAGED;
import static android.app.admin.DevicePolicyManager.PASSWORD_QUALITY_NUMERIC;
import static android.app.admin.DevicePolicyManager.PASSWORD_QUALITY_NUMERIC_COMPLEX;
import static android.app.admin.DevicePolicyManager.PASSWORD_QUALITY_SOMETHING;
@@ -189,6 +190,16 @@ public class ChooseLockGenericControllerTest {
assertThat(mController.isScreenLockEnabled(ScreenLockType.PASSWORD)).isTrue();
}
+ @Test
+ public void isScreenLockEnabled_QualityManaged() {
+ setDevicePolicyPasswordQuality(PASSWORD_QUALITY_MANAGED);
+ assertThat(mController.isScreenLockEnabled(ScreenLockType.NONE)).isFalse();
+ assertThat(mController.isScreenLockEnabled(ScreenLockType.SWIPE)).isFalse();
+ assertThat(mController.isScreenLockEnabled(ScreenLockType.PATTERN)).isFalse();
+ assertThat(mController.isScreenLockEnabled(ScreenLockType.PIN)).isFalse();
+ assertThat(mController.isScreenLockEnabled(ScreenLockType.PASSWORD)).isFalse();
+ }
+
@Test
public void isScreenLockEnabled_NoneComplexity() {
when(mLockPatternUtils.getRequestedPasswordComplexity(anyInt(), anyBoolean()))
@@ -353,6 +364,9 @@ public class ChooseLockGenericControllerTest {
when(mLockPatternUtils.getRequestedPasswordMetrics(anyInt(), anyBoolean()))
.thenReturn(policy.getMinMetrics());
+
+ when(mLockPatternUtils.isCredentialsDisabledForUser(anyInt()))
+ .thenReturn(quality == PASSWORD_QUALITY_MANAGED);
}
private ChooseLockGenericController.Builder createBuilder() {
diff --git a/tests/robotests/src/com/android/settings/password/ChooseLockPasswordTest.java b/tests/robotests/src/com/android/settings/password/ChooseLockPasswordTest.java
index 7da9c505b8e..e789b61f188 100644
--- a/tests/robotests/src/com/android/settings/password/ChooseLockPasswordTest.java
+++ b/tests/robotests/src/com/android/settings/password/ChooseLockPasswordTest.java
@@ -404,18 +404,6 @@ public class ChooseLockPasswordTest {
"Must be fewer than 17 characters");
}
- @Test
- public void assertThat_chooseLockIconChanged_WhenFingerprintExtraSet() {
- ShadowDrawable drawable = setActivityAndGetIconDrawable(true);
- assertThat(drawable.getCreatedFromResId()).isEqualTo(R.drawable.ic_fingerprint_header);
- }
-
- @Test
- public void assertThat_chooseLockIconNotChanged_WhenFingerprintExtraSet() {
- ShadowDrawable drawable = setActivityAndGetIconDrawable(false);
- assertThat(drawable.getCreatedFromResId()).isNotEqualTo(R.drawable.ic_fingerprint_header);
- }
-
@Test
public void validateComplexityMergedFromDpmOnCreate() {
ShadowLockPatternUtils.setRequiredPasswordComplexity(PASSWORD_COMPLEXITY_LOW);
diff --git a/tests/robotests/src/com/android/settings/password/ChooseLockPatternTest.java b/tests/robotests/src/com/android/settings/password/ChooseLockPatternTest.java
index 1cb946b786f..f5cc39435ad 100644
--- a/tests/robotests/src/com/android/settings/password/ChooseLockPatternTest.java
+++ b/tests/robotests/src/com/android/settings/password/ChooseLockPatternTest.java
@@ -31,9 +31,6 @@ import com.android.settings.R;
import com.android.settings.password.ChooseLockPattern.ChooseLockPatternFragment;
import com.android.settings.password.ChooseLockPattern.IntentBuilder;
import com.android.settings.testutils.shadow.ShadowUtils;
-import com.android.settingslib.testutils.DrawableTestHelper;
-
-import com.google.android.setupdesign.GlifLayout;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -99,16 +96,6 @@ public class ChooseLockPatternTest {
.isNotNull();
}
- @Config(qualifiers = "sw400dp")
- @Test
- public void fingerprintExtraSet_shouldDisplayFingerprintIcon() {
- ChooseLockPattern activity = createActivity(true);
- ChooseLockPatternFragment fragment = (ChooseLockPatternFragment)
- activity.getSupportFragmentManager().findFragmentById(R.id.main_content);
- DrawableTestHelper.assertDrawableResId(((GlifLayout) fragment.getView()).getIcon(),
- R.drawable.ic_fingerprint_header);
- }
-
@Config(qualifiers = "sw300dp")
@Test
public void smallScreens_shouldHideIcon() {
diff --git a/tests/robotests/src/com/android/settings/wifi/WifiDialogActivityTest.java b/tests/robotests/src/com/android/settings/wifi/WifiDialogActivityTest.java
index 685819e7839..f601e36229c 100644
--- a/tests/robotests/src/com/android/settings/wifi/WifiDialogActivityTest.java
+++ b/tests/robotests/src/com/android/settings/wifi/WifiDialogActivityTest.java
@@ -16,25 +16,12 @@
package com.android.settings.wifi;
-import static android.Manifest.permission.ACCESS_COARSE_LOCATION;
-import static android.Manifest.permission.ACCESS_FINE_LOCATION;
-
-import static com.android.settings.wifi.WifiDialogActivity.REQUEST_CODE_WIFI_DPP_ENROLLEE_QR_CODE_SCANNER;
-import static com.android.settings.wifi.WifiDialogActivity.RESULT_CONNECTED;
-import static com.android.settings.wifi.WifiDialogActivity.RESULT_OK;
-
import static com.google.common.truth.Truth.assertThat;
-import static org.mockito.ArgumentMatchers.any;
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.Intent;
-import android.content.pm.PackageManager;
import android.net.wifi.WifiConfiguration;
-import android.net.wifi.WifiManager;
import androidx.lifecycle.Lifecycle.State;
import androidx.test.core.app.ActivityScenario;
@@ -44,7 +31,6 @@ import com.android.settings.testutils.shadow.ShadowAlertDialogCompat;
import com.android.settings.testutils.shadow.ShadowConnectivityManager;
import com.android.settings.testutils.shadow.ShadowNetworkDetailsTracker;
import com.android.settings.testutils.shadow.ShadowWifiManager;
-import com.android.settingslib.wifi.AccessPoint;
import com.google.android.setupcompat.util.WizardManagerHelper;
@@ -69,25 +55,7 @@ import org.robolectric.util.ReflectionHelpers;
})
public class WifiDialogActivityTest {
- private static final String CALLING_PACKAGE = "calling_package";
private static final String AP1_SSID = "\"ap1\"";
-
- @Mock
- PackageManager mPackageManager;
- @Mock
- WifiManager mWifiManager;
- @Mock
- WifiDialog mWifiDialog;
- @Mock
- WifiConfiguration mWifiConfiguration;
- @Mock
- AccessPoint mAccessPoint;
- @Mock
- WifiDialog2 mWifiDialog2;
- @Mock
- WifiConfigController2 mWifiConfiguration2;
- @Mock
- Intent mResultData;
@Mock
private WifiConfigController mController;
@Mock
@@ -98,10 +66,6 @@ public class WifiDialogActivityTest {
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
- when(mWifiDialog.getController()).thenReturn(mController);
- when(mController.getConfig()).thenReturn(mWifiConfiguration);
- when(mController.getAccessPoint()).thenReturn(mAccessPoint);
- when(mWifiDialog2.getController()).thenReturn(mWifiConfiguration2);
WifiConfiguration wifiConfig = new WifiConfiguration();
wifiConfig.SSID = AP1_SSID;
@@ -133,52 +97,6 @@ public class WifiDialogActivityTest {
assertThat(ShadowWifiManager.get().savedWifiConfig.SSID).isEqualTo(AP1_SSID);
}
- @Test
- public void onSubmit_noPermissionForResult_setResultWithoutData() {
- WifiDialogActivity activity = spy(Robolectric.setupActivity(WifiDialogActivity.class));
- when(activity.hasPermissionForResult()).thenReturn(false);
- when(activity.getSystemService(WifiManager.class)).thenReturn(mWifiManager);
-
- activity.onSubmit(mWifiDialog);
-
- verify(activity).setResult(RESULT_CONNECTED, null);
- }
-
- @Test
- public void onSubmit_hasPermissionForResult_setResultWithData() {
- WifiDialogActivity activity = spy(Robolectric.setupActivity(WifiDialogActivity.class));
- when(activity.hasPermissionForResult()).thenReturn(true);
- when(activity.createResultData(any(), any())).thenReturn(mResultData);
- when(activity.getSystemService(WifiManager.class)).thenReturn(mWifiManager);
-
- activity.onSubmit(mWifiDialog);
-
- verify(activity).setResult(RESULT_CONNECTED, mResultData);
- }
-
- @Test
- public void onSubmit2_noPermissionForResult_setResultWithoutData() {
- WifiDialogActivity activity = spy(Robolectric.setupActivity(WifiDialogActivity.class));
- when(activity.hasPermissionForResult()).thenReturn(false);
- when(activity.getSystemService(WifiManager.class)).thenReturn(mWifiManager);
-
- activity.onSubmit(mWifiDialog2);
-
- verify(activity).setResult(RESULT_CONNECTED, null);
- }
-
- @Test
- public void onSubmit2_hasPermissionForResult_setResultWithData() {
- WifiDialogActivity activity = spy(Robolectric.setupActivity(WifiDialogActivity.class));
- when(activity.hasPermissionForResult()).thenReturn(true);
- when(activity.createResultData(any(), any())).thenReturn(mResultData);
- when(activity.getSystemService(WifiManager.class)).thenReturn(mWifiManager);
-
- activity.onSubmit(mWifiDialog2);
-
- verify(activity).setResult(RESULT_CONNECTED, mResultData);
- }
-
@Test
@Ignore
public void onSubmit2_whenConnectForCallerIsTrue_shouldConnectToNetwork() {
@@ -260,97 +178,4 @@ public class WifiDialogActivityTest {
assertThat(dialog.getContext().getThemeResId())
.isEqualTo(R.style.SuwAlertDialogThemeCompat_Light);
}
-
- @Test
- public void onActivityResult_noPermissionForResult_setResultWithoutData() {
- WifiDialogActivity activity = spy(Robolectric.setupActivity(WifiDialogActivity.class));
- when(activity.hasPermissionForResult()).thenReturn(false);
- final Intent data = new Intent();
-
- activity.onActivityResult(REQUEST_CODE_WIFI_DPP_ENROLLEE_QR_CODE_SCANNER, RESULT_OK,
- data);
-
- verify(activity).setResult(RESULT_CONNECTED);
- }
-
- @Test
- public void onActivityResult_hasPermissionForResult_setResultWithData() {
- WifiDialogActivity activity = spy(Robolectric.setupActivity(WifiDialogActivity.class));
- when(activity.hasPermissionForResult()).thenReturn(true);
- final Intent data = new Intent();
-
- activity.onActivityResult(REQUEST_CODE_WIFI_DPP_ENROLLEE_QR_CODE_SCANNER, RESULT_OK,
- data);
-
- verify(activity).setResult(RESULT_CONNECTED, data);
- }
-
- @Test
- public void hasPermissionForResult_noCallingPackage_returnFalse() {
- WifiDialogActivity activity = spy(Robolectric.setupActivity(WifiDialogActivity.class));
- when(activity.getCallingPackage()).thenReturn(null);
-
- final boolean result = activity.hasPermissionForResult();
-
- assertThat(result).isFalse();
- }
-
- @Test
- public void hasPermissionForResult_noPermission_returnFalse() {
- WifiDialogActivity activity = spy(Robolectric.setupActivity(WifiDialogActivity.class));
- when(activity.getCallingPackage()).thenReturn(null);
- when(mPackageManager.checkPermission(ACCESS_COARSE_LOCATION, CALLING_PACKAGE))
- .thenReturn(PackageManager.PERMISSION_DENIED);
- when(mPackageManager.checkPermission(ACCESS_FINE_LOCATION, CALLING_PACKAGE))
- .thenReturn(PackageManager.PERMISSION_DENIED);
-
- final boolean result = activity.hasPermissionForResult();
-
- assertThat(result).isFalse();
- }
-
- @Test
- public void hasPermissionForResult_hasCoarseLocationPermission_returnTrue() {
- WifiDialogActivity activity = spy(Robolectric.setupActivity(WifiDialogActivity.class));
- when(activity.getCallingPackage()).thenReturn(CALLING_PACKAGE);
- when(activity.getPackageManager()).thenReturn(mPackageManager);
- when(mPackageManager.checkPermission(ACCESS_COARSE_LOCATION, CALLING_PACKAGE))
- .thenReturn(PackageManager.PERMISSION_GRANTED);
- when(mPackageManager.checkPermission(ACCESS_FINE_LOCATION, CALLING_PACKAGE))
- .thenReturn(PackageManager.PERMISSION_DENIED);
-
- final boolean result = activity.hasPermissionForResult();
-
- assertThat(result).isTrue();
- }
-
- @Test
- public void hasPermissionForResult_hasFineLocationPermission_returnTrue() {
- WifiDialogActivity activity = spy(Robolectric.setupActivity(WifiDialogActivity.class));
- when(activity.getCallingPackage()).thenReturn(CALLING_PACKAGE);
- when(activity.getPackageManager()).thenReturn(mPackageManager);
- when(mPackageManager.checkPermission(ACCESS_COARSE_LOCATION, CALLING_PACKAGE))
- .thenReturn(PackageManager.PERMISSION_DENIED);
- when(mPackageManager.checkPermission(ACCESS_FINE_LOCATION, CALLING_PACKAGE))
- .thenReturn(PackageManager.PERMISSION_GRANTED);
-
- final boolean result = activity.hasPermissionForResult();
-
- assertThat(result).isTrue();
- }
-
- @Test
- public void hasPermissionForResult_haveBothLocationPermissions_returnTrue() {
- WifiDialogActivity activity = spy(Robolectric.setupActivity(WifiDialogActivity.class));
- when(activity.getCallingPackage()).thenReturn(CALLING_PACKAGE);
- when(activity.getPackageManager()).thenReturn(mPackageManager);
- when(mPackageManager.checkPermission(ACCESS_COARSE_LOCATION, CALLING_PACKAGE))
- .thenReturn(PackageManager.PERMISSION_GRANTED);
- when(mPackageManager.checkPermission(ACCESS_FINE_LOCATION, CALLING_PACKAGE))
- .thenReturn(PackageManager.PERMISSION_GRANTED);
-
- final boolean result = activity.hasPermissionForResult();
-
- assertThat(result).isTrue();
- }
}
diff --git a/tests/robotests/src/com/android/settings/wifi/details2/WifiNetworkDetailsFragment2Test.java b/tests/robotests/src/com/android/settings/wifi/details/WifiNetworkDetailsFragmentTest.java
similarity index 91%
rename from tests/robotests/src/com/android/settings/wifi/details2/WifiNetworkDetailsFragment2Test.java
rename to tests/robotests/src/com/android/settings/wifi/details/WifiNetworkDetailsFragmentTest.java
index fdd6295ab65..4f742549f24 100644
--- a/tests/robotests/src/com/android/settings/wifi/details2/WifiNetworkDetailsFragment2Test.java
+++ b/tests/robotests/src/com/android/settings/wifi/details/WifiNetworkDetailsFragmentTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2020 The Android Open Source Project
+ * Copyright (C) 2021 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package com.android.settings.wifi.details2;
+package com.android.settings.wifi.details;
import static com.android.settings.wifi.WifiSettings.WIFI_DIALOG_ID;
@@ -54,9 +54,9 @@ import org.robolectric.RuntimeEnvironment;
import java.util.ArrayList;
@RunWith(RobolectricTestRunner.class)
-public class WifiNetworkDetailsFragment2Test {
+public class WifiNetworkDetailsFragmentTest {
- final String TEST_PREFERENCE_KEY = "TEST_PREFERENCE_KEY";
+ private static final String TEST_PREFERENCE_KEY = "TEST_PREFERENCE_KEY";
@Mock
WifiEntry mWifiEntry;
@@ -64,7 +64,7 @@ public class WifiNetworkDetailsFragment2Test {
NetworkDetailsTracker mNetworkDetailsTracker;
@Mock
Menu mMenu;
- private WifiNetworkDetailsFragment2 mFragment;
+ private WifiNetworkDetailsFragment mFragment;
@Before
public void setUp() {
@@ -72,7 +72,7 @@ public class WifiNetworkDetailsFragment2Test {
doReturn(mWifiEntry).when(mNetworkDetailsTracker).getWifiEntry();
doReturn(true).when(mWifiEntry).isSaved();
- mFragment = new WifiNetworkDetailsFragment2();
+ mFragment = new WifiNetworkDetailsFragment();
mFragment.mNetworkDetailsTracker = mNetworkDetailsTracker;
}
@@ -165,8 +165,8 @@ public class WifiNetworkDetailsFragment2Test {
verify(controller).displayPreference(screen);
}
- // Fake WifiNetworkDetailsFragment2 to override the protected method as public.
- public class FakeFragment extends WifiNetworkDetailsFragment2 {
+ // Fake WifiNetworkDetailsFragment to override the protected method as public.
+ public static class FakeFragment extends WifiNetworkDetailsFragment {
@Override
public void addPreferenceController(AbstractPreferenceController controller) {
@@ -179,7 +179,7 @@ public class WifiNetworkDetailsFragment2Test {
}
}
- public class TestController extends BasePreferenceController {
+ public static class TestController extends BasePreferenceController {
public TestController() {
super(RuntimeEnvironment.application, TEST_PREFERENCE_KEY);
diff --git a/tests/robotests/src/com/android/settings/wifi/details2/WifiDetailPreferenceController2Test.java b/tests/robotests/src/com/android/settings/wifi/details2/WifiDetailPreferenceController2Test.java
index 7354d85bc7a..6a098bc9ead 100644
--- a/tests/robotests/src/com/android/settings/wifi/details2/WifiDetailPreferenceController2Test.java
+++ b/tests/robotests/src/com/android/settings/wifi/details2/WifiDetailPreferenceController2Test.java
@@ -76,6 +76,7 @@ import com.android.settings.Utils;
import com.android.settings.testutils.shadow.ShadowDevicePolicyManager;
import com.android.settings.testutils.shadow.ShadowEntityHeaderController;
import com.android.settings.widget.EntityHeaderController;
+import com.android.settings.wifi.details.WifiNetworkDetailsFragment;
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
import com.android.settingslib.core.lifecycle.Lifecycle;
import com.android.settingslib.utils.StringUtil;
@@ -145,7 +146,7 @@ public class WifiDetailPreferenceController2Test {
@Mock
private WifiInfo mMockWifiInfo;
@Mock
- private WifiNetworkDetailsFragment2 mMockFragment;
+ private WifiNetworkDetailsFragment mMockFragment;
@Mock
private WifiManager mMockWifiManager;
@Mock
diff --git a/tests/unit/src/com/android/settings/biometrics/combination/BiometricSettingsAppPreferenceControllerTest.java b/tests/unit/src/com/android/settings/biometrics/combination/BiometricSettingsAppPreferenceControllerTest.java
new file mode 100644
index 00000000000..f66e65f6c5b
--- /dev/null
+++ b/tests/unit/src/com/android/settings/biometrics/combination/BiometricSettingsAppPreferenceControllerTest.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright (C) 2021 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.biometrics.combination;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import android.content.Context;
+
+import androidx.test.core.app.ApplicationProvider;
+import androidx.test.ext.junit.runners.AndroidJUnit4;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+@RunWith(AndroidJUnit4.class)
+public class BiometricSettingsAppPreferenceControllerTest {
+
+ private Context mContext;
+ private BiometricSettingsAppPreferenceController mController;
+
+ @Before
+ public void setUp() {
+ mContext = ApplicationProvider.getApplicationContext();
+ mController = new BiometricSettingsAppPreferenceController(mContext, "key");
+ }
+
+ @Test
+ public void isSliceable_returnFalse() {
+ assertThat(mController.isSliceable()).isFalse();
+ }
+}
diff --git a/tests/unit/src/com/android/settings/biometrics/combination/BiometricSettingsKeyguardPreferenceControllerTest.java b/tests/unit/src/com/android/settings/biometrics/combination/BiometricSettingsKeyguardPreferenceControllerTest.java
new file mode 100644
index 00000000000..400b4fe70e9
--- /dev/null
+++ b/tests/unit/src/com/android/settings/biometrics/combination/BiometricSettingsKeyguardPreferenceControllerTest.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright (C) 2021 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.biometrics.combination;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import android.content.Context;
+
+import androidx.test.core.app.ApplicationProvider;
+import androidx.test.ext.junit.runners.AndroidJUnit4;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+@RunWith(AndroidJUnit4.class)
+public class BiometricSettingsKeyguardPreferenceControllerTest {
+
+ private Context mContext;
+ private BiometricSettingsKeyguardPreferenceController mController;
+
+ @Before
+ public void setUp() {
+ mContext = ApplicationProvider.getApplicationContext();
+ mController = new BiometricSettingsKeyguardPreferenceController(mContext, "key");
+ }
+
+ @Test
+ public void isSliceable_returnFalse() {
+ assertThat(mController.isSliceable()).isFalse();
+ }
+}
diff --git a/tests/unit/src/com/android/settings/biometrics/face/FaceSettingsAppPreferenceControllerTest.java b/tests/unit/src/com/android/settings/biometrics/face/FaceSettingsAppPreferenceControllerTest.java
new file mode 100644
index 00000000000..af45a68d7d1
--- /dev/null
+++ b/tests/unit/src/com/android/settings/biometrics/face/FaceSettingsAppPreferenceControllerTest.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright (C) 2021 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.biometrics.face;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import android.content.Context;
+
+import androidx.test.core.app.ApplicationProvider;
+import androidx.test.ext.junit.runners.AndroidJUnit4;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+@RunWith(AndroidJUnit4.class)
+public class FaceSettingsAppPreferenceControllerTest {
+
+ private Context mContext;
+ private FaceSettingsAppPreferenceController mController;
+
+ @Before
+ public void setUp() {
+ mContext = ApplicationProvider.getApplicationContext();
+ mController = new FaceSettingsAppPreferenceController(mContext);
+ }
+
+ @Test
+ public void isSliceable_returnFalse() {
+ assertThat(mController.isSliceable()).isFalse();
+ }
+}
diff --git a/tests/unit/src/com/android/settings/biometrics/face/FaceSettingsConfirmPreferenceControllerTest.java b/tests/unit/src/com/android/settings/biometrics/face/FaceSettingsConfirmPreferenceControllerTest.java
new file mode 100644
index 00000000000..678295943e7
--- /dev/null
+++ b/tests/unit/src/com/android/settings/biometrics/face/FaceSettingsConfirmPreferenceControllerTest.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright (C) 2021 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.biometrics.face;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import android.content.Context;
+
+import androidx.test.core.app.ApplicationProvider;
+import androidx.test.ext.junit.runners.AndroidJUnit4;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+@RunWith(AndroidJUnit4.class)
+public class FaceSettingsConfirmPreferenceControllerTest {
+
+ private Context mContext;
+ private FaceSettingsConfirmPreferenceController mController;
+
+ @Before
+ public void setUp() {
+ mContext = ApplicationProvider.getApplicationContext();
+ mController = new FaceSettingsConfirmPreferenceController(mContext);
+ }
+
+ @Test
+ public void isSliceable_returnFalse() {
+ assertThat(mController.isSliceable()).isFalse();
+ }
+}
diff --git a/tests/unit/src/com/android/settings/biometrics/face/FaceSettingsKeyguardPreferenceControllerTest.java b/tests/unit/src/com/android/settings/biometrics/face/FaceSettingsKeyguardPreferenceControllerTest.java
new file mode 100644
index 00000000000..ee62ed7ba34
--- /dev/null
+++ b/tests/unit/src/com/android/settings/biometrics/face/FaceSettingsKeyguardPreferenceControllerTest.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 2021 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.biometrics.face;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import android.content.Context;
+
+import androidx.test.core.app.ApplicationProvider;
+import androidx.test.ext.junit.runners.AndroidJUnit4;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+@RunWith(AndroidJUnit4.class)
+public class FaceSettingsKeyguardPreferenceControllerTest {
+ private Context mContext;
+ private FaceSettingsKeyguardPreferenceController mController;
+
+ @Before
+ public void setUp() {
+ mContext = ApplicationProvider.getApplicationContext();
+ mController = new FaceSettingsKeyguardPreferenceController(mContext);
+ }
+
+ @Test
+ public void isSliceable_returnFalse() {
+ assertThat(mController.isSliceable()).isFalse();
+ }
+}
diff --git a/tests/unit/src/com/android/settings/display/ColorModePreferenceFragmentTest.java b/tests/unit/src/com/android/settings/display/ColorModePreferenceFragmentTest.java
index cfdedc78e0c..450525c9339 100644
--- a/tests/unit/src/com/android/settings/display/ColorModePreferenceFragmentTest.java
+++ b/tests/unit/src/com/android/settings/display/ColorModePreferenceFragmentTest.java
@@ -39,6 +39,7 @@ import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
+import java.util.ArrayList;
import java.util.List;
@RunWith(AndroidJUnit4.class)
@@ -232,4 +233,15 @@ public class ColorModePreferenceFragmentTest {
verify(mFragment).setColorMode(ColorDisplayManager.COLOR_MODE_AUTOMATIC);
}
+
+ @Test
+ @UiThreadTest
+ public void checkViewPagerTotalCount() throws Throwable {
+ final ArrayList viewPagerResList = mFragment.getViewPagerResource();
+
+ assertThat(viewPagerResList.size()).isEqualTo(3);
+ for (int idx = 0; idx < viewPagerResList.size(); idx++) {
+ assertThat(viewPagerResList.get(idx) > 0).isTrue();
+ }
+ }
}
diff --git a/tests/unit/src/com/android/settings/network/NetworkProviderDownloadedSimsCategoryControllerTest.java b/tests/unit/src/com/android/settings/network/NetworkProviderDownloadedSimsCategoryControllerTest.java
index e34b489844e..90455022eda 100644
--- a/tests/unit/src/com/android/settings/network/NetworkProviderDownloadedSimsCategoryControllerTest.java
+++ b/tests/unit/src/com/android/settings/network/NetworkProviderDownloadedSimsCategoryControllerTest.java
@@ -26,9 +26,12 @@ import static org.mockito.Mockito.when;
import android.content.Context;
import android.os.Looper;
+import android.telephony.SubscriptionInfo;
+import com.android.settings.testutils.ResourcesUtils;
import com.android.settingslib.core.lifecycle.Lifecycle;
+import androidx.preference.Preference;
import androidx.preference.PreferenceCategory;
import androidx.preference.PreferenceManager;
import androidx.preference.PreferenceScreen;
@@ -41,38 +44,39 @@ import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
+import java.util.ArrayList;
+import java.util.Arrays;
+
@RunWith(AndroidJUnit4.class)
public class NetworkProviderDownloadedSimsCategoryControllerTest {
private static final String KEY_PREFERENCE_CATEGORY_DOWNLOADED_SIM =
"provider_model_downloaded_sim_category";
+ private static final String KEY_ADD_MORE = "add_more";
+ private static final String SUB_1 = "SUB_1";
+ private static final String SUB_2 = "SUB_2";
+ private static final int SUB_ID_1 = 1;
+ private static final int SUB_ID_2 = 2;
- @Mock
- private NetworkProviderDownloadedSimListController mNetworkProviderDownloadedSimListController;
- @Mock
- private PreferenceCategory mPreferenceCategory;
@Mock
private Lifecycle mLifecycle;
+ @Mock
+ private SubscriptionInfo mSubscriptionInfo1;
+ @Mock
+ private SubscriptionInfo mSubscriptionInfo2;
private Context mContext;
private NetworkProviderDownloadedSimsCategoryController mCategoryController;
-
+ private PreferenceCategory mPreferenceCategory;
private PreferenceManager mPreferenceManager;
private PreferenceScreen mPreferenceScreen;
+ private Preference mAddMorePreference;
@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
mContext = spy(ApplicationProvider.getApplicationContext());
- mCategoryController = new NetworkProviderDownloadedSimsCategoryController(
- mContext, KEY_PREFERENCE_CATEGORY_DOWNLOADED_SIM) {
- @Override
- protected NetworkProviderDownloadedSimListController createDownloadedSimListController(
- Lifecycle lifecycle) {
- return mNetworkProviderDownloadedSimListController;
- }
- };
if (Looper.myLooper() == null) {
Looper.prepare();
@@ -80,14 +84,21 @@ public class NetworkProviderDownloadedSimsCategoryControllerTest {
mPreferenceManager = new PreferenceManager(mContext);
mPreferenceScreen = mPreferenceManager.createPreferenceScreen(mContext);
- when(mPreferenceCategory.getKey()).thenReturn(KEY_PREFERENCE_CATEGORY_DOWNLOADED_SIM);
- when(mPreferenceCategory.getPreferenceCount()).thenReturn(1);
+ mPreferenceCategory = new PreferenceCategory(mContext);
+ mPreferenceCategory.setKey(KEY_PREFERENCE_CATEGORY_DOWNLOADED_SIM);
+ mAddMorePreference = new Preference(mContext);
+ mAddMorePreference.setKey(KEY_ADD_MORE);
+ mAddMorePreference.setVisible(true);
mPreferenceScreen.addPreference(mPreferenceCategory);
+ mPreferenceScreen.addPreference(mAddMorePreference);
+
+ mCategoryController = new NetworkProviderDownloadedSimsCategoryController(mContext,
+ KEY_PREFERENCE_CATEGORY_DOWNLOADED_SIM, mLifecycle);
}
@Test
public void getAvailabilityStatus_returnUnavailable() {
- mNetworkProviderDownloadedSimListController = null;
+ SubscriptionUtil.setAvailableSubscriptionsForTesting(new ArrayList<>());
assertThat(mCategoryController.getAvailabilityStatus()).isEqualTo(
CONDITIONALLY_UNAVAILABLE);
@@ -95,10 +106,46 @@ public class NetworkProviderDownloadedSimsCategoryControllerTest {
@Test
public void displayPreference_isVisible() {
- when(mNetworkProviderDownloadedSimListController.isAvailable()).thenReturn(true);
- mCategoryController.init(mLifecycle);
+ setUpSubscriptionInfoForDownloadedSim(SUB_ID_1, SUB_1, mSubscriptionInfo1);
+ SubscriptionUtil.setAvailableSubscriptionsForTesting(Arrays.asList(mSubscriptionInfo1));
mCategoryController.displayPreference(mPreferenceScreen);
assertEquals(mPreferenceCategory.isVisible(), true);
}
+
+
+ @Test
+ public void updateState_setTitle_withTwoDownloadedSims_returnDownloadedSims() {
+ setUpSubscriptionInfoForDownloadedSim(SUB_ID_1, SUB_1, mSubscriptionInfo1);
+ setUpSubscriptionInfoForDownloadedSim(SUB_ID_2, SUB_2, mSubscriptionInfo2);
+ SubscriptionUtil.setAvailableSubscriptionsForTesting(
+ Arrays.asList(mSubscriptionInfo1, mSubscriptionInfo2));
+
+ mCategoryController.displayPreference(mPreferenceScreen);
+ mCategoryController.updateState(mPreferenceCategory);
+
+ assertThat(mPreferenceCategory.getPreferenceCount()).isEqualTo(2);
+ assertThat(mPreferenceCategory.getTitle()).isEqualTo(
+ ResourcesUtils.getResourcesString(mContext, "downloaded_sims_category_title"));
+ }
+
+ @Test
+ public void updateState_setTitle_withOneDownloadedSim_returnDownloadedSim() {
+ setUpSubscriptionInfoForDownloadedSim(SUB_ID_1, SUB_1, mSubscriptionInfo1);
+ SubscriptionUtil.setAvailableSubscriptionsForTesting(Arrays.asList(mSubscriptionInfo1));
+
+ mCategoryController.displayPreference(mPreferenceScreen);
+ mCategoryController.updateState(mPreferenceCategory);
+
+ assertThat(mPreferenceCategory.getPreferenceCount()).isEqualTo(1);
+ assertThat(mPreferenceCategory.getTitle()).isEqualTo(
+ ResourcesUtils.getResourcesString(mContext, "downloaded_sim_category_title"));
+ }
+
+ private void setUpSubscriptionInfoForDownloadedSim(int subId, String displayName,
+ SubscriptionInfo subscriptionInfo) {
+ when(subscriptionInfo.isEmbedded()).thenReturn(true);
+ when(subscriptionInfo.getSubscriptionId()).thenReturn(subId);
+ when(subscriptionInfo.getDisplayName()).thenReturn(displayName);
+ }
}
diff --git a/tests/unit/src/com/android/settings/network/NetworkProviderSimListControllerTest.java b/tests/unit/src/com/android/settings/network/NetworkProviderSimListControllerTest.java
index 3b0a40ab702..066cf6b5f69 100644
--- a/tests/unit/src/com/android/settings/network/NetworkProviderSimListControllerTest.java
+++ b/tests/unit/src/com/android/settings/network/NetworkProviderSimListControllerTest.java
@@ -16,10 +16,14 @@
package com.android.settings.network;
+import static com.android.settings.core.BasePreferenceController.CONDITIONALLY_UNAVAILABLE;
+import static com.google.common.truth.Truth.assertThat;
+
import static androidx.lifecycle.Lifecycle.Event;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
@@ -170,7 +174,6 @@ public class NetworkProviderSimListControllerTest {
assertTrue(TextUtils.equals(mController.getSummary(SUB_ID_1, DISPLAY_NAME_1), summary));
}
-
@Test
@UiThreadTest
public void getSummary_inactivePSim() {
@@ -227,4 +230,18 @@ public class NetworkProviderSimListControllerTest {
assertTrue(TextUtils.equals(mController.getSummary(SUB_ID_1, DISPLAY_NAME_1), summary));
}
+ @Test
+ @UiThreadTest
+ public void getAvailablePhysicalSubscription_withTwoPhysicalSims_returnTwo() {
+ final SubscriptionInfo info1 = mock(SubscriptionInfo.class);
+ when(info1.isEmbedded()).thenReturn(false);
+ final SubscriptionInfo info2 = mock(SubscriptionInfo.class);
+ when(info2.isEmbedded()).thenReturn(false);
+ when(mSubscriptionManager.getAvailableSubscriptionInfoList()).thenReturn(
+ Arrays.asList(info1, info2));
+ displayPreferenceWithLifecycle();
+
+ assertThat(mController.getAvailablePhysicalSubscription().size()).isEqualTo(2);
+ }
+
}
diff --git a/tests/unit/src/com/android/settings/network/NetworkProviderSimsCategoryControllerTest.java b/tests/unit/src/com/android/settings/network/NetworkProviderSimsCategoryControllerTest.java
index cfa376bd183..c8d750ce437 100644
--- a/tests/unit/src/com/android/settings/network/NetworkProviderSimsCategoryControllerTest.java
+++ b/tests/unit/src/com/android/settings/network/NetworkProviderSimsCategoryControllerTest.java
@@ -17,6 +17,7 @@
package com.android.settings.network;
import static com.android.settings.core.BasePreferenceController.CONDITIONALLY_UNAVAILABLE;
+
import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.assertEquals;
@@ -25,7 +26,10 @@ import static org.mockito.Mockito.when;
import android.content.Context;
import android.os.Looper;
+import android.telephony.SubscriptionInfo;
+import android.telephony.SubscriptionManager;
+import com.android.settings.testutils.ResourcesUtils;
import com.android.settingslib.core.lifecycle.Lifecycle;
import androidx.preference.PreferenceCategory;
@@ -40,37 +44,35 @@ import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
+import java.util.ArrayList;
+import java.util.Arrays;
+
@RunWith(AndroidJUnit4.class)
public class NetworkProviderSimsCategoryControllerTest {
private static final String KEY_PREFERENCE_CATEGORY_SIM = "provider_model_sim_category";
+ private static final String SUB_1 = "SUB_1";
+ private static final String SUB_2 = "SUB_2";
+ private static final int SUB_ID_1 = 1;
+ private static final int SUB_ID_2 = 2;
- @Mock
- private NetworkProviderSimListController mNetworkProviderSimListController;
- @Mock
- private PreferenceCategory mPreferenceCategory;
@Mock
private Lifecycle mLifecycle;
+ @Mock
+ private SubscriptionInfo mSubscriptionInfo1;
+ @Mock
+ private SubscriptionInfo mSubscriptionInfo2;
private Context mContext;
private NetworkProviderSimsCategoryController mCategoryController;
-
private PreferenceManager mPreferenceManager;
private PreferenceScreen mPreferenceScreen;
+ private PreferenceCategory mPreferenceCategory;
@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
-
mContext = spy(ApplicationProvider.getApplicationContext());
- mCategoryController = new NetworkProviderSimsCategoryController(
- mContext, KEY_PREFERENCE_CATEGORY_SIM) {
- @Override
- protected NetworkProviderSimListController createSimListController(
- Lifecycle lifecycle) {
- return mNetworkProviderSimListController;
- }
- };
if (Looper.myLooper() == null) {
Looper.prepare();
@@ -78,14 +80,17 @@ public class NetworkProviderSimsCategoryControllerTest {
mPreferenceManager = new PreferenceManager(mContext);
mPreferenceScreen = mPreferenceManager.createPreferenceScreen(mContext);
- when(mPreferenceCategory.getKey()).thenReturn(KEY_PREFERENCE_CATEGORY_SIM);
- when(mPreferenceCategory.getPreferenceCount()).thenReturn(1);
+ mPreferenceCategory = new PreferenceCategory(mContext);
+ mPreferenceCategory.setKey(KEY_PREFERENCE_CATEGORY_SIM);
mPreferenceScreen.addPreference(mPreferenceCategory);
+
+ mCategoryController = new NetworkProviderSimsCategoryController(
+ mContext, KEY_PREFERENCE_CATEGORY_SIM, mLifecycle);
}
@Test
public void getAvailabilityStatus_returnUnavailable() {
- mNetworkProviderSimListController = null;
+ SubscriptionUtil.setAvailableSubscriptionsForTesting(new ArrayList<>());
assertThat(mCategoryController.getAvailabilityStatus()).isEqualTo(
CONDITIONALLY_UNAVAILABLE);
@@ -93,10 +98,46 @@ public class NetworkProviderSimsCategoryControllerTest {
@Test
public void displayPreference_isVisible() {
- when(mNetworkProviderSimListController.isAvailable()).thenReturn(true);
- mCategoryController.init(mLifecycle);
+ setUpSubscriptionInfoForPhysicalSim(SUB_ID_1, SUB_1, mSubscriptionInfo1);
+ SubscriptionUtil.setAvailableSubscriptionsForTesting(Arrays.asList(mSubscriptionInfo1));
mCategoryController.displayPreference(mPreferenceScreen);
assertEquals(mPreferenceCategory.isVisible(), true);
}
+
+ @Test
+ public void updateState_setTitle_withTwoPhysicalSims_returnSims() {
+ setUpSubscriptionInfoForPhysicalSim(SUB_ID_1, SUB_1, mSubscriptionInfo1);
+ setUpSubscriptionInfoForPhysicalSim(SUB_ID_2, SUB_2, mSubscriptionInfo2);
+ SubscriptionUtil.setAvailableSubscriptionsForTesting(
+ Arrays.asList(mSubscriptionInfo1, mSubscriptionInfo2));
+
+ mCategoryController.displayPreference(mPreferenceScreen);
+ mCategoryController.updateState(mPreferenceCategory);
+
+ assertThat(mPreferenceCategory.getPreferenceCount()).isEqualTo(2);
+ assertThat(mPreferenceCategory.getTitle()).isEqualTo(
+ ResourcesUtils.getResourcesString(mContext, "provider_network_settings_title"));
+ }
+
+ @Test
+ public void updateState_setTitle_withOnePhysicalSim_returnSim() {
+ setUpSubscriptionInfoForPhysicalSim(SUB_ID_1, SUB_1, mSubscriptionInfo1);
+ SubscriptionUtil.setAvailableSubscriptionsForTesting(Arrays.asList(mSubscriptionInfo1));
+
+ mCategoryController.displayPreference(mPreferenceScreen);
+ mCategoryController.updateState(mPreferenceCategory);
+
+ assertThat(mPreferenceCategory.getPreferenceCount()).isEqualTo(1);
+ assertThat(mPreferenceCategory.getTitle()).isEqualTo(
+ ResourcesUtils.getResourcesString(mContext, "sim_category_title"));
+ }
+
+ private void setUpSubscriptionInfoForPhysicalSim(int subId, String displayName,
+ SubscriptionInfo subscriptionInfo) {
+ when(subscriptionInfo.isEmbedded()).thenReturn(false);
+ when(subscriptionInfo.getSubscriptionId()).thenReturn(subId);
+ when(subscriptionInfo.getDisplayName()).thenReturn(displayName);
+ }
+
}
diff --git a/tests/unit/src/com/android/settings/network/SubscriptionsPreferenceControllerTest.java b/tests/unit/src/com/android/settings/network/SubscriptionsPreferenceControllerTest.java
index cb78d19714c..7cffb76f983 100644
--- a/tests/unit/src/com/android/settings/network/SubscriptionsPreferenceControllerTest.java
+++ b/tests/unit/src/com/android/settings/network/SubscriptionsPreferenceControllerTest.java
@@ -665,6 +665,7 @@ public class SubscriptionsPreferenceControllerTest {
doReturn(true).when(sInjector).isProviderModelEnabled(mContext);
doReturn(sub.get(0)).when(mSubscriptionManager).getDefaultDataSubscriptionInfo();
Drawable icon = mock(Drawable.class);
+ when(mTelephonyManager.isDataEnabled()).thenReturn(true);
doReturn(icon).when(sInjector).getIcon(any(), anyInt(), anyInt(), eq(false));
setupGetIconConditions(sub.get(0).getSubscriptionId(), true, true,
true, ServiceState.STATE_IN_SERVICE);
@@ -683,6 +684,7 @@ public class SubscriptionsPreferenceControllerTest {
doReturn(true).when(sInjector).isProviderModelEnabled(mContext);
doReturn(subs.get(0)).when(mSubscriptionManager).getDefaultDataSubscriptionInfo();
Drawable icon = mock(Drawable.class);
+ when(mTelephonyManager.isDataEnabled()).thenReturn(true);
doReturn(icon).when(sInjector).getIcon(any(), anyInt(), anyInt(), eq(false));
setupGetIconConditions(subId, false, true,
true, ServiceState.STATE_IN_SERVICE);
@@ -701,7 +703,8 @@ public class SubscriptionsPreferenceControllerTest {
doReturn(true).when(sInjector).isProviderModelEnabled(mContext);
doReturn(subs.get(0)).when(mSubscriptionManager).getDefaultDataSubscriptionInfo();
Drawable icon = mock(Drawable.class);
- doReturn(icon).when(sInjector).getIcon(any(), anyInt(), anyInt(), eq(false));
+ when(mTelephonyManager.isDataEnabled()).thenReturn(false);
+ doReturn(icon).when(sInjector).getIcon(any(), anyInt(), anyInt(), eq(true));
setupGetIconConditions(subId, false, false,
false, ServiceState.STATE_IN_SERVICE);
diff --git a/tests/unit/src/com/android/settings/network/telephony/NrAdvancedCallingPreferenceControllerTest.java b/tests/unit/src/com/android/settings/network/telephony/NrAdvancedCallingPreferenceControllerTest.java
new file mode 100644
index 00000000000..9eb67df96ca
--- /dev/null
+++ b/tests/unit/src/com/android/settings/network/telephony/NrAdvancedCallingPreferenceControllerTest.java
@@ -0,0 +1,168 @@
+/*
+ * Copyright (C) 2021 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.network.telephony;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.ArgumentMatchers.anyBoolean;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.when;
+
+import android.content.Context;
+import android.os.PersistableBundle;
+import android.telephony.CarrierConfigManager;
+import android.telephony.SubscriptionManager;
+import android.telephony.TelephonyManager;
+
+import androidx.preference.SwitchPreference;
+import androidx.test.core.app.ApplicationProvider;
+import androidx.test.ext.junit.runners.AndroidJUnit4;
+
+import com.android.settings.core.BasePreferenceController;
+import com.android.settingslib.RestrictedSwitchPreference;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+
+@RunWith(AndroidJUnit4.class)
+public class NrAdvancedCallingPreferenceControllerTest {
+ private static final int SUB_ID = 2;
+
+ @Mock
+ private TelephonyManager mTelephonyManager;
+ @Mock
+ private TelephonyManager mInvalidTelephonyManager;
+ @Mock
+ private SubscriptionManager mSubscriptionManager;
+ @Mock
+ private CarrierConfigManager mCarrierConfigManager;
+
+ private NrAdvancedCallingPreferenceController mController;
+ private SwitchPreference mPreference;
+ private PersistableBundle mCarrierConfig;
+ private Context mContext;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+
+ mContext = spy(ApplicationProvider.getApplicationContext());
+ when(mContext.getSystemService(TelephonyManager.class)).thenReturn(mTelephonyManager);
+ when(mContext.getSystemService(SubscriptionManager.class)).thenReturn(mSubscriptionManager);
+ when(mContext.getSystemService(CarrierConfigManager.class))
+ .thenReturn(mCarrierConfigManager);
+
+ doReturn(mTelephonyManager).when(mTelephonyManager).createForSubscriptionId(SUB_ID);
+ doReturn(mInvalidTelephonyManager).when(mTelephonyManager).createForSubscriptionId(
+ SubscriptionManager.INVALID_SUBSCRIPTION_ID);
+ doReturn(TelephonyManager.NETWORK_TYPE_BITMASK_NR).when(
+ mTelephonyManager).getSupportedRadioAccessFamily();
+ doReturn(false).when(mTelephonyManager).isVoNrEnabled();
+ doReturn(TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED).when(
+ mTelephonyManager).setVoNrEnabled(anyBoolean());
+ mCarrierConfig = new PersistableBundle();
+ doReturn(mCarrierConfig).when(mCarrierConfigManager).getConfigForSubId(SUB_ID);
+ mCarrierConfig.putBoolean(CarrierConfigManager.KEY_VONR_SETTING_VISIBILITY_BOOL, false);
+ mCarrierConfig.putIntArray(CarrierConfigManager.KEY_CARRIER_NR_AVAILABILITIES_INT_ARRAY,
+ new int[]{1, 2});
+
+ mPreference = new RestrictedSwitchPreference(mContext);
+ mController = spy(new NrAdvancedCallingPreferenceController(mContext, "VoNr"));
+ mController.init(SUB_ID);
+ doReturn(true).when(mController).isCallStateIdle();
+ mPreference.setKey(mController.getPreferenceKey());
+ }
+
+ @Test
+ public void getAvailabilityStatus_vonrDisabled_returnUnavailable() {
+ mCarrierConfig.putBoolean(CarrierConfigManager.KEY_VONR_SETTING_VISIBILITY_BOOL, false);
+
+ mController.init(SUB_ID);
+
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(
+ BasePreferenceController.CONDITIONALLY_UNAVAILABLE);
+ }
+
+ @Test
+ public void getAvailabilityStatus_vonrEnabled_returnAvailable() {
+ mCarrierConfig.putBoolean(CarrierConfigManager.KEY_VONR_SETTING_VISIBILITY_BOOL, true);
+
+ mController.init(SUB_ID);
+
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(
+ BasePreferenceController.AVAILABLE);
+ }
+
+ @Test
+ public void getAvailabilityStatus_deviceNoNr_returnUnavailable() {
+ doReturn(TelephonyManager.NETWORK_TYPE_BITMASK_LTE).when(
+ mTelephonyManager).getSupportedRadioAccessFamily();
+
+ mController.init(SUB_ID);
+
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(
+ BasePreferenceController.CONDITIONALLY_UNAVAILABLE);
+ }
+
+ @Test
+ public void getAvailabilityStatus_carrierNoNr_returnUnavailable() {
+ mCarrierConfig.putIntArray(CarrierConfigManager.KEY_CARRIER_NR_AVAILABILITIES_INT_ARRAY,
+ new int[0]);
+
+ mController.init(SUB_ID);
+
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(
+ BasePreferenceController.CONDITIONALLY_UNAVAILABLE);
+ }
+
+ @Test
+ public void getAvailabilityStatus_carrierConfigNrIsNull_returnUnavailable() {
+ mCarrierConfig.putIntArray(CarrierConfigManager.KEY_CARRIER_NR_AVAILABILITIES_INT_ARRAY,
+ null);
+
+ mController.init(SUB_ID);
+
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(
+ BasePreferenceController.CONDITIONALLY_UNAVAILABLE);
+ }
+
+ @Test
+ public void updateState_callStateNotIdle_prefDisabled() {
+ doReturn(false).when(mController).isCallStateIdle();
+ mPreference.setEnabled(true);
+
+ mController.updateState(mPreference);
+
+ assertThat(mPreference.isEnabled()).isFalse();
+ }
+
+ @Test
+ public void updateState_configOn_prefChecked() {
+ doReturn(TelephonyManager.ENABLE_VONR_SUCCESS).when(
+ mTelephonyManager).setVoNrEnabled(anyBoolean());
+ doReturn(true).when(mTelephonyManager).isVoNrEnabled();
+ mPreference.setChecked(false);
+
+ mController.updateState(mPreference);
+
+ assertThat(mPreference.isChecked()).isTrue();
+ }
+}
diff --git a/tests/unit/src/com/android/settings/panel/InternetConnectivityPanelTest.java b/tests/unit/src/com/android/settings/panel/InternetConnectivityPanelTest.java
deleted file mode 100644
index 30a272950f5..00000000000
--- a/tests/unit/src/com/android/settings/panel/InternetConnectivityPanelTest.java
+++ /dev/null
@@ -1,341 +0,0 @@
-/*
- * Copyright (C) 2021 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.settings.panel;
-
-import static com.google.common.truth.Truth.assertThat;
-
-import static org.mockito.Mockito.clearInvocations;
-import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.spy;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-import android.content.Context;
-import android.net.Uri;
-import android.net.wifi.ScanResult;
-import android.net.wifi.WifiManager;
-import android.os.Handler;
-
-import androidx.test.core.app.ApplicationProvider;
-import androidx.test.ext.junit.runners.AndroidJUnit4;
-
-import com.android.settings.network.AirplaneModePreferenceController;
-import com.android.settings.network.InternetUpdater;
-import com.android.settings.network.ProviderModelSliceHelper;
-import com.android.settings.slices.CustomSliceRegistry;
-import com.android.settings.testutils.ResourcesUtils;
-
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnit;
-import org.mockito.junit.MockitoRule;
-
-import java.util.ArrayList;
-import java.util.List;
-
-@RunWith(AndroidJUnit4.class)
-public class InternetConnectivityPanelTest {
-
- public static final String TITLE_INTERNET = ResourcesUtils.getResourcesString(
- ApplicationProvider.getApplicationContext(), "provider_internet_settings");
- public static final String TITLE_APM = ResourcesUtils.getResourcesString(
- ApplicationProvider.getApplicationContext(), "airplane_mode");
- public static final String SUBTITLE_TEXT_WIFI_IS_OFF =
- ResourcesUtils.getResourcesString(ApplicationProvider.getApplicationContext(),
- "wifi_is_off");
- public static final String SUBTITLE_TEXT_TAP_A_NETWORK_TO_CONNECT =
- ResourcesUtils.getResourcesString(ApplicationProvider.getApplicationContext(),
- "tap_a_network_to_connect");
- public static final String SUBTITLE_NON_CARRIER_NETWORK_UNAVAILABLE =
- ResourcesUtils.getResourcesString(ApplicationProvider.getApplicationContext(),
- "non_carrier_network_unavailable");
- public static final String SUBTITLE_ALL_NETWORK_UNAVAILABLE =
- ResourcesUtils.getResourcesString(ApplicationProvider.getApplicationContext(),
- "all_network_unavailable");
- public static final String BUTTON_TURN_ON_WIFI = ResourcesUtils.getResourcesString(
- ApplicationProvider.getApplicationContext(), "turn_on_wifi");
- public static final String BUTTON_TURN_OFF_WIFI = ResourcesUtils.getResourcesString(
- ApplicationProvider.getApplicationContext(), "turn_off_wifi");
-
- @Rule
- public final MockitoRule mMocks = MockitoJUnit.rule();
- @Mock
- Handler mMainThreadHandler;
- @Mock
- PanelContentCallback mPanelContentCallback;
- @Mock
- InternetUpdater mInternetUpdater;
- @Mock
- private WifiManager mWifiManager;
- @Mock
- private ProviderModelSliceHelper mProviderModelSliceHelper;
-
- private Context mContext;
- private FakeHandlerInjector mFakeHandlerInjector;
- private InternetConnectivityPanel mPanel;
-
- private class FakeHandlerInjector extends InternetConnectivityPanel.HandlerInjector {
-
- private Runnable mRunnable;
-
- FakeHandlerInjector(Context context) {
- super(context);
- }
-
- @Override
- public void postDelay(Runnable runnable) {
- mRunnable = runnable;
- }
-
- public Runnable getRunnable() {
- return mRunnable;
- }
- }
-
- @Before
- public void setUp() {
- mContext = spy(ApplicationProvider.getApplicationContext());
- mFakeHandlerInjector = new FakeHandlerInjector(mContext);
- when(mContext.getApplicationContext()).thenReturn(mContext);
- when(mContext.getMainThreadHandler()).thenReturn(mMainThreadHandler);
- when(mContext.getSystemService(WifiManager.class)).thenReturn(mWifiManager);
-
- mPanel = InternetConnectivityPanel.create(mContext);
- mPanel.registerCallback(mPanelContentCallback);
- mPanel.mIsProviderModelEnabled = true;
- mPanel.mInternetUpdater = mInternetUpdater;
- mPanel.mProviderModelSliceHelper = mProviderModelSliceHelper;
- mPanel.mHandlerInjector = mFakeHandlerInjector;
- }
-
- @Test
- public void getTitle_apmOff_shouldBeInternet() {
- doReturn(false).when(mInternetUpdater).isAirplaneModeOn();
-
- assertThat(mPanel.getTitle()).isEqualTo(TITLE_INTERNET);
- }
-
- @Test
- public void getTitle_apmOn_shouldBeApm() {
- doReturn(true).when(mInternetUpdater).isAirplaneModeOn();
-
- assertThat(mPanel.getTitle()).isEqualTo(TITLE_APM);
- }
-
- @Test
- public void getSubTitle_apmOnWifiOff_shouldBeNull() {
- doReturn(true).when(mInternetUpdater).isAirplaneModeOn();
- doReturn(false).when(mInternetUpdater).isWifiEnabled();
-
- assertThat(mPanel.getSubTitle()).isNull();
- }
-
- @Test
- public void getSubTitle_apmOnWifiOn_shouldBeNull() {
- doReturn(true).when(mInternetUpdater).isAirplaneModeOn();
- doReturn(true).when(mInternetUpdater).isWifiEnabled();
-
- assertThat(mPanel.getSubTitle()).isNull();
- }
-
- @Test
- public void getSubTitle_apmOffWifiOff_wifiIsOn() {
- doReturn(false).when(mInternetUpdater).isAirplaneModeOn();
- doReturn(false).when(mInternetUpdater).isWifiEnabled();
-
- mPanel.updatePanelTitle();
-
- assertThat(mPanel.getSubTitle()).isEqualTo(SUBTITLE_TEXT_WIFI_IS_OFF);
- }
-
- @Test
- public void getSubTitle_apmOffWifiOnNoWifiListHasCarrierData_NonCarrierNetworkUnavailable() {
- List wifiList = new ArrayList();
- mockCondition(false, true, true, true, true, true, wifiList);
-
- mPanel.updatePanelTitle();
-
- assertThat(mPanel.getSubTitle()).isEqualTo(SUBTITLE_NON_CARRIER_NETWORK_UNAVAILABLE);
- }
-
- @Test
- public void getSubTitle_apmOffWifiOnNoWifiListNoCarrierItem_AllNetworkUnavailable() {
- List wifiList = new ArrayList();
- mockCondition(false, false, false, false, false, true, wifiList);
-
- mPanel.updatePanelTitle();
-
- assertThat(mPanel.getSubTitle()).isEqualTo(SUBTITLE_ALL_NETWORK_UNAVAILABLE);
- }
-
- @Test
- public void getSubTitle_apmOffWifiOnNoWifiListNoDataSimActive_AllNetworkUnavailable() {
- List wifiList = new ArrayList();
- mockCondition(false, true, false, true, true, true, wifiList);
-
- mPanel.updatePanelTitle();
-
- assertThat(mPanel.getSubTitle()).isEqualTo(SUBTITLE_ALL_NETWORK_UNAVAILABLE);
- }
-
- @Test
- public void getSubTitle_apmOffWifiOnNoWifiListNoService_AllNetworkUnavailable() {
- List wifiList = new ArrayList();
- mockCondition(false, true, false, true, false, true, wifiList);
-
- mPanel.updatePanelTitle();
-
- assertThat(mPanel.getSubTitle()).isEqualTo(SUBTITLE_ALL_NETWORK_UNAVAILABLE);
- }
-
- @Test
- public void getSubTitle_apmOffWifiOnTwoWifiItemsNoCarrierData_tapANetworkToConnect() {
- List wifiList = new ArrayList();
- wifiList.add(new ScanResult());
- wifiList.add(new ScanResult());
- mockCondition(false, true, false, true, true, true, wifiList);
-
- mPanel.updatePanelTitle();
-
- assertThat(mPanel.getSubTitle()).isEqualTo(SUBTITLE_TEXT_TAP_A_NETWORK_TO_CONNECT);
- }
-
- @Test
- public void getSlices_providerModelDisabled_containsNecessarySlices() {
- mPanel.mIsProviderModelEnabled = false;
- List uris = mPanel.getSlices();
-
- assertThat(uris).containsExactly(
- AirplaneModePreferenceController.SLICE_URI,
- CustomSliceRegistry.MOBILE_DATA_SLICE_URI,
- CustomSliceRegistry.WIFI_SLICE_URI);
- }
-
- @Test
- public void getSlices_providerModelEnabled_containsNecessarySlices() {
- List uris = mPanel.getSlices();
-
- assertThat(uris).containsExactly(CustomSliceRegistry.PROVIDER_MODEL_SLICE_URI);
- }
-
- @Test
- public void getSeeMoreIntent_providerModelDisabled_shouldNotNull() {
- mPanel.mIsProviderModelEnabled = false;
-
- assertThat(mPanel.getSeeMoreIntent()).isNotNull();
- }
-
- @Test
- public void getSeeMoreIntent_providerModelEnabled_shouldBeNull() {
- mPanel.mIsProviderModelEnabled = true;
-
- assertThat(mPanel.getSeeMoreIntent()).isNull();
- }
-
- @Test
- public void updatePanelTitle_onHeaderChanged() {
- clearInvocations(mPanelContentCallback);
-
- mPanel.updatePanelTitle();
-
- verify(mPanelContentCallback).onHeaderChanged();
- }
-
- @Test
- public void updateProgressBar_wifiDisabled_hideProgress() {
- mPanel.mIsProgressBarVisible = true;
- doReturn(false).when(mInternetUpdater).isWifiEnabled();
- clearInvocations(mPanelContentCallback);
-
- mPanel.updateProgressBar();
-
- assertThat(mPanel.isProgressBarVisible()).isFalse();
- verify(mPanelContentCallback).onProgressBarVisibleChanged();
- }
-
- @Test
- public void updateProgressBar_noWifiScanResults_showProgressForever() {
- mPanel.mIsScanningSubTitleShownOnce = false;
- mPanel.mIsProgressBarVisible = false;
- doReturn(true).when(mInternetUpdater).isWifiEnabled();
- List noWifiScanResults = new ArrayList<>();
- doReturn(noWifiScanResults).when(mWifiManager).getScanResults();
- clearInvocations(mPanelContentCallback);
-
- mPanel.updateProgressBar();
-
- assertThat(mPanel.mIsProgressBarVisible).isTrue();
- verify(mPanelContentCallback).onProgressBarVisibleChanged();
- verify(mPanelContentCallback).onHeaderChanged();
-
- assertThat(mFakeHandlerInjector.getRunnable())
- .isEqualTo(mPanel.mHideScanningSubTitleRunnable);
- mFakeHandlerInjector.getRunnable().run();
- assertThat(mPanel.mIsScanningSubTitleShownOnce).isTrue();
- assertThat(mPanel.mIsProgressBarVisible).isTrue();
- }
-
- @Test
- public void updateProgressBar_hasWifiScanResults_showProgressDelayedHide() {
- mPanel.mIsProgressBarVisible = false;
- doReturn(true).when(mInternetUpdater).isWifiEnabled();
- List hasWifiScanResults = mock(ArrayList.class);
- doReturn(1).when(hasWifiScanResults).size();
- doReturn(hasWifiScanResults).when(mWifiManager).getScanResults();
- clearInvocations(mPanelContentCallback);
-
- mPanel.updateProgressBar();
-
- assertThat(mPanel.isProgressBarVisible()).isTrue();
- verify(mPanelContentCallback).onProgressBarVisibleChanged();
-
- assertThat(mFakeHandlerInjector.getRunnable())
- .isEqualTo(mPanel.mHideProgressBarRunnable);
- mFakeHandlerInjector.getRunnable().run();
- assertThat(mPanel.mIsProgressBarVisible).isFalse();
- }
-
- @Test
- public void setProgressBarVisible_onProgressBarVisibleChanged() {
- mPanel.mIsProgressBarVisible = false;
- doReturn(true).when(mInternetUpdater).isWifiEnabled();
- clearInvocations(mPanelContentCallback);
-
- mPanel.setProgressBarVisible(true);
-
- assertThat(mPanel.mIsProgressBarVisible).isTrue();
- verify(mPanelContentCallback).onProgressBarVisibleChanged();
- verify(mPanelContentCallback).onHeaderChanged();
- }
-
- private void mockCondition(boolean airplaneMode, boolean hasCarrier,
- boolean isDataSimActive, boolean isMobileDataEnabled, boolean isServiceInService,
- boolean isWifiEnabled, List wifiItems) {
- doReturn(airplaneMode).when(mInternetUpdater).isAirplaneModeOn();
- when(mProviderModelSliceHelper.hasCarrier()).thenReturn(hasCarrier);
- when(mProviderModelSliceHelper.isDataSimActive()).thenReturn(isDataSimActive);
- when(mProviderModelSliceHelper.isMobileDataEnabled()).thenReturn(isMobileDataEnabled);
- when(mProviderModelSliceHelper.isDataStateInService()).thenReturn(isServiceInService);
- when(mProviderModelSliceHelper.isVoiceStateInService()).thenReturn(isServiceInService);
- doReturn(isWifiEnabled).when(mInternetUpdater).isWifiEnabled();
- doReturn(wifiItems).when(mWifiManager).getScanResults();
- }
-}
diff --git a/tests/unit/src/com/android/settings/panel/PanelFeatureProviderImplTest.java b/tests/unit/src/com/android/settings/panel/PanelFeatureProviderImplTest.java
index 3b61a734af1..a02c054237f 100644
--- a/tests/unit/src/com/android/settings/panel/PanelFeatureProviderImplTest.java
+++ b/tests/unit/src/com/android/settings/panel/PanelFeatureProviderImplTest.java
@@ -20,7 +20,12 @@ import static com.android.settings.panel.SettingsPanelActivity.KEY_PANEL_TYPE_AR
import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
+
import android.content.Context;
+import android.content.Intent;
import android.os.Bundle;
import android.provider.Settings;
@@ -36,25 +41,28 @@ public class PanelFeatureProviderImplTest {
private static final String TEST_PACKAGENAME = "com.test.packagename";
+ private static final String SYSTEMUI_PACKAGE_NAME = "com.android.systemui";
private Context mContext;
private PanelFeatureProviderImpl mProvider;
private Bundle mBundle;
@Before
public void setUp() {
- mContext = ApplicationProvider.getApplicationContext();
+ mContext = spy(ApplicationProvider.getApplicationContext());
mProvider = new PanelFeatureProviderImpl();
mBundle = new Bundle();
mBundle.putString(KEY_MEDIA_PACKAGE_NAME, TEST_PACKAGENAME);
}
@Test
- public void getPanel_internetConnectivityKey_returnsCorrectPanel() {
+ public void getPanel_internetConnectivityKey_sendsCorrectBroadcast() {
mBundle.putString(KEY_PANEL_TYPE_ARGUMENT, Settings.Panel.ACTION_INTERNET_CONNECTIVITY);
+ mProvider.getPanel(mContext, mBundle);
+ Intent intent = new Intent(Settings.Panel.ACTION_INTERNET_CONNECTIVITY);
+ intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND)
+ .setPackage(SYSTEMUI_PACKAGE_NAME);
- final PanelContent panel = mProvider.getPanel(mContext, mBundle);
-
- assertThat(panel).isInstanceOf(InternetConnectivityPanel.class);
+ verify(mContext, never()).sendBroadcast(intent);
}
@Test