Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package `in`.juspay.airborneplugin

import android.content.Context
import android.content.pm.PackageManager
import android.os.Build
import androidx.annotation.Keep
import `in`.juspay.airborne.HyperOTAServices
import `in`.juspay.airborne.LazyDownloadCallback
Expand Down Expand Up @@ -46,14 +48,31 @@ class Airborne(
}
}

private val hyperOTAServices = HyperOTAServices(
context,
airborneInterface.getNamespace(),
"",
releaseConfigUrl,
trackerCallback,
this::bootComplete
)
private val hyperOTAServices = run {
val appVersion = try {
val packageInfo = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
context.packageManager.getPackageInfo(
context.packageName,
PackageManager.PackageInfoFlags.of(0)
)
} else {
@Suppress("DEPRECATION")
context.packageManager.getPackageInfo(context.packageName, 0)
}
packageInfo.versionName ?: ""
} catch (_: Exception) {
""
Comment thread
Yash02Rajput marked this conversation as resolved.
}

HyperOTAServices(
context,
airborneInterface.getNamespace(),
appVersion,
releaseConfigUrl,
trackerCallback,
this::bootComplete
)
}

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

Expand Down
2 changes: 0 additions & 2 deletions airborne-react-native/ios/AirborneReact.mm
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#import "AirborneReact.h"
#import "Airborne.h"
#import <React/RCTLog.h>
#import <Airborne/AJPLoggerDelegate.h>
#import <Airborne/AJPApplicationManager.h>
#import <Airborne/Airborne-Swift.h>

@implementation AirborneReact
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,22 @@ public typealias AJPReleaseConfigCompletionHandler = (AJPApplicationManifest?, E
}

self.utils = AJPApplicationManagerUtils(fileUtil: self.fileUtil, tracker: self.tracker, remoteFileUtil: self.remoteFileUtil)

let majorVersion = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String ?? ""
let minorVersion = Bundle.main.infoDictionary?["CFBundleVersion"] as? String ?? ""
let appVersion = "\(majorVersion).\(minorVersion)"
Comment thread
Yash02Rajput marked this conversation as resolved.

let storedVersion = UserDefaults.standard.string(forKey: AJPApplicationConstants.APP_VERSION_USER_DEFAULTS_KEY)
if let storedVersion = storedVersion, storedVersion != appVersion {
self.utils.cleanupManifestDirectory()
self.utils.cleanupPackageDirectory()
let cleanupLog = NSMutableDictionary()
cleanupLog["previous_version"] = storedVersion
cleanupLog["current_version"] = appVersion
self.tracker.trackInfo("app_version_changed_cleanup", value: cleanupLog)
}

UserDefaults.standard.set(appVersion, forKey: AJPApplicationConstants.APP_VERSION_USER_DEFAULTS_KEY)

// Handle if any previously downloaded packages are available.
self.handleTempPackageInstallation()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,15 @@ class AJPApplicationManagerUtils {
try? fileManager.removeItem(atPath: tempDirPath)
}
}


func cleanupPackageDirectory() {
fileUtil.cleanupEntireDirectory(AJPApplicationConstants.JUSPAY_PACKAGE_DIR)
}

func cleanupManifestDirectory() {
fileUtil.cleanupEntireDirectory(AJPApplicationConstants.JUSPAY_MANIFEST_DIR)
}

// MARK: - File System Helpers

func getAllFilesInDirectory(_ directory: String, subFolder: String, includeSubfolders: Bool) -> [String] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,4 +246,22 @@ import Foundation
let path = fullPathInStorageForFilePath(fileName, inFolder: folder)
try FileManager.default.removeItem(atPath: path)
}

/// Removes an entire top-level directory from the application's Library folder.
/// Unlike workspace-scoped deletions, this does not insert the workspace segment.
/// - Parameter dirName: The name of the directory to remove (e.g. "JuspayManifests").
@objc public func cleanupEntireDirectory(_ dirName: String) {
let paths = NSSearchPathForDirectoriesInDomains(.libraryDirectory, .userDomainMask, true)
guard var rootPath = paths.first else { return }

let subPaths = dirName.components(separatedBy: "/")
for subPath in subPaths {
rootPath = (rootPath as NSString).appendingPathComponent(subPath)
}

let fileManager = FileManager.default
if fileManager.fileExists(atPath: rootPath) {
try? fileManager.removeItem(atPath: rootPath)
}
}
Comment thread
Yash02Rajput marked this conversation as resolved.
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ import Foundation
public static let RELEASE_CONFIG_TIMEOUT_NOTIFICATION = Notification.Name("AJPReleaseConfigTimeoutNotification")
public static let LAZY_PACKAGE_NOTIFICATION = Notification.Name("AJPLazyPackageNotification")

// MARK: - UserDefaults Keys
public static let APP_VERSION_USER_DEFAULTS_KEY = "in.juspay.airborne.appVersion"

// MARK: - Misc
public static let APPL_MANAGER_SUB_CAT = "hyperota"
}
Loading