AppUtils.kt 2.4 KB
Newer Older
1
package com.ydl.ydlcommon.utils
konghaorui committed
2 3 4

import android.app.ActivityManager
import android.content.Context
5
import com.ydl.ydlcommon.base.BaseApp
6
import com.ydl.ydlcommon.base.config.YDLConstants.ENV_NEW_TEST
7 8 9
import com.ydl.ydlcommon.base.config.YDLConstants.ENV_TEST
import com.ydl.ydlcommon.data.PlatformDataManager
import com.ydl.ydlcommon.modular.ModularServiceManager
霍志良 committed
10
import com.yidianling.common.tools.LogUtil
11 12
import com.yidianling.common.tools.RxAppTool
import com.yidianling.common.tools.RxDeviceTool
konghaorui committed
13 14 15 16 17 18 19 20 21 22 23

/**
 * Created by haorui on 2019/4/25.
 * Des:
 */
object AppUtils {
    fun isServiceRunning(context: Context, className: String): Boolean {
        if (className.isEmpty()) {
            return false
        }
        var isRunning: Boolean = false
24 25 26 27
        val activityManager: ActivityManager =
            context.getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager
        val serviceList: List<ActivityManager.RunningServiceInfo> =
            activityManager.getRunningServices(30)
konghaorui committed
28 29 30 31 32 33 34 35 36 37 38 39
        if (serviceList.isEmpty()) {
            return false
        }
        serviceList.forEach { item ->
            if (item.service.className == className) {
                isRunning = true
                return@forEach
            }
        }
        return isRunning
    }

40 41 42 43
    /**
     * 获取http请求公用参数
     *
     */
44
    fun getHttpCommonParams(): Map<String, Any> {
45 46
        val mMap = mutableMapOf<String, Any>()
        val appEnv = BaseApp.instance.getGlobalConfig().appEnv
霍志良 committed
47
        var isDevelopment = "0"
48

49
        if (ENV_TEST == appEnv) {
霍志良 committed
50
            isDevelopment = "1"
51
        } else if (ENV_NEW_TEST == appEnv) {
霍志良 committed
52
            isDevelopment = "2"
53
        }
霍志良 committed
54
        LogUtil.e("aaaaaapputils"+isDevelopment+"环境"+appEnv)
55 56 57 58 59 60

        val osBuild = "${RxDeviceTool.getBuildBrandModel()},${RxDeviceTool.getSDKVersionName()},${
            RxAppTool.getAppVersionName(
                BaseApp.getApp()
            )
        }"
61 62 63

        val loginBean = ModularServiceManager.getPlatformUserService()?.getUser()

64 65 66
        mMap["isDevelopment"] = isDevelopment
        mMap["uid"] = loginBean?.userId ?: ""
        mMap["accessToken"] = loginBean?.token ?: ""
67 68 69 70 71 72 73
        mMap["isFromApp"] = "1"
        mMap["version"] = RxAppTool.getAppVersionName(BaseApp.getApp())
        mMap["osBuild"] = osBuild
        mMap["ffrom"] = PlatformDataManager.getRam().getChannelName()
        mMap["osType"] = "android"
        return mMap
    }
konghaorui committed
74
}