Merge "Listen for REQUEST_LISTENING on all users." into rvc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
0005f681b9
@@ -69,10 +69,14 @@ public class TileServices extends IQSService.Stub {
|
||||
mHost = host;
|
||||
mContext = mHost.getContext();
|
||||
mBroadcastDispatcher = broadcastDispatcher;
|
||||
mBroadcastDispatcher.registerReceiver(mRequestListeningReceiver,
|
||||
new IntentFilter(TileService.ACTION_REQUEST_LISTENING));
|
||||
mHandler = new Handler(looper);
|
||||
mMainHandler = new Handler(Looper.getMainLooper());
|
||||
mBroadcastDispatcher.registerReceiver(
|
||||
mRequestListeningReceiver,
|
||||
new IntentFilter(TileService.ACTION_REQUEST_LISTENING),
|
||||
null, // Use the default Executor
|
||||
UserHandle.ALL
|
||||
);
|
||||
}
|
||||
|
||||
public Context getContext() {
|
||||
|
||||
@@ -18,13 +18,22 @@ package com.android.systemui.qs.external;
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
import static junit.framework.Assert.assertTrue;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyLong;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.ComponentName;
|
||||
import android.content.IntentFilter;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.os.UserHandle;
|
||||
import android.service.quicksettings.Tile;
|
||||
import android.service.quicksettings.TileService;
|
||||
import android.test.suitebuilder.annotation.SmallTest;
|
||||
import android.testing.AndroidTestingRunner;
|
||||
import android.testing.TestableLooper;
|
||||
@@ -50,7 +59,6 @@ import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Mockito;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -99,7 +107,7 @@ public class TileServicesTest extends SysuiTestCase {
|
||||
mTunerService,
|
||||
() -> mAutoTileManager,
|
||||
mDumpManager,
|
||||
mBroadcastDispatcher,
|
||||
mock(BroadcastDispatcher.class),
|
||||
Optional.of(mStatusBar),
|
||||
mQSLogger,
|
||||
mUiEventLogger);
|
||||
@@ -112,6 +120,14 @@ public class TileServicesTest extends SysuiTestCase {
|
||||
TestableLooper.get(this).processAllMessages();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testActiveTileListenerRegisteredOnAllUsers() {
|
||||
ArgumentCaptor<IntentFilter> captor = ArgumentCaptor.forClass(IntentFilter.class);
|
||||
verify(mBroadcastDispatcher).registerReceiver(any(), captor.capture(), any(), eq(
|
||||
UserHandle.ALL));
|
||||
assertTrue(captor.getValue().hasAction(TileService.ACTION_REQUEST_LISTENING));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRecalculateBindAllowance() {
|
||||
// Add some fake tiles.
|
||||
@@ -125,10 +141,9 @@ public class TileServicesTest extends SysuiTestCase {
|
||||
}
|
||||
mTileService.recalculateBindAllowance();
|
||||
for (int i = 0; i < NUM_FAKES; i++) {
|
||||
Mockito.verify(mManagers.get(i), Mockito.times(1)).calculateBindPriority(
|
||||
Mockito.anyLong());
|
||||
verify(mManagers.get(i), times(1)).calculateBindPriority(anyLong());
|
||||
ArgumentCaptor<Boolean> captor = ArgumentCaptor.forClass(Boolean.class);
|
||||
Mockito.verify(mManagers.get(i), Mockito.times(1)).setBindAllowed(captor.capture());
|
||||
verify(mManagers.get(i), times(1)).setBindAllowed(captor.capture());
|
||||
|
||||
assertEquals("" + i + "th service", i >= (NUM_FAKES - TileServices.DEFAULT_MAX_BOUND),
|
||||
(boolean) captor.getValue());
|
||||
@@ -142,7 +157,7 @@ public class TileServicesTest extends SysuiTestCase {
|
||||
|
||||
for (int i = 0; i < NUM_FAKES; i++) {
|
||||
ArgumentCaptor<Boolean> captor = ArgumentCaptor.forClass(Boolean.class);
|
||||
Mockito.verify(mManagers.get(i), Mockito.times(2)).setBindAllowed(captor.capture());
|
||||
verify(mManagers.get(i), times(2)).setBindAllowed(captor.capture());
|
||||
|
||||
assertEquals("" + i + "th service", i >= (NUM_FAKES - TileServices.REDUCED_MAX_BOUND),
|
||||
(boolean) captor.getValue());
|
||||
@@ -158,12 +173,12 @@ public class TileServicesTest extends SysuiTestCase {
|
||||
|
||||
for (int i = 0; i < TileServices.DEFAULT_MAX_BOUND - 1; i++) {
|
||||
// Shouldn't get bind prioirities calculated when there are less than the max services.
|
||||
Mockito.verify(mManagers.get(i), Mockito.never()).calculateBindPriority(
|
||||
Mockito.anyLong());
|
||||
verify(mManagers.get(i), never()).calculateBindPriority(
|
||||
anyLong());
|
||||
|
||||
// All should be bound since there are less than the max services.
|
||||
ArgumentCaptor<Boolean> captor = ArgumentCaptor.forClass(Boolean.class);
|
||||
Mockito.verify(mManagers.get(i), Mockito.times(1)).setBindAllowed(captor.capture());
|
||||
verify(mManagers.get(i), times(1)).setBindAllowed(captor.capture());
|
||||
|
||||
assertTrue(captor.getValue());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user