From cfaf32cb490f011d4d63a8b936b9e2822b8fd2a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=96=E6=A4=92=E8=82=89=E4=B8=9D?= <641840315@qq.com> Date: Thu, 19 Sep 2024 20:01:08 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E5=BF=AB=E9=80=9F=E9=80=80?= =?UTF-8?q?=E5=87=BA=E3=80=81=E6=8E=A5=E5=85=A5=E6=97=B6=E5=AF=BC=E8=87=B4?= =?UTF-8?q?=E7=9A=84=E9=BB=91=E5=B1=8F=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cloudphone/apiimpl/CloudPhoneImpl.java | 23 +++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/cloudphone/src/main/java/com/huawei/cloudphone/apiimpl/CloudPhoneImpl.java b/cloudphone/src/main/java/com/huawei/cloudphone/apiimpl/CloudPhoneImpl.java index d7e960a..51a2067 100644 --- a/cloudphone/src/main/java/com/huawei/cloudphone/apiimpl/CloudPhoneImpl.java +++ b/cloudphone/src/main/java/com/huawei/cloudphone/apiimpl/CloudPhoneImpl.java @@ -66,11 +66,9 @@ import com.huawei.cloudphone.virtualdevice.common.VirtualDeviceManager; import com.huawei.cloudphone.virtualdevice.common.VirtualDeviceProtocol; import com.huawei.cloudphone.virtualdevice.sensor.VirtualSensorManager; -import java.nio.charset.StandardCharsets; import java.security.SecureRandom; import java.util.HashMap; import java.util.Map; -import java.util.Objects; import java.util.Timer; import java.util.TimerTask; @@ -135,6 +133,7 @@ public class CloudPhoneImpl implements ICloudPhone { private int mTouchCount = 0; private VelocityTracker mVelocityTracker = VelocityTracker.obtain(); private Toast toast = null; + private int surfaceId = -1; // 避免快速连接时新的窗口已建立,旧的窗口执行销毁操作发送pause private long initTime = 0; @@ -407,14 +406,26 @@ public class CloudPhoneImpl implements ICloudPhone { mSurfaceView = new PhoneView(activity, false); } mSurfaceView.getHolder().addCallback(new SurfaceHolder.Callback() { + private int curSurfaceId; + @Override public void surfaceCreated(SurfaceHolder holder) { - CASLog.i(TAG, "surfaceCreated..."); + SecureRandom random = new SecureRandom(); + curSurfaceId = random.nextInt(10000); + while (curSurfaceId == surfaceId) { + curSurfaceId = random.nextInt(10000); + } + surfaceId = curSurfaceId; + CASLog.i(TAG, "surfaceCreated, surfaceId:" + this.curSurfaceId); mIsNewCreated = true; } @Override public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { + if (this.curSurfaceId != surfaceId) { + CASLog.w(TAG, "cancel surfaceChanged(). curSurfaceId:" + this.curSurfaceId + ", surfaceId:" + surfaceId); + return; + } mDisplayWidth = Math.min(width, height); mDisplayHeight = Math.max(width, height); @@ -442,9 +453,13 @@ public class CloudPhoneImpl implements ICloudPhone { @Override public void surfaceDestroyed(SurfaceHolder holder) { + if (this.curSurfaceId != surfaceId) { + CASLog.w(TAG, "cancel surfaceDestroyed(). curSurfaceId:" + this.curSurfaceId + ", surfaceId:" + surfaceId); + return; + } synchronized (mCloudPhoneLock) { try { - CASLog.i(TAG, "surfaceDestroyed..."); + CASLog.i(TAG, "surfaceDestroyed, surfaceId:" + surfaceId); if (mProccessor != null && mProccessor.getState() != JNIState.JNI_STOPPED) { mProccessor.stop(true); } -- Gitee