NPE in Stk app.
Added null checks.
Bug: 35032559
Test: No tests.
Change-Id: I66e68b9492d99bbe9e19846cb5d5415ddbb6a3c7
diff --git a/src/com/android/stk/StkAppService.java b/src/com/android/stk/StkAppService.java
index c8c8e38..9eec59e 100755
--- a/src/com/android/stk/StkAppService.java
+++ b/src/com/android/stk/StkAppService.java
@@ -798,14 +798,17 @@
// returns true if any Stk related activity already has focus on the screen
private boolean isTopOfStack() {
- ActivityManager mAcivityManager = (ActivityManager) mContext
+ ActivityManager mActivityManager = (ActivityManager) mContext
.getSystemService(ACTIVITY_SERVICE);
- String currentPackageName = mAcivityManager.getRunningTasks(1).get(0).topActivity
- .getPackageName();
+ String currentPackageName = null;
+ List<RunningTaskInfo> tasks = mActivityManager.getRunningTasks(1);
+ if (tasks == null || tasks.get(0).topActivity == null) {
+ return false;
+ }
+ currentPackageName = tasks.get(0).topActivity.getPackageName();
if (null != currentPackageName) {
return currentPackageName.equals(PACKAGE_NAME);
}
-
return false;
}