[Provider Model] Launch Wi-Fi detailed when tap the connected Wi-Fi

- Uses the WifiUtils.getWifiDetailsSettingsIntent() to launch Network details settings

Bug: 191475923
Test: manual test with the topic CLs.
atest -c com.android.systemui.qs.tiles.dialog

Change-Id: I38622dc3c91e39e35c71274ca3a06272a5da17fe
This commit is contained in:
Weng Su
2021-07-15 12:10:26 +08:00
parent 5deb2aa289
commit a5570e10aa
3 changed files with 94 additions and 33 deletions

View File

@@ -55,6 +55,10 @@ import android.widget.Space;
import android.widget.Switch;
import android.widget.TextView;
import androidx.annotation.VisibleForTesting;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.android.internal.logging.UiEvent;
import com.android.internal.logging.UiEventLogger;
import com.android.settingslib.Utils;
@@ -67,10 +71,6 @@ import com.android.wifitrackerlib.WifiEntry;
import java.util.List;
import androidx.annotation.VisibleForTesting;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
/**
* Dialog for showing mobile network, connected Wi-Fi network and Wi-Fi networks.
*/
@@ -298,9 +298,7 @@ public class InternetDialog extends SystemUIDialog implements
isChecked, false);
}
});
mConnectedWifListLayout.setOnClickListener(v -> {
// TODO(b/191475923): Need to launch the detailed page of Wi-Fi entry.
});
mConnectedWifListLayout.setOnClickListener(v -> onClickConnectedWifi());
mSeeAllLayout.setOnClickListener(v -> onClickSeeMoreButton());
mWiFiToggle.setOnCheckedChangeListener(
(buttonView, isChecked) -> {
@@ -354,6 +352,10 @@ public class InternetDialog extends SystemUIDialog implements
mConnectedWifListLayout.setBackground(mBackgroundOn);
}
void onClickConnectedWifi() {
mInternetDialogController.launchWifiNetworkDetailsSetting();
}
void onClickSeeMoreButton() {
mInternetDialogController.launchNetworkSetting();
}

View File

@@ -48,6 +48,10 @@ import android.util.Log;
import android.view.Gravity;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
import com.android.internal.logging.UiEventLogger;
import com.android.keyguard.KeyguardUpdateMonitor;
import com.android.keyguard.KeyguardUpdateMonitorCallback;
@@ -56,6 +60,7 @@ import com.android.settingslib.Utils;
import com.android.settingslib.graph.SignalDrawable;
import com.android.settingslib.mobile.MobileMappings;
import com.android.settingslib.net.SignalStrengthUtil;
import com.android.settingslib.wifi.WifiUtils;
import com.android.systemui.R;
import com.android.systemui.broadcast.BroadcastDispatcher;
import com.android.systemui.dagger.qualifiers.Main;
@@ -78,10 +83,6 @@ import java.util.stream.Stream;
import javax.inject.Inject;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
public class InternetDialogController implements WifiEntry.DisconnectCallback,
NetworkController.AccessPointController.AccessPointCallback {
@@ -104,7 +105,6 @@ public class InternetDialogController implements WifiEntry.DisconnectCallback,
private WifiManager mWifiManager;
private Context mContext;
private ActivityStarter mActivityStarter;
private SubscriptionManager mSubscriptionManager;
private TelephonyManager mTelephonyManager;
private ConnectivityManager mConnectivityManager;
@@ -118,13 +118,16 @@ public class InternetDialogController implements WifiEntry.DisconnectCallback,
private IntentFilter mWifiStateFilter;
private InternetDialogCallback mCallback;
private List<WifiEntry> mWifiEntry;
private WifiEntry mConnectedEntry;
private UiEventLogger mUiEventLogger;
private BroadcastDispatcher mBroadcastDispatcher;
private KeyguardUpdateMonitor mKeyguardUpdateMonitor;
private GlobalSettings mGlobalSettings;
private int mDefaultDataSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
@VisibleForTesting
protected ActivityStarter mActivityStarter;
@VisibleForTesting
protected WifiEntry mConnectedEntry;
@VisibleForTesting
protected SubscriptionManager.OnSubscriptionsChangedListener mOnSubscriptionsChangedListener;
@VisibleForTesting
@@ -226,6 +229,17 @@ public class InternetDialogController implements WifiEntry.DisconnectCallback,
return new Intent(ACTION_NETWORK_PROVIDER_SETTINGS).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
}
protected Intent getWifiDetailsSettingsIntent() {
String key = mConnectedEntry == null ? null : mConnectedEntry.getKey();
if (TextUtils.isEmpty(key)) {
if (DEBUG) {
Log.d(TAG, "connected entry's key is empty");
}
return null;
}
return WifiUtils.getWifiDetailsSettingsIntent(key);
}
CharSequence getDialogTitleText() {
if (isAirplaneModeEnabled()) {
return mContext.getText(R.string.airplane_mode);
@@ -533,6 +547,14 @@ public class InternetDialogController implements WifiEntry.DisconnectCallback,
mActivityStarter.postStartActivityDismissingKeyguard(getSettingsIntent(), 0);
}
void launchWifiNetworkDetailsSetting() {
Intent intent = getWifiDetailsSettingsIntent();
if (intent != null) {
mCallback.dismissDialog();
mActivityStarter.postStartActivityDismissingKeyguard(intent, 0);
}
}
void connectCarrierNetwork() {
final MergedCarrierEntry mergedCarrierEntry =
mAccessPointController.getMergedCarrierEntry();

View File

@@ -3,11 +3,16 @@ package com.android.systemui.qs.tiles.dialog;
import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.wifi.ScanResult;
import android.net.wifi.WifiInfo;
@@ -20,6 +25,9 @@ import android.testing.AndroidTestingRunner;
import android.testing.TestableLooper;
import android.text.TextUtils;
import androidx.annotation.Nullable;
import androidx.test.filters.SmallTest;
import com.android.internal.logging.UiEventLogger;
import com.android.keyguard.KeyguardUpdateMonitor;
import com.android.systemui.SysuiTestCase;
@@ -33,9 +41,6 @@ import com.android.systemui.util.settings.GlobalSettings;
import com.android.systemui.util.time.FakeSystemClock;
import com.android.wifitrackerlib.WifiEntry;
import androidx.annotation.Nullable;
import androidx.test.filters.SmallTest;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -68,13 +73,15 @@ public class InternetDialogControllerTest extends SysuiTestCase {
@Mock
private Handler mHandler;
@Mock
private ActivityStarter mActivityStarter;
@Mock
private GlobalSettings mGlobalSettings;
@Mock
private KeyguardUpdateMonitor mKeyguardUpdateMonitor;
@Mock
private NetworkController.AccessPointController mAccessPointController;
@Mock
private WifiEntry mWifiEntryConnected = mock(WifiEntry.class);
private WifiEntry mConnectedEntry;
@Mock
private WifiInfo mWifiInfo;
@Mock
@@ -94,6 +101,8 @@ public class InternetDialogControllerTest extends SysuiTestCase {
mSubscriptionManager.addOnSubscriptionsChangedListener(mExecutor,
mInternetDialogController.mOnSubscriptionsChangedListener);
mInternetDialogController.onStart(mCallback);
mInternetDialogController.mActivityStarter = mActivityStarter;
mInternetDialogController.mConnectedEntry = mConnectedEntry;
}
@Test
@@ -188,7 +197,7 @@ public class InternetDialogControllerTest extends SysuiTestCase {
@Test
public void getConnectedWifiTitle_withNoConnectedEntry_returnNull() {
mInternetDialogController.setConnectedWifiEntry(null);
mInternetDialogController.mConnectedEntry = null;
assertTrue(TextUtils.equals(mInternetDialogController.getConnectedWifiTitle(),
""));
@@ -196,8 +205,7 @@ public class InternetDialogControllerTest extends SysuiTestCase {
@Test
public void getConnectedWifiTitle_withConnectedEntry_returnTitle() {
mInternetDialogController.setConnectedWifiEntry(mWifiEntryConnected);
when(mWifiEntryConnected.getTitle()).thenReturn(CONNECTED_TITLE);
when(mConnectedEntry.getTitle()).thenReturn(CONNECTED_TITLE);
assertTrue(TextUtils.equals(mInternetDialogController.getConnectedWifiTitle(),
CONNECTED_TITLE));
@@ -205,7 +213,7 @@ public class InternetDialogControllerTest extends SysuiTestCase {
@Test
public void getConnectedWifiSummary_withNoConnectedEntry_returnNull() {
mInternetDialogController.setConnectedWifiEntry(null);
mInternetDialogController.mConnectedEntry = null;
assertTrue(TextUtils.equals(mInternetDialogController.getConnectedWifiSummary(),
""));
@@ -213,13 +221,52 @@ public class InternetDialogControllerTest extends SysuiTestCase {
@Test
public void getConnectedWifiSummary_withConnectedEntry_returnSummary() {
mInternetDialogController.setConnectedWifiEntry(mWifiEntryConnected);
when(mWifiEntryConnected.getSummary(false)).thenReturn(CONNECTED_SUMMARY);
when(mConnectedEntry.getSummary(false)).thenReturn(CONNECTED_SUMMARY);
assertTrue(TextUtils.equals(mInternetDialogController.getConnectedWifiSummary(),
CONNECTED_SUMMARY));
}
@Test
public void getWifiDetailsSettingsIntent_withNoConnectedEntry_returnNull() {
mInternetDialogController.mConnectedEntry = null;
assertThat(mInternetDialogController.getWifiDetailsSettingsIntent()).isNull();
}
@Test
public void getWifiDetailsSettingsIntent_withNoConnectedEntryKey_returnNull() {
when(mConnectedEntry.getKey()).thenReturn(null);
assertThat(mInternetDialogController.getWifiDetailsSettingsIntent()).isNull();
}
@Test
public void getWifiDetailsSettingsIntent_withConnectedEntryKey_returnIntent() {
when(mConnectedEntry.getKey()).thenReturn("test_key");
assertThat(mInternetDialogController.getWifiDetailsSettingsIntent()).isNotNull();
}
@Test
public void launchWifiNetworkDetailsSetting_withNoConnectedEntry_doNothing() {
mInternetDialogController.mConnectedEntry = null;
mInternetDialogController.launchWifiNetworkDetailsSetting();
verify(mActivityStarter, never())
.postStartActivityDismissingKeyguard(any(Intent.class), anyInt());
}
@Test
public void launchWifiNetworkDetailsSetting_withConnectedEntryKey_startActivity() {
when(mConnectedEntry.getKey()).thenReturn("test_key");
mInternetDialogController.launchWifiNetworkDetailsSetting();
verify(mActivityStarter).postStartActivityDismissingKeyguard(any(Intent.class), anyInt());
}
private String getResourcesString(String name) {
return mContext.getResources().getString(getResourcesId(name));
}
@@ -231,7 +278,6 @@ public class InternetDialogControllerTest extends SysuiTestCase {
private class MockInternetDialogController extends InternetDialogController {
private WifiEntry mConnectedEntry;
private GlobalSettings mGlobalSettings;
private boolean mIsAirplaneModeOn;
@@ -256,14 +302,5 @@ public class InternetDialogControllerTest extends SysuiTestCase {
public void setAirplaneModeEnabled(boolean enabled) {
mIsAirplaneModeOn = enabled;
}
@Override
WifiEntry getConnectedWifiEntry() {
return mConnectedEntry;
}
public void setConnectedWifiEntry(WifiEntry connectedEntry) {
mConnectedEntry = connectedEntry;
}
}
}