react-native-update 10.59.1 → 10.60.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README-CN.md +7 -7
- package/README.md +7 -6
- package/android/build.gradle +25 -33
- package/android/jni/Android.mk +16 -24
- package/android/lib/arm64-v8a/librnpushy.so +0 -0
- package/android/lib/armeabi-v7a/librnpushy.so +0 -0
- package/android/lib/x86/librnpushy.so +0 -0
- package/android/lib/x86_64/librnpushy.so +0 -0
- package/android/proguard.pro +9 -7
- package/android/src/main/java/cn/reactnative/modules/update/ApkInstaller.java +11 -12
- package/android/src/main/java/cn/reactnative/modules/update/ArchiveLimits.java +23 -6
- package/android/src/main/java/cn/reactnative/modules/update/BundledResourceCopier.java +50 -51
- package/android/src/main/java/cn/reactnative/modules/update/CleanupKeepNames.java +12 -13
- package/android/src/main/java/cn/reactnative/modules/update/CopyGroupResult.java +3 -0
- package/android/src/main/java/cn/reactnative/modules/update/CrashHold.java +22 -30
- package/android/src/main/java/cn/reactnative/modules/update/DownloadTask.java +181 -332
- package/android/src/main/java/cn/reactnative/modules/update/DownloadTaskParams.java +3 -1
- package/android/src/main/java/cn/reactnative/modules/update/ErrorCodes.java +27 -0
- package/android/src/main/java/cn/reactnative/modules/update/FileOperationException.java +1 -1
- package/android/src/main/java/cn/reactnative/modules/update/FlowBridge.java +32 -8
- package/android/src/main/java/cn/reactnative/modules/update/HttpClients.java +63 -0
- package/android/src/main/java/cn/reactnative/modules/update/HttpUtils.java +0 -11
- package/android/src/main/java/cn/reactnative/modules/update/InstallRecord.java +66 -116
- package/android/src/main/java/cn/reactnative/modules/update/NativeCore.java +9 -1
- package/android/src/main/java/cn/reactnative/modules/update/PatchFailedException.java +1 -1
- package/android/src/main/java/cn/reactnative/modules/update/PushyRuntime.java +32 -60
- package/android/src/main/java/cn/reactnative/modules/update/ReactReloadManager.java +8 -23
- package/android/src/main/java/cn/reactnative/modules/update/SafeZipFile.java +42 -80
- package/android/src/main/java/cn/reactnative/modules/update/StateSerialRunner.java +22 -39
- package/android/src/main/java/cn/reactnative/modules/update/SyncCoordinator.java +176 -299
- package/android/src/main/java/cn/reactnative/modules/update/Threads.java +35 -0
- package/android/src/main/java/cn/reactnative/modules/update/UpdateContext.java +242 -174
- package/android/src/main/java/cn/reactnative/modules/update/UpdateEventEmitter.java +1 -1
- package/android/src/main/java/cn/reactnative/modules/update/UpdateFileUtils.java +75 -17
- package/android/src/main/java/cn/reactnative/modules/update/{UpdateModuleImpl.java → UpdateModule.java} +113 -95
- package/android/src/main/java/cn/reactnative/modules/update/UpdatePackage.java +16 -19
- package/android/src/oldarch/cn/reactnative/modules/update/NativePushySpec.java +69 -0
- package/cpp/android_jni/archive_limits_jni.cpp +83 -0
- package/cpp/android_jni/install_record_jni.cpp +89 -0
- package/cpp/android_jni/jni_log.h +31 -0
- package/cpp/android_jni/jni_natives.h +40 -0
- package/cpp/android_jni/jni_registration.cpp +133 -0
- package/cpp/android_jni/jni_util.h +160 -0
- package/cpp/android_jni/update_core_android.cpp +450 -0
- package/cpp/android_jni/update_flow_jni.cpp +133 -0
- package/{android/jni → cpp/hpatch}/hpatch.c +5 -5
- package/{android/jni → cpp/hpatch}/hpatch.h +4 -1
- package/cpp/patch_core/archive_limits.cpp +194 -0
- package/cpp/patch_core/archive_limits.h +99 -10
- package/cpp/patch_core/archive_patch_core.cpp +96 -12
- package/cpp/patch_core/archive_patch_core.h +49 -0
- package/cpp/patch_core/digest.h +5 -4
- package/cpp/patch_core/error_codes.h +5 -3
- package/cpp/patch_core/install_record.cpp +430 -0
- package/cpp/patch_core/install_record.h +163 -9
- package/cpp/patch_core/patch_core.cpp +62 -16
- package/cpp/patch_core/patch_core.h +27 -7
- package/cpp/patch_core/patch_manifest.cpp +201 -0
- package/cpp/patch_core/patch_manifest.h +74 -0
- package/cpp/patch_core/state_ops.h +3 -3
- package/cpp/update_flow_core/flow_json.cpp +82 -8
- package/cpp/update_flow_core/flow_json.h +21 -0
- package/cpp/update_flow_core/native_config.cpp +456 -0
- package/cpp/update_flow_core/native_config.h +84 -0
- package/cpp/update_flow_core/native_round.cpp +326 -0
- package/cpp/update_flow_core/native_round.h +90 -0
- package/cpp/update_flow_core/update_flow_core.h +2 -2
- package/harmony/hvigor-plugin.ts +11 -19
- package/harmony/pushy/src/main/cpp/CMakeLists.txt +19 -26
- package/harmony/pushy/src/main/cpp/PushyPackage.h +2 -2
- package/harmony/pushy/src/main/cpp/PushyTurboModule.cpp +55 -94
- package/harmony/pushy/src/main/cpp/pushy.cpp +694 -517
- package/harmony/pushy/src/main/ets/ArchiveLimits.ts +48 -72
- package/harmony/pushy/src/main/ets/DownloadTask.ts +164 -404
- package/harmony/pushy/src/main/ets/DownloadTaskParams.ts +1 -3
- package/harmony/pushy/src/main/ets/ErrorCodes.ts +1 -14
- package/harmony/pushy/src/main/ets/EventHub.ts +1 -1
- package/harmony/pushy/src/main/ets/InstallRecord.ts +52 -151
- package/harmony/pushy/src/main/ets/Logger.ts +20 -34
- package/harmony/pushy/src/main/ets/NativePatchCore.ts +116 -42
- package/harmony/pushy/src/main/ets/PushyConfiguration.ts +8 -85
- package/harmony/pushy/src/main/ets/PushyTurboModule.ts +11 -25
- package/harmony/pushy/src/main/ets/SaveFile.ts +99 -18
- package/harmony/pushy/src/main/ets/SyncCoordinator.ts +136 -335
- package/harmony/pushy/src/main/ets/Texts.ts +0 -4
- package/harmony/pushy/src/main/ets/UpdateContext.ts +106 -119
- package/harmony/pushy.har +0 -0
- package/ios/RCTPushy/RCTPushy+Launch.mm +185 -0
- package/ios/RCTPushy/RCTPushy.h +12 -0
- package/ios/RCTPushy/RCTPushy.mm +87 -2628
- package/ios/RCTPushy/RCTPushyCommon.h +34 -0
- package/ios/RCTPushy/RCTPushyConfiguration.h +0 -8
- package/ios/RCTPushy/RCTPushyConfiguration.mm +40 -121
- package/ios/RCTPushy/RCTPushyDownloader.mm +40 -37
- package/ios/RCTPushy/RCTPushyInstallRecord.mm +61 -0
- package/ios/RCTPushy/RCTPushyInstaller.mm +689 -0
- package/ios/RCTPushy/RCTPushyInternal.h +144 -0
- package/ios/RCTPushy/RCTPushyOrchestrator.mm +1001 -0
- package/ios/RCTPushy/RCTPushyState.mm +314 -0
- package/package.json +25 -23
- package/react-native-update.podspec +74 -83
- package/src/client.ts +361 -451
- package/src/context.ts +1 -1
- package/src/core.ts +35 -8
- package/src/endpoint.ts +0 -2
- package/src/error.ts +13 -32
- package/src/i18n.ts +18 -83
- package/src/locales/en.ts +0 -4
- package/src/locales/zh.ts +0 -4
- package/src/provider.tsx +60 -53
- package/src/telemetry.ts +0 -13
- package/src/type.ts +0 -15
- package/src/updateFlowCore.ts +116 -10
- package/src/utils.ts +49 -42
- package/android/src/main/java/cn/reactnative/modules/update/ArchivePatchPlanResult.java +0 -6
- package/android/src/main/java/cn/reactnative/modules/update/PushyConfiguration.java +0 -104
- package/android/src/main/java/cn/reactnative/modules/update/UiThreadRunner.java +0 -37
- package/android/src/newarch/cn/reactnative/modules/update/UpdateModule.java +0 -121
- package/android/src/oldarch/cn/reactnative/modules/update/UpdateModule.java +0 -125
- package/cpp/patch_core/jni_natives.h +0 -27
- package/cpp/patch_core/jni_registration.cpp +0 -103
- package/cpp/patch_core/jni_util.h +0 -60
- package/cpp/patch_core/patch_core_android.cpp +0 -97
- package/cpp/patch_core/update_core_android.cpp +0 -485
- package/cpp/update_flow_core/update_flow_jni.cpp +0 -150
|
@@ -1,485 +0,0 @@
|
|
|
1
|
-
#include <jni.h>
|
|
2
|
-
|
|
3
|
-
#include "jni_natives.h"
|
|
4
|
-
#include "obscured_text.h"
|
|
5
|
-
|
|
6
|
-
#include <exception>
|
|
7
|
-
#include <string>
|
|
8
|
-
#include <vector>
|
|
9
|
-
|
|
10
|
-
#include "archive_patch_core.h"
|
|
11
|
-
#include "hbc_transform_wire.h"
|
|
12
|
-
#include "jni_util.h"
|
|
13
|
-
#include "state_core.h"
|
|
14
|
-
#include "state_ops.h"
|
|
15
|
-
|
|
16
|
-
namespace {
|
|
17
|
-
|
|
18
|
-
using pushy::jni_util::JArrayToVector;
|
|
19
|
-
using pushy::jni_util::JStringToString;
|
|
20
|
-
using pushy::jni_util::ThrowRuntimeException;
|
|
21
|
-
using pushy::state_ops::StateOperation;
|
|
22
|
-
|
|
23
|
-
void SetStringField(
|
|
24
|
-
JNIEnv* env,
|
|
25
|
-
jobject target,
|
|
26
|
-
jclass target_class,
|
|
27
|
-
const char* field_name,
|
|
28
|
-
const std::string& value) {
|
|
29
|
-
jfieldID field =
|
|
30
|
-
env->GetFieldID(target_class, field_name, "Ljava/lang/String;");
|
|
31
|
-
if (field == nullptr) {
|
|
32
|
-
// Clear the pending NoSuchFieldError so subsequent JNI calls are not
|
|
33
|
-
// executed with an exception pending (undefined behavior / CheckJNI abort).
|
|
34
|
-
env->ExceptionClear();
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
37
|
-
if (value.empty()) {
|
|
38
|
-
env->SetObjectField(target, field, nullptr);
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
jstring java_value = env->NewStringUTF(value.c_str());
|
|
43
|
-
env->SetObjectField(target, field, java_value);
|
|
44
|
-
env->DeleteLocalRef(java_value);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
void SetBooleanField(
|
|
48
|
-
JNIEnv* env,
|
|
49
|
-
jobject target,
|
|
50
|
-
jclass target_class,
|
|
51
|
-
const char* field_name,
|
|
52
|
-
bool value) {
|
|
53
|
-
jfieldID field = env->GetFieldID(target_class, field_name, "Z");
|
|
54
|
-
if (field == nullptr) {
|
|
55
|
-
env->ExceptionClear();
|
|
56
|
-
return;
|
|
57
|
-
}
|
|
58
|
-
env->SetBooleanField(target, field, value ? JNI_TRUE : JNI_FALSE);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
std::string GetStringField(
|
|
62
|
-
JNIEnv* env,
|
|
63
|
-
jobject target,
|
|
64
|
-
jclass target_class,
|
|
65
|
-
const char* field_name) {
|
|
66
|
-
jfieldID field =
|
|
67
|
-
env->GetFieldID(target_class, field_name, "Ljava/lang/String;");
|
|
68
|
-
if (field == nullptr) {
|
|
69
|
-
env->ExceptionClear();
|
|
70
|
-
return std::string();
|
|
71
|
-
}
|
|
72
|
-
auto* value = static_cast<jstring>(env->GetObjectField(target, field));
|
|
73
|
-
std::string result = JStringToString(env, value);
|
|
74
|
-
if (value != nullptr) {
|
|
75
|
-
env->DeleteLocalRef(value);
|
|
76
|
-
}
|
|
77
|
-
return result;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
bool GetBooleanField(
|
|
81
|
-
JNIEnv* env,
|
|
82
|
-
jobject target,
|
|
83
|
-
jclass target_class,
|
|
84
|
-
const char* field_name) {
|
|
85
|
-
jfieldID field = env->GetFieldID(target_class, field_name, "Z");
|
|
86
|
-
if (field == nullptr) {
|
|
87
|
-
env->ExceptionClear();
|
|
88
|
-
return false;
|
|
89
|
-
}
|
|
90
|
-
return env->GetBooleanField(target, field) == JNI_TRUE;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
pushy::state::State ReadState(
|
|
94
|
-
const std::string& package_version,
|
|
95
|
-
const std::string& build_time,
|
|
96
|
-
const std::string& current_version,
|
|
97
|
-
const std::string& last_version,
|
|
98
|
-
bool first_time,
|
|
99
|
-
bool first_time_ok,
|
|
100
|
-
const std::string& rolled_back_version) {
|
|
101
|
-
pushy::state::State state;
|
|
102
|
-
state.package_version = package_version;
|
|
103
|
-
state.build_time = build_time;
|
|
104
|
-
state.current_version = current_version;
|
|
105
|
-
state.last_version = last_version;
|
|
106
|
-
state.first_time = first_time;
|
|
107
|
-
state.first_time_ok = first_time_ok;
|
|
108
|
-
state.rolled_back_version = rolled_back_version;
|
|
109
|
-
return state;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
pushy::state::State ReadStateFromResult(JNIEnv* env, jobject state_result) {
|
|
113
|
-
if (state_result == nullptr) {
|
|
114
|
-
return pushy::state::State();
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
jclass state_class = env->GetObjectClass(state_result);
|
|
118
|
-
if (state_class == nullptr) {
|
|
119
|
-
return pushy::state::State();
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
pushy::state::State state = ReadState(
|
|
123
|
-
GetStringField(env, state_result, state_class, "packageVersion"),
|
|
124
|
-
GetStringField(env, state_result, state_class, "buildTime"),
|
|
125
|
-
GetStringField(env, state_result, state_class, "currentVersion"),
|
|
126
|
-
GetStringField(env, state_result, state_class, "lastVersion"),
|
|
127
|
-
GetBooleanField(env, state_result, state_class, "firstTime"),
|
|
128
|
-
GetBooleanField(env, state_result, state_class, "firstTimeOk"),
|
|
129
|
-
GetStringField(env, state_result, state_class, "rolledBackVersion"));
|
|
130
|
-
env->DeleteLocalRef(state_class);
|
|
131
|
-
return state;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
jobject NewStateCoreResult(
|
|
135
|
-
JNIEnv* env,
|
|
136
|
-
const pushy::state::State& state,
|
|
137
|
-
bool changed,
|
|
138
|
-
const std::string& stale_version_to_delete,
|
|
139
|
-
const std::string& load_version,
|
|
140
|
-
bool did_rollback,
|
|
141
|
-
bool consumed_first_time) {
|
|
142
|
-
jclass result_class =
|
|
143
|
-
env->FindClass(
|
|
144
|
-
pushy::text::Reveal("3919bbc3ab8a6b512c3e08f0c0b6df60452311edfbc8f780624b2d1de38c93a99b63511201f9cd97878c695522").c_str());
|
|
145
|
-
if (result_class == nullptr) {
|
|
146
|
-
return nullptr;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
jmethodID constructor = env->GetMethodID(result_class, "<init>", "()V");
|
|
150
|
-
if (constructor == nullptr) {
|
|
151
|
-
return nullptr;
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
jobject result = env->NewObject(result_class, constructor);
|
|
155
|
-
if (result == nullptr) {
|
|
156
|
-
return nullptr;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
SetStringField(env, result, result_class, "packageVersion", state.package_version);
|
|
160
|
-
SetStringField(env, result, result_class, "buildTime", state.build_time);
|
|
161
|
-
SetStringField(env, result, result_class, "currentVersion", state.current_version);
|
|
162
|
-
SetStringField(env, result, result_class, "lastVersion", state.last_version);
|
|
163
|
-
SetBooleanField(env, result, result_class, "firstTime", state.first_time);
|
|
164
|
-
SetBooleanField(env, result, result_class, "firstTimeOk", state.first_time_ok);
|
|
165
|
-
SetStringField(
|
|
166
|
-
env,
|
|
167
|
-
result,
|
|
168
|
-
result_class,
|
|
169
|
-
"rolledBackVersion",
|
|
170
|
-
state.rolled_back_version);
|
|
171
|
-
SetBooleanField(env, result, result_class, "changed", changed);
|
|
172
|
-
SetStringField(
|
|
173
|
-
env,
|
|
174
|
-
result,
|
|
175
|
-
result_class,
|
|
176
|
-
"staleVersionToDelete",
|
|
177
|
-
stale_version_to_delete);
|
|
178
|
-
SetStringField(env, result, result_class, "loadVersion", load_version);
|
|
179
|
-
SetBooleanField(env, result, result_class, "didRollback", did_rollback);
|
|
180
|
-
SetBooleanField(
|
|
181
|
-
env,
|
|
182
|
-
result,
|
|
183
|
-
result_class,
|
|
184
|
-
"consumedFirstTime",
|
|
185
|
-
consumed_first_time);
|
|
186
|
-
return result;
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
jobject NewArchivePatchPlanResult(
|
|
190
|
-
JNIEnv* env,
|
|
191
|
-
const pushy::archive_patch::ArchivePatchPlan& plan) {
|
|
192
|
-
jclass result_class =
|
|
193
|
-
env->FindClass(
|
|
194
|
-
pushy::text::Reveal("3919bbc3ab8a6b512c3e08f0c0b6df60452311edfbc8f780624b2d1de38c81af997f5d270bdbc9b181974c55371dc2c8b9926855").c_str());
|
|
195
|
-
if (result_class == nullptr) {
|
|
196
|
-
return nullptr;
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
jmethodID constructor = env->GetMethodID(result_class, "<init>", "()V");
|
|
200
|
-
if (constructor == nullptr) {
|
|
201
|
-
return nullptr;
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
jobject result = env->NewObject(result_class, constructor);
|
|
205
|
-
if (result == nullptr) {
|
|
206
|
-
return nullptr;
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
SetStringField(
|
|
210
|
-
env,
|
|
211
|
-
result,
|
|
212
|
-
result_class,
|
|
213
|
-
"mergeSourceSubdir",
|
|
214
|
-
plan.merge_source_subdir);
|
|
215
|
-
SetBooleanField(env, result, result_class, "enableMerge", plan.enable_merge);
|
|
216
|
-
return result;
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
jobject NewCopyGroupResult(
|
|
220
|
-
JNIEnv* env,
|
|
221
|
-
jclass result_class,
|
|
222
|
-
jclass string_class,
|
|
223
|
-
const pushy::archive_patch::CopyGroup& group) {
|
|
224
|
-
jmethodID constructor = env->GetMethodID(result_class, "<init>", "()V");
|
|
225
|
-
if (constructor == nullptr) {
|
|
226
|
-
return nullptr;
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
jobject result = env->NewObject(result_class, constructor);
|
|
230
|
-
if (result == nullptr) {
|
|
231
|
-
return nullptr;
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
SetStringField(env, result, result_class, "from", group.from);
|
|
235
|
-
jfieldID to_paths_field =
|
|
236
|
-
env->GetFieldID(result_class, "toPaths", "[Ljava/lang/String;");
|
|
237
|
-
if (to_paths_field != nullptr) {
|
|
238
|
-
jobjectArray to_paths = env->NewObjectArray(
|
|
239
|
-
static_cast<jsize>(group.to_paths.size()), string_class, nullptr);
|
|
240
|
-
if (to_paths != nullptr) {
|
|
241
|
-
for (jsize index = 0; index < static_cast<jsize>(group.to_paths.size());
|
|
242
|
-
++index) {
|
|
243
|
-
jstring value = env->NewStringUTF(group.to_paths[index].c_str());
|
|
244
|
-
env->SetObjectArrayElement(to_paths, index, value);
|
|
245
|
-
env->DeleteLocalRef(value);
|
|
246
|
-
}
|
|
247
|
-
env->SetObjectField(result, to_paths_field, to_paths);
|
|
248
|
-
env->DeleteLocalRef(to_paths);
|
|
249
|
-
}
|
|
250
|
-
} else {
|
|
251
|
-
env->ExceptionClear();
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
return result;
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
bool ToArchivePatchType(
|
|
258
|
-
jint patch_type,
|
|
259
|
-
pushy::archive_patch::ArchivePatchType* out) {
|
|
260
|
-
// Delegate to the shared parser so Android and HarmonyOS agree on which
|
|
261
|
-
// integer values are valid and neither silently falls back to kFull.
|
|
262
|
-
return pushy::archive_patch::TryParseArchivePatchType(
|
|
263
|
-
static_cast<int>(patch_type), out);
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
pushy::delta::PatchManifest BuildManifest(
|
|
267
|
-
const std::vector<std::string>& copy_froms,
|
|
268
|
-
const std::vector<std::string>& copy_tos,
|
|
269
|
-
const std::vector<std::string>& deletes) {
|
|
270
|
-
pushy::delta::PatchManifest manifest;
|
|
271
|
-
for (size_t index = 0; index < copy_froms.size(); ++index) {
|
|
272
|
-
manifest.copies.push_back(
|
|
273
|
-
pushy::delta::CopyOperation{copy_froms[index], copy_tos[index]});
|
|
274
|
-
}
|
|
275
|
-
manifest.deletes = deletes;
|
|
276
|
-
return manifest;
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
jobject MakeStateResult(
|
|
280
|
-
JNIEnv* env,
|
|
281
|
-
const pushy::state::State& state,
|
|
282
|
-
bool changed = false,
|
|
283
|
-
const std::string& stale_version_to_delete = std::string(),
|
|
284
|
-
const std::string& load_version = std::string(),
|
|
285
|
-
bool did_rollback = false,
|
|
286
|
-
bool consumed_first_time = false) {
|
|
287
|
-
return NewStateCoreResult(
|
|
288
|
-
env,
|
|
289
|
-
state,
|
|
290
|
-
changed,
|
|
291
|
-
stale_version_to_delete,
|
|
292
|
-
load_version,
|
|
293
|
-
did_rollback,
|
|
294
|
-
consumed_first_time);
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
} // namespace
|
|
298
|
-
|
|
299
|
-
// 客户端可消费的 diff 轨道版本(能力上报,而非 SDK 版本映射);JS 层经
|
|
300
|
-
// getConstants 暴露,随 checkUpdate 以 diffV 上报,服务端据此下发 v2 轨道。
|
|
301
|
-
jint pushy::jni_natives::SupportedDiffVersion(
|
|
302
|
-
JNIEnv*,
|
|
303
|
-
jclass) {
|
|
304
|
-
return static_cast<jint>(pushy::hbc::kSupportedDiffVersion);
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
jobject pushy::jni_natives::SyncStateWithBinaryVersion(
|
|
308
|
-
JNIEnv* env,
|
|
309
|
-
jclass,
|
|
310
|
-
jstring package_version,
|
|
311
|
-
jstring build_time,
|
|
312
|
-
jobject state_result) {
|
|
313
|
-
// C++ exceptions (bad_alloc/length_error from input-proportional STL
|
|
314
|
-
// allocations) must not unwind through the JNI boundary: convert them to a
|
|
315
|
-
// Java RuntimeException like every other failure of these entry points.
|
|
316
|
-
try {
|
|
317
|
-
pushy::state::State state = ReadStateFromResult(env, state_result);
|
|
318
|
-
pushy::state::BinaryVersionSyncResult result = pushy::state::SyncBinaryVersion(
|
|
319
|
-
state,
|
|
320
|
-
JStringToString(env, package_version),
|
|
321
|
-
JStringToString(env, build_time));
|
|
322
|
-
return MakeStateResult(env, result.state, result.changed);
|
|
323
|
-
} catch (const std::exception& error) {
|
|
324
|
-
ThrowRuntimeException(env, error.what());
|
|
325
|
-
} catch (...) {
|
|
326
|
-
ThrowRuntimeException(env, "Unexpected native exception in syncStateWithBinaryVersion");
|
|
327
|
-
}
|
|
328
|
-
return nullptr;
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
jobject pushy::jni_natives::RunStateCore(
|
|
332
|
-
JNIEnv* env,
|
|
333
|
-
jclass,
|
|
334
|
-
jint operation,
|
|
335
|
-
jobject state_result,
|
|
336
|
-
jstring string_arg,
|
|
337
|
-
jboolean flag_a,
|
|
338
|
-
jboolean flag_b) {
|
|
339
|
-
try {
|
|
340
|
-
const pushy::state::State state = ReadStateFromResult(env, state_result);
|
|
341
|
-
switch (static_cast<StateOperation>(operation)) {
|
|
342
|
-
case StateOperation::kSwitchVersion:
|
|
343
|
-
return MakeStateResult(
|
|
344
|
-
env,
|
|
345
|
-
pushy::state::SwitchVersion(state, JStringToString(env, string_arg)));
|
|
346
|
-
case StateOperation::kMarkSuccess: {
|
|
347
|
-
const pushy::state::MarkSuccessResult result =
|
|
348
|
-
pushy::state::MarkSuccess(state);
|
|
349
|
-
return MakeStateResult(
|
|
350
|
-
env,
|
|
351
|
-
result.state,
|
|
352
|
-
false,
|
|
353
|
-
result.stale_version_to_delete);
|
|
354
|
-
}
|
|
355
|
-
case StateOperation::kRollback: {
|
|
356
|
-
const pushy::state::State next = pushy::state::Rollback(state);
|
|
357
|
-
return MakeStateResult(
|
|
358
|
-
env, next, false, std::string(), next.current_version, true);
|
|
359
|
-
}
|
|
360
|
-
case StateOperation::kClearFirstTime:
|
|
361
|
-
return MakeStateResult(env, pushy::state::ClearFirstTime(state));
|
|
362
|
-
case StateOperation::kClearRollbackMark:
|
|
363
|
-
return MakeStateResult(env, pushy::state::ClearRollbackMark(state));
|
|
364
|
-
case StateOperation::kResolveLaunch: {
|
|
365
|
-
const pushy::state::LaunchDecision decision =
|
|
366
|
-
pushy::state::ResolveLaunchState(
|
|
367
|
-
state, flag_a == JNI_TRUE, flag_b == JNI_TRUE);
|
|
368
|
-
return MakeStateResult(
|
|
369
|
-
env,
|
|
370
|
-
decision.state,
|
|
371
|
-
false,
|
|
372
|
-
std::string(),
|
|
373
|
-
decision.load_version,
|
|
374
|
-
decision.did_rollback,
|
|
375
|
-
decision.consumed_first_time);
|
|
376
|
-
}
|
|
377
|
-
}
|
|
378
|
-
|
|
379
|
-
ThrowRuntimeException(env, "Unknown state operation");
|
|
380
|
-
} catch (const std::exception& error) {
|
|
381
|
-
ThrowRuntimeException(env, error.what());
|
|
382
|
-
} catch (...) {
|
|
383
|
-
ThrowRuntimeException(env, "Unexpected native exception in runStateCore");
|
|
384
|
-
}
|
|
385
|
-
return nullptr;
|
|
386
|
-
}
|
|
387
|
-
|
|
388
|
-
jobject pushy::jni_natives::BuildArchivePlan(
|
|
389
|
-
JNIEnv* env,
|
|
390
|
-
jclass,
|
|
391
|
-
jint patch_type,
|
|
392
|
-
jobjectArray entry_names,
|
|
393
|
-
jobjectArray copy_froms,
|
|
394
|
-
jobjectArray copy_tos,
|
|
395
|
-
jobjectArray deletes) {
|
|
396
|
-
try {
|
|
397
|
-
const std::vector<std::string> from_values = JArrayToVector(env, copy_froms);
|
|
398
|
-
const std::vector<std::string> to_values = JArrayToVector(env, copy_tos);
|
|
399
|
-
if (from_values.size() != to_values.size()) {
|
|
400
|
-
ThrowRuntimeException(env, "copy_froms and copy_tos length mismatch");
|
|
401
|
-
return nullptr;
|
|
402
|
-
}
|
|
403
|
-
|
|
404
|
-
pushy::delta::PatchManifest manifest =
|
|
405
|
-
BuildManifest(from_values, to_values, JArrayToVector(env, deletes));
|
|
406
|
-
pushy::archive_patch::ArchivePatchType archive_type;
|
|
407
|
-
if (!ToArchivePatchType(patch_type, &archive_type)) {
|
|
408
|
-
ThrowRuntimeException(env, "Unknown archive delta type");
|
|
409
|
-
return nullptr;
|
|
410
|
-
}
|
|
411
|
-
pushy::archive_patch::ArchivePatchPlan plan;
|
|
412
|
-
pushy::delta::Status status = pushy::archive_patch::BuildArchivePatchPlan(
|
|
413
|
-
archive_type,
|
|
414
|
-
manifest,
|
|
415
|
-
JArrayToVector(env, entry_names),
|
|
416
|
-
&plan);
|
|
417
|
-
if (!status.ok) {
|
|
418
|
-
ThrowRuntimeException(env, status.message);
|
|
419
|
-
return nullptr;
|
|
420
|
-
}
|
|
421
|
-
|
|
422
|
-
return NewArchivePatchPlanResult(env, plan);
|
|
423
|
-
} catch (const std::exception& error) {
|
|
424
|
-
ThrowRuntimeException(env, error.what());
|
|
425
|
-
} catch (...) {
|
|
426
|
-
ThrowRuntimeException(env, "Unexpected native exception while planning archive");
|
|
427
|
-
}
|
|
428
|
-
return nullptr;
|
|
429
|
-
}
|
|
430
|
-
|
|
431
|
-
jobjectArray pushy::jni_natives::BuildCopyGroups(
|
|
432
|
-
JNIEnv* env,
|
|
433
|
-
jclass,
|
|
434
|
-
jobjectArray copy_froms,
|
|
435
|
-
jobjectArray copy_tos) {
|
|
436
|
-
try {
|
|
437
|
-
const std::vector<std::string> from_values = JArrayToVector(env, copy_froms);
|
|
438
|
-
const std::vector<std::string> to_values = JArrayToVector(env, copy_tos);
|
|
439
|
-
if (from_values.size() != to_values.size()) {
|
|
440
|
-
ThrowRuntimeException(env, "copy_froms and copy_tos length mismatch");
|
|
441
|
-
return nullptr;
|
|
442
|
-
}
|
|
443
|
-
|
|
444
|
-
pushy::delta::PatchManifest manifest = BuildManifest(
|
|
445
|
-
from_values, to_values, std::vector<std::string>());
|
|
446
|
-
std::vector<pushy::archive_patch::CopyGroup> groups;
|
|
447
|
-
pushy::delta::Status status =
|
|
448
|
-
pushy::archive_patch::BuildCopyGroups(manifest, &groups);
|
|
449
|
-
if (!status.ok) {
|
|
450
|
-
ThrowRuntimeException(env, status.message);
|
|
451
|
-
return nullptr;
|
|
452
|
-
}
|
|
453
|
-
|
|
454
|
-
jclass result_class =
|
|
455
|
-
env->FindClass(
|
|
456
|
-
pushy::text::Reveal("3919bbc3ab8a6b512c3e08f0c0b6df60452311edfbc8f780624b2d1de38c83b28a6e732301fed897878c695522").c_str());
|
|
457
|
-
if (result_class == nullptr) {
|
|
458
|
-
return nullptr;
|
|
459
|
-
}
|
|
460
|
-
|
|
461
|
-
jclass string_class = env->FindClass("java/lang/String");
|
|
462
|
-
if (string_class == nullptr) {
|
|
463
|
-
return nullptr;
|
|
464
|
-
}
|
|
465
|
-
|
|
466
|
-
jobjectArray result = env->NewObjectArray(
|
|
467
|
-
static_cast<jsize>(groups.size()), result_class, nullptr);
|
|
468
|
-
if (result == nullptr) {
|
|
469
|
-
return nullptr;
|
|
470
|
-
}
|
|
471
|
-
|
|
472
|
-
for (jsize index = 0; index < static_cast<jsize>(groups.size()); ++index) {
|
|
473
|
-
jobject group = NewCopyGroupResult(env, result_class, string_class, groups[index]);
|
|
474
|
-
env->SetObjectArrayElement(result, index, group);
|
|
475
|
-
env->DeleteLocalRef(group);
|
|
476
|
-
}
|
|
477
|
-
env->DeleteLocalRef(string_class);
|
|
478
|
-
return result;
|
|
479
|
-
} catch (const std::exception& error) {
|
|
480
|
-
ThrowRuntimeException(env, error.what());
|
|
481
|
-
} catch (...) {
|
|
482
|
-
ThrowRuntimeException(env, "Unexpected native exception in buildCopyGroups");
|
|
483
|
-
}
|
|
484
|
-
return nullptr;
|
|
485
|
-
}
|
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
// JNI surface of the update-flow decision layer for the Android orchestrator
|
|
2
|
-
// (SyncCoordinator.java). Pure string-in/string-out: every payload is
|
|
3
|
-
// JSON, matching the decision layer's own boundary. A null return means
|
|
4
|
-
// "input did not parse" and the caller skips the check round; a C++ exception
|
|
5
|
-
// (bad_alloc/length_error from an oversized body) maps onto that same path —
|
|
6
|
-
// it must never unwind through the JNI boundary.
|
|
7
|
-
#include <jni.h>
|
|
8
|
-
|
|
9
|
-
#include "jni_natives.h"
|
|
10
|
-
|
|
11
|
-
#include <cstdint>
|
|
12
|
-
#include <exception>
|
|
13
|
-
#include <limits>
|
|
14
|
-
#include <string>
|
|
15
|
-
#include <vector>
|
|
16
|
-
|
|
17
|
-
#include "../patch_core/jni_util.h"
|
|
18
|
-
#include "flow_json.h"
|
|
19
|
-
#include "update_flow_core.h"
|
|
20
|
-
|
|
21
|
-
namespace {
|
|
22
|
-
|
|
23
|
-
jstring ToJString(JNIEnv* env, const std::string& value) {
|
|
24
|
-
// flow_json emits standard UTF-8, while NewStringUTF expects JNI's modified
|
|
25
|
-
// UTF-8 and corrupts supplementary code points. Decode explicitly and pass
|
|
26
|
-
// UTF-16 code units to NewString. Accept encoded surrogate code points too:
|
|
27
|
-
// strings originating in Java may have entered through modified UTF-8.
|
|
28
|
-
std::vector<jchar> utf16;
|
|
29
|
-
utf16.reserve(value.size());
|
|
30
|
-
size_t i = 0;
|
|
31
|
-
while (i < value.size()) {
|
|
32
|
-
const unsigned char first = static_cast<unsigned char>(value[i]);
|
|
33
|
-
uint32_t codePoint = 0xfffd;
|
|
34
|
-
size_t width = 1;
|
|
35
|
-
if (first < 0x80) {
|
|
36
|
-
codePoint = first;
|
|
37
|
-
} else if (first >= 0xc2 && first <= 0xdf && i + 1 < value.size()) {
|
|
38
|
-
const unsigned char b1 = static_cast<unsigned char>(value[i + 1]);
|
|
39
|
-
if ((b1 & 0xc0) == 0x80) {
|
|
40
|
-
codePoint = ((first & 0x1f) << 6) | (b1 & 0x3f);
|
|
41
|
-
width = 2;
|
|
42
|
-
}
|
|
43
|
-
} else if (first == 0xc0 && i + 1 < value.size() &&
|
|
44
|
-
static_cast<unsigned char>(value[i + 1]) == 0x80) {
|
|
45
|
-
codePoint = 0; // modified UTF-8 encoding of U+0000
|
|
46
|
-
width = 2;
|
|
47
|
-
} else if (first >= 0xe0 && first <= 0xef && i + 2 < value.size()) {
|
|
48
|
-
const unsigned char b1 = static_cast<unsigned char>(value[i + 1]);
|
|
49
|
-
const unsigned char b2 = static_cast<unsigned char>(value[i + 2]);
|
|
50
|
-
if ((b1 & 0xc0) == 0x80 && (b2 & 0xc0) == 0x80 &&
|
|
51
|
-
!(first == 0xe0 && b1 < 0xa0)) {
|
|
52
|
-
codePoint = ((first & 0x0f) << 12) | ((b1 & 0x3f) << 6) |
|
|
53
|
-
(b2 & 0x3f);
|
|
54
|
-
width = 3;
|
|
55
|
-
}
|
|
56
|
-
} else if (first >= 0xf0 && first <= 0xf4 && i + 3 < value.size()) {
|
|
57
|
-
const unsigned char b1 = static_cast<unsigned char>(value[i + 1]);
|
|
58
|
-
const unsigned char b2 = static_cast<unsigned char>(value[i + 2]);
|
|
59
|
-
const unsigned char b3 = static_cast<unsigned char>(value[i + 3]);
|
|
60
|
-
if ((b1 & 0xc0) == 0x80 && (b2 & 0xc0) == 0x80 &&
|
|
61
|
-
(b3 & 0xc0) == 0x80 && !(first == 0xf0 && b1 < 0x90) &&
|
|
62
|
-
!(first == 0xf4 && b1 > 0x8f)) {
|
|
63
|
-
codePoint = ((first & 0x07) << 18) | ((b1 & 0x3f) << 12) |
|
|
64
|
-
((b2 & 0x3f) << 6) | (b3 & 0x3f);
|
|
65
|
-
width = 4;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
i += width;
|
|
69
|
-
if (codePoint <= 0xffff) {
|
|
70
|
-
utf16.push_back(static_cast<jchar>(codePoint));
|
|
71
|
-
} else {
|
|
72
|
-
codePoint -= 0x10000;
|
|
73
|
-
utf16.push_back(static_cast<jchar>(0xd800 + (codePoint >> 10)));
|
|
74
|
-
utf16.push_back(static_cast<jchar>(0xdc00 + (codePoint & 0x3ff)));
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
if (utf16.size() > static_cast<size_t>(std::numeric_limits<jsize>::max())) {
|
|
78
|
-
return nullptr;
|
|
79
|
-
}
|
|
80
|
-
return env->NewString(utf16.empty() ? nullptr : utf16.data(),
|
|
81
|
-
static_cast<jsize>(utf16.size()));
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
} // namespace
|
|
85
|
-
|
|
86
|
-
jstring pushy::jni_natives::FlowBuildRequestBody(
|
|
87
|
-
JNIEnv* env, jclass, jstring inputJson) {
|
|
88
|
-
try {
|
|
89
|
-
bool ok = false;
|
|
90
|
-
flowjson::Value input = flowjson::Parse(
|
|
91
|
-
pushy::jni_util::JStringToString(env, inputJson), &ok);
|
|
92
|
-
if (!ok || !input.IsObject()) {
|
|
93
|
-
return nullptr;
|
|
94
|
-
}
|
|
95
|
-
return ToJString(
|
|
96
|
-
env, flowjson::Stringify(flowcore::BuildRequestBody(input)));
|
|
97
|
-
} catch (...) {
|
|
98
|
-
return nullptr;
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
jstring pushy::jni_natives::FlowOrderEndpointCandidates(
|
|
103
|
-
JNIEnv* env, jclass, jstring endpointsJson, jdouble randomSample) {
|
|
104
|
-
try {
|
|
105
|
-
bool ok = false;
|
|
106
|
-
flowjson::Value endpoints = flowjson::Parse(
|
|
107
|
-
pushy::jni_util::JStringToString(env, endpointsJson), &ok);
|
|
108
|
-
if (!ok || !endpoints.IsArray()) {
|
|
109
|
-
return nullptr;
|
|
110
|
-
}
|
|
111
|
-
return ToJString(env, flowjson::Stringify(flowcore::OrderEndpointCandidates(
|
|
112
|
-
endpoints, randomSample)));
|
|
113
|
-
} catch (...) {
|
|
114
|
-
return nullptr;
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
jboolean pushy::jni_natives::FlowIsValidResponse(
|
|
119
|
-
JNIEnv* env, jclass, jstring responseText) {
|
|
120
|
-
if (responseText == nullptr) {
|
|
121
|
-
return JNI_FALSE;
|
|
122
|
-
}
|
|
123
|
-
try {
|
|
124
|
-
return flowcore::IsValidResponse(
|
|
125
|
-
pushy::jni_util::JStringToString(env, responseText))
|
|
126
|
-
? JNI_TRUE
|
|
127
|
-
: JNI_FALSE;
|
|
128
|
-
} catch (...) {
|
|
129
|
-
return JNI_FALSE;
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
jstring pushy::jni_natives::FlowHandleResponse(
|
|
134
|
-
JNIEnv* env, jclass, jstring responseText, jstring identityJson,
|
|
135
|
-
jstring afterDownload) {
|
|
136
|
-
try {
|
|
137
|
-
bool ok = false;
|
|
138
|
-
flowjson::Value identity = flowjson::Parse(
|
|
139
|
-
pushy::jni_util::JStringToString(env, identityJson), &ok);
|
|
140
|
-
if (!ok || !identity.IsObject()) {
|
|
141
|
-
return nullptr;
|
|
142
|
-
}
|
|
143
|
-
return ToJString(env, flowjson::Stringify(flowcore::HandleResponse(
|
|
144
|
-
pushy::jni_util::JStringToString(env, responseText),
|
|
145
|
-
identity, false,
|
|
146
|
-
pushy::jni_util::JStringToString(env, afterDownload))));
|
|
147
|
-
} catch (...) {
|
|
148
|
-
return nullptr;
|
|
149
|
-
}
|
|
150
|
-
}
|