changeset 465:7c8aebcc882a

request permissions if not already granted
author Carl Byington <carl@five-ten-sg.com>
date Mon, 19 Aug 2019 11:12:40 -0700
parents 3ebfae9bc0bd
children 12e2d9dd95df
files app/src/main/AndroidManifest.xml app/src/main/java/com/five_ten_sg/connectbot/HostListActivity.java app/src/main/java/com/five_ten_sg/connectbot/service/TerminalKeyListener.java build.gradle xml/510connectbot.in
diffstat 5 files changed, 41 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/app/src/main/AndroidManifest.xml	Sun Apr 28 18:26:39 2019 -0700
+++ b/app/src/main/AndroidManifest.xml	Mon Aug 19 11:12:40 2019 -0700
@@ -17,10 +17,11 @@
 -->
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
 	package="com.five_ten_sg.connectbot"
-	android:versionName="1.9.3-4"
-	android:versionCode="1934"
+	android:versionName="1.9.3-5"
+	android:versionCode="1935"
 	android:installLocation="auto">
 
+    <!--  permissions must match HostListActivity.java -->
 	<uses-permission android:name="android.permission.INTERNET" />
 	<uses-permission android:name="android.permission.VIBRATE" />
 	<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
--- a/app/src/main/java/com/five_ten_sg/connectbot/HostListActivity.java	Sun Apr 28 18:26:39 2019 -0700
+++ b/app/src/main/java/com/five_ten_sg/connectbot/HostListActivity.java	Mon Aug 19 11:12:40 2019 -0700
@@ -70,6 +70,11 @@
 import android.widget.ListView;
 import android.widget.Spinner;
 import android.widget.TextView;
+import android.content.pm.PackageManager;
+import android.os.Build;
+import android.Manifest;
+import android.support.v4.app.ActivityCompat;
+import android.support.v4.content.ContextCompat;
 
 public class HostListActivity extends ListActivity {
     protected static final String TAG = "ConnectBot.HostListActivity";
@@ -168,6 +173,15 @@
                                     getResources().getText(R.string.title_hosts_list)));
         this.prefs = PreferenceManager.getDefaultSharedPreferences(this);
 
+        // ask for permissions, must match AndroidManifest.xml
+        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
+            String [] perms = {Manifest.permission.INTERNET,
+                               Manifest.permission.ACCESS_NETWORK_STATE,
+                               Manifest.permission.WAKE_LOCK,
+                               Manifest.permission.WRITE_EXTERNAL_STORAGE};
+            checkp(perms);
+        }
+
         // detect HTC Dream and apply special preferences
         if (Build.MANUFACTURER.equals("HTC") && Build.DEVICE.equals("dream")) {
             if (!prefs.contains(PreferenceConstants.SHIFT_FKEYS) &&
@@ -252,6 +266,16 @@
         this.inflater = LayoutInflater.from(this);
     }
 
+    public void checkp(String [] perms) {
+        boolean need = false;
+        for (String perm : perms) {
+            if (ContextCompat.checkSelfPermission(this, perm) != PackageManager.PERMISSION_GRANTED) {
+                need = true;
+            }
+        }
+        if (need) ActivityCompat.requestPermissions(this, perms, 1);
+    }
+
     @Override
     public boolean onPrepareOptionsMenu(Menu menu) {
         super.onPrepareOptionsMenu(menu);
--- a/app/src/main/java/com/five_ten_sg/connectbot/service/TerminalKeyListener.java	Sun Apr 28 18:26:39 2019 -0700
+++ b/app/src/main/java/com/five_ten_sg/connectbot/service/TerminalKeyListener.java	Mon Aug 19 11:12:40 2019 -0700
@@ -142,6 +142,13 @@
         try {
             int repeat = event.getRepeatCount();
 
+            // if keycode debugging enabled, log and print the pressed key
+            if (prefs.getBoolean(PreferenceConstants.DEBUG_KEYCODES, false)) {
+                String keyCodeString = String.format(": %d %d %d", keyCode, repeat, event.getAction());
+                String toastText = v.getContext().getString(R.string.keycode_pressed) + keyCodeString;
+                Log.d(TAG, toastText);
+            }
+
             // skip keys if we aren't connected yet or have been disconnected
             if (bridge.isDisconnected()) return false;
 
@@ -153,13 +160,6 @@
                 // There's nothing else here for virtual keyboard users.
                 if (!hardKeyboard || hardKeyboardHidden) return false;
 
-                // if keycode debugging enabled, log and print the pressed key
-                if (prefs.getBoolean(PreferenceConstants.DEBUG_KEYCODES, false)) {
-                    String keyCodeString = String.format(": %d", keyCode);
-                    String toastText = v.getContext().getString(R.string.keycode_pressed) + keyCodeString;
-                    Log.d(TAG, toastText);
-                }
-
                 if (fullKeyboard()) {
                     switch (keyCode) {
                         case KeyEvent.KEYCODE_CTRL_LEFT:
@@ -573,14 +573,14 @@
                 return (handleShortcut(v, hwbuttonShortcut, repeat, down));
 
             case KeyEvent.KEYCODE_VOLUME_UP:
-                // check to see which shortcut the volume button triggers
+                // check to see which shortcut the volume up button triggers
                 hwbuttonShortcut = manager.prefs.getString(
                                        PreferenceConstants.VOLUP,
                                        PreferenceConstants.HWBUTTON_FUNCTION_KEYS);
                 return (handleShortcut(v, hwbuttonShortcut, repeat, down));
 
             case KeyEvent.KEYCODE_VOLUME_DOWN:
-                // check to see which shortcut the camera button triggers
+                // check to see which shortcut the volume down button triggers
                 hwbuttonShortcut = manager.prefs.getString(
                                        PreferenceConstants.VOLDN,
                                        PreferenceConstants.HWBUTTON_TAB);
--- a/build.gradle	Sun Apr 28 18:26:39 2019 -0700
+++ b/build.gradle	Mon Aug 19 11:12:40 2019 -0700
@@ -6,7 +6,7 @@
         google()
     }
     dependencies {
-        classpath 'com.android.tools.build:gradle:3.4.0'
+        classpath 'com.android.tools.build:gradle:3.4.2'
     }
 }
 
--- a/xml/510connectbot.in	Sun Apr 28 18:26:39 2019 -0700
+++ b/xml/510connectbot.in	Mon Aug 19 11:12:40 2019 -0700
@@ -29,7 +29,7 @@
 
     <refentry id="x@PACKAGE@.1">
         <refentryinfo>
-            <date>2019-04-28</date>
+            <date>2019-05-13</date>
             <author>
                 <firstname>Carl</firstname>
                 <surname>Byington</surname>
@@ -331,7 +331,7 @@
 
     <refentry id="x@PACKAGE@.5">
         <refentryinfo>
-            <date>2019-04-28</date>
+            <date>2019-05-13</date>
             <author>
                 <firstname>Carl</firstname>
                 <surname>Byington</surname>
@@ -353,8 +353,8 @@
         <refsect1 id='description.5'>
             <title>Description</title>
 
-            <para>The <command>deployment.connections</command> file
-            is show by this example. If this file exists at the top
+            <para>The <command>deployment.connections</command> sample
+            file is below. If this file exists at the top
             level of the external storage (as returned by
             Environment.getExternalStorageDirectory().getAbsolutePath()),
             it is read, parsed, and deleted.  Comments start with #