• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.DrmManagerClient;
21 import android.drm.DrmStore;
22 import android.net.Uri;
23 import android.util.Log;
24 
25 import com.android.mms.LogTag;
26 import com.android.mms.MmsApp;
27 
28 public class DrmUtils {
29     private static final String TAG = LogTag.TAG;
30 
31     /** The MIME type of special DRM files */
32     private static final String EXTENSION_ANDROID_FWDL = ".fl";
33 
DrmUtils()34     private DrmUtils() {
35     }
36 
getConvertExtension(String mimetype)37     public static String getConvertExtension(String mimetype) {
38         return EXTENSION_ANDROID_FWDL;
39     }
40 
isDrmType(String mimeType)41     public static boolean isDrmType(String mimeType) {
42         boolean result = false;
43         DrmManagerClient drmManagerClient = MmsApp.getApplication().getDrmManagerClient();
44         if (drmManagerClient != null) {
45             try {
46                 if (drmManagerClient.canHandle("", mimeType)) {
47                     result = true;
48                 }
49             } catch (IllegalArgumentException ex) {
50                 Log.w(TAG, "canHandle called with wrong parameters");
51             } catch (IllegalStateException ex) {
52                 Log.w(TAG, "DrmManagerClient didn't initialize properly");
53             }
54         }
55         return result;
56     }
57 
58     /**
59      * Check if content may be forwarded according to DRM
60      *
61      * @param uri Uri to content
62      * @return true if the content may be forwarded
63      */
haveRightsForAction(Uri uri, int action)64     public static boolean haveRightsForAction(Uri uri, int action) {
65         DrmManagerClient drmManagerClient = MmsApp.getApplication().getDrmManagerClient();
66 
67         try {
68             // first check if the URI is registered as DRM in DRM-framework
69             if (drmManagerClient.canHandle(uri.toString(), null)) {
70                 int check = drmManagerClient.checkRightsStatus(uri.toString(), action);
71                 return (check == DrmStore.RightsStatus.RIGHTS_VALID);
72             }
73         } catch (Exception e) {
74             // Ignore exception and assume it is OK to forward file.
75         } finally {
76         }
77         return true;
78     }
79 }
80