chromium/base/android/proguard/chromium_apk.flags

# Copyright 2016 The Chromium Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

# Contains //base flags that we'd like all Chromium .apks to use. Note that
# these rules will not be applied to Chromium code that ships in third-party
# APKs, e.g. Cronet.

# Keep line number information, useful for stack traces.
-keepattributes SourceFile,LineNumberTable

# Enable protobuf-related optimizations.
-shrinkunusedprotofields

# Allowing Proguard to change modifiers.
-allowaccessmodification

# Keep all CREATOR fields within Parcelable that are kept.
-keepclassmembers class !cr_allowunused,** implements android.os.Parcelable {
  public static *** CREATOR;
}

# Don't obfuscate Parcelables as they might be marshalled outside Chrome.
# If we annotated all Parcelables that get put into Bundles other than
# for saveInstanceState (e.g. PendingIntents), then we could actually keep the
# names of just those ones. For now, we'll just keep them all.
-keepnames,allowaccessmodification class !cr_allowunused,** implements android.os.Parcelable {}

# Keep all default constructors for used Fragments. Required since they are
# called reflectively when fragments are reinflated after the app is killed.
-keepclassmembers class !cr_allowunused,** extends android.app.Fragment {
  public <init>();
}
-keepclassmembers class !cr_allowunused,** extends androidx.fragment.app.Fragment {
  public <init>();
}

# Keep all enum values and valueOf methods. See
# http://proguard.sourceforge.net/index.html#manual/examples.html
# for the reason for this. Also, see http://crbug.com/248037.
-keepclassmembers enum !cr_allowunused,** {
    public static **[] values();
}

# This is to workaround crbug.com/1204690 - an old GMS app version crashes when
# ObjectWrapper contains > 1 fields, and this prevents R8 from inserting a
# synthetic field.
-keep,allowaccessmodification class !cr_allowunused,com.google.android.gms.dynamic.ObjectWrapper {
  <fields>;
}

# Remove calls to String.format() where the result goes unused. This can mask
# exceptions if the parameters to String.format() are invalid, but such cases
# are generally programming bugs anyways.
# Not using the return value generally occurs due to logging being stripped.
-assumenosideeffects class java.lang.String {
  static java.lang.String format(...);
}

# Allows R8 to remove static field accesses to library APIs when the results
# are unused (E.g. tell it that it's okay to not trigger <clinit>).
# Not using the return value generally occurs due to logging being stripped.
-assumenosideeffects class android.**, java.** {
  static <fields>;
}

# Causes R8 to more agressively optimize ServiceLoader.load() calls, by
# assuming no exceptions will be thrown.
-assumenosideeffects class java.util.ServiceLoader {
  static *** load(...);
}

# Keep the names of exception types, to make it easier to understand stack
# traces in contexts where it's not trivial to deobfuscate them - for example
# when reported to app developers who are using WebView.
-keepnames,allowaccessmodification class ** extends java.lang.Throwable {}

# Should be removed once we use Android V SDK. b/336753747
-keep class !cr_allowunused,androidx.privacysandbox.ads.adservices.internal.ContinuationOutcomeReceiver {
  <methods>;
}