zoukankan      html  css  js  c++  java
  • RK平台Android4.4 添加一个新的遥控器支持以及添加特殊按键【转】

    本文转载自:http://blog.csdn.net/coding__madman/article/details/52904063

    瑞芯微平台

    SDK:Android4.4

    好久没写博客了,最近工作中需要在SDK中添加一个新的遥控器支持,由于自己对java代码比较头大,过程也是一波三折,整个流程其实分析下来并不难,这里做个简单的总结。也算是学习android的一个开端。

    1.  遥控器红外键值到linux层的映射

          安卓4.4后linux层和红外层的键值映射是在设备树中修改的,不需要在linux中修改驱动代码,直接在相应的dts文件中修改即可,首先每个遥控器都有一个usercode,按照瑞芯微方面提供的文档:

    在终端中输入命令:echo 1 > sys/module/cmcc_pwm_remotectl/parameters/code_print

    其中USERCODE=0xf601的遥控器用户码,用来标识是哪一个遥控器,RMC_GETDATA=bb,这个是遥控器设备linux驱动中对应的按键上报的对应的键值。

    文件目录kernelarcharmootdtsxxx.dts

    在代码中先添加如下框架(文件里面照葫芦画瓢)(先把usercode这样加上,然后输入上面的命令才能记录相应按键DTS中对应的值):

    我这上面是修改好的样子,0xbb和0xbc分别对应的是向上键和确定键。这些都是记录的键值,

    <0xbc KEY_REPLY>, 其中0xbc在DTS文件中确定键对应的宏定义 KEY_REPLY这个要在input.h文件中去找

    input.h文件路径:kernelarcharmootdtsincludedt-bindingsinputinput.h

    DTS文件中每一按键的键值都可以通过打印来记录,每一个键值所对应的宏可以通过linux驱动层中input.h文件中对应的宏找到。名字一定要保持一致!其中上面确定键对应的232是linux层上报android层的键值。

    就这样记录所有的按键,然后在DTS文件对号入座,第一步遥控器红外层到linux层的键值映射就搞定了

    2. Linux层到android层的键值映射

    同样通过终端输入命令:getevent 记录Linux层到android层的键值记录

    对应的映射文件就是110b0030_pwm.kl 这个是可以在相关配置文件修改确定是哪个KL文件是linux层到android层键值映射,也可以修改为自己创建的KL文件。

    文件目录:盒子根文件目录下的/system/usr/keylayout/110b0030_pwm.kl文件

    这里232是确定键从Linux层上报到android层的键值,其中确定键对应的宏DPAD_CENTER 这个可以在keyevent.java文件中找到

    一般的遥控器常规按键做到这两步了,基本都没问题了,但是特殊按键的添加还需要继续完善!

    通常Linux驱动层基本不需要修改,第一步:我们只需要修改对应的KL文件即可。

    已遥控器上的搜索按键为例:

    由于DTS文件中:

    <0xa7 KEY_PROGRAM>  a7是记录的搜索键的键值, 后边对应的宏是input.h文件中可以找到对应的,这个加进去就好了

    KL文件中:

    key 362   TV_SEARCH    //362是getevent命令记录的搜索键的键值, TV_SEARCH是自定义的宏,这个名字自己可以随便定义。

    第二个修改的地方是keycodes.h文件

    文件目录:frameworks ativeincludeandroidkeycodes.h

    在文件中添加一个没有用到的键值

    第三个修改的地方是KeycodeLables.h文件

    文件目录:frameworks ativeincludeinputKeycodeLables.h

    第四个修改attrs.xml文件

    文件目录:frameworksasecore es esvaluesarrrs.xml

    第五个修改的文件:KeyEvent.java    (这个文件修改的地方有两个)

    如果添加的是最后一个别忘了LAST_KEYCODE 这个要和最后一个保持一致.下面还有一个地方也要添加:

    至此特殊按键搜索按键从红键值外层到android层的键值映射就完成了。搜索按键到android应用层的键值映射就是257.

    特殊按键应用层特殊处理可以修改PhoneWindowManager.java文件

    文件目录:frameworksasepolicysrccomandroidinternalpolicyimplPhoneWindowManager.java

    特殊按键处理这次应用层的做法是修改PhoneWindowManager.java文件,同时在上面的目录中添加keyfunction.java文件。

    [java] view plain copy
     
    1. package com.android.internal.policy.impl;  
    2.   
    3. import java.io.IOException;  
    4. import java.io.InputStream;  
    5. import java.io.FileInputStream;  
    6. import java.io.FileNotFoundException;  
    7. import java.lang.reflect.Field;  
    8. import java.util.ArrayList;  
    9. import java.util.List;  
    10. import java.util.HashMap;  
    11. import java.io.File;  
    12.   
    13. import javax.xml.parsers.DocumentBuilder;  
    14. import javax.xml.parsers.DocumentBuilderFactory;  
    15. import javax.xml.parsers.ParserConfigurationException;  
    16.   
    17. import org.w3c.dom.Document;  
    18. import org.w3c.dom.NodeList;  
    19.   
    20. import org.w3c.dom.Element;  
    21. import org.w3c.dom.Node;  
    22. import java.io.Serializable;  
    23.   
    24. import org.xml.sax.SAXException;  
    25. import android.os.Looper;  
    26. import android.content.Context;  
    27. import android.content.Intent;  
    28. import android.content.IntentFilter;  
    29. import android.content.ContextWrapper;  
    30. import android.util.Log;  
    31. import android.os.Message;  
    32. import android.os.Messenger;  
    33. import android.os.Bundle;  
    34. import android.os.Handler;  
    35. import android.os.IBinder;  
    36. import android.os.UserHandle;  
    37. import android.media.AudioService;  
    38. import android.os.RemoteException;  
    39. import android.os.ServiceManager;  
    40. import android.os.SystemClock;  
    41. //import com.hisilicon.android.HiDisplayManager;  
    42. //import com.hisilicon.android.DispFmt;  
    43. import android.widget.Toast;  
    44. import android.view.KeyEvent;  
    45. import android.os.SystemProperties;  
    46. import android.content.res.Configuration;  
    47. import android.app.ActivityManagerNative;  
    48. import android.app.ActivityManager;  
    49. import android.content.ComponentName;  
    50. import android.content.pm.PackageInfo;  
    51. //import android.view.VGAToast;  
    52.   
    53. public class Keyfunction {  
    54.     private static Keyfunction mInstance = null;  
    55.     private static final String KEYFUNTIONXLMNAME = "/system/etc/keyfunction.xml";  
    56.     private static final int MSG_TO_SET_FORMAT = 111;  
    57.     private static Context mContext;  
    58. //    private HiDisplayManager mDisplayManager = null;  
    59.     private ToastUtil toast = null;  
    60.     private String mProduc_name = null;  
    61.     private final String TAG = "Keyfunction";  
    62.   
    63.     private boolean is4Cpu = true;  
    64.     private static ArrayList<Integer> settingFormatValueList = new ArrayList<Integer>();  
    65.     private static ArrayList<String> settingFormatStringList = new ArrayList<String>();  
    66.   
    67.     private File avplay;  
    68.     private int[] threeD_ValueList = {19, 20, 21};  
    69.     private String[] threeD_StringList = {"1080P 24Hz FramePacking", "720P 60Hz FramePacking", "720P 50Hz FramePacking"};  
    70.     private int[] fourK_ValueList = {0x100, 0x101, 0x102, 0x103};  
    71.     private String[] fourK_StringList = {"3840X2160 24Hz", "3840X2160 25Hz", "3840X2160 30Hz", "4096X2160 24Hz"};  
    72.   
    73.     private int nCurrentFormat;  
    74.     private boolean currFmtInSets = false;  
    75.     private int nCurrentFormatIndex;  
    76.     private String CurrentFormatIndexString;  
    77.   
    78.     private boolean bEventWasHandled = true;  
    79.   
    80.     private final long TIME_SPACE = 3000;  
    81.     private int mScreenCount = 0;  
    82.     private Keyfunction(Context context) {  
    83.         Log.e(TAG, "-------->Keyfunction <---------");  
    84.         showStartMsg = false;  
    85.         mContext = context;  
    86.         loadKeyFuntion(mContext);  
    87.         toast = new ToastUtil();  
    88.   
    89.         mProduc_name = SystemProperties.get("ro.product.device");  
    90.         is4Cpu = mProduc_name.substring(0, 5).equals("Hi379")?true:false;  
    91.     }  
    92.     public static class ToastUtil {  
    93.   
    94.         private static Handler handler = new Handler(Looper.getMainLooper());  
    95.   
    96.         private static Toast toast = null;  
    97.   
    98.         private static Object synObj = new Object();  
    99.   
    100.         public static void showMessage(final Context act, final String msg) {  
    101.             showMessage(act, msg, Toast.LENGTH_SHORT);  
    102.         }  
    103.   
    104.         public static void showMessage(final Context act, final int msg) {  
    105.             showMessage(act, msg, Toast.LENGTH_SHORT);  
    106.         }  
    107.   
    108.         public static void showMessage(final Context act, final String msg,  
    109.                 final int len) {  
    110.   
    111.             handler.post(new Runnable() {  
    112.                 @Override  
    113.                 public void run() {  
    114.                     synchronized (synObj) {  
    115.                         if (toast != null) {  
    116.                             // toast.cancel();  
    117.                             toast.setText(msg);  
    118.                             toast.setDuration(len);  
    119.                         } else {  
    120.                             toast = Toast.makeText(act, msg, len);  
    121.                         }  
    122.                         toast.show();  
    123.                     }  
    124.                 }  
    125.             });  
    126.         }  
    127.   
    128.         public static void showMessage(final Context act, final int msg,  
    129.                 final int len) {  
    130.   
    131.             handler.post(new Runnable() {  
    132.                 @Override  
    133.                 public void run() {  
    134.                     synchronized (synObj) {  
    135.                         if (toast != null) {  
    136.                             // toast.cancel();  
    137.                             toast.setText(msg);  
    138.                             toast.setDuration(len);  
    139.                         } else {  
    140.                             toast = Toast.makeText(act, msg, len);  
    141.                         }  
    142.                         toast.show();  
    143.                     }  
    144.                 }  
    145.             });  
    146.         }  
    147.     }  
    148.       
    149.     private static Keyfunction keyfunction;  
    150.     HashMap<String, AppInfoVO> keyFunctionMap = new HashMap<String, Keyfunction.AppInfoVO>();  
    151.     private final boolean showStartMsg;  
    152.       
    153.     public static Keyfunction getInstance(Context context) {  
    154.         if (keyfunction == null) {  
    155.             keyfunction = new Keyfunction(context);  
    156.         }  
    157.         return keyfunction;  
    158.     }  
    159.   
    160.     static int parseToInt(String number) throws Exception {  
    161.         int n = -1;  
    162.         if (number.startsWith("0x") || number.startsWith("0X")) {  
    163.             n = Integer.parseInt(number.substring(2), 16);  
    164.         } else {  
    165.             n = Integer.parseInt(number);  
    166.         }  
    167.         return n;  
    168.     }  
    169.   
    170.     static int parseToInt(String number, int def) {  
    171.         int n = def;  
    172.         try {  
    173.             n = parseToInt(number);  
    174.         } catch (Exception e) {  
    175.             return def;  
    176.         }  
    177.         return n;  
    178.     }  
    179.   
    180.     private HashMap<String, AppInfoVO> loadKeyFuntion(Context mContext) {  
    181.         File file = null;  
    182.         file = new File(KEYFUNTIONXLMNAME);  
    183.         if ((!file.exists()) || (!file.canRead())) {  
    184.             keyFunctionMap.clear();  
    185.             return keyFunctionMap;  
    186.         }  
    187.         try {  
    188.             keyFunctionMap.clear();  
    189.             DocumentBuilderFactory xmlparser = DocumentBuilderFactory.newInstance();  
    190.             DocumentBuilder xmlDOC;  
    191.             Document doc = null;  
    192.             xmlDOC = xmlparser.newDocumentBuilder();  
    193.             doc = xmlDOC.parse(file);  
    194.             if (null == doc)  
    195.                 return keyFunctionMap;  
    196.             NodeList appItems = doc.getElementsByTagName("key");  
    197.             for (int i = 0; i < appItems.getLength(); i++) {  
    198.                 Node appItem = appItems.item(i);  
    199.                 if (!appItem.hasChildNodes())  
    200.                     continue;  
    201.                 String actionType = ((Element) appItem).getAttribute("actionType");  
    202.   
    203.                 NodeList appInfoItems = appItem.getChildNodes();  
    204.                 AppInfoVO appInfo = new AppInfoVO();  
    205.                 appInfo.actionType = ((actionType == null || actionType.length() == 0) ? AppInfoVO.ACTION_TYPE_ACTIVITY  
    206.                         : actionType);  
    207.                 for (int j = 0; j < appInfoItems.getLength(); j++) {  
    208.                     Node appInfoItem = appInfoItems.item(j);  
    209.                     String nodeName = appInfoItem.getNodeName();  
    210.                     String nodeTextContent = appInfoItem.getTextContent();  
    211.                     if (nodeName.equalsIgnoreCase("keyName")) {  
    212.                         appInfo.keyName = nodeTextContent;  
    213.                     } else if (nodeName.equalsIgnoreCase("keyValue")) {  
    214.                         appInfo.keyValue = nodeTextContent;  
    215.                     } else if (nodeName.equalsIgnoreCase("packageName")) {  
    216.                         appInfo.packageName = nodeTextContent;  
    217.                     } else if (nodeName.equalsIgnoreCase("activityName")) {  
    218.                         appInfo.activityName = nodeTextContent;  
    219.                     } else if (nodeName.equalsIgnoreCase("serviceName")) {  
    220.                         appInfo.serviceName = nodeTextContent;  
    221.                     } else if (nodeName.equalsIgnoreCase("action")) {  
    222.                         appInfo.action = nodeTextContent;  
    223.                     } else if (nodeName.equalsIgnoreCase("flags")) {  
    224.                         appInfo.flags = parseToInt(nodeTextContent, Intent.FLAG_ACTIVITY_NEW_TASK);  
    225.                     } else if (nodeName.equalsIgnoreCase("method")) {  
    226.                         appInfo.method = parseToInt(nodeTextContent, AppInfoVO.METHOD_FOR_INTERCEPT);  
    227.                     } else if (nodeName.equalsIgnoreCase("extras")) {  
    228.                         if (!appInfoItem.hasChildNodes())  
    229.                             continue;  
    230.                         NodeList appExtraItems = appInfoItem.getChildNodes();  
    231.                         String isBundle = ((Element) appInfoItem).getAttribute("isBundle");  
    232.                         appInfo.isExtarsBundle = (isBundle != null && isBundle.length() > 0 && ("true"  
    233.                                 .equalsIgnoreCase(isBundle) || isBundle.charAt(0) == '0'));  
    234.                         appInfo.extras = new HashMap<String, Object>();  
    235.                         for (int k = 0; k < appExtraItems.getLength(); k++) {  
    236.                             Node appExtraItem = appExtraItems.item(k);  
    237.                             if (!(appExtraItem instanceof Element))  
    238.                                 continue;  
    239.                             // Log.i(TAG,node.getNodeType());  
    240.                             String type = ((Element) appExtraItem).getAttribute("type");  
    241.                             String name = appExtraItem.getNodeName();  
    242.                             String value = appExtraItem.getTextContent();  
    243.                             parseExtra(appInfo.extras, type, name, value);  
    244.                         }  
    245.                     } else if (nodeName.equalsIgnoreCase("exclude")) {  
    246.                         if (!appInfoItem.hasChildNodes())  
    247.                             continue;  
    248.                         NodeList appExtraItems = appInfoItem.getChildNodes();  
    249.                         appInfo.excludePackage = new ArrayList<String>();  
    250.                         appInfo.excludeActivity = new ArrayList<String>();  
    251.                         for (int k = 0; k < appExtraItems.getLength(); k++) {  
    252.                             Node appExtraItem = appExtraItems.item(k);  
    253.                             if (!(appExtraItem instanceof Element))  
    254.                                 continue;  
    255.                             String name = appExtraItem.getNodeName();  
    256.                             String value = appExtraItem.getTextContent();  
    257.                             if (name == null || name.length() == 0 || value == null  
    258.                                     || value.length() == 0) {  
    259.                                 continue;  
    260.                             }  
    261.                             if ("packageName".equalsIgnoreCase(name)) {  
    262.                                 appInfo.excludePackage.add(value);  
    263.                             } else if ("activityName".equalsIgnoreCase(name)) {  
    264.                                 appInfo.excludeActivity.add(value);  
    265.                             }  
    266.                         }  
    267.                     }  
    268.                 }  
    269.                 if (appInfo.checkValid()) {  
    270.                     appInfo.generatIntent();  
    271.                     Log.i(TAG, "Got keyfunction : " + appInfo);  
    272.                     keyFunctionMap.put(appInfo.keyValue, appInfo);  
    273.                 }  
    274.             }  
    275.         } catch (Exception e) {  
    276.             Log.e(TAG, "loadKeyFuntionn fail:", e);  
    277.         }  
    278.         Log.i(TAG, "Got " + keyFunctionMap.size() + " items from the xml file");  
    279.         return keyFunctionMap;  
    280.     }  
    281.   
    282.     private HashMap<String, Object> parseExtra(HashMap<String, Object> extra, String type,  
    283.             String name, String value) {  
    284.         Object v = null;  
    285.         // Log.i(TAG,"parseExtra s type:" + type + ";" + name + "=" +  
    286.         // value);  
    287.         try {  
    288.             if ("int".equalsIgnoreCase(type)) {  
    289.                 v = Integer.parseInt(value);  
    290.             } else if ("long".equalsIgnoreCase(type)) {  
    291.                 v = Long.parseLong(value);  
    292.             } else if ("double".equalsIgnoreCase(type)) {  
    293.                 v = Double.parseDouble(value);  
    294.             } else if ("float".equalsIgnoreCase(type)) {  
    295.                 v = Float.parseFloat(value);  
    296.             } else if ("boolean".equalsIgnoreCase(type)) {  
    297.                 v = Boolean.parseBoolean(value);  
    298.             } else if ("string".equalsIgnoreCase(type) || "".endsWith(type)) {  
    299.                 v = value;  
    300.             } else {  
    301.                 Log.i(TAG, "parseExtra  unknown type:" + type);  
    302.                 v = null;  
    303.             }  
    304.         } catch (Exception e) {  
    305.             Log.i(TAG, "parseExtra  data error :" + e.getMessage());  
    306.             v = null;  
    307.         }  
    308.         // Log.i(TAG,"parseExtra e type:" + type + ";" + name + "=" +  
    309.         // (v != null ? v : null));  
    310.         if (v != null)  
    311.             extra.put(name, v);  
    312.         return extra;  
    313.     }  
    314.   
    315.     public AppInfoVO getKeyFunction(int keyValue) {  
    316.         return keyFunctionMap.get(String.valueOf(keyValue));  
    317.     }  
    318.   
    319.     public AppInfoVO getBeforeUserKeyFunction(int keyValue) {  
    320.         AppInfoVO app = getKeyFunction(keyValue);  
    321.         if (app == null)  
    322.             return null;  
    323.         if (app.method == AppInfoVO.METHOD_FOR_INTERCEPT  
    324.                 || app.method == AppInfoVO.METHOD_FOR_UNINTERCEPT)  
    325.             return app;  
    326.         return null;  
    327.     }  
    328.   
    329.     public AppInfoVO getUserUnhandledKeyFunction(int keyValue) {  
    330.         AppInfoVO app = getKeyFunction(keyValue);  
    331.         if (app == null)  
    332.             return null;  
    333.         if (app.method == AppInfoVO.METHOD_FOR_AFTER_USER_UNHANDLED)  
    334.             return app;  
    335.         return null;  
    336.     }  
    337.     public boolean isNeedExcludeOnTopComponent(AppInfoVO app, ComponentName cn) {  
    338.         boolean exclude = false;  
    339.         if (cn != null && app != null) {  
    340.             String pck = cn.getPackageName();  
    341.             if (pck != null && pck.length() > 0) {  
    342.                 exclude = app.isExclucePackage(pck);  
    343.             }  
    344.             String activityName = cn.getClassName();  
    345.             if (!exclude && activityName != null && activityName.length() > 0) {  
    346.                 if(activityName.equals(app.activityName)){  
    347.                     exclude = true;  
    348.                     Log.w(TAG, "is current app!! no need run keyfun");  
    349.                 }  
    350.                 if (!activityName.contains("."))  
    351.                     activityName = pck + "." + activityName;  
    352.                 if (!exclude)  
    353.                     exclude = app.isExcluceActivity(activityName);  
    354.                 if (!exclude)  
    355.                     exclude = app.isExcluceActivity(pck + "." + cn.getShortClassName());  
    356.             }  
    357.             if (exclude) {  
    358.                 Log.w(TAG, "no need run keyfun for:" + cn + " app id:" + app.keyValue + " name:" + app.keyName);  
    359.             }  
    360.         }  
    361.         return exclude;  
    362.     }  
    363.     /** 
    364.      *  
    365.      * @param app 
    366.      * @return 是否需要拦截 
    367.      */  
    368.     public boolean runKeyFunction(AppInfoVO app) {  
    369.         boolean needIntercept = false;  
    370.         boolean succ = false;  
    371.         if (app == null)  
    372.             return false;  
    373.         if (!keyFunctionMap.containsValue(app))  
    374.             return false;  
    375.         Log.i(TAG, "runKeyFunction..s app:" + app);  
    376.         needIntercept = app.method == AppInfoVO.METHOD_FOR_INTERCEPT;  
    377.         Log.i(TAG, "runKeyFunction..needIntercept=" + needIntercept);  
    378.         Intent intent = app.getStartIntent();  
    379.         try {  
    380.             if (intent != null) {  
    381.                 // intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);  
    382.                 if (AppInfoVO.ACTION_TYPE_ACTIVITY.equalsIgnoreCase(app.actionType)) {  
    383.                     if (showStartMsg)  
    384.                         ToastUtil.showMessage(mContext, "startActivity for " + app.keyName + ":"  
    385.                                 + app.keyValue + " " + intent.getComponent());  
    386.                     mContext.startActivity(intent);  
    387.                     succ = true;  
    388.                 } else if (AppInfoVO.ACTION_TYPE_SERVICE.equalsIgnoreCase(app.actionType)) {  
    389.                     if (showStartMsg)  
    390.                         ToastUtil.showMessage(mContext, "startService for " + app.keyName + ":"  
    391.                                 + app.keyValue + " " + intent.getComponent());  
    392.                     ComponentName t = mContext.startService(intent);  
    393.                     if (t != null)  
    394.                         succ = true;  
    395.                 } else if (AppInfoVO.ACTION_TYPE_BOADCAST.equalsIgnoreCase(app.actionType)) {  
    396.                     if (showStartMsg)  
    397.                         ToastUtil.showMessage(mContext, "sendBroadcast for " + app.keyName + ":"  
    398.                                 + app.keyValue + " " + intent);  
    399.                     mContext.sendBroadcast(intent);  
    400.                     succ = true;  
    401.                 } else {  
    402.                     Log.e(TAG, "runKeyFunction unknow intent action");  
    403.                 }  
    404.             }  
    405.         } catch (Exception e) {  
    406.             succ = false;  
    407.             Log.e(TAG, "runKeyFunction fail:", e);  
    408.         }  
    409.         Log.i(TAG, "runKeyFunction..e succ=" + succ);  
    410.   
    411.         return succ && needIntercept;  
    412.     }  
    413.   
    414.     class AppInfoVO {  
    415.         public AppInfoVO() {  
    416.         }  
    417.   
    418.         public static final String ACTION_TYPE_ACTIVITY = "activity";  
    419.         public static final String ACTION_TYPE_SERVICE = "service";  
    420.         public static final String ACTION_TYPE_BOADCAST = "broadcast";  
    421.   
    422.         public static final int METHOD_FOR_INTERCEPT = 0;  
    423.         public static final int METHOD_FOR_UNINTERCEPT = 1;  
    424.         public static final int METHOD_FOR_AFTER_USER_UNHANDLED = 2;  
    425.   
    426.         public boolean checkStringValid(String s) {  
    427.             return s != null && s.length() > 0;  
    428.         }  
    429.   
    430.         public boolean checkActivity() {  
    431.             return ((ACTION_TYPE_ACTIVITY.equalsIgnoreCase(actionType)) && (checkStringValid(action) || (checkStringValid(packageName) && checkStringValid(activityName))));  
    432.         }  
    433.   
    434.         public boolean checkService() {  
    435.             return ((ACTION_TYPE_SERVICE.equalsIgnoreCase(actionType)) && (checkStringValid(action) || (checkStringValid(packageName) && checkStringValid(activityName))));  
    436.         }  
    437.   
    438.         public boolean checkBroadcast() {  
    439.             return ((ACTION_TYPE_BOADCAST.equalsIgnoreCase(actionType)) && (checkStringValid(action)));  
    440.         }  
    441.   
    442.         public boolean checkValid() {  
    443.             boolean succ = checkStringValid(keyValue);  
    444.             succ = succ && (checkActivity() || checkService() || checkBroadcast());  
    445.             return succ;  
    446.         }  
    447.   
    448.         public Intent getStartIntent() {  
    449.             return intent;  
    450.         }  
    451.   
    452.         public boolean isExclucePackage(String pck) {  
    453.             return excludePackage != null && excludePackage.contains(pck);  
    454.         }  
    455.   
    456.         public boolean isExcluceActivity(String a) {  
    457.             return excludeActivity != null && excludeActivity.contains(a);  
    458.         }  
    459.           
    460.         private void addIntentExtras(Intent intent, HashMap<String, Object> extra) {  
    461.             if (extra == null || extra.size() <= 0)  
    462.                 return;  
    463.             for (String key : extra.keySet()) {  
    464.                 Object value = extra.get(key);  
    465.                 Log.i(TAG, "key=" + key + ";value=" + value);  
    466.                 if (value != null && value instanceof Serializable) {  
    467.                     Log.i(TAG, "add extra:" + key + "=" + value);  
    468.                     intent.putExtra(key, (Serializable) value);  
    469.                 }  
    470.             }  
    471.         }  
    472.   
    473.         public Intent generatIntent() {  
    474.             if (intent != null)  
    475.                 return intent;  
    476.             intent = new Intent();  
    477.             if (action != null && action.length() > 0) {  
    478.                 intent.setAction(action);  
    479.             }  
    480.             intent.addFlags(flags);  
    481.             if (ACTION_TYPE_ACTIVITY.equalsIgnoreCase(actionType)) {  
    482.                 if (checkStringValid(packageName) && checkStringValid(activityName))  
    483.                     intent.setClassName(packageName, activityName);  
    484.             } else if (ACTION_TYPE_SERVICE.equalsIgnoreCase(actionType)) {  
    485.                 if (checkStringValid(packageName) && checkStringValid(activityName))  
    486.                     intent.setClassName(packageName, serviceName);  
    487.             } else if (ACTION_TYPE_BOADCAST.equalsIgnoreCase(actionType)) {  
    488.                 // TODO  
    489.             }  
    490.             if (isExtarsBundle) {  
    491.                 // TODO  
    492.             } else {  
    493.                 addIntentExtras(intent, extras);  
    494.             }  
    495.             return intent;  
    496.         }  
    497.   
    498.         @Override  
    499.         public String toString() {  
    500.             StringBuilder sb = new StringBuilder();  
    501.             sb.append("{{keyValue:" + keyValue + "};");  
    502.             sb.append("{keyName:" + keyName + "};");  
    503.             sb.append("{actionType:" + actionType + "};");  
    504.             sb.append("{flags:0x" + Integer.toHexString(flags) + "};");  
    505.             sb.append("{method:" + method + "};");  
    506.             sb.append("{action:" + action + "};");  
    507.             sb.append("{packageName:" + packageName + "};");  
    508.             sb.append("{activityName:" + activityName + "};");  
    509.             sb.append("{serviceName:" + serviceName + "};");  
    510.             sb.append("{extras:" + extras + "};");  
    511.             sb.append("{excludePackage:" + excludePackage + "};");  
    512.             sb.append("{excludeActivity:" + excludeActivity + "};");  
    513.             sb.append("{intent:" + intent + "}}");  
    514.             return sb.toString();  
    515.         }  
    516.   
    517.         public String actionType = ACTION_TYPE_ACTIVITY;// TODO  
    518.         public int flags = Intent.FLAG_ACTIVITY_NEW_TASK;  
    519.         public int method = METHOD_FOR_INTERCEPT;  
    520.         public boolean isExtarsBundle = false;  
    521.         public String keyValue;  
    522.         public String keyName;  
    523.         public String packageName;  
    524.         public String action;  
    525.         public String activityName;  
    526.         public String serviceName;  
    527.         public HashMap<String, Object> extras;  
    528.         public ArrayList<String> excludePackage;  
    529.         public ArrayList<String> excludeActivity;  
    530.         public Intent intent;  
    531.     }  
    532.     public void readSwitch() {  
    533.   
    534.     }  
    535.   
    536.     private Handler FMThandler = new Handler() {  
    537.         public void handleMessage(Message msg) {  
    538.             int i = 0;  
    539.             switch (msg.what) {  
    540.             case MSG_TO_SET_FORMAT:  
    541.                 Log.e(TAG, "receive MSG_TO_SET_FORMAT msg");  
    542.                 for (i = 0; i < settingFormatValueList.size(); i++) {  
    543.                     if (settingFormatValueList.get(i) == nCurrentFormat) {  
    544.                         break;  
    545.                     }  
    546.                 }  
    547.                 Log.e(TAG, "nCurrentFormatIndex: "+nCurrentFormatIndex);  
    548.                 Log.e(TAG, "settingFormatValueList.get(nCurrentFormatIndex): "+settingFormatValueList.get(nCurrentFormatIndex));  
    549.                 if(nCurrentFormatIndex != i)  
    550.                 {  
    551. //                    mDisplayManager.setFmt(settingFormatValueList.get(nCurrentFormatIndex));  
    552. //                    mDisplayManager.SaveParam();  
    553. //                    mDisplayManager.setOptimalFormatEnable(0);  
    554.   
    555.                     Intent in = new Intent("com.hisilicon.intent.action.ACTION_FORMAT_CHANGED");  
    556.                     mContext.sendBroadcastAsUser(in, UserHandle.ALL);  
    557.                 }  
    558.                 bEventWasHandled = true;  
    559.                 break;  
    560.             case 1:  
    561.   
    562.             }  
    563.             super.handleMessage(msg);  
    564.         }  
    565.   
    566.     };  
    567.     public void keyToResolution() {  
    568. //  mDisplayManager = new HiDisplayManager();  
    569.     FMThandler.removeMessages(1);  
    570.     Message message = new Message();  
    571.     message.what = 1;  
    572.     FMThandler.sendMessage(message);  
    573.    }  
    574.     public void keySwitchFormat() {  
    575.         FMThandler.removeMessages(MSG_TO_SET_FORMAT);  
    576.   
    577. //        mDisplayManager = new HiDisplayManager();  
    578.         Message message = new Message();  
    579. //        nCurrentFormat = mDisplayManager.getFmt();  
    580.         getDisplayFormatList();  
    581.         int i;  
    582.   
    583.         Log.e(TAG, "current format is: "+nCurrentFormat);  
    584.         Log.e(TAG, "bEventWasHandled is: "+bEventWasHandled);  
    585.         if(bEventWasHandled)  
    586.         {  
    587.             for (i = 0; i < settingFormatValueList.size(); i++)  
    588.             {  
    589.                 if (settingFormatValueList.get(i) == nCurrentFormat)  
    590.                 {  
    591.                     nCurrentFormatIndex = i;  
    592.                     currFmtInSets = true;  
    593.                     break;  
    594.                 }  
    595.                 else  
    596.                 {  
    597.                     currFmtInSets = false;  
    598.                     nCurrentFormatIndex = 0;  
    599.                 }  
    600.              }  
    601.          }  
    602.          else  
    603.          {  
    604.              currFmtInSets = true;  
    605.              nCurrentFormatIndex = (nCurrentFormatIndex + 1)%settingFormatValueList.size();  
    606.          }  
    607.          Log.e(TAG, "currFmtInSets is: "+currFmtInSets);  
    608.          Log.e(TAG, "nCurrentFormatIndex is: "+nCurrentFormatIndex);  
    609.   
    610.          if(currFmtInSets)  
    611.          {  
    612.              bEventWasHandled = false;  
    613.              CurrentFormatIndexString = settingFormatStringList.get(nCurrentFormatIndex);  
    614.              toast.showMessage(mContext, CurrentFormatIndexString, Toast.LENGTH_LONG);  
    615.   
    616.              message.what = MSG_TO_SET_FORMAT;  
    617.              FMThandler.sendMessageDelayed(message, TIME_SPACE);  
    618.          }  
    619.          else  
    620.          {  
    621.              //3d format case  
    622.              for (i = 0; i < threeD_ValueList.length; i++)  
    623.              {  
    624.                  if (threeD_ValueList[i] == nCurrentFormat)  
    625.                  {  
    626.                     Log.e(TAG, "3d format case");  
    627.                     toast.showMessage(mContext, threeD_StringList[i], Toast.LENGTH_SHORT);  
    628.                     avplay = new File("/proc/msp/avplay00");  
    629.                     if (!avplay.exists()) {  
    630.                         Log.e(TAG, "no active avplay");  
    631.                         //switch format  
    632.                         message.what = MSG_TO_SET_FORMAT;  
    633.                         FMThandler.sendMessageDelayed(message, TIME_SPACE);  
    634.                     }  
    635.                     return;  
    636.                  }  
    637.              }  
    638.   
    639.              //4k format case  
    640.              for (i = 0; i < fourK_ValueList.length; i++)  
    641.              {  
    642.                  if (fourK_ValueList[i] == nCurrentFormat)  
    643.                  {  
    644.                     Log.e(TAG, "4k format case");  
    645.                     toast.showMessage(mContext, fourK_StringList[i], Toast.LENGTH_SHORT);  
    646.                     //switch format  
    647.                     message.what = MSG_TO_SET_FORMAT;  
    648.                     FMThandler.sendMessageDelayed(message, TIME_SPACE);  
    649.                     return;  
    650.                  }  
    651.              }  
    652.   
    653.          }  
    654.     }  
    655.   
    656.     public void getDisplayFormatList()  
    657.     {  
    658.           
    659.     }  
    660.   
    661. }  

    同时在盒子根目录下的/system/etc目录下添加keyfunction.xml配置文件。
    [plain] view plain copy
     
    1. <?xml version="1.0" encoding="utf-8"?>  
    2. <Applications>  
    3. <!-- <key>  
    4.         <keyName>VOD_SEARCH</keyName>  
    5.         <keyValue>84</keyValue>  
    6.         <packageName>com.ipanel.portal</packageName>  
    7.         <activityName>com.ipanel.portal.IPanel30PortalActivity</activityName>  
    8.         <action>android.intent.action.MAIN</action>  
    9.         <method>0</method>  
    10.         <flags>0x14008000</flags>  
    11.         <extras>  
    12.             <url type="string">http://vod.fjgdwl.com:80/gldb/NEW_UI/search/search_2.htm</url>  
    13.         </extras>  
    14.         <exclude>  
    15.             <packageName>com.ipanel.join.live.fj</packageName>  
    16.             <activityName>com.ipanel.portal.IPanel30PortalActivity</activityName>  
    17.         </exclude>  
    18.     </key>  
    19.       
    20.       
    21.       
    22.           
    23.     <key>  
    24.         <keyName>Huikan</keyName>  
    25.         <keyValue>67</keyValue>  
    26.         <packageName>com.ipanel.portal</packageName>  
    27.         <activityName>com.ipanel.portal.IPanel30PortalActivity</activityName>  
    28.         <action>android.intent.action.MAIN</action>  
    29.         <method>1</method>  
    30.         <flags>0x14008000</flags>  
    31.         <exclude>  
    32.             <packageName>com.ipanel.portal</packageName>  
    33.         </exclude>  
    34.         <extras>  
    35.             <url type="string">http://vod.fjgdwl.com:80/gldb/NEW_UI/lookBack/list.htm?typePos=0</url>  
    36.         </extras>  
    37.     </key>  
    38. -->  
    39.   
    40.     <key>  
    41.         <keyName>>Huikan</keyName>  
    42.         <keyValue>275</keyValue>  
    43.         <packageName>com.ipanel.join.vod.fj</packageName>  
    44.             <activityName>com.ipanel.join.vod.ui.BTVChannelListActivity</activityName>  
    45.         <action>android.intent.action.MAIN</action>  
    46.         <method>0</method>  
    47.         <flags>0x14008000 </flags>  
    48.     </key>      
    49.       
    50.       
    51.     <key>  
    52.         <keyName>SEARCH</keyName>  
    53.         <keyValue>257</keyValue>  
    54.         <packageName>com.ipanel.join.vod.fj</packageName>  
    55.             <activityName>com.ipanel.join.vod.fj.SearchActionActivity</activityName>  
    56.         <action>android.intent.action.MAIN</action>  
    57.         <method>0</method>  
    58.         <flags>0x14008000 </flags>  
    59.         <exclude>  
    60.             <packageName>com.ipanel.join.live.fj</packageName>  
    61.         </exclude>  
    62.     </key>      
    63.   
    64.   
    65.   
    66.     <key>  
    67.         <keyName>HD</keyName>  
    68.         <keyValue>170</keyValue>  
    69.         <packageName>com.ipanel.join.live.fj</packageName>  
    70.         <activityName>com.jiangxi.apps.nclive.LiveActivity</activityName>  
    71.         <action>android.intent.action.MAIN</action>  
    72.         <flags>0x10200000</flags>  
    73.         <extras>  
    74.         <bouquet type="string">815</bouquet>  
    75.             <live_show_epg type="boolean">true</live_show_epg>  
    76.         </extras>  
    77.     </key>  
    78.   
    79.     <key>  
    80.         <keyName>Love</keyName>  
    81.         <keyValue>256</keyValue>  
    82.         <packageName>com.ipanel.join.live.fj</packageName>  
    83.         <activityName>com.jiangxi.apps.nclive.LiveActivity</activityName>  
    84.         <action>android.intent.action.MAIN</action>  
    85.         <flags>0x10200000</flags>  
    86.         <extras>  
    87.         <bouquet type="string">2147483627</bouquet>  
    88.             <live_show_epg type="boolean">true</live_show_epg>  
    89.         </extras>  
    90.     </key>  
    91.   
    92.     <key>  
    93.         <keyName>Settings</keyName>  
    94.         <keyValue>176</keyValue>  
    95.         <packageName>com.ipanel.join.cq.settings</packageName>  
    96.             <activityName>com.ipanel.join.cq.settings.SettingActivity</activityName>  
    97.         <action>android.intent.action.MAIN</action>  
    98.     </key>  
    99.       
    100.     <key>  
    101.         <keyName>Email</keyName>  
    102.         <keyValue>65</keyValue>  
    103.         <packageName>com.ipanel.join.cq.settings</packageName>  
    104.             <activityName>com.ipanel.join.cq.settings.activity.MailListActivity</activityName>  
    105.         <action>android.intent.action.MAIN</action>  
    106.     </key>  
    107.   
    108.     <key>  
    109.         <keyName>HiPQSetting</keyName>  
    110.         <keyValue>1185</keyValue>  
    111.         <packageName>com.hisilicon.android.pqsetting</packageName>  
    112.         <serviceName>com.hisilicon.android.pqsetting.MainService</serviceName>  
    113.         <action>android.intent.action.MAIN</action>  
    114.     </key>  
    115.       
    116. </Applications>  

    至此搜索按键从红外层到应用层的映射一直到安卓应用层的处理就全部完毕。这里搜索按键是跳到特殊的APP应用界面。
               
  • 相关阅读:
    inf的设置【知识】
    输入加速【模板】
    floyed算法【最短路】【模板】
    vector的erase函数使用
    欧拉图
    组合索引
    索引的存储
    索引失效
    装饰器和代理模式
    单例模式
  • 原文地址:https://www.cnblogs.com/zzb-Dream-90Time/p/7665897.html
Copyright © 2011-2022 走看看