From 647f53231e0bf7589272a8e20629a4d781b9116f Mon Sep 17 00:00:00 2001 From: androidacy-user Date: Thu, 27 Apr 2023 21:18:09 -0400 Subject: [PATCH] (misc) small fixes and updates Signed-off-by: androidacy-user --- app/build.gradle.kts | 8 ++++++++ .../main/java/com/fox2code/mmm/MainActivity.java | 14 ++++++++++++-- .../java/com/fox2code/mmm/MainApplication.java | 4 ---- .../mmm/installer/InstallerInitializer.java | 4 +++- 4 files changed, 23 insertions(+), 7 deletions(-) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index ab3cf23..12e70f4 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -28,6 +28,7 @@ android { val gitRemote = providers.exec { commandLine("git", "config", "--get", "remote.origin.url") }.standardOutput.asText.get().toString().trim() + val timestamp = System.currentTimeMillis() namespace = "com.fox2code.mmm" compileSdk = 33 @@ -95,6 +96,8 @@ android { productFlavors { create("default") { dimension = "type" + // current timestamp of build + buildConfigField("long", "BUILD_TIME", "$timestamp") // debug http requests. do not set this to true if you care about performance!!!!! buildConfigField("boolean", "DEBUG_HTTP", "false") // Latest commit hash as BuildConfig.COMMIT_HASH @@ -156,6 +159,8 @@ android { create("play") { dimension = "type" applicationIdSuffix = ".play" + // current timestamp of build + buildConfigField("long", "BUILD_TIME", "$timestamp") // debug http requests. do not set this to true if you care about performance!!!!! buildConfigField("boolean", "DEBUG_HTTP", "false") // Latest commit hash as BuildConfig.COMMIT_HASH @@ -216,6 +221,8 @@ android { create("fdroid") { dimension = "type" applicationIdSuffix = ".fdroid" + // current timestamp of build + buildConfigField("long", "BUILD_TIME", "$timestamp") // debug http requests. do not set this to true if you care about performance!!!!! buildConfigField("boolean", "DEBUG_HTTP", "false") @@ -308,6 +315,7 @@ sentry { setOf( InstrumentationFeature.DATABASE, InstrumentationFeature.FILE_IO, + InstrumentationFeature.OKHTTP, InstrumentationFeature.COMPOSE ) ) diff --git a/app/src/main/java/com/fox2code/mmm/MainActivity.java b/app/src/main/java/com/fox2code/mmm/MainActivity.java index 321ee34..3026cb0 100644 --- a/app/src/main/java/com/fox2code/mmm/MainActivity.java +++ b/app/src/main/java/com/fox2code/mmm/MainActivity.java @@ -57,6 +57,7 @@ import com.google.android.material.snackbar.Snackbar; import org.matomo.sdk.extra.TrackHelper; +import java.sql.Timestamp; import java.util.Objects; import io.realm.Realm; @@ -120,12 +121,21 @@ public class MainActivity extends FoxActivity implements SwipeRefreshLayout.OnRe } TrackHelper.track().event("enabled_repos", enabledRepos.toString()).with(MainApplication.getINSTANCE().getTracker()); realm.close(); - // log all shared preferences that are present - if (!Iof) { + // hide this behind a buildconfig flag for now, but crash the app if it's not an official build and not debug + if (BuildConfig.ENABLE_PROTECTION && !Iof && !BuildConfig.DEBUG) { + throw new RuntimeException("This is not an official build of FoxMMM"); + } else if (!Iof && !BuildConfig.DEBUG) { Timber.w("You may be running an untrusted build."); // Show a toast to warn the user Toast.makeText(this, R.string.not_official_build, Toast.LENGTH_LONG).show(); } + Timestamp ts = new Timestamp(System.currentTimeMillis() - (30L * 24 * 60 * 60 * 1000)); + // check if this build has expired + Timestamp buildTime = new Timestamp(BuildConfig.BUILD_TIME); + // if the build time is more than 30 days ago, throw an exception + if (ts.getTime() < buildTime.getTime()) { + throw new IllegalStateException("This build has expired. Please download a stable build or update to the latest version."); + } setContentView(R.layout.activity_main); this.setTitle(R.string.app_name); // set window flags to ignore status bar diff --git a/app/src/main/java/com/fox2code/mmm/MainApplication.java b/app/src/main/java/com/fox2code/mmm/MainApplication.java index 35ca3fb..7a520ba 100644 --- a/app/src/main/java/com/fox2code/mmm/MainApplication.java +++ b/app/src/main/java/com/fox2code/mmm/MainApplication.java @@ -422,10 +422,6 @@ public class MainApplication extends FoxApplication implements androidx.work.Con Iof = Arrays.asList(osh).contains(oosh); } catch (PackageManager.NameNotFoundException ignored) { } - // hide this behind a buildconfig flag for now, but crash the app if it's not an official build and not debug - if (BuildConfig.ENABLE_PROTECTION && !Iof && !BuildConfig.DEBUG) { - throw new RuntimeException("This is not an official build of FoxMMM"); - } SharedPreferences sharedPreferences = MainApplication.getPreferences("mmm"); // We are only one process so it's ok to do this SharedPreferences bootPrefs = MainApplication.getPreferences("mmm_boot"); diff --git a/app/src/main/java/com/fox2code/mmm/installer/InstallerInitializer.java b/app/src/main/java/com/fox2code/mmm/installer/InstallerInitializer.java index 3c2b7a3..050fe5e 100644 --- a/app/src/main/java/com/fox2code/mmm/installer/InstallerInitializer.java +++ b/app/src/main/java/com/fox2code/mmm/installer/InstallerInitializer.java @@ -138,7 +138,9 @@ public class InstallerInitializer extends Shell.Initializer { @Override public boolean onInit(@NonNull Context context, @NonNull Shell shell) { - if (!shell.isRoot()) { + // open a new shell + shell.newJob().add("id").exec().getOut(); + if (!Boolean.TRUE.equals(Shell.isAppGrantedRoot())) { Timber.w("No root access!"); return false; }