Fix the SetConnectivityStatus callback
SetConnectivityStatus callback should only update the InternetTile when there is no default network because this callback doesn't contain the updated the information of the WiFi or Cellular. When there is no default network, InternetTile should show the globe icon so SetConnectivityStatus should trigger the tile refresh. When there is default network, InternetTile should be updated by the corresponding callback (setMobileDataIndicators or setWifiIndicators), while SetConnectivityStatus is supposed to only update the mNoDefaultNetwork field. This CL also added some QSlogs specifically for the InternetTile. Bug: 241655191 Test: Unit test, manual test Change-Id: I6560e016ee1663779b3c59d45520ef98507cad77
This commit is contained in:
@@ -129,6 +129,15 @@ class QSLogger @Inject constructor(
|
||||
})
|
||||
}
|
||||
|
||||
fun logInternetTileUpdate(lastType: Int, callback: String) {
|
||||
log(VERBOSE, {
|
||||
int1 = lastType
|
||||
str1 = callback
|
||||
}, {
|
||||
"mLastTileState=$int1, Callback=$str1."
|
||||
})
|
||||
}
|
||||
|
||||
fun logTileUpdated(tileSpec: String, state: QSTile.State) {
|
||||
log(VERBOSE, {
|
||||
str1 = tileSpec
|
||||
|
||||
@@ -369,11 +369,10 @@ public class InternetTile extends QSTileImpl<SignalState> {
|
||||
mWifiInfo.mNoDefaultNetwork = noDefaultNetwork;
|
||||
mWifiInfo.mNoValidatedNetwork = noValidatedNetwork;
|
||||
mWifiInfo.mNoNetworksAvailable = noNetworksAvailable;
|
||||
if (mLastTileState == LAST_STATE_WIFI) {
|
||||
refreshState(mWifiInfo);
|
||||
} else {
|
||||
refreshState(mCellularInfo);
|
||||
if (!noDefaultNetwork) {
|
||||
return;
|
||||
}
|
||||
refreshState(mWifiInfo);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -388,6 +387,7 @@ public class InternetTile extends QSTileImpl<SignalState> {
|
||||
|
||||
@Override
|
||||
protected void handleUpdateState(SignalState state, Object arg) {
|
||||
mQSLogger.logInternetTileUpdate(mLastTileState, arg == null ? "null" : arg.toString());
|
||||
if (arg instanceof CellularCallbackInfo) {
|
||||
mLastTileState = LAST_STATE_CELLULAR;
|
||||
handleUpdateCellularState(state, arg);
|
||||
@@ -605,4 +605,9 @@ public class InternetTile extends QSTileImpl<SignalState> {
|
||||
pw.print(" "); pw.println("mLastTileState=" + mLastTileState);
|
||||
pw.print(" "); pw.println("mSignalCallback=" + mSignalCallback.toString());
|
||||
}
|
||||
|
||||
// For testing usage only.
|
||||
protected int getLastTileState() {
|
||||
return mLastTileState;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,116 @@
|
||||
/*
|
||||
* Copyright (C) 2022 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.systemui.qs.tiles;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
|
||||
import android.os.Handler;
|
||||
import android.testing.AndroidTestingRunner;
|
||||
import android.testing.TestableLooper;
|
||||
|
||||
import androidx.test.filters.SmallTest;
|
||||
|
||||
import com.android.internal.logging.MetricsLogger;
|
||||
import com.android.systemui.R;
|
||||
import com.android.systemui.SysuiTestCase;
|
||||
import com.android.systemui.classifier.FalsingManagerFake;
|
||||
import com.android.systemui.plugins.ActivityStarter;
|
||||
import com.android.systemui.plugins.statusbar.StatusBarStateController;
|
||||
import com.android.systemui.qs.QSTileHost;
|
||||
import com.android.systemui.qs.logging.QSLogger;
|
||||
import com.android.systemui.qs.tiles.dialog.InternetDialogFactory;
|
||||
import com.android.systemui.statusbar.connectivity.AccessPointController;
|
||||
import com.android.systemui.statusbar.connectivity.NetworkController;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
@RunWith(AndroidTestingRunner.class)
|
||||
@TestableLooper.RunWithLooper(setAsMainLooper = true)
|
||||
@SmallTest
|
||||
public class InternetTileTest extends SysuiTestCase {
|
||||
|
||||
@Mock
|
||||
private QSTileHost mHost;
|
||||
@Mock
|
||||
private NetworkController mNetworkController;
|
||||
@Mock
|
||||
private AccessPointController mAccessPointController;
|
||||
@Mock
|
||||
private InternetDialogFactory mInternetDialogFactory;
|
||||
|
||||
private TestableLooper mTestableLooper;
|
||||
private InternetTile mTile;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mTestableLooper = TestableLooper.get(this);
|
||||
when(mHost.getContext()).thenReturn(mContext);
|
||||
when(mHost.getUserContext()).thenReturn(mContext);
|
||||
|
||||
mTile = new InternetTile(
|
||||
mHost,
|
||||
mTestableLooper.getLooper(),
|
||||
new Handler(mTestableLooper.getLooper()),
|
||||
new FalsingManagerFake(),
|
||||
mock(MetricsLogger.class),
|
||||
mock(StatusBarStateController.class),
|
||||
mock(ActivityStarter.class),
|
||||
mock(QSLogger.class),
|
||||
mNetworkController,
|
||||
mAccessPointController,
|
||||
mInternetDialogFactory
|
||||
);
|
||||
|
||||
mTile.initialize();
|
||||
mTestableLooper.processAllMessages();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setConnectivityStatus_defaultNetworkNotExists_updateTile() {
|
||||
mTile.mSignalCallback.setConnectivityStatus(
|
||||
/* noDefaultNetwork= */ true,
|
||||
/* noValidatedNetwork= */ true,
|
||||
/* noNetworksAvailable= */ true);
|
||||
mTestableLooper.processAllMessages();
|
||||
assertThat(String.valueOf(mTile.getState().secondaryLabel))
|
||||
.isEqualTo(mContext.getString(R.string.quick_settings_networks_unavailable));
|
||||
assertThat(mTile.getLastTileState()).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setConnectivityStatus_defaultNetworkExists_notUpdateTile() {
|
||||
mTile.mSignalCallback.setConnectivityStatus(
|
||||
/* noDefaultNetwork= */ false,
|
||||
/* noValidatedNetwork= */ true,
|
||||
/* noNetworksAvailable= */ true);
|
||||
mTestableLooper.processAllMessages();
|
||||
assertThat(String.valueOf(mTile.getState().secondaryLabel))
|
||||
.isNotEqualTo(mContext.getString(R.string.quick_settings_networks_unavailable));
|
||||
assertThat(String.valueOf(mTile.getState().secondaryLabel))
|
||||
.isNotEqualTo(mContext.getString(R.string.quick_settings_networks_available));
|
||||
assertThat(mTile.getLastTileState()).isEqualTo(-1);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user