Introduce new Disconnect functionality for Wifi networks in Internet
Panel only - Display the close icon on the Wi-Fi network connected to the Internet, and performs the same action as tapping on the carrier network when tapped it. - Display the cog icon on the Wi-Fi network if it has no the Internet access. - Screenshot: https://screenshot.googleplex.com/YBQ8onG2dFJ8Q2a Bug: 187995278 Test: manual test atest -c ProviderModelSliceTest Change-Id: Id54a94c1fdfc37aff5cc37d6fb9f5478c0dccb00
This commit is contained in:
@@ -34,6 +34,7 @@ import androidx.annotation.VisibleForTesting;
|
|||||||
import androidx.core.graphics.drawable.IconCompat;
|
import androidx.core.graphics.drawable.IconCompat;
|
||||||
import androidx.slice.Slice;
|
import androidx.slice.Slice;
|
||||||
import androidx.slice.builders.ListBuilder;
|
import androidx.slice.builders.ListBuilder;
|
||||||
|
import androidx.slice.builders.SliceAction;
|
||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.SubSettings;
|
import com.android.settings.SubSettings;
|
||||||
@@ -59,6 +60,8 @@ import java.util.stream.Collectors;
|
|||||||
public class ProviderModelSlice extends WifiSlice {
|
public class ProviderModelSlice extends WifiSlice {
|
||||||
|
|
||||||
private static final String TAG = "ProviderModelSlice";
|
private static final String TAG = "ProviderModelSlice";
|
||||||
|
protected static final String ACTION_TITLE_CONNECT_TO_CARRIER = "Connect_To_Carrier";
|
||||||
|
|
||||||
private final ProviderModelSliceHelper mHelper;
|
private final ProviderModelSliceHelper mHelper;
|
||||||
|
|
||||||
public ProviderModelSlice(Context context) {
|
public ProviderModelSlice(Context context) {
|
||||||
@@ -249,6 +252,31 @@ public class ProviderModelSlice extends WifiSlice {
|
|||||||
.setSubtitle(mContext.getText(R.string.to_switch_networks_disconnect_ethernet));
|
.setSubtitle(mContext.getText(R.string.to_switch_networks_disconnect_ethernet));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected ListBuilder.RowBuilder getWifiSliceItemRow(WifiSliceItem wifiSliceItem) {
|
||||||
|
final CharSequence title = wifiSliceItem.getTitle();
|
||||||
|
final IconCompat levelIcon = getWifiSliceItemLevelIcon(wifiSliceItem);
|
||||||
|
final ListBuilder.RowBuilder rowBuilder = new ListBuilder.RowBuilder()
|
||||||
|
.setTitleItem(levelIcon, ListBuilder.ICON_IMAGE)
|
||||||
|
.setTitle(title)
|
||||||
|
.setSubtitle(wifiSliceItem.getSummary())
|
||||||
|
.setContentDescription(wifiSliceItem.getContentDescription());
|
||||||
|
|
||||||
|
final IconCompat endIcon;
|
||||||
|
if (wifiSliceItem.hasInternetAccess()) {
|
||||||
|
rowBuilder.setPrimaryAction(SliceAction.create(getBroadcastIntent(mContext),
|
||||||
|
levelIcon, ListBuilder.ICON_IMAGE, ACTION_TITLE_CONNECT_TO_CARRIER));
|
||||||
|
endIcon = IconCompat.createWithResource(mContext, R.drawable.ic_settings_close);
|
||||||
|
} else {
|
||||||
|
rowBuilder.setPrimaryAction(getWifiEntryAction(wifiSliceItem, levelIcon, title));
|
||||||
|
endIcon = getEndIcon(wifiSliceItem);
|
||||||
|
}
|
||||||
|
if (endIcon != null) {
|
||||||
|
rowBuilder.addEndItem(endIcon, ListBuilder.ICON_IMAGE);
|
||||||
|
}
|
||||||
|
return rowBuilder;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected IconCompat getWifiSliceItemLevelIcon(WifiSliceItem wifiSliceItem) {
|
protected IconCompat getWifiSliceItemLevelIcon(WifiSliceItem wifiSliceItem) {
|
||||||
if (wifiSliceItem.getConnectedState() == WifiEntry.CONNECTED_STATE_CONNECTED
|
if (wifiSliceItem.getConnectedState() == WifiEntry.CONNECTED_STATE_CONNECTED
|
||||||
|
@@ -183,7 +183,7 @@ public class WifiSlice implements CustomSliceable {
|
|||||||
return Utils.createIconWithDrawable(drawable);
|
return Utils.createIconWithDrawable(drawable);
|
||||||
}
|
}
|
||||||
|
|
||||||
private IconCompat getEndIcon(WifiSliceItem wifiSliceItem) {
|
protected IconCompat getEndIcon(WifiSliceItem wifiSliceItem) {
|
||||||
if (wifiSliceItem.getConnectedState() != WifiEntry.CONNECTED_STATE_DISCONNECTED) {
|
if (wifiSliceItem.getConnectedState() != WifiEntry.CONNECTED_STATE_DISCONNECTED) {
|
||||||
return IconCompat.createWithResource(mContext, R.drawable.ic_settings_24dp);
|
return IconCompat.createWithResource(mContext, R.drawable.ic_settings_24dp);
|
||||||
}
|
}
|
||||||
@@ -194,7 +194,7 @@ public class WifiSlice implements CustomSliceable {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private SliceAction getWifiEntryAction(WifiSliceItem wifiSliceItem, IconCompat icon,
|
protected SliceAction getWifiEntryAction(WifiSliceItem wifiSliceItem, IconCompat icon,
|
||||||
CharSequence title) {
|
CharSequence title) {
|
||||||
final int requestCode = wifiSliceItem.getKey().hashCode();
|
final int requestCode = wifiSliceItem.getKey().hashCode();
|
||||||
|
|
||||||
|
@@ -36,6 +36,7 @@ public class WifiSliceItem {
|
|||||||
private final int mLevel;
|
private final int mLevel;
|
||||||
private final boolean mShouldShowXLevelIcon;
|
private final boolean mShouldShowXLevelIcon;
|
||||||
private final boolean mShouldEditBeforeConnect;
|
private final boolean mShouldEditBeforeConnect;
|
||||||
|
private final boolean mHasInternetAccess;
|
||||||
private final String mSummary;
|
private final String mSummary;
|
||||||
|
|
||||||
// These values must be kept within [WifiEntry.WIFI_LEVEL_MIN, WifiEntry.WIFI_LEVEL_MAX]
|
// These values must be kept within [WifiEntry.WIFI_LEVEL_MIN, WifiEntry.WIFI_LEVEL_MAX]
|
||||||
@@ -56,6 +57,7 @@ public class WifiSliceItem {
|
|||||||
mLevel = wifiEntry.getLevel();
|
mLevel = wifiEntry.getLevel();
|
||||||
mShouldShowXLevelIcon = wifiEntry.shouldShowXLevelIcon();
|
mShouldShowXLevelIcon = wifiEntry.shouldShowXLevelIcon();
|
||||||
mShouldEditBeforeConnect = wifiEntry.shouldEditBeforeConnect();
|
mShouldEditBeforeConnect = wifiEntry.shouldEditBeforeConnect();
|
||||||
|
mHasInternetAccess = wifiEntry.hasInternetAccess();
|
||||||
mSummary = wifiEntry.getSummary(false /* concise */);
|
mSummary = wifiEntry.getSummary(false /* concise */);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -111,6 +113,13 @@ public class WifiSliceItem {
|
|||||||
return mShouldShowXLevelIcon;
|
return mShouldShowXLevelIcon;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true when the Wi-Fi network has Internet access.
|
||||||
|
*/
|
||||||
|
public boolean hasInternetAccess() {
|
||||||
|
return mHasInternetAccess;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* In Wi-Fi picker, when users click a saved network, it will connect to the Wi-Fi network.
|
* In Wi-Fi picker, when users click a saved network, it will connect to the Wi-Fi network.
|
||||||
* However, for some special cases, Wi-Fi picker should show Wi-Fi editor UI for users to edit
|
* However, for some special cases, Wi-Fi picker should show Wi-Fi editor UI for users to edit
|
||||||
|
@@ -16,6 +16,8 @@
|
|||||||
|
|
||||||
package com.android.settings.network;
|
package com.android.settings.network;
|
||||||
|
|
||||||
|
import static com.android.settings.network.ProviderModelSlice.ACTION_TITLE_CONNECT_TO_CARRIER;
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import static org.mockito.ArgumentMatchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
@@ -96,10 +98,12 @@ public class ProviderModelSliceTest {
|
|||||||
private WifiSliceItem mMockWifiSliceItem3;
|
private WifiSliceItem mMockWifiSliceItem3;
|
||||||
@Mock
|
@Mock
|
||||||
ListBuilder.RowBuilder mMockCarrierRowBuild;
|
ListBuilder.RowBuilder mMockCarrierRowBuild;
|
||||||
|
@Mock
|
||||||
|
WifiPickerTracker mWifiPickerTracker;
|
||||||
|
@Mock
|
||||||
|
WifiSliceItem mWifiSliceItem;
|
||||||
|
|
||||||
private FakeFeatureFactory mFeatureFactory;
|
private FakeFeatureFactory mFeatureFactory;
|
||||||
@Mock
|
|
||||||
private WifiPickerTracker mWifiPickerTracker;
|
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
@UiThreadTest
|
@UiThreadTest
|
||||||
@@ -388,4 +392,29 @@ public class ProviderModelSliceTest {
|
|||||||
|
|
||||||
verify(mMockNetworkProviderWorker, never()).connectCarrierNetwork();
|
verify(mMockNetworkProviderWorker, never()).connectCarrierNetwork();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getWifiSliceItemRow_wifiNoInternetAccess_actionConnectToWifiSsid() {
|
||||||
|
when(mWifiSliceItem.getKey()).thenReturn("wifi_key");
|
||||||
|
when(mWifiSliceItem.getTitle()).thenReturn("wifi_ssid");
|
||||||
|
when(mWifiSliceItem.hasInternetAccess()).thenReturn(false);
|
||||||
|
|
||||||
|
ListBuilder.RowBuilder rowBuilder =
|
||||||
|
mMockProviderModelSlice.getWifiSliceItemRow(mWifiSliceItem);
|
||||||
|
|
||||||
|
assertThat(rowBuilder.getPrimaryAction().getTitle())
|
||||||
|
.isEqualTo("wifi_ssid");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getWifiSliceItemRow_wifiHasInternetAccess_actionConnectToCarrier() {
|
||||||
|
when(mWifiSliceItem.getTitle()).thenReturn("wifi_ssid");
|
||||||
|
when(mWifiSliceItem.hasInternetAccess()).thenReturn(true);
|
||||||
|
|
||||||
|
ListBuilder.RowBuilder rowBuilder =
|
||||||
|
mMockProviderModelSlice.getWifiSliceItemRow(mWifiSliceItem);
|
||||||
|
|
||||||
|
assertThat(rowBuilder.getPrimaryAction().getTitle())
|
||||||
|
.isEqualTo(ACTION_TITLE_CONNECT_TO_CARRIER);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user