summaryrefslogtreecommitdiff
path: root/media/java/android/media/metrics/MediaMetricsManager.java
diff options
context:
space:
mode:
Diffstat (limited to 'media/java/android/media/metrics/MediaMetricsManager.java')
-rw-r--r--media/java/android/media/metrics/MediaMetricsManager.java115
1 files changed, 115 insertions, 0 deletions
diff --git a/media/java/android/media/metrics/MediaMetricsManager.java b/media/java/android/media/metrics/MediaMetricsManager.java
new file mode 100644
index 000000000000..f2eae5fad3c3
--- /dev/null
+++ b/media/java/android/media/metrics/MediaMetricsManager.java
@@ -0,0 +1,115 @@
+/*
+ * 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.SystemService;
+import android.content.Context;
+import android.os.RemoteException;
+
+/**
+ * This class gives information about, and interacts with media metrics.
+ */
+@SystemService(Context.MEDIA_METRICS_SERVICE)
+public class MediaMetricsManager {
+ // TODO: unhide APIs.
+ private static final String TAG = "MediaMetricsManager";
+
+ private IMediaMetricsManager mService;
+ private int mUserId;
+
+ /**
+ * @hide
+ */
+ public MediaMetricsManager(IMediaMetricsManager service, int userId) {
+ mService = service;
+ mUserId = userId;
+ }
+
+ /**
+ * Reports playback metrics.
+ * @hide
+ */
+ public void reportPlaybackMetrics(@NonNull String sessionId, PlaybackMetrics metrics) {
+ try {
+ mService.reportPlaybackMetrics(sessionId, metrics, mUserId);
+ } catch (RemoteException e) {
+ throw e.rethrowFromSystemServer();
+ }
+ }
+ /**
+ * Reports network event.
+ * @hide
+ */
+ public void reportNetworkEvent(@NonNull String sessionId, NetworkEvent event) {
+ try {
+ mService.reportNetworkEvent(sessionId, event, mUserId);
+ } catch (RemoteException e) {
+ throw e.rethrowFromSystemServer();
+ }
+ }
+
+ /**
+ * Reports playback state event.
+ * @hide
+ */
+ public void reportPlaybackStateEvent(@NonNull String sessionId, PlaybackStateEvent event) {
+ try {
+ mService.reportPlaybackStateEvent(sessionId, event, mUserId);
+ } catch (RemoteException e) {
+ throw e.rethrowFromSystemServer();
+ }
+ }
+
+ /**
+ * Reports track change event.
+ * @hide
+ */
+ public void reportTrackChangeEvent(@NonNull String sessionId, TrackChangeEvent event) {
+ try {
+ mService.reportTrackChangeEvent(sessionId, event, mUserId);
+ } catch (RemoteException e) {
+ throw e.rethrowFromSystemServer();
+ }
+ }
+
+ /**
+ * Creates a playback session.
+ */
+ @NonNull
+ public PlaybackSession createPlaybackSession() {
+ try {
+ String id = mService.getSessionId(mUserId);
+ PlaybackSession session = new PlaybackSession(id, this);
+ return session;
+ } catch (RemoteException e) {
+ throw e.rethrowFromSystemServer();
+ }
+ }
+
+ /**
+ * Reports error event.
+ * @hide
+ */
+ public void reportPlaybackErrorEvent(@NonNull String sessionId, PlaybackErrorEvent event) {
+ try {
+ mService.reportPlaybackErrorEvent(sessionId, event, mUserId);
+ } catch (RemoteException e) {
+ throw e.rethrowFromSystemServer();
+ }
+ }
+}