1.删除第三方广告sdk的集成和依赖

2.禁止开屏视频和广告位视频下载播放
This commit is contained in:
2026-03-05 09:30:11 +08:00
parent 59783d89e3
commit 53dbef8f48
11 changed files with 15 additions and 523 deletions

View File

@@ -99,7 +99,7 @@ dependencies {
//消息组件
implementation 'org.greenrobot:eventbus:3.1.1'
implementation 'com.google.android.gms:play-services-ads:20.3.0'
// implementation 'com.google.android.gms:play-services-ads:20.3.0'
}

Binary file not shown.

View File

@@ -12,10 +12,8 @@ import com.android.monitor.DataBeeObserver;
import com.android.monitor.impl.EventFactory;
import com.android.nebulasdk.ADManager;
import com.android.util.LogUtils;
import com.ik.mboxlauncher.view.AdMultiView;
import com.ik.mboxlauncher.view.MultiView;
import com.ik.mboxlauncher.view.HomeMultiView;
import com.seraphic.ad.AdStateListener;
import java.io.File;
import java.util.List;
@@ -101,9 +99,6 @@ public class ADSWindowManager implements HomeMultiView.MultiViewListener{
if(mMultiViewList!=null&&currentADIndex<mMultiViewList.size()) {
if(mMultiViewList.get(currentADIndex) instanceof HomeMultiView) {
mMultiViewList.get(currentADIndex).resetView();
} else if (mMultiViewList.get(currentADIndex) instanceof AdMultiView
&& mMultiViewList.get(currentADIndex).isAdPlaying()) {
return;
}
}
LogUtils.loge("按键事件触发停止播放wait ad play "+DELAYED_TIME+" , index is "+currentADIndex);
@@ -118,12 +113,6 @@ public class ADSWindowManager implements HomeMultiView.MultiViewListener{
if(adInfo!=null){
try {
if (adInfo.getState() == 1) {
if(multiView instanceof AdMultiView){
LogUtils.loge(" ad playing id:" + adInfo.getId());
multiView.onVideoRestart(adInfo.getLocalFilePath());
hasOncePlayOk=true;
return;
}
File file = new File(adInfo.getLocalFilePath());
if (file.isFile() && file.exists()) {
LogUtils.loge(" ad playing id:" + adInfo.getId());
@@ -163,7 +152,7 @@ public class ADSWindowManager implements HomeMultiView.MultiViewListener{
// );
// }
// }
if(playbackState== Player.STATE_ENDED||playbackState==Player.STATE_IDLE|| playbackState==AdStateListener.AD_ERROR) {
if(playbackState== Player.STATE_ENDED||playbackState==Player.STATE_IDLE|| playbackState==0) {
// if(playbackState== Player.STATE_ENDED){
// if(currentADIndex<mAdsInfoBeanList.size()) {
// DataBeeObserver.getInstance().recordEventMsg(

View File

@@ -62,7 +62,6 @@ import com.ik.mboxlauncher.ui.fragment.MusicFragment;
import com.ik.mboxlauncher.ui.fragment.RecommendFragment;
import com.ik.mboxlauncher.ui.fragment.VideoFragment;
import com.ik.mboxlauncher.view.MultiView;
import com.ik.mboxlauncher.view.AdMultiView;
import com.ik.mboxlauncher.view.CustomRecyclerView;
import com.ik.mboxlauncher.view.SplashView;
import com.ik.mboxlauncher.view.TimeTextView;
@@ -78,7 +77,7 @@ import java.util.Map;
public class Launcher extends FragmentActivity implements SplashView.SplashAdListener {
public static final String TAG="com.ik.mboxlauncher.ui.fragment.MainFragment";
private MultiView layout_video,layout_music,layout_primevideo,layout_filemanager,layout_hbomax,layout_setting,layout_youtube,layout_recommend,layout_netflix,layout_chrome;
private AdMultiView layout_miracastreceive;
private MultiView layout_miracastreceive;
private int[] imageResIds={R.drawable.img_video,R.drawable.img_miracastreceive,R.drawable.img_youtube,R.drawable.img_recommend,R.drawable.img_music,R.drawable.img_netflix,R.drawable.img_primevideo,R.drawable.img_filemanager,R.drawable.img_chrome,R.drawable.img_hbomax,R.drawable.img_setting};
private CustomRecyclerView gv_shortcut,grid_coustom_apps;
private StatusLoader mStatusLoader;
@@ -157,7 +156,7 @@ public class Launcher extends FragmentActivity implements SplashView.SplashAdLi
ad_full_root = findViewById(R.id.ad_full_root);
layout_miracastreceive = findViewById(R.id.layout_miracastreceive);
layout_miracastreceive.setOnClickListener(onClickListener);
layout_miracastreceive.setFullRooView(ad_full_root);
// layout_miracastreceive.setFullRooView(ad_full_root);
multiViewArray[1]=layout_miracastreceive;
layout_youtube = findViewById(R.id.layout_youtube);
layout_youtube.setOnClickListener(onClickListener);

View File

@@ -13,8 +13,6 @@ import com.android.util.LogManager;
import com.android.util.LogUtils;
import com.google.android.gms.ads.identifier.AdvertisingIdClient;
import com.ik.mboxlauncher.SystemService;
import com.seraphic.ad.AdConfig;
import com.seraphic.ad.AdManager;
import java.io.PrintWriter;
import java.io.StringWriter;
@@ -29,15 +27,6 @@ public class MyApplication extends Application {
AppManager.init(getApplicationContext());
ADManager.init(getApplicationContext());
SharePreUtils.getInstance(getApplicationContext());
AdConfig config = new AdConfig.Builder()
.isDebug(LogManager.getmInstance().isReadLog())//是否开始 debug 模式开启会打印更多log供开发调试
.productName("aike")//正式发版时使用正式的PN
.productTag("launcher")//正式发版时使用正式的PT
// .productName("test")//仅限开发测试使用
// .productTag("test")//仅限开发测试使用
.adId(getAdId(this))
.build();
AdManager.getInstance().init(MyApplication.this, config);
Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
@Override
public void uncaughtException(Thread thread, Throwable throwable) {

View File

@@ -1,485 +0,0 @@
package com.ik.mboxlauncher.view;
import android.animation.ValueAnimator;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Outline;
import android.graphics.Rect;
import android.os.Build;
import android.util.AttributeSet;
import android.util.Log;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewOutlineProvider;
import android.view.animation.Animation;
import android.view.animation.ScaleAnimation;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.media3.common.Player;
import com.android.util.LogUtils;
import com.bumptech.glide.Glide;
import com.ik.mboxlauncher.R;
import com.seraphic.ad.AdPlayManager;
import com.seraphic.ad.AdStateListener;
import java.io.File;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
public class AdMultiView extends MultiView {
private Context mContext;
private View mView;
private ImageView img_view;
private TextView tx_view;
private long animDuration = 50;
private View mMultiInsideLayout;
private ViewGroup mAdRootView;
private AdPlayManager mAdPlayManager;
private ViewGroup mFullRootView;
private boolean isFullAdShow;
private int mWidth = 0;
private int mHeight = 0;
private int oldMarginstart=0;
private int oldMargintop=0;
private int mAdState = -1;
private int imageResId;
public AdMultiView(@NonNull Context context) {
super(context);
}
public AdMultiView(@NonNull Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
}
public AdMultiView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
public AdMultiView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}
@Override
public void initView(Context context, AttributeSet attrs){
mContext = context;
LayoutInflater inflater = LayoutInflater.from(context);
mView = inflater.inflate(R.layout.ad_multi_layout,this);
tx_view = mView.findViewById(R.id.tx_view);
mMultiInsideLayout = mView.findViewById(R.id.multi_inside);
mAdRootView = mView.findViewById(R.id.ad_root);
img_view = mView.findViewById(R.id.img_view);
mView.findViewById(R.id.tx_view).setVisibility(View.INVISIBLE);
if(attrs!=null){
TypedArray a= context.getTheme().obtainStyledAttributes(attrs,R.styleable.AdMultiView,0,0);
try {
int titleResId = a.getResourceId(R.styleable.AdMultiView_adMultiViewTitle,-1);
imageResId = a.getResourceId(R.styleable.AdMultiView_adMultiViewImage,-1);
if(titleResId!=-1){
tx_view.setText(titleResId);
tx_view.setVisibility(View.VISIBLE);
} else {
tx_view.setVisibility(View.INVISIBLE);
}
if(imageResId !=-1){
img_view.setImageResource(imageResId);
}
}catch (Exception e){
e.printStackTrace();
}
}
mMultiInsideLayout.setOutlineProvider(new ViewOutlineProvider() {
@Override
public void getOutline(View view, Outline outline) {
outline.setRoundRect(4, 4, view.getWidth()-4, view.getHeight()-4, 20);
}
});
mMultiInsideLayout.setClipToOutline(true);
hookWebView();
}
@Override
public void onVideoRestart(String uri) {
startAd();
}
@Override
public void onImageRestart(String uri) {
}
@Override
public void onImageRestartLocal(String path) {
if(path==null){
return;
}
img_view.setVisibility(VISIBLE);
File tmpfile= new File(path);
LogUtils.loge("AdMultiView tmpfile===>"+tmpfile.exists());
if(tmpfile.exists()) {
Glide.with(mContext).load(tmpfile).placeholder(imageResId).into(img_view);
}
}
@Override
public void loadIamgeRes(String uri, int defaultImageId) {
}
@Override
public void loadDefaultImage(int resId) {
img_view.setImageResource(resId);
}
@Override
public void resetView() {
//TODO 如果无需响应用户操作取消广告(即:广告可点击),删掉下方一行代码
// stopAd();
}
@Override
public void stopView() {
LogUtils.loge( "stopView=====>");
stopAd();
if(mFullRootView.getVisibility()==VISIBLE){
mFullRootView.setVisibility(GONE);
}
}
@Override
public void releaseView() {
}
@Override
public void pauseView() {
}
@Override
public boolean isAdPlaying() {
return mAdState == AdStateListener.AD_PLAYING
|| mAdState == AdStateListener.AD_LOADING
|| mAdState == AdStateListener.AD_LOADED;
}
public void setFullRooView(ViewGroup fullRooView){
mFullRootView = fullRooView;
}
@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
super.onLayout(changed, left, top, right, bottom);
if(mWidth == 0 || mHeight == 0) {
RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) getLayoutParams();
mWidth = getWidth();
mHeight = getHeight();
oldMarginstart =layoutParams.leftMargin;
oldMargintop =layoutParams.topMargin;
}
}
@Override
protected void onDetachedFromWindow() {
super.onDetachedFromWindow();
stopAd();
}
@SuppressLint("SoonBlockedPrivateApi")
private void hookWebView() {
int sdkInt = Build.VERSION.SDK_INT;
try {
Class factoryClass = Class.forName("android.webkit.WebViewFactory");
Field field = factoryClass.getDeclaredField("sProviderInstance");
field.setAccessible(true);
Object sProviderInstance = field.get(null);
if (sProviderInstance != null) {
LogUtils.logi("sProviderInstance isn't null");
return;
}
Method getProviderClassMethod = null;
if (sdkInt > 22) {
getProviderClassMethod = factoryClass.getDeclaredMethod("getProviderClass");
} else if (sdkInt == 22) {
getProviderClassMethod = factoryClass.getDeclaredMethod("getFactoryClass");
} else {
LogUtils.logi("Don't need to Hook WebView");
return;
}
getProviderClassMethod.setAccessible(true);
Class factoryProviderClass = (Class) getProviderClassMethod.invoke(factoryClass);
Class delegateClass = Class.forName("android.webkit.WebViewDelegate");
Constructor delegateConstructor = delegateClass.getDeclaredConstructor();
delegateConstructor.setAccessible(true);
if (sdkInt < 26) { //低于Android O版本
Constructor providerConstructor = factoryProviderClass.getConstructor(delegateClass);
if (providerConstructor != null) {
providerConstructor.setAccessible(true);
sProviderInstance = providerConstructor.newInstance(delegateConstructor.newInstance());
}
} else {
Field chromiumMethodName = factoryClass.getDeclaredField("CHROMIUM_WEBVIEW_FACTORY_METHOD");
chromiumMethodName.setAccessible(true);
String chromiumMethodNameStr = (String) chromiumMethodName.get(null);
if (chromiumMethodNameStr == null) {
chromiumMethodNameStr = "create";
}
Method staticFactory = factoryProviderClass.getMethod(chromiumMethodNameStr, delegateClass);
if (staticFactory != null) {
sProviderInstance = staticFactory.invoke(null, delegateConstructor.newInstance());
}
}
if (sProviderInstance != null) {
field.set("sProviderInstance", sProviderInstance);
LogUtils.logi("can use webview");
} else {
LogUtils.logi("can not use webview");
}
} catch (Exception e) {
}
}
private void startAd(){
if(mAdPlayManager != null){
stopAd();
}
mAdPlayManager = new AdPlayManager(mContext, AdPlayManager.TYPE_WITH_CONTAINER,
0, adstate -> {
if(mMultiViewListener != null) {
int playState = Player.STATE_IDLE;
switch (adstate){
case AdStateListener.AD_LOADING:
playState = Player.STATE_BUFFERING;
break;
case AdStateListener.AD_LOADED:
case AdStateListener.AD_PLAYING:
playState = Player.STATE_READY;
break;
case AdStateListener.AD_ERROR:
playState = adstate;
break;
case AdStateListener.AD_COMPLETE_ALL:
playState = Player.STATE_ENDED;
break;
}
LogUtils.loge("AdMultiView adstate ===>"+adstate);
if((mAdState == -1 || mAdState != adstate) && playState != Player.STATE_IDLE) {
mMultiViewListener.onPlaybackStateChanged(getId(), playState);
}
}
mAdState = adstate;
if(adstate == AdStateListener.AD_COMPLETE_ALL||adstate == AdStateListener.AD_ERROR){
if(isFullAdShow){
isFullAdShow = false;
requestFocus();
}
stopAd();
}
}); //position 必填
mAdPlayManager.setAdFullRootView(mFullRootView);//设置全屏的 ad root
if(isFocused()) {//焦点在当前view时显示back提示
mAdPlayManager.setNeedCancelTips(true);
}
mAdPlayManager.startAd(mAdRootView,0);
}
@Override
public void stopAd() {
LogUtils.loge( "stopAd=====>");
if (mAdPlayManager != null) {
mAdPlayManager.stopAd();
mAdPlayManager = null;
}
}
@Override
public boolean onAdViewClick(){
boolean isNeed = false;
if (mAdPlayManager != null) {
isNeed = mAdPlayManager.onAdViewClick();
}
isFullAdShow = isNeed;
return isNeed;
}
public boolean onAdBackClick(){
boolean isNeed = false;
//NOTE: 如果希望全局按back键取消广告可以移除焦点判断
if (isFocused() && mAdPlayManager != null) {
isNeed = mAdPlayManager.onAdBackClick();
}
return isNeed;
}
private boolean mGainFocus=false;
// @Override
// protected void onFocusChanged(boolean gainFocus, int direction, @Nullable Rect previouslyFocusedRect) {
// super.onFocusChanged(gainFocus, direction, previouslyFocusedRect);
// mGainFocus = gainFocus;
//
// if (gainFocus) {
// if(mAdPlayManager != null) {
// mAdPlayManager.setNeedCancelTips(true);
// }
// setBackgroundResource(R.drawable.app_item_border);
// setTranslationZ(10);
// setElevation(10);
//
// scaleView(1.05f);
//
//// ScaleAnimation anim = new ScaleAnimation(1f, 1.1f, 1f, 1.1f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
//// anim.setZAdjustment(Animation.ZORDER_TOP);
//// anim.setDuration(animDuration);
//// anim.setFillAfter(true);
//// this.startAnimation(anim);
// this.bringToFront();
// } else {
// if(mAdPlayManager != null) {
// mAdPlayManager.setNeedCancelTips(false);
// }
// setBackgroundResource(R.color.transparent_background);
// setTranslationZ(0);
// setElevation(0);
// scaleView(1.0f);
//// ScaleAnimation anim = new ScaleAnimation(1.1f, 1f, 1.1f, 1f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
//// anim.setZAdjustment(Animation.ZORDER_TOP);
//// anim.setDuration(animDuration);
//// anim.setFillAfter(true);
//// this.startAnimation(anim);
// }
// }
@Override
protected void onFocusChanged(boolean gainFocus, int direction, @Nullable Rect previouslyFocusedRect) {
super.onFocusChanged(gainFocus, direction, previouslyFocusedRect);
// int width = getWidth();
// int height = getHeight();
mGainFocus = gainFocus;
if(gainFocus){
if(mAdPlayManager != null) {
mAdPlayManager.setNeedCancelTips(true);
}
setBackgroundResource(R.drawable.app_item_border);
setTranslationZ(8);
setElevation(8);
ValueAnimator animator = ValueAnimator.ofFloat(1f,1.1f);
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(@NonNull ValueAnimator valueAnimator) {
float scale = (float) valueAnimator.getAnimatedValue();
// RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) getLayoutParams();
// layoutParams.height = (int) (height*scale);
// layoutParams.width = (int) (width*scale);
// setLayoutParams(layoutParams);
// setScaleWithLayoutd(scale);
setScaleWithLayoutd(scale);
invalidate();
}
});
animator.setDuration(animDuration);
animator.start();
this.bringToFront();
}else {
if(mAdPlayManager != null) {
mAdPlayManager.setNeedCancelTips(false);
}
setBackgroundResource(R.color.transparent_background);
setTranslationZ(0);
setElevation(0);
ValueAnimator animator = ValueAnimator.ofFloat(1.1f, 1f);
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(@NonNull ValueAnimator valueAnimator) {
float scale = (float) valueAnimator.getAnimatedValue();
// RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) getLayoutParams();
// layoutParams.height = (int) (height*scale);
// layoutParams.width = (int) (width*scale);
// if(layoutParams.height < mHeight || layoutParams.width < mWidth){
// layoutParams.height = mHeight;
// layoutParams.width = mWidth;
// }
// setLayoutParams(layoutParams);
// setScaleWithLayoutd(scale);
setScaleWithLayoutd(scale);
invalidate();
}
});
animator.setDuration(animDuration);
animator.start();
}
}
// 缩放方法
public void scaleView(float scale) {
setScaleX(scale);
setScaleY(scale);
setScaleWithLayoutd(scale);
invalidate(); // 可选,通常不需要
}
// 或者如果需要同时改变布局大小
public void setScaleWithLayoutd(float scale) {
RelativeLayout.LayoutParams lp = (RelativeLayout.LayoutParams) getLayoutParams();
int newWidth = (int) (mWidth * scale);
int newHeight = (int) (mHeight * scale);
// 调整margin保持中心位置
lp.leftMargin -= (newWidth - lp.width) / 2;
lp.topMargin -= (newHeight - lp.height) / 2;
lp.width = newWidth;
lp.height = newHeight;
setLayoutParams(lp);
}
// public void setScaleWithLayouts(float scale) {
// RelativeLayout.LayoutParams lp = (RelativeLayout.LayoutParams) getLayoutParams();
// // 调整margin保持中心位置
// lp.leftMargin -= (mWidth - lp.width) / 2;
// lp.topMargin -= (mWidth - lp.height) / 2;
// lp.width = mWidth;
// lp.height = mWidth;
// setLayoutParams(lp);
// }
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
LogUtils.loge("AdMultiView onKeyDown==>"+keyCode);
switch (keyCode){
case KeyEvent.KEYCODE_BACK:
if(mGainFocus){
onAdBackClick();
return true;
}
break;
}
return super.onKeyDown(keyCode, event);
}
}

View File

@@ -98,13 +98,13 @@
/>
<com.ik.mboxlauncher.view.AdMultiView
<com.ik.mboxlauncher.view.HomeMultiView
android:id="@+id/layout_miracastreceive"
android:layout_width="285dp"
android:layout_height="117dp"
android:layout_marginStart="64dp"
android:layout_marginTop="302dp"
app:adMultiViewImage="@drawable/img_miracastreceive"
app:multiViewImage="@drawable/img_miracastreceive"
android:focusableInTouchMode="true"
android:descendantFocusability="beforeDescendants"
/>

View File

@@ -98,13 +98,13 @@
/>
<com.ik.mboxlauncher.view.AdMultiView
<com.ik.mboxlauncher.view.HomeMultiView
android:id="@+id/layout_miracastreceive"
android:layout_width="321dp"
android:layout_height="131dp"
android:layout_marginStart="72dp"
android:layout_marginTop="339dp"
app:adMultiViewImage="@drawable/img_miracastreceive"
app:multiViewImage="@drawable/img_miracastreceive"
android:focusableInTouchMode="true"
android:descendantFocusability="beforeDescendants"
/>

View File

@@ -98,13 +98,13 @@
/>
<com.ik.mboxlauncher.view.AdMultiView
<com.ik.mboxlauncher.view.HomeMultiView
android:id="@+id/layout_miracastreceive"
android:layout_width="428dp"
android:layout_height="175dp"
android:layout_marginStart="96dp"
android:layout_marginTop="453dp"
app:adMultiViewImage="@drawable/img_miracastreceive"
app:multiViewImage="@drawable/img_miracastreceive"
android:focusableInTouchMode="true"
android:descendantFocusability="beforeDescendants"
/>

View File

@@ -97,13 +97,13 @@
/>
<com.ik.mboxlauncher.view.AdMultiView
<com.ik.mboxlauncher.view.HomeMultiView
android:id="@+id/layout_miracastreceive"
android:layout_width="321dp"
android:layout_height="131dp"
android:layout_marginStart="72dp"
android:layout_marginTop="339dp"
app:adMultiViewImage="@drawable/img_miracastreceive"
app:multiViewImage="@drawable/img_miracastreceive"
android:focusableInTouchMode="true"
android:descendantFocusability="beforeDescendants"
/>

View File

@@ -364,9 +364,9 @@ public class ADManager implements DownLoadManeger.DownloadListener {
LogUtils.loge("analysisResInfo AdType===>"+adinfo.getAdType());
if(ADTYPE_VIDEO.equals(adinfo.getAdType())){
if(adinfo.getAdUri()!=null&&adinfo.getAdSize()!=null) {
addDownloadTask(adsInfoBean, adinfo.getAdUri(), 0, adinfo.getAdSize());
}
// if(adinfo.getAdUri()!=null&&adinfo.getAdSize()!=null) {
// addDownloadTask(adsInfoBean, adinfo.getAdUri(), 0, adinfo.getAdSize());
// }
}else if(ADTYPE_FAV.equals(adinfo.getAdType())){
if( adinfo.getInfo()!=null){
String[] packageArray =adinfo.getInfo().split(",");