From 893ff7a6f9adb068f40c4d29348bbc4a6066ecec Mon Sep 17 00:00:00 2001 From: Ying Xu Date: Fri, 21 Apr 2023 10:37:19 -0700 Subject: [PATCH] Add synchronization for refreshing InternetTile with cached states Bug: 278816604 Test: atest -c com.android.systemui.qs.tiles.InternetTileTest Change-Id: I724426d5abbba603747e62b5629f0c323217ff99 --- .../systemui/qs/tiles/InternetTile.java | 32 +++++++++++++++---- 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/qs/tiles/InternetTile.java b/packages/SystemUI/src/com/android/systemui/qs/tiles/InternetTile.java index f16f0dcc5dbae..ffe5489d656f7 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/tiles/InternetTile.java +++ b/packages/SystemUI/src/com/android/systemui/qs/tiles/InternetTile.java @@ -458,13 +458,28 @@ public class InternetTile extends QSTileImpl { getTileSpec(), mLastTileState, arg == null ? "null" : arg.toString()); if (arg instanceof CellularCallbackInfo) { mLastTileState = LAST_STATE_CELLULAR; - handleUpdateCellularState(state, arg); + CellularCallbackInfo cb = (CellularCallbackInfo) arg; + CellularCallbackInfo cellularInfo = new CellularCallbackInfo(); + synchronized (cb) { + cb.copyTo(cellularInfo); + } + handleUpdateCellularState(state, cellularInfo); } else if (arg instanceof WifiCallbackInfo) { mLastTileState = LAST_STATE_WIFI; - handleUpdateWifiState(state, arg); + WifiCallbackInfo cb = (WifiCallbackInfo) arg; + WifiCallbackInfo wifiInfo = new WifiCallbackInfo(); + synchronized (cb) { + cb.copyTo(wifiInfo); + } + handleUpdateWifiState(state, wifiInfo); } else if (arg instanceof EthernetCallbackInfo) { mLastTileState = LAST_STATE_ETHERNET; - handleUpdateEthernetState(state, arg); + EthernetCallbackInfo cb = (EthernetCallbackInfo) arg; + EthernetCallbackInfo ethernetInfo = new EthernetCallbackInfo(); + synchronized (cb) { + cb.copyTo(ethernetInfo); + } + handleUpdateEthernetState(state, ethernetInfo); } else { // handleUpdateState will be triggered when user expands the QuickSetting panel with // arg = null, in this case the last updated CellularCallbackInfo or WifiCallbackInfo @@ -476,11 +491,11 @@ public class InternetTile extends QSTileImpl { } handleUpdateCellularState(state, cellularInfo); } else if (mLastTileState == LAST_STATE_WIFI) { - WifiCallbackInfo mifiInfo = new WifiCallbackInfo(); + WifiCallbackInfo wifiInfo = new WifiCallbackInfo(); synchronized (mSignalCallback.mWifiInfo) { - mSignalCallback.mWifiInfo.copyTo(mifiInfo); + mSignalCallback.mWifiInfo.copyTo(wifiInfo); } - handleUpdateWifiState(state, mifiInfo); + handleUpdateWifiState(state, wifiInfo); } else if (mLastTileState == LAST_STATE_ETHERNET) { EthernetCallbackInfo ethernetInfo = new EthernetCallbackInfo(); synchronized (mSignalCallback.mEthernetInfo) { @@ -667,11 +682,16 @@ public class InternetTile extends QSTileImpl { } @Override + @NonNull public Drawable getDrawable(Context context) { SignalDrawable d = new SignalDrawable(context); d.setLevel(getState()); return d; } + @Override + public String toString() { + return String.format("SignalIcon[mState=0x%08x]", mState); + } } /**