OSDN Git Service

Fix the consistency of connection status displayed on Wi-Fi card
authorJason Chiu <chiujason@google.com>
Wed, 23 Jan 2019 10:09:45 +0000 (18:09 +0800)
committerJason Chiu <chiujason@google.com>
Thu, 24 Jan 2019 06:56:04 +0000 (14:56 +0800)
- Refresh slice in WifiTracker.onConnectedChanged
- Only expose notifySliceChange to child in SliceBackgroundWorker

Fixes: 123270015
Test: make RunSettingsRoboTests -j ROBOTEST_FILTER=com.android.settings.wifi.slice
Change-Id: Id5540ebae2746e58e14924665c5e62bf437ebcf0

src/com/android/settings/homepage/contextualcards/slices/BluetoothUpdateWorker.java
src/com/android/settings/slices/SliceBackgroundWorker.java
src/com/android/settings/wifi/slice/WifiSlice.java
tests/robotests/src/com/android/settings/wifi/slice/WifiSliceTest.java

index ff26888..1602f56 100644 (file)
@@ -30,16 +30,11 @@ public class BluetoothUpdateWorker extends SliceBackgroundWorker implements Blue
 
     private static final String TAG = "BluetoothUpdateWorker";
 
-    private final Context mContext;
-    private final Uri mUri;
     private final LocalBluetoothManager mLocalBluetoothManager;
 
     public BluetoothUpdateWorker(Context context, Uri uri) {
         super(context, uri);
-
-        mContext = context;
-        mUri = uri;
-        mLocalBluetoothManager = Utils.getLocalBtManager(mContext);
+        mLocalBluetoothManager = Utils.getLocalBtManager(context);
     }
 
     @Override
@@ -89,8 +84,4 @@ public class BluetoothUpdateWorker extends SliceBackgroundWorker implements Blue
             int bluetoothProfile) {
         notifySliceChange();
     }
-
-    private void notifySliceChange() {
-        mContext.getContentResolver().notifyChange(mUri, null);
-    }
 }
\ No newline at end of file
index 284fd23..6df45ba 100644 (file)
@@ -59,10 +59,6 @@ public abstract class SliceBackgroundWorker<E> implements Closeable {
         mUri = uri;
     }
 
-    protected Uri getUri() {
-        return mUri;
-    }
-
     /**
      * Returns the singleton instance of the {@link SliceBackgroundWorker} for specified {@link Uri}
      * if exists
@@ -148,7 +144,14 @@ public abstract class SliceBackgroundWorker<E> implements Closeable {
 
         if (needNotify) {
             mCachedResults = results;
-            mContext.getContentResolver().notifyChange(mUri, null);
+            notifySliceChange();
         }
     }
-}
+
+    /**
+     * Notify that data was updated and attempt to sync changes to the Slice.
+     */
+    protected void notifySliceChange() {
+        mContext.getContentResolver().notifyChange(mUri, null);
+    }
+}
\ No newline at end of file
index 1c79c1d..88fa8b2 100644 (file)
@@ -292,11 +292,12 @@ public class WifiSlice implements CustomSliceable {
 
         @Override
         public void onWifiStateChanged(int state) {
-            mContext.getContentResolver().notifyChange(getUri(), null);
+            notifySliceChange();
         }
 
         @Override
         public void onConnectedChanged() {
+            notifySliceChange();
         }
 
         @Override
index ae352cc..dd99e55 100644 (file)
@@ -139,4 +139,11 @@ public class WifiSliceTest {
 
         verify(mResolver).notifyChange(WIFI_SLICE_URI, null);
     }
+
+    @Test
+    public void onConnectedChanged_shouldNotifyChange() {
+        mWifiScanWorker.onConnectedChanged();
+
+        verify(mResolver).notifyChange(WIFI_SLICE_URI, null);
+    }
 }