Home | History | Annotate | Download | only in input
      1 <!--
      2    Copyright 2011 The Android Open Source Project
      3 
      4    Licensed under the Apache License, Version 2.0 (the "License");
      5    you may not use this file except in compliance with the License.
      6    You may obtain a copy of the License at
      7 
      8        http://www.apache.org/licenses/LICENSE-2.0
      9 
     10    Unless required by applicable law or agreed to in writing, software
     11    distributed under the License is distributed on an "AS IS" BASIS,
     12    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13    See the License for the specific language governing permissions and
     14    limitations under the License.
     15 -->
     16 
     17 # Validate Keymaps Tool #
     18 
     19 The Android framework has a small tool called `validatekeymaps` to validate the
     20 syntax of input device configuration files, key layout files, key character
     21 maps files and virtual key definition files.
     22 
     23 ## Compilation ##
     24 
     25 To compile `validatekeymaps`, set up the development environment, download
     26 the Android source tree, compile it, then run:
     27 
     28     $ mmm frameworks/base/tools/validatekeymaps
     29 
     30 This command should compile a host tool called validatekeymaps into the
     31 `out/host/&lt;os&gt;/bin` directory.
     32 
     33 ## Usage ##
     34 
     35 If you ran `envsetup.sh` to set up your development environment, then the
     36 `validatekeymaps` tool should already be on your path.  You can verify
     37 this by running `validatekeymaps`.
     38 
     39     $ validatekeymaps
     40 
     41     Keymap Validation Tool
     42 
     43     Usage:
     44      validatekeymaps [*.kl] [*.kcm] [*.idc] [virtualkeys.*] [...]
     45        Validates the specified key layouts, key character maps, 
     46        input device configurations, or virtual key definitions.
     47 
     48 Then all you need to do is run `validatekeymaps` an give it the path of
     49 one or more files to validate.
     50 
     51     $ validatekeymaps frameworks/base/data/keyboards/Generic.kl
     52 
     53     Validating file 'frameworks/base/data/keyboards/Generic.kl'...
     54     No errors.
     55 
     56     Success.
     57 
     58 And if there is an error...
     59 
     60     $ validatekeymaps Bad.kl
     61 
     62     Validating file 'Bad.kl'...
     63     E/KeyLayoutMap(87688): Bad.kl:24: Expected keyword, got 'ke'.
     64     Error -22 parsing key layout file.
     65 
     66     Failed!
     67 
     68 ## Automation ##
     69 
     70 It is a *very* good idea to run `validatekeymaps` on all configuration files
     71 before installing them on a device.
     72 
     73 The process can easily be automated as part of the build system by using a
     74 script or a makefile.
     75 
     76 The following sample makefile is based on the contents of
     77 `frameworks/base/data/keyboards/Android.mk`.
     78 
     79     # This makefile performs build time validation of framework keymap files.
     80 
     81     LOCAL_PATH := $(call my-dir)
     82 
     83     # Validate all key maps.
     84     include $(CLEAR_VARS)
     85 
     86     validatekeymaps := $(HOST_OUT_EXECUTABLES)/validatekeymaps$(HOST_EXECUTABLE_SUFFIX)
     87     files := MyKeyboard.kl MyKeyboard.kcm MyTouchScreen.idc
     88 
     89     LOCAL_MODULE := validate_framework_keymaps
     90     LOCAL_MODULE_TAGS := optional
     91     LOCAL_REQUIRED_MODULES := validatekeymaps
     92 
     93     validate_framework_keymaps: $(files)
     94         $(hide) $(validatekeymaps) $(files)
     95 
     96     include $(BUILD_PHONY_PACKAGE)
     97