• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2013 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.internal.telephony;
18 
19 import android.Manifest;
20 import android.app.Activity;
21 import android.app.AppOpsManager;
22 import android.content.Context;
23 import android.content.Intent;
24 import android.os.Message;
25 import android.os.UserHandle;
26 import android.provider.Telephony;
27 import android.telephony.SubscriptionManager;
28 import android.telephony.SmsCbMessage;
29 
30 /**
31  * Dispatch new Cell Broadcasts to receivers. Acquires a private wakelock until the broadcast
32  * completes and our result receiver is called.
33  */
34 public class CellBroadcastHandler extends WakeLockStateMachine {
35 
CellBroadcastHandler(Context context, Phone phone)36     private CellBroadcastHandler(Context context, Phone phone) {
37         this("CellBroadcastHandler", context, phone);
38     }
39 
CellBroadcastHandler(String debugTag, Context context, Phone phone)40     protected CellBroadcastHandler(String debugTag, Context context, Phone phone) {
41         super(debugTag, context, phone);
42     }
43 
44     /**
45      * Create a new CellBroadcastHandler.
46      * @param context the context to use for dispatching Intents
47      * @return the new handler
48      */
makeCellBroadcastHandler(Context context, Phone phone)49     public static CellBroadcastHandler makeCellBroadcastHandler(Context context, Phone phone) {
50         CellBroadcastHandler handler = new CellBroadcastHandler(context, phone);
51         handler.start();
52         return handler;
53     }
54 
55     /**
56      * Handle Cell Broadcast messages from {@code CdmaInboundSmsHandler}.
57      * 3GPP-format Cell Broadcast messages sent from radio are handled in the subclass.
58      *
59      * @param message the message to process
60      * @return true if an ordered broadcast was sent; false on failure
61      */
62     @Override
handleSmsMessage(Message message)63     protected boolean handleSmsMessage(Message message) {
64         if (message.obj instanceof SmsCbMessage) {
65             handleBroadcastSms((SmsCbMessage) message.obj);
66             return true;
67         } else {
68             loge("handleMessage got object of type: " + message.obj.getClass().getName());
69             return false;
70         }
71     }
72 
73     /**
74      * Dispatch a Cell Broadcast message to listeners.
75      * @param message the Cell Broadcast to broadcast
76      */
handleBroadcastSms(SmsCbMessage message)77     protected void handleBroadcastSms(SmsCbMessage message) {
78         String receiverPermission;
79         int appOp;
80 
81         Intent intent;
82         if (message.isEmergencyMessage()) {
83             log("Dispatching emergency SMS CB, SmsCbMessage is: " + message);
84             intent = new Intent(Telephony.Sms.Intents.SMS_EMERGENCY_CB_RECEIVED_ACTION);
85             receiverPermission = Manifest.permission.RECEIVE_EMERGENCY_BROADCAST;
86             appOp = AppOpsManager.OP_RECEIVE_EMERGECY_SMS;
87         } else {
88             log("Dispatching SMS CB, SmsCbMessage is: " + message);
89             intent = new Intent(Telephony.Sms.Intents.SMS_CB_RECEIVED_ACTION);
90             receiverPermission = Manifest.permission.RECEIVE_SMS;
91             appOp = AppOpsManager.OP_RECEIVE_SMS;
92         }
93         intent.putExtra("message", message);
94         SubscriptionManager.putPhoneIdAndSubIdExtra(intent, mPhone.getPhoneId());
95         mContext.sendOrderedBroadcastAsUser(intent, UserHandle.ALL, receiverPermission, appOp,
96                 mReceiver, getHandler(), Activity.RESULT_OK, null, null);
97     }
98 }
99