Commit 4898ff58 authored by Mygod's avatar Mygod Committed by Max Lv

Catch no files manager exception

parent c6e4491a
...@@ -5,10 +5,10 @@ jobs: ...@@ -5,10 +5,10 @@ jobs:
docker: docker:
- image: shadowsocks/shadowsocks-android:circleci - image: shadowsocks/shadowsocks-android:circleci
environment: environment:
JVM_OPTS: -Xmx3.5g JVM_OPTS: -Xmx5g
resource_class: medium+
steps: steps:
- checkout - checkout
- run: git submodule sync
- run: git submodule update --init --recursive - run: git submodule update --init --recursive
- restore_cache: - restore_cache:
key: jars-{{ checksum "build.gradle" }} key: jars-{{ checksum "build.gradle" }}
...@@ -16,7 +16,7 @@ jobs: ...@@ -16,7 +16,7 @@ jobs:
key: go-full-{{ checksum "~/code/.git/modules/core/src/overture/go/HEAD" }} key: go-full-{{ checksum "~/code/.git/modules/core/src/overture/go/HEAD" }}
- run: - run:
name: Run Build and Tests name: Run Build and Tests
command: ./gradlew goBuild assembleDebug check command: ./gradlew assembleDebug check
- save_cache: - save_cache:
paths: paths:
- ~/.gradle - ~/.gradle
......
...@@ -77,6 +77,7 @@ ...@@ -77,6 +77,7 @@
<!-- alert category --> <!-- alert category -->
<string name="profile_empty">Please select a profile</string> <string name="profile_empty">Please select a profile</string>
<string name="proxy_empty">Proxy/Password should not be empty</string> <string name="proxy_empty">Proxy/Password should not be empty</string>
<string name="file_manager_missing">Please install a file manager like MiXplorer</string>
<string name="connect">Connect</string> <string name="connect">Connect</string>
<!-- menu category --> <!-- menu category -->
......
...@@ -22,10 +22,7 @@ package com.github.shadowsocks ...@@ -22,10 +22,7 @@ package com.github.shadowsocks
import android.annotation.SuppressLint import android.annotation.SuppressLint
import android.app.Activity import android.app.Activity
import android.content.ClipData import android.content.*
import android.content.ClipboardManager
import android.content.Context
import android.content.Intent
import android.nfc.NdefMessage import android.nfc.NdefMessage
import android.nfc.NdefRecord import android.nfc.NdefRecord
import android.nfc.NfcAdapter import android.nfc.NfcAdapter
...@@ -42,6 +39,7 @@ import androidx.core.content.getSystemService ...@@ -42,6 +39,7 @@ import androidx.core.content.getSystemService
import androidx.core.os.bundleOf import androidx.core.os.bundleOf
import androidx.fragment.app.DialogFragment import androidx.fragment.app.DialogFragment
import androidx.recyclerview.widget.* import androidx.recyclerview.widget.*
import com.crashlytics.android.Crashlytics
import com.github.shadowsocks.bg.BaseService import com.github.shadowsocks.bg.BaseService
import com.github.shadowsocks.database.Profile import com.github.shadowsocks.database.Profile
import com.github.shadowsocks.database.ProfileManager import com.github.shadowsocks.database.ProfileManager
...@@ -383,7 +381,7 @@ class ProfilesFragment : ToolbarFragment(), Toolbar.OnMenuItemClickListener { ...@@ -383,7 +381,7 @@ class ProfilesFragment : ToolbarFragment(), Toolbar.OnMenuItemClickListener {
true true
} }
R.id.action_import_file -> { R.id.action_import_file -> {
startActivityForResult(Intent(Intent.ACTION_GET_CONTENT).apply { startFilesForResult(Intent(Intent.ACTION_GET_CONTENT).apply {
addCategory(Intent.CATEGORY_OPENABLE) addCategory(Intent.CATEGORY_OPENABLE)
type = "application/json" type = "application/json"
putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true) putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true)
...@@ -404,7 +402,7 @@ class ProfilesFragment : ToolbarFragment(), Toolbar.OnMenuItemClickListener { ...@@ -404,7 +402,7 @@ class ProfilesFragment : ToolbarFragment(), Toolbar.OnMenuItemClickListener {
true true
} }
R.id.action_export_file -> { R.id.action_export_file -> {
startActivityForResult(Intent(Intent.ACTION_CREATE_DOCUMENT).apply { startFilesForResult(Intent(Intent.ACTION_CREATE_DOCUMENT).apply {
addCategory(Intent.CATEGORY_OPENABLE) addCategory(Intent.CATEGORY_OPENABLE)
type = "application/json" type = "application/json"
putExtra(Intent.EXTRA_TITLE, "profiles.json") // optional title that can be edited putExtra(Intent.EXTRA_TITLE, "profiles.json") // optional title that can be edited
...@@ -415,6 +413,18 @@ class ProfilesFragment : ToolbarFragment(), Toolbar.OnMenuItemClickListener { ...@@ -415,6 +413,18 @@ class ProfilesFragment : ToolbarFragment(), Toolbar.OnMenuItemClickListener {
} }
} }
private fun startFilesForResult(intent: Intent?, requestCode: Int) {
try {
startActivityForResult(intent, requestCode)
} catch (e: ActivityNotFoundException) {
Crashlytics.logException(e)
(activity as MainActivity).snackbar(getString(R.string.file_manager_missing)).show()
} catch (e: SecurityException) {
Crashlytics.logException(e)
(activity as MainActivity).snackbar(getString(R.string.file_manager_missing)).show()
}
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
if (resultCode != Activity.RESULT_OK) super.onActivityResult(requestCode, resultCode, data) if (resultCode != Activity.RESULT_OK) super.onActivityResult(requestCode, resultCode, data)
else when (requestCode) { else when (requestCode) {
......
...@@ -22,6 +22,7 @@ package com.github.shadowsocks.tv ...@@ -22,6 +22,7 @@ package com.github.shadowsocks.tv
import android.app.Activity import android.app.Activity
import android.app.backup.BackupManager import android.app.backup.BackupManager
import android.content.ActivityNotFoundException
import android.content.Intent import android.content.Intent
import android.net.VpnService import android.net.VpnService
import android.os.Bundle import android.os.Bundle
...@@ -238,7 +239,7 @@ class MainPreferenceFragment : LeanbackPreferenceFragment(), ShadowsocksConnecti ...@@ -238,7 +239,7 @@ class MainPreferenceFragment : LeanbackPreferenceFragment(), ShadowsocksConnecti
true true
} }
Key.controlImport -> { Key.controlImport -> {
startActivityForResult(Intent(Intent.ACTION_GET_CONTENT).apply { startFilesForResult(Intent(Intent.ACTION_GET_CONTENT).apply {
addCategory(Intent.CATEGORY_OPENABLE) addCategory(Intent.CATEGORY_OPENABLE)
type = "application/json" type = "application/json"
putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true) putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true)
...@@ -246,7 +247,7 @@ class MainPreferenceFragment : LeanbackPreferenceFragment(), ShadowsocksConnecti ...@@ -246,7 +247,7 @@ class MainPreferenceFragment : LeanbackPreferenceFragment(), ShadowsocksConnecti
true true
} }
Key.controlExport -> { Key.controlExport -> {
startActivityForResult(Intent(Intent.ACTION_CREATE_DOCUMENT).apply { startFilesForResult(Intent(Intent.ACTION_CREATE_DOCUMENT).apply {
addCategory(Intent.CATEGORY_OPENABLE) addCategory(Intent.CATEGORY_OPENABLE)
type = "application/json" type = "application/json"
putExtra(Intent.EXTRA_TITLE, "profiles.json") // optional title that can be edited putExtra(Intent.EXTRA_TITLE, "profiles.json") // optional title that can be edited
...@@ -256,6 +257,18 @@ class MainPreferenceFragment : LeanbackPreferenceFragment(), ShadowsocksConnecti ...@@ -256,6 +257,18 @@ class MainPreferenceFragment : LeanbackPreferenceFragment(), ShadowsocksConnecti
else -> super.onPreferenceTreeClick(preference) else -> super.onPreferenceTreeClick(preference)
} }
private fun startFilesForResult(intent: Intent?, requestCode: Int) {
try {
startActivityForResult(intent, requestCode)
} catch (e: ActivityNotFoundException) {
Crashlytics.logException(e)
Toast.makeText(activity, R.string.file_manager_missing, Toast.LENGTH_SHORT).show()
} catch (e: SecurityException) {
Crashlytics.logException(e)
Toast.makeText(activity, R.string.file_manager_missing, Toast.LENGTH_SHORT).show()
}
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
when (requestCode) { when (requestCode) {
REQUEST_CONNECT -> if (resultCode == Activity.RESULT_OK) Core.startService() else { REQUEST_CONNECT -> if (resultCode == Activity.RESULT_OK) Core.startService() else {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment