2
2
3
3
import android .app .ActivityManager ;
4
4
import android .content .Intent ;
5
+ import android .os .Bundle ;
5
6
import android .os .Handler ;
6
7
import android .os .Looper ;
7
8
import androidx .localbroadcastmanager .content .LocalBroadcastManager ;
@@ -60,7 +61,7 @@ public void onNewToken(String token) {
60
61
@ Override
61
62
public void onMessageReceived (RemoteMessage remoteMessage ) {
62
63
if (BuildConfig .DEBUG ) {
63
- Log .d (TAG , "Bundle data : " + remoteMessage .getData ());
64
+ Log .d (TAG , "VoiceFirebaseMessagingService onMessageReceived : " + remoteMessage .getMessageType ());
64
65
}
65
66
66
67
// Check if message contains a data payload.
@@ -74,7 +75,6 @@ public void onMessageReceived(RemoteMessage remoteMessage) {
74
75
boolean valid = Voice .handleMessage (data , new MessageListener () {
75
76
@ Override
76
77
public void onCallInvite (final CallInvite callInvite ) {
77
-
78
78
// We need to run this on the main thread, as the React code assumes that is true.
79
79
// Namely, DevServerHelper constructs a Handler() without a Looper, which triggers:
80
80
// "Can't create handler inside thread that has not called Looper.prepare()"
@@ -93,7 +93,9 @@ public void run() {
93
93
Intent launchIntent = callNotificationManager .getLaunchIntent (
94
94
(ReactApplicationContext )context ,
95
95
notificationId ,
96
- callInvite ,
96
+ callInvite .getCallSid (),
97
+ callInvite .getFrom (),
98
+ callInvite .getTo (),
97
99
false ,
98
100
appImportance
99
101
);
@@ -106,28 +108,53 @@ public void run() {
106
108
intent .putExtra (INCOMING_CALL_INVITE , callInvite );
107
109
LocalBroadcastManager .getInstance (context ).sendBroadcast (intent );
108
110
} else {
109
- // Otherwise wait for construction, then handle the incoming call
110
- mReactInstanceManager .addReactInstanceEventListener (new ReactInstanceManager .ReactInstanceEventListener () {
111
- public void onReactContextInitialized (ReactContext context ) {
112
- int appImportance = callNotificationManager .getApplicationImportance ((ReactApplicationContext )context );
113
- if (BuildConfig .DEBUG ) {
114
- Log .d (TAG , "CONTEXT not present appImportance = " + appImportance );
115
- }
116
- Intent launchIntent = callNotificationManager .getLaunchIntent ((ReactApplicationContext )context , notificationId , callInvite , true , appImportance );
117
- context .startActivity (launchIntent );
118
- Intent intent = new Intent (ACTION_INCOMING_CALL );
119
- intent .putExtra (INCOMING_CALL_NOTIFICATION_ID , notificationId );
120
- intent .putExtra (INCOMING_CALL_INVITE , callInvite );
121
- LocalBroadcastManager .getInstance (context ).sendBroadcast (intent );
122
- callNotificationManager .createIncomingCallNotification (
123
- (ReactApplicationContext ) context , callInvite , notificationId ,
124
- launchIntent );
125
- }
126
- });
127
- if (!mReactInstanceManager .hasStartedCreatingInitialContext ()) {
128
- // Construct it in the background
129
- mReactInstanceManager .createReactContextInBackground ();
130
- }
111
+ Intent callKeepIntent = new Intent ();
112
+ callKeepIntent .setAction ("com.hoxfon.HoxFon.DEV.debug.BACKGROUND_CALL" );
113
+ callKeepIntent .setPackage ("com.hoxfon.HoxFon.DEV.debug" );
114
+ Bundle bundle = new Bundle ();
115
+ bundle .putString ("call_state" , "PENDING" );
116
+ bundle .putString ("call_sid" , callInvite .getCallSid ());
117
+ bundle .putString ("call_from" , callInvite .getFrom ());
118
+ bundle .putString ("call_to" , callInvite .getTo ());
119
+ callKeepIntent .putExtras (bundle );
120
+ Log .d (TAG , "BACKGROUND onCallInvite, callKeepIntent " + callKeepIntent );
121
+
122
+ sendBroadcast (callKeepIntent );
123
+
124
+ // // Otherwise wait for construction, then handle the incoming call
125
+ // mReactInstanceManager.addReactInstanceEventListener(new ReactInstanceManager.ReactInstanceEventListener() {
126
+ // public void onReactContextInitialized(ReactContext context) {
127
+ // int appImportance = callNotificationManager.getApplicationImportance((ReactApplicationContext)context);
128
+ // if (BuildConfig.DEBUG) {
129
+ // Log.d(TAG, "CONTEXT not present appImportance = " + appImportance);
130
+ // }
131
+ // Intent launchIntent = callNotificationManager.getLaunchIntent(
132
+ // (ReactApplicationContext)context,
133
+ // notificationId,
134
+ // callInvite.getCallSid(),
135
+ // callInvite.getFrom(),
136
+ // callInvite.getTo(),
137
+ // true,
138
+ // appImportance
139
+ // );
140
+ // context.startActivity(launchIntent);
141
+ // Intent intent = new Intent(ACTION_INCOMING_CALL);
142
+ // intent.putExtra(INCOMING_CALL_NOTIFICATION_ID, notificationId);
143
+ // intent.putExtra(INCOMING_CALL_INVITE, callInvite);
144
+ // LocalBroadcastManager.getInstance(context).sendBroadcast(intent);
145
+ // callNotificationManager.createIncomingCallNotification(
146
+ // (ReactApplicationContext) context,
147
+ // callInvite.getCallSid(),
148
+ // callInvite.getFrom(),
149
+ // notificationId,
150
+ // launchIntent
151
+ // );
152
+ // }
153
+ // });
154
+ // if (!mReactInstanceManager.hasStartedCreatingInitialContext()) {
155
+ // // Construct it in the background
156
+ // mReactInstanceManager.createReactContextInBackground();
157
+ // }
131
158
}
132
159
}
133
160
});
@@ -160,8 +187,19 @@ public void run() {
160
187
*/
161
188
private void sendCancelledCallInviteToActivity (CancelledCallInvite cancelledCallInvite ) {
162
189
SoundPoolManager .getInstance ((this )).stopRinging ();
163
- Intent intent = new Intent (ACTION_CANCEL_CALL_INVITE );
164
- intent .putExtra (CANCELLED_CALL_INVITE , cancelledCallInvite );
165
- LocalBroadcastManager .getInstance (this ).sendBroadcast (intent );
190
+ // Intent intent = new Intent(ACTION_CANCEL_CALL_INVITE);
191
+ // intent.putExtra(CANCELLED_CALL_INVITE, cancelledCallInvite);
192
+ // LocalBroadcastManager.getInstance(this).sendBroadcast(intent);
193
+
194
+ Intent callKeepIntent = new Intent ();
195
+ callKeepIntent .setAction ("com.hoxfon.react.RNTwilioVoice.BACKGROUND_CALL" );
196
+ callKeepIntent .setPackage ("com.hoxfon.react.RNTwilioVoice" );
197
+ Bundle bundle = new Bundle ();
198
+ bundle .putString ("call_state" , "CANCELLED" );
199
+ bundle .putString ("call_sid" , cancelledCallInvite .getCallSid ());
200
+ bundle .putString ("call_from" , cancelledCallInvite .getFrom ());
201
+ bundle .putString ("call_to" , cancelledCallInvite .getTo ());
202
+ callKeepIntent .putExtras (bundle );
203
+ sendBroadcast (callKeepIntent );
166
204
}
167
205
}
0 commit comments