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.database.sqlite.SqliteWrapper; 21 22 import android.content.ContentResolver; 23 import android.content.ContentValues; 24 import android.content.Context; 25 import android.net.Uri; 26 import android.util.Log; 27 28 import java.io.IOException; 29 import java.io.OutputStream; 30 31 public class DrmUtils { 32 private static final String TAG = "DrmUtils"; 33 private static final Uri DRM_TEMP_URI = Uri.parse("content://mms/drm"); 34 DrmUtils()35 private DrmUtils() { 36 } 37 cleanupStorage(Context context)38 public static void cleanupStorage(Context context) { 39 SqliteWrapper.delete(context, context.getContentResolver(), 40 DRM_TEMP_URI, null, null); 41 } 42 insert(Context context, DrmWrapper drmObj)43 public static Uri insert(Context context, DrmWrapper drmObj) 44 throws IOException { 45 ContentResolver cr = context.getContentResolver(); 46 Uri uri = SqliteWrapper.insert(context, cr, DRM_TEMP_URI, 47 new ContentValues(0)); 48 OutputStream os = null; 49 try { 50 os = cr.openOutputStream(uri); 51 byte[] data = drmObj.getDecryptedData(); 52 if (data != null) { 53 os.write(data); 54 } 55 return uri; 56 } finally { 57 if (os != null) { 58 try { 59 os.close(); 60 } catch (IOException e) { 61 Log.e(TAG, e.getMessage(), e); 62 } 63 } 64 } 65 } 66 } 67