# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in /Users/btang/sdk/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
#   http://developer.android.com/guide/developing/tools/proguard.html

# Add any project specific keep options here:

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
#   public *;
#}

-dontshrink

# Multiple passes may result in further improvements
-optimizationpasses 5

# Specifies not to generate mixed-case class names while obfuscating
-dontusemixedcaseclassnames

# Specifies not to ignore non-public library classes. As of version 4.5, this is the default setting
-dontskipnonpubliclibraryclasses

# Specifies not to ignore package visible library class members (fields and methods).
-dontskipnonpubliclibraryclassmembers

# Specifies not to preverify the processed class files
-dontpreverify

# Prints stack trace in case of exception
-verbose

# code/simplification/arithmetic - Performs peephole optimizations for arithmetic instructions.
# !field/* - Don't perform field optimizations
# !class/merging/* - Don't merge classes vertical nor horizontal
# !code/allocation/variable - Don't optimize variable allocation on the local variable frame.
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*,!code/allocation/variable

# Keep classes extending from Activity, Like BoxPreviewActivity
-keep public class * extends android.app.Activity

# This keeps View classes, like BoxTransferProgressBar
-keepclasseswithmembers class * {
    public <init>(android.content.Context, android.util.AttributeSet);
}

# This keeps View classes
-keepclasseswithmembers class * {
    public <init>(android.content.Context, android.util.AttributeSet, int);
}

# This keeps View classes
-keepclassmembers class * extends android.app.Activity {
    public void *(android.view.View);
}

####
## Box Preview SDK
####

# This keeps all preview-sdk public classes with it's properties
-keep  class com.box.androidsdk.preview.** {
    public protected *;
    private void writeObject(java.io.ObjectOutputStream);
    private void readObject(java.io.ObjectInputStream);
    java.lang.Object writeReplace();
    java.lang.Object readResolve();
    static final long serialVersionUID;
}

# This keeps preview R class
-keep class com.box.androidsdk.preview.R { *; }

####
## PSPDFKit related
####

# Keep PSPDFKit framework classes – they are already proguarded by default.
-keep class com.pspdfkit.framework.** { *; }
-keep class com.pspdfkit.datastructures.Range { *; }
-keep class com.pspdfkit.exceptions.** { *; }
-keep class com.pspdfkit.undo.exceptions** { *; }
-keep class com.pspdfkit.utils.** { *; }

# Keep PSPDFKit Instant framework classes – they are already proguarded by default.
-keep class com.pspdfkit.instant.framework.** { *; }
-keep class com.pspdfkit.instant.exceptions.** { *; }
-keep class com.pspdfkit.instant.ui.** { *; }

-keepparameternames
-renamesourcefileattribute SourceFile
-keepattributes Exceptions
-keepattributes InnerClasses
-keepattributes Signature
-keepattributes Deprecated
-keepattributes SourceFile
-keepattributes LineNumberTable
-keepattributes *Annotation*
-keepattributes EnclosingMethod

# Preserve all .class method names.
-keepclassmembernames class * {
    java.lang.Class class$(java.lang.String);
    java.lang.Class class$(java.lang.String, boolean);
}

# Preserve all native method names and the names of their classes.
-keepclasseswithmembernames,includedescriptorclasses class * {
    native <methods>;
}

# Preserve the special static methods that are required in all enumeration classes.
-keepclassmembers,allowoptimization enum * {
    public static **[] values(); public static ** valueOf(java.lang.String);
}

# Explicitly preserve all serialization members. The Serializable interface
# is only a marker interface, so it wouldn't save them.
-keepclassmembers class * implements java.io.Serializable {
    static final long serialVersionUID;
    private static final java.io.ObjectStreamField[] serialPersistentFields;
    private void writeObject(java.io.ObjectOutputStream);
    private void readObject(java.io.ObjectInputStream);
    java.lang.Object writeReplace();
    java.lang.Object readResolve();
}

# Explicitly preseve all parcelation members.
-keepclassmembers class * implements android.os.Parcelable {
    public static final ** CREATOR;
}

# Preseve classes/methods/fields with keep annotation
-keep class androidx.annotation.Keep

-keep @androidx.annotation.Keep class * {*;}

-keepclasseswithmembers class * {
    @androidx.annotation.Keep <methods>;
}

-keepclasseswithmembers class * {
    @androidx.annotation.Keep <fields>;
}

-keepclasseswithmembers class * {
    @androidx.annotation.Keep <init>(...);
}

# RxJava is used by PSPDFKit and needs these lines for proper operation.
-keep class rx.internal.util.unsafe.** { *; }
-keepnames class io.reactivex.android.schedulers.AndroidSchedulers
-keepnames class io.reactivex.Observable
# API 19 specific rules
-keep class io.reactivex.subjects.ReplaySubject { *; }
-keep class io.reactivex.processors.BehaviorProcessor { *; }

# Optional third party libraries. You can safely ignore those warnings.
-dontwarn com.pspdfkit.ui.PdfYouTubeActivity
-dontwarn com.pspdfkit.media.MediaGalleryView*
-dontwarn com.squareup.okhttp.**
-dontwarn com.getkeepsafe.relinker.**
-dontwarn com.facebook.device.yearclass.**
-dontwarn sun.misc.**

# Keep third party lib class names. PSPDFKit relies on those class names to be present.
-keepnames class androidx.cardview.widget.CardView

# OkHttp is used by PSPDFKit Instant and needs these lines for proper operation.
-keep class okhttp3.** { *; }
-dontwarn okio.**
-dontwarn javax.annotation.Nullable
-dontwarn javax.annotation.ParametersAreNonnullByDefault

# AutoValue is used by PSPDFKit and retains its annotations. You can safely ignore those warnings.
-dontwarn com.google.auto.value.AutoValue

# Java 8 is used by PSPDFKit. You can safely ignore those warnings produced by lambdas.
-dontwarn java.lang.invoke.**

####
## AndroidX
####
# Keeps androidx classes used in preview-sdk
-dontwarn androidx.**
-keep class androidx.** { *; }
-keep interface androidx.** { *; }

####
## Kotlin related section
## PSPDFKit seem to have properly obfuscated their Kotlin code, so this is virtually useless
####
-keep class kotlin.** { *; }
-keep class kotlin.Metadata { *; }

-dontwarn kotlin.**
-keepclassmembers class **$WhenMappings {
    <fields>;
}

-keepclassmembers class * {
    static final % *;
    static final java.lang.String *;
}
