diff options
| author | Stephen Bird <sbird@cyngn.com> | 2016-01-21 19:04:13 -0800 |
|---|---|---|
| committer | Richard MacGregor <rmacgregor@cyngn.com> | 2016-04-08 10:42:49 -0700 |
| commit | a6049e69f130b9f5557465315112c5ca6647b3b9 (patch) | |
| tree | 11d9eb75ea2a396cc33a489bc6a3755b31bdd5e3 /src-ambient/incall/CallMethodUtils.java | |
| parent | c5f5b115f589f95d02fb0fd3690d098ca6397974 (diff) | |
| download | packages_apps_PhoneCommon-a6049e69f130b9f5557465315112c5ca6647b3b9.tar.gz packages_apps_PhoneCommon-a6049e69f130b9f5557465315112c5ca6647b3b9.tar.bz2 packages_apps_PhoneCommon-a6049e69f130b9f5557465315112c5ca6647b3b9.zip | |
Bring CallMethod items here
Change-Id: Iec207cac5b513199e7a1707e4e6617f607d78771
Diffstat (limited to 'src-ambient/incall/CallMethodUtils.java')
| -rw-r--r-- | src-ambient/incall/CallMethodUtils.java | 108 |
1 files changed, 108 insertions, 0 deletions
diff --git a/src-ambient/incall/CallMethodUtils.java b/src-ambient/incall/CallMethodUtils.java new file mode 100644 index 0000000..f80a6ad --- /dev/null +++ b/src-ambient/incall/CallMethodUtils.java @@ -0,0 +1,108 @@ +package com.android.phone.common.incall; + +import android.content.Context; +import android.telecom.PhoneAccount; +import android.telecom.PhoneAccountHandle; +import android.telecom.TelecomManager; +import android.telephony.SubscriptionInfo; +import android.telephony.SubscriptionManager; +import android.telephony.TelephonyManager; + +import com.android.phone.common.R; + +import java.util.ArrayList; +import java.util.List; + +import static com.cyanogen.ambient.incall.util.InCallHelper.NO_COLOR; + +/** + * Basic Utils for call method modifications + */ +public class CallMethodUtils { + + public final static String PREF_SPINNER_COACHMARK_SHOW = "pref_spinner_coachmark_shown"; + public final static String PREF_LAST_ENABLED_PROVIDER = "pref_last_enabled_provider"; + public final static String PREF_INTERNATIONAL_CALLS = "pref_international_calls"; + + /** + * Return whether the card in the given slot is activated + */ + public static boolean isIccCardActivated(int slot) { + TelephonyManager tm = TelephonyManager.getDefault(); + final int simState = tm.getSimState(slot); + return (simState != TelephonyManager.SIM_STATE_ABSENT) + && (simState != TelephonyManager.SIM_STATE_UNKNOWN); + } + + public static List<CallMethodInfo> getSimInfoList(Context context) { + final TelecomManager telecomMgr = + (TelecomManager) context.getSystemService(Context.TELECOM_SERVICE); + final List<PhoneAccountHandle> accountHandles = telecomMgr.getCallCapablePhoneAccounts(); + ArrayList<CallMethodInfo> callMethodInfoList = new ArrayList<CallMethodInfo>(); + for (PhoneAccountHandle accountHandle : accountHandles) { + PhoneAccount phoneAccount = telecomMgr.getPhoneAccount(accountHandle); + CallMethodInfo callMethodInfo = new CallMethodInfo(); + callMethodInfo.mComponent = accountHandle.getComponentName(); + callMethodInfo.mId = accountHandle.getId(); + callMethodInfo.mUserHandle = accountHandle.getUserHandle(); + callMethodInfo.mColor = getPhoneAccountColor(phoneAccount); + callMethodInfo.mSubId = Integer.parseInt(accountHandle.getId()); + callMethodInfo.mSlotId = SubscriptionManager.getSlotId(callMethodInfo.mSubId); + callMethodInfo.mName = + getPhoneAccountName(context, phoneAccount, callMethodInfo.mSlotId); + callMethodInfo.mIsInCallProvider = false; + if (isIccCardActivated(callMethodInfo.mSlotId)) { + callMethodInfoList.add(callMethodInfo); + } + } + return callMethodInfoList; + } + + private static String getPhoneAccountName(Context context, PhoneAccount phoneAccount, + int slotId) { + if (phoneAccount == null) { + return context.getString(R.string.call_method_spinner_item_unknown_sim, slotId + 1); + } + return phoneAccount.getLabel().toString(); + } + + private static int getPhoneAccountColor(PhoneAccount phoneAccount) { + if (phoneAccount == null) { + return NO_COLOR; + } + + int highlightColor = phoneAccount.getHighlightColor(); + + if (highlightColor != PhoneAccount.NO_HIGHLIGHT_COLOR) { + return highlightColor; + } else { + return NO_COLOR; + } + } + + public static CallMethodInfo getDefaultDataSimInfo(Context context) { + SubscriptionManager subMgr = SubscriptionManager.from(context); + SubscriptionInfo subInfo = subMgr.getActiveSubscriptionInfo( + SubscriptionManager.getDefaultSubId()); + + if (subInfo == null) return null; + + CallMethodInfo callMethodInfo = new CallMethodInfo(); + callMethodInfo.mSubId = subInfo.getSubscriptionId(); + callMethodInfo.mColor = subInfo.getIconTint(); + callMethodInfo.mName = subInfo.getDisplayName().toString(); + callMethodInfo.mSlotId = SubscriptionManager.getSlotId(callMethodInfo.mSubId); + + final TelecomManager telecomMgr = + (TelecomManager) context.getSystemService(Context.TELECOM_SERVICE); + final List<PhoneAccountHandle> accountHandles = telecomMgr.getCallCapablePhoneAccounts(); + for (PhoneAccountHandle accountHandle : accountHandles) { + if (callMethodInfo.mSubId == Integer.parseInt(accountHandle.getId())) { + callMethodInfo.mComponent = accountHandle.getComponentName(); + break; + } + } + + return callMethodInfo; + } +} |
