FreeRDP
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 
11 package com.freerdp.freerdpcore.services;
12 
13 import android.app.Activity;
14 import android.app.SearchManager;
15 import android.content.Intent;
16 import android.os.Bundle;
17 import androidx.appcompat.app.AppCompatActivity;
18 
19 import com.freerdp.freerdpcore.domain.ConnectionReference;
20 import com.freerdp.freerdpcore.presentation.BookmarkActivity;
21 import com.freerdp.freerdpcore.presentation.SessionActivity;
22 
23 public class SessionRequestHandlerActivity extends AppCompatActivity
24 {
25 
26  @Override public void onCreate(Bundle savedInstanceState)
27  {
28  super.onCreate(savedInstanceState);
29  handleIntent(getIntent());
30  }
31 
32  @Override protected void onNewIntent(Intent intent)
33  {
34  setIntent(intent);
35  handleIntent(intent);
36  }
37 
38  private void startSessionWithConnectionReference(String refStr)
39  {
40 
41  Bundle bundle = new Bundle();
42  bundle.putString(SessionActivity.PARAM_CONNECTION_REFERENCE, refStr);
43  Intent sessionIntent = new Intent(this, SessionActivity.class);
44  sessionIntent.putExtras(bundle);
45 
46  startActivityForResult(sessionIntent, 0);
47  }
48 
49  private void editBookmarkWithConnectionReference(String refStr)
50  {
51  Bundle bundle = new Bundle();
52  bundle.putString(BookmarkActivity.PARAM_CONNECTION_REFERENCE, refStr);
53  Intent bookmarkIntent = new Intent(this.getApplicationContext(), BookmarkActivity.class);
54  bookmarkIntent.putExtras(bundle);
55  startActivityForResult(bookmarkIntent, 0);
56  }
57 
58  private void handleIntent(Intent intent)
59  {
60 
61  String action = intent.getAction();
62  if (Intent.ACTION_SEARCH.equals(action))
63  startSessionWithConnectionReference(ConnectionReference.getHostnameReference(
64  intent.getStringExtra(SearchManager.QUERY)));
65  else if (Intent.ACTION_VIEW.equals(action))
66  startSessionWithConnectionReference(intent.getDataString());
67  else if (Intent.ACTION_EDIT.equals(action))
68  editBookmarkWithConnectionReference(intent.getDataString());
69  }
70 
71  @Override protected void onActivityResult(int requestCode, int resultCode, Intent data)
72  {
73  super.onActivityResult(requestCode, resultCode, data);
74  this.setResult(resultCode);
75  this.finish();
76  }
77 }