From 75c40168ac623435968bbbdad53cd0794f10d1a2 Mon Sep 17 00:00:00 2001 From: Jonathan Bennett Date: Thu, 18 Jun 2015 18:32:56 -0500 Subject: [PATCH] V1.0.1 Fixes a permissions related crash that can occur if Juicessh is installed after Fwknop2 --- app/build.gradle | 4 +- .../fwknop2/ConfigDetailFragment.java | 46 ++++++++++++------- 2 files changed, 32 insertions(+), 18 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index f37a25e..b51a518 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -32,8 +32,8 @@ android { applicationId "org.cipherdyne.fwknop2" minSdkVersion 15 targetSdkVersion 19 - versionCode 4 - versionName "1.0" + versionCode 5 + versionName "1.0.1" ndk { moduleName 'libfwknop' ldLibs 'log' diff --git a/app/src/main/java/biz/incomsystems/fwknop2/ConfigDetailFragment.java b/app/src/main/java/biz/incomsystems/fwknop2/ConfigDetailFragment.java index 01ac316..eb952ee 100644 --- a/app/src/main/java/biz/incomsystems/fwknop2/ConfigDetailFragment.java +++ b/app/src/main/java/biz/incomsystems/fwknop2/ConfigDetailFragment.java @@ -18,6 +18,7 @@ import android.app.Activity; import android.content.Context; +import android.content.pm.PackageManager; import android.net.Uri; import android.os.Bundle; import android.support.v4.app.Fragment; @@ -375,26 +376,39 @@ public void onItemSelected(AdapterView parent, View view, lay_sshcmd.setVisibility(View.VISIBLE); spn_juice.setVisibility(View.GONE); } else if (parent.getItemAtPosition(pos).toString().equalsIgnoreCase("Juicessh")) { - lay_sshcmd.setVisibility(View.GONE); - - if (connectionListLoader == null) { - connectionListLoader = new ConnectionListLoader(getActivity(), juice_adapt); - connectionListLoader.setOnLoadedListener(new ConnectionListLoader.OnLoadedListener() { - @Override - public void onLoaded() { // This is so ugly... - spn_juice.setVisibility(View.VISIBLE); - if (config.SSH_CMD.contains("juice:") && spn_juice.getCount() > 0 ) { - for (int n = 0; n < spn_juice.getCount(); n++) { - if (config.SSH_CMD.contains(juice_adapt.getConnectionName(n))) { - spn_juice.setSelection(n); + if(getActivity().checkCallingOrSelfPermission("com.sonelli.juicessh.api.v1.permission.READ_CONNECTIONS") == PackageManager.PERMISSION_GRANTED) { + + lay_sshcmd.setVisibility(View.GONE); + + if (connectionListLoader == null) { + connectionListLoader = new ConnectionListLoader(getActivity(), juice_adapt); + connectionListLoader.setOnLoadedListener(new ConnectionListLoader.OnLoadedListener() { + @Override + public void onLoaded() { // This is so ugly... + spn_juice.setVisibility(View.VISIBLE); + if (config.SSH_CMD.contains("juice:") && spn_juice.getCount() > 0) { + for (int n = 0; n < spn_juice.getCount(); n++) { + if (config.SSH_CMD.contains(juice_adapt.getConnectionName(n))) { + spn_juice.setSelection(n); + } } } } - } - }); - getActivity().getSupportLoaderManager().initLoader(0, null, connectionListLoader); + }); + getActivity().getSupportLoaderManager().initLoader(0, null, connectionListLoader); + } else { + getActivity().getSupportLoaderManager().restartLoader(0, null, connectionListLoader); + } } else { - getActivity().getSupportLoaderManager().restartLoader(0, null, connectionListLoader); + Context context = getActivity(); + CharSequence text = "Fwknop2 does not have permission to access Juicessh connection list. Please reinstall Fwknop2."; + int duration = Toast.LENGTH_LONG; + Toast toast = Toast.makeText(context, text, duration); + toast.setGravity(Gravity.CENTER, 0, 0); + LinearLayout toastLayout = (LinearLayout) toast.getView(); + TextView toastTV = (TextView) toastLayout.getChildAt(0); + toastTV.setTextSize(30); + toast.show(); } } }