// Path: playerSDK/src/main/java/com/kaltura/playersdk/helpers/KStringUtilities.java
// @NonNull
// public static String toHexString(byte[] bytes) {
//     // Create Hex String
//     StringBuilder hexString = new StringBuilder();
//     for (byte b : bytes) {
//         String h = Integer.toHexString(0xFF & b);
//         hexString.append(h.length() == 1 ? "0" : "").append(h);
//     }
//     return hexString.toString();
// }


import android.annotation.TargetApi;
import android.media.MediaCrypto;
import android.media.MediaCryptoException;
import android.media.MediaDrm;
import android.media.NotProvisionedException;
import android.media.UnsupportedSchemeException;
import android.os.Build;
import android.support.annotation.NonNull;
import android.util.Log;
import com.google.android.exoplayer.drm.DrmInitData;
import com.google.android.exoplayer.drm.DrmSessionManager;
import com.google.android.exoplayer.drm.UnsupportedDrmException;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
import static com.google.android.libraries.mediaframework.exoplayerextensions.ExoplayerUtil.WIDEVINE_UUID;
import static com.kaltura.playersdk.helpers.KStringUtilities.toHexString;
package com.kaltura.playersdk.drm;





/**
 * Created by noamt on 04/05/2016.
 */
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
class OfflineDrmSessionManager implements DrmSessionManager {


    private static final String TAG = "OfflineDrmSessionMgr";

    private final MediaDrm mMediaDrm;
    private final OfflineKeySetStorage mStorage;
    private MediaCrypto mMediaCrypto;
    private MediaDrmSession mSession;
    private int mState = STATE_CLOSED;
    private Exception mLastError;
    private AtomicInteger mOpenCount = new AtomicInteger(0);

    OfflineDrmSessionManager(OfflineKeySetStorage storage) throws UnsupportedDrmException {

        mStorage = storage;

        try {
            mMediaDrm = new MediaDrm(WIDEVINE_UUID);
            OfflineDrmManager.printAllProperties(mMediaDrm);

            mMediaDrm.setOnEventListener(new MediaDrm.OnEventListener() {
                @Override
                public void onEvent(@NonNull MediaDrm md, byte[] sessionId, int event, int extra, byte[] data) {
// Path: playerSDK/src/main/java/com/kaltura/playersdk/helpers/KStringUtilities.java
// @NonNull
// public static String toHexString(byte[] bytes) {
//     // Create Hex String
//     StringBuilder hexString = new StringBuilder();
//     for (byte b : bytes) {
//         String h = Integer.toHexString(0xFF & b);
//         hexString.append(h.length() == 1 ? "0" : "").append(h);
//     }
//     return hexString.toString();
// }


// Path: playerSDK/src/main/java/com/kaltura/playersdk/drm/OfflineDrmSessionManager.java
import android.annotation.TargetApi;
import android.media.MediaCrypto;
import android.media.MediaCryptoException;
import android.media.MediaDrm;
import android.media.NotProvisionedException;
import android.media.UnsupportedSchemeException;
import android.os.Build;
import android.support.annotation.NonNull;
import android.util.Log;
import com.google.android.exoplayer.drm.DrmInitData;
import com.google.android.exoplayer.drm.DrmSessionManager;
import com.google.android.exoplayer.drm.UnsupportedDrmException;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
import static com.google.android.libraries.mediaframework.exoplayerextensions.ExoplayerUtil.WIDEVINE_UUID;
import static com.kaltura.playersdk.helpers.KStringUtilities.toHexString;

package com.kaltura.playersdk.drm;





/**
 * Created by noamt on 04/05/2016.
 */
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
class OfflineDrmSessionManager implements DrmSessionManager {


    private static final String TAG = "OfflineDrmSessionMgr";

    private final MediaDrm mMediaDrm;
    private final OfflineKeySetStorage mStorage;
    private MediaCrypto mMediaCrypto;
    private MediaDrmSession mSession;
    private int mState = STATE_CLOSED;
    private Exception mLastError;
    private AtomicInteger mOpenCount = new AtomicInteger(0);

    OfflineDrmSessionManager(OfflineKeySetStorage storage) throws UnsupportedDrmException {

        mStorage = storage;

        try {
            mMediaDrm = new MediaDrm(WIDEVINE_UUID);
            OfflineDrmManager.printAllProperties(mMediaDrm);

            mMediaDrm.setOnEventListener(new MediaDrm.OnEventListener() {
                @Override
                public void onEvent(@NonNull MediaDrm md, byte[] sessionId, int event, int extra, byte[] data) {
                    Log.d(TAG, "onEvent:" + toHexString(sessionId) + ":" + event + ":" + extra + ":" + toHexString(data));