Skip to content

Commit

Permalink
opt: 重写模块底层逻辑
Browse files Browse the repository at this point in the history
  • Loading branch information
HChenX committed Dec 2, 2024
1 parent 9e06f92 commit 7714c54
Show file tree
Hide file tree
Showing 111 changed files with 488 additions and 523 deletions.
41 changes: 37 additions & 4 deletions app/processor/src/main/java/com/hchen/database/HookBase.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,51 @@
/*
* This file is part of HyperCeiler.
* HyperCeiler is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
* Copyright (C) 2023-2024 HyperCeiler Contributions
*/
package com.hchen.database;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* @author 焕晨HChen
*/
@Retention(RetentionPolicy.SOURCE)
@Target(ElementType.TYPE)
public @interface HookBase {
String pkg();
/*
* 目标作用域
* */
String targetPackage();

boolean isPad();
/*
* 目标安卓版本
* */
int targetSdk() default -1;

int tarSdkVersion();
/*
* 目标 ROM 版本
* */
float targetOSVersion() default -1F;

boolean skip() default false;
/*
* 是否是 pad 专属
* */
boolean isPad() default false;
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
/*
* This file is part of HyperCeiler.
* HyperCeiler is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
* Copyright (C) 2023-2024 HyperCeiler Contributions
*/
package com.hchen.database;

import com.google.auto.service.AutoService;
Expand All @@ -16,6 +34,9 @@
import javax.lang.model.element.Element;
import javax.lang.model.element.TypeElement;

/**
* @author 焕晨HChen
*/
@AutoService(Processor.class)
@SupportedAnnotationTypes("com.hchen.database.HookBase")
@SupportedSourceVersion(SourceVersion.RELEASE_21)
Expand All @@ -29,46 +50,69 @@ public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment
delayedOutput();
try (Writer writer = processingEnv.getFiler().createSourceFile("com.sevtinge.hyperceiler.module.base.DataBase").openWriter()) {
writer.write("""
/*
* This file is part of HyperCeiler.
* HyperCeiler is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
* Copyright (C) 2023-2024 HyperCeiler Contributions
*/
package com.sevtinge.hyperceiler.module.base;
import java.util.HashMap;
/**
* 注解处理器自动生成的 Map 图
*
* @author 焕晨HChen
*/
public class DataBase {
public static class DataHelper {
public String fullName;
public int android;
public boolean isPad;
public boolean skip;
public DataHelper(String fullName,int android,boolean isPad,boolean skip){
this.fullName = fullName;
this.android = android;
this.isPad = isPad;
this.skip = skip;
}
public String mTargetPackage;
public int mTargetSdk;
public float mTargetOSVersion;
public boolean isPad;
public DataBase(String targetPackage, int targetSdk, float targetOSVersion, boolean isPad){
this.mTargetPackage = targetPackage;
this.mTargetSdk = targetSdk;
this.mTargetOSVersion = targetOSVersion;
this.isPad = isPad;
}
public static MultiValueMap<String, DataHelper> get() {
MultiValueMap<String, DataHelper> dataMap = new MultiValueMap<>();
public static HashMap<String, DataBase> get() {
HashMap<String, DataBase> dataMap = new HashMap<>();
""");
roundEnv.getElementsAnnotatedWith(HookBase.class).forEach(new Consumer<Element>() {
@Override
public void accept(Element element) {
String fullClassName = null;
if (element instanceof TypeElement typeElement) {
fullClassName = getFullClassName(typeElement);
fullClassName = typeElement.getQualifiedName().toString();
// System.out.println("Full class name: " + fullClassName);
}
if (fullClassName == null) {
System.out.println("W: Full class name is null!!!");
}
HookBase hookBase = element.getAnnotation(HookBase.class);
String pkg = hookBase.pkg();
int android = hookBase.tarSdkVersion();
String targetPackage = hookBase.targetPackage();
int targetSdk = hookBase.targetSdk();
float targetOSVersion = hookBase.targetOSVersion();
boolean isPad = hookBase.isPad();
boolean skip = hookBase.skip();
try {
writer.write(" ");
writer.write("dataMap.put(\"" + pkg + "\", new DataHelper(\"" + fullClassName + "\", "
+ android + ", " + isPad + ", " + skip + "));\n");
writer.write("dataMap.put(\"" + fullClassName + "\", new DataBase(\"" + targetPackage + "\", "
+ targetSdk + ", " + targetOSVersion + "F, " + isPad + "));\n");
} catch (IOException e) {
e.printStackTrace();
}
Expand All @@ -77,7 +121,6 @@ public void accept(Element element) {
writer.write("""
return dataMap;
}
}
""");
} catch (IOException e) {
Expand All @@ -86,10 +129,6 @@ public void accept(Element element) {
return true;
}

private String getFullClassName(TypeElement typeElement) {
return typeElement.getQualifiedName().toString();
}

/*
________ ___ ___ ________ ________ ___ ___
|\ _____\|\ \|\ \ |\ __ \ |\ __ \ |\ \ / /|
Expand Down Expand Up @@ -119,7 +158,7 @@ private void delayedOutput() {
System.out.println(BLUE + " \\|__| \\|_______| \\|__|\\|__| \\|__|\\|__||\\___/ / " + RESET);
System.out.println(BLUE + " \\|___|/ " + RESET);
System.out.println(BLUE + " " + RESET);
System.out.println(BLUE + " Code By HyperCeiler Contributors " + RESET);
System.out.println(BLUE + " Code By 焕晨HChen " + RESET); // 别改谢谢
}

}
26 changes: 13 additions & 13 deletions app/src/main/java/com/sevtinge/hyperceiler/Application.java
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
/*
* This file is part of HyperCeiler.
* This file is part of HyperCeiler.
* HyperCeiler is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License.
* HyperCeiler is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
* Copyright (C) 2023-2024 HyperCeiler Contributions
*/
* Copyright (C) 2023-2024 HyperCeiler Contributions
*/
package com.sevtinge.hyperceiler;

import android.content.Context;
Expand Down
Loading

0 comments on commit 7714c54

Please sign in to comment.