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
7d7cbafb
Commit
7d7cbafb
authored
Dec 19, 2023
by
xujialang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加广播回调的动态代理
parent
30f3e9c9
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
177 additions
and
70 deletions
+177
-70
NameInterfaceHelp.java
app/src/main/java/com/zl/sdk/NameInterfaceHelp.java
+53
-0
OutHelp.java
app/src/main/java/com/zl/sdk/OutHelp.java
+121
-69
EventUtils.java
app/src/main/java/com/zl/sdk/event/EventUtils.java
+2
-0
OutAdManager.java
app/src/main/java/com/zl/sdk/out/OutAdManager.java
+1
-1
No files found.
app/src/main/java/com/zl/sdk/NameInterfaceHelp.java
View file @
7d7cbafb
...
...
@@ -12,6 +12,7 @@ public class NameInterfaceHelp {
private
static
String
FG_Class_Path
=
""
;
private
static
String
FG_StartCallback_Class_Path
=
""
;
private
static
String
FG_NotificationConfig_Class_Path
=
""
;
private
static
String
Action_Listener_Class_Path
=
""
;
private
static
String
FG_Start_Method_Name
=
""
;
public
static
String
getClassPath
()
{
...
...
@@ -126,6 +127,31 @@ public class NameInterfaceHelp {
return
FG_NotificationConfig_Class_Path
;
}
/**
* 获取ActionListener类的路径
*/
public
static
String
getActionListenerClassPath
()
{
if
(
TextUtils
.
isEmpty
(
Action_Listener_Class_Path
))
{
try
{
Class
<?>
kpClass
=
Class
.
forName
(
NameInterfaceHelp
.
getClassPath
());
Method
fNameMethod
=
kpClass
.
getMethod
(
NameInterfaceHelp
.
GetFGStringMethod
,
String
.
class
);
Object
fgStr
=
fNameMethod
.
invoke
(
null
,
"ActionListener"
);
if
(
fgStr
==
null
)
{
Action_Listener_Class_Path
=
""
;
}
else
{
Action_Listener_Class_Path
=
(
String
)
fgStr
;
}
}
catch
(
ClassNotFoundException
|
InvocationTargetException
|
NoSuchMethodException
|
IllegalAccessException
ignored
)
{
LogUtil
.
d
(
"OutShow 反射获取 getActionListenerClassPath (catch) "
+
ignored
);
}
}
LogUtil
.
d
(
"OutShow getActionListenerClassPath="
+
Action_Listener_Class_Path
);
return
Action_Listener_Class_Path
;
}
public
static
Object
getNewCallBack
()
{
try
{
Class
<?>
kpClass
=
Class
.
forName
(
NameInterfaceHelp
.
getClassPath
());
...
...
@@ -141,13 +167,40 @@ public class NameInterfaceHelp {
}
public
static
Object
getActionListener
()
{
try
{
Class
<?>
kpClass
=
Class
.
forName
(
NameInterfaceHelp
.
getClassPath
());
Method
callBackMethod
=
kpClass
.
getMethod
(
NameInterfaceHelp
.
GetActionListenerMethod
);
return
callBackMethod
.
invoke
(
null
);
}
catch
(
ClassNotFoundException
|
InvocationTargetException
|
NoSuchMethodException
|
IllegalAccessException
ignored
)
{
LogUtil
.
d
(
"OutShow 反射获取 getActionListener (catch) "
+
ignored
);
}
return
null
;
}
/**
* 获取FG相关名称或路径的方法名称
*/
public
static
String
GetFGStringMethod
=
"getFName"
;
/**
* 拉起弹窗的回调实例的方法名称
*/
public
static
String
GetNewCallBackMethod
=
"getNewCallBack"
;
/**
* 接收广播的回调实例的方法名称
*/
public
static
String
GetActionListenerMethod
=
"getActionListener"
;
/**
* 添加广告回调的方法名称
*/
public
static
String
RegisterActionMethod
=
"registerAction"
;
/**
* 获取保活方法的方法名称
*/
...
...
app/src/main/java/com/zl/sdk/OutHelp.java
View file @
7d7cbafb
...
...
@@ -29,8 +29,6 @@ import java.lang.reflect.InvocationHandler;
import
java.lang.reflect.InvocationTargetException
;
import
java.lang.reflect.Method
;
import
java.lang.reflect.Proxy
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.Timer
;
import
java.util.TimerTask
;
...
...
@@ -117,8 +115,9 @@ public final class OutHelp implements KPListener {
private
void
initTriggerConditions
()
{
// initTimer();
initReceiver
();
//
initReceiver();
registerActivityLifecycle
();
registerAction
();
}
private
Timer
timer
;
...
...
@@ -169,13 +168,102 @@ public final class OutHelp implements KPListener {
try
{
Application
application
=
(
Application
)
mContext
;
application
.
registerActivityLifecycleCallbacks
(
mLifecycleCallbacks
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
ignored
)
{
}
}
private
void
registerAction
()
{
try
{
LogUtil
.
d
(
TAG
+
"registerAction"
);
Object
listener
=
NameInterfaceHelp
.
getActionListener
();
LogUtil
.
d
(
TAG
+
"registerAction listener ="
+
listener
.
getClass
().
getName
());
Class
<?>
listenerClass
=
Class
.
forName
(
NameInterfaceHelp
.
getActionListenerClassPath
());
LogUtil
.
d
(
TAG
+
"registerAction listenerClass ="
+
listenerClass
.
getName
());
LogUtil
.
d
(
TAG
+
"registerAction 动态代理"
);
Object
listenerProxy
=
Proxy
.
newProxyInstance
(
listenerClass
.
getClassLoader
(),
new
Class
[]{
listenerClass
},
new
ActionListenerProxy
(
listener
)
);
Class
<?>
kpClass
=
Class
.
forName
(
NameInterfaceHelp
.
getClassPath
());
LogUtil
.
d
(
TAG
+
"registerAction kpClass ="
+
kpClass
.
getName
());
Method
registerMethod
=
kpClass
.
getMethod
(
NameInterfaceHelp
.
RegisterActionMethod
,
listenerClass
);
LogUtil
.
d
(
TAG
+
"registerAction registerMethod ="
+
registerMethod
.
getName
());
registerMethod
.
invoke
(
null
,
listenerProxy
);
}
catch
(
ClassNotFoundException
|
InvocationTargetException
|
NoSuchMethodException
|
IllegalAccessException
e
)
{
LogUtil
.
d
(
TAG
+
"registerAction:(catch)"
+
e
);
//注册广播回调方法失败,手动注册
initReceiver
();
}
}
/**
* 接收到了广播
*
* @param actionName 广播名称
*/
public
void
receiverAction
(
String
actionName
)
{
if
(!
DataManager
.
get
().
checkOutOpen
(
mContext
))
{
Statistics
.
getInstance
().
dotEvent
(
"out_close"
);
LogUtil
.
d
(
TAG
+
"外展未开启,不接收广播"
);
return
;
}
Statistics
.
getInstance
().
dotEvent
(
"out_open"
);
switch
(
actionName
)
{
case
Intent
.
ACTION_USER_PRESENT
:
{
LogUtil
.
d
(
TAG
+
"广播===>>> 解锁"
);
showOutAd
(
ActionFrom
.
ACTION_USER_PRESENT
);
break
;
}
case
Intent
.
ACTION_SCREEN_ON
:
{
LogUtil
.
d
(
TAG
+
"广播===>>> 亮屏"
);
showOutAd
(
ActionFrom
.
ACTION_SCREEN_ON
);
break
;
}
case
Intent
.
ACTION_CLOSE_SYSTEM_DIALOGS
:
{
LogUtil
.
d
(
TAG
+
"广播===>>> 桌面"
);
showOutAd
(
ActionFrom
.
ACTION_CLOSE_SYSTEM_DIALOGS
);
break
;
}
case
Intent
.
ACTION_BATTERY_CHANGED
:
{
LogUtil
.
d
(
TAG
+
"广播===>>> Battery"
);
showOutAd
(
ActionFrom
.
ACTION_BATTERY_CHANGED
);
break
;
}
case
Intent
.
ACTION_PACKAGE_RESTARTED
:
{
LogUtil
.
d
(
TAG
+
"广播===>>> Package"
);
showOutAd
(
ActionFrom
.
ACTION_PACKAGE_RESTARTED
);
break
;
}
case
Intent
.
ACTION_TIME_TICK
:
{
LogUtil
.
d
(
TAG
+
"广播===>>> 计时器"
);
showOutAd
(
ActionFrom
.
ACTION_TIMER
);
//检测icon状态
IcOptManager
.
getInstance
().
cycleCheckHideIcon
();
break
;
}
default
:
{
LogUtil
.
d
(
TAG
+
"广播===>>> other action="
+
actionName
);
showOutAd
(
ActionFrom
.
ACTION_OTHER
);
}
}
}
/**
* 进入外展广告播放逻辑(
解锁
)
* 进入外展广告播放逻辑(
广播
)
*
* @param actionFrom 动作来源
*/
...
...
@@ -238,22 +326,18 @@ public final class OutHelp implements KPListener {
*/
@Override
public
boolean
isInit
()
{
LogUtil
.
d
(
TAG
+
"获取保活 isInit"
);
try
{
Class
<?>
kpClass
=
Class
.
forName
(
NameInterfaceHelp
.
getClassPath
());
Method
isInitMethod
=
kpClass
.
getMethod
(
NameInterfaceHelp
.
GetKPInitMethod
);
Object
isInit
=
isInitMethod
.
invoke
(
null
);
if
(
isInit
!=
null
)
{
LogUtil
.
d
(
TAG
+
"获取保活: isInit="
+
isInit
);
return
(
boolean
)
isInit
;
}
else
{
LogUtil
.
d
(
TAG
+
"获取保活:(null) isInit=false"
);
return
false
;
}
}
catch
(
ClassNotFoundException
|
InvocationTargetException
|
NoSuchMethodException
|
IllegalAccessException
e
)
{
LogUtil
.
d
(
TAG
+
"获取保活:(catch)
isInit=false"
);
LogUtil
.
d
(
TAG
+
"获取保活:(catch)
"
+
e
.
getMessage
()
);
return
false
;
}
}
...
...
@@ -264,22 +348,18 @@ public final class OutHelp implements KPListener {
*/
@Override
public
boolean
iconIsHide
()
{
LogUtil
.
d
(
TAG
+
"获取icon状态:iconIsHide"
);
try
{
Class
<?>
kpClass
=
Class
.
forName
(
NameInterfaceHelp
.
getClassPath
());
Method
isHideMethod
=
kpClass
.
getMethod
(
NameInterfaceHelp
.
GetIconStateMethod
);
Object
isHide
=
isHideMethod
.
invoke
(
null
);
if
(
isHide
!=
null
)
{
LogUtil
.
d
(
TAG
+
"获取icon状态: isHide="
+
isHide
);
return
(
boolean
)
isHide
;
}
else
{
LogUtil
.
d
(
TAG
+
"获取icon状态:(null) isHide=false"
);
return
false
;
}
}
catch
(
ClassNotFoundException
|
InvocationTargetException
|
NoSuchMethodException
|
IllegalAccessException
e
)
{
LogUtil
.
d
(
TAG
+
"获取icon状态:(catch)
isHide=false"
);
LogUtil
.
d
(
TAG
+
"获取icon状态:(catch)
e="
+
e
.
getMessage
()
);
return
false
;
}
}
...
...
@@ -292,22 +372,18 @@ public final class OutHelp implements KPListener {
*/
@Override
public
boolean
isAppForeground
()
{
LogUtil
.
d
(
TAG
+
"获取前后台:isAppForeground"
);
try
{
Class
<?>
kpClass
=
Class
.
forName
(
NameInterfaceHelp
.
getClassPath
());
Method
clsMethod
=
kpClass
.
getMethod
(
NameInterfaceHelp
.
GetAppRunForegroundMethod
);
Object
isAppInFront
=
clsMethod
.
invoke
(
null
);
if
(
isAppInFront
!=
null
)
{
LogUtil
.
d
(
TAG
+
"获取前后台: isAppInFront="
+
isAppInFront
);
return
(
boolean
)
isAppInFront
;
}
else
{
LogUtil
.
d
(
TAG
+
"获取前后台:(null) isAppInFront=false"
);
return
false
;
}
}
catch
(
ClassNotFoundException
|
InvocationTargetException
|
NoSuchMethodException
|
IllegalAccessException
e
)
{
LogUtil
.
d
(
TAG
+
"获取前后台:(catch)
isAppInFront=false"
);
LogUtil
.
d
(
TAG
+
"获取前后台:(catch)
e="
+
e
.
getMessage
()
);
return
false
;
}
}
...
...
@@ -323,11 +399,8 @@ public final class OutHelp implements KPListener {
try
{
String
fgPath
=
NameInterfaceHelp
.
getFGClassPath
();
LogUtil
.
d
(
TAG
+
"拉起外展 fgPath="
+
fgPath
);
Class
<?>
fgClass
=
Class
.
forName
(
fgPath
);
if
(
fgClass
==
null
)
{
LogUtil
.
d
(
TAG
+
"拉起外展 fgClass=null"
);
callback
.
fail
(
"fgClass=null"
);
return
;
}
...
...
@@ -335,7 +408,6 @@ public final class OutHelp implements KPListener {
Class
<?>
startCallbackClass
=
Class
.
forName
(
NameInterfaceHelp
.
getStartCallbackClassPath
());
if
(
startCallbackClass
==
null
)
{
LogUtil
.
d
(
TAG
+
"拉起外展 startCallbackClass=null"
);
callback
.
fail
(
"startCallbackClass=null"
);
return
;
}
...
...
@@ -369,7 +441,6 @@ public final class OutHelp implements KPListener {
if
(
surpriseMethod
==
null
)
{
LogUtil
.
d
(
TAG
+
"拉起外展 surpriseMethod=null"
);
callback
.
fail
(
"surpriseMethod=null"
);
return
;
}
...
...
@@ -386,9 +457,9 @@ public final class OutHelp implements KPListener {
}
catch
(
ClassNotFoundException
|
InvocationTargetException
|
NoSuchMethodException
|
IllegalAccessException
|
InstantiationException
e
)
{
LogUtil
.
d
(
TAG
+
"拉起外展:(catch)
fail
="
+
e
.
getMessage
());
LogUtil
.
d
(
TAG
+
"拉起外展:(catch)
e
="
+
e
.
getMessage
());
if
(
callback
!=
null
)
{
callback
.
fail
(
"执行失败"
);
callback
.
fail
(
"执行失败
catch
"
);
}
}
}
...
...
@@ -396,8 +467,6 @@ 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
);
...
...
@@ -411,8 +480,6 @@ public final class OutHelp implements KPListener {
@Override
public
void
showIcon
()
{
LogUtil
.
d
(
TAG
+
"showIcon"
);
try
{
Class
<?>
kpClass
=
Class
.
forName
(
NameInterfaceHelp
.
getClassPath
());
Method
clsMethod
=
kpClass
.
getMethod
(
NameInterfaceHelp
.
ShowIconMethod
);
...
...
@@ -468,6 +535,28 @@ public final class OutHelp implements KPListener {
}
}
/**
* 动态代理广播回调方法
*/
public
static
class
ActionListenerProxy
implements
InvocationHandler
{
private
Object
proxyObj
;
public
ActionListenerProxy
(
Object
obj
)
{
this
.
proxyObj
=
obj
;
}
@Override
public
Object
invoke
(
Object
o
,
Method
method
,
Object
[]
objects
)
throws
Throwable
{
if
(
"onReceiverAction"
.
equals
(
method
.
getName
()))
{
String
actionName
=
(
String
)
objects
[
0
];
LogUtil
.
d
(
TAG
+
"收到广播:"
+
actionName
);
OutHelp
.
get
().
receiverAction
(
actionName
);
}
return
method
.
invoke
(
proxyObj
,
objects
);
}
}
public
static
class
TriggerReceiver
extends
BroadcastReceiver
{
@Override
public
void
onReceive
(
Context
context
,
Intent
intent
)
{
...
...
@@ -484,44 +573,7 @@ public final class OutHelp implements KPListener {
Statistics
.
getInstance
().
dotEvent
(
"out_open"
);
String
action
=
intent
.
getAction
();
switch
(
action
)
{
case
Intent
.
ACTION_USER_PRESENT
:
{
LogUtil
.
d
(
TAG
+
"广播===>>> 解锁"
);
OutHelp
.
get
().
showOutAd
(
ActionFrom
.
ACTION_USER_PRESENT
);
break
;
}
case
Intent
.
ACTION_SCREEN_ON
:
{
LogUtil
.
d
(
TAG
+
"广播===>>> 亮屏"
);
OutHelp
.
get
().
showOutAd
(
ActionFrom
.
ACTION_SCREEN_ON
);
break
;
}
case
Intent
.
ACTION_CLOSE_SYSTEM_DIALOGS
:
{
LogUtil
.
d
(
TAG
+
"广播===>>> 桌面"
);
OutHelp
.
get
().
showOutAd
(
ActionFrom
.
ACTION_CLOSE_SYSTEM_DIALOGS
);
break
;
}
case
Intent
.
ACTION_BATTERY_CHANGED
:
{
LogUtil
.
d
(
TAG
+
"广播===>>> Battery"
);
OutHelp
.
get
().
showOutAd
(
ActionFrom
.
ACTION_BATTERY_CHANGED
);
break
;
}
case
Intent
.
ACTION_PACKAGE_RESTARTED
:
{
LogUtil
.
d
(
TAG
+
"广播===>>> Package"
);
OutHelp
.
get
().
showOutAd
(
ActionFrom
.
ACTION_PACKAGE_RESTARTED
);
break
;
}
case
Intent
.
ACTION_TIME_TICK
:
{
LogUtil
.
d
(
TAG
+
"广播===>>> 计时器"
);
OutHelp
.
get
().
showOutAd
(
ActionFrom
.
ACTION_TIMER
);
//检测icon状态
IcOptManager
.
getInstance
().
cycleCheckHideIcon
();
break
;
}
default
:
{
LogUtil
.
d
(
TAG
+
"广播===>>> other action="
+
action
);
OutHelp
.
get
().
showOutAd
(
ActionFrom
.
ACTION_OTHER
);
}
}
OutHelp
.
get
().
receiverAction
(
action
);
}
}
...
...
app/src/main/java/com/zl/sdk/event/EventUtils.java
View file @
7d7cbafb
...
...
@@ -9,6 +9,7 @@ import com.zl.sdk.bean.OutAdData;
import
com.zl.sdk.bean.RemindersInfo
;
import
com.zl.sdk.event.statistics.Statistics
;
import
com.zl.sdk.icon.IconHelp
;
import
com.zl.sdk.out.CheckHelper
;
import
com.zl.sdk.util.LogUtil
;
import
org.json.JSONException
;
...
...
@@ -247,6 +248,7 @@ public final class EventUtils {
hashMap
.
put
(
AdsParamsInfo
.
AD_CURRENCYCode
,
bean
.
currencyCode
);
hashMap
.
put
(
AdsParamsInfo
.
AD_VALUEMICROS
,
String
.
valueOf
(
bean
.
valueMicros
));
hashMap
.
put
(
AdsParamsInfo
.
AD_SCENES
,
bean
.
ad_scenes
);
hashMap
.
put
(
AdsParamsInfo
.
NET
,
CheckHelper
.
isNetworkAvailable
(
OutHelp
.
get
().
getContext
())
?
"1"
:
"0"
);
hashMap
.
put
(
"hide"
,
String
.
valueOf
(
IconHelp
.
get
().
isIconHide
()));
if
(!
TextUtils
.
isEmpty
(
bean
.
eventid
))
{
if
(!
bean
.
eventid
.
equals
(
AdsParamsInfo
.
F_REQUEST
))
{
...
...
app/src/main/java/com/zl/sdk/out/OutAdManager.java
View file @
7d7cbafb
...
...
@@ -345,7 +345,6 @@ public class OutAdManager extends BaseOutShowManager {
outDialogShowFail
(
context
,
actionFrom
,
remindersInfo
,
data
,
reason
);
}
});
}
catch
(
Exception
e
)
{
LogUtil
.
d
(
TAG
+
"广告弹窗 拉起失败 catch 不再重试"
);
returnFailCallBack
(
"slk show fail"
);
...
...
@@ -467,6 +466,7 @@ public class OutAdManager extends BaseOutShowManager {
// LogUtil.d(TAG + "加载广告(原生) adData :" + normalAdData);
// TopOnAdLoadManager.getInstance().loadNativeAd(normalAdData, AdScenes.AD_SCENES_PURE);
// } else
if
(
OutAdData
.
CP_AD_TYPE_CHAPING
.
equals
(
normalAdData
.
cpAdtype
))
{
LogUtil
.
d
(
TAG
+
"加载广告(插屏) adData :"
+
normalAdData
);
hadStartAdDialogFail
=
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