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

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

Merge "Add 1.extras, 2.recording session, 3.ID wrapper to MediaMetrics" into sc-dev

parents 5632ba9e b4d741a2
Loading
Loading
Loading
Loading
+14 −1
Original line number Diff line number Diff line
@@ -17,22 +17,30 @@
package android.media.metrics;

import android.annotation.IntRange;
import android.os.Bundle;

/**
 * Abstract class for metrics events.
 */
public abstract class Event {
    private final long mTimeSinceCreatedMillis;
    final long mTimeSinceCreatedMillis;
    Bundle mExtras;

    // hide default constructor
    /* package */ Event() {
        mTimeSinceCreatedMillis = MediaMetricsManager.INVALID_TIMESTAMP;
    }

    // TODO: remove
    protected Event(long timeSinceCreatedMillis) {
        mTimeSinceCreatedMillis = timeSinceCreatedMillis;
    }

    /* package */ Event(long timeSinceCreatedMillis, Bundle extras) {
        mTimeSinceCreatedMillis = timeSinceCreatedMillis;
        mExtras = extras;
    }

    /**
     * Gets time since the corresponding instance is created in millisecond.
     * @return the timestamp since the instance is created, or -1 if unknown.
@@ -41,4 +49,9 @@ public abstract class Event {
    public long getTimeSinceCreatedMillis() {
        return mTimeSinceCreatedMillis;
    }

    /** @hide */
    public Bundle getExtras() {
        return mExtras;
    }
}
+2 −1
Original line number Diff line number Diff line
@@ -28,7 +28,8 @@ import android.media.metrics.TrackChangeEvent;
 */
interface IMediaMetricsManager {
    void reportPlaybackMetrics(in String sessionId, in PlaybackMetrics metrics, int userId);
    String getSessionId(int userId);
    String getPlaybackSessionId(int userId);
    String getRecordingSessionId(int userId);
    void reportNetworkEvent(in String sessionId, in NetworkEvent event, int userId);
    void reportPlaybackErrorEvent(in String sessionId, in PlaybackErrorEvent event, int userId);
    void reportPlaybackStateEvent(in String sessionId, in PlaybackStateEvent event, int userId);
+34 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2021 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 android.media.metrics;

/**
 * An instances of this class represents the ID of a log session.
 * @hide
 */
public class LogSessionId {
    private final String mSessionId;

    /* package */ LogSessionId(String id) {
        mSessionId = id;
    }

    /** @hide */
    public String getStringId() {
        return mSessionId;
    }
}
+16 −1
Original line number Diff line number Diff line
@@ -94,7 +94,7 @@ public class MediaMetricsManager {
    @NonNull
    public PlaybackSession createPlaybackSession() {
        try {
            String id = mService.getSessionId(mUserId);
            String id = mService.getPlaybackSessionId(mUserId);
            PlaybackSession session = new PlaybackSession(id, this);
            return session;
        } catch (RemoteException e) {
@@ -102,6 +102,21 @@ public class MediaMetricsManager {
        }
    }

    /**
     * Creates a recording session.
     * @hide
     */
    @NonNull
    public RecordingSession createRecordingSession() {
        try {
            String id = mService.getRecordingSessionId(mUserId);
            RecordingSession session = new RecordingSession(id, this);
            return session;
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    /**
     * Reports error event.
     * @hide
+33 −3
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import android.annotation.IntDef;
import android.annotation.IntRange;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.os.Bundle;
import android.os.Parcel;
import android.os.Parcelable;

@@ -33,6 +34,9 @@ import java.util.Objects;
public final class NetworkEvent extends Event implements Parcelable {
    /** Network type is not specified. Default type. */
    public static final int NETWORK_TYPE_NONE = 0;
    // TODO: replace NONE with UNKNOWN
    /** @hide */
    public static final int NETWORK_TYPE_UNKNOWN = 0;
    /** Other network type */
    public static final int NETWORK_TYPE_OTHER = 1;
    /** Wi-Fi network */
@@ -49,6 +53,9 @@ public final class NetworkEvent extends Event implements Parcelable {
    public static final int NETWORK_TYPE_5G_NSA = 7;
    /** 5G SA network */
    public static final int NETWORK_TYPE_5G_SA = 8;
    /** Not network connected */
    /** @hide */
    public static final int NETWORK_TYPE_OFFLINE = 9;

    private final int mNetworkType;
    private final long mTimeSinceCreatedMillis;
@@ -56,6 +63,7 @@ public final class NetworkEvent extends Event implements Parcelable {
    /** @hide */
    @IntDef(prefix = "NETWORK_TYPE_", value = {
        NETWORK_TYPE_NONE,
        NETWORK_TYPE_UNKNOWN,
        NETWORK_TYPE_OTHER,
        NETWORK_TYPE_WIFI,
        NETWORK_TYPE_ETHERNET,
@@ -63,7 +71,8 @@ public final class NetworkEvent extends Event implements Parcelable {
        NETWORK_TYPE_3G,
        NETWORK_TYPE_4G,
        NETWORK_TYPE_5G_NSA,
        NETWORK_TYPE_5G_SA
        NETWORK_TYPE_5G_SA,
        NETWORK_TYPE_OFFLINE
    })
    @Retention(RetentionPolicy.SOURCE)
    public @interface NetworkType {}
@@ -92,6 +101,8 @@ public final class NetworkEvent extends Event implements Parcelable {
                return "NETWORK_TYPE_5G_NSA";
            case NETWORK_TYPE_5G_SA:
                return "NETWORK_TYPE_5G_SA";
            case NETWORK_TYPE_OFFLINE:
                return "NETWORK_TYPE_OFFLINE";
            default:
                return Integer.toHexString(value);
        }
@@ -102,9 +113,10 @@ public final class NetworkEvent extends Event implements Parcelable {
     *
     * @hide
     */
    public NetworkEvent(@NetworkType int type, long timeSinceCreatedMillis) {
    public NetworkEvent(@NetworkType int type, long timeSinceCreatedMillis, Bundle extras) {
        this.mNetworkType = type;
        this.mTimeSinceCreatedMillis = timeSinceCreatedMillis;
        this.mExtras = extras.deepCopy();
    }

    /**
@@ -149,8 +161,12 @@ public final class NetworkEvent extends Event implements Parcelable {

    @Override
    public void writeToParcel(@NonNull android.os.Parcel dest, int flags) {
        byte flg = 0;
        if (mExtras != null) flg |= 0x1;
        dest.writeByte(flg);
        dest.writeInt(mNetworkType);
        dest.writeLong(mTimeSinceCreatedMillis);
        if (mExtras != null) dest.writeBundle(mExtras);
    }

    @Override
@@ -160,11 +176,14 @@ public final class NetworkEvent extends Event implements Parcelable {

    /** @hide */
    /* package-private */ NetworkEvent(@NonNull android.os.Parcel in) {
        byte flg = in.readByte();
        int type = in.readInt();
        long timeSinceCreatedMillis = in.readLong();
        Bundle extras = (flg & 0x2) == 0 ? null : in.readBundle();

        this.mNetworkType = type;
        this.mTimeSinceCreatedMillis = timeSinceCreatedMillis;
        this.mExtras = extras;
    }

    /**
@@ -189,6 +208,7 @@ public final class NetworkEvent extends Event implements Parcelable {
    public static final class Builder {
        private int mNetworkType = NETWORK_TYPE_NONE;
        private long mTimeSinceCreatedMillis = -1;
        private Bundle mExtras;

        /**
         * Creates a new Builder.
@@ -214,9 +234,19 @@ public final class NetworkEvent extends Event implements Parcelable {
            return this;
        }

        /**
         * Set extras for compatibility.
         * <p>Should be used by support library only.
         * @hide
         */
        public @NonNull Builder setExtras(@NonNull Bundle extras) {
            mExtras = extras;
            return this;
        }

        /** Builds the instance. */
        public @NonNull NetworkEvent build() {
            NetworkEvent o = new NetworkEvent(mNetworkType, mTimeSinceCreatedMillis);
            NetworkEvent o = new NetworkEvent(mNetworkType, mTimeSinceCreatedMillis, mExtras);
            return o;
        }
    }
Loading