Home | History | Annotate | Download | only in app
      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 
     17 package android.app;
     18 
     19 import static org.junit.Assert.assertEquals;
     20 import static org.junit.Assert.assertTrue;
     21 
     22 import android.content.Context;
     23 import android.content.Intent;
     24 import android.content.pm.PackageManager;
     25 import android.content.pm.ResolveInfo;
     26 import android.os.Parcel;
     27 import android.service.wallpaper.WallpaperService;
     28 import android.support.test.InstrumentationRegistry;
     29 import android.support.test.filters.SmallTest;
     30 import android.support.test.runner.AndroidJUnit4;
     31 
     32 import org.junit.Test;
     33 import org.junit.runner.RunWith;
     34 
     35 import java.util.List;
     36 
     37 /**
     38  * Tests for hidden WallpaperInfo methods.
     39  */
     40 @RunWith(AndroidJUnit4.class)
     41 @SmallTest
     42 public 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