1 /* 2 * Copyright (C) 2018 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.appsecurity.cts.orderedactivity; 18 19 import static org.junit.Assert.assertEquals; 20 import static org.junit.Assert.assertNotNull; 21 22 import android.content.Intent; 23 import android.content.pm.PackageManager; 24 import android.content.pm.ResolveInfo; 25 import android.net.Uri; 26 27 import androidx.test.InstrumentationRegistry; 28 import androidx.test.runner.AndroidJUnit4; 29 30 import org.junit.Test; 31 import org.junit.runner.RunWith; 32 33 import java.util.List; 34 35 @RunWith(AndroidJUnit4.class) 36 public class PackageResolutionTest { 37 @Test queryActivityOrdered()38 public void queryActivityOrdered() throws Exception { 39 final PackageManager pm = 40 InstrumentationRegistry.getInstrumentation().getContext().getPackageManager(); 41 final Intent intent = new Intent("android.cts.intent.action.ORDERED"); 42 intent.setData(Uri.parse("https://www.google.com/cts/packageresolution")); 43 final List<ResolveInfo> resolve = pm.queryIntentActivities(intent, 0 /*flags*/); 44 45 assertNotNull(resolve); 46 assertEquals(4, resolve.size()); 47 assertEquals("android.appsecurity.cts.orderedactivity.OrderActivity3", 48 resolve.get(0).activityInfo.name); 49 assertEquals("android.appsecurity.cts.orderedactivity.OrderActivity2", 50 resolve.get(1).activityInfo.name); 51 assertEquals("android.appsecurity.cts.orderedactivity.OrderActivity1", 52 resolve.get(2).activityInfo.name); 53 assertEquals("android.appsecurity.cts.orderedactivity.OrderActivityDefault", 54 resolve.get(3).activityInfo.name); 55 } 56 57 @Test queryServiceOrdered()58 public void queryServiceOrdered() throws Exception { 59 final PackageManager pm = 60 InstrumentationRegistry.getInstrumentation().getContext().getPackageManager(); 61 final Intent intent = new Intent("android.cts.intent.action.ORDERED"); 62 intent.setData(Uri.parse("https://www.google.com/cts/packageresolution")); 63 final List<ResolveInfo> resolve = pm.queryIntentServices(intent, 0 /*flags*/); 64 65 assertNotNull(resolve); 66 assertEquals(4, resolve.size()); 67 assertEquals("android.appsecurity.cts.orderedactivity.OrderService3", 68 resolve.get(0).serviceInfo.name); 69 assertEquals("android.appsecurity.cts.orderedactivity.OrderService2", 70 resolve.get(1).serviceInfo.name); 71 assertEquals("android.appsecurity.cts.orderedactivity.OrderService1", 72 resolve.get(2).serviceInfo.name); 73 assertEquals("android.appsecurity.cts.orderedactivity.OrderServiceDefault", 74 resolve.get(3).serviceInfo.name); 75 } 76 77 @Test queryReceiverOrdered()78 public void queryReceiverOrdered() throws Exception { 79 final PackageManager pm = 80 InstrumentationRegistry.getInstrumentation().getContext().getPackageManager(); 81 final Intent intent = new Intent("android.cts.intent.action.ORDERED"); 82 intent.setData(Uri.parse("https://www.google.com/cts/packageresolution")); 83 final List<ResolveInfo> resolve = pm.queryBroadcastReceivers(intent, 0 /*flags*/); 84 85 assertNotNull(resolve); 86 assertEquals(4, resolve.size()); 87 assertEquals("android.appsecurity.cts.orderedactivity.OrderReceiver3", 88 resolve.get(0).activityInfo.name); 89 assertEquals("android.appsecurity.cts.orderedactivity.OrderReceiver2", 90 resolve.get(1).activityInfo.name); 91 assertEquals("android.appsecurity.cts.orderedactivity.OrderReceiver1", 92 resolve.get(2).activityInfo.name); 93 assertEquals("android.appsecurity.cts.orderedactivity.OrderReceiverDefault", 94 resolve.get(3).activityInfo.name); 95 } 96 } 97