DefaultKeyedAppStatesReporter extends KeyedAppStatesReporter { @Override public void setStates(@NonNull Collection<KeyedAppState> states) { setStates(states, false); } DefaultKeyedAppStatesReporter(@NonNull Context context, @NonNull Executor executor);   DefaultKeyedAppStatesReporter(@NonNull Context context); @Override void setStates(@NonNull Collection<KeyedAppState> states); @Override void setStatesImmediate(@NonNull Collection<KeyedAppState> states);  }
@Test @SmallTest public void setNotImmediate() { setTestHandlerReceivesStates(); KeyedAppStatesReporter reporter = getReporter(mContext); reporter.setStates(singletonList(mState)); assertThat(mTestHandler.latestMessage().what).isEqualTo(WHAT_STATE); }
@Test @SmallTest public void set_doesNotGoToNormalApps() { addComponentAsRespondingToAppStatesIntent(mTestComponentName); setComponentBindingToHandler(mTestComponentName, mTestHandler); KeyedAppStatesReporter reporter = getReporter(mContext); reporter.setStates(singletonList(mState)); assertThat(mTestHandler.latestMessage()).isNull(); }
@Test @SmallTest public void set_goesToDeviceOwner() { addComponentAsRespondingToAppStatesIntent(mTestComponentName); setComponentBindingToHandler(mTestComponentName, mTestHandler); shadowOf(mDevicePolicyManager).setDeviceOwner(mTestComponentName); KeyedAppStatesReporter reporter = getReporter(mContext); reporter.setStates(singletonList(mState)); assertThat(mTestHandler.latestMessage()).isNotNull(); }
@Test @SmallTest public void set_goesToProfileOwner() { addComponentAsRespondingToAppStatesIntent(mTestComponentName); setComponentBindingToHandler(mTestComponentName, mTestHandler); shadowOf(mDevicePolicyManager).setProfileOwner(mTestComponentName); KeyedAppStatesReporter reporter = getReporter(mContext); reporter.setStates(singletonList(mState)); assertThat(mTestHandler.latestMessage()).isNotNull(); }
@Test @SmallTest public void set_goesToPhonesky() { ComponentName phoneskyComponentName = new ComponentName(PHONESKY_PACKAGE_NAME, ""); addComponentAsRespondingToAppStatesIntent(phoneskyComponentName); setComponentBindingToHandler(phoneskyComponentName, mTestHandler); KeyedAppStatesReporter reporter = getReporter(mContext); reporter.setStates(singletonList(mState)); assertThat(mTestHandler.latestMessage()).isNotNull(); }
@Test @SmallTest public void set_goesToMultiple() { addComponentAsRespondingToAppStatesIntent(mTestComponentName); setComponentBindingToHandler(mTestComponentName, mTestHandler); shadowOf(mDevicePolicyManager).setProfileOwner(mTestComponentName); ComponentName phoneskyComponentName = new ComponentName(PHONESKY_PACKAGE_NAME, ""); TestHandler phoneskyTestHandler = new TestHandler(); addComponentAsRespondingToAppStatesIntent(phoneskyComponentName); setComponentBindingToHandler(phoneskyComponentName, phoneskyTestHandler); KeyedAppStatesReporter reporter = getReporter(mContext); reporter.setStates(singletonList(mState)); assertThat(mTestHandler.latestMessage()).isNotNull(); assertThat(phoneskyTestHandler.latestMessage()).isNotNull(); }
@Test @SmallTest public void set_changeProfileOwner_goesToNewProfileOwner() { addComponentAsRespondingToAppStatesIntent(mTestComponentName); setComponentBindingToHandler(mTestComponentName, mTestHandler); shadowOf(mDevicePolicyManager).setProfileOwner(mTestComponentName); KeyedAppStatesReporter reporter = getReporter(mContext); reporter.setStates(singletonList(mState)); mTestHandler.reset(); ComponentName newComponentName = new ComponentName("second_test_package", ""); TestHandler newTestHandler = new TestHandler(); addComponentAsRespondingToAppStatesIntent(newComponentName); setComponentBindingToHandler(newComponentName, newTestHandler); shadowOf(mDevicePolicyManager).setProfileOwner(newComponentName); reporter.setStates(singletonList(mState)); assertThat(mTestHandler.latestMessage()).isNull(); assertThat(newTestHandler.latestMessage()).isNotNull(); }
@Test @SmallTest public void set_changeDeviceOwner_goesToNewDeviceOwner() { addComponentAsRespondingToAppStatesIntent(mTestComponentName); setComponentBindingToHandler(mTestComponentName, mTestHandler); shadowOf(mDevicePolicyManager).setDeviceOwner(mTestComponentName); KeyedAppStatesReporter reporter = getReporter(mContext); reporter.setStates(singletonList(mState)); mTestHandler.reset(); ComponentName newComponentName = new ComponentName("second_test_package", ""); TestHandler newTestHandler = new TestHandler(); addComponentAsRespondingToAppStatesIntent(newComponentName); setComponentBindingToHandler(newComponentName, newTestHandler); shadowOf(mDevicePolicyManager).setDeviceOwner(newComponentName); reporter.setStates(singletonList(mState)); assertThat(mTestHandler.latestMessage()).isNull(); assertThat(newTestHandler.latestMessage()).isNotNull(); }
@Test @SmallTest @Config(minSdk = 26) public void set_deadConnection_reconnectsAndSendsToNewApp() { addComponentAsRespondingToAppStatesIntent(mTestComponentName); setComponentBindingToHandler(mTestComponentName, mTestHandler); shadowOf(mDevicePolicyManager).setProfileOwner(mTestComponentName); KeyedAppStatesReporter reporter = getReporter(mContext); reporter.setStates(singletonList(mState)); mTestHandler.reset(); TestHandler newAppTestHandler = new TestHandler(); setComponentBindingToHandler(mTestComponentName, newAppTestHandler); simulateDeadServiceConnection(); reporter.setStates(singletonList(mState)); assertThat(mTestHandler.latestMessage()).isNull(); assertThat(newAppTestHandler.latestMessage()).isNotNull(); }
@Test @SmallTest @Config(maxSdk = 25) public void set_connectionHasDisconnected_sdkLessThan26_reconnectsAndSendsToNewApp() { addComponentAsRespondingToAppStatesIntent(mTestComponentName); setComponentBindingToHandler(mTestComponentName, mTestHandler); shadowOf(mDevicePolicyManager).setProfileOwner(mTestComponentName); KeyedAppStatesReporter reporter = getReporter(mContext); reporter.setStates(singletonList(mState)); mTestHandler.reset(); TestHandler newAppTestHandler = new TestHandler(); setComponentBindingToHandler(mTestComponentName, newAppTestHandler); simulateDisconnectingServiceConnection(); reporter.setStates(singletonList(mState)); assertThat(mTestHandler.latestMessage()).isNull(); assertThat(newAppTestHandler.latestMessage()).isNotNull(); }
@Test @SmallTest @Config(minSdk = 26) public void set_connectionHasDisconnected_doesNotSend() { addComponentAsRespondingToAppStatesIntent(mTestComponentName); setComponentBindingToHandler(mTestComponentName, mTestHandler); shadowOf(mDevicePolicyManager).setProfileOwner(mTestComponentName); KeyedAppStatesReporter reporter = getReporter(mContext); reporter.setStates(singletonList(mState)); mTestHandler.reset(); simulateDisconnectingServiceConnection(); reporter.setStates(singletonList(mState)); assertThat(mTestHandler.latestMessage()).isNull(); }
@Test @SmallTest @Config(minSdk = 26) public void set_sendsWhenReconnected() { addComponentAsRespondingToAppStatesIntent(mTestComponentName); setComponentBindingToHandler(mTestComponentName, mTestHandler); shadowOf(mDevicePolicyManager).setProfileOwner(mTestComponentName); KeyedAppStatesReporter reporter = getReporter(mContext); reporter.setStates(singletonList(mState)); mTestHandler.reset(); simulateDisconnectingServiceConnection(); reporter.setStates(singletonList(mState)); simulateReconnectingServiceConnection(); assertThat(mTestHandler.latestMessage()).isNotNull(); }
@Test @SmallTest public void set_connectionHasReconnected_doesSend() { addComponentAsRespondingToAppStatesIntent(mTestComponentName); setComponentBindingToHandler(mTestComponentName, mTestHandler); shadowOf(mDevicePolicyManager).setProfileOwner(mTestComponentName); KeyedAppStatesReporter reporter = getReporter(mContext); reporter.setStates(singletonList(mState)); mTestHandler.reset(); setComponentBindingToHandler(mTestComponentName, new TestHandler()); simulateDisconnectingServiceConnection(); simulateReconnectingServiceConnection(); reporter.setStates(singletonList(mState)); assertThat(mTestHandler.latestMessage()).isNotNull(); }
@Test @SmallTest public void setStates_constructedWithExecutor_usesExecutor() { TestExecutor testExecutor = new TestExecutor(); KeyedAppStatesReporter reporter = new DefaultKeyedAppStatesReporter(mContext, testExecutor); reporter.setStates(singleton(mState)); assertThat(testExecutor.lastExecuted()).isNotNull(); }
@Test @SmallTest public void setEmpty_doesNotSend() { setTestHandlerReceivesStates(); KeyedAppStatesReporter reporter = getReporter(mContext); reporter.setStates(Collections.<KeyedAppState>emptyList()); assertThat(mTestHandler.latestMessage()).isNull(); }