Skip to content

Commit

Permalink
(Android) Add background battery usage restriction
Browse files Browse the repository at this point in the history
  • Loading branch information
peachbits committed Nov 11, 2024
1 parent 0aba510 commit f1f6345
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Unreleased

- added: (Android) Detect if user restricted background battery usage

## 3.23.0 (2024-11-01)

- changed: Changed semantics for invalid password login error message: "Invalid username or password"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.Manifest;
import android.app.Activity;
import android.app.ActivityManager;
import android.content.Context;
import android.content.pm.PackageManager;
import android.hardware.fingerprint.FingerprintManager;
Expand Down Expand Up @@ -392,10 +393,15 @@ public void getSupportedBiometryType(Promise promise) {
}
}

// Function should only be used in iOS and not available on android.
// Resolve with a unavailable if ever, meaning not available on this device
@ReactMethod
public void backgroundAppRefreshStatus(Promise promise) {
promise.resolve("unavailable");
if (android.os.Build.VERSION.SDK_INT >= 28) {
ActivityManager activityManager =
(ActivityManager) getReactApplicationContext().getSystemService(Context.ACTIVITY_SERVICE);
String backgroundStatus = activityManager.isBackgroundRestricted() ? "blocked" : "granted";
promise.resolve(backgroundStatus);
} else {
promise.resolve("unavailable");
}
}
}
8 changes: 3 additions & 5 deletions src/util/notificationPermissionReminder.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,9 @@ export const showNotificationPermissionReminder = async (
? 1
: 0

const statusAppRefresh = isIos
? await AbcCoreJsUi.backgroundAppRefreshStatus().catch((error: undefined) =>
console.log(error)
)
: undefined
const statusAppRefresh = await AbcCoreJsUi.backgroundAppRefreshStatus().catch(
(error: unknown) => console.log(error)
)
const refreshEnabled = statusAppRefresh !== RESULTS.BLOCKED ? 1 : 0

const notificationPermissionsInfoJson = await disklet
Expand Down

0 comments on commit f1f6345

Please sign in to comment.