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

オープン 初心者向け
#583 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
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. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

transistorsoft/react-native-background-fetch のほかの issue

transistorsoft/react-native-background-fetch の issue をすべて見る

似ている issue

Java の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。