[Bug]: status() returns STATUS_AVAILABLE while battery usage is Restricted

未关闭 适合新手
#583 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
78/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
android, java, react-native
领域
mobile

调研方向

阅读 issue 中链接的 Android 实现,android/tsbackgroundfetch/src/main/java/com/transistorsoft/tsbackgroundfetch/BackgroundFetch.java,尤其是 status()。检查 Android 如何报告后台使用受限,并将其与预期的状态常量进行比较。完成标准是:后台使用受限时,status()报告STATUS_DENIED,且该行为已在 Android 9 或更高版本上验证。

由索引模型根据 Issue 内容生成。

描述

bug
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,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

transistorsoft/react-native-background-fetch 的其他 Issue

查看 transistorsoft/react-native-background-fetch 的全部 Issue

相似的 Issue

更多 Java Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。