Android 透过adb setprop 对手机设定参数,让你的APP可以动态开启隐藏功能

有时候可能为了开发使用,但又不想要让所有使用者看到该功能,这时候该怎么办,也许可以模仿连续点选某处10次,或者输入什么神秘密码的方式在app中,但除了这些方法外,是否还有什么更科技一点的方式呢?

透过adb setprop

参考firebase 设定debugApp的一个方式,可以透过

adb shell setprop debug.firebase.analytics.app com.packageName

来进行设定开启某一个app的debug资讯上传,于是乎就想到是不是这样就代表可以对手机写入一个动态设定呢? 而这个设定是重开机后就不见的

问了一下chatgpt后进行设定

adb shell setprop debug.hidden_feature_enabled true

可以看到是这样

adb shell setprop {key} {value}

透过

adb shell getprop

就可以看到他列出了系统所有的prop

[debug.atrace.tags.enableflags]: [0][debug.c2.use_dmabufheaps]: [1][debug.force_rtl]: [false][debug.hidden_feature_enabled]: [true][debug.hwc.winupdate]: [1][debug.hwui.use_hint_manager]: [true][debug.renderengine.backend]: [skiaglthreaded][debug.sf.dim_in_gamma_in_enhanced_screenshots]: [1][debug.sf.disable_backpressure]: [0][debug.sf.early.app.duration]: [16600000][debug.sf.early.sf.duration]: [16600000][debug.sf.earlyGl.app.duration]: [16600000][debug.sf.earlyGl.sf.duration]: [16600000][debug.sf.enable_adpf_cpu_hint]: [true][debug.sf.enable_gl_backpressure]: [1]

就可以看到刚刚的

[debug.hidden_feature_enabled]: [true] true

App中怎么获得这个资讯?

我写了这个method

private fun readRuntimeProperty(key: String,execute: (String) -> Unit) {      with(Runtime.getRuntime().exec("getprop $key")) {          BufferedReader(InputStreamReader(inputStream)).useLines {              execute(it.first())          }          destroy()      }  }

因此可以直接透过

private fun main() {readRuntimeProperty("debug.hidden_feature_enabled") {      toast("hasEnable:$it")  }}

就可以得到设定的结果做动态的应用,譬如给你家的QA让他透过ADB输入后(或者写成一个script),可以开启一些特殊让他测试用的介面或者功能

System.getProperty

另外你可能会提到System.getProperty(propertyName) 他是只会读到build.prop中设定值,理论上这边是系统资讯不可更改的区域

结论

可以用来作为快速的开关一些功能介面的隐藏指令,但建议不要把机密功能打开在里面


关于作者: 网站小编

码农网专注IT技术教程资源分享平台,学习资源下载网站,58码农网包含计算机技术、网站程序源码下载、编程技术论坛、互联网资源下载等产品服务,提供原创、优质、完整内容的专业码农交流分享平台。

热门文章