1 /*
2  * Copyright (C) 2021 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.NonNull;
20 import android.annotation.Nullable;
21 
22 import com.android.internal.util.AnnotationValidations;
23 
24 import java.util.Objects;
25 
26 /**
27  * An instances of this class represents a session of media recording.
28  */
29 public final class RecordingSession implements AutoCloseable {
30     private final @NonNull String mId;
31     private final @NonNull MediaMetricsManager mManager;
32     private final @NonNull LogSessionId mLogSessionId;
33     private boolean mClosed = false;
34 
35     /** @hide */
RecordingSession(@onNull String id, @NonNull MediaMetricsManager manager)36     public RecordingSession(@NonNull String id, @NonNull MediaMetricsManager manager) {
37         mId = id;
38         mManager = manager;
39         AnnotationValidations.validate(NonNull.class, null, mId);
40         AnnotationValidations.validate(NonNull.class, null, mManager);
41         mLogSessionId = new LogSessionId(mId);
42     }
43 
getSessionId()44     public @NonNull LogSessionId getSessionId() {
45         return mLogSessionId;
46     }
47 
48     @Override
equals(@ullable Object o)49     public boolean equals(@Nullable Object o) {
50         if (this == o) return true;
51         if (o == null || getClass() != o.getClass()) return false;
52         RecordingSession that = (RecordingSession) o;
53         return Objects.equals(mId, that.mId);
54     }
55 
56     @Override
hashCode()57     public int hashCode() {
58         return Objects.hash(mId);
59     }
60 
61     @Override
close()62     public void close() {
63         mClosed = true;
64         mManager.releaseSessionId(mLogSessionId.getStringId());
65     }
66 }
67