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 editing.
28   */
29  public final class EditingSession implements AutoCloseable {
30      private final @NonNull String mId;
31      private final @NonNull MediaMetricsManager mManager;
32      private final @NonNull LogSessionId mLogSessionId;
33  
34      /** @hide */
EditingSession(@onNull String id, @NonNull MediaMetricsManager manager)35      public EditingSession(@NonNull String id, @NonNull MediaMetricsManager manager) {
36          mId = id;
37          mManager = manager;
38          AnnotationValidations.validate(NonNull.class, null, mId);
39          AnnotationValidations.validate(NonNull.class, null, mManager);
40          mLogSessionId = new LogSessionId(mId);
41      }
42  
getSessionId()43      public @NonNull LogSessionId getSessionId() {
44          return mLogSessionId;
45      }
46  
47      @Override
equals(@ullable Object o)48      public boolean equals(@Nullable Object o) {
49          if (this == o) return true;
50          if (o == null || getClass() != o.getClass()) return false;
51          EditingSession that = (EditingSession) o;
52          return Objects.equals(mId, that.mId);
53      }
54  
55      @Override
hashCode()56      public int hashCode() {
57          return Objects.hash(mId);
58      }
59  
60      @Override
close()61      public void close() {
62          mManager.releaseSessionId(mLogSessionId.getStringId());
63      }
64  }
65