From 9c8bb24293820c9be973e085511e24808b9bf707 Mon Sep 17 00:00:00 2001 From: JosJuice Date: Sun, 9 May 2021 15:23:11 +0200 Subject: [PATCH] Android: Add a "user data" screen To make it clearer for users where Dolphin is storing user data, now that there's more than one possible place. --- .../Android/app/src/main/AndroidManifest.xml | 6 +++ .../activities/UserDataActivity.java | 45 +++++++++++++++++++ .../ui/SettingsFragmentPresenter.java | 3 ++ .../utils/DirectoryInitialization.java | 11 ++++- .../main/res/layout/activity_user_data.xml | 45 +++++++++++++++++++ .../app/src/main/res/values/strings.xml | 6 +++ 6 files changed, 115 insertions(+), 1 deletion(-) create mode 100644 Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/UserDataActivity.java create mode 100644 Source/Android/app/src/main/res/layout/activity_user_data.xml diff --git a/Source/Android/app/src/main/AndroidManifest.xml b/Source/Android/app/src/main/AndroidManifest.xml index 4a1798d975..15bd0ee7fc 100644 --- a/Source/Android/app/src/main/AndroidManifest.xml +++ b/Source/Android/app/src/main/AndroidManifest.xml @@ -120,6 +120,12 @@ android:exported="false" android:theme="@style/DolphinBase" /> + + diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/UserDataActivity.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/UserDataActivity.java new file mode 100644 index 0000000000..79fcc09123 --- /dev/null +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/UserDataActivity.java @@ -0,0 +1,45 @@ +// SPDX-License-Identifier: GPL-2.0-or-later + +package org.dolphinemu.dolphinemu.activities; + +import android.content.Context; +import android.content.Intent; +import android.os.Build; +import android.os.Bundle; +import android.view.View; +import android.widget.TextView; + +import androidx.appcompat.app.AppCompatActivity; + +import org.dolphinemu.dolphinemu.R; +import org.dolphinemu.dolphinemu.utils.DirectoryInitialization; + +public class UserDataActivity extends AppCompatActivity +{ + public static void launch(Context context) + { + Intent launcher = new Intent(context, UserDataActivity.class); + context.startActivity(launcher); + } + + @Override + protected void onCreate(Bundle savedInstanceState) + { + super.onCreate(savedInstanceState); + + setContentView(R.layout.activity_user_data); + + TextView textType = findViewById(R.id.text_type); + TextView textPath = findViewById(R.id.text_path); + TextView textAndroid11 = findViewById(R.id.text_android_11); + + textType.setText(DirectoryInitialization.isUsingLegacyUserDirectory() ? + R.string.user_data_old_location : R.string.user_data_new_location); + + textPath.setText(DirectoryInitialization.getUserDirectory()); + + boolean show_android_11_text = Build.VERSION.SDK_INT >= Build.VERSION_CODES.R && + !DirectoryInitialization.isUsingLegacyUserDirectory(); + textAndroid11.setVisibility(show_android_11_text ? View.VISIBLE : View.GONE); + } +} diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsFragmentPresenter.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsFragmentPresenter.java index d91faa775e..c718bab15e 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsFragmentPresenter.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsFragmentPresenter.java @@ -10,6 +10,7 @@ import android.text.TextUtils; import org.dolphinemu.dolphinemu.DolphinApplication; import org.dolphinemu.dolphinemu.NativeLibrary; import org.dolphinemu.dolphinemu.R; +import org.dolphinemu.dolphinemu.activities.UserDataActivity; import org.dolphinemu.dolphinemu.features.settings.model.AbstractIntSetting; import org.dolphinemu.dolphinemu.features.settings.model.AbstractStringSetting; import org.dolphinemu.dolphinemu.features.settings.model.AdHocBooleanSetting; @@ -252,6 +253,8 @@ public final class SettingsFragmentPresenter sl.add(new SubmenuSetting(mContext, R.string.advanced_submenu, MenuTag.CONFIG_ADVANCED)); sl.add(new SubmenuSetting(mContext, R.string.log_submenu, MenuTag.CONFIG_LOG)); sl.add(new SubmenuSetting(mContext, R.string.debug_submenu, MenuTag.DEBUG)); + sl.add(new RunRunnable(mContext, R.string.user_data_submenu, 0, 0, 0, + () -> UserDataActivity.launch(mContext))); } private void addGeneralSettings(ArrayList sl) diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/DirectoryInitialization.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/DirectoryInitialization.java index c2f6d638df..48963052dc 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/DirectoryInitialization.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/DirectoryInitialization.java @@ -43,6 +43,7 @@ public final class DirectoryInitialization private static volatile boolean areDirectoriesAvailable = false; private static String userPath; private static AtomicBoolean isDolphinDirectoryInitializationRunning = new AtomicBoolean(false); + private static boolean isUsingLegacyUserDirectory = false; public enum DirectoryInitializationState { @@ -108,7 +109,10 @@ public final class DirectoryInitialization if (!Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) return false; - File path = preferLegacyUserDirectory(context) && PermissionsHandler.hasWriteAccess(context) ? + isUsingLegacyUserDirectory = + preferLegacyUserDirectory(context) && PermissionsHandler.hasWriteAccess(context); + + File path = isUsingLegacyUserDirectory ? getLegacyUserDirectoryPath() : context.getExternalFilesDir(null); if (path == null) @@ -388,6 +392,11 @@ public final class DirectoryInitialization isExternalFilesDirEmpty(context) && legacyUserDirectoryExists(); } + public static boolean isUsingLegacyUserDirectory() + { + return isUsingLegacyUserDirectory; + } + public static boolean isWaitingForWriteAccess(Context context) { // This first check is only for performance, not correctness diff --git a/Source/Android/app/src/main/res/layout/activity_user_data.xml b/Source/Android/app/src/main/res/layout/activity_user_data.xml new file mode 100644 index 0000000000..dc7aa50fb9 --- /dev/null +++ b/Source/Android/app/src/main/res/layout/activity_user_data.xml @@ -0,0 +1,45 @@ + + + + + + + + + + diff --git a/Source/Android/app/src/main/res/values/strings.xml b/Source/Android/app/src/main/res/values/strings.xml index 6671023dea..5020e1b93e 100644 --- a/Source/Android/app/src/main/res/values/strings.xml +++ b/Source/Android/app/src/main/res/values/strings.xml @@ -324,6 +324,12 @@ Jit Branch Disabled Jit Register Cache Disabled + + User Data + Your user data is stored in a location which will not be deleted when you uninstall the app: + Your user data is stored in a location which will be deleted when you uninstall the app: + Because you\'re using Android 11 or newer, you can\'t access this location using file manager apps. However, you can access it using the file manager in the system settings, or by connecting your device to a PC. + Yes No