Skip to content

Commit

Permalink
autostart mechanism changed
Browse files Browse the repository at this point in the history
  • Loading branch information
romanvht committed Dec 15, 2024
1 parent ce9b8f4 commit 1fbec0b
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 127 deletions.
13 changes: 1 addition & 12 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -89,18 +89,6 @@
</intent-filter>
</service>

<service
android:name=".services.AutoStartService"
android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE"
android:exported="true">
<intent-filter>
<action android:name="android.accessibilityservice.AccessibilityService" />
</intent-filter>
<meta-data
android:name="android.accessibility_service"
android:resource="@xml/accessibility_service_config" />
</service>

<receiver
android:name=".receiver.BootReceiver"
android:enabled="true"
Expand All @@ -109,6 +97,7 @@
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
<action android:name="android.intent.action.REBOOT" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ import android.view.MenuItem
import android.widget.Toast
import androidx.activity.result.contract.ActivityResultContracts
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.app.AppCompatDelegate
import androidx.core.content.ContextCompat
import androidx.core.os.LocaleListCompat
import androidx.lifecycle.lifecycleScope
import io.github.dovecoteescapee.byedpi.R
import io.github.dovecoteescapee.byedpi.data.*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package io.github.dovecoteescapee.byedpi.fragments
import android.content.Intent
import android.content.SharedPreferences
import android.os.Bundle
import android.provider.Settings
import android.util.Log
import androidx.appcompat.app.AppCompatDelegate
import androidx.core.os.LocaleListCompat
Expand All @@ -12,8 +11,6 @@ import io.github.dovecoteescapee.byedpi.BuildConfig
import io.github.dovecoteescapee.byedpi.R
import io.github.dovecoteescapee.byedpi.activities.TestActivity
import io.github.dovecoteescapee.byedpi.data.Mode
import io.github.dovecoteescapee.byedpi.utility.AccessibilityUtils
import io.github.dovecoteescapee.byedpi.services.AutoStartService
import io.github.dovecoteescapee.byedpi.utility.*

class MainSettingsFragment : PreferenceFragmentCompat() {
Expand Down Expand Up @@ -77,10 +74,8 @@ class MainSettingsFragment : PreferenceFragmentCompat() {
setTheme(newValue as String)
true
}

val accessibilityStatus = findPreferenceNotNull<Preference>("accessibility_service_status")
val switchCommandLineSettings = findPreferenceNotNull<SwitchPreference>("byedpi_enable_cmd_settings")


val switchCmdSettings = findPreferenceNotNull<SwitchPreference>("byedpi_enable_cmd_settings")
val uiSettings = findPreferenceNotNull<Preference>("byedpi_ui_settings")
val cmdSettings = findPreferenceNotNull<Preference>("byedpi_cmd_settings")
val proxyTest = findPreferenceNotNull<Preference>("proxy_test")
Expand All @@ -91,20 +86,14 @@ class MainSettingsFragment : PreferenceFragmentCompat() {
proxyTest.isEnabled = enable
}

setByeDpiSettingsMode(switchCommandLineSettings.isChecked)
setByeDpiSettingsMode(switchCmdSettings.isChecked)

switchCommandLineSettings.setOnPreferenceChangeListener { _, newValue ->
switchCmdSettings.setOnPreferenceChangeListener { _, newValue ->
setByeDpiSettingsMode(newValue as Boolean)
updatePreferences()
true
}

accessibilityStatus.setOnPreferenceClickListener {
val intent = Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS)
startActivity(intent)
true
}

findPreferenceNotNull<Preference>("proxy_test")
.setOnPreferenceClickListener {
val intent = Intent(context, TestActivity::class.java)
Expand All @@ -114,14 +103,12 @@ class MainSettingsFragment : PreferenceFragmentCompat() {

findPreferenceNotNull<Preference>("version").summary = BuildConfig.VERSION_NAME

updateAccessibilityStatus()
updatePreferences()
}

override fun onResume() {
super.onResume()
sharedPreferences?.registerOnSharedPreferenceChangeListener(preferenceListener)
updateAccessibilityStatus()
updatePreferences()
}

Expand Down Expand Up @@ -179,17 +166,4 @@ class MainSettingsFragment : PreferenceFragmentCompat() {
}
}
}

private fun updateAccessibilityStatus() {
val accessibilityStatus = findPreferenceNotNull<Preference>("accessibility_service_status")
val isEnabled = AccessibilityUtils.isAccessibilityServiceEnabled(
requireContext(),
AutoStartService::class.java
)
accessibilityStatus.summary = if (isEnabled) {
getString(R.string.accessibility_service_enabled)
} else {
getString(R.string.accessibility_service_disabled)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,31 @@ package io.github.dovecoteescapee.byedpi.receiver
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import io.github.dovecoteescapee.byedpi.services.AutoStartService
import io.github.dovecoteescapee.byedpi.utility.AccessibilityUtils
import android.net.VpnService
import io.github.dovecoteescapee.byedpi.data.Mode
import io.github.dovecoteescapee.byedpi.services.ServiceManager
import io.github.dovecoteescapee.byedpi.utility.getPreferences
import io.github.dovecoteescapee.byedpi.utility.mode

class BootReceiver : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
if (intent.action == Intent.ACTION_BOOT_COMPLETED ||
intent.action == Intent.ACTION_REBOOT ||
intent.action == "android.intent.action.QUICKBOOT_POWERON") {

val autorunEnabled = AccessibilityUtils.isAccessibilityServiceEnabled(
context,
AutoStartService::class.java
)
val preferences = context.getPreferences()
val autorunEnabled = preferences.getBoolean("autostart", false)

if(autorunEnabled) {
val serviceIntent = Intent(context, AutoStartService::class.java)
context.startService(serviceIntent)
when (preferences.mode()) {
Mode.VPN -> {
if (VpnService.prepare(context) == null) {
ServiceManager.start(context, Mode.VPN)
}
}

Mode.Proxy -> ServiceManager.start(context, Mode.Proxy)
}
}
}
}
Expand Down

This file was deleted.

This file was deleted.

2 changes: 1 addition & 1 deletion app/src/main/res/values-en/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
<string name="byedpi_protocols_category">Protocols</string>
<string name="byedpi_protocols_hint">Uncheck all to desync all traffic</string>
<string name="automation">Automation</string>
<string name="accessibility_service_description">Autostart service on device startup</string>
<string name="autostart_settings">Autostart service on device startup</string>
<string name="autohide_settings">Automatically hide application after autostart</string>
<string name="autoconnect_settings">Automatically connect when the application starts</string>
<string name="accessibility_service_status">Autostart status</string>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
<string name="byedpi_protocols_category">Протоколы</string>
<string name="byedpi_protocols_hint">Снимите все галочки, чтобы десинхронизировать весь трафик</string>
<string name="automation">Автоматизация</string>
<string name="accessibility_service_description">Автозапуск приложения при включении устройства</string>
<string name="autostart_settings">Автозапуск приложения при включении устройства</string>
<string name="autohide_settings">Автоматически скрывать приложение после автозапуска</string>
<string name="autoconnect_settings">Автоматическое подключение при открытии приложения</string>
<string name="accessibility_service_status">Статус автозапуска</string>
Expand Down
7 changes: 0 additions & 7 deletions app/src/main/res/xml/accessibility_service_config.xml

This file was deleted.

7 changes: 4 additions & 3 deletions app/src/main/res/xml/main_settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,10 @@
<androidx.preference.PreferenceCategory
android:title="@string/automation">

<Preference
android:key="accessibility_service_status"
android:title="@string/accessibility_service_status" />
<SwitchPreference
android:key="autostart"
android:title="@string/autostart_settings"
android:defaultValue="false" />

<SwitchPreference
android:key="auto_connect"
Expand Down

0 comments on commit 1fbec0b

Please sign in to comment.