From a4d1aa42cd38b6118c37eee75c5f8a381f5fbb36 Mon Sep 17 00:00:00 2001
From: endian11 <Dana_Lee1016@126.com>
Date: 星期四, 19 九月 2019 18:49:21 +0800
Subject: [PATCH] 修改log保存目录;lib库修改与远程service有关的放到一个单例类里面
---
lib/src/main/java/com/anyun/exam/lib/AYSdk.java | 93 +++++-----------------------------------------
1 files changed, 10 insertions(+), 83 deletions(-)
diff --git a/lib/src/main/java/com/anyun/exam/lib/AYSdk.java b/lib/src/main/java/com/anyun/exam/lib/AYSdk.java
index 6cbae82..44754b9 100644
--- a/lib/src/main/java/com/anyun/exam/lib/AYSdk.java
+++ b/lib/src/main/java/com/anyun/exam/lib/AYSdk.java
@@ -18,13 +18,11 @@
private static final String TAG = "AYSDK";
- private IAYExamListener mCallback;
- //杩滅▼鏈嶅姟鎺ュ彛
- private IRemoteInterface remoteInterface;
+
//瀹夎繍椹捐�冪郴缁� sdk 鍗曚緥妯″紡
private volatile static AYSdk ourInstance = null;
private Context mContext;
- private MyServiceConn conn;
+
public static AYSdk getInstance() {
if (ourInstance == null){
@@ -44,9 +42,7 @@
public void init(Context context){
this.mContext = context;
//bind service
- Intent intent = new Intent(mContext,RemoteService.class);
- conn = new MyServiceConn();
- mContext.bindService(intent,conn,Context.BIND_AUTO_CREATE);
+ SvrManager.getInstance().bindRemoteService(mContext);
}
@@ -56,15 +52,8 @@
*/
public void uninit(){
if (mContext != null){
- if (remoteInterface!=null && remoteInterface.asBinder().isBinderAlive()){
- try {
- remoteInterface.unRegistListener(RemoteCallback);
-
- } catch (RemoteException e) {
- e.printStackTrace();
- }
- }
- mContext.unbindService(conn);
+ //UnbinService
+ SvrManager.getInstance().unBindRemoteService(mContext);
}else{
Log.e(TAG,"mContext == null锛宲lease init SDK firstly");
throw new RuntimeException("mContext == null锛宲lease init SDK firstly");
@@ -75,20 +64,6 @@
}
- /**
- * 杩滅▼鏈嶅姟鍥炶皟閫氱煡瀹㈡埛绔秷鎭�
- */
- IListenerInterface RemoteCallback = new IListenerInterface.Stub(){
- @Override
- public void onMessageArrived(String json) throws RemoteException {
-
- if (mCallback != null){
- mCallback.callBackMsg(json);
- }
- }
-
-
- };
@Override
public void checkSignal(int type) {
@@ -97,65 +72,17 @@
@Override
public void add() {
- if (!checkRemoteIsNull()){
- try {
- remoteInterface.add();
- } catch (RemoteException e) {
- e.printStackTrace();
- }
- }
+ SvrManager.getInstance().add();
}
@Override
public void registListener(IAYExamListener iayExamListener) {
- this.mCallback = iayExamListener;
- }
-
- /**
- * 妫�鏌ヨ繙绋嬫湇鍔℃槸鍚﹀彲浠ヤ娇鐢�
- * @return 鍙互鐢╢alse锛屼笉鍙互鐢╰rue
- */
- private boolean checkRemoteIsNull() {
- return remoteInterface==null?true:false;
- }
-
- class MyServiceConn implements ServiceConnection {
- @Override
- public void onServiceConnected(ComponentName name, IBinder service) {
- remoteInterface = IRemoteInterface.Stub.asInterface(service);
- try {
- //璁剧疆姝讳骸浠g悊
- service.linkToDeath(mDeathRecipient,0);
-
- remoteInterface.registListener(RemoteCallback);
- } catch (RemoteException e) {
- e.printStackTrace();
- }
- }
-
- @Override
- public void onServiceDisconnected(ComponentName name) {
-
- }
-
+ SvrManager.getInstance().registerListener(iayExamListener);
}
- /**
- * Binder鏂鍥炶皟
- * 濡傛灉鏈嶅姟绔繘绋嬬敱浜庢煇绉嶅紓甯稿師鍥犲仠姝�
- */
- private IBinder.DeathRecipient mDeathRecipient = new IBinder.DeathRecipient() {
- @Override
- public void binderDied() {
- Log.e(TAG,"IBinder.DeathRecipient binderDied");
- if (remoteInterface != null){
- Log.e(TAG,"IBinder.DeathRecipient binderDied remoteInterface != null ,return");
- return;
- }
- remoteInterface.asBinder().unlinkToDeath(mDeathRecipient,0);
- remoteInterface = null;
- }
- };
+
+
+
}
--
Gitblit v1.8.0