Move to plugins🐱🎉

This commit is contained in:
Gregory Velichko
2024-04-14 18:40:32 +03:00
parent fb06babb96
commit 7b882d9bd8
17 changed files with 141 additions and 484 deletions

View File

@@ -34,7 +34,7 @@ import 'package:android_intent_plus/android_intent.dart';
import 'package:flutter_archive/flutter_archive.dart';
import 'package:share_plus/share_plus.dart';
import 'package:shared_storage/shared_storage.dart' as saf;
import 'native_provider.dart';
import 'package:shizuku_apk_installer/shizuku_apk_installer.dart';
final pm = AndroidPackageManager();
@@ -634,7 +634,7 @@ class AppsProvider with ChangeNotifier {
!(await canDowngradeApps())) {
throw DowngradeError();
}
if (needsBGWorkaround) {
if (needsBGWorkaround && !settingsProvider.useShizuku) {
// The below 'await' will never return if we are in a background process
// To work around this, we should assume the install will be successful
// So we update the app's installed version first as we will never get to the later code
@@ -647,13 +647,10 @@ class AppsProvider with ChangeNotifier {
}
int? code;
if (!settingsProvider.useShizuku) {
code = await AndroidPackageInstaller.installApk(
apkFilePath: file.file.path);
code = await AndroidPackageInstaller.installApk(apkFilePath: file.file.path);
} else {
code = (await NativeFeatures.installWithShizuku(
apkFileUri: file.file.uri.toString()))
? 0
: 1;
code = await ShizukuApkInstaller.installAPK(file.file.uri.toString(),
settingsProvider.pretendToBeGooglePlay ? "com.android.vending" : "");
}
bool installed = false;
if (code != null && code != 0 && code != 3) {
@@ -828,11 +825,16 @@ class AppsProvider with ChangeNotifier {
throw ObtainiumError(tr('cancelled'));
}
} else {
int code = await NativeFeatures.checkPermissionShizuku();
if (code == 0) {
throw ObtainiumError(tr('cancelled'));
} else if (code == -1) {
throw ObtainiumError(tr('shizukuBinderNotFound'));
String? code = await ShizukuApkInstaller.checkPermission();
switch(code!){
case 'binder_not_found':
throw ObtainiumError(tr('shizukuBinderNotFound'));
case 'old_shizuku':
throw ObtainiumError(tr('shizukuOld'));
case 'old_android_with_adb':
throw ObtainiumError(tr('shizukuOldAndroidWithADB'));
case 'denied':
throw ObtainiumError(tr('cancelled'));
}
}
if (!willBeSilent && context != null && !settingsProvider.useShizuku) {

View File

@@ -4,36 +4,13 @@ import 'package:android_system_font/android_system_font.dart';
import 'package:flutter/services.dart';
class NativeFeatures {
static const MethodChannel _channel = MethodChannel('native');
static bool _systemFontLoaded = false;
static bool _callbacksApplied = false;
static int _resPermShizuku = -2; // not set
static Future<ByteData> _readFileBytes(String path) async {
var bytes = await File(path).readAsBytes();
return ByteData.view(bytes.buffer);
}
static Future _handleCalls(MethodCall call) async {
if (call.method == 'resPermShizuku') {
_resPermShizuku = call.arguments['res'];
}
}
static Future _waitWhile(bool Function() test,
[Duration pollInterval = const Duration(milliseconds: 250)]) {
var completer = Completer();
check() {
if (test()) {
Timer(pollInterval, check);
} else {
completer.complete();
}
}
check();
return completer.future;
}
static Future loadSystemFont() async {
if (_systemFontLoaded) return;
var fontLoader = FontLoader('SystemFont');
@@ -42,23 +19,4 @@ class NativeFeatures {
fontLoader.load();
_systemFontLoaded = true;
}
static Future<int> checkPermissionShizuku() async {
if (!_callbacksApplied) {
_channel.setMethodCallHandler(_handleCalls);
_callbacksApplied = true;
}
int res = await _channel.invokeMethod('checkPermissionShizuku');
if (res == -2) {
await _waitWhile(() => _resPermShizuku == -2);
res = _resPermShizuku;
_resPermShizuku = -2;
}
return res;
}
static Future<bool> installWithShizuku({required String apkFileUri}) async {
return await _channel.invokeMethod(
'installWithShizuku', {'apkFileUri': apkFileUri});
}
}

View File

@@ -82,6 +82,15 @@ class SettingsProvider with ChangeNotifier {
notifyListeners();
}
bool get pretendToBeGooglePlay{
return prefs?.getBool('pretendToBeGooglePlay') ?? false;
}
set pretendToBeGooglePlay(bool pretendToBeGooglePlay) {
prefs?.setBool('pretendToBeGooglePlay', pretendToBeGooglePlay);
notifyListeners();
}
ThemeSettings get theme {
return ThemeSettings
.values[prefs?.getInt('theme') ?? ThemeSettings.system.index];