[RESTRICT AUTOMERGE] Add Wi-Fi Scanning notify to QS Internet Dialog
- Show message when Wi-Fi is OFF and Wi-Fi Scanning is ON
- Don't show message when device is locked
- Show a "Change" link to launch Wi-Fi Scanning Settings
Bug: 202323013
Test: manual test to verify on the device.
atest -c InternetDialogControllerTest \
InternetDialogTest
Change-Id: I5eb4563a69e85050532c8b4fe3748e01cc7d9ca5
(cherry picked from commit 8c0847b0fe)
This commit is contained in:
committed by
Android Build Coastguard Worker
parent
148d7fe341
commit
7a42ab512f
@@ -323,6 +323,46 @@
|
||||
</FrameLayout>
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/wifi_scan_notify_layout"
|
||||
style="@style/InternetDialog.Network"
|
||||
android:orientation="vertical"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingBottom="4dp"
|
||||
android:clickable="false"
|
||||
android:focusable="false">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:minWidth="56dp"
|
||||
android:gravity="start|top"
|
||||
android:orientation="horizontal"
|
||||
android:paddingEnd="12dp"
|
||||
android:paddingTop="16dp"
|
||||
android:paddingBottom="4dp">
|
||||
<ImageView
|
||||
android:src="@drawable/ic_info_outline"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:tint="?android:attr/textColorTertiary"/>
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
<TextView
|
||||
android:id="@+id/wifi_scan_notify_text"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingTop="16dp"
|
||||
android:paddingBottom="8dp"
|
||||
android:textColor="?android:attr/textColorSecondary"
|
||||
android:clickable="true"/>
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/done_layout"
|
||||
android:layout_width="67dp"
|
||||
|
||||
@@ -30,7 +30,7 @@ import java.util.Optional;
|
||||
/**
|
||||
* A span that turns the text wrapped by annotation tag into the clickable link text.
|
||||
*/
|
||||
class AnnotationLinkSpan extends ClickableSpan {
|
||||
public class AnnotationLinkSpan extends ClickableSpan {
|
||||
private final Optional<View.OnClickListener> mClickListener;
|
||||
|
||||
private AnnotationLinkSpan(View.OnClickListener listener) {
|
||||
@@ -50,7 +50,7 @@ class AnnotationLinkSpan extends ClickableSpan {
|
||||
* @param linkInfos used to attach the click action into the corresponding span
|
||||
* @return the text attached with the span
|
||||
*/
|
||||
static CharSequence linkify(CharSequence text, LinkInfo... linkInfos) {
|
||||
public static CharSequence linkify(CharSequence text, LinkInfo... linkInfos) {
|
||||
final SpannableString msg = new SpannableString(text);
|
||||
final Annotation[] spans =
|
||||
msg.getSpans(/* queryStart= */ 0, msg.length(), Annotation.class);
|
||||
@@ -78,12 +78,12 @@ class AnnotationLinkSpan extends ClickableSpan {
|
||||
/**
|
||||
* Data class to store the annotation and the click action.
|
||||
*/
|
||||
static class LinkInfo {
|
||||
static final String DEFAULT_ANNOTATION = "link";
|
||||
public static class LinkInfo {
|
||||
public static final String DEFAULT_ANNOTATION = "link";
|
||||
private final Optional<String> mAnnotation;
|
||||
private final Optional<View.OnClickListener> mListener;
|
||||
|
||||
LinkInfo(@NonNull String annotation, View.OnClickListener listener) {
|
||||
public LinkInfo(@NonNull String annotation, View.OnClickListener listener) {
|
||||
mAnnotation = Optional.of(annotation);
|
||||
mListener = Optional.ofNullable(listener);
|
||||
}
|
||||
|
||||
@@ -36,6 +36,7 @@ import android.telephony.TelephonyDisplayInfo;
|
||||
import android.telephony.TelephonyManager;
|
||||
import android.text.Html;
|
||||
import android.text.TextUtils;
|
||||
import android.text.method.LinkMovementMethod;
|
||||
import android.util.Log;
|
||||
import android.view.Gravity;
|
||||
import android.view.LayoutInflater;
|
||||
@@ -63,6 +64,7 @@ import com.android.internal.logging.UiEvent;
|
||||
import com.android.internal.logging.UiEventLogger;
|
||||
import com.android.systemui.Prefs;
|
||||
import com.android.systemui.R;
|
||||
import com.android.systemui.accessibility.floatingmenu.AnnotationLinkSpan;
|
||||
import com.android.systemui.dagger.SysUISingleton;
|
||||
import com.android.systemui.dagger.qualifiers.Main;
|
||||
import com.android.systemui.statusbar.phone.SystemUIDialog;
|
||||
@@ -110,6 +112,8 @@ public class InternetDialog extends SystemUIDialog implements
|
||||
private LinearLayout mTurnWifiOnLayout;
|
||||
private LinearLayout mEthernetLayout;
|
||||
private TextView mWifiToggleTitleText;
|
||||
private LinearLayout mWifiScanNotifyLayout;
|
||||
private TextView mWifiScanNotifyText;
|
||||
private LinearLayout mSeeAllLayout;
|
||||
private RecyclerView mWifiRecyclerView;
|
||||
private ImageView mConnectedWifiIcon;
|
||||
@@ -220,6 +224,8 @@ public class InternetDialog extends SystemUIDialog implements
|
||||
mMobileNetworkLayout = mDialogView.requireViewById(R.id.mobile_network_layout);
|
||||
mTurnWifiOnLayout = mDialogView.requireViewById(R.id.turn_on_wifi_layout);
|
||||
mWifiToggleTitleText = mDialogView.requireViewById(R.id.wifi_toggle_title);
|
||||
mWifiScanNotifyLayout = mDialogView.requireViewById(R.id.wifi_scan_notify_layout);
|
||||
mWifiScanNotifyText = mDialogView.requireViewById(R.id.wifi_scan_notify_text);
|
||||
mConnectedWifListLayout = mDialogView.requireViewById(R.id.wifi_connected_layout);
|
||||
mConnectedWifiIcon = mDialogView.requireViewById(R.id.wifi_connected_icon);
|
||||
mConnectedWifiTitleText = mDialogView.requireViewById(R.id.wifi_connected_title);
|
||||
@@ -313,8 +319,10 @@ public class InternetDialog extends SystemUIDialog implements
|
||||
showProgressBar();
|
||||
final boolean isDeviceLocked = mInternetDialogController.isDeviceLocked();
|
||||
final boolean isWifiEnabled = mWifiManager.isWifiEnabled();
|
||||
final boolean isWifiScanEnabled = mWifiManager.isScanAlwaysAvailable();
|
||||
updateWifiToggle(isWifiEnabled, isDeviceLocked);
|
||||
updateConnectedWifi(isWifiEnabled, isDeviceLocked);
|
||||
updateWifiScanNotify(isWifiEnabled, isWifiScanEnabled, isDeviceLocked);
|
||||
|
||||
final int visibility = (isDeviceLocked || !isWifiEnabled || mWifiEntriesCount <= 0)
|
||||
? View.GONE : View.VISIBLE;
|
||||
@@ -411,6 +419,24 @@ public class InternetDialog extends SystemUIDialog implements
|
||||
mContext.getColor(R.color.connected_network_primary_color));
|
||||
}
|
||||
|
||||
@MainThread
|
||||
private void updateWifiScanNotify(boolean isWifiEnabled, boolean isWifiScanEnabled,
|
||||
boolean isDeviceLocked) {
|
||||
if (isWifiEnabled || !isWifiScanEnabled || isDeviceLocked) {
|
||||
mWifiScanNotifyLayout.setVisibility(View.GONE);
|
||||
return;
|
||||
}
|
||||
if (TextUtils.isEmpty(mWifiScanNotifyText.getText())) {
|
||||
final AnnotationLinkSpan.LinkInfo linkInfo = new AnnotationLinkSpan.LinkInfo(
|
||||
AnnotationLinkSpan.LinkInfo.DEFAULT_ANNOTATION,
|
||||
v -> mInternetDialogController.launchWifiScanningSetting());
|
||||
mWifiScanNotifyText.setText(AnnotationLinkSpan.linkify(
|
||||
getContext().getText(R.string.wifi_scan_notify_message), linkInfo));
|
||||
mWifiScanNotifyText.setMovementMethod(LinkMovementMethod.getInstance());
|
||||
}
|
||||
mWifiScanNotifyLayout.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
void onClickConnectedWifi() {
|
||||
if (mConnectedWifiEntry == null) {
|
||||
return;
|
||||
|
||||
@@ -103,6 +103,8 @@ public class InternetDialogController implements WifiEntry.DisconnectCallback,
|
||||
private static final String TAG = "InternetDialogController";
|
||||
private static final String ACTION_NETWORK_PROVIDER_SETTINGS =
|
||||
"android.settings.NETWORK_PROVIDER_SETTINGS";
|
||||
private static final String ACTION_WIFI_SCANNING_SETTINGS =
|
||||
"android.settings.WIFI_SCANNING_SETTINGS";
|
||||
private static final String EXTRA_CHOSEN_WIFI_ENTRY_KEY = "key_chosen_wifientry_key";
|
||||
public static final Drawable EMPTY_DRAWABLE = new ColorDrawable(Color.TRANSPARENT);
|
||||
public static final int NO_CELL_DATA_TYPE_ICON = 0;
|
||||
@@ -603,6 +605,13 @@ public class InternetDialogController implements WifiEntry.DisconnectCallback,
|
||||
}
|
||||
}
|
||||
|
||||
void launchWifiScanningSetting() {
|
||||
mCallback.dismissDialog();
|
||||
final Intent intent = new Intent(ACTION_WIFI_SCANNING_SETTINGS);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
mActivityStarter.postStartActivityDismissingKeyguard(intent, 0);
|
||||
}
|
||||
|
||||
void connectCarrierNetwork() {
|
||||
final MergedCarrierEntry mergedCarrierEntry =
|
||||
mAccessPointController.getMergedCarrierEntry();
|
||||
|
||||
@@ -19,6 +19,7 @@ import android.testing.AndroidTestingRunner;
|
||||
import android.testing.TestableLooper;
|
||||
import android.view.View;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import androidx.test.filters.SmallTest;
|
||||
@@ -73,6 +74,7 @@ public class InternetDialogTest extends SysuiTestCase {
|
||||
private LinearLayout mConnectedWifi;
|
||||
private RecyclerView mWifiList;
|
||||
private LinearLayout mSeeAll;
|
||||
private LinearLayout mWifiScanNotify;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@@ -104,6 +106,7 @@ public class InternetDialogTest extends SysuiTestCase {
|
||||
mConnectedWifi = mDialogView.requireViewById(R.id.wifi_connected_layout);
|
||||
mWifiList = mDialogView.requireViewById(R.id.wifi_list_layout);
|
||||
mSeeAll = mDialogView.requireViewById(R.id.see_all_layout);
|
||||
mWifiScanNotify = mDialogView.requireViewById(R.id.wifi_scan_notify_layout);
|
||||
}
|
||||
|
||||
@After
|
||||
@@ -263,6 +266,50 @@ public class InternetDialogTest extends SysuiTestCase {
|
||||
assertThat(mSeeAll.getVisibility()).isEqualTo(View.GONE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateDialog_wifiOn_hideWifiScanNotify() {
|
||||
// The preconditions WiFi ON and Internet WiFi are already in setUp()
|
||||
|
||||
mInternetDialog.updateDialog();
|
||||
|
||||
assertThat(mWifiScanNotify.getVisibility()).isEqualTo(View.GONE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateDialog_wifiOffAndWifiScanOff_hideWifiScanNotify() {
|
||||
when(mWifiManager.isWifiEnabled()).thenReturn(false);
|
||||
when(mWifiManager.isScanAlwaysAvailable()).thenReturn(false);
|
||||
|
||||
mInternetDialog.updateDialog();
|
||||
|
||||
assertThat(mWifiScanNotify.getVisibility()).isEqualTo(View.GONE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateDialog_wifiOffAndWifiScanOnAndDeviceLocked_hideWifiScanNotify() {
|
||||
when(mWifiManager.isWifiEnabled()).thenReturn(false);
|
||||
when(mWifiManager.isScanAlwaysAvailable()).thenReturn(true);
|
||||
when(mInternetDialogController.isDeviceLocked()).thenReturn(true);
|
||||
|
||||
mInternetDialog.updateDialog();
|
||||
|
||||
assertThat(mWifiScanNotify.getVisibility()).isEqualTo(View.GONE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateDialog_wifiOffAndWifiScanOnAndDeviceUnlocked_showWifiScanNotify() {
|
||||
when(mWifiManager.isWifiEnabled()).thenReturn(false);
|
||||
when(mWifiManager.isScanAlwaysAvailable()).thenReturn(true);
|
||||
when(mInternetDialogController.isDeviceLocked()).thenReturn(false);
|
||||
|
||||
mInternetDialog.updateDialog();
|
||||
|
||||
assertThat(mWifiScanNotify.getVisibility()).isEqualTo(View.VISIBLE);
|
||||
TextView wifiScanNotifyText = mDialogView.requireViewById(R.id.wifi_scan_notify_text);
|
||||
assertThat(wifiScanNotifyText.getText().length()).isNotEqualTo(0);
|
||||
assertThat(wifiScanNotifyText.getMovementMethod()).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onClickSeeMoreButton_clickSeeAll_verifyLaunchNetworkSetting() {
|
||||
mSeeAll.performClick();
|
||||
|
||||
Reference in New Issue
Block a user