Home | History | Annotate | Download | only in cellbroadcastreceiver
      1 /*
      2  * Copyright (C) 2015 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.cellbroadcastreceiver;
     18 
     19 import android.content.BroadcastReceiver;
     20 import android.content.Context;
     21 import android.content.Intent;
     22 import android.os.UserHandle;
     23 import android.telephony.CellBroadcastMessage;
     24 import android.util.Log;
     25 
     26 public class CellBroadcastAreaInfoReceiver extends BroadcastReceiver {
     27     private static final String TAG = "CBAreaInfoReceiver";
     28     static final boolean DBG = false;    // STOPSHIP: change to false before ship
     29     private static final String GET_LATEST_CB_AREA_INFO_ACTION =
     30             "com.android.cellbroadcastreceiver.GET_LATEST_CB_AREA_INFO";
     31 
     32     @Override
     33     public void onReceive(Context context, Intent intent) {
     34         if (DBG) Log.d(TAG, "onReceive " + intent);
     35 
     36         String action = intent.getAction();
     37 
     38         if (GET_LATEST_CB_AREA_INFO_ACTION.equals(action)) {
     39             CellBroadcastMessage message = CellBroadcastReceiverApp.getLatestAreaInfo();
     40             if (message != null) {
     41                 Intent areaInfoIntent = new Intent(
     42                         CellBroadcastAlertService.CB_AREA_INFO_RECEIVED_ACTION);
     43                 areaInfoIntent.setPackage(CellBroadcastAlertService.SETTINGS_APP);
     44                 areaInfoIntent.putExtra("message", message);
     45                 // Send broadcast twice, once for apps that have PRIVILEGED permission and once
     46                 // for those that have the runtime one
     47                 context.sendBroadcastAsUser(areaInfoIntent, UserHandle.ALL,
     48                         android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE);
     49                 context.sendBroadcastAsUser(areaInfoIntent, UserHandle.ALL,
     50                         android.Manifest.permission.READ_PHONE_STATE);
     51             }
     52         }
     53     }
     54 }
     55