Skip to content

Commit

Permalink
chore(native_storage): Migrate to jni 0.8 (#105)
Browse files Browse the repository at this point in the history
Enables isolated Android storage as JNI objects can now be shared via
isolates.
  • Loading branch information
dnys1 authored Apr 5, 2024
1 parent 438aca4 commit b755a6e
Show file tree
Hide file tree
Showing 6 changed files with 3,453 additions and 3,222 deletions.
4 changes: 4 additions & 0 deletions packages/native/storage/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.1.3

- chore: Migrate to jni 0.8.0 to enable isolated Android storage

## 0.1.2

- feat: Isolated memory storage on web
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import 'package:jni/jni.dart';
import 'package:native_storage/src/isolated/isolated_storage.dart';
import 'package:native_storage/src/isolated/isolated_storage_platform.unsupported.dart'
as unsupported;
import 'package:native_storage/src/local/local_storage_platform.vm.dart';
import 'package:native_storage/src/native/android/android.dart';

Expand Down Expand Up @@ -45,10 +42,4 @@ final class LocalStoragePlatformAndroid extends NativeLocalStoragePlatform {
_storage.write(key.toJString(), value.toJString());
return value;
}

// jni objects cannot be shared across isolates
// TODO(dnys1): Should be fixed in jni 0.8.0
@override
IsolatedNativeStorage get isolated =>
unsupported.IsolatedNativeStoragePlatform.from(this);
}
4 changes: 2 additions & 2 deletions packages/native/storage/lib/src/native/android/android.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ final class AndroidCommon {

// Must be getters so that they are fresh for each JNI call
late final Activity _mainActivity =
Activity.fromRef(Jni.getCurrentActivity());
Activity.fromReference(Jni.getCurrentActivity());
late final Context _mainActivityContext =
Context.fromRef(_mainActivity.reference);
Context.fromReference(_mainActivity.reference);

late final String packageName =
_mainActivityContext.getPackageName().toDartString();
Expand Down
Loading

0 comments on commit b755a6e

Please sign in to comment.