Skip to content

Commit 9ec317b

Browse files
Yash02Rajputbalaganesh-juspay
authored andcommitted
fix: add cleanup after native update
1 parent ed77681 commit 9ec317b

6 files changed

Lines changed: 73 additions & 11 deletions

File tree

airborne-react-native/android/src/main/java/in/juspay/airborneplugin/Airborne.kt

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package `in`.juspay.airborneplugin
22

33
import android.content.Context
4+
import android.content.pm.PackageManager
5+
import android.os.Build
46
import androidx.annotation.Keep
57
import `in`.juspay.airborne.HyperOTAServices
68
import `in`.juspay.airborne.LazyDownloadCallback
@@ -46,14 +48,31 @@ class Airborne(
4648
}
4749
}
4850

49-
private val hyperOTAServices = HyperOTAServices(
50-
context,
51-
airborneInterface.getNamespace(),
52-
"",
53-
releaseConfigUrl,
54-
trackerCallback,
55-
this::bootComplete
56-
)
51+
private val hyperOTAServices = run {
52+
val appVersion = try {
53+
val packageInfo = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
54+
context.packageManager.getPackageInfo(
55+
context.packageName,
56+
PackageManager.PackageInfoFlags.of(0)
57+
)
58+
} else {
59+
@Suppress("DEPRECATION")
60+
context.packageManager.getPackageInfo(context.packageName, 0)
61+
}
62+
packageInfo.versionName ?: ""
63+
} catch (_: Exception) {
64+
""
65+
}
66+
67+
HyperOTAServices(
68+
context,
69+
airborneInterface.getNamespace(),
70+
appVersion,
71+
releaseConfigUrl,
72+
trackerCallback,
73+
this::bootComplete
74+
)
75+
}
5776

5877
private val applicationManager = hyperOTAServices.createApplicationManager(airborneInterface.getDimensions())
5978

airborne-react-native/ios/AirborneReact.mm

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
#import "AirborneReact.h"
22
#import "Airborne.h"
33
#import <React/RCTLog.h>
4-
#import <Airborne/AJPLoggerDelegate.h>
5-
#import <Airborne/AJPApplicationManager.h>
64
#import <Airborne/Airborne-Swift.h>
75

86
@implementation AirborneReact

airborne_sdk_iOS/hyper-ota/Airborne/AirborneSwift/AJPApplicationManager.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,22 @@ public typealias AJPReleaseConfigCompletionHandler = (AJPApplicationManifest?, E
276276
}
277277

278278
self.utils = AJPApplicationManagerUtils(fileUtil: self.fileUtil, tracker: self.tracker, remoteFileUtil: self.remoteFileUtil)
279+
280+
let majorVersion = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String ?? ""
281+
let minorVersion = Bundle.main.infoDictionary?["CFBundleVersion"] as? String ?? ""
282+
let appVersion = "\(majorVersion).\(minorVersion)"
283+
284+
let storedVersion = UserDefaults.standard.string(forKey: AJPApplicationConstants.APP_VERSION_USER_DEFAULTS_KEY)
285+
if let storedVersion = storedVersion, storedVersion != appVersion {
286+
self.utils.cleanupManifestDirectory()
287+
self.utils.cleanupPackageDirectory()
288+
let cleanupLog = NSMutableDictionary()
289+
cleanupLog["previous_version"] = storedVersion
290+
cleanupLog["current_version"] = appVersion
291+
self.tracker.trackInfo("app_version_changed_cleanup", value: cleanupLog)
292+
}
293+
294+
UserDefaults.standard.set(appVersion, forKey: AJPApplicationConstants.APP_VERSION_USER_DEFAULTS_KEY)
279295

280296
// Handle if any previously downloaded packages are available.
281297
self.handleTempPackageInstallation()

airborne_sdk_iOS/hyper-ota/Airborne/AirborneSwift/AJPApplicationManagerUtils.swift

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,15 @@ class AJPApplicationManagerUtils {
4848
try? fileManager.removeItem(atPath: tempDirPath)
4949
}
5050
}
51-
51+
52+
func cleanupPackageDirectory() {
53+
fileUtil.cleanupEntireDirectory(AJPApplicationConstants.JUSPAY_PACKAGE_DIR)
54+
}
55+
56+
func cleanupManifestDirectory() {
57+
fileUtil.cleanupEntireDirectory(AJPApplicationConstants.JUSPAY_MANIFEST_DIR)
58+
}
59+
5260
// MARK: - File System Helpers
5361

5462
func getAllFilesInDirectory(_ directory: String, subFolder: String, includeSubfolders: Bool) -> [String] {

airborne_sdk_iOS/hyper-ota/Airborne/AirborneSwiftCore/AJPFileUtil.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,4 +246,22 @@ import Foundation
246246
let path = fullPathInStorageForFilePath(fileName, inFolder: folder)
247247
try FileManager.default.removeItem(atPath: path)
248248
}
249+
250+
/// Removes an entire top-level directory from the application's Library folder.
251+
/// Unlike workspace-scoped deletions, this does not insert the workspace segment.
252+
/// - Parameter dirName: The name of the directory to remove (e.g. "JuspayManifests").
253+
@objc public func cleanupEntireDirectory(_ dirName: String) {
254+
let paths = NSSearchPathForDirectoriesInDomains(.libraryDirectory, .userDomainMask, true)
255+
guard var rootPath = paths.first else { return }
256+
257+
let subPaths = dirName.components(separatedBy: "/")
258+
for subPath in subPaths {
259+
rootPath = (rootPath as NSString).appendingPathComponent(subPath)
260+
}
261+
262+
let fileManager = FileManager.default
263+
if fileManager.fileExists(atPath: rootPath) {
264+
try? fileManager.removeItem(atPath: rootPath)
265+
}
266+
}
249267
}

airborne_sdk_iOS/hyper-ota/Airborne/AirborneSwiftModel/AJPApplicationConstants.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ import Foundation
3535
public static let RELEASE_CONFIG_TIMEOUT_NOTIFICATION = Notification.Name("AJPReleaseConfigTimeoutNotification")
3636
public static let LAZY_PACKAGE_NOTIFICATION = Notification.Name("AJPLazyPackageNotification")
3737

38+
// MARK: - UserDefaults Keys
39+
public static let APP_VERSION_USER_DEFAULTS_KEY = "in.juspay.airborne.appVersion"
40+
3841
// MARK: - Misc
3942
public static let APPL_MANAGER_SUB_CAT = "hyperota"
4043
}

0 commit comments

Comments
 (0)