summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTreeHugger Robot <treehugger-gerrit@google.com>2020-06-21 17:30:30 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2020-06-21 17:30:30 +0000
commit5f27d811a48d21279fb3956f1a55b3590441e89f (patch)
tree1a4a3e613368c490cd3287f1e254692db5f160cf
parent2eb1cb6e4066cdb80b489a3fdb8a34da7e38d523 (diff)
parentc7c214b128d27a8f719744adfe5d3f96fe41d88f (diff)
downloadQuickAccessWallet-android11-dev.tar.gz
Merge "Hide Cards and Passes setting when unavailable" into rvc-devandroid11-dev
-rw-r--r--src/com/android/systemui/plugin/globalactions/wallet/WalletPluginService.java24
-rw-r--r--tests/robolectric/src/com/android/systemui/plugin/globalactions/wallet/QuickAccessWalletClientTest.java10
-rw-r--r--tests/robolectric/src/com/android/systemui/plugin/globalactions/wallet/WalletPluginServiceTest.java69
3 files changed, 85 insertions, 18 deletions
diff --git a/src/com/android/systemui/plugin/globalactions/wallet/WalletPluginService.java b/src/com/android/systemui/plugin/globalactions/wallet/WalletPluginService.java
index 381cdb9..d0b9d44 100644
--- a/src/com/android/systemui/plugin/globalactions/wallet/WalletPluginService.java
+++ b/src/com/android/systemui/plugin/globalactions/wallet/WalletPluginService.java
@@ -16,6 +16,9 @@
package com.android.systemui.plugin.globalactions.wallet;
+import static android.provider.Settings.Secure.GLOBAL_ACTIONS_PANEL_AVAILABLE;
+import static android.provider.Settings.Secure.GLOBAL_ACTIONS_PANEL_ENABLED;
+
import android.content.ContentResolver;
import android.content.Context;
import android.provider.Settings;
@@ -44,11 +47,17 @@ public class WalletPluginService implements GlobalActionsPanelPlugin {
@Override
public void onCreate(Context sysuiContext, Context pluginContext) {
+ onCreate(sysuiContext, pluginContext, QuickAccessWalletClient.create(sysuiContext));
+ }
+
+ @VisibleForTesting
+ void onCreate(Context sysuiContext, Context pluginContext, QuickAccessWalletClient client) {
mSysuiContext = sysuiContext;
mPluginContext = pluginContext;
- enableFeatureInSettings(mSysuiContext);
+ updateSettingsFeatureAvailability(mSysuiContext, client.isWalletServiceAvailable());
}
+
/**
* Invoked when the GlobalActions menu is shown.
*
@@ -68,7 +77,9 @@ public class WalletPluginService implements GlobalActionsPanelPlugin {
GlobalActionsPanelPlugin.Callbacks callbacks,
boolean isDeviceLocked,
QuickAccessWalletClient client) {
- if (!client.isWalletServiceAvailable() || !client.isWalletFeatureAvailable()) {
+ boolean serviceAvailable = client.isWalletServiceAvailable();
+ updateSettingsFeatureAvailability(mSysuiContext, serviceAvailable);
+ if (!serviceAvailable || !client.isWalletFeatureAvailable()) {
return null;
}
WalletPanelViewController panelViewController = new WalletPanelViewController(
@@ -89,13 +100,14 @@ public class WalletPluginService implements GlobalActionsPanelPlugin {
* GLOBAL_ACTIONS_PANEL_ENABLED when the settings is not set effectively turns the feature on by
* default.
*/
- static void enableFeatureInSettings(Context context) {
+ @VisibleForTesting
+ static void updateSettingsFeatureAvailability(Context context, boolean available) {
ContentResolver cr = context.getContentResolver();
// Turning on the availability toggle lets users turn the feature on and off in Settings
- Settings.Secure.putInt(cr, Settings.Secure.GLOBAL_ACTIONS_PANEL_AVAILABLE, 1);
+ Settings.Secure.putInt(cr, GLOBAL_ACTIONS_PANEL_AVAILABLE, available ? 1 : 0);
// Enable the panel by default, but do not re-enable if the user has disabled it.
- if (Settings.Secure.getInt(cr, Settings.Secure.GLOBAL_ACTIONS_PANEL_ENABLED, -1) == -1) {
- Settings.Secure.putInt(cr, Settings.Secure.GLOBAL_ACTIONS_PANEL_ENABLED, 1);
+ if (Settings.Secure.getInt(cr, GLOBAL_ACTIONS_PANEL_ENABLED, -1) == -1) {
+ Settings.Secure.putInt(cr, GLOBAL_ACTIONS_PANEL_ENABLED, 1);
}
}
}
diff --git a/tests/robolectric/src/com/android/systemui/plugin/globalactions/wallet/QuickAccessWalletClientTest.java b/tests/robolectric/src/com/android/systemui/plugin/globalactions/wallet/QuickAccessWalletClientTest.java
index a9a7bda..e11c356 100644
--- a/tests/robolectric/src/com/android/systemui/plugin/globalactions/wallet/QuickAccessWalletClientTest.java
+++ b/tests/robolectric/src/com/android/systemui/plugin/globalactions/wallet/QuickAccessWalletClientTest.java
@@ -105,7 +105,7 @@ public class QuickAccessWalletClientTest {
public void isWalletFeatureAvailable_happyCase() {
setDefaultPaymentApp(mContext.getPackageName());
registerWalletService();
- WalletPluginService.enableFeatureInSettings(mContext);
+ WalletPluginService.updateSettingsFeatureAvailability(mContext, true);
ContentResolver cr = mContext.getContentResolver();
Settings.Secure.putInt(cr, Settings.Secure.USER_SETUP_COMPLETE, 1);
@@ -118,7 +118,7 @@ public class QuickAccessWalletClientTest {
public void isWalletFeatureAvailable_wrongUser() {
setDefaultPaymentApp(mContext.getPackageName());
registerWalletService();
- WalletPluginService.enableFeatureInSettings(mContext);
+ WalletPluginService.updateSettingsFeatureAvailability(mContext, true);
ContentResolver cr = mContext.getContentResolver();
Settings.Secure.putInt(cr, Settings.Secure.USER_SETUP_COMPLETE, 1);
ShadowActivityManager.setCurrentUser(11);
@@ -132,7 +132,7 @@ public class QuickAccessWalletClientTest {
public void isWalletFeatureAvailable_userSetupIncomplete() {
setDefaultPaymentApp(mContext.getPackageName());
registerWalletService();
- WalletPluginService.enableFeatureInSettings(mContext);
+ WalletPluginService.updateSettingsFeatureAvailability(mContext, true);
// do not set user setup complete
mWalletClient = QuickAccessWalletClient.create(mContext);
@@ -144,7 +144,7 @@ public class QuickAccessWalletClientTest {
public void isWalletFeatureAvailable_globalActionsPanelDisabled() {
setDefaultPaymentApp(mContext.getPackageName());
registerWalletService();
- WalletPluginService.enableFeatureInSettings(mContext);
+ WalletPluginService.updateSettingsFeatureAvailability(mContext, true);
ContentResolver cr = mContext.getContentResolver();
Settings.Secure.putInt(cr,
Settings.Secure.GLOBAL_ACTIONS_PANEL_ENABLED, 0);
@@ -159,7 +159,7 @@ public class QuickAccessWalletClientTest {
public void isWalletFeatureAvailable_userInLockdown() {
setDefaultPaymentApp(mContext.getPackageName());
registerWalletService();
- WalletPluginService.enableFeatureInSettings(mContext);
+ WalletPluginService.updateSettingsFeatureAvailability(mContext, true);
ContentResolver cr = mContext.getContentResolver();
Settings.Secure.putInt(cr, Settings.Secure.USER_SETUP_COMPLETE, 1);
ShadowLockPatternUtils.sIsUserInLockdown = true;
diff --git a/tests/robolectric/src/com/android/systemui/plugin/globalactions/wallet/WalletPluginServiceTest.java b/tests/robolectric/src/com/android/systemui/plugin/globalactions/wallet/WalletPluginServiceTest.java
index 8ad4ea0..aaf8a80 100644
--- a/tests/robolectric/src/com/android/systemui/plugin/globalactions/wallet/WalletPluginServiceTest.java
+++ b/tests/robolectric/src/com/android/systemui/plugin/globalactions/wallet/WalletPluginServiceTest.java
@@ -30,22 +30,22 @@ import org.robolectric.shadows.ShadowLog;
public class WalletPluginServiceTest {
private final Context mContext = ApplicationProvider.getApplicationContext();
- @Mock
- QuickAccessWalletClient mWalletClient;
- @Mock
- GlobalActionsPanelPlugin.Callbacks mPluginCallbacks;
+ @Mock QuickAccessWalletClient mWalletClient;
+ @Mock GlobalActionsPanelPlugin.Callbacks mPluginCallbacks;
private WalletPluginService mPluginService;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
+ when(mWalletClient.isWalletServiceAvailable()).thenReturn(true);
mPluginService = new WalletPluginService();
- mPluginService.onCreate(mContext, mContext);
ShadowLog.stream = System.out;
}
@Test
- public void onCreate_enablesFeatureInSettings() {
+ public void onCreate_serviceAvailable_enablesFeatureInSettings() {
+ mPluginService.onCreate(mContext, mContext, mWalletClient);
+
ContentResolver cr = mContext.getContentResolver();
assertThat(Settings.Secure.getInt(
cr, Settings.Secure.GLOBAL_ACTIONS_PANEL_AVAILABLE, -1)).isEqualTo(1);
@@ -54,20 +54,72 @@ public class WalletPluginServiceTest {
}
@Test
+ public void onCreate_serviceUnavailable_disablesFeatureInSettings() {
+ when(mWalletClient.isWalletServiceAvailable()).thenReturn(false);
+
+ mPluginService.onCreate(mContext, mContext, mWalletClient);
+
+ ContentResolver cr = mContext.getContentResolver();
+ assertThat(Settings.Secure.getInt(
+ cr, Settings.Secure.GLOBAL_ACTIONS_PANEL_AVAILABLE, -1)).isEqualTo(0);
+ assertThat(Settings.Secure.getInt(
+ cr, Settings.Secure.GLOBAL_ACTIONS_PANEL_ENABLED, -1)).isEqualTo(1);
+ }
+
+ @Test
public void onCreate_doesNotOverridePanelEnabledSettingIfOff() {
ContentResolver cr = mContext.getContentResolver();
Settings.Secure.putInt(cr, Settings.Secure.GLOBAL_ACTIONS_PANEL_ENABLED, 0);
- mPluginService.onCreate(mContext, mContext);
+ mPluginService.onCreate(mContext, mContext, mWalletClient);
assertThat(Settings.Secure.getInt(
cr, Settings.Secure.GLOBAL_ACTIONS_PANEL_ENABLED, -1)).isEqualTo(0);
}
@Test
+ public void onPanelShown_wasUnavailable_nowAvailable_updatesFeatureAvailabilityInSettings() {
+ when(mWalletClient.isWalletServiceAvailable()).thenReturn(false);
+ mPluginService.onCreate(mContext, mContext, mWalletClient);
+ ContentResolver cr = mContext.getContentResolver();
+ assertThat(Settings.Secure.getInt(
+ cr, Settings.Secure.GLOBAL_ACTIONS_PANEL_AVAILABLE, -1)).isEqualTo(0);
+ assertThat(Settings.Secure.getInt(
+ cr, Settings.Secure.GLOBAL_ACTIONS_PANEL_ENABLED, -1)).isEqualTo(1);
+ when(mWalletClient.isWalletServiceAvailable()).thenReturn(true);
+
+ mPluginService.onPanelShown(mPluginCallbacks, false, mWalletClient);
+
+ assertThat(Settings.Secure.getInt(
+ cr, Settings.Secure.GLOBAL_ACTIONS_PANEL_AVAILABLE, -1)).isEqualTo(1);
+ assertThat(Settings.Secure.getInt(
+ cr, Settings.Secure.GLOBAL_ACTIONS_PANEL_ENABLED, -1)).isEqualTo(1);
+ }
+
+ @Test
+ public void onPanelShown_wasAvailable_nowUnavailable_updatesFeatureAvailabilityInSettings() {
+ when(mWalletClient.isWalletServiceAvailable()).thenReturn(true);
+ mPluginService.onCreate(mContext, mContext, mWalletClient);
+ ContentResolver cr = mContext.getContentResolver();
+ assertThat(Settings.Secure.getInt(
+ cr, Settings.Secure.GLOBAL_ACTIONS_PANEL_AVAILABLE, -1)).isEqualTo(1);
+ assertThat(Settings.Secure.getInt(
+ cr, Settings.Secure.GLOBAL_ACTIONS_PANEL_ENABLED, -1)).isEqualTo(1);
+ when(mWalletClient.isWalletServiceAvailable()).thenReturn(false);
+
+ mPluginService.onPanelShown(mPluginCallbacks, false, mWalletClient);
+
+ assertThat(Settings.Secure.getInt(
+ cr, Settings.Secure.GLOBAL_ACTIONS_PANEL_AVAILABLE, -1)).isEqualTo(0);
+ assertThat(Settings.Secure.getInt(
+ cr, Settings.Secure.GLOBAL_ACTIONS_PANEL_ENABLED, -1)).isEqualTo(1);
+ }
+
+ @Test
public void onPanelShown_returnsControllerIfFeatureAvailable() {
when(mWalletClient.isWalletServiceAvailable()).thenReturn(true);
when(mWalletClient.isWalletFeatureAvailable()).thenReturn(true);
+ mPluginService.onCreate(mContext, mContext, mWalletClient);
GlobalActionsPanelPlugin.PanelViewController viewController =
mPluginService.onPanelShown(mPluginCallbacks, false, mWalletClient);
@@ -79,6 +131,7 @@ public class WalletPluginServiceTest {
public void onPanelShown_performsGetWalletCardsRequest() {
when(mWalletClient.isWalletServiceAvailable()).thenReturn(true);
when(mWalletClient.isWalletFeatureAvailable()).thenReturn(true);
+ mPluginService.onCreate(mContext, mContext, mWalletClient);
mPluginService.onPanelShown(mPluginCallbacks, false, mWalletClient);
@@ -89,6 +142,7 @@ public class WalletPluginServiceTest {
public void onPanelShown_returnsNullIfFeatureUnavailable() {
when(mWalletClient.isWalletServiceAvailable()).thenReturn(true);
when(mWalletClient.isWalletFeatureAvailable()).thenReturn(false);
+ mPluginService.onCreate(mContext, mContext, mWalletClient);
GlobalActionsPanelPlugin.PanelViewController viewController =
mPluginService.onPanelShown(mPluginCallbacks, false, mWalletClient);
@@ -100,6 +154,7 @@ public class WalletPluginServiceTest {
public void onPanelShown_returnsNullIfServiceUnavailable() {
when(mWalletClient.isWalletServiceAvailable()).thenReturn(false);
when(mWalletClient.isWalletFeatureAvailable()).thenReturn(true);
+ mPluginService.onCreate(mContext, mContext, mWalletClient);
GlobalActionsPanelPlugin.PanelViewController viewController =
mPluginService.onPanelShown(mPluginCallbacks, false, mWalletClient);