1 /*
2  * Copyright (C) 2020 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 package com.android.test.nullhome;
17 
18 import android.content.Context;
19 import android.content.pm.PackageManager;
20 import android.content.pm.ResolveInfo;
21 import android.util.Log;
22 
23 import androidx.test.InstrumentationRegistry;
24 
25 import org.junit.Assert;
26 import org.junit.Before;
27 import org.junit.Test;
28 import org.junit.runner.RunWith;
29 import org.junit.runners.JUnit4;
30 
31 import java.util.ArrayList;
32 import java.util.List;
33 
34 /*
35  * Check if NullHome/SystemUserHome activity does not exist/is disabled.
36  *
37  * SystemUserHome is only enabled in bootable CSI (csi_x86, csi_arm64)
38  * products and should not be enabled in other products.
39  *
40  * Shell's NullHome is empty and caused issues in sevaral manual GUI tests
41  * that try to select/use it, and should be removed.
42  *
43  * Settings' FallbackHome is fine because it's specially handled by Settings.
44  *
45  */
46 
47 @RunWith(JUnit4.class)
48 public class NullHomeTest {
49     private static final String TAG = "NullHomeTest";
50     private Context mContext;
51     private PackageManager mPm;
52 
53     @Before
before()54     public void before() {
55         Log.d(TAG, "beforeClass()");
56         mContext = InstrumentationRegistry.getInstrumentation().getContext();
57         mPm = mContext.getPackageManager();
58     }
59 
60     @Test
checkNullHome()61     public void checkNullHome() {
62         final List<ResolveInfo> homeActivities = new ArrayList<>();
63 
64         mPm.getHomeActivities(homeActivities);
65         for (ResolveInfo activity : homeActivities) {
66             Log.d(TAG, "Home activity: " + activity.activityInfo.packageName);
67             Assert.assertNotEquals(activity.activityInfo.packageName,
68                     "com.android.internal.app.SystemUserHomeActivity");
69             Assert.assertNotEquals(activity.activityInfo.packageName,
70                     "com.android.shell");
71         }
72     }
73 }
74