设置–显示–显示大小调节
packages/apps/Settings/src/com/android/settings/display/ScreenZoomSettings.java +48
*/
public class ScreenZoomSettings extends PreviewSeekBarPreferenceFragment implements Indexable {
private int mDefaultDensity;
private int[] mValues;
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mActivityLayoutResId = R.layout.screen_zoom_activity;
// This should be replaced once the final preview sample screen is in place.
mPreviewSampleResIds = new int[]{R.layout.screen_zoom_preview_1,
R.layout.screen_zoom_preview_2,
R.layout.screen_zoom_preview_settings};
final DisplayDensityUtils density = new DisplayDensityUtils(getContext());
final int initialIndex = density.getCurrentIndex(); 这里打印实际的值,把该值写进framework默认
if (initialIndex < 0) {
// Failed to obtain default density, which means we failed to
// connect to the window manager service. Just use the current
// density and don't let the user change anything.
final int densityDpi = getResources().getDisplayMetrics().densityDpi;
mValues = new int[] { densityDpi };
frameworks/base/packages/SettingsLib/src/com/android/settingslib/display/DisplayDensityUtils.java +240
public static void setForcedDisplayDensity(final int displayId, final int density) {
final int userId = UserHandle.myUserId();
AsyncTask.execute(() -> {
try {
final IWindowManager wm = WindowManagerGlobal.getWindowManagerService();
wm.setForcedDisplayDensityForUser(displayId, density, userId);
} catch (RemoteException exc) {
Log.w(LOG_TAG, “Unable to save forced display density setting”);
}
});
}
}
frameworks/base/services/core/java/com/android/server/wm/WindowManagerService.java +9870
@Override
public void setForcedDisplayDensityForUser(int displayId, int density, int userId) {
if (mContext.checkCallingOrSelfPermission(
android.Manifest.permission.WRITE_SECURE_SETTINGS) !=
PackageManager.PERMISSION_GRANTED) {
throw new SecurityException("Must hold permission " +
android.Manifest.permission.WRITE_SECURE_SETTINGS);
}
if (displayId != Display.DEFAULT_DISPLAY) {
throw new IllegalArgumentException(“Can only set the default display”);
}
final int targetUserId = ActivityManager.handleIncomingUser(Binder.getCallingPid(),
Binder.getCallingUid(), userId, false, true, "setForcedDisplayDensityForUser",
null);
final long ident = Binder.clearCallingIdentity();
try {
synchronized(mWindowMap) {
final DisplayContent displayContent = getDisplayContentLocked(displayId);
if (displayContent != null && mCurrentUserId == targetUserId) {
setForcedDisplayDensityLocked(displayContent, density);
}
Settings.Secure.putStringForUser(mContext.getContentResolver(),
Settings.Secure.DISPLAY_DENSITY_FORCED,
Integer.toString(density), targetUserId);
}
} finally {
Binder.restoreCallingIdentity(ident);
}
}
Index: frameworks/base/services/core/java/com/android/server/wm/WindowManagerService.java
===================================================================
--- frameworks/base/services/core/java/com/android/server/wm/WindowManagerService.java (revision 311)
+++ frameworks/base/services/core/java/com/android/server/wm/WindowManagerService.java (working copy)
@@ -7433,6 +7433,7 @@
+ " from " + mRotation + (mAltOrientation ? " (alt)" : "")
+ ", lastOrientation=" + mLastOrientation);
}
+ rotation = Surface.ROTATION_0;
mRotation = rotation;
mAltOrientation = altOrientation;
@@ -9935,16 +9936,17 @@
private int getForcedDisplayDensityForUserLocked(int userId) {
String densityStr = Settings.Secure.getStringForUser(mContext.getContentResolver(),
Settings.Secure.DISPLAY_DENSITY_FORCED, userId);
+ Log.i("fan","get DISPLAY_DENSITY_FORCED="+densityStr);
if (densityStr == null || densityStr.length() == 0) {
densityStr = SystemProperties.get(DENSITY_OVERRIDE, null);
}
if (densityStr != null && densityStr.length() > 0) {
try {
- return Integer.parseInt(densityStr);
+ return 212;//Integer.parseInt(densityStr); 默认
} catch (NumberFormatException ex) {
}
}
- return 0;
+ return 212; 默认
}