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

Commit e708e600 authored by shubang's avatar shubang
Browse files

Add initial playback metrics classes

Test: make;
Bug: 167036690
Change-Id: I78aa08374b45ffc86a3253037de724a2d3750977
parent 92c2f231
Loading
Loading
Loading
Loading
+27 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2020 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;

import android.media.metrics.PlaybackMetrics;

/**
 * Interface to the playback manager service.
 * @hide
 */
interface IPlaybackMetricsManager {
    void reportPlaybackMetrics(in PlaybackMetrics metrics, int userId);
}
 No newline at end of file
+3 −0
Original line number Diff line number Diff line
essick@google.com
nchalko@google.com
shubang@google.com
 No newline at end of file
+19 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2020 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;

parcelable PlaybackMetrics;
+88 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2020 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;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.os.Parcel;
import android.os.Parcelable;

import java.util.Objects;

/**
 * This class is used to store playback data.
 * @hide
 */
public final class PlaybackMetrics implements Parcelable {
    private int mStreamSourceType;

    /**
     * Creates a new PlaybackMetrics.
     *
     * @hide
     */
    public PlaybackMetrics(int streamSourceType) {
        this.mStreamSourceType = streamSourceType;
    }

    public int getStreamSourceType() {
        return mStreamSourceType;
    }

    @Override
    public boolean equals(@Nullable Object o) {

        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        PlaybackMetrics that = (PlaybackMetrics) o;
        return mStreamSourceType == that.mStreamSourceType;
    }

    @Override
    public int hashCode() {
        return Objects.hash(mStreamSourceType);
    }

    @Override
    public void writeToParcel(@NonNull Parcel dest, int flags) {
        dest.writeInt(mStreamSourceType);
    }

    @Override
    public int describeContents() {
        return 0;
    }

    /** @hide */
    /* package-private */ PlaybackMetrics(@NonNull Parcel in) {
        int streamSourceType = in.readInt();
        this.mStreamSourceType = streamSourceType;
    }

    public static final @NonNull Parcelable.Creator<PlaybackMetrics> CREATOR =
            new Parcelable.Creator<PlaybackMetrics>() {
                @Override
                public PlaybackMetrics[] newArray(int size) {
                    return new PlaybackMetrics[size];
                }

                @Override
                public PlaybackMetrics createFromParcel(@NonNull Parcel in) {
                    return new PlaybackMetrics(in);
                }
            };
}
+49 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2020 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;

import android.os.RemoteException;

/**
 * @hide
 */
public class PlaybackMetricsManager {
    // TODO: unhide APIs.
    private static final String TAG = "PlaybackMetricsManager";

    private IPlaybackMetricsManager mService;
    private int mUserId;

    /**
     * @hide
     */
    public PlaybackMetricsManager(IPlaybackMetricsManager service, int userId) {
        mService = service;
        mUserId = userId;
    }

    /**
     * Reports playback metrics.
     */
    public void reportPlaybackMetrics(PlaybackMetrics metrics) {
        try {
            mService.reportPlaybackMetrics(metrics, mUserId);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }
}
Loading