From 8661761cb691d9bed446b87d55a4fa7043a3aa95 Mon Sep 17 00:00:00 2001 From: Chris Wren Date: Thu, 9 Jan 2014 11:08:37 -0500 Subject: better support for multiple files don't exit on error, just log. new verbose flag to print more information Change-Id: I5c4895a837cb8a31901aabceade3ab976abf4af0 --- util/com/android/launcher3/DecoderRing.java | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) (limited to 'util') diff --git a/util/com/android/launcher3/DecoderRing.java b/util/com/android/launcher3/DecoderRing.java index 7098e189d..86431d9b7 100644 --- a/util/com/android/launcher3/DecoderRing.java +++ b/util/com/android/launcher3/DecoderRing.java @@ -86,6 +86,7 @@ class DecoderRing { boolean fromLogs = false; int skip = 0; List files = new LinkedList(); + boolean verbose = false; for (int i = 0; i < args.length; i++) { if ("-k".equals(args[i])) { @@ -108,6 +109,8 @@ class DecoderRing { } } else if ("-x".equals(args[i])) { extractImages = true; + } else if ("-v".equals(args[i])) { + verbose = true; } else if ("-L".equals(args[i])) { fromLogs = true; } else if (args[i] != null && !args[i].startsWith("-")) { @@ -123,7 +126,7 @@ class DecoderRing { usage(args); } - if (files.size() > 1) { + if (files.size() > 1 && defaultType != null) { System.err.println("Explicit type ignored for multiple files."); defaultType = null; } @@ -136,8 +139,13 @@ class DecoderRing { Class type = null; if (defaultType == null) { Key key = decodeKey(source.getName().getBytes(), fromLogs); - type = TYPES[key.type]; - System.err.println("This is a " + type.getSimpleName() + " backup"); + if (key != null) { + type = TYPES[key.type]; + if (verbose) { + System.err.println(source.getName() + " is a " + type.getSimpleName()); + System.out.println(key.toString()); + } + } } else { type = defaultType; } @@ -178,12 +186,14 @@ class DecoderRing { byte[] payload = byteStream.toByteArray(); if (type == Key.class) { proto = decodeKey(payload, fromLogs); - } else { + } else if (type != null) { proto = decodeBackupData(payload, type, fromLogs); } // Generic string output - System.out.println(proto.toString()); + if (proto != null) { + System.out.println(proto.toString()); + } if (extractImages) { String prefix = "stdin"; @@ -262,7 +272,7 @@ class DecoderRing { byte[] rawKey = DatatypeConverter.parseBase64Binary(encodedKey); if (rawKey[0] != 'L' || rawKey[1] != ':') { System.err.println(encodedKey + " is not a launcher backup key."); - System.exit(1); + return null; } encodedKey = new String(rawKey, 2, rawKey.length - 2); } @@ -270,16 +280,16 @@ class DecoderRing { key = Key.parseFrom(keyProtoData); } catch (InvalidProtocolBufferNanoException protoException) { System.err.println("failed to extract key from filename: " + protoException); - System.exit(1); + return null; } catch (IllegalArgumentException base64Exception) { System.err.println("failed to extract key from filename: " + base64Exception); - System.exit(1); + return null; } // keys are self-checked if (key.checksum != checkKey(key)) { System.err.println("key ckecksum failed"); - System.exit(1); + return null; } return key; } @@ -323,6 +333,7 @@ class DecoderRing { System.err.println("\t-w\tdecode a widget"); System.err.println("\t-S b\tskip b bytes"); System.err.println("\t-x\textract image data to files"); + System.err.println("\t-v\tprint key type data, as well as payload"); System.err.println("\t-l\texpect data from logcat, instead of the local transport"); System.err.println("\tfilename\tread from filename, not stdin"); System.exit(1); -- cgit v1.2.3