[DO NOT MERGE] Add synchronization for refreshing InternetTile with cached states
Cherry picked from ag/21985770 Bug: 223737670 Test: atest -c com.android.systemui.qs.tiles.InternetTileTest Change-Id: I36037dec885b106e21ae6ca6b5a492066630f255 Merged-in: I36037dec885b106e21ae6ca6b5a492066630f255
This commit is contained in:
@@ -35,6 +35,7 @@ import android.widget.Switch;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.android.internal.annotations.GuardedBy;
|
||||
import com.android.internal.logging.MetricsLogger;
|
||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
import com.android.settingslib.graph.SignalDrawable;
|
||||
@@ -71,12 +72,16 @@ public class InternetTile extends QSTileImpl<SignalState> {
|
||||
public static final String TILE_SPEC = "internet";
|
||||
|
||||
private static final Intent WIFI_SETTINGS = new Intent(Settings.ACTION_WIFI_SETTINGS);
|
||||
private static final int LAST_STATE_UNKNOWN = -1;
|
||||
private static final int LAST_STATE_CELLULAR = 0;
|
||||
private static final int LAST_STATE_WIFI = 1;
|
||||
private static final int LAST_STATE_ETHERNET = 2;
|
||||
|
||||
protected final NetworkController mController;
|
||||
private final AccessPointController mAccessPointController;
|
||||
private final DataUsageController mDataController;
|
||||
// The last updated tile state, 0: mobile, 1: wifi, 2: ethernet.
|
||||
private int mLastTileState = -1;
|
||||
private int mLastTileState = LAST_STATE_UNKNOWN;
|
||||
|
||||
protected final InternetSignalCallback mSignalCallback = new InternetSignalCallback();
|
||||
private final InternetDialogFactory mInternetDialogFactory;
|
||||
@@ -170,6 +175,15 @@ public class InternetTile extends QSTileImpl<SignalState> {
|
||||
@Nullable
|
||||
String mEthernetContentDescription;
|
||||
|
||||
public void copyTo(EthernetCallbackInfo ethernetCallbackInfo) {
|
||||
if (ethernetCallbackInfo == null) {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
ethernetCallbackInfo.mConnected = this.mConnected;
|
||||
ethernetCallbackInfo.mEthernetSignalIconId = this.mEthernetSignalIconId;
|
||||
ethernetCallbackInfo.mEthernetContentDescription = this.mEthernetContentDescription;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new StringBuilder("EthernetCallbackInfo[")
|
||||
@@ -196,6 +210,23 @@ public class InternetTile extends QSTileImpl<SignalState> {
|
||||
boolean mNoValidatedNetwork;
|
||||
boolean mNoNetworksAvailable;
|
||||
|
||||
public void copyTo(WifiCallbackInfo wifiCallbackInfo) {
|
||||
if (wifiCallbackInfo == null) {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
wifiCallbackInfo.mAirplaneModeEnabled = this.mAirplaneModeEnabled;
|
||||
wifiCallbackInfo.mEnabled = this.mEnabled;
|
||||
wifiCallbackInfo.mConnected = this.mConnected;
|
||||
wifiCallbackInfo.mWifiSignalIconId = this.mWifiSignalIconId;
|
||||
wifiCallbackInfo.mSsid = this.mSsid;
|
||||
wifiCallbackInfo.mWifiSignalContentDescription = this.mWifiSignalContentDescription;
|
||||
wifiCallbackInfo.mIsTransient = this.mIsTransient;
|
||||
wifiCallbackInfo.mStatusLabel = this.mStatusLabel;
|
||||
wifiCallbackInfo.mNoDefaultNetwork = this.mNoDefaultNetwork;
|
||||
wifiCallbackInfo.mNoValidatedNetwork = this.mNoValidatedNetwork;
|
||||
wifiCallbackInfo.mNoNetworksAvailable = this.mNoNetworksAvailable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new StringBuilder("WifiCallbackInfo[")
|
||||
@@ -228,6 +259,23 @@ public class InternetTile extends QSTileImpl<SignalState> {
|
||||
boolean mNoValidatedNetwork;
|
||||
boolean mNoNetworksAvailable;
|
||||
|
||||
public void copyTo(CellularCallbackInfo cellularCallbackInfo) {
|
||||
if (cellularCallbackInfo == null) {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
cellularCallbackInfo.mAirplaneModeEnabled = this.mAirplaneModeEnabled;
|
||||
cellularCallbackInfo.mDataSubscriptionName = this.mDataSubscriptionName;
|
||||
cellularCallbackInfo.mDataContentDescription = this.mDataContentDescription;
|
||||
cellularCallbackInfo.mMobileSignalIconId = this.mMobileSignalIconId;
|
||||
cellularCallbackInfo.mQsTypeIcon = this.mQsTypeIcon;
|
||||
cellularCallbackInfo.mNoSim = this.mNoSim;
|
||||
cellularCallbackInfo.mRoaming = this.mRoaming;
|
||||
cellularCallbackInfo.mMultipleSubs = this.mMultipleSubs;
|
||||
cellularCallbackInfo.mNoDefaultNetwork = this.mNoDefaultNetwork;
|
||||
cellularCallbackInfo.mNoValidatedNetwork = this.mNoValidatedNetwork;
|
||||
cellularCallbackInfo.mNoNetworksAvailable = this.mNoNetworksAvailable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new StringBuilder("CellularCallbackInfo[")
|
||||
@@ -247,8 +295,11 @@ public class InternetTile extends QSTileImpl<SignalState> {
|
||||
}
|
||||
|
||||
protected final class InternetSignalCallback implements SignalCallback {
|
||||
@GuardedBy("mWifiInfo")
|
||||
final WifiCallbackInfo mWifiInfo = new WifiCallbackInfo();
|
||||
@GuardedBy("mCellularInfo")
|
||||
final CellularCallbackInfo mCellularInfo = new CellularCallbackInfo();
|
||||
@GuardedBy("mEthernetInfo")
|
||||
final EthernetCallbackInfo mEthernetInfo = new EthernetCallbackInfo();
|
||||
|
||||
|
||||
@@ -257,19 +308,23 @@ public class InternetTile extends QSTileImpl<SignalState> {
|
||||
if (DEBUG) {
|
||||
Log.d(TAG, "setWifiIndicators: " + indicators);
|
||||
}
|
||||
mWifiInfo.mEnabled = indicators.enabled;
|
||||
mWifiInfo.mSsid = indicators.description;
|
||||
mWifiInfo.mIsTransient = indicators.isTransient;
|
||||
mWifiInfo.mStatusLabel = indicators.statusLabel;
|
||||
synchronized (mWifiInfo) {
|
||||
mWifiInfo.mEnabled = indicators.enabled;
|
||||
mWifiInfo.mSsid = indicators.description;
|
||||
mWifiInfo.mIsTransient = indicators.isTransient;
|
||||
mWifiInfo.mStatusLabel = indicators.statusLabel;
|
||||
if (indicators.qsIcon != null) {
|
||||
mWifiInfo.mConnected = indicators.qsIcon.visible;
|
||||
mWifiInfo.mWifiSignalIconId = indicators.qsIcon.icon;
|
||||
mWifiInfo.mWifiSignalContentDescription = indicators.qsIcon.contentDescription;
|
||||
} else {
|
||||
mWifiInfo.mConnected = false;
|
||||
mWifiInfo.mWifiSignalIconId = 0;
|
||||
mWifiInfo.mWifiSignalContentDescription = null;
|
||||
}
|
||||
}
|
||||
if (indicators.qsIcon != null) {
|
||||
mWifiInfo.mConnected = indicators.qsIcon.visible;
|
||||
mWifiInfo.mWifiSignalIconId = indicators.qsIcon.icon;
|
||||
mWifiInfo.mWifiSignalContentDescription = indicators.qsIcon.contentDescription;
|
||||
refreshState(mWifiInfo);
|
||||
} else {
|
||||
mWifiInfo.mConnected = false;
|
||||
mWifiInfo.mWifiSignalIconId = 0;
|
||||
mWifiInfo.mWifiSignalContentDescription = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -282,14 +337,16 @@ public class InternetTile extends QSTileImpl<SignalState> {
|
||||
// Not data sim, don't display.
|
||||
return;
|
||||
}
|
||||
mCellularInfo.mDataSubscriptionName = indicators.qsDescription == null
|
||||
synchronized (mCellularInfo) {
|
||||
mCellularInfo.mDataSubscriptionName = indicators.qsDescription == null
|
||||
? mController.getMobileDataNetworkName() : indicators.qsDescription;
|
||||
mCellularInfo.mDataContentDescription = indicators.qsDescription != null
|
||||
mCellularInfo.mDataContentDescription = indicators.qsDescription != null
|
||||
? indicators.typeContentDescriptionHtml : null;
|
||||
mCellularInfo.mMobileSignalIconId = indicators.qsIcon.icon;
|
||||
mCellularInfo.mQsTypeIcon = indicators.qsType;
|
||||
mCellularInfo.mRoaming = indicators.roaming;
|
||||
mCellularInfo.mMultipleSubs = mController.getNumberSubscriptions() > 1;
|
||||
mCellularInfo.mMobileSignalIconId = indicators.qsIcon.icon;
|
||||
mCellularInfo.mQsTypeIcon = indicators.qsType;
|
||||
mCellularInfo.mRoaming = indicators.roaming;
|
||||
mCellularInfo.mMultipleSubs = mController.getNumberSubscriptions() > 1;
|
||||
}
|
||||
refreshState(mCellularInfo);
|
||||
}
|
||||
|
||||
@@ -299,9 +356,11 @@ public class InternetTile extends QSTileImpl<SignalState> {
|
||||
Log.d(TAG, "setEthernetIndicators: "
|
||||
+ "icon = " + (icon == null ? "" : icon.toString()));
|
||||
}
|
||||
mEthernetInfo.mConnected = icon.visible;
|
||||
mEthernetInfo.mEthernetSignalIconId = icon.icon;
|
||||
mEthernetInfo.mEthernetContentDescription = icon.contentDescription;
|
||||
synchronized (mEthernetInfo) {
|
||||
mEthernetInfo.mConnected = icon.visible;
|
||||
mEthernetInfo.mEthernetSignalIconId = icon.icon;
|
||||
mEthernetInfo.mEthernetContentDescription = icon.contentDescription;
|
||||
}
|
||||
if (icon.visible) {
|
||||
refreshState(mEthernetInfo);
|
||||
}
|
||||
@@ -314,11 +373,13 @@ public class InternetTile extends QSTileImpl<SignalState> {
|
||||
+ "show = " + show + ","
|
||||
+ "simDetected = " + simDetected);
|
||||
}
|
||||
mCellularInfo.mNoSim = show;
|
||||
if (mCellularInfo.mNoSim) {
|
||||
// Make sure signal gets cleared out when no sims.
|
||||
mCellularInfo.mMobileSignalIconId = 0;
|
||||
mCellularInfo.mQsTypeIcon = 0;
|
||||
synchronized (mCellularInfo) {
|
||||
mCellularInfo.mNoSim = show;
|
||||
if (mCellularInfo.mNoSim) {
|
||||
// Make sure signal gets cleared out when no sims.
|
||||
mCellularInfo.mMobileSignalIconId = 0;
|
||||
mCellularInfo.mQsTypeIcon = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -331,8 +392,12 @@ public class InternetTile extends QSTileImpl<SignalState> {
|
||||
if (mCellularInfo.mAirplaneModeEnabled == icon.visible) {
|
||||
return;
|
||||
}
|
||||
mCellularInfo.mAirplaneModeEnabled = icon.visible;
|
||||
mWifiInfo.mAirplaneModeEnabled = icon.visible;
|
||||
synchronized (mCellularInfo) {
|
||||
mCellularInfo.mAirplaneModeEnabled = icon.visible;
|
||||
}
|
||||
synchronized (mWifiInfo) {
|
||||
mWifiInfo.mAirplaneModeEnabled = icon.visible;
|
||||
}
|
||||
if (!mSignalCallback.mEthernetInfo.mConnected) {
|
||||
// Always use mWifiInfo to refresh the Internet Tile if airplane mode is enabled,
|
||||
// because Internet Tile will show different information depending on whether WiFi
|
||||
@@ -359,12 +424,16 @@ public class InternetTile extends QSTileImpl<SignalState> {
|
||||
+ "noValidatedNetwork = " + noValidatedNetwork + ","
|
||||
+ "noNetworksAvailable = " + noNetworksAvailable);
|
||||
}
|
||||
mCellularInfo.mNoDefaultNetwork = noDefaultNetwork;
|
||||
mCellularInfo.mNoValidatedNetwork = noValidatedNetwork;
|
||||
mCellularInfo.mNoNetworksAvailable = noNetworksAvailable;
|
||||
mWifiInfo.mNoDefaultNetwork = noDefaultNetwork;
|
||||
mWifiInfo.mNoValidatedNetwork = noValidatedNetwork;
|
||||
mWifiInfo.mNoNetworksAvailable = noNetworksAvailable;
|
||||
synchronized (mCellularInfo) {
|
||||
mCellularInfo.mNoDefaultNetwork = noDefaultNetwork;
|
||||
mCellularInfo.mNoValidatedNetwork = noValidatedNetwork;
|
||||
mCellularInfo.mNoNetworksAvailable = noNetworksAvailable;
|
||||
}
|
||||
synchronized (mWifiInfo) {
|
||||
mWifiInfo.mNoDefaultNetwork = noDefaultNetwork;
|
||||
mWifiInfo.mNoValidatedNetwork = noValidatedNetwork;
|
||||
mWifiInfo.mNoNetworksAvailable = noNetworksAvailable;
|
||||
}
|
||||
if (!noDefaultNetwork) {
|
||||
return;
|
||||
}
|
||||
@@ -386,24 +455,36 @@ public class InternetTile extends QSTileImpl<SignalState> {
|
||||
mQSLogger.logInternetTileUpdate(
|
||||
getTileSpec(), mLastTileState, arg == null ? "null" : arg.toString());
|
||||
if (arg instanceof CellularCallbackInfo) {
|
||||
mLastTileState = 0;
|
||||
mLastTileState = LAST_STATE_CELLULAR;
|
||||
handleUpdateCellularState(state, arg);
|
||||
} else if (arg instanceof WifiCallbackInfo) {
|
||||
mLastTileState = 1;
|
||||
mLastTileState = LAST_STATE_WIFI;
|
||||
handleUpdateWifiState(state, arg);
|
||||
} else if (arg instanceof EthernetCallbackInfo) {
|
||||
mLastTileState = 2;
|
||||
mLastTileState = LAST_STATE_ETHERNET;
|
||||
handleUpdateEthernetState(state, arg);
|
||||
} else {
|
||||
// handleUpdateState will be triggered when user expands the QuickSetting panel with
|
||||
// arg = null, in this case the last updated CellularCallbackInfo or WifiCallbackInfo
|
||||
// should be used to refresh the tile.
|
||||
if (mLastTileState == 0) {
|
||||
handleUpdateCellularState(state, mSignalCallback.mCellularInfo);
|
||||
} else if (mLastTileState == 1) {
|
||||
handleUpdateWifiState(state, mSignalCallback.mWifiInfo);
|
||||
} else if (mLastTileState == 2) {
|
||||
handleUpdateEthernetState(state, mSignalCallback.mEthernetInfo);
|
||||
if (mLastTileState == LAST_STATE_CELLULAR) {
|
||||
CellularCallbackInfo cellularInfo = new CellularCallbackInfo();
|
||||
synchronized (mSignalCallback.mCellularInfo) {
|
||||
mSignalCallback.mCellularInfo.copyTo(cellularInfo);
|
||||
}
|
||||
handleUpdateCellularState(state, cellularInfo);
|
||||
} else if (mLastTileState == LAST_STATE_WIFI) {
|
||||
WifiCallbackInfo mifiInfo = new WifiCallbackInfo();
|
||||
synchronized (mSignalCallback.mWifiInfo) {
|
||||
mSignalCallback.mWifiInfo.copyTo(mifiInfo);
|
||||
}
|
||||
handleUpdateCellularState(state, mifiInfo);
|
||||
} else if (mLastTileState == LAST_STATE_ETHERNET) {
|
||||
EthernetCallbackInfo ethernetInfo = new EthernetCallbackInfo();
|
||||
synchronized (mSignalCallback.mEthernetInfo) {
|
||||
mSignalCallback.mEthernetInfo.copyTo(ethernetInfo);
|
||||
}
|
||||
handleUpdateCellularState(state, ethernetInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user