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

Commit b0412060 authored by Winson Chung's avatar Winson Chung Committed by Android (Google) Code Review
Browse files

Merge changes Iad270dfd,Ice608e6d,I375369a8

* changes:
  Adding initial TRON logging for picture-in-picture.
  Disallow entering PiP when activity is locked.
  Preventing cases where an app can be stopped while entering PiP.
parents 58f34b82 14fbe141
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -77,7 +77,7 @@ public class PipMenuActivityController {
        void onPipMinimize();

        /**
         * Called when the PIP requested to be expanded.
         * Called when the PIP requested to be dismissed.
         */
        void onPipDismiss();
    }
+21 −2
Original line number Diff line number Diff line
@@ -44,6 +44,8 @@ import android.view.InputEventReceiver;
import android.view.MotionEvent;
import android.view.ViewConfiguration;

import com.android.internal.logging.MetricsLogger;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.internal.os.BackgroundThread;
import com.android.internal.policy.PipMotionHelper;
import com.android.internal.policy.PipSnapAlgorithm;
@@ -58,6 +60,10 @@ public class PipTouchHandler implements TunerService.Tunable {
    private static final String TAG = "PipTouchHandler";
    private static final boolean DEBUG_ALLOW_OUT_OF_BOUNDS_STACK = false;

    // These values are used for metrics and should never change
    private static final int METRIC_VALUE_DISMISSED_BY_TAP = 0;
    private static final int METRIC_VALUE_DISMISSED_BY_DRAG = 1;

    private static final String TUNER_KEY_DRAG_TO_DISMISS = "pip_drag_to_dismiss";
    private static final String TUNER_KEY_ALLOW_MINIMIZE = "pip_allow_minimize";

@@ -147,6 +153,8 @@ public class PipTouchHandler implements TunerService.Tunable {
            } else {
                unregisterInputConsumer();
            }
            MetricsLogger.visibility(mContext, MetricsEvent.ACTION_PICTURE_IN_PICTURE_MENU,
                    visible);
        }

        @Override
@@ -165,6 +173,8 @@ public class PipTouchHandler implements TunerService.Tunable {
        @Override
        public void onPipDismiss() {
            BackgroundThread.getHandler().post(PipTouchHandler.this::dismissPinnedStack);
            MetricsLogger.action(mContext, MetricsEvent.ACTION_PICTURE_IN_PICTURE_DISMISSED,
                    METRIC_VALUE_DISMISSED_BY_TAP);
        }
    }

@@ -230,6 +240,10 @@ public class PipTouchHandler implements TunerService.Tunable {
    }

    public void onMinimizedStateChanged(boolean isMinimized) {
        if (mIsMinimized != isMinimized) {
            MetricsLogger.action(mContext, MetricsEvent.ACTION_PICTURE_IN_PICTURE_MINIMIZED,
                    isMinimized);
        }
        mIsMinimized = isMinimized;
        mSnapAlgorithm.setMinimized(isMinimized);
    }
@@ -439,7 +453,7 @@ public class PipTouchHandler implements TunerService.Tunable {
    /**
     * Flings the PIP to the closest snap target.
     */
    private void flingToSnapTarget(float velocity, float velocityX, float velocityY) {
    private Rect flingToSnapTarget(float velocity, float velocityX, float velocityY) {
        Rect toBounds = mSnapAlgorithm.findClosestSnapBounds(mBoundedPinnedStackBounds,
                mPinnedStackBounds, velocityX, velocityY);
        if (!mPinnedStackBounds.equals(toBounds)) {
@@ -450,12 +464,13 @@ public class PipTouchHandler implements TunerService.Tunable {
                velocity);
            mPinnedStackBoundsAnimator.start();
        }
        return toBounds;
    }

    /**
     * Animates the PIP to the closest snap target.
     */
    private void animateToClosestSnapTarget() {
    private Rect animateToClosestSnapTarget() {
        Rect toBounds = mSnapAlgorithm.findClosestSnapBounds(mBoundedPinnedStackBounds,
                mPinnedStackBounds);
        if (!mPinnedStackBounds.equals(toBounds)) {
@@ -463,6 +478,7 @@ public class PipTouchHandler implements TunerService.Tunable {
                toBounds, SNAP_STACK_DURATION, FAST_OUT_SLOW_IN, mUpdatePinnedStackBoundsListener);
            mPinnedStackBoundsAnimator.start();
        }
        return toBounds;
    }

    /**
@@ -576,6 +592,9 @@ public class PipTouchHandler implements TunerService.Tunable {
                        PointF lastTouch = touchState.getLastTouchPosition();
                        if (dismissBounds.contains((int) lastTouch.x, (int) lastTouch.y)) {
                            animateDismissPinnedStack(dismissBounds);
                            MetricsLogger.action(mContext,
                                    MetricsEvent.ACTION_PICTURE_IN_PICTURE_DISMISSED,
                                            METRIC_VALUE_DISMISSED_BY_DRAG);
                            return true;
                        }
                    }
+27 −0
Original line number Diff line number Diff line
@@ -3351,6 +3351,33 @@ message MetricsEvent {
    // OS: O
    BACKUP_SETTINGS = 818;

    // ACTION: Picture-in-picture was explicitly entered for an activity
    // VALUE: true if it was entered while hiding as a result of moving to another task, false otherwise
    ACTION_PICTURE_IN_PICTURE_ENTERED = 819;

    // ACTION: The activity currently in picture-in-picture was expanded back to fullscreen
    // PACKAGE: The package name of the activity that was expanded back to fullscreen
    ACTION_PICTURE_IN_PICTURE_EXPANDED_TO_FULLSCREEN = 820;

    // ACTION: The activity currently in picture-in-picture was minimized
    // VALUE: True if the PiP was minimized, false otherwise
    ACTION_PICTURE_IN_PICTURE_MINIMIZED = 821;

    // ACTION: Picture-in-picture was dismissed via the dismiss button
    // VALUE: 0 if dismissed by tap, 1 if dismissed by drag
    ACTION_PICTURE_IN_PICTURE_DISMISSED = 822;

    // ACTION: The visibility of the picture-in-picture meny
    // VALUE: Whether or not the menu is visible
    ACTION_PICTURE_IN_PICTURE_MENU = 823;

    // Enclosing category for group of PICTURE_IN_PICTURE_ASPECT_RATIO_FOO events,
    // logged when the aspect ratio changes
    ACTION_PICTURE_IN_PICTURE_ASPECT_RATIO_CHANGED = 824;

    // The current aspect ratio of the PiP, logged when it changes.
    PICTURE_IN_PICTURE_ASPECT_RATIO = 825;

    // ---- End O Constants, all O constants go above this line ----

    // Add new aosp constants above this line.
+25 −2
Original line number Diff line number Diff line
@@ -235,6 +235,7 @@ import android.graphics.Bitmap;
import android.graphics.Point;
import android.graphics.Rect;
import android.location.LocationManager;
import android.metrics.LogMaker;
import android.net.Proxy;
import android.net.ProxyInfo;
import android.net.Uri;
@@ -312,6 +313,7 @@ import android.view.WindowManager;
import com.google.android.collect.Lists;
import com.google.android.collect.Maps;
import com.android.internal.R;
import com.android.internal.annotations.GuardedBy;
import com.android.internal.app.AssistUtils;
@@ -322,6 +324,8 @@ import com.android.internal.app.IVoiceInteractor;
import com.android.internal.app.ProcessMap;
import com.android.internal.app.SystemUserHomeActivity;
import com.android.internal.app.procstats.ProcessStats;
import com.android.internal.logging.MetricsLogger;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.internal.os.BackgroundThread;
import com.android.internal.os.BatteryStatsImpl;
import com.android.internal.os.IResultReceiver;
@@ -6730,7 +6734,8 @@ public class ActivityManagerService extends IActivityManager.Stub
            ActivityStack stack = ActivityRecord.getStackLocked(token);
            if (stack != null) {
                ActivityRecord r =
                        mStackSupervisor.activityIdleInternalLocked(token, false, config);
                        mStackSupervisor.activityIdleInternalLocked(token, false /* fromTimeout */,
                                false /* processPausingActivities */, config);
                if (stopProfiling) {
                    if ((mProfileProc == r.app) && (mProfileFd != null)) {
                        try {
@@ -7610,7 +7615,8 @@ public class ActivityManagerService extends IActivityManager.Stub
                // Activity supports picture-in-picture, now check that we can enter PiP at this
                // point, if it is
                if (!r.checkEnterPictureInPictureState("enterPictureInPictureMode")) {
                if (!r.checkEnterPictureInPictureState("enterPictureInPictureMode",
                        false /* noThrow */)) {
                    return false;
                }
@@ -7625,6 +7631,10 @@ public class ActivityManagerService extends IActivityManager.Stub
                    mStackSupervisor.moveActivityToPinnedStackLocked(r, "enterPictureInPictureMode",
                            bounds, true /* moveHomeStackToFront */);
                    mStackSupervisor.getStack(PINNED_STACK_ID).setPictureInPictureActions(actions);
                    MetricsLogger.action(mContext, MetricsEvent.ACTION_PICTURE_IN_PICTURE_ENTERED,
                            r.supportsPictureInPictureWhilePausing);
                    logPictureInPictureArgs(args);
                };
                if (isKeyguardLocked()) {
@@ -7678,12 +7688,25 @@ public class ActivityManagerService extends IActivityManager.Stub
                    stack.setPictureInPictureAspectRatio(r.pictureInPictureArgs.getAspectRatio());
                    stack.setPictureInPictureActions(r.pictureInPictureArgs.getActions());
                }
                logPictureInPictureArgs(args);
            }
        } finally {
            Binder.restoreCallingIdentity(origId);
        }
    }
    private void logPictureInPictureArgs(PictureInPictureArgs args) {
        if (args.hasSetActions()) {
            MetricsLogger.histogram(mContext, "tron_varz_picture_in_picture_actions_count",
                    args.getActions().size());
        }
        if (args.hasSetAspectRatio()) {
            LogMaker lm = new LogMaker(MetricsEvent.ACTION_PICTURE_IN_PICTURE_ASPECT_RATIO_CHANGED);
            lm.addTaggedData(MetricsEvent.PICTURE_IN_PICTURE_ASPECT_RATIO, args.getAspectRatio());
            MetricsLogger.action(lm);
        }
    }
    private boolean isValidPictureInPictureAspectRatio(float aspectRatio) {
        return mMinPipAspectRatio <= aspectRatio && aspectRatio <= mMaxPipAspectRatio;
    }
+1 −1
Original line number Diff line number Diff line
@@ -2043,7 +2043,7 @@ final class ActivityManagerShellCommand extends ShellCommand {
            mInterface.stopLockTaskMode();
        } else {
            int taskId = Integer.parseInt(taskIdStr);
            mInterface.startLockTaskModeById(taskId);
            mInterface.startSystemLockTaskMode(taskId);
        }
        pw.println("Activity manager is " + (mInterface.isInLockTaskMode() ? "" : "not ") +
                "in lockTaskMode");
Loading