From 1596b13743b2d84683a979b328d2d19246753e05 Mon Sep 17 00:00:00 2001 From: Robin Kertels Date: Sat, 8 Apr 2023 14:54:49 +0200 Subject: [PATCH 1/2] Android: Give Debug and Benchmark builds unique names on the launcher and for the DocumentsProvider --- Source/Android/app/build.gradle | 5 +++-- Source/Android/app/src/main/AndroidManifest.xml | 4 ++-- .../org/dolphinemu/dolphinemu/features/DocumentProvider.kt | 4 ++-- .../java/org/dolphinemu/dolphinemu/ui/main/MainActivity.java | 1 + 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/Source/Android/app/build.gradle b/Source/Android/app/build.gradle index bbc5a410fb..36ed3baf02 100644 --- a/Source/Android/app/build.gradle +++ b/Source/Android/app/build.gradle @@ -40,7 +40,6 @@ android { } defaultConfig { - // TODO If this is ever modified, change application_id in strings.xml applicationId "org.dolphinemu.dolphinemu" minSdkVersion 21 targetSdkVersion 33 @@ -74,6 +73,7 @@ android { signingConfig signingConfigs.release } + resValue 'string', 'app_name_suffixed', 'Dolphin Emulator' minifyEnabled true shrinkResources true proguardFiles getDefaultProguardFile( @@ -86,13 +86,14 @@ android { // Signed by debug key disallowing distribution on Play Store. // Attaches 'debug' suffix to version and package name, allowing installation alongside the release build. debug { - // TODO If this is ever modified, change application_id in debug/strings.xml + resValue 'string', 'app_name_suffixed', 'Dolphin Debug' applicationIdSuffix ".debug" versionNameSuffix '-debug' jniDebuggable true } benchmark { + resValue 'string', 'app_name_suffixed', 'Dolphin Benchmark' signingConfig signingConfigs.debug matchingFallbacks = ['release'] debuggable false diff --git a/Source/Android/app/src/main/AndroidManifest.xml b/Source/Android/app/src/main/AndroidManifest.xml index ce871e67d4..f470bafee7 100644 --- a/Source/Android/app/src/main/AndroidManifest.xml +++ b/Source/Android/app/src/main/AndroidManifest.xml @@ -31,7 +31,7 @@ diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/DocumentProvider.kt b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/DocumentProvider.kt index 089170125c..85fee36a18 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/DocumentProvider.kt +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/DocumentProvider.kt @@ -59,7 +59,7 @@ class DocumentProvider : DocumentsProvider() { result.newRow().apply { add(DocumentsContract.Root.COLUMN_ROOT_ID, ROOT_ID) - add(DocumentsContract.Root.COLUMN_TITLE, context!!.getString(R.string.app_name)) + add(DocumentsContract.Root.COLUMN_TITLE, context!!.getString(R.string.app_name_suffixed)) add(DocumentsContract.Root.COLUMN_ICON, R.drawable.ic_dolphin) add( DocumentsContract.Root.COLUMN_FLAGS, @@ -171,7 +171,7 @@ class DocumentProvider : DocumentsProvider() { } val name = if (file == rootDirectory) { - context!!.getString(R.string.app_name) + context!!.getString(R.string.app_name_suffixed) } else { file.name } diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/MainActivity.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/MainActivity.java index 1b0ff8cc32..488f0909df 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/MainActivity.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/MainActivity.java @@ -77,6 +77,7 @@ public final class MainActivity extends AppCompatActivity setInsets(); ThemeHelper.enableStatusBarScrollTint(this, mBinding.appbarMain); + mBinding.toolbarMain.setTitle(R.string.app_name); setSupportActionBar(mBinding.toolbarMain); // Set up the FAB. From 57ed5320b59371fd0d3162e7611312cdc80e3b46 Mon Sep 17 00:00:00 2001 From: Robin Kertels Date: Sat, 8 Apr 2023 15:55:50 +0200 Subject: [PATCH 2/2] Android: Fix various issues with the DocumentProvider Fixes copying & deleting folders and copy conflict handling. --- .../dolphinemu/features/DocumentProvider.kt | 80 ++++++------------- 1 file changed, 25 insertions(+), 55 deletions(-) diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/DocumentProvider.kt b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/DocumentProvider.kt index 85fee36a18..b637962177 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/DocumentProvider.kt +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/DocumentProvider.kt @@ -54,7 +54,6 @@ class DocumentProvider : DocumentsProvider() { override fun queryRoots(projection: Array?): Cursor { val result = MatrixCursor(projection ?: DEFAULT_ROOT_PROJECTION) - rootDirectory = rootDirectory ?: DirectoryInitialization.getUserDirectoryPath(context) rootDirectory ?: return result result.newRow().apply { @@ -73,7 +72,6 @@ class DocumentProvider : DocumentsProvider() { override fun queryDocument(documentId: String, projection: Array?): Cursor { val result = MatrixCursor(projection ?: DEFAULT_DOCUMENT_PROJECTION) - rootDirectory = rootDirectory ?: DirectoryInitialization.getUserDirectoryPath(context) rootDirectory ?: return result val file = documentIdToPath(documentId) appendDocument(file, result) @@ -102,7 +100,9 @@ class DocumentProvider : DocumentsProvider() { documentId: String, mode: String, signal: CancellationSignal? - ): ParcelFileDescriptor { + ): ParcelFileDescriptor? { + rootDirectory ?: return null + val file = documentIdToPath(documentId) return ParcelFileDescriptor.open(file, ParcelFileDescriptor.parseMode(mode)) } @@ -111,7 +111,9 @@ class DocumentProvider : DocumentsProvider() { parentDocumentId: String, mimeType: String, displayName: String - ): String { + ): String? { + rootDirectory ?: return null + val folder = documentIdToPath(parentDocumentId) val file = findFileNameForNewFile(File(folder, displayName)) if (mimeType == DocumentsContract.Document.MIME_TYPE_DIR) { @@ -122,52 +124,36 @@ class DocumentProvider : DocumentsProvider() { return pathToDocumentId(file) } - override fun copyDocument(sourceDocumentId: String, targetParentDocumentId: String): String { - val file = documentIdToPath(sourceDocumentId) - val target = documentIdToPath(targetParentDocumentId) - val copy = copyRecursively(file, File(target, file.name)) - return pathToDocumentId(copy) - } + override fun deleteDocument(documentId: String) { + rootDirectory ?: return - override fun removeDocument(documentId: String, parentDocumentId: String) { val file = documentIdToPath(documentId) file.deleteRecursively() } - override fun moveDocument( - sourceDocumentId: String, - sourceParentDocumentId: String, - targetParentDocumentId: String - ): String { - val copy = copyDocument(sourceDocumentId, targetParentDocumentId) - val file = documentIdToPath(sourceDocumentId) - file.delete() - return copy + override fun renameDocument(documentId: String, displayName: String): String? { + rootDirectory ?: return null + + val file = documentIdToPath(documentId) + val dest = findFileNameForNewFile(File(file.parentFile, displayName)) + file.renameTo(dest) + return pathToDocumentId(dest) } - override fun renameDocument(documentId: String, displayName: String): String { - val file = documentIdToPath(documentId) - file.renameTo(findFileNameForNewFile(File(file.parentFile, displayName))) - return pathToDocumentId(file) - } - - override fun isChildDocument(parentDocumentId: String, documentId: String): Boolean { - val file = documentIdToPath(documentId) - val folder = documentIdToPath(parentDocumentId) - return file.relativeToOrNull(folder) != null - } + override fun isChildDocument(parentDocumentId: String, documentId: String): Boolean + = documentId.startsWith(parentDocumentId) private fun appendDocument(file: File, cursor: MatrixCursor) { var flags = 0 - if (file.isDirectory && file.canWrite()) { - flags = DocumentsContract.Document.FLAG_DIR_SUPPORTS_CREATE - } else if (file.canWrite()) { - flags = DocumentsContract.Document.FLAG_SUPPORTS_WRITE + if (file.canWrite()) { + flags = if (file.isDirectory) { + DocumentsContract.Document.FLAG_DIR_SUPPORTS_CREATE + } else { + DocumentsContract.Document.FLAG_SUPPORTS_WRITE + } flags = flags or DocumentsContract.Document.FLAG_SUPPORTS_DELETE - flags = flags or DocumentsContract.Document.FLAG_SUPPORTS_REMOVE - flags = flags or DocumentsContract.Document.FLAG_SUPPORTS_MOVE - flags = flags or DocumentsContract.Document.FLAG_SUPPORTS_COPY flags = flags or DocumentsContract.Document.FLAG_SUPPORTS_RENAME + // The system will handle copy + move for us } val name = if (file == rootDirectory) { @@ -217,22 +203,6 @@ class DocumentProvider : DocumentsProvider() { unusedFile = File("$pathWithoutExtension.$i.$extension") i++ } - return file - } - - private fun copyRecursively(src: File, dst: File): File { - val actualDst = findFileNameForNewFile(dst) - if (src.isDirectory) { - actualDst.mkdirs() - val children = src.listFiles() - if (children !== null) { - for (file in children) { - copyRecursively(file, File(actualDst, file.name)) - } - } - } else { - src.copyTo(actualDst) - } - return actualDst + return unusedFile } }