FreeRDP
Loading...
Searching...
No Matches
SessionRequestHandlerActivity.java
1/*
2 Activity for handling connection requests
3
4 Copyright 2013 Thincast Technologies GmbH, Author: Martin Fleisz
5
6 This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
7 If a copy of the MPL was not distributed with this file, You can obtain one at
8 http://mozilla.org/MPL/2.0/.
9*/
10
11package com.freerdp.freerdpcore.services;
12
13import android.app.SearchManager;
14import android.content.Intent;
15import android.os.Bundle;
16import androidx.activity.result.ActivityResultLauncher;
17import androidx.activity.result.contract.ActivityResultContracts;
18import androidx.appcompat.app.AppCompatActivity;
19
20import com.freerdp.freerdpcore.domain.ConnectionReference;
21import com.freerdp.freerdpcore.presentation.BookmarkActivity;
22import com.freerdp.freerdpcore.presentation.SessionActivity;
23
24public class SessionRequestHandlerActivity extends AppCompatActivity
25{
26 private final ActivityResultLauncher<Intent> launcher =
27 registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), result -> {
28 setResult(result.getResultCode());
29 finish();
30 });
31
32 @Override public void onCreate(Bundle savedInstanceState)
33 {
34 super.onCreate(savedInstanceState);
35 handleIntent(getIntent());
36 }
37
38 @Override protected void onNewIntent(Intent intent)
39 {
40 setIntent(intent);
41 handleIntent(intent);
42 }
43
44 private void startSessionWithConnectionReference(String refStr)
45 {
46
47 Bundle bundle = new Bundle();
48 bundle.putString(SessionActivity.PARAM_CONNECTION_REFERENCE, refStr);
49 Intent sessionIntent = new Intent(this, SessionActivity.class);
50 sessionIntent.putExtras(bundle);
51
52 launcher.launch(sessionIntent);
53 }
54
55 private void editBookmarkWithConnectionReference(String refStr)
56 {
57 Bundle bundle = new Bundle();
58 bundle.putString(BookmarkActivity.PARAM_CONNECTION_REFERENCE, refStr);
59 Intent bookmarkIntent = new Intent(this.getApplicationContext(), BookmarkActivity.class);
60 bookmarkIntent.putExtras(bundle);
61 launcher.launch(bookmarkIntent);
62 }
63
64 private void handleIntent(Intent intent)
65 {
66
67 String action = intent.getAction();
68 if (Intent.ACTION_SEARCH.equals(action))
69 startSessionWithConnectionReference(ConnectionReference.getHostnameReference(
70 intent.getStringExtra(SearchManager.QUERY)));
71 else if (Intent.ACTION_VIEW.equals(action))
72 startSessionWithConnectionReference(intent.getDataString());
73 else if (Intent.ACTION_EDIT.equals(action))
74 editBookmarkWithConnectionReference(intent.getDataString());
75 }
76}