[Provider Model] Add Wi-Fi toggle in internet panel
- Add a new slice row for Wi-Fi toggle in the network lists - Increase the maximum number of network lists to 6 Bug: 189912933 Test: manual test atest -c ProviderModelSliceTest Change-Id: Ie25e108573f264ab3a94fc6804b9d46d855eeea1
This commit is contained in:
@@ -16,10 +16,10 @@
|
||||
|
||||
package com.android.settings.network;
|
||||
|
||||
|
||||
import static android.app.slice.Slice.EXTRA_TOGGLE_STATE;
|
||||
|
||||
import static com.android.settings.slices.CustomSliceRegistry.PROVIDER_MODEL_SLICE_URI;
|
||||
import static com.android.settings.slices.CustomSliceRegistry.WIFI_SLICE_URI;
|
||||
|
||||
import android.annotation.ColorInt;
|
||||
import android.app.AlertDialog;
|
||||
@@ -96,78 +96,77 @@ public class ProviderModelSlice extends WifiSlice {
|
||||
@Override
|
||||
public Slice getSlice() {
|
||||
// The provider model slice step:
|
||||
// First section: Add a Wi-Fi item which state is connected.
|
||||
// Second section: Add a carrier item.
|
||||
// Third section: Add the Wi-Fi items which are not connected.
|
||||
// Fourth section: If device has connection problem, this row show the message for user.
|
||||
@InternetUpdater.InternetType int internetType = getInternetType();
|
||||
// First section: Add the Ethernet item.
|
||||
// Second section: Add the carrier item.
|
||||
// Third section: Add the Wi-Fi toggle item.
|
||||
// Fourth section: Add the connected Wi-Fi item.
|
||||
// Fifth section: Add the Wi-Fi items which are not connected.
|
||||
// Sixth section: Add the See All item.
|
||||
final ListBuilder listBuilder = mHelper.createListBuilder(getUri());
|
||||
if (mHelper.isAirplaneModeEnabled() && !mWifiManager.isWifiEnabled()
|
||||
&& internetType != InternetUpdater.INTERNET_ETHERNET) {
|
||||
log("Airplane mode is enabled.");
|
||||
return listBuilder.build();
|
||||
}
|
||||
|
||||
int maxListSize = 0;
|
||||
List<WifiSliceItem> wifiList = null;
|
||||
final NetworkProviderWorker worker = getWorker();
|
||||
if (worker != null) {
|
||||
// get Wi-Fi list.
|
||||
wifiList = worker.getResults();
|
||||
maxListSize = worker.getApRowCount();
|
||||
} else {
|
||||
log("network provider worker is null.");
|
||||
}
|
||||
|
||||
final boolean hasCarrier = mHelper.hasCarrier();
|
||||
log("hasCarrier: " + hasCarrier);
|
||||
|
||||
// First section: Add a Ethernet or Wi-Fi item which state is connected.
|
||||
boolean isConnectedWifiAddedTop = false;
|
||||
final WifiSliceItem connectedWifiItem = mHelper.getConnectedWifiItem(wifiList);
|
||||
if (internetType == InternetUpdater.INTERNET_ETHERNET) {
|
||||
// First section: Add the Ethernet item.
|
||||
if (getInternetType() == InternetUpdater.INTERNET_ETHERNET) {
|
||||
log("get Ethernet item which is connected");
|
||||
listBuilder.addRow(createEthernetRow());
|
||||
maxListSize--;
|
||||
} else {
|
||||
if (connectedWifiItem != null && internetType == InternetUpdater.INTERNET_WIFI) {
|
||||
log("get Wi-Fi item which is connected to internet");
|
||||
listBuilder.addRow(getWifiSliceItemRow(connectedWifiItem));
|
||||
isConnectedWifiAddedTop = true;
|
||||
}
|
||||
|
||||
// Second section: Add the carrier item.
|
||||
if (!mHelper.isAirplaneModeEnabled()) {
|
||||
final boolean hasCarrier = mHelper.hasCarrier();
|
||||
log("hasCarrier: " + hasCarrier);
|
||||
if (hasCarrier) {
|
||||
mHelper.updateTelephony();
|
||||
listBuilder.addRow(
|
||||
mHelper.createCarrierRow(
|
||||
worker != null ? worker.getNetworkTypeDescription() : ""));
|
||||
maxListSize--;
|
||||
}
|
||||
}
|
||||
|
||||
// Second section: Add a carrier item.
|
||||
if (hasCarrier) {
|
||||
mHelper.updateTelephony();
|
||||
listBuilder.addRow(
|
||||
mHelper.createCarrierRow(
|
||||
worker != null ? worker.getNetworkTypeDescription() : ""));
|
||||
maxListSize--;
|
||||
// Third section: Add the Wi-Fi toggle item.
|
||||
final boolean isWifiEnabled = mWifiManager.isWifiEnabled();
|
||||
listBuilder.addRow(createWifiToggleRow(mContext, isWifiEnabled));
|
||||
maxListSize--;
|
||||
if (!isWifiEnabled) {
|
||||
log("Wi-Fi is disabled");
|
||||
return listBuilder.build();
|
||||
}
|
||||
List<WifiSliceItem> wifiList = (worker != null) ? worker.getResults() : null;
|
||||
if (wifiList == null || wifiList.size() <= 0) {
|
||||
log("Wi-Fi list is empty");
|
||||
return listBuilder.build();
|
||||
}
|
||||
|
||||
// Third section: Add the connected Wi-Fi item to Wi-Fi list if the Ethernet is connected.
|
||||
if (connectedWifiItem != null && !isConnectedWifiAddedTop) {
|
||||
// Fourth section: Add the connected Wi-Fi item.
|
||||
final WifiSliceItem connectedWifiItem = mHelper.getConnectedWifiItem(wifiList);
|
||||
if (connectedWifiItem != null) {
|
||||
log("get Wi-Fi item which is connected");
|
||||
listBuilder.addRow(getWifiSliceItemRow(connectedWifiItem));
|
||||
maxListSize--;
|
||||
}
|
||||
|
||||
// Fourth section: Add the Wi-Fi items which are not connected.
|
||||
if (wifiList != null && wifiList.size() > 0) {
|
||||
log("get Wi-Fi items which are not connected. Wi-Fi items : " + wifiList.size());
|
||||
|
||||
final List<WifiSliceItem> disconnectedWifiList = wifiList.stream()
|
||||
.filter(wifiSliceItem -> wifiSliceItem.getConnectedState()
|
||||
!= WifiEntry.CONNECTED_STATE_CONNECTED)
|
||||
.limit(maxListSize - 1)
|
||||
.collect(Collectors.toList());
|
||||
for (WifiSliceItem item : disconnectedWifiList) {
|
||||
listBuilder.addRow(getWifiSliceItemRow(item));
|
||||
}
|
||||
listBuilder.addRow(getSeeAllRow());
|
||||
// Fifth section: Add the Wi-Fi items which are not connected.
|
||||
log("get Wi-Fi items which are not connected. Wi-Fi items : " + wifiList.size());
|
||||
final List<WifiSliceItem> disconnectedWifiList = wifiList.stream()
|
||||
.filter(item -> item.getConnectedState() != WifiEntry.CONNECTED_STATE_CONNECTED)
|
||||
.limit(maxListSize - 1)
|
||||
.collect(Collectors.toList());
|
||||
for (WifiSliceItem item : disconnectedWifiList) {
|
||||
listBuilder.addRow(getWifiSliceItemRow(item));
|
||||
}
|
||||
|
||||
// Sixth section: Add the See All item.
|
||||
log("add See-All");
|
||||
listBuilder.addRow(getSeeAllRow());
|
||||
|
||||
return listBuilder.build();
|
||||
}
|
||||
|
||||
@@ -324,6 +323,26 @@ public class ProviderModelSlice extends WifiSlice {
|
||||
.setSubtitle(mContext.getText(R.string.to_switch_networks_disconnect_ethernet));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return a {@link ListBuilder.RowBuilder} of the Wi-Fi toggle.
|
||||
*/
|
||||
protected ListBuilder.RowBuilder createWifiToggleRow(Context context, boolean isWifiEnabled) {
|
||||
final Intent intent = new Intent(WIFI_SLICE_URI.toString())
|
||||
.setData(WIFI_SLICE_URI)
|
||||
.setClass(context, SliceBroadcastReceiver.class)
|
||||
.putExtra(EXTRA_TOGGLE_STATE, !isWifiEnabled)
|
||||
// The FLAG_RECEIVER_FOREGROUND flag is necessary to avoid the intent delay of
|
||||
// the first sending after the device restarts
|
||||
.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
|
||||
final PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, intent,
|
||||
PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE);
|
||||
final SliceAction toggleSliceAction = SliceAction.createToggle(pendingIntent,
|
||||
null /* actionTitle */, isWifiEnabled);
|
||||
return new ListBuilder.RowBuilder()
|
||||
.setTitle(context.getString(R.string.wifi_settings))
|
||||
.setPrimaryAction(toggleSliceAction);
|
||||
}
|
||||
|
||||
protected ListBuilder.RowBuilder getSeeAllRow() {
|
||||
final CharSequence title = mContext.getText(R.string.previous_connected_see_all);
|
||||
final IconCompat icon = getSeeAllIcon();
|
||||
|
Reference in New Issue
Block a user