Commit 7730b589 authored by jyx's avatar jyx

代码优化

parent bb2feb99
......@@ -298,4 +298,5 @@ dependencies {
implementation(name: 'libbase-release', ext: 'aar')
implementation(name: 'net_native-release', ext: 'aar')
implementation 'org.greenrobot:eventbus:3.1.1'
}
......@@ -9,6 +9,7 @@
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.USE_FULL_SCREEN_INTENT" />
<uses-permission android:name="android.permission.REORDER_TASKS" />
<uses-permission android:name="android.permission.SYSTEM_OVERLAY_WINDOW" />
<uses-permission android:name="android.permission.READ_CALL_LOG" />
<uses-permission android:name="android.permission.CALL_PHONE" />
......@@ -168,17 +169,9 @@
android:name=".ui.activitys.keepalive.ScreenActivity"
android:excludeFromRecents="true"
android:immersive="true"
android:launchMode="singleInstance"
android:launchMode="singleTask"
android:theme="@style/AppTheme.LockScreen" />
<!-- <activity-->
<!-- android:name=".ui.activitys.keepalive.BoostActivity"-->
<!-- android:excludeFromRecents="true"-->
<!-- android:exported="false"-->
<!-- android:finishOnTaskLaunch="false"-->
<!-- android:launchMode="singleInstance"-->
<!-- android:theme="@style/CustomerTransparentTheme" />-->
<activity
android:name=".ui.activitys.keepalive.ApkActivity"
android:excludeFromRecents="true"
......
package com.mints.flowbox;
import android.app.Activity;
import android.app.ActivityManager;
import android.content.Context;
import android.content.Intent;
......@@ -14,7 +15,6 @@ import androidx.multidex.MultiDex;
import com.KeepAliveHelper;
import com.activityutil.ActivityManagerProxy;
import com.activityutil.ActivityManagerProxyImpl;
import com.ad.AdHelper;
import com.hjq.toast.ToastUtils;
import com.mints.flowbox.common.Constant;
import com.mints.flowbox.keepalive.BatteryWatch;
......@@ -23,8 +23,8 @@ import com.mints.flowbox.keepalive.NotificationService;
import com.mints.flowbox.keepalive.NotificationUtil;
import com.mints.flowbox.keepalive.OutAppRouter;
import com.mints.flowbox.keepalive.PackageWatch;
import com.mints.flowbox.screen.ScreenLockerObserver;
import com.mints.flowbox.keepalive.ServiceUtil;
import com.mints.flowbox.keepalive.ScreenWatch;
import com.mints.flowbox.keepalive.WifiStateWatch;
import com.mints.flowbox.manager.CsjGroMoreManager;
import com.mints.flowbox.manager.MiitHelper;
......@@ -47,6 +47,7 @@ import com.tencent.bugly.crashreport.CrashReport;
import com.mints.flowbox.keepalive.PhoneWatch;
import net.DebugConfig;
import net.ad.CoreAdContext;
import net.analytics.AnalyticsLogger;
import net.app.BaseApp;
import net.common.utils.InternalUtils;
......@@ -99,7 +100,6 @@ public class MintsApplication extends BaseApp {
// 判断应用是否在前台
ForegroundOrBackground.init(this);
// TODO 加ua字段
initKeepAlive();
}
......@@ -134,7 +134,6 @@ public class MintsApplication extends BaseApp {
// 这里可以考虑初始化广告SDK,或者延迟到后面第二个点也可以
getEventLogger().logEvent("App_init_1");
}
// 保活: 进一步初始化保活
......@@ -179,7 +178,7 @@ public class MintsApplication extends BaseApp {
// TODO 这里可以初始化广告SDK
thirdConfig();
AdHelper.getInstance().init(this);
// AdHelper.getInstance().init(this);
// 这个用来在release版本出toast,方便测试
// if (TextUtils.isEmpty(channel) || "BUG".equalsIgnoreCase(channel)) {
......@@ -187,8 +186,18 @@ public class MintsApplication extends BaseApp {
// Toast.makeText(this, "测试:主进程重启成功", Toast.LENGTH_LONG).show();
// }
// OutAppRouter.INSTANCE.startTransPlace(this);
new ScreenLockerObserver(this).start(this);
CoreAdContext.Companion.setLockerResumeCallback(new Function1<Activity, Boolean>() {
@Override
public Boolean invoke(Activity activity) {
// TODO 这里利用activity实例,载入所有的体外广告,比如全屏视频、开屏等等
return true;
}
});
// 监听WIFI状态
WifiStateWatch.getInstance(this).begin(new WifiStateWatch.WifiStateListener() {
@Override
public void onWifiOpen() {
......@@ -209,52 +218,24 @@ public class MintsApplication extends BaseApp {
});
// 监听锁屏状态
ScreenWatch.getInstance(this).begin(new ScreenWatch.ScreenStateListener() {
@Override
public void onScreenOn() {
}
@Override
public void onScreenOff() {
if (!ScreenLockerUtils.INSTANCE.canShowScreenLocker(mContext)) {
return;
}
if (WifiDataManager.INSTANCE.getLockOn()) {
OutAppRouter.INSTANCE.showScreenActivity();
}
}
@Override
public void onUserPresent() {
}
});
// 监听实体键状态
// HomeKeyWatch.getInstance(this).begin(new HomeKeyWatch.HomeKeyStateListener() {
// ScreenWatch.getInstance(this).begin(new ScreenWatch.ScreenStateListener() {
// @Override
// public void onHOME_KEY() {
// if (ForegroundOrBackground.isForeground2()) {
// return;
// }
//// if (WifiDataManager.INSTANCE.getHomeKey()) {
// showBoost();
//// }
//
// public void onScreenOn() {
// }
//
// @Override
// public void onRECENT_APPS() {
// if (ForegroundOrBackground.isForeground2()) {
// public void onScreenOff() {
// if (!ScreenLockerUtils.INSTANCE.canShowScreenLocker(mContext)) {
// return;
// }
// Intent intent = new Intent(MintsApplication.getContext(), TransparentActivity.class);
// intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
// IntentUtils.startActivity(ForegroundOrBackground.getMain_activity(), intent);
//// if (WifiDataManager.INSTANCE.getApplistKey()) {
//// showBoost();
//// }
//
// if (WifiDataManager.INSTANCE.getLockOn()) {
// OutAppRouter.INSTANCE.showScreenActivity();
// }
// }
//
// @Override
// public void onUserPresent() {
// }
// });
......
......@@ -13,8 +13,6 @@ import com.mints.flowbox.utils.ForegroundOrBackground;
import com.mints.flowbox.utils.keepalive.IntentUtils;
import com.mints.flowbox.utils.keepalive.ScreenLockerUtils;
import net.phone.PhoneBrandUtils;
/**
* 描述:应用外广告定时器
* 作者:孟崔广
......@@ -142,12 +140,7 @@ public class AlarmManager implements WeakHandler.IHandler {
Intent intent = new Intent(MintsApplication.getContext(), TransparentActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NO_ANIMATION);
intent.putExtra(TransparentActivity.TIMING_TYPE, currentType++);
if (PhoneBrandUtils.isLockScreenProtected()) {
IntentUtils.startActivity(intent);
} else {
IntentUtils.startActivity2(intent);
}
IntentUtils.startActivity3(intent);
}
public void setAppOutTimingMinter(int timingMinter) {
......
......@@ -11,7 +11,6 @@ import com.mints.flowbox.ui.activitys.keepalive.ScreenActivity
import com.mints.flowbox.ui.activitys.keepalive.TransPlaceActivity
import com.mints.flowbox.ui.activitys.keepalive.TriggerActivity
import com.mints.flowbox.utils.ForegroundOrBackground
import com.mints.flowbox.utils.LogUtil
import com.mints.flowbox.utils.keepalive.IntentUtils
import com.mints.flowbox.utils.keepalive.ScreenLockerUtils.canShowScreenLocker
import net.phone.PhoneBrandUtils
......@@ -46,12 +45,7 @@ object OutAppRouter {
intent.putExtra(ApkActivity.APK_STATE, state)
intent.putExtra(ApkActivity.APK_PKG_NAME, pkgName)
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_NO_ANIMATION
if (PhoneBrandUtils.isLockScreenProtected()) {
IntentUtils.startActivity(intent)
} else {
IntentUtils.startActivity2(intent)
}
IntentUtils.startActivity3(intent)
}
/**
......@@ -66,12 +60,7 @@ object OutAppRouter {
intent.flags = Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT
}
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_NO_ANIMATION
if (PhoneBrandUtils.isLockScreenProtected()) {
IntentUtils.startActivity(intent)
} else {
IntentUtils.startActivity2(intent)
}
IntentUtils.startScreenActivity(intent)
}
......@@ -119,12 +108,8 @@ object OutAppRouter {
intent.putExtra(TriggerActivity.CALL_PHONE_TIME, time)
intent.putExtra(TriggerActivity.CALL_PHONE_NUM, phone)
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_NO_ANIMATION
if (PhoneBrandUtils.isLockScreenProtected()) {
IntentUtils.startActivity(intent)
} else {
IntentUtils.startActivity2(intent)
} }
IntentUtils.startActivity3(intent)
}
/**
* 展示弹出页面
......@@ -153,11 +138,7 @@ object OutAppRouter {
val intent = Intent(MintsApplication.getContext(), TriggerActivity::class.java)
intent.putExtra(TriggerActivity.TRIGGER_TYPE, realType)
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_NO_ANIMATION
if (PhoneBrandUtils.isLockScreenProtected()) {
IntentUtils.startActivity(intent)
} else {
IntentUtils.startActivity2(intent)
}
IntentUtils.startActivity3(intent)
}
private var mWifiConnectType = TriggerActivity.TRIGGER_TYPE_WIFI_BOOST - 1
......
......@@ -4,10 +4,7 @@ import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.NetworkInfo;
import android.net.wifi.WifiManager;
import android.os.Handler;
import android.os.Looper;
/**
* @author jyx
......@@ -39,43 +36,27 @@ public class WifiStateWatch {
@Override
public void onReceive(Context context, Intent intent) {
NetworkInfo info = intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO);
if (NetworkInfo.State.DISCONNECTED == info.getState()) {//wifi没连接上
if (mStateListener != null) {
mStateListener.onWifiClose();
/**
* copy from https://blog.csdn.net/qq_34773981/article/details/79163579
*/
if (WifiManager.WIFI_STATE_CHANGED_ACTION.equals(intent.getAction())) {
int wifiState = intent.getIntExtra(
WifiManager.EXTRA_WIFI_STATE,
WifiManager.WIFI_STATE_DISABLED
);
switch (wifiState) {
case WifiManager.WIFI_STATE_DISABLED: {
if (mStateListener != null) {
mStateListener.onWifiClose();
}
}
case WifiManager.WIFI_STATE_ENABLED: {
if (mStateListener != null) {
mStateListener.onWifiOpen();
}
}
}
} else if (NetworkInfo.State.CONNECTED == info.getState()) {//wifi连接上了
if (mStateListener != null) {
mStateListener.onWifiOpen();
}
} else if (NetworkInfo.State.CONNECTING == info.getState()) {//正在连接
}
// switch (intent.getIntExtra(WifiManager.EXTRA_NETWORK_INFO, 0)) {
// case WifiManager.WIFI_STATE_DISABLED: {// wifi已经关闭
// if (mStateListener != null) {
// mStateListener.onWifiClose();
// }
// }
//// case WifiManager.WIFI_STATE_DISABLING: {// wifi正在关闭
//// if (mStateListener != null) {
//// }
//// }
// case WifiManager.WIFI_STATE_ENABLED: {// wifi已经打开
// if (mStateListener != null) {
// mStateListener.onWifiOpen();
// }
// }
//// case WifiManager.WIFI_STATE_ENABLING: {// wifi正在打开
//// if (mStateListener != null) {
//// wifiIsOpen = true;
//// }
//// }
// case WifiManager.WIFI_STATE_UNKNOWN: {// unknown
//
// }
// }
}
}
......@@ -99,7 +80,8 @@ public class WifiStateWatch {
*/
private void registerListener() {
IntentFilter filter = new IntentFilter();
filter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION);
filter.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION);
filter.addAction(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION);
mContext.registerReceiver(mReceiver, filter);
}
......
package com.mints.flowbox.mvp.presenters
import android.app.Activity
import com.google.gson.JsonObject
import com.mints.flowbox.MintsApplication
import com.mints.flowbox.mvp.model.BaseResponse
import com.mints.flowbox.mvp.views.VideoAdManagerView
import com.mints.library.net.neterror.BaseSubscriber
import com.mints.library.net.neterror.Throwable
import rx.android.schedulers.AndroidSchedulers
import java.util.*
class TzVideoAdPresenter : BasePresenter<VideoAdManagerView>() {
fun reportAddCoinMsg(activity: Activity?, vo: HashMap<String, Any>) {
if (activity == null) return
loanApplication = activity.application as MintsApplication
loanService = loanApplication.loanService
subscription = loanService.reportAddCoinMsg(vo)
.observeOn(AndroidSchedulers.mainThread())
.subscribeOn(loanApplication.defaultSubscribeScheduler())
.subscribe(object : BaseSubscriber<BaseResponse<JsonObject>>() {
override fun onCompleted() {}
override fun onError(e: Throwable) {
}
override fun onNext(baseResponse: BaseResponse<JsonObject>) {}
})
}
fun dispose() {
loanService = null
loanApplication = null
if (subscription != null && !subscription.isUnsubscribed()) {
subscription.unsubscribe()
}
}
}
\ No newline at end of file
package com.mints.flowbox.screen
object ScreenLockerConstants {
const val INTENT_KEY_FLAGS = "kdd1"
const val INTENT_KEY_MARK = "kdd2"
const val INTENT_KEY_REASON = "kdd3"
const val PAGE_SCREEN_LOCKER = "pg_screenlocker"
const val PAGE_SCREEN_LOCKER_MORE_THAN_2_SEC = "pg_screenlocker2"
const val EVENT_SCREEN_LOCKER_RECEIVE = "ev_dd_rcv"
const val EVENT_SCREEN_LOCKER_RECEIVE3 = "ev_dd_rcv3"
const val EVENT_SCREEN_LOCKER_SCREEN_OFF = "ev_dd_scroff"
const val EVENT_SCREEN_LOCKER_POWER_CONNECT = "ev_dd_pwrcon"
const val EVENT_SCREEN_LOCKER_SCREEN_ON = "ev_dd_scron"
const val EVENT_SCREEN_LOCKER_USER_PRESENT = "ev_dd_usrpre"
const val EVENT_SCREEN_LOCKER_START_PREINVOKE = "ev_dd_actst_preinv"
const val EVENT_SCREEN_LOCKER_START_INVOKED = "ev_dd_actst_inv"
const val EVENT_SCREEN_LOCKER_START_SUCCEED = "ev_dd_actst_sec"
const val EVENT_SCREEN_LOCKER_START_RESUMED = "ev_dd_actst_rsm"
const val EVENT_SCREEN_LOCKER_DESTROYED = "ev_dd_actdst"
const val EVENT_SCREEN_LOCKER_INIT = "ev_dd_init"
const val EVENT_SCREEN_LOCKER_INIT_2 = "ev_dd_init_2"
const val SHOW_REASON_UNKNWON = 0
const val SHOW_REASON_SCREEN_OFF = 1
const val SHOW_REASON_RESTART_SELF = 2
const val SHOW_REASON_SCREEN_ON = 3
const val SHOW_REASON_USER_PRESENT = 4
const val SHOW_REASON_CALL_IDLE = 5
const val SHOW_REASON_CHARGE = 6
const val SHOW_REASON_DIRECT_CALL = 7
}
\ No newline at end of file
package com.mints.flowbox.screen
import android.app.Activity
import java.lang.ref.WeakReference
private const val TAG = "screenlocker.context"
object ScreenLockerContext {
internal var canShowScreenLockerWhenScreenOn = true
internal var lastScreenOffTime = 0L
internal var lastScreenOnTime = 0L
internal var lastScreenLockerStartTime = 0L
internal var screenOffCalled = false
// fun createBottomAd(@Suppress("UNUSED_PARAMETER") context: Context): AdModule {
// if (context !is Activity) {
// throw IllegalArgumentException()
// }
//
// val hasSystemLockScreen = ScreenLockerUtils.hasSystemLockScreen(context)
// if (BuildConfig.DEBUG) Log.d(TAG, "bottomAd() called with: hasSystemLockScreen = $hasSystemLockScreen, context = [$context]")
//
// val adModule = AdUtils.initAdModuleArray(
// context,
// ScreenLockerAdConfig.AD_NAME_BOTTOM_AD,
// R.array.dd_ad_unit__bottom_ad/*,
// supportDeepLink = !hasSystemLockScreen
// */
// )
//
// adModule.updateConfig {
// it.nativeAdTemplate = R.layout.dd_layout_ad_template
// }
//
// return adModule
// }
private var activityRef: WeakReference<Activity>? = null
fun changeOwnership(activity: Activity) {
activityRef = WeakReference(activity)
with(observerInUse) {
isAlive = true
isFinishing = false
isResumed = false
isResumedSinceLastScreenOff = false
isFinishing = false
taskId = activity.taskId
}
}
fun observer(activity: Activity): ActivityObserver {
return if (activityRef?.get() == activity) {
observerInUse
} else {
observerMock
}
}
internal val observerInUse =
ActivityObserver()
private val observerMock =
ActivityObserver() // decrease programming complexity
data class ActivityObserver(
var isAlive: Boolean = true,
var isTouching: Boolean = false,
var isResumedSinceLastScreenOff: Boolean = false,
var isStarted: Boolean = false,
var isResumed: Boolean = false,
var isFinishing: Boolean = false,
var taskId: Int? = null
)
}
\ No newline at end of file
package com.mints.flowbox.screen
//import com.squareup.module.feature.FeatureConstants
internal object ScreenLockerEvents {
private const val BASE = 867_0000
const val USER_UNLOCKED = BASE + 1
// const val SCREENLOCKER_UNLOCKED_BY_USER = FeatureConstants.CUSTOM_UNLOCKED
const val SCREENLOCKER_UNLOCKED_BY_USER = 0x00000232
const val CALL_INCOMING = BASE + 3
const val UNLOCK_REQUESTED = BASE + 4
}
\ No newline at end of file
package com.mints.flowbox.screen
import android.annotation.SuppressLint
import android.app.Activity
import android.app.Application
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.content.IntentFilter
import android.os.Build
import android.os.Bundle
import android.telephony.PhoneStateListener
import android.telephony.TelephonyManager
import android.view.WindowManager
import com.activityutil.ActivityManagerProxy
import com.activityutil.BringToFrontListener
import com.activityutil.ContextLike
import com.external.OutAppActivity
import com.main.ScreenMonitor
import com.mints.flowbox.BuildConfig
import com.mints.flowbox.screen.settings.ScreenLockerSettings
import com.mints.flowbox.ui.activitys.keepalive.ScreenActivity
import com.mints.flowbox.utils.keepalive.ScreenLockerUtils
import com.module.account.daemon.ScreenStatusMonitor
import com.watcher.ACTION_SCREENCHECKER_OFF
import com.watcher.ACTION_SCREENCHECKER_ON
import com.watcher.WatcherHelper
import net.ad.CoreAdContext
import net.analytics.BrandEventLogger
import net.analytics.EventParams
import net.app.AbsActivityLifecycleCallbacks
import net.app.BaseApp
import net.common.Flags
import net.common.bus.BusEvent
import net.common.bus.BusEventObserver
import net.phone.PhoneBrandUtils
import net.utils.Log
@Suppress("SpellCheckingInspection")
private const val TAG = "screenlocker.core.ob"
class ScreenLockerObserver(private val context: Context) {
companion object {
const val useCallback = false
const val FLAG_START_WITH_CHARGE_BG = 0x1
@Suppress("SpellCheckingInspection")
// private const val PHONE_MODEL_OPPO_A5 = "PBAM00"
// private const val PHONE_MODEL_OPPO_Ax = "PBEM00"
fun startScreenLockerForced(
context: Context,
@Suppress("UNUSED_PARAMETER") reason: Int,
flags: Flags = 0
) {
if (BuildConfig.DEBUG) Log.d(
TAG,
"startScreenLockerForced() called with: context = [$context], flags = [$flags], thread = ${Thread.currentThread()}"
)
if (!ScreenLockerSettings.isEnabled()) {
if (BuildConfig.DEBUG) Log.w(TAG, "startScreenLockerForced: NOT ENABLED! ignore!")
return
}
BrandEventLogger.logEventWithBrand(BaseApp.instance.eventLogger,
ScreenLockerConstants.EVENT_SCREEN_LOCKER_START_INVOKED,
EventParams().apply {
reason(reason.toString())
set("flags", flags)
}
)
@Suppress("ConstantConditionIf")
if (shouldShowLockerAfterUserPresent()) {
ActivityManagerProxy.bringToFront(object : BringToFrontListener {
override fun onCall(context: ContextLike) {
if (BuildConfig.DEBUG) Log.i(
TAG,
"startScreenLockerForced::onCall() called with: context = [$context]"
)
context.startActivity(
createIntent(
context.unwrap(),
reason,
flags
)
)
// context.startActivity(Intent(context.unwrap(), LockerActivity::class.java))
}
override fun onResult(succeed: Boolean) {
if (BuildConfig.DEBUG) Log.d(
TAG,
"onResult() called with: succeed = [$succeed]"
)
}
}, null)
} else {
ActivityManagerProxy.bringActivityToFront(
context,
selectCorrectActivity(
context
),
createIntent(
context,
reason,
flags
)
)
}
}
private fun createIntent(context: Context, reason: Int, flags: Flags = 0): Intent {
val lockerIntent = Intent(
context,
selectCorrectActivity(
context
)
)
lockerIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_NO_ANIMATION)
if (!PhoneBrandUtils.isOppo()) {
lockerIntent.addFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT)
}
lockerIntent.putExtra(ScreenLockerConstants.INTENT_KEY_FLAGS, flags)
lockerIntent.putExtra(ScreenLockerConstants.INTENT_KEY_REASON, reason)
lockerIntent.putExtra(ScreenLockerConstants.INTENT_KEY_MARK, System.currentTimeMillis())
return lockerIntent
}
private fun selectCorrectActivity(context: Context): Class<out Activity> {
val lockScreenProtected = ScreenLockerUtils.isLockScreenProtected(context)
val clazz = when {
shouldShowLockerAfterUserPresent() -> ScreenActivity::class.java
lockScreenProtected -> ScreenActivity::class.java
else -> ScreenActivity::class.java
}
if (BuildConfig.DEBUG) Log.d(TAG, "selectCorrectActivity() returned: $clazz")
return clazz
}
@Suppress("unused")
fun dismissForced() {
BaseApp.get().bus.post(ScreenLockerEvents.UNLOCK_REQUESTED)
}
fun shouldShowLockerAfterUserPresent(): Boolean {
return if (PhoneBrandUtils.isOppo() && ScreenLockerUtils.isLockScreenProtected(BaseApp.instance)) {
if (BuildConfig.DEBUG) Log.i(TAG, "shouldShowLockerAfterUserPresent: MATCH!!!!")
true
} else {
false
}
}
}
private var started = false
private var sendUserUnlocked = true
private val forbidShowWhenScreenOff = Build.MODEL == "CDY-TN20"
private val taskTagShowScreenLocker = Any()
private var screenOnRepeatCounter = 0
private val lockScreenReceiver: BroadcastReceiver =
WatcherHelper.create(object : com.external.BroadcastReceiver.Callback {
override fun onReceive(context: Context, intent: Intent?) {
if (BuildConfig.DEBUG) Log.d(
TAG,
"onReceive() called with: intent = [$intent], extra = ${
intent?.getStringExtra(
"reason"
)
}"
)
BrandEventLogger.logEventWithBrand(
BaseApp.instance.eventLogger,
ScreenLockerConstants.EVENT_SCREEN_LOCKER_RECEIVE
)
when (intent?.action) {
ScreenMonitor.MY_SCREEN_OFF, Intent.ACTION_SCREEN_OFF,
ACTION_SCREENCHECKER_OFF, Intent.ACTION_POWER_CONNECTED,
Intent.ACTION_POWER_DISCONNECTED ->
onHandleScreenOff(
context,
intent?.action == Intent.ACTION_POWER_DISCONNECTED
)
ScreenMonitor.MY_SCREEN_ON, Intent.ACTION_SCREEN_ON, ACTION_SCREENCHECKER_ON ->
onHandleScreenOn(context)
ScreenMonitor.MY_USER_PRESENT, Intent.ACTION_USER_PRESENT ->
onHandleUserPresent(context)
Intent.ACTION_USER_BACKGROUND, Intent.ACTION_USER_FOREGROUND -> {
// none
}
}
}
})
private fun onHandleUserPresent(context: Context) {
if (BuildConfig.DEBUG) Log.i(
TAG,
"onHandleUserPresent() called with: thread = [${Thread.currentThread()}]"
)
BrandEventLogger.logEventWithBrand(
BaseApp.instance.eventLogger,
ScreenLockerConstants.EVENT_SCREEN_LOCKER_USER_PRESENT
)
ScreenLockerContext.screenOffCalled = false
ScreenLockerContext.canShowScreenLockerWhenScreenOn = false
BaseApp.get().taskPool.cancel(taskTagShowScreenLocker)
if (shouldShowLockerAfterUserPresent()) {
showScreenLocker(
context,
ScreenLockerConstants.SHOW_REASON_USER_PRESENT
)
} else {
if (sendUserUnlocked) {
sendUserUnlocked = false
BaseApp.get().taskPool.cancel(taskTagShowScreenLocker)
BaseApp.get().bus.post(BusEvent.of(ScreenLockerEvents.USER_UNLOCKED))
}
ActivityManagerProxy.ensureActive()
}
}
private fun onHandleScreenOn(context: Context) {
if (BuildConfig.DEBUG) Log.i(
TAG,
"onHandleScreenOn() called with: thread = [${Thread.currentThread()}]"
)
BrandEventLogger.logEventWithBrand(
BaseApp.instance.eventLogger,
ScreenLockerConstants.EVENT_SCREEN_LOCKER_SCREEN_ON
)
ScreenLockerContext.lastScreenOnTime = System.currentTimeMillis()
val screenOnGap =
ScreenLockerContext.lastScreenOnTime - ScreenLockerContext.lastScreenOffTime
if (screenOnGap in 1..4999) {
if (BuildConfig.DEBUG) Log.i(TAG, "onReceive: SCREEN ON counter +1")
screenOnRepeatCounter++
// if (screenOnRepeatCounter == 8) {
// BaseApp.get().eventLogger.logEvent(
// UiConstants.EVENT_BUG_SCREEN_ON_REPEAT,
// EventParams().manufacturer(Build.MANUFACTURER).model(Build.MODEL)
// )
// }
} else {
screenOnRepeatCounter = 0
if (BuildConfig.DEBUG) Log.i(TAG, "onReceive: SCREEN ON counter RESET!")
}
ScreenLockerContext.screenOffCalled = false
// 避免有的其他应用盖我们,尽量再启动一次。也避免灭屏广告收不到的问题。
if ((ScreenLockerContext.canShowScreenLockerWhenScreenOn && shouldInvokeScreenLockerUiWhenScreenOn())) {
if (forbidShowWhenScreenOff || shouldShowLockerAfterUserPresent()) {
// start on thread...
showScreenLocker(
context,
ScreenLockerConstants.SHOW_REASON_SCREEN_ON
)
} else {
BaseApp.get().taskPool.launchOnUiDelayed(1000L, taskTagShowScreenLocker) {
if (/*shouldShowLockerAfterUserPresent || */ScreenLockerContext.canShowScreenLockerWhenScreenOn && shouldInvokeScreenLockerUiWhenScreenOn()) {
showScreenLocker(
context,
ScreenLockerConstants.SHOW_REASON_SCREEN_ON
)
} else {
if (BuildConfig.DEBUG) Log.w(
TAG,
"onReceive: screen is on. but ignored showScreenLocker() invocation. Root cause = condition checking... A 2 " +
"\nScreenLockerContext.canShowScreenLockerWhenScreenOn = ${ScreenLockerContext.canShowScreenLockerWhenScreenOn}" +
"\nshouldInvokeScreenLockerUiWhenScreenOn() = ${shouldInvokeScreenLockerUiWhenScreenOn()}"
)
}
}
}
} else {
if (BuildConfig.DEBUG) Log.w(
TAG,
"onReceive: screen is on. but ignored showScreenLocker() invocation. Root cause = condition checking... A 1" +
"\nScreenLockerContext.canShowScreenLockerWhenScreenOn = ${ScreenLockerContext.canShowScreenLockerWhenScreenOn}" +
"\nshouldInvokeScreenLockerUiWhenScreenOn() = ${shouldInvokeScreenLockerUiWhenScreenOn()}"
)
}
}
private fun onHandleScreenOff(context: Context, isPowerDisconnected: Boolean = false) {
if (BuildConfig.DEBUG) Log.i(
TAG,
"onHandleScreenOff() called with: thread = [${Thread.currentThread()}], isPowerDisconnected = [$isPowerDisconnected]"
)
try {
BrandEventLogger.logEventWithBrand(
BaseApp.instance.eventLogger,
ScreenLockerConstants.EVENT_SCREEN_LOCKER_SCREEN_OFF
)
ScreenLockerContext.lastScreenOffTime = System.currentTimeMillis()
ScreenLockerContext.screenOffCalled = true
ScreenLockerContext.canShowScreenLockerWhenScreenOn =
!shouldShowLockerAfterUserPresent() || forbidShowWhenScreenOff
sendUserUnlocked = ScreenLockerUtils.hasSystemLockScreen(context)
BaseApp.get().taskPool.cancel(taskTagShowScreenLocker)
} catch (e: Throwable) {
if (BuildConfig.DEBUG) Log.e(TAG, "onHandleScreenOff: ERROR", e)
}
if (!isPowerDisconnected || !tryShowChargeReportDialog(context)) {
if (!shouldShowLockerAfterUserPresent() && !forbidShowWhenScreenOff) {
showScreenLocker(
context,
ScreenLockerConstants.SHOW_REASON_SCREEN_OFF
)
}
}
}
private val lockScreenCallback = object : ScreenStatusMonitor.ScreenStatusListener {
override fun onScreenOff() {
BaseApp.instance.eventLogger.logEvent(ScreenLockerConstants.EVENT_SCREEN_LOCKER_RECEIVE3)
onHandleScreenOff(BaseApp.instance)
}
override fun onScreenOn() {
BaseApp.instance.eventLogger.logEvent(ScreenLockerConstants.EVENT_SCREEN_LOCKER_RECEIVE3)
onHandleScreenOn(BaseApp.instance)
}
override fun onUserPresent() {
BaseApp.instance.eventLogger.logEvent(ScreenLockerConstants.EVENT_SCREEN_LOCKER_RECEIVE3)
onHandleUserPresent(BaseApp.instance)
}
}
private fun shouldInvokeScreenLockerUiWhenScreenOn(): Boolean {
return forbidShowWhenScreenOff || (ScreenLockerContext.observerInUse.isAlive && !ScreenLockerContext.observerInUse.isTouching && !ScreenLockerContext.observerInUse.isFinishing)
}
private val phoneStateListener: PhoneStateListener = object : PhoneStateListener() {
override fun onCallStateChanged(state: Int, incomingNumber: String?) {
if (BuildConfig.DEBUG) Log.d(
TAG,
"onCallStateChanged() called with: state = [$state], incomingNumber = [$incomingNumber]"
)
when (state) {
TelephonyManager.CALL_STATE_RINGING, TelephonyManager.CALL_STATE_OFFHOOK -> {
CoreAdContext.callProcessing = true
BaseApp.get().bus.post(ScreenLockerEvents.CALL_INCOMING)
}
TelephonyManager.CALL_STATE_IDLE -> {
CoreAdContext.callProcessing = false
}
}
super.onCallStateChanged(state, incomingNumber)
}
}
private fun showScreenLocker(context: Context, reason: Int) {
if (BuildConfig.DEBUG) Log.d(
TAG,
"showScreenLocker() called with: context = [$context], thread = ${Thread.currentThread()}",
java.lang.RuntimeException()
)
BaseApp.get().taskPool.cancel(taskTagShowScreenLocker)
// if (isScreenLockerActive) {
// if (BuildConfig.DEBUG) Log.w(TAG, "showScreenLocker: ScreenLocker is ACTIVE.")
// ScreenLockerActivity.start(context)
// return
// }
BrandEventLogger.logEventWithBrand(BaseApp.instance.eventLogger,
ScreenLockerConstants.EVENT_SCREEN_LOCKER_START_PREINVOKE,
EventParams().apply {
reason(reason.toString())
}
)
if (CoreAdContext.highPriorityEventBlockedPopup || CoreAdContext.callProcessing) {
if (BuildConfig.DEBUG) Log.w(
TAG,
"showScreenLocker: highPriorityEventBlockedPopup = ${CoreAdContext.highPriorityEventBlockedPopup}, callProcessing = ${CoreAdContext.callProcessing}"
)
return
}
startScreenLockerForced(
context,
reason,
0
)
}
@SuppressLint("CheckResult")
fun start(app: Application) {
if (BuildConfig.DEBUG) Log.d(TAG, "start() called started = $started")
if (!started) {
started = true
val filter = IntentFilter()
filter.addAction(Intent.ACTION_USER_FOREGROUND)
filter.addAction(Intent.ACTION_USER_BACKGROUND)
filter.addAction(Intent.ACTION_POWER_CONNECTED)
filter.addAction(Intent.ACTION_POWER_DISCONNECTED)
BrandEventLogger.logEventWithBrand(
BaseApp.instance.eventLogger,
ScreenLockerConstants.EVENT_SCREEN_LOCKER_INIT,
EventParams()
)
try {
context.registerReceiver(lockScreenReceiver, filter)
} catch (e: Exception) {
if (BuildConfig.DEBUG) Log.e(TAG, "start: ERROR", e)
}
BaseApp.instance.eventLogger.logEvent(ScreenLockerConstants.EVENT_SCREEN_LOCKER_INIT_2)
if (useCallback) {
ScreenStatusMonitor.getInstance().addCallback(lockScreenCallback)
} else {
ScreenMonitor.getInstance().register(null, lockScreenReceiver)
}
if (ScreenLockerUtils.canShowScreenLocker(context)) {
ScreenLockerContext.screenOffCalled = true
sendUserUnlocked = ScreenLockerUtils.hasSystemLockScreen(context)
showScreenLocker(
context,
ScreenLockerConstants.SHOW_REASON_SCREEN_OFF
)
}
BusEventObserver.observe(BaseApp.get().bus, this::onBusEvent)
val telephonyManager =
context.getSystemService(Context.TELEPHONY_SERVICE) as TelephonyManager
telephonyManager.listen(phoneStateListener, PhoneStateListener.LISTEN_CALL_STATE)
CoreAdContext.shouldCallOnUnlockWhenUserPresent = !shouldShowLockerAfterUserPresent()
}
app.registerActivityLifecycleCallbacks(object : AbsActivityLifecycleCallbacks() {
override fun onActivityStarted(activity: Activity) {
super.onActivityStarted(activity)
if (BuildConfig.DEBUG) Log.w(TAG, "onActivityStarted: activity = $activity")
}
override fun onActivityCreated(activity: Activity, savedInstanceState: Bundle?) {
super.onActivityCreated(activity, savedInstanceState)
if (BuildConfig.DEBUG) Log.w(TAG, "onActivityCreated: activity = $activity")
// some activities may launched from screen locker activity even when device is still locked.
if (activity !is OutAppActivity) {
if (BuildConfig.DEBUG) Log.i(
TAG,
"onActivityCreated: Adding SHOW_WHEN_LOCKED = true... activity = $activity"
)
@Suppress("DEPRECATION")
activity.window.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED)
}
}
override fun onActivityResumed(activity: Activity) {
super.onActivityResumed(activity)
if (BuildConfig.DEBUG) Log.w(TAG, "onActivityResumed: activity = $activity")
// avoid back ad shows on top of system lock screen
if (activity is ScreenActivity) {
// CoreAdContext.lastShowScreenLockerTimestamp = System.currentTimeMillis()
// if (BuildConfig.DEBUG) Log.i(TAG, "onActivityResumed: activity = $activity")
}
}
override fun onActivityPaused(activity: Activity) {
super.onActivityPaused(activity)
if (BuildConfig.DEBUG) Log.w(TAG, "onActivityPaused: activity = $activity")
// avoid back ad shows on top of system lock screen
if (activity is ScreenActivity) {
// CoreAdContext.lastShowScreenLockerTimestamp = System.currentTimeMillis()
}
}
override fun onActivityDestroyed(activity: Activity) {
super.onActivityDestroyed(activity)
if (BuildConfig.DEBUG) Log.w(TAG, "onActivityDestroyed: activity = $activity")
}
})
}
private fun onBusEvent(event: BusEvent) {
if (BuildConfig.DEBUG) Log.d(TAG, "onBusEvent() called with: event = [$event]")
when (event.event) {
ScreenLockerEvents.SCREENLOCKER_UNLOCKED_BY_USER -> {
ScreenLockerContext.canShowScreenLockerWhenScreenOn = false
}
}
}
@Suppress("unused")
fun stop() {
if (BuildConfig.DEBUG) Log.d(TAG, "stop() called started = $started")
if (started) {
started = false
try {
context.unregisterReceiver(lockScreenReceiver)
} catch (e: Exception) {
if (BuildConfig.DEBUG) Log.d(TAG, "stop() called ")
}
if (useCallback) {
ScreenStatusMonitor.getInstance().removeCallback(lockScreenCallback)
} else {
ScreenMonitor.getInstance().unregister(null, lockScreenReceiver)
}
try {
val telephonyManager =
context.getSystemService(Context.TELEPHONY_SERVICE) as TelephonyManager
telephonyManager.listen(phoneStateListener, PhoneStateListener.LISTEN_NONE)
} catch (e: Exception) {
if (BuildConfig.DEBUG) Log.e(TAG, "[ERROR]", e)
}
}
}
private fun tryShowChargeReportDialog(@Suppress("UNUSED_PARAMETER") context: Context): Boolean {
// var handled = false
// if (BuildConfig.DEBUG) Log.d(
// TAG,
// "tryShowChargeReportDialog() currentTimeMillis: " + System.currentTimeMillis() + ", ChargeStartTime: " + ChargeReport.getChargeStartTime()
// )
// if (ChargeReport.isChargeReportOpened(context) && ChargeReport.getChargeStartTime() > 0 && System.currentTimeMillis() - ChargeReport.getChargeStartTime() >= 2 * 60 * 1000) {
//// Intent chargeReportIntent = new Intent(context, ActivityChargeReport.class);
// val chargeReportIntent = Intent(context, ActivityChargeReportDg::class.java)
// chargeReportIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
// try {
// AdHelper.config.avoidRestartSelfOnUserLeaveHint = true
// context.startActivity(chargeReportIntent)
// ActionTime.setTimeBySPKey(context, ActionTime.SP_Pop_Last_Time)
// handled = true
// } catch (e: ActivityNotFoundException) {
// if (BuildConfig.DEBUG) Log.d(TAG, "tryShowChargeReportDialog() exception: $e")
// AnalyticsLogger.logException(e)
// }
// } else {
// if (BuildConfig.DEBUG) Log.d(TAG, "tryShowChargeReportDialog() condition false")
// Thread { ChargeReport.reset(context) }.start()
// }
// return handled
return false
}
}
package com.mints.flowbox.screen.settings
import net.settings.IRemoteKeys
object ScreenLockerRemoteKeys : IRemoteKeys {
const val KEY_DISMISS_WITH_SYSTEM_KEYGUARD = "ext_dd_dwsk"
const val KEY_AD_EXPIRE_INTERVAL = "ext_dd_aexpint"
const val KEY_AD_POPULATE_INTERVAL = "ext_dd_alint"
const val KEY_RED_PACKET_POPUP_INTERVAL = "ext_dd_rp_ppint"
}
\ No newline at end of file
package com.mints.flowbox.screen.settings
import net.cloud.RemoteProxy
import net.common.minutesMillis
import net.settings.AppSettings
import net.settings.ISettings
object ScreenLockerSettings {
const val KEY_ENABLED = "dd_ena"
const val KEY_RED_PACKET_POPUP_TIME = "dd_rp_pptime"
const val ENABLED_DEFAULT = ISettings.BOOLEAN_TRUE
fun isEnabled(): Boolean {
return AppSettings.global.readInt(
KEY_ENABLED,
ENABLED_DEFAULT
) == ISettings.BOOLEAN_TRUE
}
fun isDismissWithSystemKeyguard(): Boolean {
return RemoteProxy.readInt(ScreenLockerRemoteKeys.KEY_DISMISS_WITH_SYSTEM_KEYGUARD, ISettings.BOOLEAN_FALSE) == ISettings.BOOLEAN_TRUE
}
/**
* 如果广告显示超过一定时长,无论如何我都换一个
*/
fun getAdExpireInterval(): Long {
return RemoteProxy.readLong(ScreenLockerRemoteKeys.KEY_AD_EXPIRE_INTERVAL, 45.minutesMillis())
}
fun getAdPopulateInterval(): Long {
return RemoteProxy.readLong(ScreenLockerRemoteKeys.KEY_AD_POPULATE_INTERVAL, 1.minutesMillis())
}
fun getRedPacketPopupInterval(): Long {
return RemoteProxy.readLong(ScreenLockerRemoteKeys.KEY_RED_PACKET_POPUP_INTERVAL, 30.minutesMillis())
}
var lastRedPacketPopupPopupTime: Long
get() = AppSettings.app.readLong(KEY_RED_PACKET_POPUP_TIME, 0L)
set(value) = AppSettings.app.writeLong(KEY_RED_PACKET_POPUP_TIME, value)
}
\ No newline at end of file
......@@ -411,19 +411,17 @@ class MainActivity : BaseActivity(), MainView, View.OnClickListener {
)
}
request.subscribe { granted: Boolean ->
if (granted) {
// 预加载信息流
ExpressManager.loadExpress(false)
val bundle = Bundle()
bundle.putString(
IncreasespeedActivity.INCREASE_TYPE,
IncreasespeedActivity.INCREASE_BOOST
)
readyGo(IncreasespeedActivity::class.java)
} else {
showMissingPermissionDialog("位置,存储")
}
// 预加载信息流
ExpressManager.loadExpress(false)
val bundle = Bundle()
bundle.putString(
IncreasespeedActivity.INCREASE_TYPE,
IncreasespeedActivity.INCREASE_BOOST
)
readyGo(IncreasespeedActivity::class.java)
}
}
......
......@@ -7,46 +7,73 @@ import android.graphics.drawable.ColorDrawable
import android.graphics.drawable.Drawable
import android.os.Build
import android.os.Bundle
import android.view.View
import android.view.Window
import android.view.WindowManager
import androidx.core.app.ActivityCompat
import com.main.ScreenMonitor
import com.mints.flowbox.R
import com.mints.flowbox.screen.ScreenLockerContext
import com.mints.flowbox.screen.ScreenLockerObserver
import com.mints.flowbox.utils.keepalive.ScreenLockerUtils
import com.mints.library.base.BaseSwipeBackCompatActivity
import com.mints.library.net.netstatus.NetUtils
import net.common.utils.CommonUtils
import net.phone.PhoneBrandUtils
import java.lang.Exception
/**
* 应用外Activity
* 应用外锁屏Activity
*/
abstract class OutAppActivity : BaseSwipeBackCompatActivity() {
abstract class OutAppActivity : BaseSwipeBackCompatActivity(), ScreenMonitor.Listener {
private var localScreenOnState = false
override fun onCreate(savedInstanceState: Bundle?) {
if (Build.VERSION.SDK_INT >= 28) {
setShowWhenLocked(true)
} else {
window.addFlags(524288)
}
window.addFlags(4194304)
if (Build.VERSION.SDK_INT >= 21) {
window.decorView.systemUiVisibility = 1792
super.onCreate(savedInstanceState)
ScreenLockerContext.changeOwnership(this)
val useNewWay = false
if (useNewWay && !ScreenLockerObserver.shouldShowLockerAfterUserPresent()) {
val window: Window = window
if (true) {
if (Build.VERSION.SDK_INT >= 28) {
setShowWhenLocked(true)
} else {
window.addFlags(524288)
}
}
window.addFlags(4194304)
if (Build.VERSION.SDK_INT >= 21) {
window.decorView.systemUiVisibility = 1792
}
}
super.onCreate(savedInstanceState)
localScreenOnState = CommonUtils.isScreenOn(this) == true
window.setWindowAnimations(R.style.AppTheme_LockScreen_Animation)
val layoutParams = window.attributes
window.attributes = layoutParams
window.statusBarColor = Color.TRANSPARENT
window.navigationBarColor = Color.TRANSPARENT
if (!useNewWay) {
window.setWindowAnimations(R.style.AppTheme_LockScreen_Animation)
val layoutParams = window.attributes
val isUsingShowWhenLockedFlag =
!ScreenLockerUtils.isLockScreenProtected(this) && !ScreenLockerObserver.shouldShowLockerAfterUserPresent()
ScreenLockerUtils.makeLockWindowFullScreen(
this,
layoutParams,
isUsingShowWhenLockedFlag
)
window.attributes = layoutParams
window.statusBarColor = Color.TRANSPARENT
window.navigationBarColor = Color.TRANSPARENT
resetWindowTransparentBackground()
// 设置锁屏页全屏
val isUsingShowWhenLockedFlag = !ScreenLockerUtils.isLockScreenProtected(this)
if (isUsingShowWhenLockedFlag) {
ScreenLockerUtils.updateWindowFlags(window.decorView)
ScreenLockerUtils.makeLockWindowFullScreen(this, window.attributes, true)
}
ScreenMonitor.getInstance().register(this, null)
resetWindowTransparentBackground()
overridePendingTransition(0, 0)
}
private fun resetWindowTransparentBackground() {
......@@ -85,4 +112,40 @@ abstract class OutAppActivity : BaseSwipeBackCompatActivity() {
override fun getLoadingTargetView() = null
override fun onResume() {
super.onResume()
ScreenLockerContext.observer(this).taskId = this.taskId
ScreenLockerContext.observer(this).isResumed = true
ScreenLockerContext.observer(this).isResumedSinceLastScreenOff = true
window.decorView.systemUiVisibility =
window.decorView.systemUiVisibility or View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY or
View.SYSTEM_UI_FLAG_IMMERSIVE or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION or
View.SYSTEM_UI_FLAG_FULLSCREEN or View.SYSTEM_UI_FLAG_LOW_PROFILE
}
override fun onPause() {
super.onPause()
ScreenLockerContext.observer(this).isResumed = false
ScreenLockerContext.observer(this).isFinishing = this.isFinishing
}
override fun onDestroy() {
super.onDestroy()
ScreenLockerContext.observer(this).taskId = null
ScreenMonitor.getInstance().unregister(this, null)
}
override fun onScreenOff() {
ScreenLockerContext.observer(this).isResumedSinceLastScreenOff = false
}
override fun onScreenOn() {
}
override fun onUserPresent() {
}
}
\ No newline at end of file
package com.mints.flowbox.utils.keepalive;
import android.app.Activity;
import android.app.ActivityManager;
import android.content.Context;
import android.content.Intent;
......@@ -11,7 +10,6 @@ import com.activityutil.BringToFrontListener;
import com.activityutil.ContextLike;
import com.mints.flowbox.MintsApplication;
import com.mints.flowbox.ui.activitys.keepalive.ScreenActivity;
import com.mints.flowbox.utils.ForegroundOrBackground;
import com.mints.flowbox.utils.LogUtil;
import net.phone.PhoneBrandUtils;
......@@ -20,36 +18,12 @@ import org.jetbrains.annotations.NotNull;
import java.util.List;
/**
* @author jyx
* @date 2021/7/10
* @des
*/
public class IntentUtils {
public static final String TAG = "IntentUtils";
public static void startActivity2(Intent intent) {
if ((PhoneBrandUtils.isHuaweiOriginal() || isHarmonyOs())) {
if (ForegroundOrBackground.getApp_activity() != null) {
startActivity(intent);
return;
}
}
ActivityManagerProxy.INSTANCE.bringToFront(new BringToFrontListener() {
@Override
public void onCall(@NotNull ContextLike contextLike) {
contextLike.startActivity(intent);
}
@Override
public void onResult(boolean b) {
}
}, null);
}
public static void startScreenActivity(Intent intent) {
if (!shouldShowLockerAfterUserPresent()) {
// if (shouldShowLockerAfterUserPresent()) {
ActivityManagerProxy.INSTANCE.bringToFront(new BringToFrontListener() {
@Override
public void onCall(@NotNull ContextLike contextLike) {
......@@ -60,31 +34,20 @@ public class IntentUtils {
public void onResult(boolean b) {
}
}, null);
} else {
ActivityManagerProxy.INSTANCE.bringActivityToFront(
MintsApplication.getContext(),
ScreenActivity.class,
intent
);
}
// } else {
// ActivityManagerProxy.INSTANCE.bringActivityToFront(
// MintsApplication.getContext(),
// ScreenActivity.class,
// intent
// );
// ActivityManagerProxy.INSTANCE.ensureActive();
// }
}
public static boolean shouldShowLockerAfterUserPresent() {
return PhoneBrandUtils.isOppo() && PhoneBrandUtils.isLockScreenProtected();
}
public static void startActivity(Intent intent) {
if (ForegroundOrBackground.getMain_activity() != null) {
Activity activity = ForegroundOrBackground.getMain_activity();
moveToFront(activity);
activity.startActivity(intent);
activity.moveTaskToBack(true);
return;
}
// startActivity3(intent);
}
public static void startActivity3(Intent intent) {
try {
ActivityManagerProxy.INSTANCE.bringToFront(new BringToFrontListener() {
......@@ -95,10 +58,7 @@ public class IntentUtils {
@Override
public void onResult(boolean b) {
if (!b) {
LogUtil.d("AAAAAAa");
startActivity(intent);
}
LogUtil.d("AAAAAAA -> " + b);
}
}, null);
} catch (Exception e) {
......@@ -149,4 +109,4 @@ public class IntentUtils {
}
}
}
}
\ No newline at end of file
......@@ -184,7 +184,6 @@
android:layout_gravity="center_horizontal"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginBottom="10dp"
android:background="@color/color_main"
android:gravity="center"
android:text="同意"
......
......@@ -29,7 +29,7 @@ RELEASE_UMENG_KEY=60d2ef4d8a102159db781cd3
RELEASE_JPUSH_KEY=d9e939e7ec22a9e11dcfc345
android.useAndroidX=true
android.enableJetifier=true
android.useNewApkCreator=false
android.useNewApkCreator=true
####### 保活相关 #######
# vvvvvv 下面不要动!!!!
APPLICATION_ID=
......
include ':app'
include ':shareSdkLib'
\ No newline at end of file
include ':shareSdkLib'
include ':screenlocker'
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment