blob: a7a6a62b23def749d35636d29b245d6b4eeff6b8 [file] [log] [blame]
Ihab Awad104f8062014-07-17 11:29:35 -07001/*
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
17package com.android.telecomm;
18
19import android.app.Activity;
20import android.os.Bundle;
Ihab Awad104f8062014-07-17 11:29:35 -070021import android.preference.PreferenceFragment;
Ihab Awad293edf22014-07-24 17:52:29 -070022import android.telecomm.PhoneAccount;
Evan Charlton89176372014-07-19 18:23:09 -070023import android.telecomm.PhoneAccountHandle;
Ihab Awad104f8062014-07-17 11:29:35 -070024
Ihab Awad293edf22014-07-24 17:52:29 -070025import java.util.ArrayList;
Ihab Awad104f8062014-07-17 11:29:35 -070026import java.util.List;
Ihab Awad104f8062014-07-17 11:29:35 -070027
28public class PhoneAccountPreferencesActivity extends Activity {
29
30 private static final String KEY_DEFAULT_OUTGOING_ACCOUNT = "default_outgoing_account";
Ihab Awad293edf22014-07-24 17:52:29 -070031 private static final String KEY_SIM_CALL_MANAGER_ACCOUNT = "sim_call_manager_account";
Ihab Awad104f8062014-07-17 11:29:35 -070032
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 Awad293edf22014-07-24 17:52:29 -070040 implements AccountSelectionPreference.AccountSelectionListener {
41 private AccountSelectionPreference mDefaultOutgoingAccount;
42 private AccountSelectionPreference mSimCallManagerAccount;
Ihab Awad104f8062014-07-17 11:29:35 -070043
44 @Override
45 public void onCreate(Bundle savedInstanceState) {
46 super.onCreate(savedInstanceState);
47
48 addPreferencesFromResource(R.xml.phone_account_preferences);
Ihab Awad104f8062014-07-17 11:29:35 -070049
Ihab Awad293edf22014-07-24 17:52:29 -070050 mDefaultOutgoingAccount = (AccountSelectionPreference)
51 findPreference(KEY_DEFAULT_OUTGOING_ACCOUNT);
52 mSimCallManagerAccount = (AccountSelectionPreference)
53 findPreference(KEY_SIM_CALL_MANAGER_ACCOUNT);
Ihab Awad104f8062014-07-17 11:29:35 -070054
Ihab Awad293edf22014-07-24 17:52:29 -070055 PhoneAccountRegistrar registrar = TelecommApp.getInstance().getPhoneAccountRegistrar();
Ihab Awad104f8062014-07-17 11:29:35 -070056
Ihab Awad293edf22014-07-24 17:52:29 -070057 mDefaultOutgoingAccount.setModel(
58 registrar,
Ihab Awad6fb37c82014-08-07 19:48:57 -070059 registrar.getOutgoingPhoneAccounts(),
Ihab Awad293edf22014-07-24 17:52:29 -070060 registrar.getDefaultOutgoingPhoneAccount(),
61 getString(R.string.account_ask_every_time));
Ihab Awad104f8062014-07-17 11:29:35 -070062
Ihab Awad293edf22014-07-24 17:52:29 -070063 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 Awad104f8062014-07-17 11:29:35 -070071 }
72
73 @Override
Ihab Awad293edf22014-07-24 17:52:29 -070074 public boolean onAccountSelected(
75 AccountSelectionPreference p, PhoneAccountHandle account) {
76 PhoneAccountRegistrar registrar = TelecommApp.getInstance().getPhoneAccountRegistrar();
Ihab Awad104f8062014-07-17 11:29:35 -070077 if (p == mDefaultOutgoingAccount) {
Ihab Awad293edf22014-07-24 17:52:29 -070078 registrar.setDefaultOutgoingPhoneAccount(account);
79 return true;
80 } else if (p == mSimCallManagerAccount) {
81 registrar.setSimCallManager(account);
Ihab Awad104f8062014-07-17 11:29:35 -070082 return true;
83 }
84 return false;
85 }
Ihab Awad293edf22014-07-24 17:52:29 -070086
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 Awadb78b2762014-07-25 15:16:23 -070092 if ((account.getCapabilities() & PhoneAccount.CAPABILITY_CONNECTION_MANAGER) != 0) {
Ihab Awad293edf22014-07-24 17:52:29 -070093 simCallManagers.add(allAccounts.get(i));
94 }
95 }
96 return simCallManagers;
97 }
Ihab Awad104f8062014-07-17 11:29:35 -070098 }
99}