1 /* 2 * Copyright (C) 2020 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.content.Context; 20 import android.content.Intent; 21 import android.content.pm.PackageManager; 22 import android.content.pm.ResolveInfo; 23 import android.provider.Telephony; 24 import android.text.TextUtils; 25 import android.util.Log; 26 27 /** 28 * This class provides utility functions related to CellBroadcast. 29 */ 30 public class CellBroadcastUtils { 31 private static final String TAG = "CellBroadcastUtils"; 32 private static final boolean VDBG = false; 33 34 /** 35 * Utility method to query the default CBR's package name. 36 */ getDefaultCellBroadcastReceiverPackageName(Context context)37 public static String getDefaultCellBroadcastReceiverPackageName(Context context) { 38 PackageManager packageManager = context.getPackageManager(); 39 ResolveInfo resolveInfo = packageManager.resolveActivity( 40 new Intent(Telephony.Sms.Intents.SMS_CB_RECEIVED_ACTION), 41 PackageManager.MATCH_SYSTEM_ONLY); 42 String packageName; 43 44 if (resolveInfo == null) { 45 Log.e(TAG, "getDefaultCellBroadcastReceiverPackageName: no package found"); 46 return null; 47 } 48 49 packageName = resolveInfo.activityInfo.applicationInfo.packageName; 50 51 if (VDBG) { 52 Log.d(TAG, "getDefaultCellBroadcastReceiverPackageName: found package: " + packageName); 53 } 54 55 if (TextUtils.isEmpty(packageName) || packageManager.checkPermission( 56 android.Manifest.permission.READ_CELL_BROADCASTS, packageName) 57 == PackageManager.PERMISSION_DENIED) { 58 Log.e(TAG, "getDefaultCellBroadcastReceiverPackageName: returning null; " 59 + "permission check failed for : " + packageName); 60 return null; 61 } 62 63 return packageName; 64 } 65 } 66