|
|
@@ -42,6 +42,12 @@ public class AppVersionService {
|
|
|
|
/// 内置包版本标识
|
|
|
|
/// 内置包版本标识
|
|
|
|
public static final String BUILTIN_VERSION = "builtin";
|
|
|
|
public static final String BUILTIN_VERSION = "builtin";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// 首个能处理外壳安装包的 Web 包版本
|
|
|
|
|
|
|
|
///
|
|
|
|
|
|
|
|
/// 更早的包不认识 shell 标记,只会把 url 当热更 zip 交给插件解压,拿到 APK 必然失败。
|
|
|
|
|
|
|
|
/// 通道指向原生包时,低于这个版本的设备改为下发热更包,先把它升到能自升级为止
|
|
|
|
|
|
|
|
public static final String SHELL_AWARE_VERSION = "1.3.2";
|
|
|
|
|
|
|
|
|
|
|
|
/// 更新日志最多返回的版本条数
|
|
|
|
/// 更新日志最多返回的版本条数
|
|
|
|
public static final int MAX_NOTES = 20;
|
|
|
|
public static final int MAX_NOTES = 20;
|
|
|
|
|
|
|
|
|
|
|
@@ -72,10 +78,17 @@ public class AppVersionService {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
int currentCode = parseInt(req.getVersionCode(), 0);
|
|
|
|
int currentCode = parseInt(req.getVersionCode(), 0);
|
|
|
|
if (release.getKind() == AppRelease.Kind.NATIVE) {
|
|
|
|
if (release.getKind() == AppRelease.Kind.NATIVE) {
|
|
|
|
AppRelease target = resolveNative(release, currentCode);
|
|
|
|
// 低于外壳升级能力的包拿不动安装包,先补热更,否则它会把 APK 当 zip 解
|
|
|
|
return target == null
|
|
|
|
boolean shellAware = 0 <= compareVersion(currentVersion, SHELL_AWARE_VERSION);
|
|
|
|
|
|
|
|
AppRelease nativeTarget = shellAware ? resolveNative(release, currentCode) : null;
|
|
|
|
|
|
|
|
if (nativeTarget != null) {
|
|
|
|
|
|
|
|
return buildResponse(nativeTarget, Boolean.TRUE.equals(nativeTarget.getMandatory()), true);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// 装不了安装包,或壳已经是最新:热更不能因为通道被原生包占着就断流
|
|
|
|
|
|
|
|
AppRelease bundle = resolveLatestBundle(product, currentCode, currentVersion, req.getDeviceId());
|
|
|
|
|
|
|
|
return bundle == null
|
|
|
|
? AppUpdateCheckResponse.none(currentVersion)
|
|
|
|
? AppUpdateCheckResponse.none(currentVersion)
|
|
|
|
: buildResponse(target, Boolean.TRUE.equals(target.getMandatory()), true);
|
|
|
|
: buildResponse(bundle, false, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
AppRelease target = resolveBundle(release, product, currentCode, currentVersion, req.getDeviceId());
|
|
|
|
AppRelease target = resolveBundle(release, product, currentCode, currentVersion, req.getDeviceId());
|
|
|
|
return target == null
|
|
|
|
return target == null
|
|
|
@@ -101,8 +114,11 @@ public class AppVersionService {
|
|
|
|
return new AppUpdateNotesResponse(null, Collections.emptyList());
|
|
|
|
return new AppUpdateNotesResponse(null, Collections.emptyList());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
AppRelease target = resolveChannelRelease(product, req);
|
|
|
|
AppRelease target = resolveChannelRelease(product, req);
|
|
|
|
// 原生包更新走安装包,与热更日志无关
|
|
|
|
// 安装包不属于更新日志:通道指向原生包时,改用最新发布的热更包做上界
|
|
|
|
if (target == null || target.getKind() == AppRelease.Kind.NATIVE) {
|
|
|
|
if (target == null || target.getKind() == AppRelease.Kind.NATIVE) {
|
|
|
|
|
|
|
|
target = latestPublishedBundle(product);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (target == null) {
|
|
|
|
return new AppUpdateNotesResponse(null, Collections.emptyList());
|
|
|
|
return new AppUpdateNotesResponse(null, Collections.emptyList());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// 当前版本不低于通道版本:已是最新,或回滚后反而超前
|
|
|
|
// 当前版本不低于通道版本:已是最新,或回滚后反而超前
|
|
|
@@ -217,6 +233,62 @@ public class AppVersionService {
|
|
|
|
return release;
|
|
|
|
return release;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// 查询设备此刻可用的最新热更包
|
|
|
|
|
|
|
|
///
|
|
|
|
|
|
|
|
/// 通道指向原生包时用它兜底:通道是单指针,原生包一上线热更就停发,
|
|
|
|
|
|
|
|
/// 而低于 SHELL_AWARE_VERSION 的设备又拿不动安装包,只能靠这里把它先升上去。
|
|
|
|
|
|
|
|
/// 只认 PUBLISHED 且版本高于当前包的记录,不会降级,最坏情况是多升一次。
|
|
|
|
|
|
|
|
///
|
|
|
|
|
|
|
|
/// @param product 产品
|
|
|
|
|
|
|
|
/// @param currentCode 当前原生 versionCode
|
|
|
|
|
|
|
|
/// @param currentVersion 当前 Web 包版本
|
|
|
|
|
|
|
|
/// @param deviceId 设备标识
|
|
|
|
|
|
|
|
/// @return 可用热更包,没有则返回 null
|
|
|
|
|
|
|
|
private AppRelease resolveLatestBundle(
|
|
|
|
|
|
|
|
AppProduct product,
|
|
|
|
|
|
|
|
int currentCode,
|
|
|
|
|
|
|
|
String currentVersion,
|
|
|
|
|
|
|
|
String deviceId
|
|
|
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
AppRelease latest = null;
|
|
|
|
|
|
|
|
for (AppRelease item : releaseMapper.selectPublished(product.getId(), AppRelease.Kind.BUNDLE)) {
|
|
|
|
|
|
|
|
if (item.getMinVersionCode() != null && currentCode < item.getMinVersionCode()) {
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (item.getMaxVersionCode() != null && item.getMaxVersionCode() < currentCode) {
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// 同级或更低不下发,避免把设备降回去
|
|
|
|
|
|
|
|
if (0 >= compareVersion(item.getVersionName(), currentVersion)) {
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!hitGray(item.getGrayPermille(), deviceId, product.getAppKey())) {
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (latest == null || 0 < compareVersion(item.getVersionName(), latest.getVersionName())) {
|
|
|
|
|
|
|
|
latest = item;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return latest;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// 取最近一次发布的热更包
|
|
|
|
|
|
|
|
///
|
|
|
|
|
|
|
|
/// 通道指向原生包时,更新日志没有「通道版本」可用,改用这里兜底。
|
|
|
|
|
|
|
|
/// 日志是「这个产品最近发了什么」,与设备能不能装无关,所以不套灰度与兼容区间
|
|
|
|
|
|
|
|
///
|
|
|
|
|
|
|
|
/// @param product 产品
|
|
|
|
|
|
|
|
/// @return 版本最高的已发布热更包,没有则返回 null
|
|
|
|
|
|
|
|
private AppRelease latestPublishedBundle(AppProduct product) {
|
|
|
|
|
|
|
|
AppRelease latest = null;
|
|
|
|
|
|
|
|
for (AppRelease item : releaseMapper.selectPublished(product.getId(), AppRelease.Kind.BUNDLE)) {
|
|
|
|
|
|
|
|
if (latest == null || 0 < compareVersion(item.getVersionName(), latest.getVersionName())) {
|
|
|
|
|
|
|
|
latest = item;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return latest;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// 判断设备是否命中灰度
|
|
|
|
/// 判断设备是否命中灰度
|
|
|
|
///
|
|
|
|
///
|
|
|
|
/// @param grayPermille 灰度比例,万分比
|
|
|
|
/// @param grayPermille 灰度比例,万分比
|
|
|
|