summaryrefslogtreecommitdiff
path: root/Source/Android/app/src/main/java
diff options
context:
space:
mode:
authorJosJuice <josjuice@gmail.com>2020-11-08 20:37:56 +0100
committerJosJuice <josjuice@gmail.com>2020-12-20 13:24:54 +0100
commit399ede37a66a161e2379df34501e2b9a172d3457 (patch)
tree432a918b545bf9d3f09929351382b0141664be50 /Source/Android/app/src/main/java
parentae8de3510533d398869cde03d59a5bf8f27f2ca7 (diff)
Android: Catch all exceptions in ContentHandler
Diffstat (limited to 'Source/Android/app/src/main/java')
-rw-r--r--Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/ContentHandler.java52
1 files changed, 38 insertions, 14 deletions
diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/ContentHandler.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/ContentHandler.java
index 5233c9dc59..1ae3a805d3 100644
--- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/ContentHandler.java
+++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/ContentHandler.java
@@ -16,6 +16,21 @@ import org.dolphinemu.dolphinemu.DolphinApplication;
import java.io.FileNotFoundException;
import java.util.List;
+/*
+ We use a lot of "catch (Exception e)" in this class. This is for two reasons:
+
+ 1. We don't want any exceptions to escape to native code, as this leads to nasty crashes
+ that often don't have stack traces that make sense.
+
+ 2. The sheer number of different exceptions, both documented and undocumented. These include:
+ - FileNotFoundException when a file doesn't exist
+ - FileNotFoundException when using an invalid open mode (according to the documentation)
+ - IllegalArgumentException when using an invalid open mode (in practice with FileProvider)
+ - IllegalArgumentException when providing a tree where a document was expected and vice versa
+ - SecurityException when trying to access something the user hasn't granted us permission to
+ - UnsupportedOperationException when a URI specifies a storage provider that doesn't exist
+ */
+
public class ContentHandler
{
@Keep
@@ -28,14 +43,12 @@ public class ContentHandler
catch (SecurityException e)
{
Log.error("Tried to open " + uri + " without permission");
- return -1;
}
- // Some content providers throw IllegalArgumentException for invalid modes,
- // despite the documentation saying that invalid modes result in a FileNotFoundException
- catch (FileNotFoundException | IllegalArgumentException | NullPointerException e)
+ catch (Exception ignored)
{
- return -1;
}
+
+ return -1;
}
@Keep
@@ -45,16 +58,20 @@ public class ContentHandler
{
return DocumentsContract.deleteDocument(getContentResolver(), unmangle(uri));
}
+ catch (FileNotFoundException e)
+ {
+ // Return true because we care about the file not being there, not the actual delete.
+ return true;
+ }
catch (SecurityException e)
{
Log.error("Tried to delete " + uri + " without permission");
- return false;
}
- catch (FileNotFoundException e)
+ catch (Exception ignored)
{
- // Return true because we care about the file not being there, not the actual delete.
- return true;
}
+
+ return false;
}
public static boolean exists(@NonNull String uri)
@@ -72,7 +89,7 @@ public class ContentHandler
{
Log.error("Tried to check if " + uri + " exists without permission");
}
- catch (FileNotFoundException ignored)
+ catch (Exception ignored)
{
}
@@ -104,7 +121,7 @@ public class ContentHandler
{
Log.error("Tried to get metadata for " + uri + " without permission");
}
- catch (FileNotFoundException ignored)
+ catch (Exception ignored)
{
}
@@ -118,10 +135,11 @@ public class ContentHandler
{
return getDisplayName(unmangle(uri));
}
- catch (FileNotFoundException e)
+ catch (Exception ignored)
{
- return null;
}
+
+ return null;
}
@Nullable
@@ -140,6 +158,9 @@ public class ContentHandler
{
Log.error("Tried to get display name of " + uri + " without permission");
}
+ catch (Exception ignored)
+ {
+ }
return null;
}
@@ -172,7 +193,7 @@ public class ContentHandler
{
Log.error("Tried to get children of " + uri + " without permission");
}
- catch (FileNotFoundException ignored)
+ catch (Exception ignored)
{
}
@@ -209,6 +230,9 @@ public class ContentHandler
{
Log.error("Tried to get child " + childName + " of " + parentUri + " without permission");
}
+ catch (Exception ignored)
+ {
+ }
throw new FileNotFoundException(parentUri + "/" + childName);
}