Merge "Update ASM logging for U release" into udc-qpr-dev

This commit is contained in:
Hani Kazmi
2023-07-24 17:39:15 +00:00
committed by Android (Google) Code Review
2 changed files with 25 additions and 12 deletions

View File

@@ -2031,6 +2031,13 @@ class ActivityStarter {
} }
} }
// ASM rules have failed. Log why
return logAsmFailureAndCheckFeatureEnabled(r, newTask, targetTask, shouldBlockActivityStart,
taskToFront);
}
private boolean logAsmFailureAndCheckFeatureEnabled(ActivityRecord r, boolean newTask,
Task targetTask, boolean shouldBlockActivityStart, boolean taskToFront) {
// ASM rules have failed. Log why // ASM rules have failed. Log why
ActivityRecord targetTopActivity = targetTask == null ? null ActivityRecord targetTopActivity = targetTask == null ? null
: targetTask.getActivity(ar -> !ar.finishing && !ar.isAlwaysOnTop()); : targetTask.getActivity(ar -> !ar.finishing && !ar.isAlwaysOnTop());
@@ -2041,6 +2048,13 @@ class ActivityStarter {
? FrameworkStatsLog.ACTIVITY_ACTION_BLOCKED__ACTION__ACTIVITY_START_SAME_TASK ? FrameworkStatsLog.ACTIVITY_ACTION_BLOCKED__ACTION__ACTIVITY_START_SAME_TASK
: FrameworkStatsLog.ACTIVITY_ACTION_BLOCKED__ACTION__ACTIVITY_START_DIFFERENT_TASK); : FrameworkStatsLog.ACTIVITY_ACTION_BLOCKED__ACTION__ACTIVITY_START_DIFFERENT_TASK);
boolean blockActivityStartAndFeatureEnabled = ActivitySecurityModelFeatureFlags
.shouldRestrictActivitySwitch(mCallingUid)
&& shouldBlockActivityStart;
String asmDebugInfo = getDebugInfoForActivitySecurity("Launch", r, targetTask,
targetTopActivity, blockActivityStartAndFeatureEnabled, /*taskToFront*/taskToFront);
FrameworkStatsLog.write(FrameworkStatsLog.ACTIVITY_ACTION_BLOCKED, FrameworkStatsLog.write(FrameworkStatsLog.ACTIVITY_ACTION_BLOCKED,
/* caller_uid */ /* caller_uid */
mSourceRecord != null ? mSourceRecord.getUid() : mCallingUid, mSourceRecord != null ? mSourceRecord.getUid() : mCallingUid,
@@ -2069,24 +2083,21 @@ class ActivityStarter {
targetTask != null && mSourceRecord != null targetTask != null && mSourceRecord != null
&& !targetTask.equals(mSourceRecord.getTask()) && targetTask.isVisible(), && !targetTask.equals(mSourceRecord.getTask()) && targetTask.isVisible(),
/* bal_code */ /* bal_code */
mBalCode mBalCode,
/* task_stack */
asmDebugInfo
); );
boolean blockActivityStartAndFeatureEnabled = ActivitySecurityModelFeatureFlags
.shouldRestrictActivitySwitch(mCallingUid)
&& shouldBlockActivityStart;
String launchedFromPackageName = r.launchedFromPackage; String launchedFromPackageName = r.launchedFromPackage;
if (ActivitySecurityModelFeatureFlags.shouldShowToast(mCallingUid)) { if (ActivitySecurityModelFeatureFlags.shouldShowToast(mCallingUid)) {
String toastText = ActivitySecurityModelFeatureFlags.DOC_LINK String toastText = ActivitySecurityModelFeatureFlags.DOC_LINK
+ (blockActivityStartAndFeatureEnabled ? " blocked " : " would block ") + (blockActivityStartAndFeatureEnabled ? " blocked " : " would block ")
+ getApplicationLabel(mService.mContext.getPackageManager(), + getApplicationLabel(mService.mContext.getPackageManager(),
launchedFromPackageName); launchedFromPackageName);
UiThread.getHandler().post(() -> Toast.makeText(mService.mContext, UiThread.getHandler().post(() -> Toast.makeText(mService.mContext,
toastText, Toast.LENGTH_LONG).show()); toastText, Toast.LENGTH_LONG).show());
logDebugInfoForActivitySecurity("Launch", r, targetTask, targetTopActivity, Slog.i(TAG, asmDebugInfo);
blockActivityStartAndFeatureEnabled, /* taskToFront */ taskToFront);
} }
if (blockActivityStartAndFeatureEnabled) { if (blockActivityStartAndFeatureEnabled) {
@@ -2104,7 +2115,7 @@ class ActivityStarter {
} }
/** Only called when an activity launch may be blocked, which should happen very rarely */ /** Only called when an activity launch may be blocked, which should happen very rarely */
private void logDebugInfoForActivitySecurity(String action, ActivityRecord r, Task targetTask, private String getDebugInfoForActivitySecurity(String action, ActivityRecord r, Task targetTask,
ActivityRecord targetTopActivity, boolean blockActivityStartAndFeatureEnabled, ActivityRecord targetTopActivity, boolean blockActivityStartAndFeatureEnabled,
boolean taskToFront) { boolean taskToFront) {
final String prefix = "[ASM] "; final String prefix = "[ASM] ";
@@ -2165,7 +2176,7 @@ class ActivityStarter {
joiner.add(prefix + "BalCode: " + balCodeToString(mBalCode)); joiner.add(prefix + "BalCode: " + balCodeToString(mBalCode));
joiner.add(prefix + "------ Activity Security " + action + " Debug Logging End ------"); joiner.add(prefix + "------ Activity Security " + action + " Debug Logging End ------");
Slog.i(TAG, joiner.toString()); return joiner.toString();
} }
/** /**
@@ -2339,7 +2350,7 @@ class ActivityStarter {
+ ActivitySecurityModelFeatureFlags.DOC_LINK, + ActivitySecurityModelFeatureFlags.DOC_LINK,
Toast.LENGTH_LONG).show()); Toast.LENGTH_LONG).show());
logDebugInfoForActivitySecurity("Clear Top", mStartActivity, targetTask, targetTaskTop, getDebugInfoForActivitySecurity("Clear Top", mStartActivity, targetTask, targetTaskTop,
shouldBlockActivityStart, /* taskToFront */ true); shouldBlockActivityStart, /* taskToFront */ true);
} }
} }

View File

@@ -1752,7 +1752,9 @@ public class ActivityTaskSupervisor implements RecentTasks.Callbacks {
/* multi_window */ /* multi_window */
false, false,
/* bal_code */ /* bal_code */
-1 -1,
/* task_stack */
null
); );
boolean restrictActivitySwitch = ActivitySecurityModelFeatureFlags boolean restrictActivitySwitch = ActivitySecurityModelFeatureFlags