Update a Slice Uri when unavailable
When a slice becomes unavailable, it should not update the underlying data even if the view has not changed. When we receive a change from an unavailable slice, notifychange on the Uri and do not change the underlying data. Change-Id: I91851ab668e4aece669fd65c14e0dc4ec2edefdf Fixes: 77980406 Test: robotests
This commit is contained in:
@@ -54,16 +54,16 @@ public class SliceBroadcastReceiver extends BroadcastReceiver {
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
final String action = intent.getAction();
|
||||
final String key = intent.getStringExtra(EXTRA_SLICE_KEY);
|
||||
final boolean isPlatformDefined = intent.getBooleanExtra(EXTRA_SLICE_PLATFORM_DEFINED,
|
||||
final boolean isPlatformSlice = intent.getBooleanExtra(EXTRA_SLICE_PLATFORM_DEFINED,
|
||||
false /* default */);
|
||||
|
||||
switch (action) {
|
||||
case ACTION_TOGGLE_CHANGED:
|
||||
handleToggleAction(context, key, isPlatformDefined);
|
||||
handleToggleAction(context, key, isPlatformSlice);
|
||||
break;
|
||||
case ACTION_SLIDER_CHANGED:
|
||||
int newPosition = intent.getIntExtra(Slice.EXTRA_RANGE_VALUE, -1);
|
||||
handleSliderAction(context, key, newPosition);
|
||||
handleSliderAction(context, key, newPosition, isPlatformSlice);
|
||||
break;
|
||||
case ACTION_WIFI_CHANGED:
|
||||
WifiManager wm = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
|
||||
@@ -95,6 +95,7 @@ public class SliceBroadcastReceiver extends BroadcastReceiver {
|
||||
if (!controller.isAvailable()) {
|
||||
Log.w(TAG, "Can't update " + key + " since the setting is unavailable");
|
||||
updateUri(context, key, isPlatformSlice);
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO post context.getContentResolver().notifyChanged(uri, null) in the Toggle controller
|
||||
@@ -107,7 +108,8 @@ public class SliceBroadcastReceiver extends BroadcastReceiver {
|
||||
updateUri(context, key, isPlatformSlice);
|
||||
}
|
||||
|
||||
private void handleSliderAction(Context context, String key, int newPosition) {
|
||||
private void handleSliderAction(Context context, String key, int newPosition,
|
||||
boolean isPlatformSlice) {
|
||||
if (TextUtils.isEmpty(key)) {
|
||||
throw new IllegalArgumentException(
|
||||
"No key passed to Intent for slider controller. Use extra: " + EXTRA_SLICE_KEY);
|
||||
@@ -123,6 +125,12 @@ public class SliceBroadcastReceiver extends BroadcastReceiver {
|
||||
throw new IllegalArgumentException("Slider action passed for a non-slider key: " + key);
|
||||
}
|
||||
|
||||
if (!controller.isAvailable()) {
|
||||
Log.w(TAG, "Can't update " + key + " since the setting is unavailable");
|
||||
updateUri(context, key, isPlatformSlice);
|
||||
return;
|
||||
}
|
||||
|
||||
final SliderPreferenceController sliderController = (SliderPreferenceController) controller;
|
||||
final int maxSteps = sliderController.getMaxSteps();
|
||||
if (newPosition < 0 || newPosition > maxSteps) {
|
||||
|
Reference in New Issue
Block a user