问题分析:
在Android11版本的机器上打印堆栈,关闭屏幕旋转后横屏手机会进行如下调用
//在NavigationBar上显示屏幕旋转按钮 04-25 13:24:22.558 17140 17140 D weihang2: setVisibility: java.lang.Throwable 04-25 13:24:22.558 17140 17140 D weihang2: at com.android.systemui.statusbar.phone.RotationContextButton.setVisibility(RotationContextButton.java:49) 04-25 13:24:22.558 17140 17140 D weihang2: at com.android.systemui.statusbar.phone.ContextualButtonGroup$ButtonData.setVisibility(ContextualButtonGroup.java:158) 04-25 13:24:22.558 17140 17140 D weihang2: at com.android.systemui.statusbar.phone.ContextualButtonGroup.setButtonVisibility(ContextualButtonGroup.java:89) 04-25 13:24:22.558 17140 17140 D weihang2: at com.android.systemui.statusbar.phone.ContextualButton.show(ContextualButton.java:95) 04-25 13:24:22.558 17140 17140 D weihang2: at com.android.systemui.statusbar.phone.RotationButtonController.setRotateSuggestionButtonState(RotationButtonController.java:223) 04-25 13:24:22.558 17140 17140 D weihang2: at com.android.systemui.statusbar.phone.RotationButtonController.setRotateSuggestionButtonState(RotationButtonController.java:183) 04-25 13:24:22.558 17140 17140 D weihang2: at com.android.systemui.statusbar.phone.RotationButtonController.showAndLogRotationSuggestion(RotationButtonController.java:348) 04-25 13:24:22.558 17140 17140 D weihang2: at com.android.systemui.statusbar.phone.RotationButtonController.onRotationProposal(RotationButtonController.java:292) 04-25 13:24:22.558 17140 17140 D weihang2: at com.android.systemui.statusbar.phone.NavigationBarFragment.onRotationProposal(NavigationBarFragment.java:795) 04-25 13:24:22.558 17140 17140 D weihang2: at com.android.systemui.statusbar.CommandQueue$H.handleMessage(CommandQueue.java:1157) 04-25 13:24:22.558 17140 17140 D weihang2: at android.os.Handler.dispatchMessage(Handler.java:106) 04-25 13:24:22.558 17140 17140 D weihang2: at android.os.Looper.loop(Looper.java:223) 04-25 13:24:22.558 17140 17140 D weihang2: at android.app.ActivityThread.main(ActivityThread.java:7848) 04-25 13:24:22.558 17140 17140 D weihang2: at java.lang.reflect.Method.invoke(Native Method) 04-25 13:24:22.558 17140 17140 D weihang2: at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:612) 04-25 13:24:22.558 17140 17140 D weihang2: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:997) 04-25 13:24:22.558 17140 17140 D weihang2: setVisibility: visibility = 0 //动画结束后,旋转按钮消失 04-25 13:24:27.678 17140 17140 D weihang2: setVisibility: java.lang.Throwable 04-25 13:24:27.678 17140 17140 D weihang2: at com.android.systemui.statusbar.phone.RotationContextButton.setVisibility(RotationContextButton.java:49) 04-25 13:24:27.678 17140 17140 D weihang2: at com.android.systemui.statusbar.phone.ContextualButtonGroup$ButtonData.setVisibility(ContextualButtonGroup.java:158) 04-25 13:24:27.678 17140 17140 D weihang2: at com.android.systemui.statusbar.phone.ContextualButtonGroup.setButtonVisibility(ContextualButtonGroup.java:93) 04-25 13:24:27.678 17140 17140 D weihang2: at com.android.systemui.statusbar.phone.ContextualButton.hide(ContextualButton.java:107) 04-25 13:24:27.678 17140 17140 D weihang2: at com.android.systemui.statusbar.phone.RotationButtonController$2.onAnimationEnd(RotationButtonController.java:245) 04-25 13:24:27.678 17140 17140 D weihang2: at android.animation.Animator$AnimatorListener.onAnimationEnd(Animator.java:554) 04-25 13:24:27.678 17140 17140 D weihang2: at android.animation.ValueAnimator.endAnimation(ValueAnimator.java:1250) 04-25 13:24:27.678 17140 17140 D weihang2: at android.animation.ValueAnimator.doAnimationframe(ValueAnimator.java:1492) 04-25 13:24:27.678 17140 17140 D weihang2: at android.animation.AnimationHandler.doAnimationframe(AnimationHandler.java:146) 04-25 13:24:27.678 17140 17140 D weihang2: at android.animation.AnimationHandler.access$100(AnimationHandler.java:37) 04-25 13:24:27.678 17140 17140 D weihang2: at android.animation.AnimationHandler$1.doframe(AnimationHandler.java:54) 04-25 13:24:27.678 17140 17140 D weihang2: at android.view.Choreographer$CallbackRecord.run(Choreographer.java:972) 04-25 13:24:27.678 17140 17140 D weihang2: at android.view.Choreographer.doCallbacks(Choreographer.java:797) 04-25 13:24:27.678 17140 17140 D weihang2: at android.view.Choreographer.doframe(Choreographer.java:728) 04-25 13:24:27.678 17140 17140 D weihang2: at android.view.Choreographer$frameDisplayEventReceiver.run(Choreographer.java:959) 04-25 13:24:27.678 17140 17140 D weihang2: at android.os.Handler.handleCallback(Handler.java:938) 04-25 13:24:27.678 17140 17140 D weihang2: at android.os.Handler.dispatchMessage(Handler.java:99) 04-25 13:24:27.678 17140 17140 D weihang2: at android.os.Looper.loop(Looper.java:223) 04-25 13:24:27.678 17140 17140 D weihang2: at android.app.ActivityThread.main(ActivityThread.java:7848) 04-25 13:24:27.678 17140 17140 D weihang2: at java.lang.reflect.Method.invoke(Native Method) 04-25 13:24:27.678 17140 17140 D weihang2: at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:612) 04-25 13:24:27.678 17140 17140 D weihang2: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:997) 04-25 13:24:27.678 17140 17140 D weihang2: setVisibility: visibility = 4
在Android GO机器上添加相同的log,关闭屏幕旋转在手机横屏时无任何log打印
由此可见OrientationListener并未往下调用
而控制OrientationListener disable或enable的参数在DisplayRotation.java中
//frameworks/base/services/core/java/com/android/server/wm/DisplayRotation.java int showRotationSuggestions = ActivityManager.isLowRamDeviceStatic() ? Settings.Secure.SHOW_ROTATION_SUGGESTIONS_DISABLED : Settings.Secure.getIntForUser(resolver, Settings.Secure.SHOW_ROTATION_SUGGESTIONS, Settings.Secure.SHOW_ROTATION_SUGGESTIONS_DEFAULT, UserHandle.USER_CURRENT);
在该位置会判断设备是否为低内存设备,如果是低内存设备则
showRotationSuggestions = Settings.Secure.SHOW_ROTATION_SUGGESTIONS_DISABLED
因此,在Android Go当中不会显示屏幕旋转按钮
该现象可以进行修改,并且修改后功能正常
但是,单独打开某几个go版本限制功能,是不会有太大问题的,只是随着打开的限制越多,逐渐积累可能会出现内存不足问题。



