• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 com.android.cts.userapptest;
18 
19 import static org.hamcrest.CoreMatchers.is;
20 import static org.junit.Assert.assertThat;
21 import static org.junit.Assert.fail;
22 
23 import android.content.Intent;
24 import android.content.pm.ResolveInfo;
25 
26 import androidx.test.InstrumentationRegistry;
27 import androidx.test.runner.AndroidJUnit4;
28 
29 import org.junit.Test;
30 import org.junit.runner.RunWith;
31 
32 import java.util.List;
33 
34 @RunWith(AndroidJUnit4.class)
35 public class ClientTest {
36     /** Action to query for test activities */
37     private static final String ACTION_QUERY_ACTIVITY =
38             "com.android.cts.instantappusertest.QUERY";
39 
40     @Test
testQueryInstant()41     public void testQueryInstant() throws Exception {
42         final Intent queryIntent = new Intent(ACTION_QUERY_ACTIVITY);
43         final List<ResolveInfo> resolveInfo = InstrumentationRegistry
44                 .getContext().getPackageManager().queryIntentActivities(queryIntent, 0 /*flags*/);
45         if (resolveInfo != null && resolveInfo.size() != 0) {
46             fail("resolved intents");
47         }
48     }
49 
50     @Test
testQueryFull()51     public void testQueryFull() throws Exception {
52         final Intent queryIntent = new Intent(ACTION_QUERY_ACTIVITY);
53         final List<ResolveInfo> resolveInfo = InstrumentationRegistry
54                 .getContext().getPackageManager().queryIntentActivities(queryIntent, 0 /*flags*/);
55         if (resolveInfo == null || resolveInfo.size() == 0) {
56             fail("didn't resolve any intents");
57         }
58         assertThat(resolveInfo.size(), is(1));
59         assertThat(resolveInfo.get(0).activityInfo.packageName,
60                 is("com.android.cts.userapp"));
61         assertThat(resolveInfo.get(0).activityInfo.name,
62                 is("com.android.cts.userapp.UserActivity"));
63     }
64 }
65