Add a key directory argument to insertkeys.py

This allows us to better integrate key selection with our existing
build process.

Change-Id: I6e3eb5fbbfffb8e31c5edcf16f74df7c38abe537
diff --git a/Android.mk b/Android.mk
index 3af7591..380f5d7 100644
--- a/Android.mk
+++ b/Android.mk
@@ -179,7 +179,7 @@
 
 $(LOCAL_BUILT_MODULE) : $(mac_perms_keys.tmp) $(HOST_OUT_EXECUTABLES)/insertkeys.py $(ALL_MAC_PERMS_FILES)
 	@mkdir -p $(dir $@)
-	$(hide) $(HOST_OUT_EXECUTABLES)/insertkeys.py -t $(TARGET_BUILD_VARIANT) -c $(TOP) $< -o $@ $(ALL_MAC_PERMS_FILES)
+	$(hide) $(HOST_OUT_EXECUTABLES)/insertkeys.py -t $(TARGET_BUILD_VARIANT) -d $(dir $(DEFAULT_SYSTEM_DEV_CERTIFICATE)) -c $(TOP) $< -o $@ $(ALL_MAC_PERMS_FILES)
 
 mac_perms_keys.tmp :=
 ##################################
diff --git a/keys.conf b/keys.conf
index c002897..cca95e9 100644
--- a/keys.conf
+++ b/keys.conf
@@ -9,17 +9,17 @@
 #
 
 [@PLATFORM]
-ALL : build/target/product/security/platform.x509.pem
+ALL : platform.x509.pem
 
 [@MEDIA]
-ALL : build/target/product/security/media.x509.pem
+ALL : media.x509.pem
 
 [@SHARED]
-ALL : build/target/product/security/shared.x509.pem
+ALL : shared.x509.pem
 
 # Example of ALL TARGET_BUILD_VARIANTS
 [@RELEASE]
-ENG       : build/target/product/security/testkey.x509.pem
-USER      : build/target/product/security/testkey.x509.pem
-USERDEBUG : build/target/product/security/testkey.x509.pem
+ENG       : testkey.x509.pem
+USER      : testkey.x509.pem
+USERDEBUG : testkey.x509.pem
 
diff --git a/tools/insertkeys.py b/tools/insertkeys.py
index 509c43f..cccb92f 100755
--- a/tools/insertkeys.py
+++ b/tools/insertkeys.py
@@ -65,7 +65,7 @@
     # This must be lowercase
     OPTION_WILDCARD_TAG = "all"
 
-    def generateKeyMap(self, target_build_variant):
+    def generateKeyMap(self, target_build_variant, key_directory):
 
         keyMap = dict()
 
@@ -87,7 +87,7 @@
                 if tag in keyMap:
                     sys.exit("Duplicate tag detected " + tag)
 
-                path = self.get(tag, option)
+                path = os.path.join(key_directory, self.get(tag, option))
 
                 keyMap[tag] = GenerateKeys(path)
 
@@ -188,6 +188,9 @@
     parser.add_option("-t", "--target-build-variant", default="eng", dest="target_build_variant",
                       help="Specify the TARGET_BUILD_VARIANT, defaults to eng")
 
+    parser.add_option("-d", "--key-directory", default="", dest="key_directory",
+                      help="Specify a parent directory for keys")
+
     (options, args) = parser.parse_args()
 
     if len(args) < 2:
@@ -205,7 +208,7 @@
     logging.info("Setting output file to: " + options.output_file)
 
     # Generate the key list
-    key_map = config.generateKeyMap(options.target_build_variant.lower())
+    key_map = config.generateKeyMap(options.target_build_variant.lower(), options.key_directory)
     logging.info("Generate key map:")
     for k in key_map:
         logging.info(k + " : " + str(key_map[k]))