-
-
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 Service related classes (Android) (#1225)
* Port `Environment.isExternalStorageManager` * Port `PermissionInfo` related classes * Port `FeatureInfo` * Port `getSystemFeature` and `hasSystemFeature` * Port `TelephonyManager` * Port `LocationManager` * Port `BluetoothAdapter` * Port `BluetoothManager` * Remove unnecessary `BinaryMessenger`s * Port `ContentResolver` * Port `Context.getContentResolver` * Port `Settings.Secure` * Remove `static` from `SettingsSecure` getters * Add `Setting` actions * Remove unnecessary `BinaryMessenger`s
- Loading branch information
1 parent
2672794
commit f1c73a9
Showing
31 changed files
with
4,614 additions
and
338 deletions.
There are no files selected for viewing
61 changes: 61 additions & 0 deletions
61
.../android/src/main/java/com/baseflow/permissionhandler/BluetoothAdapterFlutterApiImpl.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.bluetooth.BluetoothAdapter; | ||
|
||
import androidx.annotation.NonNull; | ||
|
||
import com.baseflow.instancemanager.InstanceManager; | ||
import com.baseflow.permissionhandler.PermissionHandlerPigeon.BluetoothAdapterFlutterApi; | ||
|
||
import java.util.UUID; | ||
|
||
import io.flutter.plugin.common.BinaryMessenger; | ||
|
||
/** | ||
* Flutter API implementation for `BluetoothAdapter`. | ||
* | ||
* <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 BluetoothAdapterFlutterApiImpl { | ||
private final InstanceManager instanceManager; | ||
|
||
private final BluetoothAdapterFlutterApi api; | ||
|
||
/** | ||
* Constructs a {@link BluetoothAdapterFlutterApiImpl}. | ||
* | ||
* @param binaryMessenger used to communicate with Dart over asynchronous messages | ||
* @param instanceManager maintains instances stored to communicate with attached Dart objects | ||
*/ | ||
public BluetoothAdapterFlutterApiImpl( | ||
@NonNull BinaryMessenger binaryMessenger, | ||
@NonNull InstanceManager instanceManager | ||
) { | ||
this.instanceManager = instanceManager; | ||
api = new BluetoothAdapterFlutterApi(binaryMessenger); | ||
} | ||
|
||
/** | ||
* Stores the `BluetoothAdapter` instance and notifies Dart to create and store a new | ||
* `BluetoothAdapter` instance that is attached to this one. If `instance` has already been | ||
* added, this method does nothing. | ||
*/ | ||
public void create(@NonNull BluetoothAdapter instance) { | ||
if (!instanceManager.containsInstance(instance)) { | ||
final UUID bluetoothAdapterInstanceUuid = instanceManager.addHostCreatedInstance(instance); | ||
api.create(bluetoothAdapterInstanceUuid.toString(), reply -> {}); | ||
} | ||
} | ||
|
||
/** | ||
* Disposes of the `BluetoothAdapter` instance in the instance manager and notifies Dart to do | ||
* the same. If `instance` was already disposed, this method does nothing. | ||
*/ | ||
public void dispose(BluetoothAdapter instance) { | ||
final UUID bluetoothAdapterInstanceUuid = instanceManager.getIdentifierForStrongReference(instance); | ||
if (bluetoothAdapterInstanceUuid != null) { | ||
api.dispose(bluetoothAdapterInstanceUuid.toString(), reply -> {}); | ||
} | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
...oid/android/src/main/java/com/baseflow/permissionhandler/BluetoothAdapterHostApiImpl.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,53 @@ | ||
package com.baseflow.permissionhandler; | ||
|
||
|
||
import android.bluetooth.BluetoothAdapter; | ||
|
||
import androidx.annotation.NonNull; | ||
|
||
import com.baseflow.instancemanager.InstanceManager; | ||
import com.baseflow.permissionhandler.PermissionHandlerPigeon.BluetoothAdapterHostApi; | ||
|
||
import java.util.UUID; | ||
|
||
/** | ||
* Host API implementation for `BluetoothAdapter`. | ||
* | ||
* <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 BluetoothAdapterHostApiImpl implements BluetoothAdapterHostApi { | ||
private final InstanceManager instanceManager; | ||
|
||
private final BluetoothAdapterFlutterApiImpl bluetoothAdapterFlutterApi; | ||
|
||
/** | ||
* Constructs an {@link BluetoothAdapterHostApiImpl}. | ||
* | ||
* @param instanceManager maintains instances stored to communicate with attached Dart objects | ||
*/ | ||
public BluetoothAdapterHostApiImpl( | ||
@NonNull BluetoothAdapterFlutterApiImpl bluetoothAdapterFlutterApi, | ||
@NonNull InstanceManager instanceManager | ||
) { | ||
this.bluetoothAdapterFlutterApi = bluetoothAdapterFlutterApi; | ||
this.instanceManager = instanceManager; | ||
} | ||
|
||
@Deprecated | ||
@NonNull | ||
@Override | ||
public String getDefaultAdapter() { | ||
final BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); | ||
bluetoothAdapterFlutterApi.create(bluetoothAdapter); | ||
return instanceManager.getIdentifierForStrongReference(bluetoothAdapter).toString(); | ||
} | ||
|
||
@NonNull | ||
@Override | ||
public Boolean isEnabled(@NonNull String instanceId) { | ||
final UUID instanceUuid = UUID.fromString(instanceId); | ||
final BluetoothAdapter bluetoothAdapter = instanceManager.getInstance(instanceUuid); | ||
return bluetoothAdapter.isEnabled(); | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
.../android/src/main/java/com/baseflow/permissionhandler/BluetoothManagerFlutterApiImpl.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.bluetooth.BluetoothManager; | ||
|
||
import androidx.annotation.NonNull; | ||
|
||
import com.baseflow.instancemanager.InstanceManager; | ||
import com.baseflow.permissionhandler.PermissionHandlerPigeon.BluetoothManagerFlutterApi; | ||
|
||
import java.util.UUID; | ||
|
||
import io.flutter.plugin.common.BinaryMessenger; | ||
|
||
/** | ||
* Flutter API implementation for `BluetoothManager`. | ||
* | ||
* <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 BluetoothManagerFlutterApiImpl { | ||
private final InstanceManager instanceManager; | ||
|
||
private final BluetoothManagerFlutterApi api; | ||
|
||
/** | ||
* Constructs a {@link BluetoothManagerFlutterApiImpl}. | ||
* | ||
* @param binaryMessenger used to communicate with Dart over asynchronous messages | ||
* @param instanceManager maintains instances stored to communicate with attached Dart objects | ||
*/ | ||
public BluetoothManagerFlutterApiImpl( | ||
@NonNull BinaryMessenger binaryMessenger, | ||
@NonNull InstanceManager instanceManager | ||
) { | ||
this.instanceManager = instanceManager; | ||
api = new BluetoothManagerFlutterApi(binaryMessenger); | ||
} | ||
|
||
/** | ||
* Stores the `BluetoothManager` instance and notifies Dart to create and store a new | ||
* `BluetoothManager` instance that is attached to this one. If `instance` has already been | ||
* added, this method does nothing. | ||
*/ | ||
public void create(@NonNull BluetoothManager instance) { | ||
if (!instanceManager.containsInstance(instance)) { | ||
final UUID bluetoothManagerInstanceUuid = instanceManager.addHostCreatedInstance(instance); | ||
api.create(bluetoothManagerInstanceUuid.toString(), reply -> {}); | ||
} | ||
} | ||
|
||
/** | ||
* Disposes of the `BluetoothManager` instance in the instance manager and notifies Dart to do | ||
* the same. If `instance` was already disposed, this method does nothing. | ||
*/ | ||
public void dispose(BluetoothManager instance) { | ||
final UUID bluetoothManagerInstanceUuid = instanceManager.getIdentifierForStrongReference(instance); | ||
if (bluetoothManagerInstanceUuid != null) { | ||
api.dispose(bluetoothManagerInstanceUuid.toString(), reply -> {}); | ||
} | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
...oid/android/src/main/java/com/baseflow/permissionhandler/BluetoothManagerHostApiImpl.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.bluetooth.BluetoothAdapter; | ||
import android.bluetooth.BluetoothManager; | ||
import android.os.Build; | ||
|
||
import androidx.annotation.NonNull; | ||
import androidx.annotation.RequiresApi; | ||
|
||
import com.baseflow.instancemanager.InstanceManager; | ||
import com.baseflow.permissionhandler.PermissionHandlerPigeon.BluetoothManagerHostApi; | ||
|
||
import java.util.UUID; | ||
|
||
/** | ||
* Host API implementation for `BluetoothManager`. | ||
* | ||
* <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 BluetoothManagerHostApiImpl implements BluetoothManagerHostApi { | ||
private final InstanceManager instanceManager; | ||
|
||
private final BluetoothAdapterFlutterApiImpl bluetoothAdapterFlutterApi; | ||
|
||
/** | ||
* Constructs an {@link BluetoothManagerHostApiImpl}. | ||
* | ||
* @param instanceManager maintains instances stored to communicate with attached Dart objects | ||
*/ | ||
public BluetoothManagerHostApiImpl( | ||
@NonNull BluetoothAdapterFlutterApiImpl bluetoothAdapterFlutterApi, | ||
@NonNull InstanceManager instanceManager | ||
) { | ||
this.bluetoothAdapterFlutterApi = bluetoothAdapterFlutterApi; | ||
this.instanceManager = instanceManager; | ||
} | ||
|
||
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR2) | ||
@NonNull | ||
@Override | ||
public String getAdapter(@NonNull String instanceId) { | ||
final UUID instanceUuid = UUID.fromString(instanceId); | ||
final BluetoothManager bluetoothManager = instanceManager.getInstance(instanceUuid); | ||
final BluetoothAdapter bluetoothAdapter = bluetoothManager.getAdapter(); | ||
|
||
bluetoothAdapterFlutterApi.create(bluetoothAdapter); | ||
|
||
return instanceManager.getIdentifierForStrongReference(bluetoothAdapter).toString(); | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
...d/android/src/main/java/com/baseflow/permissionhandler/ContentResolverFlutterApiImpl.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.ContentResolver; | ||
|
||
import androidx.annotation.NonNull; | ||
|
||
import com.baseflow.instancemanager.InstanceManager; | ||
import com.baseflow.permissionhandler.PermissionHandlerPigeon.ContentResolverFlutterApi; | ||
|
||
import java.util.UUID; | ||
|
||
import io.flutter.plugin.common.BinaryMessenger; | ||
|
||
/** | ||
* Flutter API implementation for `ContentResolver`. | ||
* | ||
* <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 ContentResolverFlutterApiImpl { | ||
private final InstanceManager instanceManager; | ||
|
||
private final ContentResolverFlutterApi api; | ||
|
||
/** | ||
* Constructs a {@link ContentResolverFlutterApiImpl}. | ||
* | ||
* @param binaryMessenger used to communicate with Dart over asynchronous messages | ||
* @param instanceManager maintains instances stored to communicate with attached Dart objects | ||
*/ | ||
public ContentResolverFlutterApiImpl( | ||
@NonNull BinaryMessenger binaryMessenger, | ||
@NonNull InstanceManager instanceManager | ||
) { | ||
this.instanceManager = instanceManager; | ||
api = new ContentResolverFlutterApi(binaryMessenger); | ||
} | ||
|
||
/** | ||
* Stores the `ContentResolver` instance and notifies Dart to create and store a new | ||
* `ContentResolver` instance that is attached to this one. If `instance` has already been | ||
* added, this method does nothing. | ||
*/ | ||
public void create(@NonNull ContentResolver instance) { | ||
if (!instanceManager.containsInstance(instance)) { | ||
final UUID contentResolverInstanceUuid = instanceManager.addHostCreatedInstance(instance); | ||
api.create(contentResolverInstanceUuid.toString(), reply -> {}); | ||
} | ||
} | ||
|
||
/** | ||
* Disposes of the `ContentResolver` instance in the instance manager and notifies Dart to do | ||
* the same. If `instance` was already disposed, this method does nothing. | ||
*/ | ||
public void dispose(ContentResolver instance) { | ||
final UUID contentResolverInstanceUuid = instanceManager.getIdentifierForStrongReference(instance); | ||
if (contentResolverInstanceUuid != null) { | ||
api.dispose(contentResolverInstanceUuid.toString(), reply -> {}); | ||
} | ||
} | ||
} |
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.