android4.0 系统层hdmi开关

1. 实现关闭hdmi功能。
a. 在状态栏增加一下按键。
 base/packages/SystemUI/res/layout-sw600dp/status_bar.xml
+ 

b. 添加状态栏按键activity的监听事件
base/packages/SystemUI/src/com/android/systemui/statusbar/tablet/TabletStatusBar.java

 import android.os.Handler;
+import android.os.SystemProperties;
+import android.os.SystemClock;

     private int mMaxNotificationIcons = 5;
+ // cjcheng add for hdmi turn off, 2-> off, 1 -> on
+ private static final String HDMI_STATUS = "persist.sys.output_mode";

     View mMenuButton;
+ View mPowerButton; // cjcheng add for hdmi off

         mHomeButton = mNavigationArea.findViewById(R.id.home);
         mMenuButton = mNavigationArea.findViewById(R.id.menu);
+ /* cjcheng add for hdmi off start */
+ mPowerButton = mNavigationArea.findViewById(R.id.power);
+ mPowerButton.setOnClickListener(mOnClickListener);
+ /* cjcheng add for hdmi off end */

    private View.OnClickListener mOnClickListener = new View.OnClickListener() {
        public void onClick(View v) {
            if (v == mRecentButton) {
                onClickRecentButton();
            } else if (v == mInputMethodSwitchButton) {
                onClickInputMethodSwitchButton();
            } else if (v == mCompatModeButton) {
                onClickCompatModeButton();
            }
            /* cjcheng add for hdmi off start */
+ else if (v == mPowerButton){
+ if (!("2".equals(SystemProperties.get(HDMI_STATUS, "0")))){
+ SystemClock.sleep(500);
+ SystemProperties.set(HDMI_STATUS, "2");
+ SystemClock.sleep(500);
+ }
+ }
            /* cjcheng add for hdmi off end */
        }
    };

2. USB鼠标和键盘唤醒HDMI
base/services/input/InputReader.cpp
 #include 
+#include 

 namespace android {

+/* cjcheng add for hdmi on start */
+void hdmi_power_on(void)
+{
+ char hdmi_status[4];
+ property_get("persist.sys.output_mode", hdmi_status, NULL);
+ if (strcmp(hdmi_status, "2") == 0)
+ property_set("persist.sys.output_mode", "1");
+}
+/* cjcheng add for hdmi on start */
+

// USB鼠标按键唤醒HDMI
void CursorButtonAccumulator::process(const RawEvent* rawEvent) {
    if (rawEvent->type == EV_KEY) {
        switch (rawEvent->scanCode) {
        case BTN_LEFT:
            mBtnLeft = rawEvent->value;
            break;
        case BTN_RIGHT:
            mBtnRight = rawEvent->value;
            break;
        case BTN_MIDDLE:
            mBtnMiddle = rawEvent->value;
            break;
        case BTN_BACK:
            mBtnBack = rawEvent->value;
            break;
        case BTN_SIDE:
            mBtnSide = rawEvent->value;
            break;
        case BTN_FORWARD:
            mBtnForward = rawEvent->value;
            break;
        case BTN_EXTRA:
            mBtnExtra = rawEvent->value;
            break;
        case BTN_TASK:
            mBtnTask = rawEvent->value;
            break;
        }
+ hdmi_power_on(); // cjcheng add for hdmi on
    }
}

// USB鼠标移动唤醒HDMI
void CursorMotionAccumulator::process(const RawEvent* rawEvent) {
    if (rawEvent->type == EV_REL) {
        switch (rawEvent->scanCode) {
        case REL_X:
            mRelX = rawEvent->value;
            break;
        case REL_Y:
            mRelY = rawEvent->value;
            break;
        }
+ hdmi_power_on(); // cjcheng add for hdmi on
    }
}

// USB键盘唤醒HDMI
void KeyboardInputMapper::processKey(nsecs_t when, bool down, int32_t keyCode,
        int32_t scanCode, uint32_t policyFlags) {

    if (down) {
        // Rotate key codes according to orientation if needed.
        if (mParameters.orientationAware && mParameters.associatedDisplayId >= 0) {
            keyCode = rotateKeyCode(keyCode, mOrientation);
        }

+ hdmi_power_on(); // cjcheng add hdmi on

    ……
   }
}

}

你可能感兴趣的:(android4.0 系统层hdmi开关)