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 05da71ce
authored
Apr 19, 2019
by
cuiliang.shi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
360 属性更新 以及 更新 取优化点算法
1 parent
aa4d5f7c
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
573 additions
and
1 deletions
app/build.gradle
app/src/main/java/com/agenew/location_server/application/BirdService.java
app/src/main/java/com/agenew/location_server/application/PhoneUtils.java
app/build.gradle
View file @
05da71c
...
@@ -33,4 +33,7 @@ dependencies {
...
@@ -33,4 +33,7 @@ dependencies {
androidTestImplementation
'com.android.support.test:runner:1.0.2'
androidTestImplementation
'com.android.support.test:runner:1.0.2'
androidTestImplementation
'com.android.support.test.espresso:espresso-core:3.0.2'
androidTestImplementation
'com.android.support.test.espresso:espresso-core:3.0.2'
implementation
'com.amap.api:location:4.5.1'
implementation
'com.amap.api:location:4.5.1'
implementation
'com.amap.api:map2d:5.2.0'
}
}
app/src/main/java/com/agenew/location_server/application/BirdService.java
View file @
05da71c
...
@@ -32,6 +32,8 @@ import com.amap.api.location.AMapLocation;
...
@@ -32,6 +32,8 @@ import com.amap.api.location.AMapLocation;
import
com.amap.api.location.AMapLocationClient
;
import
com.amap.api.location.AMapLocationClient
;
import
com.amap.api.location.AMapLocationClientOption
;
import
com.amap.api.location.AMapLocationClientOption
;
import
com.amap.api.location.AMapLocationListener
;
import
com.amap.api.location.AMapLocationListener
;
import
com.amap.api.maps2d.AMapUtils
;
import
com.amap.api.maps2d.model.LatLng
;
import
org.json.JSONObject
;
import
org.json.JSONObject
;
...
@@ -69,6 +71,10 @@ public class BirdService extends Service {
...
@@ -69,6 +71,10 @@ public class BirdService extends Service {
private
String
ret_cfgv
=
"2019031512"
;
private
String
ret_cfgv
=
"2019031512"
;
private
LocationManager
mLocationManager
;
private
LocationManager
mLocationManager
;
private
int
mNewMsgCount
=
0
;
private
int
mNewMsgCount
=
0
;
private
double
mWifiLatitude
=
0
;
private
double
mWifiLongitude
=
0
;
private
double
mGpsLatitude
=
0
;
private
double
mGpsLongitude
=
0
;
@Override
@Override
public
IBinder
onBind
(
Intent
intent
)
{
public
IBinder
onBind
(
Intent
intent
)
{
...
@@ -115,6 +121,9 @@ public class BirdService extends Service {
...
@@ -115,6 +121,9 @@ public class BirdService extends Service {
private
int
mLocationCount
=
0
;
private
int
mLocationCount
=
0
;
private
float
mAccuracy
=
10000
;
private
float
mAccuracy
=
10000
;
private
float
mWifiAccuracy
=
1000
;
private
float
mGpsAccuracy
=
1000
;
public
AMapLocationListener
mLocationListener
=
new
AMapLocationListener
()
{
public
AMapLocationListener
mLocationListener
=
new
AMapLocationListener
()
{
@Override
@Override
...
@@ -123,6 +132,7 @@ public class BirdService extends Service {
...
@@ -123,6 +132,7 @@ public class BirdService extends Service {
if
(
amapLocation
!=
null
)
{
if
(
amapLocation
!=
null
)
{
if
(
amapLocation
.
getErrorCode
()
==
0
)
{
if
(
amapLocation
.
getErrorCode
()
==
0
)
{
mLocationCount
++;
mLocationCount
++;
Log
.
d
(
TAG
,
"amapLocation.getLatitude(): "
+
amapLocation
.
getLatitude
()
Log
.
d
(
TAG
,
"amapLocation.getLatitude(): "
+
amapLocation
.
getLatitude
()
+
", amapLocation.getLongitude(): "
+
amapLocation
.
getLongitude
()
+
", amapLocation.getLongitude(): "
+
amapLocation
.
getLongitude
()
+
", amapLocation.getAccuracy():"
+
amapLocation
.
getAccuracy
()
+
", amapLocation.getAccuracy():"
+
amapLocation
.
getAccuracy
()
...
@@ -134,7 +144,45 @@ public class BirdService extends Service {
...
@@ -134,7 +144,45 @@ public class BirdService extends Service {
mLongitude
=
String
.
valueOf
(
amapLocation
.
getLongitude
());
mLongitude
=
String
.
valueOf
(
amapLocation
.
getLongitude
());
}
}
if
(
amapLocation
.
getLocationType
()
==
5
){
if
(
amapLocation
.
getAccuracy
()
<
mWifiAccuracy
){
mWifiAccuracy
=
amapLocation
.
getAccuracy
();
mWifiLatitude
=
amapLocation
.
getLatitude
();
mWifiLongitude
=
amapLocation
.
getLongitude
();
}
}
if
(
amapLocation
.
getLocationType
()
==
1
){
if
(
amapLocation
.
getAccuracy
()
<
mGpsAccuracy
){
mGpsAccuracy
=
amapLocation
.
getAccuracy
();
mGpsLatitude
=
amapLocation
.
getLatitude
();
mGpsLongitude
=
amapLocation
.
getLongitude
();
}
}
if
(
mLocationCount
>
15
){
if
(
mLocationCount
>
15
){
if
(
mWifiLatitude
!=
0
&&
mWifiLongitude
!=
0
&&
mGpsLatitude
!=
0
&&
mGpsLongitude
!=
0
){
LatLng
wifiLatLng
=
new
LatLng
(
mWifiLatitude
,
mWifiLongitude
);
LatLng
gpsLatLng
=
new
LatLng
(
mGpsLatitude
,
mGpsLongitude
);
float
distance
=
AMapUtils
.
calculateLineDistance
(
wifiLatLng
,
gpsLatLng
);
Log
.
d
(
TAG
,
"distance: "
+
distance
+
", mWifiAccuracy:"
+
mWifiAccuracy
+
", mGpsAccuracy: "
+
mGpsAccuracy
);
if
(
distance
>
mWifiAccuracy
+
60
){
mLatitude
=
String
.
valueOf
(
mWifiLatitude
);
mLongitude
=
String
.
valueOf
(
mWifiLongitude
);
mAccuracy
=
mWifiAccuracy
;
}
else
{
mLatitude
=
String
.
valueOf
(
mGpsLatitude
);
mLongitude
=
String
.
valueOf
(
mGpsLongitude
);
mAccuracy
=
mGpsAccuracy
;
}
}
Log
.
d
(
TAG
,
"LAST PERFECT INFO amapLocation.getLatitude(): "
+
mLatitude
Log
.
d
(
TAG
,
"LAST PERFECT INFO amapLocation.getLatitude(): "
+
mLatitude
+
", amapLocation.getLongitude(): "
+
mLongitude
+
", amapLocation.getLongitude(): "
+
mLongitude
+
", amapLocation.getAccuracy():"
+
mAccuracy
);
+
", amapLocation.getAccuracy():"
+
mAccuracy
);
...
@@ -338,7 +386,8 @@ public class BirdService extends Service {
...
@@ -338,7 +386,8 @@ public class BirdService extends Service {
mIMSIStr
=
temp_imsi
.
substring
(
0
,
temp_imsi
.
length
()
-
1
);
mIMSIStr
=
temp_imsi
.
substring
(
0
,
temp_imsi
.
length
()
-
1
);
mICCIDStr
=
temp_iccid
.
substring
(
0
,
temp_iccid
.
length
()
-
1
);
mICCIDStr
=
temp_iccid
.
substring
(
0
,
temp_iccid
.
length
()
-
1
);
String
temp_model
=
Build
.
MODEL
;
// String temp_model = Build.MODEL;
String
temp_model
=
PhoneUtils
.
getProperty
(
"ro.qiku.custom.model"
,
"undefined"
);
mModel
=
temp_model
.
trim
().
replaceAll
(
" "
,
""
);
mModel
=
temp_model
.
trim
().
replaceAll
(
" "
,
""
);
}
}
...
...
app/src/main/java/com/agenew/location_server/application/PhoneUtils.java
0 → 100644
View file @
05da71c
package
com
.
agenew
.
location_server
.
application
;
import
android.content.Context
;
import
android.content.pm.PackageManager
;
import
android.net.ConnectivityManager
;
import
android.net.NetworkInfo
;
import
android.os.Build
;
import
android.provider.Settings
;
import
android.telephony.SubscriptionInfo
;
import
android.telephony.SubscriptionManager
;
import
android.telephony.TelephonyManager
;
import
android.text.TextUtils
;
import
android.util.ArrayMap
;
import
android.util.Log
;
import
java.lang.reflect.InvocationTargetException
;
import
java.lang.reflect.Method
;
import
java.util.List
;
import
java.util.regex.Matcher
;
import
java.util.regex.Pattern
;
import
static
android
.
content
.
Context
.
TELEPHONY_SERVICE
;
import
static
android
.
telephony
.
TelephonyManager
.
SIM_STATE_READY
;
public
class
PhoneUtils
{
public
static
final
long
VAL_USER_REFRESH_INTERVAL
=
10
*
60
*
1000
;
// 10min
public
static
final
long
VAL_AUTO_REFRESH_INTERVAL
=
6
*
60
*
60
*
1000
;
// 6 hours
public
static
final
long
VAL_AUTO_RELOAD_INTERVAL
=
1
*
60
*
1000
;
//1min
private
static
final
String
TAG
=
PhoneUtils
.
class
.
getSimpleName
();
private
static
final
ArrayMap
<
String
,
String
>
mobileAlias
=
new
ArrayMap
<>();
public
static
int
getSimState
(
int
slot
)
{
int
state
=
-
1
;
Class
<?>
subManagerClazz
=
SubscriptionManager
.
class
;
try
{
Method
method
=
subManagerClazz
.
getMethod
(
"getSimStateForSlotIdx"
,
int
.
class
);
if
(
method
!=
null
)
{
method
.
setAccessible
(
true
);
state
=
(
int
)
method
.
invoke
(
subManagerClazz
,
slot
);
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
state
;
}
// public static void startObserving(Context context) {
// context.getContentResolver().registerContentObserver(
// Settings.Global.getUriFor(Settings.Global.MOBILE_DATA),
// false, this);
// for (int i = 0; i < 2; i++) {
// context.getContentResolver().registerContentObserver(
// Settings.Global.getUriFor(Settings.Global.MOBILE_DATA + i),
// false, this);
// }
// context.getContentResolver().registerContentObserver(
// Settings.Global.getUriFor(Settings.Global.AIRPLANE_MODE_ON),
// false, this);
// }
//
// public void endObserving() {
// mContext.getContentResolver().unregisterContentObserver(this);
// }
public
static
int
getSimStateO
(
int
slot
)
{
int
state
=
-
1
;
Class
<?>
subManagerClazz
=
SubscriptionManager
.
class
;
try
{
Method
method
=
subManagerClazz
.
getMethod
(
"getSimStateForSlotIndex"
,
int
.
class
);
if
(
method
!=
null
)
{
method
.
setAccessible
(
true
);
state
=
(
int
)
method
.
invoke
(
subManagerClazz
,
slot
);
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
state
;
}
public
static
boolean
isNetwork
(
Context
context
)
{
if
(
context
!=
null
)
{
ConnectivityManager
mConnectivityManager
=
(
ConnectivityManager
)
context
.
getSystemService
(
Context
.
CONNECTIVITY_SERVICE
);
NetworkInfo
mNetworkInfo
=
mConnectivityManager
.
getActiveNetworkInfo
();
if
(
mNetworkInfo
!=
null
)
{
Log
.
d
(
"PHONE"
,
"has network"
);
return
mNetworkInfo
.
isAvailable
();
}
}
Log
.
d
(
"PHONE"
,
"no network"
);
return
false
;
}
public
static
String
getSubscriptionIccId
(
Context
context
,
int
slot
)
{
String
iccId
=
""
;
SubscriptionManager
subscriptionManager
=
(
SubscriptionManager
)
context
.
getSystemService
(
Context
.
TELEPHONY_SUBSCRIPTION_SERVICE
);
SubscriptionInfo
subscriptionInfo
=
subscriptionManager
.
getActiveSubscriptionInfoForSimSlotIndex
(
slot
);
if
(
subscriptionInfo
!=
null
)
{
iccId
=
subscriptionInfo
.
getIccId
();
}
if
(
iccId
==
null
)
{
iccId
=
""
;
}
return
iccId
;
}
public
static
String
getSubscriptionMeid
(
Context
context
,
int
slot
)
{
String
meid
=
""
;
try
{
TelephonyManager
telephonyManager
=
(
TelephonyManager
)
context
.
getSystemService
(
TELEPHONY_SERVICE
);
Method
method
=
telephonyManager
.
getClass
().
getMethod
(
"getMeid"
,
int
.
class
);
meid
=
(
String
)
method
.
invoke
(
telephonyManager
,
2
);
}
catch
(
NoSuchMethodException
|
InvocationTargetException
|
IllegalAccessException
e
)
{
e
.
printStackTrace
();
}
if
(
meid
==
null
)
{
meid
=
""
;
}
return
meid
;
}
// public static void setMobileDataEnabled(Context context,boolean status) {
// ConnectivityManager connectivityManager = null;
// Class connectivityManagerClz = null;
// try {
// connectivityManager = (ConnectivityManager) context
// .getSystemService(Context.CONNECTIVITY_SERVICE);
// connectivityManagerClz = connectivityManager.getClass();
// Method[] methods = connectivityManagerClz.getMethods();
// for (Method method : methods) {
// Log.d("PHONE", method.toGenericString());
// }
// Method method = connectivityManagerClz.getMethod(
// "setMobileDataEnabled", new Class[]{boolean.class});
// method.invoke(connectivityManager, status);
// } catch (Exception e)
//
// {
// e.printStackTrace();
// }
//
// }
public
static
boolean
isWifiConnected
(
Context
contxt
)
{
ConnectivityManager
mConnectivityManager
=
(
ConnectivityManager
)
contxt
.
getSystemService
(
Context
.
CONNECTIVITY_SERVICE
);
if
(
mConnectivityManager
!=
null
)
{
NetworkInfo
info
=
mConnectivityManager
.
getActiveNetworkInfo
();
return
(
info
!=
null
&&
info
.
getState
()
==
NetworkInfo
.
State
.
CONNECTED
&&
info
.
getType
()
==
ConnectivityManager
.
TYPE_WIFI
);
}
return
false
;
}
public
static
void
setDefaultDataSub
(
SubscriptionManager
subscriptionManager
,
int
slotId
)
{
try
{
Method
method
=
subscriptionManager
.
getClass
().
getMethod
(
"setDefaultDataSubId"
,
int
.
class
);
if
(
method
!=
null
)
{
method
.
invoke
(
subscriptionManager
,
slotId
);
}
}
catch
(
NoSuchMethodException
e
)
{
e
.
printStackTrace
();
}
catch
(
InvocationTargetException
e
)
{
e
.
printStackTrace
();
}
catch
(
IllegalAccessException
e
)
{
e
.
printStackTrace
();
}
}
public
static
void
setMobileDataState
(
Context
context
,
boolean
enabled
)
{
SubscriptionManager
subscriptionManager
=
(
SubscriptionManager
)
context
.
getSystemService
(
Context
.
TELEPHONY_SUBSCRIPTION_SERVICE
);
List
<
SubscriptionInfo
>
subList
=
subscriptionManager
.
getActiveSubscriptionInfoList
();
if
(
subList
==
null
)
{
return
;
}
for
(
SubscriptionInfo
record
:
subList
)
{
if
(
record
!=
null
)
{
TelephonyManager
telephonyService
=
(
TelephonyManager
)
context
.
getSystemService
(
TELEPHONY_SERVICE
);
int
dataSubId
=
0
;
int
subId
=
record
.
getSubscriptionId
();
if
(
Build
.
VERSION
.
SDK_INT
>
Build
.
VERSION_CODES
.
M
)
{
// 6.0¼°ÒÔÉÏ
dataSubId
=
subscriptionManager
.
getDefaultDataSubscriptionId
();
}
else
{
try
{
Method
getDataSubId
=
subscriptionManager
.
getClass
().
getDeclaredMethod
(
"getDefaultDataSubId"
);
if
(
null
!=
getDataSubId
)
{
dataSubId
=
(
int
)
getDataSubId
.
invoke
(
subscriptionManager
);
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
Log
.
i
(
TAG
,
"subId="
+
subId
+
",dataSubId="
+
dataSubId
);
if
(
dataSubId
<
0
)
{
Log
.
i
(
TAG
,
"setDefaultDataSubId="
+
subId
);
setDefaultDataSub
(
subscriptionManager
,
subId
);
}
else
{
Log
.
i
(
TAG
,
"DO NOT setDefaultDataSubId!"
);
}
try
{
Method
setDataEnabled
=
telephonyService
.
getClass
().
getDeclaredMethod
(
"setDataEnabled"
,
boolean
.
class
);
if
(
null
!=
setDataEnabled
)
{
setDataEnabled
.
invoke
(
telephonyService
,
enabled
);
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
break
;
}
}
}
public
boolean
isAirplaneModeOn
(
Context
context
)
{
return
(
Settings
.
System
.
getInt
(
context
.
getContentResolver
(),
Settings
.
System
.
AIRPLANE_MODE_ON
,
0
)
!=
0
);
}
// private void setEnabled(Context context, boolean enabled) {
// // Do not make mobile data on/off if airplane mode on or has no sim card
// final boolean airPlaneModeOn = isAirplaneModeOn(context);
//
// if (airPlaneModeOn) {
// Log.d(TAG, "setEnabled enabled = " + enabled + " Settings.Global.AIRPLANE_MODE_ON"
// + airPlaneModeOn);
// return;
// }
// Log.d(TAG, "setEnabled enabled=" + enabled);
// int subId0 = -1;
// int subId1 = -1;
// int[] subs0 = SubscriptionManager.getSubId(PhoneConstants.SIM_ID_1);
// int[] subs1 = SubscriptionManager.getSubId(PhoneConstants.SIM_ID_2);
// subId0 = subs0 == null ? -1 : subs0[0];
// subId1 = subs1 == null ? -1 : subs1[0];
// if (enabled) {
// int defDataSubId = SubscriptionManager.getDefaultDataSubscriptionId();
// if (SubscriptionManager.isValidSubscriptionId(defDataSubId)) {
// Log.d(TAG, "setDataEnabled true, dataSubId = " + defDataSubId);
// mTelephonyManager.setDataEnabled(true);
// } else if (SubscriptionManager.isValidSubscriptionId(subId0)) {
// Log.d(TAG, "setDataEnabled true, subId0 = " + subId0);
// mTelephonyManager.setDataEnabled(subId0, true);
// } else if (SubscriptionManager.isValidSubscriptionId(subId1)) {
// Log.d(TAG, "setDataEnabled true, subId1 = " + subId1);
// mTelephonyManager.setDataEnabled(subId1, true);
// }
// } else {
// // if (QKCommRunMode.getDefault().isLEOS() || QKCommRunMode.getDefault().isSEOS()) {
// int[] subList = SubscriptionManager.from(context).getActiveSubscriptionIdList();
// for (int subId : subList) {
// if (mTelephonyManager.getDataEnabled(subId)) {
// Log.d(TAG, "setDataEnabled false, subId = " + subId);
// mTelephonyManager.setDataEnabled(subId, false);
// }
// }
// // } else {
// // mTelephonyManager.setDataEnabled(false);
// // }
//
// }
// // 360OS modify end, for Bug 192116
//
// // if (enabled && QKCommRunMode.getDefault().isMTKPlatform()) {//fix Bug 153456
// int[] subList = SubscriptionManager.from(mContext).getActiveSubscriptionIdList();
// Log.d(TAG, "setEnabled subList = " + (subList == null));
// int dataSubId = SubscriptionManager.getDefaultDataSubscriptionId();
// for (int subId : subList) {
// if (subId != dataSubId && mTelephonyManager.getDataEnabled(subId)) {
// mTelephonyManager.setDataEnabled(subId, false);
// }
// }
// // }
// }
public
static
boolean
getMobileDataState
(
Context
context
)
{
TelephonyManager
telephonyService
=
(
TelephonyManager
)
context
.
getSystemService
(
TELEPHONY_SERVICE
);
try
{
Method
getDataEnabled
=
telephonyService
.
getClass
().
getDeclaredMethod
(
"getDataEnabled"
);
if
(
null
!=
getDataEnabled
)
{
return
(
Boolean
)
getDataEnabled
.
invoke
(
telephonyService
);
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
false
;
}
public
static
boolean
isSimAvailable
(
Context
context
,
int
slot
)
{
SubscriptionManager
subscriptionManager
=
(
SubscriptionManager
)
context
.
getSystemService
(
Context
.
TELEPHONY_SUBSCRIPTION_SERVICE
);
SubscriptionInfo
subscriptionInfo
=
subscriptionManager
.
getActiveSubscriptionInfoForSimSlotIndex
(
slot
);
if
(
Build
.
VERSION
.
SDK_INT
>=
26
)
{
return
subscriptionInfo
!=
null
&&
(
getSimStateO
(
slot
)
==
SIM_STATE_READY
);
}
else
{
return
subscriptionInfo
!=
null
&&
(
getSimState
(
slot
)
==
SIM_STATE_READY
);
}
}
public
static
boolean
isMobileNumberInValid
(
String
str
)
{
Log
.
d
(
"PHONE"
,
"isMobileNumberInValid:"
+
str
);
if
(
TextUtils
.
isEmpty
(
str
))
{
return
true
;
}
Pattern
pattern
;
Matcher
matcher
;
pattern
=
Pattern
.
compile
(
"^((\\+86)|(86))?[1][3456789][0-9]{9}$"
);
matcher
=
pattern
.
matcher
(
str
);
boolean
result
=
!
matcher
.
matches
();
Log
.
d
(
"PHONE"
,
"isMobileNumberInValid:"
+
result
);
return
result
;
}
public
static
String
trimNum
(
String
prefix
,
String
number
)
{
String
s
=
number
;
if
(
prefix
.
length
()
>
0
&&
number
.
startsWith
(
prefix
))
{
s
=
number
.
substring
(
prefix
.
length
());
}
return
s
;
}
public
static
String
getLocalNumber
(
Context
context
,
int
slot
)
{
String
number
=
""
;
SubscriptionManager
subscriptionManager
=
(
SubscriptionManager
)
context
.
getSystemService
(
Context
.
TELEPHONY_SUBSCRIPTION_SERVICE
);
SubscriptionInfo
subscriptionInfo
=
subscriptionManager
.
getActiveSubscriptionInfoForSimSlotIndex
(
slot
);
if
(
null
!=
subscriptionInfo
)
{
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
N
)
{
number
=
getPhoneNumberN
(
context
,
subscriptionInfo
.
getSubscriptionId
());
}
else
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
LOLLIPOP_MR1
)
{
number
=
getPhoneNumberM
(
context
,
subscriptionInfo
.
getSubscriptionId
());
}
}
if
(
number
==
null
)
{
number
=
""
;
}
return
number
;
}
private
static
String
getPhoneNumberN
(
Context
context
,
int
subId
)
{
String
result
=
""
;
try
{
TelephonyManager
telephonyManager
=
(
TelephonyManager
)
context
.
getSystemService
(
TELEPHONY_SERVICE
);
Class
<?>
telephonyManagerClazz
=
telephonyManager
.
getClass
();
Method
getNumMethod
=
telephonyManagerClazz
.
getMethod
(
"getLine1Number"
,
int
.
class
);
result
=
(
String
)
getNumMethod
.
invoke
(
telephonyManager
,
subId
);
}
catch
(
NoSuchMethodException
|
InvocationTargetException
|
IllegalAccessException
e
)
{
e
.
printStackTrace
();
}
if
(
result
==
null
)
{
result
=
""
;
}
Log
.
d
(
"PHONE"
,
"getPhoneNumberN "
+
result
);
return
result
;
}
private
static
String
getPhoneNumberM
(
Context
context
,
int
subId
)
{
String
result
=
""
;
TelephonyManager
telephonyManager
=
(
TelephonyManager
)
context
.
getSystemService
(
TELEPHONY_SERVICE
);
try
{
Class
<?>
telephonyManagerClazz
=
telephonyManager
.
getClass
();
Method
getSimState
=
telephonyManagerClazz
.
getMethod
(
"getLine1NumberForSubscriber"
,
int
.
class
);
result
=
(
String
)
getSimState
.
invoke
(
telephonyManager
,
subId
);
}
catch
(
NoSuchMethodException
|
InvocationTargetException
|
IllegalAccessException
e
)
{
e
.
printStackTrace
();
}
if
(
result
==
null
)
{
result
=
""
;
}
Log
.
d
(
"PHONE"
,
"getPhoneNumberM "
+
result
);
return
result
;
}
static
public
String
getProperty
(
String
key
,
String
defaultValue
)
{
String
value
=
defaultValue
;
try
{
Class
<?>
c
=
Class
.
forName
(
"android.os.SystemProperties"
);
Method
get
=
c
.
getMethod
(
"get"
,
String
.
class
,
String
.
class
);
value
=
(
String
)(
get
.
invoke
(
c
,
key
,
""
));
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
finally
{
return
value
;
}
}
private
static
final
String
[]
PROPERTY_UIM_SUBSCRIBER_ID
=
{
"ril.uim.subscriberid.1"
,
"ril.uim.subscriberid.2"
,
};
private
static
final
String
[]
PROPERTY_GSM_SUBSCRIBER_ID
=
{
" vendor.ril.data.gsm_imsi1"
,
" vendor.ril.data.gsm_imsi2"
,
};
/**
* @param slotId 0 or 1
* @return
*/
// public static final int getSubId(int slotId) {
// int[] subIds = SubscriptionManager.getSubId(slotId);
// return null != subIds && subIds.length > 0 ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID;
// }
public
static
int
getSubId
(
Context
context
,
int
slotId
)
{
final
SubscriptionManager
subscriptionManager
=
SubscriptionManager
.
from
(
context
);
final
SubscriptionInfo
sir
=
subscriptionManager
.
getActiveSubscriptionInfoForSimSlotIndex
(
slotId
);
int
subId
=
SubscriptionManager
.
INVALID_SUBSCRIPTION_ID
;
if
(
sir
!=
null
)
{
subId
=
sir
.
getSubscriptionId
();
}
return
subId
;
}
public
static
String
getMccMnc
(
Context
context
,
int
subId
)
{
String
imsi
=
""
;
if
(
subId
<
0
){
return
""
;
}
TelephonyManager
telephonyManager
=
(
TelephonyManager
)
context
.
getSystemService
(
TELEPHONY_SERVICE
);
try
{
Class
<?>
telephonyManagerClazz
=
telephonyManager
.
getClass
();
Method
getSubscriberId
=
telephonyManagerClazz
.
getMethod
(
"getSubscriberId"
,
int
.
class
);
imsi
=
(
String
)
getSubscriberId
.
invoke
(
telephonyManager
,
subId
);
if
(
imsi
==
null
||
imsi
.
isEmpty
())
{
imsi
=
""
+
getProperty
(
PROPERTY_UIM_SUBSCRIBER_ID
[
subId
],
""
);
}
if
(
imsi
==
null
||
imsi
.
isEmpty
())
{
imsi
=
""
+
getProperty
(
PROPERTY_GSM_SUBSCRIBER_ID
[
subId
],
""
);
}
}
catch
(
NoSuchMethodException
|
InvocationTargetException
|
IllegalAccessException
e
)
{
e
.
printStackTrace
();
}
finally
{
Log
.
d
(
"PHONE"
,
"getMccMnc imsi:"
+
imsi
);
//if (imsi != null && imsi.length() > 5) {
// imsi = imsi.substring(0, 5);
// }
if
(
imsi
==
null
)
{
imsi
=
""
;
}
return
imsi
;
}
}
public
static
String
getPhoneMEID
(
Context
context
){
//实例化TelephonyManager对象
TelephonyManager
telephonyManager
=
(
TelephonyManager
)
context
.
getSystemService
(
Context
.
TELEPHONY_SERVICE
);
String
meid
=
""
;
try
{
Method
method
=
telephonyManager
.
getClass
().
getMethod
(
"getDeviceId"
,
int
.
class
);
meid
=
getProperty
(
"gsm.mtk.meid"
,
""
);
if
(
TextUtils
.
isEmpty
(
meid
))
meid
=
getProperty
(
"persist.radio.us.meid"
,
""
);
if
(
TextUtils
.
isEmpty
(
meid
))
meid
=
getProperty
(
"sys.tt.meid"
,
""
);
int
phoneCount
=
telephonyManager
.
getPhoneCount
();
if
(
TextUtils
.
isEmpty
(
meid
)){
for
(
int
slot
=
0
;
slot
<
phoneCount
;
slot
++)
{
String
deviceId
=
(
String
)
method
.
invoke
(
telephonyManager
,
slot
);
if
(
deviceId
!=
null
&&
deviceId
.
length
()
==
14
)
{
if
(
TextUtils
.
isEmpty
(
meid
)
||
meid
.
length
()
<
14
)
meid
=
deviceId
;
}
}
}
if
(
TextUtils
.
isEmpty
(
meid
)){
for
(
int
slot
=
0
;
slot
<
phoneCount
;
slot
++)
{
if
(
TextUtils
.
isEmpty
(
meid
)
||
meid
.
startsWith
(
"00000"
))
{
Method
getMeid
=
telephonyManager
.
getClass
().
getMethod
(
"getMeid"
,
int
.
class
);
Object
r
=
getMeid
.
invoke
(
telephonyManager
,
slot
);
if
(
r
instanceof
String
)
{
String
tmp
=
(
String
)
r
;
if
(!
TextUtils
.
isEmpty
(
tmp
)
&&
tmp
.
trim
().
length
()
==
14
&&
!
tmp
.
startsWith
(
"00000"
)){
meid
=
tmp
;
}
}
else
{
Log
.
w
(
TAG
,
"getMeid: slot="
+
slot
+
" meid return null! "
);
}
}
}
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
meid
;
}
private
static
boolean
isLogSystemValid
(
Context
context
)
{
return
true
;
//return getVersionCode(context, "com.qiku.logsystem") >= 138;
}
private
static
boolean
isTelProviderBlockValid
(
Context
context
)
{
return
true
;
//return getVersionCode(context, "com.android.providers.telephony") >= 24;
}
public
static
int
getVersionCode
(
Context
context
,
String
pkgName
)
{
int
versionCode
;
Log
.
d
(
"PHONE"
,
"getVersionCode,pkgName="
+
pkgName
);
try
{
versionCode
=
context
.
getPackageManager
().
getPackageInfo
(
pkgName
,
0
).
versionCode
;
}
catch
(
PackageManager
.
NameNotFoundException
ex
)
{
versionCode
=
0
;
}
Log
.
d
(
"PHONE"
,
"getVersionCode,versionCode="
+
versionCode
);
return
versionCode
;
}
}
\ No newline at end of file
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