blob: 476b99155672c9d6936db41dc876414bbbc6e174 [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;
Brett Chabot502ec7a2019-03-01 14:43:20 -080029
30import androidx.test.InstrumentationRegistry;
31import androidx.test.filters.SmallTest;
32import androidx.test.runner.AndroidJUnit4;
Lucas Dupin7517b5d2017-08-22 12:51:25 -070033
34import org.junit.Test;
35import org.junit.runner.RunWith;
36
37import java.util.List;
38
39/**
40 * Tests for hidden WallpaperInfo methods.
41 */
42@RunWith(AndroidJUnit4.class)
43@SmallTest
44public class WallpaperInfoTest {
45
46 @Test
47 public void testSupportsAmbientMode() throws Exception {
48 Context context = InstrumentationRegistry.getTargetContext();
49
50 Intent intent = new Intent(WallpaperService.SERVICE_INTERFACE);
51 intent.setPackage("com.android.internal.tests");
52 PackageManager pm = context.getPackageManager();
53 List<ResolveInfo> result = pm.queryIntentServices(intent, PackageManager.GET_META_DATA);
54 assertEquals(1, result.size());
55 ResolveInfo info = result.get(0);
56 WallpaperInfo wallpaperInfo = new WallpaperInfo(context, info);
57
58 // Defined as true in the XML
59 assertTrue("supportsAmbientMode should be true, as defined in the XML.",
Lucas Dupin8f09a502018-07-27 16:47:45 +080060 wallpaperInfo.supportsAmbientMode());
Lucas Dupin7517b5d2017-08-22 12:51:25 -070061 Parcel parcel = Parcel.obtain();
62 wallpaperInfo.writeToParcel(parcel, 0 /* flags */);
63 parcel.setDataPosition(0);
64 WallpaperInfo fromParcel = WallpaperInfo.CREATOR.createFromParcel(parcel);
65 assertTrue("supportsAmbientMode should have been restored from parcelable",
Lucas Dupin8f09a502018-07-27 16:47:45 +080066 fromParcel.supportsAmbientMode());
Lucas Dupin7517b5d2017-08-22 12:51:25 -070067 parcel.recycle();
68 }
Weien Wang4710c042018-10-05 19:46:41 +080069
70 @Test
71 public void testGetSettingsSliceUri() throws Exception {
72 Context context = InstrumentationRegistry.getTargetContext();
73
74 Intent intent = new Intent(WallpaperService.SERVICE_INTERFACE);
75 intent.setPackage("com.android.internal.tests");
76 PackageManager pm = context.getPackageManager();
77 List<ResolveInfo> result = pm.queryIntentServices(intent, PackageManager.GET_META_DATA);
78 assertEquals(1, result.size());
79 ResolveInfo info = result.get(0);
80 WallpaperInfo wallpaperInfo = new WallpaperInfo(context, info);
81
82 // This expected Uri must be the same as that in livewallpaper.xml
83 Uri expectedUri = Uri.parse("content://com.android.internal.tests/slice");
84 Uri settingsUri = wallpaperInfo.getSettingsSliceUri();
85 assertEquals("The loaded URI should equal to the string in livewallpaper.xml",
86 0, expectedUri.compareTo(settingsUri));
87 Parcel parcel = Parcel.obtain();
88 wallpaperInfo.writeToParcel(parcel, 0 /* flags */);
89 parcel.setDataPosition(0);
90 WallpaperInfo fromParcel = WallpaperInfo.CREATOR.createFromParcel(parcel);
91 assertEquals("settingsSliceUri should be restorable from parcelable",
92 0, expectedUri.compareTo(fromParcel.getSettingsSliceUri()));
93 parcel.recycle();
94 }
Lucas Dupin7517b5d2017-08-22 12:51:25 -070095}
96