blob: 81397db088a724e168fae8c7477ef2c0a860dd55 [file] [log] [blame]
Alexandre Lisiona8b78722013-12-13 10:18:33 -05001/*
Alexandre Lisionc1024c02014-01-06 11:12:53 -05002 * Copyright (C) 2004-2014 Savoir-Faire Linux Inc.
Alexandre Lisiona8b78722013-12-13 10:18:33 -05003 *
4 * Author: Alexandre Lision <alexandre.lision@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
Alexandre Lision064e1e02013-10-01 16:18:42 -040032package org.sflphone.loaders;
alision11e8e162013-05-28 10:33:14 -040033
34import java.util.ArrayList;
35import java.util.HashMap;
36
Alexandre Lisionbe54c342014-01-21 17:10:33 -050037import android.support.v4.content.AsyncTaskLoader;
Alexandre Lision064e1e02013-10-01 16:18:42 -040038import org.sflphone.model.Account;
39import org.sflphone.service.ISipService;
40
alision11e8e162013-05-28 10:33:14 -040041import android.content.Context;
Alexandre Lisiond2e9e062013-10-21 16:27:33 -040042import android.os.Bundle;
alision11e8e162013-05-28 10:33:14 -040043import android.os.RemoteException;
44import android.util.Log;
45
Alexandre Lisiond2e9e062013-10-21 16:27:33 -040046public class AccountsLoader extends AsyncTaskLoader<Bundle> {
alision11e8e162013-05-28 10:33:14 -040047
48 private static final String TAG = AccountsLoader.class.getSimpleName();
Alexandre Lisiond2e9e062013-10-21 16:27:33 -040049 public static final String ACCOUNTS = "accounts";
50 public static final String ACCOUNT_IP2IP = "IP2IP";
alision11e8e162013-05-28 10:33:14 -040051 ISipService service;
52
53 public AccountsLoader(Context context, ISipService ref) {
54 super(context);
55 service = ref;
56 }
57
Alexandre Lisionef2aa9e2013-10-25 16:22:52 -040058 @SuppressWarnings("unchecked")
59 // Hashmap runtime cast
alision11e8e162013-05-28 10:33:14 -040060 @Override
Alexandre Lisiond2e9e062013-10-21 16:27:33 -040061 public Bundle loadInBackground() {
alision5cfc35d2013-07-11 15:11:39 -040062
Alexandre Lisiond2e9e062013-10-21 16:27:33 -040063 ArrayList<Account> accounts = new ArrayList<Account>();
64 Account IP2IP = null;
Alexandre Lisionef2aa9e2013-10-25 16:22:52 -040065
alision11e8e162013-05-28 10:33:14 -040066 try {
Alexandre Lisiond2e9e062013-10-21 16:27:33 -040067 ArrayList<String> accountIDs = (ArrayList<String>) service.getAccountList();
68 HashMap<String, String> details;
Alexandre Lision3b7148e2013-11-13 17:23:06 -050069 ArrayList<HashMap<String, String>> credentials;
alision11e8e162013-05-28 10:33:14 -040070 for (String id : accountIDs) {
alision5cfc35d2013-07-11 15:11:39 -040071
Alexandre Lisiond2e9e062013-10-21 16:27:33 -040072 if (id.contentEquals(ACCOUNT_IP2IP)) {
73 details = (HashMap<String, String>) service.getAccountDetails(id);
Alexandre Lision3b7148e2013-11-13 17:23:06 -050074 IP2IP = new Account(ACCOUNT_IP2IP, details, new ArrayList<HashMap<String, String>>()); // Empty credentials
alision11e8e162013-05-28 10:33:14 -040075 continue;
76 }
77 details = (HashMap<String, String>) service.getAccountDetails(id);
Alexandre Lision3b7148e2013-11-13 17:23:06 -050078 credentials = (ArrayList<HashMap<String, String>>) service.getCredentials(id);
79 Account tmp = new Account(id, details, credentials);
Alexandre Lisionef2aa9e2013-10-25 16:22:52 -040080
Alexandre Lision059da9d2013-10-22 11:17:25 -040081 accounts.add(tmp);
Alexandre Lisionef2aa9e2013-10-25 16:22:52 -040082
83 Log.i(TAG, "account:" + tmp.getAlias() + " " + tmp.isEnabled());
alision11e8e162013-05-28 10:33:14 -040084
85 }
86 } catch (RemoteException e) {
87 Log.e(TAG, e.toString());
alision5cfc35d2013-07-11 15:11:39 -040088 } catch (NullPointerException e1) {
alisiondf1dac92013-06-27 17:35:53 -040089 Log.e(TAG, e1.toString());
alision11e8e162013-05-28 10:33:14 -040090 }
Alexandre Lision3b7148e2013-11-13 17:23:06 -050091
Alexandre Lisiond2e9e062013-10-21 16:27:33 -040092 Bundle result = new Bundle();
93 result.putParcelableArrayList(ACCOUNTS, accounts);
94 result.putParcelable(ACCOUNT_IP2IP, IP2IP);
alision11e8e162013-05-28 10:33:14 -040095 return result;
96 }
97
98}