-
-
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.
- Loading branch information
1 parent
d955c86
commit 05f587a
Showing
15 changed files
with
718 additions
and
13 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
...droid/src/main/java/com/baseflow/permissionhandler/NotificationManagerFlutterApiImpl.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.NotificationManager; | ||
|
||
import androidx.annotation.NonNull; | ||
|
||
import com.baseflow.instancemanager.InstanceManager; | ||
import com.baseflow.permissionhandler.PermissionHandlerPigeon.NotificationManagerFlutterApi; | ||
|
||
import java.util.UUID; | ||
|
||
import io.flutter.plugin.common.BinaryMessenger; | ||
|
||
/** | ||
* Flutter API implementation for `NotificationManager`. | ||
* | ||
* <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 NotificationManagerFlutterApiImpl { | ||
// To ease adding additional methods, this value is added prematurely. | ||
@SuppressWarnings({"unused", "FieldCanBeLocal"}) | ||
private final BinaryMessenger binaryMessenger; | ||
|
||
private final InstanceManager instanceManager; | ||
|
||
private final NotificationManagerFlutterApi api; | ||
|
||
/** | ||
* Constructs a {@link NotificationManagerFlutterApiImpl}. | ||
* | ||
* @param binaryMessenger used to communicate with Dart over asynchronous messages | ||
* @param instanceManager maintains instances stored to communicate with attached Dart objects | ||
*/ | ||
public NotificationManagerFlutterApiImpl( | ||
@NonNull BinaryMessenger binaryMessenger, | ||
@NonNull InstanceManager instanceManager | ||
) { | ||
this.binaryMessenger = binaryMessenger; | ||
this.instanceManager = instanceManager; | ||
api = new NotificationManagerFlutterApi(binaryMessenger); | ||
} | ||
|
||
/** | ||
* Stores the `NotificationManager` instance and notifies Dart to create and store a new `NotificationManager` | ||
* instance that is attached to this one. If `instance` has already been added, this method does | ||
* nothing. | ||
*/ | ||
public void create(@NonNull NotificationManager instance) { | ||
if (!instanceManager.containsInstance(instance)) { | ||
final UUID notificationManagerInstanceUuid = instanceManager.addHostCreatedInstance(instance); | ||
api.create(notificationManagerInstanceUuid.toString(), reply -> {}); | ||
} | ||
} | ||
|
||
/** | ||
* Disposes of the `NotificationManager` instance in the instance manager and notifies Dart to do the | ||
* same. If `instance` was already disposed, this method does nothing. | ||
*/ | ||
public void dispose(NotificationManager instance) { | ||
final UUID notificationManagerInstanceUuid = instanceManager.getIdentifierForStrongReference(instance); | ||
if (notificationManagerInstanceUuid != null) { | ||
api.dispose(notificationManagerInstanceUuid.toString(), reply -> {}); | ||
} | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
.../android/src/main/java/com/baseflow/permissionhandler/NotificationManagerHostApiImpl.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,67 @@ | ||
package com.baseflow.permissionhandler; | ||
|
||
import android.app.NotificationManager; | ||
import android.os.Build; | ||
|
||
import androidx.annotation.NonNull; | ||
import androidx.annotation.RequiresApi; | ||
import androidx.core.app.NotificationManagerCompat; | ||
|
||
import com.baseflow.instancemanager.InstanceManager; | ||
import com.baseflow.permissionhandler.PermissionHandlerPigeon.NotificationManagerHostApi; | ||
|
||
import java.util.UUID; | ||
|
||
import io.flutter.plugin.common.BinaryMessenger; | ||
|
||
/** | ||
* Host API implementation for `NotificationManager`. | ||
* | ||
* <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 NotificationManagerHostApiImpl implements NotificationManagerHostApi { | ||
// To ease adding additional methods, this value is added prematurely. | ||
@SuppressWarnings({"unused", "FieldCanBeLocal"}) | ||
private final BinaryMessenger binaryMessenger; | ||
|
||
private final InstanceManager instanceManager; | ||
|
||
/** | ||
* Constructs an {@link NotificationManagerHostApiImpl}. | ||
* | ||
* @param binaryMessenger used to communicate with Dart over asynchronous messages | ||
* @param instanceManager maintains instances stored to communicate with attached Dart objects | ||
*/ | ||
public NotificationManagerHostApiImpl( | ||
@NonNull BinaryMessenger binaryMessenger, | ||
@NonNull InstanceManager instanceManager | ||
) { | ||
this.binaryMessenger = binaryMessenger; | ||
this.instanceManager = instanceManager; | ||
} | ||
|
||
@RequiresApi(api = Build.VERSION_CODES.M) | ||
@NonNull | ||
@Override | ||
public Boolean isNotificationPolicyAccessGranted( | ||
@NonNull String instanceId | ||
) { | ||
final UUID instanceUuid = UUID.fromString(instanceId); | ||
final NotificationManager notificationManager = instanceManager.getInstance(instanceUuid); | ||
|
||
return notificationManager.isNotificationPolicyAccessGranted(); | ||
} | ||
|
||
@RequiresApi(api = Build.VERSION_CODES.N) | ||
@NonNull | ||
@Override | ||
public Boolean areNotificationsEnabled( | ||
@NonNull String instanceId | ||
) { | ||
final UUID instanceUuid = UUID.fromString(instanceId); | ||
final NotificationManager notificationManager = instanceManager.getInstance(instanceUuid); | ||
|
||
return notificationManager.areNotificationsEnabled(); | ||
} | ||
} |
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.