blob: 7f06f2cb7aebe9d200b23d40b2d95bb1bdbccbc6 [file] [log] [blame]
Lucas Dupin7517b5d2017-08-22 12:51:25 -07001/*
2 * Copyright (C) 2017 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 android.app;
18
19import static org.junit.Assert.assertEquals;
20import static org.junit.Assert.assertTrue;
21
22import android.content.Context;
23import android.content.Intent;
24import android.content.pm.PackageManager;
25import android.content.pm.ResolveInfo;
Weien Wang4710c042018-10-05 19:46:41 +080026import android.net.Uri;
Lucas Dupin7517b5d2017-08-22 12:51:25 -070027import android.os.Parcel;
28import android.service.wallpaper.WallpaperService;
29import android.support.test.InstrumentationRegistry;
30import android.support.test.filters.SmallTest;
31import android.support.test.runner.AndroidJUnit4;
32
33import org.junit.Test;
34import org.junit.runner.RunWith;
35
36import java.util.List;
37
38/**
39 * Tests for hidden WallpaperInfo methods.
40 */
41@RunWith(AndroidJUnit4.class)
42@SmallTest
43public class WallpaperInfoTest {
44
45 @Test
46 public void testSupportsAmbientMode() throws Exception {
47 Context context = InstrumentationRegistry.getTargetContext();
48
49 Intent intent = new Intent(WallpaperService.SERVICE_INTERFACE);
50 intent.setPackage("com.android.internal.tests");
51 PackageManager pm = context.getPackageManager();
52 List<ResolveInfo> result = pm.queryIntentServices(intent, PackageManager.GET_META_DATA);
53 assertEquals(1, result.size());
54 ResolveInfo info = result.get(0);
55 WallpaperInfo wallpaperInfo = new WallpaperInfo(context, info);
56
57 // Defined as true in the XML
58 assertTrue("supportsAmbientMode should be true, as defined in the XML.",
Lucas Dupin8f09a502018-07-27 16:47:45 +080059 wallpaperInfo.supportsAmbientMode());
Lucas Dupin7517b5d2017-08-22 12:51:25 -070060 Parcel parcel = Parcel.obtain();
61 wallpaperInfo.writeToParcel(parcel, 0 /* flags */);
62 parcel.setDataPosition(0);
63 WallpaperInfo fromParcel = WallpaperInfo.CREATOR.createFromParcel(parcel);
64 assertTrue("supportsAmbientMode should have been restored from parcelable",
Lucas Dupin8f09a502018-07-27 16:47:45 +080065 fromParcel.supportsAmbientMode());
Lucas Dupin7517b5d2017-08-22 12:51:25 -070066 parcel.recycle();
67 }
Weien Wang4710c042018-10-05 19:46:41 +080068
69 @Test
70 public void testGetSettingsSliceUri() throws Exception {
71 Context context = InstrumentationRegistry.getTargetContext();
72
73 Intent intent = new Intent(WallpaperService.SERVICE_INTERFACE);
74 intent.setPackage("com.android.internal.tests");
75 PackageManager pm = context.getPackageManager();
76 List<ResolveInfo> result = pm.queryIntentServices(intent, PackageManager.GET_META_DATA);
77 assertEquals(1, result.size());
78 ResolveInfo info = result.get(0);
79 WallpaperInfo wallpaperInfo = new WallpaperInfo(context, info);
80
81 // This expected Uri must be the same as that in livewallpaper.xml
82 Uri expectedUri = Uri.parse("content://com.android.internal.tests/slice");
83 Uri settingsUri = wallpaperInfo.getSettingsSliceUri();
84 assertEquals("The loaded URI should equal to the string in livewallpaper.xml",
85 0, expectedUri.compareTo(settingsUri));
86 Parcel parcel = Parcel.obtain();
87 wallpaperInfo.writeToParcel(parcel, 0 /* flags */);
88 parcel.setDataPosition(0);
89 WallpaperInfo fromParcel = WallpaperInfo.CREATOR.createFromParcel(parcel);
90 assertEquals("settingsSliceUri should be restorable from parcelable",
91 0, expectedUri.compareTo(fromParcel.getSettingsSliceUri()));
92 parcel.recycle();
93 }
Lucas Dupin7517b5d2017-08-22 12:51:25 -070094}
95