# ===============================
# Android远程控制APK加密防反编译配置
# ===============================

# 基础配置
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-verbose
-dontoptimize
-dontpreverify

# 保持注解
-keepattributes *Annotation*
-keepattributes Signature
-keepattributes SourceFile,LineNumberTable
-keepattributes InnerClasses
-keepattributes EnclosingMethod

# 保持Activity和Service的基本结构
-keep public class * extends android.app.Activity
-keep public class * extends android.app.Service
-keep public class * extends android.content.BroadcastReceiver
-keep public class * extends android.content.ContentProvider
-keep public class * extends android.app.backup.BackupAgentHelper
-keep public class * extends android.preference.Preference
-keep public class * extends android.view.View

# 保持无障碍服务的关键方法
-keep class com.hikoncont.service.AccessibilityRemoteService {
    public <methods>;
    private <methods>;
}

# 保持所有服务类和管理器类
-keep class com.hikoncont.service.** { *; }
-keep class com.hikoncont.manager.** { *; }
-keep class com.hikoncont.network.** { *; }
-keep class com.hikoncont.util.** { *; }
-keep class com.hikoncont.security.** { *; }

# ✅ 保持日志记录相关类（关键修复）
-keep class com.hikoncont.service.modules.LoggingManager { *; }
-keep class com.hikoncont.OperationLogCollector { *; }
-keepclassmembers class com.hikoncont.service.modules.LoggingManager {
    public <methods>;
    private <methods>;
}
-keepclassmembers class com.hikoncont.OperationLogCollector {
    public <methods>;
    private <methods>;
}

# 保持Socket.IO相关类
-keep class io.socket.** { *; }
-keep class okhttp3.** { *; }
-keep class okio.** { *; }

# 保持JSON相关类
-keep class org.json.** { *; }

# 保持Kotlin相关
-keep class kotlin.** { *; }
-keep class kotlinx.** { *; }
-dontwarn kotlin.**
-dontwarn kotlinx.**

# 保持MainActivity的关键方法
-keep class com.hikoncont.MainActivity {
    public <methods>;
    private void updateStatusTextSafely(java.lang.String, java.lang.Integer);
}

# 保持枚举类
-keepclassmembers enum * {
    public static **[] values();
    public static ** valueOf(java.lang.String);
}

# 保持Parcelable
-keep class * implements android.os.Parcelable {
    public static final android.os.Parcelable$Creator *;
}

# 保持Serializable
-keepnames class * implements java.io.Serializable
-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();
}

# 保持反射相关的类和方法
-keepclassmembers class * {
    @android.webkit.JavascriptInterface <methods>;
}

# 保持WebView相关
-keepclassmembers class fqcn.of.javascript.interface.for.webview {
    public *;
}

# 混淆配置 - 适度混淆
-overloadaggressively
-repackageclasses 'o'
-allowaccessmodification
-flattenpackagehierarchy

# 🔇 移除所有日志输出 - 仅在release和enhancement版本中生效
-assumenosideeffects class android.util.Log {
    public static boolean isLoggable(java.lang.String, int);
    public static int v(...);
    public static int d(...);
    public static int i(...);
    public static int w(...);
    public static int e(...);
    public static int wtf(...);
}

# 移除System.out.println
-assumenosideeffects class java.lang.System {
    public static void out.println(...);
    public static void err.println(...);
}

# 保持反调试和加密类
-keep class com.hikoncont.security.** { *; }
-keep class com.hikoncont.util.StringEncryption { *; }
-keep class com.hikoncont.util.ConfigEncryption { *; }

# 保持关键服务的监听器接口
-keep interface com.hikoncont.service.** { *; }

# 保持协程相关
-keep class kotlinx.coroutines.** { *; }
-dontwarn kotlinx.coroutines.**

# 混淆类名但保持功能
-keepclasseswithmembernames class * {
    native <methods>;
}

# 保持自定义View的构造方法
-keepclasseswithmembers class * {
    public <init>(android.content.Context, android.util.AttributeSet);
}

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

# 保持Activity的生命周期方法
-keepclassmembers class * extends android.app.Activity {
    public void *(android.view.View);
}

# 保持R类
-keep class **.R$* {
    *;
}

# 适度的资源文件名混淆
-adaptresourcefilenames **.png,**.jpg,**.jpeg,**.gif
-adaptresourcefilecontents **.xml

# 控制流混淆
-obfuscationdictionary proguard-dict.txt
-classobfuscationdictionary proguard-dict.txt
-packageobfuscationdictionary proguard-dict.txt

# 保持构建配置相关
-keepclassmembers class **.BuildConfig {
    public static final <fields>;
}

# 警告处理
-dontwarn javax.annotation.**
-dontwarn javax.inject.**
-dontwarn sun.misc.Unsafe
-dontwarn com.google.errorprone.annotations.** 