Skip to content
This repository has been archived by the owner on Jan 9, 2024. It is now read-only.

Commit

Permalink
R3.12
Browse files Browse the repository at this point in the history
拒绝自动化服务操作应用,防止意外行为。
集成华为AGC分析服务,作为Firebase的备用措施。
  • Loading branch information
ryuunoakaihitomi committed Sep 1, 2021
1 parent c2bdf31 commit fa9b74d
Show file tree
Hide file tree
Showing 14 changed files with 72 additions and 10 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,6 @@ lint/tmp/

# --- 自定义配置 ---
# 签名信息
signInfo.properties
signInfo.properties
# 华为分析
agconnect-services.json
3 changes: 2 additions & 1 deletion BUILD_NOTE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
20 changes: 16 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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')}"

Expand All @@ -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() + '\"'
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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'
}
}

Expand All @@ -116,20 +126,22 @@ 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'
implementation "io.noties.markwon:core:$markwon_version"
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'
// 固定在此版本,理由同下段注释
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package github.ryuunoakaihitomi.powerpanel.stat

import android.content.Context
import android.os.Bundle

/**
Expand All @@ -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) {}
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()}")
}
//</editor-fold>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
*/
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/raw-zh-rCN/help.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@
## 隐私声明
本应用开源,代码可供任何人查看。开发者承诺不会使应用做出任何有损用户隐私权等利益的行为。

使用Firebase相关组件进行崩溃报告收集和使用信息统计,这些信息有益于开发者改进本应用。详情参阅:[Firebase 中的隐私权和安全性](https://firebase.google.cn/support/privacy)
使用Firebase与华为AppGallery Connect相关组件进行崩溃报告收集和使用信息统计,这些信息有益于开发者改进本应用。详情参阅:[Firebase 中的隐私权和安全性](https://firebase.google.cn/support/privacy) [华为AppGallery Connect隐私及安全声明](https://developer.huawei.com/consumer/cn/doc/app/86741055)
1 change: 1 addition & 0 deletions app/src/main/res/raw/help.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
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

/**
* 目前使用的是`Firebase`
*/
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) {
Expand Down
5 changes: 5 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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'
}
}

Expand All @@ -24,6 +28,7 @@ allprojects {
google()
mavenCentral()
maven { url "https://jitpack.io" }
maven { url 'https://developer.huawei.com/repo/' }
}
}

Expand Down

0 comments on commit fa9b74d

Please sign in to comment.