Tie ContextualWifiSlice to UI instead of garbage collector
- Introduce a static long in SliceFeatureProvider that updates once every "session". A session is when user is in an UI (screen rotation, going to subpage, etc does not break the continuation of session). - Use session token in ContextualWifiSlice to determine when to refresh, instead of relying on WeakHashMap from CustomSliceManager. WeakHashMap can be cleaned up at any time by gc so it doesn't match what we want on the UI. - Also as a side fix, merged CustomSliceManager into SliceFeatureProvider. Fixes: 123937830 Test: robo Change-Id: I199bceceb208b99a32f3f08e624787b5a03e73a9
This commit is contained in:
@@ -25,6 +25,7 @@ import android.util.Log;
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.slice.Slice;
|
||||
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settings.slices.CustomSliceRegistry;
|
||||
import com.android.settings.slices.CustomSliceable;
|
||||
|
||||
@@ -35,7 +36,9 @@ public class ContextualWifiSlice extends WifiSlice {
|
||||
|
||||
private static final String TAG = "ContextualWifiSlice";
|
||||
@VisibleForTesting
|
||||
boolean mPreviouslyDisplayed;
|
||||
static long sActiveUiSession = -1000;
|
||||
@VisibleForTesting
|
||||
static boolean sPreviouslyDisplayed;
|
||||
|
||||
public ContextualWifiSlice(Context context) {
|
||||
super(context);
|
||||
@@ -48,13 +51,19 @@ public class ContextualWifiSlice extends WifiSlice {
|
||||
|
||||
@Override
|
||||
public Slice getSlice() {
|
||||
if (!mPreviouslyDisplayed && !TextUtils.equals(getActiveSSID(), WifiSsid.NONE)) {
|
||||
final long currentUiSession = FeatureFactory.getFactory(mContext)
|
||||
.getSlicesFeatureProvider().getUiSessionToken();
|
||||
if (currentUiSession != sActiveUiSession) {
|
||||
sActiveUiSession = currentUiSession;
|
||||
sPreviouslyDisplayed = false;
|
||||
}
|
||||
if (!sPreviouslyDisplayed && !TextUtils.equals(getActiveSSID(), WifiSsid.NONE)) {
|
||||
Log.d(TAG, "Wifi is connected, no point showing any suggestion.");
|
||||
return null;
|
||||
}
|
||||
// Set mPreviouslyDisplayed to true - we will show *something* on the screen. So we should
|
||||
// Set sPreviouslyDisplayed to true - we will show *something* on the screen. So we should
|
||||
// keep showing this card to keep UI stable, even if wifi connects to a network later.
|
||||
mPreviouslyDisplayed = true;
|
||||
sPreviouslyDisplayed = true;
|
||||
|
||||
return super.getSlice();
|
||||
}
|
||||
|
Reference in New Issue
Block a user