Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
android_fairyland_pro
Project
Project
Details
Activity
Releases
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
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
android
android_fairyland_pro
Commits
2165a9dd
Commit
2165a9dd
authored
May 12, 2021
by
jyx
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
更新风控策略
parent
34487f7d
Changes
12
Show whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
298 additions
and
153 deletions
+298
-153
build.gradle
app/build.gradle
+4
-3
AndroidManifest.xml
app/src/main/AndroidManifest.xml
+0
-3
DeviceInfo.kt
app/src/main/java/com/mints/fairyland/common/DeviceInfo.kt
+34
-0
SimulatorManager.kt
...main/java/com/mints/fairyland/manager/SimulatorManager.kt
+24
-0
TrackManager.java
...c/main/java/com/mints/fairyland/manager/TrackManager.java
+6
-0
AwardPresenter.java
...va/com/mints/fairyland/mvp/presenters/AwardPresenter.java
+0
-50
DrawcashPresenter.java
...com/mints/fairyland/mvp/presenters/DrawcashPresenter.java
+2
-43
LoginPresenter.kt
...java/com/mints/fairyland/mvp/presenters/LoginPresenter.kt
+2
-45
TrackPresenter.java
...va/com/mints/fairyland/mvp/presenters/TrackPresenter.java
+70
-0
AwardActivity.kt
...in/java/com/mints/fairyland/ui/activitys/AwardActivity.kt
+1
-1
MainFragment.kt
...main/java/com/mints/fairyland/ui/fragment/MainFragment.kt
+8
-8
AccessibilityUtils.java
...in/java/com/mints/fairyland/utils/AccessibilityUtils.java
+147
-0
No files found.
app/build.gradle
View file @
2165a9dd
...
...
@@ -185,6 +185,10 @@ dependencies {
implementation
'com.mindorks.android:prdownloader:0.6.0'
// 圆角库
implementation
'com.github.SheHuan:NiceImageView:1.0.5'
// 跑马灯
implementation
'com.sunfusheng:marqueeview:1.2.0'
// 检测运行设备是否模拟器
implementation
'com.snail:antifake:1.4'
// 工具类
// gson
...
...
@@ -291,9 +295,6 @@ dependencies {
implementation
'com.squareup.retrofit2:converter-scalars:2.6.2'
implementation
'com.squareup.retrofit2:converter-gson:2.6.2'
// 跑马灯
implementation
'com.sunfusheng:marqueeview:1.2.0'
// 激励视频RTA
implementation
(
name:
'taskwake1.0'
,
ext:
'aar'
)
implementation
'com.squareup.retrofit2:converter-gson:2.6.2'
...
...
app/src/main/AndroidManifest.xml
View file @
2165a9dd
...
...
@@ -168,9 +168,6 @@
<activity
android:name=
".ui.activitys.GuideActivity"
android:screenOrientation=
"portrait"
/>
<activity
android:name=
".ui.activitys.LiebaoGameActivity"
android:screenOrientation=
"portrait"
/>
<activity
android:name=
".ui.activitys.DrawcashActivity"
android:screenOrientation=
"portrait"
/>
...
...
app/src/main/java/com/mints/fairyland/common/DeviceInfo.kt
View file @
2165a9dd
...
...
@@ -916,6 +916,40 @@ class DeviceInfo private constructor() {
return
WifiAddress
}
/**
* 获取后台运行APP
*/
fun
getRunningApp
():
String
{
try
{
val
appList
:
MutableList
<
MutableMap
<
String
,
String
>>
=
ArrayList
()
val
localPackageManager
=
mContext
?.
packageManager
localPackageManager
?.
let
{
val
localList
=
localPackageManager
.
getInstalledPackages
(
0
)
for
(
i
in
0
until
localList
.
size
)
{
val
pinfo
=
localList
.
get
(
i
)
as
PackageInfo
if
(
pinfo
.
applicationInfo
.
flags
and
ApplicationInfo
.
FLAG_SYSTEM
>
0
)
{
//系统程序 忽略
continue
}
if
(
ApplicationInfo
.
FLAG_UPDATED_SYSTEM_APP
and
pinfo
.
applicationInfo
.
flags
==
0
&&
ApplicationInfo
.
FLAG_STOPPED
and
pinfo
.
applicationInfo
.
flags
==
0
)
{
val
appMap
:
MutableMap
<
String
,
String
>
=
HashMap
()
appMap
[
"appName"
]
=
pinfo
.
applicationInfo
.
loadLabel
(
mContext
!!
.
packageManager
)
as
String
appMap
[
"appPkg"
]
=
pinfo
.
packageName
appList
.
add
(
appMap
)
}
}
return
JsonUtil
.
toJson
(
appList
)
}
}
catch
(
e
:
Exception
){
}
return
""
}
/**
* 遍历循环所有的网络接口,找到接口是 wlan0
* 必须的权限 <uses-permission android:name="android.permission.INTERNET"></uses-permission>
...
...
app/src/main/java/com/mints/fairyland/manager/SimulatorManager.kt
0 → 100644
View file @
2165a9dd
package
com.mints.fairyland.manager
import
com.mints.fairyland.MintsApplication
import
com.snail.antifake.jni.EmulatorDetectUtil
/**
* 描述:模拟器校验
* 作者:孟崔广
*/
object
SimulatorManager
{
/**
* 是否是模拟器 0-不是模拟器
*/
fun
isEmulator
():
Int
{
try
{
return
if
(
EmulatorDetectUtil
.
isEmulator
(
MintsApplication
.
getContext
()))
1
else
0
}
catch
(
e
:
Exception
)
{
e
.
printStackTrace
()
}
return
0
}
}
\ No newline at end of file
app/src/main/java/com/mints/fairyland/manager/TrackManager.java
View file @
2165a9dd
...
...
@@ -132,4 +132,10 @@ public class TrackManager {
}
}
public
void
riskinfo
()
{
if
(
trackPresenter
!=
null
&&
!
TextUtils
.
isEmpty
(
UserManager
.
getInstance
().
getUserID
()))
{
trackPresenter
.
riskinfo
();
}
}
}
app/src/main/java/com/mints/fairyland/mvp/presenters/AwardPresenter.java
View file @
2165a9dd
...
...
@@ -198,54 +198,4 @@ public class AwardPresenter extends BasePresenter<AwardView> {
});
}
public
void
riskinfo
()
{
DeviceInfo
deviceInfo
=
DeviceInfo
.
Companion
.
getInstance
();
RxjavaUtil
.
executeRxTask
(
new
CommonRxTask
<
String
>(
""
)
{
@Override
public
void
doInIOThread
()
{
setT
(
deviceInfo
.
getAppInfoMap
());
}
@Override
public
void
doInUIThread
()
{
HashMap
<
String
,
Object
>
vo
=
new
HashMap
<>();
vo
.
put
(
"androidid"
,
deviceInfo
.
getAndroidId
(
null
));
vo
.
put
(
"os"
,
"android"
);
vo
.
put
(
"model"
,
deviceInfo
.
getBrand
()
+
" "
+
deviceInfo
.
getMobileModel
());
vo
.
put
(
"uuid"
,
new
DeviceUuidFactory
().
getDeviceUuid
());
vo
.
put
(
"osversion"
,
deviceInfo
.
getOSVersion
());
vo
.
put
(
"appversion"
,
deviceInfo
.
getVersionName
());
vo
.
put
(
"applist"
,
getT
());
vo
.
put
(
"eventid"
,
Constant
.
RISK_EVENT_ID_TASK
);
vo
.
put
(
"ischarge"
,
deviceInfo
.
isCharging
());
vo
.
put
(
"isusbdebug"
,
deviceInfo
.
getGetUsbStatus
());
vo
.
put
(
"iswifi"
,
deviceInfo
.
getGetWifiConnected
());
vo
.
put
(
"isroot"
,
deviceInfo
.
isRoot
());
vo
.
put
(
"isvpn"
,
deviceInfo
.
isVPN
());
vo
.
put
(
"memory"
,
deviceInfo
.
getTotalMemory
()
+
"+"
+
deviceInfo
.
getTotalStorage
());
vo
.
put
(
"operator"
,
deviceInfo
.
getOperator
());
vo
.
put
(
"idfa"
,
""
);
vo
.
put
(
"imei"
,
deviceInfo
.
getIMEI
());
vo
.
put
(
"oaid"
,
MintsApplication
.
OAID
);
AppHttpManager
.
getInstance
(
loanApplication
)
.
call
(
loanService
.
riskinfo
(
vo
),
new
BaseSubscriber
<
BaseResponse
<
Object
>>()
{
@Override
public
void
onCompleted
()
{
if
(
isLinkView
())
return
;
}
@Override
public
void
onError
(
Throwable
e
)
{
}
@Override
public
void
onNext
(
BaseResponse
<
Object
>
baseResponse
)
{
}
});
}
});
}
}
app/src/main/java/com/mints/fairyland/mvp/presenters/DrawcashPresenter.java
View file @
2165a9dd
...
...
@@ -8,6 +8,7 @@ import com.mints.fairyland.common.Constant;
import
com.mints.fairyland.common.DeviceInfo
;
import
com.mints.fairyland.manager.AppHttpManager
;
import
com.mints.fairyland.manager.ShumeiManager
;
import
com.mints.fairyland.manager.TrackManager
;
import
com.mints.fairyland.manager.UserManager
;
import
com.mints.fairyland.mvp.model.BaseResponse
;
import
com.mints.fairyland.mvp.model.DrawcashBean
;
...
...
@@ -152,7 +153,7 @@ public class DrawcashPresenter extends BasePresenter<DrawcashView> {
vo
.
put
(
"oaid"
,
MintsApplication
.
OAID
);
}
riskinfo
(
deviceInfo
,
getT
()
);
TrackManager
.
getInstance
().
riskinfo
(
);
AppHttpManager
.
getInstance
(
loanApplication
)
.
call
(
loanService
.
saveTerminalInfo
(
vo
),
...
...
@@ -314,46 +315,4 @@ public class DrawcashPresenter extends BasePresenter<DrawcashView> {
});
}
/**
* 风控信息
*/
private
void
riskinfo
(
DeviceInfo
deviceInfo
,
String
appPkgList
)
{
HashMap
<
String
,
Object
>
vo
=
new
HashMap
<>();
vo
.
put
(
"androidid"
,
deviceInfo
.
getAndroidId
(
null
));
vo
.
put
(
"os"
,
"android"
);
vo
.
put
(
"model"
,
deviceInfo
.
getBrand
()
+
" "
+
deviceInfo
.
getMobileModel
());
vo
.
put
(
"uuid"
,
new
DeviceUuidFactory
().
getDeviceUuid
());
vo
.
put
(
"osversion"
,
deviceInfo
.
getOSVersion
());
vo
.
put
(
"appversion"
,
deviceInfo
.
getVersionName
());
vo
.
put
(
"applist"
,
appPkgList
);
vo
.
put
(
"eventid"
,
Constant
.
RISK_EVENT_ID_DRAWCASH
);
vo
.
put
(
"ischarge"
,
deviceInfo
.
isCharging
());
vo
.
put
(
"isusbdebug"
,
deviceInfo
.
getGetUsbStatus
());
vo
.
put
(
"iswifi"
,
deviceInfo
.
getGetWifiConnected
());
vo
.
put
(
"isroot"
,
deviceInfo
.
isRoot
());
vo
.
put
(
"isvpn"
,
deviceInfo
.
isVPN
());
vo
.
put
(
"memory"
,
deviceInfo
.
getTotalMemory
()
+
"+"
+
deviceInfo
.
getTotalStorage
());
vo
.
put
(
"operator"
,
deviceInfo
.
getOperator
());
vo
.
put
(
"idfa"
,
""
);
vo
.
put
(
"imei"
,
deviceInfo
.
getIMEI
());
vo
.
put
(
"oaid"
,
MintsApplication
.
OAID
);
AppHttpManager
.
getInstance
(
loanApplication
)
.
call
(
loanService
.
riskinfo
(
vo
),
new
BaseSubscriber
<
BaseResponse
<
Object
>>()
{
@Override
public
void
onCompleted
()
{
if
(
isLinkView
())
return
;
}
@Override
public
void
onError
(
Throwable
e
)
{
}
@Override
public
void
onNext
(
BaseResponse
<
Object
>
baseResponse
)
{
}
});
}
}
app/src/main/java/com/mints/fairyland/mvp/presenters/LoginPresenter.kt
View file @
2165a9dd
...
...
@@ -2,12 +2,8 @@ package com.mints.fairyland.mvp.presenters
import
android.text.TextUtils
import
com.mints.fairyland.MintsApplication
import
com.mints.fairyland.common.Constant
import
com.mints.fairyland.common.DeviceInfo
import
com.mints.fairyland.manager.AppHttpManager
import
com.mints.fairyland.manager.JpushManager
import
com.mints.fairyland.manager.ShumeiManager
import
com.mints.fairyland.manager.UserManager
import
com.mints.fairyland.manager.*
import
com.mints.fairyland.mvp.model.BaseResponse
import
com.mints.fairyland.mvp.model.UserBean
import
com.mints.fairyland.mvp.views.LoginView
...
...
@@ -251,7 +247,7 @@ class LoginPresenter : BasePresenter<LoginView>() {
vo
[
"shumeiId"
]
=
ShumeiManager
.
getInstance
().
getShumeiDeviceId
()
vo
[
"appPkgList"
]
=
t
.
toString
()
riskinfo
(
deviceInfo
,
t
.
toString
()
)
TrackManager
.
getInstance
().
riskinfo
(
)
AppHttpManager
.
getInstance
(
loanApplication
)
.
call
(
loanService
.
saveTerminalInfo
(
vo
),
...
...
@@ -280,43 +276,4 @@ class LoginPresenter : BasePresenter<LoginView>() {
}
/**
* 风控信息
*/
fun
riskinfo
(
deviceInfo
:
DeviceInfo
,
appPkgList
:
String
)
{
val
vo
=
HashMap
<
String
,
Any
>()
vo
[
"androidid"
]
=
deviceInfo
.
getAndroidId
(
null
)
vo
[
"os"
]
=
"android"
vo
[
"model"
]
=
deviceInfo
.
brand
+
" "
+
deviceInfo
.
mobileModel
vo
[
"uuid"
]
=
DeviceUuidFactory
().
deviceUuid
vo
[
"osversion"
]
=
deviceInfo
.
oSVersion
vo
[
"appversion"
]
=
deviceInfo
.
versionName
vo
[
"applist"
]
=
appPkgList
vo
[
"eventid"
]
=
Constant
.
RISK_EVENT_ID_LOGIN
vo
[
"ischarge"
]
=
deviceInfo
.
isCharging
vo
[
"isusbdebug"
]
=
deviceInfo
.
getUsbStatus
vo
[
"iswifi"
]
=
deviceInfo
.
getWifiConnected
vo
[
"isroot"
]
=
deviceInfo
.
isRoot
vo
[
"isvpn"
]
=
deviceInfo
.
isVPN
vo
[
"memory"
]
=
deviceInfo
.
totalMemory
+
"+"
+
deviceInfo
.
totalStorage
vo
[
"operator"
]
=
deviceInfo
.
operator
vo
[
"idfa"
]
=
""
vo
[
"imei"
]
=
deviceInfo
.
iMEI
vo
[
"oaid"
]
=
MintsApplication
.
OAID
AppHttpManager
.
getInstance
(
loanApplication
)
.
call
(
loanService
.
riskinfo
(
vo
),
object
:
BaseSubscriber
<
BaseResponse
<
Object
>>()
{
override
fun
onCompleted
()
{
}
override
fun
onError
(
e
:
Throwable
)
{
}
override
fun
onNext
(
baseResponse
:
BaseResponse
<
Object
>)
{
}
})
}
}
\ No newline at end of file
app/src/main/java/com/mints/fairyland/mvp/presenters/TrackPresenter.java
View file @
2165a9dd
...
...
@@ -6,11 +6,17 @@ import com.google.gson.JsonObject;
import
com.mints.fairyland.MintsApplication
;
import
com.mints.fairyland.common.AppConfig
;
import
com.mints.fairyland.common.Constant
;
import
com.mints.fairyland.common.DeviceInfo
;
import
com.mints.fairyland.manager.AppHttpManager
;
import
com.mints.fairyland.manager.SimulatorManager
;
import
com.mints.fairyland.manager.UserWeight
;
import
com.mints.fairyland.mvp.model.BaseResponse
;
import
com.mints.fairyland.mvp.model.CommonParamBean
;
import
com.mints.fairyland.mvp.model.UserTaskMsgBean
;
import
com.mints.fairyland.utils.AccessibilityUtils
;
import
com.mints.fairyland.utils.DeviceUuidFactory
;
import
com.mints.fairyland.utils.rxutil.CommonRxTask
;
import
com.mints.fairyland.utils.rxutil.RxjavaUtil
;
import
com.mints.library.net.neterror.BaseSubscriber
;
import
com.mints.library.net.neterror.Throwable
;
...
...
@@ -303,4 +309,68 @@ public class TrackPresenter extends BaseTrackPresenter {
});
}
public
void
riskinfo
()
{
DeviceInfo
deviceInfo
=
DeviceInfo
.
Companion
.
getInstance
();
HashMap
<
String
,
Object
>
vo
=
new
HashMap
<>();
RxjavaUtil
.
executeRxTask
(
new
CommonRxTask
<
String
>(
""
)
{
@Override
public
void
doInIOThread
()
{
setT
(
deviceInfo
.
getAppInfoMap
());
}
@Override
public
void
doInUIThread
()
{
vo
.
put
(
"androidid"
,
deviceInfo
.
getAndroidId
(
null
));
vo
.
put
(
"os"
,
"android"
);
vo
.
put
(
"model"
,
deviceInfo
.
getBrand
()
+
" "
+
deviceInfo
.
getMobileModel
());
vo
.
put
(
"uuid"
,
new
DeviceUuidFactory
().
getDeviceUuid
());
vo
.
put
(
"osversion"
,
deviceInfo
.
getOSVersion
());
vo
.
put
(
"appversion"
,
deviceInfo
.
getVersionName
());
vo
.
put
(
"applist"
,
getT
());
vo
.
put
(
"eventid"
,
Constant
.
RISK_EVENT_ID_TASK
);
vo
.
put
(
"ischarge"
,
deviceInfo
.
isCharging
());
vo
.
put
(
"isusbdebug"
,
deviceInfo
.
getGetUsbStatus
());
vo
.
put
(
"iswifi"
,
deviceInfo
.
getGetWifiConnected
());
vo
.
put
(
"isroot"
,
deviceInfo
.
isRoot
());
vo
.
put
(
"isvpn"
,
deviceInfo
.
isVPN
());
vo
.
put
(
"memory"
,
deviceInfo
.
getTotalMemory
()
+
"+"
+
deviceInfo
.
getTotalStorage
());
vo
.
put
(
"operator"
,
deviceInfo
.
getOperator
());
vo
.
put
(
"idfa"
,
""
);
vo
.
put
(
"imei"
,
deviceInfo
.
getIMEI
());
vo
.
put
(
"oaid"
,
MintsApplication
.
OAID
);
vo
.
put
(
"isSimulator"
,
SimulatorManager
.
INSTANCE
.
isEmulator
());
vo
.
put
(
"isAccessibility"
,
AccessibilityUtils
.
isAccessibilityEnabled
());
RxjavaUtil
.
executeRxTask
(
new
CommonRxTask
<
String
>(
""
)
{
@Override
public
void
doInIOThread
()
{
setT
(
deviceInfo
.
getRunningApp
());
}
@Override
public
void
doInUIThread
()
{
vo
.
put
(
"appRunningPkgList"
,
getT
());
AppHttpManager
.
getInstance
(
loanApplication
)
.
call
(
loanService
.
riskinfo
(
vo
),
new
BaseSubscriber
<
BaseResponse
<
Object
>>()
{
@Override
public
void
onCompleted
()
{
}
@Override
public
void
onError
(
Throwable
e
)
{
}
@Override
public
void
onNext
(
BaseResponse
<
Object
>
baseResponse
)
{
}
});
}
});
}
});
}
}
app/src/main/java/com/mints/fairyland/ui/activitys/AwardActivity.kt
View file @
2165a9dd
...
...
@@ -611,7 +611,7 @@ class AwardActivity : BaseActivity(), AwardView, View.OnClickListener {
// 上传风控信息
if
(
riskFlag
)
{
awardPresenter
.
riskinfo
()
TrackManager
.
getInstance
()
.
riskinfo
()
}
}
...
...
app/src/main/java/com/mints/fairyland/ui/fragment/MainFragment.kt
View file @
2165a9dd
...
...
@@ -330,7 +330,7 @@ class MainFragment : BaseFragment(), HomeView, View.OnClickListener {
}
/**
*
一览
视频初始化
*
快手
视频初始化
*/
private
fun
showLittle
()
{
val
adScene
=
KsScene
.
Builder
(
5746000003L
).
build
()
...
...
@@ -427,7 +427,7 @@ class MainFragment : BaseFragment(), HomeView, View.OnClickListener {
private
fun
initListener
()
{
val
params
=
LinearLayout
.
LayoutParams
(
LinearLayout
.
LayoutParams
.
WRAP_CONTENT
,
LinearLayout
.
LayoutParams
.
WRAP_CONTENT
)
params
.
setMargins
(
0
,
0
,
0
,
BubbleUtils
.
dp2px
(
32
0
))
params
.
setMargins
(
0
,
0
,
0
,
BubbleUtils
.
dp2px
(
40
0
))
cdvvYilanTime
.
layoutParams
=
params
val
paramsRedBox
=
FrameLayout
.
LayoutParams
(
FrameLayout
.
LayoutParams
.
WRAP_CONTENT
,
FrameLayout
.
LayoutParams
.
WRAP_CONTENT
)
...
...
@@ -439,12 +439,12 @@ class MainFragment : BaseFragment(), HomeView, View.OnClickListener {
rl_fragment_main_redbox
.
isClickable
=
false
}
private
fun
resumeAdTime
()
{
// 视频未转满 且 界面切换时可继续加进度
if
(!
isAward
)
{
cdvvYilanTime
?.
resume
()
}
}
//
private fun resumeAdTime() {
//
// 视频未转满 且 界面切换时可继续加进度
//
if (!isAward) {
//
cdvvYilanTime?.resume()
//
}
//
}
/**
* 将播放的id记录到list中
...
...
app/src/main/java/com/mints/fairyland/utils/AccessibilityUtils.java
0 → 100644
View file @
2165a9dd
package
com
.
mints
.
fairyland
.
utils
;
import
android.accessibilityservice.AccessibilityServiceInfo
;
import
android.content.ContentResolver
;
import
android.content.Context
;
import
android.content.Intent
;
import
android.content.pm.ResolveInfo
;
import
android.database.Cursor
;
import
android.net.Uri
;
import
android.os.Build
;
import
android.provider.Settings
;
import
android.text.TextUtils
;
import
android.view.accessibility.AccessibilityManager
;
import
com.mints.fairyland.MintsApplication
;
import
java.util.ArrayList
;
import
java.util.List
;
/**
* 无障碍服务
*/
public
class
AccessibilityUtils
{
/**
* 判断用户是否开启无障碍服务
*
* @return 0-未开启无障碍功能
* @throws RuntimeException
*/
public
static
int
isAccessibilityEnabled
()
{
try
{
// 检查AccessibilityService是否开启
AccessibilityManager
am
=
(
AccessibilityManager
)
MintsApplication
.
getContext
().
getSystemService
(
Context
.
ACCESSIBILITY_SERVICE
);
boolean
isAccessibilityEnabled_flag
=
am
.
isEnabled
();
return
isAccessibilityEnabled_flag
?
1
:
0
;
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
0
;
// boolean isExploreByTouchEnabled_flag = false;
//
// // 检查无障碍服务是否以语音播报的方式开启
// isExploreByTouchEnabled_flag = isScreenReaderActive(context);
//
// return (isAccessibilityEnabled_flag && isExploreByTouchEnabled_flag);
}
private
final
static
String
SCREEN_READER_INTENT_ACTION
=
"android.accessibilityservice.AccessibilityService"
;
private
final
static
String
SCREEN_READER_INTENT_CATEGORY
=
"android.accessibilityservice.category.FEEDBACK_SPOKEN"
;
private
static
boolean
isScreenReaderActive
(
Context
context
)
{
// 通过Intent方式判断是否存在以语音播报方式提供服务的Service,还需要判断开启状态
Intent
screenReaderIntent
=
new
Intent
(
SCREEN_READER_INTENT_ACTION
);
screenReaderIntent
.
addCategory
(
SCREEN_READER_INTENT_CATEGORY
);
List
<
ResolveInfo
>
screenReaders
=
context
.
getPackageManager
().
queryIntentServices
(
screenReaderIntent
,
0
);
// 如果没有,返回false
if
(
screenReaders
==
null
||
screenReaders
.
size
()
<=
0
)
{
return
false
;
}
boolean
hasActiveScreenReader
=
false
;
if
(
Build
.
VERSION
.
SDK_INT
<=
15
)
{
ContentResolver
cr
=
context
.
getContentResolver
();
Cursor
cursor
=
null
;
int
status
=
0
;
for
(
ResolveInfo
screenReader
:
screenReaders
)
{
cursor
=
cr
.
query
(
Uri
.
parse
(
"content://"
+
screenReader
.
serviceInfo
.
packageName
+
".providers.StatusProvider"
),
null
,
null
,
null
,
null
);
if
(
cursor
!=
null
&&
cursor
.
moveToFirst
())
{
status
=
cursor
.
getInt
(
0
);
cursor
.
close
();
// 状态1为开启状态,直接返回true即可
if
(
status
==
1
)
{
return
true
;
}
}
}
}
else
if
(
Build
.
VERSION
.
SDK_INT
>=
26
)
{
// 高版本可以直接判断服务是否处于开启状态
for
(
ResolveInfo
screenReader
:
screenReaders
)
{
hasActiveScreenReader
|=
isAccessibilitySettingsOn
(
context
,
screenReader
.
serviceInfo
.
packageName
+
"/"
+
screenReader
.
serviceInfo
.
name
);
}
}
else
{
// 判断正在运行的Service里有没有上述存在的Service
List
<
String
>
runningServices
=
new
ArrayList
<
String
>();
android
.
app
.
ActivityManager
manager
=
(
android
.
app
.
ActivityManager
)
context
.
getSystemService
(
Context
.
ACTIVITY_SERVICE
);
for
(
android
.
app
.
ActivityManager
.
RunningServiceInfo
service
:
manager
.
getRunningServices
(
Integer
.
MAX_VALUE
))
{
runningServices
.
add
(
service
.
service
.
getPackageName
());
}
for
(
ResolveInfo
screenReader
:
screenReaders
)
{
if
(
runningServices
.
contains
(
screenReader
.
serviceInfo
.
packageName
))
{
hasActiveScreenReader
|=
true
;
}
}
}
return
hasActiveScreenReader
;
}
// To check if service is enabled
private
static
boolean
isAccessibilitySettingsOn
(
Context
context
,
String
service
)
{
TextUtils
.
SimpleStringSplitter
mStringColonSplitter
=
new
TextUtils
.
SimpleStringSplitter
(
':'
);
String
settingValue
=
Settings
.
Secure
.
getString
(
context
.
getApplicationContext
().
getContentResolver
(),
Settings
.
Secure
.
ENABLED_ACCESSIBILITY_SERVICES
);
if
(
settingValue
!=
null
)
{
mStringColonSplitter
.
setString
(
settingValue
);
while
(
mStringColonSplitter
.
hasNext
())
{
String
accessibilityService
=
mStringColonSplitter
.
next
();
if
(
accessibilityService
.
equalsIgnoreCase
(
service
))
{
return
true
;
}
}
}
return
false
;
}
/**
* 判断AccessibilityService服务是否已经启动
*
* @param context
* @param name
* @return
*/
public
static
boolean
isStartAccessibilityService
(
Context
context
,
String
name
)
{
AccessibilityManager
am
=
(
AccessibilityManager
)
context
.
getSystemService
(
Context
.
ACCESSIBILITY_SERVICE
);
List
<
AccessibilityServiceInfo
>
serviceInfos
=
am
.
getEnabledAccessibilityServiceList
(
AccessibilityServiceInfo
.
FEEDBACK_GENERIC
);
for
(
AccessibilityServiceInfo
info
:
serviceInfos
)
{
String
id
=
info
.
getId
();
LogUtil
.
d
(
"all -->"
+
id
);
if
(
id
.
contains
(
name
))
{
return
true
;
}
}
return
false
;
}
}
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