From 068976cd9782fa848c7c3d66f2b7d106593bc745 Mon Sep 17 00:00:00 2001 From: zealotchen <92966734+zealotchen0@users.noreply.github.com> Date: Tue, 5 Mar 2024 17:40:21 +0800 Subject: [PATCH] Feature/ohos framework (#25) * feat(ohos): ohos framework hippy engine && bundle loader * feat(ohos): bridge interface * feat(ohos): ohos framework type error * feat(ohos): fix resManager null --- .../ohos-demo/src/main/ets/pages/Index.ets | 12 +- .../main/ets/hippy_framework/HippyEngine.ets | 130 ++++++++++++++++- .../hippy_framework/HippyEngineContext.ets | 62 +++++++- .../HippyEngineContextImpl.ets | 51 +++++++ ...ineImpl.ets => HippyEngineManagerImpl.ets} | 75 ++++++++-- .../hippy_framework/HippyGlobalConfigs.ets | 132 ++++++++++++++++++ .../storage/PreferencesStorageAdapter.ets | 2 +- .../hippy_framework/bridge/HippyBridge.ets | 20 +++ .../bridge/HippyBridgeImpl.ets | 28 +++- .../bridge/HippyBridgeManager.ets | 23 +++ .../bridge/HippyBridgeManagerImpl.ets | 42 ++++++ .../bundleloader/HippyAssetBundleLoader.ets | 95 +++++++++++++ .../bridge/bundleloader/HippyBundleLoader.ets | 32 +++++ .../bundleloader/HippyFileBundleLoader.ets | 77 ++++++++++ .../bundleloader/HippyRemoteBundleLoader.ets | 74 ++++++++++ .../hippy_framework/connector/JsDriver.ets | 5 +- .../main/ets/support/utils/TimeMonitor.ets | 36 ++--- 17 files changed, 854 insertions(+), 42 deletions(-) create mode 100644 framework/ohos/src/main/ets/hippy_framework/HippyEngineContextImpl.ets rename framework/ohos/src/main/ets/hippy_framework/{HippyEngineImpl.ets => HippyEngineManagerImpl.ets} (64%) create mode 100644 framework/ohos/src/main/ets/hippy_framework/bridge/bundleloader/HippyAssetBundleLoader.ets create mode 100644 framework/ohos/src/main/ets/hippy_framework/bridge/bundleloader/HippyBundleLoader.ets create mode 100644 framework/ohos/src/main/ets/hippy_framework/bridge/bundleloader/HippyFileBundleLoader.ets create mode 100644 framework/ohos/src/main/ets/hippy_framework/bridge/bundleloader/HippyRemoteBundleLoader.ets diff --git a/framework/examples/ohos-demo/src/main/ets/pages/Index.ets b/framework/examples/ohos-demo/src/main/ets/pages/Index.ets index a8d9c3faaf9..afeac39a6be 100644 --- a/framework/examples/ohos-demo/src/main/ets/pages/Index.ets +++ b/framework/examples/ohos-demo/src/main/ets/pages/Index.ets @@ -33,7 +33,17 @@ struct Index { aboutToAppear(): void { this.hippyEngine?.initEngine((statusCode: EngineInitStatus, msg: string) => { if (statusCode == EngineInitStatus.STATUS_OK) { - this.hippyEngine?.loadModule(new ModuleLoadParams(), (statusCode: ModuleLoadStatus, msg: string) => { + this.hippyEngine?.loadModule( + new ModuleLoadParams( + '', + '', + '', + '', + null, + null, + null, + ), + (statusCode: ModuleLoadStatus, msg: string) => { }) } diff --git a/framework/ohos/src/main/ets/hippy_framework/HippyEngine.ets b/framework/ohos/src/main/ets/hippy_framework/HippyEngine.ets index 1240f88a1ba..fb2c8598164 100644 --- a/framework/ohos/src/main/ets/hippy_framework/HippyEngine.ets +++ b/framework/ohos/src/main/ets/hippy_framework/HippyEngine.ets @@ -19,8 +19,21 @@ */ import { HippyLibrary } from '../hippy_library/HippyLibrary'; import { NativeRenderContext } from '../renderer_native/NativeRenderContext'; +import { HippyMap } from '../support/common/HippyTypes'; +import { HippyDeviceAdapter } from './adapter/device/HippyDeviceAdapter'; +import { HippyExceptionHandlerAdapter } from './adapter/exception/HippyExceptionHandlerAdapter'; +import { HippyExecutorSupplierAdapter } from './adapter/executor/HippyExecutorSupplierAdapter'; +import { HippyFontScaleAdapter } from './adapter/font/HippyFontScaleAdapter'; +import { HippyHttpAdapter } from './adapter/http/HippyHttpAdapter'; +import { HippyLogAdapter } from './adapter/log/HippyLogAdapter'; +import { HippyEngineMonitorAdapter } from './adapter/monitor/HippyEngineMonitorAdapter'; +import { HippySoLoaderAdapter } from './adapter/soloader/HippySoLoaderAdapter'; +import { HippyStorageAdapter } from './adapter/storage/HippyStorageAdapter'; +import { PreferencesStorageAdapter } from './adapter/storage/PreferencesStorageAdapter'; +import { HippyThirdPartyAdapter } from './adapter/thirdparty/HippyThirdPartyAdapter'; +import { HippyBundleLoader } from './bridge/bundleloader/HippyBundleLoader'; import { HippyAPIProvider } from './HippyAPIProvider'; -import { HippyEngineImpl } from './HippyEngineImpl'; +import { HippyEngineManagerImpl } from './HippyEngineManagerImpl'; export interface HippyEngine { initEngine(initCallbak: HippyEngineInitCallback): void @@ -32,15 +45,75 @@ export interface HippyEngine { } export function createHippyEngine(params: EngineInitParams): HippyEngine { - return new HippyEngineImpl(params) + return new HippyEngineManagerImpl(params) } export type HippyEngineInitCallback = (statusCode: EngineInitStatus, msg: string) => void export type HippyModuleLoadCallback = (statusCode: ModuleLoadStatus, msg: string) => void +export class V8InitParams { + public initialHeapSize: number = 0; + public maximumHeapSize: number = 0; +} + + export class EngineInitParams { libHippy: HippyLibrary - context: Context // UIAbilityContext + // 必须 宿主(Hippy的使用者)的UIAbilityContext + public context: Context | null; + // 可选参数 核心的jsbundle的assets路径(assets路径和文件路径二选一,优先使用assets路径),debugMode = false时有效 + public coreJSAssetsPath: string = ''; + // 可选参数 核心的jsbundle的文件路径(assets路径和文件路径二选一,优先使用assets路径),debugMode = false时有效 + public coreJSFilePath: string = ''; + // 可选参数 指定需要预加载的业务模块bundle assets路径 + public jsPreloadAssetsPath: HippyBundleLoader | null = null; + // 可选参数 指定需要预加载的业务模块bundle 文件路径 + public jsPreloadFilePath: HippyBundleLoader | null = null; + public debugMode = false; + // 可选参数 是否开启调试模式,默认为false,不开启 + // 可选参数 Hippy Server的jsbundle名字,默认为"index.bundle"。debugMode = true时有效 + public debugBundleName = "index.bundle"; + // 可选参数 Hippy Server的Host。默认为"localhost:38989"。debugMode = true时有效 + public debugServerHost = "localhost:38989"; + // optional args, Hippy Server url using remote debug in no usb (if not empty will replace debugServerHost and debugBundleName). debugMode = true take effect + public remoteServerUrl = ""; + // 可选参数 自定义的,用来提供Native modules、JavaScript modules、View controllers的管理器。1个或多个 + // public List providers; + // public List processors; + //Optional is use V8 serialization or json + public enableV8Serialization = true; + // 可选参数 是否打印引擎的完整的log。默认为false + public enableLog = false; + // 可选参数 code cache的名字,如果设置为空,则不启用code cache,默认为 "" + public codeCacheTag = ""; + + //可选参数 接收RuntimeId + public thirdPartyAdapter: HippyThirdPartyAdapter | null = null; + + // 可选参数 接收异常 + public exceptionHandler: HippyExceptionHandlerAdapter | null = null; + // 可选参数 设置相关 + public preferencesStorageAdapter: PreferencesStorageAdapter | null = null; + // 可选参数 Http request adapter + public httpAdapter: HippyHttpAdapter | null = null; + // 可选参数 Storage adapter 设置相关 + public storageAdapter: HippyStorageAdapter | null = null; + // 可选参数 Executor Supplier adapter + public executorSupplier: HippyExecutorSupplierAdapter | null = null; + // 可选参数 Engine Monitor adapter + public engineMonitor: HippyEngineMonitorAdapter | null = null; + // 可选参数 font scale adapter + public fontScaleAdapter: HippyFontScaleAdapter | null = null; + // 可选参数 so加载位置 + public soLoader: HippySoLoaderAdapter | null = null; + // 可选参数 device adapter + public deviceAdapter: HippyDeviceAdapter | null = null; + // 设置Hippy引擎的组,同一组的HippyEngine,会共享C层的v8 引擎实例。 默认值为-1(无效组,即不属于任何group组) + public groupId = -1; + // 可选参数 日志输出 + public logAdapter: HippyLogAdapter | null = null; + public v8InitParams: V8InitParams | null = null; + public enableTurbo = false; providers: Array | null = null @@ -50,18 +123,65 @@ export class EngineInitParams { ) { this.libHippy = libHippy this.context = context + } } +// Hippy 业务模块jsbundle加载时的参数设置 export class ModuleLoadParams { + // 必须参数 + // public context: Context; + /** + * 必须参数 业务模块jsbundle中定义的组件名称。componentName对应的是js文件中的"appName",比如: var hippy = new Hippy({ + * appName: "Demo", entryPage: App }); + */ + public componentName: string; + + // 可选参数 二选一设置 自己开发的业务模块的jsbundle的assets路径(assets路径和文件路径二选一,优先使用assets路径) + public jsAssetsPath: string; + // 可选参数 二选一设置 自己开发的业务模块的文件路径(assets路径和文件路径二选一,优先使用assets路径) + public jsFilePath: string; + // 可选参数 传递给前端的rootview:比如:Hippy.entryPage: class App extends Component + public jsParams: HippyMap | null = null; + // 可选参数 目前只有一个用处:映射:"CustomViewCreator" <==> 宿主自定义的一个HippyCustomViewCreator(这个creator还得通过ModuleParams.Builder.setCustomViewCreator来指定才行) + public nativeParams: HippyMap | null = null; + // 可选参数 Bundle加载器,老式用法,不建议使用(若一定要使用,则会覆盖jsAssetsPath,jsFilePath的值)。参见jsAssetsPath,jsFilePath + // 可选参数 code cache的名字,如果设置为空,则不启用code cache,默认为 "" + public codeCacheTag = ""; + public bundleLoader: HippyBundleLoader | null = null; + public constructor( + jsAssetsPath = '', + jsFilePath = '', + componentName = '', + codeCacheTag = '', + jsParams: HippyMap | null, + nativeParams: HippyMap | null, + bundleLoader: HippyBundleLoader | null, + ) { + this.jsAssetsPath = jsAssetsPath; + this.jsFilePath = jsFilePath; + this.componentName = componentName; + this.jsParams = jsParams; + this.nativeParams = nativeParams; + this.codeCacheTag = codeCacheTag; + this.bundleLoader = bundleLoader; +} } export enum EngineInitStatus { - STATUS_OK = 0 + STATUS_OK = 0, // 加载正常 + STATUS_ERR_BRIDGE = -101, // 初始化过程,initBridge错误 + STATUS_ERR_DEVSERVER = -102, // 初始化过程,devServer错误 + STATUS_WRONG_STATE = -103, // 状态错误。调用init函数时,引擎不在未初始化的状态 + STATUS_INIT_EXCEPTION = -104, // 初始化过程,抛出了未知的异常,详情需要查看传回的Throwable } export enum ModuleLoadStatus { - STATUS_OK = 0 + STATUS_OK = 0, // 加载正常 + STATUS_ENGINE_UNINIT = -201, // 引擎未完成初始化就加载JSBundle + STATUS_VARIABLE_NULL = -202, // check变量(bundleUniKey, loader, rootView)引用为空 + STATUS_ERR_RUN_BUNDLE = -203, // 业务JSBundle执行错误 + STATUS_REPEAT_LOAD = -204, // 重复加载同一JSBundle } diff --git a/framework/ohos/src/main/ets/hippy_framework/HippyEngineContext.ets b/framework/ohos/src/main/ets/hippy_framework/HippyEngineContext.ets index fdb5520a21f..0f0f1fa6893 100644 --- a/framework/ohos/src/main/ets/hippy_framework/HippyEngineContext.ets +++ b/framework/ohos/src/main/ets/hippy_framework/HippyEngineContext.ets @@ -17,9 +17,63 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { Context } from '@kit.AbilityKit'; +import { TimeMonitor } from '../support/utils/TimeMonitor'; +import { VfsManager } from '../vfs/VfsManager'; +import { HippyBridgeManager } from './bridge/HippyBridgeManager'; +import { JsDriver } from './connector/JsDriver'; +import { HippyGlobalConfigs } from './HippyGlobalConfigs'; +import { HippyModuleManager } from './modules/HippyModuleManager'; -export class HippyEngineContext { - constructor() { - } +export interface HippyEngineContext { + + getComponentName(): string + + // @Nullable + // HashMap getNativeParams(); + + getVfsManager(): VfsManager + + getJsDriver(): JsDriver + + getMonitor(): TimeMonitor + + getGlobalConfigs(): HippyGlobalConfigs + + getModuleManager(): HippyModuleManager + + getBridgeManager(): HippyBridgeManager + + // TODO + // DevSupportManager getDevSupportManager(); + // + // DevtoolsManager getDevtoolsManager(); + + // ViewGroup getRootView(); + // + // View getRootView(int rootId); + // + // @Nullable + // View findViewById(int nodeId); + + // void addEngineLifecycleEventListener(HippyEngineLifecycleEventListener listener); + // + // void removeEngineLifecycleEventListener(HippyEngineLifecycleEventListener listener); + // + // void handleException(Throwable throwable); + + // int getEngineId(); + // + // int getDomManagerId(); + // + // int getVfsId(); + // + // int getDevtoolsId(); + // + // void onRuntimeInitialized(); + // + // void onBridgeDestroyed(boolean isReload, Throwable e); + // + // void onLoadModuleCompleted(ModuleLoadStatus statusCode, @Nullable String msg); + // + // void onLoadInstanceCompleted(long result, String reason); } diff --git a/framework/ohos/src/main/ets/hippy_framework/HippyEngineContextImpl.ets b/framework/ohos/src/main/ets/hippy_framework/HippyEngineContextImpl.ets new file mode 100644 index 00000000000..ef548958908 --- /dev/null +++ b/framework/ohos/src/main/ets/hippy_framework/HippyEngineContextImpl.ets @@ -0,0 +1,51 @@ +import { TimeMonitor } from '../support/utils/TimeMonitor'; +import { VfsManager } from '../vfs/VfsManager'; +import { HippyBridgeManager } from './bridge/HippyBridgeManager'; +import { DomManager } from './connector/DomManager'; +import { JsDriver } from './connector/JsDriver'; +import { HippyEngineContext } from './HippyEngineContext'; +import { HippyGlobalConfigs } from './HippyGlobalConfigs'; +import { HippyModuleManager } from './modules/HippyModuleManager'; + + +export class HippyEngineContextImpl implements HippyEngineContext { + private mGlobalConfigs: HippyGlobalConfigs; + + // TODO + // private mDevtoolsManager: DevtoolsManager; + + + public constructor( + domManager: DomManager, + globalConfigs: HippyGlobalConfigs) { + this.mGlobalConfigs = globalConfigs; + } + + getComponentName(): string { + throw new Error('Method not implemented.'); + } + + getVfsManager(): VfsManager { + throw new Error('Method not implemented.'); + } + + getJsDriver(): JsDriver { + throw new Error('Method not implemented.'); + } + + getMonitor(): TimeMonitor { + throw new Error('Method not implemented.'); + } + + getGlobalConfigs(): HippyGlobalConfigs { + return this.mGlobalConfigs; + } + + getModuleManager(): HippyModuleManager { + throw new Error('Method not implemented.'); + } + + getBridgeManager(): HippyBridgeManager { + throw new Error('Method not implemented.'); + } +} diff --git a/framework/ohos/src/main/ets/hippy_framework/HippyEngineImpl.ets b/framework/ohos/src/main/ets/hippy_framework/HippyEngineManagerImpl.ets similarity index 64% rename from framework/ohos/src/main/ets/hippy_framework/HippyEngineImpl.ets rename to framework/ohos/src/main/ets/hippy_framework/HippyEngineManagerImpl.ets index 3ae809fd7b6..e1f0a7f2dc5 100644 --- a/framework/ohos/src/main/ets/hippy_framework/HippyEngineImpl.ets +++ b/framework/ohos/src/main/ets/hippy_framework/HippyEngineManagerImpl.ets @@ -24,7 +24,8 @@ import { EngineInitParams, HippyEngine, HippyEngineInitCallback, HippyModuleLoadCallback, ModuleLoadParams, - ModuleLoadStatus + ModuleLoadStatus, + V8InitParams } from '.'; import { DefaultProcessor } from '../vfs/DefaultProcessor' import { DomManager } from './connector/DomManager'; @@ -40,12 +41,21 @@ import { HippyException } from '../support/common/HippyException'; import { HippyResourceLoader } from './adapter/http/HippyResourceLoader'; import { HippyAPIProvider } from './HippyAPIProvider'; import { HRRenderViewCreator } from '../renderer_native/components/HippyRenderRegisterMap'; - -export class HippyEngineImpl implements HippyEngine, FrameworkProxy { +import { HippyGlobalConfigs } from './HippyGlobalConfigs'; +import { TimeMonitor } from '../support/utils/TimeMonitor'; +import { TextUtils } from '../support/utils/TextUtils'; +import { HippyAssetBundleLoader } from './bridge/bundleloader/HippyAssetBundleLoader'; +import { HippyBundleLoader } from './bridge/bundleloader/HippyBundleLoader'; +import { HippyFileBundleLoader } from './bridge/bundleloader/HippyFileBundleLoader'; +import { HippyThirdPartyAdapter } from './adapter/thirdparty/HippyThirdPartyAdapter'; +import { HippyEngineContextImpl } from './HippyEngineContextImpl'; +import { HippyModuleManager } from './modules/HippyModuleManager'; + +export class HippyEngineManagerImpl implements HippyEngine, FrameworkProxy { private libHippy: HippyLibrary - private resourceManager: resmgr.ResourceManager + private resourceManager: resmgr.ResourceManager | null = null - private providers: Array | null + private providers: Array | null = null public vfsManager: VfsManager public jsDriver: JsDriver | null = null @@ -53,18 +63,63 @@ export class HippyEngineImpl implements HippyEngine, FrameworkProxy { public nativeRenderProvider: NativeRenderProvider | null = null public nativeRenderer: NativeRenderer | null = null + public mGlobalConfigs: HippyGlobalConfigs + public mCoreBundleLoader: HippyBundleLoader | null = null; + public mDebugMode: boolean; + public mServerBundleName: string; + public enableV8Serialization: boolean; + public mRemoteServerUrl: string; + public mGroupId: number; + public mMonitor: TimeMonitor; + public mServerHost: string; + public mThirdPartyAdapter: HippyThirdPartyAdapter | null; + public v8InitParams: V8InitParams | null; + public mEngineContext: HippyEngineContextImpl | null = null; + public moduleManager: HippyModuleManager | null = null; + constructor(params: EngineInitParams) { this.libHippy = params.libHippy - this.resourceManager = params.context.resourceManager + this.libHippy = params.libHippy this.providers = params.providers this.vfsManager = new VfsManager(this.libHippy) const resourceLoader = new HippyResourceLoader() this.vfsManager.addProcessorAtFirst(new DefaultProcessor(resourceLoader)) + this.mGlobalConfigs = new HippyGlobalConfigs(params) + this.mDebugMode = params.debugMode; + this.mServerBundleName = params.debugMode ? params.debugBundleName : ""; + this.enableV8Serialization = params.enableV8Serialization; + this.mServerHost = params.debugServerHost; + this.mRemoteServerUrl = params.remoteServerUrl; + this.mGroupId = params.groupId; + this.mThirdPartyAdapter = params.thirdPartyAdapter; + this.v8InitParams = params.v8InitParams; + this.mMonitor = new TimeMonitor(); + + + if (!params.context) { + return + } + this.resourceManager = params.context.resourceManager + // create core bundle loader + let coreBundleLoader: HippyBundleLoader | null = null; + if (!TextUtils.isEmpty(params.coreJSAssetsPath)) { + coreBundleLoader = new HippyAssetBundleLoader(params.context, params.coreJSAssetsPath, + !TextUtils.isEmpty(params.codeCacheTag), params.codeCacheTag); + } else if (!TextUtils.isEmpty(params.coreJSFilePath)) { + coreBundleLoader = new HippyFileBundleLoader(params.coreJSFilePath, + !TextUtils.isEmpty(params.codeCacheTag), params.codeCacheTag); + } + this.mCoreBundleLoader = coreBundleLoader; + // this.mPreloadBundleLoader = preloadBundleLoader; + // TODO + // this.mProviders = params.providers; + // this.mProcessors = params.processors; } initEngine(initCallbak: HippyEngineInitCallback): void { this.domMgr = new DomManager(this.libHippy) - + this.mEngineContext = new HippyEngineContextImpl(this.domMgr, this.mGlobalConfigs); + this.moduleManager = new HippyModuleManager(this.mEngineContext) let customRenderViewCreatorMap: Map | null = null if (this.providers) { customRenderViewCreatorMap = new Map() @@ -86,9 +141,9 @@ export class HippyEngineImpl implements HippyEngine, FrameworkProxy { let rootNodeId = this.getNativeRenderContext().getRootId() this.domMgr.createRootNode(rootNodeId, PixelUtil.getDensity()) this.domMgr.attachToRoot(rootNodeId) - this.jsDriver = new JsDriver(this.libHippy) + this.jsDriver = new JsDriver(this.libHippy, this.moduleManager) this.jsDriver.initialize(this.domMgr.instanceId, this.vfsManager.instanceId, (result: number, reason: string) => { - if (!this.jsDriver || !this.domMgr || !this.vfsManager) { + if (!this.jsDriver || !this.domMgr || !this.vfsManager || !this.resourceManager) { return } hilog.info(0x0000, 'hippy', 'jsDriver initialize callback, instanceId: %{public}d', this.jsDriver.instanceId); @@ -147,7 +202,7 @@ export class HippyEngineImpl implements HippyEngine, FrameworkProxy { } loadJsModule() { - if (!this.jsDriver || !this.vfsManager) { + if (!this.jsDriver || !this.vfsManager || !this.resourceManager) { return } this.jsDriver.runScriptFromUri("asset:/vue2/index.android.js", diff --git a/framework/ohos/src/main/ets/hippy_framework/HippyGlobalConfigs.ets b/framework/ohos/src/main/ets/hippy_framework/HippyGlobalConfigs.ets index ee0182f5ba4..c4837997437 100644 --- a/framework/ohos/src/main/ets/hippy_framework/HippyGlobalConfigs.ets +++ b/framework/ohos/src/main/ets/hippy_framework/HippyGlobalConfigs.ets @@ -17,6 +17,138 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +import { LogUtils } from '../support/utils/LogUtils'; +import { HippyDeviceAdapter } from './adapter/device/HippyDeviceAdapter'; +import { HippyExceptionHandlerAdapter } from './adapter/exception/HippyExceptionHandlerAdapter'; +import { HippyExecutorSupplierAdapter } from './adapter/executor/HippyExecutorSupplierAdapter'; +import { HippyFontScaleAdapter } from './adapter/font/HippyFontScaleAdapter'; +import { HippyHttpAdapter } from './adapter/http/HippyHttpAdapter'; +import { HippyLogAdapter } from './adapter/log/HippyLogAdapter'; +import { HippyEngineMonitorAdapter } from './adapter/monitor/HippyEngineMonitorAdapter'; +import { HippySoLoaderAdapter } from './adapter/soloader/HippySoLoaderAdapter'; +import { HippyStorageAdapter } from './adapter/storage/HippyStorageAdapter'; +import { PreferencesStorageAdapter } from './adapter/storage/PreferencesStorageAdapter'; +import { EngineInitParams } from './HippyEngine'; + export class HippyGlobalConfigs { + /** + * SharedPreferences + */ + private mPreferencesStorageAdapter: PreferencesStorageAdapter | null; + private mContext: Context | null; + /** + * Crash Handler + */ + private mExceptionHandler: HippyExceptionHandlerAdapter | null; + /** + * Http request adapter + */ + private mHttpAdapter: HippyHttpAdapter | null; + /** + * Storage adapter + */ + private mStorageAdapter: HippyStorageAdapter | null; + /** + * Executor Supplier adapter + */ + private mExecutorSupplierAdapter: HippyExecutorSupplierAdapter | null; + /** + * Engine Monitor adapter + */ + private mEngineMonitorAdapter: HippyEngineMonitorAdapter | null; + /** + * font scale adapter + */ + private mFontScaleAdapter: HippyFontScaleAdapter | null; + /** + * font so loader adapter + */ + private mSoLoaderAdapter: HippySoLoaderAdapter | null; + /** + * device adapter + */ + private mDeviceAdapter: HippyDeviceAdapter | null; + private mLogAdapter: HippyLogAdapter | null; + private mEnableTurbo: boolean; + + constructor(params: EngineInitParams) { + this.mContext = params.context; + this.mPreferencesStorageAdapter = params.preferencesStorageAdapter; + this.mExceptionHandler = params.exceptionHandler; + this.mHttpAdapter = params.httpAdapter; + this.mStorageAdapter = params.storageAdapter; + this.mExecutorSupplierAdapter = params.executorSupplier; + this.mEngineMonitorAdapter = params.engineMonitor; + this.mFontScaleAdapter = params.fontScaleAdapter; + this.mSoLoaderAdapter = params.soLoader; + this.mDeviceAdapter = params.deviceAdapter; + this.mLogAdapter = params.logAdapter; + this.mEnableTurbo = params.enableTurbo; + } + + public destroyIfNeed() { + try { + if (this.mHttpAdapter != null) { + this.mHttpAdapter.destroyIfNeed(); + } + // TODO + // if (this.mStorageAdapter != null) { + // this.mStorageAdapter.destroyIfNeed(); + // } + if (this.mExecutorSupplierAdapter != null) { + this.mExecutorSupplierAdapter.destroyIfNeed(); + } + this.mContext = null; + } catch (e) { + LogUtils.d("HippyGlobalConfigs", "destroyIfNeed: " + e.getMessage()); + } + } + + public getLogAdapter(): HippyLogAdapter | null { + return this.mLogAdapter; + } + + public getSoLoaderAdapter(): HippySoLoaderAdapter | null { + return this.mSoLoaderAdapter; + } + + public getSharedPreferencesAdapter(): PreferencesStorageAdapter | null { + return this.mPreferencesStorageAdapter; + } + + public getExceptionHandler(): HippyExceptionHandlerAdapter | null { + return this.mExceptionHandler; + } + + public getFontScaleAdapter(): HippyFontScaleAdapter | null { + return this.mFontScaleAdapter; + } + + public getDeviceAdapter(): HippyDeviceAdapter | null { + return this.mDeviceAdapter; + } + + public getHttpAdapter(): HippyHttpAdapter | null { + return this.mHttpAdapter; + } + + public getContext(): Context | null { + return this.mContext; + } + + public getStorageAdapter(): HippyStorageAdapter | null { + return this.mStorageAdapter; + } + + public getExecutorSupplierAdapter(): HippyExecutorSupplierAdapter | null { + return this.mExecutorSupplierAdapter; + } + + public getEngineMonitorAdapter(): HippyEngineMonitorAdapter | null { + return this.mEngineMonitorAdapter; + } + public enableTurbo(): boolean { + return this.mEnableTurbo; + } } diff --git a/framework/ohos/src/main/ets/hippy_framework/adapter/storage/PreferencesStorageAdapter.ets b/framework/ohos/src/main/ets/hippy_framework/adapter/storage/PreferencesStorageAdapter.ets index 7353243b14c..a9f952c1b9f 100644 --- a/framework/ohos/src/main/ets/hippy_framework/adapter/storage/PreferencesStorageAdapter.ets +++ b/framework/ohos/src/main/ets/hippy_framework/adapter/storage/PreferencesStorageAdapter.ets @@ -25,7 +25,7 @@ import { HippyException } from '../../../support/common/HippyException'; const PREFERENCES_NAME = 'HippyStorage' -export class DefaultStorageAdapter implements HippyStorageAdapter { +export class PreferencesStorageAdapter implements HippyStorageAdapter { private context: Context constructor(context: Context) { diff --git a/framework/ohos/src/main/ets/hippy_framework/bridge/HippyBridge.ets b/framework/ohos/src/main/ets/hippy_framework/bridge/HippyBridge.ets index 3e85750dfa7..5ea3b5a642b 100644 --- a/framework/ohos/src/main/ets/hippy_framework/bridge/HippyBridge.ets +++ b/framework/ohos/src/main/ets/hippy_framework/bridge/HippyBridge.ets @@ -17,7 +17,27 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +import { NativeCallback } from '../connector/NativeCallback'; export interface HippyBridge { + initJSBridge(gobalConfig: string, callback: NativeCallback, groupId: number): void; + + runScriptFromUri(uri: string, canUseCodeCache: boolean, codeCacheTag: string, callback: NativeCallback): boolean; + + onDestroy(): void; + + destroy(callback: NativeCallback, isReload: boolean): void; + + callFunction(functionId: number, callback: NativeCallback, buffer: Uint8Array): void; + + getV8RuntimeId(): number; +} + +export interface BridgeCallback { + + callNatives(moduleName: string, moduleFunc: string, callId: string, params: Uint8Array): void; + + reportException(message: string, stackTrace: string): void; + } diff --git a/framework/ohos/src/main/ets/hippy_framework/bridge/HippyBridgeImpl.ets b/framework/ohos/src/main/ets/hippy_framework/bridge/HippyBridgeImpl.ets index 8684b128316..fed85776af0 100644 --- a/framework/ohos/src/main/ets/hippy_framework/bridge/HippyBridgeImpl.ets +++ b/framework/ohos/src/main/ets/hippy_framework/bridge/HippyBridgeImpl.ets @@ -20,11 +20,37 @@ import { HippyBridge } from './HippyBridge'; import { JsDriver } from '../connector/JsDriver'; import { HippyAny } from '../../support/common/HippyTypes'; +import { NativeCallback } from '../connector/NativeCallback'; export class HippyBridgeImpl implements HippyBridge { + private URI_SCHEME_ASSETS: string = ''; + private URI_SCHEME_FILE: string = ''; private jsDriver: JsDriver - callFunction(functionId: number, callback: HippyAny, buffer: Uint8Array) { + public constructor(jsDriver: JsDriver) { + this.jsDriver = jsDriver; + } + initJSBridge(gobalConfig: string, callback: NativeCallback, groupId: number): void { + throw new Error('Method not implemented.'); + } + + runScriptFromUri(uri: string, canUseCodeCache: boolean, codeCacheTag: string, callback: NativeCallback): boolean { + throw new Error('Method not implemented.'); + } + + onDestroy(): void { + throw new Error('Method not implemented.'); + } + + destroy(callback: NativeCallback, isReload: boolean): void { + throw new Error('Method not implemented.'); + } + + getV8RuntimeId(): number { + throw new Error('Method not implemented.'); + } + + callFunction(functionId: number, callback: NativeCallback, buffer: Uint8Array) { } } diff --git a/framework/ohos/src/main/ets/hippy_framework/bridge/HippyBridgeManager.ets b/framework/ohos/src/main/ets/hippy_framework/bridge/HippyBridgeManager.ets index a6b1bad4c04..772281c57de 100644 --- a/framework/ohos/src/main/ets/hippy_framework/bridge/HippyBridgeManager.ets +++ b/framework/ohos/src/main/ets/hippy_framework/bridge/HippyBridgeManager.ets @@ -17,7 +17,30 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +import { HippyMap } from '../../support/common/HippyTypes'; +import { HippyThirdPartyAdapter } from '../adapter/thirdparty/HippyThirdPartyAdapter'; +import { HippyBundleLoader } from './bundleloader/HippyBundleLoader'; export interface HippyBridgeManager { + initBridge(): void; + runBundle(id: number, loader: HippyBundleLoader): void; + + loadInstance(name: string, id: number, params: HippyMap): void; + + resumeInstance(id: number): void; + + pauseInstance(id: number): void; + + destroyInstance(id: number): void; + + execCallback(params: HippyMap): void; + + destroyBridge(isReload: boolean): void; + + destroy(): void; + + callJavaScriptModule(mName: string, name: string, params: HippyMap): void; + + getThirdPartyAdapter(): HippyThirdPartyAdapter; } diff --git a/framework/ohos/src/main/ets/hippy_framework/bridge/HippyBridgeManagerImpl.ets b/framework/ohos/src/main/ets/hippy_framework/bridge/HippyBridgeManagerImpl.ets index 86290c65967..2b64451249c 100644 --- a/framework/ohos/src/main/ets/hippy_framework/bridge/HippyBridgeManagerImpl.ets +++ b/framework/ohos/src/main/ets/hippy_framework/bridge/HippyBridgeManagerImpl.ets @@ -21,10 +21,52 @@ import { BinaryWriter } from '../../serialization/writer/BinaryWriter'; import { HippyAny, HippyMap, HippyValue } from '../../support/common/HippyTypes'; import { ArgumentUtils } from '../../support/utils/ArgumentUtils'; import { I18nUtil } from '../../support/utils/I18nUtil'; +import { HippyThirdPartyAdapter } from '../adapter/thirdparty/HippyThirdPartyAdapter'; import { Serializer } from '../serialization/Serializer'; +import { HippyBundleLoader } from './bundleloader/HippyBundleLoader'; import { HippyBridgeManager } from './HippyBridgeManager'; export class HippyBridgeManagerImpl implements HippyBridgeManager { + initBridge(): void { + throw new Error('Method not implemented.'); + } + + runBundle(id: number, loader: HippyBundleLoader): void { + throw new Error('Method not implemented.'); + } + + resumeInstance(id: number): void { + throw new Error('Method not implemented.'); + } + + pauseInstance(id: number): void { + throw new Error('Method not implemented.'); + } + + destroyInstance(id: number): void { + throw new Error('Method not implemented.'); + } + + execCallback(params: HippyMap): void { + throw new Error('Method not implemented.'); + } + + destroyBridge(isReload: boolean): void { + throw new Error('Method not implemented.'); + } + + destroy(): void { + throw new Error('Method not implemented.'); + } + + callJavaScriptModule(mName: string, name: string, params: HippyMap): void { + throw new Error('Method not implemented.'); + } + + getThirdPartyAdapter(): HippyThirdPartyAdapter { + throw new Error('Method not implemented.'); + } + loadInstance(name: string, id: number, params: HippyMap) { // TODO(hot): diff --git a/framework/ohos/src/main/ets/hippy_framework/bridge/bundleloader/HippyAssetBundleLoader.ets b/framework/ohos/src/main/ets/hippy_framework/bridge/bundleloader/HippyAssetBundleLoader.ets new file mode 100644 index 00000000000..31668a26c85 --- /dev/null +++ b/framework/ohos/src/main/ets/hippy_framework/bridge/bundleloader/HippyAssetBundleLoader.ets @@ -0,0 +1,95 @@ +/* Tencent is pleased to support the open source community by making Hippy available. + * Copyright (C) 2018 THL A29 Limited, a Tencent company. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { TextUtils } from '../../../support/utils/TextUtils'; +import { NativeCallback } from '../../connector/NativeCallback'; +import { HippyBridge } from '../HippyBridge'; +import { HippyBundleLoader } from './HippyBundleLoader'; + + +export class HippyAssetBundleLoader implements HippyBundleLoader { + + private ASSETS_STR = "assets://"; + private mContext: Context; + + private mAssetPath = ''; + + private mCanUseCodeCache = false; + + private mCodeCacheTag = ''; + + + + public constructor( + context: Context, + assetName: string, + canUseCodeCache: boolean, + codeCacheTag: string) { + this.mContext = context; + this.mAssetPath = assetName; + this.mCanUseCodeCache = canUseCodeCache; + this.mCodeCacheTag = codeCacheTag; + } + + public setCodeCache(canUseCodeCache: boolean, codeCacheTag: string) { + this.mCanUseCodeCache = canUseCodeCache; + this.mCodeCacheTag = codeCacheTag; + } + + public load(bridge: HippyBridge, callback: NativeCallback) { + if (TextUtils.isEmpty(this.mAssetPath)) { + return; + } + + // AssetManager assetManager = mContext.getAssets(); + // String uri = mAssetPath; + // if (!mAssetPath.startsWith(URI_SCHEME_ASSETS)) { + // if (mAssetPath.startsWith("/")) { + // uri = URI_SCHEME_ASSETS + mAssetPath; + // } else { + // uri = URI_SCHEME_ASSETS + "/" + mAssetPath; + // } + // } + // + // boolean ret = bridge + // .runScriptFromUri(uri, assetManager, mCanUseCodeCache, mCodeCacheTag, callback); + // LogUtils.d("HippyAssetBundleLoader", "load: ret" + ret); + } + + public getPath(): string { + if (this.mAssetPath != null && !this.mAssetPath.startsWith(this.ASSETS_STR)) { + return this.ASSETS_STR + this.mAssetPath; + } else { + return this.mAssetPath; + } + } + + public getRawPath(): string { + return this.mAssetPath; + } + + public getBundleUniKey(): string { + return this.getPath(); + } + + public canUseCodeCache(): boolean { + return this.mCanUseCodeCache; + } + + public getCodeCacheTag(): string { + return this.mCodeCacheTag; + } + +} diff --git a/framework/ohos/src/main/ets/hippy_framework/bridge/bundleloader/HippyBundleLoader.ets b/framework/ohos/src/main/ets/hippy_framework/bridge/bundleloader/HippyBundleLoader.ets new file mode 100644 index 00000000000..391762206a8 --- /dev/null +++ b/framework/ohos/src/main/ets/hippy_framework/bridge/bundleloader/HippyBundleLoader.ets @@ -0,0 +1,32 @@ +/* Tencent is pleased to support the open source community by making Hippy available. + * Copyright (C) 2018 THL A29 Limited, a Tencent company. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { NativeCallback } from '../../connector/NativeCallback'; +import { HippyBridge } from '../HippyBridge'; + +export interface HippyBundleLoader { + + load(bridge: HippyBridge, callback: NativeCallback): void; + + getPath(): string; + + getRawPath(): string; + + getBundleUniKey(): string; + + canUseCodeCache(): boolean; + + getCodeCacheTag(): string; +} diff --git a/framework/ohos/src/main/ets/hippy_framework/bridge/bundleloader/HippyFileBundleLoader.ets b/framework/ohos/src/main/ets/hippy_framework/bridge/bundleloader/HippyFileBundleLoader.ets new file mode 100644 index 00000000000..bd5f60fe25c --- /dev/null +++ b/framework/ohos/src/main/ets/hippy_framework/bridge/bundleloader/HippyFileBundleLoader.ets @@ -0,0 +1,77 @@ +/* Tencent is pleased to support the open source community by making Hippy available. + * Copyright (C) 2018 THL A29 Limited, a Tencent company. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { TextUtils } from '../../../support/utils/TextUtils'; +import { NativeCallback } from '../../connector/NativeCallback'; +import { HippyBridge } from '../HippyBridge'; +import { HippyBundleLoader } from './HippyBundleLoader'; + + +export class HippyFileBundleLoader implements HippyBundleLoader { + private ASSETS_STR = "assets://"; + private mFilePath: string; + private mCanUseCodeCache = false; + private mCodeCacheTag = ''; + + public constructor( + filePath: string, + canUseCodeCache: boolean, + codeCacheTag: string) { + this.mFilePath = filePath; + this.mCanUseCodeCache = canUseCodeCache; + this.mCodeCacheTag = codeCacheTag; + } + + + public setCodeCache(canUseCodeCache: boolean, codeCacheTag: string) { + this.mCanUseCodeCache = canUseCodeCache; + this.mCodeCacheTag = codeCacheTag; + } + + public load(bridge: HippyBridge, callback: NativeCallback) { + if (TextUtils.isEmpty(this.mFilePath)) { + return; + } + + // String uri = + // (!mFilePath.startsWith(URI_SCHEME_FILE)) ? (URI_SCHEME_FILE + mFilePath) : mFilePath; + // boolean ret = bridge.runScriptFromUri(uri, null, mCanUseCodeCache, mCodeCacheTag, callback); + // LogUtils.d("HippyFileBundleLoader", "load: ret" + ret); + } + + public getPath(): string { + if (this.mFilePath != null && !this.mFilePath.startsWith(this.ASSETS_STR)) { + return this.ASSETS_STR + this.mFilePath; + } else { + return this.mFilePath; + } + } + + public getRawPath(): string { + return this.mFilePath; + } + + public getBundleUniKey(): string { + return this.getPath(); + } + + public canUseCodeCache(): boolean { + return this.mCanUseCodeCache; + } + + public getCodeCacheTag(): string { + return this.mCodeCacheTag; + } +} diff --git a/framework/ohos/src/main/ets/hippy_framework/bridge/bundleloader/HippyRemoteBundleLoader.ets b/framework/ohos/src/main/ets/hippy_framework/bridge/bundleloader/HippyRemoteBundleLoader.ets new file mode 100644 index 00000000000..ffddb3015df --- /dev/null +++ b/framework/ohos/src/main/ets/hippy_framework/bridge/bundleloader/HippyRemoteBundleLoader.ets @@ -0,0 +1,74 @@ +/* Tencent is pleased to support the open source community by making Hippy available. + * Copyright (C) 2018 THL A29 Limited, a Tencent company. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { TextUtils } from '../../../support/utils/TextUtils'; +import { NativeCallback } from '../../connector/NativeCallback'; +import { HippyBridge } from '../HippyBridge'; +import { HippyBundleLoader } from './HippyBundleLoader'; + + +export class HippyRemoteBundleLoader implements HippyBundleLoader { + private mUrl: string; + private mIsDebugMode = false; + private mCanUseCodeCache = false; + private mCodeCacheTag = ''; + + public constructor( + url: string, + canUseCodeCache: boolean, + codeCacheTag: string) { + this.mUrl = url; + this.mCanUseCodeCache = canUseCodeCache; + this.mCodeCacheTag = codeCacheTag; + } + + public setCodeCache(canUseCodeCache: boolean, codeCacheTag: string) { + this.mCanUseCodeCache = canUseCodeCache; + this.mCodeCacheTag = codeCacheTag; + } + + public setIsDebugMode(debugMode: boolean) { + this.mIsDebugMode = debugMode; + } + + public load(bridge: HippyBridge, callback: NativeCallback) { + if (TextUtils.isEmpty(this.mUrl)) { + return; + } + + // boolean ret = bridge.runScriptFromUri(mUrl, null, mCanUseCodeCache, mCodeCacheTag, callback); + // LogUtils.d("HippyRemoteBundleLoader", "load: ret" + ret); + } + + public getPath(): string { + return this.mUrl; + } + + public getRawPath(): string { + return this.mUrl; + } + + public getBundleUniKey(): string { + return this.getPath(); + } + + public canUseCodeCache(): boolean { + return this.mCanUseCodeCache; + } + + public getCodeCacheTag(): string { + return this.mCodeCacheTag; + } +} diff --git a/framework/ohos/src/main/ets/hippy_framework/connector/JsDriver.ets b/framework/ohos/src/main/ets/hippy_framework/connector/JsDriver.ets index 6b159d1af77..42a315ec3cf 100644 --- a/framework/ohos/src/main/ets/hippy_framework/connector/JsDriver.ets +++ b/framework/ohos/src/main/ets/hippy_framework/connector/JsDriver.ets @@ -30,8 +30,9 @@ export class JsDriver { public instanceId: number = -1 public moduleManager: HippyModuleManager | null = null - constructor(libHippy: HippyLibrary) { + constructor(libHippy: HippyLibrary, moduleManager: HippyModuleManager) { this.libHippy = libHippy + this.moduleManager = moduleManager; } initialize( @@ -53,8 +54,6 @@ export class JsDriver { vfsId, 0 ) - - this.moduleManager = new HippyModuleManager(new HippyEngineContext()) } onCreate( diff --git a/framework/ohos/src/main/ets/support/utils/TimeMonitor.ets b/framework/ohos/src/main/ets/support/utils/TimeMonitor.ets index 3968cb71e31..5f7f02a1ebe 100644 --- a/framework/ohos/src/main/ets/support/utils/TimeMonitor.ets +++ b/framework/ohos/src/main/ets/support/utils/TimeMonitor.ets @@ -37,7 +37,7 @@ export class TimeMonitor { public static MONITOR_POINT_LOAD_BUSINESS_JS: string = "loadBusinessJs"; public static MONITOR_POINT_LOAD_INSTANCE: string = "loadInstance"; public static MONITOR_POINT_FIRST_FRAME: string = "firstFrame"; - mMonitorGroups: HashMap + mMonitorGroups: HashMap | null = null; public startPoint(groupType: MonitorGroupType, point: string): void { if (this.mMonitorGroups == null) { @@ -51,7 +51,7 @@ export class TimeMonitor { monitorGroup.startPoint(point); } - public endGroup(groupType: MonitorGroupType): MonitorGroup { + public endGroup(groupType: MonitorGroupType): MonitorGroup | null { if (this.mMonitorGroups == null) { return null; } @@ -62,7 +62,7 @@ export class TimeMonitor { return monitorGroup; } - public getMonitorGroup(groupType: MonitorGroupType): MonitorGroup { + public getMonitorGroup(groupType: MonitorGroupType): MonitorGroup | null { if (this.mMonitorGroups == null) { return null; } @@ -75,21 +75,23 @@ export class MonitorGroup { public beginTime: number = -1 public totalTime: number = -1 public isActive: boolean; - private mMonitorPoints: ArrayList - private mLastPoint: MonitorPoint; + private mMonitorPoints: ArrayList | null = null; + private mLastPoint: MonitorPoint | null = null; constructor(type: MonitorGroupType) { this.type = type; this.isActive = true; } - private checkMonitorPoint(pointKey: string): MonitorPoint { - - this.mMonitorPoints.forEach(monitorPoint => { - if (monitorPoint.key == pointKey) { - return monitorPoint - } - }); + private checkMonitorPoint(pointKey: string): MonitorPoint | null { + if (this.mMonitorPoints && this.mMonitorPoints.length > 0) { + this.mMonitorPoints.forEach((monitorPoint) => { + if (monitorPoint.key == pointKey) { + return monitorPoint + } + return null; + }); + } return null; } @@ -100,7 +102,7 @@ export class MonitorGroup { if (this.mMonitorPoints == null) { this.mMonitorPoints = new ArrayList(); } - let monitorPoint: MonitorPoint = this.checkMonitorPoint(pointKey); + let monitorPoint: MonitorPoint | null = this.checkMonitorPoint(pointKey); if (monitorPoint == null) { monitorPoint = new MonitorPoint(pointKey); this.mMonitorPoints.add(monitorPoint); @@ -128,7 +130,7 @@ export class MonitorGroup { } } - public getMonitorPoints(): ArrayList { + public getMonitorPoints(): ArrayList | null { return this.mMonitorPoints; } @@ -143,14 +145,14 @@ export class MonitorGroup { } catch (e) { console.info(`Failed to get currentTime. message:${e.message}, code:${e.code}`); } - return null + return -1 } } export class MonitorPoint { public key: string - public startTime: number - public endTime: number + public startTime: number = 0 + public endTime: number = 0 constructor(key: string) { this.key = key;