1 /* 2 * Copyright (C) 2017 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.settings.applications.defaultapps; 18 19 import android.content.ComponentName; 20 import android.content.Context; 21 import android.telephony.TelephonyManager; 22 23 import com.android.internal.telephony.SmsApplication; 24 import com.android.settingslib.applications.DefaultAppInfo; 25 26 import java.util.Collection; 27 28 public class DefaultSmsPreferenceController extends DefaultAppPreferenceController { 29 DefaultSmsPreferenceController(Context context)30 public DefaultSmsPreferenceController(Context context) { 31 super(context); 32 } 33 34 @Override isAvailable()35 public boolean isAvailable() { 36 boolean isRestrictedUser = mUserManager.getUserInfo(mUserId).isRestricted(); 37 TelephonyManager tm = 38 (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE); 39 return !isRestrictedUser && tm.isSmsCapable(); 40 } 41 42 @Override getPreferenceKey()43 public String getPreferenceKey() { 44 return "default_sms_app"; 45 } 46 47 @Override getDefaultAppInfo()48 protected DefaultAppInfo getDefaultAppInfo() { 49 final ComponentName app = SmsApplication.getDefaultSmsApplication(mContext, true); 50 if (app != null) { 51 return new DefaultAppInfo(mContext, mPackageManager, mUserId, app); 52 } 53 return null; 54 } 55 hasSmsPreference(String pkg, Context context)56 public static boolean hasSmsPreference(String pkg, Context context) { 57 Collection<SmsApplication.SmsApplicationData> smsApplications = 58 SmsApplication.getApplicationCollection(context); 59 for (SmsApplication.SmsApplicationData data : smsApplications) { 60 if (data.mPackageName.equals(pkg)) { 61 return true; 62 } 63 } 64 return false; 65 } 66 isSmsDefault(String pkg, Context context)67 public static boolean isSmsDefault(String pkg, Context context) { 68 ComponentName appName = SmsApplication.getDefaultSmsApplication(context, true); 69 return appName != null && appName.getPackageName().equals(pkg); 70 } 71 } 72