# -------- Config Path: base/android/proguard/shared_with_cronet.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 flags that we want to apply not only to Chromium APKs, but also to
# third-party apps that bundle the Cronet library.

# WARNING: rules in this file are applied to entire third-party APKs, not just
# Chromium code. They MUST be scoped appropriately to avoid side effects on app
# code that we do not own.

# Keep all CREATOR fields within Parcelable that are kept.
-keepclassmembers class !cr_allowunused,org.chromium.** 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,org.chromium.** implements android.os.Parcelable {}

# 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,org.chromium.** {
    public static **[] values();
}

# Required to remove fields until b/274802355 is resolved.
-assumevalues class !cr_allowunused,** {
  final org.chromium.base.ThreadUtils$ThreadChecker * return _NONNULL_;
}
# -------- Config Path: build/android/chromium_annotations.flags --------
# Copyright 2022 The Chromium Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

# Contains flags related to annotations in //build/android that can be safely
# shared with Cronet, and thus would be appropriate for third-party apps to
# include.

# Keep all annotation related attributes that can affect runtime
-keepattributes RuntimeVisible*Annotations
-keepattributes AnnotationDefault

# Keeps for class level annotations.
-keep,allowaccessmodification @internal.org.chromium.build.annotations.UsedByReflection class ** {}

# Keeps for method level annotations.
-keepclasseswithmembers,allowaccessmodification class ** {
  @internal.org.chromium.build.annotations.UsedByReflection <methods>;
}
-keepclasseswithmembers,allowaccessmodification class ** {
  @internal.org.chromium.build.annotations.UsedByReflection <fields>;
}

# Never inline classes, methods, or fields with this annotation, but allow
# shrinking and obfuscation.
# Relevant to fields when they are needed to store strong references to objects
# that are held as weak references by native code.
-if @internal.org.chromium.build.annotations.DoNotInline class * {
    *** *(...);
}
-keep,allowobfuscation,allowaccessmodification class <1> {
    *** <2>(...);
}
-keepclassmembers,allowobfuscation,allowaccessmodification class * {
   @internal.org.chromium.build.annotations.DoNotInline <methods>;
}
-keepclassmembers,allowobfuscation,allowaccessmodification class * {
   @internal.org.chromium.build.annotations.DoNotInline <fields>;
}

-alwaysinline class * {
    @internal.org.chromium.build.annotations.AlwaysInline *;
}

# Keep all logs (Log.VERBOSE = 2). R8 does not allow setting to 0.
-maximumremovedandroidloglevel 1 class ** {
   @internal.org.chromium.build.annotations.DoNotStripLogs <methods>;
}
-maximumremovedandroidloglevel 1 @internal.org.chromium.build.annotations.DoNotStripLogs class ** {
   <methods>;
}

# Never merge classes horizontally or vertically with this annotation.
# Relevant to classes being used as a key in maps or sets.
-keep,allowaccessmodification,allowobfuscation,allowshrinking @internal.org.chromium.build.annotations.DoNotClassMerge class *

# Mark members annotated with IdentifierNameString as identifier name strings
-identifiernamestring class * {
    @internal.org.chromium.build.annotations.IdentifierNameString *;
}

# Mark fields with this to help R8 figure out that they cannot be null.
# Use assumevalues in addition to assumenosideeffects block because Google3 proguard cannot parse
# assumenosideeffects blocks which overwrite return value.
-assumevalues class ** {
  @internal.org.chromium.build.annotations.OptimizeAsNonNull *** *(...) return _NONNULL_;
}
-assumenosideeffects class ** {
  @internal.org.chromium.build.annotations.OptimizeAsNonNull *** *(...);
}
-assumevalues class ** {
  @internal.org.chromium.build.annotations.OptimizeAsNonNull *** * return _NONNULL_;
}
-assumenosideeffects class ** {
  @internal.org.chromium.build.annotations.OptimizeAsNonNull *** *;
}
# -------- Config Path: components/cronet/android/cronet_shared_proguard.cfg --------
# Proguard config for apps that depend on cronet_shared_java.jar (which should
# be all apps that depend on any part of Cronet)

# Part of the Android System SDK, so ProGuard won't be able to resolve it if
# running against the standard SDK.
-dontwarn android.util.StatsEvent
-dontwarn android.util.StatsEvent$*
# There is also an undefined reference to android.util.StatsLog.write(), which
# R8 appears to be fine with but other processors (e.g. internal Google
# ProGuard) may not be. See b/315269496.
-dontwarn android.util.StatsLog

# These annotations are only used by the jni_zero code generator, and are not
# needed at runtime. There are cases where we can end up shipping classes that
# have @CalledByNative methods, but we don't ship jni_zero because there is no
# native code; for example, CronetMetrics when called by the Java/fallback
# Cronet impl (as opposed to the native impl). See also
# https://crbug.com/445372626.
-dontwarn internal.org.jni_zero.CalledByNative
-dontwarn internal.org.jni_zero.JNINamespace

# Sadly missing from //third_party/android_deps:protobuf_lite_runtime_java. See
# https://crbug.com/40704600.
# Note: this won't affect the user's protobuf because we rename our protobuf
# classes before shipping them (and these rules are automatically renamed too).
# See _cronet_repackage_rules in BUILD.gn.
-dontwarn org.chromium.net.internal.com.google.protobuf.Any
-dontwarn org.chromium.net.internal.com.google.protobuf.Any$Builder
# -------- Config Path: third_party/protobuf/java/lite/proguard.pgcfg --------
# Keep the annotations that proguard needs to process.
-keep @org.chromium.net.internal.com.google.protobuf.DoNotInline class *

# Allow the method to be shrunk if unused and obfuscated even it it is used.
-keepclassmembers,allowshrinking,allowobfuscation class * {
    @org.chromium.net.internal.com.google.protobuf.DoNotInline *;
}

# Skip runtime check for isOnAndroidDevice().
# One line to make it easy to remove with sed.
-assumevalues class org.chromium.net.internal.com.google.protobuf.Android { static boolean ASSUME_ANDROID return true; }

-keepclassmembers class * extends org.chromium.net.internal.com.google.protobuf.GeneratedMessageLite {
  <fields>;
}
