Files
mdm/src/main/java/com/midm/model/file/AppFile.java
T
rick 10aa1829f5 fix: repair decompiled sources and add exhaustive documentation
- restore generic signatures, scoped variables and missing code from original bytecode
- remove decompiler artifacts and document classes, methods, fields and packages
- restore resources, add Batik/BouncyCastle dependencies and build/runtime docs
2026-11-16 17:28:23 +08:00

452 lines
12 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package com.midm.model.file;
import com.google.api.client.util.Strings;
import com.google.gson.annotations.Expose;
import com.midm.model.org.User;
import com.mitac.cell.db.DbObject;
import com.mitac.cell.io.McApkFile;
import com.mitac.cell.io.McFile;
import java.util.List;
import java.util.UUID;
import net.dongliu.apk.parser.bean.ApkMeta;
import org.springframework.data.annotation.Transient;
import org.springframework.data.mongodb.core.mapping.Document;
/**
* 【MongoDB 文档实体】{@code AppFile}
*
* 类职责:
* <ul>
* <li>作为 MongoDB 集合文档,承载该领域对象的持久化字段与索引。</li>
* <li>通过字段/依赖注入持有运行期状态,字段含义见下方“核心字段”。</li>
* </ul>
*
* 核心字段(按声明顺序):
* <ul>
* <li>{@code appInfo}(DbObject):应用信息</li>
* <li>{@code updateOptions}(DbObject):更新选项列表</li>
* <li>{@code generateIcon}(boolean):生成Icon</li>
* </ul>
*
* 协作对象:{@code DbObject}。
*
* 持久化/框架标记:{@code @Document} 映射为 MongoDB 集合。
*
* 学习提示:先看字段与 @Field/@Indexed,再看对应 Service/Repository 如何构造查询条件。
*/
@Document
public class AppFile extends BaseFile {
/**
* 应用信息。
*/
private DbObject appInfo;
/**
* 更新选项列表。
*/
private DbObject updateOptions;
/**
* 生成Icon;不持久化到 MongoDB,仅运行时使用;Gson 序列化控制。
*
* 注解:{@code @Transient @Expose(serialize = false)}。
*/
@Transient
@Expose(
serialize = false
)
private boolean generateIcon;
/**
* 构造 {@code AppFile} 实例。
* 使用默认字段值,后续通常由 Spring/Mongo 或调用方填充。
*/
public AppFile() {
this.generateIcon = true;
}
/**
* 构造 {@code AppFile} 实例。
*
* @param user 当前用户({@code User})
* @param fileUuid 文件 UUID({@code UUID})
* @param file 文件({@code McFile})
*/
public AppFile(User user, UUID fileUuid, McFile file) {
this(user, fileUuid, file, true);
}
/**
* 构造 {@code AppFile} 实例。
*
* @param user 当前用户({@code User})
* @param fileUuid 文件 UUID({@code UUID})
* @param file 文件({@code McFile})
* @param generateIcon 参数 {@code generateIcon}({@code boolean})
*/
public AppFile(User user, UUID fileUuid, McFile file, boolean generateIcon) {
super(user, fileUuid, file);
this.generateIcon = true;
this.generateIcon = generateIcon;
this.setAppInfo(file);
}
/**
* 判断 {@code apk}。
* @return 字段/派生属性 {@code apk} 的值
*/
public boolean isApk() {
return !Strings.isNullOrEmpty(this.getPackageName());
}
/**
* 判断 {@code systemPermission}。
* @return 字段/派生属性 {@code systemPermission} 的值
*/
public boolean hasSystemPermission() {
return "android.uid.system".equals(this.getSharedUserId());
}
/**
* 获取 {@code appInfo}。
*
* 实现要点:包含 1 个条件分支、0 个循环;主要调用:new DbObject。
* @return MongoDB 文档扩展对象
*/
public DbObject getAppInfo() {
if (this.appInfo == null) {
this.appInfo = new DbObject();
}
return this.appInfo;
}
/**
* 设置 {@code appInfo}。
*
* @param appInfo 参数 {@code appInfo}({@code DbObject})
*/
public void setAppInfo(DbObject appInfo) {
this.appInfo = appInfo;
}
/**
* 设置应用信息。
*
* @param key 键/配置项({@code String})
* @param value 值({@code Object})
*/
public void setAppInfo(String key, Object value) {
this.getAppInfo().append(key, value);
}
/**
* 获取 {@code updateOptions}。
*
* 实现要点:包含 1 个条件分支、0 个循环;主要调用:new DbObject。
* @return MongoDB 文档扩展对象
*/
public DbObject getUpdateOptions() {
if (this.updateOptions == null) {
this.updateOptions = new DbObject();
}
return this.updateOptions;
}
/**
* 设置 {@code updateOptions}。
*
* @param updateOptions 参数 {@code updateOptions}({@code DbObject})
*/
public void setUpdateOptions(DbObject updateOptions) {
this.updateOptions = updateOptions;
}
/**
* 设置更新选项列表。
*
* @param key 键/配置项({@code String})
* @param value 值({@code Object})
*/
public void setUpdateOptions(String key, Object value) {
this.getUpdateOptions().append(key, value);
}
/**
* 判断 {@code mitacApp}。
* @return 字段/派生属性 {@code mitacApp} 的值
*/
public boolean isMitacApp() {
return this.getPackageName().toLowerCase().contains("mitac");
}
/**
* 获取 {@code packageName}。
* @return 字符串结果
*/
public String getPackageName() {
return this.getAppInfo().getString("packageName");
}
/**
* 设置 {@code packageName}。
*
* @param packageName 参数 {@code packageName}({@code String})
*/
public void setPackageName(String packageName) {
this.setAppInfo("packageName", packageName);
}
/**
* 获取 {@code sharedUserId}。
* @return 字符串结果
*/
public String getSharedUserId() {
return this.getAppInfo().getString("sharedUid");
}
/**
* 设置 {@code sharedUserId}。
*
* 实现要点:包含 1 个条件分支、0 个循环。
*
* @param sharedUid 参数 {@code sharedUid}({@code String})
*/
public void setSharedUserId(String sharedUid) {
if (!Strings.isNullOrEmpty(sharedUid)) {
this.setAppInfo("sharedUid", sharedUid);
}
}
/**
* 获取 {@code label}。
* @return 字符串结果
*/
public String getLabel() {
return this.getAppInfo().getString("label");
}
/**
* 设置 {@code label}。
*
* @param label 参数 {@code label}({@code String})
*/
public void setLabel(String label) {
this.setAppInfo("label", label);
}
/**
* 获取 {@code iconName}。
* @return 字符串结果
*/
public String getIconName() {
return this.getAppInfo().getString("iconName");
}
/**
* 设置 {@code iconName}。
*
* @param iconName 参数 {@code iconName}({@code String})
*/
public void setIconName(String iconName) {
this.setAppInfo("iconName", iconName);
}
/**
* 获取 {@code versionCode}。
* @return 数量/长度
*/
public long getVersionCode() {
return this.getAppInfo().getLong("versionCode");
}
/**
* 设置 {@code versionCode}。
*
* @param versionCode 参数 {@code versionCode}({@code long})
*/
public void setVersionCode(long versionCode) {
this.setAppInfo("versionCode", versionCode);
}
/**
* 获取 {@code versionName}。
* @return 字符串结果
*/
public String getVersionName() {
return this.getAppInfo().getString("versionName");
}
/**
* 设置 {@code versionName}。
*
* @param versionName 参数 {@code versionName}({@code String})
*/
public void setVersionName(String versionName) {
this.setAppInfo("versionName", versionName);
}
/**
* 获取 {@code minSdkVersion}。
* @return 数量/长度
*/
public int getMinSdkVersion() {
return this.getAppInfo().getInteger("minSdkVersion", -1);
}
/**
* 设置 {@code minSdkVersion}。
*
* 实现要点:包含 1 个条件分支、0 个循环。
*
* @param minSdkVersion 参数 {@code minSdkVersion}({@code String})
*/
public void setMinSdkVersion(String minSdkVersion) {
if (!Strings.isNullOrEmpty(minSdkVersion)) {
this.setMinSdkVersion(Integer.parseInt(minSdkVersion));
}
}
/**
* 设置 {@code minSdkVersion}。
*
* @param minSdkVersion 参数 {@code minSdkVersion}({@code int})
*/
public void setMinSdkVersion(int minSdkVersion) {
this.setAppInfo("minSdkVersion", minSdkVersion);
}
/**
* 获取 {@code maxSdkVersion}。
* @return 数量/长度
*/
public int getMaxSdkVersion() {
return this.getAppInfo().getInteger("maxSdkVersion", -1);
}
/**
* 设置 {@code maxSdkVersion}。
*
* 实现要点:包含 1 个条件分支、0 个循环。
*
* @param maxSdkVersion 参数 {@code maxSdkVersion}({@code String})
*/
public void setMaxSdkVersion(String maxSdkVersion) {
if (!Strings.isNullOrEmpty(maxSdkVersion)) {
this.setAppInfo("maxSdkVersion", Integer.parseInt(maxSdkVersion));
}
}
/**
* 获取 {@code targetSdkVersion}。
* @return 数量/长度
*/
public int getTargetSdkVersion() {
return this.getAppInfo().getInteger("targetSdkVersion", -1);
}
/**
* 设置 {@code targetSdkVersion}。
*
* 实现要点:包含 1 个条件分支、0 个循环。
*
* @param targetSdkVersion 参数 {@code targetSdkVersion}({@code String})
*/
public void setTargetSdkVersion(String targetSdkVersion) {
if (Strings.isNullOrEmpty(targetSdkVersion)) {
this.getAppInfo().remove("targetSdkVersion");
} else {
this.setAppInfo("targetSdkVersion", Integer.parseInt(targetSdkVersion));
}
}
/**
* 获取 {@code userPermission}。
* @return String列表,可能为空
*/
public List<String> getUserPermission() {
return this.getAppInfo().getList("userPermission", String.class);
}
/**
* 设置 {@code userPermission}。
*
* @param userPermission 参数 {@code userPermission}({@code List<String>})
*/
public void setUserPermission(List<String> userPermission) {
this.setAppInfo("userPermission", userPermission);
}
/**
* 获取 {@code certMd5}。
* @return 字符串结果
*/
public String getCertMd5() {
return this.getAppInfo().getString("certMd5");
}
/**
* 设置 {@code certMd5}。
*
* 实现要点:包含 1 个条件分支、0 个循环。
*
* @param certMd5 参数 {@code certMd5}({@code String})
*/
public void setCertMd5(String certMd5) {
if (!Strings.isNullOrEmpty(certMd5)) {
this.setAppInfo("certMd5", certMd5);
}
}
/**
* 设置 {@code appInfo}。
*
* 实现要点:包含异常捕获与降级/回滚分支;包含 2 个条件分支、0 个循环;主要调用:new McApkFile、close。
*
* @param file 文件({@code McFile})
*/
public void setAppInfo(McFile file) {
try {
McApkFile apkFile = new McApkFile(file);
ApkMeta meta = apkFile.getApkMeta();
this.setSharedUserId(meta.getSharedUserId());
this.setPackageName(meta.getPackageName());
String label = meta.getLabel();
if (Strings.isNullOrEmpty(label)) {
label = meta.getPackageName();
}
this.setLabel(label);
this.setVersionCode(meta.getVersionCode());
this.setVersionName(meta.getVersionName());
this.setUserPermission(meta.getUsesPermissions());
this.setMinSdkVersion(meta.getMinSdkVersion());
this.setMaxSdkVersion(meta.getMaxSdkVersion());
this.setTargetSdkVersion(meta.getTargetSdkVersion());
this.setCertMd5(apkFile.getCertMd5());
this.setName(this.getLabel());
if (this.generateIcon) {
apkFile.saveIcon(file.getPath() + ".png");
}
apkFile.close();
} catch (Exception var5) {
}
}
/**
* 处理minify。
*/
public void minify() {
super.minify();
this.setUserPermission((List)null);
this.setTargetSdkVersion((String)null);
this.setVersionName((String)null);
}
}