Petr Cermak | 10011fa | 2018-02-05 19:00:54 +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 com.android.systemui.statusbar.policy; |
| 18 | |
| 19 | import static junit.framework.Assert.assertEquals; |
| 20 | import static junit.framework.Assert.assertFalse; |
| 21 | import static junit.framework.Assert.assertTrue; |
| 22 | |
Milo Sredkov | 41dc4ba | 2018-12-27 12:03:45 +0000 | [diff] [blame] | 23 | import android.app.RemoteInput; |
Petr Cermak | 10011fa | 2018-02-05 19:00:54 +0000 | [diff] [blame] | 24 | import android.os.Handler; |
| 25 | import android.os.Looper; |
Gustav Sennton | 8fa7e95 | 2019-01-29 19:37:00 +0000 | [diff] [blame] | 26 | import android.provider.DeviceConfig; |
Petr Cermak | 10011fa | 2018-02-05 19:00:54 +0000 | [diff] [blame] | 27 | import android.test.suitebuilder.annotation.SmallTest; |
| 28 | import android.testing.AndroidTestingRunner; |
| 29 | import android.testing.TestableLooper; |
| 30 | import android.testing.TestableResources; |
| 31 | |
Gustav Sennton | 8fa7e95 | 2019-01-29 19:37:00 +0000 | [diff] [blame] | 32 | import com.android.internal.config.sysui.SystemUiDeviceConfigFlags; |
Petr Cermak | 10011fa | 2018-02-05 19:00:54 +0000 | [diff] [blame] | 33 | import com.android.systemui.R; |
| 34 | import com.android.systemui.SysuiTestCase; |
| 35 | |
Gustav Sennton | 8fa7e95 | 2019-01-29 19:37:00 +0000 | [diff] [blame] | 36 | import org.junit.After; |
Petr Cermak | 10011fa | 2018-02-05 19:00:54 +0000 | [diff] [blame] | 37 | import org.junit.Before; |
| 38 | import org.junit.Test; |
| 39 | import org.junit.runner.RunWith; |
| 40 | |
| 41 | @RunWith(AndroidTestingRunner.class) |
| 42 | @TestableLooper.RunWithLooper |
| 43 | @SmallTest |
| 44 | public class SmartReplyConstantsTest extends SysuiTestCase { |
| 45 | |
| 46 | private static final int CONTENT_OBSERVER_TIMEOUT_SECONDS = 10; |
| 47 | |
| 48 | private SmartReplyConstants mConstants; |
| 49 | |
| 50 | @Before |
| 51 | public void setUp() { |
Gustav Sennton | 8fa7e95 | 2019-01-29 19:37:00 +0000 | [diff] [blame] | 52 | resetAllDeviceConfigFlags(); |
Petr Cermak | 10011fa | 2018-02-05 19:00:54 +0000 | [diff] [blame] | 53 | TestableResources resources = mContext.getOrCreateTestableResources(); |
| 54 | resources.addOverride(R.bool.config_smart_replies_in_notifications_enabled, true); |
| 55 | resources.addOverride( |
| 56 | R.integer.config_smart_replies_in_notifications_max_squeeze_remeasure_attempts, 7); |
Milo Sredkov | 41dc4ba | 2018-12-27 12:03:45 +0000 | [diff] [blame] | 57 | resources.addOverride( |
| 58 | R.bool.config_smart_replies_in_notifications_edit_choices_before_sending, false); |
Gustav Sennton | 3f3eaff | 2019-01-08 09:39:51 +0000 | [diff] [blame] | 59 | resources.addOverride(R.bool.config_smart_replies_in_notifications_show_in_heads_up, true); |
Gustav Sennton | a31f6ae | 2019-01-08 11:20:49 +0000 | [diff] [blame] | 60 | resources.addOverride( |
| 61 | R.integer.config_smart_replies_in_notifications_min_num_system_generated_replies, |
| 62 | 2); |
Gustav Sennton | 8fa7e95 | 2019-01-29 19:37:00 +0000 | [diff] [blame] | 63 | resources.addOverride( |
| 64 | R.integer.config_smart_replies_in_notifications_max_num_actions, -1); |
Jason Monk | 6dceace | 2018-05-15 20:24:07 -0400 | [diff] [blame] | 65 | mConstants = new SmartReplyConstants(Handler.createAsync(Looper.myLooper()), mContext); |
Petr Cermak | 10011fa | 2018-02-05 19:00:54 +0000 | [diff] [blame] | 66 | } |
| 67 | |
Gustav Sennton | 8fa7e95 | 2019-01-29 19:37:00 +0000 | [diff] [blame] | 68 | @After |
| 69 | public void tearDown() { |
| 70 | resetAllDeviceConfigFlags(); |
| 71 | } |
| 72 | |
Petr Cermak | 10011fa | 2018-02-05 19:00:54 +0000 | [diff] [blame] | 73 | @Test |
| 74 | public void testIsEnabledWithNoConfig() { |
| 75 | assertTrue(mConstants.isEnabled()); |
| 76 | } |
| 77 | |
| 78 | @Test |
| 79 | public void testIsEnabledWithInvalidConfig() { |
Gustav Sennton | 8fa7e95 | 2019-01-29 19:37:00 +0000 | [diff] [blame] | 80 | overrideSetting(SystemUiDeviceConfigFlags.SSIN_ENABLED, "invalid config"); |
Petr Cermak | 10011fa | 2018-02-05 19:00:54 +0000 | [diff] [blame] | 81 | triggerConstantsOnChange(); |
| 82 | assertTrue(mConstants.isEnabled()); |
| 83 | } |
| 84 | |
| 85 | @Test |
| 86 | public void testIsEnabledWithValidConfig() { |
Gustav Sennton | 8fa7e95 | 2019-01-29 19:37:00 +0000 | [diff] [blame] | 87 | overrideSetting(SystemUiDeviceConfigFlags.SSIN_ENABLED, "false"); |
Petr Cermak | 10011fa | 2018-02-05 19:00:54 +0000 | [diff] [blame] | 88 | triggerConstantsOnChange(); |
| 89 | assertFalse(mConstants.isEnabled()); |
| 90 | } |
| 91 | |
| 92 | @Test |
Richard Ledley | 4069f7a | 2018-02-26 10:36:00 +0000 | [diff] [blame] | 93 | public void testRequiresTargetingPConfig() { |
Gustav Sennton | 8fa7e95 | 2019-01-29 19:37:00 +0000 | [diff] [blame] | 94 | overrideSetting(SystemUiDeviceConfigFlags.SSIN_REQUIRES_TARGETING_P, "false"); |
Richard Ledley | 4069f7a | 2018-02-26 10:36:00 +0000 | [diff] [blame] | 95 | triggerConstantsOnChange(); |
| 96 | assertEquals(false, mConstants.requiresTargetingP()); |
| 97 | |
Gustav Sennton | 8fa7e95 | 2019-01-29 19:37:00 +0000 | [diff] [blame] | 98 | overrideSetting(SystemUiDeviceConfigFlags.SSIN_REQUIRES_TARGETING_P, ""); |
Richard Ledley | 4069f7a | 2018-02-26 10:36:00 +0000 | [diff] [blame] | 99 | triggerConstantsOnChange(); |
| 100 | assertEquals(true, mConstants.requiresTargetingP()); |
| 101 | } |
| 102 | |
| 103 | @Test |
Petr Cermak | 10011fa | 2018-02-05 19:00:54 +0000 | [diff] [blame] | 104 | public void testGetMaxSqueezeRemeasureAttemptsWithNoConfig() { |
| 105 | assertTrue(mConstants.isEnabled()); |
| 106 | assertEquals(7, mConstants.getMaxSqueezeRemeasureAttempts()); |
| 107 | } |
| 108 | |
| 109 | @Test |
| 110 | public void testGetMaxSqueezeRemeasureAttemptsWithInvalidConfig() { |
Gustav Sennton | 8fa7e95 | 2019-01-29 19:37:00 +0000 | [diff] [blame] | 111 | overrideSetting(SystemUiDeviceConfigFlags.SSIN_MAX_SQUEEZE_REMEASURE_ATTEMPTS, |
| 112 | "invalid config"); |
Petr Cermak | 10011fa | 2018-02-05 19:00:54 +0000 | [diff] [blame] | 113 | triggerConstantsOnChange(); |
| 114 | assertEquals(7, mConstants.getMaxSqueezeRemeasureAttempts()); |
| 115 | } |
| 116 | |
| 117 | @Test |
| 118 | public void testGetMaxSqueezeRemeasureAttemptsWithValidConfig() { |
Gustav Sennton | 8fa7e95 | 2019-01-29 19:37:00 +0000 | [diff] [blame] | 119 | overrideSetting(SystemUiDeviceConfigFlags.SSIN_MAX_SQUEEZE_REMEASURE_ATTEMPTS, "5"); |
Petr Cermak | 10011fa | 2018-02-05 19:00:54 +0000 | [diff] [blame] | 120 | triggerConstantsOnChange(); |
| 121 | assertEquals(5, mConstants.getMaxSqueezeRemeasureAttempts()); |
| 122 | } |
| 123 | |
Milo Sredkov | 41dc4ba | 2018-12-27 12:03:45 +0000 | [diff] [blame] | 124 | @Test |
| 125 | public void testGetEffectiveEditChoicesBeforeSendingWithNoConfig() { |
Milo Sredkov | 41dc4ba | 2018-12-27 12:03:45 +0000 | [diff] [blame] | 126 | triggerConstantsOnChange(); |
| 127 | assertFalse( |
| 128 | mConstants.getEffectiveEditChoicesBeforeSending( |
| 129 | RemoteInput.EDIT_CHOICES_BEFORE_SENDING_AUTO)); |
| 130 | assertTrue( |
| 131 | mConstants.getEffectiveEditChoicesBeforeSending( |
| 132 | RemoteInput.EDIT_CHOICES_BEFORE_SENDING_ENABLED)); |
| 133 | assertFalse( |
| 134 | mConstants.getEffectiveEditChoicesBeforeSending( |
| 135 | RemoteInput.EDIT_CHOICES_BEFORE_SENDING_DISABLED)); |
| 136 | } |
| 137 | |
| 138 | @Test |
| 139 | public void testGetEffectiveEditChoicesBeforeSendingWithEnabledConfig() { |
Gustav Sennton | 8fa7e95 | 2019-01-29 19:37:00 +0000 | [diff] [blame] | 140 | overrideSetting(SystemUiDeviceConfigFlags.SSIN_EDIT_CHOICES_BEFORE_SENDING, "true"); |
Milo Sredkov | 41dc4ba | 2018-12-27 12:03:45 +0000 | [diff] [blame] | 141 | triggerConstantsOnChange(); |
| 142 | assertTrue( |
| 143 | mConstants.getEffectiveEditChoicesBeforeSending( |
| 144 | RemoteInput.EDIT_CHOICES_BEFORE_SENDING_AUTO)); |
| 145 | assertTrue( |
| 146 | mConstants.getEffectiveEditChoicesBeforeSending( |
| 147 | RemoteInput.EDIT_CHOICES_BEFORE_SENDING_ENABLED)); |
| 148 | assertFalse( |
| 149 | mConstants.getEffectiveEditChoicesBeforeSending( |
| 150 | RemoteInput.EDIT_CHOICES_BEFORE_SENDING_DISABLED)); |
| 151 | } |
| 152 | |
| 153 | @Test |
| 154 | public void testGetEffectiveEditChoicesBeforeSendingWithDisabledConfig() { |
Gustav Sennton | 8fa7e95 | 2019-01-29 19:37:00 +0000 | [diff] [blame] | 155 | overrideSetting(SystemUiDeviceConfigFlags.SSIN_EDIT_CHOICES_BEFORE_SENDING, "false"); |
Milo Sredkov | 41dc4ba | 2018-12-27 12:03:45 +0000 | [diff] [blame] | 156 | triggerConstantsOnChange(); |
| 157 | assertFalse( |
| 158 | mConstants.getEffectiveEditChoicesBeforeSending( |
| 159 | RemoteInput.EDIT_CHOICES_BEFORE_SENDING_AUTO)); |
| 160 | assertTrue( |
| 161 | mConstants.getEffectiveEditChoicesBeforeSending( |
| 162 | RemoteInput.EDIT_CHOICES_BEFORE_SENDING_ENABLED)); |
| 163 | assertFalse( |
| 164 | mConstants.getEffectiveEditChoicesBeforeSending( |
| 165 | RemoteInput.EDIT_CHOICES_BEFORE_SENDING_DISABLED)); |
| 166 | } |
| 167 | |
Gustav Sennton | 3f3eaff | 2019-01-08 09:39:51 +0000 | [diff] [blame] | 168 | @Test |
| 169 | public void testShowInHeadsUpWithNoConfig() { |
| 170 | assertTrue(mConstants.isEnabled()); |
| 171 | assertTrue(mConstants.getShowInHeadsUp()); |
| 172 | } |
| 173 | |
| 174 | @Test |
| 175 | public void testShowInHeadsUpEnabled() { |
Gustav Sennton | 8fa7e95 | 2019-01-29 19:37:00 +0000 | [diff] [blame] | 176 | overrideSetting(SystemUiDeviceConfigFlags.SSIN_SHOW_IN_HEADS_UP, "true"); |
Gustav Sennton | 3f3eaff | 2019-01-08 09:39:51 +0000 | [diff] [blame] | 177 | triggerConstantsOnChange(); |
| 178 | assertTrue(mConstants.getShowInHeadsUp()); |
| 179 | } |
| 180 | |
| 181 | @Test |
| 182 | public void testShowInHeadsUpDisabled() { |
Gustav Sennton | 8fa7e95 | 2019-01-29 19:37:00 +0000 | [diff] [blame] | 183 | overrideSetting(SystemUiDeviceConfigFlags.SSIN_SHOW_IN_HEADS_UP, "false"); |
Gustav Sennton | 3f3eaff | 2019-01-08 09:39:51 +0000 | [diff] [blame] | 184 | triggerConstantsOnChange(); |
| 185 | assertFalse(mConstants.getShowInHeadsUp()); |
| 186 | } |
| 187 | |
Gustav Sennton | 4bf5ff5 | 2019-01-16 14:27:25 +0000 | [diff] [blame] | 188 | @Test |
Gustav Sennton | a31f6ae | 2019-01-08 11:20:49 +0000 | [diff] [blame] | 189 | public void testGetMinNumSystemGeneratedRepliesWithNoConfig() { |
| 190 | assertTrue(mConstants.isEnabled()); |
| 191 | assertEquals(2, mConstants.getMinNumSystemGeneratedReplies()); |
| 192 | } |
| 193 | |
| 194 | @Test |
| 195 | public void testGetMinNumSystemGeneratedRepliesWithValidConfig() { |
Gustav Sennton | 8fa7e95 | 2019-01-29 19:37:00 +0000 | [diff] [blame] | 196 | overrideSetting(SystemUiDeviceConfigFlags.SSIN_MIN_NUM_SYSTEM_GENERATED_REPLIES, "5"); |
Gustav Sennton | a31f6ae | 2019-01-08 11:20:49 +0000 | [diff] [blame] | 197 | triggerConstantsOnChange(); |
| 198 | assertEquals(5, mConstants.getMinNumSystemGeneratedReplies()); |
| 199 | } |
| 200 | |
Gustav Sennton | 8fa7e95 | 2019-01-29 19:37:00 +0000 | [diff] [blame] | 201 | @Test |
| 202 | public void testMaxNumActionsWithNoConfig() { |
| 203 | assertTrue(mConstants.isEnabled()); |
| 204 | assertEquals(-1, mConstants.getMaxNumActions()); |
| 205 | } |
| 206 | |
| 207 | @Test |
| 208 | public void testMaxNumActionsSet() { |
| 209 | overrideSetting(SystemUiDeviceConfigFlags.SSIN_MAX_NUM_ACTIONS, "10"); |
| 210 | triggerConstantsOnChange(); |
| 211 | assertEquals(10, mConstants.getMaxNumActions()); |
| 212 | } |
| 213 | |
| 214 | private void overrideSetting(String propertyName, String value) { |
| 215 | DeviceConfig.setProperty(DeviceConfig.NAMESPACE_SYSTEMUI, |
| 216 | propertyName, value, false /* makeDefault */); |
| 217 | } |
| 218 | |
Petr Cermak | 10011fa | 2018-02-05 19:00:54 +0000 | [diff] [blame] | 219 | private void triggerConstantsOnChange() { |
Gustav Sennton | 8fa7e95 | 2019-01-29 19:37:00 +0000 | [diff] [blame] | 220 | mConstants.onDeviceConfigPropertyChanged(DeviceConfig.NAMESPACE_SYSTEMUI, |
| 221 | "" /* name */, "" /* value */); |
| 222 | } |
| 223 | |
| 224 | private void resetAllDeviceConfigFlags() { |
| 225 | DeviceConfig.setProperty(DeviceConfig.NAMESPACE_SYSTEMUI, |
| 226 | SystemUiDeviceConfigFlags.SSIN_ENABLED, "", false /* makeDefault */); |
| 227 | DeviceConfig.setProperty(DeviceConfig.NAMESPACE_SYSTEMUI, |
| 228 | SystemUiDeviceConfigFlags.SSIN_REQUIRES_TARGETING_P, "", false /* makeDefault */); |
| 229 | DeviceConfig.setProperty(DeviceConfig.NAMESPACE_SYSTEMUI, |
| 230 | SystemUiDeviceConfigFlags.SSIN_MAX_SQUEEZE_REMEASURE_ATTEMPTS, "", |
| 231 | false /* makeDefault */); |
| 232 | DeviceConfig.setProperty(DeviceConfig.NAMESPACE_SYSTEMUI, |
| 233 | SystemUiDeviceConfigFlags.SSIN_EDIT_CHOICES_BEFORE_SENDING, "", |
| 234 | false /* makeDefault */); |
| 235 | DeviceConfig.setProperty(DeviceConfig.NAMESPACE_SYSTEMUI, |
| 236 | SystemUiDeviceConfigFlags.SSIN_SHOW_IN_HEADS_UP, "", false /* makeDefault */); |
| 237 | DeviceConfig.setProperty(DeviceConfig.NAMESPACE_SYSTEMUI, |
| 238 | SystemUiDeviceConfigFlags.SSIN_MIN_NUM_SYSTEM_GENERATED_REPLIES, "", |
| 239 | false /* makeDefault */); |
| 240 | DeviceConfig.setProperty(DeviceConfig.NAMESPACE_SYSTEMUI, |
| 241 | SystemUiDeviceConfigFlags.SSIN_MAX_NUM_ACTIONS, "", false /* makeDefault */); |
Petr Cermak | 10011fa | 2018-02-05 19:00:54 +0000 | [diff] [blame] | 242 | } |
| 243 | } |