From 248862fd6609345404e3c9ea3a80fc6786ad7b9d Mon Sep 17 00:00:00 2001 From: Carmen Jackson Date: Sat, 4 Feb 2023 02:45:05 +0000 Subject: [PATCH] Include the Subreason, if any, in ApplicationExitInfo.getDescription(). Instead of making the Subreasons public, which could introduce API churn, let's add the string representation of the subreason into getDescription so that an app developer can relatively easily see those details if they're interested. Bug: 266248465 Test: atest ApplicationExitInfoTest Change-Id: Id4fd8d846886b05302ecfa8fe7f764364ca94f60 --- .../java/android/app/ApplicationExitInfo.java | 17 ++++++- .../server/am/ApplicationExitInfoTest.java | 47 +++++++++++-------- 2 files changed, 44 insertions(+), 20 deletions(-) diff --git a/core/java/android/app/ApplicationExitInfo.java b/core/java/android/app/ApplicationExitInfo.java index 51ea04f397d24..f74b8984e8d1c 100644 --- a/core/java/android/app/ApplicationExitInfo.java +++ b/core/java/android/app/ApplicationExitInfo.java @@ -706,7 +706,22 @@ public final class ApplicationExitInfo implements Parcelable { * guarantees that the format is stable across devices or Android releases.

*/ public @Nullable String getDescription() { - return mDescription; + final StringBuilder sb = new StringBuilder(); + + if (mSubReason != SUBREASON_UNKNOWN) { + sb.append("["); + sb.append(subreasonToString(mSubReason)); + sb.append("]"); + } + + if (!TextUtils.isEmpty(mDescription)) { + if (sb.length() > 0) { + sb.append(" "); + } + sb.append(mDescription); + } + + return sb.toString(); } /** diff --git a/services/tests/mockingservicestests/src/com/android/server/am/ApplicationExitInfoTest.java b/services/tests/mockingservicestests/src/com/android/server/am/ApplicationExitInfoTest.java index 4a40b5f2de7b2..9c581f9e4af28 100644 --- a/services/tests/mockingservicestests/src/com/android/server/am/ApplicationExitInfoTest.java +++ b/services/tests/mockingservicestests/src/com/android/server/am/ApplicationExitInfoTest.java @@ -711,8 +711,6 @@ public class ApplicationExitInfoTest { null); // description // Case 8: App1 gets "remove task" - final String app1Description = "remove task"; - sleep(1); final int app1IsolatedUidUser2 = 1099002; // isolated uid final long app1Pss4 = 34343; @@ -739,7 +737,7 @@ public class ApplicationExitInfoTest { mAppExitInfoTracker.mIsolatedUidRecords.addIsolatedUid(app1IsolatedUidUser2, app1UidUser2); noteAppKill(app, ApplicationExitInfo.REASON_OTHER, - ApplicationExitInfo.SUBREASON_UNKNOWN, app1Description, now8); + ApplicationExitInfo.SUBREASON_REMOVE_TASK, null, now8); updateExitInfo(app, now8); list.clear(); @@ -749,21 +747,21 @@ public class ApplicationExitInfoTest { info = list.get(0); verifyApplicationExitInfo( - info, // info - now8, // timestamp - app1PidUser2, // pid - app1IsolatedUidUser2, // uid - app1UidUser2, // packageUid - null, // definingUid - app1ProcessName, // processName - 0, // connectionGroup - ApplicationExitInfo.REASON_OTHER, // reason - ApplicationExitInfo.SUBREASON_UNKNOWN, // subReason - 0, // status - app1Pss4, // pss - app1Rss4, // rss - IMPORTANCE_CACHED, // importance - app1Description); // description + info, // info + now8, // timestamp + app1PidUser2, // pid + app1IsolatedUidUser2, // uid + app1UidUser2, // packageUid + null, // definingUid + app1ProcessName, // processName + 0, // connectionGroup + ApplicationExitInfo.REASON_OTHER, // reason + ApplicationExitInfo.SUBREASON_REMOVE_TASK, // subReason + 0, // status + app1Pss4, // pss + app1Rss4, // rss + IMPORTANCE_CACHED, // importance + null); // description // App1 gets "too many empty" final String app1Description2 = "too many empty"; @@ -1058,7 +1056,18 @@ public class ApplicationExitInfoTest { if (importance != null) { assertEquals(importance.intValue(), info.getImportance()); } - if (description != null) { + + // info.getDescription returns a combination of subReason & description + if ((subReason != null) && (subReason != ApplicationExitInfo.SUBREASON_UNKNOWN) + && (description != null)) { + assertTrue(TextUtils.equals( + "[" + info.subreasonToString(subReason) + "] " + description, + info.getDescription())); + } else if ((subReason != null) && (subReason != ApplicationExitInfo.SUBREASON_UNKNOWN)) { + assertTrue(TextUtils.equals( + "[" + info.subreasonToString(subReason) + "]", + info.getDescription())); + } else if (description != null) { assertTrue(TextUtils.equals(description, info.getDescription())); } }