当前位置: 代码迷 >> 综合 >> Adroid M过场动画引出SettingsProvider的整个逻辑
  详细解决方案

Adroid M过场动画引出SettingsProvider的整个逻辑

热度:41   发布时间:2024-01-17 17:01:32.0

一、描述

测试发现点击进入媒体中心,屏幕右侧抖动(明显),在原生设置中关闭过渡动画发现OK
要求framework给关闭关闭过场动画

二、关闭转场动画方法

一开始的思路是:修改原生设置中对应的默认值
这个思路在在Android O上,下面这样修改是OK的

<item name="config_appTransitionAnimationDurationScaleDefault" format="float" type="dimen">0.0</item>

在Android M上,修改DatabaseHelper.java,替换上去不好使,这什么鬼?!

packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java
loadFractionSetting(stmt,Settings.System.TRANSITION_ANIMATION_SCALE,R.fraction.def_window_transition_scale, 0);services/core/java/com/android/server/wm/WindowManagerService.java    
float mTransitionAnimationScaleSetting = 0.0f;

三、SettingsProvider逻辑

只能添加日志看代码逻辑了,中间遇到ftp拷贝文件,而文件md5不一致的现象,需要改用二级制传输
(1)SystemServer启动后,调用ActivityManagerService.installSystemProviders()安装SettingsProvider
(2)走到com.android.providers.settings.SettingsProvider.onCreate()后,创建SettingsRegistry
(3)SettingsRegistry初始化过程中创建migrateAllLegacySettingsIfNeeded(),并把数据库转为xml文件
这个过程中会创建数据库助手SQLiteOpenHelper的具体类DatabaseHelper
(4)执行DatabaseHelper.onCreate()中,会loadSystemSettings、loadGlobalSettings
而transition_animation_scale在system中,后面会迁移到global中

那对应的修改方案在loadSystemSettings、loadGlobalSettings都改了,应该OK了吧
替换上还不好使!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

[13:33:32]01-01 20:02:16.590  1930  1930 E SettingsProvider: loadGlobalSettings 
[13:33:32]01-01 20:02:16.590  1930  1930 E SettingsProvider: java.lang.Exception
[13:33:32]01-01 20:02:16.590  1930  1930 E SettingsProvider:      at com.android.providers.settings.DatabaseHelper.loadGlobalSettings(DatabaseHelper.java:2678)
[13:33:32]01-01 20:02:16.590  1930  1930 E SettingsProvider:      at com.android.providers.settings.DatabaseHelper.loadSettings(DatabaseHelper.java:2409)
[13:33:32]01-01 20:02:16.590  1930  1930 E SettingsProvider:      at com.android.providers.settings.DatabaseHelper.onCreate(DatabaseHelper.java:247)
[13:33:32]01-01 20:02:16.590  1930  1930 E SettingsProvider:      at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:251)
[13:33:32]01-01 20:02:16.590  1930  1930 E SettingsProvider:      at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:163)
[13:33:32]01-01 20:02:16.590  1930  1930 E SettingsProvider:      at com.android.providers.settings.SettingsProvider$SettingsRegistry.migrateAllLegacySettingsIfNeeded(SettingsProvider.java:1559)
[13:33:32]01-01 20:02:16.590  1930  1930 E SettingsProvider:      at com.android.providers.settings.SettingsProvider$SettingsRegistry.<init>(SettingsProvider.java:1385)
[13:33:32]01-01 20:02:16.590  1930  1930 E SettingsProvider:      at com.android.providers.settings.SettingsProvider.onCreate(SettingsProvider.java:218)
[13:33:32]01-01 20:02:16.590  1930  1930 E SettingsProvider:      at android.content.ContentProvider.attachInfo(ContentProvider.java:1748)
[13:33:32]01-01 20:02:16.590  1930  1930 E SettingsProvider:      at android.content.ContentProvider.attachInfo(ContentProvider.java:1723)
[13:33:32]01-01 20:02:16.590  1930  1930 E SettingsProvider:      at android.app.ActivityThread.installProvider(ActivityThread.java:5167)
[13:33:32]01-01 20:02:16.590  1930  1930 E SettingsProvider:      at android.app.ActivityThread.installContentProviders(ActivityThread.java:4762)
[13:33:32]01-01 20:02:16.590  1930  1930 E SettingsProvider:      at android.app.ActivityThread.installSystemProviders(ActivityThread.java:5348)
[13:33:32]01-01 20:02:16.590  1930  1930 E SettingsProvider:      at com.android.server.am.ActivityManagerService.installSystemProviders(ActivityManagerService.java:10409)
[13:33:32]01-01 20:02:16.590  1930  1930 E SettingsProvider:      at com.android.server.SystemServer.startOtherServices(SystemServer.java:515)
[13:33:32]01-01 20:02:16.590  1930  1930 E SettingsProvider:      at com.android.server.SystemServer.run(SystemServer.java:291)
[13:33:32]01-01 20:02:16.590  1930  1930 E SettingsProvider:      at com.android.server.SystemServer.main(SystemServer.java:189)
[13:33:32]01-01 20:02:16.590  1930  1930 E SettingsProvider:      at java.lang.reflect.Method.invoke(Native Method)
[13:33:32]01-01 20:02:16.590  1930  1930 E SettingsProvider:      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:731)
[13:33:32]01-01 20:02:16.590  1930  1930 E SettingsProvider:      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:621)
[13:33:32]01-01 20:02:16.590  1930  1930 E SettingsProvider: loadFractionSetting, key=window_animation_scale, value=0.0, stmt=SQLiteProgram: INSERT OR IGNORE INTO global(name,value) VALUES(?,?);
[13:33:32]01-01 20:02:16.590  1930  1930 E SettingsProvider: loadFractionSetting, key=transition_animation_scale, value=0.0, stmt=SQLiteProgram: INSERT OR IGNORE INTO global(name,value) VALUES(?,?);
[13:33:32]01-01 20:02:16.607  1930  1930 E SettingsProvider: migrateLegacySettingsLocked, name=window_animation_scale, value=0.0
[13:33:32]01-01 20:02:16.607  1930  1930 E SettingsProvider: migrateLegacySettingsLocked, name=transition_animation_scale, value=0.0

四、WindowManagerService逻辑

之前一直怀疑修改的地方不对,根本没往wm上怀疑
算了直接发大招吧,直接在Settings.java加上日志打印看看都谁调用的

[13:27:38]01-01 20:00:21.487  1854  1875 E Settings: putStringForUser
[13:27:38]01-01 20:00:21.487  1854  1875 E Settings: java.lang.Exception
[13:27:38]01-01 20:00:21.487  1854  1875 E Settings:      at android.provider.Settings$Global.putStringForUser(Settings.java:8003)
[13:27:38]01-01 20:00:21.487  1854  1875 E Settings:      at android.provider.Settings$Global.putString(Settings.java:7996)
[13:27:38]01-01 20:00:21.487  1854  1875 E Settings:      at android.provider.Settings$Global.putFloat(Settings.java:8231)
[13:27:38]01-01 20:00:21.487  1854  1875 E Settings:      at com.android.server.wm.WindowManagerService$H.handleMessage(WindowManagerService.java:8261)
[13:27:38]01-01 20:00:21.487  1854  1875 E Settings:      at android.os.Handler.dispatchMessage(Handler.java:102)
[13:27:38]01-01 20:00:21.487  1854  1875 E Settings:      at android.os.Looper.loop(Looper.java:148)
[13:27:38]01-01 20:00:21.487  1854  1875 E Settings:      at android.os.HandlerThread.run(HandlerThread.java:61)
[13:27:38]01-01 20:00:21.487  1854  1875 E Settings:      at com.android.server.ServiceThread.run(ServiceThread.java:46)
[13:27:38]01-01 20:00:21.487  1854  1875 V Settings: Global.putString(name=transition_animation_scale, value=1.0 for 0

finishActivity中会改这个值

01-01 20:04:31.335  1754  2081 E WindowManager: mTransitionAnimationScaleSetting=1.0
01-01 20:04:31.335  1754  2081 E WindowManager: java.lang.Exception
01-01 20:04:31.335  1754  2081 E WindowManager: 	at com.android.server.wm.WindowManagerService.setAnimationScale(WindowManagerService.java:5750)
01-01 20:04:31.335  1754  2081 E WindowManager: 	at com.android.server.am.ActivityStack.destroyActivityLocked(ActivityStack.java:3543)
01-01 20:04:31.335  1754  2081 E WindowManager: 	at com.android.server.am.ActivityStack.finishCurrentActivityLocked(ActivityStack.java:3073)
01-01 20:04:31.335  1754  2081 E WindowManager: 	at com.android.server.am.ActivityStack.finishActivityLocked(ActivityStack.java:3016)
01-01 20:04:31.335  1754  2081 E WindowManager: 	at com.android.server.am.ActivityStack.requestFinishActivityLocked(ActivityStack.java:2832)
01-01 20:04:31.335  1754  2081 E WindowManager: 	at com.android.server.am.ActivityManagerService.finishActivity(ActivityManagerService.java:4412)
01-01 20:04:31.335  1754  2081 E WindowManager: 	at android.app.ActivityManagerNative.onTransact(ActivityManagerNative.java:350)
01-01 20:04:31.335  1754  2081 E WindowManager: 	at com.android.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:2526)
01-01 20:04:31.335  1754  2081 E WindowManager: 	at android.os.Binder.execTransact(Binder.java:453)

systemReady也会这个值

[16:42:17]01-01 20:00:10.287  1770  1770 W WindowManager: turn off transition_animation_scale if in user mode
[16:42:17]01-01 20:00:10.288  1770  1770 E WindowManager: mTransitionAnimationScaleSetting=1.0
[16:42:17]01-01 20:00:10.288  1770  1770 E WindowManager: java.lang.Exception
[16:42:17]01-01 20:00:10.288  1770  1770 E WindowManager:         at com.android.server.wm.WindowManagerService.setAnimationScale(WindowManagerService.java:5750)
[16:42:17]01-01 20:00:10.288  1770  1770 E WindowManager:         at com.android.server.wm.WindowManagerService.systemReady(WindowManagerService.java:7943)
[16:42:17]01-01 20:00:10.288  1770  1770 E WindowManager:         at com.android.server.SystemServer.startOtherServices(SystemServer.java:1140)
[16:42:17]01-01 20:00:10.288  1770  1770 E WindowManager:         at com.android.server.SystemServer.run(SystemServer.java:291)
[16:42:17]01-01 20:00:10.288  1770  1770 E WindowManager:         at com.android.server.SystemServer.main(SystemServer.java:189)
[16:42:17]01-01 20:00:10.288  1770  1770 E WindowManager:         at java.lang.reflect.Method.invoke(Native Method)
[16:42:17]01-01 20:00:10.288  1770  1770 E WindowManager:         at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:731)
[16:42:17]01-01 20:00:10.288  1770  1770 E WindowManager:         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:621)

发现我改的是对的,但是每次等屏亮后就被改了,或者待机开机又被改了
找打这个地方就知道怎么修改了,但是我的两天假期谁赔给我。。。。。。。。。。。。。。。。。。。。。。。。
心中一万只草泥马在奔腾

五、参考

https://blog.csdn.net/zhoumushui/article/details/51684984