如何检测Google Play预发布报告运行环境?
精准识别Google Play预发布报告环境的技术方案
之前通过宽泛检测FTL环境来跳过启动UI的方案,会误覆盖Google Play应用审核场景,导致隐私合规问题。以下是几种精准区分预发布报告与普通FTL(含审核)环境的可靠方法:
方法1:检测预发布报告特有系统属性
Google Play预发布报告运行时,设备会自动设置专属系统属性firebase.test.lab.prelaunch为true,而其他FTL场景(包括应用审核)不会携带该属性。
Kotlin实现:
fun isRunningInPrelaunchReport(): Boolean { return try { val prelaunchProp = System.getProperty("firebase.test.lab.prelaunch") prelaunchProp != null && prelaunchProp.equals("true", ignoreCase = true) } catch (e: SecurityException) { // 若权限受限,默认返回false false } }
Java实现:
public static boolean isRunningInPrelaunchReport() { try { String prelaunchProp = System.getProperty("firebase.test.lab.prelaunch"); return prelaunchProp != null && prelaunchProp.equalsIgnoreCase("true"); } catch (SecurityException e) { return false; } }
方法2:通过FTL测试类型区分
FTL环境会暴露firebase.test.lab.testType系统属性,预发布报告的测试类型值为PRELAUNCH,而应用审核的FTL测试类型为APP_REVIEW,可通过该值精准判断。
Kotlin实现:
fun getFTLTestType(): String? { return try { System.getProperty("firebase.test.lab.testType") } catch (e: SecurityException) { null } } fun isRunningInPrelaunchReport(): Boolean { val testType = getFTLTestType() return testType != null && testType.equals("PRELAUNCH", ignoreCase = true) }
方法3:多条件组合校验(推荐)
为避免单一属性变更导致误判,可结合原有FTL环境检测逻辑与预发布特有属性,进一步提高准确性:
fun isRunningInFTL(): Boolean { return try { val ftlProp = System.getProperty("firebase.test.lab.instrumentation_test") ftlProp != null && ftlProp.equals("true", ignoreCase = true) } catch (e: SecurityException) { false } } fun isRunningInPrelaunchReport(): Boolean { return isRunningInFTL() && try { val prelaunchProp = System.getProperty("firebase.test.lab.prelaunch") prelaunchProp != null && prelaunchProp.equals("true", ignoreCase = true) } catch (e: SecurityException) { false } }
不推荐的方案说明
检测屏幕随机点击的方法不可靠:
- 应用审核也可能采用自动化脚本执行点击操作,容易误判
- 随机点击的检测逻辑难以标准化,易出现漏判或误触发
内容的提问来源于stack exchange,提问作者Stu
相关产品推荐
相关产品推荐

