Show slice without toggle when there's no wifi permission
When the presenter app doesn't have certain permissions, it's safer to go with a generic fallback slice which just redirects user to the actual settings page. Test: test on the presenter app. robo test Fix: 178014725 Change-Id: I6f5358af2e00cb2fedba0b3f1474a026135986c6
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;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user