Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ else {
android {
ndkVersion "26.0.10792818"
namespace 'com.dishii.soh'
compileSdkVersion 31
compileSdkVersion 33
buildFeatures {
buildConfig = true
}
Expand Down
3 changes: 2 additions & 1 deletion Android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
android:allowBackup="true"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
android:hardwareAccelerated="true"
android:requestLegacyExternalStorage="true"
android:appCategory="game" >


Expand All @@ -83,7 +84,7 @@
<meta-data android:name="SDL_ENV.SDL_IOS_ORIENTATIONS" android:value="LandscapeLeft LandscapeRight"/>


<activity android:name="MainActivity"
<activity android:name=".MainActivity"
android:label="@string/app_name"
android:alwaysRetainTaskState="true"
android:launchMode="singleInstance"
Expand Down
74 changes: 63 additions & 11 deletions Android/app/src/main/java/com/dishii/soh/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
import java.io.OutputStream;
import java.io.FileOutputStream;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicBoolean;

import android.Manifest;
import android.content.ActivityNotFoundException;
import android.content.pm.PackageManager;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
Expand All @@ -42,26 +44,40 @@ public class MainActivity extends SDLActivity{

SharedPreferences preferences;
private static final CountDownLatch setupLatch = new CountDownLatch(1);
private final AtomicBoolean isSetupStarted = new AtomicBoolean(false);

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

preferences = getSharedPreferences("com.dishii.soh.prefs",Context.MODE_PRIVATE);

setupControllerOverlay();
attachController();

// Check if storage permissions are granted
if (hasStoragePermission()) {
doVersionCheck();
checkAndSetupFiles();
if (isSetupStarted.compareAndSet(false, true)) {
doVersionCheck();
checkAndSetupFiles();
}
} else {
requestStoragePermission();
}
}

super.onCreate(savedInstanceState);
@Override
protected void onResume() {
super.onResume();

setupControllerOverlay();
attachController();
if (hasStoragePermission()) {
if (isSetupStarted.compareAndSet(false, true)) {
doVersionCheck();
checkAndSetupFiles();
}
}
}

public static void waitForSetupFromNative() {
Expand Down Expand Up @@ -152,12 +168,20 @@ private void requestStoragePermission() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
// Android 11+ → MANAGE_EXTERNAL_STORAGE
if (!Environment.isExternalStorageManager()) {
Intent intent = new Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION);
intent.setData(Uri.parse("package:" + getPackageName()));
startActivityForResult(intent, STORAGE_PERMISSION_REQUEST_CODE);
try {
Intent intent = new Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION);
intent.setData(Uri.parse("package:" + getPackageName()));
startActivityForResult(intent, STORAGE_PERMISSION_REQUEST_CODE);
} catch (ActivityNotFoundException e) {
Intent intent = new Intent(Settings.ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION);
startActivityForResult(intent, STORAGE_PERMISSION_REQUEST_CODE);
}
} else {
// Already granted
checkAndSetupFiles();
if (isSetupStarted.compareAndSet(false, true)) {
doVersionCheck();
checkAndSetupFiles();
}
}
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
// Android 6–10 → request READ/WRITE at runtime
Expand All @@ -169,7 +193,10 @@ private void requestStoragePermission() {
STORAGE_PERMISSION_REQUEST_CODE);
} else {
// Below Android 6 → permissions granted at install time
checkAndSetupFiles();
if (isSetupStarted.compareAndSet(false, true)) {
doVersionCheck();
checkAndSetupFiles();
}
}
}

Expand Down Expand Up @@ -326,14 +353,39 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// Handle MANAGE_EXTERNAL_STORAGE result
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
if (Environment.isExternalStorageManager()) {
checkAndSetupFiles();
if (isSetupStarted.compareAndSet(false, true)) {
doVersionCheck();
checkAndSetupFiles();
}
} else {
Toast.makeText(this, "Storage permission is required to access files.", Toast.LENGTH_LONG).show();
}
}
}
}

@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
if (requestCode == STORAGE_PERMISSION_REQUEST_CODE) {
boolean allGranted = grantResults.length > 0;
for (int result : grantResults) {
if (result != PackageManager.PERMISSION_GRANTED) {
allGranted = false;
break;
}
}
if (allGranted) {
if (isSetupStarted.compareAndSet(false, true)) {
doVersionCheck();
checkAndSetupFiles();
}
} else {
Toast.makeText(this, "Storage permission is required to access files.", Toast.LENGTH_LONG).show();
}
}
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
}

public void openFilePicker() {
// Create an Intent to open the file picker dialog
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
Expand Down