From aa1155809b3b43be345f7219960551918fd6f034 Mon Sep 17 00:00:00 2001 From: erfanian Date: Tue, 11 Jul 2017 12:24:52 -0700 Subject: Remove obsolete wrapper bundle from CallIntent Bundle. Add additional null checks during deseriailzation. Bug: 63575857 Test: unit tests, on device PiperOrigin-RevId: 161564824 Change-Id: I54f52e12397adb4473b523325f8c006ff534fbd9 --- java/com/android/dialer/protos/ProtoParsers.java | 26 ++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) (limited to 'java/com/android/dialer/protos/ProtoParsers.java') diff --git a/java/com/android/dialer/protos/ProtoParsers.java b/java/com/android/dialer/protos/ProtoParsers.java index 5a60799bc..e5292061b 100644 --- a/java/com/android/dialer/protos/ProtoParsers.java +++ b/java/com/android/dialer/protos/ProtoParsers.java @@ -30,8 +30,14 @@ public final class ProtoParsers { /** Retrieve a proto from a Bundle which was not created within the current executable/version. */ @SuppressWarnings("unchecked") // We want to eventually optimize away parser classes, so cast - public static T get(Bundle bundle, String key, T defaultInstance) + public static T get( + @NonNull Bundle bundle, @NonNull String key, @NonNull T defaultInstance) throws InvalidProtocolBufferException { + + Assert.isNotNull(bundle); + Assert.isNotNull(key); + Assert.isNotNull(defaultInstance); + byte[] bytes = bundle.getByteArray(key); return (T) mergeFrom(bytes, defaultInstance.getDefaultInstanceForType()); } @@ -41,7 +47,8 @@ public final class ProtoParsers { * * @throws RuntimeException if the proto cannot be parsed */ - public static T getTrusted(Bundle bundle, String key, T defaultInstance) { + public static T getTrusted( + @NonNull Bundle bundle, @NonNull String key, @NonNull T defaultInstance) { try { return get(bundle, key, defaultInstance); } catch (InvalidProtocolBufferException e) { @@ -54,7 +61,9 @@ public final class ProtoParsers { * * @throws RuntimeException if the proto cannot be parsed */ - public static T getTrusted(Intent intent, String key, T defaultInstance) { + public static T getTrusted( + @NonNull Intent intent, @NonNull String key, @NonNull T defaultInstance) { + Assert.isNotNull(intent); return getTrusted(intent.getExtras(), key, defaultInstance); } @@ -64,7 +73,9 @@ public final class ProtoParsers { */ public static void put( @NonNull Bundle bundle, @NonNull String key, @NonNull MessageLite message) { - Assert.checkState(message != null); + Assert.isNotNull(message); + Assert.isNotNull(bundle); + Assert.isNotNull(key); bundle.putByteArray(key, message.toByteArray()); } @@ -72,8 +83,11 @@ public final class ProtoParsers { * Stores a proto in an Intent, for later retrieval by {@link #get(Bundle, String, MessageLite)}. * Needs separate method because Intent has similar to but different API than Bundle. */ - public static void put(@NonNull Intent intent, @NonNull String key, MessageLite message) { - Assert.checkState(message != null); + public static void put( + @NonNull Intent intent, @NonNull String key, @NonNull MessageLite message) { + Assert.isNotNull(message); + Assert.isNotNull(intent); + Assert.isNotNull(key); intent.putExtra(key, message.toByteArray()); } -- cgit v1.2.3