| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 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 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 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 |
| 54 |
public void before() { |
| 55 |
Log.d(TAG, "beforeClass()"); |
| 56 |
mContext = InstrumentationRegistry.getInstrumentation().getContext(); |
| 57 |
mPm = mContext.getPackageManager(); |
| 58 |
} |
| 59 |
|
| 60 |
@Test |
| 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 |
} |