OSDN Git Service

Make summary text update after settings changes
authorMatthew Fritze <mfritze@google.com>
Wed, 23 May 2018 20:03:27 +0000 (13:03 -0700)
committerMatthew Fritze <mfritze@google.com>
Thu, 24 May 2018 20:08:23 +0000 (13:08 -0700)
The uri's being pinged when changes happened were incorrect, because
of a hard coded '/'.

Bug: 79779837
Test: robotest
Change-Id: I6735c5a60dc7df6894bd17e67d7702a7ec6c07d4

src/com/android/settings/slices/SliceBroadcastReceiver.java
tests/robotests/src/com/android/settings/slices/SliceBroadcastReceiverTest.java

index 213bf00..d81734a 100644 (file)
@@ -27,6 +27,7 @@ import static com.android.settings.wifi.WifiSliceBuilder.ACTION_WIFI_SLICE_CHANG
 
 import android.app.slice.Slice;
 import android.content.BroadcastReceiver;
+import android.content.ContentResolver;
 import android.content.Context;
 import android.content.Intent;
 import android.net.Uri;
@@ -155,6 +156,7 @@ public class SliceBroadcastReceiver extends BroadcastReceiver {
 
         sliderController.setSliderPosition(newPosition);
         logSliceValueChange(context, key, newPosition);
+        updateUri(context, key, isPlatformSlice);
     }
 
     /**
@@ -177,8 +179,15 @@ public class SliceBroadcastReceiver extends BroadcastReceiver {
     }
 
     private void updateUri(Context context, String key, boolean isPlatformDefined) {
-        final String path = SettingsSlicesContract.PATH_SETTING_ACTION + "/" + key;
-        final Uri uri = SliceBuilderUtils.getUri(path, isPlatformDefined);
+        final String authority = isPlatformDefined
+                ? SettingsSlicesContract.AUTHORITY
+                : SettingsSliceProvider.SLICE_AUTHORITY;
+        final Uri uri = new Uri.Builder()
+                .scheme(ContentResolver.SCHEME_CONTENT)
+                .authority(authority)
+                .appendPath(SettingsSlicesContract.PATH_SETTING_ACTION)
+                .appendPath(key)
+                .build();
         context.getContentResolver().notifyChange(uri, null /* observer */);
     }
 }
index 5f0bc96..6d18449 100644 (file)
@@ -96,8 +96,16 @@ public class SliceBroadcastReceiverTest {
     @Test
     public void onReceive_toggleChanged() {
         final String key = "key";
+        final Uri uri = new Uri.Builder()
+                .scheme(ContentResolver.SCHEME_CONTENT)
+                .authority(SettingsSliceProvider.SLICE_AUTHORITY)
+                .appendPath(SettingsSlicesContract.PATH_SETTING_ACTION)
+                .appendPath(key)
+                .build();
         mSearchFeatureProvider.getSearchIndexableResources().getProviderValues().clear();
         insertSpecialCase(key);
+        final ContentResolver resolver = mock(ContentResolver.class);
+        doReturn(resolver).when(mContext).getContentResolver();
         // Turn on toggle setting
         FakeToggleController fakeToggleController = new FakeToggleController(mContext, key);
         fakeToggleController.setChecked(true);
@@ -121,6 +129,7 @@ public class SliceBroadcastReceiverTest {
         assertThat(namePair.first).isEqualTo(MetricsEvent.FIELD_SETTINGS_PREFERENCE_CHANGE_NAME);
         assertThat(namePair.second).isEqualTo(fakeToggleController.getPreferenceKey());
 
+        verify(resolver).notifyChange(uri, null);
         assertThat(valuePair.first)
                 .isEqualTo(MetricsEvent.FIELD_SETTINGS_PREFERENCE_CHANGE_INT_VALUE);
         assertThat(valuePair.second).isEqualTo(0);
@@ -150,9 +159,13 @@ public class SliceBroadcastReceiverTest {
 
         assertThat(fakeToggleController.isChecked()).isFalse();
 
-        final Uri expectedUri = SliceBuilderUtils.getUri(
-                SettingsSlicesContract.PATH_SETTING_ACTION + "/" + key, false);
-        verify(resolver).notifyChange(eq(expectedUri), eq(null));
+        final Uri expectedUri = new Uri.Builder()
+                .scheme(ContentResolver.SCHEME_CONTENT)
+                .authority(SettingsSliceProvider.SLICE_AUTHORITY)
+                .appendPath(SettingsSlicesContract.PATH_SETTING_ACTION)
+                .appendPath(key)
+                .build();
+        verify(resolver).notifyChange(expectedUri, null);
     }
 
     @Test
@@ -183,6 +196,14 @@ public class SliceBroadcastReceiverTest {
     @Test
     public void onReceive_sliderChanged() {
         final String key = "key";
+        final Uri uri = new Uri.Builder()
+                .scheme(ContentResolver.SCHEME_CONTENT)
+                .authority(SettingsSliceProvider.SLICE_AUTHORITY)
+                .appendPath(SettingsSlicesContract.PATH_SETTING_ACTION)
+                .appendPath(key)
+                .build();
+        final ContentResolver resolver = mock(ContentResolver.class);
+        doReturn(resolver).when(mContext).getContentResolver();
         final int position = FakeSliderController.MAX_STEPS - 1;
         final int oldPosition = FakeSliderController.MAX_STEPS;
         mSearchFeatureProvider.getSearchIndexableResources().getProviderValues().clear();
@@ -213,6 +234,7 @@ public class SliceBroadcastReceiverTest {
         assertThat(namePair.first).isEqualTo(MetricsEvent.FIELD_SETTINGS_PREFERENCE_CHANGE_NAME);
         assertThat(namePair.second).isEqualTo(key);
 
+        verify(resolver).notifyChange(uri, null);
         assertThat(valuePair.first)
                 .isEqualTo(MetricsEvent.FIELD_SETTINGS_PREFERENCE_CHANGE_INT_VALUE);
         assertThat(valuePair.second).isEqualTo(position);
@@ -286,8 +308,12 @@ public class SliceBroadcastReceiverTest {
 
         // Check the value is the same and the Uri has been notified.
         assertThat(fakeToggleController.isChecked()).isTrue();
-        final Uri expectedUri = SliceBuilderUtils.getUri(
-                SettingsSlicesContract.PATH_SETTING_ACTION + "/" + key, false);
+        final Uri expectedUri = new Uri.Builder()
+                .scheme(ContentResolver.SCHEME_CONTENT)
+                .authority(SettingsSliceProvider.SLICE_AUTHORITY)
+                .appendPath(SettingsSlicesContract.PATH_SETTING_ACTION)
+                .appendPath(key)
+                .build();
         verify(resolver).notifyChange(eq(expectedUri), eq(null));
     }
 
@@ -323,8 +349,12 @@ public class SliceBroadcastReceiverTest {
 
         // Check position is the same and the Uri has been notified.
         assertThat(fakeSliderController.getSliderPosition()).isEqualTo(oldPosition);
-        final Uri expectedUri = SliceBuilderUtils.getUri(
-                SettingsSlicesContract.PATH_SETTING_ACTION + "/" + key, false);
+        final Uri expectedUri = new Uri.Builder()
+                .scheme(ContentResolver.SCHEME_CONTENT)
+                .authority(SettingsSliceProvider.SLICE_AUTHORITY)
+                .appendPath(SettingsSlicesContract.PATH_SETTING_ACTION)
+                .appendPath(key)
+                .build();
         verify(resolver).notifyChange(eq(expectedUri), eq(null));
     }