From c7c214b128d27a8f719744adfe5d3f96fe41d88f Mon Sep 17 00:00:00 2001 From: Sean Pont Date: Fri, 19 Jun 2020 19:02:38 -0700 Subject: Hide Cards and Passes setting when unavailable Fixes: 154497863 Test: manual - enable and disable wallet, observe settings Test: atest QuickAccessWalletRoboTests Change-Id: Ifb833b2f8202e3dc116d1325808654dd767a374a --- .../globalactions/wallet/WalletPluginService.java | 24 ++++++-- .../wallet/QuickAccessWalletClientTest.java | 10 ++-- .../wallet/WalletPluginServiceTest.java | 69 +++++++++++++++++++--- 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); @@ -53,21 +53,73 @@ public class WalletPluginServiceTest { cr, Settings.Secure.GLOBAL_ACTIONS_PANEL_ENABLED, -1)).isEqualTo(1); } + @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); -- cgit v1.2.3