changeset 499:267e72057707

updates for android10+
author Carl Byington <carl@five-ten-sg.com>
date Tue, 07 Jun 2022 16:04:52 -0700
parents 3feac274a27b
children 11d714165a2d
files app/src/main/AndroidManifest.xml app/src/main/java/com/five_ten_sg/connectbot/HostListActivity.java
diffstat 2 files changed, 127 insertions(+), 112 deletions(-) [+]
line wrap: on
line diff
--- a/app/src/main/AndroidManifest.xml	Mon Jun 06 15:05:20 2022 -0700
+++ b/app/src/main/AndroidManifest.xml	Tue Jun 07 16:04:52 2022 -0700
@@ -16,113 +16,114 @@
  limitations under the License.
 -->
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
-	package="com.five_ten_sg.connectbot"
-	android:versionName="1.9.4-4"
-	android:versionCode="1944"
-	android:installLocation="auto">
+    package="com.five_ten_sg.connectbot"
+    android:versionName="1.9.4-4"
+    android:versionCode="1944"
+    android:installLocation="auto">
 
     <!--  permissions must match HostListActivity.java -->
-	<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
-	<uses-permission android:name="android.permission.FOREGROUND" />
-	<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
-	<uses-permission android:name="android.permission.INTERNET" />
-	<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
+    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
+    <uses-permission android:name="android.permission.FOREGROUND" />
+    <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
+    <uses-permission android:name="android.permission.INTERNET" />
+    <uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
+    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
     <uses-permission android:name="android.permission.REORDER_TASKS"/>
-	<uses-permission android:name="android.permission.VIBRATE" />
-	<uses-permission android:name="android.permission.WAKE_LOCK" />
-	<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
-	<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:maxSdkVersion="28" />
+    <uses-permission android:name="android.permission.VIBRATE" />
+    <uses-permission android:name="android.permission.WAKE_LOCK" />
+    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:maxSdkVersion="28" />
 
-	<permission
-		android:name="org.openintents.ssh.permission.ACCESS_SSH_AGENT"
-		android:protectionLevel="dangerous"
-		android:label="@string/ssh_agent_permission_label"
-		android:description="@string/ssh_agent_permission_desc"
-		android:icon="@drawable/pubkey">
-	</permission>
-	<!--	android:permissionGroup="android.permission-group.PERSONAL_INFO"
+    <permission
+        android:name="org.openintents.ssh.permission.ACCESS_SSH_AGENT"
+        android:protectionLevel="dangerous"
+        android:label="@string/ssh_agent_permission_label"
+        android:description="@string/ssh_agent_permission_desc"
+        android:icon="@drawable/pubkey">
+    </permission>
+    <!--    android:permissionGroup="android.permission-group.PERSONAL_INFO"
     -->
 
-	<uses-feature android:name="android.hardware.touchscreen" android:required="false"/>
+    <uses-feature android:name="android.hardware.touchscreen" android:required="false"/>
 
-	<supports-screens />
+    <supports-screens />
 
-	<application
+    <application
         android:requestLegacyExternalStorage="true"
-		android:icon="@drawable/icon"
-		android:label="@string/app_name"
-		android:description="@string/app_desc"
-		android:allowBackup="false"
-		android:backupAgent=".service.BackupAgent"
-		android:killAfterRestore="true">
+        android:usesCleartextTraffic="true"
+        android:icon="@drawable/icon"
+        android:label="@string/app_name"
+        android:description="@string/app_desc"
+        android:allowBackup="false"
+        android:backupAgent=".service.BackupAgent"
+        android:killAfterRestore="true">
 
-		<activity android:name=".HostListActivity" android:exported="true">
-			<intent-filter>
-				<action android:name="android.intent.action.MAIN" />
-				<category android:name="android.intent.category.LAUNCHER" />
-			</intent-filter>
-			<intent-filter>
-				<action android:name="android.intent.action.CREATE_SHORTCUT" />
-				<category android:name="android.intent.category.DEFAULT" />
-			</intent-filter>
-			<intent-filter>
-				<action android:name="android.intent.action.PICK" />
-				<category android:name="android.intent.category.DEFAULT" />
-				<data android:scheme="tn5250" />
-				<data android:scheme="ssh"    />
-				<data android:scheme="telnet" />
-				<data android:scheme="local"  />
-			</intent-filter>
-		</activity>
+        <activity android:name=".HostListActivity" android:exported="true">
+            <intent-filter>
+                <action android:name="android.intent.action.MAIN" />
+                <category android:name="android.intent.category.LAUNCHER" />
+            </intent-filter>
+            <intent-filter>
+                <action android:name="android.intent.action.CREATE_SHORTCUT" />
+                <category android:name="android.intent.category.DEFAULT" />
+            </intent-filter>
+            <intent-filter>
+                <action android:name="android.intent.action.PICK" />
+                <category android:name="android.intent.category.DEFAULT" />
+                <data android:scheme="tn5250" />
+                <data android:scheme="ssh"    />
+                <data android:scheme="telnet" />
+                <data android:scheme="local"  />
+            </intent-filter>
+        </activity>
 
-		<activity android:name=".PubkeyListActivity" android:exported="false" android:configChanges="keyboardHidden|orientation" >
-			<intent-filter>
-				<action android:name="org.openintents.ssh.agent.IDENTITY_ADMIN" />
-				<category android:name="android.intent.category.DEFAULT" />
-			</intent-filter>
-		</activity>
-		<activity android:name=".GeneratePubkeyActivity" android:configChanges="keyboardHidden|orientation" />
-		<activity android:name=".HostEditorActivity" android:configChanges="keyboardHidden|orientation" />
-		<activity android:name=".PortForwardListActivity" android:configChanges="keyboardHidden|orientation" />
-		<activity android:name=".SettingsActivity" android:configChanges="keyboardHidden|orientation" />
-		<activity android:name=".WizardActivity" android:configChanges="keyboardHidden|orientation" />
-		<activity android:name=".HelpActivity" android:configChanges="keyboardHidden|orientation" />
-		<activity android:name=".HelpTopicActivity" android:configChanges="keyboardHidden|orientation" />
-		<activity android:name=".ColorsActivity" android:configChanges="keyboardHidden|orientation" />
-		<activity android:name="com.lamerman.FileDialog" android:configChanges="keyboardHidden|orientation" />
+        <activity android:name=".PubkeyListActivity" android:exported="false" android:configChanges="keyboardHidden|orientation" >
+            <intent-filter>
+                <action android:name="org.openintents.ssh.agent.IDENTITY_ADMIN" />
+                <category android:name="android.intent.category.DEFAULT" />
+            </intent-filter>
+        </activity>
+        <activity android:name=".GeneratePubkeyActivity" android:configChanges="keyboardHidden|orientation" />
+        <activity android:name=".HostEditorActivity" android:configChanges="keyboardHidden|orientation" />
+        <activity android:name=".PortForwardListActivity" android:configChanges="keyboardHidden|orientation" />
+        <activity android:name=".SettingsActivity" android:configChanges="keyboardHidden|orientation" />
+        <activity android:name=".WizardActivity" android:configChanges="keyboardHidden|orientation" />
+        <activity android:name=".HelpActivity" android:configChanges="keyboardHidden|orientation" />
+        <activity android:name=".HelpTopicActivity" android:configChanges="keyboardHidden|orientation" />
+        <activity android:name=".ColorsActivity" android:configChanges="keyboardHidden|orientation" />
+        <activity android:name="com.lamerman.FileDialog" android:configChanges="keyboardHidden|orientation" />
 
-		<service android:name="com.five_ten_sg.connectbot.service.TerminalManager"
-			android:configChanges="keyboardHidden|orientation"
-			android:description="@string/service_desc" />
+        <service android:name="com.five_ten_sg.connectbot.service.TerminalManager"
+            android:configChanges="keyboardHidden|orientation"
+            android:description="@string/service_desc" />
 
-		<service android:name="com.five_ten_sg.connectbot.service.AuthAgentService"
-			android:description="@string/auth_agent_service_desc"
-			android:permission="org.openintents.ssh.permission.ACCESS_SSH_AGENT"
-			android:exported="true">
-			<intent-filter>
-				<action android:name="org.openintents.ssh.BIND_SSH_AGENT_SERVICE" />
-			</intent-filter>
-		</service>
+        <service android:name="com.five_ten_sg.connectbot.service.AuthAgentService"
+            android:description="@string/auth_agent_service_desc"
+            android:permission="org.openintents.ssh.permission.ACCESS_SSH_AGENT"
+            android:exported="true">
+            <intent-filter>
+                <action android:name="org.openintents.ssh.BIND_SSH_AGENT_SERVICE" />
+            </intent-filter>
+        </service>
 
-		<activity android:name=".ConsoleActivity" android:exported="true" android:configChanges="keyboardHidden|orientation"
-			android:theme="@style/NoTitle" android:windowSoftInputMode="stateAlwaysVisible|adjustResize"
-			android:launchMode="singleTop" android:hardwareAccelerated="false">
-			<intent-filter>
-				<action android:name="android.intent.action.VIEW" />
-				<category android:name="android.intent.category.DEFAULT" />
-				<category android:name="android.intent.category.BROWSABLE" />
-				<data android:scheme="tn5250" />
-				<data android:scheme="ssh"    />
-				<data android:scheme="telnet" />
-				<data android:scheme="local"  />
-				<!-- format:  ssh://user@host:port/#nickname  -->
-				<!-- format:  telnet://host:port/#nickname  -->
-				<!-- format:  local://  -->
-			</intent-filter>
-		</activity>
+        <activity android:name=".ConsoleActivity" android:exported="true" android:configChanges="keyboardHidden|orientation"
+            android:theme="@style/NoTitle" android:windowSoftInputMode="stateAlwaysVisible|adjustResize"
+            android:launchMode="singleTop" android:hardwareAccelerated="false">
+            <intent-filter>
+                <action android:name="android.intent.action.VIEW" />
+                <category android:name="android.intent.category.DEFAULT" />
+                <category android:name="android.intent.category.BROWSABLE" />
+                <data android:scheme="tn5250" />
+                <data android:scheme="ssh"    />
+                <data android:scheme="telnet" />
+                <data android:scheme="local"  />
+                <!-- format:  ssh://user@host:port/#nickname  -->
+                <!-- format:  telnet://host:port/#nickname  -->
+                <!-- format:  local://  -->
+            </intent-filter>
+        </activity>
 
-		<meta-data android:name="com.google.android.backup.api_key"
-			android:value="AEdPqrEAAAAIDlFz9nSUr2g0gSytW0t2cNnYAGHDkptlVohsBA" />
+        <meta-data android:name="com.google.android.backup.api_key"
+            android:value="AEdPqrEAAAAIDlFz9nSUr2g0gSytW0t2cNnYAGHDkptlVohsBA" />
 
-	</application>
+    </application>
 </manifest>
--- a/app/src/main/java/com/five_ten_sg/connectbot/HostListActivity.java	Mon Jun 06 15:05:20 2022 -0700
+++ b/app/src/main/java/com/five_ten_sg/connectbot/HostListActivity.java	Tue Jun 07 16:04:52 2022 -0700
@@ -176,27 +176,14 @@
 
         // 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};
-            checkp(perms);
+            get_permissions(new String[] {Manifest.permission.ACCESS_NETWORK_STATE,
+                                          Manifest.permission.INTERNET,
+                                          Manifest.permission.WAKE_LOCK});
             if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
-                if (!Environment.isExternalStorageManager()) {
-                    try {
-                        Intent intent = new Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION);
-                        intent.addCategory("android.intent.category.DEFAULT");
-                        intent.setData(Uri.parse(String.format("package:%s",getApplicationContext().getPackageName())));
-                        startActivity(intent);
-                    } catch (Exception e) {
-                        Intent intent = new Intent();
-                        intent.setAction(Settings.ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION);
-                        startActivity(intent);
-                    }
-                }
+                get_storage_manager();
             }
             else {
-                String [] perms2 = {Manifest.permission.WRITE_EXTERNAL_STORAGE};
-                checkp(perms2);
+                get_permissions(new String[] {Manifest.permission.WRITE_EXTERNAL_STORAGE});
             }
         }
 
@@ -291,7 +278,34 @@
         }
     }
 
-    public void checkp(String [] perms) {
+    public void get_storage_manager() {
+        if (!Environment.isExternalStorageManager()) {
+            try {
+                Intent intent = new Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION);
+                intent.addCategory("android.intent.category.DEFAULT");
+                intent.setData(Uri.parse(String.format("package:%s",getApplicationContext().getPackageName())));
+                startActivityForResult(intent, 31415);
+            } catch (Exception e) {
+                Intent intent = new Intent();
+                intent.setAction(Settings.ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION);
+                startActivityForResult(intent, 31415);
+            }
+        }
+    }
+
+    @Override
+    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
+        super.onActivityResult(requestCode, resultCode, data);
+        if (requestCode == 31415) {
+            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
+                if (!Environment.isExternalStorageManager()) {
+                    Toast.makeText(this, "Allow permission for storage access!", Toast.LENGTH_SHORT).show();
+                }
+            }
+        }
+    }
+
+    public void get_permissions(String [] perms) {
         boolean need = false;
         for (String perm : perms) {
             if (ContextCompat.checkSelfPermission(this, perm) != PackageManager.PERMISSION_GRANTED) {