Wifi details: minor ordering fixes.
1. Set mNetwork before the NetworkCallbacks can be delivered. Previously, the code would set mNetwork in updateInfo, relying on the fact that the BroadcastReceiver registered in onResume is immediately invoked. However, this races with the callbacks, which are also immediately invoked. If the callbacks won the race, mNetwork would not be set and they would be ignored. 2. Call updateInfo in onResume instead of in displayPreference. This ensures that it's always called exactly once before the activity starts running, regardless of whether it's being displayed the first time (i.e., after onStart) or resumed by switching from another app. displayPreference is only called in the former case. 3. Don't call getLinkProperties and getNetworkCapabilities in updateInfo. These calls are superfluous, because this information is update by the NetworkCallbacks, and they can cause jank because updateInfo is called on the UI thread. This requires that the tests be changed so they always call onResume, since no UI elements are populated until onResume is called. Bug: 62209358 Test: make -j64 RunSettingsRoboTests Change-Id: Iccb1b9ae51188755d890a6df83004dbe9bec565e
This commit is contained in:
@@ -269,16 +269,19 @@ public class WifiDetailPreferenceController extends PreferenceController impleme
|
||||
mForgetButton = (Button) mButtonsPref.findViewById(R.id.forget_button);
|
||||
mForgetButton.setText(R.string.forget);
|
||||
mForgetButton.setOnClickListener(view -> forgetNetwork());
|
||||
updateInfo();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
// Ensure mNetwork is set before any callbacks above are delivered, since our
|
||||
// NetworkCallback only looks at changes to mNetwork.
|
||||
mNetwork = mWifiManager.getCurrentNetwork();
|
||||
mLinkProperties = mConnectivityManager.getLinkProperties(mNetwork);
|
||||
mNetworkCapabilities = mConnectivityManager.getNetworkCapabilities(mNetwork);
|
||||
updateInfo();
|
||||
mContext.registerReceiver(mReceiver, mFilter);
|
||||
mConnectivityManagerWrapper.registerNetworkCallback(mNetworkRequest, mNetworkCallback,
|
||||
mHandler);
|
||||
// updateInfo() will be called during registration because NETWORK_STATE_CHANGED_ACTION is
|
||||
// a sticky broadcast.
|
||||
mContext.registerReceiver(mReceiver, mFilter);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -293,9 +296,8 @@ public class WifiDetailPreferenceController extends PreferenceController impleme
|
||||
}
|
||||
|
||||
private void updateInfo() {
|
||||
mNetwork = mWifiManager.getCurrentNetwork();
|
||||
mLinkProperties = mConnectivityManager.getLinkProperties(mNetwork);
|
||||
mNetworkCapabilities = mConnectivityManager.getNetworkCapabilities(mNetwork);
|
||||
// No need to fetch LinkProperties and NetworkCapabilities, they are updated by the
|
||||
// callbacks. mNetwork doesn't change except in onResume.
|
||||
mNetworkInfo = mConnectivityManager.getNetworkInfo(mNetwork);
|
||||
mWifiInfo = mWifiManager.getConnectionInfo();
|
||||
if (mNetwork == null || mNetworkInfo == null || mWifiInfo == null) {
|
||||
|
Reference in New Issue
Block a user