Add missing null check in HomeVisibilityListener

Fixes: 178028272
Test: atest HomeVisibilityListenerTest
Change-Id: I3d4158cece84e79b3bfa29efcdb038c65e393d38
This commit is contained in:
Hall Liu
2021-01-20 13:50:22 -08:00
parent 6d6a948994
commit fc490ab278

View File

@@ -19,6 +19,7 @@ package android.app;
import android.annotation.SuppressLint;
import android.annotation.SystemApi;
import android.annotation.TestApi;
import android.content.ComponentName;
import android.content.Context;
import android.os.Binder;
@@ -101,12 +102,11 @@ public abstract class HomeVisibilityListener {
}
// We can assume that the screen is idle if the home application is in the foreground.
String defaultHomePackage = mContext.getPackageManager()
.getHomeActivities(new ArrayList<>()).getPackageName();
if (Objects.equals(top, defaultHomePackage)) {
return true;
}
ComponentName defaultHomeComponent = mContext.getPackageManager()
.getHomeActivities(new ArrayList<>());
if (defaultHomeComponent == null) return false;
return false;
String defaultHomePackage = defaultHomeComponent.getPackageName();
return Objects.equals(top, defaultHomePackage);
}
}