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 d7e960a2eef7312072183c10848f44a11662dce2..51a20670fa8ce6f12f4b9f03d390f4c1df78f7fc 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); }