blob: 53ccc01db04035ee5dee21af68b0e6b19bba1141 [file] [log] [blame]
Adrien BĂ©raud04d822c2015-04-02 17:44:36 -04001/*
2 * Copyright (C) 2004-2014 Savoir-Faire Linux Inc.
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
32package cx.ring.fragments;
33
34import android.content.BroadcastReceiver;
35import android.content.Context;
36import android.content.Intent;
37import android.content.IntentFilter;
38import android.os.Bundle;
39import android.support.v4.app.Fragment;
40import android.util.Log;
41import cx.ring.interfaces.CallInterface;
42import cx.ring.model.Conference;
43import cx.ring.service.CallManagerCallBack;
44
45import java.util.HashMap;
46
47public abstract class CallableWrapperFragment extends Fragment implements CallInterface {
48
49
50 private CallReceiver mReceiver;
51
52
53 @Override
54 public void onCreate(Bundle savedInstanceState) {
55 super.onCreate(savedInstanceState);
56 mReceiver = new CallReceiver();
57 }
58
59 @Override
60 public void onResume() {
61 super.onResume();
62 IntentFilter intentFilter = new IntentFilter();
63 intentFilter.addAction(CallManagerCallBack.INCOMING_CALL);
64 intentFilter.addAction(CallManagerCallBack.INCOMING_TEXT);
65 intentFilter.addAction(CallManagerCallBack.CALL_STATE_CHANGED);
66 intentFilter.addAction(CallManagerCallBack.CONF_CREATED);
67 intentFilter.addAction(CallManagerCallBack.CONF_REMOVED);
68 intentFilter.addAction(CallManagerCallBack.CONF_CHANGED);
69 intentFilter.addAction(CallManagerCallBack.RECORD_STATE_CHANGED);
70 intentFilter.addAction(CallManagerCallBack.ZRTP_OFF);
71 intentFilter.addAction(CallManagerCallBack.ZRTP_ON);
72 intentFilter.addAction(CallManagerCallBack.DISPLAY_SAS);
73 intentFilter.addAction(CallManagerCallBack.ZRTP_NEGOTIATION_FAILED);
74 intentFilter.addAction(CallManagerCallBack.ZRTP_NOT_SUPPORTED);
75 intentFilter.addAction(CallManagerCallBack.RTCP_REPORT_RECEIVED);
76 getActivity().registerReceiver(mReceiver, intentFilter);
77 }
78
79
80 @Override
81 public void onPause() {
82 super.onPause();
83 getActivity().unregisterReceiver(mReceiver);
84 }
85
86 @Override
87 public void callStateChanged(Conference c, String callID, String state) {
88
89 }
90
91 @Override
92 public void incomingText(Conference c, String ID, String from, String msg) {
93
94 }
95
96 @Override
97 public void confCreated(Conference c, String id) {
98
99 }
100
101 @Override
102 public void confRemoved(Conference c, String id) {
103
104 }
105
106 @Override
107 public void confChanged(Conference c, String id, String state) {
108
109 }
110
111 @Override
112 public void recordingChanged(Conference c, String callID, String filename) {
113
114 }
115
116 @Override
117 public void secureZrtpOn(Conference c, String id) {
118
119 }
120
121 @Override
122 public void secureZrtpOff(Conference c, String id) {
123
124 }
125
126 @Override
127 public void displaySAS(Conference c, String securedCallID) {
128
129 }
130
131 @Override
132 public void zrtpNegotiationFailed(Conference c, String securedCallID) {
133
134 }
135
136 @Override
137 public void zrtpNotSupported(Conference c, String securedCallID) {
138
139 }
140
141 @Override
142 public void rtcpReportReceived(Conference c, HashMap<String, Integer> stats) {
143
144 }
145
146
147 public class CallReceiver extends BroadcastReceiver {
148
149 private final String TAG = CallReceiver.class.getSimpleName();
150
151 @Override
152 public void onReceive(Context context, Intent intent) {
153 if (intent.getAction().contentEquals(CallManagerCallBack.INCOMING_TEXT)) {
154 incomingText((Conference) intent.getParcelableExtra("conference"), intent.getStringExtra("CallID"), intent.getStringExtra("From"), intent.getStringExtra("Msg"));
155 } else if (intent.getAction().contentEquals(CallManagerCallBack.CALL_STATE_CHANGED)) {
156 callStateChanged((Conference) intent.getParcelableExtra("conference"), intent.getStringExtra("CallID"), intent.getStringExtra("State"));
157 } else if (intent.getAction().contentEquals(CallManagerCallBack.CONF_CREATED)) {
158 confCreated((Conference) intent.getParcelableExtra("conference"), intent.getStringExtra("confID"));
159 } else if (intent.getAction().contentEquals(CallManagerCallBack.CONF_REMOVED)) {
160 confRemoved((Conference) intent.getParcelableExtra("conference"), intent.getStringExtra("confID"));
161 } else if (intent.getAction().contentEquals(CallManagerCallBack.CONF_CHANGED)) {
162 confChanged((Conference) intent.getParcelableExtra("conference"), intent.getStringExtra("confID"), intent.getStringExtra("state"));
163 } else if (intent.getAction().contentEquals(CallManagerCallBack.RECORD_STATE_CHANGED)) {
164 recordingChanged((Conference) intent.getParcelableExtra("conference"), intent.getStringExtra("callID"), intent.getStringExtra("file"));
165 } else if (intent.getAction().contentEquals(CallManagerCallBack.ZRTP_OFF)) {
166 secureZrtpOff((Conference) intent.getParcelableExtra("conference"), intent.getStringExtra("callID"));
167 } else if (intent.getAction().contentEquals(CallManagerCallBack.ZRTP_ON)) {
168 secureZrtpOn((Conference) intent.getParcelableExtra("conference"), intent.getStringExtra("callID"));
169 } else if (intent.getAction().contentEquals(CallManagerCallBack.DISPLAY_SAS)) {
170 displaySAS((Conference) intent.getParcelableExtra("conference"), intent.getStringExtra("callID"));
171 } else if (intent.getAction().contentEquals(CallManagerCallBack.ZRTP_NEGOTIATION_FAILED)) {
172 zrtpNegotiationFailed((Conference) intent.getParcelableExtra("conference"), intent.getStringExtra("callID"));
173 } else if (intent.getAction().contentEquals(CallManagerCallBack.ZRTP_NOT_SUPPORTED)) {
174 zrtpNotSupported((Conference) intent.getParcelableExtra("conference"), intent.getStringExtra("callID"));
175 } else if (intent.getAction().contentEquals(CallManagerCallBack.RTCP_REPORT_RECEIVED)) {
176 rtcpReportReceived(null, null); // FIXME
177 } else {
178 Log.e(TAG, "Unknown action: " + intent.getAction());
179 }
180
181 }
182
183 }
184}