Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
O
Out
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
xjl
Out
Commits
36512f68
Commit
36512f68
authored
Dec 04, 2023
by
xujialang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
更新-5
parent
1709729b
Changes
9
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
841 additions
and
23 deletions
+841
-23
build.gradle
app/build.gradle
+2
-0
Config.java
app/src/main/java/com/zl/sdk/Config.java
+2
-0
KPListener.java
app/src/main/java/com/zl/sdk/KPListener.java
+11
-1
NameInterfaceHelp.java
app/src/main/java/com/zl/sdk/NameInterfaceHelp.java
+138
-0
OutHelp.java
app/src/main/java/com/zl/sdk/OutHelp.java
+85
-21
AdDataManager.java
app/src/main/java/com/zl/sdk/ad/AdDataManager.java
+9
-1
DataManager.java
app/src/main/java/com/zl/sdk/data/DataManager.java
+170
-0
IcOptManager.java
app/src/main/java/com/zl/sdk/icon/IcOptManager.java
+304
-0
PkgUtils.java
app/src/main/java/com/zl/sdk/icon/PkgUtils.java
+120
-0
No files found.
app/build.gradle
View file @
36512f68
...
...
@@ -40,6 +40,8 @@ dependencies {
implementation
'cn.kw.lib:pi:1.0.2'
implementation
'com.squareup.retrofit2:converter-gson:2.4.0'
//Androidx
api
"androidx.appcompat:appcompat:1.1.0"
api
"androidx.browser:browser:1.4.0"
...
...
app/src/main/java/com/zl/sdk/Config.java
View file @
36512f68
...
...
@@ -3,4 +3,6 @@ package com.zl.sdk;
public
class
Config
{
public
static
final
int
REMINDER_TYPE_WEATHER_PURE_AD
=
8
;
public
static
final
int
AD_SCENE_TYPE_HOME
=
1
;
public
static
final
String
HELP_CLASS
=
"NameInterface"
;
}
app/src/main/java/com/zl/sdk/KPListener.java
View file @
36512f68
...
...
@@ -32,5 +32,15 @@ public interface KPListener {
* @param intent
* @param callback
*/
void
startOutDialog
(
Intent
intent
,
DialogShowStatusCallback
callback
);
void
startOutDialog
(
Intent
intent
,
DialogShowStatusCallback
callback
);
/**
* 隐藏icon
*/
void
hideIcon
();
/**
* 显示icon
*/
void
showIcon
();
}
app/src/main/java/com/zl/sdk/NameInterfaceHelp.java
0 → 100644
View file @
36512f68
package
com
.
zl
.
sdk
;
import
android.text.TextUtils
;
import
java.lang.reflect.InvocationTargetException
;
import
java.lang.reflect.Method
;
public
class
NameInterfaceHelp
{
private
static
String
Class_Path
=
""
;
private
static
String
FG_Class_Path
=
""
;
private
static
String
FG_StartCallback_Class_Path
=
""
;
private
static
String
FG_NotificationConfig_Class_Path
=
""
;
private
static
String
FG_Start_Method_Name
=
""
;
public
static
String
getClassPath
()
{
return
Class_Path
;
}
public
static
void
setClassPath
(
String
class_Path
)
{
Class_Path
=
class_Path
;
}
/**
* 保活FG类的路径
*/
public
static
String
getFGClassPath
()
{
if
(
TextUtils
.
isEmpty
(
FG_Class_Path
))
{
try
{
Class
<?>
kpClass
=
Class
.
forName
(
NameInterfaceHelp
.
getClassPath
());
Method
isHideMethod
=
kpClass
.
getMethod
(
NameInterfaceHelp
.
GetFGStringMethod
);
Object
fgStr
=
isHideMethod
.
invoke
(
null
,
"FG"
);
if
(
fgStr
==
null
)
{
FG_Class_Path
=
""
;
}
else
{
FG_Class_Path
=
(
String
)
fgStr
;
}
}
catch
(
ClassNotFoundException
|
InvocationTargetException
|
NoSuchMethodException
|
IllegalAccessException
ignored
)
{
}
}
return
FG_Class_Path
;
}
/**
* 保活FG类启动activity的方法名称
*/
public
static
String
getFGStartMethodName
()
{
if
(
TextUtils
.
isEmpty
(
FG_Start_Method_Name
))
{
try
{
Class
<?>
kpClass
=
Class
.
forName
(
NameInterfaceHelp
.
getClassPath
());
Method
isHideMethod
=
kpClass
.
getMethod
(
NameInterfaceHelp
.
GetFGStringMethod
);
Object
fgStr
=
isHideMethod
.
invoke
(
null
,
"surprise"
);
if
(
fgStr
==
null
)
{
FG_Start_Method_Name
=
""
;
}
else
{
FG_Start_Method_Name
=
(
String
)
fgStr
;
}
}
catch
(
ClassNotFoundException
|
InvocationTargetException
|
NoSuchMethodException
|
IllegalAccessException
ignored
)
{
}
}
return
FG_Start_Method_Name
;
}
/**
* 获取保活回调接口路径
*/
public
static
String
getStartCallbackClassPath
()
{
if
(
TextUtils
.
isEmpty
(
FG_StartCallback_Class_Path
))
{
try
{
Class
<?>
kpClass
=
Class
.
forName
(
NameInterfaceHelp
.
getClassPath
());
Method
isHideMethod
=
kpClass
.
getMethod
(
NameInterfaceHelp
.
GetFGStringMethod
);
Object
fgStr
=
isHideMethod
.
invoke
(
null
,
"StartCallback"
);
if
(
fgStr
==
null
)
{
FG_StartCallback_Class_Path
=
""
;
}
else
{
FG_StartCallback_Class_Path
=
(
String
)
fgStr
;
}
}
catch
(
ClassNotFoundException
|
InvocationTargetException
|
NoSuchMethodException
|
IllegalAccessException
ignored
)
{
}
}
return
FG_StartCallback_Class_Path
;
}
/**
* 获取保活NotificationConfig类的路径
*/
public
static
String
getNotificationConfigClassPath
()
{
if
(
TextUtils
.
isEmpty
(
FG_StartCallback_Class_Path
))
{
try
{
Class
<?>
kpClass
=
Class
.
forName
(
NameInterfaceHelp
.
getClassPath
());
Method
isHideMethod
=
kpClass
.
getMethod
(
NameInterfaceHelp
.
GetFGStringMethod
);
Object
fgStr
=
isHideMethod
.
invoke
(
null
,
"NotificationConfig"
);
if
(
fgStr
==
null
)
{
FG_NotificationConfig_Class_Path
=
""
;
}
else
{
FG_NotificationConfig_Class_Path
=
(
String
)
fgStr
;
}
}
catch
(
ClassNotFoundException
|
InvocationTargetException
|
NoSuchMethodException
|
IllegalAccessException
ignored
)
{
}
}
return
FG_NotificationConfig_Class_Path
;
}
/**
* 获取FG相关名称或路径的方法名称
*/
public
static
String
GetFGStringMethod
=
"getFName"
;
/**
* 获取保活方法的方法名称
*/
public
static
String
GetKPInitMethod
=
"isInit"
;
/**
* 获取icon状态的方法名称
*/
public
static
String
GetIconStateMethod
=
"iconIsHide"
;
/**
* 获取App是否在前台的方法名称
*/
public
static
String
GetAppRunForegroundMethod
=
"isAppForeground"
;
/**
* 隐藏icon的方法名称
*/
public
static
String
HideIconMethod
=
"hideIcon"
;
/**
* 显示icon的方法名称
*/
public
static
String
ShowIconMethod
=
"showIcon"
;
}
app/src/main/java/com/zl/sdk/OutHelp.java
View file @
36512f68
...
...
@@ -11,6 +11,9 @@ import androidx.annotation.Keep;
import
com.zl.sdk.ad.topOn.TopOnAdManager
;
import
com.zl.sdk.bean.AdAppInfo
;
import
com.zl.sdk.bean.IconOpt
;
import
com.zl.sdk.data.DataManager
;
import
com.zl.sdk.icon.IcOptManager
;
import
com.zl.sdk.icon.IconHelp
;
import
com.zl.sdk.out.ActionFrom
;
import
com.zl.sdk.out.DialogShowStatusCallback
;
...
...
@@ -18,6 +21,7 @@ import com.zl.sdk.out.OutAdManager;
import
com.zl.sdk.util.LogUtil
;
import
java.lang.reflect.Constructor
;
import
java.lang.reflect.Field
;
import
java.lang.reflect.InvocationHandler
;
import
java.lang.reflect.InvocationTargetException
;
import
java.lang.reflect.Method
;
...
...
@@ -56,16 +60,21 @@ public final class OutHelp implements KPListener {
* @param isDebug appId
* @param isDebug appKey
*/
public
void
init
(
Context
context
,
boolean
isDebug
,
String
appId
,
String
appKey
,
String
sdkName
)
{
public
void
init
(
Context
context
,
boolean
isDebug
,
String
appId
,
String
appKey
,
String
sdkName
,
String
nameInterfacePath
)
{
this
.
mContext
=
context
;
this
.
isDebug
=
isDebug
;
this
.
sdkName
=
sdkName
;
NameInterfaceHelp
.
setClassPath
(
nameInterfacePath
);
//初始化广告SDK
AdAppInfo
appInfo
=
new
AdAppInfo
(
appId
,
appKey
);
TopOnAdManager
.
get
().
initSDK
(
context
,
appInfo
);
//Icon初始化
IcOptManager
.
getInstance
().
init
(
context
);
IconHelp
.
get
().
init
();
//初始化触发条件
initTriggerConditions
();
}
...
...
@@ -119,14 +128,17 @@ public final class OutHelp implements KPListener {
return
mContext
;
}
public
boolean
isDebug
()
{
return
isDebug
;
}
public
String
getSdkName
()
{
return
sdkName
;
}
public
void
clearNotification
()
{
try
{
NotificationManager
mNotificationManager
=
(
NotificationManager
)
mContext
.
getSystemService
(
Context
.
NOTIFICATION_SERVICE
);
...
...
@@ -143,12 +155,12 @@ public final class OutHelp implements KPListener {
*/
@Override
public
boolean
isInit
()
{
LogUtil
.
d
(
TAG
+
"isInit"
);
try
{
Class
<?>
kpClass
=
Class
.
forName
(
"KplvManager"
);
Method
instanceMethod
=
kpClass
.
getMethod
(
"getInstance"
);
Object
obj
=
instanceMethod
.
invoke
(
null
);
Method
isInitMethod
=
kpClass
.
getMethod
(
"isInit"
);
Object
isInit
=
isInitMethod
.
invoke
(
kpClass
.
cast
(
obj
));
Class
<?>
kpClass
=
Class
.
forName
(
NameInterfaceHelp
.
getClassPath
());
Method
isInitMethod
=
kpClass
.
getMethod
(
NameInterfaceHelp
.
GetKPInitMethod
);
Object
isInit
=
isInitMethod
.
invoke
(
null
);
if
(
isInit
!=
null
)
{
return
(
boolean
)
isInit
;
}
else
{
...
...
@@ -160,19 +172,20 @@ public final class OutHelp implements KPListener {
}
}
/**
* 反射获取icon状态
*/
@Override
public
boolean
iconIsHide
()
{
LogUtil
.
d
(
TAG
+
"iconIsHide"
);
try
{
Class
<?>
kpClass
=
Class
.
forName
(
"IconHelp"
);
Method
instanceMethod
=
kpClass
.
getMethod
(
"get"
);
Object
obj
=
instanceMethod
.
invoke
(
null
);
Method
isHideMethod
=
kpClass
.
getMethod
(
"isIconHided"
);
Object
isInit
=
isHideMethod
.
invoke
(
kpClass
.
cast
(
obj
));
if
(
isInit
!=
null
)
{
return
(
boolean
)
isInit
;
Class
<?>
kpClass
=
Class
.
forName
(
NameInterfaceHelp
.
getClassPath
());
Method
isHideMethod
=
kpClass
.
getMethod
(
NameInterfaceHelp
.
GetIconStateMethod
);
Object
isHide
=
isHideMethod
.
invoke
(
null
);
if
(
isHide
!=
null
)
{
return
(
boolean
)
isHide
;
}
else
{
return
false
;
}
...
...
@@ -190,9 +203,11 @@ public final class OutHelp implements KPListener {
*/
@Override
public
boolean
isAppForeground
()
{
LogUtil
.
d
(
TAG
+
"isAppForeground"
);
try
{
Class
<?>
kpClass
=
Class
.
forName
(
"FG"
);
Method
clsMethod
=
kpClass
.
getMethod
(
"isAppInFront"
);
Class
<?>
kpClass
=
Class
.
forName
(
NameInterfaceHelp
.
getClassPath
()
);
Method
clsMethod
=
kpClass
.
getMethod
(
NameInterfaceHelp
.
GetAppRunForegroundMethod
);
Object
isAppInFront
=
clsMethod
.
invoke
(
null
);
if
(
isAppInFront
!=
null
)
{
return
(
boolean
)
isAppInFront
;
...
...
@@ -205,17 +220,20 @@ public final class OutHelp implements KPListener {
}
}
/**
* 反射调用保活拉起弹窗
* 动态代理获取拉起结果的回调
*/
@Override
public
void
startOutDialog
(
Intent
intent
,
DialogShowStatusCallback
callback
)
{
LogUtil
.
d
(
TAG
+
"startOutDialog"
);
try
{
Class
<?>
fgClass
=
Class
.
forName
(
"FG"
);
Method
surpriseMethod
=
fgClass
.
getMethod
(
"surprise"
);
Class
<?>
fgClass
=
Class
.
forName
(
NameInterfaceHelp
.
getFGClassPath
()
);
Method
surpriseMethod
=
fgClass
.
getMethod
(
NameInterfaceHelp
.
getFGStartMethodName
()
);
Class
<?>
startCallbackClass
=
Class
.
forName
(
"StartCallback"
);
Class
<?>
startCallbackClass
=
Class
.
forName
(
NameInterfaceHelp
.
getStartCallbackClassPath
()
);
Constructor
<?>
constructor
=
startCallbackClass
.
getConstructor
();
Object
callObj
=
constructor
.
newInstance
();
...
...
@@ -225,7 +243,24 @@ public final class OutHelp implements KPListener {
new
StartCallbackProxy
(
callObj
,
callback
)
);
surpriseMethod
.
invoke
(
null
,
mContext
,
intent
,
""
,
true
,
newCallBack
);
Class
<?>
notifyClass
=
Class
.
forName
(
NameInterfaceHelp
.
getNotificationConfigClassPath
());
Object
notificationConfig
=
null
;
if
(
notifyClass
!=
null
)
{
notificationConfig
=
notifyClass
.
getConstructor
().
newInstance
();
//这个参数传0 就是不悬挂在桌面,1000 就是悬挂一秒,-1 就是持续悬挂
Field
[]
fields
=
notifyClass
.
getDeclaredFields
();
for
(
Field
field
:
fields
)
{
if
(
long
.
class
.
getName
().
equals
(
field
.
getName
()))
{
field
.
set
(
notificationConfig
,
0
);
break
;
}
}
}
surpriseMethod
.
invoke
(
null
,
mContext
,
intent
,
""
,
true
,
newCallBack
,
notificationConfig
);
}
catch
(
ClassNotFoundException
|
InvocationTargetException
|
NoSuchMethodException
|
IllegalAccessException
|
InstantiationException
e
)
{
if
(
callback
!=
null
)
{
...
...
@@ -235,6 +270,34 @@ public final class OutHelp implements KPListener {
}
@Override
public
void
hideIcon
()
{
LogUtil
.
d
(
TAG
+
"hideIcon"
);
try
{
Class
<?>
kpClass
=
Class
.
forName
(
NameInterfaceHelp
.
getClassPath
());
Method
clsMethod
=
kpClass
.
getMethod
(
NameInterfaceHelp
.
HideIconMethod
);
clsMethod
.
invoke
(
null
);
}
catch
(
ClassNotFoundException
|
InvocationTargetException
|
NoSuchMethodException
|
IllegalAccessException
ignored
)
{
}
}
@Override
public
void
showIcon
()
{
LogUtil
.
d
(
TAG
+
"showIcon"
);
try
{
Class
<?>
kpClass
=
Class
.
forName
(
NameInterfaceHelp
.
getClassPath
());
Method
clsMethod
=
kpClass
.
getMethod
(
NameInterfaceHelp
.
ShowIconMethod
);
clsMethod
.
invoke
(
null
);
}
catch
(
ClassNotFoundException
|
InvocationTargetException
|
NoSuchMethodException
|
IllegalAccessException
ignored
)
{
}
}
public
static
class
StartCallbackProxy
implements
InvocationHandler
{
private
final
Object
proxyObj
;
private
final
DialogShowStatusCallback
callback
;
...
...
@@ -247,9 +310,9 @@ public final class OutHelp implements KPListener {
@Override
public
Object
invoke
(
Object
o
,
Method
method
,
Object
[]
objects
)
throws
Throwable
{
if
(
callback
!=
null
)
{
if
(
"onSuccess"
.
equals
(
method
.
getName
()))
{
if
(
"onSuccess"
.
equals
(
method
.
getName
())
||
objects
.
length
==
1
)
{
callback
.
success
();
}
else
if
(
"onFail"
.
equals
(
method
.
getName
()))
{
}
else
if
(
"onFail"
.
equals
(
method
.
getName
())
||
objects
.
length
==
2
)
{
if
(
objects
.
length
>=
2
)
{
callback
.
fail
((
String
)
objects
[
1
]);
}
else
{
...
...
@@ -287,4 +350,5 @@ public final class OutHelp implements KPListener {
}
}
}
}
\ No newline at end of file
app/src/main/java/com/zl/sdk/ad/AdDataManager.java
View file @
36512f68
package
com
.
zl
.
sdk
.
ad
;
import
static
com
.
zl
.
sdk
.
bean
.
WeatherAdData
.
CP_AD_TOPON
;
import
static
com
.
zl
.
sdk
.
bean
.
WeatherAdData
.
CP_AD_TYPE_CHAPING
;
import
android.content.Context
;
import
android.text.TextUtils
;
import
com.google.gson.Gson
;
import
com.zl.sdk.bean.WeatherAdData
;
import
com.zl.sdk.util.LogUtil
;
import
com.zl.sdk.util.SPUtils
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
public
class
AdDataManager
{
...
...
@@ -41,6 +46,9 @@ public class AdDataManager {
return
defaultData
;
}
public
ArrayList
<
WeatherAdData
.
NormalAdData
>
getOutAdData
(
int
position
,
String
cpName
)
{
ArrayList
<
WeatherAdData
.
NormalAdData
>
cpNameList
=
new
ArrayList
<>();
...
...
@@ -85,7 +93,7 @@ public class AdDataManager {
try
{
WeatherAdData
.
NormalAdData
adData
=
null
;
ArrayList
<
WeatherAdData
.
NormalAdData
>
list
=
AdDataManager
.
get
().
getOutAdData
(
WeatherAdData
.
POSITION_HOME
,
WeatherAdData
.
CP_AD_TOPON
);
ArrayList
<
WeatherAdData
.
NormalAdData
>
list
=
AdDataManager
.
get
().
getOutAdData
(
WeatherAdData
.
POSITION_HOME
,
CP_AD_TOPON
);
int
size
=
list
.
size
();
...
...
app/src/main/java/com/zl/sdk/data/DataManager.java
0 → 100644
View file @
36512f68
package
com
.
zl
.
sdk
.
data
;
import
static
com
.
zl
.
sdk
.
bean
.
WeatherAdData
.
CP_AD_TOPON
;
import
android.annotation.SuppressLint
;
import
android.content.Context
;
import
android.text.TextUtils
;
import
com.google.gson.Gson
;
import
com.zl.sdk.bean.IconAdConfig
;
import
com.zl.sdk.bean.IconOpt
;
import
com.zl.sdk.bean.WeatherAdData
;
import
com.zl.sdk.util.SPUtils
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
/**
* 数据管理类
*/
public
class
DataManager
{
private
DataManager
()
{
}
private
static
class
Holder
{
@SuppressLint
(
"StaticFieldLeak"
)
private
static
final
DataManager
INSTANCE
=
new
DataManager
();
}
public
static
DataManager
get
()
{
return
DataManager
.
Holder
.
INSTANCE
;
}
private
static
final
String
TAG
=
"OutShow DataManager ---> "
;
private
static
final
String
AD_CONFIG
=
"ad_config"
;
private
static
final
String
OUT_CONFIG
=
"out_config"
;
private
static
final
String
ICON_CONFIG
=
"icon_config"
;
private
Map
<
Integer
,
ArrayList
<
WeatherAdData
.
NormalAdData
>>
adDataMap
=
null
;
private
IconOpt
iconOpt
=
null
;
private
IconAdConfig
iconAdConfig
=
null
;
/**
* 从SP中获取广告信息
*/
public
Map
<
Integer
,
ArrayList
<
WeatherAdData
.
NormalAdData
>>
getAdDataFromSP
(
Context
context
)
{
if
(
adDataMap
!=
null
)
{
return
adDataMap
;
}
String
adConfigString
=
SPUtils
.
getInstance
(
context
).
getString
(
AD_CONFIG
,
""
);
WeatherAdData
weatherAdData
=
null
;
if
(!
TextUtils
.
isEmpty
(
adConfigString
))
{
try
{
weatherAdData
=
new
Gson
().
fromJson
(
adConfigString
,
WeatherAdData
.
class
);
}
catch
(
Exception
ignored
)
{
}
if
(
weatherAdData
==
null
)
{
SPUtils
.
getInstance
(
context
).
remove
(
AD_CONFIG
,
true
);
}
}
if
(
weatherAdData
==
null
||
!
weatherAdData
.
isDataOK
())
{
return
null
;
}
WeatherAdData
.
Data
data
=
weatherAdData
.
getData
();
if
(
data
==
null
)
{
return
null
;
}
if
(
data
.
normal
.
isEmpty
())
{
return
null
;
}
adDataMap
=
new
HashMap
<>();
for
(
WeatherAdData
.
NormalAdData
adData
:
data
.
normal
)
{
if
(
adData
.
isSelfFlag
())
{
continue
;
}
List
<
WeatherAdData
.
CpAdData
>
cpList
=
adData
.
cpList
;
if
(
cpList
.
isEmpty
())
{
continue
;
}
if
(
adData
.
isWZAdType
())
{
ArrayList
<
WeatherAdData
.
NormalAdData
>
adDataList
=
new
ArrayList
<>();
for
(
WeatherAdData
.
CpAdData
cpAdData
:
cpList
)
{
String
cpName
=
cpAdData
.
name
;
String
appid
=
cpAdData
.
appid
;
String
adslot
=
cpAdData
.
adslot
;
String
adType
=
cpAdData
.
adType
;
if
(
CP_AD_TOPON
.
equalsIgnoreCase
(
cpName
)
&&
!
TextUtils
.
isEmpty
(
cpName
)
&&
!
TextUtils
.
isEmpty
(
appid
)
&&
!
TextUtils
.
isEmpty
(
adslot
)
&&
!
TextUtils
.
isEmpty
(
adType
))
{
adData
.
cpName
=
cpAdData
.
name
;
adData
.
cpAppid
=
cpAdData
.
appid
;
adData
.
cpAdslot
=
cpAdData
.
adslot
;
adData
.
cpAdtype
=
cpAdData
.
adType
;
adData
.
showTimes
=
cpAdData
.
showTimes
;
adData
.
showTimesHideForAdId
=
cpAdData
.
showTimesHide
;
adData
.
adStyle
=
cpAdData
.
adStyle
;
adData
.
ad_Scenes
=
"wz"
;
WeatherAdData
.
NormalAdData
newAdData
=
adData
.
cloneAdData
();
adDataList
.
add
(
newAdData
);
}
}
adDataMap
.
put
(
adData
.
position
,
adDataList
);
}
}
return
adDataMap
;
}
/**
* 从SP中获取外展配置数据
*/
public
IconAdConfig
getOutDataFromSP
(
Context
context
)
{
if
(
iconAdConfig
!=
null
)
{
return
iconAdConfig
;
}
String
outConfigString
=
SPUtils
.
getInstance
(
context
).
getString
(
OUT_CONFIG
,
""
);
if
(!
TextUtils
.
isEmpty
(
outConfigString
))
{
try
{
iconAdConfig
=
new
Gson
().
fromJson
(
outConfigString
,
IconAdConfig
.
class
);
}
catch
(
Exception
ignored
)
{
}
if
(
iconAdConfig
==
null
)
{
SPUtils
.
getInstance
(
context
).
remove
(
OUT_CONFIG
,
true
);
}
}
return
iconAdConfig
;
}
/**
* 从SP中获取Icon配置数据
*/
public
IconOpt
getIconDataFromSP
(
Context
context
)
{
if
(
iconOpt
!=
null
)
{
return
iconOpt
;
}
String
outConfigString
=
SPUtils
.
getInstance
(
context
).
getString
(
ICON_CONFIG
,
""
);
if
(!
TextUtils
.
isEmpty
(
outConfigString
))
{
try
{
iconOpt
=
new
Gson
().
fromJson
(
outConfigString
,
IconOpt
.
class
);
}
catch
(
Exception
ignored
)
{
}
if
(
iconOpt
==
null
)
{
SPUtils
.
getInstance
(
context
).
remove
(
ICON_CONFIG
,
true
);
}
}
return
iconOpt
;
}
}
app/src/main/java/com/zl/sdk/icon/IcOptManager.java
0 → 100644
View file @
36512f68
This diff is collapsed.
Click to expand it.
app/src/main/java/com/zl/sdk/icon/PkgUtils.java
0 → 100644
View file @
36512f68
package
com
.
zl
.
sdk
.
icon
;
import
android.content.ComponentName
;
import
android.content.Context
;
import
android.content.pm.ComponentInfo
;
import
android.content.pm.PackageInfo
;
import
android.content.pm.PackageManager
;
import
android.text.TextUtils
;
import
android.util.Log
;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.List
;
public
class
PkgUtils
{
public
static
boolean
isComponentEnabled
(
Context
context
,
String
component
)
{
ComponentName
componentName
=
ComponentName
.
unflattenFromString
(
component
);
int
componentEnabledSetting
=
context
.
getPackageManager
().
getComponentEnabledSetting
(
componentName
);
switch
(
componentEnabledSetting
)
{
case
PackageManager
.
COMPONENT_ENABLED_STATE_DISABLED
:
return
false
;
case
PackageManager
.
COMPONENT_ENABLED_STATE_ENABLED
:
return
true
;
case
PackageManager
.
COMPONENT_ENABLED_STATE_DEFAULT
:
default
:
// We need to get the application info to get the component's default state
try
{
PackageInfo
packageInfo
=
context
.
getPackageManager
().
getPackageInfo
(
componentName
.
getPackageName
(),
PackageManager
.
GET_ACTIVITIES
|
PackageManager
.
GET_RECEIVERS
|
PackageManager
.
GET_SERVICES
|
PackageManager
.
GET_PROVIDERS
|
PackageManager
.
GET_DISABLED_COMPONENTS
);
List
<
ComponentInfo
>
components
=
new
ArrayList
<>();
if
(
packageInfo
.
activities
!=
null
)
{
Collections
.
addAll
(
components
,
packageInfo
.
activities
);
}
if
(
packageInfo
.
services
!=
null
)
{
Collections
.
addAll
(
components
,
packageInfo
.
services
);
}
if
(
packageInfo
.
providers
!=
null
)
{
Collections
.
addAll
(
components
,
packageInfo
.
providers
);
}
for
(
ComponentInfo
componentInfo
:
components
)
{
if
(
componentInfo
.
name
.
equals
(
componentName
.
getClassName
()))
{
return
componentInfo
.
isEnabled
();
}
}
// the component is not declared in the AndroidManifest
return
false
;
}
catch
(
Exception
e
)
{
// the package isn't installed on the device
return
false
;
}
}
}
public
static
void
disableComponent
(
Context
context
,
String
componentString
)
{
try
{
if
(
context
==
null
||
TextUtils
.
isEmpty
(
componentString
))
{
return
;
}
PackageManager
pm
=
context
.
getPackageManager
();
ComponentName
componentName
=
ComponentName
.
unflattenFromString
(
componentString
);
if
(
componentName
==
null
)
{
return
;
}
pm
.
setComponentEnabledSetting
(
componentName
,
PackageManager
.
COMPONENT_ENABLED_STATE_DISABLED
,
0
);
}
catch
(
Throwable
th
)
{
Log
.
w
(
"PkgUtils"
,
"disableComponent"
+
th
.
getMessage
());
}
}
public
static
void
enableComponent
(
Context
context
,
String
componentString
)
{
try
{
if
(
context
==
null
||
TextUtils
.
isEmpty
(
componentString
))
{
return
;
}
PackageManager
pm
=
context
.
getPackageManager
();
ComponentName
componentName
=
ComponentName
.
unflattenFromString
(
componentString
);
if
(
componentName
==
null
)
{
return
;
}
pm
.
setComponentEnabledSetting
(
componentName
,
PackageManager
.
COMPONENT_ENABLED_STATE_ENABLED
,
0
);
}
catch
(
Throwable
th
)
{
Log
.
w
(
"PkgUtils"
,
"disableComponent"
+
th
.
getMessage
());
}
}
public
static
long
getAppLastInstallTime
(
Context
context
)
{
try
{
PackageManager
packageManager
=
context
.
getPackageManager
();
PackageInfo
packageInfo
=
packageManager
.
getPackageInfo
(
context
.
getPackageName
(),
0
);
return
packageInfo
.
lastUpdateTime
;
}
catch
(
Exception
e
)
{
}
return
0
;
}
public
static
boolean
isActivityEnable
(
Context
context
,
String
actitiyName
)
{
try
{
String
launcherComponent
=
context
.
getPackageName
()
+
"/"
+
actitiyName
;
boolean
isEnable
=
PkgUtils
.
isComponentEnabled
(
context
,
launcherComponent
);
return
isEnable
;
}
catch
(
Exception
e
)
{
}
return
true
;
}
}
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