Skip to main content

OTAUpgradeManger

class OTAUpgradeManger

Description: Upgrade Management

    class OTAUpgradeManger : IOTAUpgradeManager {

companion object {

private const val CLASS_NAME = "[OTAUpgradeManger]"
const val TAG = Constants.MSDK_UPGRADE

//Retry count
private const val RETRY_MAX_COUNTS = 5

// Maximum number of device information entries
private const val GET_DEVICE_INFO_MAX_COUNTS = 20

fun getInstance(): IOTAUpgradeManager {
return Holder.instance
}
}

private object Holder {
val instance = OTAUpgradeManger()
}

/**
* app type
*/
var mAppType: String = "Enterprise"

// App upgrade object
private var appUpgradeBean: CheckResponseBean? = null

// Device upgrade object
private val deviceUpdateBeanMap = HashMap<String, CheckResponseBean.Data>()

// Listener
private val mListeners = CopyOnWriteArrayList<UpgradeVersionListener>()

private val mHandler = Handler(Looper.getMainLooper())

// Used to report upgrade status to the backend
private var cacheRegisterProductBean: RegisterProsRequestBean? = null


private val isDetectingApp = AtomicReference(false)
private val isDetectingDevice = AtomicReference(false)
}

method addUpgradeVersionListener

fun addUpgradeVersionListener(l: OTAUpgradeManger.UpgradeVersionListener)

Description: Registers an upgrade-related listener.

Input Parameters: l: Listener [OTAUpgradeManger.UpgradeVersionListener]

Output Parameters: None.

Related Parameters: OTAUpgradeManger.UpgradeVersionListener。

method removeUpgradeVersionListener

fun removeUpgradeVersionListener(l: OTAUpgradeManger.UpgradeVersionListener)

Description: Unregisters an upgrade-related listener.

Input Parameters: l: Listener [OTAUpgradeManger.UpgradeVersionListener]

Output Parameters: None.

Related Parameters: OTAUpgradeManger.UpgradeVersionListener。

method getAppType

fun getAppType():String

Description: Gets the app type.

Input Parameters: None.

Output Parameters: Application type [String]

Related Parameters: String

method detectAppUpdateInfo

fun detectAppUpdateInfo(manual: Boolean? = false)

Description: Checks for app update information.

Input Parameters: manual: Whether triggered manually [Boolean]

Output Parameters: None.

Related Parameters: Boolean

method detectDeviceUpdateInfo

fun detectDeviceUpdateInfo()

Description: Checks for aircraft and remote controller update information.

Input Parameters: None.

Output Parameters: None.

Related Parameters: None.

method isAppNeedUpdate

fun isAppNeedUpdate(): Boolean

Description: Determines if the app needs to be updated.

Input Parameters: None.

Output Parameters: Whether an update is needed [Boolean]

Related Parameters: Boolean

method isRCNeedUpdate

fun isRCNeedUpdate(): Boolean

Description: Determines if the remote controller needs to be updated.

Input Parameters: None.

Output Parameters: Whether an update is needed [Boolean]

Related Parameters: Boolean

method isDroneNeedUpdate

fun isDroneNeedUpdate(deviceId:Int? = null):Boolean

Description: Determines if a specific or any aircraft needs to be updated.

Input Parameters: deviceId:Device ID [Int]

Output Parameters: Whether an update is needed [Boolean]

Related Parameters: Boolean

method getAppUpdateInfo

fun getAppUpdateInfo(): CheckResponseBean?

Description: Gets the app's upgrade information.

Input Parameters: None.

Output Parameters: App upgrade information [CheckResponseBean]

Related Parameters: CheckResponseBean

method getDeviceUpdateInfo

 fun getDeviceUpdateInfo(): HashMap<String, CheckResponseBean.Data>

Description: Gets the upgrade information for remote controllers and aircraft.

Input Parameters: None.

Output Parameters: Upgrade information for remote controllers and aircraft [HashMap]

Related Parameters: HashMap,CheckResponseBean

method switchUpgradeMode

fun switchUpgradeMode(enter: Boolean)

Description: Enables or disables the aircraft upgrade mode, enhancing the bandwidth for uploading OTA files. The success of the switch is reported through the UpgradeVersionListener callback.

Input Parameters: enter: On or off

Output Parameters: None.

Related Parameters: None.

method downloadFile

    fun downloadFile(url: String, fileName: String, downloadCallback: FileTransmitListener<File>): S3DownloadInterceptor 

Description: Downloads a file from the given URL.

Input Parameters: url:URL for the specific file fileName:Name of the file to download downloadCallback:Callback through which the download progresses

Output Parameters: Download interceptor for handling exceptions

Related Parameters: None.

method downloadAppFile

    fun downloadAppFile(url: String, fileName: String, downloadCallback: FileTransmitListener<File>): S3DownloadInterceptor 

Description: Downloads an application file from the given URL.

Input Parameters: url:URL for the specific file fileName:Name of the file to download downloadCallback:Callback through which the download progresses

Output Parameters: None.

Related Parameters: None.

method reportUpgrade

    fun reportUpgrade(
status: UpgradeResultEnum,
upgradeTaskId: Int,
sn: String,
description: String? = "",
)

Description: Reports the upgrade status to the server.

Input Parameters: status:Upgrade status [UpgradeResultEnum] upgradeTaskId:Upgrade task ID [Int] sn:SN code [String] description:Description[String]

Output Parameters: None.

Related Parameters: None.

method registerRemoterAutoUpgradeListener

fun registerRemoterAutoUpgradeListener(listener: RemoterAutoUpgradeWrapper.RemoterAutoUpgradeListener)

Description: Registers a listener for the remote controller's automatic upgrade status, primarily for upgrading offline packages through SD card insertion.

Input Parameters: listener: Status interface [RemoterAutoUpgradeWrapper.RemoterAutoUpgradeListener]

Output Parameters: None.

Related Parameters: RemoterAutoUpgradeWrapper.RemoterAutoUpgradeListener。

method unRegisterRemoterAutoUpgradeListener

fun unRegisterRemoterAutoUpgradeListener()

Description: Unregisters the remote controller's automatic upgrade listener.

Input Parameters: None.

Output Parameters: None.

Related Parameters: None.

method registerDeviceRecoveryListener

fun registerDeviceRecoveryListener(listener: DeviceRecoveryWrapper.DeviceRecoveryListener)

Description: Registers a listener for the consistency check of software versions across drone modules.

Input Parameters:

listener:Listener [DeviceRecoveryWrapper.DeviceRecoveryListener], which provides callbacks to determine version consistency, recovery progress, and results.

Output Parameters: None.

Related Parameters: DeviceRecoveryWrapper.DeviceRecoveryListener。

method unRegisterDeviceRecoveryListener

fun unRegisterDeviceRecoveryListener()

Description: Unregisters the listener for the consistency check of software versions across drone modules.

Input Parameters: None.

Output Parameters: None.

Related Parameters: None.

method startDroneComponentRecover

fun startDroneComponentRecover(deviceId:Int)

Description: Starts the software version recovery process for drone modules, monitored through the DeviceRecoveryListener.

Input Parameters:

deviceId:Device ID obtained through the device method getDeviceNumber()

Output Parameters: None.

Related Parameters: None.

    // Upgrade version information reporting
interface UpgradeVersionListener {

/**
* App upgrade notification
*/
fun onAppUpgrade(manual: Boolean, needUpgrade: Boolean, bean: CheckResponseBean?)

/**
* Device upgrade notification
*/
fun onDeviceUpgrade(beanMap: HashMap<String, CheckResponseBean.Data>)

/**
* Whether entering upgrade mode was successful
*/
fun onEnterUpgradeMode(success: Boolean)

/**
* Whether exiting upgrade mode was successful
*/
fun onExitUpgradeMode(success: Boolean)
}