Ihab Awad | 104f806 | 2014-07-17 11:29:35 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 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.telecomm; |
| 18 | |
| 19 | import android.app.Activity; |
| 20 | import android.os.Bundle; |
Ihab Awad | 104f806 | 2014-07-17 11:29:35 -0700 | [diff] [blame] | 21 | import android.preference.PreferenceFragment; |
Ihab Awad | 293edf2 | 2014-07-24 17:52:29 -0700 | [diff] [blame] | 22 | import android.telecomm.PhoneAccount; |
Evan Charlton | 8917637 | 2014-07-19 18:23:09 -0700 | [diff] [blame] | 23 | import android.telecomm.PhoneAccountHandle; |
Ihab Awad | 104f806 | 2014-07-17 11:29:35 -0700 | [diff] [blame] | 24 | |
Ihab Awad | 293edf2 | 2014-07-24 17:52:29 -0700 | [diff] [blame] | 25 | import java.util.ArrayList; |
Ihab Awad | 104f806 | 2014-07-17 11:29:35 -0700 | [diff] [blame] | 26 | import java.util.List; |
Ihab Awad | 104f806 | 2014-07-17 11:29:35 -0700 | [diff] [blame] | 27 | |
| 28 | public class PhoneAccountPreferencesActivity extends Activity { |
| 29 | |
| 30 | private static final String KEY_DEFAULT_OUTGOING_ACCOUNT = "default_outgoing_account"; |
Ihab Awad | 293edf2 | 2014-07-24 17:52:29 -0700 | [diff] [blame] | 31 | private static final String KEY_SIM_CALL_MANAGER_ACCOUNT = "sim_call_manager_account"; |
Ihab Awad | 104f806 | 2014-07-17 11:29:35 -0700 | [diff] [blame] | 32 | |
| 33 | @Override |
| 34 | public void onCreate(Bundle savedInstanceState) { |
| 35 | super.onCreate(savedInstanceState); |
| 36 | setContentView(R.layout.phone_account_preferences); |
| 37 | } |
| 38 | |
| 39 | public static class PreferencesFragment extends PreferenceFragment |
Ihab Awad | 293edf2 | 2014-07-24 17:52:29 -0700 | [diff] [blame] | 40 | implements AccountSelectionPreference.AccountSelectionListener { |
| 41 | private AccountSelectionPreference mDefaultOutgoingAccount; |
| 42 | private AccountSelectionPreference mSimCallManagerAccount; |
Ihab Awad | 104f806 | 2014-07-17 11:29:35 -0700 | [diff] [blame] | 43 | |
| 44 | @Override |
| 45 | public void onCreate(Bundle savedInstanceState) { |
| 46 | super.onCreate(savedInstanceState); |
| 47 | |
| 48 | addPreferencesFromResource(R.xml.phone_account_preferences); |
Ihab Awad | 104f806 | 2014-07-17 11:29:35 -0700 | [diff] [blame] | 49 | |
Ihab Awad | 293edf2 | 2014-07-24 17:52:29 -0700 | [diff] [blame] | 50 | mDefaultOutgoingAccount = (AccountSelectionPreference) |
| 51 | findPreference(KEY_DEFAULT_OUTGOING_ACCOUNT); |
| 52 | mSimCallManagerAccount = (AccountSelectionPreference) |
| 53 | findPreference(KEY_SIM_CALL_MANAGER_ACCOUNT); |
Ihab Awad | 104f806 | 2014-07-17 11:29:35 -0700 | [diff] [blame] | 54 | |
Ihab Awad | 293edf2 | 2014-07-24 17:52:29 -0700 | [diff] [blame] | 55 | PhoneAccountRegistrar registrar = TelecommApp.getInstance().getPhoneAccountRegistrar(); |
Ihab Awad | 104f806 | 2014-07-17 11:29:35 -0700 | [diff] [blame] | 56 | |
Ihab Awad | 293edf2 | 2014-07-24 17:52:29 -0700 | [diff] [blame] | 57 | mDefaultOutgoingAccount.setModel( |
| 58 | registrar, |
Ihab Awad | 6fb37c8 | 2014-08-07 19:48:57 -0700 | [diff] [blame] | 59 | registrar.getOutgoingPhoneAccounts(), |
Ihab Awad | 293edf2 | 2014-07-24 17:52:29 -0700 | [diff] [blame] | 60 | registrar.getDefaultOutgoingPhoneAccount(), |
| 61 | getString(R.string.account_ask_every_time)); |
Ihab Awad | 104f806 | 2014-07-17 11:29:35 -0700 | [diff] [blame] | 62 | |
Ihab Awad | 293edf2 | 2014-07-24 17:52:29 -0700 | [diff] [blame] | 63 | mSimCallManagerAccount.setModel( |
| 64 | registrar, |
| 65 | getSimCallManagers(registrar), |
| 66 | registrar.getSimCallManager(), |
| 67 | getString(R.string.do_not_use_sim_call_manager)); |
| 68 | |
| 69 | mDefaultOutgoingAccount.setListener(this); |
| 70 | mSimCallManagerAccount.setListener(this); |
Ihab Awad | 104f806 | 2014-07-17 11:29:35 -0700 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | @Override |
Ihab Awad | 293edf2 | 2014-07-24 17:52:29 -0700 | [diff] [blame] | 74 | public boolean onAccountSelected( |
| 75 | AccountSelectionPreference p, PhoneAccountHandle account) { |
| 76 | PhoneAccountRegistrar registrar = TelecommApp.getInstance().getPhoneAccountRegistrar(); |
Ihab Awad | 104f806 | 2014-07-17 11:29:35 -0700 | [diff] [blame] | 77 | if (p == mDefaultOutgoingAccount) { |
Ihab Awad | 293edf2 | 2014-07-24 17:52:29 -0700 | [diff] [blame] | 78 | registrar.setDefaultOutgoingPhoneAccount(account); |
| 79 | return true; |
| 80 | } else if (p == mSimCallManagerAccount) { |
| 81 | registrar.setSimCallManager(account); |
Ihab Awad | 104f806 | 2014-07-17 11:29:35 -0700 | [diff] [blame] | 82 | return true; |
| 83 | } |
| 84 | return false; |
| 85 | } |
Ihab Awad | 293edf2 | 2014-07-24 17:52:29 -0700 | [diff] [blame] | 86 | |
| 87 | private List<PhoneAccountHandle> getSimCallManagers(PhoneAccountRegistrar registrar) { |
| 88 | List<PhoneAccountHandle> simCallManagers = new ArrayList<>(); |
| 89 | List<PhoneAccountHandle> allAccounts = registrar.getAllPhoneAccountHandles(); |
| 90 | for (int i = 0; i < allAccounts.size(); i++) { |
| 91 | PhoneAccount account = registrar.getPhoneAccount(allAccounts.get(i)); |
Ihab Awad | b78b276 | 2014-07-25 15:16:23 -0700 | [diff] [blame] | 92 | if ((account.getCapabilities() & PhoneAccount.CAPABILITY_CONNECTION_MANAGER) != 0) { |
Ihab Awad | 293edf2 | 2014-07-24 17:52:29 -0700 | [diff] [blame] | 93 | simCallManagers.add(allAccounts.get(i)); |
| 94 | } |
| 95 | } |
| 96 | return simCallManagers; |
| 97 | } |
Ihab Awad | 104f806 | 2014-07-17 11:29:35 -0700 | [diff] [blame] | 98 | } |
| 99 | } |