默认开机横屏
很多老人机和平板都有默认系统默认开机横屏的需求,但是网上修改大多都比较麻烦且固定死了一个方向,本文将介绍一种较为简单的实现方式(这种方式不影响开机动画)。
实现原理:系统自动旋转其实是修改的是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() {
至此,开机默认横屏简单方法介绍完毕!如有不清楚的可留言