Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲
 Android教程網 >> Android技術 >> 關於Android編程 >> android4.0.4 增加HDMI設置

android4.0.4 增加HDMI設置

編輯:關於Android編程

最近到4412最基本的都調了 然後覺得沒事做了 所以增加一個HDMI的設置 不能閒著

以下使用的是廣州斯道的icool210開發板 源碼修改如下

最開始我是先在設置裡加上這些設置然後在去實現功能 這裡就一起說了 之前android2.3裡有HDMI設置所以這裡就參照那個增加 首先修改Setting

查看libhdmi庫首先查看下hdmi能設置的格式 源碼路徑

 

你會發現有如下代碼

 

    mHdmiResolutionValueList[0]  = 1080960;
    mHdmiResolutionValueList[1]  = 1080950;
    mHdmiResolutionValueList[2]  = 1080930;
    mHdmiResolutionValueList[3]  = 1080160;
    mHdmiResolutionValueList[4]  = 1080150;
    mHdmiResolutionValueList[5]  = 720960;
    mHdmiResolutionValueList[6]  = 720950;
    mHdmiResolutionValueList[7]  = 5769501;
    mHdmiResolutionValueList[8]  = 5769502;
    mHdmiResolutionValueList[9]  = 4809601;
    mHdmiResolutionValueList[10] = 4809602;
ResolutionValue根據這個我們大致知道了支持了格式 下面來修改Setting

 

 

增加如下代碼

 

   
    
	1080P_60
	1080P_50
	1080P_30
	1080I_60
	1080I_50
	720P_60
	720P_50
	576P_50_16_9
	576P_50_4_3
	480P_60_16_9
	480P_60_4_3
    

    
    
	
	1080960
	
	1080950
	
	1080930
	
	1080160
	
	1080150
	
	720960
	
	720950
	
	5769501
	
	5769502
	
	4809601
	
	4809602
    

    
    
	Disable
	Enable
    

    
	
	
	0
	
	1
    

    
    
	HDMI(YCbCr)
	HDMI(RGB)
	DVI
    

    
    
	
	0
	
	1
	
	2
    
源碼路徑 packages/apps/Settings/res/values/strings.xml

 

增加如下內容

 

    
    TV Mode
    
    Choose TV out mode
    
    TV Resolution
    
    Choose TV resolution
    
    TV HDCP
    
    Enable HDMI HDCP
源碼路徑 packages/apps/Settings/res/xml/display_settings.xml

 

增加如下內容

 

		

		

		
接著修改framework

 

源碼路徑:frameworks/base/core/java/android/provider/Settings.java 

增加如下內容:

 

        /**
         * The tv out mode.
         */
        public static final String TV_MODE = tv_mode;

        /**
         * The tv out resolution.
         */
        public static final String TV_RESOLUTION = tv_resolution;

        /**
         * The tv out mode.
         */
        public static final String TV_HDCP = tv_hdcp;
接著在這個文件裡搜所SCREEN_OFF_TIMEOUT

 

會在public static final String[] SETTINGS_TO_BACKUP這個數組裡找到一個 然後在它下面增加如下

 

            TV_MODE,
            TV_RESOLUTION,
            TV_HDCP,
按照我的理解這裡應該是用來保存數據到數據庫的 然後系統再次啟動後設置還能保存

 

接著增加調用hdmi相關函數的接口 這裡我是直接把2.3的拷過來然後進行的修改

創建相應目錄增加以下文件frameworks/base/slsi/java/com/slsi/sec/android/HdmiService.java

內容如下

 

package com.slsi.sec.android;

public class HdmiService
{
    static {
        System.loadLibrary(hdmiservice_jni);
    }

    public native void setHdmiCableStatus(int status);
    public native void setHdmiMode(int mode);
    public native void setHdmiResolution(int resolution);
    public native void setHdmiHdcp(int enHdcp);
    public native void initHdmiService();
}
增加以下文件frameworks/base/slsi/jni/Android.mk

 

內容如下

 

LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)

LOCAL_SRC_FILES:= 
    com_slsi_sec_android_HdmiService.cpp 
    onload.cpp

LOCAL_C_INCLUDES += 
	$(JNI_H_INCLUDE)

LOCAL_SHARED_LIBRARIES := 
    libcutils 
    libandroid_runtime 
    libnativehelper

ifeq ($(S5P_BOARD_USES_HDMI),true)
LOCAL_C_INCLUDES += 
    device/samsung/common/s5p/libhdmi

LOCAL_SHARED_LIBRARIES += libhdmiclient

LOCAL_CFLAGS     += -DBOARD_USES_HDMI
endif

LOCAL_PRELINK_MODULE := false

ifeq ($(TARGET_SIMULATOR),true)
ifeq ($(TARGET_OS),linux)
ifeq ($(TARGET_ARCH),x86)
LOCAL_LDLIBS += -lpthread -ldl -lrt
endif
endif
endif

ifeq ($(WITH_MALLOC_LEAK_CHECK),true)
	LOCAL_CFLAGS += -DMALLOC_LEAK_CHECK
endif

LOCAL_MODULE_TAGS := optional eng
LOCAL_MODULE:= libhdmiservice_jni

include $(BUILD_SHARED_LIBRARY)
增加以下文件frameworks/base/slsi/jni/com_slsi_sec_android_HdmiService.cpp

 

內容如下

 

#define LOG_TAG HDMIStatusService

#include jni.h
#include JNIHelp.h
#include 

#if defined(BOARD_USES_HDMI)
#include SecHdmiClient.h
#endif

namespace android {

/*
 * Class:     com_slsi_sec_android_HdmiService
 * Method:    setHdmiCableStatus
 * Signature: (I)V
 */
static void com_slsi_sec_android_HdmiService_setHdmiCableStatus
  (JNIEnv *env, jobject obj, jint i)
{
    int result = 0;

#if defined(BOARD_USES_HDMI)
    //LOGD(%s HDMI status: %d, __func__, i);
    (SecHdmiClient::getInstance())->setHdmiCableStatus(i);
#else
    return;
#endif

    //return result;
}

/*
 * Class:     com_slsi_sec_android_setHdmiMode
 * Method:    setHdmiMode
 * Signature: (I)V
 */
static void com_slsi_sec_android_HdmiService_setHdmiMode
  (JNIEnv *env, jobject obj, jint i)
{
    int result = 0;

#if defined(BOARD_USES_HDMI)
    (SecHdmiClient::getInstance())->setHdmiMode(i);
#else
    return;
#endif
}

/*
 * Class:     com_slsi_sec_android_setHdmiResolution
 * Method:    setHdmiResolution
 * Signature: (I)V
 */
static void com_slsi_sec_android_HdmiService_setHdmiResolution
(JNIEnv *env, jobject obj, jint i)
{
    int result = 0;

#if defined(BOARD_USES_HDMI)
    (SecHdmiClient::getInstance())->setHdmiResolution(i);
#else
    return;
#endif
}

/*
 * Class:     com_slsi_sec_android_setHdmiHdcp
 * Method:    setHdmiHdcp
 * Signature: (I)V
 */
static void com_slsi_sec_android_HdmiService_setHdmiHdcp
(JNIEnv *env, jobject obj, jint i)
{
    int result = 0;

#if defined(BOARD_USES_HDMI)
    (SecHdmiClient::getInstance())->setHdmiHdcp(i);
#else
    return;
#endif
}

/*
 * Class:     com_slsi_sec_android_HdmiService
 * Method:    initHdmiService
 * Signature: ()V
 */
static void com_slsi_sec_android_HdmiService_initHdmiService
  (JNIEnv *env, jobject obj)
{
#if defined(BOARD_USES_HDMI)
    LOGI(%s , __func__);
    //(SecHdmiClient::getInstance())->init();
#else
    return;
#endif
    //return result;
}

static JNINativeMethod gMethods[] = {
    {setHdmiCableStatus, (I)V, (void*)com_slsi_sec_android_HdmiService_setHdmiCableStatus},
    {setHdmiMode, (I)V, (void*)com_slsi_sec_android_HdmiService_setHdmiMode},
    {setHdmiResolution, (I)V, (void*)com_slsi_sec_android_HdmiService_setHdmiResolution},
    {setHdmiHdcp, (I)V, (void*)com_slsi_sec_android_HdmiService_setHdmiHdcp},
    {initHdmiService, ()V, (void*)com_slsi_sec_android_HdmiService_initHdmiService},
};

int register_com_samsung_sec_android_HdmiService(JNIEnv* env)
{
     jclass clazz = env->FindClass(com/slsi/sec/android/HdmiService);

     if (clazz == NULL)
     {
         LOGE(Can't find com/slsi/sec/android/HdmiService);
         return -1;
     }

     return jniRegisterNativeMethods(env, com/slsi/sec/android/HdmiService,
                                     gMethods, NELEM(gMethods));
}

} /* namespace android */
增加如下文件:frameworks/base/slsi/jni/onload.cpp

 

內容如下

 

#include JNIHelp.h
#include jni.h
#include utils/Log.h
#include utils/misc.h

namespace android {
int register_com_samsung_sec_android_HdmiService(JNIEnv* env);
};

using namespace android;

extern C jint JNI_OnLoad(JavaVM* vm, void* reserved)
{
    JNIEnv* env = NULL;
    jint result = -1;

    if (vm->GetEnv((void**) &env, JNI_VERSION_1_4) != JNI_OK) {
        LOGE(GetEnv failed!);
        return result;
    }
    LOG_ASSERT(env, Could not retrieve the env!);

    if(register_com_samsung_sec_android_HdmiService(env) == -1)
        LOGE(%s register_com_samsung_sec_android_HdmiStatus is failed, __func__);

    return JNI_VERSION_1_4;
}
然後修改build/core/pathmap.mk

 

在FRAMEWORKS_BASE_SUBDIRS裡增加slsi

我們要讓他啟動的時候能能自動設置成設置的參數所以

接著修改frameworks/base/services/java/com/android/server/SystemServer.java

增加如下內容

 

import com.slsi.sec.android.HdmiService;
import static android.provider.Settings.System.TV_MODE;
import static android.provider.Settings.System.TV_RESOLUTION;
import static android.provider.Settings.System.TV_HDCP;
private HdmiService mHdmiService;
然後在

 

 

 mContentResolver = context.getContentResolver();
之後增加如下代碼

 

 

			Slog.i(TAG, HDMI Setting);
			mHdmiService = new HdmiService();
			mHdmiService.setHdmiMode(Settings.System.getInt(mContentResolver, TV_MODE, 0));
			mHdmiService.setHdmiResolution(Settings.System.getInt(mContentResolver, TV_RESOLUTION, 4809601));
			mHdmiService.setHdmiHdcp(Settings.System.getInt(mContentResolver, TV_HDCP, 0));
跟著最後修改Setting裡的DisplaySetting

 

源碼路徑packages/apps/Settings/src/com/android/settings/DisplaySettings.java

增加如下內容

 

import com.slsi.sec.android.HdmiService;
import static android.provider.Settings.System.TV_MODE;
import static android.provider.Settings.System.TV_RESOLUTION;
import static android.provider.Settings.System.TV_HDCP;
    private static final String KEY_TV_MODE = tv_mode;
    private static final String KEY_TV_RESOLUTION = tv_resolution;
    private static final String KEY_TV_HDCP = tv_hdcp;
    private static final int FALLBACK_TV_MODE_VALUE = 0;
    private static final int FALLBACK_TV_RESOLUTION_VALUE = 4809601;
    private static final int FALLBACK_TV_HDCP_VALUE = 0;
    private HdmiService mHdmiService;
然後在onCreate增加如下代碼

 

 

        ListPreference tvModePreference =
            (ListPreference) findPreference(KEY_TV_MODE);
        tvModePreference.setValue(String.valueOf(Settings.System.getInt(
                        resolver, TV_MODE, FALLBACK_TV_MODE_VALUE)));
        tvModePreference.setOnPreferenceChangeListener(this);

        ListPreference tvResolutionPreference =
            (ListPreference) findPreference(KEY_TV_RESOLUTION);
        tvResolutionPreference.setValue(String.valueOf(Settings.System.getInt(
                        resolver, TV_RESOLUTION, FALLBACK_TV_RESOLUTION_VALUE)));
        tvResolutionPreference.setOnPreferenceChangeListener(this);

        ListPreference tvHdcpPreference =
            (ListPreference) findPreference(KEY_TV_HDCP);
        tvHdcpPreference.setValue(String.valueOf(Settings.System.getInt(
                        resolver, TV_HDCP, FALLBACK_TV_HDCP_VALUE)));
        tvHdcpPreference.setOnPreferenceChangeListener(this);
		mHdmiService = new HdmiService();
接著在onPreferenceChange函數裡增加如下內容

 

 

        if (KEY_TV_MODE.equals(key)) {
            int value = Integer.parseInt((String) objValue);
            try {
                Settings.System.putInt(getContentResolver(),
                        TV_MODE, value);
            } catch (NumberFormatException e) {
                Log.e(TAG, could not persist tv mode setting, e);
            }
            mHdmiService.setHdmiMode(value);
        }
        if (KEY_TV_RESOLUTION.equals(key)) {
            int value = Integer.parseInt((String) objValue);
            try {
                Settings.System.putInt(getContentResolver(),
                        TV_RESOLUTION, value);
            } catch (NumberFormatException e) {
                Log.e(TAG, could not persist tv resolution setting, e);
            }
            mHdmiService.setHdmiResolution(value);
        }if (KEY_TV_HDCP.equals(key)) {
            int value = Integer.parseInt((String) objValue);
            try {
                Settings.System.putInt(getContentResolver(),
                        TV_HDCP, value);
            } catch (NumberFormatException e) {
                Log.e(TAG, could not persist tv resolution setting, e);
            }
            mHdmiService.setHdmiHdcp(value);
        }
基本上就搞定了 最後如圖所示

 

\

相關patch我也上傳到了我的資源 不知道為啥沒顯示出來 需要的可以去下載

  1. 上一頁:
  2. 下一頁:
熱門文章
閱讀排行版
Copyright © Android教程網 All Rights Reserved