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

Đang mở Phù hợp với người mới
#583 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
78/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
android, java, react-native
Lĩnh vực
mobile

Hướng nghiên cứu

Đọc phần triển khai Android được liên kết trong issue, android/tsbackgroundfetch/src/main/java/com/transistorsoft/tsbackgroundfetch/BackgroundFetch.java, đặc biệt là status(). Kiểm tra cách Android báo cáo việc sử dụng nền bị hạn chế và so sánh với các hằng số trạng thái dự kiến. Hoàn thành khi status() báo cáo STATUS_DENIED nếu việc sử dụng nền bị hạn chế và hành vi này đã được xác minh trên Android 9 trở lên.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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
Ngôn ngữ chính
Java
Star
1.6k
Fork
194
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của transistorsoft/react-native-background-fetch

Tất cả issue của transistorsoft/react-native-background-fetch

Issue tương tự

Thêm issue về Java

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.