Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit bf3bdebe authored by Hani Kazmi's avatar Hani Kazmi
Browse files

Add logging for activity finishActivity to be blocked as part of go/activity-security

Adds logs for activity actions which don't match the following rules from the document:

3. Only the top activity can finish its task

These logs will be used to determine which valid use cases may be
blocked by the ASM project in the future.

Also updated the existing logs to use the new atom fields.

BYPASS_LONG_LINES_REASON: Auto generated enum names
Bug: 246738504
Test: statsd_testdrive 495
Test: Manually reproduced scenario and checked logs

Change-Id: I57ed3c51ccdc187895cd99294f47d482e14e90c0
parent bd224c8a
Loading
Loading
Loading
Loading
+34 −0
Original line number Diff line number Diff line
@@ -86,6 +86,7 @@ import android.window.TransitionInfo;
import com.android.internal.app.AssistUtils;
import com.android.internal.policy.IKeyguardDismissCallback;
import com.android.internal.protolog.common.ProtoLog;
import com.android.internal.util.FrameworkStatsLog;
import com.android.server.LocalServices;
import com.android.server.Watchdog;
import com.android.server.pm.KnownPackages;
@@ -454,6 +455,39 @@ class ActivityClientController extends IActivityClientController.Stub {
                        finishTask == Activity.FINISH_TASK_WITH_ROOT_ACTIVITY;
                if (finishTask == Activity.FINISH_TASK_WITH_ACTIVITY
                        || (finishWithRootActivity && r == rootR)) {
                    ActivityRecord topActivity =
                            r.getTask().getTopNonFinishingActivity();
                    boolean passesAsmChecks = topActivity != null
                            && topActivity.getUid() == r.getUid();
                    if (!passesAsmChecks) {
                        Slog.i(TAG, "Finishing task from background. r: " + r);
                        FrameworkStatsLog.write(FrameworkStatsLog.ACTIVITY_ACTION_BLOCKED,
                                /* caller_uid */
                                r.getUid(),
                                /* caller_activity_class_name */
                                r.info.name,
                                /* target_task_top_activity_uid */
                                topActivity == null ? -1 : topActivity.getUid(),
                                /* target_task_top_activity_class_name */
                                topActivity == null ? null : topActivity.info.name,
                                /* target_task_is_different */
                                false,
                                /* target_activity_uid */
                                -1,
                                /* target_activity_class_name */
                                null,
                                /* target_intent_action */
                                null,
                                /* target_intent_flags */
                                0,
                                /* action */
                                FrameworkStatsLog.ACTIVITY_ACTION_BLOCKED__ACTION__FINISH_TASK,
                                /* version */
                                1,
                                /* multi_window */
                                false
                        );
                    }
                    // If requested, remove the task that is associated to this activity only if it
                    // was the root activity in the task. The result code and data is ignored
                    // because we don't support returning them across task boundaries. Also, to
+13 −1
Original line number Diff line number Diff line
@@ -1856,6 +1856,11 @@ class ActivityStarter {
                        + " from background: " + mSourceRecord
                        + ". New task: " + newTask);
                boolean newOrEmptyTask = newTask || (targetTopActivity == null);
                int action = newTask
                        ? FrameworkStatsLog.ACTIVITY_ACTION_BLOCKED__ACTION__ACTIVITY_START_NEW_TASK
                        : (mSourceRecord.getTask().equals(targetTask)
                                ? FrameworkStatsLog.ACTIVITY_ACTION_BLOCKED__ACTION__ACTIVITY_START_SAME_TASK
                                :  FrameworkStatsLog.ACTIVITY_ACTION_BLOCKED__ACTION__ACTIVITY_START_DIFFERENT_TASK);
                FrameworkStatsLog.write(FrameworkStatsLog.ACTIVITY_ACTION_BLOCKED,
                        /* caller_uid */
                        callerUid,
@@ -1874,7 +1879,14 @@ class ActivityStarter {
                        /* target_intent_action */
                        r.intent.getAction(),
                        /* target_intent_flags */
                        r.intent.getFlags()
                        r.intent.getFlags(),
                        /* action */
                        action,
                        /* version */
                        1,
                        /* multi_window */
                        targetTask != null && !targetTask.equals(mSourceRecord.getTask())
                                && targetTask.isVisible()
                );
            }
        }