diff --git a/app_pojavlauncher/src/main/AndroidManifest.xml b/app_pojavlauncher/src/main/AndroidManifest.xml
index a33cdc8f0..5260b0ed8 100644
--- a/app_pojavlauncher/src/main/AndroidManifest.xml
+++ b/app_pojavlauncher/src/main/AndroidManifest.xml
@@ -28,19 +28,24 @@
-
-
+ android:label="@string/app_short_name">
-
+
+
+ ());
+ public static ExecutorService sExecutorService = new ThreadPoolExecutor(4, 4, 500, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>());
@Override
public void onCreate() {
@@ -73,8 +73,6 @@ public class PojavApplication extends Application {
.concat("/x86");
}
AsyncAssetManager.unpackRuntime(getAssets(), false);
- AsyncAssetManager.unpackComponents(this);
- AsyncAssetManager.unpackSingleFiles(this);
} catch (Throwable throwable) {
Intent ferrorIntent = new Intent(this, FatalErrorActivity.class);
ferrorIntent.putExtra("throwable", throwable);
diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/TestStorageActivity.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/TestStorageActivity.java
new file mode 100644
index 000000000..a95297916
--- /dev/null
+++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/TestStorageActivity.java
@@ -0,0 +1,67 @@
+package net.kdt.pojavlaunch;
+
+import android.Manifest;
+import android.app.Activity;
+import android.content.Context;
+import android.content.Intent;
+import android.content.pm.PackageManager;
+import android.os.Build;
+import android.os.Bundle;
+import android.widget.Toast;
+
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+import androidx.core.app.ActivityCompat;
+import androidx.core.content.ContextCompat;
+
+import net.kdt.pojavlaunch.tasks.AsyncAssetManager;
+
+public class TestStorageActivity extends Activity {
+ private final int REQUEST_STORAGE_REQUEST_CODE = 1;
+ @Override
+ protected void onCreate(@Nullable Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ if(Build.VERSION.SDK_INT >= 23 && Build.VERSION.SDK_INT < 29 && !isStorageAllowed(this)) requestStoragePermission();
+ else exit();
+ }
+
+ @Override
+ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
+ super.onRequestPermissionsResult(requestCode, permissions, grantResults);
+ if(requestCode == REQUEST_STORAGE_REQUEST_CODE) {
+ if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
+ exit();
+ } else {
+ Toast.makeText(this, R.string.toast_permission_denied, Toast.LENGTH_LONG).show();
+ requestStoragePermission();
+ }
+ }
+ }
+
+ public static boolean isStorageAllowed(Context context) {
+ //Getting the permission status
+ int result1 = ContextCompat.checkSelfPermission(context, Manifest.permission.WRITE_EXTERNAL_STORAGE);
+ int result2 = ContextCompat.checkSelfPermission(context, Manifest.permission.READ_EXTERNAL_STORAGE);
+
+
+ //If permission is granted returning true
+ return result1 == PackageManager.PERMISSION_GRANTED &&
+ result2 == PackageManager.PERMISSION_GRANTED;
+ }
+
+ private void requestStoragePermission() {
+
+ ActivityCompat.requestPermissions(this, new String[]{
+ Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE}, REQUEST_STORAGE_REQUEST_CODE);
+ }
+
+ private void exit() {
+ //Only run them once we get a definitive green light to use storage
+ AsyncAssetManager.unpackComponents(this);
+ AsyncAssetManager.unpackSingleFiles(this);
+
+ Intent intent = new Intent(this, LauncherActivity.class);
+ startActivity(intent);
+ finish();
+ }
+}
diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/tasks/AsyncAssetManager.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/tasks/AsyncAssetManager.java
index efd1a8464..7410911ad 100644
--- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/tasks/AsyncAssetManager.java
+++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/tasks/AsyncAssetManager.java
@@ -4,22 +4,12 @@ package net.kdt.pojavlaunch.tasks;
import static net.kdt.pojavlaunch.Architecture.archAsString;
import static net.kdt.pojavlaunch.PojavApplication.sExecutorService;
-import android.app.Notification;
-import android.app.Service;
import android.content.Context;
-import android.content.Intent;
import android.content.res.AssetManager;
-import android.os.Handler;
-import android.os.HandlerThread;
-import android.os.IBinder;
import android.util.Log;
-import androidx.annotation.Nullable;
-import androidx.core.app.NotificationCompat;
-
import com.kdt.mcgui.ProgressLayout;
-import net.kdt.pojavlaunch.R;
import net.kdt.pojavlaunch.Tools;
import net.kdt.pojavlaunch.multirt.MultiRTUtils;
@@ -49,7 +39,8 @@ public class AsyncAssetManager {
} catch (IOException e) {
Log.e("JREAuto", "JRE was not included on this APK.", e);
}
- if(current_rt_version == null && MultiRTUtils.getExactJreName(8) != null) return true; //Assume user maintains his own runtime
+ String exactJREName = MultiRTUtils.getExactJreName(8);
+ if(current_rt_version == null && exactJREName != null && !exactJREName.equals("Internal")/*this clause is for when the internal runtime is goofed*/) return true; //Assume user maintains his own runtime
if(rt_version == null) return otherRuntimesAvailable; // On noruntime builds, skip if there is at least 1 runtime installed (no matter if it is 8 or not)
if(rt_version.equals(current_rt_version)) return true; //If we already have an integrated one installed, check if it's up-to-date
@@ -73,8 +64,8 @@ public class AsyncAssetManager {
/** Unpack single files, with no regard to version tracking */
public static void unpackSingleFiles(Context ctx){
+ ProgressLayout.setProgress(ProgressLayout.EXTRACT_SINGLE_FILES, 0);
sExecutorService.execute(() -> {
-
try {
Tools.copyAssetFile(ctx, "options.txt", Tools.DIR_GAME_NEW, false);
Tools.copyAssetFile(ctx, "default.json", Tools.CTRLMAP_PATH, false);
@@ -85,11 +76,12 @@ public class AsyncAssetManager {
} catch (IOException e) {
Log.e("AsyncAssetManager", "Failed to unpack critical components !");
}
-
+ ProgressLayout.clearProgress(ProgressLayout.EXTRACT_SINGLE_FILES);
});
}
public static void unpackComponents(Context ctx){
+ ProgressLayout.setProgress(ProgressLayout.EXTRACT_COMPONENTS, 0);
sExecutorService.execute(() -> {
try {
unpackComponent(ctx, "caciocavallo", false);
@@ -101,6 +93,7 @@ public class AsyncAssetManager {
} catch (IOException e) {
Log.e("AsyncAssetManager", "Failed o unpack components !",e );
}
+ ProgressLayout.clearProgress(ProgressLayout.EXTRACT_COMPONENTS);
});
}