Milo Sredkov | 22b8d9e | 2018-11-27 15:52:10 +0000 | [diff] [blame] | 1 | /** |
| 2 | * Copyright (C) 2018 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package android.ext.services.notification; |
| 18 | |
Tony Mak | e1a27ac | 2019-01-31 16:32:19 +0000 | [diff] [blame] | 19 | import static android.ext.services.notification.AssistantSettings.DEFAULT_MAX_SUGGESTIONS; |
Tony Mak | e1a27ac | 2019-01-31 16:32:19 +0000 | [diff] [blame] | 20 | import static android.provider.DeviceConfig.setProperty; |
| 21 | |
Stanislav Zholnin | c1b13d0 | 2019-03-05 18:13:34 +0000 | [diff] [blame] | 22 | import static com.android.compatibility.common.util.SystemUtil.runWithShellPermissionIdentity; |
| 23 | |
Milo Sredkov | 22b8d9e | 2018-11-27 15:52:10 +0000 | [diff] [blame] | 24 | import static junit.framework.Assert.assertFalse; |
| 25 | import static junit.framework.Assert.assertTrue; |
| 26 | |
| 27 | import static org.junit.Assert.assertEquals; |
| 28 | import static org.mockito.Mockito.never; |
| 29 | import static org.mockito.Mockito.verify; |
| 30 | |
| 31 | import android.content.ContentResolver; |
| 32 | import android.os.Handler; |
| 33 | import android.os.Looper; |
Gustav Sennton | ddd78b2 | 2019-02-18 17:58:12 +0000 | [diff] [blame] | 34 | import android.provider.DeviceConfig; |
Milo Sredkov | 22b8d9e | 2018-11-27 15:52:10 +0000 | [diff] [blame] | 35 | import android.provider.Settings; |
Tony Mak | e1a27ac | 2019-01-31 16:32:19 +0000 | [diff] [blame] | 36 | import android.support.test.uiautomator.UiDevice; |
Milo Sredkov | 22b8d9e | 2018-11-27 15:52:10 +0000 | [diff] [blame] | 37 | import android.testing.TestableContext; |
| 38 | |
Brett Chabot | 84151d9 | 2019-02-27 15:37:59 -0800 | [diff] [blame] | 39 | import androidx.test.InstrumentationRegistry; |
| 40 | import androidx.test.runner.AndroidJUnit4; |
| 41 | |
Gustav Sennton | ddd78b2 | 2019-02-18 17:58:12 +0000 | [diff] [blame] | 42 | import com.android.internal.config.sysui.SystemUiDeviceConfigFlags; |
| 43 | |
Tony Mak | e1a27ac | 2019-01-31 16:32:19 +0000 | [diff] [blame] | 44 | import org.junit.After; |
Milo Sredkov | 22b8d9e | 2018-11-27 15:52:10 +0000 | [diff] [blame] | 45 | import org.junit.Before; |
| 46 | import org.junit.Rule; |
| 47 | import org.junit.Test; |
| 48 | import org.junit.runner.RunWith; |
| 49 | import org.mockito.Mock; |
| 50 | import org.mockito.MockitoAnnotations; |
| 51 | |
Tony Mak | e1a27ac | 2019-01-31 16:32:19 +0000 | [diff] [blame] | 52 | import java.io.IOException; |
| 53 | |
Milo Sredkov | 22b8d9e | 2018-11-27 15:52:10 +0000 | [diff] [blame] | 54 | @RunWith(AndroidJUnit4.class) |
| 55 | public class AssistantSettingsTest { |
Tony Mak | e1a27ac | 2019-01-31 16:32:19 +0000 | [diff] [blame] | 56 | private static final String CLEAR_DEVICE_CONFIG_KEY_CMD = |
Gustav Sennton | ddd78b2 | 2019-02-18 17:58:12 +0000 | [diff] [blame] | 57 | "device_config delete " + DeviceConfig.NAMESPACE_SYSTEMUI; |
Tony Mak | e1a27ac | 2019-01-31 16:32:19 +0000 | [diff] [blame] | 58 | |
Milo Sredkov | 22b8d9e | 2018-11-27 15:52:10 +0000 | [diff] [blame] | 59 | private static final int USER_ID = 5; |
| 60 | |
| 61 | @Rule |
| 62 | public final TestableContext mContext = |
| 63 | new TestableContext(InstrumentationRegistry.getContext(), null); |
| 64 | |
| 65 | @Mock Runnable mOnUpdateRunnable; |
| 66 | |
| 67 | private ContentResolver mResolver; |
| 68 | private AssistantSettings mAssistantSettings; |
| 69 | |
| 70 | @Before |
| 71 | public void setUp() { |
| 72 | MockitoAnnotations.initMocks(this); |
| 73 | |
| 74 | mResolver = mContext.getContentResolver(); |
| 75 | Handler handler = new Handler(Looper.getMainLooper()); |
| 76 | |
| 77 | // To bypass real calls to global settings values, set the Settings values here. |
| 78 | Settings.Global.putFloat(mResolver, |
| 79 | Settings.Global.BLOCKING_HELPER_DISMISS_TO_VIEW_RATIO_LIMIT, 0.8f); |
| 80 | Settings.Global.putInt(mResolver, Settings.Global.BLOCKING_HELPER_STREAK_LIMIT, 2); |
Milo Sredkov | 22b8d9e | 2018-11-27 15:52:10 +0000 | [diff] [blame] | 81 | Settings.Secure.putInt(mResolver, Settings.Secure.NOTIFICATION_NEW_INTERRUPTION_MODEL, 1); |
| 82 | |
| 83 | mAssistantSettings = AssistantSettings.createForTesting( |
| 84 | handler, mResolver, USER_ID, mOnUpdateRunnable); |
| 85 | } |
| 86 | |
Tony Mak | e1a27ac | 2019-01-31 16:32:19 +0000 | [diff] [blame] | 87 | @After |
| 88 | public void tearDown() throws IOException { |
| 89 | clearDeviceConfig(); |
| 90 | } |
| 91 | |
Milo Sredkov | 22b8d9e | 2018-11-27 15:52:10 +0000 | [diff] [blame] | 92 | @Test |
| 93 | public void testGenerateRepliesDisabled() { |
Stanislav Zholnin | c1b13d0 | 2019-03-05 18:13:34 +0000 | [diff] [blame] | 94 | runWithShellPermissionIdentity(() -> setProperty( |
Gustav Sennton | ddd78b2 | 2019-02-18 17:58:12 +0000 | [diff] [blame] | 95 | DeviceConfig.NAMESPACE_SYSTEMUI, |
| 96 | SystemUiDeviceConfigFlags.NAS_GENERATE_REPLIES, |
Gustav Sennton | 73a8c1b | 2019-01-23 18:15:39 +0000 | [diff] [blame] | 97 | "false", |
Stanislav Zholnin | c1b13d0 | 2019-03-05 18:13:34 +0000 | [diff] [blame] | 98 | false /* makeDefault */)); |
Gustav Sennton | 13cc6eb | 2019-01-17 18:05:46 +0000 | [diff] [blame] | 99 | mAssistantSettings.onDeviceConfigPropertyChanged( |
Gustav Sennton | ddd78b2 | 2019-02-18 17:58:12 +0000 | [diff] [blame] | 100 | DeviceConfig.NAMESPACE_SYSTEMUI, |
| 101 | SystemUiDeviceConfigFlags.NAS_GENERATE_REPLIES, |
Gustav Sennton | 13cc6eb | 2019-01-17 18:05:46 +0000 | [diff] [blame] | 102 | "false"); |
Milo Sredkov | 22b8d9e | 2018-11-27 15:52:10 +0000 | [diff] [blame] | 103 | |
| 104 | assertFalse(mAssistantSettings.mGenerateReplies); |
| 105 | } |
| 106 | |
| 107 | @Test |
| 108 | public void testGenerateRepliesEnabled() { |
Stanislav Zholnin | c1b13d0 | 2019-03-05 18:13:34 +0000 | [diff] [blame] | 109 | runWithShellPermissionIdentity(() -> setProperty( |
Gustav Sennton | ddd78b2 | 2019-02-18 17:58:12 +0000 | [diff] [blame] | 110 | DeviceConfig.NAMESPACE_SYSTEMUI, |
| 111 | SystemUiDeviceConfigFlags.NAS_GENERATE_REPLIES, |
Gustav Sennton | 73a8c1b | 2019-01-23 18:15:39 +0000 | [diff] [blame] | 112 | "true", |
Stanislav Zholnin | c1b13d0 | 2019-03-05 18:13:34 +0000 | [diff] [blame] | 113 | false /* makeDefault */)); |
Gustav Sennton | 13cc6eb | 2019-01-17 18:05:46 +0000 | [diff] [blame] | 114 | mAssistantSettings.onDeviceConfigPropertyChanged( |
Gustav Sennton | ddd78b2 | 2019-02-18 17:58:12 +0000 | [diff] [blame] | 115 | DeviceConfig.NAMESPACE_SYSTEMUI, |
| 116 | SystemUiDeviceConfigFlags.NAS_GENERATE_REPLIES, |
Gustav Sennton | 13cc6eb | 2019-01-17 18:05:46 +0000 | [diff] [blame] | 117 | "true"); |
Milo Sredkov | 22b8d9e | 2018-11-27 15:52:10 +0000 | [diff] [blame] | 118 | |
Gustav Sennton | 13cc6eb | 2019-01-17 18:05:46 +0000 | [diff] [blame] | 119 | assertTrue(mAssistantSettings.mGenerateReplies); |
| 120 | } |
Milo Sredkov | 22b8d9e | 2018-11-27 15:52:10 +0000 | [diff] [blame] | 121 | |
Gustav Sennton | 13cc6eb | 2019-01-17 18:05:46 +0000 | [diff] [blame] | 122 | @Test |
Stanislav Zholnin | 3353c11 | 2019-03-07 16:09:20 +0000 | [diff] [blame] | 123 | public void testGenerateRepliesNullFlag() { |
Stanislav Zholnin | c1b13d0 | 2019-03-05 18:13:34 +0000 | [diff] [blame] | 124 | runWithShellPermissionIdentity(() -> setProperty( |
Gustav Sennton | ddd78b2 | 2019-02-18 17:58:12 +0000 | [diff] [blame] | 125 | DeviceConfig.NAMESPACE_SYSTEMUI, |
| 126 | SystemUiDeviceConfigFlags.NAS_GENERATE_REPLIES, |
Gustav Sennton | 73a8c1b | 2019-01-23 18:15:39 +0000 | [diff] [blame] | 127 | "false", |
Stanislav Zholnin | c1b13d0 | 2019-03-05 18:13:34 +0000 | [diff] [blame] | 128 | false /* makeDefault */)); |
Gustav Sennton | 13cc6eb | 2019-01-17 18:05:46 +0000 | [diff] [blame] | 129 | mAssistantSettings.onDeviceConfigPropertyChanged( |
Gustav Sennton | ddd78b2 | 2019-02-18 17:58:12 +0000 | [diff] [blame] | 130 | DeviceConfig.NAMESPACE_SYSTEMUI, |
| 131 | SystemUiDeviceConfigFlags.NAS_GENERATE_REPLIES, |
Gustav Sennton | 13cc6eb | 2019-01-17 18:05:46 +0000 | [diff] [blame] | 132 | "false"); |
| 133 | |
| 134 | assertFalse(mAssistantSettings.mGenerateReplies); |
| 135 | |
Stanislav Zholnin | c1b13d0 | 2019-03-05 18:13:34 +0000 | [diff] [blame] | 136 | runWithShellPermissionIdentity(() -> setProperty( |
Gustav Sennton | ddd78b2 | 2019-02-18 17:58:12 +0000 | [diff] [blame] | 137 | DeviceConfig.NAMESPACE_SYSTEMUI, |
| 138 | SystemUiDeviceConfigFlags.NAS_GENERATE_REPLIES, |
Stanislav Zholnin | 3353c11 | 2019-03-07 16:09:20 +0000 | [diff] [blame] | 139 | null, |
Stanislav Zholnin | c1b13d0 | 2019-03-05 18:13:34 +0000 | [diff] [blame] | 140 | false /* makeDefault */)); |
Gustav Sennton | 13cc6eb | 2019-01-17 18:05:46 +0000 | [diff] [blame] | 141 | mAssistantSettings.onDeviceConfigPropertyChanged( |
Gustav Sennton | ddd78b2 | 2019-02-18 17:58:12 +0000 | [diff] [blame] | 142 | DeviceConfig.NAMESPACE_SYSTEMUI, |
| 143 | SystemUiDeviceConfigFlags.NAS_GENERATE_REPLIES, |
Stanislav Zholnin | 3353c11 | 2019-03-07 16:09:20 +0000 | [diff] [blame] | 144 | null); |
Gustav Sennton | 13cc6eb | 2019-01-17 18:05:46 +0000 | [diff] [blame] | 145 | |
| 146 | // Go back to the default value. |
Milo Sredkov | 22b8d9e | 2018-11-27 15:52:10 +0000 | [diff] [blame] | 147 | assertTrue(mAssistantSettings.mGenerateReplies); |
| 148 | } |
| 149 | |
| 150 | @Test |
| 151 | public void testGenerateActionsDisabled() { |
Stanislav Zholnin | c1b13d0 | 2019-03-05 18:13:34 +0000 | [diff] [blame] | 152 | runWithShellPermissionIdentity(() -> setProperty( |
Gustav Sennton | ddd78b2 | 2019-02-18 17:58:12 +0000 | [diff] [blame] | 153 | DeviceConfig.NAMESPACE_SYSTEMUI, |
| 154 | SystemUiDeviceConfigFlags.NAS_GENERATE_ACTIONS, |
Gustav Sennton | 73a8c1b | 2019-01-23 18:15:39 +0000 | [diff] [blame] | 155 | "false", |
Stanislav Zholnin | c1b13d0 | 2019-03-05 18:13:34 +0000 | [diff] [blame] | 156 | false /* makeDefault */)); |
Gustav Sennton | 13cc6eb | 2019-01-17 18:05:46 +0000 | [diff] [blame] | 157 | mAssistantSettings.onDeviceConfigPropertyChanged( |
Gustav Sennton | ddd78b2 | 2019-02-18 17:58:12 +0000 | [diff] [blame] | 158 | DeviceConfig.NAMESPACE_SYSTEMUI, |
| 159 | SystemUiDeviceConfigFlags.NAS_GENERATE_ACTIONS, |
Gustav Sennton | 13cc6eb | 2019-01-17 18:05:46 +0000 | [diff] [blame] | 160 | "false"); |
Milo Sredkov | 22b8d9e | 2018-11-27 15:52:10 +0000 | [diff] [blame] | 161 | |
Gustav Sennton | 13cc6eb | 2019-01-17 18:05:46 +0000 | [diff] [blame] | 162 | assertFalse(mAssistantSettings.mGenerateActions); |
Milo Sredkov | 22b8d9e | 2018-11-27 15:52:10 +0000 | [diff] [blame] | 163 | } |
| 164 | |
| 165 | @Test |
| 166 | public void testGenerateActionsEnabled() { |
Stanislav Zholnin | c1b13d0 | 2019-03-05 18:13:34 +0000 | [diff] [blame] | 167 | runWithShellPermissionIdentity(() -> setProperty( |
Gustav Sennton | ddd78b2 | 2019-02-18 17:58:12 +0000 | [diff] [blame] | 168 | DeviceConfig.NAMESPACE_SYSTEMUI, |
| 169 | SystemUiDeviceConfigFlags.NAS_GENERATE_ACTIONS, |
Gustav Sennton | 73a8c1b | 2019-01-23 18:15:39 +0000 | [diff] [blame] | 170 | "true", |
Stanislav Zholnin | c1b13d0 | 2019-03-05 18:13:34 +0000 | [diff] [blame] | 171 | false /* makeDefault */)); |
Gustav Sennton | 13cc6eb | 2019-01-17 18:05:46 +0000 | [diff] [blame] | 172 | mAssistantSettings.onDeviceConfigPropertyChanged( |
Gustav Sennton | ddd78b2 | 2019-02-18 17:58:12 +0000 | [diff] [blame] | 173 | DeviceConfig.NAMESPACE_SYSTEMUI, |
| 174 | SystemUiDeviceConfigFlags.NAS_GENERATE_ACTIONS, |
Gustav Sennton | 13cc6eb | 2019-01-17 18:05:46 +0000 | [diff] [blame] | 175 | "true"); |
Milo Sredkov | 22b8d9e | 2018-11-27 15:52:10 +0000 | [diff] [blame] | 176 | |
Gustav Sennton | 13cc6eb | 2019-01-17 18:05:46 +0000 | [diff] [blame] | 177 | assertTrue(mAssistantSettings.mGenerateActions); |
| 178 | } |
Milo Sredkov | 22b8d9e | 2018-11-27 15:52:10 +0000 | [diff] [blame] | 179 | |
Gustav Sennton | 13cc6eb | 2019-01-17 18:05:46 +0000 | [diff] [blame] | 180 | @Test |
Stanislav Zholnin | 3353c11 | 2019-03-07 16:09:20 +0000 | [diff] [blame] | 181 | public void testGenerateActionsNullFlag() { |
Stanislav Zholnin | c1b13d0 | 2019-03-05 18:13:34 +0000 | [diff] [blame] | 182 | runWithShellPermissionIdentity(() -> setProperty( |
Gustav Sennton | ddd78b2 | 2019-02-18 17:58:12 +0000 | [diff] [blame] | 183 | DeviceConfig.NAMESPACE_SYSTEMUI, |
| 184 | SystemUiDeviceConfigFlags.NAS_GENERATE_ACTIONS, |
Gustav Sennton | 73a8c1b | 2019-01-23 18:15:39 +0000 | [diff] [blame] | 185 | "false", |
Stanislav Zholnin | c1b13d0 | 2019-03-05 18:13:34 +0000 | [diff] [blame] | 186 | false /* makeDefault */)); |
Gustav Sennton | 13cc6eb | 2019-01-17 18:05:46 +0000 | [diff] [blame] | 187 | mAssistantSettings.onDeviceConfigPropertyChanged( |
Gustav Sennton | ddd78b2 | 2019-02-18 17:58:12 +0000 | [diff] [blame] | 188 | DeviceConfig.NAMESPACE_SYSTEMUI, |
| 189 | SystemUiDeviceConfigFlags.NAS_GENERATE_ACTIONS, |
Gustav Sennton | 13cc6eb | 2019-01-17 18:05:46 +0000 | [diff] [blame] | 190 | "false"); |
| 191 | |
| 192 | assertFalse(mAssistantSettings.mGenerateActions); |
| 193 | |
Stanislav Zholnin | c1b13d0 | 2019-03-05 18:13:34 +0000 | [diff] [blame] | 194 | runWithShellPermissionIdentity(() -> setProperty( |
Gustav Sennton | ddd78b2 | 2019-02-18 17:58:12 +0000 | [diff] [blame] | 195 | DeviceConfig.NAMESPACE_SYSTEMUI, |
| 196 | SystemUiDeviceConfigFlags.NAS_GENERATE_ACTIONS, |
Stanislav Zholnin | 3353c11 | 2019-03-07 16:09:20 +0000 | [diff] [blame] | 197 | null, |
Stanislav Zholnin | c1b13d0 | 2019-03-05 18:13:34 +0000 | [diff] [blame] | 198 | false /* makeDefault */)); |
Gustav Sennton | 13cc6eb | 2019-01-17 18:05:46 +0000 | [diff] [blame] | 199 | mAssistantSettings.onDeviceConfigPropertyChanged( |
Gustav Sennton | ddd78b2 | 2019-02-18 17:58:12 +0000 | [diff] [blame] | 200 | DeviceConfig.NAMESPACE_SYSTEMUI, |
| 201 | SystemUiDeviceConfigFlags.NAS_GENERATE_ACTIONS, |
Stanislav Zholnin | 3353c11 | 2019-03-07 16:09:20 +0000 | [diff] [blame] | 202 | null); |
Gustav Sennton | 13cc6eb | 2019-01-17 18:05:46 +0000 | [diff] [blame] | 203 | |
| 204 | // Go back to the default value. |
| 205 | assertTrue(mAssistantSettings.mGenerateActions); |
Milo Sredkov | 22b8d9e | 2018-11-27 15:52:10 +0000 | [diff] [blame] | 206 | } |
| 207 | |
| 208 | @Test |
Tony Mak | e1a27ac | 2019-01-31 16:32:19 +0000 | [diff] [blame] | 209 | public void testMaxMessagesToExtract() { |
Stanislav Zholnin | c1b13d0 | 2019-03-05 18:13:34 +0000 | [diff] [blame] | 210 | runWithShellPermissionIdentity(() -> setProperty( |
Gustav Sennton | ddd78b2 | 2019-02-18 17:58:12 +0000 | [diff] [blame] | 211 | DeviceConfig.NAMESPACE_SYSTEMUI, |
| 212 | SystemUiDeviceConfigFlags.NAS_MAX_MESSAGES_TO_EXTRACT, |
Tony Mak | e1a27ac | 2019-01-31 16:32:19 +0000 | [diff] [blame] | 213 | "10", |
Stanislav Zholnin | c1b13d0 | 2019-03-05 18:13:34 +0000 | [diff] [blame] | 214 | false /* makeDefault */)); |
Tony Mak | e1a27ac | 2019-01-31 16:32:19 +0000 | [diff] [blame] | 215 | mAssistantSettings.onDeviceConfigPropertyChanged( |
Gustav Sennton | ddd78b2 | 2019-02-18 17:58:12 +0000 | [diff] [blame] | 216 | DeviceConfig.NAMESPACE_SYSTEMUI, |
| 217 | SystemUiDeviceConfigFlags.NAS_MAX_MESSAGES_TO_EXTRACT, |
Tony Mak | e1a27ac | 2019-01-31 16:32:19 +0000 | [diff] [blame] | 218 | "10"); |
| 219 | |
| 220 | assertEquals(10, mAssistantSettings.mMaxMessagesToExtract); |
| 221 | } |
| 222 | |
| 223 | @Test |
| 224 | public void testMaxSuggestions() { |
Stanislav Zholnin | c1b13d0 | 2019-03-05 18:13:34 +0000 | [diff] [blame] | 225 | runWithShellPermissionIdentity(() -> setProperty( |
Gustav Sennton | ddd78b2 | 2019-02-18 17:58:12 +0000 | [diff] [blame] | 226 | DeviceConfig.NAMESPACE_SYSTEMUI, |
| 227 | SystemUiDeviceConfigFlags.NAS_MAX_SUGGESTIONS, |
Tony Mak | e1a27ac | 2019-01-31 16:32:19 +0000 | [diff] [blame] | 228 | "5", |
Stanislav Zholnin | c1b13d0 | 2019-03-05 18:13:34 +0000 | [diff] [blame] | 229 | false /* makeDefault */)); |
Tony Mak | e1a27ac | 2019-01-31 16:32:19 +0000 | [diff] [blame] | 230 | mAssistantSettings.onDeviceConfigPropertyChanged( |
Gustav Sennton | ddd78b2 | 2019-02-18 17:58:12 +0000 | [diff] [blame] | 231 | DeviceConfig.NAMESPACE_SYSTEMUI, |
| 232 | SystemUiDeviceConfigFlags.NAS_MAX_SUGGESTIONS, |
Tony Mak | e1a27ac | 2019-01-31 16:32:19 +0000 | [diff] [blame] | 233 | "5"); |
| 234 | |
| 235 | assertEquals(5, mAssistantSettings.mMaxSuggestions); |
| 236 | } |
| 237 | |
| 238 | @Test |
| 239 | public void testMaxSuggestionsEmpty() { |
| 240 | mAssistantSettings.onDeviceConfigPropertyChanged( |
Gustav Sennton | ddd78b2 | 2019-02-18 17:58:12 +0000 | [diff] [blame] | 241 | DeviceConfig.NAMESPACE_SYSTEMUI, |
| 242 | SystemUiDeviceConfigFlags.NAS_MAX_SUGGESTIONS, |
Tony Mak | e1a27ac | 2019-01-31 16:32:19 +0000 | [diff] [blame] | 243 | ""); |
| 244 | |
| 245 | assertEquals(DEFAULT_MAX_SUGGESTIONS, mAssistantSettings.mMaxSuggestions); |
| 246 | } |
| 247 | |
| 248 | @Test |
Milo Sredkov | 22b8d9e | 2018-11-27 15:52:10 +0000 | [diff] [blame] | 249 | public void testStreakLimit() { |
| 250 | verify(mOnUpdateRunnable, never()).run(); |
| 251 | |
| 252 | // Update settings value. |
| 253 | int newStreakLimit = 4; |
| 254 | Settings.Global.putInt(mResolver, |
| 255 | Settings.Global.BLOCKING_HELPER_STREAK_LIMIT, newStreakLimit); |
| 256 | |
| 257 | // Notify for the settings value we updated. |
| 258 | mAssistantSettings.onChange(false, Settings.Global.getUriFor( |
| 259 | Settings.Global.BLOCKING_HELPER_STREAK_LIMIT)); |
| 260 | |
| 261 | assertEquals(newStreakLimit, mAssistantSettings.mStreakLimit); |
| 262 | verify(mOnUpdateRunnable).run(); |
| 263 | } |
| 264 | |
| 265 | @Test |
| 266 | public void testDismissToViewRatioLimit() { |
| 267 | verify(mOnUpdateRunnable, never()).run(); |
| 268 | |
| 269 | // Update settings value. |
| 270 | float newDismissToViewRatioLimit = 3f; |
| 271 | Settings.Global.putFloat(mResolver, |
| 272 | Settings.Global.BLOCKING_HELPER_DISMISS_TO_VIEW_RATIO_LIMIT, |
| 273 | newDismissToViewRatioLimit); |
| 274 | |
| 275 | // Notify for the settings value we updated. |
| 276 | mAssistantSettings.onChange(false, Settings.Global.getUriFor( |
| 277 | Settings.Global.BLOCKING_HELPER_DISMISS_TO_VIEW_RATIO_LIMIT)); |
| 278 | |
| 279 | assertEquals(newDismissToViewRatioLimit, mAssistantSettings.mDismissToViewRatioLimit, 1e-6); |
| 280 | verify(mOnUpdateRunnable).run(); |
| 281 | } |
Tony Mak | e1a27ac | 2019-01-31 16:32:19 +0000 | [diff] [blame] | 282 | |
| 283 | private static void clearDeviceConfig() throws IOException { |
| 284 | UiDevice uiDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()); |
| 285 | uiDevice.executeShellCommand( |
Gustav Sennton | ddd78b2 | 2019-02-18 17:58:12 +0000 | [diff] [blame] | 286 | CLEAR_DEVICE_CONFIG_KEY_CMD + " " + SystemUiDeviceConfigFlags.NAS_GENERATE_ACTIONS); |
Tony Mak | e1a27ac | 2019-01-31 16:32:19 +0000 | [diff] [blame] | 287 | uiDevice.executeShellCommand( |
Gustav Sennton | ddd78b2 | 2019-02-18 17:58:12 +0000 | [diff] [blame] | 288 | CLEAR_DEVICE_CONFIG_KEY_CMD + " " + SystemUiDeviceConfigFlags.NAS_GENERATE_REPLIES); |
Tony Mak | e1a27ac | 2019-01-31 16:32:19 +0000 | [diff] [blame] | 289 | uiDevice.executeShellCommand( |
Gustav Sennton | ddd78b2 | 2019-02-18 17:58:12 +0000 | [diff] [blame] | 290 | CLEAR_DEVICE_CONFIG_KEY_CMD + " " |
| 291 | + SystemUiDeviceConfigFlags.NAS_MAX_MESSAGES_TO_EXTRACT); |
Tony Mak | e1a27ac | 2019-01-31 16:32:19 +0000 | [diff] [blame] | 292 | uiDevice.executeShellCommand( |
Gustav Sennton | ddd78b2 | 2019-02-18 17:58:12 +0000 | [diff] [blame] | 293 | CLEAR_DEVICE_CONFIG_KEY_CMD + " " + SystemUiDeviceConfigFlags.NAS_MAX_SUGGESTIONS); |
Tony Mak | e1a27ac | 2019-01-31 16:32:19 +0000 | [diff] [blame] | 294 | } |
| 295 | |
Milo Sredkov | 22b8d9e | 2018-11-27 15:52:10 +0000 | [diff] [blame] | 296 | } |