From bed53c06e8ceb917f61cf1816cda2eee2dfcfc22 Mon Sep 17 00:00:00 2001 From: mahaonan Date: Mon, 11 Dec 2023 20:44:12 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E4=BB=BB=E5=8A=A1=E6=8F=8F=E8=BF=B0?= =?UTF-8?q?=E3=80=91=20=E5=B7=B2=E7=BB=8F=E7=AD=BE=E5=90=8D=E8=BF=87?= =?UTF-8?q?=E7=9A=84=E5=B7=A5=E7=A8=8B=EF=BC=8C=E5=86=8D=E6=AC=A1=E7=BC=96?= =?UTF-8?q?=E8=AF=91=E6=97=B6=EF=BC=8C=E4=BD=BF=E7=94=A8=E5=8E=9F=E6=9C=89?= =?UTF-8?q?=E7=AD=BE=E5=90=8D=E6=96=87=E4=BB=B6=E8=BF=9B=E8=A1=8C=E7=AD=BE?= =?UTF-8?q?=E5=90=8D=20=E3=80=90=E8=A7=A3=E5=86=B3=E6=96=B9=E6=A1=88?= =?UTF-8?q?=E3=80=91=20=E6=A0=B9=E6=8D=AEhap=E5=8C=85=E5=AE=89=E8=A3=85?= =?UTF-8?q?=E4=B8=8E=E6=9B=B4=E6=96=B0=E6=97=B6=E9=97=B4=E5=88=A4=E6=96=AD?= =?UTF-8?q?=E6=98=AF=E5=90=A6=E9=9C=80=E8=A6=81=E6=8B=B7=E8=B4=9D=20flutte?= =?UTF-8?q?r=20=E8=B5=84=E6=BA=90=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: mahaonan --- .../embedding/engine/loader/FlutterLoader.ets | 39 ++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/loader/FlutterLoader.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/loader/FlutterLoader.ets index 8917880d49..2f874e60a9 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/loader/FlutterLoader.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/loader/FlutterLoader.ets @@ -25,6 +25,8 @@ import StringUtils from '../../../util/StringUtils'; import ApplicationInfoLoader from './ApplicationInfoLoader'; import bundleManager from '@ohos.bundle.bundleManager'; import fs from '@ohos.file.fs'; +import { BusinessError } from '@ohos.base'; +import data_preferences from '@ohos.data.preferences'; const TAG = "FlutterLoader"; @@ -95,10 +97,45 @@ export default class FlutterLoader { Log.d(TAG, "flutterLoader end init") } + private async isNeedCopyResource(): Promise { + let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_DEFAULT; + try { + if (this.context != null) { + let bundleInfo = await bundleManager.getBundleInfoForSelf(bundleFlags); + let key = bundleInfo.name + '.bundleInfoPreferences' + let preferences: data_preferences.Preferences = await data_preferences.getPreferences(this.context, key); + let storeInstallTime = await preferences.get("installTime", 0); + let storeUpdateTime = await preferences.get("updateTime", 0); + if (storeInstallTime != bundleInfo.installTime || storeUpdateTime != bundleInfo.updateTime) { + await preferences.put("installTime", bundleInfo.installTime); + await preferences.put("updateTime", bundleInfo.updateTime); + await preferences.flush(); + return true; + } + } + + return false; + } catch (err) { + let message = (err as BusinessError).message; + Log.i(TAG, 'Judge is need copy resource : %{public}s', message); + return true; + } + } + private async copyResource(context: common.Context) { + let copyFlag = await this.isNeedCopyResource(); + if (!copyFlag) { + return; + } + let filePath = context.filesDir + FILE_SEPARATOR + this.flutterApplicationInfo!.flutterAssetsDir - if (!fs.accessSync(filePath + FILE_SEPARATOR + DEFAULT_KERNEL_BLOB) && this.context != null) { + if (this.context != null) { Log.d(TAG, "start copyResource") + if (fs.accessSync(filePath + FILE_SEPARATOR + DEFAULT_KERNEL_BLOB)) { + Log.d(TAG, "hap has changed, start delete previous file") + fs.rmdirSync(filePath); + } + fs.mkdirSync(filePath) let icudtlBuffer = await this.context.resourceManager.getRawFileContent(this.flutterApplicationInfo!.flutterAssetsDir + "/icudtl.dat") -- Gitee