diff --git a/lib/services/root_api.dart b/lib/services/root_api.dart index 60ba4598..7965a359 100644 --- a/lib/services/root_api.dart +++ b/lib/services/root_api.dart @@ -5,6 +5,15 @@ class RootAPI { final String _postFsDataDirPath = '/data/adb/post-fs-data.d'; final String _serviceDDirPath = '/data/adb/service.d'; + Future isRooted() async { + try { + bool? isRooted = await Root.isRootAvailable(); + return isRooted != null && isRooted; + } on Exception { + return false; + } + } + Future hasRootPermissions() async { try { bool? isRooted = await Root.isRootAvailable(); diff --git a/lib/ui/views/installer/installer_view.dart b/lib/ui/views/installer/installer_view.dart index e9cccb71..22bbdd4b 100644 --- a/lib/ui/views/installer/installer_view.dart +++ b/lib/ui/views/installer/installer_view.dart @@ -106,7 +106,7 @@ class InstallerView extends StatelessWidget { ), ), Visibility( - visible: !model.isInstalled, + visible: !model.isInstalled && model.isRooted, child: CustomMaterialButton( isFilled: false, label: diff --git a/lib/ui/views/installer/installer_viewmodel.dart b/lib/ui/views/installer/installer_viewmodel.dart index 70b51347..d355600b 100644 --- a/lib/ui/views/installer/installer_viewmodel.dart +++ b/lib/ui/views/installer/installer_viewmodel.dart @@ -1,3 +1,4 @@ +// ignore_for_file: use_build_context_synchronously import 'package:device_apps/device_apps.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; @@ -9,6 +10,7 @@ import 'package:revanced_manager/models/patch.dart'; import 'package:revanced_manager/models/patched_application.dart'; import 'package:revanced_manager/services/manager_api.dart'; import 'package:revanced_manager/services/patcher_api.dart'; +import 'package:revanced_manager/services/root_api.dart'; import 'package:revanced_manager/services/toast.dart'; import 'package:revanced_manager/ui/views/patcher/patcher_viewmodel.dart'; import 'package:revanced_manager/ui/widgets/shared/custom_material_button.dart'; @@ -18,6 +20,7 @@ import 'package:wakelock/wakelock.dart'; class InstallerViewModel extends BaseViewModel { final ManagerAPI _managerAPI = locator(); final PatcherAPI _patcherAPI = locator(); + final RootAPI _rootAPI = RootAPI(); final Toast _toast = locator(); final PatchedApplication _app = locator().selectedApp!; final List _patches = locator().selectedPatches; @@ -28,11 +31,13 @@ class InstallerViewModel extends BaseViewModel { double? progress = 0.0; String logs = ''; String headerLogs = ''; + bool isRooted = false; bool isPatching = true; bool isInstalled = false; bool hasErrors = false; Future initialize(BuildContext context) async { + isRooted = await _rootAPI.isRooted(); if (await Permission.ignoreBatteryOptimizations.isGranted) { try { FlutterBackground.initialize(