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