@@ -0,0 +1,2318 @@
+/*%0A * Copyright (C) 2019 The Android Open Source Project%0A *%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A *      http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0Apackage com.google.android.exoplayer2.drm;%0A%0A/**%0A * A reference-counted resource used in the decryption of media samples.%0A *%0A * @param %3CT%3E The reference type with which to make %7B@link Owner#onLastReferenceReleased%7D calls.%0A */%0Apublic abstract class CryptoResource%3CT extends CryptoResource%3CT%3E%3E %7B%0A%0A  /**%0A   * Implemented by the class in charge of managing a %7B@link CryptoResource resource's%7D lifecycle.%0A   */%0A  public interface Owner%3CT extends CryptoResource%3CT%3E%3E %7B%0A%0A    /**%0A     * Called when the last reference to a %7B@link CryptoResource%7D is %7B@link #releaseReference()%0A     * released%7D.%0A     */%0A    void onLastReferenceReleased(CryptoResource%3CT%3E resource);%0A  %7D%0A%0A  // TODO: Consider adding a handler on which the owner should be called.%0A  private final CryptoResource.Owner%3CT%3E owner;%0A  private int referenceCount;%0A%0A  /**%0A   * Creates a new instance with no incoming references.%0A   *%0A   * @param owner The owner of this instance.%0A   */%0A  public CryptoResource(Owner%3CT%3E owner) %7B%0A    this.owner = owner;%0A    referenceCount = 0;%0A  %7D%0A%0A  /** Increases by one the incoming reference count for this resource. */%0A  public void acquireReference() %7B%0A    referenceCount++;%0A  %7D%0A%0A  /**%0A   * Decreases by one the incoming reference count for this resource, and notifies the owner if said%0A   * count reached zero as a result of this operation.%0A   *%0A   * %3Cp%3EMust only be called as releasing counter-part of %7B@link #acquireReference()%7D.%0A   */%0A  @SuppressWarnings(%22unchecked%22)%0A  public synchronized void releaseReference() %7B%0A    if (--referenceCount == 0) %7B%0A      owner.onLastReferenceReleased(this);%0A    %7D else if (referenceCount %3C 0) %7B%0A      throw new IllegalStateException(%22Illegal release of resource.%22);%0A    %7D%0A  %7D%0A%7D%0A

Add abstract superclass for Crypto resources