-
-
Notifications
You must be signed in to change notification settings - Fork 874
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor: Port
canScheduleExactAlarms
(Android) (#1214)
* Port Android `Manifest.permission` and `Manifest.permission_group` (#1196) * Port `Manifest.permission` and `Manifest.permission_group` * Use Dart conventions for `Manifest` variables * Implement `checkPermissionStatus` * Change entry point of getting an `Activity`, implement `requestPermission` * Expose `requestCode` * Update tests * Update main.dart * Update CHANGELOG.md * Elaborate on concern * Replace `AndroidActivity` with `ActivityAware` * Delete test * Apply small fixes * Elaborate on missing Android activity * Regenerate pigeon files * Make small adjustments based on review * Update documentation * Update documentation * Implement `Settings` mirror * Implement `Uri` mirror * Add `Intent` constructor and update `Uri` implementation * Implement `Intent` methods * Implement `startActivity`, `getPackageName` for `Context` * Copy new `Context` methods to `Activity` * Implement `openAppSettings` in `PermissionHandlerAndroid` * Follow-up changes * Run `dart format .` * Add `startActivityForResult` * Add actions to `Settings` * Update TODOs * Run `dart format .` * Implement `getSystemService` * Add `Build` * Implement `PowerManager` * Fix bug with `PowerManager`, update `PermissionHandlerAndroid` * Run `dart format .` * Add sdk check to `isIgnoringBatteryOptimizations` * Implement `AlarmManager`
- Loading branch information
1 parent
b1bf5fc
commit 84ac0f9
Showing
14 changed files
with
872 additions
and
180 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
...roid/android/src/main/java/com/baseflow/permissionhandler/AlarmManagerFlutterApiImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package com.baseflow.permissionhandler; | ||
|
||
import android.app.AlarmManager; | ||
|
||
import androidx.annotation.NonNull; | ||
|
||
import com.baseflow.instancemanager.InstanceManager; | ||
import com.baseflow.permissionhandler.PermissionHandlerPigeon.AlarmManagerFlutterApi; | ||
|
||
import java.util.UUID; | ||
|
||
import io.flutter.plugin.common.BinaryMessenger; | ||
|
||
/** | ||
* Flutter API implementation for `AlarmManager`. | ||
* | ||
* <p>This class may handle adding native instances that are attached to a Dart instance or passing | ||
* arguments of callbacks methods to a Dart instance. | ||
*/ | ||
public class AlarmManagerFlutterApiImpl { | ||
// To ease adding additional methods, this value is added prematurely. | ||
@SuppressWarnings({"unused", "FieldCanBeLocal"}) | ||
private final BinaryMessenger binaryMessenger; | ||
|
||
private final InstanceManager instanceManager; | ||
|
||
private final AlarmManagerFlutterApi api; | ||
|
||
/** | ||
* Constructs a {@link AlarmManagerFlutterApiImpl}. | ||
* | ||
* @param binaryMessenger used to communicate with Dart over asynchronous messages | ||
* @param instanceManager maintains instances stored to communicate with attached Dart objects | ||
*/ | ||
public AlarmManagerFlutterApiImpl( | ||
@NonNull BinaryMessenger binaryMessenger, | ||
@NonNull InstanceManager instanceManager | ||
) { | ||
this.binaryMessenger = binaryMessenger; | ||
this.instanceManager = instanceManager; | ||
api = new AlarmManagerFlutterApi(binaryMessenger); | ||
} | ||
|
||
/** | ||
* Stores the `AlarmManager` instance and notifies Dart to create and store a new `AlarmManager` | ||
* instance that is attached to this one. If `instance` has already been added, this method does | ||
* nothing. | ||
*/ | ||
public void create(@NonNull AlarmManager instance) { | ||
if (!instanceManager.containsInstance(instance)) { | ||
final UUID alarmManagerInstanceUuid = instanceManager.addHostCreatedInstance(instance); | ||
api.create(alarmManagerInstanceUuid.toString(), reply -> {}); | ||
} | ||
} | ||
|
||
/** | ||
* Disposes of the `AlarmManager` instance in the instance manager and notifies Dart to do the | ||
* same. If `instance` was already disposed, this method does nothing. | ||
*/ | ||
public void dispose(AlarmManager instance) { | ||
final UUID alarmManagerInstanceUuid = instanceManager.getIdentifierForStrongReference(instance); | ||
if (alarmManagerInstanceUuid != null) { | ||
api.dispose(alarmManagerInstanceUuid.toString(), reply -> {}); | ||
} | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
...android/android/src/main/java/com/baseflow/permissionhandler/AlarmManagerHostApiImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package com.baseflow.permissionhandler; | ||
|
||
import android.os.Build; | ||
import android.app.AlarmManager; | ||
|
||
import androidx.annotation.NonNull; | ||
import androidx.annotation.RequiresApi; | ||
|
||
import com.baseflow.instancemanager.InstanceManager; | ||
import com.baseflow.permissionhandler.PermissionHandlerPigeon.AlarmManagerHostApi; | ||
|
||
import java.util.UUID; | ||
|
||
import io.flutter.plugin.common.BinaryMessenger; | ||
|
||
/** | ||
* Host API implementation for `AlarmManager`. | ||
* | ||
* <p>This class may handle instantiating and adding native object instances that are attached to a | ||
* Dart instance or handle method calls on the associated native class or an instance of the class. | ||
*/ | ||
public class AlarmManagerHostApiImpl implements AlarmManagerHostApi { | ||
// To ease adding additional methods, this value is added prematurely. | ||
@SuppressWarnings({"unused", "FieldCanBeLocal"}) | ||
private final BinaryMessenger binaryMessenger; | ||
|
||
private final InstanceManager instanceManager; | ||
|
||
/** | ||
* Constructs an {@link AlarmManagerHostApiImpl}. | ||
* | ||
* @param binaryMessenger used to communicate with Dart over asynchronous messages | ||
* @param instanceManager maintains instances stored to communicate with attached Dart objects | ||
*/ | ||
public AlarmManagerHostApiImpl( | ||
@NonNull BinaryMessenger binaryMessenger, | ||
@NonNull InstanceManager instanceManager | ||
) { | ||
this.binaryMessenger = binaryMessenger; | ||
this.instanceManager = instanceManager; | ||
} | ||
|
||
@RequiresApi(api = Build.VERSION_CODES.S) | ||
@NonNull | ||
@Override | ||
public Boolean canScheduleExactAlarms(@NonNull String instanceId) { | ||
final UUID instanceUuid = UUID.fromString(instanceId); | ||
final AlarmManager alarmManager = instanceManager.getInstance(instanceUuid); | ||
|
||
return alarmManager.canScheduleExactAlarms(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.