@@ -95,7 +95,7 @@ P2Q5dClenjjjVA==
9595object BundleUpdateStoreAndroid {
9696 private val bcProvider = BouncyCastleProvider ()
9797 private const val PREFS_NAME = " BundleUpdatePrefs"
98- private const val NATIVE_VERSION_PREFS_NAME = " NativeVersionPrefs"
98+ internal const val NATIVE_VERSION_PREFS_NAME = " NativeVersionPrefs"
9999 private const val CURRENT_BUNDLE_VERSION_KEY = " currentBundleVersion"
100100
101101 fun getDownloadBundleDir (context : Context ): String {
@@ -207,6 +207,47 @@ object BundleUpdateStoreAndroid {
207207 prefs.edit().putString(" nativeVersion" , nativeVersion).apply ()
208208 }
209209
210+ fun getBuildNumber (context : Context ): String {
211+ return try {
212+ val pm = context.packageManager
213+ val pi = pm.getPackageInfo(context.packageName, 0 )
214+ if (android.os.Build .VERSION .SDK_INT >= android.os.Build .VERSION_CODES .P ) {
215+ pi.longVersionCode.toString()
216+ } else {
217+ @Suppress(" DEPRECATION" )
218+ pi.versionCode.toString()
219+ }
220+ } catch (e: Exception ) {
221+ OneKeyLog .error(" BundleUpdate" , " Error getting build number: ${e.message} " )
222+ " "
223+ }
224+ }
225+
226+ fun getNativeBuildNumber (context : Context ): String {
227+ val prefs = context.getSharedPreferences(NATIVE_VERSION_PREFS_NAME , Context .MODE_PRIVATE )
228+ return prefs.getString(" nativeBuildNumber" , " " ) ? : " "
229+ }
230+
231+ fun setNativeBuildNumber (context : Context , buildNumber : String ) {
232+ val prefs = context.getSharedPreferences(NATIVE_VERSION_PREFS_NAME , Context .MODE_PRIVATE )
233+ prefs.edit().putString(" nativeBuildNumber" , buildNumber).apply ()
234+ }
235+
236+ fun clearNativeVersionPrefs (context : Context ) {
237+ val prefs = context.getSharedPreferences(NATIVE_VERSION_PREFS_NAME , Context .MODE_PRIVATE )
238+ prefs.edit().remove(" nativeVersion" ).remove(" nativeBuildNumber" ).apply ()
239+ }
240+
241+ fun getBuiltinBundleVersion (context : Context ): String {
242+ return try {
243+ val appInfo = context.packageManager.getApplicationInfo(context.packageName, android.content.pm.PackageManager .GET_META_DATA )
244+ appInfo.metaData?.getString(" BUNDLE_VERSION" ) ? : " "
245+ } catch (e: Exception ) {
246+ OneKeyLog .error(" BundleUpdate" , " Error getting builtin bundle version: ${e.message} " )
247+ " "
248+ }
249+ }
250+
210251 fun calculateSHA256 (filePath : String ): String? {
211252 return try {
212253 val digest = MessageDigest .getInstance(" SHA-256" )
@@ -513,6 +554,16 @@ object BundleUpdateStoreAndroid {
513554 if (currentAppVersion != prevNativeVersion) {
514555 OneKeyLog .info(" BundleUpdate" , " currentAppVersion is not equal to prevNativeVersion $currentAppVersion $prevNativeVersion " )
515556 clearUpdateBundleData(context)
557+ clearNativeVersionPrefs(context)
558+ return null
559+ }
560+
561+ val currentBuildNumber = getBuildNumber(context)
562+ val prevBuildNumber = getNativeBuildNumber(context)
563+ if (currentBuildNumber.isNotEmpty() && prevBuildNumber.isNotEmpty() && currentBuildNumber != prevBuildNumber) {
564+ OneKeyLog .info(" BundleUpdate" , " buildNumber changed from $prevBuildNumber to $currentBuildNumber , clearing bundle data" )
565+ clearUpdateBundleData(context)
566+ clearNativeVersionPrefs(context)
516567 return null
517568 }
518569
@@ -1008,6 +1059,8 @@ class ReactNativeBundleUpdate : HybridReactNativeBundleUpdateSpec() {
10081059 BundleUpdateStoreAndroid .setCurrentBundleVersionAndSignature(context, folderName, signature)
10091060 val nativeVersion = BundleUpdateStoreAndroid .getAppVersion(context) ? : " "
10101061 BundleUpdateStoreAndroid .setNativeVersion(context, nativeVersion)
1062+ val buildNumber = BundleUpdateStoreAndroid .getBuildNumber(context)
1063+ BundleUpdateStoreAndroid .setNativeBuildNumber(context, buildNumber)
10111064
10121065 // Manage fallback data
10131066 try {
@@ -1097,6 +1150,7 @@ class ReactNativeBundleUpdate : HybridReactNativeBundleUpdateSpec() {
10971150 OneKeyLog .info(" BundleUpdate" , " clearAllJSBundleData: deleted bundle dir" )
10981151 }
10991152 BundleUpdateStoreAndroid .clearUpdateBundleData(context)
1153+ BundleUpdateStoreAndroid .clearNativeVersionPrefs(context)
11001154
11011155 OneKeyLog .info(" BundleUpdate" , " clearAllJSBundleData: completed successfully" )
11021156 TestResult (success = true , message = " Successfully cleared all JS bundle data" )
@@ -1197,6 +1251,24 @@ class ReactNativeBundleUpdate : HybridReactNativeBundleUpdateSpec() {
11971251 }
11981252 }
11991253
1254+ override fun getNativeBuildNumber (): Promise <String > {
1255+ return Promise .async {
1256+ val context = getContext()
1257+ val buildNumber = BundleUpdateStoreAndroid .getBuildNumber(context)
1258+ OneKeyLog .info(" BundleUpdate" , " getNativeBuildNumber: $buildNumber " )
1259+ buildNumber
1260+ }
1261+ }
1262+
1263+ override fun getBuiltinBundleVersion (): Promise <String > {
1264+ return Promise .async {
1265+ val context = getContext()
1266+ val version = BundleUpdateStoreAndroid .getBuiltinBundleVersion(context)
1267+ OneKeyLog .info(" BundleUpdate" , " getBuiltinBundleVersion: $version " )
1268+ version
1269+ }
1270+ }
1271+
12001272 override fun testVerification (): Promise <Boolean > {
12011273 return Promise .async {
12021274 val testSignature = """ -----BEGIN PGP SIGNED MESSAGE-----
0 commit comments