Alexandre Lision | a8b7872 | 2013-12-13 10:18:33 -0500 | [diff] [blame] | 1 | /* |
Alexandre Lision | c1024c0 | 2014-01-06 11:12:53 -0500 | [diff] [blame] | 2 | * Copyright (C) 2004-2014 Savoir-Faire Linux Inc. |
Alexandre Lision | a8b7872 | 2013-12-13 10:18:33 -0500 | [diff] [blame] | 3 | * |
| 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 Lision | 064e1e0 | 2013-10-01 16:18:42 -0400 | [diff] [blame] | 32 | package org.sflphone.loaders; |
alision | 11e8e16 | 2013-05-28 10:33:14 -0400 | [diff] [blame] | 33 | |
| 34 | import java.util.ArrayList; |
| 35 | import java.util.HashMap; |
| 36 | |
Alexandre Lision | be54c34 | 2014-01-21 17:10:33 -0500 | [diff] [blame] | 37 | import android.support.v4.content.AsyncTaskLoader; |
Alexandre Lision | 064e1e0 | 2013-10-01 16:18:42 -0400 | [diff] [blame] | 38 | import org.sflphone.model.Account; |
| 39 | import org.sflphone.service.ISipService; |
| 40 | |
alision | 11e8e16 | 2013-05-28 10:33:14 -0400 | [diff] [blame] | 41 | import android.content.Context; |
Alexandre Lision | d2e9e06 | 2013-10-21 16:27:33 -0400 | [diff] [blame] | 42 | import android.os.Bundle; |
alision | 11e8e16 | 2013-05-28 10:33:14 -0400 | [diff] [blame] | 43 | import android.os.RemoteException; |
| 44 | import android.util.Log; |
| 45 | |
Alexandre Lision | d2e9e06 | 2013-10-21 16:27:33 -0400 | [diff] [blame] | 46 | public class AccountsLoader extends AsyncTaskLoader<Bundle> { |
alision | 11e8e16 | 2013-05-28 10:33:14 -0400 | [diff] [blame] | 47 | |
| 48 | private static final String TAG = AccountsLoader.class.getSimpleName(); |
Alexandre Lision | d2e9e06 | 2013-10-21 16:27:33 -0400 | [diff] [blame] | 49 | public static final String ACCOUNTS = "accounts"; |
| 50 | public static final String ACCOUNT_IP2IP = "IP2IP"; |
alision | 11e8e16 | 2013-05-28 10:33:14 -0400 | [diff] [blame] | 51 | ISipService service; |
| 52 | |
| 53 | public AccountsLoader(Context context, ISipService ref) { |
| 54 | super(context); |
| 55 | service = ref; |
| 56 | } |
| 57 | |
Alexandre Lision | ef2aa9e | 2013-10-25 16:22:52 -0400 | [diff] [blame] | 58 | @SuppressWarnings("unchecked") |
| 59 | // Hashmap runtime cast |
alision | 11e8e16 | 2013-05-28 10:33:14 -0400 | [diff] [blame] | 60 | @Override |
Alexandre Lision | d2e9e06 | 2013-10-21 16:27:33 -0400 | [diff] [blame] | 61 | public Bundle loadInBackground() { |
alision | 5cfc35d | 2013-07-11 15:11:39 -0400 | [diff] [blame] | 62 | |
Alexandre Lision | d2e9e06 | 2013-10-21 16:27:33 -0400 | [diff] [blame] | 63 | ArrayList<Account> accounts = new ArrayList<Account>(); |
| 64 | Account IP2IP = null; |
Alexandre Lision | ef2aa9e | 2013-10-25 16:22:52 -0400 | [diff] [blame] | 65 | |
alision | 11e8e16 | 2013-05-28 10:33:14 -0400 | [diff] [blame] | 66 | try { |
Alexandre Lision | d2e9e06 | 2013-10-21 16:27:33 -0400 | [diff] [blame] | 67 | ArrayList<String> accountIDs = (ArrayList<String>) service.getAccountList(); |
| 68 | HashMap<String, String> details; |
Alexandre Lision | 3b7148e | 2013-11-13 17:23:06 -0500 | [diff] [blame] | 69 | ArrayList<HashMap<String, String>> credentials; |
alision | 11e8e16 | 2013-05-28 10:33:14 -0400 | [diff] [blame] | 70 | for (String id : accountIDs) { |
alision | 5cfc35d | 2013-07-11 15:11:39 -0400 | [diff] [blame] | 71 | |
Alexandre Lision | d2e9e06 | 2013-10-21 16:27:33 -0400 | [diff] [blame] | 72 | if (id.contentEquals(ACCOUNT_IP2IP)) { |
| 73 | details = (HashMap<String, String>) service.getAccountDetails(id); |
Alexandre Lision | 3b7148e | 2013-11-13 17:23:06 -0500 | [diff] [blame] | 74 | IP2IP = new Account(ACCOUNT_IP2IP, details, new ArrayList<HashMap<String, String>>()); // Empty credentials |
alision | 11e8e16 | 2013-05-28 10:33:14 -0400 | [diff] [blame] | 75 | continue; |
| 76 | } |
| 77 | details = (HashMap<String, String>) service.getAccountDetails(id); |
Alexandre Lision | 3b7148e | 2013-11-13 17:23:06 -0500 | [diff] [blame] | 78 | credentials = (ArrayList<HashMap<String, String>>) service.getCredentials(id); |
| 79 | Account tmp = new Account(id, details, credentials); |
Alexandre Lision | ef2aa9e | 2013-10-25 16:22:52 -0400 | [diff] [blame] | 80 | |
Alexandre Lision | 059da9d | 2013-10-22 11:17:25 -0400 | [diff] [blame] | 81 | accounts.add(tmp); |
Alexandre Lision | ef2aa9e | 2013-10-25 16:22:52 -0400 | [diff] [blame] | 82 | |
| 83 | Log.i(TAG, "account:" + tmp.getAlias() + " " + tmp.isEnabled()); |
alision | 11e8e16 | 2013-05-28 10:33:14 -0400 | [diff] [blame] | 84 | |
| 85 | } |
| 86 | } catch (RemoteException e) { |
| 87 | Log.e(TAG, e.toString()); |
alision | 5cfc35d | 2013-07-11 15:11:39 -0400 | [diff] [blame] | 88 | } catch (NullPointerException e1) { |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 89 | Log.e(TAG, e1.toString()); |
alision | 11e8e16 | 2013-05-28 10:33:14 -0400 | [diff] [blame] | 90 | } |
Alexandre Lision | 3b7148e | 2013-11-13 17:23:06 -0500 | [diff] [blame] | 91 | |
Alexandre Lision | d2e9e06 | 2013-10-21 16:27:33 -0400 | [diff] [blame] | 92 | Bundle result = new Bundle(); |
| 93 | result.putParcelableArrayList(ACCOUNTS, accounts); |
| 94 | result.putParcelable(ACCOUNT_IP2IP, IP2IP); |
alision | 11e8e16 | 2013-05-28 10:33:14 -0400 | [diff] [blame] | 95 | return result; |
| 96 | } |
| 97 | |
| 98 | } |