-
-
Notifications
You must be signed in to change notification settings - Fork 876
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6004d9c
commit e3b6fd9
Showing
14 changed files
with
548 additions
and
0 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.