Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ac4aeb5218 | ||
|
|
86a2b3f1ab | ||
|
|
74dad98fc1 | ||
|
|
01da6b1131 | ||
|
|
7c5840b288 | ||
|
|
24116b53bc | ||
|
|
cffd9d1eb4 | ||
|
|
3c532f1ac5 | ||
|
|
c64e15acad | ||
|
|
9ff33ec1fd | ||
|
|
a1aed680fd | ||
|
|
dec2059a36 | ||
|
|
f7083025a0 | ||
|
|
74e2935f1e | ||
|
|
0af450008b | ||
|
|
75bc9334ef | ||
|
|
ec803d9859 | ||
|
|
f63842f773 | ||
|
|
f218282e28 | ||
|
|
6d866633bf | ||
|
|
550f06cf2a | ||
|
|
cad258da6e | ||
|
|
71cd80a634 | ||
|
|
633b9764c6 | ||
|
|
0643c60f0f | ||
|
|
5a562ae343 | ||
|
|
9838875996 | ||
|
|
25aacd20d5 | ||
|
|
7026ca99fc | ||
|
|
258a573e8c | ||
|
|
2b225dbc59 | ||
|
|
c9b48af022 | ||
|
|
984a8c926e | ||
|
|
5cf256f532 | ||
|
|
5f4a4dc1e1 |
+2
-1
@@ -29,7 +29,8 @@ The exclamation mark in the Wi-Fi/cellular icon appears because the system fails
|
|||||||
3. Some ROM like [Flyme](https://github.com/shadowsocks/shadowsocks-android/issues/1589) has **very** broken direct boot support;
|
3. Some ROM like [Flyme](https://github.com/shadowsocks/shadowsocks-android/issues/1589) has **very** broken direct boot support;
|
||||||
4. If you have Xposed framework and/or battery saver apps, it's likely that this app wouldn't work well with these either.
|
4. If you have Xposed framework and/or battery saver apps, it's likely that this app wouldn't work well with these either.
|
||||||
|
|
||||||
* Fixes for MIUI: [#772](https://github.com/shadowsocks/shadowsocks-android/issues/772) [#888](https://github.com/shadowsocks/shadowsocks-android/issues/888)
|
* Fixes for MIUI: [#772](https://github.com/shadowsocks/shadowsocks-android/issues/772)
|
||||||
|
* Fixes for EMUI: [#888](https://github.com/shadowsocks/shadowsocks-android/issues/888)
|
||||||
* Fixes for Huawei: [#1091 (comment)](https://github.com/shadowsocks/shadowsocks-android/issues/1091#issuecomment-276949836)
|
* Fixes for Huawei: [#1091 (comment)](https://github.com/shadowsocks/shadowsocks-android/issues/1091#issuecomment-276949836)
|
||||||
* Related to Xposed: [#1414](https://github.com/shadowsocks/shadowsocks-android/issues/1414)
|
* Related to Xposed: [#1414](https://github.com/shadowsocks/shadowsocks-android/issues/1414)
|
||||||
* Samsung and/or Brevent: [#1410](https://github.com/shadowsocks/shadowsocks-android/issues/1410)
|
* Samsung and/or Brevent: [#1410](https://github.com/shadowsocks/shadowsocks-android/issues/1410)
|
||||||
|
|||||||
+2
-6
@@ -12,11 +12,6 @@
|
|||||||
|
|
||||||
Использйте интеграцию с [Tasker](http://tasker.dinglisch.net/).
|
Использйте интеграцию с [Tasker](http://tasker.dinglisch.net/).
|
||||||
|
|
||||||
### Как добавить QR код из локальной галереи?
|
|
||||||
|
|
||||||
Отсканируйте его при помощи стороннего сканера, например [QuickMark Barcode Scanner](https://play.google.com/store/apps/details?id=tw.com.quickmark) и нажмите на `ss` ссылку.
|
|
||||||
|
|
||||||
|
|
||||||
### Почему режим NAT более не поддерживается?
|
### Почему режим NAT более не поддерживается?
|
||||||
|
|
||||||
1. Требуются ROOT права;
|
1. Требуются ROOT права;
|
||||||
@@ -34,7 +29,8 @@
|
|||||||
3. Некоторые ROM, такие как [Flyme](https://github.com/shadowsocks/shadowsocks-android/issues/1589) имеют **слишком** испорченную поддержку "непосредственной загрузки";
|
3. Некоторые ROM, такие как [Flyme](https://github.com/shadowsocks/shadowsocks-android/issues/1589) имеют **слишком** испорченную поддержку "непосредственной загрузки";
|
||||||
4. Если вы используете фреймворк Xposed и/или приложения для энергосбережения, вероятно наше приложение не будет нормально работать с ними.
|
4. Если вы используете фреймворк Xposed и/или приложения для энергосбережения, вероятно наше приложение не будет нормально работать с ними.
|
||||||
|
|
||||||
* Иправления для MIUI: [#772](https://github.com/shadowsocks/shadowsocks-android/issues/772) [#888](https://github.com/shadowsocks/shadowsocks-android/issues/888)
|
* Исправления для MIUI: [#772](https://github.com/shadowsocks/shadowsocks-android/issues/772)
|
||||||
|
* Исправления для EMUI: [#888](https://github.com/shadowsocks/shadowsocks-android/issues/888)
|
||||||
* Иправления для Huawei: [#1091 (комментарий)](https://github.com/shadowsocks/shadowsocks-android/issues/1091#issuecomment-276949836)
|
* Иправления для Huawei: [#1091 (комментарий)](https://github.com/shadowsocks/shadowsocks-android/issues/1091#issuecomment-276949836)
|
||||||
* Вызванные из-за Xposed: [#1414](https://github.com/shadowsocks/shadowsocks-android/issues/1414)
|
* Вызванные из-за Xposed: [#1414](https://github.com/shadowsocks/shadowsocks-android/issues/1414)
|
||||||
* Samsung и/или Brevent: [#1410](https://github.com/shadowsocks/shadowsocks-android/issues/1410)
|
* Samsung и/или Brevent: [#1410](https://github.com/shadowsocks/shadowsocks-android/issues/1410)
|
||||||
|
|||||||
+3
-3
@@ -4,12 +4,12 @@ apply plugin: 'com.github.ben-manes.versions'
|
|||||||
|
|
||||||
buildscript {
|
buildscript {
|
||||||
ext {
|
ext {
|
||||||
kotlinVersion = '1.2.21'
|
kotlinVersion = '1.2.30'
|
||||||
minSdkVersion = 21
|
minSdkVersion = 21
|
||||||
sdkVersion = 27
|
sdkVersion = 27
|
||||||
buildToolsVersion = '27.0.3'
|
buildToolsVersion = '27.0.3'
|
||||||
supportLibraryVersion = '27.0.2'
|
supportLibraryVersion = '27.1.0'
|
||||||
takisoftFixVersion = '27.0.2.0'
|
takisoftFixVersion = '27.1.0.0'
|
||||||
playServicesVersion = '11.8.0'
|
playServicesVersion = '11.8.0'
|
||||||
junitVersion = '4.12'
|
junitVersion = '4.12'
|
||||||
androidTestVersion = '1.0.1'
|
androidTestVersion = '1.0.1'
|
||||||
|
|||||||
Submodule core/src/overture/src/github.com/shadowsocks/overture updated: 58ab31a9fd...e7594118e8
+4
-4
@@ -21,8 +21,8 @@ android {
|
|||||||
applicationId "com.github.shadowsocks"
|
applicationId "com.github.shadowsocks"
|
||||||
minSdkVersion rootProject.minSdkVersion
|
minSdkVersion rootProject.minSdkVersion
|
||||||
targetSdkVersion rootProject.sdkVersion
|
targetSdkVersion rootProject.sdkVersion
|
||||||
versionCode 4050000
|
versionCode 4050200
|
||||||
versionName "4.5.0"
|
versionName "4.5.2"
|
||||||
testApplicationId "com.github.shadowsocks.test"
|
testApplicationId "com.github.shadowsocks.test"
|
||||||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
|
||||||
resConfigs "fa", "fr", "ja", "ko", "ru", "zh-rCN", "zh-rTW"
|
resConfigs "fa", "fr", "ja", "ko", "ru", "zh-rCN", "zh-rTW"
|
||||||
@@ -63,9 +63,9 @@ dependencies {
|
|||||||
implementation "com.google.android.gms:play-services-analytics:$playServicesVersion"
|
implementation "com.google.android.gms:play-services-analytics:$playServicesVersion"
|
||||||
implementation "com.google.android.gms:play-services-vision:$playServicesVersion"
|
implementation "com.google.android.gms:play-services-vision:$playServicesVersion"
|
||||||
implementation "com.google.firebase:firebase-config:$playServicesVersion"
|
implementation "com.google.firebase:firebase-config:$playServicesVersion"
|
||||||
implementation 'com.j256.ormlite:ormlite-android:5.0'
|
implementation 'com.j256.ormlite:ormlite-android:5.1'
|
||||||
implementation 'com.mikepenz:materialdrawer:6.0.6'
|
implementation 'com.mikepenz:materialdrawer:6.0.6'
|
||||||
implementation 'com.squareup.okhttp3:okhttp:3.9.1'
|
implementation 'com.squareup.okhttp3:okhttp:3.10.0'
|
||||||
implementation "com.takisoft.fix:preference-v7-simplemenu:$takisoftFixVersion"
|
implementation "com.takisoft.fix:preference-v7-simplemenu:$takisoftFixVersion"
|
||||||
implementation 'com.twofortyfouram:android-plugin-api-for-locale:1.0.2'
|
implementation 'com.twofortyfouram:android-plugin-api-for-locale:1.0.2'
|
||||||
implementation 'dnsjava:dnsjava:2.1.8'
|
implementation 'dnsjava:dnsjava:2.1.8'
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
package="com.github.shadowsocks"
|
package="com.github.shadowsocks"
|
||||||
android:installLocation="internalOnly">
|
android:installLocation="internalOnly">
|
||||||
|
|
||||||
|
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"/>
|
||||||
<uses-permission android:name="android.permission.INTERNET"/>
|
<uses-permission android:name="android.permission.INTERNET"/>
|
||||||
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
|
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
|
||||||
<uses-permission android:name="android.permission.NFC" />
|
<uses-permission android:name="android.permission.NFC" />
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -71,7 +71,10 @@ class App : Application() {
|
|||||||
val deviceContext: Context by lazy { if (Build.VERSION.SDK_INT < 24) this else DeviceContext(this) }
|
val deviceContext: Context by lazy { if (Build.VERSION.SDK_INT < 24) this else DeviceContext(this) }
|
||||||
val remoteConfig: FirebaseRemoteConfig by lazy { FirebaseRemoteConfig.getInstance() }
|
val remoteConfig: FirebaseRemoteConfig by lazy { FirebaseRemoteConfig.getInstance() }
|
||||||
private val tracker: Tracker by lazy { GoogleAnalytics.getInstance(deviceContext).newTracker(R.xml.tracker) }
|
private val tracker: Tracker by lazy { GoogleAnalytics.getInstance(deviceContext).newTracker(R.xml.tracker) }
|
||||||
val info: PackageInfo by lazy { packageManager.getPackageInfo(packageName, PackageManager.GET_SIGNATURES) }
|
val info: PackageInfo by lazy { getPackageInfo(packageName) }
|
||||||
|
|
||||||
|
fun getPackageInfo(packageName: String) =
|
||||||
|
packageManager.getPackageInfo(packageName, PackageManager.GET_SIGNATURES)!!
|
||||||
|
|
||||||
fun startService() {
|
fun startService() {
|
||||||
val intent = Intent(this, BaseService.serviceClass.java)
|
val intent = Intent(this, BaseService.serviceClass.java)
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ class GlobalSettingsPreferenceFragment : PreferenceFragmentCompatDividers() {
|
|||||||
boot.isChecked = BootReceiver.enabled
|
boot.isChecked = BootReceiver.enabled
|
||||||
|
|
||||||
val dba = findPreference(Key.directBootAware)
|
val dba = findPreference(Key.directBootAware)
|
||||||
if (Build.VERSION.SDK_INT >= 24 && context!!.getSystemService(DevicePolicyManager::class.java)
|
if (Build.VERSION.SDK_INT >= 24 && requireContext().getSystemService(DevicePolicyManager::class.java)
|
||||||
.storageEncryptionStatus == DevicePolicyManager.ENCRYPTION_STATUS_ACTIVE_PER_USER)
|
.storageEncryptionStatus == DevicePolicyManager.ENCRYPTION_STATUS_ACTIVE_PER_USER)
|
||||||
dba.onPreferenceChangeListener = directBootAwareListener else dba.parent!!.removePreference(dba)
|
dba.onPreferenceChangeListener = directBootAwareListener else dba.parent!!.removePreference(dba)
|
||||||
|
|
||||||
@@ -59,7 +59,7 @@ class GlobalSettingsPreferenceFragment : PreferenceFragmentCompatDividers() {
|
|||||||
tfo.setOnPreferenceChangeListener { _, value ->
|
tfo.setOnPreferenceChangeListener { _, value ->
|
||||||
val result = TcpFastOpen.enabled(value as Boolean)
|
val result = TcpFastOpen.enabled(value as Boolean)
|
||||||
if (result != null && result != "Success.")
|
if (result != null && result != "Success.")
|
||||||
Snackbar.make(activity!!.findViewById(R.id.snackbar), result, Snackbar.LENGTH_LONG).show()
|
Snackbar.make(requireActivity().findViewById(R.id.snackbar), result, Snackbar.LENGTH_LONG).show()
|
||||||
value == TcpFastOpen.sendEnabled
|
value == TcpFastOpen.sendEnabled
|
||||||
}
|
}
|
||||||
if (!TcpFastOpen.supported) {
|
if (!TcpFastOpen.supported) {
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ class ProfileConfigFragment : PreferenceFragmentCompatDividers(), Toolbar.OnMenu
|
|||||||
private const val REQUEST_CODE_PLUGIN_CONFIGURE = 1
|
private const val REQUEST_CODE_PLUGIN_CONFIGURE = 1
|
||||||
}
|
}
|
||||||
|
|
||||||
private lateinit var profile: Profile
|
private var profileId = -1
|
||||||
private lateinit var isProxyApps: SwitchPreference
|
private lateinit var isProxyApps: SwitchPreference
|
||||||
private lateinit var plugin: IconListPreference
|
private lateinit var plugin: IconListPreference
|
||||||
private lateinit var pluginConfigure: EditTextPreference
|
private lateinit var pluginConfigure: EditTextPreference
|
||||||
@@ -65,14 +65,8 @@ class ProfileConfigFragment : PreferenceFragmentCompatDividers(), Toolbar.OnMenu
|
|||||||
|
|
||||||
override fun onCreatePreferencesFix(savedInstanceState: Bundle?, rootKey: String?) {
|
override fun onCreatePreferencesFix(savedInstanceState: Bundle?, rootKey: String?) {
|
||||||
preferenceManager.preferenceDataStore = DataStore.privateStore
|
preferenceManager.preferenceDataStore = DataStore.privateStore
|
||||||
val activity = activity!!
|
val activity = requireActivity()
|
||||||
val profile = ProfileManager.getProfile(activity.intent.getIntExtra(Action.EXTRA_PROFILE_ID, -1))
|
profileId = activity.intent.getIntExtra(Action.EXTRA_PROFILE_ID, -1)
|
||||||
if (profile == null) {
|
|
||||||
activity.finish()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
this.profile = profile
|
|
||||||
profile.serialize()
|
|
||||||
addPreferencesFromResource(R.xml.pref_profile)
|
addPreferencesFromResource(R.xml.pref_profile)
|
||||||
if (Build.VERSION.SDK_INT >= 25 && activity.getSystemService(UserManager::class.java).isDemoUser) {
|
if (Build.VERSION.SDK_INT >= 25 && activity.getSystemService(UserManager::class.java).isDemoUser) {
|
||||||
findPreference(Key.host).summary = "shadowsocks.example.org"
|
findPreference(Key.host).summary = "shadowsocks.example.org"
|
||||||
@@ -130,11 +124,13 @@ class ProfileConfigFragment : PreferenceFragmentCompatDividers(), Toolbar.OnMenu
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun saveAndExit() {
|
fun saveAndExit() {
|
||||||
|
val profile = ProfileManager.getProfile(profileId) ?: Profile()
|
||||||
|
profile.id = profileId
|
||||||
profile.deserialize()
|
profile.deserialize()
|
||||||
ProfileManager.updateProfile(profile)
|
ProfileManager.updateProfile(profile)
|
||||||
ProfilesFragment.instance?.profilesAdapter?.deepRefreshId(profile.id)
|
ProfilesFragment.instance?.profilesAdapter?.deepRefreshId(profileId)
|
||||||
if (DataStore.profileId == profile.id && DataStore.directBootAware) DirectBoot.update()
|
if (DataStore.profileId == profileId && DataStore.directBootAware) DirectBoot.update()
|
||||||
activity!!.finish()
|
requireActivity().finish()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onResume() {
|
override fun onResume() {
|
||||||
@@ -161,7 +157,7 @@ class ProfileConfigFragment : PreferenceFragmentCompatDividers(), Toolbar.OnMenu
|
|||||||
override fun onDisplayPreferenceDialog(preference: Preference) {
|
override fun onDisplayPreferenceDialog(preference: Preference) {
|
||||||
if (preference.key == Key.pluginConfigure) {
|
if (preference.key == Key.pluginConfigure) {
|
||||||
val intent = PluginManager.buildIntent(pluginConfiguration.selected, PluginContract.ACTION_CONFIGURE)
|
val intent = PluginManager.buildIntent(pluginConfiguration.selected, PluginContract.ACTION_CONFIGURE)
|
||||||
if (intent.resolveActivity(activity!!.packageManager) != null)
|
if (intent.resolveActivity(requireContext().packageManager) != null)
|
||||||
startActivityForResult(intent.putExtra(PluginContract.EXTRA_OPTIONS,
|
startActivityForResult(intent.putExtra(PluginContract.EXTRA_OPTIONS,
|
||||||
pluginConfiguration.selectedOptions.toString()), REQUEST_CODE_PLUGIN_CONFIGURE) else {
|
pluginConfiguration.selectedOptions.toString()), REQUEST_CODE_PLUGIN_CONFIGURE) else {
|
||||||
showPluginEditor()
|
showPluginEditor()
|
||||||
@@ -183,11 +179,11 @@ class ProfileConfigFragment : PreferenceFragmentCompatDividers(), Toolbar.OnMenu
|
|||||||
|
|
||||||
override fun onMenuItemClick(item: MenuItem) = when (item.itemId) {
|
override fun onMenuItemClick(item: MenuItem) = when (item.itemId) {
|
||||||
R.id.action_delete -> {
|
R.id.action_delete -> {
|
||||||
val activity = activity!!
|
val activity = requireActivity()
|
||||||
AlertDialog.Builder(activity)
|
AlertDialog.Builder(activity)
|
||||||
.setTitle(R.string.delete_confirm_prompt)
|
.setTitle(R.string.delete_confirm_prompt)
|
||||||
.setPositiveButton(R.string.yes, { _, _ ->
|
.setPositiveButton(R.string.yes, { _, _ ->
|
||||||
ProfileManager.delProfile(profile.id)
|
ProfileManager.delProfile(profileId)
|
||||||
activity.finish()
|
activity.finish()
|
||||||
})
|
})
|
||||||
.setNegativeButton(R.string.no, null)
|
.setNegativeButton(R.string.no, null)
|
||||||
|
|||||||
@@ -123,12 +123,12 @@ class ProfilesFragment : ToolbarFragment(), Toolbar.OnMenuItemClickListener {
|
|||||||
private var adView: AdView? = null
|
private var adView: AdView? = null
|
||||||
|
|
||||||
init {
|
init {
|
||||||
edit.setOnClickListener { startConfig(item.id) }
|
edit.setOnClickListener { startConfig(item) }
|
||||||
TooltipCompat.setTooltipText(edit, edit.contentDescription)
|
TooltipCompat.setTooltipText(edit, edit.contentDescription)
|
||||||
itemView.setOnClickListener(this)
|
itemView.setOnClickListener(this)
|
||||||
val share = itemView.findViewById<View>(R.id.share)
|
val share = itemView.findViewById<View>(R.id.share)
|
||||||
share.setOnClickListener {
|
share.setOnClickListener {
|
||||||
val popup = PopupMenu(activity!!, share)
|
val popup = PopupMenu(requireContext(), share)
|
||||||
popup.menuInflater.inflate(R.menu.profile_share_popup, popup.menu)
|
popup.menuInflater.inflate(R.menu.profile_share_popup, popup.menu)
|
||||||
popup.setOnMenuItemClickListener(this)
|
popup.setOnMenuItemClickListener(this)
|
||||||
popup.show()
|
popup.show()
|
||||||
@@ -173,10 +173,10 @@ class ProfilesFragment : ToolbarFragment(), Toolbar.OnMenuItemClickListener {
|
|||||||
var adView = adView
|
var adView = adView
|
||||||
if (item.host == "198.199.101.152") {
|
if (item.host == "198.199.101.152") {
|
||||||
if (adView == null) {
|
if (adView == null) {
|
||||||
val params =
|
val params = LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
|
||||||
LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)
|
ViewGroup.LayoutParams.WRAP_CONTENT)
|
||||||
params.gravity = Gravity.CENTER_HORIZONTAL
|
params.gravity = Gravity.CENTER_HORIZONTAL
|
||||||
val context = context!!
|
val context = requireContext()
|
||||||
adView = AdView(context)
|
adView = AdView(context)
|
||||||
adView.layoutParams = params
|
adView.layoutParams = params
|
||||||
adView.adUnitId = "ca-app-pub-9097031975646651/7760346322"
|
adView.adUnitId = "ca-app-pub-9097031975646651/7760346322"
|
||||||
@@ -208,7 +208,7 @@ class ProfilesFragment : ToolbarFragment(), Toolbar.OnMenuItemClickListener {
|
|||||||
|
|
||||||
override fun onMenuItemClick(item: MenuItem): Boolean = when (item.itemId) {
|
override fun onMenuItemClick(item: MenuItem): Boolean = when (item.itemId) {
|
||||||
R.id.action_qr_code_nfc -> {
|
R.id.action_qr_code_nfc -> {
|
||||||
fragmentManager!!.beginTransaction().add(QRCodeDialog(this.item.toString()), "")
|
requireFragmentManager().beginTransaction().add(QRCodeDialog(this.item.toString()), "")
|
||||||
.commitAllowingStateLoss()
|
.commitAllowingStateLoss()
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
@@ -229,8 +229,8 @@ class ProfilesFragment : ToolbarFragment(), Toolbar.OnMenuItemClickListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onBindViewHolder(holder: ProfileViewHolder, position: Int) = holder.bind(profiles[position])
|
override fun onBindViewHolder(holder: ProfileViewHolder, position: Int) = holder.bind(profiles[position])
|
||||||
override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): ProfileViewHolder = ProfileViewHolder(
|
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ProfileViewHolder = ProfileViewHolder(
|
||||||
LayoutInflater.from(parent!!.context).inflate(R.layout.layout_profile, parent, false))
|
LayoutInflater.from(parent.context).inflate(R.layout.layout_profile, parent, false))
|
||||||
override fun getItemCount(): Int = profiles.size
|
override fun getItemCount(): Int = profiles.size
|
||||||
override fun getItemId(position: Int): Long = profiles[position].id.toLong()
|
override fun getItemId(position: Int): Long = profiles[position].id.toLong()
|
||||||
|
|
||||||
@@ -305,10 +305,12 @@ class ProfilesFragment : ToolbarFragment(), Toolbar.OnMenuItemClickListener {
|
|||||||
private var txTotal: Long = 0L
|
private var txTotal: Long = 0L
|
||||||
private var rxTotal: Long = 0L
|
private var rxTotal: Long = 0L
|
||||||
|
|
||||||
private val clipboard by lazy { activity!!.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager }
|
private val clipboard by lazy { requireContext().getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager }
|
||||||
|
|
||||||
private fun startConfig(id: Int) = startActivity(Intent(context, ProfileConfigActivity::class.java)
|
private fun startConfig(profile: Profile) {
|
||||||
.putExtra(Action.EXTRA_PROFILE_ID, id))
|
profile.serialize()
|
||||||
|
startActivity(Intent(context, ProfileConfigActivity::class.java).putExtra(Action.EXTRA_PROFILE_ID, profile.id))
|
||||||
|
}
|
||||||
|
|
||||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? =
|
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? =
|
||||||
inflater.inflate(R.layout.layout_list, container, false)
|
inflater.inflate(R.layout.layout_list, container, false)
|
||||||
@@ -331,7 +333,7 @@ class ProfilesFragment : ToolbarFragment(), Toolbar.OnMenuItemClickListener {
|
|||||||
profilesList.itemAnimator = animator
|
profilesList.itemAnimator = animator
|
||||||
profilesList.adapter = profilesAdapter
|
profilesList.adapter = profilesAdapter
|
||||||
instance = this
|
instance = this
|
||||||
undoManager = UndoSnackbarManager(activity!!.findViewById(R.id.snackbar),
|
undoManager = UndoSnackbarManager(requireActivity().findViewById(R.id.snackbar),
|
||||||
profilesAdapter::undo, profilesAdapter::commit)
|
profilesAdapter::undo, profilesAdapter::commit)
|
||||||
ItemTouchHelper(object : ItemTouchHelper.SimpleCallback(ItemTouchHelper.UP or ItemTouchHelper.DOWN,
|
ItemTouchHelper(object : ItemTouchHelper.SimpleCallback(ItemTouchHelper.UP or ItemTouchHelper.DOWN,
|
||||||
ItemTouchHelper.START or ItemTouchHelper.END) {
|
ItemTouchHelper.START or ItemTouchHelper.END) {
|
||||||
@@ -351,7 +353,7 @@ class ProfilesFragment : ToolbarFragment(), Toolbar.OnMenuItemClickListener {
|
|||||||
profilesAdapter.move(viewHolder.adapterPosition, target.adapterPosition)
|
profilesAdapter.move(viewHolder.adapterPosition, target.adapterPosition)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
override fun clearView(recyclerView: RecyclerView?, viewHolder: RecyclerView.ViewHolder?) {
|
override fun clearView(recyclerView: RecyclerView, viewHolder: RecyclerView.ViewHolder) {
|
||||||
super.clearView(recyclerView, viewHolder)
|
super.clearView(recyclerView, viewHolder)
|
||||||
profilesAdapter.commitMove()
|
profilesAdapter.commitMove()
|
||||||
}
|
}
|
||||||
@@ -366,25 +368,25 @@ class ProfilesFragment : ToolbarFragment(), Toolbar.OnMenuItemClickListener {
|
|||||||
}
|
}
|
||||||
R.id.action_import -> {
|
R.id.action_import -> {
|
||||||
try {
|
try {
|
||||||
val profiles = Profile.findAll(clipboard.primaryClip.getItemAt(0).text).toList()
|
val profiles = Profile.findAll(clipboard.primaryClip!!.getItemAt(0).text).toList()
|
||||||
if (profiles.isNotEmpty()) {
|
if (profiles.isNotEmpty()) {
|
||||||
profiles.forEach { ProfileManager.createProfile(it) }
|
profiles.forEach { ProfileManager.createProfile(it) }
|
||||||
Snackbar.make(activity!!.findViewById(R.id.snackbar), R.string.action_import_msg,
|
Snackbar.make(requireActivity().findViewById(R.id.snackbar), R.string.action_import_msg,
|
||||||
Snackbar.LENGTH_LONG).show()
|
Snackbar.LENGTH_LONG).show()
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
} catch (_: IndexOutOfBoundsException) { }
|
} catch (_: Exception) { }
|
||||||
Snackbar.make(activity!!.findViewById(R.id.snackbar), R.string.action_import_err, Snackbar.LENGTH_LONG)
|
Snackbar.make(requireActivity().findViewById(R.id.snackbar), R.string.action_import_err,
|
||||||
.show()
|
Snackbar.LENGTH_LONG).show()
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
R.id.action_manual_settings -> {
|
R.id.action_manual_settings -> {
|
||||||
startConfig(ProfileManager.createProfile().id)
|
startConfig(ProfileManager.createProfile())
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
R.id.action_export -> {
|
R.id.action_export -> {
|
||||||
val profiles = ProfileManager.getAllProfiles()
|
val profiles = ProfileManager.getAllProfiles()
|
||||||
Snackbar.make(activity!!.findViewById(R.id.snackbar), if (profiles != null) {
|
Snackbar.make(requireActivity().findViewById(R.id.snackbar), if (profiles != null) {
|
||||||
clipboard.primaryClip = ClipData.newPlainText(null, profiles.joinToString("\n"))
|
clipboard.primaryClip = ClipData.newPlainText(null, profiles.joinToString("\n"))
|
||||||
R.string.action_export_msg
|
R.string.action_export_msg
|
||||||
} else R.string.action_export_err, Snackbar.LENGTH_LONG).show()
|
} else R.string.action_export_err, Snackbar.LENGTH_LONG).show()
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ class CustomRulesFragment : ToolbarFragment(), Toolbar.OnMenuItemClickListener,
|
|||||||
private lateinit var positive: Button
|
private lateinit var positive: Button
|
||||||
|
|
||||||
init {
|
init {
|
||||||
val activity = activity!!
|
val activity = requireActivity()
|
||||||
val view = activity.layoutInflater.inflate(R.layout.dialog_acl_rule, null)
|
val view = activity.layoutInflater.inflate(R.layout.dialog_acl_rule, null)
|
||||||
templateSelector = view.findViewById(R.id.template_selector)
|
templateSelector = view.findViewById(R.id.template_selector)
|
||||||
editText = view.findViewById(R.id.content)
|
editText = view.findViewById(R.id.content)
|
||||||
@@ -360,7 +360,7 @@ class CustomRulesFragment : ToolbarFragment(), Toolbar.OnMenuItemClickListener,
|
|||||||
private lateinit var list: RecyclerView
|
private lateinit var list: RecyclerView
|
||||||
private var mode: ActionMode? = null
|
private var mode: ActionMode? = null
|
||||||
private lateinit var undoManager: UndoSnackbarManager<Any>
|
private lateinit var undoManager: UndoSnackbarManager<Any>
|
||||||
private val clipboard by lazy { activity!!.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager }
|
private val clipboard by lazy { requireContext().getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager }
|
||||||
|
|
||||||
private fun onSelectedItemsUpdated() {
|
private fun onSelectedItemsUpdated() {
|
||||||
if (selectedItems.isEmpty()) mode?.finish() else if (mode == null) mode = toolbar.startActionMode(this)
|
if (selectedItems.isEmpty()) mode?.finish() else if (mode == null) mode = toolbar.startActionMode(this)
|
||||||
@@ -383,12 +383,13 @@ class CustomRulesFragment : ToolbarFragment(), Toolbar.OnMenuItemClickListener,
|
|||||||
toolbar.setTitle(R.string.custom_rules)
|
toolbar.setTitle(R.string.custom_rules)
|
||||||
toolbar.inflateMenu(R.menu.custom_rules_menu)
|
toolbar.inflateMenu(R.menu.custom_rules_menu)
|
||||||
toolbar.setOnMenuItemClickListener(this)
|
toolbar.setOnMenuItemClickListener(this)
|
||||||
|
val activity = requireActivity()
|
||||||
list = view.findViewById(R.id.list)
|
list = view.findViewById(R.id.list)
|
||||||
list.layoutManager = LinearLayoutManager(activity, LinearLayoutManager.VERTICAL, false)
|
list.layoutManager = LinearLayoutManager(activity, LinearLayoutManager.VERTICAL, false)
|
||||||
list.itemAnimator = DefaultItemAnimator()
|
list.itemAnimator = DefaultItemAnimator()
|
||||||
list.adapter = adapter
|
list.adapter = adapter
|
||||||
view.findViewById<FastScroller>(R.id.fastscroller).setRecyclerView(list)
|
view.findViewById<FastScroller>(R.id.fastscroller).setRecyclerView(list)
|
||||||
undoManager = UndoSnackbarManager(activity!!.findViewById(R.id.snackbar), adapter::undo)
|
undoManager = UndoSnackbarManager(activity.findViewById(R.id.snackbar), adapter::undo)
|
||||||
ItemTouchHelper(object : ItemTouchHelper.SimpleCallback(0, ItemTouchHelper.START or ItemTouchHelper.END) {
|
ItemTouchHelper(object : ItemTouchHelper.SimpleCallback(0, ItemTouchHelper.START or ItemTouchHelper.END) {
|
||||||
override fun getSwipeDirs(recyclerView: RecyclerView, viewHolder: RecyclerView.ViewHolder): Int =
|
override fun getSwipeDirs(recyclerView: RecyclerView, viewHolder: RecyclerView.ViewHolder): Int =
|
||||||
if (isEnabled && selectedItems.isEmpty()) super.getSwipeDirs(recyclerView, viewHolder) else 0
|
if (isEnabled && selectedItems.isEmpty()) super.getSwipeDirs(recyclerView, viewHolder) else 0
|
||||||
@@ -437,10 +438,10 @@ class CustomRulesFragment : ToolbarFragment(), Toolbar.OnMenuItemClickListener,
|
|||||||
}
|
}
|
||||||
R.id.action_import -> {
|
R.id.action_import -> {
|
||||||
try {
|
try {
|
||||||
adapter.addToProxy(clipboard.primaryClip.getItemAt(0).text.toString()) != null
|
check(adapter.addToProxy(clipboard.primaryClip!!.getItemAt(0).text.toString()) != null)
|
||||||
} catch (exc: Exception) {
|
} catch (exc: Exception) {
|
||||||
Snackbar.make(activity!!.findViewById(R.id.snackbar), R.string.action_import_err, Snackbar.LENGTH_LONG)
|
Snackbar.make(requireActivity().findViewById(R.id.snackbar), R.string.action_import_err,
|
||||||
.show()
|
Snackbar.LENGTH_LONG).show()
|
||||||
app.track(exc)
|
app.track(exc)
|
||||||
}
|
}
|
||||||
true
|
true
|
||||||
@@ -462,7 +463,7 @@ class CustomRulesFragment : ToolbarFragment(), Toolbar.OnMenuItemClickListener,
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onCreateActionMode(mode: ActionMode, menu: Menu): Boolean {
|
override fun onCreateActionMode(mode: ActionMode, menu: Menu): Boolean {
|
||||||
val activity = activity!!
|
val activity = requireActivity()
|
||||||
val window = activity.window
|
val window = activity.window
|
||||||
// In the end material_grey_100 is used for background, see AppCompatDrawableManager (very complicated)
|
// In the end material_grey_100 is used for background, see AppCompatDrawableManager (very complicated)
|
||||||
if (Build.VERSION.SDK_INT >= 23) {
|
if (Build.VERSION.SDK_INT >= 23) {
|
||||||
@@ -495,7 +496,7 @@ class CustomRulesFragment : ToolbarFragment(), Toolbar.OnMenuItemClickListener,
|
|||||||
else -> false
|
else -> false
|
||||||
}
|
}
|
||||||
override fun onDestroyActionMode(mode: ActionMode) {
|
override fun onDestroyActionMode(mode: ActionMode) {
|
||||||
val activity = activity!!
|
val activity = requireActivity()
|
||||||
val window = activity.window
|
val window = activity.window
|
||||||
window.statusBarColor = ContextCompat.getColor(activity,
|
window.statusBarColor = ContextCompat.getColor(activity,
|
||||||
activity.theme.resolveResourceId(android.R.attr.statusBarColor))
|
activity.theme.resolveResourceId(android.R.attr.statusBarColor))
|
||||||
|
|||||||
@@ -84,7 +84,6 @@ object LocalDnsService {
|
|||||||
Acl.BYPASS_CHN, Acl.BYPASS_LAN_CHN, Acl.GFWLIST, Acl.CUSTOM_RULES -> config
|
Acl.BYPASS_CHN, Acl.BYPASS_LAN_CHN, Acl.GFWLIST, Acl.CUSTOM_RULES -> config
|
||||||
.put("PrimaryDNS", localDns)
|
.put("PrimaryDNS", localDns)
|
||||||
.put("AlternativeDNS", remoteDns)
|
.put("AlternativeDNS", remoteDns)
|
||||||
.put("IPNetworkFile", "china_ip_list.txt")
|
|
||||||
.put("DomainFile", data.aclFile!!.absolutePath)
|
.put("DomainFile", data.aclFile!!.absolutePath)
|
||||||
Acl.CHINALIST -> config
|
Acl.CHINALIST -> config
|
||||||
.put("PrimaryDNS", localDns)
|
.put("PrimaryDNS", localDns)
|
||||||
|
|||||||
@@ -21,9 +21,11 @@
|
|||||||
package com.github.shadowsocks.bg
|
package com.github.shadowsocks.bg
|
||||||
|
|
||||||
import android.app.Service
|
import android.app.Service
|
||||||
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.content.pm.PackageManager
|
import android.content.pm.PackageManager
|
||||||
import android.net.LocalSocket
|
import android.net.*
|
||||||
|
import android.os.Build
|
||||||
import android.os.IBinder
|
import android.os.IBinder
|
||||||
import android.os.ParcelFileDescriptor
|
import android.os.ParcelFileDescriptor
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
@@ -50,6 +52,21 @@ class VpnService : BaseVpnService(), LocalDnsService.Interface {
|
|||||||
private const val PRIVATE_VLAN6 = "fdfe:dcba:9876::%s"
|
private const val PRIVATE_VLAN6 = "fdfe:dcba:9876::%s"
|
||||||
|
|
||||||
private val getInt: Method = FileDescriptor::class.java.getDeclaredMethod("getInt$")
|
private val getInt: Method = FileDescriptor::class.java.getDeclaredMethod("getInt$")
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unfortunately registerDefaultNetworkCallback is going to return VPN interface since Android P DP1:
|
||||||
|
* https://android.googlesource.com/platform/frameworks/base/+/dda156ab0c5d66ad82bdcf76cda07cbc0a9c8a2e
|
||||||
|
*
|
||||||
|
* This makes doing a requestNetwork with REQUEST necessary so that we don't get ALL possible networks that
|
||||||
|
* satisfies default network capabilities but only THE default network. Unfortunately we need to have
|
||||||
|
* android.permission.CHANGE_NETWORK_STATE to be able to call requestNetwork.
|
||||||
|
*
|
||||||
|
* Source: https://android.googlesource.com/platform/frameworks/base/+/2df4c7d/services/core/java/com/android/server/ConnectivityService.java#887
|
||||||
|
*/
|
||||||
|
private val defaultNetworkRequest = NetworkRequest.Builder()
|
||||||
|
.addCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)
|
||||||
|
.addCapability(NetworkCapabilities.NET_CAPABILITY_NOT_RESTRICTED)
|
||||||
|
.build()
|
||||||
}
|
}
|
||||||
|
|
||||||
private inner class ProtectWorker : LocalSocketListener("ShadowsocksVpnThread") {
|
private inner class ProtectWorker : LocalSocketListener("ShadowsocksVpnThread") {
|
||||||
@@ -59,13 +76,22 @@ class VpnService : BaseVpnService(), LocalDnsService.Interface {
|
|||||||
var success = false
|
var success = false
|
||||||
try {
|
try {
|
||||||
socket.inputStream.read()
|
socket.inputStream.read()
|
||||||
val fds = socket.ancillaryFileDescriptors
|
val fd = socket.ancillaryFileDescriptors!!.single()!!
|
||||||
if (fds.isEmpty()) return
|
val fdInt = getInt.invoke(fd) as Int
|
||||||
val fd = getInt.invoke(fds.first()) as Int
|
try {
|
||||||
success = protect(fd)
|
val network = underlyingNetwork
|
||||||
JniHelper.close(fd) // Trick to close file decriptor
|
success = if (network != null && Build.VERSION.SDK_INT >= 23) {
|
||||||
|
network.bindSocket(fd)
|
||||||
|
true
|
||||||
|
} else protect(fdInt)
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Log.e(tag, "Error when protect socket", e)
|
||||||
|
app.track(e)
|
||||||
|
} finally {
|
||||||
|
JniHelper.close(fdInt) // Trick to close file decriptor
|
||||||
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Log.e(tag, "Error when protect socket", e)
|
Log.e(tag, "Error when receiving ancillary fd", e)
|
||||||
app.track(e)
|
app.track(e)
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
@@ -89,6 +115,26 @@ class VpnService : BaseVpnService(), LocalDnsService.Interface {
|
|||||||
private var conn: ParcelFileDescriptor? = null
|
private var conn: ParcelFileDescriptor? = null
|
||||||
private var worker: ProtectWorker? = null
|
private var worker: ProtectWorker? = null
|
||||||
private var tun2socksProcess: GuardedProcess? = null
|
private var tun2socksProcess: GuardedProcess? = null
|
||||||
|
private var underlyingNetwork: Network? = null
|
||||||
|
set(value) {
|
||||||
|
if (Build.VERSION.SDK_INT >= 22) setUnderlyingNetworks(if (value == null) null else arrayOf(value))
|
||||||
|
field = value
|
||||||
|
}
|
||||||
|
|
||||||
|
private val connectivity by lazy { getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager }
|
||||||
|
private val defaultNetworkCallback = object : ConnectivityManager.NetworkCallback() {
|
||||||
|
override fun onAvailable(network: Network) {
|
||||||
|
underlyingNetwork = network
|
||||||
|
}
|
||||||
|
override fun onCapabilitiesChanged(network: Network, networkCapabilities: NetworkCapabilities?) {
|
||||||
|
// it's a good idea to refresh capabilities
|
||||||
|
underlyingNetwork = network
|
||||||
|
}
|
||||||
|
override fun onLost(network: Network) {
|
||||||
|
underlyingNetwork = null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private var listeningForDefaultNetwork = false
|
||||||
|
|
||||||
override fun onBind(intent: Intent): IBinder? = when (intent.action) {
|
override fun onBind(intent: Intent): IBinder? = when (intent.action) {
|
||||||
SERVICE_INTERFACE -> super<BaseVpnService>.onBind(intent)
|
SERVICE_INTERFACE -> super<BaseVpnService>.onBind(intent)
|
||||||
@@ -98,6 +144,10 @@ class VpnService : BaseVpnService(), LocalDnsService.Interface {
|
|||||||
override fun onRevoke() = stopRunner(true)
|
override fun onRevoke() = stopRunner(true)
|
||||||
|
|
||||||
override fun killProcesses() {
|
override fun killProcesses() {
|
||||||
|
if (listeningForDefaultNetwork) {
|
||||||
|
connectivity.unregisterNetworkCallback(defaultNetworkCallback)
|
||||||
|
listeningForDefaultNetwork = false
|
||||||
|
}
|
||||||
worker?.stopThread()
|
worker?.stopThread()
|
||||||
worker = null
|
worker = null
|
||||||
super.killProcesses()
|
super.killProcesses()
|
||||||
@@ -179,6 +229,10 @@ class VpnService : BaseVpnService(), LocalDnsService.Interface {
|
|||||||
this.conn = conn
|
this.conn = conn
|
||||||
val fd = conn.fd
|
val fd = conn.fd
|
||||||
|
|
||||||
|
// we want REQUEST here instead of LISTEN
|
||||||
|
connectivity.requestNetwork(defaultNetworkRequest, defaultNetworkCallback)
|
||||||
|
listeningForDefaultNetwork = true
|
||||||
|
|
||||||
val cmd = arrayListOf(File(applicationInfo.nativeLibraryDir, Executable.TUN2SOCKS).absolutePath,
|
val cmd = arrayListOf(File(applicationInfo.nativeLibraryDir, Executable.TUN2SOCKS).absolutePath,
|
||||||
"--netif-ipaddr", PRIVATE_VLAN.format(Locale.ENGLISH, "2"),
|
"--netif-ipaddr", PRIVATE_VLAN.format(Locale.ENGLISH, "2"),
|
||||||
"--netif-netmask", "255.255.255.0",
|
"--netif-netmask", "255.255.255.0",
|
||||||
|
|||||||
@@ -0,0 +1,61 @@
|
|||||||
|
/*******************************************************************************
|
||||||
|
* *
|
||||||
|
* Copyright (C) 2017 by Max Lv <max.c.lv@gmail.com> *
|
||||||
|
* Copyright (C) 2017 by Mygod Studio <contact-shadowsocks-android@mygod.be> *
|
||||||
|
* *
|
||||||
|
* This program is free software: you can redistribute it and/or modify *
|
||||||
|
* it under the terms of the GNU General Public License as published by *
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or *
|
||||||
|
* (at your option) any later version. *
|
||||||
|
* *
|
||||||
|
* This program is distributed in the hope that it will be useful, *
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||||
|
* GNU General Public License for more details. *
|
||||||
|
* *
|
||||||
|
* You should have received a copy of the GNU General Public License *
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
||||||
|
* *
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
package com.github.shadowsocks.database
|
||||||
|
|
||||||
|
import android.database.sqlite.SQLiteDatabaseLockedException
|
||||||
|
import com.j256.ormlite.dao.Dao
|
||||||
|
import com.j256.ormlite.support.ConnectionSource
|
||||||
|
import com.j256.ormlite.table.TableUtils
|
||||||
|
import java.sql.SQLException
|
||||||
|
|
||||||
|
private val Throwable.ultimateCause: Throwable get() {
|
||||||
|
var result = this
|
||||||
|
while (true) {
|
||||||
|
val cause = result.cause ?: return result
|
||||||
|
result = cause
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Throws(SQLException::class)
|
||||||
|
fun <T> safeWrapper(func: () -> T): T {
|
||||||
|
while (true) {
|
||||||
|
try {
|
||||||
|
return func()
|
||||||
|
} catch (e: SQLException) {
|
||||||
|
if (e.ultimateCause !is SQLiteDatabaseLockedException) throw e
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Throws(SQLException::class)
|
||||||
|
inline fun <reified T> ConnectionSource.createTableSafe() = safeWrapper { TableUtils.createTable(this, T::class.java) }
|
||||||
|
@Throws(SQLException::class)
|
||||||
|
fun <T, ID> Dao<T, ID>.queryAllSafe(): MutableList<T> = safeWrapper { queryForAll() }
|
||||||
|
@Throws(SQLException::class)
|
||||||
|
fun <T, ID> Dao<T, ID>.queryByIdSafe(id: ID?): T? = safeWrapper { queryForId(id) }
|
||||||
|
@Throws(SQLException::class)
|
||||||
|
fun <T, ID> Dao<T, ID>.updateSafe(data: T?): Int = safeWrapper { update(data) }
|
||||||
|
@Throws(SQLException::class)
|
||||||
|
fun <T, ID> Dao<T, ID>.replaceSafe(data: T?): Dao.CreateOrUpdateStatus? = safeWrapper { createOrUpdate(data) }
|
||||||
|
@Throws(SQLException::class)
|
||||||
|
fun <T, ID> Dao<T, ID>.deleteByIdSafe(id: ID?) = safeWrapper { deleteById(id) }
|
||||||
|
@Throws(SQLException::class)
|
||||||
|
fun <T, ID> Dao<T, ID>.executeSafe(statement: String?) = safeWrapper { executeRawNoArgs(statement) }
|
||||||
@@ -37,18 +37,18 @@ object PrivateDatabase : OrmLiteSqliteOpenHelper(app, Key.DB_PROFILE, null, 25)
|
|||||||
@Suppress("UNCHECKED_CAST")
|
@Suppress("UNCHECKED_CAST")
|
||||||
val kvPairDao: Dao<KeyValuePair, String?> by lazy { getDao(KeyValuePair::class.java) as Dao<KeyValuePair, String?> }
|
val kvPairDao: Dao<KeyValuePair, String?> by lazy { getDao(KeyValuePair::class.java) as Dao<KeyValuePair, String?> }
|
||||||
|
|
||||||
override fun onCreate(database: SQLiteDatabase?, connectionSource: ConnectionSource?) {
|
override fun onCreate(database: SQLiteDatabase?, connectionSource: ConnectionSource) {
|
||||||
TableUtils.createTable(connectionSource, Profile::class.java)
|
connectionSource.createTableSafe<Profile>()
|
||||||
TableUtils.createTable(connectionSource, KeyValuePair::class.java)
|
connectionSource.createTableSafe<KeyValuePair>()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun recreate(database: SQLiteDatabase?, connectionSource: ConnectionSource?) {
|
private fun recreate(database: SQLiteDatabase?, connectionSource: ConnectionSource) {
|
||||||
TableUtils.dropTable<Profile, Int>(connectionSource, Profile::class.java, true)
|
TableUtils.dropTable<Profile, Int>(connectionSource, Profile::class.java, true)
|
||||||
TableUtils.dropTable<KeyValuePair, String?>(connectionSource, KeyValuePair::class.java, true)
|
TableUtils.dropTable<KeyValuePair, String?>(connectionSource, KeyValuePair::class.java, true)
|
||||||
onCreate(database, connectionSource)
|
onCreate(database, connectionSource)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onUpgrade(database: SQLiteDatabase?, connectionSource: ConnectionSource?,
|
override fun onUpgrade(database: SQLiteDatabase?, connectionSource: ConnectionSource,
|
||||||
oldVersion: Int, newVersion: Int) {
|
oldVersion: Int, newVersion: Int) {
|
||||||
if (oldVersion < 7) {
|
if (oldVersion < 7) {
|
||||||
recreate(database, connectionSource)
|
recreate(database, connectionSource)
|
||||||
@@ -57,38 +57,38 @@ object PrivateDatabase : OrmLiteSqliteOpenHelper(app, Key.DB_PROFILE, null, 25)
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
if (oldVersion < 8) {
|
if (oldVersion < 8) {
|
||||||
profileDao.executeRawNoArgs("ALTER TABLE `profile` ADD COLUMN udpdns SMALLINT;")
|
profileDao.executeSafe("ALTER TABLE `profile` ADD COLUMN udpdns SMALLINT;")
|
||||||
}
|
}
|
||||||
if (oldVersion < 9) {
|
if (oldVersion < 9) {
|
||||||
profileDao.executeRawNoArgs("ALTER TABLE `profile` ADD COLUMN route VARCHAR DEFAULT 'all';")
|
profileDao.executeSafe("ALTER TABLE `profile` ADD COLUMN route VARCHAR DEFAULT 'all';")
|
||||||
} else if (oldVersion < 19) {
|
} else if (oldVersion < 19) {
|
||||||
profileDao.executeRawNoArgs("UPDATE `profile` SET route = 'all' WHERE route IS NULL;")
|
profileDao.executeSafe("UPDATE `profile` SET route = 'all' WHERE route IS NULL;")
|
||||||
}
|
}
|
||||||
if (oldVersion < 11) {
|
if (oldVersion < 11) {
|
||||||
profileDao.executeRawNoArgs("ALTER TABLE `profile` ADD COLUMN ipv6 SMALLINT;")
|
profileDao.executeSafe("ALTER TABLE `profile` ADD COLUMN ipv6 SMALLINT;")
|
||||||
}
|
}
|
||||||
if (oldVersion < 12) {
|
if (oldVersion < 12) {
|
||||||
profileDao.executeRawNoArgs("BEGIN TRANSACTION;")
|
profileDao.executeSafe("BEGIN TRANSACTION;")
|
||||||
profileDao.executeRawNoArgs("ALTER TABLE `profile` RENAME TO `tmp`;")
|
profileDao.executeSafe("ALTER TABLE `profile` RENAME TO `tmp`;")
|
||||||
TableUtils.createTable(connectionSource, Profile::class.java)
|
connectionSource.createTableSafe<Profile>()
|
||||||
profileDao.executeRawNoArgs(
|
profileDao.executeSafe(
|
||||||
"INSERT INTO `profile`(id, name, host, localPort, remotePort, password, method, route," +
|
"INSERT INTO `profile`(id, name, host, localPort, remotePort, password, method, route," +
|
||||||
" proxyApps, bypass, udpdns, ipv6, individual) " +
|
" proxyApps, bypass, udpdns, ipv6, individual) " +
|
||||||
"SELECT id, name, host, localPort, remotePort, password, method, route, 1 - global," +
|
"SELECT id, name, host, localPort, remotePort, password, method, route, 1 - global," +
|
||||||
" bypass, udpdns, ipv6, individual FROM `tmp`;")
|
" bypass, udpdns, ipv6, individual FROM `tmp`;")
|
||||||
profileDao.executeRawNoArgs("DROP TABLE `tmp`;")
|
profileDao.executeSafe("DROP TABLE `tmp`;")
|
||||||
profileDao.executeRawNoArgs("COMMIT;")
|
profileDao.executeSafe("COMMIT;")
|
||||||
} else if (oldVersion < 13) {
|
} else if (oldVersion < 13) {
|
||||||
profileDao.executeRawNoArgs("ALTER TABLE `profile` ADD COLUMN tx LONG;")
|
profileDao.executeSafe("ALTER TABLE `profile` ADD COLUMN tx LONG;")
|
||||||
profileDao.executeRawNoArgs("ALTER TABLE `profile` ADD COLUMN rx LONG;")
|
profileDao.executeSafe("ALTER TABLE `profile` ADD COLUMN rx LONG;")
|
||||||
profileDao.executeRawNoArgs("ALTER TABLE `profile` ADD COLUMN date VARCHAR;")
|
profileDao.executeSafe("ALTER TABLE `profile` ADD COLUMN date VARCHAR;")
|
||||||
}
|
}
|
||||||
|
|
||||||
if (oldVersion < 15) {
|
if (oldVersion < 15) {
|
||||||
if (oldVersion >= 12) profileDao.executeRawNoArgs("ALTER TABLE `profile` ADD COLUMN userOrder LONG;")
|
if (oldVersion >= 12) profileDao.executeSafe("ALTER TABLE `profile` ADD COLUMN userOrder LONG;")
|
||||||
var i = 0L
|
var i = 0L
|
||||||
val apps by lazy { app.packageManager.getInstalledApplications(0) }
|
val apps by lazy { app.packageManager.getInstalledApplications(0) }
|
||||||
for (profile in profileDao.queryForAll()) {
|
for (profile in profileDao.queryAllSafe()) {
|
||||||
if (oldVersion < 14) {
|
if (oldVersion < 14) {
|
||||||
val uidSet = profile.individual.split('|').filter(TextUtils::isDigitsOnly)
|
val uidSet = profile.individual.split('|').filter(TextUtils::isDigitsOnly)
|
||||||
.map(String::toInt).toSet()
|
.map(String::toInt).toSet()
|
||||||
@@ -96,28 +96,28 @@ object PrivateDatabase : OrmLiteSqliteOpenHelper(app, Key.DB_PROFILE, null, 25)
|
|||||||
.joinToString("\n") { it.packageName }
|
.joinToString("\n") { it.packageName }
|
||||||
}
|
}
|
||||||
profile.userOrder = i
|
profile.userOrder = i
|
||||||
profileDao.update(profile)
|
profileDao.updateSafe(profile)
|
||||||
i += 1
|
i += 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (oldVersion < 16) {
|
if (oldVersion < 16) {
|
||||||
profileDao.executeRawNoArgs(
|
profileDao.executeSafe(
|
||||||
"UPDATE `profile` SET route = 'bypass-lan-china' WHERE route = 'bypass-china'")
|
"UPDATE `profile` SET route = 'bypass-lan-china' WHERE route = 'bypass-china'")
|
||||||
}
|
}
|
||||||
|
|
||||||
if (oldVersion < 21) {
|
if (oldVersion < 21) {
|
||||||
profileDao.executeRawNoArgs("ALTER TABLE `profile` ADD COLUMN remoteDns VARCHAR DEFAULT '8.8.8.8';")
|
profileDao.executeSafe("ALTER TABLE `profile` ADD COLUMN remoteDns VARCHAR DEFAULT '8.8.8.8';")
|
||||||
}
|
}
|
||||||
|
|
||||||
if (oldVersion < 17) {
|
if (oldVersion < 17) {
|
||||||
profileDao.executeRawNoArgs("ALTER TABLE `profile` ADD COLUMN plugin VARCHAR;")
|
profileDao.executeSafe("ALTER TABLE `profile` ADD COLUMN plugin VARCHAR;")
|
||||||
} else if (oldVersion < 22) {
|
} else if (oldVersion < 22) {
|
||||||
// upgrade kcptun to SIP003 plugin
|
// upgrade kcptun to SIP003 plugin
|
||||||
profileDao.executeRawNoArgs("BEGIN TRANSACTION;")
|
profileDao.executeSafe("BEGIN TRANSACTION;")
|
||||||
profileDao.executeRawNoArgs("ALTER TABLE `profile` RENAME TO `tmp`;")
|
profileDao.executeSafe("ALTER TABLE `profile` RENAME TO `tmp`;")
|
||||||
TableUtils.createTable(connectionSource, Profile::class.java)
|
connectionSource.createTableSafe<Profile>()
|
||||||
profileDao.executeRawNoArgs(
|
profileDao.executeSafe(
|
||||||
"INSERT INTO `profile`(id, name, host, localPort, remotePort, password, method, route, " +
|
"INSERT INTO `profile`(id, name, host, localPort, remotePort, password, method, route, " +
|
||||||
"remoteDns, proxyApps, bypass, udpdns, ipv6, individual, tx, rx, date, userOrder, " +
|
"remoteDns, proxyApps, bypass, udpdns, ipv6, individual, tx, rx, date, userOrder, " +
|
||||||
"plugin) " +
|
"plugin) " +
|
||||||
@@ -125,17 +125,17 @@ object PrivateDatabase : OrmLiteSqliteOpenHelper(app, Key.DB_PROFILE, null, 25)
|
|||||||
"CASE WHEN kcp = 1 THEN kcpPort ELSE remotePort END, password, method, route, " +
|
"CASE WHEN kcp = 1 THEN kcpPort ELSE remotePort END, password, method, route, " +
|
||||||
"remoteDns, proxyApps, bypass, udpdns, ipv6, individual, tx, rx, date, userOrder, " +
|
"remoteDns, proxyApps, bypass, udpdns, ipv6, individual, tx, rx, date, userOrder, " +
|
||||||
"CASE WHEN kcp = 1 THEN 'kcptun ' || kcpcli ELSE NULL END FROM `tmp`;")
|
"CASE WHEN kcp = 1 THEN 'kcptun ' || kcpcli ELSE NULL END FROM `tmp`;")
|
||||||
profileDao.executeRawNoArgs("DROP TABLE `tmp`;")
|
profileDao.executeSafe("DROP TABLE `tmp`;")
|
||||||
profileDao.executeRawNoArgs("COMMIT;")
|
profileDao.executeSafe("COMMIT;")
|
||||||
}
|
}
|
||||||
|
|
||||||
if (oldVersion < 23) {
|
if (oldVersion < 23) {
|
||||||
profileDao.executeRawNoArgs("BEGIN TRANSACTION;")
|
profileDao.executeSafe("BEGIN TRANSACTION;")
|
||||||
TableUtils.createTable(connectionSource, KeyValuePair::class.java)
|
connectionSource.createTableSafe<KeyValuePair>()
|
||||||
profileDao.executeRawNoArgs("COMMIT;")
|
profileDao.executeSafe("COMMIT;")
|
||||||
val old = PreferenceManager.getDefaultSharedPreferences(app)
|
val old = PreferenceManager.getDefaultSharedPreferences(app)
|
||||||
PublicDatabase.kvPairDao.createOrUpdate(KeyValuePair(Key.id).put(old.getInt(Key.id, 0)))
|
PublicDatabase.kvPairDao.replaceSafe(KeyValuePair(Key.id).put(old.getInt(Key.id, 0)))
|
||||||
PublicDatabase.kvPairDao.createOrUpdate(KeyValuePair(Key.tfo).put(old.getBoolean(Key.tfo, false)))
|
PublicDatabase.kvPairDao.replaceSafe(KeyValuePair(Key.tfo).put(old.getBoolean(Key.tfo, false)))
|
||||||
}
|
}
|
||||||
|
|
||||||
if (oldVersion < 25) {
|
if (oldVersion < 25) {
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ import com.j256.ormlite.field.DataType
|
|||||||
import com.j256.ormlite.field.DatabaseField
|
import com.j256.ormlite.field.DatabaseField
|
||||||
import java.io.Serializable
|
import java.io.Serializable
|
||||||
import java.net.URI
|
import java.net.URI
|
||||||
|
import java.net.URISyntaxException
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
class Profile : Serializable {
|
class Profile : Serializable {
|
||||||
@@ -43,41 +44,51 @@ class Profile : Serializable {
|
|||||||
|
|
||||||
fun findAll(data: CharSequence?) = pattern.findAll(data ?: "").map {
|
fun findAll(data: CharSequence?) = pattern.findAll(data ?: "").map {
|
||||||
val uri = Uri.parse(it.value)
|
val uri = Uri.parse(it.value)
|
||||||
if (uri.userInfo == null) {
|
try {
|
||||||
val match = legacyPattern.matchEntire(String(Base64.decode(uri.host, Base64.NO_PADDING)))
|
if (uri.userInfo == null) {
|
||||||
if (match != null) {
|
val match = legacyPattern.matchEntire(String(Base64.decode(uri.host, Base64.NO_PADDING)))
|
||||||
val profile = Profile()
|
if (match != null) {
|
||||||
profile.method = match.groupValues[1].toLowerCase()
|
val profile = Profile()
|
||||||
profile.password = match.groupValues[2]
|
profile.method = match.groupValues[1].toLowerCase()
|
||||||
profile.host = match.groupValues[3]
|
profile.password = match.groupValues[2]
|
||||||
profile.remotePort = match.groupValues[4].toInt()
|
profile.host = match.groupValues[3]
|
||||||
profile.plugin = uri.getQueryParameter(Key.plugin)
|
profile.remotePort = match.groupValues[4].toInt()
|
||||||
profile.name = uri.fragment
|
profile.plugin = uri.getQueryParameter(Key.plugin)
|
||||||
profile
|
profile.name = uri.fragment
|
||||||
|
profile
|
||||||
|
} else {
|
||||||
|
Log.e(TAG, "Unrecognized URI: ${it.value}")
|
||||||
|
null
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
Log.e(TAG, "Unrecognized URI: ${it.value}")
|
val match = userInfoPattern.matchEntire(String(Base64.decode(uri.userInfo,
|
||||||
null
|
Base64.NO_PADDING or Base64.NO_WRAP or Base64.URL_SAFE)))
|
||||||
}
|
if (match != null) {
|
||||||
} else {
|
val profile = Profile()
|
||||||
val match = userInfoPattern.matchEntire(String(Base64.decode(uri.userInfo,
|
profile.method = match.groupValues[1]
|
||||||
Base64.NO_PADDING or Base64.NO_WRAP or Base64.URL_SAFE)))
|
profile.password = match.groupValues[2]
|
||||||
if (match != null) {
|
// bug in Android: https://code.google.com/p/android/issues/detail?id=192855
|
||||||
val profile = Profile()
|
try {
|
||||||
profile.method = match.groupValues[1]
|
val javaURI = URI(it.value)
|
||||||
profile.password = match.groupValues[2]
|
profile.host = javaURI.host ?: ""
|
||||||
// bug in Android: https://code.google.com/p/android/issues/detail?id=192855
|
if (profile.host.firstOrNull() == '[' && profile.host.lastOrNull() == ']')
|
||||||
val javaURI = URI(it.value)
|
profile.host = profile.host.substring(1, profile.host.length - 1)
|
||||||
profile.host = javaURI.host
|
profile.remotePort = javaURI.port
|
||||||
if (profile.host.firstOrNull() == '[' && profile.host.lastOrNull() == ']')
|
profile.plugin = uri.getQueryParameter(Key.plugin)
|
||||||
profile.host = profile.host.substring(1, profile.host.length - 1)
|
profile.name = uri.fragment ?: ""
|
||||||
profile.remotePort = javaURI.port
|
profile
|
||||||
profile.plugin = uri.getQueryParameter(Key.plugin)
|
} catch (e: URISyntaxException) {
|
||||||
profile.name = uri.fragment ?: ""
|
Log.e(TAG, "Invalid URI: ${it.value}")
|
||||||
profile
|
null
|
||||||
} else {
|
}
|
||||||
Log.e(TAG, "Unknown user info: ${it.value}")
|
} else {
|
||||||
null
|
Log.e(TAG, "Unknown user info: ${it.value}")
|
||||||
|
null
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} catch (e: IllegalArgumentException) {
|
||||||
|
Log.e(TAG, "Invalid base64 detected: ${it.value}")
|
||||||
|
null
|
||||||
}
|
}
|
||||||
}.filterNotNull()
|
}.filterNotNull()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,10 +48,12 @@ object ProfileManager {
|
|||||||
profile.individual = oldProfile.individual
|
profile.individual = oldProfile.individual
|
||||||
profile.udpdns = oldProfile.udpdns
|
profile.udpdns = oldProfile.udpdns
|
||||||
}
|
}
|
||||||
val last = PrivateDatabase.profileDao.queryRaw(PrivateDatabase.profileDao.queryBuilder()
|
val last = safeWrapper {
|
||||||
|
PrivateDatabase.profileDao.queryRaw(PrivateDatabase.profileDao.queryBuilder()
|
||||||
.selectRaw("MAX(userOrder)").prepareStatementString()).firstResult
|
.selectRaw("MAX(userOrder)").prepareStatementString()).firstResult
|
||||||
|
}
|
||||||
if (last != null && last.size == 1 && last[0] != null) profile.userOrder = last[0].toLong() + 1
|
if (last != null && last.size == 1 && last[0] != null) profile.userOrder = last[0].toLong() + 1
|
||||||
PrivateDatabase.profileDao.createOrUpdate(profile)
|
PrivateDatabase.profileDao.replaceSafe(profile)
|
||||||
ProfilesFragment.instance?.profilesAdapter?.add(profile)
|
ProfilesFragment.instance?.profilesAdapter?.add(profile)
|
||||||
return profile
|
return profile
|
||||||
}
|
}
|
||||||
@@ -60,10 +62,10 @@ object ProfileManager {
|
|||||||
* Note: It's caller's responsibility to update DirectBoot profile if necessary.
|
* Note: It's caller's responsibility to update DirectBoot profile if necessary.
|
||||||
*/
|
*/
|
||||||
@Throws(SQLException::class)
|
@Throws(SQLException::class)
|
||||||
fun updateProfile(profile: Profile) = PrivateDatabase.profileDao.update(profile)
|
fun updateProfile(profile: Profile) = PrivateDatabase.profileDao.updateSafe(profile)
|
||||||
|
|
||||||
fun getProfile(id: Int): Profile? = try {
|
fun getProfile(id: Int): Profile? = try {
|
||||||
PrivateDatabase.profileDao.queryForId(id)
|
PrivateDatabase.profileDao.queryByIdSafe(id)
|
||||||
} catch (ex: SQLException) {
|
} catch (ex: SQLException) {
|
||||||
Log.e(TAG, "getProfile", ex)
|
Log.e(TAG, "getProfile", ex)
|
||||||
app.track(ex)
|
app.track(ex)
|
||||||
@@ -72,13 +74,16 @@ object ProfileManager {
|
|||||||
|
|
||||||
@Throws(SQLException::class)
|
@Throws(SQLException::class)
|
||||||
fun delProfile(id: Int) {
|
fun delProfile(id: Int) {
|
||||||
PrivateDatabase.profileDao.deleteById(id)
|
PrivateDatabase.profileDao.deleteByIdSafe(id)
|
||||||
ProfilesFragment.instance?.profilesAdapter?.removeId(id)
|
ProfilesFragment.instance?.profilesAdapter?.removeId(id)
|
||||||
if (id == DataStore.profileId && DataStore.directBootAware) DirectBoot.clean()
|
if (id == DataStore.profileId && DataStore.directBootAware) DirectBoot.clean()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getFirstProfile(): Profile? = try {
|
fun getFirstProfile(): Profile? = try {
|
||||||
PrivateDatabase.profileDao.query(PrivateDatabase.profileDao.queryBuilder().limit(1L).prepare()).singleOrNull()
|
safeWrapper {
|
||||||
|
PrivateDatabase.profileDao.query(
|
||||||
|
PrivateDatabase.profileDao.queryBuilder().limit(1L).prepare()).singleOrNull()
|
||||||
|
}
|
||||||
} catch (ex: SQLException) {
|
} catch (ex: SQLException) {
|
||||||
Log.e(TAG, "getFirstProfile", ex)
|
Log.e(TAG, "getFirstProfile", ex)
|
||||||
app.track(ex)
|
app.track(ex)
|
||||||
@@ -86,7 +91,10 @@ object ProfileManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun getAllProfiles(): List<Profile>? = try {
|
fun getAllProfiles(): List<Profile>? = try {
|
||||||
PrivateDatabase.profileDao.query(PrivateDatabase.profileDao.queryBuilder().orderBy("userOrder", true).prepare())
|
safeWrapper {
|
||||||
|
PrivateDatabase.profileDao.query(
|
||||||
|
PrivateDatabase.profileDao.queryBuilder().orderBy("userOrder", true).prepare())
|
||||||
|
}
|
||||||
} catch (ex: SQLException) {
|
} catch (ex: SQLException) {
|
||||||
Log.e(TAG, "getAllProfiles", ex)
|
Log.e(TAG, "getAllProfiles", ex)
|
||||||
app.track(ex)
|
app.track(ex)
|
||||||
|
|||||||
@@ -34,20 +34,21 @@ object PublicDatabase : OrmLiteSqliteOpenHelper(app.deviceContext, Key.DB_PUBLIC
|
|||||||
@Suppress("UNCHECKED_CAST")
|
@Suppress("UNCHECKED_CAST")
|
||||||
val kvPairDao: Dao<KeyValuePair, String?> by lazy { getDao(KeyValuePair::class.java) as Dao<KeyValuePair, String?> }
|
val kvPairDao: Dao<KeyValuePair, String?> by lazy { getDao(KeyValuePair::class.java) as Dao<KeyValuePair, String?> }
|
||||||
|
|
||||||
override fun onCreate(database: SQLiteDatabase?, connectionSource: ConnectionSource?) {
|
override fun onCreate(database: SQLiteDatabase?, connectionSource: ConnectionSource) {
|
||||||
TableUtils.createTable(connectionSource, KeyValuePair::class.java)
|
connectionSource.createTableSafe<KeyValuePair>()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onUpgrade(database: SQLiteDatabase?, connectionSource: ConnectionSource?,
|
override fun onUpgrade(database: SQLiteDatabase?, connectionSource: ConnectionSource?,
|
||||||
oldVersion: Int, newVersion: Int) {
|
oldVersion: Int, newVersion: Int) {
|
||||||
if (oldVersion < 1) {
|
if (oldVersion < 1) {
|
||||||
PrivateDatabase.kvPairDao.queryBuilder().where().`in`("key",
|
safeWrapper {
|
||||||
|
PrivateDatabase.kvPairDao.queryBuilder().where().`in`("key",
|
||||||
Key.id, Key.tfo, Key.serviceMode, Key.portProxy, Key.portLocalDns, Key.portTransproxy).query()
|
Key.id, Key.tfo, Key.serviceMode, Key.portProxy, Key.portLocalDns, Key.portTransproxy).query()
|
||||||
.forEach { kvPairDao.createOrUpdate(it) }
|
}.forEach { kvPairDao.replaceSafe(it) }
|
||||||
}
|
}
|
||||||
|
|
||||||
if (oldVersion < 2) {
|
if (oldVersion < 2) {
|
||||||
kvPairDao.createOrUpdate(KeyValuePair(Acl.CUSTOM_RULES).put(Acl().fromId(Acl.CUSTOM_RULES).toString()))
|
kvPairDao.replaceSafe(KeyValuePair(Acl.CUSTOM_RULES).put(Acl().fromId(Acl.CUSTOM_RULES).toString()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ import android.os.Bundle
|
|||||||
|
|
||||||
class NativePlugin(resolveInfo: ResolveInfo) : ResolvedPlugin(resolveInfo) {
|
class NativePlugin(resolveInfo: ResolveInfo) : ResolvedPlugin(resolveInfo) {
|
||||||
init {
|
init {
|
||||||
assert(resolveInfo.providerInfo != null)
|
check(resolveInfo.providerInfo != null)
|
||||||
}
|
}
|
||||||
|
|
||||||
override val metaData: Bundle get() = resolveInfo.providerInfo.metaData
|
override val metaData: Bundle get() = resolveInfo.providerInfo.metaData
|
||||||
|
|||||||
@@ -134,7 +134,7 @@ object PluginManager {
|
|||||||
private fun initNative(options: PluginOptions): String? {
|
private fun initNative(options: PluginOptions): String? {
|
||||||
val providers = app.packageManager.queryIntentContentProviders(
|
val providers = app.packageManager.queryIntentContentProviders(
|
||||||
Intent(PluginContract.ACTION_NATIVE_PLUGIN, buildUri(options.id)), 0)
|
Intent(PluginContract.ACTION_NATIVE_PLUGIN, buildUri(options.id)), 0)
|
||||||
assert(providers.size == 1)
|
check(providers.size == 1)
|
||||||
val uri = Uri.Builder()
|
val uri = Uri.Builder()
|
||||||
.scheme(ContentResolver.SCHEME_CONTENT)
|
.scheme(ContentResolver.SCHEME_CONTENT)
|
||||||
.authority(providers[0].providerInfo.authority)
|
.authority(providers[0].providerInfo.authority)
|
||||||
@@ -154,7 +154,7 @@ object PluginManager {
|
|||||||
out.putString(PluginContract.EXTRA_OPTIONS, options.id)
|
out.putString(PluginContract.EXTRA_OPTIONS, options.id)
|
||||||
val result = cr.call(uri, PluginContract.METHOD_GET_EXECUTABLE, null, out)
|
val result = cr.call(uri, PluginContract.METHOD_GET_EXECUTABLE, null, out)
|
||||||
.getString(PluginContract.EXTRA_ENTRY)
|
.getString(PluginContract.EXTRA_ENTRY)
|
||||||
assert(File(result).canExecute())
|
check(File(result).canExecute())
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -173,7 +173,7 @@ object PluginManager {
|
|||||||
do {
|
do {
|
||||||
val path = cursor.getString(0)
|
val path = cursor.getString(0)
|
||||||
val file = File(pluginDir, path)
|
val file = File(pluginDir, path)
|
||||||
assert(file.absolutePath.startsWith(pluginDirPath))
|
check(file.absolutePath.startsWith(pluginDirPath))
|
||||||
cr.openInputStream(uri.buildUpon().path(path).build()).use { inStream ->
|
cr.openInputStream(uri.buildUpon().path(path).build()).use { inStream ->
|
||||||
file.outputStream().use { outStream -> inStream.copyTo(outStream) }
|
file.outputStream().use { outStream -> inStream.copyTo(outStream) }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,5 +33,7 @@ abstract class ResolvedPlugin(protected val resolveInfo: ResolveInfo) : Plugin()
|
|||||||
override val icon: Drawable by lazy { resolveInfo.loadIcon(app.packageManager) }
|
override val icon: Drawable by lazy { resolveInfo.loadIcon(app.packageManager) }
|
||||||
override val defaultConfig: String by lazy { metaData.getString(PluginContract.METADATA_KEY_DEFAULT_CONFIG) }
|
override val defaultConfig: String by lazy { metaData.getString(PluginContract.METADATA_KEY_DEFAULT_CONFIG) }
|
||||||
override val packageName: String get() = resolveInfo.resolvePackageName
|
override val packageName: String get() = resolveInfo.resolvePackageName
|
||||||
override val trusted by lazy { app.info.signatures.any(PluginManager.trustedSignatures::contains) }
|
override val trusted by lazy {
|
||||||
|
app.getPackageInfo(packageName).signatures.any(PluginManager.trustedSignatures::contains)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -101,8 +101,8 @@ class BottomSheetPreferenceDialogFragment : PreferenceDialogFragmentCompat() {
|
|||||||
private var clickedIndex = -1
|
private var clickedIndex = -1
|
||||||
|
|
||||||
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
||||||
val activity = activity
|
val activity = requireActivity()
|
||||||
val dialog = BottomSheetDialog(activity!!, theme)
|
val dialog = BottomSheetDialog(activity, theme)
|
||||||
val recycler = RecyclerView(activity)
|
val recycler = RecyclerView(activity)
|
||||||
val padding = resources.getDimensionPixelOffset(R.dimen.bottom_sheet_padding)
|
val padding = resources.getDimensionPixelOffset(R.dimen.bottom_sheet_padding)
|
||||||
recycler.setPadding(0, padding, 0, padding)
|
recycler.setPadding(0, padding, 0, padding)
|
||||||
|
|||||||
+16
-13
@@ -22,17 +22,20 @@ package com.github.shadowsocks.preference
|
|||||||
|
|
||||||
import android.support.v7.preference.PreferenceDataStore
|
import android.support.v7.preference.PreferenceDataStore
|
||||||
import com.github.shadowsocks.database.KeyValuePair
|
import com.github.shadowsocks.database.KeyValuePair
|
||||||
|
import com.github.shadowsocks.database.deleteByIdSafe
|
||||||
|
import com.github.shadowsocks.database.queryByIdSafe
|
||||||
|
import com.github.shadowsocks.database.replaceSafe
|
||||||
import com.j256.ormlite.dao.Dao
|
import com.j256.ormlite.dao.Dao
|
||||||
import java.util.HashSet
|
import java.util.HashSet
|
||||||
|
|
||||||
@Suppress("MemberVisibilityCanPrivate", "unused")
|
@Suppress("MemberVisibilityCanPrivate", "unused")
|
||||||
open class OrmLitePreferenceDataStore(private val kvPairDao: Dao<KeyValuePair, String?>) : PreferenceDataStore() {
|
open class OrmLitePreferenceDataStore(private val kvPairDao: Dao<KeyValuePair, String?>) : PreferenceDataStore() {
|
||||||
fun getBoolean(key: String?) = kvPairDao.queryForId(key)?.boolean
|
fun getBoolean(key: String?) = kvPairDao.queryByIdSafe(key)?.boolean
|
||||||
fun getFloat(key: String?) = kvPairDao.queryForId(key)?.float
|
fun getFloat(key: String?) = kvPairDao.queryByIdSafe(key)?.float
|
||||||
fun getInt(key: String?) = kvPairDao.queryForId(key)?.int
|
fun getInt(key: String?) = kvPairDao.queryByIdSafe(key)?.int
|
||||||
fun getLong(key: String?) = kvPairDao.queryForId(key)?.long
|
fun getLong(key: String?) = kvPairDao.queryByIdSafe(key)?.long
|
||||||
fun getString(key: String?) = kvPairDao.queryForId(key)?.string
|
fun getString(key: String?) = kvPairDao.queryByIdSafe(key)?.string
|
||||||
fun getStringSet(key: String?) = kvPairDao.queryForId(key)?.stringSet
|
fun getStringSet(key: String?) = kvPairDao.queryByIdSafe(key)?.stringSet
|
||||||
|
|
||||||
override fun getBoolean(key: String?, defValue: Boolean) = getBoolean(key) ?: defValue
|
override fun getBoolean(key: String?, defValue: Boolean) = getBoolean(key) ?: defValue
|
||||||
override fun getFloat(key: String?, defValue: Float) = getFloat(key) ?: defValue
|
override fun getFloat(key: String?, defValue: Float) = getFloat(key) ?: defValue
|
||||||
@@ -46,32 +49,32 @@ open class OrmLitePreferenceDataStore(private val kvPairDao: Dao<KeyValuePair, S
|
|||||||
fun putInt(key: String?, value: Int?) = if (value == null) remove(key) else putInt(key, value)
|
fun putInt(key: String?, value: Int?) = if (value == null) remove(key) else putInt(key, value)
|
||||||
fun putLong(key: String?, value: Long?) = if (value == null) remove(key) else putLong(key, value)
|
fun putLong(key: String?, value: Long?) = if (value == null) remove(key) else putLong(key, value)
|
||||||
override fun putBoolean(key: String?, value: Boolean) {
|
override fun putBoolean(key: String?, value: Boolean) {
|
||||||
kvPairDao.createOrUpdate(KeyValuePair(key).put(value))
|
kvPairDao.replaceSafe(KeyValuePair(key).put(value))
|
||||||
fireChangeListener(key)
|
fireChangeListener(key)
|
||||||
}
|
}
|
||||||
override fun putFloat(key: String?, value: Float) {
|
override fun putFloat(key: String?, value: Float) {
|
||||||
kvPairDao.createOrUpdate(KeyValuePair(key).put(value))
|
kvPairDao.replaceSafe(KeyValuePair(key).put(value))
|
||||||
fireChangeListener(key)
|
fireChangeListener(key)
|
||||||
}
|
}
|
||||||
override fun putInt(key: String?, value: Int) {
|
override fun putInt(key: String?, value: Int) {
|
||||||
kvPairDao.createOrUpdate(KeyValuePair(key).put(value))
|
kvPairDao.replaceSafe(KeyValuePair(key).put(value))
|
||||||
fireChangeListener(key)
|
fireChangeListener(key)
|
||||||
}
|
}
|
||||||
override fun putLong(key: String?, value: Long) {
|
override fun putLong(key: String?, value: Long) {
|
||||||
kvPairDao.createOrUpdate(KeyValuePair(key).put(value))
|
kvPairDao.replaceSafe(KeyValuePair(key).put(value))
|
||||||
fireChangeListener(key)
|
fireChangeListener(key)
|
||||||
}
|
}
|
||||||
override fun putString(key: String?, value: String?) = if (value == null) remove(key) else {
|
override fun putString(key: String?, value: String?) = if (value == null) remove(key) else {
|
||||||
kvPairDao.createOrUpdate(KeyValuePair(key).put(value))
|
kvPairDao.replaceSafe(KeyValuePair(key).put(value))
|
||||||
fireChangeListener(key)
|
fireChangeListener(key)
|
||||||
}
|
}
|
||||||
override fun putStringSet(key: String?, values: MutableSet<String>?) = if (values == null) remove(key) else {
|
override fun putStringSet(key: String?, values: MutableSet<String>?) = if (values == null) remove(key) else {
|
||||||
kvPairDao.createOrUpdate(KeyValuePair(key).put(values))
|
kvPairDao.replaceSafe(KeyValuePair(key).put(values))
|
||||||
fireChangeListener(key)
|
fireChangeListener(key)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun remove(key: String?) {
|
fun remove(key: String?) {
|
||||||
kvPairDao.deleteById(key)
|
kvPairDao.deleteByIdSafe(key)
|
||||||
fireChangeListener(key)
|
fireChangeListener(key)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+3
-2
@@ -40,8 +40,9 @@ class PluginConfigurationDialogFragment : EditTextPreferenceDialogFragmentCompat
|
|||||||
super.onPrepareDialogBuilder(builder)
|
super.onPrepareDialogBuilder(builder)
|
||||||
val intent = PluginManager.buildIntent(arguments!!.getString(PLUGIN_ID_FRAGMENT_TAG),
|
val intent = PluginManager.buildIntent(arguments!!.getString(PLUGIN_ID_FRAGMENT_TAG),
|
||||||
PluginContract.ACTION_HELP)
|
PluginContract.ACTION_HELP)
|
||||||
if (intent.resolveActivity(activity!!.packageManager) != null) builder.setNeutralButton("?", { _, _ ->
|
val activity = requireActivity()
|
||||||
activity!!.startActivityForResult(intent.putExtra(PluginContract.EXTRA_OPTIONS, editText.text.toString()),
|
if (intent.resolveActivity(activity.packageManager) != null) builder.setNeutralButton("?", { _, _ ->
|
||||||
|
activity.startActivityForResult(intent.putExtra(PluginContract.EXTRA_OPTIONS, editText.text.toString()),
|
||||||
ProfileConfigActivity.REQUEST_CODE_PLUGIN_HELP)
|
ProfileConfigActivity.REQUEST_CODE_PLUGIN_HELP)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ abstract class NativePluginProvider : ContentProvider() {
|
|||||||
|
|
||||||
override fun query(uri: Uri, projection: Array<out String>?, selection: String?, selectionArgs: Array<out String>?,
|
override fun query(uri: Uri, projection: Array<out String>?, selection: String?, selectionArgs: Array<out String>?,
|
||||||
sortOrder: String?): Cursor {
|
sortOrder: String?): Cursor {
|
||||||
assert(selection == null && selectionArgs == null && sortOrder == null)
|
check(selection == null && selectionArgs == null && sortOrder == null)
|
||||||
val result = MatrixCursor(projection)
|
val result = MatrixCursor(projection)
|
||||||
populateFiles(PathProvider(uri, result))
|
populateFiles(PathProvider(uri, result))
|
||||||
return result
|
return result
|
||||||
@@ -79,7 +79,7 @@ abstract class NativePluginProvider : ContentProvider() {
|
|||||||
|
|
||||||
abstract fun openFile(uri: Uri?): ParcelFileDescriptor
|
abstract fun openFile(uri: Uri?): ParcelFileDescriptor
|
||||||
override fun openFile(uri: Uri?, mode: String?): ParcelFileDescriptor {
|
override fun openFile(uri: Uri?, mode: String?): ParcelFileDescriptor {
|
||||||
assert(mode == "r")
|
check(mode == "r")
|
||||||
return openFile(uri)
|
return openFile(uri)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user