mirror of
https://github.com/jrpie/Launcher.git
synced 2025-02-23 06:21:31 +01:00
some refactoring
This commit is contained in:
parent
cc64745c0f
commit
edc4927f1a
2 changed files with 21 additions and 18 deletions
|
@ -23,6 +23,7 @@ class LauncherAccessibilityService : AccessibilityService() {
|
|||
}
|
||||
|
||||
companion object {
|
||||
private const val TAG = "Launcher Accessibility"
|
||||
const val ACTION_LOCK_SCREEN = "ACTION_LOCK_SCREEN"
|
||||
|
||||
fun lockScreen(context: Context) {
|
||||
|
@ -44,17 +45,14 @@ class LauncherAccessibilityService : AccessibilityService() {
|
|||
}
|
||||
|
||||
fun isEnabled(context: Context): Boolean {
|
||||
val enabledServices = Settings.Secure.getString(context.contentResolver, Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES)
|
||||
for (service in enabledServices.split(":")) {
|
||||
val pkg = service.split("/")[0]
|
||||
val serviceClass = service.split("/")[1]
|
||||
if (pkg == context.packageName && serviceClass == LauncherAccessibilityService::class.java.name) {
|
||||
Log.d("ServiceEnabled", "true")
|
||||
return true
|
||||
}
|
||||
}
|
||||
Log.d("ServiceEnabled", "false")
|
||||
return false
|
||||
val enabledServices = Settings.Secure.getString(
|
||||
context.contentResolver,
|
||||
Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES
|
||||
) ?: return false
|
||||
|
||||
return enabledServices.split(":")
|
||||
.contains("${context.packageName}/${LauncherAccessibilityService::class.java.name}")
|
||||
.also { Log.d(TAG, "Accessibility Service enabled: $it") }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -67,11 +65,7 @@ class LauncherAccessibilityService : AccessibilityService() {
|
|||
getString(R.string.toast_accessibility_service_not_enabled),
|
||||
Toast.LENGTH_LONG
|
||||
).show()
|
||||
startActivity(
|
||||
Intent(android.provider.Settings.ACTION_ACCESSIBILITY_SETTINGS).addFlags(
|
||||
Intent.FLAG_ACTIVITY_NEW_TASK
|
||||
)
|
||||
)
|
||||
requestEnable()
|
||||
return START_NOT_STICKY
|
||||
}
|
||||
|
||||
|
@ -82,6 +76,14 @@ class LauncherAccessibilityService : AccessibilityService() {
|
|||
return super.onStartCommand(intent, flags, startId)
|
||||
}
|
||||
|
||||
private fun requestEnable() {
|
||||
startActivity(
|
||||
Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS).addFlags(
|
||||
Intent.FLAG_ACTIVITY_NEW_TASK
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
private fun handleLockScreen() {
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.P) {
|
||||
Toast.makeText(
|
||||
|
@ -98,7 +100,8 @@ class LauncherAccessibilityService : AccessibilityService() {
|
|||
this,
|
||||
getText(R.string.alert_lock_screen_failed),
|
||||
Toast.LENGTH_LONG
|
||||
).show()
|
||||
).show()
|
||||
requestEnable()
|
||||
}
|
||||
}
|
||||
}
|
|
@ -247,7 +247,7 @@
|
|||
<string name="device_admin_description">Enable the lock screen action</string>
|
||||
<string name="alert_no_torch_found">No camera with torch detected.</string>
|
||||
<string name="alert_torch_access_exception">Error: Can\'t access torch.</string>
|
||||
<string name="alert_lock_screen_failed">Error: Failed to lock screen. (if you just upgraded/reinstalled the app, try to disable and re-enable the accessibility service in phone settings)</string>
|
||||
<string name="alert_lock_screen_failed">Error: Failed to lock screen. (If you just upgraded the app, try to disable and re-enable the accessibility service in phone settings)</string>
|
||||
<string name="toast_accessibility_service_not_enabled">μLauncher\'s accessibility service is not enabled. Please enable it in settings</string>
|
||||
<string name="toast_lock_screen_not_supported">Error: Locking the screen using accessibility is not supported on this device. Please use device admin instead.</string>
|
||||
<string name="accessibility_service_name">µLauncher - lock screen</string>
|
||||
|
|
Loading…
Add table
Reference in a new issue