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

Commit 9683b889 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "add atom and logging for Picture-in-Picture feature"

parents 1f62f7c7 52cacc6c
Loading
Loading
Loading
Loading
+26 −0
Original line number Diff line number Diff line
@@ -85,6 +85,7 @@ message Atom {
        AppStartCancelChanged app_start_cancel_changed = 49;
        AppStartFullyDrawnChanged app_start_fully_drawn_changed = 50;
        LmkEventOccurred lmk_event_occurred = 51;
        PictureInPictureStateChanged picture_in_picture_state_changed = 52;
        // TODO: Reorder the numbering so that the most frequent occur events occur in the first 15.
    }

@@ -937,6 +938,31 @@ message AppStartFullyDrawnChanged {
    optional int64 app_startup_time_ms = 6;
}

/**
 * Logs a picture-in-picture action
 * Logged from:
 *      frameworks/base/services/core/java/com/android/server/am/ActivityManagerService.java
 *      frameworks/base/services/core/java/com/android/server/am/ActivityStackSupervisor.java
 *      frameworks/base/packages/SystemUI/src/com/android/systemui/pip/phone/PipTouchHandler.java
 */
message PictureInPictureStateChanged {
    optional int32 uid = 1;

    optional string package_name = 2;

    optional string class_name = 3;

    // Picture-in-Picture action occurred, similar to
    // frameworks/base/proto/src/metrics_constants.proto
    enum State {
        ENTERED = 1;
        EXPANDED_TO_FULL_SCREEN = 2;
        MINIMIZED = 3;
        DISMISSED = 4;
    }
    optional State state = 4;
}

/**
 * Pulls bytes transferred via wifi (Sum of foreground and background usage).
 *
+99 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2018 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.internal.os.logging;

import android.content.Context;
import android.util.StatsLog;

import com.android.internal.logging.MetricsLogger;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;

/**
 * Used to wrap different logging calls in one, so that client side code base is clean and more
 * readable.
 */
public class MetricsLoggerWrapper {

    private static final int METRIC_VALUE_DISMISSED_BY_TAP = 0;
    private static final int METRIC_VALUE_DISMISSED_BY_DRAG = 1;

    public static void logPictureInPictureDismissByTap(Context context) {
        MetricsLogger.action(context, MetricsEvent.ACTION_PICTURE_IN_PICTURE_DISMISSED,
                METRIC_VALUE_DISMISSED_BY_TAP);
        StatsLog.write(StatsLog.PICTURE_IN_PICTURE_STATE_CHANGED,
                context.getUserId(),
                context.getApplicationInfo().packageName,
                context.getApplicationInfo().className,
                StatsLog.PICTURE_IN_PICTURE_STATE_CHANGED__STATE__DISMISSED);
    }

    public static void logPictureInPictureDismissByDrag(Context context) {
        MetricsLogger.action(context,
                MetricsEvent.ACTION_PICTURE_IN_PICTURE_DISMISSED,
                METRIC_VALUE_DISMISSED_BY_DRAG);
        StatsLog.write(StatsLog.PICTURE_IN_PICTURE_STATE_CHANGED,
                context.getUserId(),
                context.getApplicationInfo().packageName,
                context.getApplicationInfo().className,
                StatsLog.PICTURE_IN_PICTURE_STATE_CHANGED__STATE__DISMISSED);
    }

    public static void logPictureInPictureMinimize(Context context, boolean isMinimized) {
        MetricsLogger.action(context, MetricsEvent.ACTION_PICTURE_IN_PICTURE_MINIMIZED,
                isMinimized);
        if (isMinimized) {
            StatsLog.write(StatsLog.PICTURE_IN_PICTURE_STATE_CHANGED,
                    context.getUserId(),
                    context.getApplicationInfo().packageName,
                    context.getApplicationInfo().className,
                    StatsLog.PICTURE_IN_PICTURE_STATE_CHANGED__STATE__MINIMIZED);
        } else {
            StatsLog.write(StatsLog.PICTURE_IN_PICTURE_STATE_CHANGED,
                    context.getUserId(),
                    context.getApplicationInfo().packageName,
                    context.getApplicationInfo().className,
                    StatsLog.PICTURE_IN_PICTURE_STATE_CHANGED__STATE__EXPANDED_TO_FULL_SCREEN);
        }
    }

    public static void logPictureInPictureMenuVisible(Context context, boolean menuStateFull) {
        MetricsLogger.visibility(context, MetricsEvent.ACTION_PICTURE_IN_PICTURE_MENU,
                menuStateFull);
    }

    public static void logPictureInPictureEnter(Context context,
            boolean supportsEnterPipOnTaskSwitch) {
        MetricsLogger.action(context, MetricsEvent.ACTION_PICTURE_IN_PICTURE_ENTERED,
                supportsEnterPipOnTaskSwitch);
        if (supportsEnterPipOnTaskSwitch) {
            StatsLog.write(StatsLog.PICTURE_IN_PICTURE_STATE_CHANGED, context.getUserId(),
                    context.getApplicationInfo().packageName,
                    context.getApplicationInfo().className,
                    StatsLog.PICTURE_IN_PICTURE_STATE_CHANGED__STATE__ENTERED);
        }
    }

    public static void logPictureInPictureFullScreen(Context context) {
        MetricsLogger.action(context,
                MetricsEvent.ACTION_PICTURE_IN_PICTURE_EXPANDED_TO_FULLSCREEN);
        StatsLog.write(StatsLog.PICTURE_IN_PICTURE_STATE_CHANGED,
                context.getUserId(),
                context.getApplicationInfo().packageName,
                context.getApplicationInfo().className,
                StatsLog.PICTURE_IN_PICTURE_STATE_CHANGED__STATE__EXPANDED_TO_FULL_SCREEN);
    }
}
+5 −15
Original line number Diff line number Diff line
@@ -42,9 +42,8 @@ import android.view.accessibility.AccessibilityEvent;
import android.view.accessibility.AccessibilityManager;
import android.view.accessibility.AccessibilityNodeInfo;
import android.view.accessibility.AccessibilityWindowInfo;

import com.android.internal.logging.MetricsLogger;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.internal.os.logging.MetricsLoggerWrapper;
import com.android.internal.policy.PipSnapAlgorithm;
import com.android.systemui.R;
import com.android.systemui.statusbar.FlingAnimationUtils;
@@ -63,10 +62,6 @@ public class PipTouchHandler {
    // Allow the PIP to be flung from anywhere on the screen to the bottom to be dismissed.
    private static final boolean ENABLE_FLING_DISMISS = 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 int SHOW_DISMISS_AFFORDANCE_DELAY = 225;

    // Allow dragging the PIP to a location to close it
@@ -163,8 +158,7 @@ public class PipTouchHandler {
        @Override
        public void onPipDismiss() {
            mMotionHelper.dismissPip();
            MetricsLogger.action(mContext, MetricsEvent.ACTION_PICTURE_IN_PICTURE_DISMISSED,
                    METRIC_VALUE_DISMISSED_BY_TAP);
            MetricsLoggerWrapper.logPictureInPictureDismissByTap(mContext);
        }

        @Override
@@ -463,8 +457,7 @@ public class PipTouchHandler {
            return;
        }
        if (mIsMinimized != isMinimized) {
            MetricsLogger.action(mContext, MetricsEvent.ACTION_PICTURE_IN_PICTURE_MINIMIZED,
                    isMinimized);
            MetricsLoggerWrapper.logPictureInPictureMinimize(mContext, isMinimized);
        }
        mIsMinimized = isMinimized;
        mSnapAlgorithm.setMinimized(isMinimized);
@@ -537,8 +530,7 @@ public class PipTouchHandler {
        mMenuState = menuState;
        updateMovementBounds(menuState);
        if (menuState != MENU_STATE_CLOSE) {
            MetricsLogger.visibility(mContext, MetricsEvent.ACTION_PICTURE_IN_PICTURE_MENU,
                    menuState == MENU_STATE_FULL);
            MetricsLoggerWrapper.logPictureInPictureMenuVisible(mContext, menuState == MENU_STATE_FULL);
        }
    }

@@ -670,9 +662,7 @@ public class PipTouchHandler {
                if (mMotionHelper.shouldDismissPip() || isFlingToBot) {
                    mMotionHelper.animateDismiss(mMotionHelper.getBounds(), vel.x,
                        vel.y, mUpdateScrimListener);
                    MetricsLogger.action(mContext,
                            MetricsEvent.ACTION_PICTURE_IN_PICTURE_DISMISSED,
                            METRIC_VALUE_DISMISSED_BY_DRAG);
                    MetricsLoggerWrapper.logPictureInPictureDismissByDrag(mContext);
                    return true;
                }
            }
+2 −2
Original line number Diff line number Diff line
@@ -396,6 +396,7 @@ import com.android.internal.notification.SystemNotificationChannels;
import com.android.internal.os.BackgroundThread;
import com.android.internal.os.BatteryStatsImpl;
import com.android.internal.os.BinderInternal;
import com.android.internal.os.logging.MetricsLoggerWrapper;
import com.android.internal.os.ByteTransferPipe;
import com.android.internal.os.IResultReceiver;
import com.android.internal.os.ProcessCpuTracker;
@@ -8391,8 +8392,7 @@ public class ActivityManagerService extends IActivityManager.Stub
                    stack.setPictureInPictureAspectRatio(aspectRatio);
                    stack.setPictureInPictureActions(actions);
                    MetricsLogger.action(mContext, MetricsEvent.ACTION_PICTURE_IN_PICTURE_ENTERED,
                            r.supportsEnterPipOnTaskSwitch);
                    MetricsLoggerWrapper.logPictureInPictureEnter(mContext, r.supportsEnterPipOnTaskSwitch);
                    logPictureInPictureArgs(params);
                };
+2 −3
Original line number Diff line number Diff line
@@ -167,7 +167,7 @@ import android.view.RemoteAnimationAdapter;

import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.content.ReferrerIntent;
import com.android.internal.logging.MetricsLogger;
import com.android.internal.os.logging.MetricsLoggerWrapper;
import com.android.internal.os.TransferPipe;
import com.android.internal.util.ArrayUtils;
import com.android.server.LocalServices;
@@ -2620,8 +2620,7 @@ public class ActivityStackSupervisor extends ConfigurationContainer implements D
                mAllowDockedStackResize = false;
            } else if (inPinnedWindowingMode && onTop) {
                // Log if we are expanding the PiP to fullscreen
                MetricsLogger.action(mService.mContext,
                        ACTION_PICTURE_IN_PICTURE_EXPANDED_TO_FULLSCREEN);
                MetricsLoggerWrapper.logPictureInPictureFullScreen(mService.mContext);
            }

            // If we are moving from the pinned stack, then the animation takes care of updating