Merge "QS Wallet priority placement" into sc-dev

This commit is contained in:
Matt Pietal
2021-04-13 19:07:08 +00:00
committed by Android (Google) Code Review
9 changed files with 186 additions and 5 deletions

View File

@@ -98,7 +98,10 @@ class QuickAccessWalletServiceInfo {
intent.setPackage(packageName);
List<ResolveInfo> resolveInfos =
context.getPackageManager().queryIntentServices(intent,
PackageManager.MATCH_DEFAULT_ONLY | PackageManager.GET_META_DATA);
PackageManager.MATCH_DIRECT_BOOT_AWARE
| PackageManager.MATCH_DIRECT_BOOT_UNAWARE
| PackageManager.MATCH_DEFAULT_ONLY
| PackageManager.GET_META_DATA);
return resolveInfos.isEmpty() ? null : resolveInfos.get(0).serviceInfo;
}

View File

@@ -34,6 +34,7 @@ import com.android.systemui.statusbar.policy.CastController;
import com.android.systemui.statusbar.policy.DataSaverController;
import com.android.systemui.statusbar.policy.DeviceControlsController;
import com.android.systemui.statusbar.policy.HotspotController;
import com.android.systemui.statusbar.policy.WalletController;
import com.android.systemui.util.settings.SecureSettings;
import javax.inject.Named;
@@ -63,6 +64,7 @@ public interface QSModule {
CastController castController,
ReduceBrightColorsController reduceBrightColorsController,
DeviceControlsController deviceControlsController,
WalletController walletController,
@Named(RBC_AVAILABLE) boolean isReduceBrightColorsAvailable) {
AutoTileManager manager = new AutoTileManager(
context,
@@ -77,6 +79,7 @@ public interface QSModule {
castController,
reduceBrightColorsController,
deviceControlsController,
walletController,
isReduceBrightColorsAvailable
);
manager.init();

View File

@@ -39,6 +39,7 @@ import com.android.systemui.statusbar.policy.DataSaverController.Listener;
import com.android.systemui.statusbar.policy.DeviceControlsController;
import com.android.systemui.statusbar.policy.HotspotController;
import com.android.systemui.statusbar.policy.HotspotController.Callback;
import com.android.systemui.statusbar.policy.WalletController;
import com.android.systemui.util.UserAwareController;
import com.android.systemui.util.settings.SecureSettings;
@@ -60,6 +61,7 @@ public class AutoTileManager implements UserAwareController {
public static final String NIGHT = "night";
public static final String CAST = "cast";
public static final String DEVICE_CONTROLS = "controls";
public static final String WALLET = "wallet";
public static final String BRIGHTNESS = "reduce_brightness";
static final String SETTING_SEPARATOR = ":";
@@ -77,6 +79,7 @@ public class AutoTileManager implements UserAwareController {
private final NightDisplayListener mNightDisplayListener;
private final CastController mCastController;
private final DeviceControlsController mDeviceControlsController;
private final WalletController mWalletController;
private final ReduceBrightColorsController mReduceBrightColorsController;
private final boolean mIsReduceBrightColorsAvailable;
private final ArrayList<AutoAddSetting> mAutoAddSettingList = new ArrayList<>();
@@ -92,6 +95,7 @@ public class AutoTileManager implements UserAwareController {
CastController castController,
ReduceBrightColorsController reduceBrightColorsController,
DeviceControlsController deviceControlsController,
WalletController walletController,
@Named(RBC_AVAILABLE) boolean isReduceBrightColorsAvailable) {
mContext = context;
mHost = host;
@@ -107,6 +111,7 @@ public class AutoTileManager implements UserAwareController {
mReduceBrightColorsController = reduceBrightColorsController;
mIsReduceBrightColorsAvailable = isReduceBrightColorsAvailable;
mDeviceControlsController = deviceControlsController;
mWalletController = walletController;
}
/**
@@ -146,6 +151,9 @@ public class AutoTileManager implements UserAwareController {
if (!mAutoTracker.isAdded(DEVICE_CONTROLS)) {
mDeviceControlsController.setCallback(mDeviceControlsCallback);
}
if (!mAutoTracker.isAdded(WALLET)) {
initWalletController();
}
int settingsN = mAutoAddSettingList.size();
for (int i = 0; i < settingsN; i++) {
@@ -294,6 +302,16 @@ public class AutoTileManager implements UserAwareController {
}
};
private void initWalletController() {
if (mAutoTracker.isAdded(WALLET)) return;
Integer position = mWalletController.getWalletPosition();
if (position != null) {
mHost.addTile(WALLET, position);
mAutoTracker.setTileAdded(WALLET);
}
}
@VisibleForTesting
final NightDisplayListener.Callback mNightDisplayCallback =
new NightDisplayListener.Callback() {

View File

@@ -61,7 +61,7 @@ public class DeviceControlsControllerImpl @Inject constructor(
companion object {
private const val TAG = "DeviceControlsControllerImpl"
internal const val QS_PRIORITY_POSITION = 3
internal const val QS_PRIORITY_POSITION = 2
internal const val QS_DEFAULT_POSITION = POSITION_AT_END
internal const val PREFS_CONTROLS_SEEDING_COMPLETED = "SeedingCompleted"

View File

@@ -0,0 +1,25 @@
/*
* Copyright (C) 2021 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.statusbar.policy
/**
* Supports adding a Quick Access Wallet QS tile
*/
interface WalletController {
/** @return valid position or null to indicate no tile should be set */
fun getWalletPosition(): Int?
}

View File

@@ -0,0 +1,51 @@
/*
* Copyright (C) 2021 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.statusbar.policy
import android.service.quickaccesswallet.QuickAccessWalletClient
import android.util.Log
import com.android.systemui.dagger.SysUISingleton
import javax.inject.Inject
/**
* Check if the wallet service is available for use, and place the tile.
*/
@SysUISingleton
public class WalletControllerImpl @Inject constructor(
private val quickAccessWalletClient: QuickAccessWalletClient
) : WalletController {
companion object {
private const val TAG = "WalletControllerImpl"
internal const val QS_PRIORITY_POSITION = 2
}
/**
* @return QS_PRIORITY_POSITION or null to indicate no tile should be set
*/
override fun getWalletPosition(): Int? {
return if (quickAccessWalletClient.isWalletServiceAvailable()) {
Log.i(TAG, "Setting WalletTile position: $QS_PRIORITY_POSITION")
QS_PRIORITY_POSITION
} else {
Log.i(TAG, "Setting WalletTile position: null")
null
}
}
}

View File

@@ -48,6 +48,8 @@ import com.android.systemui.statusbar.policy.SecurityController;
import com.android.systemui.statusbar.policy.SecurityControllerImpl;
import com.android.systemui.statusbar.policy.UserInfoController;
import com.android.systemui.statusbar.policy.UserInfoControllerImpl;
import com.android.systemui.statusbar.policy.WalletController;
import com.android.systemui.statusbar.policy.WalletControllerImpl;
import com.android.systemui.statusbar.policy.ZenModeController;
import com.android.systemui.statusbar.policy.ZenModeControllerImpl;
@@ -118,6 +120,10 @@ public interface StatusBarPolicyModule {
DeviceControlsController provideDeviceControlsController(
DeviceControlsControllerImpl controllerImpl);
/** */
@Binds
WalletController provideWalletController(WalletControllerImpl controllerImpl);
/** */
@Binds
NetworkController.AccessPointController provideAccessPointController(

View File

@@ -30,6 +30,7 @@ import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.inOrder;
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;
@@ -56,6 +57,7 @@ import com.android.systemui.statusbar.policy.CastController.CastDevice;
import com.android.systemui.statusbar.policy.DataSaverController;
import com.android.systemui.statusbar.policy.DeviceControlsController;
import com.android.systemui.statusbar.policy.HotspotController;
import com.android.systemui.statusbar.policy.WalletController;
import com.android.systemui.util.settings.FakeSettings;
import com.android.systemui.util.settings.SecureSettings;
@@ -95,7 +97,8 @@ public class AutoTileManagerTest extends SysuiTestCase {
@Mock private ManagedProfileController mManagedProfileController;
@Mock private NightDisplayListener mNightDisplayListener;
@Mock private ReduceBrightColorsController mReduceBrightColorsController;
@Mock private DeviceControlsController mDeviceControlsController;;
@Mock private DeviceControlsController mDeviceControlsController;
@Mock private WalletController mWalletController;
@Mock(answer = Answers.RETURNS_SELF)
private AutoAddTracker.Builder mAutoAddTrackerBuilder;
@Mock private Context mUserContext;
@@ -142,6 +145,7 @@ public class AutoTileManagerTest extends SysuiTestCase {
CastController castController,
ReduceBrightColorsController reduceBrightColorsController,
DeviceControlsController deviceControlsController,
WalletController walletController,
@Named(RBC_AVAILABLE) boolean isReduceBrightColorsAvailable) {
return new AutoTileManager(context, autoAddTrackerBuilder, mQsTileHost,
Handler.createAsync(TestableLooper.get(this).getLooper()),
@@ -153,6 +157,7 @@ public class AutoTileManagerTest extends SysuiTestCase {
castController,
reduceBrightColorsController,
deviceControlsController,
walletController,
isReduceBrightColorsAvailable);
}
@@ -160,7 +165,7 @@ public class AutoTileManagerTest extends SysuiTestCase {
return createAutoTileManager(context, mAutoAddTrackerBuilder, mHotspotController,
mDataSaverController, mManagedProfileController, mNightDisplayListener,
mCastController, mReduceBrightColorsController, mDeviceControlsController,
mIsReduceBrightColorsAvailable);
mWalletController, mIsReduceBrightColorsAvailable);
}
@Test
@@ -175,10 +180,11 @@ public class AutoTileManagerTest extends SysuiTestCase {
CastController cC = mock(CastController.class);
ReduceBrightColorsController rBC = mock(ReduceBrightColorsController.class);
DeviceControlsController dCC = mock(DeviceControlsController.class);
WalletController wC = mock(WalletController.class);
AutoTileManager manager =
createAutoTileManager(mock(Context.class), builder, hC, dSC, mPC, nDS, cC, rBC,
dCC, true);
dCC, wC, true);
verify(tracker, never()).initialize();
verify(hC, never()).addCallback(any());
@@ -188,6 +194,7 @@ public class AutoTileManagerTest extends SysuiTestCase {
verify(cC, never()).addCallback(any());
verify(rBC, never()).addCallback(any());
verify(dCC, never()).setCallback(any());
verify(wC, never()).getWalletPosition();
assertNull(manager.getSecureSettingForKey(TEST_SETTING));
assertNull(manager.getSecureSettingForKey(TEST_SETTING_COMPONENT));
}
@@ -240,6 +247,8 @@ public class AutoTileManagerTest extends SysuiTestCase {
inOrderDevices.verify(mDeviceControlsController).removeCallback();
inOrderDevices.verify(mDeviceControlsController).setCallback(any());
verify(mWalletController, times(2)).getWalletPosition();
SecureSetting setting = mAutoTileManager.getSecureSettingForKey(TEST_SETTING);
assertEquals(USER + 1, setting.getCurrentUser());
assertTrue(setting.isListening());
@@ -288,6 +297,8 @@ public class AutoTileManagerTest extends SysuiTestCase {
inOrderDevices.verify(mDeviceControlsController).removeCallback();
inOrderDevices.verify(mDeviceControlsController).setCallback(any());
verify(mWalletController, times(2)).getWalletPosition();
SecureSetting setting = mAutoTileManager.getSecureSettingForKey(TEST_SETTING);
assertEquals(USER + 1, setting.getCurrentUser());
assertFalse(setting.isListening());

View File

@@ -0,0 +1,64 @@
/*
* Copyright (C) 2021 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.statusbar.policy
import android.service.quickaccesswallet.QuickAccessWalletClient
import android.testing.AndroidTestingRunner
import androidx.test.filters.SmallTest
import com.android.systemui.SysuiTestCase
import com.android.systemui.statusbar.policy.DeviceControlsControllerImpl.Companion.QS_PRIORITY_POSITION
import com.google.common.truth.Truth.assertThat
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.Mock
import org.mockito.MockitoAnnotations
import org.mockito.Mockito.`when`
@SmallTest
@RunWith(AndroidTestingRunner::class)
class WalletControllerImplTest : SysuiTestCase() {
@Mock
private lateinit var quickAccessWalletClient: QuickAccessWalletClient
private lateinit var controller: WalletController
@Before
fun setUp() {
MockitoAnnotations.initMocks(this)
controller = WalletControllerImpl(quickAccessWalletClient)
}
@Test
fun testResultIsNullWhenNoServiceAvailable() {
`when`(quickAccessWalletClient.isWalletServiceAvailable()).thenReturn(false)
assertThat(controller.getWalletPosition()).isNull()
}
@Test
fun testResultIsIntWhenServiceAvailable() {
`when`(quickAccessWalletClient.isWalletServiceAvailable()).thenReturn(true)
assertThat(controller.getWalletPosition()).isEqualTo(QS_PRIORITY_POSITION)
}
}