Merge "Remove dependency on connectivity sticky broadcasts" into rvc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
54ba50a500
@@ -133,6 +133,35 @@ public class WifiStatusTracker {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches initial state as if a WifiManager.NETWORK_STATE_CHANGED_ACTION have been received.
|
||||
* This replaces the dependency on the initial sticky broadcast.
|
||||
*/
|
||||
public void fetchInitialState() {
|
||||
if (mWifiManager == null) {
|
||||
return;
|
||||
}
|
||||
updateWifiState();
|
||||
final NetworkInfo networkInfo =
|
||||
mConnectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
|
||||
connected = networkInfo != null && networkInfo.isConnected();
|
||||
mWifiInfo = null;
|
||||
ssid = null;
|
||||
if (connected) {
|
||||
mWifiInfo = mWifiManager.getConnectionInfo();
|
||||
if (mWifiInfo != null) {
|
||||
if (mWifiInfo.isPasspointAp() || mWifiInfo.isOsuAp()) {
|
||||
ssid = mWifiInfo.getPasspointProviderFriendlyName();
|
||||
} else {
|
||||
ssid = getValidSsid(mWifiInfo);
|
||||
}
|
||||
updateRssi(mWifiInfo.getRssi());
|
||||
maybeRequestNetworkScore();
|
||||
}
|
||||
}
|
||||
updateStatusLabel();
|
||||
}
|
||||
|
||||
public void handleBroadcast(Intent intent) {
|
||||
if (mWifiManager == null) {
|
||||
return;
|
||||
|
||||
@@ -1301,6 +1301,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
|
||||
private FingerprintManager mFpm;
|
||||
private FaceManager mFaceManager;
|
||||
private boolean mFingerprintLockedOut;
|
||||
private TelephonyManager mTelephonyManager;
|
||||
|
||||
/**
|
||||
* When we receive a
|
||||
@@ -1728,10 +1729,22 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
|
||||
}
|
||||
updateAirplaneModeState();
|
||||
|
||||
TelephonyManager telephony =
|
||||
mTelephonyManager =
|
||||
(TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
|
||||
if (telephony != null) {
|
||||
telephony.listen(mPhoneStateListener, LISTEN_ACTIVE_DATA_SUBSCRIPTION_ID_CHANGE);
|
||||
if (mTelephonyManager != null) {
|
||||
mTelephonyManager.listen(mPhoneStateListener,
|
||||
LISTEN_ACTIVE_DATA_SUBSCRIPTION_ID_CHANGE);
|
||||
// Set initial sim states values.
|
||||
for (int slot = 0; slot < mTelephonyManager.getActiveModemCount(); slot++) {
|
||||
int state = mTelephonyManager.getSimState(slot);
|
||||
int[] subIds = mSubscriptionManager.getSubscriptionIds(slot);
|
||||
if (subIds != null) {
|
||||
for (int subId : subIds) {
|
||||
mHandler.obtainMessage(MSG_SIM_STATE_CHANGE, subId, slot, state)
|
||||
.sendToTarget();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -85,6 +85,8 @@ import com.android.systemui.statusbar.policy.PreviewInflater;
|
||||
import com.android.systemui.tuner.LockscreenFragment.LockButtonFactory;
|
||||
import com.android.systemui.tuner.TunerService;
|
||||
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
/**
|
||||
* Implementation for the bottom area of the Keyguard, including camera/phone affordance and status
|
||||
* text.
|
||||
@@ -553,7 +555,7 @@ public class KeyguardBottomAreaView extends FrameLayout implements View.OnClickL
|
||||
}
|
||||
};
|
||||
if (!mKeyguardStateController.canDismissLockScreen()) {
|
||||
AsyncTask.execute(runnable);
|
||||
Dependency.get(Executor.class).execute(runnable);
|
||||
} else {
|
||||
boolean dismissShade = !TextUtils.isEmpty(mRightButtonStr)
|
||||
&& Dependency.get(TunerService.class).getValue(LOCKSCREEN_RIGHT_UNLOCK, 1) != 0;
|
||||
|
||||
@@ -357,7 +357,18 @@ public class NetworkControllerImpl extends BroadcastReceiver
|
||||
mBroadcastDispatcher.registerReceiverWithHandler(this, filter, mReceiverHandler);
|
||||
mListening = true;
|
||||
|
||||
// Initial setup of connectivity. Handled as if we had received a sticky broadcast of
|
||||
// ConnectivityManager.CONNECTIVITY_ACTION or ConnectivityManager.INET_CONDITION_ACTION.
|
||||
mReceiverHandler.post(this::updateConnectivity);
|
||||
|
||||
// Initial setup of WifiSignalController. Handled as if we had received a sticky broadcast
|
||||
// of WifiManager.WIFI_STATE_CHANGED_ACTION or WifiManager.NETWORK_STATE_CHANGED_ACTION
|
||||
mReceiverHandler.post(mWifiSignalController::fetchInitialState);
|
||||
updateMobileControllers();
|
||||
|
||||
// Initial setup of emergency information. Handled as if we had received a sticky broadcast
|
||||
// of TelephonyManager.ACTION_DEFAULT_VOICE_SUBSCRIPTION_CHANGED.
|
||||
mReceiverHandler.post(this::recalculateEmergency);
|
||||
}
|
||||
|
||||
private void unregisterListeners() {
|
||||
|
||||
@@ -101,6 +101,20 @@ public class WifiSignalController extends
|
||||
wifiDesc, mCurrentState.isTransient, mCurrentState.statusLabel);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches wifi initial state replacing the initial sticky broadcast.
|
||||
*/
|
||||
public void fetchInitialState() {
|
||||
mWifiTracker.fetchInitialState();
|
||||
mCurrentState.enabled = mWifiTracker.enabled;
|
||||
mCurrentState.connected = mWifiTracker.connected;
|
||||
mCurrentState.ssid = mWifiTracker.ssid;
|
||||
mCurrentState.rssi = mWifiTracker.rssi;
|
||||
mCurrentState.level = mWifiTracker.level;
|
||||
mCurrentState.statusLabel = mWifiTracker.statusLabel;
|
||||
notifyListenersIfNecessary();
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract wifi state directly from broadcasts about changes in wifi state.
|
||||
*/
|
||||
|
||||
@@ -61,6 +61,7 @@ import android.os.UserManager;
|
||||
import android.telephony.ServiceState;
|
||||
import android.telephony.SubscriptionInfo;
|
||||
import android.telephony.SubscriptionManager;
|
||||
import android.telephony.TelephonyManager;
|
||||
import android.test.suitebuilder.annotation.SmallTest;
|
||||
import android.testing.AndroidTestingRunner;
|
||||
import android.testing.TestableContext;
|
||||
@@ -133,20 +134,23 @@ public class KeyguardUpdateMonitorTest extends SysuiTestCase {
|
||||
@Mock
|
||||
private BroadcastDispatcher mBroadcastDispatcher;
|
||||
@Mock
|
||||
private Executor mBackgroundExecutor;
|
||||
@Mock
|
||||
private RingerModeTracker mRingerModeTracker;
|
||||
@Mock
|
||||
private LiveData<Integer> mRingerModeLiveData;
|
||||
@Mock
|
||||
private TelephonyManager mTelephonyManager;
|
||||
// Direct executor
|
||||
private Executor mBackgroundExecutor = Runnable::run;
|
||||
private TestableLooper mTestableLooper;
|
||||
private TestableKeyguardUpdateMonitor mKeyguardUpdateMonitor;
|
||||
private TestableContext mSpiedContext;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
TestableContext context = spy(mContext);
|
||||
mSpiedContext = spy(mContext);
|
||||
when(mPackageManager.hasSystemFeature(anyString())).thenReturn(true);
|
||||
when(context.getPackageManager()).thenReturn(mPackageManager);
|
||||
when(mSpiedContext.getPackageManager()).thenReturn(mPackageManager);
|
||||
doAnswer(invocation -> {
|
||||
IBiometricEnabledOnKeyguardCallback callback = invocation.getArgument(0);
|
||||
callback.onChanged(BiometricSourceType.FACE, true /* enabled */,
|
||||
@@ -161,19 +165,20 @@ public class KeyguardUpdateMonitorTest extends SysuiTestCase {
|
||||
when(mStrongAuthTracker
|
||||
.isUnlockingWithBiometricAllowed(anyBoolean() /* isStrongBiometric */))
|
||||
.thenReturn(true);
|
||||
context.addMockSystemService(TrustManager.class, mTrustManager);
|
||||
context.addMockSystemService(FingerprintManager.class, mFingerprintManager);
|
||||
context.addMockSystemService(BiometricManager.class, mBiometricManager);
|
||||
context.addMockSystemService(FaceManager.class, mFaceManager);
|
||||
context.addMockSystemService(UserManager.class, mUserManager);
|
||||
context.addMockSystemService(DevicePolicyManager.class, mDevicePolicyManager);
|
||||
context.addMockSystemService(SubscriptionManager.class, mSubscriptionManager);
|
||||
mSpiedContext.addMockSystemService(TrustManager.class, mTrustManager);
|
||||
mSpiedContext.addMockSystemService(FingerprintManager.class, mFingerprintManager);
|
||||
mSpiedContext.addMockSystemService(BiometricManager.class, mBiometricManager);
|
||||
mSpiedContext.addMockSystemService(FaceManager.class, mFaceManager);
|
||||
mSpiedContext.addMockSystemService(UserManager.class, mUserManager);
|
||||
mSpiedContext.addMockSystemService(DevicePolicyManager.class, mDevicePolicyManager);
|
||||
mSpiedContext.addMockSystemService(SubscriptionManager.class, mSubscriptionManager);
|
||||
mSpiedContext.addMockSystemService(TelephonyManager.class, mTelephonyManager);
|
||||
|
||||
when(mRingerModeTracker.getRingerMode()).thenReturn(mRingerModeLiveData);
|
||||
|
||||
mTestableLooper = TestableLooper.get(this);
|
||||
allowTestableLooperAsMainThread();
|
||||
mKeyguardUpdateMonitor = new TestableKeyguardUpdateMonitor(context);
|
||||
mKeyguardUpdateMonitor = new TestableKeyguardUpdateMonitor(mSpiedContext);
|
||||
}
|
||||
|
||||
@After
|
||||
@@ -191,6 +196,22 @@ public class KeyguardUpdateMonitorTest extends SysuiTestCase {
|
||||
any(IntentFilter.class), any(Handler.class), eq(UserHandle.ALL));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSimStateInitialized() {
|
||||
final int subId = 3;
|
||||
final int state = TelephonyManager.SIM_STATE_ABSENT;
|
||||
|
||||
when(mTelephonyManager.getActiveModemCount()).thenReturn(1);
|
||||
when(mTelephonyManager.getSimState(anyInt())).thenReturn(state);
|
||||
when(mSubscriptionManager.getSubscriptionIds(anyInt())).thenReturn(new int[] { subId });
|
||||
|
||||
KeyguardUpdateMonitor testKUM = new TestableKeyguardUpdateMonitor(mSpiedContext);
|
||||
|
||||
mTestableLooper.processAllMessages();
|
||||
|
||||
assertThat(testKUM.getSimState(subId)).isEqualTo(state);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIgnoresSimStateCallback_rebroadcast() {
|
||||
Intent intent = new Intent(TelephonyIntents.ACTION_SIM_STATE_CHANGED);
|
||||
|
||||
@@ -85,6 +85,7 @@ import com.android.systemui.statusbar.phone.KeyguardBypassController;
|
||||
import com.android.systemui.statusbar.phone.LockscreenLockIconController;
|
||||
import com.android.systemui.statusbar.phone.NotificationGroupManager;
|
||||
import com.android.systemui.statusbar.phone.NotificationShadeWindowController;
|
||||
import com.android.systemui.statusbar.phone.NotificationShadeWindowView;
|
||||
import com.android.systemui.statusbar.phone.ShadeController;
|
||||
import com.android.systemui.statusbar.policy.BatteryController;
|
||||
import com.android.systemui.statusbar.policy.ConfigurationController;
|
||||
@@ -183,6 +184,8 @@ public class BubbleControllerTest extends SysuiTestCase {
|
||||
private DumpManager mDumpManager;
|
||||
@Mock
|
||||
private LockscreenLockIconController mLockIconController;
|
||||
@Mock
|
||||
private NotificationShadeWindowView mNotificationShadeWindowView;
|
||||
|
||||
private SuperStatusBarViewFactory mSuperStatusBarViewFactory;
|
||||
private BubbleData mBubbleData;
|
||||
@@ -219,8 +222,7 @@ public class BubbleControllerTest extends SysuiTestCase {
|
||||
mWindowManager, mActivityManager, mDozeParameters, mStatusBarStateController,
|
||||
mConfigurationController, mKeyguardBypassController, mColorExtractor,
|
||||
mDumpManager);
|
||||
mNotificationShadeWindowController.setNotificationShadeView(
|
||||
mSuperStatusBarViewFactory.getNotificationShadeWindowView());
|
||||
mNotificationShadeWindowController.setNotificationShadeView(mNotificationShadeWindowView);
|
||||
mNotificationShadeWindowController.attach();
|
||||
|
||||
// Need notifications for bubbles
|
||||
|
||||
@@ -79,6 +79,7 @@ import com.android.systemui.statusbar.phone.KeyguardBypassController;
|
||||
import com.android.systemui.statusbar.phone.LockscreenLockIconController;
|
||||
import com.android.systemui.statusbar.phone.NotificationGroupManager;
|
||||
import com.android.systemui.statusbar.phone.NotificationShadeWindowController;
|
||||
import com.android.systemui.statusbar.phone.NotificationShadeWindowView;
|
||||
import com.android.systemui.statusbar.phone.ShadeController;
|
||||
import com.android.systemui.statusbar.policy.BatteryController;
|
||||
import com.android.systemui.statusbar.policy.ConfigurationController;
|
||||
@@ -134,6 +135,8 @@ public class NewNotifPipelineBubbleControllerTest extends SysuiTestCase {
|
||||
private KeyguardBypassController mKeyguardBypassController;
|
||||
@Mock
|
||||
private FloatingContentCoordinator mFloatingContentCoordinator;
|
||||
@Mock
|
||||
private NotificationShadeWindowView mNotificationShadeWindowView;
|
||||
|
||||
private SysUiState mSysUiState = new SysUiState();
|
||||
|
||||
@@ -206,8 +209,7 @@ public class NewNotifPipelineBubbleControllerTest extends SysuiTestCase {
|
||||
mWindowManager, mActivityManager, mDozeParameters, mStatusBarStateController,
|
||||
mConfigurationController, mKeyguardBypassController, mColorExtractor,
|
||||
mDumpManager);
|
||||
mNotificationShadeWindowController.setNotificationShadeView(
|
||||
mSuperStatusBarViewFactory.getNotificationShadeWindowView());
|
||||
mNotificationShadeWindowController.setNotificationShadeView(mNotificationShadeWindowView);
|
||||
mNotificationShadeWindowController.attach();
|
||||
|
||||
// Need notifications for bubbles
|
||||
|
||||
@@ -6,11 +6,18 @@ import android.view.LayoutInflater
|
||||
import androidx.test.filters.SmallTest
|
||||
import com.android.systemui.R
|
||||
import com.android.systemui.SysuiTestCase
|
||||
import com.android.systemui.assist.AssistManager
|
||||
import com.android.systemui.plugins.ActivityStarter
|
||||
import com.android.systemui.statusbar.policy.AccessibilityController
|
||||
import com.android.systemui.statusbar.policy.FlashlightController
|
||||
import com.android.systemui.statusbar.policy.KeyguardStateController
|
||||
import com.android.systemui.tuner.TunerService
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.mockito.Mock
|
||||
import org.mockito.MockitoAnnotations
|
||||
import java.util.concurrent.Executor
|
||||
|
||||
@SmallTest
|
||||
@RunWith(AndroidTestingRunner::class)
|
||||
@@ -24,6 +31,15 @@ class KeyguardBottomAreaTest : SysuiTestCase() {
|
||||
@Before
|
||||
fun setup() {
|
||||
MockitoAnnotations.initMocks(this)
|
||||
// Mocked dependencies
|
||||
mDependency.injectMockDependency(AccessibilityController::class.java)
|
||||
mDependency.injectMockDependency(ActivityStarter::class.java)
|
||||
mDependency.injectMockDependency(AssistManager::class.java)
|
||||
mDependency.injectTestDependency(Executor::class.java, Executor { it.run() })
|
||||
mDependency.injectMockDependency(FlashlightController::class.java)
|
||||
mDependency.injectMockDependency(KeyguardStateController::class.java)
|
||||
mDependency.injectMockDependency(TunerService::class.java)
|
||||
|
||||
mKeyguardBottomArea = LayoutInflater.from(mContext).inflate(
|
||||
R.layout.keyguard_bottom_area, null, false) as KeyguardBottomAreaView
|
||||
mKeyguardBottomArea.setStatusBar(mStatusBar)
|
||||
|
||||
@@ -32,6 +32,7 @@ import static org.mockito.Mockito.atLeastOnce;
|
||||
import static org.mockito.Mockito.doAnswer;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.app.Instrumentation;
|
||||
@@ -222,7 +223,7 @@ public class NetworkControllerBaseTest extends SysuiTestCase {
|
||||
|
||||
ArgumentCaptor<ConnectivityManager.NetworkCallback> callbackArg =
|
||||
ArgumentCaptor.forClass(ConnectivityManager.NetworkCallback.class);
|
||||
Mockito.verify(mMockCm, atLeastOnce())
|
||||
verify(mMockCm, atLeastOnce())
|
||||
.registerDefaultNetworkCallback(callbackArg.capture(), isA(Handler.class));
|
||||
mNetworkCallback = callbackArg.getValue();
|
||||
assertNotNull(mNetworkCallback);
|
||||
@@ -384,7 +385,7 @@ public class NetworkControllerBaseTest extends SysuiTestCase {
|
||||
}
|
||||
|
||||
protected void verifyHasNoSims(boolean hasNoSimsVisible) {
|
||||
Mockito.verify(mCallbackHandler, Mockito.atLeastOnce()).setNoSims(
|
||||
verify(mCallbackHandler, Mockito.atLeastOnce()).setNoSims(
|
||||
eq(hasNoSimsVisible), eq(false));
|
||||
}
|
||||
|
||||
@@ -395,7 +396,7 @@ public class NetworkControllerBaseTest extends SysuiTestCase {
|
||||
ArgumentCaptor<Boolean> dataInArg = ArgumentCaptor.forClass(Boolean.class);
|
||||
ArgumentCaptor<Boolean> dataOutArg = ArgumentCaptor.forClass(Boolean.class);
|
||||
|
||||
Mockito.verify(mCallbackHandler, Mockito.atLeastOnce()).setMobileDataIndicators(
|
||||
verify(mCallbackHandler, Mockito.atLeastOnce()).setMobileDataIndicators(
|
||||
any(),
|
||||
iconArg.capture(),
|
||||
anyInt(),
|
||||
@@ -429,7 +430,7 @@ public class NetworkControllerBaseTest extends SysuiTestCase {
|
||||
ArgumentCaptor<Integer> typeIconArg = ArgumentCaptor.forClass(Integer.class);
|
||||
|
||||
// TODO: Verify all fields.
|
||||
Mockito.verify(mCallbackHandler, Mockito.atLeastOnce()).setMobileDataIndicators(
|
||||
verify(mCallbackHandler, Mockito.atLeastOnce()).setMobileDataIndicators(
|
||||
iconArg.capture(),
|
||||
any(),
|
||||
typeIconArg.capture(),
|
||||
@@ -475,7 +476,7 @@ public class NetworkControllerBaseTest extends SysuiTestCase {
|
||||
ArgumentCaptor<CharSequence> typeContentDescriptionHtmlArg =
|
||||
ArgumentCaptor.forClass(CharSequence.class);
|
||||
|
||||
Mockito.verify(mCallbackHandler, Mockito.atLeastOnce()).setMobileDataIndicators(
|
||||
verify(mCallbackHandler, Mockito.atLeastOnce()).setMobileDataIndicators(
|
||||
iconArg.capture(),
|
||||
qsIconArg.capture(),
|
||||
typeIconArg.capture(),
|
||||
|
||||
@@ -2,12 +2,14 @@ package com.android.systemui.statusbar.policy;
|
||||
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.anyBoolean;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.NetworkCapabilities;
|
||||
import android.net.NetworkInfo;
|
||||
import android.net.wifi.WifiInfo;
|
||||
@@ -171,6 +173,32 @@ public class NetworkControllerWifiTest extends NetworkControllerBaseTest {
|
||||
verifyLastWifiIcon(true, WifiIcons.WIFI_SIGNAL_STRENGTH[1][testLevel]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFetchInitialData() {
|
||||
mNetworkController.mWifiSignalController.fetchInitialState();
|
||||
Mockito.verify(mMockWm).getWifiState();
|
||||
Mockito.verify(mMockCm).getNetworkInfo(ConnectivityManager.TYPE_WIFI);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFetchInitialData_correctValues() {
|
||||
String testSsid = "TEST";
|
||||
|
||||
when(mMockWm.getWifiState()).thenReturn(WifiManager.WIFI_STATE_ENABLED);
|
||||
NetworkInfo networkInfo = mock(NetworkInfo.class);
|
||||
when(networkInfo.isConnected()).thenReturn(true);
|
||||
when(mMockCm.getNetworkInfo(ConnectivityManager.TYPE_WIFI)).thenReturn(networkInfo);
|
||||
WifiInfo wifiInfo = mock(WifiInfo.class);
|
||||
when(wifiInfo.getSSID()).thenReturn(testSsid);
|
||||
when(mMockWm.getConnectionInfo()).thenReturn(wifiInfo);
|
||||
|
||||
mNetworkController.mWifiSignalController.fetchInitialState();
|
||||
|
||||
assertTrue(mNetworkController.mWifiSignalController.mCurrentState.enabled);
|
||||
assertTrue(mNetworkController.mWifiSignalController.mCurrentState.connected);
|
||||
assertEquals(testSsid, mNetworkController.mWifiSignalController.mCurrentState.ssid);
|
||||
}
|
||||
|
||||
protected void setWifiActivity(int activity) {
|
||||
// TODO: Not this, because this variable probably isn't sticking around.
|
||||
mNetworkController.mWifiSignalController.setActivity(activity);
|
||||
|
||||
Reference in New Issue
Block a user