RtpSessionActivity.java

  1package eu.siacs.conversations.ui;
  2
  3import android.Manifest;
  4import android.annotation.SuppressLint;
  5import android.content.Context;
  6import android.content.Intent;
  7import android.databinding.DataBindingUtil;
  8import android.os.Build;
  9import android.os.Bundle;
 10import android.os.PowerManager;
 11import android.support.annotation.NonNull;
 12import android.support.annotation.StringRes;
 13import android.util.Log;
 14import android.view.View;
 15import android.view.WindowManager;
 16import android.widget.Toast;
 17
 18import com.google.common.collect.ImmutableList;
 19
 20import java.lang.ref.WeakReference;
 21import java.util.Arrays;
 22import java.util.Set;
 23
 24import eu.siacs.conversations.Config;
 25import eu.siacs.conversations.R;
 26import eu.siacs.conversations.databinding.ActivityRtpSessionBinding;
 27import eu.siacs.conversations.entities.Account;
 28import eu.siacs.conversations.entities.Contact;
 29import eu.siacs.conversations.services.AppRTCAudioManager;
 30import eu.siacs.conversations.services.XmppConnectionService;
 31import eu.siacs.conversations.utils.PermissionUtils;
 32import eu.siacs.conversations.xmpp.jingle.AbstractJingleConnection;
 33import eu.siacs.conversations.xmpp.jingle.JingleRtpConnection;
 34import eu.siacs.conversations.xmpp.jingle.RtpEndUserState;
 35import rocks.xmpp.addr.Jid;
 36
 37import static eu.siacs.conversations.utils.PermissionUtils.getFirstDenied;
 38import static java.util.Arrays.asList;
 39
 40//TODO if last state was BUSY (or RETRY); we want to reset action to view or something so we don’t automatically call again on recreate
 41
 42public class RtpSessionActivity extends XmppActivity implements XmppConnectionService.OnJingleRtpConnectionUpdate {
 43
 44    private static final String PROXIMITY_WAKE_LOCK_TAG = "conversations:in-rtp-session";
 45
 46    private static final int REQUEST_ACCEPT_CALL = 0x1111;
 47
 48    public static final String EXTRA_WITH = "with";
 49    public static final String EXTRA_SESSION_ID = "session_id";
 50    public static final String EXTRA_LAST_REPORTED_STATE = "last_reported_state";
 51
 52    public static final String ACTION_ACCEPT_CALL = "action_accept_call";
 53    public static final String ACTION_MAKE_VOICE_CALL = "action_make_voice_call";
 54    public static final String ACTION_MAKE_VIDEO_CALL = "action_make_video_call";
 55
 56    private WeakReference<JingleRtpConnection> rtpConnectionReference;
 57
 58    private ActivityRtpSessionBinding binding;
 59    private PowerManager.WakeLock mProximityWakeLock;
 60
 61    @Override
 62    public void onCreate(Bundle savedInstanceState) {
 63        super.onCreate(savedInstanceState);
 64        getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
 65                | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
 66                | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
 67                | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
 68        Log.d(Config.LOGTAG, "RtpSessionActivity.onCreate()");
 69        this.binding = DataBindingUtil.setContentView(this, R.layout.activity_rtp_session);
 70    }
 71
 72    @Override
 73    public void onStart() {
 74        super.onStart();
 75        Log.d(Config.LOGTAG, "RtpSessionActivity.onStart()");
 76    }
 77
 78    private void endCall(View view) {
 79        endCall();
 80    }
 81
 82    private void endCall() {
 83        if (this.rtpConnectionReference == null) {
 84            final Intent intent = getIntent();
 85            final Account account = extractAccount(intent);
 86            final Jid with = Jid.of(intent.getStringExtra(EXTRA_WITH));
 87            xmppConnectionService.getJingleConnectionManager().retractSessionProposal(account, with.asBareJid());
 88            finish();
 89        } else {
 90            requireRtpConnection().endCall();
 91        }
 92    }
 93
 94    private void rejectCall(View view) {
 95        requireRtpConnection().rejectCall();
 96        finish();
 97    }
 98
 99    private void acceptCall(View view) {
100        requestPermissionsAndAcceptCall();
101    }
102
103    private void requestPermissionsAndAcceptCall() {
104        if (PermissionUtils.hasPermission(this, ImmutableList.of(Manifest.permission.RECORD_AUDIO), REQUEST_ACCEPT_CALL)) {
105            //TODO like wise the propose; we might just wait here for the audio manager to come up
106            putScreenInCallMode();
107            requireRtpConnection().acceptCall();
108        }
109    }
110
111    @SuppressLint("WakelockTimeout")
112    private void putScreenInCallMode() {
113        getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
114        final JingleRtpConnection rtpConnection = rtpConnectionReference != null ? rtpConnectionReference.get() : null;
115        final AppRTCAudioManager audioManager = rtpConnection == null ? null : rtpConnection.getAudioManager();
116        if (audioManager == null || audioManager.getSelectedAudioDevice() == AppRTCAudioManager.AudioDevice.EARPIECE) {
117            acquireProximityWakeLock();
118        }
119    }
120
121    private void acquireProximityWakeLock() {
122        final PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
123        if (powerManager == null) {
124            Log.e(Config.LOGTAG, "power manager not available");
125            return;
126        }
127        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
128            if (this.mProximityWakeLock == null) {
129                this.mProximityWakeLock = powerManager.newWakeLock(PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK, PROXIMITY_WAKE_LOCK_TAG);
130            }
131            if (!this.mProximityWakeLock.isHeld()) {
132                Log.d(Config.LOGTAG, "acquiring proximity wake lock");
133                this.mProximityWakeLock.acquire();
134            }
135        }
136    }
137
138    private void releaseProximityWakeLock() {
139        if (this.mProximityWakeLock != null && mProximityWakeLock.isHeld()) {
140            Log.d(Config.LOGTAG, "releasing proximity wake lock");
141            this.mProximityWakeLock.release();
142            this.mProximityWakeLock = null;
143        }
144    }
145
146    private void putProximityWakeLockInProperState() {
147        if (requireRtpConnection().getAudioManager().getSelectedAudioDevice() == AppRTCAudioManager.AudioDevice.EARPIECE) {
148            acquireProximityWakeLock();
149        } else {
150            releaseProximityWakeLock();
151        }
152    }
153
154    @Override
155    protected void refreshUiReal() {
156
157    }
158
159    @Override
160    public void onNewIntent(final Intent intent) {
161        super.onNewIntent(intent);
162        setIntent(intent);
163        if (xmppConnectionService == null) {
164            Log.d(Config.LOGTAG, "RtpSessionActivity: background service wasn't bound in onNewIntent()");
165            return;
166        }
167        final Account account = extractAccount(intent);
168        final Jid with = Jid.of(intent.getStringExtra(EXTRA_WITH));
169        final String sessionId = intent.getStringExtra(EXTRA_SESSION_ID);
170        if (sessionId != null) {
171            Log.d(Config.LOGTAG, "reinitializing from onNewIntent()");
172            initializeActivityWithRunningRtpSession(account, with, sessionId);
173            if (ACTION_ACCEPT_CALL.equals(intent.getAction())) {
174                Log.d(Config.LOGTAG, "accepting call from onNewIntent()");
175                requestPermissionsAndAcceptCall();
176                resetIntent(intent.getExtras());
177            }
178        } else {
179            throw new IllegalStateException("received onNewIntent without sessionId");
180        }
181    }
182
183    @Override
184    void onBackendConnected() {
185        final Intent intent = getIntent();
186        final Account account = extractAccount(intent);
187        final Jid with = Jid.of(intent.getStringExtra(EXTRA_WITH));
188        final String sessionId = intent.getStringExtra(EXTRA_SESSION_ID);
189        if (sessionId != null) {
190            initializeActivityWithRunningRtpSession(account, with, sessionId);
191            if (ACTION_ACCEPT_CALL.equals(intent.getAction())) {
192                Log.d(Config.LOGTAG, "intent action was accept");
193                requestPermissionsAndAcceptCall();
194                resetIntent(intent.getExtras());
195            }
196        } else if (asList(ACTION_MAKE_VIDEO_CALL, ACTION_MAKE_VOICE_CALL).contains(intent.getAction())) {
197            proposeJingleRtpSession(account, with);
198            binding.with.setText(account.getRoster().getContact(with).getDisplayName());
199        } else if (Intent.ACTION_VIEW.equals(intent.getAction())) {
200            final String extraLastState = intent.getStringExtra(EXTRA_LAST_REPORTED_STATE);
201            if (extraLastState != null) {
202                Log.d(Config.LOGTAG, "restored last state from intent extra");
203                RtpEndUserState state = RtpEndUserState.valueOf(extraLastState);
204                updateButtonConfiguration(state);
205                updateStateDisplay(state);
206            }
207            binding.with.setText(account.getRoster().getContact(with).getDisplayName());
208        }
209    }
210
211    private void proposeJingleRtpSession(final Account account, final Jid with) {
212        xmppConnectionService.getJingleConnectionManager().proposeJingleRtpSession(account, with);
213        //TODO maybe we don’t want to acquire a wake lock just yet and wait for audio manager to discover what speaker we are using
214        putScreenInCallMode();
215    }
216
217    @Override
218    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
219        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
220        if (PermissionUtils.allGranted(grantResults)) {
221            if (requestCode == REQUEST_ACCEPT_CALL) {
222                requireRtpConnection().acceptCall();
223            }
224        } else {
225            @StringRes int res;
226            final String firstDenied = getFirstDenied(grantResults, permissions);
227            if (Manifest.permission.RECORD_AUDIO.equals(firstDenied)) {
228                res = R.string.no_microphone_permission;
229            } else if (Manifest.permission.CAMERA.equals(firstDenied)) {
230                res = R.string.no_camera_permission;
231            } else {
232                throw new IllegalStateException("Invalid permission result request");
233            }
234            Toast.makeText(this, res, Toast.LENGTH_SHORT).show();
235        }
236    }
237
238    @Override
239    public void onStop() {
240        releaseProximityWakeLock();
241        //TODO maybe we want to finish if call had ended
242        super.onStop();
243    }
244
245    @Override
246    public void onBackPressed() {
247        endCall();
248        super.onBackPressed();
249    }
250
251
252    private void initializeActivityWithRunningRtpSession(final Account account, Jid with, String sessionId) {
253        final WeakReference<JingleRtpConnection> reference = xmppConnectionService.getJingleConnectionManager()
254                .findJingleRtpConnection(account, with, sessionId);
255        if (reference == null || reference.get() == null) {
256            finish();
257            return;
258        }
259        this.rtpConnectionReference = reference;
260        final RtpEndUserState currentState = requireRtpConnection().getEndUserState();
261        if (currentState == RtpEndUserState.ENDED) {
262            finish();
263            return;
264        }
265        if (currentState == RtpEndUserState.INCOMING_CALL) {
266            getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
267        }
268        if (JingleRtpConnection.STATES_SHOWING_ONGOING_CALL.contains(requireRtpConnection().getState())) {
269            putScreenInCallMode();
270        }
271        binding.with.setText(getWith().getDisplayName());
272        updateStateDisplay(currentState);
273        updateButtonConfiguration(currentState);
274    }
275
276    private void reInitializeActivityWithRunningRapSession(final Account account, Jid with, String sessionId) {
277        runOnUiThread(() -> {
278            initializeActivityWithRunningRtpSession(account, with, sessionId);
279        });
280        final Intent intent = new Intent(Intent.ACTION_VIEW);
281        intent.putExtra(EXTRA_ACCOUNT, account.getJid().toEscapedString());
282        intent.putExtra(EXTRA_WITH, with.toEscapedString());
283        intent.putExtra(EXTRA_SESSION_ID, sessionId);
284        setIntent(intent);
285    }
286
287    private void updateStateDisplay(final RtpEndUserState state) {
288        switch (state) {
289            case INCOMING_CALL:
290                binding.status.setText(R.string.rtp_state_incoming_call);
291                break;
292            case CONNECTING:
293                binding.status.setText(R.string.rtp_state_connecting);
294                break;
295            case CONNECTED:
296                binding.status.setText(R.string.rtp_state_connected);
297                break;
298            case ACCEPTING_CALL:
299                binding.status.setText(R.string.rtp_state_accepting_call);
300                break;
301            case ENDING_CALL:
302                binding.status.setText(R.string.rtp_state_ending_call);
303                break;
304            case FINDING_DEVICE:
305                binding.status.setText(R.string.rtp_state_finding_device);
306                break;
307            case RINGING:
308                binding.status.setText(R.string.rtp_state_ringing);
309                break;
310            case DECLINED_OR_BUSY:
311                binding.status.setText(R.string.rtp_state_declined_or_busy);
312                break;
313            case CONNECTIVITY_ERROR:
314                binding.status.setText(R.string.rtp_state_connectivity_error);
315                break;
316            case APPLICATION_ERROR:
317                binding.status.setText(R.string.rtp_state_application_failure);
318                break;
319            case ENDED:
320                throw new IllegalStateException("Activity should have called finishAndReleaseWakeLock();");
321            default:
322                throw new IllegalStateException(String.format("State %s has not been handled in UI", state));
323        }
324    }
325
326    @SuppressLint("RestrictedApi")
327    private void updateButtonConfiguration(final RtpEndUserState state) {
328        if (state == RtpEndUserState.INCOMING_CALL) {
329            this.binding.rejectCall.setOnClickListener(this::rejectCall);
330            this.binding.rejectCall.setImageResource(R.drawable.ic_call_end_white_48dp);
331            this.binding.rejectCall.setVisibility(View.VISIBLE);
332            this.binding.endCall.setVisibility(View.INVISIBLE);
333            this.binding.acceptCall.setOnClickListener(this::acceptCall);
334            this.binding.acceptCall.setImageResource(R.drawable.ic_call_white_48dp);
335            this.binding.acceptCall.setVisibility(View.VISIBLE);
336        } else if (state == RtpEndUserState.ENDING_CALL) {
337            this.binding.rejectCall.setVisibility(View.INVISIBLE);
338            this.binding.endCall.setVisibility(View.INVISIBLE);
339            this.binding.acceptCall.setVisibility(View.INVISIBLE);
340        } else if (state == RtpEndUserState.DECLINED_OR_BUSY) {
341            this.binding.rejectCall.setVisibility(View.INVISIBLE);
342            this.binding.endCall.setOnClickListener(this::exit);
343            this.binding.endCall.setImageResource(R.drawable.ic_clear_white_48dp);
344            this.binding.endCall.setVisibility(View.VISIBLE);
345            this.binding.acceptCall.setVisibility(View.INVISIBLE);
346        } else if (state == RtpEndUserState.CONNECTIVITY_ERROR || state == RtpEndUserState.APPLICATION_ERROR) {
347            this.binding.rejectCall.setOnClickListener(this::exit);
348            this.binding.rejectCall.setImageResource(R.drawable.ic_clear_white_48dp);
349            this.binding.rejectCall.setVisibility(View.VISIBLE);
350            this.binding.endCall.setVisibility(View.INVISIBLE);
351            this.binding.acceptCall.setOnClickListener(this::retry);
352            this.binding.acceptCall.setImageResource(R.drawable.ic_replay_white_48dp);
353            this.binding.acceptCall.setVisibility(View.VISIBLE);
354        } else {
355            this.binding.rejectCall.setVisibility(View.INVISIBLE);
356            this.binding.endCall.setOnClickListener(this::endCall);
357            this.binding.endCall.setImageResource(R.drawable.ic_call_end_white_48dp);
358            this.binding.endCall.setVisibility(View.VISIBLE);
359            this.binding.acceptCall.setVisibility(View.INVISIBLE);
360        }
361        updateInCallButtonConfiguration(state);
362    }
363
364    private void updateInCallButtonConfiguration() {
365        updateInCallButtonConfiguration(requireRtpConnection().getEndUserState());
366    }
367
368    @SuppressLint("RestrictedApi")
369    private void updateInCallButtonConfiguration(final RtpEndUserState state) {
370        if (state == RtpEndUserState.CONNECTED) {
371            final AppRTCAudioManager audioManager = requireRtpConnection().getAudioManager();
372            updateInCallButtonConfiguration(
373                    audioManager.getSelectedAudioDevice(),
374                    audioManager.getAudioDevices().size(),
375                    requireRtpConnection().isMicrophoneEnabled()
376            );
377        } else {
378            this.binding.inCallActionLeft.setVisibility(View.GONE);
379            this.binding.inCallActionRight.setVisibility(View.GONE);
380        }
381    }
382
383    @SuppressLint("RestrictedApi")
384    private void updateInCallButtonConfiguration(final AppRTCAudioManager.AudioDevice selectedAudioDevice, final int numberOfChoices, final boolean microphoneEnabled) {
385        switch (selectedAudioDevice) {
386            case EARPIECE:
387                this.binding.inCallActionLeft.setImageResource(R.drawable.ic_volume_off_black_24dp);
388                if (numberOfChoices >= 2) {
389                    this.binding.inCallActionLeft.setOnClickListener(this::switchToSpeaker);
390                } else {
391                    this.binding.inCallActionLeft.setOnClickListener(null);
392                    this.binding.inCallActionLeft.setClickable(false);
393                }
394                break;
395            case WIRED_HEADSET:
396                this.binding.inCallActionLeft.setImageResource(R.drawable.ic_headset_black_24dp);
397                this.binding.inCallActionLeft.setOnClickListener(null);
398                this.binding.inCallActionLeft.setClickable(false);
399                break;
400            case SPEAKER_PHONE:
401                this.binding.inCallActionLeft.setImageResource(R.drawable.ic_volume_up_black_24dp);
402                if (numberOfChoices >= 2) {
403                    this.binding.inCallActionLeft.setOnClickListener(this::switchToEarpiece);
404                } else {
405                    this.binding.inCallActionLeft.setOnClickListener(null);
406                    this.binding.inCallActionLeft.setClickable(false);
407                }
408                break;
409            case BLUETOOTH:
410                this.binding.inCallActionLeft.setImageResource(R.drawable.ic_bluetooth_audio_black_24dp);
411                this.binding.inCallActionLeft.setOnClickListener(null);
412                this.binding.inCallActionLeft.setClickable(false);
413                break;
414        }
415        this.binding.inCallActionLeft.setVisibility(View.VISIBLE);
416        if (microphoneEnabled) {
417            this.binding.inCallActionRight.setImageResource(R.drawable.ic_mic_black_24dp);
418            this.binding.inCallActionRight.setOnClickListener(this::disableMicrophone);
419        } else {
420            this.binding.inCallActionRight.setImageResource(R.drawable.ic_mic_off_black_24dp);
421            this.binding.inCallActionRight.setOnClickListener(this::enableMicrophone);
422        }
423        this.binding.inCallActionRight.setVisibility(View.VISIBLE);
424    }
425
426    private void disableMicrophone(View view) {
427        JingleRtpConnection rtpConnection = requireRtpConnection();
428        rtpConnection.setMicrophoneEnabled(false);
429        updateInCallButtonConfiguration();
430    }
431
432    private void enableMicrophone(View view) {
433        JingleRtpConnection rtpConnection = requireRtpConnection();
434        rtpConnection.setMicrophoneEnabled(true);
435        updateInCallButtonConfiguration();
436    }
437
438    private void switchToEarpiece(View view) {
439        requireRtpConnection().getAudioManager().setDefaultAudioDevice(AppRTCAudioManager.AudioDevice.EARPIECE);
440        acquireProximityWakeLock();
441    }
442
443    private void switchToSpeaker(View view) {
444        requireRtpConnection().getAudioManager().setDefaultAudioDevice(AppRTCAudioManager.AudioDevice.SPEAKER_PHONE);
445        releaseProximityWakeLock();
446    }
447
448    private void retry(View view) {
449        Log.d(Config.LOGTAG, "attempting retry");
450        final Intent intent = getIntent();
451        final Account account = extractAccount(intent);
452        final Jid with = Jid.of(intent.getStringExtra(EXTRA_WITH));
453        this.rtpConnectionReference = null;
454        proposeJingleRtpSession(account, with);
455    }
456
457    private void exit(View view) {
458        finish();
459    }
460
461    private Contact getWith() {
462        final AbstractJingleConnection.Id id = requireRtpConnection().getId();
463        final Account account = id.account;
464        return account.getRoster().getContact(id.with);
465    }
466
467    private JingleRtpConnection requireRtpConnection() {
468        final JingleRtpConnection connection = this.rtpConnectionReference != null ? this.rtpConnectionReference.get() : null;
469        if (connection == null) {
470            throw new IllegalStateException("No RTP connection found");
471        }
472        return connection;
473    }
474
475    @Override
476    public void onJingleRtpConnectionUpdate(Account account, Jid with, final String sessionId, RtpEndUserState state) {
477        if (Arrays.asList(RtpEndUserState.APPLICATION_ERROR, RtpEndUserState.DECLINED_OR_BUSY, RtpEndUserState.DECLINED_OR_BUSY).contains(state)) {
478            releaseProximityWakeLock();
479        }
480        Log.d(Config.LOGTAG, "onJingleRtpConnectionUpdate(" + state + ")");
481        if (with.isBareJid()) {
482            updateRtpSessionProposalState(account, with, state);
483            return;
484        }
485        if (this.rtpConnectionReference == null) {
486            //this happens when going from proposed session to actual session
487            reInitializeActivityWithRunningRapSession(account, with, sessionId);
488            return;
489        }
490        final AbstractJingleConnection.Id id = requireRtpConnection().getId();
491        if (account == id.account && id.with.equals(with) && id.sessionId.equals(sessionId)) {
492            if (state == RtpEndUserState.ENDED) {
493                finish();
494                return;
495            } else if (asList(RtpEndUserState.APPLICATION_ERROR, RtpEndUserState.DECLINED_OR_BUSY, RtpEndUserState.CONNECTIVITY_ERROR).contains(state)) {
496                resetIntent(account, with, state);
497            }
498            runOnUiThread(() -> {
499                updateStateDisplay(state);
500                updateButtonConfiguration(state);
501            });
502        } else {
503            Log.d(Config.LOGTAG, "received update for other rtp session");
504            //TODO if we only ever have one; we might just switch over? Maybe!
505        }
506    }
507
508    @Override
509    public void onAudioDeviceChanged(AppRTCAudioManager.AudioDevice selectedAudioDevice, Set<AppRTCAudioManager.AudioDevice> availableAudioDevices) {
510        Log.d(Config.LOGTAG, "onAudioDeviceChanged in activity: selected:" + selectedAudioDevice + ", available:" + availableAudioDevices);
511        try {
512            if (requireRtpConnection().getEndUserState() == RtpEndUserState.CONNECTED) {
513                final AppRTCAudioManager audioManager = requireRtpConnection().getAudioManager();
514                updateInCallButtonConfiguration(
515                        audioManager.getSelectedAudioDevice(),
516                        audioManager.getAudioDevices().size(),
517                        requireRtpConnection().isMicrophoneEnabled()
518                );
519            }
520            putProximityWakeLockInProperState();
521        } catch (IllegalStateException e) {
522            Log.d(Config.LOGTAG, "RTP connection was not available when audio device changed");
523        }
524    }
525
526    private void updateRtpSessionProposalState(final Account account, final Jid with, final RtpEndUserState state) {
527        final Intent currentIntent = getIntent();
528        final String withExtra = currentIntent == null ? null : currentIntent.getStringExtra(EXTRA_WITH);
529        if (withExtra == null) {
530            return;
531        }
532        if (Jid.ofEscaped(withExtra).asBareJid().equals(with)) {
533            runOnUiThread(() -> {
534                updateStateDisplay(state);
535                updateButtonConfiguration(state);
536            });
537            resetIntent(account, with, state);
538        }
539    }
540
541    private void resetIntent(final Bundle extras) {
542        final Intent intent = new Intent(Intent.ACTION_VIEW);
543        intent.putExtras(extras);
544        setIntent(intent);
545    }
546
547    private void resetIntent(final Account account, Jid with, final RtpEndUserState state) {
548        final Intent intent = new Intent(Intent.ACTION_VIEW);
549        intent.putExtra(EXTRA_WITH, with.asBareJid().toEscapedString());
550        intent.putExtra(EXTRA_ACCOUNT, account.getJid().toEscapedString());
551        intent.putExtra(EXTRA_LAST_REPORTED_STATE, state.toString());
552        setIntent(intent);
553    }
554}