1/* 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; 26import android.os.Parcel; 27import android.service.wallpaper.WallpaperService; 28import android.support.test.InstrumentationRegistry; 29import android.support.test.filters.SmallTest; 30import android.support.test.runner.AndroidJUnit4; 31 32import org.junit.Test; 33import org.junit.runner.RunWith; 34 35import java.util.List; 36 37/** 38 * Tests for hidden WallpaperInfo methods. 39 */ 40@RunWith(AndroidJUnit4.class) 41@SmallTest 42public class WallpaperInfoTest { 43 44 @Test 45 public void testSupportsAmbientMode() throws Exception { 46 Context context = InstrumentationRegistry.getTargetContext(); 47 48 Intent intent = new Intent(WallpaperService.SERVICE_INTERFACE); 49 intent.setPackage("com.android.internal.tests"); 50 PackageManager pm = context.getPackageManager(); 51 List<ResolveInfo> result = pm.queryIntentServices(intent, PackageManager.GET_META_DATA); 52 assertEquals(1, result.size()); 53 ResolveInfo info = result.get(0); 54 WallpaperInfo wallpaperInfo = new WallpaperInfo(context, info); 55 56 // Defined as true in the XML 57 assertTrue("supportsAmbientMode should be true, as defined in the XML.", 58 wallpaperInfo.getSupportsAmbientMode()); 59 Parcel parcel = Parcel.obtain(); 60 wallpaperInfo.writeToParcel(parcel, 0 /* flags */); 61 parcel.setDataPosition(0); 62 WallpaperInfo fromParcel = WallpaperInfo.CREATOR.createFromParcel(parcel); 63 assertTrue("supportsAmbientMode should have been restored from parcelable", 64 fromParcel.getSupportsAmbientMode()); 65 parcel.recycle(); 66 } 67} 68 69