Alexandre Lision | 270c875 | 2013-10-01 17:25:39 -0400 | [diff] [blame] | 1 | /** |
| 2 | * Copyright (C) 2010-2012 Regis Montoya (aka r3gis - www.r3gis.fr) |
| 3 | * Copyright (C) 2004-2012 Savoir-Faire Linux Inc. |
| 4 | * |
| 5 | * Author: Alexandre Savard <alexandre.savard@savoirfairelinux.com> |
| 6 | * |
| 7 | * This program is free software: you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation, either version 3 of the License, or |
| 10 | * (at your option) any later version. |
| 11 | * If you own a pjsip commercial license you can also redistribute it |
| 12 | * and/or modify it under the terms of the GNU Lesser General Public License |
| 13 | * as an android library. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | * GNU General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU General Public License |
| 21 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 22 | */ |
| 23 | package org.sflphone.service; |
| 24 | |
| 25 | import android.content.Context; |
| 26 | import android.content.Intent; |
| 27 | import android.support.v4.content.LocalBroadcastManager; |
| 28 | |
| 29 | public class ConfigurationManagerCallback extends ConfigurationCallback { |
| 30 | // private static final String TAG = "ConfigurationManagerCallback"; |
| 31 | private Context mContext; |
| 32 | |
| 33 | static public final String SIGNAL_NAME = "signal-name"; |
| 34 | static public final String ACCOUNTS_CHANGED = "accounts-changed"; |
| 35 | static public final String ACCOUNT_STATE_CHANGED = "account-state-changed"; |
| 36 | |
| 37 | public ConfigurationManagerCallback(Context context) { |
| 38 | mContext = context; |
| 39 | } |
| 40 | |
| 41 | @Override |
| 42 | public void on_accounts_changed() { |
| 43 | sendAccountsChangedMessage(); |
| 44 | } |
| 45 | |
| 46 | @Override |
| 47 | public void on_account_state_changed(String accoundID, int state) { |
| 48 | String strState = ""; |
| 49 | switch (state){ |
| 50 | case 0: |
| 51 | strState = "UNREGISTERED"; |
| 52 | break; |
| 53 | case 1: |
| 54 | strState = "TRYING"; |
| 55 | break; |
| 56 | case 2: |
| 57 | strState = "REGISTERED"; |
| 58 | break; |
| 59 | case 3: |
| 60 | strState = "ERROR_GENERIC"; |
| 61 | break; |
| 62 | case 4: |
| 63 | strState = "ERROR_AUTH"; |
| 64 | break; |
| 65 | case 5: |
| 66 | strState = "ERROR_NETWORK"; |
| 67 | break; |
| 68 | case 6: |
| 69 | strState = "ERROR_HOST"; |
| 70 | break; |
| 71 | case 7: |
| 72 | strState = "ERROR_EXIST_STUN"; |
| 73 | break; |
| 74 | case 8: |
| 75 | strState = "ERROR_NOT_ACCEPTABLE"; |
| 76 | break; |
| 77 | case 9: |
| 78 | strState = "NUMBER_OF_STATES"; |
| 79 | break; |
| 80 | } |
| 81 | |
| 82 | |
| 83 | sendAccountsStateChangedMessage(accoundID, strState, 0); |
| 84 | } |
| 85 | |
| 86 | @Override |
| 87 | public void on_account_state_changed_with_code(String accoundID, String state, int code) { |
| 88 | sendAccountsStateChangedMessage(accoundID, state, code); |
| 89 | } |
| 90 | |
| 91 | private void sendAccountsStateChangedMessage(String accoundID, String state, int code) { |
| 92 | Intent intent = new Intent(ACCOUNT_STATE_CHANGED); |
| 93 | intent.putExtra("Account", accoundID); |
| 94 | intent.putExtra("state", state); |
| 95 | intent.putExtra("code", code); |
| 96 | LocalBroadcastManager.getInstance(mContext).sendBroadcast(intent); |
| 97 | } |
| 98 | |
| 99 | private void sendAccountsChangedMessage() { |
| 100 | Intent intent = new Intent(ACCOUNTS_CHANGED); |
| 101 | LocalBroadcastManager.getInstance(mContext).sendBroadcast(intent); |
| 102 | } |
| 103 | |
| 104 | } |