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
This commit is contained in:
Carmen Jackson
2023-02-04 02:45:05 +00:00
parent c743163013
commit 248862fd66
2 changed files with 44 additions and 20 deletions

View File

@@ -706,7 +706,22 @@ public final class ApplicationExitInfo implements Parcelable {
* guarantees that the format is stable across devices or Android releases.</p>
*/
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();
}
/**

View File

@@ -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()));
}
}