2 * Copyright (C) 2017 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package com.android.settings.applications.defaultapps;
19 import android.content.ComponentName;
20 import android.content.Context;
21 import android.telephony.TelephonyManager;
23 import com.android.internal.telephony.SmsApplication;
24 import com.android.settingslib.applications.DefaultAppInfo;
26 import java.util.Collection;
28 public class DefaultSmsPreferenceController extends DefaultAppPreferenceController {
30 public DefaultSmsPreferenceController(Context context) {
35 public boolean isAvailable() {
36 boolean isRestrictedUser = mUserManager.getUserInfo(mUserId).isRestricted();
38 (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE);
39 return !isRestrictedUser && tm.isSmsCapable();
43 public String getPreferenceKey() {
44 return "default_sms_app";
48 protected DefaultAppInfo getDefaultAppInfo() {
49 final ComponentName app = SmsApplication.getDefaultSmsApplication(mContext, true);
51 return new DefaultAppInfo(mContext, mPackageManager, mUserId, app);
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)) {
67 public static boolean isSmsDefault(String pkg, Context context) {
68 ComponentName appName = SmsApplication.getDefaultSmsApplication(context, true);
69 return appName != null && appName.getPackageName().equals(pkg);