Alexandre Savard | fccd1dc | 2012-10-17 17:31:38 -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 com.savoirfairelinux.sflphone.service; |
| 24 | |
Alexandre Savard | 4f11d7a | 2012-10-18 13:15:36 -0400 | [diff] [blame] | 25 | import android.content.Context; |
| 26 | import android.content.Intent; |
| 27 | import android.support.v4.content.LocalBroadcastManager; |
Alexandre Savard | fccd1dc | 2012-10-17 17:31:38 -0400 | [diff] [blame] | 28 | import android.util.Log; |
| 29 | |
| 30 | public class ConfigurationManagerCallback extends ConfigurationCallback { |
Alexandre Savard | 4f11d7a | 2012-10-18 13:15:36 -0400 | [diff] [blame] | 31 | private static final String TAG = "ConfigurationManagerCallback"; |
alision | 58356b7 | 2013-06-03 17:13:36 -0400 | [diff] [blame] | 32 | private Context mContext; |
Alexandre Savard | 4f11d7a | 2012-10-18 13:15:36 -0400 | [diff] [blame] | 33 | |
Alexandre Savard | bb6f187 | 2012-11-01 17:25:55 -0400 | [diff] [blame] | 34 | static public final String SIGNAL_NAME = "signal-name"; |
alision | a432515 | 2013-04-19 11:10:03 -0400 | [diff] [blame] | 35 | static public final String ACCOUNTS_CHANGED = "accounts-changed"; |
Alexandre Savard | bb6f187 | 2012-11-01 17:25:55 -0400 | [diff] [blame] | 36 | static public final String ACCOUNT_STATE_CHANGED = "account-state-changed"; |
| 37 | |
Alexandre Savard | 74c1cad | 2012-10-24 16:39:00 -0400 | [diff] [blame] | 38 | public ConfigurationManagerCallback(Context context) { |
Alexandre Savard | 4f11d7a | 2012-10-18 13:15:36 -0400 | [diff] [blame] | 39 | mContext = context; |
| 40 | } |
Alexandre Savard | fccd1dc | 2012-10-17 17:31:38 -0400 | [diff] [blame] | 41 | |
| 42 | @Override |
alision | 58356b7 | 2013-06-03 17:13:36 -0400 | [diff] [blame] | 43 | public void on_accounts_changed() { |
Alexandre Savard | 4f11d7a | 2012-10-18 13:15:36 -0400 | [diff] [blame] | 44 | sendAccountsChangedMessage(); |
| 45 | } |
| 46 | |
alision | 58356b7 | 2013-06-03 17:13:36 -0400 | [diff] [blame] | 47 | @Override |
| 48 | public void on_account_state_changed(String accoundID, int state) { |
| 49 | String strState = ""; |
| 50 | switch (state){ |
| 51 | case 0: |
| 52 | strState = "UNREGISTERED"; |
| 53 | break; |
| 54 | case 1: |
| 55 | strState = "TRYING"; |
| 56 | break; |
| 57 | case 2: |
| 58 | strState = "REGISTERED"; |
| 59 | break; |
| 60 | case 3: |
| 61 | strState = "ERROR_GENERIC"; |
| 62 | break; |
| 63 | case 4: |
| 64 | strState = "ERROR_AUTH"; |
| 65 | break; |
| 66 | case 5: |
| 67 | strState = "ERROR_NETWORK"; |
| 68 | break; |
| 69 | case 6: |
| 70 | strState = "ERROR_HOST"; |
| 71 | break; |
| 72 | case 7: |
| 73 | strState = "ERROR_EXIST_STUN"; |
| 74 | break; |
| 75 | case 8: |
| 76 | strState = "ERROR_NOT_ACCEPTABLE"; |
| 77 | break; |
| 78 | case 9: |
| 79 | strState = "NUMBER_OF_STATES"; |
| 80 | break; |
| 81 | } |
| 82 | |
| 83 | |
| 84 | sendAccountsStateChangedMessage(accoundID, strState, 0); |
| 85 | } |
| 86 | |
| 87 | @Override |
| 88 | public void on_account_state_changed_with_code(String accoundID, String state, int code) { |
| 89 | sendAccountsStateChangedMessage(accoundID, state, code); |
| 90 | } |
| 91 | |
| 92 | private void sendAccountsStateChangedMessage(String accoundID, String state, int code) { |
| 93 | Intent intent = new Intent(ACCOUNT_STATE_CHANGED); |
| 94 | intent.putExtra("Account", accoundID); |
| 95 | intent.putExtra("state", state); |
| 96 | intent.putExtra("code", code); |
Alexandre Savard | 4f11d7a | 2012-10-18 13:15:36 -0400 | [diff] [blame] | 97 | LocalBroadcastManager.getInstance(mContext).sendBroadcast(intent); |
Alexandre Savard | fccd1dc | 2012-10-17 17:31:38 -0400 | [diff] [blame] | 98 | } |
Alexandre Savard | bb6f187 | 2012-11-01 17:25:55 -0400 | [diff] [blame] | 99 | |
alision | 58356b7 | 2013-06-03 17:13:36 -0400 | [diff] [blame] | 100 | private void sendAccountsChangedMessage() { |
| 101 | Intent intent = new Intent(ACCOUNTS_CHANGED); |
Alexandre Savard | bb6f187 | 2012-11-01 17:25:55 -0400 | [diff] [blame] | 102 | LocalBroadcastManager.getInstance(mContext).sendBroadcast(intent); |
| 103 | } |
alision | 58356b7 | 2013-06-03 17:13:36 -0400 | [diff] [blame] | 104 | |
Alexandre Savard | fccd1dc | 2012-10-17 17:31:38 -0400 | [diff] [blame] | 105 | } |