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/SvrManager.java | 126 +++++++++++++++++++++++++++++++
build.gradle | 2
lib/src/main/java/com/anyun/exam/lib/AYSdk.java | 93 ++--------------------
app/src/main/java/safeluck/drive/evaluation/util/MyLog.java | 2
4 files changed, 138 insertions(+), 85 deletions(-)
diff --git a/app/src/main/java/safeluck/drive/evaluation/util/MyLog.java b/app/src/main/java/safeluck/drive/evaluation/util/MyLog.java
index 9a8ba13..5df62fb 100644
--- a/app/src/main/java/safeluck/drive/evaluation/util/MyLog.java
+++ b/app/src/main/java/safeluck/drive/evaluation/util/MyLog.java
@@ -33,7 +33,7 @@
private static char MYLOG_TYPE = 'v';
// 鏃ュ織鏂囦欢鍦╯dcard涓殑璺緞
- private static String MYLOG_PATH_SDCARD_DIR = "/sdcard/nvlog";
+ private static String MYLOG_PATH_SDCARD_DIR = "/sdcard/nvjiakaolog";
private static int SDCARD_LOG_FILE_SAVE_DAYS = 3;// sd鍗′腑鏃ュ織鏂囦欢鐨勬渶澶氫繚瀛樺ぉ鏁�
diff --git a/build.gradle b/build.gradle
index 0125c22..fafc1b9 100644
--- a/build.gradle
+++ b/build.gradle
@@ -7,7 +7,7 @@
}
dependencies {
- classpath 'com.android.tools.build:gradle:3.3.0'
+ classpath 'com.android.tools.build:gradle:3.4.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
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;
- }
- };
+
+
+
}
diff --git a/lib/src/main/java/com/anyun/exam/lib/SvrManager.java b/lib/src/main/java/com/anyun/exam/lib/SvrManager.java
new file mode 100644
index 0000000..128fff3
--- /dev/null
+++ b/lib/src/main/java/com/anyun/exam/lib/SvrManager.java
@@ -0,0 +1,126 @@
+package com.anyun.exam.lib;
+
+import android.content.ComponentName;
+import android.content.Context;
+import android.content.Intent;
+import android.content.ServiceConnection;
+import android.os.IBinder;
+import android.os.RemoteException;
+import android.util.Log;
+
+import java.util.LinkedList;
+
+/**
+ * MyApplication2
+ * Created by lzw on 2019/9/19. 18:19:48
+ * 閭锛�632393724@qq.com
+ * All Rights Saved! Chongqing AnYun Tech co. LTD
+ */
+class SvrManager {
+ private static final SvrManager ourInstance = new SvrManager();
+ private static final String TAG = "SvrManager";
+ private MyServiceConn conn;
+
+
+ private IAYExamListener mCallback;
+ //杩滅▼鏈嶅姟鎺ュ彛
+ private IRemoteInterface remoteInterface;
+ static SvrManager getInstance() {
+ return ourInstance;
+ }
+
+ private SvrManager() {
+ }
+ /**
+ * 妫�鏌ヨ繙绋嬫湇鍔℃槸鍚﹀彲浠ヤ娇鐢�
+ * @return 鍙互鐢╢alse锛屼笉鍙互鐢╰rue
+ */
+ private boolean checkRemoteIsNull() {
+ return remoteInterface==null?true:false;
+ }
+ /**
+ * 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;
+ }
+ };
+
+ public void registerListener(IAYExamListener iayExamListener) {
+ this.mCallback = iayExamListener;
+ }
+
+ public void add() {
+ if (!checkRemoteIsNull()){
+ try {
+ remoteInterface.add();
+ } catch (RemoteException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ 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) {
+
+ }
+
+
+ }
+ public void bindRemoteService(Context mContext){
+ Intent intent = new Intent(mContext,RemoteService.class);
+ conn = new MyServiceConn();
+ mContext.bindService(intent,conn, Context.BIND_AUTO_CREATE);
+ }
+
+ public void unBindRemoteService(Context mContext){
+ if (remoteInterface!=null && remoteInterface.asBinder().isBinderAlive()){
+ try {
+ remoteInterface.unRegistListener(RemoteCallback);
+
+ } catch (RemoteException e) {
+ e.printStackTrace();
+ }
+ }
+ mContext.unbindService(conn);
+ }
+
+ /**
+ * 杩滅▼鏈嶅姟鍥炶皟閫氱煡瀹㈡埛绔秷鎭�
+ */
+ IListenerInterface RemoteCallback = new IListenerInterface.Stub(){
+ @Override
+ public void onMessageArrived(String json) throws RemoteException {
+
+ if (mCallback != null){
+ mCallback.callBackMsg(json);
+ }
+ }
+
+
+ };
+
+}
--
Gitblit v1.8.0