diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 6e1d8f8c6ba..b4579771762 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -1825,7 +1825,7 @@
@@ -2591,6 +2591,12 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/res/layout/dialog_mobile_network_rename.xml b/res/layout/dialog_mobile_network_rename.xml
new file mode 100644
index 00000000000..d67f0dc6824
--- /dev/null
+++ b/res/layout/dialog_mobile_network_rename.xml
@@ -0,0 +1,64 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/res/values/ids.xml b/res/values/ids.xml
index 66af163e2b8..ba14e855286 100644
--- a/res/values/ids.xml
+++ b/res/values/ids.xml
@@ -31,4 +31,7 @@
+
+
+
diff --git a/res/values/strings.xml b/res/values/strings.xml
index ab52c5cfb19..039fb13e070 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -7056,7 +7056,9 @@
network, mobile network state, service state, signal strength, mobile network type, roaming, iccid
serial number, hardware version
android security patch level, baseband version, kernel version
-
+
+ theme, light, dark, mode
+
financial app, sms, permission
@@ -10456,6 +10458,14 @@
Inactive eSIM
+
+ SIM name
+
+ Rename
Preferred network type
diff --git a/res/xml/display_settings.xml b/res/xml/display_settings.xml
index b110b46ce26..0f4c1d349f0 100644
--- a/res/xml/display_settings.xml
+++ b/res/xml/display_settings.xml
@@ -141,6 +141,7 @@
android:dialogTitle="@string/dark_ui_mode_title"
android:entries="@array/dark_ui_mode_entries"
android:entryValues="@array/dark_ui_mode_values"
+ settings:keywords="@string/keywords_dark_ui_mode"
settings:controller="com.android.settings.display.DarkUIPreferenceController" />
{
final LocalTime time = LocalTime.of(hourOfDay, minute);
if (dialogId == DIALOG_START_TIME) {
- mController.setCustomStartTime(time);
+ mColorDisplayManager.setNightDisplayCustomStartTime(time);
} else {
- mController.setCustomEndTime(time);
+ mColorDisplayManager.setNightDisplayCustomEndTime(time);
}
}, initialTime.getHour(), initialTime.getMinute(), use24HourFormat);
}
diff --git a/src/com/android/settings/display/NightDisplayTimeFormatter.java b/src/com/android/settings/display/NightDisplayTimeFormatter.java
index 1b82e0ae3ab..1b5b146ea2d 100644
--- a/src/com/android/settings/display/NightDisplayTimeFormatter.java
+++ b/src/com/android/settings/display/NightDisplayTimeFormatter.java
@@ -19,7 +19,6 @@ package com.android.settings.display;
import android.content.Context;
import android.hardware.display.ColorDisplayManager;
-import com.android.internal.app.ColorDisplayController;
import com.android.settings.R;
import java.text.DateFormat;
@@ -46,22 +45,23 @@ public class NightDisplayTimeFormatter {
return mTimeFormatter.format(c.getTime());
}
- public String getAutoModeTimeSummary(Context context, ColorDisplayController controller) {
- final int summaryFormatResId = controller.isActivated() ? R.string.night_display_summary_on
- : R.string.night_display_summary_off;
- return context.getString(summaryFormatResId, getAutoModeSummary(context, controller));
+ public String getAutoModeTimeSummary(Context context, ColorDisplayManager manager) {
+ final int summaryFormatResId =
+ manager.isNightDisplayActivated() ? R.string.night_display_summary_on
+ : R.string.night_display_summary_off;
+ return context.getString(summaryFormatResId, getAutoModeSummary(context, manager));
}
- private String getAutoModeSummary(Context context, ColorDisplayController controller) {
- final boolean isActivated = controller.isActivated();
- final int autoMode = controller.getAutoMode();
+ private String getAutoModeSummary(Context context, ColorDisplayManager manager) {
+ final boolean isActivated = manager.isNightDisplayActivated();
+ final int autoMode = manager.getNightDisplayAutoMode();
if (autoMode == ColorDisplayManager.AUTO_MODE_CUSTOM_TIME) {
if (isActivated) {
return context.getString(R.string.night_display_summary_on_auto_mode_custom,
- getFormattedTimeString(controller.getCustomEndTime()));
+ getFormattedTimeString(manager.getNightDisplayCustomEndTime()));
} else {
return context.getString(R.string.night_display_summary_off_auto_mode_custom,
- getFormattedTimeString(controller.getCustomStartTime()));
+ getFormattedTimeString(manager.getNightDisplayCustomStartTime()));
}
} else if (autoMode == ColorDisplayManager.AUTO_MODE_TWILIGHT) {
return context.getString(isActivated
diff --git a/src/com/android/settings/homepage/contextualcards/legacysuggestion/LegacySuggestionContextualCardController.java b/src/com/android/settings/homepage/contextualcards/legacysuggestion/LegacySuggestionContextualCardController.java
index bbcebbe6a2e..3b0b46d2f2b 100644
--- a/src/com/android/settings/homepage/contextualcards/legacysuggestion/LegacySuggestionContextualCardController.java
+++ b/src/com/android/settings/homepage/contextualcards/legacysuggestion/LegacySuggestionContextualCardController.java
@@ -128,8 +128,10 @@ public class LegacySuggestionContextualCardController implements ContextualCardC
return;
}
final List suggestions = mSuggestionController.getSuggestions();
- Log.d(TAG, "Loaded suggests: "
- + suggestions == null ? "null" : String.valueOf(suggestions.size()));
+ final String suggestionCount = suggestions == null
+ ? "null"
+ : String.valueOf(suggestions.size());
+ Log.d(TAG, "Loaded suggests: " + suggestionCount);
final List cards = new ArrayList<>();
if (suggestions != null) {
diff --git a/src/com/android/settings/location/AppLocationPermissionPreferenceController.java b/src/com/android/settings/location/AppLocationPermissionPreferenceController.java
index 1fd19860659..43a6a9b26de 100644
--- a/src/com/android/settings/location/AppLocationPermissionPreferenceController.java
+++ b/src/com/android/settings/location/AppLocationPermissionPreferenceController.java
@@ -76,7 +76,7 @@ public class AppLocationPermissionPreferenceController extends
PermissionControllerManager permController =
mContext.getSystemService(PermissionControllerManager.class);
permController.countPermissionApps(
- Arrays.asList(ACCESS_FINE_LOCATION, ACCESS_COARSE_LOCATION), false, false,
+ Arrays.asList(ACCESS_FINE_LOCATION, ACCESS_COARSE_LOCATION), 0,
(numApps) -> {
mNumTotal = numApps;
if (loadingInProgress.decrementAndGet() == 0) {
@@ -85,7 +85,8 @@ public class AppLocationPermissionPreferenceController extends
}, null);
permController.countPermissionApps(
- Collections.singletonList(ACCESS_BACKGROUND_LOCATION), true, false,
+ Collections.singletonList(ACCESS_BACKGROUND_LOCATION),
+ PermissionControllerManager.COUNT_ONLY_WHEN_GRANTED,
(numApps) -> {
mNumBackground = numApps;
if (loadingInProgress.decrementAndGet() == 0) {
diff --git a/src/com/android/settings/location/LocationEnabler.java b/src/com/android/settings/location/LocationEnabler.java
index e1bdf162ef2..db5397330e1 100644
--- a/src/com/android/settings/location/LocationEnabler.java
+++ b/src/com/android/settings/location/LocationEnabler.java
@@ -15,9 +15,7 @@ package com.android.settings.location;
import static com.android.settingslib.RestrictedLockUtilsInternal.checkIfRestrictionEnforced;
import static com.android.settingslib.Utils.updateLocationEnabled;
-import static com.android.settingslib.Utils.updateLocationMode;
-import android.app.ActivityManager;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
@@ -125,26 +123,6 @@ public class LocationEnabler implements LifecycleObserver, OnStart, OnStop {
refreshLocationMode();
}
- void setLocationMode(int mode) {
- final int currentMode = Settings.Secure.getInt(mContext.getContentResolver(),
- Settings.Secure.LOCATION_MODE, Settings.Secure.LOCATION_MODE_OFF);
- if (isRestricted()) {
- // Location toggling disabled by user restriction. Read the current location mode to
- // update the location master switch.
- if (Log.isLoggable(TAG, Log.INFO)) {
- Log.i(TAG, "Restricted user, not setting location mode");
- }
- if (mListener != null) {
- mListener.onLocationModeChanged(currentMode, true);
- }
- return;
- }
-
- updateLocationMode(mContext, currentMode, mode, ActivityManager.getCurrentUser(),
- Settings.Secure.LOCATION_CHANGER_SYSTEM_SETTINGS);
- refreshLocationMode();
- }
-
boolean isEnabled(int mode) {
return mode != Settings.Secure.LOCATION_MODE_OFF && !isRestricted();
}
diff --git a/src/com/android/settings/location/TopLevelLocationPreferenceController.java b/src/com/android/settings/location/TopLevelLocationPreferenceController.java
index 6d7789fe4fe..2a7a3d7de2d 100644
--- a/src/com/android/settings/location/TopLevelLocationPreferenceController.java
+++ b/src/com/android/settings/location/TopLevelLocationPreferenceController.java
@@ -71,7 +71,7 @@ public class TopLevelLocationPreferenceController extends BasePreferenceControll
return;
}
mContext.getSystemService(PermissionControllerManager.class).countPermissionApps(
- Arrays.asList(ACCESS_FINE_LOCATION, ACCESS_COARSE_LOCATION), false, false,
+ Arrays.asList(ACCESS_FINE_LOCATION, ACCESS_COARSE_LOCATION), 0,
(numApps) -> {
setLocationAppCount(numApps);
}, null);
diff --git a/src/com/android/settings/network/telephony/MobileNetworkActivity.java b/src/com/android/settings/network/telephony/MobileNetworkActivity.java
index a5f011c8120..821b1e1e8d8 100644
--- a/src/com/android/settings/network/telephony/MobileNetworkActivity.java
+++ b/src/com/android/settings/network/telephony/MobileNetworkActivity.java
@@ -97,13 +97,6 @@ public class MobileNetworkActivity extends SettingsBaseActivity {
actionBar.setDisplayHomeAsUpEnabled(true);
}
- // Set the title to the name of the subscription. If we don't have subscription info, the
- // title will just default to the label for this activity that's already specified in
- // AndroidManifest.xml.
- final SubscriptionInfo subscription = getSubscription();
- if (subscription != null) {
- setTitle(subscription.getDisplayName());
- }
updateSubscriptions(savedInstanceState);
}
@@ -136,6 +129,14 @@ public class MobileNetworkActivity extends SettingsBaseActivity {
@VisibleForTesting
void updateSubscriptions(Bundle savedInstanceState) {
+ // Set the title to the name of the subscription. If we don't have subscription info, the
+ // title will just default to the label for this activity that's already specified in
+ // AndroidManifest.xml.
+ final SubscriptionInfo subscription = getSubscription();
+ if (subscription != null) {
+ setTitle(subscription.getDisplayName());
+ }
+
mSubscriptionInfos = mSubscriptionManager.getActiveSubscriptionInfoList(true);
if (!FeatureFlagPersistent.isEnabled(this, FeatureFlags.NETWORK_INTERNET_V2)) {
diff --git a/src/com/android/settings/network/telephony/MobileNetworkSettings.java b/src/com/android/settings/network/telephony/MobileNetworkSettings.java
index 52015868cf8..a4156f565dd 100644
--- a/src/com/android/settings/network/telephony/MobileNetworkSettings.java
+++ b/src/com/android/settings/network/telephony/MobileNetworkSettings.java
@@ -28,9 +28,9 @@ import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.util.Log;
-
-import androidx.annotation.VisibleForTesting;
-import androidx.preference.Preference;
+import android.view.Menu;
+import android.view.MenuInflater;
+import android.view.MenuItem;
import com.android.internal.telephony.TelephonyIntents;
import com.android.settings.R;
@@ -52,6 +52,9 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
+import androidx.annotation.VisibleForTesting;
+import androidx.preference.Preference;
+
@SearchIndexable(forTarget = SearchIndexable.ALL & ~SearchIndexable.ARC)
public class MobileNetworkSettings extends RestrictedDashboardFragment {
@@ -219,6 +222,31 @@ public class MobileNetworkSettings extends RestrictedDashboardFragment {
}
}
+ @Override
+ public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
+ if (FeatureFlagPersistent.isEnabled(getContext(), FeatureFlags.NETWORK_INTERNET_V2) &&
+ mSubId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
+ final MenuItem item = menu.add(Menu.NONE, R.id.edit_sim_name, Menu.NONE,
+ R.string.mobile_network_sim_name);
+ item.setIcon(com.android.internal.R.drawable.ic_mode_edit);
+ item.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
+ }
+ super.onCreateOptionsMenu(menu, inflater);
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem menuItem) {
+ if (FeatureFlagPersistent.isEnabled(getContext(), FeatureFlags.NETWORK_INTERNET_V2) &&
+ mSubId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
+ if (menuItem.getItemId() == R.id.edit_sim_name) {
+ RenameMobileNetworkDialogFragment.newInstance(mSubId).show(
+ getFragmentManager(), RenameMobileNetworkDialogFragment.TAG);
+ return true;
+ }
+ }
+ return super.onOptionsItemSelected(menuItem);
+ }
+
public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
new BaseSearchIndexProvider() {
@Override
diff --git a/src/com/android/settings/network/telephony/RenameMobileNetworkDialogFragment.java b/src/com/android/settings/network/telephony/RenameMobileNetworkDialogFragment.java
new file mode 100644
index 00000000000..488f9300e2e
--- /dev/null
+++ b/src/com/android/settings/network/telephony/RenameMobileNetworkDialogFragment.java
@@ -0,0 +1,137 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.network.telephony;
+
+import android.app.Dialog;
+import android.app.settings.SettingsEnums;
+import android.content.Context;
+import android.os.Bundle;
+import android.telephony.ServiceState;
+import android.telephony.SubscriptionInfo;
+import android.telephony.SubscriptionManager;
+import android.telephony.TelephonyManager;
+import android.text.BidiFormatter;
+import android.text.TextDirectionHeuristics;
+import android.text.TextUtils;
+import android.util.Log;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.widget.EditText;
+import android.widget.TextView;
+
+import com.android.settings.R;
+import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
+import com.android.settingslib.DeviceInfoUtils;
+
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+import androidx.annotation.VisibleForTesting;
+import androidx.appcompat.app.AlertDialog;
+
+/** A dialog allowing the display name of a mobile network subscription to be changed */
+public class RenameMobileNetworkDialogFragment extends InstrumentedDialogFragment {
+ public static final String TAG ="RenameMobileNetwork";
+
+ private static final String KEY_SUBSCRIPTION_ID = "subscription_id";
+
+ private TelephonyManager mTelephonyManager;
+ private SubscriptionManager mSubscriptionManager;
+ private int mSubId;
+ private EditText mNameView;
+
+ public static RenameMobileNetworkDialogFragment newInstance(int subscriptionId) {
+ final Bundle args = new Bundle(1);
+ args.putInt(KEY_SUBSCRIPTION_ID, subscriptionId);
+ final RenameMobileNetworkDialogFragment fragment = new RenameMobileNetworkDialogFragment();
+ fragment.setArguments(args);
+ return fragment;
+ }
+
+ @VisibleForTesting
+ protected TelephonyManager getTelephonyManager(Context context) {
+ return context.getSystemService(TelephonyManager.class);
+ }
+
+ @VisibleForTesting
+ protected SubscriptionManager getSubscriptionManager(Context context) {
+ return context.getSystemService(SubscriptionManager.class);
+ }
+
+ @VisibleForTesting
+ protected EditText getNameView() {
+ return mNameView;
+ }
+
+ @Override
+ public void onAttach(Context context) {
+ super.onAttach(context);
+ mTelephonyManager = getTelephonyManager(context);
+ mSubscriptionManager = getSubscriptionManager(context);
+ mSubId = getArguments().getInt(KEY_SUBSCRIPTION_ID);
+ }
+
+ @NonNull
+ @Override
+ public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
+ final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
+ final LayoutInflater layoutInflater = builder.getContext().getSystemService(
+ LayoutInflater.class);
+ final View view = layoutInflater.inflate(R.layout.dialog_mobile_network_rename, null);
+ populateView(view);
+ builder.setTitle(R.string.mobile_network_sim_name)
+ .setView(view)
+ .setPositiveButton(R.string.mobile_network_sim_name_rename, (dialog, which) -> {
+ SubscriptionInfo currentInfo = mSubscriptionManager.getActiveSubscriptionInfo(
+ mSubId);
+ String newName = mNameView.getText().toString();
+ if (currentInfo != null && !currentInfo.getDisplayName().equals(newName)) {
+ mSubscriptionManager.setDisplayName(newName, mSubId);
+ }
+ })
+ .setNegativeButton(android.R.string.cancel, null);
+ return builder.create();
+ }
+
+ @VisibleForTesting
+ protected void populateView(View view) {
+ mNameView = (EditText) view.findViewById(R.id.edittext);
+ final SubscriptionInfo info = mSubscriptionManager.getActiveSubscriptionInfo(mSubId);
+ if (info == null) {
+ Log.w(TAG, "got null SubscriptionInfo for mSubId:" + mSubId);
+ return;
+ }
+ final CharSequence displayName = info.getDisplayName();
+ mNameView.setText(displayName);
+ if (!TextUtils.isEmpty(displayName)) {
+ mNameView.setSelection(displayName.length());
+ }
+
+ final TextView operatorName = view.findViewById(R.id.operator_name_value);
+ final ServiceState serviceState = mTelephonyManager.getServiceStateForSubscriber(mSubId);
+ operatorName.setText(serviceState.getOperatorAlphaLong());
+
+ final TextView phoneNumber = view.findViewById(R.id.number_value);
+ final String formattedNumber = DeviceInfoUtils.getFormattedPhoneNumber(getContext(), info);
+ phoneNumber.setText(BidiFormatter.getInstance().unicodeWrap(formattedNumber,
+ TextDirectionHeuristics.LTR));
+ }
+
+ @Override
+ public int getMetricsCategory() {
+ return SettingsEnums.MOBILE_NETWORK_RENAME_DIALOG;
+ }
+}
diff --git a/src/com/android/settings/notification/SilentStatusBarPreferenceController.java b/src/com/android/settings/notification/SilentStatusBarPreferenceController.java
index 4721f5c9b27..5bf943ac37a 100644
--- a/src/com/android/settings/notification/SilentStatusBarPreferenceController.java
+++ b/src/com/android/settings/notification/SilentStatusBarPreferenceController.java
@@ -24,17 +24,24 @@ import android.provider.Settings;
import com.android.settings.core.TogglePreferenceController;
+import com.google.common.annotations.VisibleForTesting;
+
public class SilentStatusBarPreferenceController extends TogglePreferenceController {
private static final String KEY = "hide_silent_icons";
private static final int MY_USER_ID = UserHandle.myUserId();
- private final NotificationBackend mBackend;
+ private NotificationBackend mBackend;
public SilentStatusBarPreferenceController(Context context) {
super(context, KEY);
mBackend = new NotificationBackend();
}
+ @VisibleForTesting
+ void setBackend(NotificationBackend backend) {
+ mBackend = backend;
+ }
+
@Override
public boolean isChecked() {
return mBackend.shouldHideSilentStatusBarIcons(mContext);
diff --git a/src/com/android/settings/security/trustagent/TrustAgentManager.java b/src/com/android/settings/security/trustagent/TrustAgentManager.java
index e039db8d8a5..f5c693aba23 100644
--- a/src/com/android/settings/security/trustagent/TrustAgentManager.java
+++ b/src/com/android/settings/security/trustagent/TrustAgentManager.java
@@ -53,7 +53,7 @@ import java.util.List;
public class TrustAgentManager {
// Only allow one trust agent on the platform.
- private static final boolean ONLY_ONE_TRUST_AGENT = true;
+ private static final boolean ONLY_ONE_TRUST_AGENT = false;
public static class TrustAgentComponentInfo {
public ComponentName componentName;
diff --git a/src/com/android/settings/widget/EntityHeaderController.java b/src/com/android/settings/widget/EntityHeaderController.java
index 567217883a5..8e31290577e 100644
--- a/src/com/android/settings/widget/EntityHeaderController.java
+++ b/src/com/android/settings/widget/EntityHeaderController.java
@@ -322,7 +322,7 @@ public class EntityHeaderController {
Utils.getColorAttrDefaultColor(activity, android.R.attr.colorPrimaryDark)));
actionBar.setElevation(0);
if (mRecyclerView != null && mLifecycle != null) {
- ActionBarShadowController.attachToRecyclerView(mActivity, mLifecycle, mRecyclerView);
+ ActionBarShadowController.attachToView(mActivity, mLifecycle, mRecyclerView);
}
return this;
diff --git a/src/com/android/settings/wifi/WifiConfigController.java b/src/com/android/settings/wifi/WifiConfigController.java
index 739ddd70200..1d78485a94b 100644
--- a/src/com/android/settings/wifi/WifiConfigController.java
+++ b/src/com/android/settings/wifi/WifiConfigController.java
@@ -366,9 +366,8 @@ public class WifiConfigController implements TextWatcher,
suggestionOrSpecifierPackageName = config.creatorName;
}
String summary = AccessPoint.getSummary(
- mConfigUi.getContext(), state, isEphemeral,
- suggestionOrSpecifierPackageName,
- providerFriendlyName);
+ mConfigUi.getContext(), /* ssid */ null, state, isEphemeral,
+ suggestionOrSpecifierPackageName);
addRow(group, R.string.wifi_status, summary);
}
diff --git a/src/com/android/settings/wifi/WifiSettings.java b/src/com/android/settings/wifi/WifiSettings.java
index 3a0040c385e..881e3d2db15 100644
--- a/src/com/android/settings/wifi/WifiSettings.java
+++ b/src/com/android/settings/wifi/WifiSettings.java
@@ -562,24 +562,24 @@ public class WifiSettings extends RestrictedSettingsFragment
* Bypass dialog and connect to unsecured networks, or previously connected saved
* networks, or Passpoint provided networks.
*/
- WifiConfiguration config = mSelectedAccessPoint.getConfig();
- if (mSelectedAccessPoint.isOsuProvider()) {
- mSelectedAccessPoint.startOsuProvisioning();
- mClickedConnect = true;
- } else if ((mSelectedAccessPoint.getSecurity() == AccessPoint.SECURITY_NONE) ||
- (mSelectedAccessPoint.getSecurity() == AccessPoint.SECURITY_OWE)) {
- mSelectedAccessPoint.generateOpenNetworkConfig();
- connect(mSelectedAccessPoint.getConfig(), mSelectedAccessPoint.isSaved());
- } else if (mSelectedAccessPoint.isSaved() && config != null
- && config.getNetworkSelectionStatus() != null
- && config.getNetworkSelectionStatus().getHasEverConnected()) {
- connect(config, true /* isSavedNetwork */);
- } else if (mSelectedAccessPoint.isPasspoint()) {
- // Access point provided by an installed Passpoint provider, connect using
- // the associated config.
- connect(config, true /* isSavedNetwork */);
- } else {
- showDialog(mSelectedAccessPoint, WifiConfigUiBase.MODE_CONNECT);
+ switch (WifiUtils.getConnectingType(mSelectedAccessPoint)) {
+ case WifiUtils.CONNECT_TYPE_OSU_PROVISION:
+ mSelectedAccessPoint.startOsuProvisioning();
+ mClickedConnect = true;
+ break;
+
+ case WifiUtils.CONNECT_TYPE_OPEN_NETWORK:
+ mSelectedAccessPoint.generateOpenNetworkConfig();
+ connect(mSelectedAccessPoint.getConfig(), mSelectedAccessPoint.isSaved());
+ break;
+
+ case WifiUtils.CONNECT_TYPE_SAVED_NETWORK:
+ connect(mSelectedAccessPoint.getConfig(), true /* isSavedNetwork */);
+ break;
+
+ default:
+ showDialog(mSelectedAccessPoint, WifiConfigUiBase.MODE_CONNECT);
+ break;
}
} else if (preference == mAddPreference) {
onAddNetworkPressed();
diff --git a/src/com/android/settings/wifi/WifiStatusTest.java b/src/com/android/settings/wifi/WifiStatusTest.java
index b06343331f3..ca7f5f7fecd 100644
--- a/src/com/android/settings/wifi/WifiStatusTest.java
+++ b/src/com/android/settings/wifi/WifiStatusTest.java
@@ -299,7 +299,8 @@ public class WifiStatusTest extends Activity {
WifiInfo info = mWifiManager.getConnectionInfo();
String summary = AccessPoint.getSummary(this, info.getSSID(),
networkInfo.getDetailedState(),
- info.getNetworkId() == WifiConfiguration.INVALID_NETWORK_ID, null, null);
+ info.getNetworkId() == WifiConfiguration.INVALID_NETWORK_ID,
+ /* suggestionOrSpecifierPackageName */ null);
mNetworkState.setText(summary);
}
}
diff --git a/src/com/android/settings/wifi/WifiUtils.java b/src/com/android/settings/wifi/WifiUtils.java
index 751fc9176d3..a22bdba868d 100644
--- a/src/com/android/settings/wifi/WifiUtils.java
+++ b/src/com/android/settings/wifi/WifiUtils.java
@@ -253,4 +253,33 @@ public class WifiUtils {
return AccessPoint.SECURITY_NONE;
}
+
+
+ public static final int CONNECT_TYPE_OTHERS = 0;
+ public static final int CONNECT_TYPE_OPEN_NETWORK = 1;
+ public static final int CONNECT_TYPE_SAVED_NETWORK = 2;
+ public static final int CONNECT_TYPE_OSU_PROVISION = 3;
+
+ /**
+ * Gets the connecting type of {@link AccessPoint}.
+ */
+ public static int getConnectingType(AccessPoint accessPoint) {
+ final WifiConfiguration config = accessPoint.getConfig();
+ if (accessPoint.isOsuProvider()) {
+ return CONNECT_TYPE_OSU_PROVISION;
+ } else if ((accessPoint.getSecurity() == AccessPoint.SECURITY_NONE) ||
+ (accessPoint.getSecurity() == AccessPoint.SECURITY_OWE)) {
+ return CONNECT_TYPE_OPEN_NETWORK;
+ } else if (accessPoint.isSaved() && config != null
+ && config.getNetworkSelectionStatus() != null
+ && config.getNetworkSelectionStatus().getHasEverConnected()) {
+ return CONNECT_TYPE_SAVED_NETWORK;
+ } else if (accessPoint.isPasspoint()) {
+ // Access point provided by an installed Passpoint provider, connect using
+ // the associated config.
+ return CONNECT_TYPE_SAVED_NETWORK;
+ } else {
+ return CONNECT_TYPE_OTHERS;
+ }
+ }
}
diff --git a/src/com/android/settings/wifi/slice/ConnectToWifiHandler.java b/src/com/android/settings/wifi/slice/ConnectToWifiHandler.java
new file mode 100644
index 00000000000..7b21b65a8e0
--- /dev/null
+++ b/src/com/android/settings/wifi/slice/ConnectToWifiHandler.java
@@ -0,0 +1,63 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.wifi.slice;
+
+import android.app.Activity;
+import android.net.wifi.WifiManager;
+import android.os.Bundle;
+
+import androidx.annotation.VisibleForTesting;
+
+import com.android.settings.wifi.WifiDialogActivity;
+import com.android.settings.wifi.WifiUtils;
+import com.android.settingslib.wifi.AccessPoint;
+
+/**
+ * This activity helps connect to the Wi-Fi network which is open or saved
+ */
+public class ConnectToWifiHandler extends Activity {
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ final Bundle accessPointState = getIntent().getBundleExtra(
+ WifiDialogActivity.KEY_ACCESS_POINT_STATE);
+
+ if (accessPointState != null) {
+ connect(new AccessPoint(this, accessPointState));
+ }
+ finish();
+ }
+
+ @VisibleForTesting
+ void connect(AccessPoint accessPoint) {
+ switch (WifiUtils.getConnectingType(accessPoint)) {
+ case WifiUtils.CONNECT_TYPE_OSU_PROVISION:
+ accessPoint.startOsuProvisioning();
+ break;
+
+ case WifiUtils.CONNECT_TYPE_OPEN_NETWORK:
+ accessPoint.generateOpenNetworkConfig();
+
+ case WifiUtils.CONNECT_TYPE_SAVED_NETWORK:
+ final WifiManager wifiManager = getSystemService(WifiManager.class);
+ wifiManager.connect(accessPoint.getConfig(), null /* listener */);
+ break;
+ }
+ }
+}
diff --git a/src/com/android/settings/wifi/slice/WifiSlice.java b/src/com/android/settings/wifi/slice/WifiSlice.java
index 88fa8b298ef..1a0ed0ce90e 100644
--- a/src/com/android/settings/wifi/slice/WifiSlice.java
+++ b/src/com/android/settings/wifi/slice/WifiSlice.java
@@ -48,6 +48,7 @@ import com.android.settings.slices.SliceBackgroundWorker;
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.details.WifiNetworkDetailsFragment;
import com.android.settingslib.wifi.AccessPoint;
import com.android.settingslib.wifi.WifiTracker;
@@ -176,6 +177,9 @@ public class WifiSlice implements CustomSliceable {
.setArguments(extras)
.setSourceMetricsCategory(SettingsEnums.WIFI)
.toIntent();
+ } else if (WifiUtils.getConnectingType(accessPoint) != WifiUtils.CONNECT_TYPE_OTHERS) {
+ intent = new Intent(mContext, ConnectToWifiHandler.class);
+ intent.putExtra(WifiDialogActivity.KEY_ACCESS_POINT_STATE, extras);
} else {
intent = new Intent(mContext, WifiDialogActivity.class);
intent.putExtra(WifiDialogActivity.KEY_ACCESS_POINT_STATE, extras);
diff --git a/tests/robotests/src/com/android/settings/accounts/AccountDetailDashboardFragmentTest.java b/tests/robotests/src/com/android/settings/accounts/AccountDetailDashboardFragmentTest.java
index 0be51c31d29..dffa96861c2 100644
--- a/tests/robotests/src/com/android/settings/accounts/AccountDetailDashboardFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/accounts/AccountDetailDashboardFragmentTest.java
@@ -15,6 +15,8 @@
*/
package com.android.settings.accounts;
+import static android.content.Intent.EXTRA_USER;
+
import static com.android.settingslib.drawer.TileUtils.META_DATA_PREFERENCE_KEYHINT;
import static com.android.settingslib.drawer.TileUtils.META_DATA_PREFERENCE_TITLE;
@@ -160,6 +162,20 @@ public class AccountDetailDashboardFragmentTest {
assertThat(intent.getStringExtra("extra.accountName")).isEqualTo("name1@abc.com");
}
+ @Test
+ public void displayTile_shouldAddUserHandleToTileIntent() {
+ mFragment.mUserHandle = new UserHandle(1);
+
+ final Tile tile = new Tile(mActivityInfo, CategoryKey.CATEGORY_ACCOUNT_DETAIL);
+ mActivityInfo.metaData.putString(METADATA_CATEGORY, CategoryKey.CATEGORY_ACCOUNT);
+ mActivityInfo.metaData.putString(METADATA_ACCOUNT_TYPE, "com.abc");
+
+ mFragment.displayTile(tile);
+
+ final UserHandle userHandle = tile.getIntent().getParcelableExtra(EXTRA_USER);
+ assertThat(userHandle.getIdentifier()).isEqualTo(1);
+ }
+
@Test
public void onResume_accountMissing_shouldFinish() {
ShadowUserManager userManager =
diff --git a/tests/robotests/src/com/android/settings/dashboard/DashboardFeatureProviderImplTest.java b/tests/robotests/src/com/android/settings/dashboard/DashboardFeatureProviderImplTest.java
index 2aa6ae22ff8..1c51b81a5e9 100644
--- a/tests/robotests/src/com/android/settings/dashboard/DashboardFeatureProviderImplTest.java
+++ b/tests/robotests/src/com/android/settings/dashboard/DashboardFeatureProviderImplTest.java
@@ -16,6 +16,8 @@
package com.android.settings.dashboard;
+import static android.content.Intent.EXTRA_USER;
+
import static com.android.settingslib.drawer.TileUtils.META_DATA_KEY_ORDER;
import static com.android.settingslib.drawer.TileUtils.META_DATA_KEY_PROFILE;
import static com.android.settingslib.drawer.TileUtils.META_DATA_PREFERENCE_KEYHINT;
@@ -67,6 +69,7 @@ import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Answers;
+import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.Robolectric;
@@ -412,4 +415,44 @@ public class DashboardFeatureProviderImplTest {
.startActivityForResult(any(Intent.class), eq(0));
verify(mActivity, never()).getSupportFragmentManager();
}
+
+ @Test
+ public void openTileIntent_profileSelectionDialog_validUserHandleShouldNotShow() {
+ final int userId = 10;
+ ShadowUserManager.getShadow().addUser(userId, "Someone", 0);
+
+ final UserHandle userHandle = new UserHandle(userId);
+ final Tile tile = new Tile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE);
+ tile.getIntent().putExtra(EXTRA_USER, userHandle);
+ final ArrayList handles = new ArrayList<>();
+ handles.add(new UserHandle(0));
+ handles.add(userHandle);
+ tile.userHandle = handles;
+
+ mImpl.openTileIntent(mActivity, tile);
+
+ final ArgumentCaptor argument = ArgumentCaptor.forClass(UserHandle.class);
+ verify(mActivity)
+ .startActivityForResultAsUser(any(Intent.class), anyInt(), argument.capture());
+ assertThat(argument.getValue().getIdentifier()).isEqualTo(userId);
+ verify(mActivity, never()).getSupportFragmentManager();
+ }
+
+ @Test
+ public void openTileIntent_profileSelectionDialog_invalidUserHandleShouldShow() {
+ ShadowUserManager.getShadow().addUser(10, "Someone", 0);
+
+ final Tile tile = new Tile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE);
+ tile.getIntent().putExtra(EXTRA_USER, new UserHandle(30));
+ final ArrayList handles = new ArrayList<>();
+ handles.add(new UserHandle(0));
+ handles.add(new UserHandle(10));
+ tile.userHandle = handles;
+
+ mImpl.openTileIntent(mActivity, tile);
+
+ verify(mActivity, never())
+ .startActivityForResultAsUser(any(Intent.class), anyInt(), any(UserHandle.class));
+ verify(mActivity).getSupportFragmentManager();
+ }
}
diff --git a/tests/robotests/src/com/android/settings/development/gamedriver/GameDriverEnableForAllAppsPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/development/gamedriver/GameDriverEnableForAllAppsPreferenceControllerTest.java
index 094cd21b3e5..3d418d9da92 100644
--- a/tests/robotests/src/com/android/settings/development/gamedriver/GameDriverEnableForAllAppsPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/development/gamedriver/GameDriverEnableForAllAppsPreferenceControllerTest.java
@@ -21,6 +21,7 @@ import static com.android.settings.core.BasePreferenceController.CONDITIONALLY_U
import static com.android.settings.development.gamedriver.GameDriverEnableForAllAppsPreferenceController.GAME_DRIVER_ALL_APPS;
import static com.android.settings.development.gamedriver.GameDriverEnableForAllAppsPreferenceController.GAME_DRIVER_DEFAULT;
import static com.android.settings.development.gamedriver.GameDriverEnableForAllAppsPreferenceController.GAME_DRIVER_OFF;
+
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.atLeastOnce;
@@ -61,11 +62,14 @@ public class GameDriverEnableForAllAppsPreferenceControllerTest {
MockitoAnnotations.initMocks(this);
mContext = RuntimeEnvironment.application;
mResolver = mContext.getContentResolver();
+
+ Settings.Global.putInt(mResolver, Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 1);
+ Settings.Global.putInt(
+ mResolver, Settings.Global.GAME_DRIVER_ALL_APPS, GAME_DRIVER_DEFAULT);
+
mController = new GameDriverEnableForAllAppsPreferenceController(mContext, "testKey");
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
mController.displayPreference(mScreen);
-
- Settings.Global.putInt(mResolver, Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 1);
}
@Test
@@ -151,7 +155,7 @@ public class GameDriverEnableForAllAppsPreferenceControllerTest {
mController.onPreferenceChange(mPreference, true);
assertThat(Settings.Global.getInt(
- mResolver, Settings.Global.GAME_DRIVER_ALL_APPS, GAME_DRIVER_DEFAULT))
+ mResolver, Settings.Global.GAME_DRIVER_ALL_APPS, GAME_DRIVER_DEFAULT))
.isEqualTo(GAME_DRIVER_ALL_APPS);
}
@@ -162,7 +166,7 @@ public class GameDriverEnableForAllAppsPreferenceControllerTest {
mController.onPreferenceChange(mPreference, false);
assertThat(Settings.Global.getInt(
- mResolver, Settings.Global.GAME_DRIVER_ALL_APPS, GAME_DRIVER_DEFAULT))
+ mResolver, Settings.Global.GAME_DRIVER_ALL_APPS, GAME_DRIVER_DEFAULT))
.isEqualTo(GAME_DRIVER_DEFAULT);
}
}
diff --git a/tests/robotests/src/com/android/settings/homepage/contextualcards/legacysuggestion/LegacySuggestionContextualCardControllerTest.java b/tests/robotests/src/com/android/settings/homepage/contextualcards/legacysuggestion/LegacySuggestionContextualCardControllerTest.java
index ebc2154a009..a2d4d093c42 100644
--- a/tests/robotests/src/com/android/settings/homepage/contextualcards/legacysuggestion/LegacySuggestionContextualCardControllerTest.java
+++ b/tests/robotests/src/com/android/settings/homepage/contextualcards/legacysuggestion/LegacySuggestionContextualCardControllerTest.java
@@ -19,6 +19,7 @@ package com.android.settings.homepage.contextualcards.legacysuggestion;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
import android.content.Context;
@@ -84,8 +85,10 @@ public class LegacySuggestionContextualCardControllerTest {
@Test
public void onServiceConnected_shouldLoadSuggestion() {
+ when(mSuggestionController.getSuggestions()).thenReturn(null);
mController.mSuggestionController = mSuggestionController;
mController.setCardUpdateListener(mCardUpdateListener);
+
mController.onServiceConnected();
verify(mSuggestionController).getSuggestions();
diff --git a/tests/robotests/src/com/android/settings/location/LocationEnablerTest.java b/tests/robotests/src/com/android/settings/location/LocationEnablerTest.java
index 806e2ecf980..fbae2f45b16 100644
--- a/tests/robotests/src/com/android/settings/location/LocationEnablerTest.java
+++ b/tests/robotests/src/com/android/settings/location/LocationEnablerTest.java
@@ -141,57 +141,6 @@ public class LocationEnablerTest {
verify(mListener).onLocationModeChanged(anyInt(), anyBoolean());
}
- @Test
- public void setLocationMode_restricted_shouldSetCurrentMode() {
- when(mUserManager.hasUserRestriction(anyString())).thenReturn(true);
- Settings.Secure.putInt(mContext.getContentResolver(),
- Settings.Secure.LOCATION_MODE, Settings.Secure.LOCATION_MODE_BATTERY_SAVING);
-
- mEnabler.setLocationMode(Settings.Secure.LOCATION_MODE_HIGH_ACCURACY);
-
- verify(mListener).onLocationModeChanged(Settings.Secure.LOCATION_MODE_BATTERY_SAVING, true);
- }
-
- @Test
- public void setLocationMode_notRestricted_shouldUpdateSecureSettings() {
- when(mUserManager.hasUserRestriction(anyString())).thenReturn(false);
- Settings.Secure.putInt(mContext.getContentResolver(),
- Settings.Secure.LOCATION_MODE, Settings.Secure.LOCATION_MODE_BATTERY_SAVING);
-
- mEnabler.setLocationMode(Settings.Secure.LOCATION_MODE_HIGH_ACCURACY);
-
- assertThat(Settings.Secure.getInt(mContext.getContentResolver(),
- Settings.Secure.LOCATION_MODE, Settings.Secure.LOCATION_MODE_BATTERY_SAVING))
- .isEqualTo(Settings.Secure.LOCATION_MODE_HIGH_ACCURACY);
- }
-
- @Test
- public void setLocationMode_notRestricted_shouldRefreshLocation() {
- when(mUserManager.hasUserRestriction(anyString())).thenReturn(false);
- Settings.Secure.putInt(mContext.getContentResolver(),
- Settings.Secure.LOCATION_MODE, Settings.Secure.LOCATION_MODE_BATTERY_SAVING);
-
- mEnabler.setLocationMode(Settings.Secure.LOCATION_MODE_HIGH_ACCURACY);
-
- verify(mEnabler).refreshLocationMode();
- }
-
- @Test
- public void setLocationMode_notRestricted_shouldBroadcastUpdateAndSetChanger() {
- when(mUserManager.hasUserRestriction(anyString())).thenReturn(false);
- Settings.Secure.putInt(mContext.getContentResolver(),
- Settings.Secure.LOCATION_MODE, Settings.Secure.LOCATION_MODE_BATTERY_SAVING);
- mEnabler.setLocationMode(Settings.Secure.LOCATION_MODE_HIGH_ACCURACY);
-
- verify(mContext).sendBroadcastAsUser(
- argThat(actionMatches(LocationManager.MODE_CHANGING_ACTION)),
- eq(UserHandle.of(ActivityManager.getCurrentUser())),
- eq(WRITE_SECURE_SETTINGS));
- assertThat(Settings.Secure.getInt(mContext.getContentResolver(),
- Settings.Secure.LOCATION_CHANGER, Settings.Secure.LOCATION_CHANGER_UNKNOWN))
- .isEqualTo(Settings.Secure.LOCATION_CHANGER_SYSTEM_SETTINGS);
- }
-
@Test
public void setLocationEnabled_notRestricted_shouldRefreshLocation() {
when(mUserManager.hasUserRestriction(anyString())).thenReturn(false);
diff --git a/tests/robotests/src/com/android/settings/network/telephony/RenameMobileNetworkDialogFragmentTest.java b/tests/robotests/src/com/android/settings/network/telephony/RenameMobileNetworkDialogFragmentTest.java
new file mode 100644
index 00000000000..df523029414
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/network/telephony/RenameMobileNetworkDialogFragmentTest.java
@@ -0,0 +1,130 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.network.telephony;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import android.content.DialogInterface;
+import android.telephony.ServiceState;
+import android.telephony.SubscriptionInfo;
+import android.telephony.SubscriptionManager;
+import android.telephony.TelephonyManager;
+import android.widget.Button;
+import android.widget.EditText;
+
+import com.android.settings.testutils.shadow.ShadowAlertDialogCompat;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.ArgumentCaptor;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.Robolectric;
+import org.robolectric.RobolectricTestRunner;
+import org.robolectric.annotation.Config;
+
+import androidx.appcompat.app.AlertDialog;
+import androidx.fragment.app.FragmentActivity;
+
+@RunWith(RobolectricTestRunner.class)
+@Config(shadows = ShadowAlertDialogCompat.class)
+public class RenameMobileNetworkDialogFragmentTest {
+ @Mock
+ private TelephonyManager mTelephonyMgr;
+ @Mock
+ private SubscriptionManager mSubscriptionMgr;
+ @Mock
+ private SubscriptionInfo mSubscriptionInfo;
+
+ private FragmentActivity mActivity;
+ private RenameMobileNetworkDialogFragment mFragment;
+ private int mSubscriptionId = 1234;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ mActivity = spy(Robolectric.buildActivity(FragmentActivity.class).setup().get());
+
+ when(mSubscriptionInfo.getSubscriptionId()).thenReturn(mSubscriptionId);
+ when(mSubscriptionInfo.getDisplayName()).thenReturn("test");
+
+ mFragment = spy(RenameMobileNetworkDialogFragment.newInstance(mSubscriptionId));
+ doReturn(mTelephonyMgr).when(mFragment).getTelephonyManager(any());
+ doReturn(mSubscriptionMgr).when(mFragment).getSubscriptionManager(any());
+
+ final ServiceState serviceState = mock(ServiceState.class);
+ when(serviceState.getOperatorAlphaLong()).thenReturn("fake carrier name");
+ when(mTelephonyMgr.getServiceStateForSubscriber(mSubscriptionId)).thenReturn(serviceState);
+ }
+
+ @Test
+ public void dialog_subscriptionMissing_noCrash() {
+ final AlertDialog dialog = startDialog();
+ final Button negativeButton = dialog.getButton(DialogInterface.BUTTON_NEGATIVE);
+ assertThat(negativeButton).isNotNull();
+ negativeButton.performClick();
+ }
+
+ @Test
+ public void dialog_cancelButtonClicked_setDisplayNameNotCalled() {
+ when(mSubscriptionMgr.getActiveSubscriptionInfo(mSubscriptionId)).thenReturn(
+ mSubscriptionInfo);
+ final AlertDialog dialog = startDialog();
+ final EditText nameView = mFragment.getNameView();
+ nameView.setText("test2");
+
+ final Button negativeButton = dialog.getButton(DialogInterface.BUTTON_NEGATIVE);
+ negativeButton.performClick();
+
+ verify(mSubscriptionMgr, never()).setDisplayName(anyString(), anyInt());
+ }
+
+ @Test
+ public void dialog_renameButtonClicked_setDisplayNameCalled() {
+ when(mSubscriptionMgr.getActiveSubscriptionInfo(mSubscriptionId)).thenReturn(
+ mSubscriptionInfo);
+
+ final AlertDialog dialog = startDialog();
+ final EditText nameView = mFragment.getNameView();
+ nameView.setText("test2");
+
+ final Button positiveButton = dialog.getButton(DialogInterface.BUTTON_POSITIVE);
+ positiveButton.performClick();
+
+ final ArgumentCaptor captor = ArgumentCaptor.forClass(String.class);
+ verify(mSubscriptionMgr).setDisplayName(captor.capture(), eq(mSubscriptionId));
+ assertThat(captor.getValue()).isEqualTo("test2");
+ }
+
+ /** Helper method to start the dialog */
+ private AlertDialog startDialog() {
+ mFragment.show(mActivity.getSupportFragmentManager(), null);
+ return ShadowAlertDialogCompat.getLatestAlertDialog();
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/notification/SilentStatusBarPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/SilentStatusBarPreferenceControllerTest.java
index 8a43a1ea2c4..9dd8ff9f5c6 100644
--- a/tests/robotests/src/com/android/settings/notification/SilentStatusBarPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/notification/SilentStatusBarPreferenceControllerTest.java
@@ -48,7 +48,6 @@ public class SilentStatusBarPreferenceControllerTest {
@Mock
private PreferenceScreen mScreen;
- private FakeFeatureFactory mFeatureFactory;
private Context mContext;
private SilentStatusBarPreferenceController mController;
private Preference mPreference;
@@ -57,8 +56,8 @@ public class SilentStatusBarPreferenceControllerTest {
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = RuntimeEnvironment.application;
- mFeatureFactory = FakeFeatureFactory.setupForTest();
mController = new SilentStatusBarPreferenceController(mContext);
+ mController.setBackend(mBackend);
mPreference = new Preference(mContext);
mPreference.setKey(mController.getPreferenceKey());
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
@@ -83,7 +82,7 @@ public class SilentStatusBarPreferenceControllerTest {
when(mBackend.shouldHideSilentStatusBarIcons(any())).thenReturn(false);
assertThat(mController.isChecked()).isFalse();
}
-/**
+
@Test
public void isChecked_settingIsOn_true() {
when(mBackend.shouldHideSilentStatusBarIcons(any())).thenReturn(true);
@@ -93,18 +92,13 @@ public class SilentStatusBarPreferenceControllerTest {
@Test
public void onPreferenceChange_on() {
mController.onPreferenceChange(mPreference, true);
-
- assertThat(mController.isChecked()).isTrue();
verify(mBackend).setHideSilentStatusIcons(true);
}
@Test
public void onPreferenceChange_off() {
mController.onPreferenceChange(mPreference, false);
-
- assertThat(mController.isChecked()).isFalse();
verify(mBackend).setHideSilentStatusIcons(false);
}
- **/
}
diff --git a/tests/robotests/src/com/android/settings/wifi/slice/ConnectToWifiHandlerTest.java b/tests/robotests/src/com/android/settings/wifi/slice/ConnectToWifiHandlerTest.java
new file mode 100644
index 00000000000..a7cf327a245
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/wifi/slice/ConnectToWifiHandlerTest.java
@@ -0,0 +1,117 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.wifi.slice;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import android.net.wifi.WifiConfiguration;
+import android.net.wifi.WifiConfiguration.NetworkSelectionStatus;
+
+import com.android.settings.testutils.shadow.ShadowConnectivityManager;
+import com.android.settings.testutils.shadow.ShadowWifiManager;
+import com.android.settingslib.wifi.AccessPoint;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.Robolectric;
+import org.robolectric.RobolectricTestRunner;
+import org.robolectric.annotation.Config;
+
+@RunWith(RobolectricTestRunner.class)
+@Config(shadows = {
+ ShadowConnectivityManager.class,
+ ShadowWifiManager.class,
+})
+public class ConnectToWifiHandlerTest {
+
+ private static final String AP1_SSID = "\"ap1\"";
+ private ConnectToWifiHandler mHandler;
+ private WifiConfiguration mWifiConfig;
+ @Mock
+ private AccessPoint mAccessPoint;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+
+ mHandler = Robolectric.setupActivity(ConnectToWifiHandler.class);
+ mWifiConfig = new WifiConfiguration();
+ mWifiConfig.SSID = AP1_SSID;
+ doReturn(mWifiConfig).when(mAccessPoint).getConfig();
+ }
+
+ @Test
+ public void connect_shouldConnectToUnsavedOpenNetwork() {
+ when(mAccessPoint.isSaved()).thenReturn(false);
+ when(mAccessPoint.getSecurity()).thenReturn(AccessPoint.SECURITY_NONE);
+
+ mHandler.connect(mAccessPoint);
+
+ assertThat(ShadowWifiManager.get().savedWifiConfig.SSID).isEqualTo(AP1_SSID);
+ }
+
+ @Test
+ public void connect_shouldStartOsuProvisioning() {
+ when(mAccessPoint.isSaved()).thenReturn(false);
+ when(mAccessPoint.isOsuProvider()).thenReturn(true);
+
+ mHandler.connect(mAccessPoint);
+
+ verify(mAccessPoint).startOsuProvisioning();
+ }
+
+
+ @Test
+ public void connect_shouldConnectWithPasspointProvider() {
+ when(mAccessPoint.isSaved()).thenReturn(false);
+ when(mAccessPoint.isPasspoint()).thenReturn(true);
+
+ mHandler.connect(mAccessPoint);
+
+ assertThat(ShadowWifiManager.get().savedWifiConfig.SSID).isEqualTo(AP1_SSID);
+ }
+
+ @Test
+ public void connect_shouldConnectToSavedSecuredNetwork() {
+ when(mAccessPoint.isSaved()).thenReturn(true);
+ when(mAccessPoint.getSecurity()).thenReturn(AccessPoint.SECURITY_PSK);
+ final NetworkSelectionStatus status = new NetworkSelectionStatus();
+ status.setHasEverConnected(true);
+ mWifiConfig.setNetworkSelectionStatus(status);
+
+ mHandler.connect(mAccessPoint);
+
+ assertThat(ShadowWifiManager.get().savedWifiConfig.SSID).isEqualTo(AP1_SSID);
+ }
+
+ @Test
+ public void connect_shouldNotConnectToUnsavedSecuredNetwork() {
+ when(mAccessPoint.isSaved()).thenReturn(false);
+ when(mAccessPoint.getSecurity()).thenReturn(AccessPoint.SECURITY_PSK);
+
+ mHandler.connect(mAccessPoint);
+
+ assertThat(ShadowWifiManager.get().savedWifiConfig).isNull();
+ }
+}
diff --git a/tests/uitests/src/com/android/settings/ui/LocationSettingsTests.java b/tests/uitests/src/com/android/settings/ui/LocationSettingsTests.java
index b4a1baa8c23..8e391f31525 100644
--- a/tests/uitests/src/com/android/settings/ui/LocationSettingsTests.java
+++ b/tests/uitests/src/com/android/settings/ui/LocationSettingsTests.java
@@ -95,7 +95,7 @@ public class LocationSettingsTests extends InstrumentationTestCase {
public void testLocationDeviceOnlyMode() throws Exception {
// Changing the value from default before testing the toggle to Device only mode
Settings.Secure.putInt(getInstrumentation().getContext().getContentResolver(),
- Settings.Secure.LOCATION_MODE, Settings.Secure.LOCATION_MODE_HIGH_ACCURACY);
+ Settings.Secure.LOCATION_MODE, Settings.Secure.LOCATION_MODE_ON);
dismissAlertDialogs();
Thread.sleep(TIMEOUT);
verifyLocationSettingsMode(Settings.Secure.LOCATION_MODE_SENSORS_ONLY);
@@ -114,7 +114,7 @@ public class LocationSettingsTests extends InstrumentationTestCase {
Settings.Secure.putInt(getInstrumentation().getContext().getContentResolver(),
Settings.Secure.LOCATION_MODE, Settings.Secure.LOCATION_MODE_SENSORS_ONLY);
Thread.sleep(TIMEOUT);
- verifyLocationSettingsMode(Settings.Secure.LOCATION_MODE_HIGH_ACCURACY);
+ verifyLocationSettingsMode(Settings.Secure.LOCATION_MODE_ON);
}
@MediumTest
@@ -145,7 +145,7 @@ public class LocationSettingsTests extends InstrumentationTestCase {
private void verifyLocationSettingsMode(int mode) throws Exception {
int modeIntValue = 1;
String textMode = "Device only";
- if (mode == Settings.Secure.LOCATION_MODE_HIGH_ACCURACY) {
+ if (mode == Settings.Secure.LOCATION_MODE_ON) {
modeIntValue = 3;
textMode = "High accuracy";
}
@@ -169,7 +169,7 @@ public class LocationSettingsTests extends InstrumentationTestCase {
dismissAlertDialogs();
mDevice.wait(Until.findObject(By.desc("Navigate up")), TIMEOUT).click();
Thread.sleep(TIMEOUT);
- if (mode == Settings.Secure.LOCATION_MODE_HIGH_ACCURACY ||
+ if (mode == Settings.Secure.LOCATION_MODE_ON ||
mode == Settings.Secure.LOCATION_MODE_BATTERY_SAVING) {
dismissAlertDialogs();
}
@@ -190,7 +190,7 @@ public class LocationSettingsTests extends InstrumentationTestCase {
}
else {
Settings.Secure.putInt(getInstrumentation().getContext().getContentResolver(),
- Settings.Secure.LOCATION_MODE, Settings.Secure.LOCATION_MODE_HIGH_ACCURACY);
+ Settings.Secure.LOCATION_MODE, Settings.Secure.LOCATION_MODE_ON);
}
dismissAlertDialogs();
// Load location settings