Ver código fonte

feat: 启动优化二期 (#42)

Co-authored-by: DoggyZhang <doggyzhang1219@gmail.com>
DoggyZhang 5 meses atrás
pai
commit
59153957dc

+ 1 - 1
app/build.gradle

@@ -467,7 +467,7 @@ dependencies {
 
     api project(":frame:room")
     api project(":frame:imkit")
-    api project(':frame:startup')
+    api libs.frame.startup
 
     api libs.frame.locale
     api libs.frame.push

+ 1 - 0
app/dependencies/releaseRuntimeClasspath.txt

@@ -260,6 +260,7 @@ com.wenext.android:frame-security:5.1.5
 com.wenext.android:frame-share:5.1.18-yoki
 com.wenext.android:frame-sound:5.1.4
 com.wenext.android:frame-spi:5.1.4
+com.wenext.android:frame-startup:5.1.0-yoki
 com.wenext.android:frame-statistics:5.1.7
 com.wenext.android:frame-storage:5.1.7-yoki
 com.wenext.android:frame-tceffect:5.1.8-yoki-beta

+ 3 - 0
app/src/main/java/com/adealink/weparty/App.kt

@@ -40,7 +40,10 @@ import com.adealink.frame.security.createSecurityService
 import com.adealink.frame.share.initShareManager
 import com.adealink.frame.sound.createSoundPlayer
 import com.adealink.frame.startup.dispatcher.StartTaskDispatcher
+import com.adealink.frame.startup.task.MainThreadStartUpTask
 import com.adealink.frame.startup.task.StartUpTask
+import com.adealink.frame.startup.task.SubNoWaitStartUpTask
+import com.adealink.frame.startup.task.SubWaitStartUpTask
 import com.adealink.frame.statistics.report.initStat
 import com.adealink.frame.storageService
 import com.adealink.frame.tceffect.TCEffectManager

+ 0 - 37
app/src/main/java/com/adealink/weparty/AppStartTask.kt

@@ -1,37 +0,0 @@
-package com.adealink.weparty
-
-import com.adealink.frame.startup.task.StartUpTask
-
-
-/**
- * 主线程启动任务(需要等待完成)
- */
-abstract class MainThreadStartUpTask : StartUpTask() {
-    override val isRunOnMainThread: Boolean = true
-
-    override fun needWait(): Boolean {
-        return true
-    }
-}
-
-/**
- * 子启动任务(需要等待完成)
- */
-abstract class SubWaitStartUpTask : StartUpTask() {
-    override val isRunOnMainThread: Boolean = false
-
-    override fun needWait(): Boolean {
-        return true
-    }
-}
-
-/**
- * 子启动任务(不需要等待完成)
- */
-abstract class SubNoWaitStartUpTask : StartUpTask() {
-    override val isRunOnMainThread: Boolean = false
-
-    override fun needWait(): Boolean {
-        return false
-    }
-}

+ 42 - 19
app/src/main/java/com/adealink/weparty/ui/MainStartUpFragment.kt

@@ -61,11 +61,41 @@ import kotlinx.coroutines.withContext
  */
 class MainStartUpFragment : BaseFragment() {
 
-    private val roomAttrViewModel by fastLazy { RoomModule.getRoomAttrViewModel(this.requireActivity()) }
-    private val familyInfoViewModel by fastLazy { FamilyModule.getFamilyInfoViewModel(this.requireActivity()) }
-    private val countryViewModel by fastLazy { ProfileModule.getCountryViewModel(this) }
-    private val walletViewModel by fastLazy { WalletModule.getWalletViewModel(requireActivity()) }
-    private val anchorViewModel by fastLazy { AnchorModule.getAnchorViewModel(requireActivity()) }
+    private val roomAttrViewModel by fastLazy {
+        if (activity?.isUiValid() == true) {
+            RoomModule.getRoomAttrViewModel(this.requireActivity())
+        } else {
+            null
+        }
+    }
+    private val familyInfoViewModel by fastLazy {
+        if (activity?.isUiValid() == true) {
+            FamilyModule.getFamilyInfoViewModel(this.requireActivity())
+        } else {
+            null
+        }
+    }
+    private val countryViewModel by fastLazy {
+        if (activity?.isUiValid() == true) {
+            ProfileModule.getCountryViewModel(this)
+        } else {
+            null
+        }
+    }
+    private val walletViewModel by fastLazy {
+        if (activity?.isUiValid() == true) {
+            WalletModule.getWalletViewModel(requireActivity())
+        } else {
+            null
+        }
+    }
+    private val anchorViewModel by fastLazy {
+        if (activity?.isUiValid() == true) {
+            AnchorModule.getAnchorViewModel(requireActivity())
+        } else {
+            null
+        }
+    }
 
     private suspend fun importantTask() {
         withContext(Dispatcher.WENEXT_THREAD_POOL) {
@@ -101,10 +131,10 @@ class MainStartUpFragment : BaseFragment() {
 //        GameModule.checkPlayingGame()
         checkNoReplyMessageIfNeed()
 
-        runIfUiValid { roomAttrViewModel?.getMyRoomInfo(true) }
-        runIfUiValid { countryViewModel?.getCountryList(true) }
-        runIfUiValid { walletViewModel?.checkThirdPayOpen() }
-        runIfUiValid { anchorViewModel?.getAnchorMessages() }
+        roomAttrViewModel?.getMyRoomInfo(true)
+        countryViewModel?.getCountryList(true)
+        walletViewModel?.checkThirdPayOpen()
+        anchorViewModel?.getAnchorMessages()
         installDynamicModule()
         Log.d(TAG, "importantLoad-end, cost:${SystemClock.elapsedRealtime() - startTs}ms")
     }
@@ -153,8 +183,8 @@ class MainStartUpFragment : BaseFragment() {
         CoupleModule.pullCoupleConfig()
         WalletModule.init()
         ProfileModule.pullUserNoteNameData()
-        runIfUiValid { walletViewModel?.addGlobalConfigListener() }
-        runIfUiValid { walletViewModel?.getUserChargeNotify() }
+        walletViewModel?.addGlobalConfigListener()
+        walletViewModel?.getUserChargeNotify()
         globalConfigManager.getAllGlobalConfig(true)
         GameModule.initRocket()
         Log.d(TAG, "minorLoad-end, cost:${SystemClock.elapsedRealtime() - startTs}ms")
@@ -180,7 +210,7 @@ class MainStartUpFragment : BaseFragment() {
         RoomTaskMonitor.init()
         HeadlineModule.init()
         OperationModule.checkSuperSupporterWhatsAppFillStatus()
-        runIfUiValid { familyInfoViewModel?.getApplyJoinFamilyUnHandleNum() }
+        familyInfoViewModel?.getApplyJoinFamilyUnHandleNum()
         reportPushSwitch()
         lifecycleScope.launch {
             OperationModule.getRecommendOppositeSexPopup()
@@ -219,13 +249,6 @@ class MainStartUpFragment : BaseFragment() {
         PreloadWebViewManager.destroy()
     }
 
-    /**
-     * 要注意:MainStartUpFragment 是一个没有view的fragment
-     */
-    fun runIfUiValid(block: () -> Unit) {
-        if (activity?.isUiValid() == true) block()
-    }
-
     companion object {
         private const val TAG = "StartUpFragment"
 

+ 32 - 0
app/src/main/java/com/adealink/weparty/ui/home/HomeFragment.kt

@@ -1,7 +1,9 @@
 package com.adealink.weparty.ui.home
 
+import android.annotation.SuppressLint
 import android.os.Bundle
 import android.view.LayoutInflater
+import android.view.View
 import android.view.ViewGroup
 import androidx.constraintlayout.widget.ConstraintLayout
 import androidx.core.view.updateLayoutParams
@@ -11,7 +13,9 @@ import com.adealink.frame.aab.util.getCompatColor
 import com.adealink.frame.aab.util.getCompatString
 import com.adealink.frame.base.Rlt
 import com.adealink.frame.ext.isViewBindingValid
+import com.adealink.frame.log.Log
 import com.adealink.frame.mvvm.view.viewBinding
+import com.adealink.frame.startup.DistributedLoadManager
 import com.adealink.weparty.AppModule
 import com.adealink.weparty.R
 import com.adealink.weparty.commonui.ext.dp
@@ -19,6 +23,8 @@ import com.adealink.weparty.commonui.ext.gone
 import com.adealink.weparty.commonui.ext.onSuccess
 import com.adealink.weparty.commonui.ext.show
 import com.adealink.weparty.commonui.util.isNavigationBarVisible
+import com.adealink.weparty.constant.TAG_TIME_APP_START
+import com.adealink.weparty.constant.logTime
 import com.adealink.weparty.databinding.FragmentHomeBinding
 import com.adealink.weparty.databinding.LayoutMainTabNormalBinding
 import com.adealink.weparty.databinding.PopupHomeMessageReplyBinding
@@ -49,6 +55,8 @@ import io.rong.imlib.IRongCoreCallback
 import io.rong.imlib.IRongCoreEnum
 import io.rong.imlib.model.Conversation
 import kotlinx.coroutines.launch
+import java.util.LinkedList
+import java.util.Queue
 
 class HomeFragment : BaseHomeFragment(R.layout.fragment_home), ITabManager by TabManager() {
 
@@ -72,6 +80,30 @@ class HomeFragment : BaseHomeFragment(R.layout.fragment_home), ITabManager by Ta
     override val tlTab: TabLayout
         get() = binding.tlTab
 
+    private lateinit var dlManager: DistributedLoadManager
+
+    @SuppressLint("MissingSuperCall")
+    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
+        logTime(TAG_TIME_APP_START, "HomeFragment.onViewCreated()")
+        dlManager = DistributedLoadManager(lifecycle, stepsLoad())
+        activity?.let { dlManager.triggerDistributedLoad(it) }
+    }
+
+    private fun stepsLoad(): Queue<Runnable> {
+        val steps = LinkedList<Runnable>()
+        steps.add(Runnable {
+            Log.d(TAG, "HomeFragment.step1: initViews, initComponents, observeViewModel")
+            initViews()
+            initComponents()
+            observeViewModel()
+        })
+        steps.add(Runnable {
+            Log.d(TAG, "HomeFragment.step2: loadData")
+            loadData()
+        })
+        return steps
+    }
+
     override fun initViews() {
         super.initViews()
         if (context?.let { isNavigationBarVisible(it) } == false) {

+ 0 - 1
frame/startup/.gitignore

@@ -1 +0,0 @@
-/build

+ 0 - 62
frame/startup/build.gradle

@@ -1,62 +0,0 @@
-plugins {
-    id 'com.android.library'
-    id 'org.jetbrains.kotlin.android'
-    id 'kotlin-parcelize'
-}
-
-android {
-    namespace 'com.adealink.frame.startup'
-    compileSdk libs.versions.compileSdk.get().toInteger()
-
-    defaultConfig {
-        minSdk libs.versions.minSdk.get().toInteger()
-        targetSdk libs.versions.targetSdk.get().toInteger()
-
-        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
-        consumerProguardFiles "consumer-rules.pro"
-        ndk {
-            abiFilters "armeabi-v7a"
-            abiFilters "arm64-v8a"
-        }
-    }
-
-    buildTypes {
-        release {
-            minifyEnabled false
-            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
-        }
-    }
-    compileOptions {
-        sourceCompatibility JavaVersion.VERSION_17
-        targetCompatibility JavaVersion.VERSION_17
-    }
-    kotlinOptions {
-        jvmTarget = JavaVersion.VERSION_17.majorVersion
-    }
-}
-
-dependencies {
-    //kotlin
-    implementation libs.kotlin.stdlib
-
-    //androidx
-    implementation libs.androidx.core.ktx
-
-    //frame
-    compileOnly libs.gson
-
-    //frame
-    compileOnly platform(libs.frame.bom)
-    compileOnly libs.frame.data
-    compileOnly libs.frame.zero
-    compileOnly libs.frame.base
-    compileOnly libs.frame.util
-    compileOnly libs.frame.coroutine
-    compileOnly libs.frame.log
-    compileOnly libs.frame.media
-
-    //test
-    testImplementation libs.junit
-    androidTestImplementation libs.androidx.junit
-    androidTestImplementation libs.androidx.espresso.core
-}

+ 0 - 0
frame/startup/consumer-rules.pro


+ 0 - 24
frame/startup/proguard-rules.pro

@@ -1,24 +0,0 @@
-# Add project specific ProGuard rules here.
-# You can control the set of applied configuration files using the
-# proguardFiles setting in build.gradle.
-#
-# For more details, see
-#   http://developer.android.com/guide/developing/tools/proguard.html
-
-# If your project uses WebView with JS, uncomment the following
-# and specify the fully qualified class name to the JavaScript interface
-# class:
-#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
-#   public *;
-#}
-
-# Uncomment this to preserve the line number information for
-# debugging stack traces.
-#-keepattributes SourceFile,LineNumberTable
-
-# If you keep the line number information, uncomment this to
-# hide the original source file name.
-#-renamesourcefileattribute SourceFile
-
-#Start Up
--keep public class * extends com.adealink.frame.startup.task.StartUpTask

+ 0 - 4
frame/startup/src/main/AndroidManifest.xml

@@ -1,4 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<manifest>
-
-</manifest>

+ 0 - 25
frame/startup/src/main/java/com/adealink/frame/startup/IAppStartUpTask.kt

@@ -1,25 +0,0 @@
-package com.adealink.frame.startup
-
-import android.app.Application
-
-interface IAppStartUpTask {
-    /**
-     * 应用启动(主线程任务)
-     */
-    fun appOnCreateMainTask(application: Application)
-
-    /**
-     * 应用启动(子线程任务)
-     */
-    fun appOnCreateSubTask(application: Application)
-
-    /**
-     * 页面启动(主线程任务)
-     */
-    fun activityOnCreateMainTask()
-
-    /**
-     * 页面启动(子线程任务)
-     */
-    fun activityOnCreateSubTask()
-}

+ 0 - 3
frame/startup/src/main/java/com/adealink/frame/startup/Tags.kt

@@ -1,3 +0,0 @@
-package com.adealink.frame.startup
-
-const val TAG_START_UP = "tag_start_up"

+ 0 - 21
frame/startup/src/main/java/com/adealink/frame/startup/base/TaskInterface.kt

@@ -1,21 +0,0 @@
-package com.adealink.frame.startup.base
-
-import android.os.Process
-import androidx.annotation.IntRange
-import com.adealink.frame.startup.task.StartUpTask
-import java.util.concurrent.Executor
-
-interface TaskInterface {
-    //线程的优先级
-    @IntRange(from = Process.THREAD_PRIORITY_FOREGROUND.toLong(), to = Process.THREAD_PRIORITY_LOWEST.toLong())
-    fun priority(): Int
-
-    //执行任务所在的线程池
-    fun runOnExecutor(): Executor
-
-    //所依赖的父亲们,父亲们执行完了,孩子才能执行
-    val dependsTaskList: List<Class<out StartUpTask>>
-
-    //在非主线程执行的Task是否需要在被调用await的时候等待,默认不需要,返回true即在Application的onCreate中阻塞,直到该任务执行完
-    fun needWait(): Boolean
-}

+ 0 - 242
frame/startup/src/main/java/com/adealink/frame/startup/dispatcher/StartTaskDispatcher.kt

@@ -1,242 +0,0 @@
-package com.adealink.frame.startup.dispatcher
-
-import android.os.Looper
-import com.adealink.frame.base.AppBaseInfo
-import com.adealink.frame.log.Log
-import com.adealink.frame.startup.TAG_START_UP
-import com.adealink.frame.startup.executor.TaskExecutorManager
-import com.adealink.frame.startup.runnable.StartTaskRunnable
-import com.adealink.frame.startup.task.StartUpTask
-import com.adealink.frame.startup.util.StartUpTaskSortUtil.getSortResult
-import com.adealink.frame.util.isMainThread
-import java.util.concurrent.CountDownLatch
-import java.util.concurrent.LinkedBlockingQueue
-import java.util.concurrent.TimeUnit
-import java.util.concurrent.atomic.AtomicInteger
-
-class StartTaskDispatcher private constructor() {
-    //存放每个Task  (key= Class < ? extends AppStartTask>)
-    private val mTaskHashMap = HashMap<Class<out StartUpTask>, StartUpTask>()
-
-    //每个Task的孩子 (key= Class < ? extends AppStartTask>)
-    private val mTaskChildHashMap = HashMap<Class<out StartUpTask>, MutableList<Class<out StartUpTask>>>()
-
-    //通过Add添加进来的所有任务
-    private val mStartTaskList: MutableList<StartUpTask> = ArrayList()
-
-    //拓扑排序后的所有任务
-    private var mSortTaskList: List<StartUpTask>? = null
-
-    //拓扑排序后的主线程的任务
-    private val mSortMainThreadTaskList: MutableList<StartUpTask> = ArrayList()
-    private val mMainThreadTaskCount = AtomicInteger()
-
-    //拓扑排序后的子线程的任务
-    private val mSortThreadPoolTaskList: MutableList<StartUpTask> = ArrayList()
-
-    //待执行的任务
-    private val mPendingTaskList: LinkedBlockingQueue<StartUpTask> = LinkedBlockingQueue()
-
-    //需要等待的任务总数,用于阻塞
-    private var mCountDownLatch: CountDownLatch? = null
-
-    //需要等待的任务总数,用于CountDownLatch
-    private val mNeedWaitCount = AtomicInteger()
-
-    //所有的任务开始时间,结束时间
-    private var mStartTime: Long = 0
-    private var mFinishTime: Long = 0
-    private var mAllTaskTime: Long = 0
-
-    //所有阻塞任务的总超时时间
-    private var mAllTaskWaitTimeOut = WAITING_TIME
-
-    fun setAllTaskWaitTimeOut(allTaskWaitTimeOut: Long): StartTaskDispatcher {
-        mAllTaskWaitTimeOut = allTaskWaitTimeOut
-        return this
-    }
-
-    fun addAppStartTask(startUpTask: StartUpTask?): StartTaskDispatcher {
-        if (startUpTask == null) {
-            throw RuntimeException("addAppStartTask() 传入的appStartTask为null")
-        }
-        mStartTaskList.add(startUpTask)
-        if (ifNeedWait(startUpTask)) {
-            mNeedWaitCount.getAndIncrement()
-        }
-        return this
-    }
-
-    fun start(): StartTaskDispatcher {
-        if (Looper.getMainLooper() != Looper.myLooper()) {
-            throw RuntimeException("start() must called on MainThread")
-        }
-        mStartTime = System.currentTimeMillis()
-        //拓扑排序,拿到排好序之后的任务队列
-        mSortTaskList = getSortResult(mStartTaskList, mTaskHashMap, mTaskChildHashMap)
-        initRealSortTask()
-        printSortTask()
-        mCountDownLatch = CountDownLatch(mNeedWaitCount.get())
-
-        Log.i(TAG_START_UP, "start(), mStartTime:$mStartTime, mNeedWaitCount:${mNeedWaitCount.get()}")
-        dispatchAppStartTask()
-        return this
-    }
-
-    //分别处理主线程和子线程的任务
-    private fun initRealSortTask() {
-        val sortTaskList = mSortTaskList
-        if (sortTaskList.isNullOrEmpty()) {
-            return
-        }
-        for (appStartTask in sortTaskList) {
-            if (appStartTask.isRunOnMainThread) {
-                mSortMainThreadTaskList.add(appStartTask)
-                mMainThreadTaskCount.getAndIncrement()
-            } else {
-                mSortThreadPoolTaskList.add(appStartTask)
-            }
-        }
-    }
-
-    //输出排好序的Task
-    private fun printSortTask() {
-        if (AppBaseInfo.isRelease) {
-            return
-        }
-        val sb = StringBuilder()
-        sb.append("printSortedTask():")
-        val sortTaskList = mSortTaskList ?: emptyList()
-        for (i in sortTaskList.indices) {
-            val taskName = sortTaskList[i].javaClass.simpleName
-            if (i != 0) {
-                sb.append("--->")
-            }
-            sb.append(taskName)
-        }
-        Log.i(TAG_START_UP, sb.toString())
-
-        val mainTaskSb = StringBuilder()
-        mainTaskSb.append("    MainThread Task List: ")
-        for (i in mSortMainThreadTaskList.indices) {
-            val taskName = mSortMainThreadTaskList[i].javaClass.simpleName
-            if (i != 0) {
-                mainTaskSb.append("--->")
-            }
-            mainTaskSb.append(taskName)
-        }
-        Log.i(TAG_START_UP, mainTaskSb.toString())
-
-        val threadTaskSb = StringBuilder()
-        threadTaskSb.append("    SubThread Task List: ")
-        for (i in mSortThreadPoolTaskList.indices) {
-            val taskName = mSortThreadPoolTaskList[i].javaClass.simpleName
-            if (i != 0) {
-                threadTaskSb.append("--->")
-            }
-            threadTaskSb.append(taskName)
-        }
-        Log.i(TAG_START_UP, threadTaskSb.toString())
-    }
-
-    //发送任务
-    private fun dispatchAppStartTask() {
-        //先发送非主线程的任务
-        var maxSubTaskCount = TaskExecutorManager.instance.getMaxTaskCount()
-        Log.d(TAG_START_UP, "dispatchAppStartTask, maxSubTaskCount:$maxSubTaskCount")
-        for (appStartTask in mSortThreadPoolTaskList) {
-            if (maxSubTaskCount > 0) {
-                maxSubTaskCount--
-                appStartTask.runOnExecutor().execute(StartTaskRunnable(appStartTask, this))
-            } else {
-                //线程池负荷过高,将任务加入待执行任务
-                mPendingTaskList.offer(appStartTask)
-            }
-        }
-        Log.d(
-            TAG_START_UP, "dispatchAppStartTask, mPendingTaskList :${
-                mPendingTaskList.joinToString(separator = ",", transform = {
-                    it::class.java.name
-                })
-            }"
-        )
-        //再发送主线程的任务,防止主线程任务阻塞,导致子线程任务不能立刻执行
-        for (appStartTask in mSortMainThreadTaskList) {
-            StartTaskRunnable(appStartTask, this).run()
-        }
-    }
-
-    //通知Children一个前置任务已完成
-    fun setNotifyChildren(startUpTask: StartUpTask) {
-        val arrayList = mTaskChildHashMap[startUpTask.javaClass]
-        if (arrayList != null && arrayList.size > 0) {
-            for (aclass in arrayList) {
-                mTaskHashMap[aclass]?.notifyDependFinish()
-            }
-        }
-    }
-
-    //标记已经完成的Task
-    fun markAppStartTaskFinish(startUpTask: StartUpTask, taskCostTime: Long) {
-        if (ifNeedWait(startUpTask)) {
-            mCountDownLatch?.countDown()
-            mNeedWaitCount.getAndDecrement()
-        }
-        mAllTaskTime += taskCostTime
-        Log.i(TAG_START_UP, "markAppStartTaskFinish, ${startUpTask::class.java}, mNeedWaitCount:${mNeedWaitCount.get()}")
-        if (isMainThread()) {
-            val mainThreadCount = mMainThreadTaskCount.decrementAndGet()
-            Log.d(TAG_START_UP, ">>>> mainThreadCount(${mainThreadCount})")
-            if (mainThreadCount == 0) {
-                tryRunTaskOnMainThread()
-            }
-        } else {
-            tryRunTaskOnSubThread()
-        }
-    }
-
-    private fun tryRunTaskOnMainThread() {
-        //主线程执行完任务了,看看是否有待执行的任务
-        val pendingTask = mPendingTaskList.poll()
-        if (pendingTask != null) {
-            Log.d(TAG_START_UP, "mPendingTask(${pendingTask::class.java}) => MainThread")
-            mMainThreadTaskCount.getAndIncrement()
-            StartTaskRunnable(pendingTask, this).run()
-        }
-    }
-
-    private fun tryRunTaskOnSubThread() {
-        val pendingTask = mPendingTaskList.poll()
-        if (pendingTask != null) {
-            Log.d(TAG_START_UP, "mPendingTask(${pendingTask::class.java}) => ThreadPool")
-            pendingTask.runOnExecutor().execute(StartTaskRunnable(pendingTask, this))
-        }
-    }
-
-    //是否需要等待,主线程的任务本来就是阻塞的,所以不用管
-    private fun ifNeedWait(task: StartUpTask): Boolean {
-        return task.isRunOnMainThread || task.needWait()
-    }
-
-    //等待,阻塞主线程
-    fun await() {
-        try {
-            val countDownLatch = mCountDownLatch ?: throw RuntimeException("You must call start() before call await()")
-            Log.i(TAG_START_UP, "await(), mAllTaskWaitTimeOut:$mAllTaskWaitTimeOut")
-            countDownLatch.await(mAllTaskWaitTimeOut, TimeUnit.MILLISECONDS)
-
-            mFinishTime = System.currentTimeMillis() - mStartTime
-            Log.i(TAG_START_UP, "All waiting task finish, cost:${mFinishTime}ms, all cost:${mAllTaskTime}ms, save time:${mAllTaskTime - mFinishTime}ms")
-        } catch (e: InterruptedException) {
-            e.printStackTrace()
-        }
-    }
-
-    companion object {
-        //所有任务需要等待的时间
-        private const val WAITING_TIME = 10_000L
-        fun create(): StartTaskDispatcher {
-            return StartTaskDispatcher()
-        }
-    }
-}

+ 0 - 88
frame/startup/src/main/java/com/adealink/frame/startup/executor/TaskExecutorManager.kt

@@ -1,88 +0,0 @@
-package com.adealink.frame.startup.executor
-
-import com.adealink.frame.thread.NamedThreadFactory
-import java.util.concurrent.BlockingQueue
-import java.util.concurrent.Executors
-import java.util.concurrent.LinkedBlockingQueue
-import java.util.concurrent.RejectedExecutionHandler
-import java.util.concurrent.ThreadPoolExecutor
-import java.util.concurrent.TimeUnit
-import kotlin.math.max
-import kotlin.math.min
-
-class TaskExecutorManager private constructor() {
-    //获得cpu密集型线程池,因为占据CPU的时间片过多的话会影响性能,所以这里控制了最大并发,防止主线程的时间片减少
-    //CPU 密集型任务的线程池
-    val cpuThreadPoolExecutor: ThreadPoolExecutor
-
-    //获得io密集型线程池,有好多任务其实占用的CPU time非常少,所以使用缓存线程池,基本上来着不拒
-    // IO 密集型任务的线程池
-//    internal val ioThreadPoolExecutor: ExecutorService
-
-    //线程池队列
-    private val mPoolWorkQueue: BlockingQueue<Runnable> = LinkedBlockingQueue()
-
-    // 这个是为了保障任务超出BlockingQueue的最大值,且线程池中的线程数已经达到MAXIMUM_POOL_SIZE时候,还有任务到来会采取任务拒绝策略,这里定义的策略就是
-    //再开一个缓存线程池去执行。当然BlockingQueue默认的最大值是int_max,所以理论上这里是用不到的
-    private val mHandler = RejectedExecutionHandler { r, executor -> Executors.newCachedThreadPool().execute(r) }
-
-    //初始化线程池
-    init {
-        //CPU 密集型任务的线程池
-        cpuThreadPoolExecutor = ThreadPoolExecutor(
-            CORE_POOL_SIZE, MAXIMUM_POOL_SIZE, KEEP_ALIVE_SECONDS.toLong(), TimeUnit.SECONDS,
-            mPoolWorkQueue, NamedThreadFactory("startup-thread", Thread.MAX_PRIORITY), mHandler
-        )
-        cpuThreadPoolExecutor.allowCoreThreadTimeOut(true)
-
-        cpuThreadPoolExecutor.taskCount
-
-//        //io密集型线程池
-//        ioThreadPoolExecutor = Dispatcher.wenextThreadPoolExecutor
-    }
-
-    fun getMaxTaskCount(): Int {
-        // 获取最大线程数
-        val maximumPoolSize: Int = cpuThreadPoolExecutor.maximumPoolSize
-        return (maximumPoolSize * MAX_LOAD_FACTOR).toInt()
-    }
-
-    /**
-     * 线程池负荷太高
-     */
-    fun isBusy(): Boolean {
-        // 获取当前活跃线程数
-        val activeCount: Int = cpuThreadPoolExecutor.getActiveCount()
-        // 获取当前池中的线程数
-        val poolSize: Int = cpuThreadPoolExecutor.getPoolSize()
-        // 获取核心线程数
-        val corePoolSize: Int = cpuThreadPoolExecutor.corePoolSize
-        // 获取最大线程数
-        val maximumPoolSize: Int = cpuThreadPoolExecutor.maximumPoolSize
-        // 获取任务队列中的待处理任务数
-        val queueSize: Int = cpuThreadPoolExecutor.queue?.size ?: 0
-        // 计算当前负荷率 (活跃线程 + 待处理任务数量 >= 最大线程 * MAX_LOAD_FACTOR)
-        return (activeCount + queueSize) >= maximumPoolSize * MAX_LOAD_FACTOR
-    }
-
-    companion object {
-        val instance: TaskExecutorManager by lazy {
-            TaskExecutorManager()
-        }
-
-        //线程池最大负荷量
-        private const val MAX_LOAD_FACTOR = 1.2f
-
-        //CPU 核数
-        private val CPU_COUNT = Runtime.getRuntime().availableProcessors()
-
-        //线程池线程数(CPU_COUNT-1留给主线程一个)
-        val CORE_POOL_SIZE = max(2.0, min((CPU_COUNT - 1).toDouble(), 5.0)).toInt()
-
-        //线程池线程数的最大值
-        private val MAXIMUM_POOL_SIZE = CORE_POOL_SIZE
-
-        //线程空置回收时间
-        private const val KEEP_ALIVE_SECONDS = 5
-    }
-}

+ 0 - 25
frame/startup/src/main/java/com/adealink/frame/startup/runnable/StartTaskRunnable.kt

@@ -1,25 +0,0 @@
-package com.adealink.frame.startup.runnable
-
-import android.os.Process
-import com.adealink.frame.log.Log
-import com.adealink.frame.startup.TAG_START_UP
-import com.adealink.frame.startup.dispatcher.StartTaskDispatcher
-import com.adealink.frame.startup.task.StartUpTask
-import com.adealink.frame.util.isMainThread
-
-class StartTaskRunnable(private val mStartUpTask: StartUpTask, private val mStartTaskDispatcher: StartTaskDispatcher) : Runnable {
-    override fun run() {
-        if (!mStartUpTask.isRunOnMainThread) {
-            Process.setThreadPriority(mStartUpTask.priority())
-        }
-        Log.i(TAG_START_UP, "${mStartUpTask::class.java} start, thread:${Thread.currentThread()}, isMainThread:${isMainThread()}")
-        val startTime = System.currentTimeMillis()
-        mStartUpTask.waitToNotify()
-        Log.i(TAG_START_UP, "${mStartUpTask::class.java} start delay: ${System.currentTimeMillis() - startTime}")
-        mStartUpTask.run()
-        val costTime = System.currentTimeMillis() - startTime
-        Log.i(TAG_START_UP, "${mStartUpTask::class.java} end, cost: $costTime")
-        mStartTaskDispatcher.setNotifyChildren(mStartUpTask)
-        mStartTaskDispatcher.markAppStartTaskFinish(mStartUpTask, costTime)
-    }
-}

+ 0 - 50
frame/startup/src/main/java/com/adealink/frame/startup/task/StartUpTask.kt

@@ -1,50 +0,0 @@
-package com.adealink.frame.startup.task
-
-import android.os.Process
-import com.adealink.frame.startup.base.TaskInterface
-import com.adealink.frame.startup.executor.TaskExecutorManager
-import java.util.concurrent.CountDownLatch
-import java.util.concurrent.Executor
-
-abstract class StartUpTask : TaskInterface {
-
-    //是否在主线程执行
-    abstract val isRunOnMainThread: Boolean
-
-    override val dependsTaskList: List<Class<out StartUpTask>>
-        get() = emptyList()
-
-    // 当前Task依赖的Task数量(等父亲们执行完了,孩子才能执行),默认没有依赖
-    private val mDepends = CountDownLatch(dependsTaskList.size)
-
-    //当前Task等待,让父亲Task先执行
-    fun waitToNotify() {
-        try {
-            mDepends.await()
-        } catch (e: InterruptedException) {
-            e.printStackTrace()
-        }
-    }
-
-    override fun priority(): Int {
-        return Process.THREAD_PRIORITY_FOREGROUND
-    }
-
-    //执行任务代码
-    abstract fun run()
-
-    //他的父亲们执行完了一个
-    fun notifyDependFinish() {
-        mDepends.countDown()
-    }
-
-    override fun runOnExecutor(): Executor {
-        return TaskExecutorManager.instance.cpuThreadPoolExecutor
-    }
-
-    override fun needWait(): Boolean {
-        return false
-    }
-
-
-}

+ 0 - 68
frame/startup/src/main/java/com/adealink/frame/startup/util/StartUpTaskSortUtil.kt

@@ -1,68 +0,0 @@
-package com.adealink.frame.startup.util
-
-import com.adealink.frame.startup.task.StartUpTask
-import com.adealink.frame.startup.util.model.TaskSortModel
-import java.util.ArrayDeque
-import java.util.Deque
-
-
-object StartUpTaskSortUtil {
-    /**
-     * 拓扑排序
-     * taskIntegerHashMap每个Task的入度(key= Class < ? extends AppStartTask>)
-     * taskHashMap每个Task            (key= Class < ? extends AppStartTask>)
-     * taskChildHashMap每个Task的孩子  (key= Class < ? extends AppStartTask>)
-     * deque 入度为0的Task
-     */
-    fun getSortResult(
-        startTaskList: List<StartUpTask>,
-        taskHashMap: HashMap<Class<out StartUpTask>, StartUpTask>,
-        taskChildHashMap: HashMap<Class<out StartUpTask>, MutableList<Class<out StartUpTask>>>
-    ): List<StartUpTask> {
-        val sortTaskList: MutableList<StartUpTask> = ArrayList()
-        val taskIntegerHashMap = HashMap<Class<out StartUpTask>, TaskSortModel>()
-        val deque: Deque<Class<out StartUpTask>> = ArrayDeque()
-        for (task in startTaskList) {
-            if (!taskIntegerHashMap.containsKey(task.javaClass)) {
-                taskHashMap[task.javaClass] = task
-                taskIntegerHashMap[task.javaClass] = TaskSortModel(task.dependsTaskList.size)
-                taskChildHashMap[task.javaClass] = ArrayList()
-                //入度为0的队列
-                if (taskIntegerHashMap[task.javaClass]?.taskIn == 0) {
-                    deque.offer(task.javaClass)
-                }
-            } else {
-                throw RuntimeException("任务重复了: " + task.javaClass)
-            }
-        }
-        //把孩子都加进去
-        for (task in startTaskList) {
-            for (aclass in task.dependsTaskList) {
-                taskChildHashMap[aclass]?.add(task.javaClass)
-            }
-        }
-        //循环去除入度0的,再把孩子入度变成0的加进去
-        while (!deque.isEmpty()) {
-            val aclass = deque.poll() ?: break
-
-            taskHashMap[aclass]?.let {
-                sortTaskList.add(it)
-            }
-
-            taskChildHashMap[aclass]?.let {
-                for (classChild in it) {
-                    taskIntegerHashMap[classChild]?.let { sortModel ->
-                        sortModel.taskIn -= 1
-                        if (sortModel.taskIn == 0) {
-                            deque.offer(classChild)
-                        }
-                    }
-                }
-            }
-        }
-        if (sortTaskList.size != startTaskList.size) {
-            throw RuntimeException("出现环了")
-        }
-        return sortTaskList
-    }
-}

+ 0 - 3
frame/startup/src/main/java/com/adealink/frame/startup/util/model/TaskSortModel.kt

@@ -1,3 +0,0 @@
-package com.adealink.frame.startup.util.model
-
-class TaskSortModel(@JvmField var taskIn: Int)

+ 2 - 1
gradle/libs.versions.toml

@@ -155,7 +155,7 @@ appleAppauth = "0.11.1"
 tiktok = "2.3.0"
 
 # frame
-frameBom = "5.1.28-yoki"
+frameBom = "5.1.29-yoki"
 
 frameRouterCompiler = "5.1.6"
 frameTrace = "1.0.0"
@@ -411,6 +411,7 @@ frame-router-compiler = { group = "com.wenext.android", name = "frame-router-com
 frame-trace-api = { module = "com.wenext.android:frame-trace-api", version.ref = "frameTrace" }
 frame-trace-plugin = { module = "com.wenext.android:frame-trace-plugin", version.ref = "frameTrace" }
 frame-bundle-tool = { group = "com.wenext.android", name = "frame-bundletool", version.ref = "frameBundleTool" }
+frame-startup = { group = "com.wenext.android", name = "frame-startup" }
 
 
 # tencent.liteav

+ 0 - 1
settings.gradle

@@ -63,7 +63,6 @@ rootProject.name = "yoki"
 include ':app'
 
 include ':frame:room'
-include ':frame:startup'
 include ':frame:imkit'
 
 include ':module:wallet'