Android: Catch SecurityException in ContentHandler
This commit is contained in:
parent
713d309386
commit
6df543fbc9
|
@ -21,6 +21,11 @@ public class ContentHandler
|
||||||
{
|
{
|
||||||
return getContentResolver().openFileDescriptor(Uri.parse(uri), mode).detachFd();
|
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,
|
// Some content providers throw IllegalArgumentException for invalid modes,
|
||||||
// despite the documentation saying that invalid modes result in a FileNotFoundException
|
// despite the documentation saying that invalid modes result in a FileNotFoundException
|
||||||
catch (FileNotFoundException | IllegalArgumentException | NullPointerException e)
|
catch (FileNotFoundException | IllegalArgumentException | NullPointerException e)
|
||||||
|
@ -35,6 +40,11 @@ public class ContentHandler
|
||||||
{
|
{
|
||||||
return DocumentsContract.deleteDocument(getContentResolver(), Uri.parse(uri));
|
return DocumentsContract.deleteDocument(getContentResolver(), Uri.parse(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.
|
||||||
|
@ -53,6 +63,10 @@ public class ContentHandler
|
||||||
return cursor.getString(0);
|
return cursor.getString(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
catch (SecurityException e)
|
||||||
|
{
|
||||||
|
Log.error("Tried to get display name of " + uri + " without permission");
|
||||||
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue