Merge "Show slice without toggle when there's no wifi permission" into tm-dev am: c5153183d8
am: a0100b2171
am: f9edc98ba7
Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Settings/+/18030884 Change-Id: I1b5fe37f1b85b7aa7e7a693389ffeed55363420e Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -97,14 +97,13 @@ public class WifiSlice implements CustomSliceable {
|
||||
@Override
|
||||
public Slice getSlice() {
|
||||
// If external calling package doesn't have Wi-Fi permission.
|
||||
if (!Utils.isSettingsIntelligence(mContext) && !isPermissionGranted(mContext)) {
|
||||
Log.i(TAG, "No wifi permissions to control wifi slice.");
|
||||
return null;
|
||||
}
|
||||
|
||||
final boolean isPermissionGranted =
|
||||
Utils.isSettingsIntelligence(mContext) || isPermissionGranted(mContext);
|
||||
final boolean isWifiEnabled = isWifiEnabled();
|
||||
ListBuilder listBuilder = getListBuilder(isWifiEnabled, null /* wifiSliceItem */);
|
||||
if (!isWifiEnabled) {
|
||||
ListBuilder listBuilder = getListBuilder(isWifiEnabled, null /* wifiSliceItem */,
|
||||
isPermissionGranted);
|
||||
// If the caller doesn't have the permission granted, just return a slice without a toggle.
|
||||
if (!isWifiEnabled || !isPermissionGranted) {
|
||||
return listBuilder.build();
|
||||
}
|
||||
|
||||
@@ -116,7 +115,8 @@ public class WifiSlice implements CustomSliceable {
|
||||
|
||||
if (isFirstApActive) {
|
||||
// refresh header subtext
|
||||
listBuilder = getListBuilder(true /* isWifiEnabled */, apList.get(0));
|
||||
listBuilder = getListBuilder(
|
||||
true /* isWifiEnabled */, apList.get(0), true /* isWiFiPermissionGranted */);
|
||||
}
|
||||
|
||||
if (isApRowCollapsed()) {
|
||||
@@ -186,16 +186,21 @@ public class WifiSlice implements CustomSliceable {
|
||||
return builder;
|
||||
}
|
||||
|
||||
private ListBuilder getListBuilder(boolean isWifiEnabled, WifiSliceItem wifiSliceItem) {
|
||||
private ListBuilder getListBuilder(boolean isWifiEnabled, WifiSliceItem wifiSliceItem,
|
||||
boolean isWiFiPermissionGranted) {
|
||||
final ListBuilder builder = new ListBuilder(mContext, getUri(), ListBuilder.INFINITY)
|
||||
.setAccentColor(COLOR_NOT_TINTED)
|
||||
.setKeywords(getKeywords())
|
||||
.addRow(getHeaderRow(isWifiEnabled, wifiSliceItem));
|
||||
|
||||
if (mWifiRestriction.isChangeWifiStateAllowed(mContext)) {
|
||||
builder.addAction(SliceAction.createToggle(
|
||||
getBroadcastIntent(mContext), null /* actionTitle */, isWifiEnabled));
|
||||
if (!isWiFiPermissionGranted || !mWifiRestriction.isChangeWifiStateAllowed(mContext)) {
|
||||
return builder;
|
||||
}
|
||||
|
||||
final PendingIntent toggleAction = getBroadcastIntent(mContext);
|
||||
final SliceAction toggleSliceAction = SliceAction.createToggle(toggleAction,
|
||||
null /* actionTitle */, isWifiEnabled);
|
||||
builder.addAction(toggleSliceAction);
|
||||
|
||||
return builder;
|
||||
}
|
||||
|
||||
|
@@ -38,6 +38,7 @@ import androidx.slice.Slice;
|
||||
import androidx.slice.SliceItem;
|
||||
import androidx.slice.SliceMetadata;
|
||||
import androidx.slice.SliceProvider;
|
||||
import androidx.slice.core.SliceAction;
|
||||
import androidx.slice.core.SliceQuery;
|
||||
import androidx.slice.widget.ListContent;
|
||||
import androidx.slice.widget.SliceLiveData;
|
||||
@@ -120,6 +121,11 @@ public class WifiSliceTest {
|
||||
final Slice wifiSlice = mWifiSlice.getSlice();
|
||||
|
||||
assertThat(wifiSlice).isNotNull();
|
||||
|
||||
final SliceMetadata metadata = SliceMetadata.from(mContext, wifiSlice);
|
||||
final List<SliceAction> toggles = metadata.getToggles();
|
||||
|
||||
assertThat(toggles).hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -128,18 +134,29 @@ public class WifiSliceTest {
|
||||
ShadowWifiSlice.setWifiPermissible(true);
|
||||
|
||||
final Slice wifiSlice = mWifiSlice.getSlice();
|
||||
|
||||
assertThat(wifiSlice).isNotNull();
|
||||
|
||||
final SliceMetadata metadata = SliceMetadata.from(mContext, wifiSlice);
|
||||
final List<SliceAction> toggles = metadata.getToggles();
|
||||
|
||||
assertThat(toggles).hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getWifiSlice_notFromSIPackageAndWithoutWifiPermission_shouldNoSlice() {
|
||||
public void getWifiSlice_notFromSIPackageAndWithoutWifiPermission_shouldReturnNoToggle() {
|
||||
when(mPackageManager.getPackagesForUid(USER_ID)).thenReturn(new String[]{"com.test"});
|
||||
ShadowWifiSlice.setWifiPermissible(false);
|
||||
|
||||
final Slice wifiSlice = mWifiSlice.getSlice();
|
||||
final SliceMetadata metadata = SliceMetadata.from(mContext, wifiSlice);
|
||||
final List<SliceAction> toggles = metadata.getToggles();
|
||||
|
||||
assertThat(wifiSlice).isNull();
|
||||
assertThat(toggles).hasSize(0);
|
||||
|
||||
final int rows = SliceQuery.findAll(wifiSlice, FORMAT_SLICE, HINT_LIST_ITEM,
|
||||
null /* nonHints */).size();
|
||||
// Title row
|
||||
assertThat(rows).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -150,7 +167,6 @@ public class WifiSliceTest {
|
||||
|
||||
final int rows = SliceQuery.findAll(wifiSlice, FORMAT_SLICE, HINT_LIST_ITEM,
|
||||
null /* nonHints */).size();
|
||||
|
||||
// Title row
|
||||
assertThat(rows).isEqualTo(1);
|
||||
}
|
||||
|
Reference in New Issue
Block a user