Android: Catch SecurityException in ContentHandler

This commit is contained in:
JosJuice 2020-11-08 12:37:32 +01:00
parent 713d309386
commit 6df543fbc9
1 changed files with 14 additions and 0 deletions

View File

@ -21,6 +21,11 @@ public class ContentHandler
{
return getContentResolver().openFileDescriptor(Uri.parse(uri), mode).detachFd();
}
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)
@ -35,6 +40,11 @@ public class ContentHandler
{
return DocumentsContract.deleteDocument(getContentResolver(), Uri.parse(uri));
}
catch (SecurityException e)
{
Log.error("Tried to delete " + uri + " without permission");
return false;
}
catch (FileNotFoundException e)
{
// Return true because we care about the file not being there, not the actual delete.
@ -53,6 +63,10 @@ public class ContentHandler
return cursor.getString(0);
}
}
catch (SecurityException e)
{
Log.error("Tried to get display name of " + uri + " without permission");
}
return null;
}