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

Abierto Apto para principiantes
#583 1 comentario 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
78/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
android, java, react-native
Área
mobile

Línea de trabajo

Lee la implementación de Android enlazada en el issue, android/tsbackgroundfetch/src/main/java/com/transistorsoft/tsbackgroundfetch/BackgroundFetch.java, especialmente status(). Comprueba cómo informa Android de las restricciones en el uso en segundo plano y compáralo con las constantes de estado esperadas. La tarea se considera terminada cuando status() devuelve STATUS_DENIED si el uso en segundo plano está restringido y el comportamiento se ha verificado en Android 9 o posterior.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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
Lenguaje dominante
Java
Estrellas
1.6k
Forks
194
Métricas de merge de PR
Sin PR fusionados en 30 d

Preparar el entorno

Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de transistorsoft/react-native-background-fetch

Todos los issues de transistorsoft/react-native-background-fetch

Issues similares

Más issues de Java

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.