Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(Android) Add background battery usage restriction detection #221

Merged
merged 1 commit into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading