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

Catch no files manager exception

parent c6e4491a
......@@ -5,10 +5,10 @@ jobs:
docker:
- image: shadowsocks/shadowsocks-android:circleci
environment:
JVM_OPTS: -Xmx3.5g
JVM_OPTS: -Xmx5g
resource_class: medium+
steps:
- checkout
- run: git submodule sync
- run: git submodule update --init --recursive
- restore_cache:
key: jars-{{ checksum "build.gradle" }}
......@@ -16,7 +16,7 @@ jobs:
key: go-full-{{ checksum "~/code/.git/modules/core/src/overture/go/HEAD" }}
- run:
name: Run Build and Tests
command: ./gradlew goBuild assembleDebug check
command: ./gradlew assembleDebug check
- save_cache:
paths:
- ~/.gradle
......
......@@ -77,6 +77,7 @@
<!-- alert category -->
<string name="profile_empty">Please select a profile</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>
<!-- menu category -->
......
......@@ -22,10 +22,7 @@ package com.github.shadowsocks
import android.annotation.SuppressLint
import android.app.Activity
import android.content.ClipData
import android.content.ClipboardManager
import android.content.Context
import android.content.Intent
import android.content.*
import android.nfc.NdefMessage
import android.nfc.NdefRecord
import android.nfc.NfcAdapter
......@@ -42,6 +39,7 @@ import androidx.core.content.getSystemService
import androidx.core.os.bundleOf
import androidx.fragment.app.DialogFragment
import androidx.recyclerview.widget.*
import com.crashlytics.android.Crashlytics
import com.github.shadowsocks.bg.BaseService
import com.github.shadowsocks.database.Profile
import com.github.shadowsocks.database.ProfileManager
......@@ -383,7 +381,7 @@ class ProfilesFragment : ToolbarFragment(), Toolbar.OnMenuItemClickListener {
true
}
R.id.action_import_file -> {
startActivityForResult(Intent(Intent.ACTION_GET_CONTENT).apply {
startFilesForResult(Intent(Intent.ACTION_GET_CONTENT).apply {
addCategory(Intent.CATEGORY_OPENABLE)
type = "application/json"
putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true)
......@@ -404,7 +402,7 @@ class ProfilesFragment : ToolbarFragment(), Toolbar.OnMenuItemClickListener {
true
}
R.id.action_export_file -> {
startActivityForResult(Intent(Intent.ACTION_CREATE_DOCUMENT).apply {
startFilesForResult(Intent(Intent.ACTION_CREATE_DOCUMENT).apply {
addCategory(Intent.CATEGORY_OPENABLE)
type = "application/json"
putExtra(Intent.EXTRA_TITLE, "profiles.json") // optional title that can be edited
......@@ -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?) {
if (resultCode != Activity.RESULT_OK) super.onActivityResult(requestCode, resultCode, data)
else when (requestCode) {
......
......@@ -22,6 +22,7 @@ package com.github.shadowsocks.tv
import android.app.Activity
import android.app.backup.BackupManager
import android.content.ActivityNotFoundException
import android.content.Intent
import android.net.VpnService
import android.os.Bundle
......@@ -238,7 +239,7 @@ class MainPreferenceFragment : LeanbackPreferenceFragment(), ShadowsocksConnecti
true
}
Key.controlImport -> {
startActivityForResult(Intent(Intent.ACTION_GET_CONTENT).apply {
startFilesForResult(Intent(Intent.ACTION_GET_CONTENT).apply {
addCategory(Intent.CATEGORY_OPENABLE)
type = "application/json"
putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true)
......@@ -246,7 +247,7 @@ class MainPreferenceFragment : LeanbackPreferenceFragment(), ShadowsocksConnecti
true
}
Key.controlExport -> {
startActivityForResult(Intent(Intent.ACTION_CREATE_DOCUMENT).apply {
startFilesForResult(Intent(Intent.ACTION_CREATE_DOCUMENT).apply {
addCategory(Intent.CATEGORY_OPENABLE)
type = "application/json"
putExtra(Intent.EXTRA_TITLE, "profiles.json") // optional title that can be edited
......@@ -256,6 +257,18 @@ class MainPreferenceFragment : LeanbackPreferenceFragment(), ShadowsocksConnecti
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?) {
when (requestCode) {
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