permission_auto_reset 0.1.0 copy "permission_auto_reset: ^0.1.0" to clipboard
permission_auto_reset: ^0.1.0 copied to clipboard

PlatformAndroid

A Flutter plugin to check and manage Android's unused-app auto-reset and hibernation feature for your app.

permission_auto_reset #

StandWithPalestine Pub Package

A small Flutter plugin around Android's permission auto-reset & app hibernation APIs. Lets you ask "is the OS allowed to revoke my permissions and hibernate my app when it's unused?" and send the user to the right system screen to change it.

Features #

  • Check whether unused-app restrictions are currently enabled or disabled for your app.
  • Open the correct system settings page so the user can toggle it — falls back through manufacturer-specific screens (Samsung, Xiaomi/MIUI, Oppo/Realme/OnePlus, Huawei/Honor, Vivo) and finally the app details page.
  • Safe no-op on iOS, web, and Android < 11.

Install #

dependencies:
  permission_auto_reset: ^0.1.0
flutter pub get

Usage #

import 'package:permission_auto_reset/permission_auto_reset.dart';

final status = await PermissionAutoReset.checkRestrictionsStatus();

switch (status) {
  case RestrictionsStatus.enabled:
    // OS may revoke permissions / hibernate the app when unused.
    break;
  case RestrictionsStatus.disabled:
    // User has opted this app out of auto-reset.
    break;
  case RestrictionsStatus.featureNotAvailable:
    // Android < 11, web, iOS, etc.
    break;
  case RestrictionsStatus.error:
    // Could not determine status.
    break;
}

// Send the user to the right screen to change it.
final opened = await PermissionAutoReset.openRestrictionsSettings();

Background-app pattern #

If your app needs to keep permissions / not be hibernated, prompt the user:

Future<void> ensureBackgroundFriendly(BuildContext context) async {
  final status = await PermissionAutoReset.checkRestrictionsStatus();
  if (status != RestrictionsStatus.enabled) return;

  final goToSettings = await showDialog<bool>(
    context: context,
    builder: (_) => AlertDialog(
      title: const Text('Keep working in the background'),
      content: const Text(
        'Android may revoke this app\'s permissions if it stays unused. '
        'Disable auto-reset to keep it working reliably.',
      ),
      actions: [
        TextButton(onPressed: () => Navigator.pop(_, false), child: const Text('Later')),
        TextButton(onPressed: () => Navigator.pop(_, true), child: const Text('Open settings')),
      ],
    ),
  );

  if (goToSettings == true) {
    await PermissionAutoReset.openRestrictionsSettings();
  }
}

Platform support #

Platform Status
Android 11+ (API 30+) Full support via UnusedAppRestrictionsConstants
Android 10 and below Returns RestrictionsStatus.featureNotAvailable
iOS / web / desktop Returns RestrictionsStatus.featureNotAvailable

Support #

If this plugin helped you, consider supporting:

Buy Me A Coffee

3
likes
160
points
32
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

A Flutter plugin to check and manage Android's unused-app auto-reset and hibernation feature for your app.

Repository (GitHub)
View/report issues

License

MIT (license)

Dependencies

flutter

More

Packages that depend on permission_auto_reset

Packages that implement permission_auto_reset