196 lines
8.0 KiB
Kotlin
196 lines
8.0 KiB
Kotlin
package com.arpa.hndahesudintocctmsdriver.base
|
||
|
||
import android.app.ActivityManager
|
||
import android.app.Application
|
||
import android.content.Context
|
||
import android.content.Intent
|
||
import android.os.Process
|
||
import android.util.Log
|
||
import cn.jiguang.api.utils.JCollectionAuth
|
||
import cn.jpush.android.api.JPushInterface
|
||
import com.alct.mdp.MDPLocationCollectionManager
|
||
import com.arpa.hndahesudintocctmsdriver.BuildConfig
|
||
import com.arpa.hndahesudintocctmsdriver.net.Api
|
||
import com.arpa.hndahesudintocctmsdriver.oss.OssServiceUtil
|
||
import com.arpa.hndahesudintocctmsdriver.third.JTTProcess
|
||
import com.arpa.hndahesudintocctmsdriver.third.PlayerMusicService
|
||
import com.arpa.hndahesudintocctmsdriver.third.SPUtil
|
||
import com.arpa.hndahesudintocctmsdriver.utils.SPUtils
|
||
import com.arpa.mylibrary.CommonBaseLibrary
|
||
import com.github.gzuliyujiang.dialog.DialogConfig
|
||
import com.github.gzuliyujiang.dialog.DialogStyle
|
||
import com.tencent.bugly.crashreport.CrashReport
|
||
import com.umeng.commonsdk.UMConfigure
|
||
import com.umeng.umverify.UMVerifyHelper
|
||
import com.umeng.umverify.listener.UMTokenResultListener
|
||
import java.security.SecureRandom
|
||
import java.security.cert.X509Certificate
|
||
import javax.net.ssl.HttpsURLConnection
|
||
import javax.net.ssl.SSLContext
|
||
import javax.net.ssl.TrustManager
|
||
import javax.net.ssl.X509TrustManager
|
||
|
||
|
||
class App : Application() {
|
||
override fun onCreate() {
|
||
super.onCreate()
|
||
app = this
|
||
CommonBaseLibrary.getInstance().init(this, Api.BASE_URL)
|
||
//选择器样式切换
|
||
DialogConfig.setDialogStyle(DialogStyle.One)
|
||
if (BuildConfig.DEBUG) {
|
||
// CrashHandler.getInstance().init(this);
|
||
// CrashHandler2.getInstance().init(getApplicationContext());
|
||
}
|
||
CrashReport.initCrashReport(applicationContext, AppConfig.BUGLY_APP_ID, false);
|
||
|
||
OssServiceUtil.getInstance().init();
|
||
|
||
initUmeng()
|
||
|
||
initJpush()
|
||
|
||
initThird()
|
||
|
||
// var pendingIntent: PendingIntent = getActivity(
|
||
// applicationContext, 0,
|
||
// Intent(applicationContext, HomeActivity::class.java),
|
||
// FLAG_UPDATE_CURRENT
|
||
// )
|
||
// Cactus.instance
|
||
// .isDebug(true)
|
||
// .setTitle("大河好运")
|
||
// .setContent("大河好运司机端为您提供服务")
|
||
// .setSmallIcon(R.mipmap.app_icon)
|
||
// .setChannelId(AppUtils.getAppPackageName())
|
||
// .setChannelName(AppUtils.getAppPackageName())
|
||
// //可选,设置通知栏点击事件
|
||
// .setPendingIntent(pendingIntent)
|
||
// .setBackgroundMusicEnabled(true)//可选,退到后台是否可以播放音乐
|
||
// .setMusicInterval(20000)//设置音乐间隔时间,时间间隔越长,越省电,默认间隔时间是0
|
||
//// .setMusicId(R.raw.main) //可选,设置音乐
|
||
//// .addCallback(new CactusCallback())//可选,运行时回调
|
||
//// .setCrashRestartUIEnabled(true) //可选,设置奔溃可以重启,google原生rom android 10以下可以正常重启
|
||
//// .setNotification(MyNotification.getInstance().getNotification(this))
|
||
// .hideNotificationAfterO(true)
|
||
// .addCallback {
|
||
// OrderUtils.getInstance().upLocation(applicationContext)
|
||
// }
|
||
// .addBackgroundCallback(object : CactusBackgroundCallback {
|
||
//
|
||
// override fun onBackground(background: Boolean) {
|
||
// if (background) {
|
||
//// getBillLocation();
|
||
// }
|
||
// }
|
||
// })
|
||
// .register(this)
|
||
}
|
||
|
||
override fun attachBaseContext(base: Context) {
|
||
super.attachBaseContext(base)
|
||
}
|
||
|
||
private fun initThird() {
|
||
val state: String = SPUtil.getSP(this, "state_data", "authorization_state")
|
||
if ("1" == state) {
|
||
try {
|
||
//安联初始化
|
||
if (packageName == getCurrentProcessName(this)) {
|
||
//Log.e("--使用的测试环境--",BuildConfig.OPEN_API_URL);
|
||
MDPLocationCollectionManager.initialize(applicationContext, BuildConfig.OPEN_AL_URL)
|
||
MDPLocationCollectionManager.initServiceProcessProguard(applicationContext) // 保活代码
|
||
startService(Intent(this, PlayerMusicService::class.java)) // 保活代码
|
||
}
|
||
|
||
//初始化交通厅
|
||
JTTProcess.init(this)
|
||
SPUtil.insSP(this, "state_data", "authorization_state", "1")
|
||
} catch (e: Exception) {
|
||
SPUtil.insSP(this, "state_data", "authorization_state", "0")
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
//忽略https的证书校验
|
||
fun handleSSLHandshake() {
|
||
try {
|
||
val trustAllCerts = arrayOf<TrustManager>(object : X509TrustManager {
|
||
override fun getAcceptedIssuers(): Array<X509Certificate?> {
|
||
return arrayOfNulls(0)
|
||
}
|
||
|
||
override fun checkClientTrusted(certs: Array<X509Certificate>, authType: String) {}
|
||
override fun checkServerTrusted(certs: Array<X509Certificate>, authType: String) {}
|
||
})
|
||
val sc = SSLContext.getInstance("TLS")
|
||
// trustAllCerts信任所有的证书
|
||
sc.init(null, trustAllCerts, SecureRandom())
|
||
HttpsURLConnection.setDefaultSSLSocketFactory(sc.socketFactory)
|
||
HttpsURLConnection.setDefaultHostnameVerifier { hostname, session -> true }
|
||
} catch (ignored: Exception) {
|
||
}
|
||
}
|
||
|
||
private fun initUmeng() {
|
||
// thread {
|
||
//友盟
|
||
UMConfigure.preInit(this, AppConfig.APP_KEY, "Umeng");
|
||
|
||
UMConfigure.init(
|
||
this,
|
||
AppConfig.APP_KEY,
|
||
"Umeng",
|
||
UMConfigure.DEVICE_TYPE_PHONE,
|
||
""
|
||
)
|
||
//实名认证
|
||
val authHelper = UMVerifyHelper.getInstance(this, object : UMTokenResultListener {
|
||
override fun onTokenSuccess(ret: String) {
|
||
Log.e("Umenginit", "onTokenSuccess: $ret")
|
||
}
|
||
|
||
override fun onTokenFailed(ret: String) {
|
||
Log.e("Umenginit", "onTokenFailed: $ret")
|
||
}
|
||
})
|
||
authHelper.setLoggerEnable(true)
|
||
// authHelper.setAuthSDKInfo("iiBVGHSKbUML/NTbj187eM1N1KMvRzh1sJbM+2FMbV7FNOnmngDlPr2reqlvouhK/8dXcaNGJuI9B+Kv7C6IlBMoGE0PMVWvwY754T8zxSgSfLUM6s7e0dVxmtMFRrCDawKBiv6g/5+X1mSK5OXNG+H//8rtDDf0vePyUUPCAU26tIX/7BCJ4wvUjobAHBDtSbMMhzqWR5MC7jTCnR0k1OwwvEYxIH6jZuRqT4QgBBO4AMKvFjboqj3rsrr5uE6Gn28fWQrBBrOkPS830GnZFU8ND/0LedGgTlMllBAXLy0gbZZ/8LKJOQ==")
|
||
authHelper.setAuthSDKInfo("4RrSpqTu/QgE8ZoIvQqZvfgDcSEqof0gQpYDV1xvLyJ+DYqwZlG6tlTZIrtzAjCKgOOunLRhIHpJnMwLvNdRIL01nGnTFF7N/tJbgUORGoGrpviSeH+un8becKp+rK7Jak+Ep+cZzsTiPuGwFDZ5txZzShCt5XHjbMwIgL7RO+c3NS2vIftq+1DmLZCkIm65/Ky7yqw97qqI6fEWwrCIXI8lJbEr2TrOvn+snW5KTNm0i5qb0Rr3k2nY1kgU/C6cV/s8O9cLChBH9PnTVWP/Q5M3Quvim00T2a1smUJQPZQyuDVpC8vGcJ1EiAkogoPjbCrJxjpdjyE=")
|
||
|
||
// }.start()
|
||
|
||
}
|
||
|
||
private fun initJpush(){
|
||
if (!SPUtils.instance.getIsFirstOpenApp(applicationContext)){
|
||
//打开日志开关,发布版本建议关闭
|
||
JPushInterface.setDebugMode(true)
|
||
|
||
//同意隐私政策,同意开启推送业务开关
|
||
JCollectionAuth.setAuth(this, true)
|
||
// 初始化SDK
|
||
// 初始化SDK
|
||
JPushInterface.init(this)
|
||
}
|
||
}
|
||
|
||
companion object {
|
||
var app: App? = null
|
||
}
|
||
|
||
fun getCurrentProcessName(context: Context): String? {
|
||
var currentProcessName = ""
|
||
val pid = Process.myPid()
|
||
val mActivityManager = context.getSystemService(ACTIVITY_SERVICE) as ActivityManager
|
||
if (mActivityManager.runningAppProcesses != null && mActivityManager.runningAppProcesses.size > 0) {
|
||
for (appProcess in mActivityManager.runningAppProcesses) {
|
||
if (appProcess.pid == pid) {
|
||
currentProcessName = appProcess.processName
|
||
}
|
||
}
|
||
}
|
||
return currentProcessName
|
||
}
|
||
} |