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

默认开机横屏

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

实现原理:系统自动旋转其实是修改的是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() {

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

相关推荐
Libraeking10 小时前
破壁行动:在旧项目中丝滑嵌入 Compose(混合开发实战)
android·经验分享·android jetpack
市场部需要一个软件开发岗位10 小时前
JAVA开发常见安全问题:Cookie 中明文存储用户名、密码
android·java·安全
JMchen12312 小时前
Android后台服务与网络保活:WorkManager的实战应用
android·java·网络·kotlin·php·android-studio
crmscs13 小时前
剪映永久解锁版/电脑版永久会员VIP/安卓SVIP手机永久版下载
android·智能手机·电脑
localbob13 小时前
杀戮尖塔 v6 MOD整合版(Slay the Spire)安卓+PC端免安装中文版分享 卡牌肉鸽神作!杀戮尖塔中文版,电脑和手机都能玩!杀戮尖塔.exe 杀戮尖塔.apk
android·杀戮尖塔apk·杀戮尖塔exe·游戏分享
机建狂魔13 小时前
手机秒变电影机:Blackmagic Camera + LUT滤镜包的专业级视频解决方案
android·拍照·摄影·lut滤镜·拍摄·摄像·录像
hudawei99613 小时前
flutter和Android动画的对比
android·flutter·动画
lxysbly15 小时前
md模拟器安卓版带金手指2026
android
儿歌八万首15 小时前
硬核春节:用 Compose 打造“赛博鞭炮”
android·kotlin·compose·春节
消失的旧时光-194318 小时前
从 Kotlin 到 Dart:为什么 sealed 是处理「多种返回结果」的最佳方式?
android·开发语言·flutter·架构·kotlin·sealed