1 /* 2 * Copyright (C) 2020 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package android.media.metrics; 18 19 import android.annotation.IntRange; 20 import android.annotation.NonNull; 21 import android.os.Bundle; 22 23 /** 24 * Abstract class for metrics events. 25 */ 26 public abstract class Event { 27 final long mTimeSinceCreatedMillis; 28 Bundle mMetricsBundle = new Bundle(); 29 30 // hide default constructor Event()31 /* package */ Event() { 32 mTimeSinceCreatedMillis = MediaMetricsManager.INVALID_TIMESTAMP; 33 } 34 Event(long timeSinceCreatedMillis, Bundle extras)35 /* package */ Event(long timeSinceCreatedMillis, Bundle extras) { 36 mTimeSinceCreatedMillis = timeSinceCreatedMillis; 37 mMetricsBundle = extras; 38 } 39 40 /** 41 * Gets time since the corresponding log session is created in millisecond. 42 * @return the timestamp since the instance is created, or -1 if unknown. 43 * @see LogSessionId 44 * @see PlaybackSession 45 * @see RecordingSession 46 */ 47 @IntRange(from = -1) getTimeSinceCreatedMillis()48 public long getTimeSinceCreatedMillis() { 49 return mTimeSinceCreatedMillis; 50 } 51 52 /** 53 * Gets metrics-related information that is not supported by dedicated methods. 54 * <p>It is intended to be used for backwards compatibility by the metrics infrastructure. 55 */ 56 @NonNull getMetricsBundle()57 public Bundle getMetricsBundle() { 58 return mMetricsBundle; 59 } 60 } 61