diff --git a/app/build.gradle b/app/build.gradle deleted file mode 100644 index 263433ac4..000000000 --- a/app/build.gradle +++ /dev/null @@ -1,180 +0,0 @@ -/* - * Copyright (c) 2016-2018 Projekt Substratum - * This file is part of Substratum. - * - * SPDX-License-Identifier: GPL-3.0-Or-Later - */ - -apply plugin: 'com.android.application' -apply plugin: 'io.fabric' - -final def gitHash = { -> - final def stdout = new ByteArrayOutputStream() - exec { - commandLine 'git', 'rev-parse', '--short', 'HEAD' - standardOutput = stdout - } - stdout.toString().trim() -} - -// Create a variable called keystorePropertiesFile, and initialize it to your -// keystore.properties file, in the rootProject folder. -final def keystorePropertiesFile = rootProject.file("keystore.properties") - -android { - compileSdkVersion 28 - lintOptions { - abortOnError false - checkAllWarnings false - checkReleaseBuilds false - ignoreWarnings true - quiet true - } - dataBinding.enabled true - android.applicationVariants.all { final variant -> - variant.outputs.all { - outputFileName = "substratum_${variant.versionCode}_${gitHash()}.apk" - } - } - defaultConfig { - applicationId "projekt.substratum" - minSdkVersion 24 - targetSdkVersion 28 - versionCode 1010 - versionName "one thousand ten" - buildConfigField "java.util.Date", "buildTime", "new java.util.Date(" + System.currentTimeMillis() + "L)" - buildConfigField "String", "GIT_HASH", "\"${gitHash()}\"" - buildConfigField "boolean", "ENHANCED_LOGGING", "false" - } - - // If the keystore file exists - if (keystorePropertiesFile.exists()) { - // Initialize a new Properties() object called keystoreProperties. - final def keystoreProperties = new Properties() - - // Load your keystore.properties file into the keystoreProperties object. - keystoreProperties.load(new FileInputStream(keystorePropertiesFile)) - - signingConfigs { - release { - keyAlias keystoreProperties['keyAlias'] - keyPassword keystoreProperties['keyPassword'] - storeFile file(keystoreProperties['storeFile']) - storePassword keystoreProperties['storePassword'] - } - } - } - buildTypes { - debug { - debuggable true - minifyEnabled false - proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' - } - release { - minifyEnabled true - useProguard false - shrinkResources true - proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' - if (keystorePropertiesFile.exists()) signingConfig signingConfigs.release - } - } - compileOptions { - sourceCompatibility JavaVersion.VERSION_1_8 - targetCompatibility JavaVersion.VERSION_1_8 - } - dexOptions { - javaMaxHeapSize '2048m' - } - packagingOptions { - exclude 'META-INF/LICENSE' - exclude 'META-INF/LICENSE-FIREBASE.txt' - exclude 'META-INF/NOTICE' - } -} - -ext { - aboutVersion = '6.0.9' - androidXVersion = '1.0.0' - apkSigVersion = '3.2.0' - caocVersion = '2.2.0' - commonsIoVersion = '2.5' - crashlyticsVersion = '2.9.5' - databindingVersion = '3.3.0-alpha08' - expandableLayoutVersion = '2.9.2' - fabSheetVersion = '1.2.1' - firebaseVersion = '16.0.4' - firebaseDBVersion = '16.0.3' - floatingHeadVersion = '2.3.2' - gestureRecyclerVersion = '1.5.0' - glideVersion = '4.8.0' - imageCropperVersion = '2.7.0' - slf4jVersion = '1.7.16' - svgViewVersion = '1.0.5' - welcomeVersion = '1.4.1' - ztZipVersion = '1.13' -} - -dependencies { - implementation fileTree(include: ['*.jar'], dir: 'libs') - - // Android Support Libraries - implementation "androidx.databinding:databinding-runtime:$databindingVersion" - implementation "androidx.appcompat:appcompat:$androidXVersion" - implementation "androidx.cardview:cardview:$androidXVersion" - implementation "androidx.recyclerview:recyclerview:$androidXVersion" - implementation "com.google.android.material:material:$androidXVersion" - implementation "androidx.palette:palette:$androidXVersion" - - // Firebase - implementation "com.google.firebase:firebase-core:$firebaseVersion" - implementation "com.google.firebase:firebase-database:$firebaseDBVersion" - - // Crashlytics - implementation "com.crashlytics.sdk.android:crashlytics:$crashlyticsVersion" - - // Image Downloading and Caching - implementation "com.github.bumptech.glide:glide:$glideVersion" - annotationProcessor "com.github.bumptech.glide:compiler:$glideVersion" - - // Commons IO - implementation "commons-io:commons-io:$commonsIoVersion" - - // APK Signer - implementation "com.android.tools.build:apksig:$apkSigVersion" - - // App Intro - implementation "com.stephentuso:welcome:$welcomeVersion" - - // Floating Action Buttons - implementation "com.gordonwong:material-sheet-fab:$fabSheetVersion" - - // About Libraries - implementation("com.mikepenz:aboutlibraries:$aboutVersion@aar") { - transitive = true - } - - // Gesture RecyclerView - implementation "com.thesurix.gesturerecycler:gesture-recycler:$gestureRecyclerVersion" - - // ZT Zip - implementation "org.zeroturnaround:zt-zip:$ztZipVersion" - - // Image Processing - implementation "com.theartofdev.edmodo:android-image-cropper:$imageCropperVersion" - - // Expandable Layout - implementation "net.cachapa.expandablelayout:expandablelayout:$expandableLayoutVersion" - - // Floating App Head - implementation "com.github.recruit-lifestyle:FloatingView:$floatingHeadVersion" - - // Crash Activity - implementation "cat.ereza:customactivityoncrash:$caocVersion" - - // Splash screen svg animation - implementation "com.jaredrummler:animated-svg-view:$svgViewVersion" - - // SLF4J LoggerFactory - implementation "org.slf4j:slf4j-api:$slf4jVersion" -} -apply plugin: 'com.google.gms.google-services' \ No newline at end of file diff --git a/app/build.gradle.kts b/app/build.gradle.kts new file mode 100644 index 000000000..ef75eabca --- /dev/null +++ b/app/build.gradle.kts @@ -0,0 +1,113 @@ +/* + * Copyright (c) 2016-2018 Projekt Substratum + * This file is part of Substratum. + * + * SPDX-License-Identifier: GPL-3.0-Or-Later + */ + +import java.io.FileInputStream +import java.io.IOException +import java.util.Properties + +plugins { + id("com.android.application") +} + +val keystorePropertiesFile = rootProject.file("keystore.properties") +val buildTypeRelease = "release" + +fun gitHash(): String { + try { + return Runtime.getRuntime().exec("git describe --tags").inputStream.reader().use { it.readText() }.trim() + } catch (ignored: IOException) { + } + return "" +} + +android { + compileSdkVersion(28) + dataBinding.isEnabled = true + defaultConfig { + applicationId = "projekt.substratum" + minSdkVersion(24) + targetSdkVersion(28) + versionCode = 1013 + versionName = "one thousand thirteen" + buildConfigField("java.util.Date", "buildTime", "new java.util.Date(${System.currentTimeMillis()}L)") + buildConfigField("String", "GIT_HASH", "\"${gitHash()}\"") + buildConfigField("boolean", "ENHANCED_LOGGING", "false") + setProperty("archivesBaseName", "substratum_${gitHash()}") + } + compileOptions { + setSourceCompatibility(JavaVersion.VERSION_1_8) + setTargetCompatibility(JavaVersion.VERSION_1_8) + } + if (keystorePropertiesFile.exists()) { + val keystoreProperties = Properties() + keystoreProperties.load(FileInputStream(keystorePropertiesFile)) + + signingConfigs { + create(buildTypeRelease) { + keyAlias = keystoreProperties["keyAlias"].toString() + keyPassword = keystoreProperties["keyPassword"].toString() + storeFile = rootProject.file(keystoreProperties["storeFile"].toString()) + storePassword = keystoreProperties["storePassword"].toString() + } + } + } + buildTypes { + getByName(buildTypeRelease) { + if (keystorePropertiesFile.exists()) signingConfig = signingConfigs.getByName("release") + isMinifyEnabled = false + //proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro") + } + } + dexOptions { + setJavaMaxHeapSize("2048m") + } + lintOptions.isAbortOnError = false +} + +dependencies { + val aboutVersion = "6.2.0" + val androidXVersion = "1.0.0" + val apkSigVersion = "3.2.1" + val caocVersion = "2.2.0" + // Apparently v2.6 relies on the framework + // having java.nio.File which Android 7 does not. + val commonsIoVersion = "2.5" + val databindingVersion = "3.2.1" + val expandableLayoutVersion = "2.9.2" + val fabSheetVersion = "1.2.1" + val floatingHeadVersion = "2.4.0" + val gestureRecyclerVersion = "1.7.0" + val glideVersion = "4.8.0" + val imageCropperVersion = "2.8.0" + val svgViewVersion = "1.0.6" + val welcomeVersion = "1.4.1" + val ztZipVersion = "1.13" + + annotationProcessor("com.github.bumptech.glide:compiler:$glideVersion") + implementation(fileTree(mapOf("dir" to "libs", "include" to listOf("*.jar")))) + implementation("androidx.appcompat:appcompat:1.0.2") + implementation("androidx.cardview:cardview:$androidXVersion") + implementation("androidx.databinding:databinding-runtime:$databindingVersion") + implementation("androidx.palette:palette:$androidXVersion") + implementation("androidx.recyclerview:recyclerview:$androidXVersion") + implementation("cat.ereza:customactivityoncrash:$caocVersion") + implementation("commons-io:commons-io:$commonsIoVersion") + implementation("com.android.tools.build:apksig:$apkSigVersion") + implementation("com.github.bumptech.glide:glide:$glideVersion") + implementation("com.github.recruit-lifestyle:FloatingView:$floatingHeadVersion") + implementation("com.google.android.material:material:$androidXVersion") + implementation("com.gordonwong:material-sheet-fab:$fabSheetVersion") + implementation("com.jaredrummler:animated-svg-view:$svgViewVersion") + implementation("com.mikepenz:aboutlibraries:$aboutVersion@aar") { + isTransitive = true + } + implementation("com.stephentuso:welcome:$welcomeVersion") + implementation("com.theartofdev.edmodo:android-image-cropper:$imageCropperVersion") + implementation("com.thesurix.gesturerecycler:gesture-recycler:$gestureRecyclerVersion") + implementation("net.cachapa.expandablelayout:expandablelayout:$expandableLayoutVersion") + implementation("org.zeroturnaround:zt-zip:$ztZipVersion") +} diff --git a/app/google-services.json b/app/google-services.json deleted file mode 100644 index 80f4fcd3d..000000000 --- a/app/google-services.json +++ /dev/null @@ -1,86 +0,0 @@ -{ - "project_info": { - "project_number": "860912288789", - "firebase_url": "https://substratum-d455c.firebaseio.com", - "project_id": "substratum-d455c", - "storage_bucket": "substratum-d455c.appspot.com" - }, - "client": [ - { - "client_info": { - "mobilesdk_app_id": "1:860912288789:android:cecb4572f9730fd6", - "android_client_info": { - "package_name": "projekt.substratum" - } - }, - "oauth_client": [ - { - "client_id": "860912288789-pfmsjp5clcmin2us8b4t71pb4an2a2dn.apps.googleusercontent.com", - "client_type": 3 - } - ], - "api_key": [ - { - "current_key": "AIzaSyDN0PNpizStRu0JsRFxZb7V6TPqRp7dQjA" - } - ], - "services": { - "analytics_service": { - "status": 1 - }, - "appinvite_service": { - "status": 1, - "other_platform_oauth_client": [] - }, - "ads_service": { - "status": 2 - } - } - }, - { - "client_info": { - "mobilesdk_app_id": "1:860912288789:android:46169996faaf4820", - "android_client_info": { - "package_name": "projekt.sungstratum" - } - }, - "oauth_client": [ - { - "client_id": "860912288789-07uk00cg2tecgabs0b38435jfkvnsfra.apps.googleusercontent.com", - "client_type": 1, - "android_info": { - "package_name": "projekt.sungstratum", - "certificate_hash": "a14849686171d90a2b873eafba6292c2ab90a61b" - } - }, - { - "client_id": "860912288789-pfmsjp5clcmin2us8b4t71pb4an2a2dn.apps.googleusercontent.com", - "client_type": 3 - } - ], - "api_key": [ - { - "current_key": "AIzaSyDN0PNpizStRu0JsRFxZb7V6TPqRp7dQjA" - } - ], - "services": { - "analytics_service": { - "status": 1 - }, - "appinvite_service": { - "status": 2, - "other_platform_oauth_client": [ - { - "client_id": "860912288789-pfmsjp5clcmin2us8b4t71pb4an2a2dn.apps.googleusercontent.com", - "client_type": 3 - } - ] - }, - "ads_service": { - "status": 2 - } - } - } - ], - "configuration_version": "1" -} \ No newline at end of file diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro index d8187e75f..a27d70962 100644 --- a/app/proguard-rules.pro +++ b/app/proguard-rules.pro @@ -44,32 +44,12 @@ -dontwarn org.slf4j.impl.** -dontwarn junit.textui.TestRunner -# Crashlytics --keep public class com.crashlytics.android.Crashlytics { *; } --keep public class io.fabric.sdk.android.Fabric { *; } - -# Android support libraries --keep public class android.support.v7.widget.** { *; } --keep public class android.support.v7.internal.widget.** { *; } --keep public class android.support.v7.internal.view.menu.** { *; } --keep class android.support.v7.widget.RoundRectDrawable { *; } --keep public class * extends android.support.v4.view.ActionProvider { - public (android.content.Context); -} --dontwarn android.support.design.** --keep class android.support.design.** { *; } --keep interface android.support.design.** { *; } --keep public class android.support.design.R$* { *; } - -# Crashlytics --keepattributes *Annotation* --keepattributes SourceFile,LineNumberTable --keep public class * extends java.lang.Exception --keep class com.crashlytics.** { *; } --dontwarn com.crashlytics.** # SLF4J -keep class org.slf4j.** { *; } # Don't obfuscate anything --dontobfuscate \ No newline at end of file +-dontobfuscate + +# Warnings are nice but please don't abort build over things I don't control +-ignorewarnings diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 2aa824e81..28c5fb00f 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -118,10 +118,6 @@ android:name=".services.profiles.ScheduledProfileService" android:permission="android.permission.BIND_JOB_SERVICE" /> - - diff --git a/app/src/main/java/projekt/substratum/MainActivity.java b/app/src/main/java/projekt/substratum/MainActivity.java index 5ce5d6a88..aa80ee08c 100644 --- a/app/src/main/java/projekt/substratum/MainActivity.java +++ b/app/src/main/java/projekt/substratum/MainActivity.java @@ -46,7 +46,6 @@ import androidx.fragment.app.FragmentManager; import androidx.fragment.app.FragmentTransaction; import androidx.localbroadcastmanager.content.LocalBroadcastManager; -import com.google.android.material.bottomnavigation.BottomNavigationMenuView; import com.google.android.material.bottomnavigation.BottomNavigationView; import com.google.android.material.bottomnavigation.LabelVisibilityMode; import projekt.substratum.activities.launch.ShowcaseActivity; @@ -56,7 +55,6 @@ import projekt.substratum.common.Restore; import projekt.substratum.common.Systems; import projekt.substratum.common.Theming; -import projekt.substratum.common.analytics.FirebaseAnalytics; import projekt.substratum.common.commands.ElevatedCommands; import projekt.substratum.common.commands.FileOperations; import projekt.substratum.common.platform.AndromedaService; @@ -73,6 +71,7 @@ import projekt.substratum.services.tiles.FloatUiTile; import projekt.substratum.util.helpers.BinaryInstaller; import projekt.substratum.util.helpers.LocaleHelper; +import projekt.substratum.util.helpers.MagiskHelper; import projekt.substratum.util.helpers.Root; import java.io.File; @@ -406,6 +405,7 @@ protected void onCreate(Bundle savedInstanceState) { return; } } + prefs.edit().remove("root_access").apply(); new RootRequester(this).execute(); } @@ -693,7 +693,8 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) { case UNINSTALL_REQUEST_CODE: if ((queuedUninstall != null) && !queuedUninstall.isEmpty()) { queuedUninstall.remove(0); - uninstallMultipleAPKS(this); + Activity activity = this; + AsyncTask.execute(() -> uninstallMultipleAPKS(activity)); } break; default: @@ -1061,10 +1062,7 @@ private void showDialogOrNot(boolean passthrough) { R.id.sungstratum_button); samsungButton.setOnClickListener(view -> launchActivityUrl(context, R.string.sungstratum_url)); - if (!FirebaseAnalytics.checkFirebaseAuthorized()) { - samsungTitle.setText(activity.getString( - R.string.samsung_prototype_no_firebase_dialog)); - } else if (Packages.isPackageInstalled(context, SST_ADDON_PACKAGE)) { + if (Packages.isPackageInstalled(context, SST_ADDON_PACKAGE)) { samsungTitle.setText( activity.getString( R.string.samsung_prototype_reinstall_dialog)); @@ -1124,7 +1122,10 @@ private void showDialogOrNot(boolean passthrough) { } } else { BinaryInstaller.install(activity.context, false); - if (Systems.checkOMS(context)) new DoCleanUp(context).execute(); + if (Systems.checkOMS(context)) { + new DoCleanUp(context).execute(); + if (Root.checkRootAccess() && Systems.IS_PIE) MagiskHelper.migrateToModule(context); + } } } } @@ -1178,14 +1179,14 @@ protected Boolean doInBackground(Void... sUrl) { if (omsCheck) { return (themeSystemModule != OVERLAY_MANAGER_SERVICE_O_UNROOTED) && (themeSystemModule != OVERLAY_MANAGER_SERVICE_N_UNROOTED) && - !Root.requestRootAccess(); + !Root.checkRootAccess(); } // Check if the system is legacy boolean legacyCheck = themeSystemModule == NO_THEME_ENGINE; if (legacyCheck) { // Throw the dialog, after checking for root - return !Root.requestRootAccess(); + return !Root.checkRootAccess(); } } return false; @@ -1247,6 +1248,7 @@ protected Void doInBackground(Void... sUrl) { if (!removeList.isEmpty()) uninstallOverlay(context, removeList); } + new Thread(MagiskHelper::forceRemoveOverlays).start(); return null; } } diff --git a/app/src/main/java/projekt/substratum/Substratum.java b/app/src/main/java/projekt/substratum/Substratum.java index e31e9795e..c10beae00 100644 --- a/app/src/main/java/projekt/substratum/Substratum.java +++ b/app/src/main/java/projekt/substratum/Substratum.java @@ -28,10 +28,6 @@ import android.util.Log; import androidx.appcompat.app.AppCompatDelegate; import cat.ereza.customactivityoncrash.config.CaocConfig; -import com.crashlytics.android.Crashlytics; -import com.crashlytics.android.core.CrashlyticsCore; -import com.google.firebase.FirebaseApp; -import io.fabric.sdk.android.Fabric; import projekt.substratum.activities.crash.SubstratumCrash; import projekt.substratum.common.Broadcasts; import projekt.substratum.common.Packages; @@ -201,14 +197,6 @@ public static void log(final String TAG, final String message) { Log.d(TAG, message); } - private void configureCrashReporting() { - CrashlyticsCore crashlyticsCore = new CrashlyticsCore.Builder() - .disabled(BuildConfig.DEBUG) - .build(); - - Fabric.with(this, new Crashlytics.Builder().core(crashlyticsCore).build()); - } - @Override public void onCreate() { super.onCreate(); @@ -232,14 +220,6 @@ public void onCreate() { AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_YES); preferences.edit().putString("app_theme", DARK_THEME).apply(); } - - // Firebase and Crashlytics - try { - FirebaseApp.initializeApp(this.getApplicationContext()); - configureCrashReporting(); - } catch (IllegalStateException ignored) { - } - // Dynamically check which theme engine is running at the moment if (isAndromedaDevice(this.getApplicationContext())) { boolean startBinderService = this.startBinderService(AndromedaBinderService.class); diff --git a/app/src/main/java/projekt/substratum/activities/launch/ManageSpaceActivity.java b/app/src/main/java/projekt/substratum/activities/launch/ManageSpaceActivity.java index 41a1435b5..31d5982b4 100644 --- a/app/src/main/java/projekt/substratum/activities/launch/ManageSpaceActivity.java +++ b/app/src/main/java/projekt/substratum/activities/launch/ManageSpaceActivity.java @@ -28,8 +28,6 @@ import java.lang.ref.WeakReference; import static projekt.substratum.common.References.LOGCHAR_DIR; -import static projekt.substratum.common.analytics.FirebaseAnalytics.NAMES_PREFS; -import static projekt.substratum.common.analytics.FirebaseAnalytics.PACKAGES_PREFS; import static projekt.substratum.common.commands.FileOperations.delete; import static projekt.substratum.common.commands.FileOperations.getFileSize; @@ -195,14 +193,6 @@ protected Void doInBackground(Void... params) { for (File f : context.getDataDir().listFiles()) { if (!"shared_prefs".equals(f.getName())) { delete(context, f.getAbsolutePath()); - } else { - for (File prefs : f.listFiles()) { - String fileName = prefs.getName(); - if (!fileName.equals(NAMES_PREFS + ".xml") && - !fileName.equals(PACKAGES_PREFS + ".xml")) { - delete(context, prefs.getAbsolutePath()); - } - } } } References.loadDefaultConfig(context); diff --git a/app/src/main/java/projekt/substratum/activities/launch/SplashScreenActivity.java b/app/src/main/java/projekt/substratum/activities/launch/SplashScreenActivity.java index 121204759..e6e143bc5 100644 --- a/app/src/main/java/projekt/substratum/activities/launch/SplashScreenActivity.java +++ b/app/src/main/java/projekt/substratum/activities/launch/SplashScreenActivity.java @@ -27,25 +27,19 @@ import projekt.substratum.Substratum; import projekt.substratum.common.Packages; import projekt.substratum.common.References; -import projekt.substratum.common.analytics.FirebaseAnalytics; import projekt.substratum.databinding.SplashscreenActivityBinding; import projekt.substratum.util.helpers.MD5; import java.io.File; import java.lang.ref.WeakReference; -import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.Locale; import static projekt.substratum.common.Internal.AUTHENTICATED_RECEIVER; import static projekt.substratum.common.Internal.AUTHENTICATE_RECEIVER; import static projekt.substratum.common.References.PLAY_STORE_PACKAGE_NAME; import static projekt.substratum.common.References.SST_ADDON_PACKAGE; -import static projekt.substratum.common.References.SUBSTRATUM_LOG; import static projekt.substratum.common.Systems.checkPackageSupport; import static projekt.substratum.common.Systems.checkThemeSystemModule; import static projekt.substratum.common.Systems.isSamsungDevice; -import static projekt.substratum.common.analytics.FirebaseAnalytics.PACKAGES_PREFS; import static projekt.substratum.common.analytics.PackageAnalytics.isLowEnd; public class SplashScreenActivity extends Activity { @@ -139,27 +133,7 @@ protected Void doInBackground(Void... voids) { prefs = context.getSharedPreferences("substratum_state", Context.MODE_PRIVATE); editor = prefs.edit(); editor.clear().apply(); - FirebaseAnalytics.withdrawBlacklistedPackages( - activity.getApplicationContext(), - activity.firstRun - ); checkPackageSupport(activity.getApplicationContext(), false); - prefs = context.getSharedPreferences(PACKAGES_PREFS, Context.MODE_PRIVATE); - SimpleDateFormat dateFormat = new SimpleDateFormat("ddMMyyyy", Locale.US); - int timeoutCount = 0; - while (!prefs.contains(dateFormat.format(new Date())) && (timeoutCount < 100)) { - try { - Thread.sleep(100L); - } catch (InterruptedException e) { - e.printStackTrace(); - } - timeoutCount++; - } - if (!prefs.contains(dateFormat.format(new Date()))) { - Log.e(SUBSTRATUM_LOG, "Failed to withdraw blacklisted packages..."); - } else { - Substratum.log(SUBSTRATUM_LOG, "Successfully withdrew blacklisted packages!"); - } if (isSamsungDevice(context) && Packages.isPackageInstalled(context, SST_ADDON_PACKAGE)) { diff --git a/app/src/main/java/projekt/substratum/common/Internal.java b/app/src/main/java/projekt/substratum/common/Internal.java index 0a3a30ae6..f557f3d02 100644 --- a/app/src/main/java/projekt/substratum/common/Internal.java +++ b/app/src/main/java/projekt/substratum/common/Internal.java @@ -135,9 +135,9 @@ public class Internal { public static final String BOOTANIMATION_DESCRIPTOR = "desc.txt"; public static final String BOOTANIMATION = "bootanimation.zip"; public static final String SHUTDOWNANIMATION = "shutdownanimation.zip"; - public static final String BOOTANIMATION_LOCATION = (Systems.IS_PIE && References.checkMagisk()) ? References.MAGISK_MIRROR_MOUNT_POINT + "media/bootanimation.zip" : "/system/media/bootanimation.zip"; + public static final String BOOTANIMATION_LOCATION = References.getPieMountPoint() + "/media/bootanimation.zip"; public static final String BOOTANIMATION_BU = "bootanimation-backup.zip"; - public static final String BOOTANIMATION_BU_LOCATION = (Systems.IS_PIE && References.checkMagisk()) ? References.MAGISK_MIRROR_MOUNT_POINT + "media/bootanimation-backup.zip" : "/system/media/bootanimation-backup.zip"; + public static final String BOOTANIMATION_BU_LOCATION = References.getPieMountPoint() + "/media/bootanimation-backup.zip"; public static final String VALIDATOR_CACHE = "ValidatorCache"; public static final String VALIDATOR_CACHE_DIR = "/ValidatorCache/"; public static final String SYSTEM_ADDON_DIR = "/system/addon.d/"; diff --git a/app/src/main/java/projekt/substratum/common/References.java b/app/src/main/java/projekt/substratum/common/References.java index 1dd03fbc4..9f719362a 100644 --- a/app/src/main/java/projekt/substratum/common/References.java +++ b/app/src/main/java/projekt/substratum/common/References.java @@ -59,10 +59,8 @@ import projekt.substratum.R; import projekt.substratum.Substratum; import projekt.substratum.activities.shortcuts.AppShortcutLaunch; -import projekt.substratum.common.analytics.FirebaseAnalytics; import projekt.substratum.services.profiles.ScheduledProfileReceiver; import projekt.substratum.util.helpers.BinaryInstaller; -import projekt.substratum.util.helpers.Root; import projekt.substratum.util.helpers.TranslatorParser; import java.io.BufferedReader; @@ -82,15 +80,11 @@ import java.util.Arrays; import java.util.Calendar; import java.util.Collections; -import java.util.Date; -import java.util.HashSet; import java.util.List; import java.util.Locale; -import java.util.Set; import static android.content.Context.CLIPBOARD_SERVICE; import static projekt.substratum.common.Internal.BYTE_ACCESS_RATE; -import static projekt.substratum.common.Systems.checkPackageRegex; public class References { @@ -191,7 +185,6 @@ public class References { public static final String DATA_RESOURCE_DIR = "/data/resource-cache/"; public static final String PIXEL_NEXUS_DIR = "/system/overlay/"; public static final String LEGACY_NEXUS_DIR = "/system/vendor/overlay/"; - public static final String MAGISK_MIRROR_MOUNT_POINT = "/sbin/.core/mirror/system"; public static final String VENDOR_DIR = "/vendor/overlay/"; // Notification Channel public static final String DEFAULT_NOTIFICATION_CHANNEL_ID = "default"; @@ -234,55 +227,25 @@ public class References { // Special permission for Samsung devices public static final String SAMSUNG_OVERLAY_PERMISSION = "com.samsung.android.permission.SAMSUNG_OVERLAY_COMPONENT"; + public static final String MAGISK_MODULE_DIR = "/sbin/.magisk/img/substratum/"; // This string controls the hero image name static final String heroImageResourceName = "heroimage"; static final String heroImageGridResourceName = "heroimage_grid"; static final String heroImageMainResourceName = "heroimage_banner"; // Specific intents Substratum should be listening to static final String APP_CRASHED = "projekt.substratum.APP_CRASHED"; - private static final String P_SYSTEM_DIR = "/system/app/"; - private static final String P_MAGISK_DIR = MAGISK_MIRROR_MOUNT_POINT + "/app/"; // Control the animation duration private static final int FADE_FROM_GRAYSCALE_TO_COLOR_DURATION = 1250; // Localized variables shared amongst common resources static ScheduledProfileReceiver scheduledProfileReceiver; - // These values control the dynamic certification of substratum - // We use java.lang.Boolean here rather than a normal boolean - // since it being an Object allows us to have a third state - null, - // which means that the variable has not been initialised, where - // boolean simply takes on the value false. - private static Boolean uncertified; private static int hashValue; - private static String pieDir = null; - private static Boolean isMagisk = null; public static String getPieDir() { - isMagisk = checkMagisk(); - if (pieDir == null) { - if (isMagisk != null && isMagisk) - pieDir = P_MAGISK_DIR; - else - pieDir = P_SYSTEM_DIR; - } - return pieDir; + return MAGISK_MODULE_DIR + "system/app/"; } public static String getPieMountPoint() { - isMagisk = checkMagisk(); - if (isMagisk != null && isMagisk) - return MAGISK_MIRROR_MOUNT_POINT; - else - return "/system"; - } - - static Boolean checkMagisk() { - if (isMagisk == null) { - try { - isMagisk = Root.runCommand(String.format("test -d %s && echo '0'", MAGISK_MIRROR_MOUNT_POINT)).equals("0"); - } catch (Exception ignored) { - } - } - return isMagisk; + return MAGISK_MODULE_DIR; } /** @@ -311,7 +274,7 @@ public static Spinner setThemeExtraLists(Context context, try { final String[] fileArray = themeAssetManager.list(listDir); final List archivedSounds = new ArrayList<>(); - Collections.addAll(archivedSounds, fileArray); + Collections.addAll(archivedSounds, fileArray != null ? fileArray : new String[0]); // Creates the list of dropdown items final ArrayList unarchivedExtra = new ArrayList<>(); @@ -746,27 +709,6 @@ static int hashPassthrough(Context context) { return 0; } - /** - * A beautiful sunshine on a gloomy night, you must escape the grasps of death as it brings you - * to the destruction of life. - * - * @param context What's the point of parameters? - * @return Is it true that there is an afterlife? - */ - static boolean spreadYourWingsAndFly(Context context, boolean override) { - if (uncertified != null && !override) { - return uncertified; - } - SharedPreferences prefs = context.getSharedPreferences(FirebaseAnalytics.PACKAGES_PREFS, Context.MODE_PRIVATE); - SimpleDateFormat dateFormat = new SimpleDateFormat("ddMMyyyy", Locale.US); - String date = dateFormat.format(new Date()); - if (prefs.contains(date)) { - Set pref = prefs.getStringSet(date, new HashSet<>()); - } - uncertified = false; - return false; - } - /** * Check if list contains item * @@ -1011,7 +953,6 @@ protected void onPostExecute(Void result) { @Override protected Void doInBackground(Void... sUrl) { - spreadYourWingsAndFly(this.context, false); hashPassthrough(this.context); return null; } diff --git a/app/src/main/java/projekt/substratum/common/Restore.java b/app/src/main/java/projekt/substratum/common/Restore.java index 0789d141a..9aa737cb3 100644 --- a/app/src/main/java/projekt/substratum/common/Restore.java +++ b/app/src/main/java/projekt/substratum/common/Restore.java @@ -276,7 +276,7 @@ protected Void doInBackground(Boolean... sUrl) { .filter(o -> Packages.getOverlayParent(context, o) != null) .collect(Collectors.toList())); } else { - FileOperations.mountRW(); + FileOperations.mountSystemRW(); FileOperations.mountRWData(); FileOperations.mountRWVendor(); FileOperations.bruteforceDelete(DATA_RESOURCE_DIR); @@ -286,7 +286,7 @@ protected Void doInBackground(Boolean... sUrl) { FileOperations.bruteforceDelete(getPieDir() + "_*.apk"); FileOperations.mountROVendor(); FileOperations.mountROData(); - FileOperations.mountRO(); + FileOperations.mountSystemRO(); } } else { ThemeManager.disableAllThemeOverlays(context); diff --git a/app/src/main/java/projekt/substratum/common/Systems.java b/app/src/main/java/projekt/substratum/common/Systems.java index 9b1b42d61..8a63219d9 100644 --- a/app/src/main/java/projekt/substratum/common/Systems.java +++ b/app/src/main/java/projekt/substratum/common/Systems.java @@ -56,7 +56,6 @@ import static projekt.substratum.common.References.hashPassthrough; import static projekt.substratum.common.References.isNetworkAvailable; import static projekt.substratum.common.References.isServiceRunning; -import static projekt.substratum.common.References.spreadYourWingsAndFly; public class Systems { @@ -193,7 +192,7 @@ public static int checkThemeSystemModule(Context context, SAMSUNG_THEME_ENGINE_N ).apply(); return SAMSUNG_THEME_ENGINE_N; - } else if (Root.requestRootAccess()) { + } else if (Root.checkRootAccess()) { // Rooted mode prefs.edit().putInt( "current_theme_mode", @@ -580,8 +579,8 @@ public static boolean checkPackageSupport(Context context, Boolean override) { * @param stringArray List of packages to check * @return True if blacklisted packages found */ - static Boolean checkPackageRegex(Context context, - String[] stringArray) { + private static Boolean checkPackageRegex(Context context, + String[] stringArray) { if (stringArray.length == 0) return true; final PackageManager pm = context.getPackageManager(); List packages = pm.getInstalledApplications(PackageManager.GET_META_DATA); @@ -720,4 +719,27 @@ public static boolean checkUsagePermissions(Context context) { return false; } } + + /** + * Checks whether there is root access on the device + * + * @return True, if root is granted + */ + public static boolean checkRootAccess() { + if (!prefs.contains("root_access")) { + setAndCheckRootAccess(); + } + return prefs.getBoolean("root_access", false); + } + + /** + * Set a retained property to refer to rather than constantly calling the requestRootAccess method + */ + private static void setAndCheckRootAccess() { + boolean access = Root.requestRootAccess(); + prefs.edit().putBoolean("root_access", false).apply(); + if (access) { + prefs.edit().putBoolean("root_access", true).apply(); + } + } } \ No newline at end of file diff --git a/app/src/main/java/projekt/substratum/common/analytics/FirebaseAnalytics.java b/app/src/main/java/projekt/substratum/common/analytics/FirebaseAnalytics.java deleted file mode 100644 index e4fd79580..000000000 --- a/app/src/main/java/projekt/substratum/common/analytics/FirebaseAnalytics.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Copyright (c) 2016-2018 Projekt Substratum - * This file is part of Substratum. - * - * SPDX-License-Identifier: GPL-3.0-Or-Later - */ - -package projekt.substratum.common.analytics; - -import android.annotation.SuppressLint; -import android.content.Context; -import android.content.SharedPreferences; -import android.os.StrictMode; -import androidx.annotation.NonNull; -import com.google.firebase.database.DataSnapshot; -import com.google.firebase.database.DatabaseError; -import com.google.firebase.database.DatabaseReference; -import com.google.firebase.database.FirebaseDatabase; -import com.google.firebase.database.ValueEventListener; -import com.google.firebase.iid.FirebaseInstanceId; -import projekt.substratum.Substratum; -import projekt.substratum.common.References; - -import javax.net.ssl.HttpsURLConnection; -import java.net.URL; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Date; -import java.util.HashSet; -import java.util.Locale; -import java.util.Set; - -import static projekt.substratum.common.Systems.checkPackageSupport; - -public class FirebaseAnalytics { - - public static final String NAMES_PREFS = "names"; - public static final String PACKAGES_PREFS = "prefs"; - private static FirebaseDatabase firebaseDatabase; - - public static boolean checkFirebaseAuthorized() { - StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); - StrictMode.setThreadPolicy(policy); - try { - HttpsURLConnection connection = (HttpsURLConnection) new URL( - "https://console.firebase.google.com/").openConnection(); - connection.setRequestMethod("HEAD"); - connection.setConnectTimeout(5000); - return connection.getResponseCode() == HttpsURLConnection.HTTP_OK; - } catch (Exception ignored) { - } - return false; - } - - @SuppressLint("MissingFirebaseInstanceTokenRefresh") - private static DatabaseReference getDatabaseReference() { - if (firebaseDatabase == null) { - firebaseDatabase = FirebaseDatabase.getInstance(); - firebaseDatabase.setPersistenceEnabled(true); - String token = FirebaseInstanceId.getInstance().getToken(); - Substratum.log(References.SUBSTRATUM_LOG, "Firebase Registration Token: " + token); - } - return firebaseDatabase.getReference(); - } - - public static void withdrawBlacklistedPackages(Context context, Boolean firstStart) { - DatabaseReference database = getDatabaseReference(); - database.child("patchers").addListenerForSingleValueEvent(new ValueEventListener() { - @Override - public void onDataChange(@NonNull DataSnapshot dataSnapshot) { - SharedPreferences.Editor editor = context - .getSharedPreferences(PACKAGES_PREFS, Context.MODE_PRIVATE).edit(); - editor.clear(); - Object dataValue = dataSnapshot.getValue(); - if (dataValue != null) { - String data = dataValue.toString(); - String[] dataArr = data.substring(1, data.length() - 1).split(","); - Collection listOfPackages = new ArrayList<>(); - for (String aDataArr : dataArr) { - String entry = aDataArr.split("=")[1]; - listOfPackages.add(entry); - } - - Set set = new HashSet<>(listOfPackages); - SimpleDateFormat dateFormat = new SimpleDateFormat("ddMMyyyy", Locale.US); - editor.putStringSet(dateFormat.format(new Date()), set); - editor.apply(); - - if (firstStart) checkPackageSupport(context, true); - } - } - - @Override - public void onCancelled(@NonNull DatabaseError databaseError) { - } - }); - } -} \ No newline at end of file diff --git a/app/src/main/java/projekt/substratum/common/commands/FileOperations.java b/app/src/main/java/projekt/substratum/common/commands/FileOperations.java index 214170eec..a04816442 100644 --- a/app/src/main/java/projekt/substratum/common/commands/FileOperations.java +++ b/app/src/main/java/projekt/substratum/common/commands/FileOperations.java @@ -126,13 +126,21 @@ private static String checkBox(final String mountType) { /** * Mount system RW */ - public static void mountRW() { + public static void mountSystemRW() { final String mountPoint; if (Systems.IS_PIE) mountPoint = References.getPieMountPoint(); else mountPoint = "/system"; - Root.runCommand(String.format("mount -t auto -o %s %s", checkBox("rw"), mountPoint)); + mountRW(mountPoint); + } + + /** + * Mount given mountpoint as RW + * @param mountpoint The directory to mount as RW + */ + public static void mountRW(final String mountpoint) { + Root.runCommand(String.format("mount -t auto -o %s %s", checkBox("rw"), mountpoint)); } /** @@ -152,13 +160,21 @@ public static void mountRWVendor() { /** * Mount system RO */ - public static void mountRO() { + public static void mountSystemRO() { final String mountPoint; if (Systems.IS_PIE) mountPoint = References.getPieMountPoint(); else mountPoint = "/system"; - Root.runCommand(String.format("mount -t auto -o %s %s", checkBox("ro"), mountPoint)); + mountRO(mountPoint); + } + + /** + * Mount given mountpoint as RO + * @param mountpoint The directory to mount as RO + */ + public static void mountRO(final String mountpoint) { + Root.runCommand(String.format("mount -t auto -o %s %s", checkBox("rw"), mountpoint)); } /** diff --git a/app/src/main/java/projekt/substratum/common/platform/ThemeManager.java b/app/src/main/java/projekt/substratum/common/platform/ThemeManager.java index 13231a857..f96ec0876 100644 --- a/app/src/main/java/projekt/substratum/common/platform/ThemeManager.java +++ b/app/src/main/java/projekt/substratum/common/platform/ThemeManager.java @@ -726,11 +726,11 @@ public static void uninstallOverlay(Context context, } if (Systems.IS_PIE && !checkSubstratumService(context)) { - FileOperations.mountRW(); + FileOperations.mountSystemRW(); for (String overlay : overlays) { FileOperations.bruteforceDelete(References.getPieDir() + '_' + overlay + ".apk"); } - FileOperations.mountRO(); + FileOperations.mountSystemRO(); return; } @@ -753,11 +753,10 @@ public static void uninstallOverlay(Context context, Toast.LENGTH_LONG).show() ); } - } else if (MainActivity.instanceBasedAndromedaFailure || - (Systems.isNewSamsungDeviceAndromeda(context)) || - (Systems.isSamsungDevice(context) && - !Root.checkRootAccess() && - !Root.requestRootAccess())) { + } else if ((MainActivity.instanceBasedAndromedaFailure || + Systems.isNewSamsungDeviceAndromeda(context) || + Systems.isSamsungDevice(context)) && + (!Root.checkRootAccess())) { for (String overlay : overlays) { Uri packageURI = Uri.parse("package:" + overlay); Intent uninstallIntent = new Intent(Intent.ACTION_UNINSTALL_PACKAGE, packageURI); diff --git a/app/src/main/java/projekt/substratum/fragments/ManagerFragment.java b/app/src/main/java/projekt/substratum/fragments/ManagerFragment.java index 724aee2f2..f89e02e99 100644 --- a/app/src/main/java/projekt/substratum/fragments/ManagerFragment.java +++ b/app/src/main/java/projekt/substratum/fragments/ManagerFragment.java @@ -581,7 +581,7 @@ private LayoutReloader(ManagerFragment fragment, String input) { @Override protected void onPreExecute() { ManagerFragment fragment = ref.get(); - if (fragment != null) { + if (fragment.isAdded() && fragment != null) { currentPosition = ((LinearLayoutManager) fragment.recyclerView .getLayoutManager()) .findFirstCompletelyVisibleItemPosition(); @@ -599,7 +599,7 @@ protected void onPreExecute() { @Override protected Void doInBackground(Void... params) { ManagerFragment fragment = ref.get(); - if (fragment != null) { + if (fragment.isAdded() && fragment != null) { try { Context context = fragment.context; fragment.overlaysList = new ArrayList<>(); @@ -731,7 +731,7 @@ protected Void doInBackground(Void... params) { protected void onPostExecute(Void result) { super.onPostExecute(result); ManagerFragment fragment = ref.get(); - if (fragment != null) { + if (fragment.isAdded() && fragment != null) { Context context = fragment.context; fragment.swipeRefreshLayout.setRefreshing(false); fragment.toggleAll.setEnabled(true); @@ -808,7 +808,7 @@ private RunEnable(ManagerFragment fragment) { @Override protected void onPreExecute() { ManagerFragment fragment = ref.get(); - if (fragment != null) { + if (fragment.isAdded() && fragment != null) { materialSheetFab.hideSheet(); fragment.loadingBar.setVisibility(View.VISIBLE); } @@ -817,7 +817,7 @@ protected void onPreExecute() { @Override protected void onPostExecute(String result) { ManagerFragment fragment = ref.get(); - if (fragment != null) { + if (fragment.isAdded() && fragment != null) { Context context = fragment.context; if ("unauthorized".equals(result)) { Toast.makeText(context, @@ -837,7 +837,7 @@ protected void onPostExecute(String result) { @Override protected String doInBackground(String... params) { ManagerFragment fragment = ref.get(); - if (fragment != null) { + if (fragment.isAdded() && fragment != null) { Context context = fragment.context; fragment.overlayList = fragment.mAdapter.getOverlayManagerList(); boolean has_failed = false; @@ -905,7 +905,7 @@ private RunDisable(ManagerFragment fragment) { @Override protected void onPreExecute() { ManagerFragment fragment = ref.get(); - if (fragment != null) { + if (fragment.isAdded() && fragment != null) { materialSheetFab.hideSheet(); fragment.loadingBar.setVisibility(View.VISIBLE); } @@ -914,7 +914,7 @@ protected void onPreExecute() { @Override protected String doInBackground(Void... voids) { ManagerFragment fragment = ref.get(); - if (fragment != null) { + if (fragment.isAdded() && fragment != null) { Context context = fragment.context; if (Systems.checkOMS(context) && !Systems.isSamsungDevice(context)) { @@ -977,7 +977,7 @@ protected String doInBackground(Void... voids) { overlay.add(fragment.overlaysList.get(i).getName()); ThemeManager.uninstallOverlay(context, overlay); } else { - FileOperations.mountRW(); + FileOperations.mountSystemRW(); FileOperations.mountRWData(); FileOperations.mountRWVendor(); FileOperations.bruteforceDelete(DATA_RESOURCE_DIR + @@ -1021,7 +1021,7 @@ protected String doInBackground(Void... voids) { vendorResourceIdmap); FileOperations.mountROVendor(); FileOperations.mountROData(); - FileOperations.mountRO(); + FileOperations.mountSystemRO(); } } } @@ -1071,7 +1071,7 @@ protected String doInBackground(Void... voids) { @Override protected void onPostExecute(String result) { ManagerFragment fragment = ref.get(); - if (fragment != null) { + if (fragment.isAdded() && fragment != null) { Context context = fragment.context; if (Systems.isAndromedaDevice(context)) { new Handler().postDelayed(fragment::setSwipeRefreshLayoutRefreshing, @@ -1126,7 +1126,7 @@ private RunEnableDisable(ManagerFragment fragment) { @Override protected void onPreExecute() { ManagerFragment fragment = ref.get(); - if (fragment != null) { + if (fragment.isAdded() && fragment != null) { materialSheetFab.hideSheet(); fragment.loadingBar.setVisibility(View.VISIBLE); } @@ -1135,7 +1135,7 @@ protected void onPreExecute() { @Override protected void onPostExecute(String result) { ManagerFragment fragment = ref.get(); - if (fragment != null) { + if (fragment.isAdded() && fragment != null) { Context context = fragment.context; if ("unauthorized".equals(result)) { Toast.makeText(context, @@ -1154,7 +1154,7 @@ protected void onPostExecute(String result) { @Override protected String doInBackground(String... params) { ManagerFragment fragment = ref.get(); - if (fragment != null) { + if (fragment.isAdded() && fragment != null) { Context context = fragment.context; fragment.overlayList = fragment.mAdapter.getOverlayManagerList(); boolean hasFailed = false; @@ -1225,7 +1225,7 @@ private RunUninstall(ManagerFragment fragment) { @Override protected void onPreExecute() { ManagerFragment fragment = ref.get(); - if (fragment != null) { + if (fragment.isAdded() && fragment != null) { MainActivity.queuedUninstall = new ArrayList<>(); materialSheetFab.hideSheet(); fragment.loadingBar.setVisibility(View.VISIBLE); @@ -1235,7 +1235,7 @@ protected void onPreExecute() { @Override protected Void doInBackground(Void... params) { ManagerFragment fragment = ref.get(); - if (fragment != null) { + if (fragment.isAdded() && fragment != null) { Context context = fragment.context; fragment.overlayList = fragment.mAdapter.getOverlayManagerList(); @@ -1294,7 +1294,7 @@ protected Void doInBackground(Void... params) { @Override protected void onPostExecute(Void result) { ManagerFragment fragment = ref.get(); - if (fragment != null) { + if (fragment.isAdded() && fragment != null) { if (Systems.isAndromedaDevice(fragment.context)) { new Handler().postDelayed(fragment::setSwipeRefreshLayoutRefreshing, MANAGER_FRAGMENT_INITIAL_DELAY); @@ -1322,7 +1322,7 @@ private FinishReceiver(ManagerFragment fragment) { @Override public void onReceive(Context context, Intent intent) { ManagerFragment fragment = ref.get(); - if (fragment != null) { + if (fragment.isAdded() && fragment != null) { if (layoutReloader != null && !layoutReloader.isCancelled()) { layoutReloader.cancel(true); layoutReloader = new LayoutReloader(fragment, MainActivity.userInput); diff --git a/app/src/main/java/projekt/substratum/fragments/PriorityLoaderFragment.java b/app/src/main/java/projekt/substratum/fragments/PriorityLoaderFragment.java index 121d39ac6..caa94a18d 100644 --- a/app/src/main/java/projekt/substratum/fragments/PriorityLoaderFragment.java +++ b/app/src/main/java/projekt/substratum/fragments/PriorityLoaderFragment.java @@ -122,7 +122,7 @@ private static class LoadPrioritizedOverlays extends AsyncTask targets = listTargetWithMultipleOverlaysEnabled(fragment.context); diff --git a/app/src/main/java/projekt/substratum/fragments/ProfileFragment.java b/app/src/main/java/projekt/substratum/fragments/ProfileFragment.java index 316297a47..271baa286 100644 --- a/app/src/main/java/projekt/substratum/fragments/ProfileFragment.java +++ b/app/src/main/java/projekt/substratum/fragments/ProfileFragment.java @@ -523,7 +523,7 @@ private static class BackupFunction extends AsyncTask { @Override protected void onPreExecute() { ProfileFragment profileFragment = ref.get(); - if (profileFragment != null) { + if (profileFragment.isAdded() && profileFragment != null) { profileFragment.headerProgress.setVisibility(View.VISIBLE); } } @@ -532,7 +532,7 @@ protected void onPreExecute() { protected void onPostExecute(String result) { super.onPostExecute(result); ProfileFragment profileFragment = ref.get(); - if (profileFragment != null) { + if (profileFragment.isAdded() && profileFragment != null) { profileFragment.headerProgress.setVisibility(View.GONE); if (Systems.checkOMS(profileFragment.context)) { String directory_parse = String.format( @@ -562,7 +562,7 @@ protected void onPostExecute(String result) { @Override protected String doInBackground(String... sUrl) { ProfileFragment profileFragment = ref.get(); - if (profileFragment != null) { + if (profileFragment.isAdded() && profileFragment != null) { String uid; try { uid = Environment.getExternalStorageDirectory().getAbsolutePath().split("/")[3]; @@ -687,7 +687,7 @@ protected String doInBackground(String... sUrl) { } File file = new File(currentDirectory); if (file.exists()) { - FileOperations.mountRW(); + FileOperations.mountSystemRW(); if (profileFragment.selectedBackup.contains( profileFragment.getString(R.string.profile_overlay))) { FileOperations.copyDir(profileFragment.context, currentDirectory, @@ -715,7 +715,7 @@ protected String doInBackground(String... sUrl) { .getAbsolutePath() + PROFILE_DIRECTORY + profileFragment.backupGetText); } - FileOperations.mountRO(); + FileOperations.mountSystemRO(); // Don't forget the wallpaper if wanted if (profileFragment.selectedBackup.contains( @@ -781,7 +781,7 @@ private static class RestoreFunction extends AsyncTask @Override protected void onPreExecute() { ProfileFragment profileFragment = ref.get(); - if (profileFragment != null) { + if (profileFragment.isAdded() && profileFragment != null) { profileFragment.headerProgress.setVisibility(View.VISIBLE); } } @@ -790,7 +790,7 @@ protected void onPreExecute() { protected void onPostExecute(String result) { super.onPostExecute(result); ProfileFragment profileFragment = ref.get(); - if (profileFragment != null) { + if (profileFragment.isAdded() && profileFragment != null) { if (Systems.checkOMS(profileFragment.context)) { if (!profileFragment.cannotRunOverlays.isEmpty()) { new AlertDialog.Builder(profileFragment.context) @@ -832,7 +832,7 @@ protected void onPostExecute(String result) { File file = new File(currentDirectory); if (file.exists()) { // Delete destination overlays - FileOperations.mountRW(); + FileOperations.mountSystemRW(); FileOperations.delete(profileFragment.context, currentDirectory); FileOperations.delete(profileFragment.context, THEME_DIRECTORY); FileOperations.createNewFolder(profileFragment.context, currentDirectory); @@ -867,12 +867,12 @@ protected void onPostExecute(String result) { FileOperations.setPermissionsRecursively(THEME_644, currentDirectory); FileOperations.setPermissions(THEME_755, currentDirectory); FileOperations.setSystemFileContext(currentDirectory); - FileOperations.mountRO(); + FileOperations.mountSystemRO(); } else { String vendorLocation = LEGACY_NEXUS_DIR; String vendorPartition = VENDOR_DIR; String currentVendor = projekt.substratum.common.Resources.inNexusFilter() ? vendorPartition : vendorLocation; - FileOperations.mountRW(); + FileOperations.mountSystemRW(); File vendor = new File(currentVendor); if (!vendor.exists()) { if (currentVendor.equals(vendorLocation)) { @@ -919,7 +919,7 @@ protected void onPostExecute(String result) { FileOperations.setPermissionsRecursively(THEME_644, currentDirectory); FileOperations.setPermissions(THEME_755, currentDirectory); FileOperations.setSystemFileContext(currentDirectory); - FileOperations.mountRO(); + FileOperations.mountSystemRO(); // Restore wallpaper new ContinueRestore(profileFragment).execute(); @@ -946,7 +946,7 @@ protected void onPostExecute(String result) { @Override protected String doInBackground(String... sUrl) { ProfileFragment profileFragment = ref.get(); - if (profileFragment != null) { + if (profileFragment.isAdded() && profileFragment != null) { if (Systems.checkOMS(profileFragment.context)) { // RRO doesn't need this profile_name = sUrl[0]; profileFragment.cannotRunOverlays = new ArrayList<>(); @@ -1092,7 +1092,7 @@ public void run() { @Override protected void onPreExecute() { ProfileFragment profileFragment = ref.get(); - if (profileFragment != null) { + if (profileFragment.isAdded() && profileFragment != null) { progressDialog = new ProgressDialog(profileFragment.context); progressDialog.setIndeterminate(true); progressDialog.setCancelable(false); @@ -1124,7 +1124,7 @@ protected void onProgressUpdate(String... progress) { @Override protected Void doInBackground(Void... params) { ProfileFragment profileFragment = ref.get(); - if (profileFragment != null) { + if (profileFragment.isAdded() && profileFragment != null) { profileFragment.lateInstall = new ArrayList<>(); if (toBeCompiled != null) { Map items = @@ -1371,14 +1371,14 @@ protected Void doInBackground(Void... params) { @Override protected void onPostExecute(Void result) { ProfileFragment profileFragment = ref.get(); - if (profileFragment != null) { + if (profileFragment.isAdded() && profileFragment != null) { progressDialog.dismiss(); } } void continueProcess() { ProfileFragment profileFragment = ref.get(); - if (profileFragment != null) { + if (profileFragment.isAdded() && profileFragment != null) { File theme = new File(Environment.getExternalStorageDirectory() .getAbsolutePath() + @@ -1388,7 +1388,7 @@ void continueProcess() { File bootanimation = new File(theme, BOOTANIMATION); if (bootanimation.exists() && (Systems.getDeviceEncryptionStatus(profileFragment.context) > 1)) { - FileOperations.mountRW(); + FileOperations.mountSystemRW(); FileOperations.move( profileFragment.context, BOOTANIMATION_LOCATION, @@ -1398,7 +1398,7 @@ void continueProcess() { bootanimation.getAbsolutePath(), BOOTANIMATION_LOCATION); FileOperations.setPermissions(THEME_644, BOOTANIMATION_LOCATION); - FileOperations.mountRO(); + FileOperations.mountSystemRO(); } // Late install @@ -1462,7 +1462,7 @@ void continueProcess() { void continueProcessWallpaper() { ProfileFragment profileFragment = ref.get(); - if (profileFragment != null) { + if (profileFragment.isAdded() && profileFragment != null) { String homeWallPath = Environment.getExternalStorageDirectory() .getAbsolutePath() + PROFILE_DIRECTORY + profileName + WALLPAPER_FILE_NAME; String lockWallPath = Environment.getExternalStorageDirectory() diff --git a/app/src/main/java/projekt/substratum/fragments/SettingsFragment.java b/app/src/main/java/projekt/substratum/fragments/SettingsFragment.java index d21aad6d1..f18272e13 100644 --- a/app/src/main/java/projekt/substratum/fragments/SettingsFragment.java +++ b/app/src/main/java/projekt/substratum/fragments/SettingsFragment.java @@ -102,8 +102,8 @@ public void onCreatePreferences( // About Substratum StringBuilder sb = new StringBuilder(); Preference aboutSubstratum = getPreferenceManager().findPreference("about_substratum"); - sb.append(BuildConfig.VERSION_NAME + " (" + BuildConfig.VERSION_CODE + ')'); - if (BuildConfig.DEBUG) sb.append(" - " + BuildConfig.GIT_HASH); + sb.append(BuildConfig.VERSION_NAME).append(" (").append(BuildConfig.VERSION_CODE).append(")"); + if (BuildConfig.DEBUG) sb.append(" - ").append(BuildConfig.GIT_HASH); aboutSubstratum.setSummary(sb.toString()); aboutSubstratum.setIcon(context.getDrawable(R.mipmap.main_launcher)); aboutSubstratum.setOnPreferenceClickListener( diff --git a/app/src/main/java/projekt/substratum/fragments/ThemeFragment.java b/app/src/main/java/projekt/substratum/fragments/ThemeFragment.java index 3109bf43c..5af1df43d 100644 --- a/app/src/main/java/projekt/substratum/fragments/ThemeFragment.java +++ b/app/src/main/java/projekt/substratum/fragments/ThemeFragment.java @@ -330,7 +330,7 @@ private static class LayoutLoader extends AsyncTask { protected void onPostExecute(String result) { super.onPostExecute(result); ThemeFragment themeFragment = fragment.get(); - if (themeFragment != null) { + if (themeFragment.isAdded() && themeFragment != null) { refreshLayout( themeFragment, themeFragment.context, @@ -343,7 +343,7 @@ protected void onPostExecute(String result) { @Override protected String doInBackground(String... sUrl) { ThemeFragment themeFragment = fragment.get(); - if (themeFragment != null) { + if (themeFragment.isAdded() && themeFragment != null) { substratumPackages = Packages.getSubstratumPackages( themeFragment.context, MainActivity.userInput); diff --git a/app/src/main/java/projekt/substratum/services/profiles/ScheduledProfileService.java b/app/src/main/java/projekt/substratum/services/profiles/ScheduledProfileService.java index c46403a78..c03bde933 100644 --- a/app/src/main/java/projekt/substratum/services/profiles/ScheduledProfileService.java +++ b/app/src/main/java/projekt/substratum/services/profiles/ScheduledProfileService.java @@ -208,11 +208,11 @@ protected Void doInBackground(Void... params) { File bootanimation = new File(theme, "bootanimation.zip"); if (bootanimation.exists() && (Systems.getDeviceEncryptionStatus(context) > 1)) { - FileOperations.mountRW(); + FileOperations.mountSystemRW(); FileOperations.move(context, Internal.BOOTANIMATION_LOCATION, Internal.BOOTANIMATION_BU_LOCATION); FileOperations.copy(context, bootanimation.getAbsolutePath(), Internal.BOOTANIMATION_LOCATION); FileOperations.setPermissions(644, Internal.BOOTANIMATION_LOCATION); - FileOperations.mountRO(); + FileOperations.mountSystemRO(); } Iterable toBeDisabled = new ArrayList<>(system); diff --git a/app/src/main/java/projekt/substratum/tabs/BootAnimations.java b/app/src/main/java/projekt/substratum/tabs/BootAnimations.java index 196d0825c..6e540588d 100644 --- a/app/src/main/java/projekt/substratum/tabs/BootAnimations.java +++ b/app/src/main/java/projekt/substratum/tabs/BootAnimations.java @@ -270,7 +270,7 @@ private void startApply() { .setMessage(R.string.root_required_boot_animation) .setPositiveButton(android.R.string.ok, (dialog, which) -> { dialog.dismiss(); - if (Root.requestRootAccess()) { + if (Root.checkRootAccess()) { if (bootAnimationSelector.getSelectedItemPosition() == 1) { new BootAnimationClearer(this).execute(""); } else { diff --git a/app/src/main/java/projekt/substratum/tabs/BootAnimationsManager.java b/app/src/main/java/projekt/substratum/tabs/BootAnimationsManager.java index 4ed9369ae..35faf19ef 100644 --- a/app/src/main/java/projekt/substratum/tabs/BootAnimationsManager.java +++ b/app/src/main/java/projekt/substratum/tabs/BootAnimationsManager.java @@ -62,14 +62,14 @@ public static void setBootAnimation(Context context, // We will mount system, make our directory, copy the bootanimation // zip into place, set proper permissions, then unmount Substratum.log(TAG, "Root option has been enabled"); - FileOperations.mountRW(); + FileOperations.mountSystemRW(); FileOperations.mountRWData(); FileOperations.setPermissions(THEME_755, themeDirectory); FileOperations.move(context, location, themeDirectory + '/' + fileName + ".zip"); FileOperations.setPermissions(THEME_644, themeDirectory + '/' + fileName + ".zip"); FileOperations.setSystemFileContext(themeDirectory); FileOperations.mountROData(); - FileOperations.mountRO(); + FileOperations.mountSystemRO(); } } @@ -101,12 +101,12 @@ public static void clearBootAnimation(Context context, } } else { // Encrypted OMS and legacy - FileOperations.mountRW(); + FileOperations.mountSystemRW(); FileOperations.move(context, BOOTANIMATION_BU_LOCATION, BOOTANIMATION_LOCATION); FileOperations.delete(context, SUBSBOOT_ADDON); - FileOperations.mountRO(); + FileOperations.mountSystemRO(); } } } \ No newline at end of file diff --git a/app/src/main/java/projekt/substratum/tabs/Fonts.java b/app/src/main/java/projekt/substratum/tabs/Fonts.java index bc976546b..17c115d0b 100644 --- a/app/src/main/java/projekt/substratum/tabs/Fonts.java +++ b/app/src/main/java/projekt/substratum/tabs/Fonts.java @@ -246,7 +246,7 @@ private FontsClearer(final Fonts fragment) { @Override protected void onPreExecute() { final Fonts fragment = ref.get(); - if (fragment != null) { + if (fragment.isAdded() && fragment != null) { final Context context = fragment.context; if (References.ENABLE_EXTRAS_DIALOG) { fragment.progressDialog = new ProgressDialog(context, R.style.RestoreDialog); @@ -262,7 +262,7 @@ protected void onPreExecute() { @Override protected void onPostExecute(final String result) { final Fonts fragment = ref.get(); - if (fragment != null) { + if (fragment.isAdded() && fragment != null) { final Context context = fragment.context; if (References.ENABLE_EXTRAS_DIALOG) { fragment.progressDialog.dismiss(); @@ -301,7 +301,7 @@ protected void onPostExecute(final String result) { @Override protected String doInBackground(final String... sUrl) { final Fonts fragment = ref.get(); - if (fragment != null) { + if (fragment.isAdded() && fragment != null) { final Context context = fragment.context; FontsManager.clearFonts(context); } diff --git a/app/src/main/java/projekt/substratum/tabs/Overlays.java b/app/src/main/java/projekt/substratum/tabs/Overlays.java index 74610a66a..a55a53362 100644 --- a/app/src/main/java/projekt/substratum/tabs/Overlays.java +++ b/app/src/main/java/projekt/substratum/tabs/Overlays.java @@ -827,6 +827,10 @@ private VariantItem setTypeOneHexAndSpinner( public void onActivityResult(int requestCode, int resultCode, Intent data) { switch (requestCode) { case 2486: + if (currentInstance.lateInstall.isEmpty()) { + refreshList(); + return; + } FileOperations.delete(context, new File(currentInstance.lateInstall.get(0)).getAbsolutePath()); if ((currentInstance.lateInstall != null) && @@ -1456,14 +1460,14 @@ private static void createOverlaysItem(Overlays overlays, @Override protected void onPreExecute() { Overlays fragment = ref.get(); - if (fragment != null) setViews(fragment, false); + if (fragment.isAdded() && fragment != null) setViews(fragment, false); } @Override protected void onPostExecute(String result) { super.onPostExecute(result); Overlays fragment = ref.get(); - if (fragment != null) { + if (fragment.isAdded() && fragment != null) { setViews(fragment, true); fragment.overlaysAdapter = new OverlaysAdapter(adapterList, fragment.context); fragment.recyclerView.setAdapter(fragment.overlaysAdapter); @@ -1479,7 +1483,7 @@ protected void onPostExecute(String result) { @Override protected String doInBackground(String... sUrl) { Overlays fragment = ref.get(); - if (fragment != null) { + if (fragment.isAdded() && fragment != null) { // Modularizing the compile process to make it easier to track errors boolean assigned = assignVariables(fragment, this); if (assigned) { diff --git a/app/src/main/java/projekt/substratum/tabs/OverlaysManager.java b/app/src/main/java/projekt/substratum/tabs/OverlaysManager.java index 8a2488939..d9055f21a 100644 --- a/app/src/main/java/projekt/substratum/tabs/OverlaysManager.java +++ b/app/src/main/java/projekt/substratum/tabs/OverlaysManager.java @@ -206,7 +206,7 @@ static void legacyDisable(Overlays overlays) { if (!overlays.currentInstance.checkedOverlays.isEmpty()) { if (Systems.isSamsungDevice(overlays.context)) { - if (Root.checkRootAccess() && Root.requestRootAccess()) { + if (Root.checkRootAccess()) { ArrayList checked_overlays = new ArrayList<>(); for (int i = 0; i < overlays.currentInstance.checkedOverlays.size(); i++) { checked_overlays.add( @@ -227,7 +227,7 @@ static void legacyDisable(Overlays overlays) { } else { overlays.overlaysAdapter.refreshOverlayStateList(overlays.context); for (int i = 0; i < overlays.currentInstance.checkedOverlays.size(); i++) { - FileOperations.mountRW(); + FileOperations.mountSystemRW(); FileOperations.delete(overlays.context, currentDirectory + overlays.currentInstance.checkedOverlays.get(i) .getFullOverlayParameters() + ".apk"); @@ -427,8 +427,8 @@ protected void onProgressUpdate(Integer... values) { protected void onPostExecute(String result) { super.onPostExecute(result); Overlays overlays = ref.get(); - if (overlays != null) { - Context context = overlays.getActivity(); + if (overlays != null && overlays.context != null) { + Context context = overlays.context; switch (state) { case COMPILE_ENABLE: // It's compile and enable mode, we have to first sort out all the @@ -497,7 +497,7 @@ protected void onPostExecute(String result) { if (Systems.isSamsungDevice(context) && (overlays.currentInstance.lateInstall != null) && !overlays.currentInstance.lateInstall.isEmpty()) { - if (Root.checkRootAccess() && Root.requestRootAccess()) { + if (Root.checkRootAccess()) { overlays.progressBar.setVisibility(View.VISIBLE); overlays.currentInstance.overlaysWaiting = overlays.currentInstance.lateInstall.size(); @@ -573,7 +573,7 @@ protected String doInBackground(String... sUrl) { } File file = new File(currentDirectory); if (file.exists()) { - FileOperations.mountRW(); + FileOperations.mountSystemRW(); FileOperations.delete(context, currentDirectory); } } diff --git a/app/src/main/java/projekt/substratum/util/compilers/SubstratumBuilder.java b/app/src/main/java/projekt/substratum/util/compilers/SubstratumBuilder.java index 351178ed8..007dc4bf4 100644 --- a/app/src/main/java/projekt/substratum/util/compilers/SubstratumBuilder.java +++ b/app/src/main/java/projekt/substratum/util/compilers/SubstratumBuilder.java @@ -371,11 +371,11 @@ public boolean beginAction(Context context, if (isDeviceOMS) { if (Systems.IS_PIE && !Systems.checkSubstratumService(context)) { // Brute force install APKs because thanks Google - FileOperations.mountRW(); + FileOperations.mountSystemRW(); final String overlay = References.getPieDir() + "_" + overlayName + ".apk"; FileOperations.move(context, signedOverlayAPKPath, overlay); FileOperations.setPermissions(644, overlay); - FileOperations.mountRO(); + FileOperations.mountSystemRO(); } else if (!Systems.isNewSamsungDeviceAndromeda(context)) { specialSnowflake = false; if (Resources.FRAMEWORK.equals(overlayPackage) || @@ -413,7 +413,7 @@ public boolean beginAction(Context context, // At this point, it is detected to be legacy mode and Substratum will push to // vendor/overlays directly. - FileOperations.mountRW(); + FileOperations.mountSystemRW(); // For Non-Nexus devices if (!Resources.inNexusFilter()) { String vendorLocation = LEGACY_NEXUS_DIR; @@ -449,7 +449,7 @@ public boolean beginAction(Context context, FileOperations.setSystemFileContext(vendorPartition); FileOperations.mountROVendor(); } - FileOperations.mountRO(); + FileOperations.mountSystemRO(); } } } diff --git a/app/src/main/java/projekt/substratum/util/helpers/MagiskHelper.java b/app/src/main/java/projekt/substratum/util/helpers/MagiskHelper.java new file mode 100644 index 000000000..5ff223d9c --- /dev/null +++ b/app/src/main/java/projekt/substratum/util/helpers/MagiskHelper.java @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2016-2018 Projekt Substratum + * This file is part of Substratum. + * + * SPDX-License-Identifier: GPL-3.0-Or-Later + */ + +package projekt.substratum.util.helpers; + +import android.content.Context; +import android.widget.Toast; +import projekt.substratum.BuildConfig; +import projekt.substratum.R; +import projekt.substratum.Substratum; +import projekt.substratum.common.References; +import projekt.substratum.common.commands.FileOperations; + +public class MagiskHelper { + + private static final String MAGISK_MIRROR_MOUNT_POINT = "/sbin/.core/mirror/system"; + private static final String MAGISK_MIRROR_MOUNT_POINT_AFTER_174 = "/sbin/.magisk/mirror/system"; + private static final String TAG = MagiskHelper.class.getSimpleName(); + private static final String CHECK_MAGISK_CMD = "if [ -d %s ] || [ -d %s ]; then echo '0'; fi"; + private static final String[] mountPoints = new String[]{MAGISK_MIRROR_MOUNT_POINT, MAGISK_MIRROR_MOUNT_POINT_AFTER_174}; + + public static void migrateToModule(final Context context) { + if (!checkMagisk()) + return; + if (Root.runCommand(String.format("test -d %s || echo '1'", + References.MAGISK_MODULE_DIR)).equals("1")) { + Substratum.log(TAG, "Magisk module does not exist, migrating"); + String command = "set -ex \n" + + String.format("mkdir -p %s; ", References.MAGISK_MODULE_DIR) + + String.format( + "printf 'name=substratum\nversion=%s\nversionCode=%s\nauthor=substratum development team\ndescription=Systemless overlays for Substratum\nminMagisk=1500\n' > %s/module.prop; ", + BuildConfig.VERSION_NAME, + BuildConfig.VERSION_CODE, + References.MAGISK_MODULE_DIR + ) + + String.format("touch %s/auto_mount; ", References.MAGISK_MODULE_DIR) + + String.format("mkdir -p %s/system/app; ", References.MAGISK_MODULE_DIR) + + String.format("mv %s/app/_*.apk %s; ", MAGISK_MIRROR_MOUNT_POINT, References.getPieDir()) + + String.format("mv %s/app/_*.apk %s; ", MAGISK_MIRROR_MOUNT_POINT_AFTER_174, References.getPieDir()); + for (String mountPoint : mountPoints) { + FileOperations.mountRW(mountPoint); + } + Root.runCommand(command); + for (String mountPoint : mountPoints) { + FileOperations.mountRO(mountPoint); + } + Toast.makeText(context, R.string.module_placed_reboot_message, Toast.LENGTH_LONG).show(); + } + } + + private static boolean checkMagisk() { + return Root.runCommand(String.format(CHECK_MAGISK_CMD, MAGISK_MIRROR_MOUNT_POINT, MAGISK_MIRROR_MOUNT_POINT_AFTER_174)).equals("0"); + } + + public static void forceRemoveOverlays() { + for (String mountPoint : mountPoints) { + FileOperations.mountRW(mountPoint); + Root.runCommand(String.format("rm -rf %s/app/_*.apk", mountPoint)); + FileOperations.mountRO(mountPoint); + } + } +} diff --git a/app/src/main/java/projekt/substratum/util/helpers/Root.java b/app/src/main/java/projekt/substratum/util/helpers/Root.java index a7347d586..14d8b7c9f 100644 --- a/app/src/main/java/projekt/substratum/util/helpers/Root.java +++ b/app/src/main/java/projekt/substratum/util/helpers/Root.java @@ -7,7 +7,7 @@ package projekt.substratum.util.helpers; -import projekt.substratum.common.References; +import projekt.substratum.common.Systems; import java.io.BufferedReader; import java.io.BufferedWriter; @@ -25,8 +25,7 @@ public class Root { * @return True, if root is present */ public static boolean checkRootAccess() { - StringBuilder check = References.runShellCommand("which su"); - return (check != null) && !check.toString().isEmpty(); + return Systems.checkRootAccess(); } /** diff --git a/app/src/main/java/projekt/substratum/util/helpers/TranslatorParser.java b/app/src/main/java/projekt/substratum/util/helpers/TranslatorParser.java index 57474c01c..ae3b354af 100644 --- a/app/src/main/java/projekt/substratum/util/helpers/TranslatorParser.java +++ b/app/src/main/java/projekt/substratum/util/helpers/TranslatorParser.java @@ -81,7 +81,7 @@ public TranslatorContributionDialog(SettingsFragment settingsFragment) { protected void onPreExecute() { super.onPreExecute(); SettingsFragment settingsFragment = ref.get(); - if (settingsFragment != null) { + if (settingsFragment.isAdded() && settingsFragment != null) { if (settingsFragment.getActivity() != null) { settingsFragment.dialog = new Dialog(settingsFragment.getActivity()); settingsFragment.dialog.setContentView(R.layout.validator_dialog); @@ -94,7 +94,7 @@ protected void onPreExecute() { @Override protected void onPostExecute(ArrayList result) { SettingsFragment settingsFragment = ref.get(); - if (settingsFragment != null) { + if (settingsFragment.isAdded() && settingsFragment != null) { settingsFragment.dialog.cancel(); if (alertDialogBuilder.get() != null) alertDialogBuilder.get().show(); } @@ -103,7 +103,7 @@ protected void onPostExecute(ArrayList result) { @Override protected ArrayList doInBackground(String... strings) { SettingsFragment settingsFragment = ref.get(); - if (settingsFragment != null) { + if (settingsFragment.isAdded() && settingsFragment != null) { InputStream inputStream = ref.get().getResources().openRawResource(R.raw.translators); TranslatorParser csvFile = new TranslatorParser(inputStream); diff --git a/app/src/main/java/projekt/substratum/util/helpers/ValidatorUtils.java b/app/src/main/java/projekt/substratum/util/helpers/ValidatorUtils.java index 66d47ec40..0efeb22cb 100644 --- a/app/src/main/java/projekt/substratum/util/helpers/ValidatorUtils.java +++ b/app/src/main/java/projekt/substratum/util/helpers/ValidatorUtils.java @@ -100,7 +100,7 @@ protected void onPostExecute(String result) { @Override protected String doInBackground(String... sUrl) { SettingsFragment settingsFragment = ref.get(); - if (settingsFragment != null) { + if (settingsFragment.isAdded() && settingsFragment != null) { return Systems.checkFirmwareSupport(settingsFragment.context, sUrl[0], sUrl[1]); } return null; @@ -125,7 +125,7 @@ public downloadRepositoryList(SettingsFragment settingsFragment) { protected void onPreExecute() { super.onPreExecute(); SettingsFragment settingsFragment = ref.get(); - if (settingsFragment != null) { + if (settingsFragment.isAdded() && settingsFragment != null) { if (settingsFragment.getActivity() != null) { settingsFragment.dialog = new Dialog(settingsFragment.getActivity()); settingsFragment.dialog.setContentView(R.layout.validator_dialog); @@ -139,7 +139,7 @@ protected void onPreExecute() { protected void onPostExecute(ArrayList result) { super.onPostExecute(result); SettingsFragment settingsFragment = ref.get(); - if (settingsFragment != null) { + if (settingsFragment.isAdded() && settingsFragment != null) { Collection erroredPackages = new ArrayList<>(); for (int x = 0; x < settingsFragment.errors.size(); x++) { ValidatorError error = settingsFragment.errors.get(x); @@ -193,7 +193,7 @@ protected ArrayList doInBackground(String... sUrl) { // First, we have to download the repository list into the cache SettingsFragment settingsFragment = ref.get(); ArrayList packages = new ArrayList<>(); - if (settingsFragment != null) { + if (settingsFragment.isAdded() && settingsFragment != null) { FileDownloader.init( settingsFragment.context, settingsFragment.getString(Systems.IS_OREO ? diff --git a/app/src/main/java/projekt/substratum/util/tabs/BootAnimationUtils.java b/app/src/main/java/projekt/substratum/util/tabs/BootAnimationUtils.java index 2b418e36e..6dab6243c 100644 --- a/app/src/main/java/projekt/substratum/util/tabs/BootAnimationUtils.java +++ b/app/src/main/java/projekt/substratum/util/tabs/BootAnimationUtils.java @@ -167,7 +167,7 @@ protected void onPostExecute(String result) { } if (!Systems.checkThemeInterfacer(context)) { FileOperations.mountROData(); - FileOperations.mountRO(); + FileOperations.mountSystemRO(); } } @@ -451,7 +451,7 @@ protected String doInBackground(String... sUrl) { // Inject backup script for encrypted legacy and encrypted OMS devices if (!hasFailed && (isEncrypted || !Systems.checkOMS(context)) && !shutdownAnimation) { - FileOperations.mountRW(); + FileOperations.mountSystemRW(); File backupScript = new File(SYSTEM_ADDON_DIR + BACKUP_SCRIPT); if (Systems.checkSubstratumFeature(context)) { diff --git a/app/src/main/java/projekt/substratum/util/tabs/FontUtils.java b/app/src/main/java/projekt/substratum/util/tabs/FontUtils.java index a4640b0eb..d24fddf40 100644 --- a/app/src/main/java/projekt/substratum/util/tabs/FontUtils.java +++ b/app/src/main/java/projekt/substratum/util/tabs/FontUtils.java @@ -58,23 +58,23 @@ private static class FontHandlerAsync extends AsyncTask private final WeakReference ref; - private FontHandlerAsync(FontUtils fragment) { + private FontHandlerAsync(FontUtils fontUtils) { super(); - ref = new WeakReference<>(fragment); + ref = new WeakReference<>(fontUtils); } @Override protected void onPreExecute() { - FontUtils fragment = ref.get(); - if (fragment != null) { - Context context = fragment.context; + FontUtils fontUtils = ref.get(); + if (fontUtils != null) { + Context context = fontUtils.context; if (References.ENABLE_EXTRAS_DIALOG) { - fragment.progress = new ProgressDialog(context, R.style.AppTheme_DialogAlert); - fragment.progress.setMessage(context.getString(R.string + fontUtils.progress = new ProgressDialog(context, R.style.AppTheme_DialogAlert); + fontUtils.progress.setMessage(context.getString(R.string .font_dialog_apply_text)); - fragment.progress.setIndeterminate(false); - fragment.progress.setCancelable(false); - fragment.progress.show(); + fontUtils.progress.setIndeterminate(false); + fontUtils.progress.setCancelable(false); + fontUtils.progress.show(); } boolean isRootless = (checkThemeInterfacer(context) || checkSubstratumService(context)); @@ -88,15 +88,15 @@ protected void onPreExecute() { @Override protected void onPostExecute(String result) { if ((result == null) || !result.equals(INTERFACER_PACKAGE)) { - FontUtils fragment = ref.get(); - if (fragment != null) { - Context context = fragment.context; + FontUtils fontUtils = ref.get(); + if (fontUtils != null) { + Context context = fontUtils.context; if (References.ENABLE_EXTRAS_DIALOG) { - fragment.progress.dismiss(); + fontUtils.progress.dismiss(); } if (result == null) { - SharedPreferences.Editor editor = fragment.prefs.edit(); - editor.putString(FONTS_APPLIED, fragment.themePid); + SharedPreferences.Editor editor = fontUtils.prefs.edit(); + editor.putString(FONTS_APPLIED, fontUtils.themePid); editor.apply(); Toast toast = Toast.makeText(context, context.getString(R.string.font_dialog_apply_success), Toast @@ -133,24 +133,24 @@ protected void onPostExecute(String result) { @Override protected String doInBackground(String... sUrl) { - FontUtils fragment = ref.get(); - if (fragment != null) { - Context context = fragment.context; + FontUtils fontUtils = ref.get(); + if (fontUtils != null) { + Context context = fontUtils.context; try { boolean isRootless = checkOMS(context) && (checkThemeInterfacer(context) && checkSubstratumService(context)); if (isRootless) { - SharedPreferences.Editor editor = fragment.prefs.edit(); - editor.putString(FONTS_APPLIED, fragment.themePid); + SharedPreferences.Editor editor = fontUtils.prefs.edit(); + editor.putString(FONTS_APPLIED, fontUtils.themePid); editor.apply(); } // Inform the font manager to start setting fonts! FontsManager.setFonts( context, - fragment.themePid, + fontUtils.themePid, sUrl[0]); if (isRootless) diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index ad14b8edf..7962e88b0 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -733,4 +733,6 @@ Restart app to switch language Restart + Substratum has installed it\'s Magisk module successfully. Please reboot to allow overlays to take effect. + diff --git a/build.gradle b/build.gradle deleted file mode 100644 index 1811f712e..000000000 --- a/build.gradle +++ /dev/null @@ -1,30 +0,0 @@ -// Top-level build file where you can add configuration options common to all sub-projects/modules. - -buildscript { - repositories { - google() - jcenter() - mavenCentral() - maven { url "https://maven.fabric.io/public" } - } - dependencies { - classpath 'com.android.tools.build:gradle:3.4.0-alpha02' - classpath 'com.google.gms:google-services:3.2.0' - classpath 'io.fabric.tools:gradle:1.25.4' - // NOTE: Do not place your application dependencies here; they belong - // in the individual module build.gradle files - } -} - -allprojects { - repositories { - google() - jcenter() - maven { url "https://jitpack.io" } - maven { url "https://maven.google.com/" } - } -} - -task clean(type: Delete) { - delete rootProject.buildDir -} \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts new file mode 100644 index 000000000..4b7ba8948 --- /dev/null +++ b/build.gradle.kts @@ -0,0 +1,47 @@ +import com.github.benmanes.gradle.versions.updates.DependencyUpdatesTask + +buildscript { + repositories { + google() + jcenter() + mavenCentral() + } + dependencies { + classpath("com.android.tools.build:gradle:3.2.1") + } +} + +plugins { + id("com.github.ben-manes.versions") version "0.20.0" +} + +allprojects { + repositories { + google() + jcenter() + maven(url = "https://jitpack.io") + } +} + +tasks.named("dependencyUpdates") { + checkForGradleUpdate = true + resolutionStrategy { + componentSelection { + all { + val rejected = listOf("alpha", "beta", "rc", "cr", "m", "preview") + .map { qualifier -> Regex("(?i).*[.-]$qualifier[.\\d-]*") } + .any { it.matches(candidate.version) + } + if (rejected) { + reject("Release candidate") + } + } + } + } +} + +tasks { + register("clean", Delete::class) { + delete(rootProject.buildDir) + } +} diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index de8a0b812..d2c9f0321 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-all.zip diff --git a/settings.gradle b/settings.gradle deleted file mode 100644 index 9d495b34f..000000000 --- a/settings.gradle +++ /dev/null @@ -1 +0,0 @@ -include ':app' \ No newline at end of file diff --git a/settings.gradle.kts b/settings.gradle.kts new file mode 100644 index 000000000..15a801b10 --- /dev/null +++ b/settings.gradle.kts @@ -0,0 +1 @@ +include(":app")