diff options
author | android-build-team Robot <android-build-team-robot@google.com> | 2020-06-21 23:12:23 +0000 |
---|---|---|
committer | android-build-team Robot <android-build-team-robot@google.com> | 2020-06-21 23:12:23 +0000 |
commit | 99a120ffb4b5191e3bc6a162e7525fb47804b1bc (patch) | |
tree | 1a4a3e613368c490cd3287f1e254692db5f160cf | |
parent | f1799d5361dd49089bae4e0b146ab766f3f56b34 (diff) | |
parent | 5f27d811a48d21279fb3956f1a55b3590441e89f (diff) | |
download | QuickAccessWallet-android-security-11.0.0_r57.tar.gz |
Snap for 6613579 from 5f27d811a48d21279fb3956f1a55b3590441e89f to rvc-releaseandroid-vts-11.0_r9android-vts-11.0_r8android-vts-11.0_r7android-vts-11.0_r6android-vts-11.0_r5android-vts-11.0_r4android-vts-11.0_r3android-vts-11.0_r2android-vts-11.0_r16android-vts-11.0_r15android-vts-11.0_r14android-vts-11.0_r13android-vts-11.0_r12android-vts-11.0_r11android-vts-11.0_r10android-vts-11.0_r1android-security-11.0.0_r69android-security-11.0.0_r68android-security-11.0.0_r67android-security-11.0.0_r66android-security-11.0.0_r65android-security-11.0.0_r64android-security-11.0.0_r63android-security-11.0.0_r62android-security-11.0.0_r61android-security-11.0.0_r60android-security-11.0.0_r59android-security-11.0.0_r58android-security-11.0.0_r57android-security-11.0.0_r56android-security-11.0.0_r55android-security-11.0.0_r54android-security-11.0.0_r53android-security-11.0.0_r52android-security-11.0.0_r51android-security-11.0.0_r50android-security-11.0.0_r49android-security-11.0.0_r1android-platform-11.0.0_r2android-platform-11.0.0_r1android-cts-11.0_r9android-cts-11.0_r8android-cts-11.0_r7android-cts-11.0_r6android-cts-11.0_r5android-cts-11.0_r4android-cts-11.0_r3android-cts-11.0_r2android-cts-11.0_r16android-cts-11.0_r15android-cts-11.0_r14android-cts-11.0_r13android-cts-11.0_r12android-cts-11.0_r11android-cts-11.0_r10android-cts-11.0_r1android-11.0.0_r6android-11.0.0_r5android-11.0.0_r4android-11.0.0_r3android-11.0.0_r25android-11.0.0_r2android-11.0.0_r17android-11.0.0_r1android11-tests-releaseandroid11-s1-releaseandroid11-release
Change-Id: Ie580780ff8338120d1568edf3364a81a348a36bf
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); |