Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
石璀亮
/
agenew_a16_sos
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 48179ddf
authored
Mar 20, 2019
by
cuiliang.shi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
对照文档更新
1 parent
15e43c96
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
88 additions
and
92 deletions
app/build.gradle
app/release/LocationServer.apk
app/release/app-release.apk
app/src/main/java/com/agenew/location_server/application/AlarmReceiver.java
app/src/main/java/com/agenew/location_server/application/BirdService.java
app/build.gradle
View file @
48179dd
...
...
@@ -16,6 +16,13 @@ android {
proguardFiles
getDefaultProguardFile
(
'proguard-android.txt'
),
'proguard-rules.pro'
}
}
android
.
applicationVariants
.
all
{
variant
->
variant
.
outputs
.
all
{
outputFileName
=
"LocationServer.apk"
}
}
}
dependencies
{
...
...
app/release/LocationServer.apk
View file @
48179dd
No preview for this file type
app/release/app-release.apk
deleted
100644 → 0
View file @
15e43c9
No preview for this file type
app/src/main/java/com/agenew/location_server/application/AlarmReceiver.java
View file @
48179dd
...
...
@@ -10,7 +10,7 @@ public class AlarmReceiver extends BroadcastReceiver {
@Override
public
void
onReceive
(
Context
context
,
Intent
intent
)
{
Log
.
d
(
"BirdService"
,
"receiver--"
+
System
.
currentTimeMillis
());
Intent
i
=
new
Intent
(
context
,
BirdService
.
class
);
Intent
i
=
new
Intent
(
context
,
BirdService
.
class
);
context
.
startForegroundService
(
i
);
}
}
app/src/main/java/com/agenew/location_server/application/BirdService.java
View file @
48179dd
package
com
.
agenew
.
location_server
.
application
;
import
android.Manifest
;
import
android.annotation.SuppressLint
;
import
android.app.AlarmManager
;
import
android.app.Notification
;
import
android.app.NotificationChannel
;
import
android.app.NotificationManager
;
import
android.app.PendingIntent
;
import
android.app.Service
;
import
android.content.BroadcastReceiver
;
import
android.content.Context
;
import
android.content.Intent
;
import
android.content.IntentFilter
;
import
android.content.pm.PackageManager
;
import
android.graphics.Color
;
import
android.os.Build
;
import
android.os.Handler
;
import
android.os.IBinder
;
import
android.os.Message
;
import
android.os.SystemClock
;
import
android.provider.Settings
;
import
android.support.annotation.Nullable
;
import
android.support.annotation.RequiresApi
;
import
android.support.v4.app.ActivityCompat
;
import
android.telephony.SubscriptionInfo
;
import
android.telephony.SubscriptionManager
;
import
android.telephony.TelephonyManager
;
import
android.text.TextUtils
;
import
android.util.Log
;
import
android.widget.Toast
;
import
com.amap.api.location.AMapLocation
;
import
com.amap.api.location.AMapLocationClient
;
...
...
@@ -58,7 +46,6 @@ public class BirdService extends Service {
private
String
mLongitude
;
private
String
mLatitude
;
private
String
mModel
;
private
String
mCfgv
;
public
AMapLocationClientOption
mLocationOption
=
null
;
private
SubscriptionManager
mSubscriptionManager
;
...
...
@@ -69,10 +56,8 @@ public class BirdService extends Service {
private
String
TAG
=
"BirdService"
;
private
Context
mContext
;
private
String
mPath
=
""
;
private
int
ret_code
=
-
1
;
private
String
ret_message
=
""
;
private
String
ret_cfgv
=
""
;
private
int
upload_time
=
0
;
private
int
ret_code
=
0
;
private
String
ret_cfgv
=
"0"
;
@Override
public
IBinder
onBind
(
Intent
intent
)
{
...
...
@@ -82,18 +67,19 @@ public class BirdService extends Service {
@Override
public
void
onDestroy
()
{
super
.
onDestroy
();
Log
.
d
(
TAG
,
"onDestory"
);
}
@RequiresApi
(
api
=
Build
.
VERSION_CODES
.
O
)
@Override
public
void
onCreate
()
{
super
.
onCreate
();
Log
.
d
(
TAG
,
"birdservice"
);
}
@Override
public
int
onStartCommand
(
Intent
intent
,
int
flags
,
int
startId
)
{
Log
.
d
(
TAG
,
"onStartCommand"
);
mContext
=
getApplicationContext
();
String
CHANNEL_ONE_ID
=
"com.primedu.cn"
;
...
...
@@ -123,53 +109,25 @@ public class BirdService extends Service {
new
Thread
(
new
Runnable
()
{
@Override
public
void
run
()
{
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
N
)
{
stopForeground
(
true
);
}
Log
.
d
(
TAG
,
"time:"
+
new
Date
().
toString
());
stopSelf
();
}
}).
start
();
mSubscriptionManager
=
SubscriptionManager
.
from
(
mContext
);
if
(
ActivityCompat
.
checkSelfPermission
(
this
,
Manifest
.
permission
.
READ_PHONE_STATE
)
!=
PackageManager
.
PERMISSION_GRANTED
)
{
// TODO: Consider calling
// ActivityCompat#requestPermissions
// here to request the missing permissions, and then overriding
// public void onRequestPermissionsResult(int requestCode, String[] permissions,
// int[] grantResults)
// to handle the case where the user grants the permission. See the documentation
// for ActivityCompat#requestPermissions for more details.
return
super
.
onStartCommand
(
intent
,
flags
,
startId
);
}
mSubList
=
mSubscriptionManager
.
getActiveSubscriptionInfoList
();
ret_cfgv
=
DevicePreferences
.
getInstance
(
getApplicationContext
()).
getString
(
"bird_ret_cfgv"
,
"0"
);
mPath
=
DevicePreferences
.
getInstance
(
mContext
).
getString
(
"bird_location_upload_url"
,
DEFAULTPATH
);
long
temp
=
DevicePreferences
.
getInstance
(
mContext
).
getLong
(
"bird_location_upload_interval"
,
DEFAULTINTERVAL
);
Log
.
d
(
TAG
,
"CONFIG - PARAM, time minutes: "
+
temp
+
", cfgv: "
+
ret_cfgv
+
", path: "
+
mPath
);
initLocation
(
mContext
);
Long
temp
=
DevicePreferences
.
getInstance
(
mContext
).
getLong
(
"bird_location_upload_interval"
,
DEFAULTINTERVAL
);
Log
.
d
(
TAG
,
"TEMP------"
+
temp
);
mInterval
=
temp
*
60
*
1000
;
if
(
mInterval
!=
0
)
{
AlarmManager
manger
=
(
AlarmManager
)
getSystemService
(
Context
.
ALARM_SERVICE
);
Intent
i
=
new
Intent
(
this
,
AlarmReceiver
.
class
);
PendingIntent
pendingIntent2
=
PendingIntent
.
getBroadcast
(
mContext
,
0
,
i
,
0
);
long
triggerAtTime
=
SystemClock
.
elapsedRealtime
();
Log
.
d
(
TAG
,
"triggerAtTime--1--"
+
triggerAtTime
+
" "
+
mInterval
);
triggerAtTime
=
triggerAtTime
+
mInterval
+
10
;
Log
.
d
(
TAG
,
"triggerAtTime--2--"
+
triggerAtTime
+
" "
+
mInterval
);
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
M
)
{
manger
.
setExactAndAllowWhileIdle
(
AlarmManager
.
ELAPSED_REALTIME_WAKEUP
,
triggerAtTime
,
pendingIntent2
);
}
}
return
super
.
onStartCommand
(
intent
,
flags
,
startId
);
}
//声明定位回调监听器
public
AMapLocationListener
mLocationListener
=
new
AMapLocationListener
()
{
@Override
...
...
@@ -178,15 +136,21 @@ public class BirdService extends Service {
if
(
amapLocation
!=
null
)
{
if
(
amapLocation
.
getErrorCode
()
==
0
)
{
SimpleDateFormat
dateformat
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
);
Log
.
d
(
TAG
,
"mInterval--"
+
mInterval
+
" "
+
mPath
);
mStartTime
=
dateformat
.
format
(
System
.
currentTimeMillis
());
mLatitude
=
String
.
valueOf
(
amapLocation
.
getLatitude
());
mLongitude
=
String
.
valueOf
(
amapLocation
.
getLongitude
());
getPhoneInfo
();
sendMsg
();
if
(
mLocationClient
!=
null
)
{
mLocationClient
.
stopLocation
();
}
}
else
{
setAlarm
();
Log
.
e
(
TAG
,
"location Error, ErrCode:"
+
amapLocation
.
getErrorCode
()
+
", errInfo:"
+
amapLocation
.
getErrorInfo
());
...
...
@@ -200,14 +164,32 @@ public class BirdService extends Service {
}
};
public
void
setAlarm
(){
Log
.
d
(
TAG
,
"setAlarm"
);
ret_cfgv
=
DevicePreferences
.
getInstance
(
getApplicationContext
()).
getString
(
"bird_ret_cfgv"
,
"0"
);
mPath
=
DevicePreferences
.
getInstance
(
mContext
).
getString
(
"bird_location_upload_url"
,
DEFAULTPATH
);
long
temp
=
DevicePreferences
.
getInstance
(
mContext
).
getLong
(
"bird_location_upload_interval"
,
DEFAULTINTERVAL
);
Log
.
d
(
TAG
,
"ALARM - CONFIG - PARAM, time minutes: "
+
temp
+
", cfgv: "
+
ret_cfgv
+
", path: "
+
mPath
);
mInterval
=
temp
*
60
*
1000
;
if
(
mInterval
!=
0
)
{
AlarmManager
manger
=
(
AlarmManager
)
getSystemService
(
Context
.
ALARM_SERVICE
);
Intent
i
=
new
Intent
(
this
,
AlarmReceiver
.
class
);
PendingIntent
pendingIntent2
=
PendingIntent
.
getBroadcast
(
getApplicationContext
(),
0
,
i
,
0
);
long
triggerAtTime
=
SystemClock
.
elapsedRealtime
();
triggerAtTime
=
triggerAtTime
+
mInterval
+
10
;
manger
.
setExactAndAllowWhileIdle
(
AlarmManager
.
ELAPSED_REALTIME_WAKEUP
,
triggerAtTime
,
pendingIntent2
);
}
}
public
void
sendMsg
()
{
Log
.
d
(
TAG
,
"send location
"
);
Log
.
d
(
TAG
,
"sendMsg
"
);
new
Thread
(
new
Runnable
()
{
@Override
public
void
run
()
{
setPhoneInfo
();
mPath
=
DevicePreferences
.
getInstance
(
mContext
).
getString
(
"bird_location_upload_url"
,
DEFAULTPATH
);
final
StringBuffer
strbuf
=
new
StringBuffer
();
strbuf
.
append
(
"longitude="
+
mLongitude
);
strbuf
.
append
(
"&latitude="
+
mLatitude
);
...
...
@@ -216,9 +198,10 @@ public class BirdService extends Service {
strbuf
.
append
(
"&tel="
+
mMobile
);
strbuf
.
append
(
"&iccid="
+
mICCIDStr
);
strbuf
.
append
(
"&imsi="
+
mIMSIStr
);
strbuf
.
append
(
"&model="
+
mModel
);
strbuf
.
append
(
"&cfgv="
+
mCfgv
);
Log
.
d
(
TAG
,
"strbuf:"
+
strbuf
);
strbuf
.
append
(
"&model="
+
mModel
);
strbuf
.
append
(
"&cfgv="
+
ret_cfgv
);
Log
.
d
(
TAG
,
"REQUEST: URL: "
+
mPath
+
", BODY:"
+
strbuf
);
URL
url
=
null
;
HttpURLConnection
httpURLConnection
=
null
;
...
...
@@ -241,10 +224,9 @@ public class BirdService extends Service {
int
responseCode
=
httpURLConnection
.
getResponseCode
();
Log
.
d
(
TAG
,
"responseCode--"
+
responseCode
);
if
(
responseCode
==
HttpURLConnection
.
HTTP_OK
)
{
upload_time
+=
1
;
InputStreamReader
is
=
new
InputStreamReader
(
httpURLConnection
.
getInputStream
());
StringBuffer
sb
=
new
StringBuffer
();
int
i
=
0
;
int
i
=
0
;
while
((
i
=
is
.
read
())
!=
-
1
)
{
sb
.
append
((
char
)
i
);
}
...
...
@@ -253,16 +235,39 @@ public class BirdService extends Service {
Log
.
d
(
TAG
,
"server response: "
+
sb
);
JSONObject
jsonObject
=
new
JSONObject
(
sb
.
toString
());
ret_code
=
jsonObject
.
getInt
(
"ret_code"
);
ret_message
=
jsonObject
.
getString
(
"ret_message"
);
ret_code
=
jsonObject
.
getInt
(
"ret_code"
);
if
(
ret_code
==
1
){
ret_cfgv
=
jsonObject
.
getString
(
"cfgv"
);
Log
.
d
(
TAG
,
"ret_cfgv---"
+
ret_cfgv
+
" "
+
jsonObject
);
mPath
=
jsonObject
.
getString
(
"url"
);
Log
.
d
(
TAG
,
"new path: "
+
mPath
);
if
(!
mPath
.
equals
(
"0"
)){
DevicePreferences
.
getInstance
(
mContext
).
putString
(
"bird_location_upload_url"
,
mPath
);
}
int
timeSpanMinutes
=
jsonObject
.
getInt
(
"time_span"
);
if
(
timeSpanMinutes
==
999999
){
DevicePreferences
.
getInstance
(
mContext
).
putLong
(
"bird_location_upload_interval"
,
0
);
}
else
if
(
timeSpanMinutes
==
0
){
Log
.
d
(
TAG
,
"time span not change"
);
}
else
{
DevicePreferences
.
getInstance
(
mContext
).
putLong
(
"bird_location_upload_interval"
,
timeSpanMinutes
);
}
DevicePreferences
.
getInstance
(
mContext
).
putString
(
"bird_ret_cfgv"
,
ret_cfgv
);
}
else
if
(
ret_code
==
0
){
Log
.
d
(
TAG
,
"upload success"
);
}
else
{
Log
.
d
(
TAG
,
"upload failed"
);
}
}
else
if
(
responseCode
!=
200
)
{
Log
.
d
(
TAG
,
"request failed"
);
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
finally
{
setAlarm
();
httpURLConnection
.
disconnect
();
Log
.
d
(
TAG
,
"close connect"
);
if
(
os
!=
null
)
{
...
...
@@ -296,39 +301,23 @@ public class BirdService extends Service {
mLocationClient
.
setLocationOption
(
mLocationOption
);
mLocationClient
.
startLocation
();
//default false,true表示only location once
//mLocationOption.setOnceLocation(true);
}
private
void
setPhoneInfo
()
{
private
void
getPhoneInfo
()
{
Log
.
d
(
TAG
,
"getPhoneInfo"
);
String
temp_imie
=
Settings
.
System
.
getString
(
getContentResolver
(),
"bird_loc_imei"
);
String
temp_mobile
=
Settings
.
System
.
getString
(
getContentResolver
(),
"bird_loc_mobile"
);
String
temp_iccid
=
Settings
.
System
.
getString
(
getContentResolver
(),
"bird_loc_iccid"
);
String
temp_imsi
=
Settings
.
System
.
getString
(
getContentResolver
(),
"bird_loc_imsi"
);
if
(
mSubList
==
null
)
{
Log
.
i
(
TAG
,
"subList == null"
);
return
;
}
Log
.
i
(
TAG
,
"subList.size:"
+
mSubList
.
size
());
String
temp_imie
=
Settings
.
System
.
getString
(
getContentResolver
(),
"bird_loc_imei"
);
String
temp_mobile
=
Settings
.
System
.
getString
(
getContentResolver
(),
"bird_loc_mobile"
);
String
temp_iccid
=
Settings
.
System
.
getString
(
getContentResolver
(),
"bird_loc_iccid"
);
String
temp_imsi
=
Settings
.
System
.
getString
(
getContentResolver
(),
"bird_loc_imsi"
);
mIMEIStr
=
temp_imie
.
substring
(
0
,
temp_imie
.
length
()-
1
)
;
mMobile
=
temp_mobile
.
substring
(
0
,
temp_mobile
.
length
()-
1
)
;
mIMSIStr
=
temp_imsi
.
substring
(
0
,
temp_imsi
.
length
()-
1
)
;
mICCIDStr
=
temp_iccid
.
substring
(
0
,
temp_iccid
.
length
()-
1
)
;
mIMEIStr
=
temp_imie
.
substring
(
0
,
temp_imie
.
length
()
-
1
);
mMobile
=
temp_mobile
.
substring
(
0
,
temp_mobile
.
length
()
-
1
);
mIMSIStr
=
temp_imsi
.
substring
(
0
,
temp_imsi
.
length
()
-
1
);
mICCIDStr
=
temp_iccid
.
substring
(
0
,
temp_iccid
.
length
()
-
1
);
String
temp_model
=
Build
.
MODEL
;
mModel
=
temp_model
.
trim
().
replaceAll
(
" "
,
"_"
);
Log
.
d
(
TAG
,
"ret_cfgv--"
+
ret_cfgv
);
if
(
TextUtils
.
isEmpty
(
ret_cfgv
))
{
mCfgv
=
"0"
;
}
else
{
mCfgv
=
ret_cfgv
;
}
Log
.
d
(
TAG
,
mIMEIStr
+
" "
+
mIMSIStr
+
" "
+
mICCIDStr
+
" sim: "
+
mMobile
);
mModel
=
temp_model
.
trim
().
replaceAll
(
" "
,
"_"
);
}
}
Write
Preview
Markdown
is supported
Attach a file
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 post a comment