Do not reference TaskRecord's intent without checking for null.
It is possible for a TaskRecord's intent to be set to null. We should
always check this before referencing it.
Change-Id: Id0dd18dc694549c348f1cd7d2dfe02915c1c7f92
Fixes: 77457970
Test: atest FrameworksServicesTests:com.android.server.am.TaskRecordTests#testReturnsToHomeStack
diff --git a/services/core/java/com/android/server/am/AppErrors.java b/services/core/java/com/android/server/am/AppErrors.java
index 35b7f2b..a6dafbb 100644
--- a/services/core/java/com/android/server/am/AppErrors.java
+++ b/services/core/java/com/android/server/am/AppErrors.java
@@ -476,7 +476,8 @@
} catch (IllegalArgumentException e) {
// Hmm, that didn't work, app might have crashed before creating a
// recents entry. Let's see if we have a safe-to-restart intent.
- final Set<String> cats = task.intent.getCategories();
+ final Set<String> cats = task.intent != null
+ ? task.intent.getCategories() : null;
if (cats != null && cats.contains(Intent.CATEGORY_LAUNCHER)) {
mService.getActivityStartController().startActivityInPackage(
task.mCallingUid, callingPid, callingUid, task.mCallingPackage,
diff --git a/services/core/java/com/android/server/am/LockTaskController.java b/services/core/java/com/android/server/am/LockTaskController.java
index bef650b..151ef49 100644
--- a/services/core/java/com/android/server/am/LockTaskController.java
+++ b/services/core/java/com/android/server/am/LockTaskController.java
@@ -555,11 +555,12 @@
return;
}
- if (mLockTaskModeTasks.isEmpty()) {
+ final Intent taskIntent = task.intent;
+ if (mLockTaskModeTasks.isEmpty() && taskIntent != null) {
mSupervisor.mRecentTasks.onLockTaskModeStateChanged(lockTaskModeState, task.userId);
// Start lock task on the handler thread
mHandler.post(() -> performStartLockTask(
- task.intent.getComponent().getPackageName(),
+ taskIntent.getComponent().getPackageName(),
task.userId,
lockTaskModeState));
}
diff --git a/services/core/java/com/android/server/am/RecentTasks.java b/services/core/java/com/android/server/am/RecentTasks.java
index a20452b..c83bacb 100644
--- a/services/core/java/com/android/server/am/RecentTasks.java
+++ b/services/core/java/com/android/server/am/RecentTasks.java
@@ -550,7 +550,7 @@
continue;
}
- ComponentName cn = tr.intent.getComponent();
+ ComponentName cn = tr.intent != null ? tr.intent.getComponent() : null;
final boolean sameComponent = cn != null && cn.getPackageName().equals(packageName)
&& (filterByClasses == null || filterByClasses.contains(cn.getClassName()));
if (sameComponent) {
diff --git a/services/core/java/com/android/server/am/TaskRecord.java b/services/core/java/com/android/server/am/TaskRecord.java
index 0e418ad..1cd1dd6 100644
--- a/services/core/java/com/android/server/am/TaskRecord.java
+++ b/services/core/java/com/android/server/am/TaskRecord.java
@@ -203,7 +203,8 @@
String rootAffinity; // Initial base affinity, or null; does not change from initial root.
final IVoiceInteractionSession voiceSession; // Voice interaction session driving task
final IVoiceInteractor voiceInteractor; // Associated interactor to provide to app
- Intent intent; // The original intent that started the task.
+ Intent intent; // The original intent that started the task. Note that this value can
+ // be null.
Intent affinityIntent; // Intent of affinity-moved activity that started this task.
int effectiveUid; // The current effective uid of the identity of this task.
ComponentName origActivity; // The non-alias activity component of the intent.
@@ -897,12 +898,12 @@
// the real activity that will be launched not the alias, so we need to use an intent with
// the component name pointing to the real activity not the alias in the activity record.
intent.setComponent(r.realActivity);
- return this.intent.filterEquals(intent);
+ return intent.filterEquals(this.intent);
}
boolean returnsToHomeStack() {
final int returnHomeFlags = FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_TASK_ON_HOME;
- return (intent.getFlags() & returnHomeFlags) == returnHomeFlags;
+ return intent != null && (intent.getFlags() & returnHomeFlags) == returnHomeFlags;
}
void setPrevAffiliate(TaskRecord prevAffiliate) {
@@ -2165,9 +2166,11 @@
out.endTag(null, TAG_AFFINITYINTENT);
}
- out.startTag(null, TAG_INTENT);
- intent.saveToXml(out);
- out.endTag(null, TAG_INTENT);
+ if (intent != null) {
+ out.startTag(null, TAG_INTENT);
+ intent.saveToXml(out);
+ out.endTag(null, TAG_INTENT);
+ }
final ArrayList<ActivityRecord> activities = mActivities;
final int numActivities = activities.size();