From fa9b74def65dc85741ad563b77fdf1fe7ab80791 Mon Sep 17 00:00:00 2001 From: ryuunoakaihitomi <22442525+ryuunoakaihitomi@users.noreply.github.com> Date: Thu, 2 Sep 2021 01:16:21 +0800 Subject: [PATCH] =?UTF-8?q?R3.12=20=E6=8B=92=E7=BB=9D=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E5=8C=96=E6=9C=8D=E5=8A=A1=E6=93=8D=E4=BD=9C=E5=BA=94=E7=94=A8?= =?UTF-8?q?=EF=BC=8C=E9=98=B2=E6=AD=A2=E6=84=8F=E5=A4=96=E8=A1=8C=E4=B8=BA?= =?UTF-8?q?=E3=80=82=20=E9=9B=86=E6=88=90=E5=8D=8E=E4=B8=BAAGC=E5=88=86?= =?UTF-8?q?=E6=9E=90=E6=9C=8D=E5=8A=A1=EF=BC=8C=E4=BD=9C=E4=B8=BAFirebase?= =?UTF-8?q?=E7=9A=84=E5=A4=87=E7=94=A8=E6=8E=AA=E6=96=BD=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 4 +++- BUILD_NOTE.md | 3 ++- app/build.gradle | 20 +++++++++++++++---- .../powerpanel/stat/InternalDoerImpl.kt | 5 +++++ .../powerpanel/MyApplication.kt | 2 +- .../powerpanel/desc/PowerExecution.kt | 13 ++++++++++++ .../powerpanel/stat/InternalDoer.kt | 2 ++ .../powerpanel/stat/Statistics.kt | 8 +++++++- .../ui/OpenSourceLibDependencyActivity.kt | 3 ++- .../powerpanel/util/Extensions.kt | 6 ++++++ app/src/main/res/raw-zh-rCN/help.md | 2 +- app/src/main/res/raw/help.md | 1 + .../powerpanel/stat/InternalDoerImpl.kt | 8 ++++++++ build.gradle | 5 +++++ 14 files changed, 72 insertions(+), 10 deletions(-) diff --git a/.gitignore b/.gitignore index 0152e96..c549c69 100644 --- a/.gitignore +++ b/.gitignore @@ -90,4 +90,6 @@ lint/tmp/ # --- 自定义配置 --- # 签名信息 -signInfo.properties \ No newline at end of file +signInfo.properties +# 华为分析 +agconnect-services.json \ No newline at end of file diff --git a/BUILD_NOTE.md b/BUILD_NOTE.md index 6165b0c..5a96999 100644 --- a/BUILD_NOTE.md +++ b/BUILD_NOTE.md @@ -16,6 +16,7 @@ - 修改[`signInfo_example.properties`](signInfo_example.properties),填入签名信息,并将其命名为`signInfo.properties` -- 如果需要构建`normal`版本,在`app`目录中加入Firebase配置文件`google-services.json` +- 如果需要构建`normal`版本,在`app`目录中加入Firebase配置文件`google-services.json`, + 在`app/src/normal`目录中加入AppGallery Connect配置文件`agconnect-services.json`。 - 执行Gradle任务:`app:assembleRelease` \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index 7cc8044..563da97 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -4,6 +4,7 @@ apply plugin: 'com.android.application' apply plugin: 'kotlin-android' apply plugin: 'com.google.gms.google-services' apply plugin: 'com.google.firebase.crashlytics' +apply plugin: 'com.huawei.agconnect' apply from: "${rootProject.file('loadProperties.gradle')}" @@ -17,9 +18,9 @@ android { //targetSdkVersion compileSdkVersion targetSdkVersion 31 // 版本号:发布日期 - versionCode 20210830 + versionCode 20210902 // 版本名说明: R3.x.y.z (R3:Refactoring 第三次重构,z:Quick Fix序号) - versionName 'R3.11.3.1' + versionName 'R3.12' resConfigs "en", "zh-rCN" buildConfigField 'String', 'BUILD_TIME', '\"' + new Date() + '\"' @@ -60,6 +61,11 @@ android { dimension "version" versionNameSuffix '-floss' applicationId 'github.ryuunoakaihitomi.powerpanel' // 现在想要个新的packageName + // 华为插件不知道加的什么东西 + // https://stackoverflow.com/a/30497221/16091156 + aaptOptions { + ignoreAssetsPattern '!tmp_json.html' + } } } compileOptions { @@ -97,6 +103,10 @@ android { exclude 'firebase-*.properties' exclude 'play-services-*.properties' exclude 'transport-*.properties' + // 华为AGC插件 + exclude 'agconnect-*.properties' + exclude 'HMSCore-*.properties' + exclude 'network-*.properties' } } @@ -116,6 +126,8 @@ dependencies { normalImplementation 'com.google.firebase:firebase-analytics-ktx' normalImplementation 'com.google.firebase:firebase-crashlytics-ktx' + normalImplementation 'com.huawei.hms:hianalytics:6.2.0.301' + /* ------- 其他第三方开源组件 ------- */ final def markwon_version = '4.6.2' @@ -123,13 +135,13 @@ dependencies { implementation "io.noties.markwon:ext-strikethrough:$markwon_version" implementation "io.noties.markwon:image:$markwon_version" - def shizuku_version = '11.0.3' + def shizuku_version = '12.0.0' implementation "dev.rikka.shizuku:api:$shizuku_version" implementation "dev.rikka.shizuku:provider:$shizuku_version" implementation 'github.ryuunoakaihitomi.poweract:poweract:1.5.1' runtimeOnly 'github.ryuunoakaihitomi.retoast:retoast:1.7.3' - implementation 'com.google.code.gson:gson:2.8.7' + implementation 'com.google.code.gson:gson:2.8.8' implementation 'com.github.GrenderG:Toasty:1.5.0' implementation 'com.github.topjohnwu.libsu:core:3.1.2' // 固定在此版本,理由同下段注释 diff --git a/app/src/floss/java/github/ryuunoakaihitomi/powerpanel/stat/InternalDoerImpl.kt b/app/src/floss/java/github/ryuunoakaihitomi/powerpanel/stat/InternalDoerImpl.kt index ebdfa77..e8ce776 100644 --- a/app/src/floss/java/github/ryuunoakaihitomi/powerpanel/stat/InternalDoerImpl.kt +++ b/app/src/floss/java/github/ryuunoakaihitomi/powerpanel/stat/InternalDoerImpl.kt @@ -1,5 +1,6 @@ package github.ryuunoakaihitomi.powerpanel.stat +import android.content.Context import android.os.Bundle import timber.log.Timber import kotlin.system.exitProcess @@ -16,6 +17,10 @@ object InternalDoerImpl : InternalDoer { } } + override fun initialize(ctx: Context) { + Timber.i("init: $ctx") + } + override fun setCustomKey(k: String, v: Any) { val value = if (v is Array<*>) v.contentToString() else v Timber.i("Custom Key: $k, $value") diff --git a/app/src/main/java/github/ryuunoakaihitomi/powerpanel/MyApplication.kt b/app/src/main/java/github/ryuunoakaihitomi/powerpanel/MyApplication.kt index 7f3bf1b..44b6272 100644 --- a/app/src/main/java/github/ryuunoakaihitomi/powerpanel/MyApplication.kt +++ b/app/src/main/java/github/ryuunoakaihitomi/powerpanel/MyApplication.kt @@ -40,7 +40,7 @@ class MyApplication : MultiDexApplication() { override fun onCreate() { super.onCreate() - Statistics.recordEnvInfo() + Statistics.initConfig(this) if (BuildConfig.DEBUG) StrictMode.enableDefaults() // 留下PowerAct核心日志用以发布后的调试 ExternalUtils.enableLog(true) diff --git a/app/src/main/java/github/ryuunoakaihitomi/powerpanel/desc/PowerExecution.kt b/app/src/main/java/github/ryuunoakaihitomi/powerpanel/desc/PowerExecution.kt index d279072..5c31fa6 100644 --- a/app/src/main/java/github/ryuunoakaihitomi/powerpanel/desc/PowerExecution.kt +++ b/app/src/main/java/github/ryuunoakaihitomi/powerpanel/desc/PowerExecution.kt @@ -23,6 +23,7 @@ import github.ryuunoakaihitomi.powerpanel.R import github.ryuunoakaihitomi.powerpanel.stat.Statistics import github.ryuunoakaihitomi.powerpanel.ui.ShortcutActivity import github.ryuunoakaihitomi.powerpanel.ui.main.MainActivity +import github.ryuunoakaihitomi.powerpanel.util.uiLog import timber.log.Timber object PowerExecution { @@ -44,6 +45,18 @@ object PowerExecution { activity.finish() } } + if (ActivityManager.isUserAMonkey() || Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q && + ActivityManager.isRunningInUserTestHarness() + ) { + activity.uiLog("Cannot execute in instrumentation test environment to prevent unexpected behaviors!") + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + activity.finishAndRemoveTask() + activity.releaseInstance() + } else { + activity.finishAffinity() + } + return + } when (labelResId) { R.string.func_lock_screen -> requestAccessibilityService(activity) { PowerAct.lockScreen(activity, callback) diff --git a/app/src/main/java/github/ryuunoakaihitomi/powerpanel/stat/InternalDoer.kt b/app/src/main/java/github/ryuunoakaihitomi/powerpanel/stat/InternalDoer.kt index 85534c9..c4df9d7 100644 --- a/app/src/main/java/github/ryuunoakaihitomi/powerpanel/stat/InternalDoer.kt +++ b/app/src/main/java/github/ryuunoakaihitomi/powerpanel/stat/InternalDoer.kt @@ -1,5 +1,6 @@ package github.ryuunoakaihitomi.powerpanel.stat +import android.content.Context import android.os.Bundle /** @@ -8,6 +9,7 @@ import android.os.Bundle */ interface InternalDoer { + fun initialize(ctx: Context) fun setCustomKey(k: String, v: Any) fun logEvent(tag: String, bundle: Bundle) fun log(level: String, tag: String, msg: String) {} diff --git a/app/src/main/java/github/ryuunoakaihitomi/powerpanel/stat/Statistics.kt b/app/src/main/java/github/ryuunoakaihitomi/powerpanel/stat/Statistics.kt index c94a570..d44ebda 100644 --- a/app/src/main/java/github/ryuunoakaihitomi/powerpanel/stat/Statistics.kt +++ b/app/src/main/java/github/ryuunoakaihitomi/powerpanel/stat/Statistics.kt @@ -1,5 +1,6 @@ package github.ryuunoakaihitomi.powerpanel.stat +import android.content.Context import android.os.Build import android.os.Bundle import androidx.annotation.StringRes @@ -58,7 +59,12 @@ object Statistics { InternalDoerImpl.logEvent(EVENT_DIALOG_CANCEL, bundle) } - fun recordEnvInfo() { + fun initConfig(context: Context) { + recordEnvInfo() + InternalDoerImpl.initialize(context) + } + + private fun recordEnvInfo() { arrayOf(Build::class, Build.VERSION::class).forEach { clz -> clz.java.fields.forEach enumProps@{ val name = it.name diff --git a/app/src/main/java/github/ryuunoakaihitomi/powerpanel/ui/OpenSourceLibDependencyActivity.kt b/app/src/main/java/github/ryuunoakaihitomi/powerpanel/ui/OpenSourceLibDependencyActivity.kt index 5c04022..c77dd33 100644 --- a/app/src/main/java/github/ryuunoakaihitomi/powerpanel/ui/OpenSourceLibDependencyActivity.kt +++ b/app/src/main/java/github/ryuunoakaihitomi/powerpanel/ui/OpenSourceLibDependencyActivity.kt @@ -23,6 +23,7 @@ import github.ryuunoakaihitomi.powerpanel.R import github.ryuunoakaihitomi.powerpanel.util.BlackMagic import github.ryuunoakaihitomi.powerpanel.util.RC import github.ryuunoakaihitomi.powerpanel.util.openUrlInBrowser +import github.ryuunoakaihitomi.powerpanel.util.uiLog import org.apache.commons.io.IOUtils import java.nio.charset.StandardCharsets import com.drakeet.about.License as L @@ -112,7 +113,7 @@ class OpenSourceLibDependencyActivity : AbsAboutActivity() { } private fun recordLogcat() { - Toast.makeText(application, "Recent $maxLineCount lines Logcat…", Toast.LENGTH_LONG).show() + uiLog("Recent $maxLineCount lines Logcat…") ar.launch("logcat_${System.currentTimeMillis().toString(Character.MAX_RADIX).uppercase()}") } // diff --git a/app/src/main/java/github/ryuunoakaihitomi/powerpanel/util/Extensions.kt b/app/src/main/java/github/ryuunoakaihitomi/powerpanel/util/Extensions.kt index 99944f0..cb0f264 100644 --- a/app/src/main/java/github/ryuunoakaihitomi/powerpanel/util/Extensions.kt +++ b/app/src/main/java/github/ryuunoakaihitomi/powerpanel/util/Extensions.kt @@ -10,6 +10,7 @@ import android.provider.Browser import android.service.quicksettings.Tile import android.text.Spannable import android.widget.TextView +import android.widget.Toast import androidx.annotation.RequiresApi import androidx.core.content.getSystemService import androidx.core.content.res.ResourcesCompat @@ -49,6 +50,11 @@ fun Context.isWatch() = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_ false } +fun Context.uiLog(msg: String) { + Timber.i("UILog -> $msg") + Toast.makeText(applicationContext, msg, Toast.LENGTH_LONG).show() +} + /** * @link https://stackoverflow.com/a/59472972/16091156 */ diff --git a/app/src/main/res/raw-zh-rCN/help.md b/app/src/main/res/raw-zh-rCN/help.md index 488ce51..bfc74af 100644 --- a/app/src/main/res/raw-zh-rCN/help.md +++ b/app/src/main/res/raw-zh-rCN/help.md @@ -29,4 +29,4 @@ ## 隐私声明 本应用开源,代码可供任何人查看。开发者承诺不会使应用做出任何有损用户隐私权等利益的行为。 -使用Firebase相关组件进行崩溃报告收集和使用信息统计,这些信息有益于开发者改进本应用。详情参阅:[Firebase 中的隐私权和安全性](https://firebase.google.cn/support/privacy) \ No newline at end of file +使用Firebase与华为AppGallery Connect相关组件进行崩溃报告收集和使用信息统计,这些信息有益于开发者改进本应用。详情参阅:[Firebase 中的隐私权和安全性](https://firebase.google.cn/support/privacy) [华为AppGallery Connect隐私及安全声明](https://developer.huawei.com/consumer/cn/doc/app/86741055) \ No newline at end of file diff --git a/app/src/main/res/raw/help.md b/app/src/main/res/raw/help.md index f6026b3..5aefb14 100644 --- a/app/src/main/res/raw/help.md +++ b/app/src/main/res/raw/help.md @@ -9,5 +9,6 @@ This android app is used to control the power state. ## Privacy statement > [Privacy and Security in Firebase](https://firebase.google.com/support/privacy) +> [Statement About Privacy and Security of HUAWEI AppGallery Connect](https://developer.huawei.com/consumer/en/doc/app/10128) The app is free and open-source, which means that its behavior will never infringe your privacy within the developer's control. \ No newline at end of file diff --git a/app/src/normal/java/github/ryuunoakaihitomi/powerpanel/stat/InternalDoerImpl.kt b/app/src/normal/java/github/ryuunoakaihitomi/powerpanel/stat/InternalDoerImpl.kt index 2a94827..496376f 100644 --- a/app/src/normal/java/github/ryuunoakaihitomi/powerpanel/stat/InternalDoerImpl.kt +++ b/app/src/normal/java/github/ryuunoakaihitomi/powerpanel/stat/InternalDoerImpl.kt @@ -1,9 +1,12 @@ package github.ryuunoakaihitomi.powerpanel.stat +import android.content.Context import android.os.Bundle import com.google.firebase.analytics.ktx.analytics import com.google.firebase.crashlytics.ktx.crashlytics import com.google.firebase.ktx.Firebase +import com.huawei.hms.analytics.HiAnalytics +import com.huawei.hms.analytics.HiAnalyticsTools import timber.log.Timber /** @@ -11,6 +14,11 @@ import timber.log.Timber */ object InternalDoerImpl : InternalDoer { + override fun initialize(ctx: Context) { + HiAnalyticsTools.enableLog() + HiAnalytics.getInstance(ctx) + } + override fun setCustomKey(k: String, v: Any) { Firebase.crashlytics.apply { when (v) { diff --git a/build.gradle b/build.gradle index 81b9121..6de858f 100644 --- a/build.gradle +++ b/build.gradle @@ -3,6 +3,7 @@ buildscript { repositories { google() mavenCentral() + maven { url 'https://developer.huawei.com/repo/' } } dependencies { classpath 'com.android.tools.build:gradle:7.0.1' @@ -11,6 +12,9 @@ buildscript { /* Crashlytics */ classpath 'com.google.gms:google-services:4.3.10' classpath 'com.google.firebase:firebase-crashlytics-gradle:2.7.1' + + /* AppGallery Connect */ + classpath 'com.huawei.agconnect:agcp:1.6.0.300' } } @@ -24,6 +28,7 @@ allprojects { google() mavenCentral() maven { url "https://jitpack.io" } + maven { url 'https://developer.huawei.com/repo/' } } }