客户要求系统实现动态hdmi-4K与普通分辨率直接热切换,先在菜单中做个试验,设置中加个切换开关,点击开关就可以直接切到hdmi-4K,这个功能实现后可以通过插拔hdmi那个状态(sys/class/drm/card0-HDMI-A-1/status)直接实现切换,测试代码也很简单,方法如下:文章来源地址https://www.toymoban.com/news/detail-813455.html
Index: packages/apps/Settings/src/com/android/settings/display/HdmiSettings.java
===================================================================
--- packages/apps/Settings/src/com/android/settings/display/HdmiSettings.java (revision 907)
+++ packages/apps/Settings/src/com/android/settings/display/HdmiSettings.java (working copy)
@@ -27,6 +27,7 @@
import androidx.preference.SwitchPreference;
import androidx.preference.PreferenceCategory;
import androidx.preference.PreferenceScreen;
+import androidx.preference.SwitchPreference;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.settings.HdmiListPreference;
@@ -39,6 +40,8 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import android.os.SystemProperties;
+import java.io.*;
import static com.android.settings.display.DrmDisplaySetting.DPY_STATUS_CONNECTED;
@@ -53,6 +56,7 @@
private static final String KEY_PRE_CATE = "Display";
private static final String KEY_PRE_RESOLUTION = "Resolution";
private static final String KEY_PRE_SCREEN_SCALE = "ScreenScale";
+ private static final String KEY_PRE_HDMI_4K = "HDMIswitch4K";
private static final String KEY_AUX_CATEGORY = "aux_category";
private static final String KEY_AUX_SCREEN_VH = "aux_screen_vh";
private static final String KEY_AUX_SCREEN_VH_LIST = "aux_screen_vhlist";
@@ -87,6 +91,7 @@
private PreferenceCategory mAuxCategory;
private CheckBoxPreference mAuxScreenVH;
private ListPreference mAuxScreenVHList;
+ private SwitchPreference hdmi4kPreference;
private Context mContext;
private DisplayInfo mSelectDisplayInfo;
private DisplayManager mDisplayManager;
@@ -114,6 +119,10 @@
if (mDestory && MSG_SWITCH_DEVICE_STATUS != msg.what) {
return;
}
+
+ Log.d(TAG, "fan msg.what ="+msg.what);
+
+ Log.d(TAG, "fan switch control ="+(ITEM_CONTROL) msg.obj);
if (MSG_UPDATE_STATUS == msg.what) {
final ITEM_CONTROL control = (ITEM_CONTROL) msg.obj;
new Thread() {
@@ -177,6 +186,7 @@
if (SWITCH_STATUS_OFF_ON == msg.arg1) {
sendSwitchDeviceOffOnMsg(control, SWITCH_STATUS_ON);
} else {
+ Log.d(TAG, "fan control ="+control);
sendUpdateStateMsg(control, 2000);
}
}
@@ -379,6 +389,7 @@
scalePreference.setOnPreferenceClickListener(this);
category.addPreference(scalePreference);
category.setEnabled(false);
+
DisplayInfo displayInfo = new DisplayInfo();
displayInfo.setDisplayNo(display);
mDisplayInfoList.put(display, displayInfo);
@@ -394,6 +405,13 @@
mAuxScreenVHList.setOnPreferenceChangeListener(this);
mAuxScreenVHList.setOnPreferenceClickListener(this);
mAuxCategory.removePreference(mAuxScreenVHList);
+ //add hdmi4kPreference
+
+ hdmi4kPreference = (SwitchPreference) findPreference(KEY_PRE_HDMI_4K);
+ hdmi4kPreference.setChecked(SystemProperties.getBoolean("persist.sys.hdmi4k", false));
+ hdmi4kPreference.setOnPreferenceChangeListener(this);
+
+
}
private void sendSwitchDeviceOffOnMsg(ITEM_CONTROL control, int status) {
@@ -583,6 +601,7 @@
cate.setEnabled(false);
}
} else if (key.startsWith(KEY_PRE_RESOLUTION)) {
+ Log.i("fan","key.replace="+key.replace(KEY_PRE_SCREEN_SCALE, ""));
for (Map.Entry<Integer, DisplayInfo> entry : mDisplayInfoList.entrySet()) {
int display = Integer.parseInt(key.replace(KEY_PRE_RESOLUTION, ""));
if (display == entry.getKey()) {
@@ -597,6 +616,23 @@
}
return true;
}
+ public static void exe_cmd(String cmd){
+
+ Process process2 = null;
+ DataOutputStream dos = null;
+ try{
+ process2 = Runtime.getRuntime().exec("su");
+ dos = new DataOutputStream(process2.getOutputStream());
+ dos.writeBytes(cmd);
+ dos.flush();
+ dos.close();
+ }
+ catch (Exception e) {
+
+ e.printStackTrace();
+ }
+
+ }
@Override
public boolean onPreferenceChange(Preference preference, Object obj) {
@@ -662,6 +698,30 @@
//mDisplayManager.forceScheduleTraversalLocked();
sendSwitchDeviceOffOnMsg(ITEM_CONTROL.REFRESH_DISPLAY_STATUS_INFO, SWITCH_STATUS_OFF_ON);
}
+
+ else if(preference == hdmi4kPreference){
+ for (Map.Entry<Integer, DisplayInfo> entry : mDisplayInfoList.entrySet()) {
+ // int display = Integer.parseInt(key.replace(KEY_PRE_RESOLUTION, ""));
+ if (0 == entry.getKey()) {
+ mSelectDisplayInfo = entry.getValue();
+ }
+ }
+ if (obj == Boolean.TRUE)
+ {
+ Log.d(TAG, "hdmi 4k is select") ;
+ exe_cmd("setprop persist.vendor.resolution.aux 3840x2160@60");
+ // exe_cmd("setprop persist.vendor.resolution.aux 1920x1080@60");
+ exe_cmd("setprop vendor.display.timeline 1");
+ exe_cmd("setprop persist.sys.hdmi4k true");
+ }
+ else{
+
+ Log.d(TAG, "hdmi 4k is close" );
+ exe_cmd("setprop persist.vendor.resolution.aux 720x480@59.94-736-798-858-489-495-525-a");
+ exe_cmd("setprop vendor.display.timeline 1");
+ exe_cmd("setprop persist.sys.hdmi4k false");
+ }
+ }
return true;
}
文章来源:https://www.toymoban.com/news/detail-813455.html
到了这里,关于安卓11菜单实现hdmi-4K动态切换的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!