Last active
July 27, 2023 21:52
-
-
Save anibalbastiass/c34b0551f38b86e151f2d0d24d721cf5 to your computer and use it in GitHub Desktop.
[Android] Force enable Animation using Accessibiity Service
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<accessibility-service | |
xmlns:android="http://schemas.android.com/apk/res/android" | |
android:accessibilityEventTypes="typeAllMask" | |
android:accessibilityFeedbackType="feedbackAllMask" | |
android:accessibilityFlags="flagDefault" | |
android:canRequestEnhancedWebAccessibility="true" | |
android:canRequestTouchExplorationMode="true" | |
android:canRetrieveWindowContent="true" | |
android:notificationTimeout="100" | |
android:packageNames="@null" | |
/> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<service | |
android:name=".ui.home.GCAccessibilityService" | |
android:exported="false" | |
android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE" | |
> | |
<intent-filter> | |
<action android:name="android.accessibilityservice.AccessibilityService" /> | |
</intent-filter> | |
<meta-data | |
android:name="android.accessibilityservice" | |
android:resource="@xml/accessibility_service_config" /> | |
</service> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* The app needs to be added as Accessibility app in Android 13+ | |
*/ | |
class GCAccessibilityService : AccessibilityService() { | |
companion object { | |
fun startIntent(ctx: Context) = | |
ctx.intentFor<RadioService>() | |
} | |
override fun onCreate() { | |
super.onCreate() | |
Log.d("ABSSS", "onCreate") | |
} | |
override fun onAccessibilityEvent(event: AccessibilityEvent) { | |
Log.d("ABSSS", "onAccessibilityEvent: event=$event") | |
event.source?.apply { | |
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { | |
Log.d("ABSSS", "setAnimationScale 1f") | |
// Force enable animation if this is disabled | |
// contentResolver must become from Activity | |
val animator = Settings.Global.getFloat(contentResolver, Settings.Global.ANIMATOR_DURATION_SCALE) | |
// Also, this can be overrided in SharedPreferences in a future | |
if (animator == 0f) | |
setAnimationScale(1f) | |
} else { | |
Log.d("ABSSS", "setAnimationScale No Changes") | |
} | |
} | |
} | |
override fun onInterrupt() { | |
Log.d("ABSSS","Accessibility Interrupted") | |
} | |
override fun onDestroy() { | |
super.onDestroy() | |
Log.d("ABSSS","Service Destroyed"); | |
} | |
override fun onServiceConnected() { | |
println("onServiceConnected") | |
Log.d("ABSSS","Service Connected") | |
val info = AccessibilityServiceInfo() | |
info.eventTypes = AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED | |
info.eventTypes = AccessibilityEvent.TYPES_ALL_MASK | |
info.feedbackType = AccessibilityServiceInfo.FEEDBACK_ALL_MASK | |
info.notificationTimeout = 100 | |
info.packageNames = null | |
serviceInfo = info | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
override fun onResume() { | |
super.onResume() | |
startService(GCAccessibilityService.startIntent(this)) | |
} | |
override fun onDestroy() { | |
stopService(this.intentFor<GCAccessibilityService>()) | |
super.onDestroy() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment