From d314cfc0ab09574f34fd14b7d296ecc433f79143 Mon Sep 17 00:00:00 2001 From: zhan-linlin <17301907374@163.com> Date: Thu, 28 Dec 2023 15:29:03 +0800 Subject: [PATCH 1/2] =?UTF-8?q?IssueNo:=20=E4=BC=98=E5=8C=96=E6=96=B9?= =?UTF-8?q?=E6=B3=95=E5=90=8D=E4=B8=8EonDetach()=20Sig:=20OpenHarmony-SIG/?= =?UTF-8?q?flutter-engine=20Feature=20or=20Bugfix:=20Bugfix=20Binary=20Sou?= =?UTF-8?q?rce:=20No?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhan-linlin <17301907374@163.com> --- .../ets/embedding/ohos/FlutterAbility.ets | 2 +- .../embedding/ohos/FlutterAbilityDelegate.ets | 24 ++++++++++--------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterAbility.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterAbility.ets index 22b808584e..0c0532914d 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterAbility.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterAbility.ets @@ -295,7 +295,7 @@ export class FlutterAbility extends UIAbility implements Host { return false; } - shouldAttachEngineToActivity(): boolean { + shouldAttachEngineToAbility(): boolean { return true; } diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterAbilityDelegate.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterAbilityDelegate.ets index cbe0e80830..bb2fdb80ce 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterAbilityDelegate.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterAbilityDelegate.ets @@ -78,8 +78,8 @@ class FlutterAbilityDelegate implements ExclusiveAppComponent { if (this.flutterEngine == null) { await this.setupFlutterEngine(); } - //shouldAttachEngineToActivity - if (this.host?.shouldAttachEngineToActivity()) { + //shouldAttachEngineToAbility + if (this.host?.shouldAttachEngineToAbility()) { // Notify any plugins that are currently attached to our FlutterEngine that they // are now attached to an Ability. Log.d(TAG, "Attaching FlutterEngine to the Ability that owns this delegate."); @@ -255,10 +255,12 @@ class FlutterAbilityDelegate implements ExclusiveAppComponent { } onDetach() { - if (this.host?.shouldAttachEngineToActivity()) { - // Notify plugins that they are no longer attached to an Activity. + if (this.host?.shouldAttachEngineToAbility()) { + // Notify plugins that they are no longer attached to an Ability. Log.d(TAG, "Detaching FlutterEngine from the Ability"); this.flutterEngine?.getAbilityControlSurface()?.detachFromAbility(); + } else { + this.isAttached = false; } } @@ -350,17 +352,17 @@ class FlutterAbilityDelegate implements ExclusiveAppComponent { detachFromFlutterEngine() { if (this.host?.shouldDestroyEngineWithHost()) { // The host owns the engine and should never have its engine taken by another exclusive - // activity. + // ability. throw new Error( "The internal FlutterEngine created by " + this.host - + " has been attached to by another activity. To persist a FlutterEngine beyond the " + + " has been attached to by another Ability. To persist a FlutterEngine beyond the " + "ownership of this ablity, explicitly create a FlutterEngine"); } // Default, but customizable, behavior is for the host to call {@link #onDetach} // deterministically as to not mix more events during the lifecycle of the next exclusive - // activity. + // ability. this.host?.detachFromFlutterEngine(); } @@ -368,7 +370,7 @@ class FlutterAbilityDelegate implements ExclusiveAppComponent { const ability = this.host?.getAbility(); if (ability == null) { throw new Error( - "FlutterActivityAndFragmentDelegate's getAppComponent should only " + "FlutterAbilityAndFragmentDelegate's getAppComponent should only " + "be queried after onAttach, when the host's ability should always be non-null"); } return ability; @@ -384,7 +386,7 @@ class FlutterAbilityDelegate implements ExclusiveAppComponent { this.flutterEngine?.getNavigationChannel()?.pushRouteInformation(initialRoute); } } else { - Log.w(TAG, "onNewIntent() invoked before FlutterFragment was attached to an Activity."); + Log.w(TAG, "onNewIntent() invoked before FlutterFragment was attached to an Ability."); } } @@ -394,7 +396,7 @@ class FlutterAbilityDelegate implements ExclusiveAppComponent { if (this.host?.shouldRestoreAndSaveState()) { wantParam[FRAMEWORK_RESTORATION_BUNDLE_KEY] = this.flutterEngine!.getRestorationChannel()!.getRestorationData(); } - if (this.host?.shouldAttachEngineToActivity()) { + if (this.host?.shouldAttachEngineToAbility()) { const plugins:Record = {} const result = this.flutterEngine?.getAbilityControlSurface()?.onSaveState(reason, plugins); wantParam[PLUGINS_RESTORATION_BUNDLE_KEY] = plugins; @@ -439,7 +441,7 @@ interface Host extends FlutterEngineProvider, FlutterEngineConfigurator, Platfor detachFromFlutterEngine(): void; - shouldAttachEngineToActivity(): boolean; + shouldAttachEngineToAbility(): boolean; getCachedEngineId(): string; -- Gitee From 73ab98223ad69359728b7a13bd641e3c2db15ee3 Mon Sep 17 00:00:00 2001 From: zhan-linlin <17301907374@163.com> Date: Thu, 28 Dec 2023 18:55:23 +0800 Subject: [PATCH 2/2] =?UTF-8?q?IssueNo:=20=E4=BC=98=E5=8C=96=E6=96=B9?= =?UTF-8?q?=E6=B3=95=E5=90=8D=E4=B8=8EonDetach()=20Sig:=20OpenHarmony-SIG/?= =?UTF-8?q?flutter-engine=20Feature=20or=20Bugfix:=20Bugfix=20Binary=20Sou?= =?UTF-8?q?rce:=20No?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhan-linlin <17301907374@163.com> --- .../src/main/ets/embedding/ohos/FlutterAbilityDelegate.ets | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterAbilityDelegate.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterAbilityDelegate.ets index bb2fdb80ce..9da5c0130c 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterAbilityDelegate.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterAbilityDelegate.ets @@ -259,9 +259,8 @@ class FlutterAbilityDelegate implements ExclusiveAppComponent { // Notify plugins that they are no longer attached to an Ability. Log.d(TAG, "Detaching FlutterEngine from the Ability"); this.flutterEngine?.getAbilityControlSurface()?.detachFromAbility(); - } else { - this.isAttached = false; } + this.isAttached = false; } onLowMemory(): void { -- Gitee