blob: 441f149a2a3e278b29c5679ae28aebcdfba5d5f6 [file] [log] [blame]
Alexandre Savard14323be2012-10-24 10:02:13 -04001/*
2 * Copyright (C) 2004-2012 Savoir-Faire Linux Inc.
3 *
4 * Author: Alexandre Savard <alexandre.savard@savoirfairelinux.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 *
20 * Additional permission under GNU GPL version 3 section 7:
21 *
22 * If you modify this program, or any covered work, by linking or
23 * combining it with the OpenSSL project's OpenSSL library (or a
24 * modified version of that library), containing parts covered by the
25 * terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc.
26 * grants you additional permission to convey the resulting work.
27 * Corresponding Source for a non-source form of such a combination
28 * shall include the source code for the parts of OpenSSL used as well
29 * as that of the covered work.
30 */
31
32package com.savoirfairelinux.sflphone.utils;
33
Alexandre Savardbb6f1872012-11-01 17:25:55 -040034import android.content.BroadcastReceiver;
35import android.content.Intent;
36import android.content.Context;
37import android.os.RemoteException;
38import android.util.Log;
39
40import java.util.ArrayList;
41
42import com.savoirfairelinux.sflphone.service.ConfigurationManagerCallback;
43import com.savoirfairelinux.sflphone.service.ISipService;
44
45public class AccountList extends BroadcastReceiver
Alexandre Savard14323be2012-10-24 10:02:13 -040046{
47 static final String TAG = "AccountList";
Alexandre Savardbb6f1872012-11-01 17:25:55 -040048 private String currentAccountID = "";
49 private ArrayList<String> mList = new ArrayList<String>();
50 private ArrayList<AccountManagementUI> mUserInterfaceList = new ArrayList<AccountManagementUI>();
51 private ISipService mService;
Alexandre Savard14323be2012-10-24 10:02:13 -040052 // private HashMap<String, AccountPreferenceScreen> mAccountList = new HashMap<String, AccountPreferenceScreen>();
53
Alexandre Savardbb6f1872012-11-01 17:25:55 -040054 public static final String DEFAULT_ACCOUNT_ID = "IP2IP";
Alexandre Savard14323be2012-10-24 10:02:13 -040055
Alexandre Savardbb6f1872012-11-01 17:25:55 -040056 public AccountList() {
57 }
58
59 public void setSipService(ISipService service) {
60 mService = service;
61 mList = getAccountListFromService();
62 }
63
64
65 public void addManagementUI(AccountManagementUI ui) {
66 mUserInterfaceList.add(ui);
67 }
68
Alexandre Savardaf0f3c62012-11-01 18:35:56 -040069 public void accountSelected(String accountID, AccountManagementUI userInterface) {
70 if(!mUserInterfaceList.isEmpty()) {
71 for(AccountManagementUI ui : mUserInterfaceList) {
72 ui.setSelectedAccount(accountID);
73 }
74 }
75 }
76
Alexandre Savardbb6f1872012-11-01 17:25:55 -040077 @Override
78 public void onReceive(Context context, Intent intent)
79 {
80 String signalName = intent.getStringExtra(ConfigurationManagerCallback.SIGNAL_NAME);
81 Log.d(TAG, "Signal received: " + signalName);
82
83 if(signalName.equals(ConfigurationManagerCallback.ACCOUNTS_CHANGED)) {
84 processAccountsChangedSignal(intent);
85 } else if(signalName.equals(ConfigurationManagerCallback.ACCOUNT_STATE_CHANGED)) {
86 processAccountStateChanged(intent);
87 }
88 }
89
90 private ArrayList<String> getAccountListFromService() {
91 ArrayList<String> list = null;
92
93 try {
94 list = (ArrayList<String>)mService.getAccountList();
95 }
96 catch (RemoteException e) {
97 Log.e(TAG, "Remote exception", e);
98 }
99
100 list.remove(DEFAULT_ACCOUNT_ID);
101
102 return list;
103 }
104
105
106 private void processAccountsChangedSignal(Intent intent) {
107 ArrayList<String> newList = getAccountListFromService();
108
109 Log.i(TAG, "Process AccountsChanged signal in AccountList");
110
111 newList.remove(DEFAULT_ACCOUNT_ID);
112
113 if(!mUserInterfaceList.isEmpty()) {
114
115 if(newList.size() > mList.size()) {
116 for(AccountManagementUI ui : mUserInterfaceList) {
Alexandre Savardbb6f1872012-11-01 17:25:55 -0400117 ui.accountAdded(newList);
118 }
119 }
Alexandre Savardbb6f1872012-11-01 17:25:55 -0400120 }
121
122 mList = newList;
123 }
124
125 private void processAccountStateChanged(Intent intent) {
126 if(!mUserInterfaceList.isEmpty()) {
127 }
Alexandre Savard14323be2012-10-24 10:02:13 -0400128 }
129}