mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-02-14 00:09:24 +01:00
Android: Catch all exceptions in ContentHandler
This commit is contained in:
parent
ae8de35105
commit
399ede37a6
@ -16,6 +16,21 @@ import org.dolphinemu.dolphinemu.DolphinApplication;
|
|||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.util.List;
|
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
|
public class ContentHandler
|
||||||
{
|
{
|
||||||
@Keep
|
@Keep
|
||||||
@ -28,14 +43,12 @@ public class ContentHandler
|
|||||||
catch (SecurityException e)
|
catch (SecurityException e)
|
||||||
{
|
{
|
||||||
Log.error("Tried to open " + uri + " without permission");
|
Log.error("Tried to open " + uri + " without permission");
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
// Some content providers throw IllegalArgumentException for invalid modes,
|
catch (Exception ignored)
|
||||||
// despite the documentation saying that invalid modes result in a FileNotFoundException
|
|
||||||
catch (FileNotFoundException | IllegalArgumentException | NullPointerException e)
|
|
||||||
{
|
{
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Keep
|
@Keep
|
||||||
@ -45,16 +58,20 @@ public class ContentHandler
|
|||||||
{
|
{
|
||||||
return DocumentsContract.deleteDocument(getContentResolver(), unmangle(uri));
|
return DocumentsContract.deleteDocument(getContentResolver(), unmangle(uri));
|
||||||
}
|
}
|
||||||
catch (SecurityException e)
|
|
||||||
{
|
|
||||||
Log.error("Tried to delete " + uri + " without permission");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
catch (FileNotFoundException e)
|
catch (FileNotFoundException e)
|
||||||
{
|
{
|
||||||
// Return true because we care about the file not being there, not the actual delete.
|
// Return true because we care about the file not being there, not the actual delete.
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
catch (SecurityException e)
|
||||||
|
{
|
||||||
|
Log.error("Tried to delete " + uri + " without permission");
|
||||||
|
}
|
||||||
|
catch (Exception ignored)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean exists(@NonNull String uri)
|
public static boolean exists(@NonNull String uri)
|
||||||
@ -72,7 +89,7 @@ public class ContentHandler
|
|||||||
{
|
{
|
||||||
Log.error("Tried to check if " + uri + " exists without permission");
|
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");
|
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));
|
return getDisplayName(unmangle(uri));
|
||||||
}
|
}
|
||||||
catch (FileNotFoundException e)
|
catch (Exception ignored)
|
||||||
{
|
{
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@ -140,6 +158,9 @@ public class ContentHandler
|
|||||||
{
|
{
|
||||||
Log.error("Tried to get display name of " + uri + " without permission");
|
Log.error("Tried to get display name of " + uri + " without permission");
|
||||||
}
|
}
|
||||||
|
catch (Exception ignored)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -172,7 +193,7 @@ public class ContentHandler
|
|||||||
{
|
{
|
||||||
Log.error("Tried to get children of " + uri + " without permission");
|
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");
|
Log.error("Tried to get child " + childName + " of " + parentUri + " without permission");
|
||||||
}
|
}
|
||||||
|
catch (Exception ignored)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
throw new FileNotFoundException(parentUri + "/" + childName);
|
throw new FileNotFoundException(parentUri + "/" + childName);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user