mirror of
https://github.com/jrpie/Launcher.git
synced 2025-02-23 14:31:30 +01:00
Merge branch 'pr-72'
This commit is contained in:
commit
8ca67103bf
2 changed files with 30 additions and 15 deletions
|
@ -5,6 +5,8 @@ import android.accessibilityservice.AccessibilityServiceInfo
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
|
import android.provider.Settings
|
||||||
|
import android.util.Log
|
||||||
import android.view.accessibility.AccessibilityEvent
|
import android.view.accessibility.AccessibilityEvent
|
||||||
import android.view.accessibility.AccessibilityManager
|
import android.view.accessibility.AccessibilityManager
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
|
@ -21,6 +23,7 @@ class LauncherAccessibilityService : AccessibilityService() {
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
private const val TAG = "Launcher Accessibility"
|
||||||
const val ACTION_LOCK_SCREEN = "ACTION_LOCK_SCREEN"
|
const val ACTION_LOCK_SCREEN = "ACTION_LOCK_SCREEN"
|
||||||
|
|
||||||
fun lockScreen(context: Context) {
|
fun lockScreen(context: Context) {
|
||||||
|
@ -42,15 +45,15 @@ class LauncherAccessibilityService : AccessibilityService() {
|
||||||
}
|
}
|
||||||
|
|
||||||
fun isEnabled(context: Context): Boolean {
|
fun isEnabled(context: Context): Boolean {
|
||||||
val accessibilityManager =
|
val enabledServices = Settings.Secure.getString(
|
||||||
context.getSystemService<AccessibilityManager>() ?: return false
|
context.contentResolver,
|
||||||
val enabledServices =
|
Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES
|
||||||
accessibilityManager.getEnabledAccessibilityServiceList(AccessibilityServiceInfo.FEEDBACK_ALL_MASK)
|
) ?: return false
|
||||||
return enabledServices.any {
|
|
||||||
it.id.startsWith(BuildConfig.APPLICATION_ID)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
return enabledServices.split(":")
|
||||||
|
.contains("${context.packageName}/${LauncherAccessibilityService::class.java.name}")
|
||||||
|
.also { Log.d(TAG, "Accessibility Service enabled: $it") }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -62,11 +65,7 @@ class LauncherAccessibilityService : AccessibilityService() {
|
||||||
getString(R.string.toast_accessibility_service_not_enabled),
|
getString(R.string.toast_accessibility_service_not_enabled),
|
||||||
Toast.LENGTH_LONG
|
Toast.LENGTH_LONG
|
||||||
).show()
|
).show()
|
||||||
startActivity(
|
requestEnable()
|
||||||
Intent(android.provider.Settings.ACTION_ACCESSIBILITY_SETTINGS).addFlags(
|
|
||||||
Intent.FLAG_ACTIVITY_NEW_TASK
|
|
||||||
)
|
|
||||||
)
|
|
||||||
return START_NOT_STICKY
|
return START_NOT_STICKY
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,6 +76,14 @@ class LauncherAccessibilityService : AccessibilityService() {
|
||||||
return super.onStartCommand(intent, flags, startId)
|
return super.onStartCommand(intent, flags, startId)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun requestEnable() {
|
||||||
|
startActivity(
|
||||||
|
Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS).addFlags(
|
||||||
|
Intent.FLAG_ACTIVITY_NEW_TASK
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
private fun handleLockScreen() {
|
private fun handleLockScreen() {
|
||||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.P) {
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.P) {
|
||||||
Toast.makeText(
|
Toast.makeText(
|
||||||
|
@ -87,6 +94,14 @@ class LauncherAccessibilityService : AccessibilityService() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
performGlobalAction(GLOBAL_ACTION_LOCK_SCREEN)
|
val success = performGlobalAction(GLOBAL_ACTION_LOCK_SCREEN)
|
||||||
|
if (!success) {
|
||||||
|
Toast.makeText(
|
||||||
|
this,
|
||||||
|
getText(R.string.alert_lock_screen_failed),
|
||||||
|
Toast.LENGTH_LONG
|
||||||
|
).show()
|
||||||
|
requestEnable()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -248,7 +248,7 @@
|
||||||
<string name="device_admin_description">Enable the lock screen action</string>
|
<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_no_torch_found">No camera with torch detected.</string>
|
||||||
<string name="alert_torch_access_exception">Error: Can\'t access torch.</string>
|
<string name="alert_torch_access_exception">Error: Can\'t access torch.</string>
|
||||||
<string name="alert_lock_screen_failed">Error: Failed to lock screen.</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_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="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>
|
<string name="accessibility_service_name">µLauncher - lock screen</string>
|
||||||
|
|
Loading…
Add table
Reference in a new issue