Skip to content

Commit ce5f329

Browse files
author
kongdywang
committed
1. Avoid the problem that some functions in the SDK cannot be used normally after a cold start on some models.
2. After the plugin executes onDetachedFromEngine, Picture-in-Picture will be forcibly closed to prevent problems caused by inconsistent variables.
1 parent 6709e6c commit ce5f329

File tree

3 files changed

+30
-18
lines changed

3 files changed

+30
-18
lines changed

Flutter/android/src/main/java/com/tencent/vod/flutter/FTXPIPManager.java

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -145,27 +145,32 @@ public void exitPip() {
145145
public int isSupportDevice() {
146146
int pipResult = FTXEvent.NO_ERROR;
147147
Activity activity = TXFlutterEngineHolder.getInstance().getCurActivity();
148-
if (!activity.isDestroyed()) {
149-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
150-
// check permission
151-
boolean isSuccess =
152-
activity.getPackageManager().hasSystemFeature(PackageManager.FEATURE_PICTURE_IN_PICTURE);
153-
if (!isSuccess) {
154-
pipResult = FTXEvent.ERROR_PIP_FEATURE_NOT_SUPPORT;
155-
LiteavLog.e(TAG, "enterPip failed,because PIP feature is disabled");
156-
} else if (!hasPipPermission(activity)) {
157-
pipResult = FTXEvent.ERROR_PIP_DENIED_PERMISSION;
158-
LiteavLog.e(TAG, "enterPip failed,because PIP has no permission");
148+
if (null != activity) {
149+
if (!activity.isDestroyed()) {
150+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
151+
// check permission
152+
boolean isSuccess =
153+
activity.getPackageManager().hasSystemFeature(PackageManager.FEATURE_PICTURE_IN_PICTURE);
154+
if (!isSuccess) {
155+
pipResult = FTXEvent.ERROR_PIP_FEATURE_NOT_SUPPORT;
156+
LiteavLog.e(TAG, "enterPip failed,because PIP feature is disabled");
157+
} else if (!hasPipPermission(activity)) {
158+
pipResult = FTXEvent.ERROR_PIP_DENIED_PERMISSION;
159+
LiteavLog.e(TAG, "enterPip failed,because PIP has no permission");
160+
}
161+
} else {
162+
pipResult = FTXEvent.ERROR_PIP_LOWER_VERSION;
163+
LiteavLog.e(TAG, "enterPip failed,because android version is too low,"
164+
+ "Minimum supported version is android 24,but current is "
165+
+ Build.VERSION.SDK_INT);
159166
}
160167
} else {
161-
pipResult = FTXEvent.ERROR_PIP_LOWER_VERSION;
162-
LiteavLog.e(TAG, "enterPip failed,because android version is too low,"
163-
+ "Minimum supported version is android 24,but current is "
164-
+ Build.VERSION.SDK_INT);
168+
pipResult = FTXEvent.ERROR_PIP_ACTIVITY_DESTROYED;
169+
LiteavLog.e(TAG, "enterPip failed,because activity is destroyed");
165170
}
166171
} else {
167172
pipResult = FTXEvent.ERROR_PIP_ACTIVITY_DESTROYED;
168-
LiteavLog.e(TAG, "enterPip failed,because activity is destroyed");
173+
LiteavLog.e(TAG, "current activity is null, please check cur act status!");
169174
}
170175
return pipResult;
171176
}

Flutter/android/src/main/java/com/tencent/vod/flutter/SuperPlayerPlugin.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,12 +465,12 @@ private FTXPIPManager getPipManager() {
465465
public void onDetachedFromEngine(@NonNull FlutterPluginBinding binding) {
466466
LiteavLog.i(TAG, "onDetachedFromEngine");
467467
mFTXDownloadManager.destroy();
468-
mFlutterPluginBinding = null;
469468
if (null != mOrientationManager) {
470469
mOrientationManager.disable();
471470
}
472471
if (null != mTxPipManager) {
473472
mTxPipManager.releaseActivityListener();
473+
mTxPipManager.exitPip();
474474
}
475475
// Close the solution to the problem of the picture-in-picture click restore
476476
// failure on some versions of Android 12.
@@ -480,6 +480,7 @@ public void onDetachedFromEngine(@NonNull FlutterPluginBinding binding) {
480480
unregisterReceiver();
481481
TXFlutterEngineHolder.getInstance().destroy(binding);
482482
TXLiveBase.setListener(null);
483+
mFlutterPluginBinding = null;
483484
}
484485

485486
@Override

Flutter/android/src/main/java/com/tencent/vod/flutter/tools/TXFlutterEngineHolder.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public static TXFlutterEngineHolder getInstance() {
3636

3737
public void attachBindLife(FlutterPlugin.FlutterPluginBinding binding) {
3838
if (mLifeCallback != null) {
39-
LiteavLog.w(TAG, "TXFlutterEngineHolder is already attach");
39+
LiteavLog.w(TAG, "TXFlutterEngineHolder is already attached");
4040
return;
4141
}
4242
if (null == binding) {
@@ -52,6 +52,7 @@ public void onActivityCreated(@NonNull Activity activity, @Nullable Bundle saved
5252
@Override
5353
public void onActivityStarted(@NonNull Activity activity) {
5454
mFrontContextCount++;
55+
LiteavLog.i(TAG, "activity is started:" + activity);
5556
if (mIsEnterBack && mFrontContextCount > 0) {
5657
mIsEnterBack = false;
5758
notifyResume();
@@ -61,6 +62,7 @@ public void onActivityStarted(@NonNull Activity activity) {
6162
@Override
6263
public void onActivityResumed(@NonNull Activity activity) {
6364
synchronized (mActivityList) {
65+
LiteavLog.i(TAG, "activity is resumed:" + activity);
6466
int index = findIndexByAct(activity);
6567
if (index >= 0) {
6668
// refresh index
@@ -78,6 +80,7 @@ public void onActivityPaused(@NonNull Activity activity) {
7880
@Override
7981
public void onActivityStopped(@NonNull Activity activity) {
8082
mFrontContextCount--;
83+
LiteavLog.i(TAG, "activity is stopped:" + activity);
8184
if (!mIsEnterBack && mFrontContextCount <= 0) {
8285
mIsEnterBack = true;
8386
notifyEnterBack();
@@ -92,6 +95,7 @@ public void onActivitySaveInstanceState(@NonNull Activity activity, @NonNull Bun
9295
@Override
9396
public void onActivityDestroyed(@NonNull Activity activity) {
9497
synchronized (mActivityList) {
98+
LiteavLog.i(TAG, "activity is destroyed:" + activity);
9599
int index = findIndexByAct(activity);
96100
if (index >= 0) {
97101
mActivityList.remove(index);
@@ -146,13 +150,15 @@ public Activity getCurActivity() {
146150
}
147151

148152
public void destroy(FlutterPlugin.FlutterPluginBinding binding) {
153+
LiteavLog.i(TAG, "called engine holder destroy");
149154
if (null == mLifeCallback) {
150155
return;
151156
}
152157
if (null == binding) {
153158
return;
154159
}
155160
((Application)binding.getApplicationContext()).unregisterActivityLifecycleCallbacks(mLifeCallback);
161+
mLifeCallback = null;
156162
}
157163

158164
public void addAppLifeListener(TXAppStatusListener listener) {

0 commit comments

Comments
 (0)