-
-
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
PermissionInfo
related classes (Android) (#1219)
* Port `Environment.isExternalStorageManager` * Port `PermissionInfo` related classes * Remove unnecessary `BinaryMessenger`s
- Loading branch information
1 parent
40e41a2
commit 2672794
Showing
46 changed files
with
3,945 additions
and
624 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
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
61 changes: 61 additions & 0 deletions
61
...roid/src/main/java/com/baseflow/permissionhandler/ApplicationInfoFlagsFlutterApiImpl.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,61 @@ | ||
package com.baseflow.permissionhandler; | ||
|
||
import android.content.pm.PackageManager.ApplicationInfoFlags; | ||
|
||
import androidx.annotation.NonNull; | ||
|
||
import com.baseflow.instancemanager.InstanceManager; | ||
import com.baseflow.permissionhandler.PermissionHandlerPigeon.ApplicationInfoFlagsFlutterApi; | ||
|
||
import java.util.UUID; | ||
|
||
import io.flutter.plugin.common.BinaryMessenger; | ||
|
||
/** | ||
* Flutter API implementation for `ApplicationInfoFlags`. | ||
* | ||
* <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 ApplicationInfoFlagsFlutterApiImpl { | ||
private final InstanceManager instanceManager; | ||
|
||
private final ApplicationInfoFlagsFlutterApi api; | ||
|
||
/** | ||
* Constructs a {@link ApplicationInfoFlagsFlutterApiImpl}. | ||
* | ||
* @param binaryMessenger used to communicate with Dart over asynchronous messages | ||
* @param instanceManager maintains instances stored to communicate with attached Dart objects | ||
*/ | ||
public ApplicationInfoFlagsFlutterApiImpl( | ||
@NonNull BinaryMessenger binaryMessenger, | ||
@NonNull InstanceManager instanceManager | ||
) { | ||
this.instanceManager = instanceManager; | ||
api = new ApplicationInfoFlagsFlutterApi(binaryMessenger); | ||
} | ||
|
||
/** | ||
* Stores the `ApplicationInfoFlags` instance and notifies Dart to create and store a new | ||
* `ApplicationInfoFlags` instance that is attached to this one. If `instance` has already been | ||
* added, this method does nothing. | ||
*/ | ||
public void create(@NonNull ApplicationInfoFlags instance) { | ||
if (!instanceManager.containsInstance(instance)) { | ||
final UUID applicationInfoFlagsInstanceUuid = instanceManager.addHostCreatedInstance(instance); | ||
api.create(applicationInfoFlagsInstanceUuid.toString(), reply -> {}); | ||
} | ||
} | ||
|
||
/** | ||
* Disposes of the `ApplicationInfoFlags` instance in the instance manager and notifies Dart to | ||
* do the same. If `instance` was already disposed, this method does nothing. | ||
*/ | ||
public void dispose(ApplicationInfoFlags instance) { | ||
final UUID applicationInfoFlagsInstanceUuid = instanceManager.getIdentifierForStrongReference(instance); | ||
if (applicationInfoFlagsInstanceUuid != null) { | ||
api.dispose(applicationInfoFlagsInstanceUuid.toString(), reply -> {}); | ||
} | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
...android/src/main/java/com/baseflow/permissionhandler/ApplicationInfoFlagsHostApiImpl.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,44 @@ | ||
package com.baseflow.permissionhandler; | ||
|
||
import android.content.pm.PackageManager; | ||
import android.os.Build; | ||
|
||
import androidx.annotation.NonNull; | ||
import androidx.annotation.RequiresApi; | ||
|
||
import com.baseflow.instancemanager.InstanceManager; | ||
import com.baseflow.permissionhandler.PermissionHandlerPigeon.ApplicationInfoFlagsHostApi; | ||
|
||
/** | ||
* Host API implementation for `ApplicationInfoFlags`. | ||
* | ||
* <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 ApplicationInfoFlagsHostApiImpl implements ApplicationInfoFlagsHostApi { | ||
private final InstanceManager instanceManager; | ||
|
||
private final ApplicationInfoFlagsFlutterApiImpl flutterApi; | ||
|
||
/** | ||
* Constructs an {@link ApplicationInfoFlagsHostApiImpl}. | ||
* | ||
* @param instanceManager maintains instances stored to communicate with attached Dart objects | ||
*/ | ||
public ApplicationInfoFlagsHostApiImpl( | ||
@NonNull ApplicationInfoFlagsFlutterApiImpl flutterApi, | ||
@NonNull InstanceManager instanceManager | ||
) { | ||
this.flutterApi = flutterApi; | ||
this.instanceManager = instanceManager; | ||
} | ||
|
||
@RequiresApi(api = Build.VERSION_CODES.TIRAMISU) | ||
@NonNull | ||
@Override | ||
public String of(@NonNull Long value) { | ||
final PackageManager.ApplicationInfoFlags flags = PackageManager.ApplicationInfoFlags.of(value); | ||
flutterApi.create(flags); | ||
return instanceManager.getIdentifierForStrongReference(flags).toString(); | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
...ndroid/src/main/java/com/baseflow/permissionhandler/ComponentInfoFlagsFlutterApiImpl.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,61 @@ | ||
package com.baseflow.permissionhandler; | ||
|
||
import android.content.pm.PackageManager.ComponentInfoFlags; | ||
|
||
import androidx.annotation.NonNull; | ||
|
||
import com.baseflow.instancemanager.InstanceManager; | ||
import com.baseflow.permissionhandler.PermissionHandlerPigeon.ComponentInfoFlagsFlutterApi; | ||
|
||
import java.util.UUID; | ||
|
||
import io.flutter.plugin.common.BinaryMessenger; | ||
|
||
/** | ||
* Flutter API implementation for `ComponentInfoFlags`. | ||
* | ||
* <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 ComponentInfoFlagsFlutterApiImpl { | ||
private final InstanceManager instanceManager; | ||
|
||
private final ComponentInfoFlagsFlutterApi api; | ||
|
||
/** | ||
* Constructs a {@link ComponentInfoFlagsFlutterApiImpl}. | ||
* | ||
* @param binaryMessenger used to communicate with Dart over asynchronous messages | ||
* @param instanceManager maintains instances stored to communicate with attached Dart objects | ||
*/ | ||
public ComponentInfoFlagsFlutterApiImpl( | ||
@NonNull BinaryMessenger binaryMessenger, | ||
@NonNull InstanceManager instanceManager | ||
) { | ||
this.instanceManager = instanceManager; | ||
api = new ComponentInfoFlagsFlutterApi(binaryMessenger); | ||
} | ||
|
||
/** | ||
* Stores the `ComponentInfoFlags` instance and notifies Dart to create and store a new | ||
* `ComponentInfoFlags` instance that is attached to this one. If `instance` has already been | ||
* added, this method does nothing. | ||
*/ | ||
public void create(@NonNull ComponentInfoFlags instance) { | ||
if (!instanceManager.containsInstance(instance)) { | ||
final UUID componentInfoFlagsInstanceUuid = instanceManager.addHostCreatedInstance(instance); | ||
api.create(componentInfoFlagsInstanceUuid.toString(), reply -> {}); | ||
} | ||
} | ||
|
||
/** | ||
* Disposes of the `ComponentInfoFlags` instance in the instance manager and notifies Dart to do | ||
* the same. If `instance` was already disposed, this method does nothing. | ||
*/ | ||
public void dispose(ComponentInfoFlags instance) { | ||
final UUID componentInfoFlagsInstanceUuid = instanceManager.getIdentifierForStrongReference(instance); | ||
if (componentInfoFlagsInstanceUuid != null) { | ||
api.dispose(componentInfoFlagsInstanceUuid.toString(), reply -> {}); | ||
} | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
...d/android/src/main/java/com/baseflow/permissionhandler/ComponentInfoFlagsHostApiImpl.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,44 @@ | ||
package com.baseflow.permissionhandler; | ||
|
||
import android.content.pm.PackageManager; | ||
import android.os.Build; | ||
|
||
import androidx.annotation.NonNull; | ||
import androidx.annotation.RequiresApi; | ||
|
||
import com.baseflow.instancemanager.InstanceManager; | ||
import com.baseflow.permissionhandler.PermissionHandlerPigeon.ComponentInfoFlagsHostApi; | ||
|
||
/** | ||
* Host API implementation for `ComponentInfoFlags`. | ||
* | ||
* <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 ComponentInfoFlagsHostApiImpl implements ComponentInfoFlagsHostApi { | ||
private final InstanceManager instanceManager; | ||
|
||
private final ComponentInfoFlagsFlutterApiImpl flutterApi; | ||
|
||
/** | ||
* Constructs an {@link ComponentInfoFlagsHostApiImpl}. | ||
* | ||
* @param instanceManager maintains instances stored to communicate with attached Dart objects | ||
*/ | ||
public ComponentInfoFlagsHostApiImpl( | ||
@NonNull ComponentInfoFlagsFlutterApiImpl flutterApi, | ||
@NonNull InstanceManager instanceManager | ||
) { | ||
this.flutterApi = flutterApi; | ||
this.instanceManager = instanceManager; | ||
} | ||
|
||
@RequiresApi(api = Build.VERSION_CODES.TIRAMISU) | ||
@NonNull | ||
@Override | ||
public String of(@NonNull Long value) { | ||
final PackageManager.ComponentInfoFlags flags = PackageManager.ComponentInfoFlags.of(value); | ||
flutterApi.create(flags); | ||
return instanceManager.getIdentifierForStrongReference(flags).toString(); | ||
} | ||
} |
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.