blob: 31621afc87c3215315389392e7fd42220db0dac9 [file] [log] [blame]
Fan Zhangcdbe1d62016-11-22 15:47:05 -08001/*
2 * Copyright (C) 2016 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.settingslib.drawer;
18
Maurice Lamb10c6ff2017-06-08 20:29:21 -070019import static com.google.common.truth.Truth.assertThat;
Fan Zhangc75174b2018-07-19 14:07:58 -070020
Tony Mantler8d167372017-07-14 15:37:17 -070021import static org.mockito.ArgumentMatchers.any;
22import static org.mockito.ArgumentMatchers.anyInt;
23import static org.mockito.ArgumentMatchers.anyString;
24import static org.mockito.ArgumentMatchers.argThat;
Ajay Nadathurd1b730b2017-09-14 17:12:27 -070025import static org.mockito.ArgumentMatchers.eq;
Tony Mantler8d167372017-07-14 15:37:17 -070026import static org.mockito.ArgumentMatchers.isNull;
Maurice Lamb10c6ff2017-06-08 20:29:21 -070027import static org.mockito.Mockito.atLeastOnce;
28import static org.mockito.Mockito.spy;
29import static org.mockito.Mockito.verify;
30import static org.mockito.Mockito.when;
31import static org.robolectric.RuntimeEnvironment.application;
32
Maurice Lamf74b9e52017-03-23 14:58:47 -070033import android.app.ActivityManager;
Shahriyar Amini676add42016-12-16 11:29:39 -080034import android.content.ContentResolver;
Fan Zhangcdbe1d62016-11-22 15:47:05 -080035import android.content.Context;
Maurice Lamf74b9e52017-03-23 14:58:47 -070036import android.content.IContentProvider;
Fan Zhangcdbe1d62016-11-22 15:47:05 -080037import android.content.Intent;
38import android.content.pm.ActivityInfo;
39import android.content.pm.ApplicationInfo;
40import android.content.pm.PackageManager;
Shahriyar Amini6b32ae32016-11-22 14:49:04 -080041import android.content.pm.PackageManager.NameNotFoundException;
Fan Zhangcdbe1d62016-11-22 15:47:05 -080042import android.content.pm.ResolveInfo;
Shahriyar Amini6b32ae32016-11-22 14:49:04 -080043import android.content.res.Resources;
Shahriyar Amini676add42016-12-16 11:29:39 -080044import android.net.Uri;
Fan Zhangcdbe1d62016-11-22 15:47:05 -080045import android.os.Bundle;
Shahriyar Amini676add42016-12-16 11:29:39 -080046import android.os.RemoteException;
Fan Zhangcdbe1d62016-11-22 15:47:05 -080047import android.os.UserHandle;
Doris Ling485df112016-12-19 10:45:47 -080048import android.os.UserManager;
49import android.provider.Settings.Global;
Ido Ofira560cd92017-01-24 13:27:36 -080050import android.text.TextUtils;
Fan Zhangcdbe1d62016-11-22 15:47:05 -080051import android.util.ArrayMap;
52import android.util.Pair;
Jaewoong Jung78c5e5d2017-06-15 18:02:44 -070053import android.widget.RemoteViews;
Fan Zhangcdbe1d62016-11-22 15:47:05 -080054
Fan Zhangc75174b2018-07-19 14:07:58 -070055import com.android.settingslib.SettingsLibRobolectricTestRunner;
56
Fan Zhangcdbe1d62016-11-22 15:47:05 -080057import org.junit.Before;
58import org.junit.Test;
59import org.junit.runner.RunWith;
Maurice Lamf74b9e52017-03-23 14:58:47 -070060import org.mockito.ArgumentCaptor;
Fan Zhangcdbe1d62016-11-22 15:47:05 -080061import org.mockito.Mock;
62import org.mockito.MockitoAnnotations;
Fan Zhangcdbe1d62016-11-22 15:47:05 -080063import org.robolectric.annotation.Config;
Ajay Nadathurd1b730b2017-09-14 17:12:27 -070064import org.robolectric.annotation.Implementation;
65import org.robolectric.annotation.Implements;
Fan Zhangcdbe1d62016-11-22 15:47:05 -080066
67import java.util.ArrayList;
68import java.util.List;
69import java.util.Map;
70
Fan Zhangc75174b2018-07-19 14:07:58 -070071@RunWith(SettingsLibRobolectricTestRunner.class)
James Lemieux5c50dc12018-02-12 01:30:32 -080072@Config(shadows = TileUtilsTest.TileUtilsShadowRemoteViews.class)
Fan Zhangcdbe1d62016-11-22 15:47:05 -080073public class TileUtilsTest {
74
Fan Zhangcdbe1d62016-11-22 15:47:05 -080075 private Context mContext;
76 @Mock
77 private PackageManager mPackageManager;
Shahriyar Amini6b32ae32016-11-22 14:49:04 -080078 @Mock
79 private Resources mResources;
Doris Ling485df112016-12-19 10:45:47 -080080 @Mock
81 private UserManager mUserManager;
Shahriyar Amini676add42016-12-16 11:29:39 -080082 @Mock
83 private IContentProvider mIContentProvider;
84 @Mock
85 private ContentResolver mContentResolver;
86
87 private static final String URI_GET_SUMMARY = "content://authority/text/summary";
88 private static final String URI_GET_ICON = "content://authority/icon/my_icon";
Fan Zhangcdbe1d62016-11-22 15:47:05 -080089
90 @Before
Shahriyar Amini6b32ae32016-11-22 14:49:04 -080091 public void setUp() throws NameNotFoundException {
Tony Mantlerf6631bf2017-10-10 11:09:08 -070092 mContext = spy(application);
Fan Zhangcdbe1d62016-11-22 15:47:05 -080093 MockitoAnnotations.initMocks(this);
94 when(mContext.getPackageManager()).thenReturn(mPackageManager);
Shahriyar Amini6b32ae32016-11-22 14:49:04 -080095 when(mPackageManager.getResourcesForApplication(anyString())).thenReturn(mResources);
Tony Mantler8d167372017-07-14 15:37:17 -070096 when(mPackageManager.getResourcesForApplication((String) isNull())).thenReturn(mResources);
Maurice Lamb10c6ff2017-06-08 20:29:21 -070097 when(mPackageManager.getApplicationInfo(eq("abc"), anyInt()))
98 .thenReturn(application.getApplicationInfo());
99 mContentResolver = spy(application.getContentResolver());
Shahriyar Amini676add42016-12-16 11:29:39 -0800100 when(mContext.getContentResolver()).thenReturn(mContentResolver);
Maurice Lamb10c6ff2017-06-08 20:29:21 -0700101 when(mContext.getPackageName()).thenReturn("com.android.settings");
Fan Zhangcdbe1d62016-11-22 15:47:05 -0800102 }
103
104 @Test
105 public void getTilesForIntent_shouldParseCategory() {
106 final String testCategory = "category1";
107 Intent intent = new Intent();
108 Map<Pair<String, String>, Tile> addedCache = new ArrayMap<>();
109 List<Tile> outTiles = new ArrayList<>();
110 List<ResolveInfo> info = new ArrayList<>();
111 info.add(newInfo(true, testCategory));
Fan Zhangcdbe1d62016-11-22 15:47:05 -0800112 when(mPackageManager.queryIntentActivitiesAsUser(eq(intent), anyInt(), anyInt()))
113 .thenReturn(info);
114
115 TileUtils.getTilesForIntent(mContext, UserHandle.CURRENT, intent, addedCache,
116 null /* defaultCategory */, outTiles, false /* usePriority */,
Maurice Lamb10c6ff2017-06-08 20:29:21 -0700117 false /* checkCategory */, true /* forceTintExternalIcon */);
Fan Zhangcdbe1d62016-11-22 15:47:05 -0800118
119 assertThat(outTiles.size()).isEqualTo(1);
120 assertThat(outTiles.get(0).category).isEqualTo(testCategory);
121 }
122
123 @Test
Shahriyar Amini6b32ae32016-11-22 14:49:04 -0800124 public void getTilesForIntent_shouldParseKeyHintForSystemApp() {
125 String keyHint = "key";
126 Intent intent = new Intent();
127 Map<Pair<String, String>, Tile> addedCache = new ArrayMap<>();
128 List<Tile> outTiles = new ArrayList<>();
129 List<ResolveInfo> info = new ArrayList<>();
130 ResolveInfo resolveInfo = newInfo(true, null /* category */, keyHint);
131 info.add(resolveInfo);
132
133 when(mPackageManager.queryIntentActivitiesAsUser(eq(intent), anyInt(), anyInt()))
134 .thenReturn(info);
135
136 TileUtils.getTilesForIntent(mContext, UserHandle.CURRENT, intent, addedCache,
137 null /* defaultCategory */, outTiles, false /* usePriority */,
Maurice Lamb10c6ff2017-06-08 20:29:21 -0700138 false /* checkCategory */, true /* forceTintExternalIcon */);
Shahriyar Amini6b32ae32016-11-22 14:49:04 -0800139
140 assertThat(outTiles.size()).isEqualTo(1);
141 assertThat(outTiles.get(0).key).isEqualTo(keyHint);
142 }
143
144 @Test
Fan Zhangcdbe1d62016-11-22 15:47:05 -0800145 public void getTilesForIntent_shouldSkipNonSystemApp() {
146 final String testCategory = "category1";
147 Intent intent = new Intent();
148 Map<Pair<String, String>, Tile> addedCache = new ArrayMap<>();
149 List<Tile> outTiles = new ArrayList<>();
150 List<ResolveInfo> info = new ArrayList<>();
151 info.add(newInfo(false, testCategory));
152
153 when(mPackageManager.queryIntentActivitiesAsUser(eq(intent), anyInt(), anyInt()))
154 .thenReturn(info);
155
156 TileUtils.getTilesForIntent(mContext, UserHandle.CURRENT, intent, addedCache,
157 null /* defaultCategory */, outTiles, false /* usePriority */,
Maurice Lamb10c6ff2017-06-08 20:29:21 -0700158 false /* checkCategory */, true /* forceTintExternalIcon */);
Fan Zhangcdbe1d62016-11-22 15:47:05 -0800159
160 assertThat(outTiles.isEmpty()).isTrue();
161 }
162
Doris Ling485df112016-12-19 10:45:47 -0800163 @Test
164 public void getCategories_shouldHandleExtraIntentAction() {
165 final String testCategory = "category1";
166 final String testAction = "action1";
167 Map<Pair<String, String>, Tile> cache = new ArrayMap<>();
168 List<ResolveInfo> info = new ArrayList<>();
169 info.add(newInfo(true, testCategory));
170 Global.putInt(mContext.getContentResolver(), Global.DEVICE_PROVISIONED, 1);
171 when(mContext.getSystemService(Context.USER_SERVICE)).thenReturn(mUserManager);
172 List<UserHandle> userHandleList = new ArrayList<>();
173 userHandleList.add(UserHandle.CURRENT);
174 when(mUserManager.getUserProfiles()).thenReturn(userHandleList);
175
Tony Mantler8d167372017-07-14 15:37:17 -0700176 when(mPackageManager.queryIntentActivitiesAsUser(argThat(
177 event -> testAction.equals(event.getAction())), anyInt(), anyInt()))
178 .thenReturn(info);
Doris Ling485df112016-12-19 10:45:47 -0800179
180 List<DashboardCategory> categoryList = TileUtils.getCategories(
Fan Zhang1b0dfa32018-07-20 12:57:55 -0700181 mContext, cache, testAction, CategoryManager.SETTING_PKG);
Doris Lingb8d2cd42017-11-27 12:24:09 -0800182 assertThat(categoryList.get(0).getTile(0).category).isEqualTo(testCategory);
Doris Ling485df112016-12-19 10:45:47 -0800183 }
Shahriyar Amini6b32ae32016-11-22 14:49:04 -0800184
Shahriyar Amini676add42016-12-16 11:29:39 -0800185 @Test
Fan Zhangc75174b2018-07-19 14:07:58 -0700186 public void getCategories_withPackageName() {
roger xue8f06ab02016-12-08 14:09:50 -0800187 ArgumentCaptor<Intent> intentCaptor = ArgumentCaptor.forClass(Intent.class);
188 Map<Pair<String, String>, Tile> cache = new ArrayMap<>();
189 Global.putInt(mContext.getContentResolver(), Global.DEVICE_PROVISIONED, 1);
190 when(mContext.getSystemService(Context.USER_SERVICE)).thenReturn(mUserManager);
191 List<UserHandle> userHandleList = new ArrayList<>();
192
193 userHandleList.add(new UserHandle(ActivityManager.getCurrentUser()));
194 when(mUserManager.getUserProfiles()).thenReturn(userHandleList);
195
Fan Zhang1b0dfa32018-07-20 12:57:55 -0700196 TileUtils.getCategories(mContext, cache, null /* action */, CategoryManager.SETTING_PKG);
roger xue8f06ab02016-12-08 14:09:50 -0800197 verify(mPackageManager, atLeastOnce()).queryIntentActivitiesAsUser(
Fan Zhange138ef12017-05-11 15:29:56 -0700198 intentCaptor.capture(), anyInt(), anyInt());
roger xue8f06ab02016-12-08 14:09:50 -0800199
200 assertThat(intentCaptor.getAllValues().get(0).getPackage())
Fan Zhang1b0dfa32018-07-20 12:57:55 -0700201 .isEqualTo(CategoryManager.SETTING_PKG);
roger xue8f06ab02016-12-08 14:09:50 -0800202 }
203
204 @Test
Fan Zhangc75174b2018-07-19 14:07:58 -0700205 public void getTilesForIntent_shouldReadMetadataTitleAsString() {
William Luh4c978a32017-03-31 15:08:16 -0700206 Intent intent = new Intent();
207 Map<Pair<String, String>, Tile> addedCache = new ArrayMap<>();
208 List<Tile> outTiles = new ArrayList<>();
209 List<ResolveInfo> info = new ArrayList<>();
210 ResolveInfo resolveInfo = newInfo(true, null /* category */, null, URI_GET_ICON,
211 URI_GET_SUMMARY, "my title", 0);
212 info.add(resolveInfo);
213
214 when(mPackageManager.queryIntentActivitiesAsUser(eq(intent), anyInt(), anyInt()))
215 .thenReturn(info);
216
217 TileUtils.getTilesForIntent(mContext, UserHandle.CURRENT, intent, addedCache,
218 null /* defaultCategory */, outTiles, false /* usePriority */,
Maurice Lamb10c6ff2017-06-08 20:29:21 -0700219 false /* checkCategory */, true /* forceTintExternalIcon */);
William Luh4c978a32017-03-31 15:08:16 -0700220
221 assertThat(outTiles.size()).isEqualTo(1);
222 assertThat(outTiles.get(0).title).isEqualTo("my title");
223 }
224
225 @Test
Fan Zhangc75174b2018-07-19 14:07:58 -0700226 public void getTilesForIntent_shouldReadMetadataTitleFromResource() {
William Luh4c978a32017-03-31 15:08:16 -0700227 Intent intent = new Intent();
228 Map<Pair<String, String>, Tile> addedCache = new ArrayMap<>();
229 List<Tile> outTiles = new ArrayList<>();
230 List<ResolveInfo> info = new ArrayList<>();
231 ResolveInfo resolveInfo = newInfo(true, null /* category */, null, URI_GET_ICON,
232 URI_GET_SUMMARY, null, 123);
233 info.add(resolveInfo);
234
235 when(mPackageManager.queryIntentActivitiesAsUser(eq(intent), anyInt(), anyInt()))
236 .thenReturn(info);
237
238 when(mResources.getString(eq(123)))
239 .thenReturn("my localized title");
240
241 TileUtils.getTilesForIntent(mContext, UserHandle.CURRENT, intent, addedCache,
242 null /* defaultCategory */, outTiles, false /* usePriority */,
Maurice Lamb10c6ff2017-06-08 20:29:21 -0700243 false /* checkCategory */, true /* forceTintExternalIcon */);
William Luh4c978a32017-03-31 15:08:16 -0700244
245 assertThat(outTiles.size()).isEqualTo(1);
246 assertThat(outTiles.get(0).title).isEqualTo("my localized title");
Maurice Lamb10c6ff2017-06-08 20:29:21 -0700247
248 // Icon should be tintable because the tile is not from settings package, and
249 // "forceTintExternalIcon" is set
250 assertThat(outTiles.get(0).isIconTintable).isTrue();
251 }
252
253 @Test
254 public void getTilesForIntent_shouldNotTintIconIfInSettingsPackage() {
255 Intent intent = new Intent();
256 Map<Pair<String, String>, Tile> addedCache = new ArrayMap<>();
257 List<Tile> outTiles = new ArrayList<>();
258 List<ResolveInfo> info = new ArrayList<>();
259 ResolveInfo resolveInfo = newInfo(true, null /* category */, null, URI_GET_ICON,
260 URI_GET_SUMMARY, null, 123);
261 resolveInfo.activityInfo.packageName = "com.android.settings";
262 resolveInfo.activityInfo.applicationInfo.packageName = "com.android.settings";
263 info.add(resolveInfo);
264
265 when(mPackageManager.queryIntentActivitiesAsUser(eq(intent), anyInt(), anyInt()))
266 .thenReturn(info);
267
268 TileUtils.getTilesForIntent(mContext, UserHandle.CURRENT, intent, addedCache,
269 null /* defaultCategory */, outTiles, false /* usePriority */,
270 false /* checkCategory */, true /* forceTintExternalIcon */);
271
272 assertThat(outTiles.size()).isEqualTo(1);
273 assertThat(outTiles.get(0).isIconTintable).isFalse();
274 }
275
276 @Test
277 public void getTilesForIntent_shouldMarkIconTintableIfMetadataSet() {
278 Intent intent = new Intent();
279 Map<Pair<String, String>, Tile> addedCache = new ArrayMap<>();
280 List<Tile> outTiles = new ArrayList<>();
281 List<ResolveInfo> info = new ArrayList<>();
282 ResolveInfo resolveInfo = newInfo(true, null /* category */, null, URI_GET_ICON,
283 URI_GET_SUMMARY, null, 123);
284 resolveInfo.activityInfo.metaData
285 .putBoolean(TileUtils.META_DATA_PREFERENCE_ICON_TINTABLE, true);
286 info.add(resolveInfo);
287
288 when(mPackageManager.queryIntentActivitiesAsUser(eq(intent), anyInt(), anyInt()))
289 .thenReturn(info);
290
291 TileUtils.getTilesForIntent(mContext, UserHandle.CURRENT, intent, addedCache,
292 null /* defaultCategory */, outTiles, false /* usePriority */,
293 false /* checkCategory */, false /* forceTintExternalIcon */);
294
295 assertThat(outTiles.size()).isEqualTo(1);
296 assertThat(outTiles.get(0).isIconTintable).isTrue();
William Luh4c978a32017-03-31 15:08:16 -0700297 }
298
299 @Test
Shahriyar Amini676add42016-12-16 11:29:39 -0800300 public void getTilesForIntent_shouldNotProcessInvalidUriContentSystemApp()
301 throws RemoteException {
302 Intent intent = new Intent();
303 Map<Pair<String, String>, Tile> addedCache = new ArrayMap<>();
304 List<Tile> outTiles = new ArrayList<>();
305 List<ResolveInfo> info = new ArrayList<>();
306 ResolveInfo resolveInfo = newInfo(true, null /* category */, null, null, URI_GET_SUMMARY);
307 info.add(resolveInfo);
308
309 when(mPackageManager.queryIntentActivitiesAsUser(eq(intent), anyInt(), anyInt()))
310 .thenReturn(info);
311
312 // Case 1: No provider associated with the uri specified.
313 TileUtils.getTilesForIntent(mContext, UserHandle.CURRENT, intent, addedCache,
314 null /* defaultCategory */, outTiles, false /* usePriority */,
Maurice Lamb10c6ff2017-06-08 20:29:21 -0700315 false /* checkCategory */, true /* forceTintExternalIcon */);
Shahriyar Amini676add42016-12-16 11:29:39 -0800316
317 assertThat(outTiles.size()).isEqualTo(1);
318 assertThat(outTiles.get(0).icon.getResId()).isEqualTo(314159);
319 assertThat(outTiles.get(0).summary).isEqualTo("static-summary");
320
321 // Case 2: Empty bundle.
322 Bundle bundle = new Bundle();
323 when(mIContentProvider.call(anyString(),
324 eq(TileUtils.getMethodFromUri(Uri.parse(URI_GET_SUMMARY))), eq(URI_GET_SUMMARY),
325 any())).thenReturn(bundle);
William Luh5a0a0d82017-04-18 11:34:38 -0700326 when(mContentResolver.acquireUnstableProvider(anyString()))
327 .thenReturn(mIContentProvider);
328 when(mContentResolver.acquireUnstableProvider(any(Uri.class)))
329 .thenReturn(mIContentProvider);
Shahriyar Amini676add42016-12-16 11:29:39 -0800330
331 TileUtils.getTilesForIntent(mContext, UserHandle.CURRENT, intent, addedCache,
332 null /* defaultCategory */, outTiles, false /* usePriority */,
Maurice Lamb10c6ff2017-06-08 20:29:21 -0700333 false /* checkCategory */, true /* forceTintExternalIcon */);
Shahriyar Amini676add42016-12-16 11:29:39 -0800334
335 assertThat(outTiles.size()).isEqualTo(1);
336 assertThat(outTiles.get(0).icon.getResId()).isEqualTo(314159);
337 assertThat(outTiles.get(0).summary).isEqualTo("static-summary");
338 }
339
340 @Test
Fan Zhangc75174b2018-07-19 14:07:58 -0700341 public void getTilesForIntent_shouldProcessUriContentForSystemApp() {
Shahriyar Amini676add42016-12-16 11:29:39 -0800342 Intent intent = new Intent();
343 Map<Pair<String, String>, Tile> addedCache = new ArrayMap<>();
344 List<Tile> outTiles = new ArrayList<>();
345 List<ResolveInfo> info = new ArrayList<>();
346 ResolveInfo resolveInfo = newInfo(true, null /* category */, null, URI_GET_ICON,
347 URI_GET_SUMMARY);
348 info.add(resolveInfo);
349
350 when(mPackageManager.queryIntentActivitiesAsUser(eq(intent), anyInt(), anyInt()))
351 .thenReturn(info);
352
Shahriyar Amini676add42016-12-16 11:29:39 -0800353 TileUtils.getTilesForIntent(mContext, UserHandle.CURRENT, intent, addedCache,
354 null /* defaultCategory */, outTiles, false /* usePriority */,
Maurice Lamb10c6ff2017-06-08 20:29:21 -0700355 false /* checkCategory */, true /* forceTintExternalIcon */);
Shahriyar Amini676add42016-12-16 11:29:39 -0800356
357 assertThat(outTiles.size()).isEqualTo(1);
Shahriyar Amini676add42016-12-16 11:29:39 -0800358 }
359
Soroosh Mariooryad56ce7662017-02-06 15:23:00 -0800360 public static ResolveInfo newInfo(boolean systemApp, String category) {
Shahriyar Amini6b32ae32016-11-22 14:49:04 -0800361 return newInfo(systemApp, category, null);
362 }
363
Soroosh Mariooryad56ce7662017-02-06 15:23:00 -0800364 private static ResolveInfo newInfo(boolean systemApp, String category, String keyHint) {
Shahriyar Amini676add42016-12-16 11:29:39 -0800365 return newInfo(systemApp, category, keyHint, null, null);
366 }
367
Soroosh Mariooryad56ce7662017-02-06 15:23:00 -0800368 private static ResolveInfo newInfo(boolean systemApp, String category, String keyHint,
William Luh4c978a32017-03-31 15:08:16 -0700369 String iconUri, String summaryUri) {
370 return newInfo(systemApp, category, keyHint, iconUri, summaryUri, null, 0);
371 }
372
373 private static ResolveInfo newInfo(boolean systemApp, String category, String keyHint,
374 String iconUri, String summaryUri, String title, int titleResId) {
375
Fan Zhangcdbe1d62016-11-22 15:47:05 -0800376 ResolveInfo info = new ResolveInfo();
377 info.system = systemApp;
378 info.activityInfo = new ActivityInfo();
379 info.activityInfo.packageName = "abc";
380 info.activityInfo.name = "123";
381 info.activityInfo.metaData = new Bundle();
382 info.activityInfo.metaData.putString("com.android.settings.category", category);
Shahriyar Amini676add42016-12-16 11:29:39 -0800383 info.activityInfo.metaData.putInt("com.android.settings.icon", 314159);
384 info.activityInfo.metaData.putString("com.android.settings.summary", "static-summary");
Shahriyar Amini6b32ae32016-11-22 14:49:04 -0800385 if (keyHint != null) {
386 info.activityInfo.metaData.putString("com.android.settings.keyhint", keyHint);
387 }
Shahriyar Amini676add42016-12-16 11:29:39 -0800388 if (iconUri != null) {
389 info.activityInfo.metaData.putString("com.android.settings.icon_uri", iconUri);
390 }
391 if (summaryUri != null) {
392 info.activityInfo.metaData.putString("com.android.settings.summary_uri", summaryUri);
393 }
Maurice Lamb10c6ff2017-06-08 20:29:21 -0700394 if (titleResId != 0) {
Fan Zhangdadfd502017-07-26 11:00:51 -0700395 info.activityInfo.metaData.putInt(TileUtils.META_DATA_PREFERENCE_TITLE, titleResId);
Maurice Lamb10c6ff2017-06-08 20:29:21 -0700396 } else if (title != null) {
William Luh4c978a32017-03-31 15:08:16 -0700397 info.activityInfo.metaData.putString(TileUtils.META_DATA_PREFERENCE_TITLE, title);
398 }
Fan Zhangcdbe1d62016-11-22 15:47:05 -0800399 info.activityInfo.applicationInfo = new ApplicationInfo();
Shahriyar Amini6b32ae32016-11-22 14:49:04 -0800400 if (systemApp) {
401 info.activityInfo.applicationInfo.flags |= ApplicationInfo.FLAG_SYSTEM;
402 }
Fan Zhangcdbe1d62016-11-22 15:47:05 -0800403 return info;
404 }
Ido Ofira560cd92017-01-24 13:27:36 -0800405
406 private void addMetadataToInfo(ResolveInfo info, String key, String value) {
407 if (!TextUtils.isEmpty(key)) {
408 if (info.activityInfo == null) {
409 info.activityInfo = new ActivityInfo();
410 }
411 if (info.activityInfo.metaData == null) {
412 info.activityInfo.metaData = new Bundle();
413 }
414 info.activityInfo.metaData.putString(key, value);
415 }
416 }
Jaewoong Jung78c5e5d2017-06-15 18:02:44 -0700417
Ajay Nadathurd1b730b2017-09-14 17:12:27 -0700418 @Implements(RemoteViews.class)
419 public static class TileUtilsShadowRemoteViews {
420
421 private Integer overrideViewId;
422 private CharSequence overrideText;
423
424 @Implementation
425 public void setTextViewText(int viewId, CharSequence text) {
426 overrideViewId = viewId;
427 overrideText = text;
428 }
429 }
Fan Zhangcdbe1d62016-11-22 15:47:05 -0800430}