由于需要适配不同分辨率,一般通过adb shell wm size 和wm demsity命令动态修改, 由于设备原因,无法进入shell,无法修改屏幕尺寸,所有要修改系统默认尺寸。
wm命令执行的是WindowManagerService的方法
public void onRun() throws Exception {
mWm = IWindowManager.Stub.asInterface(ServiceManager.checkService(
Context.WINDOW_SERVICE));
if (mWm == null) {
System.err.println(NO_SYSTEM_ERROR_CODE);
throw new AndroidException("Can't connect to window manager; is the system running?");
}
String op = nextArgRequired();
if (op.equals("size")) {
runDisplaySize();
} else if (op.equals("density")) {
runDisplayDensity();
} else if (op.equals("overscan")) {
runDisplayOverscan();
} else {
showError("Error: unknown command '" + op + "'");
return;
}
}
runDisplaySize() 执行WindowManagerService的setForcedDisplaySize
runDisplayDensity() 执行WindowManagerService的setForcedDisplayDensityForUser
最终会执行
Settings.Global.putString(mService.mContext.getContentResolver(), Settings.Global.DISPLAY_SIZE_FORCED, sizeString);
Settings.Secure.putStringForUser(mService.mContext.getContentResolver(), Settings.Secure.DISPLAY_DENSITY_FORCED, densityString, userId);
由此可知默认大小和密度由Settings.Global.DISPLAY_SIZE_FORCED和Settings.Secure.DISPLAY_DENSITY_FORCED两个值决定,因此修改这两个值得默认值就修改系统默认尺寸