1 /* 2 * Copyright (C) 2008 Esmertec AG. 3 * Copyright (C) 2008 The Android Open Source Project 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18 package com.android.mms.drm; 19 20 import android.drm.*; 21 import android.net.Uri; 22 import android.util.Log; 23 24 import java.io.File; 25 import java.io.FileInputStream; 26 import java.io.FileOutputStream; 27 import java.io.IOException; 28 import java.io.RandomAccessFile; 29 30 import com.android.mms.MmsApp; 31 32 public class DrmUtils { 33 private static final String TAG = "DrmUtils"; 34 35 /** The MIME type of special DRM files */ 36 private static final String EXTENSION_ANDROID_FWDL = ".fl"; 37 DrmUtils()38 private DrmUtils() { 39 } 40 getConvertExtension(String mimetype)41 public static String getConvertExtension(String mimetype) { 42 return EXTENSION_ANDROID_FWDL; 43 } 44 isDrmType(String mimeType)45 public static boolean isDrmType(String mimeType) { 46 boolean result = false; 47 DrmManagerClient drmManagerClient = MmsApp.getApplication().getDrmManagerClient(); 48 if (drmManagerClient != null) { 49 try { 50 if (drmManagerClient.canHandle("", mimeType)) { 51 result = true; 52 } 53 } catch (IllegalArgumentException ex) { 54 Log.w(TAG, "canHandle called with wrong parameters"); 55 } catch (IllegalStateException ex) { 56 Log.w(TAG, "DrmManagerClient didn't initialize properly"); 57 } 58 } 59 return result; 60 } 61 62 /** 63 * Check if content may be forwarded according to DRM 64 * 65 * @param uri Uri to content 66 * @return true if the content may be forwarded 67 */ haveRightsForAction(Uri uri, int action)68 public static boolean haveRightsForAction(Uri uri, int action) { 69 DrmManagerClient drmManagerClient = MmsApp.getApplication().getDrmManagerClient(); 70 71 try { 72 // first check if the URI is registered as DRM in DRM-framework 73 if (drmManagerClient.canHandle(uri.toString(), null)) { 74 int check = drmManagerClient.checkRightsStatus(uri.toString(), action); 75 return (check == DrmStore.RightsStatus.RIGHTS_VALID); 76 } 77 } catch (Exception e) { 78 // Ignore exception and assume it is OK to forward file. 79 } finally { 80 } 81 return true; 82 } 83 } 84