[Bug]: status() returns STATUS_AVAILABLE while battery usage is Restricted
还没有人认领这个 Issue。
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 78/100
调研方向
阅读 issue 中链接的 Android 实现,android/tsbackgroundfetch/src/main/java/com/transistorsoft/tsbackgroundfetch/BackgroundFetch.java,尤其是 status()。检查 Android 如何报告后台使用受限,并将其与预期的状态常量进行比较。完成标准是:后台使用受限时,status()报告STATUS_DENIED,且该行为已在 Android 9 或更高版本上验证。
由索引模型根据 Issue 内容生成。
描述
Required Reading
- Confirmed
Plugin Version
4.4.2 (tsbackgroundfetch 4.1.1)
Mobile operating-system(s)
- iOS
- Android
Device Manufacturer(s) and Model(s)
Xiaomi 14T
Device operating-systems(s)
Android 16
React Native / Expo version
0.88.1
What happened?
status() always returns STATUS_AVAILABLE, also when the app's battery usage is Restricted, which blocks the fetch job in the background. Expected STATUS_DENIED, as on iOS when the user turns Background App Refresh off:
public static final int STATUS_DENIED = 1; // matches the JS constant
public int status() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
ActivityManager am = (ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE);
if (am != null && am.isBackgroundRestricted()) return STATUS_DENIED;
}
return STATUS_AVAILABLE;
}
If status() is meant to be iOS-only, a note in the docs would help.
Plugin Code and/or Config
BackgroundFetch.configure(
{
minimumFetchInterval: 15,
stopOnTerminate: false,
startOnBoot: true,
enableHeadless: true,
},
onFetch,
onTimeout
);
await BackgroundFetch.status(); // 2 while Restricted
Relevant log output
Restricted (adb shell cmd appops set <pkg> RUN_ANY_IN_BACKGROUND ignore), app in the background, adb shell am make-uid-idle <pkg>, from dumpsys jobscheduler:
JOB #u0a558/999: … com.transistorsoft.tsbackgroundfetch.FetchJobService
Satisfied constraints: DEVICE_NOT_DOZING WITHIN_QUOTA SSRU [0xb000000]
readyNotRestrictedInBg: false
STOP-P: #u0a558/999 … FetchJobService constraints
Allowed, same steps:
Satisfied constraints: FLEXIBILITY DEVICE_NOT_DOZING BACKGROUND_NOT_RESTRICTED WITHIN_QUOTA SSRU [0xb600000]
readyNotRestrictedInBg: true
D TSBackgroundFetch: - Background Fetch event received: react-native-background-fetch
- 主要语言
- Java
- 星标
- 1.6k
- 派生
- 194
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
transistorsoft/react-native-background-fetch 的其他 Issue
-
bug
难度 4/5 3-5 天 新手友好度 32/100
transistorsoft/react-native-background-fetch#582 · 2 条评论 ·
查看 transistorsoft/react-native-background-fetch 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 65/100
NationalSecurityAgency/ghidra#10220 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 76/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 80/100
维护者通常 1 天内回复
-
RIS export splits an organization name containing “and” into multiple authors可能已有人在做 @Gautam-aman 今天认领。 未关闭status: needs-triage
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
FailureContext.java rounds down thresholds in lastedAtLeast()可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭
难度 2/5 1-3 小时 新手友好度 82/100
维护者通常 1 天内回复