Skip to content

Commit

Permalink
Add Support for JuiceSSH as per murgo#141
Browse files Browse the repository at this point in the history
  • Loading branch information
pc-coholic committed Dec 2, 2018
1 parent 42a52b1 commit fd888f0
Show file tree
Hide file tree
Showing 12 changed files with 307 additions and 17 deletions.
1 change: 1 addition & 0 deletions Android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ allprojects {
repositories {
jcenter()
google()
maven { url 'https://raw.github.com/Sonelli/maven/master' }
}
}

Expand Down
2 changes: 2 additions & 0 deletions Android/mobile/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ dependencies {

implementation "com.android.support:appcompat-v7:27.1.1"
implementation 'com.android.support:support-v4:27.1.1'

implementation 'com.sonelli:juicessh-pluginlibrary:1.0.+@aar'
}

apply plugin: 'com.google.gms.google-services'
14 changes: 12 additions & 2 deletions Android/mobile/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="fi.iki.murgo.irssinotifier" >
xmlns:tools="http://schemas.android.com/tools"
package="fi.iki.murgo.irssinotifier">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.USE_CREDENTIALS" />
<uses-permission android:name="com.sonelli.juicessh.api.v1.permission.READ_CONNECTIONS" />
<uses-permission android:name="com.sonelli.juicessh.api.v1.permission.OPEN_SESSIONS" />
<!--
This was required on lower API levels but I guess not any more?
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
-->

<uses-sdk />

<application android:icon="@drawable/icon"
<application tools:replace="android:icon"
android:icon="@drawable/icon"
android:name="fi.iki.murgo.irssinotifier.IrssiNotifierApplication"
android:label="@string/app_name"
android:allowBackup="false"
Expand Down Expand Up @@ -52,6 +56,12 @@
android:theme="@style/Theme.IrssiTheme"
>
</activity>
<activity
android:name="fi.iki.murgo.irssinotifier.JuiceSSHLauncher"
android:label="@string/app_name"
android:theme="@style/Theme.IrssiTheme"
>
</activity>

<!--
<meta-data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,11 @@ public boolean onCreateOptionsMenu(Menu menu) {
menu.findItem(R.id.menu_irssi_connectbot).setEnabled(false);
}

if (!preferences.getJuiceSSHEnabled() || !IntentSniffer.isPackageAvailable(this, JuiceSSHLauncher.PACKAGE_JUICESSH)) {
menu.findItem(R.id.menu_juicessh).setVisible(false);
menu.findItem(R.id.menu_juicessh).setEnabled(false);
}

return true;
}

Expand All @@ -383,6 +388,9 @@ public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == R.id.menu_irssi_connectbot) {
IrssiConnectbotLauncher.launchIrssiConnectbot(this);
//MessageGenerator.Flood(this);
} else if (item.getItemId() == R.id.menu_juicessh) {
Intent intent = new Intent(this, JuiceSSHLauncher.class);
startActivity(intent);
} else if (item.getItemId() == R.id.menu_settings) {
Intent settingsActivity = new Intent(this, SettingsActivity.class);
startActivity(settingsActivity);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@

package fi.iki.murgo.irssinotifier;

import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.widget.Toast;

import com.sonelli.juicessh.pluginlibrary.PluginClient;
import com.sonelli.juicessh.pluginlibrary.PluginContract;
import com.sonelli.juicessh.pluginlibrary.exceptions.ServiceNotConnectedException;
import com.sonelli.juicessh.pluginlibrary.listeners.OnClientStartedListener;
import com.sonelli.juicessh.pluginlibrary.listeners.OnSessionFinishedListener;
import com.sonelli.juicessh.pluginlibrary.listeners.OnSessionStartedListener;

public class JuiceSSHLauncher extends Activity implements OnSessionStartedListener, OnSessionFinishedListener, OnClientStartedListener {
public final static String PACKAGE_JUICESSH = "com.sonelli.juicessh";
private final static int JUICESSH_REQUEST_ID = 2342;
private final PluginClient client = new PluginClient();
private boolean isClientStarted = false;
private boolean isConnectionInitiated = false;
private String hostUUID;

@Override
public void onStart() {
super.onStart();

Preferences prefs = new Preferences(this);
hostUUID = prefs.getJuiceSSHHostUUID();

if (hostUUID == null) {
if (!IntentSniffer.isPackageAvailable(this, JuiceSSHLauncher.PACKAGE_JUICESSH)) {
finish();
}

Intent juiceSSHActivity = new Intent(this.getPackageManager().getLaunchIntentForPackage(PACKAGE_JUICESSH));
this.startActivity(juiceSSHActivity);
finish();
}

if (!hasPermissions()) {
ActivityCompat.requestPermissions(this,
new String[]{PluginContract.PERMISSION_OPEN_SESSIONS},
0);
finish();
}

if (!isConnectionInitiated) {
client.start(this, JuiceSSHLauncher.this);
} else if (isConnectionInitiated && isClientStarted) {
finish();
}
}

@Override
protected void onStop() {
super.onStop();
if(isClientStarted && !isConnectionInitiated){
isClientStarted = false;
client.stop(this);
}
}

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}

@Override
public void onSessionStarted(final int sessionId, final String sessionKey) {
try {
client.attach(sessionId, sessionKey);
} catch (ServiceNotConnectedException e) {
e.printStackTrace();
}
}

@Override
public void onSessionCancelled() {
if(isClientStarted) {
isClientStarted = false;
client.stop(this);
}
}

@Override
public void onSessionFinished() {
if(isClientStarted) {
isClientStarted = false;
client.stop(this);
}
}

@Override
public void onClientStarted() {
isClientStarted = true;

if (isClientStarted){
try {
isConnectionInitiated = true;
client.connect(this, java.util.UUID.fromString(hostUUID), JuiceSSHLauncher.this, JUICESSH_REQUEST_ID);
} catch (ServiceNotConnectedException e) {
Toast.makeText(this, "Could not connect to JuiceSSH Plugin Service", Toast.LENGTH_SHORT).show();
}
}
}

@Override
public void onClientStopped() {
isClientStarted = false;
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);

if(requestCode == JUICESSH_REQUEST_ID){
client.gotActivityResult(requestCode, resultCode, data);
}
}

private boolean hasPermissions() {
return (ContextCompat.checkSelfPermission(this, PluginContract.PERMISSION_OPEN_SESSIONS)
== PackageManager.PERMISSION_GRANTED);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import android.net.Uri;
import android.preference.PreferenceManager;
import android.provider.Settings;
import android.util.Log;

import com.google.firebase.iid.FirebaseInstanceId;

Expand Down Expand Up @@ -40,6 +39,9 @@ public class Preferences {
private static final String ICB_HOST_INTENT_URI = "IcbHostIntentUri";
private static final String ICB_HOST_NAME = "IcbHostName";
private static final String ICB_ENABLED = "IcbEnabled";
private static final String JUICESSH_HOST_INTENT_URI = "JuiceSSHHostIntentUri";
private static final String JUICESSH_HOST_NAME = "JuiceSSHHostName";
private static final String JUICESSH_ENABLED = "JuiceSSHEnabled";
private static final String THEME_DISABLED = "ThemeDisabled";
private static final String ACCOUNT_NAME = "AccountName";
private static final String CUSTOM_LIGHT_COLOR = "CustomLightColor";
Expand Down Expand Up @@ -193,7 +195,22 @@ public boolean getIcbEnabled() {
public String getIcbHostIntentUri() {
return sharedPreferences.getString(ICB_HOST_INTENT_URI, null);
}
public boolean setJuiceSSHHost(String hostName, String hostUri) {
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putString(JUICESSH_HOST_NAME, hostName);
editor.putString(JUICESSH_HOST_INTENT_URI, hostUri);
return editor.commit();
}

public String getJuiceSSHHostName() {
return sharedPreferences.getString(JUICESSH_HOST_NAME, null);
}
public boolean getJuiceSSHEnabled() {
return sharedPreferences.getBoolean(JUICESSH_ENABLED, true);
}
public String getJuiceSSHHostUUID() {
return sharedPreferences.getString(JUICESSH_HOST_INTENT_URI, null);
}
public boolean isThemeDisabled() {
return sharedPreferences.getBoolean(THEME_DISABLED, false);
}
Expand Down
Loading

0 comments on commit fd888f0

Please sign in to comment.