默认开机横屏(全网最简单,不影响重力传感器)

默认开机横屏

很多老人机和平板都有默认系统默认开机横屏的需求,但是网上修改大多都比较麻烦且固定死了一个方向,本文将介绍一种较为简单的实现方式(这种方式不影响开机动画)。

实现原理:系统自动旋转其实是修改的是Settings.System.USER_ROTATION这个值,我们只要在系统启动时将这个值修改为我们需要角度即可,接下来将介绍在Android7和Android9的实现方式。

Android7实现方式:

将自动旋转默认关闭

frameworks/base/packages/SettingsProvider/res/values/defaults.xml

复制代码
-    <bool name="def_accelerometer_rotation">true</bool>
+    <bool name="def_accelerometer_rotation">false</bool>

-    <integer name="def_user_rotation">0</integer>
+    <integer name="def_user_rotation">90</integer>

默认角度修改为自己需要

frameworks/base/services/core/java/com/android/server/am/ActivityManagerService.java

复制代码
import com.mediatek.multiwindow.MultiWindowManager;
-
+import android.view.Surface;
 public final class ActivityManagerService extends ActivityManagerNative
         implements Watchdog.Monitor, BatteryStatsImpl.BatteryCallback {
 
@@ -4122,6 +4122,7 @@ public final class ActivityManagerService extends ActivityManagerNative
             // error message and don't try to start anything.
             return false;
         }
+               Settings.System.putInt(mContext.getContentResolver(), Settings.System.USER_ROTATION, Surface.ROTATION_90);
         Intent intent = getHomeIntent();
         ActivityInfo aInfo = resolveActivityInfo(intent, STOCK_PM_FLAGS, userId);
         if (aInfo != null) {

将Launcher设置为默认允许旋转

packages/apps/Launcher3/src/com/android/launcher3/Utilities.java

复制代码
@ -143,16 +143,16 @@ public final class Utilities {
     }
 
     public static boolean isAllowRotationPrefEnabled(Context context) {
-        boolean allowRotationPref = false;
-        if (ATLEAST_N) {
-            // If the device was scaled, used the original dimensions to determine if rotation
-            // is allowed of not.
-            int originalDensity = DisplayMetrics.DENSITY_DEVICE_STABLE;
-            Resources res = context.getResources();
-            int originalSmallestWidth = res.getConfiguration().smallestScreenWidthDp
-                    * res.getDisplayMetrics().densityDpi / originalDensity;
-            allowRotationPref = originalSmallestWidth >= 600;
-        }
+        boolean allowRotationPref = true;
+        // if (ATLEAST_N) {
+        //     // If the device was scaled, used the original dimensions to determine if rotation
+        //     // is allowed of not.
+        //     int originalDensity = DisplayMetrics.DENSITY_DEVICE_STABLE;
+        //     Resources res = context.getResources();
+        //     int originalSmallestWidth = res.getConfiguration().smallestScreenWidthDp
+        //             * res.getDisplayMetrics().densityDpi / originalDensity;
+        //     allowRotationPref = originalSmallestWidth >= 600;
+        // }
         return getPrefs(context).getBoolean(ALLOW_ROTATION_PREFERENCE_KEY, allowRotationPref);
     }

锁屏允许旋转

frameworks/base/core/res/res/values/config.xml

复制代码
-    <bool name="config_enableLockScreenRotation">false</bool>
+    <bool name="config_enableLockScreenRotation">true</bool>

Android9实现方式:

开机修改为自己要的角度

frameworks/base/services/core/java/com/android/server/am/ActivityManagerService.java

复制代码
import com.android.server.vr.VrManagerInternal;
 import com.android.server.wm.PinnedStackWindowController;
 import com.android.server.wm.WindowManagerService;
-
+import android.view.Surface;
 /// M: MTK AmsExt
 import com.mediatek.server.am.AmsExt;
 
@@ -4751,6 +4751,9 @@ public class ActivityManagerService extends IActivityManager.Stub
             // error message and don't try to start anything.
             return false;
         }
+               
+               Settings.System.putInt(mContext.getContentResolver(), Settings.System.USER_ROTATION, Surface.ROTATION_90);
+               
         Intent intent = getHomeIntent();
         ActivityInfo aInfo = resolveActivityInfo(intent, STOCK_PM_FLAGS, userId);
         if (aInfo != null) {

Launcher默认可旋转

复制代码
index e866445..ff4b560 100644
--- a/ap/vendor/mediatek/proprietary/packages/apps/Launcher3/src/com/android/launcher3/states/RotationHelper.java
+++ b/ap/vendor/mediatek/proprietary/packages/apps/Launcher3/src/com/android/launcher3/states/RotationHelper.java
@@ -38,15 +38,15 @@ public class RotationHelper implements OnSharedPreferenceChangeListener {
     public static final String ALLOW_ROTATION_PREFERENCE_KEY = "pref_allowRotation";
 
     public static boolean getAllowRotationDefaultValue() {
-        if (ATLEAST_NOUGAT) {
-            // If the device was scaled, used the original dimensions to determine if rotation
-            // is allowed of not.
-            Resources res = Resources.getSystem();
-            int originalSmallestWidth = res.getConfiguration().smallestScreenWidthDp
-                    * res.getDisplayMetrics().densityDpi / DENSITY_DEVICE_STABLE;
-            return originalSmallestWidth >= 600;
-        }
-        return false;
+        // if (ATLEAST_NOUGAT) {
+        //     // If the device was scaled, used the original dimensions to determine if rotation
+        //     // is allowed of not.
+        //     Resources res = Resources.getSystem();
+        //     int originalSmallestWidth = res.getConfiguration().smallestScreenWidthDp
+        //             * res.getDisplayMetrics().densityDpi / DENSITY_DEVICE_STABLE;
+        //     return originalSmallestWidth >= 600;
+        // }
+        return true;
     }

默认关闭自动自动旋转、修改默认角度

复制代码
--- a/ap/vendor/mediatek/proprietary/packages/apps/SettingsProvider/res/values/defaults.xml
+++ b/ap/vendor/mediatek/proprietary/packages/apps/SettingsProvider/res/values/defaults.xml
@@ -86,7 +86,7 @@
     <integer name="def_max_sound_trigger_detection_service_ops_per_day" translatable="false">1000</integer>
     <integer name="def_sound_trigger_detection_service_op_timeout" translatable="false">15000</integer>
 
-    <bool name="def_lockscreen_disabled">false</bool>
+    <bool name="def_lockscreen_disabled">true</bool>
     <bool name="def_device_provisioned">false</bool>
     <integer name="def_dock_audio_media_enabled">1</integer>
 
@@ -115,7 +115,7 @@
     <bool name="def_accessibility_display_magnification_auto_update">true</bool>
 
     <!-- Default for Settings.System.USER_ROTATION -->
-    <integer name="def_user_rotation">0</integer>
+    <integer name="def_user_rotation">90</integer>
 
     <!-- Default for Settings.Secure.DOWNLOAD_MAX_BYTES_OVER_MOBILE. <=0 if no limit -->

每次关机都会被SystemUI改掉,所以需要添加以下修改

复制代码
diff --git a/ap/vendor/mediatek/proprietary/packages/apps/SystemUI/src/com/android/systemui/statusbar/policy/RotationLockControllerImpl.java b/ap/vendor/mediatek/proprietary/packa
ges/apps/SystemUI/src/com/android/systemui/statusbar/policy/RotationLockControllerImpl.java
old mode 100644
new mode 100755
index 5418dc1..7c87e51
--- a/ap/vendor/mediatek/proprietary/packages/apps/SystemUI/src/com/android/systemui/statusbar/policy/RotationLockControllerImpl.java
+++ b/ap/vendor/mediatek/proprietary/packages/apps/SystemUI/src/com/android/systemui/statusbar/policy/RotationLockControllerImpl.java
@@ -64,7 +64,7 @@ public final class RotationLockControllerImpl implements RotationLockController
     }
 
     public void setRotationLockedAtAngle(boolean locked, int rotation){
-        RotationPolicy.setRotationLockAtAngle(mContext, locked, rotation);
+        RotationPolicy.setRotationLockAtAngle(mContext, locked, 1);
     }
 
     public boolean isRotationLockAffordanceVisible() {

至此,开机默认横屏简单方法介绍完毕!如有不清楚的可留言

相关推荐
三少爷的鞋12 分钟前
Retrofit 核心流程模拟实现深解析
android
zhimingwen12 分钟前
使用 adb shell 命令检查手机上 App的APK大小
android·adb
泥嚎泥嚎16 分钟前
【Android】RecyclerView 刷新方式全解析:从 notifyDataSetChanged 到 DiffUtil
android·java
用户693717500138416 分钟前
23.Kotlin 继承:继承的细节:覆盖方法与属性
android·后端·kotlin
Haha_bj20 分钟前
五、Kotlin——条件控制、循环控制
android·kotlin
弥巷22 分钟前
【Android】深入理解Window和WindowManager
android·java
AllBlue25 分钟前
安卓调用unity中的方法
android·unity·游戏引擎
zhimingwen1 小时前
通过ADB获取Android应用的SHA1签名
android·adb
2501_916007471 小时前
深入理解 iOS 文件管理体系,从沙盒结构到多工具协同的工程化文件管理实践
android·ios·小程序·https·uni-app·iphone·webview
00后程序员张1 小时前
iOS 性能检测工具深度解析 多工具协同下的全维度性能检测体系建设
android·ios·小程序·https·uni-app·iphone·webview