1 /* 2 * Copyright (C) 2019 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.network.telephony; 18 19 import android.content.Context; 20 import android.telephony.SubscriptionManager; 21 22 import androidx.lifecycle.LifecycleOwner; 23 24 import com.android.settingslib.core.lifecycle.Lifecycle; 25 import com.android.settingslib.mobile.dataservice.SubscriptionInfoEntity; 26 27 public class SmsDefaultSubscriptionController extends DefaultSubscriptionController { 28 29 private final boolean mIsAskEverytimeSupported; 30 SmsDefaultSubscriptionController(Context context, String preferenceKey, Lifecycle lifecycle, LifecycleOwner lifecycleOwner)31 public SmsDefaultSubscriptionController(Context context, String preferenceKey, 32 Lifecycle lifecycle, LifecycleOwner lifecycleOwner) { 33 super(context, preferenceKey, lifecycle, lifecycleOwner); 34 mIsAskEverytimeSupported = mContext.getResources() 35 .getBoolean(com.android.internal.R.bool.config_sms_ask_every_time_support); 36 } 37 SmsDefaultSubscriptionController(Context context, String preferenceKey)38 public SmsDefaultSubscriptionController(Context context, String preferenceKey) { 39 super(context, preferenceKey); 40 mIsAskEverytimeSupported = mContext.getResources() 41 .getBoolean(com.android.internal.R.bool.config_sms_ask_every_time_support); 42 } 43 44 @Override getDefaultSubscriptionId()45 protected int getDefaultSubscriptionId() { 46 int defaultSmsSubId = SubscriptionManager.getDefaultSmsSubscriptionId(); 47 for (SubscriptionInfoEntity subInfo : mSubInfoEntityList) { 48 int subId = subInfo.getSubId(); 49 if (subInfo.isActiveSubscriptionId && subId == defaultSmsSubId) { 50 return subId; 51 } 52 } 53 return SubscriptionManager.INVALID_SUBSCRIPTION_ID; 54 } 55 56 @Override setDefaultSubscription(int subscriptionId)57 protected void setDefaultSubscription(int subscriptionId) { 58 mManager.setDefaultSmsSubId(subscriptionId); 59 } 60 61 @Override isAskEverytimeSupported()62 protected boolean isAskEverytimeSupported() { 63 return mIsAskEverytimeSupported; 64 } 65 66 @Override getSummary()67 public CharSequence getSummary() { 68 return MobileNetworkUtils.getPreferredStatus(isRtlMode(), mContext, false, 69 mSubInfoEntityList); 70 } 71 } 72