Merge changes I566dfa75,Id0d372cf,Ifb79e402,Ic80ed7f8,I40ff3ed0 into sc-qpr1-dev
* changes: [Provider Model] Fix the condition about admin user [Provider Model] 1.Only admin can config mobile data 2.Do not connect to mobile data when device is locked [Provider Model] Fix the toggle's size and dialog's width [Provider Model] Correct the connected Wi-Fi UI [Provider Model] Should not show Wi-Fi entries under lockscreen
This commit is contained in:
@@ -18,8 +18,6 @@
|
||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item
|
||||
android:top="@dimen/settingslib_switch_thumb_margin"
|
||||
android:left="@dimen/settingslib_switch_thumb_margin"
|
||||
android:right="@dimen/settingslib_switch_thumb_margin"
|
||||
android:bottom="@dimen/settingslib_switch_thumb_margin">
|
||||
<shape android:shape="oval">
|
||||
<size
|
||||
|
||||
@@ -18,8 +18,6 @@
|
||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item
|
||||
android:top="@dimen/settingslib_switch_thumb_margin"
|
||||
android:left="@dimen/settingslib_switch_thumb_margin"
|
||||
android:right="@dimen/settingslib_switch_thumb_margin"
|
||||
android:bottom="@dimen/settingslib_switch_thumb_margin">
|
||||
<shape android:shape="oval">
|
||||
<size
|
||||
|
||||
@@ -19,6 +19,8 @@
|
||||
android:shape="rectangle"
|
||||
android:width="@dimen/settingslib_switch_track_width"
|
||||
android:height="@dimen/settingslib_switch_track_height">
|
||||
<padding android:left="@dimen/settingslib_switch_thumb_margin"
|
||||
android:right="@dimen/settingslib_switch_thumb_margin"/>
|
||||
<solid android:color="@color/settingslib_track_off_color"/>
|
||||
<corners android:radius="@dimen/settingslib_switch_track_radius"/>
|
||||
</shape>
|
||||
|
||||
@@ -19,6 +19,8 @@
|
||||
android:shape="rectangle"
|
||||
android:width="@dimen/settingslib_switch_track_width"
|
||||
android:height="@dimen/settingslib_switch_track_height">
|
||||
<padding android:left="@dimen/settingslib_switch_thumb_margin"
|
||||
android:right="@dimen/settingslib_switch_thumb_margin"/>
|
||||
<solid android:color="@color/settingslib_track_on_color"/>
|
||||
<corners android:radius="@dimen/settingslib_switch_track_radius"/>
|
||||
</shape>
|
||||
|
||||
@@ -19,18 +19,18 @@
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:androidprv="http://schemas.android.com/apk/prv/res/android"
|
||||
android:id="@+id/internet_connectivity_dialog"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="@dimen/internet_dialog_list_max_width"
|
||||
android:layout_height="@dimen/internet_dialog_list_max_height"
|
||||
android:background="@drawable/internet_dialog_rounded_top_corner_background"
|
||||
android:orientation="vertical">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
style="@style/Widget.SliceView.Panel"
|
||||
android:gravity="center_vertical|center_horizontal"
|
||||
android:layout_marginTop="24dp"
|
||||
android:layout_marginBottom="16dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
@@ -54,21 +54,28 @@
|
||||
android:textSize="14sp"/>
|
||||
</LinearLayout>
|
||||
|
||||
<View
|
||||
android:id="@+id/divider"
|
||||
android:layout_gravity="center_vertical|center_horizontal"
|
||||
android:layout_width="340dp"
|
||||
android:layout_height="4dp"
|
||||
android:background="?androidprv:attr/colorSurfaceVariant"/>
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/wifi_searching_progress"
|
||||
android:indeterminate="true"
|
||||
android:layout_width="340dp"
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:visibility="gone"
|
||||
style="@style/TrimmedHorizontalProgressBar"/>
|
||||
android:layout_marginBottom="16dp"
|
||||
android:orientation="vertical">
|
||||
|
||||
<View
|
||||
android:id="@+id/divider"
|
||||
android:layout_gravity="center_vertical|center_horizontal"
|
||||
android:layout_width="340dp"
|
||||
android:layout_height="4dp"
|
||||
android:background="?androidprv:attr/colorSurfaceVariant"/>
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/wifi_searching_progress"
|
||||
android:indeterminate="true"
|
||||
android:layout_width="340dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:visibility="gone"
|
||||
style="@style/TrimmedHorizontalProgressBar"/>
|
||||
</LinearLayout>
|
||||
|
||||
<androidx.core.widget.NestedScrollView
|
||||
android:id="@+id/scroll_view"
|
||||
@@ -96,7 +103,6 @@
|
||||
android:orientation="horizontal"
|
||||
android:layout_marginEnd="@dimen/settingslib_switchbar_margin"
|
||||
android:layout_marginStart="@dimen/settingslib_switchbar_margin"
|
||||
android:layout_marginTop="16dp"
|
||||
android:paddingStart="22dp"
|
||||
android:paddingEnd="22dp">
|
||||
|
||||
@@ -148,14 +154,15 @@
|
||||
</LinearLayout>
|
||||
|
||||
<FrameLayout
|
||||
android:layout_width="48dp"
|
||||
android:layout_width="@dimen/settingslib_switch_track_width"
|
||||
android:layout_height="48dp"
|
||||
android:layout_gravity="end|center_vertical">
|
||||
<Switch
|
||||
android:id="@+id/mobile_toggle"
|
||||
android:switchMinWidth="@dimen/settingslib_switch_track_width"
|
||||
android:layout_gravity="center"
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="@dimen/settingslib_switch_track_width"
|
||||
android:layout_height="@dimen/settingslib_switch_track_height"
|
||||
android:track="@drawable/settingslib_track_selector"
|
||||
android:thumb="@drawable/settingslib_thumb_selector"
|
||||
android:theme="@style/MainSwitch.Settingslib"/>
|
||||
@@ -195,15 +202,16 @@
|
||||
</FrameLayout>
|
||||
|
||||
<FrameLayout
|
||||
android:layout_width="48dp"
|
||||
android:layout_width="@dimen/settingslib_switch_track_width"
|
||||
android:layout_height="48dp"
|
||||
android:layout_marginTop="10dp"
|
||||
android:layout_marginBottom="10dp">
|
||||
<Switch
|
||||
android:id="@+id/wifi_toggle"
|
||||
android:switchMinWidth="@dimen/settingslib_switch_track_width"
|
||||
android:layout_gravity="center"
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="@dimen/settingslib_switch_track_width"
|
||||
android:layout_height="@dimen/settingslib_switch_track_height"
|
||||
android:track="@drawable/settingslib_track_selector"
|
||||
android:thumb="@drawable/settingslib_thumb_selector"
|
||||
android:theme="@style/MainSwitch.Settingslib"/>
|
||||
@@ -343,31 +351,23 @@
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<Space
|
||||
android:id="@+id/space"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="28dp"
|
||||
android:visibility="gone"/>
|
||||
|
||||
<LinearLayout
|
||||
<FrameLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="48dp"
|
||||
android:layout_marginBottom="25dp"
|
||||
android:gravity="end"
|
||||
android:orientation="horizontal">
|
||||
android:layout_marginBottom="40dp">
|
||||
<Button
|
||||
style="@*android:style/Widget.DeviceDefault.Button.Borderless.Colored"
|
||||
android:id="@+id/done"
|
||||
android:layout_width="60dp"
|
||||
android:layout_height="30dp"
|
||||
android:layout_width="67dp"
|
||||
android:layout_height="36dp"
|
||||
android:layout_marginEnd="24dp"
|
||||
android:layout_gravity="end"
|
||||
android:layout_gravity="end|center_vertical"
|
||||
android:background="@drawable/internet_dialog_footer_background"
|
||||
android:textColor="?android:attr/textColorPrimary"
|
||||
android:text="@string/inline_done_button"
|
||||
android:textSize="14sp"
|
||||
android:fontFamily="google-sans"/>
|
||||
</LinearLayout>
|
||||
</FrameLayout>
|
||||
</LinearLayout>
|
||||
</androidx.core.widget.NestedScrollView>
|
||||
</LinearLayout>
|
||||
|
||||
@@ -1593,7 +1593,8 @@
|
||||
|
||||
<!-- Internet panel related dimensions -->
|
||||
<dimen name="internet_dialog_list_margin">12dp</dimen>
|
||||
<dimen name="internet_dialog_list_max_height">614dp</dimen>
|
||||
<dimen name="internet_dialog_list_max_height">646dp</dimen>
|
||||
<dimen name="internet_dialog_list_max_width">412dp</dimen>
|
||||
|
||||
<!-- Signal icon in internet dialog -->
|
||||
<dimen name="signal_strength_icon_size">24dp</dimen>
|
||||
@@ -1604,21 +1605,26 @@
|
||||
<!-- Size of internet dialog -->
|
||||
<dimen name="settingslib_switchbar_margin">16dp</dimen>
|
||||
<!-- Minimum width of switch -->
|
||||
<dimen name="settingslib_min_switch_width">48dp</dimen>
|
||||
<dimen name="settingslib_min_switch_width">52dp</dimen>
|
||||
<!-- Size of layout margin left -->
|
||||
<dimen name="settingslib_switchbar_padding_left">20dp</dimen>
|
||||
<!-- Size of layout margin right -->
|
||||
<dimen name="settingslib_switchbar_padding_right">20dp</dimen>
|
||||
<!-- Radius of switch bar -->
|
||||
<dimen name="settingslib_switch_bar_radius">24dp</dimen>
|
||||
<dimen name="settingslib_switch_bar_radius">35dp</dimen>
|
||||
<!-- Margin of switch thumb -->
|
||||
<dimen name="settingslib_switch_thumb_margin">4dp</dimen>
|
||||
<!-- Size of switch thumb -->
|
||||
<dimen name="settingslib_switch_thumb_size">16dp</dimen>
|
||||
<dimen name="settingslib_switch_thumb_size">20dp</dimen>
|
||||
<!-- Width of switch track -->
|
||||
<dimen name="settingslib_switch_track_width">48dp</dimen>
|
||||
<dimen name="settingslib_switch_track_width">52dp</dimen>
|
||||
<!-- Height of switch track -->
|
||||
<dimen name="settingslib_switch_track_height">24dp</dimen>
|
||||
<dimen name="settingslib_switch_track_height">28dp</dimen>
|
||||
<!-- Radius of switch track -->
|
||||
<dimen name="settingslib_switch_track_radius">31dp</dimen>
|
||||
<dimen name="settingslib_switch_track_radius">35dp</dimen>
|
||||
|
||||
<!-- Height percentage of the parent container occupied by the communal view -->
|
||||
<item name="communal_source_height_percentage" format="float" type="dimen">0.80</item>
|
||||
|
||||
<dimen name="drag_and_drop_icon_size">70dp</dimen>
|
||||
</resources>
|
||||
|
||||
@@ -3021,6 +3021,8 @@
|
||||
<string name="pref_title_network_details" msgid="7329759534269363308">"Network details"</string>
|
||||
<!-- Provider Model: Panel subtitle for tapping a network to connect to internet. [CHAR LIMIT=60] -->
|
||||
<string name="tap_a_network_to_connect">Tap a network to connect</string>
|
||||
<!-- Provider Model: Panel subtitle for unlocking screen to view networks. [CHAR LIMIT=60] -->
|
||||
<string name="unlock_to_view_networks">Unlock to view networks</string>
|
||||
<!-- Provider Model: Wi-Fi settings. text displayed when Wi-Fi is on and network list is empty [CHAR LIMIT=50]-->
|
||||
<string name="wifi_empty_list_wifi_on">Searching for networks\u2026</string>
|
||||
<!-- Provider Model: Failure notification for connect -->
|
||||
|
||||
@@ -97,7 +97,8 @@ public class InternetAdapter extends RecyclerView.Adapter<InternetAdapter.Intern
|
||||
}
|
||||
|
||||
return mInternetDialogController.getWifiEntryList().stream()
|
||||
.filter(wifiEntry -> !wifiEntry.isDefaultNetwork())
|
||||
.filter(wifiEntry -> (!wifiEntry.isDefaultNetwork()
|
||||
|| !wifiEntry.hasInternetAccess()))
|
||||
.limit(getItemCount())
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
@@ -107,21 +108,21 @@ public class InternetAdapter extends RecyclerView.Adapter<InternetAdapter.Intern
|
||||
* {@link InternetDialog}.
|
||||
*
|
||||
* Airplane mode is ON (mobile network is gone):
|
||||
* Return four Wi-Fi's entries if no default Wi-Fi.
|
||||
* Return three Wi-Fi's entries if one default Wi-Fi.
|
||||
* Return four Wi-Fi's entries if no internet Wi-Fi.
|
||||
* Return three Wi-Fi's entries if one internet Wi-Fi.
|
||||
* Airplane mode is OFF (mobile network is visible):
|
||||
* Return three Wi-Fi's entries if no default Wi-Fi.
|
||||
* Return two Wi-Fi's entries if one default Wi-Fi.
|
||||
* Return three Wi-Fi's entries if no internet Wi-Fi.
|
||||
* Return two Wi-Fi's entries if one internet Wi-Fi.
|
||||
*
|
||||
* @return The total number of networks.
|
||||
*/
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
final boolean hasDefaultWifi = mInternetDialogController.getDefaultWifiEntry() != null;
|
||||
final boolean hasInternetWifi = mInternetDialogController.getInternetWifiEntry() != null;
|
||||
if (mInternetDialogController.isAirplaneModeEnabled()) {
|
||||
return hasDefaultWifi ? 3 : 4;
|
||||
return hasInternetWifi ? 3 : 4;
|
||||
} else {
|
||||
return hasDefaultWifi ? 2 : 3;
|
||||
return hasInternetWifi ? 2 : 3;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -112,7 +112,6 @@ public class InternetDialog extends SystemUIDialog implements
|
||||
private LinearLayout mMobileNetworkList;
|
||||
private LinearLayout mTurnWifiOnLayout;
|
||||
private LinearLayout mSeeAllLayout;
|
||||
private Space mSpace;
|
||||
private RecyclerView mWifiRecyclerView;
|
||||
private ImageView mConnectedWifiIcon;
|
||||
private ImageView mWifiSettingsIcon;
|
||||
@@ -126,6 +125,7 @@ public class InternetDialog extends SystemUIDialog implements
|
||||
private Button mDoneButton;
|
||||
private Drawable mBackgroundOn;
|
||||
private int mListMaxHeight;
|
||||
private int mListMaxWidth;
|
||||
private int mDefaultDataSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
|
||||
private boolean mCanConfigMobileData;
|
||||
|
||||
@@ -174,6 +174,8 @@ public class InternetDialog extends SystemUIDialog implements
|
||||
};
|
||||
mListMaxHeight = context.getResources().getDimensionPixelSize(
|
||||
R.dimen.internet_dialog_list_max_height);
|
||||
mListMaxWidth = context.getResources().getDimensionPixelSize(
|
||||
R.dimen.internet_dialog_list_max_width);
|
||||
mUiEventLogger = uiEventLogger;
|
||||
mAdapter = new InternetAdapter(mInternetDialogController);
|
||||
if (!aboveStatusBar) {
|
||||
@@ -200,7 +202,7 @@ public class InternetDialog extends SystemUIDialog implements
|
||||
layoutParams.setFitInsetsIgnoringVisibility(true);
|
||||
window.setAttributes(layoutParams);
|
||||
window.setContentView(mDialogView);
|
||||
window.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
||||
window.setLayout(mListMaxWidth, ViewGroup.LayoutParams.WRAP_CONTENT);
|
||||
window.setWindowAnimations(R.style.Animation_InternetDialog);
|
||||
window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
|
||||
window.addFlags(FLAG_LAYOUT_NO_LIMITS);
|
||||
@@ -221,7 +223,6 @@ public class InternetDialog extends SystemUIDialog implements
|
||||
mWifiSettingsIcon = mDialogView.requireViewById(R.id.wifi_settings_icon);
|
||||
mWifiRecyclerView = mDialogView.requireViewById(R.id.wifi_list_layout);
|
||||
mSeeAllLayout = mDialogView.requireViewById(R.id.see_all_layout);
|
||||
mSpace = mDialogView.requireViewById(R.id.space);
|
||||
mDoneButton = mDialogView.requireViewById(R.id.done);
|
||||
mSignalIcon = mDialogView.requireViewById(R.id.signal_icon);
|
||||
mMobileTitleText = mDialogView.requireViewById(R.id.mobile_title);
|
||||
@@ -287,19 +288,27 @@ public class InternetDialog extends SystemUIDialog implements
|
||||
}
|
||||
showProgressBar();
|
||||
setMobileDataLayout(mInternetDialogController.activeNetworkIsCellular());
|
||||
setConnectedWifiLayout();
|
||||
boolean isWifiEnabled = mWifiManager.isWifiEnabled();
|
||||
mWiFiToggle.setChecked(isWifiEnabled);
|
||||
int visible = isWifiEnabled ? View.VISIBLE : View.GONE;
|
||||
mWifiRecyclerView.setVisibility(visible);
|
||||
mAdapter.notifyDataSetChanged();
|
||||
mSeeAllLayout.setVisibility(visible);
|
||||
mSpace.setVisibility(isWifiEnabled ? View.GONE : View.VISIBLE);
|
||||
|
||||
final boolean isDeviceLocked = mInternetDialogController.isDeviceLocked();
|
||||
final boolean isWifiEnabled = mWifiManager.isWifiEnabled();
|
||||
updateWifiToggle(isWifiEnabled, isDeviceLocked);
|
||||
updateConnectedWifi(isWifiEnabled, isDeviceLocked);
|
||||
|
||||
List<WifiEntry> wifiEntryList = mInternetDialogController.getWifiEntryList();
|
||||
final int wifiListVisibility =
|
||||
(isDeviceLocked || wifiEntryList == null || wifiEntryList.size() <= 0)
|
||||
? View.GONE : View.VISIBLE;
|
||||
mWifiRecyclerView.setVisibility(wifiListVisibility);
|
||||
if (wifiListVisibility == View.VISIBLE) {
|
||||
mAdapter.notifyDataSetChanged();
|
||||
}
|
||||
mSeeAllLayout.setVisibility(wifiListVisibility);
|
||||
}
|
||||
|
||||
private void setOnClickListener() {
|
||||
mMobileNetworkLayout.setOnClickListener(v -> {
|
||||
if (mInternetDialogController.isMobileDataEnabled()) {
|
||||
if (mInternetDialogController.isMobileDataEnabled()
|
||||
&& !mInternetDialogController.isDeviceLocked()) {
|
||||
if (!mInternetDialogController.activeNetworkIsCellular()) {
|
||||
mInternetDialogController.connectCarrierNetwork();
|
||||
}
|
||||
@@ -320,7 +329,6 @@ public class InternetDialog extends SystemUIDialog implements
|
||||
(buttonView, isChecked) -> {
|
||||
buttonView.setChecked(isChecked);
|
||||
mWifiManager.setWifiEnabled(isChecked);
|
||||
mSpace.setVisibility(isChecked ? View.GONE : View.VISIBLE);
|
||||
});
|
||||
mDoneButton.setOnClickListener(v -> dismiss());
|
||||
}
|
||||
@@ -358,17 +366,23 @@ public class InternetDialog extends SystemUIDialog implements
|
||||
}
|
||||
}
|
||||
|
||||
private void setConnectedWifiLayout() {
|
||||
if (!mWifiManager.isWifiEnabled() || mConnectedWifiEntry == null) {
|
||||
private void updateWifiToggle(boolean isWifiEnabled, boolean isDeviceLocked) {
|
||||
mWiFiToggle.setChecked(isWifiEnabled);
|
||||
mTurnWifiOnLayout.setBackground(
|
||||
(isDeviceLocked && mConnectedWifiEntry != null) ? mBackgroundOn : null);
|
||||
}
|
||||
|
||||
private void updateConnectedWifi(boolean isWifiEnabled, boolean isDeviceLocked) {
|
||||
if (!isWifiEnabled || mConnectedWifiEntry == null || isDeviceLocked) {
|
||||
mConnectedWifListLayout.setBackground(null);
|
||||
mConnectedWifListLayout.setVisibility(View.GONE);
|
||||
return;
|
||||
}
|
||||
mConnectedWifListLayout.setVisibility(View.VISIBLE);
|
||||
mConnectedWifiTitleText.setText(getConnectedWifiTitle());
|
||||
mConnectedWifiSummaryText.setText(getConnectedWifiSummary());
|
||||
mConnectedWifiTitleText.setText(mInternetDialogController.getInternetWifiTitle());
|
||||
mConnectedWifiSummaryText.setText(mInternetDialogController.getInternetWifiSummary());
|
||||
mConnectedWifiIcon.setImageDrawable(
|
||||
mInternetDialogController.getConnectedWifiDrawable(mConnectedWifiEntry));
|
||||
mInternetDialogController.getInternetWifiDrawable(mConnectedWifiEntry));
|
||||
if (mInternetDialogController.isNightMode()) {
|
||||
mConnectedWifiTitleText.setTextColor(
|
||||
mContext.getColor(R.color.connected_network_primary_color));
|
||||
@@ -409,16 +423,9 @@ public class InternetDialog extends SystemUIDialog implements
|
||||
return mInternetDialogController.getMobileNetworkSummary();
|
||||
}
|
||||
|
||||
String getConnectedWifiTitle() {
|
||||
return mInternetDialogController.getDefaultWifiTitle();
|
||||
}
|
||||
|
||||
String getConnectedWifiSummary() {
|
||||
return mInternetDialogController.getDefaultWifiSummary();
|
||||
}
|
||||
|
||||
protected void showProgressBar() {
|
||||
if (mWifiManager == null || !mWifiManager.isWifiEnabled()) {
|
||||
if (mWifiManager == null || !mWifiManager.isWifiEnabled()
|
||||
|| mInternetDialogController.isDeviceLocked()) {
|
||||
setProgressBarVisible(false);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -67,6 +67,7 @@ import com.android.systemui.R;
|
||||
import com.android.systemui.broadcast.BroadcastDispatcher;
|
||||
import com.android.systemui.dagger.qualifiers.Main;
|
||||
import com.android.systemui.plugins.ActivityStarter;
|
||||
import com.android.systemui.statusbar.policy.KeyguardStateController;
|
||||
import com.android.systemui.statusbar.policy.NetworkController;
|
||||
import com.android.systemui.statusbar.policy.NetworkController.AccessPointController;
|
||||
import com.android.systemui.util.settings.GlobalSettings;
|
||||
@@ -97,6 +98,8 @@ public class InternetDialogController implements WifiEntry.DisconnectCallback,
|
||||
private static final int SUBTITLE_TEXT_WIFI_IS_OFF = R.string.wifi_is_off;
|
||||
private static final int SUBTITLE_TEXT_TAP_A_NETWORK_TO_CONNECT =
|
||||
R.string.tap_a_network_to_connect;
|
||||
private static final int SUBTITLE_TEXT_UNLOCK_TO_VIEW_NETWORKS =
|
||||
R.string.unlock_to_view_networks;
|
||||
private static final int SUBTITLE_TEXT_SEARCHING_FOR_NETWORKS =
|
||||
R.string.wifi_empty_list_wifi_on;
|
||||
private static final int SUBTITLE_TEXT_NON_CARRIER_NETWORK_UNAVAILABLE =
|
||||
@@ -137,6 +140,9 @@ public class InternetDialogController implements WifiEntry.DisconnectCallback,
|
||||
@VisibleForTesting
|
||||
protected WifiUtils.InternetIconInjector mWifiIconInjector;
|
||||
|
||||
@VisibleForTesting
|
||||
KeyguardStateController mKeyguardStateController;
|
||||
|
||||
private final KeyguardUpdateMonitorCallback mKeyguardUpdateCallback =
|
||||
new KeyguardUpdateMonitorCallback() {
|
||||
@Override
|
||||
@@ -161,7 +167,7 @@ public class InternetDialogController implements WifiEntry.DisconnectCallback,
|
||||
@Nullable WifiManager wifiManager, ConnectivityManager connectivityManager,
|
||||
@Main Handler handler, @Main Executor mainExecutor,
|
||||
BroadcastDispatcher broadcastDispatcher, KeyguardUpdateMonitor keyguardUpdateMonitor,
|
||||
GlobalSettings globalSettings) {
|
||||
GlobalSettings globalSettings, KeyguardStateController keyguardStateController) {
|
||||
if (DEBUG) {
|
||||
Log.d(TAG, "Init InternetDialogController");
|
||||
}
|
||||
@@ -175,6 +181,7 @@ public class InternetDialogController implements WifiEntry.DisconnectCallback,
|
||||
mSubscriptionManager = subscriptionManager;
|
||||
mBroadcastDispatcher = broadcastDispatcher;
|
||||
mKeyguardUpdateMonitor = keyguardUpdateMonitor;
|
||||
mKeyguardStateController = keyguardStateController;
|
||||
mConnectionStateFilter = new IntentFilter();
|
||||
mConnectionStateFilter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION);
|
||||
mConnectionStateFilter.addAction(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION);
|
||||
@@ -272,6 +279,15 @@ public class InternetDialogController implements WifiEntry.DisconnectCallback,
|
||||
return mContext.getText(SUBTITLE_TEXT_WIFI_IS_OFF);
|
||||
}
|
||||
|
||||
if (isDeviceLocked()) {
|
||||
// When the device is locked.
|
||||
// Sub-Title: Unlock to view networks
|
||||
if (DEBUG) {
|
||||
Log.d(TAG, "The device is locked.");
|
||||
}
|
||||
return mContext.getText(SUBTITLE_TEXT_UNLOCK_TO_VIEW_NETWORKS);
|
||||
}
|
||||
|
||||
final List<ScanResult> wifiList = mWifiManager.getScanResults();
|
||||
if (wifiList != null && wifiList.size() != 0) {
|
||||
return mContext.getText(SUBTITLE_TEXT_TAP_A_NETWORK_TO_CONNECT);
|
||||
@@ -318,9 +334,9 @@ public class InternetDialogController implements WifiEntry.DisconnectCallback,
|
||||
return mContext.getText(SUBTITLE_TEXT_NON_CARRIER_NETWORK_UNAVAILABLE);
|
||||
}
|
||||
|
||||
Drawable getConnectedWifiDrawable(@NonNull WifiEntry wifiEntry) {
|
||||
Drawable getInternetWifiDrawable(@NonNull WifiEntry wifiEntry) {
|
||||
final Drawable drawable =
|
||||
mWifiIconInjector.getIcon(false /* noInternet*/, wifiEntry.getLevel());
|
||||
mWifiIconInjector.getIcon(wifiEntry.shouldShowXLevelIcon(), wifiEntry.getLevel());
|
||||
if (drawable == null) {
|
||||
return null;
|
||||
}
|
||||
@@ -533,24 +549,24 @@ public class InternetDialogController implements WifiEntry.DisconnectCallback,
|
||||
return summary;
|
||||
}
|
||||
|
||||
String getDefaultWifiTitle() {
|
||||
if (getDefaultWifiEntry() == null) {
|
||||
String getInternetWifiTitle() {
|
||||
if (getInternetWifiEntry() == null) {
|
||||
if (DEBUG) {
|
||||
Log.d(TAG, "connected entry is null");
|
||||
}
|
||||
return "";
|
||||
}
|
||||
return getDefaultWifiEntry().getTitle();
|
||||
return getInternetWifiEntry().getTitle();
|
||||
}
|
||||
|
||||
String getDefaultWifiSummary() {
|
||||
if (getDefaultWifiEntry() == null) {
|
||||
String getInternetWifiSummary() {
|
||||
if (getInternetWifiEntry() == null) {
|
||||
if (DEBUG) {
|
||||
Log.d(TAG, "connected entry is null");
|
||||
}
|
||||
return "";
|
||||
}
|
||||
return getDefaultWifiEntry().getSummary(false);
|
||||
return getInternetWifiEntry().getSummary(false);
|
||||
}
|
||||
|
||||
void launchNetworkSetting() {
|
||||
@@ -578,11 +594,12 @@ public class InternetDialogController implements WifiEntry.DisconnectCallback,
|
||||
return mWifiEntry;
|
||||
}
|
||||
|
||||
WifiEntry getDefaultWifiEntry() {
|
||||
if (mConnectedEntry != null && mConnectedEntry.isDefaultNetwork()) {
|
||||
return mConnectedEntry;
|
||||
WifiEntry getInternetWifiEntry() {
|
||||
if (mConnectedEntry == null || !mConnectedEntry.isDefaultNetwork()
|
||||
|| !mConnectedEntry.hasInternetAccess()) {
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
return mConnectedEntry;
|
||||
}
|
||||
|
||||
WifiManager getWifiManager() {
|
||||
@@ -683,6 +700,10 @@ public class InternetDialogController implements WifiEntry.DisconnectCallback,
|
||||
&& serviceState.getState() == serviceState.STATE_IN_SERVICE;
|
||||
}
|
||||
|
||||
public boolean isDeviceLocked() {
|
||||
return !mKeyguardStateController.isUnlocked();
|
||||
}
|
||||
|
||||
boolean activeNetworkIsCellular() {
|
||||
if (mConnectivityManager == null) {
|
||||
if (DEBUG) {
|
||||
@@ -781,7 +802,7 @@ public class InternetDialogController implements WifiEntry.DisconnectCallback,
|
||||
mConnectedEntry = null;
|
||||
}
|
||||
|
||||
mCallback.onAccessPointsChanged(mWifiEntry, getDefaultWifiEntry());
|
||||
mCallback.onAccessPointsChanged(mWifiEntry, getInternetWifiEntry());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -69,6 +69,7 @@ public class AccessPointControllerImpl
|
||||
|
||||
private final ArrayList<AccessPointCallback> mCallbacks = new ArrayList<AccessPointCallback>();
|
||||
private final UserManager mUserManager;
|
||||
private final UserTracker mUserTracker;
|
||||
private final Executor mMainExecutor;
|
||||
|
||||
private @Nullable WifiPickerTracker mWifiPickerTracker;
|
||||
@@ -85,6 +86,7 @@ public class AccessPointControllerImpl
|
||||
WifiPickerTrackerFactory wifiPickerTrackerFactory
|
||||
) {
|
||||
mUserManager = userManager;
|
||||
mUserTracker = userTracker;
|
||||
mCurrentUser = userTracker.getUserId();
|
||||
mMainExecutor = mainExecutor;
|
||||
mWifiPickerTrackerFactory = wifiPickerTrackerFactory;
|
||||
@@ -121,7 +123,7 @@ public class AccessPointControllerImpl
|
||||
|
||||
public boolean canConfigMobileData() {
|
||||
return !mUserManager.hasUserRestriction(UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS,
|
||||
UserHandle.of(mCurrentUser));
|
||||
UserHandle.of(mCurrentUser)) && mUserTracker.getUserInfo().isAdmin();
|
||||
}
|
||||
|
||||
public void onUserSwitched(int newUserId) {
|
||||
|
||||
@@ -32,6 +32,8 @@ public class InternetAdapterTest extends SysuiTestCase {
|
||||
private static final String WIFI_TITLE = "Wi-Fi Title";
|
||||
private static final String WIFI_SUMMARY = "Wi-Fi Summary";
|
||||
|
||||
@Mock
|
||||
private WifiEntry mInternetWifiEntry;
|
||||
@Mock
|
||||
private WifiEntry mWifiEntry;
|
||||
@Mock
|
||||
@@ -45,41 +47,49 @@ public class InternetAdapterTest extends SysuiTestCase {
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mInternetAdapter = new InternetAdapter(mInternetDialogController);
|
||||
mViewHolder = mInternetAdapter.onCreateViewHolder(new LinearLayout(mContext), 0);
|
||||
when(mInternetWifiEntry.getTitle()).thenReturn(WIFI_TITLE);
|
||||
when(mInternetWifiEntry.getSummary(false)).thenReturn(WIFI_SUMMARY);
|
||||
when(mInternetWifiEntry.isDefaultNetwork()).thenReturn(true);
|
||||
when(mInternetWifiEntry.hasInternetAccess()).thenReturn(true);
|
||||
when(mWifiEntry.getTitle()).thenReturn(WIFI_TITLE);
|
||||
when(mWifiEntry.getSummary(false)).thenReturn(WIFI_SUMMARY);
|
||||
|
||||
mInternetAdapter = new InternetAdapter(mInternetDialogController);
|
||||
mViewHolder = mInternetAdapter.onCreateViewHolder(new LinearLayout(mContext), 0);
|
||||
when(mInternetDialogController.getInternetWifiEntry()).thenReturn(mInternetWifiEntry);
|
||||
when(mInternetDialogController.getWifiEntryList()).thenReturn(Arrays.asList(mWifiEntry));
|
||||
mViewHolder.mWifiIconInjector = mWifiIconInjector;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getItemCount_withApmOnWifiOnNoDefaultWifi_returnFour() {
|
||||
public void getItemCount_withApmOnWifiOnNoInternetWifi_returnFour() {
|
||||
// The preconditions WiFi ON is already in setUp()
|
||||
when(mInternetDialogController.getInternetWifiEntry()).thenReturn(null);
|
||||
when(mInternetDialogController.isAirplaneModeEnabled()).thenReturn(true);
|
||||
|
||||
assertThat(mInternetAdapter.getItemCount()).isEqualTo(4);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getItemCount_withApmOnWifiOnHasDefaultWifi_returnThree() {
|
||||
when(mWifiEntry.isDefaultNetwork()).thenReturn(true);
|
||||
when(mInternetDialogController.getDefaultWifiEntry()).thenReturn(mWifiEntry);
|
||||
public void getItemCount_withApmOnWifiOnHasInternetWifi_returnThree() {
|
||||
// The preconditions WiFi ON and Internet WiFi are already in setUp()
|
||||
when(mInternetDialogController.isAirplaneModeEnabled()).thenReturn(true);
|
||||
|
||||
assertThat(mInternetAdapter.getItemCount()).isEqualTo(3);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getItemCount_withApmOffWifiOnNoDefaultWifi_returnThree() {
|
||||
public void getItemCount_withApmOffWifiOnNoInternetWifi_returnThree() {
|
||||
// The preconditions WiFi ON is already in setUp()
|
||||
when(mInternetDialogController.getInternetWifiEntry()).thenReturn(null);
|
||||
when(mInternetDialogController.isAirplaneModeEnabled()).thenReturn(false);
|
||||
|
||||
assertThat(mInternetAdapter.getItemCount()).isEqualTo(3);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getItemCount_withApmOffWifiOnHasDefaultWifi_returnTwo() {
|
||||
when(mWifiEntry.isDefaultNetwork()).thenReturn(true);
|
||||
when(mInternetDialogController.getDefaultWifiEntry()).thenReturn(mWifiEntry);
|
||||
public void getItemCount_withApmOffWifiOnHasInternetWifi_returnTwo() {
|
||||
// The preconditions WiFi ON and Internet WiFi are already in setUp()
|
||||
when(mInternetDialogController.isAirplaneModeEnabled()).thenReturn(false);
|
||||
|
||||
assertThat(mInternetAdapter.getItemCount()).isEqualTo(2);
|
||||
|
||||
@@ -18,7 +18,6 @@ import android.content.Intent;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.wifi.ScanResult;
|
||||
import android.net.wifi.WifiInfo;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.os.Handler;
|
||||
import android.telephony.ServiceState;
|
||||
@@ -33,13 +32,13 @@ import androidx.test.filters.SmallTest;
|
||||
|
||||
import com.android.internal.logging.UiEventLogger;
|
||||
import com.android.keyguard.KeyguardUpdateMonitor;
|
||||
import com.android.settingslib.Utils;
|
||||
import com.android.settingslib.wifi.WifiUtils;
|
||||
import com.android.systemui.R;
|
||||
import com.android.systemui.SysuiTestCase;
|
||||
import com.android.systemui.broadcast.BroadcastDispatcher;
|
||||
import com.android.systemui.dagger.qualifiers.Main;
|
||||
import com.android.systemui.plugins.ActivityStarter;
|
||||
import com.android.systemui.statusbar.policy.KeyguardStateController;
|
||||
import com.android.systemui.statusbar.policy.NetworkController;
|
||||
import com.android.systemui.statusbar.policy.NetworkController.AccessPointController;
|
||||
import com.android.systemui.util.concurrency.FakeExecutor;
|
||||
@@ -79,14 +78,12 @@ public class InternetDialogControllerTest extends SysuiTestCase {
|
||||
@Mock
|
||||
private GlobalSettings mGlobalSettings;
|
||||
@Mock
|
||||
private KeyguardUpdateMonitor mKeyguardUpdateMonitor;
|
||||
private KeyguardStateController mKeyguardStateController;
|
||||
@Mock
|
||||
private NetworkController.AccessPointController mAccessPointController;
|
||||
@Mock
|
||||
private WifiEntry mConnectedEntry;
|
||||
@Mock
|
||||
private WifiInfo mWifiInfo;
|
||||
@Mock
|
||||
private ServiceState mServiceState;
|
||||
@Mock
|
||||
private BroadcastDispatcher mBroadcastDispatcher;
|
||||
@@ -99,15 +96,16 @@ public class InternetDialogControllerTest extends SysuiTestCase {
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
doReturn(mTelephonyManager).when(mTelephonyManager).createForSubscriptionId(SUB_ID);
|
||||
when(mWifiManager.getConnectionInfo()).thenReturn(mWifiInfo);
|
||||
doReturn(mTelephonyManager).when(mTelephonyManager).createForSubscriptionId(anyInt());
|
||||
when(mKeyguardStateController.isUnlocked()).thenReturn(true);
|
||||
when(mConnectedEntry.isDefaultNetwork()).thenReturn(true);
|
||||
when(mConnectedEntry.hasInternetAccess()).thenReturn(true);
|
||||
|
||||
mInternetDialogController = new MockInternetDialogController(mContext,
|
||||
mock(UiEventLogger.class), mock(ActivityStarter.class), mAccessPointController,
|
||||
mSubscriptionManager, mTelephonyManager, mWifiManager,
|
||||
mock(ConnectivityManager.class), mHandler, mExecutor, mBroadcastDispatcher,
|
||||
mKeyguardUpdateMonitor, mGlobalSettings);
|
||||
mock(KeyguardUpdateMonitor.class), mGlobalSettings, mKeyguardStateController);
|
||||
mSubscriptionManager.addOnSubscriptionsChangedListener(mExecutor,
|
||||
mInternetDialogController.mOnSubscriptionsChangedListener);
|
||||
mInternetDialogController.onStart(
|
||||
@@ -173,6 +171,16 @@ public class InternetDialogControllerTest extends SysuiTestCase {
|
||||
getResourcesString("tap_a_network_to_connect")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSubtitleText_deviceLockedWithWifiOn_returnUnlockToViewNetworks() {
|
||||
mInternetDialogController.setAirplaneModeEnabled(false);
|
||||
when(mWifiManager.isWifiEnabled()).thenReturn(true);
|
||||
when(mKeyguardStateController.isUnlocked()).thenReturn(false);
|
||||
|
||||
assertTrue(TextUtils.equals(mInternetDialogController.getSubtitleText(false),
|
||||
getResourcesString("unlock_to_view_networks")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSubtitleText_withNoService_returnNoNetworksAvailable() {
|
||||
mInternetDialogController.setAirplaneModeEnabled(false);
|
||||
@@ -211,53 +219,62 @@ public class InternetDialogControllerTest extends SysuiTestCase {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getDefaultWifiEntry_connectedEntryIsNull_returnNull() {
|
||||
public void getInternetWifiEntry_connectedEntryIsNull_returnNull() {
|
||||
mInternetDialogController.mConnectedEntry = null;
|
||||
|
||||
assertThat(mInternetDialogController.getDefaultWifiEntry()).isNull();
|
||||
assertThat(mInternetDialogController.getInternetWifiEntry()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getDefaultWifiEntry_connectedEntryIsNotDefault_returnNull() {
|
||||
public void getInternetWifiEntry_connectedWifiIsNotDefaultNetwork_returnNull() {
|
||||
when(mConnectedEntry.isDefaultNetwork()).thenReturn(false);
|
||||
|
||||
assertThat(mInternetDialogController.getDefaultWifiEntry()).isNull();
|
||||
assertThat(mInternetDialogController.getInternetWifiEntry()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getDefaultWifiEntry_connectedEntryIsDefault_returnConnectedEntry() {
|
||||
// The default conditions have been set in setUp().
|
||||
// - The connected Wi-Fi entry with the default network condition.
|
||||
public void getInternetWifiEntry_connectedWifiHasNotInternetAccess_returnNull() {
|
||||
when(mConnectedEntry.hasInternetAccess()).thenReturn(false);
|
||||
|
||||
assertThat(mInternetDialogController.getDefaultWifiEntry()).isEqualTo(mConnectedEntry);
|
||||
assertThat(mInternetDialogController.getInternetWifiEntry()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getDefaultWifiTitle_withNoDefaultEntry_returnEmpty() {
|
||||
public void getInternetWifiEntry_connectedEntryIsInternetWifi_returnConnectedEntry() {
|
||||
// The preconditions have been set in setUp().
|
||||
// - The connected Wi-Fi entry have both default network and internet access conditions.
|
||||
|
||||
assertThat(mInternetDialogController.getInternetWifiEntry()).isEqualTo(mConnectedEntry);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getInternetWifiTitle_withNoConnectedWifiEntry_returnEmpty() {
|
||||
mInternetDialogController.mConnectedEntry = null;
|
||||
|
||||
assertThat(mInternetDialogController.getDefaultWifiTitle()).isEmpty();
|
||||
assertThat(mInternetDialogController.getInternetWifiTitle()).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getDefaultWifiTitle_withDefaultEntry_returnTitle() {
|
||||
public void getInternetWifiTitle_withInternetWifi_returnTitle() {
|
||||
// The preconditions have been set in setUp().
|
||||
// - The connected Wi-Fi entry have both default network and internet access conditions.
|
||||
when(mConnectedEntry.getTitle()).thenReturn(CONNECTED_TITLE);
|
||||
|
||||
assertThat(mInternetDialogController.getDefaultWifiTitle()).isEqualTo(CONNECTED_TITLE);
|
||||
assertThat(mInternetDialogController.getInternetWifiTitle()).isEqualTo(CONNECTED_TITLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getDefaultWifiSummary_withNoDefaultEntry_returnEmpty() {
|
||||
public void getInternetWifiSummary_withNoConnectedWifiEntry_returnEmpty() {
|
||||
mInternetDialogController.mConnectedEntry = null;
|
||||
|
||||
assertThat(mInternetDialogController.getDefaultWifiSummary()).isEmpty();
|
||||
assertThat(mInternetDialogController.getInternetWifiSummary()).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getDefaultWifiSummary_withDefaultEntry_returnSummary() {
|
||||
public void getInternetWifiSummary_withInternetWifi_returnSummary() {
|
||||
when(mConnectedEntry.getSummary(false)).thenReturn(CONNECTED_SUMMARY);
|
||||
|
||||
assertThat(mInternetDialogController.getDefaultWifiSummary()).isEqualTo(CONNECTED_SUMMARY);
|
||||
assertThat(mInternetDialogController.getInternetWifiSummary()).isEqualTo(CONNECTED_SUMMARY);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -282,11 +299,11 @@ public class InternetDialogControllerTest extends SysuiTestCase {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getWifiConnectedDrawable_withConnectedEntry_returnIntentIconWithColorAccent() {
|
||||
public void getWifiDrawable_withConnectedEntry_returnIntentIconWithCorrectColor() {
|
||||
final Drawable drawable = mock(Drawable.class);
|
||||
when(mWifiIconInjector.getIcon(anyBoolean(), anyInt())).thenReturn(drawable);
|
||||
|
||||
mInternetDialogController.getConnectedWifiDrawable(mConnectedEntry);
|
||||
mInternetDialogController.getInternetWifiDrawable(mConnectedEntry);
|
||||
|
||||
verify(mWifiIconInjector).getIcon(eq(false), anyInt());
|
||||
verify(drawable).setTint(mContext.getColor(R.color.connected_network_primary_color));
|
||||
@@ -311,6 +328,20 @@ public class InternetDialogControllerTest extends SysuiTestCase {
|
||||
verify(mActivityStarter).postStartActivityDismissingKeyguard(any(Intent.class), anyInt());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isDeviceLocked_keyguardIsUnlocked_returnFalse() {
|
||||
when(mKeyguardStateController.isUnlocked()).thenReturn(true);
|
||||
|
||||
assertThat(mInternetDialogController.isDeviceLocked()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isDeviceLocked_keyguardIsLocked_returnTrue() {
|
||||
when(mKeyguardStateController.isUnlocked()).thenReturn(false);
|
||||
|
||||
assertThat(mInternetDialogController.isDeviceLocked()).isTrue();
|
||||
}
|
||||
|
||||
private String getResourcesString(String name) {
|
||||
return mContext.getResources().getString(getResourcesId(name));
|
||||
}
|
||||
@@ -331,10 +362,12 @@ public class InternetDialogControllerTest extends SysuiTestCase {
|
||||
@Nullable WifiManager wifiManager, ConnectivityManager connectivityManager,
|
||||
@Main Handler handler, @Main Executor mainExecutor,
|
||||
BroadcastDispatcher broadcastDispatcher,
|
||||
KeyguardUpdateMonitor keyguardUpdateMonitor, GlobalSettings globalSettings) {
|
||||
KeyguardUpdateMonitor keyguardUpdateMonitor, GlobalSettings globalSettings,
|
||||
KeyguardStateController keyguardStateController) {
|
||||
super(context, uiEventLogger, starter, accessPointController, subscriptionManager,
|
||||
telephonyManager, wifiManager, connectivityManager, handler, mainExecutor,
|
||||
broadcastDispatcher, keyguardUpdateMonitor, globalSettings);
|
||||
broadcastDispatcher, keyguardUpdateMonitor, globalSettings,
|
||||
keyguardStateController);
|
||||
mGlobalSettings = globalSettings;
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.android.systemui.qs.tiles.dialog;
|
||||
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.anyLong;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
@@ -11,12 +12,7 @@ import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.net.wifi.ScanResult;
|
||||
import android.net.wifi.WifiInfo;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.os.Handler;
|
||||
import android.telephony.TelephonyManager;
|
||||
@@ -32,7 +28,6 @@ import androidx.test.filters.SmallTest;
|
||||
import com.android.internal.logging.UiEventLogger;
|
||||
import com.android.systemui.R;
|
||||
import com.android.systemui.SysuiTestCase;
|
||||
import com.android.systemui.dagger.qualifiers.Main;
|
||||
import com.android.wifitrackerlib.WifiEntry;
|
||||
|
||||
import org.junit.After;
|
||||
@@ -53,52 +48,61 @@ import java.util.List;
|
||||
@TestableLooper.RunWithLooper(setAsMainLooper = true)
|
||||
public class InternetDialogTest extends SysuiTestCase {
|
||||
|
||||
private static final int SUB_ID = 1;
|
||||
private static final String MOBILE_NETWORK_TITLE = "Mobile Title";
|
||||
private static final String MOBILE_NETWORK_SUMMARY = "Mobile Summary";
|
||||
private static final String WIFI_TITLE = "Connected Wi-Fi Title";
|
||||
private static final String WIFI_SUMMARY = "Connected Wi-Fi Summary";
|
||||
|
||||
private final UiEventLogger mUiEventLogger = mock(UiEventLogger.class);
|
||||
|
||||
private InternetDialogFactory mInternetDialogFactory = mock(InternetDialogFactory.class);
|
||||
private InternetAdapter mInternetAdapter = mock(InternetAdapter.class);
|
||||
private InternetDialogController mInternetDialogController = mock(
|
||||
InternetDialogController.class);
|
||||
private InternetDialogController.InternetDialogCallback mCallback =
|
||||
mock(InternetDialogController.InternetDialogCallback.class);
|
||||
private MockInternetDialog mInternetDialog;
|
||||
private WifiReceiver mWifiReceiver = null;
|
||||
private WifiManager mMockWifiManager = mock(WifiManager.class);
|
||||
private TelephonyManager mTelephonyManager = mock(TelephonyManager.class);
|
||||
@Mock
|
||||
private WifiEntry mWifiEntry = mock(WifiEntry.class);
|
||||
@Mock
|
||||
private WifiInfo mWifiInfo;
|
||||
@Mock
|
||||
private Handler mHandler;
|
||||
@Mock
|
||||
private TelephonyManager mTelephonyManager;
|
||||
@Mock
|
||||
private WifiManager mWifiManager;
|
||||
@Mock
|
||||
private WifiEntry mInternetWifiEntry;
|
||||
@Mock
|
||||
private WifiEntry mWifiEntry;
|
||||
@Mock
|
||||
private InternetAdapter mInternetAdapter;
|
||||
@Mock
|
||||
private InternetDialogController mInternetDialogController;
|
||||
|
||||
private InternetDialog mInternetDialog;
|
||||
private LinearLayout mWifiToggle;
|
||||
private LinearLayout mConnectedWifi;
|
||||
private RecyclerView mWifiList;
|
||||
private LinearLayout mSeeAll;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mInternetDialog = new MockInternetDialog(mContext, mInternetDialogFactory,
|
||||
mInternetDialogController, true, true, mUiEventLogger, mHandler);
|
||||
mInternetDialog.show();
|
||||
doReturn(mTelephonyManager).when(mTelephonyManager).createForSubscriptionId(SUB_ID);
|
||||
when(mMockWifiManager.isWifiEnabled()).thenReturn(true);
|
||||
when(mMockWifiManager.getConnectionInfo()).thenReturn(mWifiInfo);
|
||||
mInternetDialog.setMobileNetworkTitle(MOBILE_NETWORK_TITLE);
|
||||
mInternetDialog.setMobileNetworkSummary(MOBILE_NETWORK_SUMMARY);
|
||||
mInternetDialog.setConnectedWifiTitle(WIFI_TITLE);
|
||||
mInternetDialog.setConnectedWifiSummary(WIFI_SUMMARY);
|
||||
mWifiReceiver = new WifiReceiver();
|
||||
IntentFilter mIntentFilter = new IntentFilter();
|
||||
mIntentFilter.addAction(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION);
|
||||
mIntentFilter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION);
|
||||
mContext.registerReceiver(mWifiReceiver, mIntentFilter);
|
||||
doReturn(mTelephonyManager).when(mTelephonyManager).createForSubscriptionId(anyInt());
|
||||
when(mWifiManager.isWifiEnabled()).thenReturn(true);
|
||||
when(mInternetWifiEntry.getTitle()).thenReturn(WIFI_TITLE);
|
||||
when(mInternetWifiEntry.getSummary(false)).thenReturn(WIFI_SUMMARY);
|
||||
when(mInternetWifiEntry.isDefaultNetwork()).thenReturn(true);
|
||||
when(mInternetWifiEntry.hasInternetAccess()).thenReturn(true);
|
||||
when(mWifiEntry.getTitle()).thenReturn(WIFI_TITLE);
|
||||
when(mWifiEntry.getSummary(false)).thenReturn(WIFI_SUMMARY);
|
||||
|
||||
when(mInternetDialogController.getMobileNetworkTitle()).thenReturn(MOBILE_NETWORK_TITLE);
|
||||
when(mInternetDialogController.getMobileNetworkSummary())
|
||||
.thenReturn(MOBILE_NETWORK_SUMMARY);
|
||||
when(mInternetDialogController.getWifiManager()).thenReturn(mWifiManager);
|
||||
when(mInternetDialogController.getInternetWifiEntry()).thenReturn(mInternetWifiEntry);
|
||||
when(mInternetDialogController.getWifiEntryList()).thenReturn(Arrays.asList(mWifiEntry));
|
||||
|
||||
mInternetDialog = new InternetDialog(mContext, mock(InternetDialogFactory.class),
|
||||
mInternetDialogController, true, true, mock(UiEventLogger.class), mHandler);
|
||||
mInternetDialog.mAdapter = mInternetAdapter;
|
||||
mInternetDialog.mConnectedWifiEntry = mInternetWifiEntry;
|
||||
mInternetDialog.show();
|
||||
|
||||
mWifiToggle = mInternetDialog.mDialogView.requireViewById(R.id.turn_on_wifi_layout);
|
||||
mConnectedWifi = mInternetDialog.mDialogView.requireViewById(R.id.wifi_connected_layout);
|
||||
mWifiList = mInternetDialog.mDialogView.requireViewById(R.id.wifi_list_layout);
|
||||
mSeeAll = mInternetDialog.mDialogView.requireViewById(R.id.see_all_layout);
|
||||
}
|
||||
|
||||
@After
|
||||
@@ -137,46 +141,80 @@ public class InternetDialogTest extends SysuiTestCase {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateDialog_withWifiOnAndHasConnectedWifi_connectedWifiLayoutVisible() {
|
||||
public void updateDialog_wifiOnAndHasInternetWifi_showConnectedWifi() {
|
||||
// The preconditions WiFi ON and Internet WiFi are already in setUp()
|
||||
doReturn(false).when(mInternetDialogController).activeNetworkIsCellular();
|
||||
when(mWifiEntry.getTitle()).thenReturn(WIFI_TITLE);
|
||||
when(mWifiEntry.getSummary(false)).thenReturn(WIFI_SUMMARY);
|
||||
when(mWifiEntry.getConnectedState()).thenReturn(WifiEntry.CONNECTED_STATE_CONNECTED);
|
||||
when(mWifiEntry.isDefaultNetwork()).thenReturn(true);
|
||||
mInternetDialog.mConnectedWifiEntry = mWifiEntry;
|
||||
|
||||
mInternetDialog.updateDialog();
|
||||
|
||||
final LinearLayout linearLayout = mInternetDialog.mDialogView.requireViewById(
|
||||
R.id.wifi_connected_layout);
|
||||
assertThat(linearLayout.getVisibility()).isEqualTo(View.VISIBLE);
|
||||
assertThat(mConnectedWifi.getVisibility()).isEqualTo(View.VISIBLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateDialog_withWifiOnAndNoConnectedWifi_connectedWifiLayoutGone() {
|
||||
public void updateDialog_wifiOnAndNoConnectedWifi_hideConnectedWifi() {
|
||||
mInternetDialog.mConnectedWifiEntry = null;
|
||||
doReturn(false).when(mInternetDialogController).activeNetworkIsCellular();
|
||||
mInternetDialog.updateDialog();
|
||||
final LinearLayout linearLayout = mInternetDialog.mDialogView.requireViewById(
|
||||
R.id.wifi_connected_layout);
|
||||
|
||||
assertThat(linearLayout.getVisibility()).isEqualTo(View.GONE);
|
||||
mInternetDialog.updateDialog();
|
||||
|
||||
assertThat(mConnectedWifi.getVisibility()).isEqualTo(View.GONE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateDialog_withWifiOff_WifiRecycleViewGone() {
|
||||
when(mMockWifiManager.isWifiEnabled()).thenReturn(false);
|
||||
mInternetDialog.updateDialog();
|
||||
final RecyclerView view = mInternetDialog.mDialogView.requireViewById(
|
||||
R.id.wifi_list_layout);
|
||||
public void updateDialog_wifiOnAndNoWifiList_hideWifiListAndSeeAll() {
|
||||
when(mInternetDialogController.getWifiEntryList()).thenReturn(null);
|
||||
|
||||
assertThat(view.getVisibility()).isEqualTo(View.GONE);
|
||||
mInternetDialog.updateDialog();
|
||||
|
||||
assertThat(mWifiList.getVisibility()).isEqualTo(View.GONE);
|
||||
assertThat(mSeeAll.getVisibility()).isEqualTo(View.GONE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onClickSeeMoreButton_clickSeeMore_verifyLaunchNetworkSetting() {
|
||||
final LinearLayout seeAllLayout = mInternetDialog.mDialogView.requireViewById(
|
||||
R.id.see_all_layout);
|
||||
seeAllLayout.performClick();
|
||||
public void updateDialog_wifiOnAndHasWifiList_showWifiListAndSeeAll() {
|
||||
// The preconditions WiFi ON and WiFi entries are already in setUp()
|
||||
|
||||
mInternetDialog.updateDialog();
|
||||
|
||||
assertThat(mWifiList.getVisibility()).isEqualTo(View.VISIBLE);
|
||||
assertThat(mSeeAll.getVisibility()).isEqualTo(View.VISIBLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateDialog_deviceLockedAndHasInternetWifi_showHighlightWifiToggle() {
|
||||
// The preconditions WiFi ON and Internet WiFi are already in setUp()
|
||||
when(mInternetDialogController.isDeviceLocked()).thenReturn(true);
|
||||
|
||||
mInternetDialog.updateDialog();
|
||||
|
||||
assertThat(mWifiToggle.getVisibility()).isEqualTo(View.VISIBLE);
|
||||
assertThat(mWifiToggle.getBackground()).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateDialog_deviceLockedAndHasInternetWifi_hideConnectedWifi() {
|
||||
// The preconditions WiFi ON and Internet WiFi are already in setUp()
|
||||
when(mInternetDialogController.isDeviceLocked()).thenReturn(true);
|
||||
|
||||
mInternetDialog.updateDialog();
|
||||
|
||||
assertThat(mConnectedWifi.getVisibility()).isEqualTo(View.GONE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateDialog_deviceLockedAndHasWifiList_hideWifiListAndSeeAll() {
|
||||
// The preconditions WiFi entries are already in setUp()
|
||||
when(mInternetDialogController.isDeviceLocked()).thenReturn(true);
|
||||
|
||||
mInternetDialog.updateDialog();
|
||||
|
||||
assertThat(mWifiList.getVisibility()).isEqualTo(View.GONE);
|
||||
assertThat(mSeeAll.getVisibility()).isEqualTo(View.GONE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onClickSeeMoreButton_clickSeeAll_verifyLaunchNetworkSetting() {
|
||||
mSeeAll.performClick();
|
||||
|
||||
verify(mInternetDialogController).launchNetworkSetting();
|
||||
}
|
||||
@@ -184,7 +222,18 @@ public class InternetDialogTest extends SysuiTestCase {
|
||||
@Test
|
||||
public void showProgressBar_wifiDisabled_hideProgressBar() {
|
||||
Mockito.reset(mHandler);
|
||||
when(mMockWifiManager.isWifiEnabled()).thenReturn(false);
|
||||
when(mWifiManager.isWifiEnabled()).thenReturn(false);
|
||||
|
||||
mInternetDialog.showProgressBar();
|
||||
|
||||
assertThat(mInternetDialog.mIsProgressBarVisible).isFalse();
|
||||
verify(mHandler, never()).postDelayed(any(Runnable.class), anyLong());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void showProgressBar_deviceLocked_hideProgressBar() {
|
||||
Mockito.reset(mHandler);
|
||||
when(mInternetDialogController.isDeviceLocked()).thenReturn(true);
|
||||
|
||||
mInternetDialog.showProgressBar();
|
||||
|
||||
@@ -195,10 +244,10 @@ public class InternetDialogTest extends SysuiTestCase {
|
||||
@Test
|
||||
public void showProgressBar_wifiEnabledWithWifiEntry_showProgressBarThenHide() {
|
||||
Mockito.reset(mHandler);
|
||||
when(mMockWifiManager.isWifiEnabled()).thenReturn(true);
|
||||
when(mWifiManager.isWifiEnabled()).thenReturn(true);
|
||||
List<ScanResult> wifiScanResults = mock(ArrayList.class);
|
||||
when(wifiScanResults.size()).thenReturn(1);
|
||||
when(mMockWifiManager.getScanResults()).thenReturn(wifiScanResults);
|
||||
when(mWifiManager.getScanResults()).thenReturn(wifiScanResults);
|
||||
|
||||
mInternetDialog.showProgressBar();
|
||||
|
||||
@@ -217,10 +266,10 @@ public class InternetDialogTest extends SysuiTestCase {
|
||||
@Test
|
||||
public void showProgressBar_wifiEnabledWithoutWifiScanResults_showProgressBarThenHideSearch() {
|
||||
Mockito.reset(mHandler);
|
||||
when(mMockWifiManager.isWifiEnabled()).thenReturn(true);
|
||||
when(mWifiManager.isWifiEnabled()).thenReturn(true);
|
||||
List<ScanResult> wifiScanResults = mock(ArrayList.class);
|
||||
when(wifiScanResults.size()).thenReturn(0);
|
||||
when(mMockWifiManager.getScanResults()).thenReturn(wifiScanResults);
|
||||
when(mWifiManager.getScanResults()).thenReturn(wifiScanResults);
|
||||
|
||||
mInternetDialog.showProgressBar();
|
||||
|
||||
@@ -236,78 +285,4 @@ public class InternetDialogTest extends SysuiTestCase {
|
||||
assertThat(mInternetDialog.mIsProgressBarVisible).isTrue();
|
||||
assertThat(mInternetDialog.mIsSearchingHidden).isTrue();
|
||||
}
|
||||
|
||||
private class MockInternetDialog extends InternetDialog {
|
||||
|
||||
private String mMobileNetworkTitle;
|
||||
private String mMobileNetworkSummary;
|
||||
private String mConnectedWifiTitle;
|
||||
private String mConnectedWifiSummary;
|
||||
|
||||
MockInternetDialog(Context context, InternetDialogFactory internetDialogFactory,
|
||||
InternetDialogController internetDialogController, boolean canConfigMobileData,
|
||||
boolean aboveStatusBar, UiEventLogger uiEventLogger, @Main Handler handler) {
|
||||
super(context, internetDialogFactory, internetDialogController, canConfigMobileData,
|
||||
aboveStatusBar, uiEventLogger, handler);
|
||||
mAdapter = mInternetAdapter;
|
||||
mWifiManager = mMockWifiManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
String getMobileNetworkTitle() {
|
||||
return mMobileNetworkTitle;
|
||||
}
|
||||
|
||||
@Override
|
||||
String getMobileNetworkSummary() {
|
||||
return mMobileNetworkSummary;
|
||||
}
|
||||
|
||||
void setMobileNetworkTitle(String title) {
|
||||
mMobileNetworkTitle = title;
|
||||
}
|
||||
|
||||
void setMobileNetworkSummary(String summary) {
|
||||
mMobileNetworkSummary = summary;
|
||||
}
|
||||
|
||||
@Override
|
||||
String getConnectedWifiTitle() {
|
||||
return mConnectedWifiTitle;
|
||||
}
|
||||
|
||||
@Override
|
||||
String getConnectedWifiSummary() {
|
||||
return mConnectedWifiSummary;
|
||||
}
|
||||
|
||||
void setConnectedWifiTitle(String title) {
|
||||
mConnectedWifiTitle = title;
|
||||
}
|
||||
|
||||
void setConnectedWifiSummary(String summary) {
|
||||
mConnectedWifiSummary = summary;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWifiStateReceived(Context context, Intent intent) {
|
||||
setMobileNetworkTitle(MOBILE_NETWORK_TITLE);
|
||||
setMobileNetworkSummary(MOBILE_NETWORK_SUMMARY);
|
||||
}
|
||||
}
|
||||
|
||||
private class WifiReceiver extends BroadcastReceiver {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
String action = intent.getAction();
|
||||
if (action.equals(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (action.equals(WifiManager.NETWORK_STATE_CHANGED_ACTION)) {
|
||||
mInternetDialog.updateDialog();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user