Merge "[Provider Model] Redirect Settings Internet panel request to SystemUI." into sc-qpr1-dev am: 538af552c0
Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Settings/+/15544646 Change-Id: Iaae85f03949e22b76390956de127513c2b806863
This commit is contained in:
@@ -1,425 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2018 The Android Open Source Project
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.android.settings.panel;
|
|
||||||
|
|
||||||
import static androidx.lifecycle.Lifecycle.Event.ON_PAUSE;
|
|
||||||
import static androidx.lifecycle.Lifecycle.Event.ON_RESUME;
|
|
||||||
|
|
||||||
import android.app.settings.SettingsEnums;
|
|
||||||
import android.content.BroadcastReceiver;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.content.IntentFilter;
|
|
||||||
import android.net.Uri;
|
|
||||||
import android.net.wifi.ScanResult;
|
|
||||||
import android.net.wifi.WifiManager;
|
|
||||||
import android.os.Handler;
|
|
||||||
import android.os.HandlerExecutor;
|
|
||||||
import android.os.Looper;
|
|
||||||
import android.provider.Settings;
|
|
||||||
import android.telephony.ServiceState;
|
|
||||||
import android.telephony.SubscriptionManager;
|
|
||||||
import android.telephony.TelephonyCallback;
|
|
||||||
import android.telephony.TelephonyManager;
|
|
||||||
import android.text.TextUtils;
|
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
import androidx.annotation.VisibleForTesting;
|
|
||||||
import androidx.lifecycle.LifecycleObserver;
|
|
||||||
import androidx.lifecycle.OnLifecycleEvent;
|
|
||||||
|
|
||||||
import com.android.settings.R;
|
|
||||||
import com.android.settings.Utils;
|
|
||||||
import com.android.settings.network.AirplaneModePreferenceController;
|
|
||||||
import com.android.settings.network.InternetUpdater;
|
|
||||||
import com.android.settings.network.ProviderModelSliceHelper;
|
|
||||||
import com.android.settings.network.SubscriptionsChangeListener;
|
|
||||||
import com.android.settings.network.telephony.DataConnectivityListener;
|
|
||||||
import com.android.settings.slices.CustomSliceRegistry;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Represents the Internet Connectivity Panel.
|
|
||||||
*/
|
|
||||||
public class InternetConnectivityPanel implements PanelContent, LifecycleObserver,
|
|
||||||
InternetUpdater.InternetChangeListener, DataConnectivityListener.Client,
|
|
||||||
SubscriptionsChangeListener.SubscriptionsChangeListenerClient {
|
|
||||||
private static final String TAG = "InternetConnectivityPanel";
|
|
||||||
private static final int SUBTITLE_TEXT_NONE = -1;
|
|
||||||
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_SEARCHING_FOR_NETWORKS =
|
|
||||||
R.string.wifi_empty_list_wifi_on;
|
|
||||||
private static final int SUBTITLE_TEXT_NON_CARRIER_NETWORK_UNAVAILABLE =
|
|
||||||
R.string.non_carrier_network_unavailable;
|
|
||||||
private static final int SUBTITLE_TEXT_ALL_CARRIER_NETWORK_UNAVAILABLE =
|
|
||||||
R.string.all_network_unavailable;
|
|
||||||
|
|
||||||
private final Context mContext;
|
|
||||||
private final WifiManager mWifiManager;
|
|
||||||
private final IntentFilter mWifiStateFilter;
|
|
||||||
private final NetworkProviderTelephonyCallback mTelephonyCallback;
|
|
||||||
private final BroadcastReceiver mWifiStateReceiver = new BroadcastReceiver() {
|
|
||||||
@Override
|
|
||||||
public void onReceive(Context context, Intent intent) {
|
|
||||||
if (intent == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (TextUtils.equals(intent.getAction(), WifiManager.SCAN_RESULTS_AVAILABLE_ACTION)) {
|
|
||||||
updateProgressBar();
|
|
||||||
updatePanelTitle();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (TextUtils.equals(intent.getAction(), WifiManager.NETWORK_STATE_CHANGED_ACTION)) {
|
|
||||||
updateProgressBar();
|
|
||||||
updatePanelTitle();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
@VisibleForTesting
|
|
||||||
boolean mIsProviderModelEnabled;
|
|
||||||
@VisibleForTesting
|
|
||||||
InternetUpdater mInternetUpdater;
|
|
||||||
@VisibleForTesting
|
|
||||||
ProviderModelSliceHelper mProviderModelSliceHelper;
|
|
||||||
|
|
||||||
private int mSubtitle = SUBTITLE_TEXT_NONE;
|
|
||||||
private PanelContentCallback mCallback;
|
|
||||||
private TelephonyManager mTelephonyManager;
|
|
||||||
private SubscriptionsChangeListener mSubscriptionsListener;
|
|
||||||
private DataConnectivityListener mConnectivityListener;
|
|
||||||
private int mDefaultDataSubid = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
|
|
||||||
|
|
||||||
// Wi-Fi scanning progress bar
|
|
||||||
protected HandlerInjector mHandlerInjector;
|
|
||||||
protected boolean mIsProgressBarVisible;
|
|
||||||
protected boolean mIsScanningSubTitleShownOnce;
|
|
||||||
protected Runnable mHideProgressBarRunnable = () -> {
|
|
||||||
setProgressBarVisible(false);
|
|
||||||
};
|
|
||||||
protected Runnable mHideScanningSubTitleRunnable = () -> {
|
|
||||||
mIsScanningSubTitleShownOnce = true;
|
|
||||||
updatePanelTitle();
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Wrapper for testing compatibility.
|
|
||||||
*/
|
|
||||||
@VisibleForTesting
|
|
||||||
static class HandlerInjector {
|
|
||||||
protected final Handler mHandler;
|
|
||||||
|
|
||||||
HandlerInjector(Context context) {
|
|
||||||
mHandler = context.getMainThreadHandler();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void postDelay(Runnable runnable) {
|
|
||||||
mHandler.postDelayed(runnable, 2000 /* delay millis */);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void removeCallbacks(Runnable runnable) {
|
|
||||||
mHandler.removeCallbacks(runnable);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private InternetConnectivityPanel(Context context) {
|
|
||||||
mContext = context.getApplicationContext();
|
|
||||||
mHandlerInjector = new HandlerInjector(context);
|
|
||||||
mIsProviderModelEnabled = Utils.isProviderModelEnabled(mContext);
|
|
||||||
mInternetUpdater = new InternetUpdater(context, null /* Lifecycle */, this);
|
|
||||||
|
|
||||||
mSubscriptionsListener = new SubscriptionsChangeListener(context, this);
|
|
||||||
mConnectivityListener = new DataConnectivityListener(context, this);
|
|
||||||
mTelephonyCallback = new NetworkProviderTelephonyCallback();
|
|
||||||
mDefaultDataSubid = getDefaultDataSubscriptionId();
|
|
||||||
mTelephonyManager = mContext.getSystemService(TelephonyManager.class);
|
|
||||||
|
|
||||||
mWifiManager = mContext.getSystemService(WifiManager.class);
|
|
||||||
mWifiStateFilter = new IntentFilter(WifiManager.NETWORK_STATE_CHANGED_ACTION);
|
|
||||||
mWifiStateFilter.addAction(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION);
|
|
||||||
|
|
||||||
mProviderModelSliceHelper = new ProviderModelSliceHelper(mContext, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** create the panel */
|
|
||||||
public static InternetConnectivityPanel create(Context context) {
|
|
||||||
return new InternetConnectivityPanel(context);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @OnLifecycleEvent(ON_RESUME) */
|
|
||||||
@OnLifecycleEvent(ON_RESUME)
|
|
||||||
public void onResume() {
|
|
||||||
if (!mIsProviderModelEnabled) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
mInternetUpdater.onResume();
|
|
||||||
mSubscriptionsListener.start();
|
|
||||||
mConnectivityListener.start();
|
|
||||||
mTelephonyManager.registerTelephonyCallback(
|
|
||||||
new HandlerExecutor(new Handler(Looper.getMainLooper())), mTelephonyCallback);
|
|
||||||
mContext.registerReceiver(mWifiStateReceiver, mWifiStateFilter);
|
|
||||||
updateProgressBar();
|
|
||||||
updatePanelTitle();
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @OnLifecycleEvent(ON_PAUSE) */
|
|
||||||
@OnLifecycleEvent(ON_PAUSE)
|
|
||||||
public void onPause() {
|
|
||||||
if (!mIsProviderModelEnabled) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
mInternetUpdater.onPause();
|
|
||||||
mSubscriptionsListener.stop();
|
|
||||||
mConnectivityListener.stop();
|
|
||||||
mTelephonyManager.unregisterTelephonyCallback(mTelephonyCallback);
|
|
||||||
mContext.unregisterReceiver(mWifiStateReceiver);
|
|
||||||
mHandlerInjector.removeCallbacks(mHideProgressBarRunnable);
|
|
||||||
mHandlerInjector.removeCallbacks(mHideScanningSubTitleRunnable);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return a string for the title of the Panel.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public CharSequence getTitle() {
|
|
||||||
if (mIsProviderModelEnabled) {
|
|
||||||
return mContext.getText(mInternetUpdater.isAirplaneModeOn()
|
|
||||||
? R.string.airplane_mode : R.string.provider_internet_settings);
|
|
||||||
}
|
|
||||||
return mContext.getText(R.string.internet_connectivity_panel_title);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return a string for the subtitle of the Panel.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public CharSequence getSubTitle() {
|
|
||||||
if (mIsProviderModelEnabled && mSubtitle != SUBTITLE_TEXT_NONE) {
|
|
||||||
return mContext.getText(mSubtitle);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<Uri> getSlices() {
|
|
||||||
final List<Uri> uris = new ArrayList<>();
|
|
||||||
if (mIsProviderModelEnabled) {
|
|
||||||
uris.add(CustomSliceRegistry.PROVIDER_MODEL_SLICE_URI);
|
|
||||||
} else {
|
|
||||||
uris.add(CustomSliceRegistry.WIFI_SLICE_URI);
|
|
||||||
uris.add(CustomSliceRegistry.MOBILE_DATA_SLICE_URI);
|
|
||||||
uris.add(AirplaneModePreferenceController.SLICE_URI);
|
|
||||||
}
|
|
||||||
return uris;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Intent getSeeMoreIntent() {
|
|
||||||
// Disable the see more button for provider model design.
|
|
||||||
if (mIsProviderModelEnabled) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Don't remove the see more intent for non-provider model design. This intent will be
|
|
||||||
// used when isCustomizedButtonUsed() returns false.
|
|
||||||
return new Intent(Settings.ACTION_WIRELESS_SETTINGS)
|
|
||||||
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isProgressBarVisible() {
|
|
||||||
return mIsProgressBarVisible;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getMetricsCategory() {
|
|
||||||
return SettingsEnums.PANEL_INTERNET_CONNECTIVITY;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void registerCallback(PanelContentCallback callback) {
|
|
||||||
mCallback = callback;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Called when airplane mode state is changed.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void onAirplaneModeChanged(boolean isAirplaneModeOn) {
|
|
||||||
log("onAirplaneModeChanged: isAirplaneModeOn:" + isAirplaneModeOn);
|
|
||||||
updatePanelTitle();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Called when Wi-Fi enabled is changed.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void onWifiEnabledChanged(boolean enabled) {
|
|
||||||
log("onWifiEnabledChanged: enabled:" + enabled);
|
|
||||||
updatePanelTitle();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onSubscriptionsChanged() {
|
|
||||||
final int defaultDataSubId = getDefaultDataSubscriptionId();
|
|
||||||
log("onSubscriptionsChanged: defaultDataSubId:" + defaultDataSubId);
|
|
||||||
if (mDefaultDataSubid == defaultDataSubId) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (SubscriptionManager.isUsableSubscriptionId(defaultDataSubId)) {
|
|
||||||
mTelephonyManager.unregisterTelephonyCallback(mTelephonyCallback);
|
|
||||||
mTelephonyManager.registerTelephonyCallback(
|
|
||||||
new HandlerExecutor(new Handler(Looper.getMainLooper())), mTelephonyCallback);
|
|
||||||
}
|
|
||||||
updatePanelTitle();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onDataConnectivityChange() {
|
|
||||||
log("onDataConnectivityChange");
|
|
||||||
updatePanelTitle();
|
|
||||||
}
|
|
||||||
|
|
||||||
@VisibleForTesting
|
|
||||||
void updatePanelTitle() {
|
|
||||||
if (mCallback == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
updateSubtitleText();
|
|
||||||
mCallback.onHeaderChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
@VisibleForTesting
|
|
||||||
int getDefaultDataSubscriptionId() {
|
|
||||||
return SubscriptionManager.getDefaultDataSubscriptionId();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updateSubtitleText() {
|
|
||||||
mSubtitle = SUBTITLE_TEXT_NONE;
|
|
||||||
if (!mInternetUpdater.isWifiEnabled()) {
|
|
||||||
if (!mInternetUpdater.isAirplaneModeOn()) {
|
|
||||||
// When the airplane mode is off and Wi-Fi is disabled.
|
|
||||||
// Sub-Title: Wi-Fi is off
|
|
||||||
log("Airplane mode off + Wi-Fi off.");
|
|
||||||
mSubtitle = SUBTITLE_TEXT_WIFI_IS_OFF;
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mInternetUpdater.isAirplaneModeOn()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
final List<ScanResult> wifiList = mWifiManager.getScanResults();
|
|
||||||
if (wifiList != null && wifiList.size() != 0) {
|
|
||||||
// When the Wi-Fi scan result is not empty
|
|
||||||
// Sub-Title: Tap a network to connect
|
|
||||||
mSubtitle = SUBTITLE_TEXT_TAP_A_NETWORK_TO_CONNECT;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!mIsScanningSubTitleShownOnce && mIsProgressBarVisible) {
|
|
||||||
// When the Wi-Fi scan result callback is received
|
|
||||||
// Sub-Title: Searching for networks...
|
|
||||||
mSubtitle = SUBTITLE_TEXT_SEARCHING_FOR_NETWORKS;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Sub-Title:
|
|
||||||
// show non_carrier_network_unavailable
|
|
||||||
// - while Wi-Fi on + no Wi-Fi item
|
|
||||||
// - while Wi-Fi on + no Wi-Fi item + mobile data off
|
|
||||||
// show all_network_unavailable:
|
|
||||||
// - while Wi-Fi on + no Wi-Fi item + no carrier item
|
|
||||||
// - while Wi-Fi on + no Wi-Fi item + service is out of service
|
|
||||||
// - while Wi-Fi on + no Wi-Fi item + mobile data on + no carrier data.
|
|
||||||
log("No Wi-Fi item.");
|
|
||||||
if (!mProviderModelSliceHelper.hasCarrier()
|
|
||||||
|| (!mProviderModelSliceHelper.isVoiceStateInService()
|
|
||||||
&& !mProviderModelSliceHelper.isDataStateInService())) {
|
|
||||||
log("no carrier or service is out of service.");
|
|
||||||
mSubtitle = SUBTITLE_TEXT_ALL_CARRIER_NETWORK_UNAVAILABLE;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!mProviderModelSliceHelper.isMobileDataEnabled()) {
|
|
||||||
log("mobile data off");
|
|
||||||
mSubtitle = SUBTITLE_TEXT_NON_CARRIER_NETWORK_UNAVAILABLE;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!mProviderModelSliceHelper.isDataSimActive()) {
|
|
||||||
log("no carrier data.");
|
|
||||||
mSubtitle = SUBTITLE_TEXT_ALL_CARRIER_NETWORK_UNAVAILABLE;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
mSubtitle = SUBTITLE_TEXT_NON_CARRIER_NETWORK_UNAVAILABLE;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void updateProgressBar() {
|
|
||||||
if (mWifiManager == null || !mInternetUpdater.isWifiEnabled()) {
|
|
||||||
setProgressBarVisible(false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
setProgressBarVisible(true);
|
|
||||||
List<ScanResult> wifiScanResults = mWifiManager.getScanResults();
|
|
||||||
if (wifiScanResults != null && wifiScanResults.size() > 0) {
|
|
||||||
mHandlerInjector.postDelay(mHideProgressBarRunnable);
|
|
||||||
} else if (!mIsScanningSubTitleShownOnce) {
|
|
||||||
mHandlerInjector.postDelay(mHideScanningSubTitleRunnable);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void setProgressBarVisible(boolean visible) {
|
|
||||||
if (mIsProgressBarVisible == visible) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
mIsProgressBarVisible = visible;
|
|
||||||
|
|
||||||
if (mCallback == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
mCallback.onProgressBarVisibleChanged();
|
|
||||||
updatePanelTitle();
|
|
||||||
}
|
|
||||||
|
|
||||||
private class NetworkProviderTelephonyCallback extends TelephonyCallback implements
|
|
||||||
TelephonyCallback.DataConnectionStateListener,
|
|
||||||
TelephonyCallback.ServiceStateListener {
|
|
||||||
@Override
|
|
||||||
public void onServiceStateChanged(ServiceState state) {
|
|
||||||
log("onServiceStateChanged voiceState=" + state.getState()
|
|
||||||
+ " dataState=" + state.getDataRegistrationState());
|
|
||||||
updatePanelTitle();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onDataConnectionStateChanged(int state, int networkType) {
|
|
||||||
log("onDataConnectionStateChanged: networkType=" + networkType + " state=" + state);
|
|
||||||
updatePanelTitle();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void log(String s) {
|
|
||||||
Log.d(TAG, s);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -17,11 +17,14 @@
|
|||||||
package com.android.settings.panel;
|
package com.android.settings.panel;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
|
|
||||||
public class PanelFeatureProviderImpl implements PanelFeatureProvider {
|
public class PanelFeatureProviderImpl implements PanelFeatureProvider {
|
||||||
|
|
||||||
|
private static final String SYSTEMUI_PACKAGE_NAME = "com.android.systemui";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PanelContent getPanel(Context context, Bundle bundle) {
|
public PanelContent getPanel(Context context, Bundle bundle) {
|
||||||
if (context == null) {
|
if (context == null) {
|
||||||
@@ -35,7 +38,12 @@ public class PanelFeatureProviderImpl implements PanelFeatureProvider {
|
|||||||
|
|
||||||
switch (panelType) {
|
switch (panelType) {
|
||||||
case Settings.Panel.ACTION_INTERNET_CONNECTIVITY:
|
case Settings.Panel.ACTION_INTERNET_CONNECTIVITY:
|
||||||
return InternetConnectivityPanel.create(context);
|
// Redirect to the internet dialog in SystemUI.
|
||||||
|
Intent intent = new Intent(Settings.Panel.ACTION_INTERNET_CONNECTIVITY);
|
||||||
|
intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND)
|
||||||
|
.setPackage(SYSTEMUI_PACKAGE_NAME);
|
||||||
|
context.sendBroadcast(intent);
|
||||||
|
return null;
|
||||||
case Settings.Panel.ACTION_NFC:
|
case Settings.Panel.ACTION_NFC:
|
||||||
return NfcPanel.create(context);
|
return NfcPanel.create(context);
|
||||||
case Settings.Panel.ACTION_WIFI:
|
case Settings.Panel.ACTION_WIFI:
|
||||||
|
@@ -1,341 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2021 The Android Open Source Project
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.android.settings.panel;
|
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
|
||||||
|
|
||||||
import static org.mockito.Mockito.clearInvocations;
|
|
||||||
import static org.mockito.Mockito.doReturn;
|
|
||||||
import static org.mockito.Mockito.mock;
|
|
||||||
import static org.mockito.Mockito.spy;
|
|
||||||
import static org.mockito.Mockito.verify;
|
|
||||||
import static org.mockito.Mockito.when;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.net.Uri;
|
|
||||||
import android.net.wifi.ScanResult;
|
|
||||||
import android.net.wifi.WifiManager;
|
|
||||||
import android.os.Handler;
|
|
||||||
|
|
||||||
import androidx.test.core.app.ApplicationProvider;
|
|
||||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
|
||||||
|
|
||||||
import com.android.settings.network.AirplaneModePreferenceController;
|
|
||||||
import com.android.settings.network.InternetUpdater;
|
|
||||||
import com.android.settings.network.ProviderModelSliceHelper;
|
|
||||||
import com.android.settings.slices.CustomSliceRegistry;
|
|
||||||
import com.android.settings.testutils.ResourcesUtils;
|
|
||||||
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Rule;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.mockito.Mock;
|
|
||||||
import org.mockito.junit.MockitoJUnit;
|
|
||||||
import org.mockito.junit.MockitoRule;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@RunWith(AndroidJUnit4.class)
|
|
||||||
public class InternetConnectivityPanelTest {
|
|
||||||
|
|
||||||
public static final String TITLE_INTERNET = ResourcesUtils.getResourcesString(
|
|
||||||
ApplicationProvider.getApplicationContext(), "provider_internet_settings");
|
|
||||||
public static final String TITLE_APM = ResourcesUtils.getResourcesString(
|
|
||||||
ApplicationProvider.getApplicationContext(), "airplane_mode");
|
|
||||||
public static final String SUBTITLE_TEXT_WIFI_IS_OFF =
|
|
||||||
ResourcesUtils.getResourcesString(ApplicationProvider.getApplicationContext(),
|
|
||||||
"wifi_is_off");
|
|
||||||
public static final String SUBTITLE_TEXT_TAP_A_NETWORK_TO_CONNECT =
|
|
||||||
ResourcesUtils.getResourcesString(ApplicationProvider.getApplicationContext(),
|
|
||||||
"tap_a_network_to_connect");
|
|
||||||
public static final String SUBTITLE_NON_CARRIER_NETWORK_UNAVAILABLE =
|
|
||||||
ResourcesUtils.getResourcesString(ApplicationProvider.getApplicationContext(),
|
|
||||||
"non_carrier_network_unavailable");
|
|
||||||
public static final String SUBTITLE_ALL_NETWORK_UNAVAILABLE =
|
|
||||||
ResourcesUtils.getResourcesString(ApplicationProvider.getApplicationContext(),
|
|
||||||
"all_network_unavailable");
|
|
||||||
public static final String BUTTON_TURN_ON_WIFI = ResourcesUtils.getResourcesString(
|
|
||||||
ApplicationProvider.getApplicationContext(), "turn_on_wifi");
|
|
||||||
public static final String BUTTON_TURN_OFF_WIFI = ResourcesUtils.getResourcesString(
|
|
||||||
ApplicationProvider.getApplicationContext(), "turn_off_wifi");
|
|
||||||
|
|
||||||
@Rule
|
|
||||||
public final MockitoRule mMocks = MockitoJUnit.rule();
|
|
||||||
@Mock
|
|
||||||
Handler mMainThreadHandler;
|
|
||||||
@Mock
|
|
||||||
PanelContentCallback mPanelContentCallback;
|
|
||||||
@Mock
|
|
||||||
InternetUpdater mInternetUpdater;
|
|
||||||
@Mock
|
|
||||||
private WifiManager mWifiManager;
|
|
||||||
@Mock
|
|
||||||
private ProviderModelSliceHelper mProviderModelSliceHelper;
|
|
||||||
|
|
||||||
private Context mContext;
|
|
||||||
private FakeHandlerInjector mFakeHandlerInjector;
|
|
||||||
private InternetConnectivityPanel mPanel;
|
|
||||||
|
|
||||||
private class FakeHandlerInjector extends InternetConnectivityPanel.HandlerInjector {
|
|
||||||
|
|
||||||
private Runnable mRunnable;
|
|
||||||
|
|
||||||
FakeHandlerInjector(Context context) {
|
|
||||||
super(context);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void postDelay(Runnable runnable) {
|
|
||||||
mRunnable = runnable;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Runnable getRunnable() {
|
|
||||||
return mRunnable;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Before
|
|
||||||
public void setUp() {
|
|
||||||
mContext = spy(ApplicationProvider.getApplicationContext());
|
|
||||||
mFakeHandlerInjector = new FakeHandlerInjector(mContext);
|
|
||||||
when(mContext.getApplicationContext()).thenReturn(mContext);
|
|
||||||
when(mContext.getMainThreadHandler()).thenReturn(mMainThreadHandler);
|
|
||||||
when(mContext.getSystemService(WifiManager.class)).thenReturn(mWifiManager);
|
|
||||||
|
|
||||||
mPanel = InternetConnectivityPanel.create(mContext);
|
|
||||||
mPanel.registerCallback(mPanelContentCallback);
|
|
||||||
mPanel.mIsProviderModelEnabled = true;
|
|
||||||
mPanel.mInternetUpdater = mInternetUpdater;
|
|
||||||
mPanel.mProviderModelSliceHelper = mProviderModelSliceHelper;
|
|
||||||
mPanel.mHandlerInjector = mFakeHandlerInjector;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void getTitle_apmOff_shouldBeInternet() {
|
|
||||||
doReturn(false).when(mInternetUpdater).isAirplaneModeOn();
|
|
||||||
|
|
||||||
assertThat(mPanel.getTitle()).isEqualTo(TITLE_INTERNET);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void getTitle_apmOn_shouldBeApm() {
|
|
||||||
doReturn(true).when(mInternetUpdater).isAirplaneModeOn();
|
|
||||||
|
|
||||||
assertThat(mPanel.getTitle()).isEqualTo(TITLE_APM);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void getSubTitle_apmOnWifiOff_shouldBeNull() {
|
|
||||||
doReturn(true).when(mInternetUpdater).isAirplaneModeOn();
|
|
||||||
doReturn(false).when(mInternetUpdater).isWifiEnabled();
|
|
||||||
|
|
||||||
assertThat(mPanel.getSubTitle()).isNull();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void getSubTitle_apmOnWifiOn_shouldBeNull() {
|
|
||||||
doReturn(true).when(mInternetUpdater).isAirplaneModeOn();
|
|
||||||
doReturn(true).when(mInternetUpdater).isWifiEnabled();
|
|
||||||
|
|
||||||
assertThat(mPanel.getSubTitle()).isNull();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void getSubTitle_apmOffWifiOff_wifiIsOn() {
|
|
||||||
doReturn(false).when(mInternetUpdater).isAirplaneModeOn();
|
|
||||||
doReturn(false).when(mInternetUpdater).isWifiEnabled();
|
|
||||||
|
|
||||||
mPanel.updatePanelTitle();
|
|
||||||
|
|
||||||
assertThat(mPanel.getSubTitle()).isEqualTo(SUBTITLE_TEXT_WIFI_IS_OFF);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void getSubTitle_apmOffWifiOnNoWifiListHasCarrierData_NonCarrierNetworkUnavailable() {
|
|
||||||
List wifiList = new ArrayList<ScanResult>();
|
|
||||||
mockCondition(false, true, true, true, true, true, wifiList);
|
|
||||||
|
|
||||||
mPanel.updatePanelTitle();
|
|
||||||
|
|
||||||
assertThat(mPanel.getSubTitle()).isEqualTo(SUBTITLE_NON_CARRIER_NETWORK_UNAVAILABLE);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void getSubTitle_apmOffWifiOnNoWifiListNoCarrierItem_AllNetworkUnavailable() {
|
|
||||||
List wifiList = new ArrayList<ScanResult>();
|
|
||||||
mockCondition(false, false, false, false, false, true, wifiList);
|
|
||||||
|
|
||||||
mPanel.updatePanelTitle();
|
|
||||||
|
|
||||||
assertThat(mPanel.getSubTitle()).isEqualTo(SUBTITLE_ALL_NETWORK_UNAVAILABLE);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void getSubTitle_apmOffWifiOnNoWifiListNoDataSimActive_AllNetworkUnavailable() {
|
|
||||||
List wifiList = new ArrayList<ScanResult>();
|
|
||||||
mockCondition(false, true, false, true, true, true, wifiList);
|
|
||||||
|
|
||||||
mPanel.updatePanelTitle();
|
|
||||||
|
|
||||||
assertThat(mPanel.getSubTitle()).isEqualTo(SUBTITLE_ALL_NETWORK_UNAVAILABLE);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void getSubTitle_apmOffWifiOnNoWifiListNoService_AllNetworkUnavailable() {
|
|
||||||
List wifiList = new ArrayList<ScanResult>();
|
|
||||||
mockCondition(false, true, false, true, false, true, wifiList);
|
|
||||||
|
|
||||||
mPanel.updatePanelTitle();
|
|
||||||
|
|
||||||
assertThat(mPanel.getSubTitle()).isEqualTo(SUBTITLE_ALL_NETWORK_UNAVAILABLE);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void getSubTitle_apmOffWifiOnTwoWifiItemsNoCarrierData_tapANetworkToConnect() {
|
|
||||||
List wifiList = new ArrayList<ScanResult>();
|
|
||||||
wifiList.add(new ScanResult());
|
|
||||||
wifiList.add(new ScanResult());
|
|
||||||
mockCondition(false, true, false, true, true, true, wifiList);
|
|
||||||
|
|
||||||
mPanel.updatePanelTitle();
|
|
||||||
|
|
||||||
assertThat(mPanel.getSubTitle()).isEqualTo(SUBTITLE_TEXT_TAP_A_NETWORK_TO_CONNECT);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void getSlices_providerModelDisabled_containsNecessarySlices() {
|
|
||||||
mPanel.mIsProviderModelEnabled = false;
|
|
||||||
List<Uri> uris = mPanel.getSlices();
|
|
||||||
|
|
||||||
assertThat(uris).containsExactly(
|
|
||||||
AirplaneModePreferenceController.SLICE_URI,
|
|
||||||
CustomSliceRegistry.MOBILE_DATA_SLICE_URI,
|
|
||||||
CustomSliceRegistry.WIFI_SLICE_URI);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void getSlices_providerModelEnabled_containsNecessarySlices() {
|
|
||||||
List<Uri> uris = mPanel.getSlices();
|
|
||||||
|
|
||||||
assertThat(uris).containsExactly(CustomSliceRegistry.PROVIDER_MODEL_SLICE_URI);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void getSeeMoreIntent_providerModelDisabled_shouldNotNull() {
|
|
||||||
mPanel.mIsProviderModelEnabled = false;
|
|
||||||
|
|
||||||
assertThat(mPanel.getSeeMoreIntent()).isNotNull();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void getSeeMoreIntent_providerModelEnabled_shouldBeNull() {
|
|
||||||
mPanel.mIsProviderModelEnabled = true;
|
|
||||||
|
|
||||||
assertThat(mPanel.getSeeMoreIntent()).isNull();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void updatePanelTitle_onHeaderChanged() {
|
|
||||||
clearInvocations(mPanelContentCallback);
|
|
||||||
|
|
||||||
mPanel.updatePanelTitle();
|
|
||||||
|
|
||||||
verify(mPanelContentCallback).onHeaderChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void updateProgressBar_wifiDisabled_hideProgress() {
|
|
||||||
mPanel.mIsProgressBarVisible = true;
|
|
||||||
doReturn(false).when(mInternetUpdater).isWifiEnabled();
|
|
||||||
clearInvocations(mPanelContentCallback);
|
|
||||||
|
|
||||||
mPanel.updateProgressBar();
|
|
||||||
|
|
||||||
assertThat(mPanel.isProgressBarVisible()).isFalse();
|
|
||||||
verify(mPanelContentCallback).onProgressBarVisibleChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void updateProgressBar_noWifiScanResults_showProgressForever() {
|
|
||||||
mPanel.mIsScanningSubTitleShownOnce = false;
|
|
||||||
mPanel.mIsProgressBarVisible = false;
|
|
||||||
doReturn(true).when(mInternetUpdater).isWifiEnabled();
|
|
||||||
List<ScanResult> noWifiScanResults = new ArrayList<>();
|
|
||||||
doReturn(noWifiScanResults).when(mWifiManager).getScanResults();
|
|
||||||
clearInvocations(mPanelContentCallback);
|
|
||||||
|
|
||||||
mPanel.updateProgressBar();
|
|
||||||
|
|
||||||
assertThat(mPanel.mIsProgressBarVisible).isTrue();
|
|
||||||
verify(mPanelContentCallback).onProgressBarVisibleChanged();
|
|
||||||
verify(mPanelContentCallback).onHeaderChanged();
|
|
||||||
|
|
||||||
assertThat(mFakeHandlerInjector.getRunnable())
|
|
||||||
.isEqualTo(mPanel.mHideScanningSubTitleRunnable);
|
|
||||||
mFakeHandlerInjector.getRunnable().run();
|
|
||||||
assertThat(mPanel.mIsScanningSubTitleShownOnce).isTrue();
|
|
||||||
assertThat(mPanel.mIsProgressBarVisible).isTrue();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void updateProgressBar_hasWifiScanResults_showProgressDelayedHide() {
|
|
||||||
mPanel.mIsProgressBarVisible = false;
|
|
||||||
doReturn(true).when(mInternetUpdater).isWifiEnabled();
|
|
||||||
List<ScanResult> hasWifiScanResults = mock(ArrayList.class);
|
|
||||||
doReturn(1).when(hasWifiScanResults).size();
|
|
||||||
doReturn(hasWifiScanResults).when(mWifiManager).getScanResults();
|
|
||||||
clearInvocations(mPanelContentCallback);
|
|
||||||
|
|
||||||
mPanel.updateProgressBar();
|
|
||||||
|
|
||||||
assertThat(mPanel.isProgressBarVisible()).isTrue();
|
|
||||||
verify(mPanelContentCallback).onProgressBarVisibleChanged();
|
|
||||||
|
|
||||||
assertThat(mFakeHandlerInjector.getRunnable())
|
|
||||||
.isEqualTo(mPanel.mHideProgressBarRunnable);
|
|
||||||
mFakeHandlerInjector.getRunnable().run();
|
|
||||||
assertThat(mPanel.mIsProgressBarVisible).isFalse();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void setProgressBarVisible_onProgressBarVisibleChanged() {
|
|
||||||
mPanel.mIsProgressBarVisible = false;
|
|
||||||
doReturn(true).when(mInternetUpdater).isWifiEnabled();
|
|
||||||
clearInvocations(mPanelContentCallback);
|
|
||||||
|
|
||||||
mPanel.setProgressBarVisible(true);
|
|
||||||
|
|
||||||
assertThat(mPanel.mIsProgressBarVisible).isTrue();
|
|
||||||
verify(mPanelContentCallback).onProgressBarVisibleChanged();
|
|
||||||
verify(mPanelContentCallback).onHeaderChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void mockCondition(boolean airplaneMode, boolean hasCarrier,
|
|
||||||
boolean isDataSimActive, boolean isMobileDataEnabled, boolean isServiceInService,
|
|
||||||
boolean isWifiEnabled, List<ScanResult> wifiItems) {
|
|
||||||
doReturn(airplaneMode).when(mInternetUpdater).isAirplaneModeOn();
|
|
||||||
when(mProviderModelSliceHelper.hasCarrier()).thenReturn(hasCarrier);
|
|
||||||
when(mProviderModelSliceHelper.isDataSimActive()).thenReturn(isDataSimActive);
|
|
||||||
when(mProviderModelSliceHelper.isMobileDataEnabled()).thenReturn(isMobileDataEnabled);
|
|
||||||
when(mProviderModelSliceHelper.isDataStateInService()).thenReturn(isServiceInService);
|
|
||||||
when(mProviderModelSliceHelper.isVoiceStateInService()).thenReturn(isServiceInService);
|
|
||||||
doReturn(isWifiEnabled).when(mInternetUpdater).isWifiEnabled();
|
|
||||||
doReturn(wifiItems).when(mWifiManager).getScanResults();
|
|
||||||
}
|
|
||||||
}
|
|
@@ -20,7 +20,12 @@ import static com.android.settings.panel.SettingsPanelActivity.KEY_PANEL_TYPE_AR
|
|||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
|
import static org.mockito.Mockito.never;
|
||||||
|
import static org.mockito.Mockito.spy;
|
||||||
|
import static org.mockito.Mockito.verify;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
|
|
||||||
@@ -36,25 +41,28 @@ public class PanelFeatureProviderImplTest {
|
|||||||
|
|
||||||
private static final String TEST_PACKAGENAME = "com.test.packagename";
|
private static final String TEST_PACKAGENAME = "com.test.packagename";
|
||||||
|
|
||||||
|
private static final String SYSTEMUI_PACKAGE_NAME = "com.android.systemui";
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
private PanelFeatureProviderImpl mProvider;
|
private PanelFeatureProviderImpl mProvider;
|
||||||
private Bundle mBundle;
|
private Bundle mBundle;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
mContext = ApplicationProvider.getApplicationContext();
|
mContext = spy(ApplicationProvider.getApplicationContext());
|
||||||
mProvider = new PanelFeatureProviderImpl();
|
mProvider = new PanelFeatureProviderImpl();
|
||||||
mBundle = new Bundle();
|
mBundle = new Bundle();
|
||||||
mBundle.putString(KEY_MEDIA_PACKAGE_NAME, TEST_PACKAGENAME);
|
mBundle.putString(KEY_MEDIA_PACKAGE_NAME, TEST_PACKAGENAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getPanel_internetConnectivityKey_returnsCorrectPanel() {
|
public void getPanel_internetConnectivityKey_sendsCorrectBroadcast() {
|
||||||
mBundle.putString(KEY_PANEL_TYPE_ARGUMENT, Settings.Panel.ACTION_INTERNET_CONNECTIVITY);
|
mBundle.putString(KEY_PANEL_TYPE_ARGUMENT, Settings.Panel.ACTION_INTERNET_CONNECTIVITY);
|
||||||
|
mProvider.getPanel(mContext, mBundle);
|
||||||
|
Intent intent = new Intent(Settings.Panel.ACTION_INTERNET_CONNECTIVITY);
|
||||||
|
intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND)
|
||||||
|
.setPackage(SYSTEMUI_PACKAGE_NAME);
|
||||||
|
|
||||||
final PanelContent panel = mProvider.getPanel(mContext, mBundle);
|
verify(mContext, never()).sendBroadcast(intent);
|
||||||
|
|
||||||
assertThat(panel).isInstanceOf(InternetConnectivityPanel.class);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
Reference in New Issue
Block a user