Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit aa115580 authored by erfanian's avatar erfanian Committed by Eric Erfanian
Browse files

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
parent 4f85fff2
Loading
Loading
Loading
Loading
+12 −10
Original line number Diff line number Diff line
@@ -19,12 +19,13 @@ package com.android.dialer.callintent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import com.android.dialer.common.LogUtil;
import com.android.dialer.protos.ProtoParsers;

/** Parses data for a call extra to get any dialer specific app data. */
public class CallIntentParser {
  static final String EXTRA_CALL_SPECIFIC_APP_DATA_WRAPPER =
      "com.android.dialer.callintent.CALL_SPECIFIC_APP_DATA_WRAPPER";


  @Nullable
  public static CallSpecificAppData getCallSpecificAppData(@Nullable Bundle extras) {
    if (extras == null) {
@@ -35,19 +36,20 @@ public class CallIntentParser {
      return null;
    }

    if (extras.getByteArray(Constants.EXTRA_CALL_SPECIFIC_APP_DATA) == null) {
      LogUtil.i(
          "CallIntentParser.getCallSpecificAppData",
          "unexpected null byte array for call specific app data proto");
      return null;
    }

    return ProtoParsers.getTrusted(
        extras.getBundle(Constants.EXTRA_CALL_SPECIFIC_APP_DATA),
        EXTRA_CALL_SPECIFIC_APP_DATA_WRAPPER,
        CallSpecificAppData.getDefaultInstance());
        extras, Constants.EXTRA_CALL_SPECIFIC_APP_DATA, CallSpecificAppData.getDefaultInstance());
  }

  public static void putCallSpecificAppData(
      @NonNull Bundle extras, @NonNull CallSpecificAppData callSpecificAppData) {
    // We wrap our bundle for consumers that may not have access to ProtoParsers in their class
    // loader. This is necessary to prevent ClassNotFoundException's
    Bundle wrapperBundle = new Bundle();
    ProtoParsers.put(wrapperBundle, EXTRA_CALL_SPECIFIC_APP_DATA_WRAPPER, callSpecificAppData);
    extras.putBundle(Constants.EXTRA_CALL_SPECIFIC_APP_DATA, wrapperBundle);
    ProtoParsers.put(extras, Constants.EXTRA_CALL_SPECIFIC_APP_DATA, callSpecificAppData);
  }

  private CallIntentParser() {}
+20 −6
Original line number Diff line number Diff line
@@ -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 extends MessageLite> T get(Bundle bundle, String key, T defaultInstance)
  public static <T extends MessageLite> 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 extends MessageLite> T getTrusted(Bundle bundle, String key, T defaultInstance) {
  public static <T extends MessageLite> 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 extends MessageLite> T getTrusted(Intent intent, String key, T defaultInstance) {
  public static <T extends MessageLite> 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());
  }