forked from idisfkj/android-startup
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
269 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
app/src/main/aidl/com/rousetime/sample/IMultipleProcessServiceInterface.aidl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// IMultipleProcessServiceInterface.aidl | ||
package com.rousetime.sample; | ||
|
||
// Declare any non-default types here with import statements | ||
import com.rousetime.sample.IServiceListenerInterface; | ||
|
||
interface IMultipleProcessServiceInterface { | ||
|
||
void addServiceListener(IServiceListenerInterface serviceListener); | ||
|
||
void initStartup(); | ||
|
||
void clear(); | ||
} |
10 changes: 10 additions & 0 deletions
10
app/src/main/aidl/com/rousetime/sample/IServiceListenerInterface.aidl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// IServiceListenerInterface.aidl | ||
package com.rousetime.sample; | ||
|
||
// Declare any non-default types here with import statements | ||
|
||
interface IServiceListenerInterface { | ||
|
||
void onCompleted(String result, long totalMainThreadCostTime); | ||
|
||
} |
97 changes: 97 additions & 0 deletions
97
app/src/main/java/com/rousetime/sample/MultipleProcessService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
package com.rousetime.sample | ||
|
||
import android.app.Service | ||
import android.content.Intent | ||
import android.os.Handler | ||
import android.os.IBinder | ||
import android.os.Looper | ||
import android.util.Log | ||
import com.rousetime.android_startup.AndroidStartup | ||
import com.rousetime.android_startup.StartupListener | ||
import com.rousetime.android_startup.StartupManager | ||
import com.rousetime.android_startup.manager.StartupCacheManager | ||
import com.rousetime.android_startup.model.CostTimesModel | ||
import com.rousetime.android_startup.model.LoggerLevel | ||
import com.rousetime.android_startup.model.StartupConfig | ||
import com.rousetime.sample.startup.multiple.SampleMultipleFifthStartup | ||
import com.rousetime.sample.startup.multiple.SampleMultipleFourthStartup | ||
import com.rousetime.sample.startup.multiple.SampleMultipleSixthStartup | ||
import com.rousetime.sample.startup.multiple.SampleMultipleThirdStartup | ||
|
||
/** | ||
* Created by idisfkj on 2020/9/15. | ||
* Email: [email protected]. | ||
*/ | ||
class MultipleProcessService : Service() { | ||
|
||
private var mServiceListener: IServiceListenerInterface? = null | ||
|
||
private var mBinder = object : IMultipleProcessServiceInterface.Stub() { | ||
|
||
override fun clear() { | ||
StartupCacheManager.instance.clear() | ||
} | ||
|
||
override fun initStartup() { | ||
// must be start main thread. | ||
Handler(Looper.getMainLooper()).post { | ||
val list = mutableListOf<AndroidStartup<*>>() | ||
list.add(SampleMultipleThirdStartup()) | ||
list.add(SampleMultipleFourthStartup()) | ||
list.add(SampleMultipleFifthStartup()) | ||
list.add(SampleMultipleSixthStartup()) | ||
val config = StartupConfig.Builder() | ||
.setLoggerLevel(LoggerLevel.DEBUG) | ||
.setAwaitTimeout(12000L) | ||
.setListener(object : StartupListener { | ||
override fun onCompleted(totalMainThreadCostTime: Long, costTimesModels: List<CostTimesModel>) { | ||
// can to do cost time statistics. | ||
mServiceListener?.onCompleted(buildString { | ||
append("Startup Completed: ") | ||
append("\n") | ||
append("\n") | ||
costTimesModels.forEach { | ||
append("\n") | ||
append("Startup Name: ${it.name}") | ||
append("\n") | ||
append("CallOnMainThread: ${it.callOnMainThread}") | ||
append("\n") | ||
append("WaitOnMainThread: ${it.waitOnMainThread}") | ||
append("\n") | ||
append("Cost times: ${it.endTime - it.startTime} ms") | ||
append("\n") | ||
} | ||
if (costTimesModels.isEmpty()) { | ||
append("result form cache.") | ||
append("\n") | ||
list.forEach { | ||
append("\n") | ||
append("${it::class.java.simpleName}: ${StartupCacheManager.instance.obtainInitializedResult<String>(it::class.java)}") | ||
append("\n") | ||
} | ||
} | ||
}, totalMainThreadCostTime) | ||
Log.d("StartupTrack", "onCompleted: ${costTimesModels.size}") | ||
} | ||
}) | ||
.build() | ||
|
||
StartupManager.Builder() | ||
.setConfig(config) | ||
.addAllStartup(list) | ||
.build(this@MultipleProcessService) | ||
.start() | ||
.await() | ||
} | ||
} | ||
|
||
override fun addServiceListener(serviceListener: IServiceListenerInterface?) { | ||
mServiceListener = serviceListener | ||
} | ||
|
||
} | ||
|
||
override fun onBind(intent: Intent?): IBinder? { | ||
return mBinder | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
app/src/main/java/com/rousetime/sample/startup/multiple/SampleMultipleFifthStartup.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.rousetime.sample.startup.multiple | ||
|
||
import android.content.Context | ||
import com.rousetime.android_startup.AndroidStartup | ||
import com.rousetime.android_startup.Startup | ||
import com.rousetime.android_startup.annotation.MultipleProcess | ||
|
||
/** | ||
* Created by idisfkj on 2020/9/15. | ||
* Email: [email protected]. | ||
*/ | ||
@MultipleProcess(":multiple.process.service") | ||
class SampleMultipleFifthStartup : AndroidStartup<String>() { | ||
|
||
override fun create(context: Context): String? { | ||
return SampleMultipleFifthStartup::class.java.simpleName | ||
} | ||
|
||
override fun callCreateOnMainThread(): Boolean = false | ||
|
||
override fun waitOnMainThread(): Boolean = false | ||
|
||
override fun dependencies(): List<Class<out Startup<*>>>? { | ||
return listOf(SampleMultipleFourthStartup::class.java) | ||
} | ||
|
||
} |
22 changes: 22 additions & 0 deletions
22
app/src/main/java/com/rousetime/sample/startup/multiple/SampleMultipleFourthStartup.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.rousetime.sample.startup.multiple | ||
|
||
import android.content.Context | ||
import com.rousetime.android_startup.AndroidStartup | ||
import com.rousetime.android_startup.annotation.MultipleProcess | ||
|
||
/** | ||
* Created by idisfkj on 2020/9/15. | ||
* Email: [email protected]. | ||
*/ | ||
@MultipleProcess(":multiple.process.service") | ||
class SampleMultipleFourthStartup : AndroidStartup<String>() { | ||
|
||
override fun create(context: Context): String? { | ||
Thread.sleep(1000) | ||
return SampleMultipleFourthStartup::class.java.simpleName | ||
} | ||
|
||
override fun callCreateOnMainThread(): Boolean = false | ||
|
||
override fun waitOnMainThread(): Boolean = false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,10 +10,10 @@ import com.rousetime.android_startup.annotation.MultipleProcess | |
* Email: [email protected]. | ||
*/ | ||
@MultipleProcess(":multiple.provider") | ||
class SampleMultipleSecondStartup : AndroidStartup<Boolean>() { | ||
class SampleMultipleSecondStartup : AndroidStartup<String>() { | ||
|
||
override fun create(context: Context): Boolean? { | ||
return true | ||
override fun create(context: Context): String? { | ||
return SampleMultipleSecondStartup::class.java.simpleName | ||
} | ||
|
||
override fun callCreateOnMainThread(): Boolean = false | ||
|
27 changes: 27 additions & 0 deletions
27
app/src/main/java/com/rousetime/sample/startup/multiple/SampleMultipleSixthStartup.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.rousetime.sample.startup.multiple | ||
|
||
import android.content.Context | ||
import com.rousetime.android_startup.AndroidStartup | ||
import com.rousetime.android_startup.Startup | ||
import com.rousetime.android_startup.annotation.MultipleProcess | ||
|
||
/** | ||
* Created by idisfkj on 2020/9/15. | ||
* Email: [email protected]. | ||
*/ | ||
@MultipleProcess(":multiple.process.service") | ||
class SampleMultipleSixthStartup : AndroidStartup<String>() { | ||
|
||
override fun create(context: Context): String? { | ||
return SampleMultipleSixthStartup::class.java.simpleName | ||
} | ||
|
||
override fun callCreateOnMainThread(): Boolean = false | ||
|
||
override fun waitOnMainThread(): Boolean = true | ||
|
||
override fun dependencies(): List<Class<out Startup<*>>>? { | ||
return listOf(SampleMultipleFifthStartup::class.java) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters