Home | History | Annotate | Download | only in drm
      1 /*
      2  * Copyright (C) 2007 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package com.android.providers.drm;
     18 
     19 import java.io.ByteArrayInputStream;
     20 import java.io.IOException;
     21 
     22 import android.drm.mobile1.DrmException;
     23 import android.drm.mobile1.DrmRights;
     24 import android.drm.mobile1.DrmRightsManager;
     25 import static android.provider.Telephony.Sms.Intents.WAP_PUSH_RECEIVED_ACTION;
     26 
     27 import android.content.Context;
     28 import android.content.Intent;
     29 import android.content.BroadcastReceiver;
     30 import android.util.Log;
     31 
     32 public class DrmPushReceiver extends BroadcastReceiver {
     33     private static final String TAG = "DrmPushReceiver";
     34 
     35     @Override
     36     public void onReceive(Context context, Intent intent) {
     37         if (intent.getAction().equals(WAP_PUSH_RECEIVED_ACTION)) {
     38             // Get right mimetype.
     39             String rightMimeType = intent.getType();
     40             if (DrmRightsManager.DRM_MIMETYPE_RIGHTS_XML_STRING.equals(rightMimeType) ||
     41                 DrmRightsManager.DRM_MIMETYPE_RIGHTS_WBXML_STRING.equals(rightMimeType)) {
     42                 // Get right data.
     43                 byte[] rightData = (byte[]) intent.getExtra("data");
     44                 if (rightData == null) {
     45                     Log.e(TAG, "The rights data is invalid.");
     46                     return;
     47                 }
     48                 ByteArrayInputStream rightDataStream = new ByteArrayInputStream(rightData);
     49                 try {
     50                     DrmRightsManager.getInstance().installRights(rightDataStream,
     51                             rightData.length,
     52                             rightMimeType);
     53                 } catch (DrmException e) {
     54                     Log.e(TAG, "Install drm rights failed.");
     55                     return;
     56                 } catch (IOException e) {
     57                     Log.e(TAG, "IOException occurs when install drm rights.");
     58                     return;
     59                 }
     60 
     61                 Log.d(TAG, "Install drm rights successfully.");
     62                 return;
     63             }
     64             Log.d(TAG, "This is not drm rights push mimetype.");
     65         }
     66         Log.d(TAG, "This is not wap push received action.");
     67     }
     68 }
     69