mirror of
https://github.com/AngelAuraMC/Amethyst-Android.git
synced 2025-09-16 16:16:04 -04:00
A bunch of fixes for old android and storage
This commit is contained in:
parent
f0c4fef803
commit
530a73e5c7
@ -28,19 +28,24 @@
|
||||
<meta-data
|
||||
android:name="android.max_aspect"
|
||||
android:value="ratio_float"/>
|
||||
|
||||
<activity
|
||||
|
||||
<activity android:name=".TestStorageActivity"
|
||||
android:exported="true"
|
||||
android:launchMode="singleTop"
|
||||
android:label="@string/app_short_name"
|
||||
android:name=".LauncherActivity">
|
||||
android:label="@string/app_short_name">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<activity android:name=".ImportControlActivity"
|
||||
<activity
|
||||
android:label="@string/app_short_name"
|
||||
android:name=".LauncherActivity">
|
||||
</activity>
|
||||
|
||||
<activity
|
||||
android:name=".ImportControlActivity"
|
||||
android:exported="true"
|
||||
android:windowSoftInputMode="stateVisible"
|
||||
android:launchMode="singleInstance"
|
||||
|
@ -36,6 +36,8 @@ public class ProgressLayout extends ConstraintLayout implements View.OnClickList
|
||||
public static final String DOWNLOAD_VERSION_LIST = "download_verlist";
|
||||
public static final String AUTHENTICATE_MICROSOFT = "authenticate_microsoft";
|
||||
public static final String INSTALL_MODPACK = "install_modpack";
|
||||
public static final String EXTRACT_COMPONENTS = "extract_components";
|
||||
public static final String EXTRACT_SINGLE_FILES = "extract_single_files";
|
||||
|
||||
public ProgressLayout(@NonNull Context context) {
|
||||
super(context);
|
||||
|
@ -191,8 +191,11 @@ public class ImportControlActivity extends Activity {
|
||||
|
||||
public String getNameFromURI(Uri uri) {
|
||||
Cursor c = getContentResolver().query(uri, null, null, null, null);
|
||||
if(c == null) return uri.getLastPathSegment(); // idk myself but it happens on asus file manager
|
||||
c.moveToFirst();
|
||||
String fileName = c.getString(c.getColumnIndex(OpenableColumns.DISPLAY_NAME));
|
||||
int columnIndex = c.getColumnIndex(OpenableColumns.DISPLAY_NAME);
|
||||
if(columnIndex == -1) return uri.getLastPathSegment();
|
||||
String fileName = c.getString(columnIndex);
|
||||
c.close();
|
||||
return trimFileName(fileName);
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ import net.kdt.pojavlaunch.utils.*;
|
||||
|
||||
public class PojavApplication extends Application {
|
||||
public static String CRASH_REPORT_TAG = "PojavCrashReport";
|
||||
public static ExecutorService sExecutorService = new ThreadPoolExecutor(0, 4, 500, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>());
|
||||
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);
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
@ -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);
|
||||
});
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user