diff --git a/README.md b/README.md index 725372c86a518055c47f9c6301441f47ac27fa59..4392831b7a48d9892aacbea4cd44f1d713fdc251 100644 --- a/README.md +++ b/README.md @@ -343,25 +343,8 @@ https://gitee.com/HuaweiCloudDeveloper/huaweicloud-cloudPhoneAccess-android/rele clouPhone.exitCloudPhone(); -#### 4.7 静音/取消静音 -- 接口介绍 - - void mute(); - - void unmute(); - -- 功能描述 - - 设置静音/取消静音。 - -- 调用示例 - - cloudPhone.mute(); - - cloudPhone.unmute(); - -#### 4.8 设置音视频参数 +#### 4.7 设置音视频参数 - 接口介绍 @@ -385,7 +368,7 @@ https://gitee.com/HuaweiCloudDeveloper/huaweicloud-cloudPhoneAccess-android/rele cloudPhone.setMediaConfig(mediaConfig); -#### 4.9 设置图像显示模式 +#### 4.8 设置图像显示模式 - 接口介绍 @@ -407,7 +390,7 @@ https://gitee.com/HuaweiCloudDeveloper/huaweicloud-cloudPhoneAccess-android/rele cloudPhone.setDisplayMode(CloudPhoneParas.DisplayMode.DISPLAY_MODE_FIT); -#### 4.10 注册状态监听 +#### 4.9 注册状态监听 - 接口介绍 @@ -437,7 +420,7 @@ https://gitee.com/HuaweiCloudDeveloper/huaweicloud-cloudPhoneAccess-android/rele ); ``` -#### 4.11 注册方向变化监听 +#### 4.10 注册方向变化监听 - 接口介绍 @@ -468,7 +451,7 @@ https://gitee.com/HuaweiCloudDeveloper/huaweicloud-cloudPhoneAccess-android/rele ); ``` -#### 4.12 注册虚拟设备数据监听 +#### 4.11 注册虚拟设备数据监听 - 接口介绍 @@ -498,7 +481,7 @@ https://gitee.com/HuaweiCloudDeveloper/huaweicloud-cloudPhoneAccess-android/rele } ); ``` -#### 4.13 发送虚拟设备数据 +#### 4.12 发送虚拟设备数据 - 接口介绍 @@ -518,7 +501,7 @@ https://gitee.com/HuaweiCloudDeveloper/huaweicloud-cloudPhoneAccess-android/rele cloudPhone.sendVirtualDeviceData(data, CAMERA_DATA); -#### 4.14 获取网络时延 +#### 4.13 获取网络时延 - 接口介绍 @@ -532,7 +515,7 @@ https://gitee.com/HuaweiCloudDeveloper/huaweicloud-cloudPhoneAccess-android/rele cloudPhone.getRtt(); -#### 4.15 双向通道 数据发送接口(支持登录、支付场景) +#### 4.14 双向通道 数据发送接口(支持登录、支付场景) - 接口介绍 diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 10fa95b09f7b2091d21840519a18279907bab768..c9378b254649c8cb01dc7f28a41e33d94dc37a3f 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -54,11 +54,6 @@ android:theme="@style/AppTheme" android:windowSoftInputMode="adjustResize" /> - \ No newline at end of file diff --git a/app/src/main/java/com/huawei/cloudapp/ui/CasCloudPhoneActivity.java b/app/src/main/java/com/huawei/cloudapp/ui/CasCloudPhoneActivity.java index b498ad162661f5ff362aa9568257d5f8fd3e48e4..f42deec11dc020fc1da08f5ca9baa9f3a5aee257 100644 --- a/app/src/main/java/com/huawei/cloudapp/ui/CasCloudPhoneActivity.java +++ b/app/src/main/java/com/huawei/cloudapp/ui/CasCloudPhoneActivity.java @@ -69,6 +69,7 @@ import com.huawei.cloudphone.api.CloudPhoneParas; import com.huawei.cloudphone.api.CloudPhoneStateListener; import com.huawei.cloudphone.api.CloudPhoneVirtualDevDataListener; import com.huawei.cloudphone.api.ICloudPhone; +import com.huawei.cloudphone.apiimpl.CloudPhoneImpl; import com.huawei.cloudphone.utils.CasHttpUtils; import com.huawei.cloudphone.virtualdevice.VirtualDeviceSession; import com.huawei.cloudphone.virtualdevice.common.RingBufferVirtualDeviceIO; @@ -145,7 +146,7 @@ public class CasCloudPhoneActivity extends FragmentActivity implements View.OnCl private static final int STATE_DEINIT = 1; private static CasCloudPhoneActivity gAcitivity = null; private static CasListener mCasListener = null; - private static final int DOUBLE_CLICK_TIME_DELTA = 500; + private static final int DOUBLE_CLICK_TIME_DELTA = 200; private long lastClickTime = 0; // flag @@ -349,7 +350,7 @@ public class CasCloudPhoneActivity extends FragmentActivity implements View.OnCl ctrlSwitch.setChecked(true); gAcitivity = this; try { - mCloudPhone = CloudPhoneManager.createCloudPhoneInstance(); + mCloudPhone = CloudPhoneManager.createCloudPhoneInstance(); mCloudPhone.setDisplayMode(CloudPhoneParas.DisplayMode.DISPLAY_MODE_FILL); mCloudPhone.init(this, DEV_PHONE); @@ -436,7 +437,6 @@ public class CasCloudPhoneActivity extends FragmentActivity implements View.OnCl public void onStop() { CASLog.i(TAG, "onStop"); super.onStop(); - mCloudPhone.mute(); } /** @@ -467,7 +467,6 @@ public class CasCloudPhoneActivity extends FragmentActivity implements View.OnCl message.what = MSG_SHOW_TRAIL_PLAY_TIMEOUT; handler.sendMessage(message); } - mCloudPhone.unmute(); } /** diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index f52aea9ea90f22c2fb0c969a792e295d1e8dd1b3..bc16f09d7f8ab0b0275291954e8c1d19e2922b0c 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -14,12 +14,12 @@ 启动失败 认证失败 获取认证信息失败 - 资源正在使用中,请稍后 + 连接被占用,请稍后重试 自动连接失败,请尝试手动连接 重连 正在尝试重新连接,请稍后 - 与服务器连接出现异常 - 与服务器连接出现异常 + 与服务器连接断开,请重新进入 + 与服务器连接断开,请重新进入 当前网络开小差 验证失败 试玩时间已到 diff --git a/cloudphone/proguard-rules.pro b/cloudphone/proguard-rules.pro index 9ae459279795e34f3b9cf71a23a651265c0002d4..c817384079122ce2e848b702714422d8a54bf912 100644 --- a/cloudphone/proguard-rules.pro +++ b/cloudphone/proguard-rules.pro @@ -29,5 +29,4 @@ -keep public enum com.huawei.cloudphone.api.CloudPhoneParas$* {*;} -keep interface com.huawei.cloudphone.service.CasInteractiveStateCallback {*;} --keep class com.huawei.cloudphone.service.CASClient {*;} -keep class com.huawei.cloudphone.utils.CasDevRandomSeed {*;} \ No newline at end of file diff --git a/cloudphone/src/main/AndroidManifest.xml b/cloudphone/src/main/AndroidManifest.xml index 9067f34f1931bcc3a5f69a7bff45f5e4b941c51c..499423753c222201deb8f682cfe6c0e6fc3d04e9 100644 --- a/cloudphone/src/main/AndroidManifest.xml +++ b/cloudphone/src/main/AndroidManifest.xml @@ -2,11 +2,5 @@ package="com.huawei.cloudphone"> - - \ No newline at end of file diff --git a/cloudphone/src/main/aidl/com/huawei/cloudphone/ICASAidlInterface.aidl b/cloudphone/src/main/aidl/com/huawei/cloudphone/ICASAidlInterface.aidl deleted file mode 100644 index 21b9d451e151403692b9110c0b85524424bbf284..0000000000000000000000000000000000000000 --- a/cloudphone/src/main/aidl/com/huawei/cloudphone/ICASAidlInterface.aidl +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright 2022 Huawei Cloud Computing Technology Co., Ltd. - * - * 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. - */ - -// ICASAidlInterfaceCasCloudAppActivityaidl -package com.huawei.cloudphone; - -// Declare any non-default types here with import statements -import android.view.Surface; -import com.huawei.cloudphone.ICASAidlListener; -import com.huawei.cloudphone.common.CasConnectorInfo; -import com.huawei.cloudphone.common.CasParcelableMap; - -interface ICASAidlInterface { - /** - * Demonstrates some basic types that you can use as parameters - * and return values in AIDL. - */ - void init(); - - void setEncryptData(in String encryptData); - - void setSurface(in Surface suf); - - boolean start(in boolean isHome); - - void stop(in boolean isHome); - - void pause(); - - void resume(); - - boolean isConnect(); - - int getState(); - - boolean reconnect(); - - void registerListener(in IBinder listener); - - void unregisterListener(); - - boolean sendTouchEvent(in int id, in int action, in int x, in int y, in int pressure, long time, int orientation, int height, int width); - - boolean sendKeyEvent(int keycode, int action); - - boolean sendMotionEvent(int materAxis, int materValue, int secondaryAxis, int secondaryValue); - - void setCasConnectorInfo(in CasConnectorInfo info); - - void setMediaConfig(in CasParcelableMap mediaConfigMap); - - boolean setRotation(in int rotation); - - int getLag(); - - boolean startJniRecv(); - - void stopJniRecv(); - - void mute(in boolean isMute); - - void sendData(byte type, in byte[] data); -} diff --git a/cloudphone/src/main/aidl/com/huawei/cloudphone/ICASAidlListener.aidl b/cloudphone/src/main/aidl/com/huawei/cloudphone/ICASAidlListener.aidl deleted file mode 100644 index 948d7c2316a2a804ca1e90ed68b79cf0d8eaba4b..0000000000000000000000000000000000000000 --- a/cloudphone/src/main/aidl/com/huawei/cloudphone/ICASAidlListener.aidl +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright 2022 Huawei Cloud Computing Technology Co., Ltd. - * - * 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. - */ - -// ICASAidlListener.aidl -package com.huawei.cloudphone; - -// Declare any non-default types here with import statements - -interface ICASAidlListener { - - void onRotationDirectionChange(int msg); - - void onCmdRecv(int code, String msg); - - void onChannelDataRecv(in byte[] data); - - void onVirtualDevDataRecv(in byte[] data); - - void onImeMsgRecv(in byte[] data); -} diff --git a/cloudphone/src/main/aidl/com/huawei/cloudphone/common/CasConnectorInfo.aidl b/cloudphone/src/main/aidl/com/huawei/cloudphone/common/CasConnectorInfo.aidl deleted file mode 100644 index aeba215af7dfb7e81d0deb7d1e74f8b086c76654..0000000000000000000000000000000000000000 --- a/cloudphone/src/main/aidl/com/huawei/cloudphone/common/CasConnectorInfo.aidl +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright 2022 Huawei Cloud Computing Technology Co., Ltd. - * - * 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. - */ - -// CasConnectorInfo.aidl -package com.huawei.cloudphone.common; -// Declare any non-default types here with import statements - -parcelable CasConnectorInfo; diff --git a/cloudphone/src/main/aidl/com/huawei/cloudphone/common/CasParcelableMap.aidl b/cloudphone/src/main/aidl/com/huawei/cloudphone/common/CasParcelableMap.aidl deleted file mode 100644 index 8dfcf3f6a8fb8182c047ef0cbe118b6ebe939840..0000000000000000000000000000000000000000 --- a/cloudphone/src/main/aidl/com/huawei/cloudphone/common/CasParcelableMap.aidl +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright 2022 Huawei Cloud Computing Technology Co., Ltd. - * - * 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. - */ - -// CasParcelableMap.aidl -package com.huawei.cloudphone.common; -// Declare any non-default types here with import statements - -parcelable CasParcelableMap; \ No newline at end of file diff --git a/cloudphone/src/main/cpp/CasController.cpp b/cloudphone/src/main/cpp/CasController.cpp index 634d183126e25dd8849949f588262173025ec538..135df22dacad9c7863df6b079daebfaa2c7bf0f9 100644 --- a/cloudphone/src/main/cpp/CasController.cpp +++ b/cloudphone/src/main/cpp/CasController.cpp @@ -482,7 +482,19 @@ bool CasController::DestroyWorkers() bool CasController::BuildConnection() { NotifyCommand(CAS_CONNECTING, CasMsgCode::GetMsg(CAS_CONNECTING)); - int connectRes = m_casClientSocket->Connect(); + int connectRes = -2; + int retry = 0; + while ((connectRes == -1 || connectRes == -2) && retry < 3) { + retry++; + INFO("Connect times: %d", retry); + connectRes = m_casClientSocket->Connect(); + if (connectRes >= 0) { + break; + } else { + usleep(500000); + } + } + if (connectRes == -1) { this->SetState(CONNECTION_FAILURE); NotifyCommand(CAS_SERVER_UNREACHABLE, CasMsgCode::GetMsg(CAS_SERVER_UNREACHABLE)); diff --git a/cloudphone/src/main/java/com/huawei/cloudphone/api/ICloudPhone.java b/cloudphone/src/main/java/com/huawei/cloudphone/api/ICloudPhone.java index f97b656928e0582bb9a401c2f608667230f04ea9..5c03089ddc2f3f88ca55935d80fbc91cee6e4d6c 100644 --- a/cloudphone/src/main/java/com/huawei/cloudphone/api/ICloudPhone.java +++ b/cloudphone/src/main/java/com/huawei/cloudphone/api/ICloudPhone.java @@ -62,16 +62,6 @@ public interface ICloudPhone { */ void exitCloudPhone() throws Exception; - /** - * 静音 - */ - void mute(); - - /** - * 取消静音 - */ - void unmute(); - /** * 设置音视频参数 * 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 2cc6f83dd99d1521cda3e778c19031d29e9d20ce..cfafdee3119a41945ee71b7aea2b0495cce31630 100644 --- a/cloudphone/src/main/java/com/huawei/cloudphone/apiimpl/CloudPhoneImpl.java +++ b/cloudphone/src/main/java/com/huawei/cloudphone/apiimpl/CloudPhoneImpl.java @@ -17,16 +17,12 @@ package com.huawei.cloudphone.apiimpl; import android.app.Activity; -import android.content.ComponentName; import android.content.Context; -import android.content.Intent; -import android.content.ServiceConnection; import android.content.pm.ActivityInfo; import android.graphics.PixelFormat; import android.os.Handler; import android.os.HandlerThread; -import android.os.IBinder; import android.os.Looper; import android.os.Message; import android.os.RemoteException; @@ -41,8 +37,6 @@ import android.view.ViewGroup; import android.widget.FrameLayout; import com.huawei.cloudphone.BuildConfig; -import com.huawei.cloudphone.ICASAidlInterface; -import com.huawei.cloudphone.ICASAidlListener; import com.huawei.cloudphone.api.CloudAppDataListener; import com.huawei.cloudphone.api.CloudPhoneOrientationChangeListener; import com.huawei.cloudphone.api.CloudPhoneParas; @@ -54,12 +48,11 @@ import com.huawei.cloudphone.common.CASLog; import com.huawei.cloudphone.common.CasConnectorInfo; import com.huawei.cloudphone.common.CasParcelableMap; import com.huawei.cloudphone.common.CasState; -import com.huawei.cloudphone.service.CASClient; -import com.huawei.cloudphone.service.CASService; +import com.huawei.cloudphone.jniwrapper.JNIWrapper; +import com.huawei.cloudphone.service.CasProcessor; import com.huawei.cloudphone.virtualdevice.VirtualDeviceSession; import com.huawei.cloudphone.virtualdevice.common.RingBufferVirtualDeviceIO; -import java.net.BindException; import java.util.HashMap; import java.util.Map; import java.util.Timer; @@ -95,7 +88,7 @@ public class CloudPhoneImpl implements ICloudPhone { private static final byte IME_DATA =14; private final Object mCloudPhoneLock = new Object(); - private CASClient mCASClient = null; + private CasProcessor mProccessor = null; private Map mStartParas = null; private Context mContext = null; private Handler mCmdHandler = null; @@ -107,7 +100,6 @@ public class CloudPhoneImpl implements ICloudPhone { private int mDisplayHeight = 0; private int mCurrentState; private DisplayMode mDisplayMode = DISPLAY_MODE_FILL; - private boolean mServiceConnect = false; private boolean mIsSurfaceDestroyed = true; private Timer mBackGroundTimer = null; private int mAutoReconnectCount = 0; @@ -118,9 +110,7 @@ public class CloudPhoneImpl implements ICloudPhone { private CloudPhoneOrientationChangeListener mOrientationChangeListener = null; private CloudPhoneVirtualDevDataListener mVirtualDevDataListener = null; private CloudAppDataListener mChannelDataListener = null; - private ServiceConnection mConnection = null; private CASListener mListener = null; - private volatile boolean mIsMute = false; private volatile boolean mIsStartSuccess = false; private CloudPhoneParas.DevType mDevType; private CasConnectorInfo mConnectorInfo = null; @@ -154,18 +144,16 @@ public class CloudPhoneImpl implements ICloudPhone { CASLog.e(TAG, "Not ready for init. current state is " + mCurrentState); throw new IllegalStateException("Not ready for init."); } - mConnection = new CloudPhoneServiceConnection(); - mCASClient = new CASClient(); + + mProccessor = new CasProcessor(); mListener = new CASListener(); mContext = context; - mServiceConnect = false; + + mProccessor.init(); + mProccessor.registerListener(mListener); + initVirtualDeviceSession(); - Intent intent = new Intent(mContext, CASService.class); - boolean ret = mContext.bindService(intent, mConnection, Context.BIND_AUTO_CREATE); - if (!ret) { - CASLog.e(TAG, "Bind service failed."); - throw new BindException("Bind service failed."); - } + mCmdHandlerThread = new HandlerThread("cmd process"); if (mCmdHandlerThread == null) { CASLog.e(TAG,"Create handler thread failed."); @@ -185,12 +173,10 @@ public class CloudPhoneImpl implements ICloudPhone { CASLog.i(TAG, "deinit called"); mCmdHandlerThread.quit(); mCmdHandlerThread.join(); - mCASClient.registerListener(null); - mContext.unbindService(mConnection); - mConnection = null; + mProccessor.registerListener(null); mCmdHandlerThread = null; mCurrentState = STATE_DEINIT; - mCASClient = null; + mProccessor = null; mContext = null; mStateListener = null; mOrientationChangeListener = null; @@ -241,8 +227,8 @@ public class CloudPhoneImpl implements ICloudPhone { mBackGroundTimer.cancel(); mBackGroundTimer = null; } - mCASClient.stopJniRecv(); - mCASClient.stop(false); + mProccessor.stopJniRecv(); + mProccessor.stop(false); mCmdHandler = null; mCurrentState = STATE_INIT; mSurfaceView.setOnTouchListener(null); @@ -266,22 +252,6 @@ public class CloudPhoneImpl implements ICloudPhone { } } - @Override - public void mute() { - if (mCASClient != null) { - mCASClient.mute(true); - } - mIsMute = true; - } - - @Override - public void unmute() { - if (mCASClient != null) { - mCASClient.mute(false); - } - mIsMute = false; - } - @Override public void setMediaConfig(HashMap mediaConfig) { if (mCmdHandler == null) { @@ -304,8 +274,8 @@ public class CloudPhoneImpl implements ICloudPhone { @Override public void sendDataToCloudApp(byte[] data) { - if (mCASClient != null) { - mCASClient.sendDataToCloudApp(data); + if (mProccessor != null) { + mProccessor.sendData(JNIWrapper.CHANNEL, data); } } @@ -326,15 +296,15 @@ public class CloudPhoneImpl implements ICloudPhone { @Override public void sendVirtualDeviceData(byte devType, byte[] data) { - if (mCASClient != null) { - mCASClient.sendDataToVirtualDevice(devType, data); + if (mProccessor != null) { + mProccessor.sendData(devType, data); } } @Override public int getRtt() { - if (mCASClient != null) { - return mCASClient.getLag(); + if (mProccessor != null) { + return mProccessor.getLag(); } else { return 0; } @@ -384,11 +354,6 @@ public class CloudPhoneImpl implements ICloudPhone { mDisplayHeight = Math.max(width, height); CASLog.i(TAG, "width = " + mDisplayWidth + " height = " + mDisplayHeight); - if (!mServiceConnect) { - mStateListener.onNotify(CasState.CAS_CONNECT_LOST, "Connect lost"); - return; - } - if (!mIsNewCreated) { return; } @@ -414,8 +379,8 @@ public class CloudPhoneImpl implements ICloudPhone { synchronized (mCloudPhoneLock) { try { CASLog.i(TAG, "surfaceDestroyed..."); - if (mCASClient != null && mCASClient.getState() != JNIState.JNI_STOPPED) { - mCASClient.stop(true); + if (mProccessor != null && mProccessor.getState() != JNIState.JNI_STOPPED) { + mProccessor.stop(true); } if (mCmdHandler != null) { Message msg = new Message(); @@ -511,7 +476,7 @@ public class CloudPhoneImpl implements ICloudPhone { return false; } CASLog.i(TAG, "keyCode = " + keyCode + " event = " + event.toString()); - mCASClient.sendKeyEvent(keyCode, event.getAction()); + mProccessor.sendKeyEvent(keyCode, event.getAction()); return true; } }); @@ -537,22 +502,21 @@ public class CloudPhoneImpl implements ICloudPhone { private void handleSurfaceCreateCmd(Message msg) { synchronized (mCloudPhoneLock) { try { - mCASClient.setCasConnectorInfo(mConnectorInfo); + mProccessor.setCasConnectorInfo(mConnectorInfo); CASLog.i(TAG, "handleSurfaceCreateCmd mCurrentState = " + mCurrentState); if (mCurrentState == STATE_STARTING) { - mCASClient.setSurface(mSurfaceView.getHolder().getSurface()); - mCASClient.startJniRecv(); - if (mCASClient.start(false)) { + mProccessor.setSurface(mSurfaceView.getHolder().getSurface()); + mProccessor.startJniRecv(); + if (mProccessor.start(false)) { mIsReconnectTaskRun = true; mCheckConnectStateThread = new CheckConnectStateThread(); mCheckConnectStateThread.start(); } - mCASClient.mute(mIsMute); mCurrentState = STATE_START; } else if (mCurrentState == STATE_PAUSE) { - mCASClient.setSurface(mSurfaceView.getHolder().getSurface()); - mCASClient.startJniRecv(); - mCASClient.start(true); + mProccessor.setSurface(mSurfaceView.getHolder().getSurface()); + mProccessor.startJniRecv(); + mProccessor.start(true); mCurrentState = STATE_START; if (mBackGroundTimer != null) { mBackGroundTimer.cancel(); @@ -575,7 +539,7 @@ public class CloudPhoneImpl implements ICloudPhone { try { if (mCurrentState == STATE_START) { CASLog.i(TAG, "handleSurfaceDestroyCmd end"); - mCASClient.pause(); + mProccessor.pause(); mCurrentState = STATE_PAUSE; mBackGroundTimer = new Timer(); mBackGroundTimer.schedule(new BackgroundTimerTask(), mBgTimeout); @@ -597,7 +561,7 @@ public class CloudPhoneImpl implements ICloudPhone { HashMap mediaConfig = (HashMap) msg.obj; CasParcelableMap parcelableMap = new CasParcelableMap(); parcelableMap.setParcelableMap(mediaConfig); - mCASClient.setMediaConfig(parcelableMap); + mProccessor.setMediaConfig(parcelableMap); } catch (Exception e) { CASLog.e(TAG, "handleSetMediaConfigCmd failed. " + e.getMessage()); } finally { @@ -629,8 +593,8 @@ public class CloudPhoneImpl implements ICloudPhone { mCheckConnectStateThread.interrupt(); mCheckConnectStateThread = null; } - mCASClient.stopJniRecv(); - mCASClient.stop(false); + mProccessor.stopJniRecv(); + mProccessor.stop(false); } } else if (state == CasState.CAS_START_SUCCESS) { mIsStartSuccess = true; @@ -664,8 +628,8 @@ public class CloudPhoneImpl implements ICloudPhone { } mCheckConnectStateThread = null; } - mCASClient.stopJniRecv(); - mCASClient.stop(false); + mProccessor.stopJniRecv(); + mProccessor.stop(false); mCurrentState = STATE_INIT; mSurfaceView = null; mActivity = null; @@ -694,11 +658,11 @@ public class CloudPhoneImpl implements ICloudPhone { return; } CASLog.i(TAG, "reconnect mAutoReconnectCount=" + mAutoReconnectCount); - mCASClient.stopJniRecv(); - if (mCASClient.reconnect()) { - int status = mCASClient.getState(); + mProccessor.stopJniRecv(); + if (mProccessor.reconnect()) { + int status = mProccessor.getState(); if (status == JNIState.JNI_CONNECTED) { - mCASClient.startJniRecv(); + mProccessor.startJniRecv(); mAutoReconnectCount = 0; mAutoReconnectTimer = null; mReconnecting = false; @@ -780,7 +744,7 @@ public class CloudPhoneImpl implements ICloudPhone { x = x1 * mDisplayWidth / mDisplayHeight; y = y1 * mDisplayHeight / mDisplayWidth; } - return mCASClient.sendTouchEvent(id, action, x, y, pressure, time, newOrientation, mDisplayHeight, mDisplayWidth); + return mProccessor.sendTouchEvent(id, action, x, y, pressure, time, newOrientation, mDisplayHeight, mDisplayWidth); } private void initVirtualDeviceSession() { @@ -817,13 +781,6 @@ public class CloudPhoneImpl implements ICloudPhone { @Override public void handleMessage(Message msg) { - while (!mServiceConnect) { - try { - Thread.sleep(10); - } catch (InterruptedException e) { - CASLog.e(TAG, "handle message failed. " + e.getMessage()); - } - } switch (msg.what) { case CMD_START: CASLog.i(TAG, "CMD_START"); @@ -863,8 +820,7 @@ public class CloudPhoneImpl implements ICloudPhone { * listener *

receive jni notify msg

*/ - class CASListener extends ICASAidlListener.Stub { - @Override + public class CASListener { public void onRotationDirectionChange(int orientation) throws RemoteException { synchronized (this) { if (mOrientationChangeListener != null) { @@ -873,7 +829,6 @@ public class CloudPhoneImpl implements ICloudPhone { } } - @Override public void onCmdRecv(int code, String describe) throws RemoteException { CASLog.i(TAG, "code = " + code + " msg = " + describe); Message msg = new Message(); @@ -885,14 +840,12 @@ public class CloudPhoneImpl implements ICloudPhone { } } - @Override public void onChannelDataRecv(byte[] data) throws RemoteException { if (mChannelDataListener != null) { mChannelDataListener.onRecvCloudAppData(data); } } - @Override public void onVirtualDevDataRecv(byte[] data) throws RemoteException { if (mVirtualDevDataListener != null) { mVirtualDevDataListener.onRecvVirtualDevData(data, data.length); @@ -945,7 +898,7 @@ public class CloudPhoneImpl implements ICloudPhone { mReconnecting = false; while (mIsReconnectTaskRun) { if (!mReconnecting && (mCurrentState != STATE_PAUSE)) { - boolean isConnected = mCASClient.isConnect(); + boolean isConnected = mProccessor.isConnect(); if (!isConnected) { Message msg = new Message(); msg.what = CMD_RECONNECT; @@ -964,29 +917,10 @@ public class CloudPhoneImpl implements ICloudPhone { } } - class CloudPhoneServiceConnection implements ServiceConnection { - @Override - public void onServiceConnected(ComponentName name, IBinder service) { - CASLog.i(TAG, "onServiceConnected called"); - ICASAidlInterface casInterface = ICASAidlInterface.Stub.asInterface(service); - mCASClient.setInterface(casInterface); - mCASClient.init(); - mCASClient.registerListener(mListener.asBinder()); - mServiceConnect = true; - } - - @Override - public void onServiceDisconnected(ComponentName name) { - CASLog.i(TAG, "onServiceDisconnected called"); - mCASClient.setInterface(null); - mServiceConnect = false; - } - } - class TextWatchListener implements CloudPhoneTextWatchListener { @Override public void onTextChange(byte[] data) { - mCASClient.sendDataToIme(data); + mProccessor.sendData(JNIWrapper.IMEDATA, data); } } diff --git a/cloudphone/src/main/java/com/huawei/cloudphone/audio/AudioTrackerCallback.java b/cloudphone/src/main/java/com/huawei/cloudphone/audio/AudioTrackerCallback.java index 73e8625534ef4368f2cc4dd6a7dfdd13e64cfbd5..7664cb6784b5bfa950992e2f1c510c4bd02601d5 100644 --- a/cloudphone/src/main/java/com/huawei/cloudphone/audio/AudioTrackerCallback.java +++ b/cloudphone/src/main/java/com/huawei/cloudphone/audio/AudioTrackerCallback.java @@ -29,6 +29,7 @@ import com.huawei.cloudphone.jniwrapper.OpusJNIWrapper; import java.util.ArrayList; import java.util.Arrays; import java.util.Date; +import java.util.Objects; /** * AudioTrackerCallback @@ -36,54 +37,21 @@ import java.util.Date; public class AudioTrackerCallback implements NewPacketCallback { private static final String TAG = "CASAudioTrackerCallback"; - private static final int MAX_BUFFER_LEN = 1024 * 1024; // 1MB - private static SparseArray sTrackMap = new SparseArray<>(32); + private SparseArray sTrackMap = new SparseArray<>(32); // Mute audio when running in background - private static volatile boolean isMute = false; private ArrayList dataList; private int maxSize; - private int fixedPid = 1001; - // 波形速度 private int mWaveSpeed = 700; - private long mLastDate; - private int mAudioPktCountPerSeconds = 0; - public AudioTrackerCallback() { sTrackMap.clear(); - Date date = new Date(System.currentTimeMillis()); - mLastDate = date.getTime(); - } - - // Mute audio when running in background - public static void setMute(boolean mute) { - isMute = mute; - for (int i = 0; i < sTrackMap.size(); i++) { - if (mute) { - sTrackMap.valueAt(i).mute(); - } else { - sTrackMap.valueAt(i).unMute(); - } - } } @Override public void onNewPacket(byte[] data) { // put the message to its thread's message queue. - Date curDate = new Date(System.currentTimeMillis()); - - CASLog.d(TAG, "lastTime:" + mLastDate + "curTime:" + curDate.getTime()); - - if (curDate.getTime() - mLastDate > 1000) { - CASLog.d(TAG, "AudioPktCountPerSeconds:" + mAudioPktCountPerSeconds); - mLastDate = curDate.getTime(); - mAudioPktCountPerSeconds = 0; - } else { - mAudioPktCountPerSeconds++; - } - short[] music = (!isBigEnd()) ? byteArray2ShortArrayLittle(data, data.length / 2) : byteArray2ShortArrayBig(data, data.length / 2); sendData(music, music.length); @@ -93,16 +61,12 @@ public class AudioTrackerCallback implements NewPacketCallback { CasRemoteMessage msg = new CasRemoteMessage(data, 0, data.length); int pid = fixedPid; - CASLog.d(TAG, "receive audio data length : " + data.length); - CasAudioPlayer casAudioPlayer = sTrackMap.get(pid, null); if (casAudioPlayer == null) { - CASLog.d(TAG, "new CasAudioPlayer:" + pid); casAudioPlayer = new CasAudioPlayer(pid); sTrackMap.put(pid, casAudioPlayer); } - CASLog.d(TAG, "reuse CasAudioPlayer: " + pid); casAudioPlayer.onReceiveMsg(msg); } @@ -172,6 +136,8 @@ public class AudioTrackerCallback implements NewPacketCallback { if (casAudioPlayer != null) { casAudioPlayer.closeAudioTracker(); } + sTrackMap.clear(); + sTrackMap = null; } class CasAudioPlayer { @@ -189,22 +155,6 @@ public class AudioTrackerCallback implements NewPacketCallback { mPid = pid; } - public void mute() { - CASLog.d(TAG, "Mute trackPlayer is " + mTrackPlayer); - - if (mTrackPlayer != null) { - mTrackPlayer.setStereoVolume(0, 0); - } - } - - public void unMute() { - CASLog.d(TAG, "UnMute trackPlayer is " + mTrackPlayer); - - if (mTrackPlayer != null) { - mTrackPlayer.setStereoVolume(vl, vr); - } - } - public void onReceiveMsg(CasRemoteMessage msg) { handleSet(msg); handleStart(msg); @@ -218,7 +168,6 @@ public class AudioTrackerCallback implements NewPacketCallback { private void handleSet(CasRemoteMessage msg) { if (mTrackPlayer != null) { - CASLog.d(TAG, "handleSet trackPlayer is already set"); return; } @@ -233,7 +182,6 @@ public class AudioTrackerCallback implements NewPacketCallback { int sampleSize = 2; mBufferLenPerSecond = sampleRateInHz * sampleSize * channelCount; - CASLog.d(TAG, "mBufferLenPerSecond is " + mBufferLenPerSecond); int minBufferLen = AudioTrack.getMinBufferSize(sampleRateInHz, channelConfig, audioFormat); @@ -241,7 +189,6 @@ public class AudioTrackerCallback implements NewPacketCallback { if (bufferSizeInBytes < bufferSizeOf200Ms) { bufferSizeInBytes = bufferSizeOf200Ms; - CASLog.d(TAG, "bufferSizeInBytes is less than bufferSizeOf200Ms so use " + bufferSizeOf200Ms); } try { @@ -257,12 +204,6 @@ public class AudioTrackerCallback implements NewPacketCallback { return; } - if (isMute) { - mute(); - } else { - unMute(); - } - try { mTrackPlayer.play(); } catch (IllegalStateException e) { @@ -303,17 +244,19 @@ public class AudioTrackerCallback implements NewPacketCallback { } private void handleDestruct(CasRemoteMessage msg) { - if (mTrackPlayer == null) { return; } - mTrackPlayer.release(); if (mDecoder != 0) { OpusJNIWrapper.destroyOpusDecoder(mDecoder); mDecoder = 0; } - sTrackMap.delete(mPid); + if (sTrackMap != null && sTrackMap.get(mPid) != null) { + sTrackMap.remove(mPid); + } + + mTrackPlayer.release(); mTrackPlayer = null; } } diff --git a/cloudphone/src/main/java/com/huawei/cloudphone/service/CASClient.java b/cloudphone/src/main/java/com/huawei/cloudphone/service/CASClient.java deleted file mode 100644 index 512428c2701e2424aded5b715f0908c09a91ea65..0000000000000000000000000000000000000000 --- a/cloudphone/src/main/java/com/huawei/cloudphone/service/CASClient.java +++ /dev/null @@ -1,355 +0,0 @@ -/* - * Copyright 2022 Huawei Cloud Computing Technology Co., Ltd. - * - * 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. - */ - -package com.huawei.cloudphone.service; - -import static com.huawei.cloudphone.jniwrapper.JNIWrapper.CHANNEL; -import static com.huawei.cloudphone.jniwrapper.JNIWrapper.IMEDATA; - -import android.os.IBinder; -import android.os.RemoteException; -import android.view.Surface; - -import com.huawei.cloudphone.ICASAidlInterface; -import com.huawei.cloudphone.common.CASLog; -import com.huawei.cloudphone.common.CasConnectorInfo; -import com.huawei.cloudphone.common.CasParcelableMap; - -/** - * CASClient - */ -public class CASClient { - - /** - * TAG:CASClient - */ - private static final String TAG = "CASClient"; - /** - * cas client - */ - private static CASClient gCASClient = null; - /** - * cas interface - */ - private ICASAidlInterface mCasInterface = null; - - public CASClient() { - mCasInterface = null; - } - - public static synchronized CASClient getInstance() { - if (gCASClient == null) { - gCASClient = new CASClient(); - } - return gCASClient; - } - - public void setInterface(ICASAidlInterface casInterface) { - mCasInterface = casInterface; - } - - public void init() { - if (mCasInterface == null) { - return; - } - try { - mCasInterface.init(); - } catch (RemoteException e) { - CASLog.e(TAG, "filed to call init"); - } - } - - public void setEncryptData(String encryptData) { - if (mCasInterface == null) { - return; - } - try { - mCasInterface.setEncryptData(encryptData); - } catch (RemoteException e) { - CASLog.e(TAG, "filed to call setEncryptData"); - } - } - - public void setSurface(Surface suf) { - if (mCasInterface == null) { - return; - } - try { - mCasInterface.setSurface(suf); - } catch (RemoteException e) { - CASLog.e(TAG, "filed to call setSurface"); - } - } - - public boolean start(boolean isHome) { - if (mCasInterface == null) { - return false; - } - boolean ret; - try { - ret = mCasInterface.start(isHome); - } catch (RemoteException e) { - CASLog.e(TAG, "filed to call start"); - ret = false; - } - return ret; - } - - public void stop(boolean isHome) { - if (mCasInterface == null) { - return; - } - try { - mCasInterface.stop(isHome); - } catch (RemoteException e) { - CASLog.e(TAG, "filed to call stop"); - } - } - - public void pause() { - if (mCasInterface == null) { - return; - } - try { - mCasInterface.pause(); - } catch (RemoteException e) { - CASLog.e(TAG, "filed to call pause"); - } - } - - public void resume() { - if (mCasInterface == null) { - return; - } - try { - mCasInterface.resume(); - } catch (RemoteException e) { - CASLog.e(TAG, "filed to call resume"); - } - } - - public boolean isConnect() { - if (mCasInterface == null) { - return false; - } - boolean ret; - try { - ret = mCasInterface.isConnect(); - } catch (RemoteException e) { - CASLog.e(TAG, "filed to call isConnect"); - ret = false; - } - return ret; - } - - public boolean reconnect() { - if (mCasInterface == null) { - return false; - } - boolean ret; - try { - ret = mCasInterface.reconnect(); - } catch (RemoteException e) { - CASLog.e(TAG, "filed to call reconnect"); - ret = false; - } - return ret; - } - - public void registerListener(IBinder listener) { - if (mCasInterface == null) { - return; - } - try { - mCasInterface.registerListener(listener); - } catch (RemoteException e) { - CASLog.e(TAG, "filed to call registerListener"); - } - } - - public void unregisterListener() { - if (mCasInterface == null) { - return; - } - try { - mCasInterface.unregisterListener(); - } catch (RemoteException e) { - CASLog.e(TAG, "filed to call unregisterListener"); - } - } - - public boolean sendTouchEvent(int id, int action, int x, int y, int pressure, long time, int orientation, int height, int width) { - if (mCasInterface == null) { - return false; - } - boolean ret; - try { - ret = mCasInterface.sendTouchEvent(id, action, x, y, pressure, time, orientation, height, width); - } catch (RemoteException e) { - CASLog.e(TAG, "filed to call sendTouchEvent"); - ret = false; - } - return ret; - } - - public boolean sendKeyEvent(int keycode, int action) { - if (mCasInterface == null) { - return false; - } - boolean ret; - try { - ret = mCasInterface.sendKeyEvent(keycode, action); - } catch (RemoteException e) { - CASLog.e(TAG, "filed to call sendKeyEvent"); - ret = false; - } - return ret; - } - - public boolean sendMotionEvent(int materAxis, int materValue, int secondaryAxis, int secondaryValue) { - if (mCasInterface == null) { - return false; - } - boolean ret; - try { - ret = mCasInterface.sendMotionEvent(materAxis, materValue, secondaryAxis, secondaryValue); - } catch (RemoteException e) { - CASLog.e(TAG, "filed to call sendMotionEvent"); - ret = false; - } - return ret; - } - - public void setCasConnectorInfo(CasConnectorInfo info) { - if (mCasInterface == null) { - return; - } - try { - mCasInterface.setCasConnectorInfo(info); - } catch (RemoteException e) { - CASLog.e(TAG, "filed to call setCasConnectorInfo"); - } - } - - public void setMediaConfig(CasParcelableMap mediaConfigMap) { - if (mCasInterface == null) { - return; - } - try { - mCasInterface.setMediaConfig(mediaConfigMap); - } catch (RemoteException e) { - CASLog.e(TAG, "filed to call setMediaConfig"); - } - } - - public int getState() { - if (mCasInterface == null) { - return 0; - } - int ret; - try { - ret = mCasInterface.getState(); - } catch (RemoteException e) { - CASLog.e(TAG, "filed to call getState"); - ret = 0; - } - return ret; - } - - public int getLag() { - if (mCasInterface == null) { - return 0; - } - int lag = 0; - try { - lag = mCasInterface.getLag(); - } catch (RemoteException e) { - CASLog.e(TAG, "filed to call getLag"); - lag = 0; - } - return lag; - } - - public boolean startJniRecv() { - if (mCasInterface == null) { - return false; - } - boolean ret; - try { - ret = mCasInterface.startJniRecv(); - } catch (RemoteException e) { - CASLog.e(TAG, "filed to call startJniRecv"); - ret = false; - } - return ret; - } - - public void stopJniRecv() { - if (mCasInterface == null) { - return; - } - try { - mCasInterface.stopJniRecv(); - } catch (RemoteException e) { - CASLog.e(TAG, "filed to call stopJniRecv"); - } - } - - public void mute(boolean isMute) { - if (mCasInterface == null) { - return; - } - try { - mCasInterface.mute(isMute); - } catch (RemoteException e) { - CASLog.e(TAG, "failed to mute."); - } - } - - public void sendDataToCloudApp(byte[] data) { - if (mCasInterface == null) { - return; - } - try { - mCasInterface.sendData(CHANNEL, data); - } catch (RemoteException e) { - CASLog.e(TAG, "failed to send data to cloud app."); - } - } - - public void sendDataToVirtualDevice(byte devType, byte[] data) { - if (mCasInterface == null) { - return; - } - try { - mCasInterface.sendData(devType, data); - } catch (RemoteException e) { - CASLog.e(TAG, "failed to send data to virtual device."); - } - } - - public void sendDataToIme(byte[] data) { - if (mCasInterface == null) { - return; - } - try { - mCasInterface.sendData(IMEDATA, data); - } catch (RemoteException e) { - CASLog.e(TAG, "failed to send data to virtual device."); - } - } - -} diff --git a/cloudphone/src/main/java/com/huawei/cloudphone/service/CASService.java b/cloudphone/src/main/java/com/huawei/cloudphone/service/CASService.java deleted file mode 100644 index 890ff2aa333d5f1f5fc2dd215b1e0864f14be646..0000000000000000000000000000000000000000 --- a/cloudphone/src/main/java/com/huawei/cloudphone/service/CASService.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright 2022 Huawei Cloud Computing Technology Co., Ltd. - * - * 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. - */ - -package com.huawei.cloudphone.service; - -import android.app.Notification; -import android.app.NotificationChannel; -import android.app.NotificationManager; -import android.app.Service; -import android.content.Context; -import android.content.Intent; -import android.os.Build; -import android.os.IBinder; - -import com.huawei.cloudphone.common.CASLog; - -/** - * CASService - */ -public class CASService extends Service { - - /** - * TAG:CASService - */ - private static final String TAG = "CASService"; - - /** - * channel id - */ - private static final String CHANNEL_ID_STRING = "CASService"; - - /** - * cas processor - */ - private CasProcessor mCasProcessor = null; - - /** - * notify id - */ - private int mNotifyID = 100; - - @Override - public IBinder onBind(Intent intent) { - CASLog.i(TAG, "onBind"); - mCasProcessor = new CasProcessor(); - return mCasProcessor; - } - - @Override - public boolean onUnbind(Intent intent) { - CASLog.i(TAG, "onUnbind"); - mCasProcessor = null; - return super.onUnbind(intent); - } - - @Override - public int onStartCommand(Intent intent, int flags, int startId) { - int ret = super.onStartCommand(intent, flags, startId); - CASLog.i(TAG, "onStartCommand"); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - NotificationManager notificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE); - NotificationChannel mChannel = new NotificationChannel(CHANNEL_ID_STRING, "CASService", NotificationManager.IMPORTANCE_HIGH); - notificationManager.createNotificationChannel(mChannel); - Notification notification = new Notification.Builder(getApplicationContext(), CHANNEL_ID_STRING).build(); - startForeground(mNotifyID, notification); - } - return ret; - } - - @Override - public void onCreate() { - CASLog.i(TAG, "onCreate"); - super.onCreate(); - } - - @Override - public void onDestroy() { - CASLog.i(TAG, "onDestroy"); - super.onDestroy(); - } -} diff --git a/cloudphone/src/main/java/com/huawei/cloudphone/service/CasProcessor.java b/cloudphone/src/main/java/com/huawei/cloudphone/service/CasProcessor.java index 1d9de02af8ea451a626cb325837b1df27d41ef36..eae0a3e8a6a14a52adcd22f994ea80872c8e73c6 100644 --- a/cloudphone/src/main/java/com/huawei/cloudphone/service/CasProcessor.java +++ b/cloudphone/src/main/java/com/huawei/cloudphone/service/CasProcessor.java @@ -16,12 +16,10 @@ package com.huawei.cloudphone.service; -import android.os.IBinder; import android.os.RemoteException; import android.view.Surface; -import com.huawei.cloudphone.ICASAidlListener; -import com.huawei.cloudphone.ICASAidlInterface; +import com.huawei.cloudphone.apiimpl.CloudPhoneImpl; import com.huawei.cloudphone.audio.AudioTrackerCallback; import com.huawei.cloudphone.common.CASLog; import com.huawei.cloudphone.datacenter.CasRecvPktDispatcher; @@ -55,7 +53,7 @@ import static com.huawei.cloudphone.jniwrapper.JNIWrapper.KEY_VERIFY_DATA; /** * CasProcessor */ -public class CasProcessor extends ICASAidlInterface.Stub { +public class CasProcessor { /** * TAG:CasProcessor @@ -85,13 +83,12 @@ public class CasProcessor extends ICASAidlInterface.Stub { /** * listener */ - private ICASAidlListener mListener = null; + private CloudPhoneImpl.CASListener mListener = null; private NewRotationDirectionPacket mNewRotationDirPkt; private NewVirtualDevDataPacket mVirtualDevDataPkt; private NewImeDataPacket mImeDataPkt; - @Override - public void init() throws RemoteException { + public void init() { CASLog.i(TAG, "init...."); CasInteractiveStateCallback interactiveStateCallback = new CasInteractiveStateCallback() { @Override @@ -108,109 +105,90 @@ public class CasProcessor extends ICASAidlInterface.Stub { JniBridge.getInstance().registerCasJNICallback(interactiveStateCallback); } - @Override - public void setEncryptData(String encryptData) throws RemoteException { + public void setEncryptData(String encryptData) { CASLog.i(TAG, "setEncryptData...."); JniBridge.getInstance().setJniConf(KEY_ENCRYPTED_DATA, encryptData); } - @Override - public void setSurface(Surface suf) throws RemoteException { + public void setSurface(Surface suf) { CASLog.i(TAG, "setSurface...."); mSurface = suf; } - @Override - public boolean start(boolean isHome) throws RemoteException { + public boolean start(boolean isHome) { CASLog.i(TAG, "start...."); return JniBridge.getInstance().start(mSurface, isHome); } - @Override - public void stop(final boolean isHome) throws RemoteException { + public void stop(final boolean isHome) { CASLog.i(TAG, "stop...."); JniBridge.getInstance().stop(isHome); } - @Override - public void pause() throws RemoteException { + public void pause() { CASLog.i(TAG, "pause...."); stopJniRecv(); } - @Override - public void resume() throws RemoteException { + public void resume() { CASLog.i(TAG, "resume...."); } - @Override - public boolean isConnect() throws RemoteException { - + public boolean isConnect() { boolean isConnect = JNIWrapper.getConnectStatus(); return isConnect; } - @Override - public int getState() throws RemoteException { + public int getState() { CASLog.i(TAG, "getState...."); return JNIWrapper.getJniStatus(); } - @Override - public boolean reconnect() throws RemoteException { + public boolean reconnect() { boolean ret = JNIWrapper.reconnect(); CASLog.i(TAG, "reconnect ret = " + ret); return ret; } - @Override - public void registerListener(IBinder listener) throws RemoteException { + public void registerListener(CloudPhoneImpl.CASListener listener) { CASLog.i(TAG, "registerListener...."); - mListener = ICASAidlListener.Stub.asInterface(listener); + mListener = listener; } - @Override - public void unregisterListener() throws RemoteException { + public void unregisterListener() { CASLog.i(TAG, "unregisterListener...."); mListener = null; } - @Override public boolean sendTouchEvent(int id, int action, int x, int y, int pressure, long time, int orientation, int height, int width) { return JniBridge.getInstance().sendTouchEvent(id, action, x, y, pressure, time, orientation, height, width); } - @Override - public boolean sendKeyEvent(int keycode, int action) throws RemoteException { + public boolean sendKeyEvent(int keycode, int action) { CASLog.i(TAG, "sendKeyEvent, keycode:" + keycode + "action:" + action); return JniBridge.getInstance().sendKeyEvent(keycode, action); } - @Override - public boolean sendMotionEvent(int materAxis, int materValue, int secondaryAxis, int secondaryValue) throws RemoteException { + public boolean sendMotionEvent(int materAxis, int materValue, int secondaryAxis, int secondaryValue) { CASLog.i(TAG, "sendMotionEvent, materAxis:" + materAxis + "materValue:" + materValue + "secondaryAxis:" + secondaryAxis + "secondaryValue:" + secondaryValue); return JniBridge.getInstance().sendMotionEvent(materAxis, materValue, secondaryAxis, secondaryValue); } - @Override public void setMediaConfig(final CasParcelableMap mediaConfigMap) { HashMap mediaConfig = mediaConfigMap.getParcelableMap(); JniBridge.getInstance().setMediaConfig(mediaConfig); } - @Override - public boolean setRotation(int rotation) throws RemoteException { + public boolean setRotation(int rotation) { CASLog.i(TAG, "setRotation... "); return JniBridge.getInstance().setRotation(rotation); } - @Override - public int getLag() throws RemoteException { + public int getLag() { return JniBridge.getInstance().getLag(); } - @Override - public boolean startJniRecv() throws RemoteException { + public boolean startJniRecv() { CASLog.i(TAG, "startJniRecv... "); mUpstreamReceiveDispatcher = new CasRecvPktDispatcher(); mAudioTrackerCallback = new AudioTrackerCallback(); @@ -236,13 +214,13 @@ public class CasProcessor extends ICASAidlInterface.Stub { mUpstreamReceiveDispatcher.deleteNewPacketCallback((byte) JNIWrapper.CHANNEL); mUpstreamReceiveDispatcher.deleteNewPacketCallback((byte) JNIWrapper.VIRTUAL_DEVICE_DATA); mUpstreamReceiveDispatcher.deleteNewPacketCallback((byte) JNIWrapper.IMEDATA); - mUpstreamReceiveDispatcher.stopBlocked(); mAudioTrackerCallback.closeAudioTrack(); + mAudioTrackerCallback = null; + mUpstreamReceiveDispatcher.stopBlocked(); mUpstreamReceiveDispatcher = null; } } - @Override public void setCasConnectorInfo(CasConnectorInfo info) { CASLog.i(TAG, "setCasConnectorInfo..."); @@ -266,13 +244,7 @@ public class CasProcessor extends ICASAidlInterface.Stub { JniBridge.getInstance().setJniConf(KEY_ENCRYPTED_DATA, encryptedData); } - @Override - public void mute(boolean isMute) throws RemoteException { - AudioTrackerCallback.setMute(isMute); - } - - @Override - public void sendData(byte devType, byte[] data) throws RemoteException { + public void sendData(byte devType, byte[] data) { JniBridge.getInstance().sendData(devType, data, data.length); }