Close ParcelFileDescriptor after improting blacklist

This commit is contained in:
xynngh 2020-10-23 14:06:05 +04:00
parent 787ca3c94a
commit 29f7d7b5b5
1 changed files with 20 additions and 12 deletions

View File

@ -249,19 +249,27 @@ public class BlacklistActivity extends AppCompatActivity {
ParcelFileDescriptor pfd = null; ParcelFileDescriptor pfd = null;
try { try {
pfd = getContentResolver().openFileDescriptor(data.getData(), "r"); try {
} catch (FileNotFoundException e) { pfd = getContentResolver().openFileDescriptor(data.getData(), "r");
error = true; } catch (FileNotFoundException e) {
LOG.warn("onActivityResult() get file for import result", e);
}
if (pfd != null) {
if (new BlacklistImporterExporter().importBlacklist(
YacbHolder.getBlacklistDao(), YacbHolder.getBlacklistService(),
pfd.getFileDescriptor())) {
Toast.makeText(this, R.string.done, Toast.LENGTH_SHORT).show();
} else {
error = true; error = true;
LOG.warn("onActivityResult() get file for import result", e);
}
if (pfd != null) {
if (new BlacklistImporterExporter().importBlacklist(
YacbHolder.getBlacklistDao(), YacbHolder.getBlacklistService(),
pfd.getFileDescriptor())) {
Toast.makeText(this, R.string.done, Toast.LENGTH_SHORT).show();
} else {
error = true;
}
}
} finally {
if (pfd != null) {
try {
pfd.close();
} catch (IOException ignored) {}
} }
} }