mirror of
https://github.com/stenzek/duckstation.git
synced 2024-11-27 08:00:36 +00:00
Android: Add option in gamedirs to force scoped storage
This commit is contained in:
parent
3cb4d8e35a
commit
4f51310e83
@ -50,6 +50,7 @@ import java.util.Set;
|
||||
|
||||
public class GameDirectoriesActivity extends AppCompatActivity {
|
||||
private static final int REQUEST_ADD_DIRECTORY_TO_GAME_LIST = 1;
|
||||
private static final String FORCE_SAF_CONFIG_KEY = "GameList/ForceStorageAccessFramework";
|
||||
|
||||
private class DirectoryListAdapter extends RecyclerView.Adapter {
|
||||
private class Entry {
|
||||
@ -219,6 +220,23 @@ public class GameDirectoriesActivity extends AppCompatActivity {
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
// Inflate the menu; this adds items to the action bar if it is present.
|
||||
getMenuInflater().inflate(R.menu.menu_edit_game_directories, menu);
|
||||
|
||||
menu.findItem(R.id.force_saf)
|
||||
.setEnabled(android.os.Build.VERSION.SDK_INT < 30)
|
||||
.setChecked(PreferenceManager.getDefaultSharedPreferences(this).getBoolean(
|
||||
FORCE_SAF_CONFIG_KEY, false))
|
||||
.setOnMenuItemClickListener(item -> {
|
||||
final SharedPreferences sharedPreferences =
|
||||
PreferenceManager.getDefaultSharedPreferences(this);
|
||||
final boolean newValue =!sharedPreferences.getBoolean(
|
||||
FORCE_SAF_CONFIG_KEY, false);
|
||||
sharedPreferences.edit()
|
||||
.putBoolean(FORCE_SAF_CONFIG_KEY, newValue)
|
||||
.commit();
|
||||
item.setChecked(newValue);
|
||||
return true;
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -240,6 +258,16 @@ public class GameDirectoriesActivity extends AppCompatActivity {
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
public static boolean useStorageAccessFramework(Context context) {
|
||||
// Use legacy storage on devices older than Android 11... apparently some of them
|
||||
// have broken storage access framework....
|
||||
if (android.os.Build.VERSION.SDK_INT >= 30)
|
||||
return true;
|
||||
|
||||
return PreferenceManager.getDefaultSharedPreferences(context).getBoolean(
|
||||
"GameList/ForceStorageAccessFramework", false);
|
||||
}
|
||||
|
||||
public static void addSearchDirectory(Context context, String path, boolean recursive) {
|
||||
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
final String key = recursive ? "GameList/RecursivePaths" : "GameList/Paths";
|
||||
@ -294,7 +322,7 @@ public class GameDirectoriesActivity extends AppCompatActivity {
|
||||
|
||||
// Use legacy storage on devices older than Android 11... apparently some of them
|
||||
// have broken storage access framework....
|
||||
if (android.os.Build.VERSION.SDK_INT < 30) {
|
||||
if (!useStorageAccessFramework(this)) {
|
||||
final String path = FileHelper.getFullPathFromTreeUri(data.getData(), this);
|
||||
if (path != null) {
|
||||
addSearchDirectory(this, path, true);
|
||||
|
@ -274,7 +274,7 @@ public class MainActivity extends AppCompatActivity {
|
||||
|
||||
// Use legacy storage on devices older than Android 11... apparently some of them
|
||||
// have broken storage access framework....
|
||||
if (android.os.Build.VERSION.SDK_INT < 30) {
|
||||
if (!GameDirectoriesActivity.useStorageAccessFramework(this)) {
|
||||
final String path = FileHelper.getFullPathFromTreeUri(data.getData(), this);
|
||||
if (path != null) {
|
||||
GameDirectoriesActivity.addSearchDirectory(this, path, true);
|
||||
|
@ -8,4 +8,8 @@
|
||||
<item
|
||||
android:id="@+id/add_path"
|
||||
android:title="@string/menu_edit_game_directories_add_path" />
|
||||
<item
|
||||
android:id="@+id/force_saf"
|
||||
android:checkable="true"
|
||||
android:title="@string/menu_edit_game_directories_force_saf" />
|
||||
</menu>
|
@ -362,4 +362,5 @@
|
||||
<string name="settings_summary_read_thread">Reduces hitches in emulation by reading/decompressing CD data asynchronously on a worker thread.</string>
|
||||
<string name="settings_cdrom_load_image_patches">Apply Image Patches</string>
|
||||
<string name="settings_summary_load_image_patches">Automatically applies patches to disc images when they are present, currently only PPF is supported.</string>
|
||||
<string name="menu_edit_game_directories_force_saf">Force Scoped Storage</string>
|
||||
</resources>
|
||||
|
Loading…
Reference in New Issue
Block a user