Skip to content

Commit

Permalink
增加隐私模式
Browse files Browse the repository at this point in the history
  • Loading branch information
WizzXu committed Jan 5, 2022
1 parent f0048fb commit 1c02899
Show file tree
Hide file tree
Showing 13 changed files with 73 additions and 40 deletions.
16 changes: 16 additions & 0 deletions CHANGE_LOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# 更新记录

| 组件 | 最新版本 |
| --- | --- |
| io.github.wizzxu:fast-startup |0.0.2 |
| io.github.wizzxu:fast-startup-api |0.0.2 |
| io.github.wizzxu:fast-startup-transformer |0.0.1 |

# fast-startup
### 0.0.2
新增隐私初始化支持
新增依赖关系打印

# fast-startup-api
### 0.0.2
新增隐私初始化支持
20 changes: 13 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# FastStartup
`FastStartup`是一个组件启动框架,旨在帮助开发人员能够简单、高效地进行各种组件的初始化操作。
`FastStartup`是一个组件启动框架,旨在帮助开发人员能够简单、高效地进行各种组件的初始化操作。
[【更新记录】](https://github.com/WizzXu/FastStartup/blob/main/CHANGE_LOG.md)

## 特点
简单、高效、支持解藕。
Expand All @@ -25,7 +26,8 @@
在项目工程目录下`build.gradle`中添加依赖
```
dependencies {
implementation "io.github.wizzxu:fast-startup:0.0.1"
//请使用最新版本
implementation "io.github.wizzxu:fast-startup:0.0.2"
}
```
### 2. 组件初始化
Expand Down Expand Up @@ -110,13 +112,16 @@ Log.d("TestGetResult", "${FastStartup.getStartupResult(IA::class.java)}")
## 依赖环检测和缺失检测
在FastStartup启动的时候会自动进行依赖环检测和缺失检测
如果依赖有环,会抛出异常并会打印如下信息
![dep_pic_1](https://github.com/WizzXu/FastStartup/blob/main/pic/dep_pic_1.png?raw=true)
![dep_pic_1](https://raw.githubusercontent.com/WizzXu/FastStartup/main/pic/dep_pic_1.png)

如果依赖有缺失,会打印如下消息
![dep_pic_2](https://github.com/WizzXu/FastStartup/blob/main/pic/dep_pic_2.png?raw=true)
![dep_pic_2](https://raw.githubusercontent.com/WizzXu/FastStartup/main/pic/dep_pic_2.png)

## 耗时统计
![cost_time](https://github.com/WizzXu/FastStartup/blob/main/pic/cost_time.png?raw=true)
![cost_time](https://raw.githubusercontent.com/WizzXu/FastStartup/main/pic/cost_time.png)

## 依赖关系打印
![dep_list_pic](https://raw.githubusercontent.com/WizzXu/FastStartup/main/pic/dep_list_pic.png)


# FastStartup 高级用法 解藕、AOP、隐私模式
Expand All @@ -126,7 +131,8 @@ Log.d("TestGetResult", "${FastStartup.getStartupResult(IA::class.java)}")
#### 1. 组件工程添加`IStartup`组件依赖
```
dependencies {
implementation "io.github.wizzxu:fast-startup-api:0.0.1"
//请使用最新版本
implementation "io.github.wizzxu:fast-startup-api:0.0.2"
}
```
组件接口必须直接继承`IStartup`
Expand Down Expand Up @@ -167,7 +173,7 @@ AOP方案的实现基于[Booster](https://github.com/didi/booster)实现
buildscript {
ext.kotlin_version = "1.5.31"
ext.booster_version = '4.0.0'
ext.fast_startup_transformer = '0.0.1'
ext.fast_startup_transformer = '0.0.1'//请使用最新版本
dependencies {
// 添加booster插件
Expand Down
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ dependencies {
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.3.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation project(path: ':fast-startup')
//api "io.github.wizzxu:fast-startup:0.0.1"
//implementation project(path: ':fast-startup')
api "io.github.wizzxu:fast-startup:0.0.2"

//implementation "io.github.wizzxu:fast-startup:0.0.1-SNAPSHOT"
//implementation project(path: ':fast-startup-api')
Expand Down
18 changes: 9 additions & 9 deletions app/src/main/java/io/github/fast_startup/startup/demo/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -76,26 +76,26 @@ class App : Application() {
).start()*/

// 测试环
TestTask.addTask(TestCircle())
//TestTask.addTask(TestCircle())
//
// //测试依缺失
TestTask.addTask(TestMissing())
//TestTask.addTask(TestMissing())
//
// //测试依赖接口方式
TestTask.addTask(TestInterfaceImp())
//TestTask.addTask(TestInterfaceImp())
//
// //测试多次添加
TestTask.addTask(TestMultiAdd())
//TestTask.addTask(TestMultiAdd())

//测试主线程需要等待子线程完成
TestTask.addTask(TestWaitMainThread())

TestTask.addTask(TestGetResult())
//TestTask.addTask(TestGetResult())

TestTask.addTask(TestAop())
//TestTask.addTask(TestAop())

TestTask.addTask(TestPrivacy())

//测试主线程需要等待子线程完成
//TestTask.addTask(TestWaitMainThread())

TestTask.startNext()

SLog.e("StartupRunnable", "all is ok")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import io.github.fast_startup.startup.demo.TestBase
class TestPrivacy : TestBase {
override fun test() {
val startups = mutableListOf<IStartup<*>>()
startups.add(C())
//startups.add(C())
startups.add(A())
startups.add(B())
startups.add(D())
Expand All @@ -31,18 +31,18 @@ class TestPrivacy : TestBase {
.setLogLevel(Log.DEBUG)
.setIsPrintDependencies(true)
.build()
).registerAllStartupCompleteListener(object : AllStartupCompleteListener{
).registerAllStartupCompleteListener(object : AllStartupCompleteListener {
override fun startupComplete() {
SLog.e("registerAllStartupCompleteListener")
//FastStartup.setPrivacyAgree(true)
//FastStartup.reStart()
}
}).registerUIStartupCompleteListener(object : UIStartupCompleteListener{
}).registerUIStartupCompleteListener(object : UIStartupCompleteListener {
override fun startupComplete() {
SLog.e("registerUIStartupCompleteListener")

}
}).registerStartupCompleteListener(object : StartupCompleteListener{
}).registerStartupCompleteListener(object : StartupCompleteListener {
override fun startupComplete(startup: IStartup<*>) {
SLog.e("registerStartupCompleteListener:${startup.javaClass.simpleName}")
}
Expand All @@ -54,7 +54,7 @@ class TestPrivacy : TestBase {

class A : IStartup<String> {
override fun start(context: Context?, isDebug: Boolean?, any: Any?): String? {
SLog.e("A()")
//SLog.e("A()")
return null
}

Expand All @@ -65,7 +65,7 @@ class A : IStartup<String> {

class B : IStartup<String> {
override fun start(context: Context?, isDebug: Boolean?, any: Any?): String? {
SLog.e("B()")
//SLog.e("B()")

return null
}
Expand Down Expand Up @@ -97,28 +97,29 @@ class C : IStartup<String> {

class D : IStartup<String> {
override fun start(context: Context?, isDebug: Boolean?, any: Any?): String? {
SLog.e("D()")
//SLog.e("D()")

return null
}

override fun dependencies(): List<Class<out IStartup<*>>>? {
return null
}

override fun runOnUIThread(): Boolean {
return true
return false
}
}

class E : IStartup<String> {
override fun start(context: Context?, isDebug: Boolean?, any: Any?): String? {
SLog.e("E()")
//SLog.e("E()")

return null
}

override fun runOnUIThread(): Boolean {
return true
return false
}

override fun dependencies(): List<Class<out IStartup<*>>>? {
Expand Down
2 changes: 1 addition & 1 deletion fast-startup-api/publish.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ task androidSourcesJar(type: Jar) {
ext {
PUBLISH_GROUP_ID = 'io.github.wizzxu'
PUBLISH_ARTIFACT_ID = 'fast-startup-api'
PUBLISH_VERSION = '0.0.1'
PUBLISH_VERSION = '0.0.2'
}

// leave them empty to allow compilation
Expand Down
4 changes: 2 additions & 2 deletions fast-startup/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ android {
dependencies {

implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
api project(path: ':fast-startup-api')
//api project(path: ':fast-startup-api')
//api "io.github.wizzxu:fast-startup-api:0.0.1-SNAPSHOT"
//api "io.github.wizzxu:fast-startup-api:0.0.1"
api "io.github.wizzxu:fast-startup-api:0.0.2"
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
Expand Down
2 changes: 1 addition & 1 deletion fast-startup/publish.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ task androidSourcesJar(type: Jar) {
ext {
PUBLISH_GROUP_ID = 'io.github.wizzxu'
PUBLISH_ARTIFACT_ID = 'fast-startup'
PUBLISH_VERSION = '0.0.1'
PUBLISH_VERSION = '0.0.2'
}

// leave them empty to allow compilation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,10 @@ object FastStartup {
*/
fun reStart() {
if (isPrivacyAgree != true || startupInfoStore?.privacyCheckFailStartupList?.size == 0) {
SLog.e("隐私未同意或者没有需要隐私权限的Startup")
SLog.i(
"隐私同意状态:${isPrivacyAgree} \n " +
"需要隐私权限的Startup数量:${startupInfoStore?.privacyCheckFailStartupList?.size ?: 0}"
)
return
}
// 初始化检测
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,15 +130,15 @@ internal object SortUtil {
startupList.forEach {
val uniqueKey = it::class.java.getUniqueKey()
if (startupMap.containsKey(uniqueKey)) {
throw StartupException("$uniqueKey ${StartupExceptionMsg.MULTI_ADD}")
throw StartupException("[$uniqueKey] ${StartupExceptionMsg.MULTI_ADD}")
}
// 保存所有startup
startupMap[uniqueKey] = it
// 保存所有 startup 依赖关系, 去除接口依赖,维护真正的依赖类
val realDepList: MutableList<String> = mutableListOf()
it.dependencies()?.forEach { dep ->
if (dep.isInterface) {
realDepList.add(startupInterfaceMap[dep]!!.getUniqueKey())
startupInterfaceMap[dep]?.let { it1 -> realDepList.add(it1.getUniqueKey()) }
} else {
realDepList.add(dep.getUniqueKey())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,15 @@ internal class DependenciesListCheckUtil {
) {
// 下面开始进行环检测和依赖丢失情况的检测
if (startupConfig?.isDebug == true) {
val orderList =
dependenciesListCheck(startupList, startupInfoStore.startupInterfaceMap)
val orderList = dependenciesListCheck(startupList)
DependenciesListPrintUtil.printDependenciesList(
orderList,
startupConfig,
startupInfoStore
)
} else {
ExecutorManager.instance.execute {
val orderList =
dependenciesListCheck(startupList, startupInfoStore.startupInterfaceMap)
val orderList = dependenciesListCheck(startupList)
DependenciesListPrintUtil.printDependenciesList(
orderList,
startupConfig,
Expand All @@ -48,10 +46,19 @@ internal class DependenciesListCheckUtil {
@JvmStatic
private fun dependenciesListCheck(
startupList: List<IStartup<*>>,
startupInterfaceMap: MutableMap<Class<*>, Class<out IStartup<*>>>,
): ArrayDeque<String> {
val startupMap: HashMap<String, IStartup<*>> = HashMap(startupList.size)
val startupChildrenMap: HashMap<String, MutableSet<String>> = HashMap()
val startupInterfaceMap = mutableMapOf<Class<*>, Class<out IStartup<*>>>()

// 构建startupInterfaceMap依赖关系表
startupList.forEach { startup ->
startup::class.java.interfaces.forEach {
if (it.interfaces.contains(IStartup::class.java)) {
startupInterfaceMap[it] = startup.javaClass
}
}
}

val zeroDequeTmp = ArrayDeque<String>()
startupList.forEach {
Expand Down
Binary file modified pic/cost_time.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added pic/dep_list_pic.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 1c02899

Please sign in to comment.