Add method to check if app has launcher activity

This method should only used for system apps.

Change-Id: Id4109d8e223933269b8dae3aaa91b8a9186c527c
Fixes: 77477987
Test: RunSettingsRoboTests
This commit is contained in:
Lei Yu
2018-04-10 14:38:46 -07:00
parent 6c4c7ba0fe
commit 7d09e2ea68
2 changed files with 47 additions and 4 deletions

View File

@@ -37,8 +37,10 @@ import static org.mockito.Mockito.when;
import android.app.AppOpsManager;
import android.content.Context;
import android.content.pm.ActivityInfo;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.os.BatteryStats;
import android.os.Build;
import android.os.Bundle;
@@ -575,7 +577,22 @@ public class BatteryUtilsTest {
}
@Test
public void testShouldHideAnomaly_systemApp_returnTrue() {
public void testShouldHideAnomaly_systemAppWithLauncher_returnTrue() {
final List<ResolveInfo> resolveInfos = new ArrayList<>();
final ResolveInfo resolveInfo = new ResolveInfo();
resolveInfo.activityInfo = new ActivityInfo();
resolveInfo.activityInfo.packageName = HIGH_SDK_PACKAGE;
doReturn(resolveInfos).when(mPackageManager).queryIntentActivities(any(), anyInt());
doReturn(new String[]{HIGH_SDK_PACKAGE}).when(mPackageManager).getPackagesForUid(UID);
mHighApplicationInfo.flags = ApplicationInfo.FLAG_SYSTEM;
assertThat(mBatteryUtils.shouldHideAnomaly(mPowerWhitelistBackend, UID)).isTrue();
}
@Test
public void testShouldHideAnomaly_systemAppWithoutLauncher_returnTrue() {
doReturn(new ArrayList<>()).when(mPackageManager).queryIntentActivities(any(), anyInt());
doReturn(new String[]{HIGH_SDK_PACKAGE}).when(mPackageManager).getPackagesForUid(UID);
mHighApplicationInfo.flags = ApplicationInfo.FLAG_SYSTEM;