升级
升级范围:升级整个OpenHarmony系统,包括内置的资源、预置应用;第三方的应用不在升级的范围。
升级依赖:升级分为SD卡升级和在线升级两种。
- SD卡升级依赖升级包和SD卡安装。
- 在线升级依赖手机厂商部署的用于管理升级包的服务器。服务器由手机厂商部署,IP由调用者传入,请求的request接口是固定的,由手机厂商开发。
导入模块
import client from 'libupdateclient.z.so'
权限列表
无
getNewVersionInfo(callback: AsyncCallback<NewVersionInfo>): void
获取新版本信息,使用callback方式作为异步方法。
-
参数
AsyncCallback<NewVersionInfo>
-
返回值
无
-
示例
updater.getNewVersionInfo(info => { console.log("getNewVersionInfo success " + info.status); console.log(`info versionName = ` + info.result[0].versionName); console.log(`info versionCode = ` + info.result[0].versionCode); console.log(`info verifyInfo = ` + info.result[0].verifyInfo); )};
getNewVersionInfo(): Promise<NewVersionInfo>
获取新版本信息,使用promise方式作为异步方法。
-
参数
无
-
返回值
Promise<NewVersionInfo>
-
示例
var p = updater.getNewVersionInfo(); p.then(function (value) { console.log(`info versionName = ` + value.result[0].versionName); console.log(`info versionCode = ` + value.result[0].versionCode); console.log(`info verifyInfo = ` + value.result[0].verifyInfo); }).catch(function (err) { console.log("getNewVersionInfo promise error: " + err.code); )};
checkNewVersion(callback: AsyncCallback<NewVersionInfo>): void
检查新版本,使用callback方式作为异步方法。
-
参数
AsyncCallback<NewVersionInfo>
-
返回值
无
-
示例
updater.checkNewVersion(info => { console.log("checkNewVersion success " + info.status); console.log(`info versionName = ` + info.result[0].versionName); console.log(`info versionCode = ` + info.result[0].versionCode); console.log(`info verifyInfo = ` + info.result[0].verifyInfo); )};
checkNewVersion(): Promise<NewVersionInfo>
检查新版本,使用promise方式作为异步方法。
-
参数
无
-
返回值
Promise<NewVersionInfo>
-
示例
var p = updater.checkNewVersion(); p.then(function (value) { console.log(`info versionName = ` + value.result[0].versionName); console.log(`info versionCode = ` + value.result[0].versionCode); console.log(`info verifyInfo = ` + value.result[0].verifyInfo); }).catch(function (err) { console.log("checkNewVersion promise error: " + err.code); )};
verifyUpdatePackage(upgradeFile: string, certsFile: string): void
升级前检查升级包是否有效。
-
参数:
-
返回值:
无
-
示例:
var getVar = update.getUpdater(); getVar.on("verifyProgress", function (callback){ console.info('on verifyProgress ' + callback.percent); }); getVar.verifyUpdatePackage("XXX", "XXX"); getVar.off("verifyProgress");
rebootAndCleanUserData(): Promise<number>
重启设备并清除用户分区数据。
-
参数:
无
-
返回值:
-
示例:
var getVar = update.getUpdater(); p = getVar.rebootAndCleanUserData(); p.then(function (value) { console.info("rebootAndCleanUserData promise success: " + value); }).catch(function (err) { console.info("rebootAndCleanUserData promise error: " + err.code); });
rebootAndCleanUserData(callback: AsyncCallback<number>): void
重启设备并清除用户分区数据。
-
参数:
-
返回值:
无
-
示例:
var getVar = update.getUpdater(); getVar.rebootAndCleanUserData(function (err, data) { if (err.code == 0) { console.info("rebootAndCleanUserData callback success:" + data) } else { console.info("rebootAndCleanUserData callback err:" + err.code) } });
applyNewVersion(): Promise<number>
重启设备后安装升级包。
-
参数:
无
-
返回值:
-
示例:
var getVar = update.getUpdater(); p.then(function (value) { console.info("applyNewVersion promise success: " + value); }).catch(function (err) { console.info("applyNewVersion promise error: " + err.code); });
applyNewVersion(callback: AsyncCallback<number>): void
重启设备后安装升级包。
-
参数:
-
返回值:
无
-
示例:
var getVar = update.getUpdater(); getVar.applyNewVersion(function (err, data) { if (err.code == 0) { console.info("applyNewVersion callback success:" + data) } else { console.info("applyNewVersion callback err:" + err.code) } });
download(): void
下载新版本,并监听下载进程。
-
参数
无
-
返回值
无
-
示例
updater.on("downloadProgress", progress => {
console.log("downloadProgress on" + progress);
console.log(`downloadProgress status: ` + progress.status);
console.log(`downloadProgress percent: ` + progress.percent);
)};
updater.download();
updater.upgrade():void
启动升级。
-
参数
无
-
返回值
无
-
示例
updater.on("upgradeProgress", progress => {
console.log("upgradeProgress on" + progress);
console.log(`upgradeProgress status: ` + progress.status);
console.log(`upgradeProgress percent: ` + progress.percent);
)};
updater.upgrade();
setUpdatePolicy(policy: UpdatePolicy, callback: AsyncCallback<number>): void
设置升级策略,使用callback方式作为异步方法。
-
参数
-
返回值
无
-
示例
// 设置策略 let policy = { autoDownload: false, autoDownloadNet: true, mode: 2, autoUpgradeInterval: [ 2, 3 ], autoUpgradeCondition: 2 } updater.setUpdatePolicy(policy, function(result) { console.log("setUpdatePolicy ", result)});
setUpdatePolicy(policy: UpdatePolicy): Promise<number>
设置升级策略,使用promise方式作为异步方法。
-
参数
-
返回值
-
示例
let policy = { autoDownload: false, autoDownloadNet: true, mode: 2, autoUpgradeInterval: [ 2, 3 ], autoUpgradeCondition: 2 } updater.setUpdatePolicy(policy) .then(data=> console.log('set policy success') )
getUpdatePolicy(callback: AsyncCallback<UpdatePolicy>): void
获取升级策略信息,使用callback方式作为异步方法。
-
参数
AsyncCallback<UpdatePolicy>
-
返回值
-
示例
updater.getUpdatePolicy(policy => { console.log("getUpdatePolicy success"); console.log(`policy autoDownload = ` + policy.autoDownload); console.log(`policy autoDownloadNet = ` + policy.autoDownloadNet); console.log(`policy mode = ` + policy.mode); )};
getUpdatePolicy(): Promise<UpdatePolicy>
获取升级策略,通过promise方式作为异步方法。
-
参数
无
-
返回值
Promise<UpdatePolicy>
-
示例
p = updater.getUpdatePolicy(); p.then(function (value) { console.log(`info autoDownload = ` + value.autoDownload); console.log(`info autoDownloadNet = ` + value.autoDownloadNet); console.log(`info mode = ` + value.mode); }).catch(function (err) { console.log("getUpdatePolicy promise error: " + err.code); )};
getUpdater(upgradeFile: string, updateType?: UpdateTypes): Updater
获取本地升级Updater。
-
参数
-
返回值
-
示例
try { page.data.updater = client.getUpdater('/data/updater/updater.zip', 'OTA'); } catch(error) { console.error(" Fail to get updater error: " + error); }
getUpdaterForOther(upgradeFile: string, device: string, updateType?: UpdateTypes): Updater
获取升级对象给待升级设备。
-
参数
-
返回值
-
示例
try { page.data.updater = client.getUpdaterForOther('/data/updater/updater.zip', '1234567890', 'OTA'); } catch(error) { console.error(" Fail to get updater error: " + error); }
getUpdaterFromOther(upgradeFile: string, device: string, updateType?: UpdateTypes): Updater
获取其它设备为本设备升级的Updater。
-
参数
-
返回值
-
示例
try { page.data.updater = client.getUpdaterFromOther('/data/updater/updater.zip', '1234567890', 'OTA'); } catch(error) { console.error(" Fail to get updater error: " + error); }
UpdateTypes
升级类型
PackageTypes
升级包类型
InstallMode
安装模式
NewVersionStatus
新版本检测状态
UpdatePolicy
升级策略
NewVersionInfo
新版本信息
Array<CheckResult> |
|||
Array<DescriptionInfo> |
CheckResult
检测结果
DescriptionInfo
版本描述信息