blob: cd9069aa12331efdcedba59ed28b83e0ecd6b4f6 [file] [log] [blame]
Petr Cermak10011fa2018-02-05 19:00:54 +00001/*
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
17package com.android.systemui.statusbar.policy;
18
19import static junit.framework.Assert.assertEquals;
20import static junit.framework.Assert.assertFalse;
21import static junit.framework.Assert.assertTrue;
22
Milo Sredkov41dc4ba2018-12-27 12:03:45 +000023import android.app.RemoteInput;
Petr Cermak10011fa2018-02-05 19:00:54 +000024import android.os.Handler;
25import android.os.Looper;
Gustav Sennton8fa7e952019-01-29 19:37:00 +000026import android.provider.DeviceConfig;
Petr Cermak10011fa2018-02-05 19:00:54 +000027import android.test.suitebuilder.annotation.SmallTest;
28import android.testing.AndroidTestingRunner;
29import android.testing.TestableLooper;
30import android.testing.TestableResources;
31
Gustav Sennton8fa7e952019-01-29 19:37:00 +000032import com.android.internal.config.sysui.SystemUiDeviceConfigFlags;
Petr Cermak10011fa2018-02-05 19:00:54 +000033import com.android.systemui.R;
34import com.android.systemui.SysuiTestCase;
35
Gustav Sennton8fa7e952019-01-29 19:37:00 +000036import org.junit.After;
Petr Cermak10011fa2018-02-05 19:00:54 +000037import org.junit.Before;
38import org.junit.Test;
39import org.junit.runner.RunWith;
40
41@RunWith(AndroidTestingRunner.class)
42@TestableLooper.RunWithLooper
43@SmallTest
44public 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 Sennton8fa7e952019-01-29 19:37:00 +000052 resetAllDeviceConfigFlags();
Petr Cermak10011fa2018-02-05 19:00:54 +000053 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 Sredkov41dc4ba2018-12-27 12:03:45 +000057 resources.addOverride(
58 R.bool.config_smart_replies_in_notifications_edit_choices_before_sending, false);
Gustav Sennton3f3eaff2019-01-08 09:39:51 +000059 resources.addOverride(R.bool.config_smart_replies_in_notifications_show_in_heads_up, true);
Gustav Senntona31f6ae2019-01-08 11:20:49 +000060 resources.addOverride(
61 R.integer.config_smart_replies_in_notifications_min_num_system_generated_replies,
62 2);
Gustav Sennton8fa7e952019-01-29 19:37:00 +000063 resources.addOverride(
64 R.integer.config_smart_replies_in_notifications_max_num_actions, -1);
Jason Monk6dceace2018-05-15 20:24:07 -040065 mConstants = new SmartReplyConstants(Handler.createAsync(Looper.myLooper()), mContext);
Petr Cermak10011fa2018-02-05 19:00:54 +000066 }
67
Gustav Sennton8fa7e952019-01-29 19:37:00 +000068 @After
69 public void tearDown() {
70 resetAllDeviceConfigFlags();
71 }
72
Petr Cermak10011fa2018-02-05 19:00:54 +000073 @Test
74 public void testIsEnabledWithNoConfig() {
75 assertTrue(mConstants.isEnabled());
76 }
77
78 @Test
79 public void testIsEnabledWithInvalidConfig() {
Gustav Sennton8fa7e952019-01-29 19:37:00 +000080 overrideSetting(SystemUiDeviceConfigFlags.SSIN_ENABLED, "invalid config");
Petr Cermak10011fa2018-02-05 19:00:54 +000081 triggerConstantsOnChange();
82 assertTrue(mConstants.isEnabled());
83 }
84
85 @Test
86 public void testIsEnabledWithValidConfig() {
Gustav Sennton8fa7e952019-01-29 19:37:00 +000087 overrideSetting(SystemUiDeviceConfigFlags.SSIN_ENABLED, "false");
Petr Cermak10011fa2018-02-05 19:00:54 +000088 triggerConstantsOnChange();
89 assertFalse(mConstants.isEnabled());
90 }
91
92 @Test
Richard Ledley4069f7a2018-02-26 10:36:00 +000093 public void testRequiresTargetingPConfig() {
Gustav Sennton8fa7e952019-01-29 19:37:00 +000094 overrideSetting(SystemUiDeviceConfigFlags.SSIN_REQUIRES_TARGETING_P, "false");
Richard Ledley4069f7a2018-02-26 10:36:00 +000095 triggerConstantsOnChange();
96 assertEquals(false, mConstants.requiresTargetingP());
97
Gustav Sennton8fa7e952019-01-29 19:37:00 +000098 overrideSetting(SystemUiDeviceConfigFlags.SSIN_REQUIRES_TARGETING_P, "");
Richard Ledley4069f7a2018-02-26 10:36:00 +000099 triggerConstantsOnChange();
100 assertEquals(true, mConstants.requiresTargetingP());
101 }
102
103 @Test
Petr Cermak10011fa2018-02-05 19:00:54 +0000104 public void testGetMaxSqueezeRemeasureAttemptsWithNoConfig() {
105 assertTrue(mConstants.isEnabled());
106 assertEquals(7, mConstants.getMaxSqueezeRemeasureAttempts());
107 }
108
109 @Test
110 public void testGetMaxSqueezeRemeasureAttemptsWithInvalidConfig() {
Gustav Sennton8fa7e952019-01-29 19:37:00 +0000111 overrideSetting(SystemUiDeviceConfigFlags.SSIN_MAX_SQUEEZE_REMEASURE_ATTEMPTS,
112 "invalid config");
Petr Cermak10011fa2018-02-05 19:00:54 +0000113 triggerConstantsOnChange();
114 assertEquals(7, mConstants.getMaxSqueezeRemeasureAttempts());
115 }
116
117 @Test
118 public void testGetMaxSqueezeRemeasureAttemptsWithValidConfig() {
Gustav Sennton8fa7e952019-01-29 19:37:00 +0000119 overrideSetting(SystemUiDeviceConfigFlags.SSIN_MAX_SQUEEZE_REMEASURE_ATTEMPTS, "5");
Petr Cermak10011fa2018-02-05 19:00:54 +0000120 triggerConstantsOnChange();
121 assertEquals(5, mConstants.getMaxSqueezeRemeasureAttempts());
122 }
123
Milo Sredkov41dc4ba2018-12-27 12:03:45 +0000124 @Test
125 public void testGetEffectiveEditChoicesBeforeSendingWithNoConfig() {
Milo Sredkov41dc4ba2018-12-27 12:03:45 +0000126 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 Sennton8fa7e952019-01-29 19:37:00 +0000140 overrideSetting(SystemUiDeviceConfigFlags.SSIN_EDIT_CHOICES_BEFORE_SENDING, "true");
Milo Sredkov41dc4ba2018-12-27 12:03:45 +0000141 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 Sennton8fa7e952019-01-29 19:37:00 +0000155 overrideSetting(SystemUiDeviceConfigFlags.SSIN_EDIT_CHOICES_BEFORE_SENDING, "false");
Milo Sredkov41dc4ba2018-12-27 12:03:45 +0000156 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 Sennton3f3eaff2019-01-08 09:39:51 +0000168 @Test
169 public void testShowInHeadsUpWithNoConfig() {
170 assertTrue(mConstants.isEnabled());
171 assertTrue(mConstants.getShowInHeadsUp());
172 }
173
174 @Test
175 public void testShowInHeadsUpEnabled() {
Gustav Sennton8fa7e952019-01-29 19:37:00 +0000176 overrideSetting(SystemUiDeviceConfigFlags.SSIN_SHOW_IN_HEADS_UP, "true");
Gustav Sennton3f3eaff2019-01-08 09:39:51 +0000177 triggerConstantsOnChange();
178 assertTrue(mConstants.getShowInHeadsUp());
179 }
180
181 @Test
182 public void testShowInHeadsUpDisabled() {
Gustav Sennton8fa7e952019-01-29 19:37:00 +0000183 overrideSetting(SystemUiDeviceConfigFlags.SSIN_SHOW_IN_HEADS_UP, "false");
Gustav Sennton3f3eaff2019-01-08 09:39:51 +0000184 triggerConstantsOnChange();
185 assertFalse(mConstants.getShowInHeadsUp());
186 }
187
Gustav Sennton4bf5ff52019-01-16 14:27:25 +0000188 @Test
Gustav Senntona31f6ae2019-01-08 11:20:49 +0000189 public void testGetMinNumSystemGeneratedRepliesWithNoConfig() {
190 assertTrue(mConstants.isEnabled());
191 assertEquals(2, mConstants.getMinNumSystemGeneratedReplies());
192 }
193
194 @Test
195 public void testGetMinNumSystemGeneratedRepliesWithValidConfig() {
Gustav Sennton8fa7e952019-01-29 19:37:00 +0000196 overrideSetting(SystemUiDeviceConfigFlags.SSIN_MIN_NUM_SYSTEM_GENERATED_REPLIES, "5");
Gustav Senntona31f6ae2019-01-08 11:20:49 +0000197 triggerConstantsOnChange();
198 assertEquals(5, mConstants.getMinNumSystemGeneratedReplies());
199 }
200
Gustav Sennton8fa7e952019-01-29 19:37:00 +0000201 @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 Cermak10011fa2018-02-05 19:00:54 +0000219 private void triggerConstantsOnChange() {
Gustav Sennton8fa7e952019-01-29 19:37:00 +0000220 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 Cermak10011fa2018-02-05 19:00:54 +0000242 }
243}