Skip to content

Commit 7b9b7ba

Browse files
committed
ota检查完回调新固件版本和大小、增加下载进度回调
1 parent 5d4334a commit 7b9b7ba

File tree

3 files changed

+43
-5
lines changed

3 files changed

+43
-5
lines changed

app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,5 @@ dependencies {
5757
implementation libs.crashreport
5858
implementation libs.androidx.core.ktx
5959
implementation libs.kotlinx.coroutines.android
60-
implementation 'com.tencent.iot.video:video-device-android:1.0.4-SNAPSHOT'
60+
implementation 'com.tencent.iot.video:video-device-android:1.0.5-SNAPSHOT'
6161
}

app/src/main/java/com/example/ivdemo/OTAUpgradeActivity.kt

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,11 @@ class OTAUpgradeActivity : BaseIPCActivity<ActivityOtaUpgradeBinding>(), IvOTACa
1818
private var isOnline = false
1919

2020
private fun initOTAUpgrade() {
21-
VideoNativeInterface.getInstance()
22-
.initOTA(OTA_FIRMWARE_PATH, OTA_FIRMWARE_VERSION, this)
21+
val hasDir = checkAndCreateDirectory(OTA_FIRMWARE_PATH)
22+
if (hasDir) {
23+
VideoNativeInterface.getInstance()
24+
.initOTA(OTA_FIRMWARE_PATH, OTA_FIRMWARE_VERSION, this)
25+
}
2326
}
2427

2528
private fun exitOTAUpgrade() {
@@ -118,15 +121,29 @@ class OTAUpgradeActivity : BaseIPCActivity<ActivityOtaUpgradeBinding>(), IvOTACa
118121
}
119122
}
120123

121-
override fun onOTAPrepare(): Int {
124+
override fun onPrepare(newFirmwareVersion: String?, newFirmwareSize: Int): Int {
125+
Log.d(TAG, "newFirmwareVersion:$newFirmwareVersion newFirmwareSize:$newFirmwareSize")
122126
return 0
123127
}
124128

129+
override fun onDownloadSize(size: Int) {
130+
Log.d(TAG, "current download progress:$size")
131+
}
132+
133+
125134
override fun onDestroy() {
126135
super.onDestroy()
127136
exitOTAUpgrade()
128137
}
129138

139+
private fun checkAndCreateDirectory(path: String): Boolean {
140+
val dir = File(path)
141+
if (!dir.exists()) {
142+
return dir.mkdirs()
143+
}
144+
return true
145+
}
146+
130147
companion object {
131148
private val TAG: String = OTAUpgradeActivity::class.java.simpleName
132149

docs/OTA升级说明.md

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
- [updateOTAProgress](#updateOTAProgress)
1414
- [onFirmwareUpdate](#onFirmwareUpdate)
1515
- [onOTAPrepare](#onOTAPrepare)
16+
- [onDownloadSize](#onDownloadSize)
1617
- [4. 数据结构](#4-数据结构)
1718
- [数据结构列表](#数据结构列表)
1819
- [数据结构描述](#数据结构描述)
@@ -163,14 +164,34 @@ int onOTAPrepare();
163164
**参数说明**
164165
| 参数名称 | 类型 | 描述 | 输入/输出 |
165166
| -------- | ---- | ---- | --------- |
166-
|||||
167+
| newFirmwareVersion | String | 查询到新固件的版本号 ||
168+
| newFirmwareSize | int | 查询到新固件的版本大小 ||
167169

168170
**返回值**
169171
| 返回值 | 描述 |
170172
| ------ | ---------------- |
171173
| 0 | 已准备好进行升级 |
172174
| 非0 | 未准备好进行升级 |
173175

176+
### onDownloadSize
177+
178+
**功能描述**
179+
OTA升级时,SDK使用此回调函数向用户输出当前下载固件大小。
180+
181+
**函数原型**
182+
```
183+
void onDownloadSize();
184+
```
185+
186+
**参数说明**
187+
| 参数名称 | 类型 | 描述 | 输入/输出 |
188+
| -------- | ---- | ---- | --------- |
189+
| size | int | 下载固件进度大小 ||
190+
191+
**返回值**
192+
| 返回值 | 描述 |
193+
| ------ | ---------------- |
194+
|||
174195

175196
# 4. 数据结构
176197

0 commit comments

Comments
 (0)