Search in sources :

Example 21 with PhoneAccount

use of android.telecom.PhoneAccount in project android_packages_apps_Dialer by MoKee.

the class CallLogCacheLollipopMr1 method getAccountIcon.

@Override
public Drawable getAccountIcon(PhoneAccountHandle accountHandle) {
    if (mPhoneAccountCallWithDrawableCache.containsKey(accountHandle)) {
        return mPhoneAccountCallWithDrawableCache.get(accountHandle);
    } else {
        PhoneAccount account = PhoneAccountUtils.getAccountOrNull(mContext, accountHandle);
        if (account == null) {
            mPhoneAccountCallWithDrawableCache.put(accountHandle, null);
            return null;
        }
        Drawable drawable = account.getIcon().loadDrawable(mContext);
        mPhoneAccountCallWithDrawableCache.put(accountHandle, drawable);
        return drawable;
    }
}
Also used : PhoneAccount(android.telecom.PhoneAccount) Drawable(android.graphics.drawable.Drawable)

Example 22 with PhoneAccount

use of android.telecom.PhoneAccount in project android_packages_apps_Dialer by MoKee.

the class CallLogCacheLollipopMr1 method isVoicemailNumber.

@Override
public boolean isVoicemailNumber(PhoneAccountHandle accountHandle, CharSequence number) {
    if (TextUtils.isEmpty(number)) {
        return false;
    }
    String curNumber = PhoneNumberUtils.extractNetworkPortionAlt(number.toString());
    if (mPhoneAccountCallWithVoiceMailNumberCache.containsKey(accountHandle)) {
        String vmNumber = mPhoneAccountCallWithVoiceMailNumberCache.get(accountHandle);
        return !TextUtils.isEmpty(curNumber) && PhoneNumberUtils.compare(curNumber, vmNumber);
    } else {
        PhoneAccount account = PhoneAccountUtils.getAccountOrNull(mContext, accountHandle);
        if (account != null && account.hasCapabilities(PhoneAccount.CAPABILITY_SIM_SUBSCRIPTION)) {
            try {
                int subId = Integer.parseInt(accountHandle.getId());
                String vmNumber = mTelephonyManager.getVoiceMailNumber(subId);
                mPhoneAccountCallWithVoiceMailNumberCache.put(accountHandle, vmNumber);
                return !TextUtils.isEmpty(curNumber) && PhoneNumberUtils.compare(curNumber, vmNumber);
            } catch (NumberFormatException e) {
                mPhoneAccountCallWithVoiceMailNumberCache.put(accountHandle, null);
            }
        } else {
            mPhoneAccountCallWithVoiceMailNumberCache.put(accountHandle, null);
        }
    }
    return false;
}
Also used : PhoneAccount(android.telecom.PhoneAccount)

Example 23 with PhoneAccount

use of android.telecom.PhoneAccount in project android_packages_apps_Settings by DirtyUnicorns.

the class SimDialogActivity method createDialog.

public Dialog createDialog(final Context context, final int id) {
    final ArrayList<String> list = new ArrayList<String>();
    final SubscriptionManager subscriptionManager = SubscriptionManager.from(context);
    final List<SubscriptionInfo> subInfoList = subscriptionManager.getActiveSubscriptionInfoList();
    final int selectableSubInfoLength = subInfoList == null ? 0 : subInfoList.size();
    final DialogInterface.OnClickListener selectionListener = new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int value) {
            final SubscriptionInfo sir;
            switch(id) {
                case DATA_PICK:
                    sir = subInfoList.get(value);
                    setDefaultDataSubId(context, sir.getSubscriptionId());
                    break;
                case CALLS_PICK:
                    final TelecomManager telecomManager = TelecomManager.from(context);
                    final List<PhoneAccountHandle> phoneAccountsList = telecomManager.getCallCapablePhoneAccounts();
                    setUserSelectedOutgoingPhoneAccount(value < 1 ? null : phoneAccountsList.get(value - 1));
                    break;
                case SMS_PICK:
                    sir = subInfoList.get(value);
                    setDefaultSmsSubId(context, sir.getSubscriptionId());
                    break;
                default:
                    throw new IllegalArgumentException("Invalid dialog type " + id + " in SIM dialog.");
            }
            finish();
        }
    };
    Dialog.OnKeyListener keyListener = new Dialog.OnKeyListener() {

        @Override
        public boolean onKey(DialogInterface arg0, int keyCode, KeyEvent event) {
            if (keyCode == KeyEvent.KEYCODE_BACK) {
                finish();
            }
            return true;
        }
    };
    ArrayList<SubscriptionInfo> callsSubInfoList = new ArrayList<SubscriptionInfo>();
    if (id == CALLS_PICK) {
        final TelecomManager telecomManager = TelecomManager.from(context);
        final TelephonyManager telephonyManager = TelephonyManager.from(context);
        final Iterator<PhoneAccountHandle> phoneAccounts = telecomManager.getCallCapablePhoneAccounts().listIterator();
        list.add(getResources().getString(R.string.sim_calls_ask_first_prefs_title));
        callsSubInfoList.add(null);
        while (phoneAccounts.hasNext()) {
            final PhoneAccount phoneAccount = telecomManager.getPhoneAccount(phoneAccounts.next());
            list.add((String) phoneAccount.getLabel());
            int subId = telephonyManager.getSubIdForPhoneAccount(phoneAccount);
            if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
                final SubscriptionInfo sir = SubscriptionManager.from(context).getActiveSubscriptionInfo(subId);
                callsSubInfoList.add(sir);
            } else {
                callsSubInfoList.add(null);
            }
        }
    } else {
        for (int i = 0; i < selectableSubInfoLength; ++i) {
            final SubscriptionInfo sir = subInfoList.get(i);
            CharSequence displayName = sir.getDisplayName();
            if (displayName == null) {
                displayName = "";
            }
            list.add(displayName.toString());
        }
    }
    String[] arr = list.toArray(new String[0]);
    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    ListAdapter adapter = new SelectAccountListAdapter(id == CALLS_PICK ? callsSubInfoList : subInfoList, builder.getContext(), R.layout.select_account_list_item, arr, id);
    switch(id) {
        case DATA_PICK:
            builder.setTitle(R.string.select_sim_for_data);
            break;
        case CALLS_PICK:
            builder.setTitle(R.string.select_sim_for_calls);
            break;
        case SMS_PICK:
            builder.setTitle(R.string.sim_card_select_title);
            break;
        default:
            throw new IllegalArgumentException("Invalid dialog type " + id + " in SIM dialog.");
    }
    Dialog dialog = builder.setAdapter(adapter, selectionListener).create();
    dialog.setOnKeyListener(keyListener);
    dialog.setOnCancelListener(new DialogInterface.OnCancelListener() {

        @Override
        public void onCancel(DialogInterface dialogInterface) {
            finish();
        }
    });
    return dialog;
}
Also used : AlertDialog(android.app.AlertDialog) DialogInterface(android.content.DialogInterface) ArrayList(java.util.ArrayList) SubscriptionInfo(android.telephony.SubscriptionInfo) SubscriptionManager(android.telephony.SubscriptionManager) KeyEvent(android.view.KeyEvent) TelephonyManager(android.telephony.TelephonyManager) Dialog(android.app.Dialog) AlertDialog(android.app.AlertDialog) ListAdapter(android.widget.ListAdapter) PhoneAccountHandle(android.telecom.PhoneAccountHandle) TelecomManager(android.telecom.TelecomManager) PhoneAccount(android.telecom.PhoneAccount)

Example 24 with PhoneAccount

use of android.telecom.PhoneAccount in project android_packages_apps_Dialer by MoKee.

the class FillCallLogTestActivity method addCall.

// Copied and modified to compile unbundled from android.provider.CallLog
public Uri addCall(String number, int presentation, int callType, int features, PhoneAccountHandle accountHandle, long start, int duration, Long dataUsage) {
    final ContentResolver resolver = getContentResolver();
    int numberPresentation = Calls.PRESENTATION_ALLOWED;
    String accountAddress = null;
    if (accountHandle != null) {
        PhoneAccount account = TelecomUtil.getPhoneAccount(this, accountHandle);
        if (account != null) {
            Uri address = account.getSubscriptionAddress();
            if (address != null) {
                accountAddress = address.getSchemeSpecificPart();
            }
        }
    }
    if (numberPresentation != Calls.PRESENTATION_ALLOWED) {
        number = "";
    }
    // accountHandle information
    String accountComponentString = null;
    String accountId = null;
    if (accountHandle != null) {
        accountComponentString = accountHandle.getComponentName().flattenToString();
        accountId = accountHandle.getId();
    }
    ContentValues values = new ContentValues(6);
    values.put(Calls.NUMBER, number);
    values.put(Calls.NUMBER_PRESENTATION, Integer.valueOf(numberPresentation));
    values.put(Calls.TYPE, Integer.valueOf(callType));
    values.put(Calls.FEATURES, features);
    values.put(Calls.DATE, Long.valueOf(start));
    values.put(Calls.DURATION, Long.valueOf(duration));
    if (dataUsage != null) {
        values.put(Calls.DATA_USAGE, dataUsage);
    }
    values.put(Calls.PHONE_ACCOUNT_COMPONENT_NAME, accountComponentString);
    values.put(Calls.PHONE_ACCOUNT_ID, accountId);
    // Calls.PHONE_ACCOUNT_ADDRESS
    values.put("phone_account_address", accountAddress);
    values.put(Calls.NEW, Integer.valueOf(1));
    if (callType == AppCompatConstants.CALLS_MISSED_TYPE) {
        values.put(Calls.IS_READ, 0);
    }
    return addEntryAndRemoveExpiredEntries(this, Calls.CONTENT_URI, values);
}
Also used : ContentValues(android.content.ContentValues) PhoneAccount(android.telecom.PhoneAccount) Uri(android.net.Uri) ContentResolver(android.content.ContentResolver)

Example 25 with PhoneAccount

use of android.telecom.PhoneAccount in project android_packages_apps_Dialer by MoKee.

the class CallCardPresenter method getSubId.

private int getSubId() {
    int subId = SubscriptionManager.getDefaultVoiceSubscriptionId();
    PhoneAccountHandle accountHandle = mPrimary.getAccountHandle();
    if (accountHandle != null) {
        TelecomManager mgr = InCallPresenter.getInstance().getTelecomManager();
        PhoneAccount account = mgr.getPhoneAccount(accountHandle);
        if (account != null) {
            subId = TelephonyManager.getDefault().getSubIdForPhoneAccount(account);
            Log.d(this, "get sub id from phone account = " + subId);
        }
    }
    return subId;
}
Also used : PhoneAccount(android.telecom.PhoneAccount) PhoneAccountHandle(android.telecom.PhoneAccountHandle) TelecomManager(android.telecom.TelecomManager)

Aggregations

PhoneAccount (android.telecom.PhoneAccount)53 PhoneAccountHandle (android.telecom.PhoneAccountHandle)41 TelecomManager (android.telecom.TelecomManager)32 TelephonyManager (android.telephony.TelephonyManager)19 ArrayList (java.util.ArrayList)13 SubscriptionInfo (android.telephony.SubscriptionInfo)11 SubscriptionManager (android.telephony.SubscriptionManager)10 AlertDialog (android.app.AlertDialog)7 Dialog (android.app.Dialog)7 DialogInterface (android.content.DialogInterface)7 KeyEvent (android.view.KeyEvent)7 ListAdapter (android.widget.ListAdapter)7 Uri (android.net.Uri)3 Context (android.content.Context)2 NotificationChannel (android.app.NotificationChannel)1 NotificationManager (android.app.NotificationManager)1 ContentResolver (android.content.ContentResolver)1 ContentValues (android.content.ContentValues)1 Drawable (android.graphics.drawable.Drawable)1 Bundle (android.os.Bundle)1