Handle denied storage permission, use ContentResolver.SCHEME_FILE constant
This commit is contained in:
@@ -29,6 +29,7 @@ import android.Manifest;
|
|||||||
import android.annotation.TargetApi;
|
import android.annotation.TargetApi;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.ClipDescription;
|
import android.content.ClipDescription;
|
||||||
|
import android.content.ContentResolver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.pm.LabeledIntent;
|
import android.content.pm.LabeledIntent;
|
||||||
@@ -635,7 +636,7 @@ public class DecryptListFragment
|
|||||||
* see https://commonsware.com/blog/2015/10/07/runtime-permissions-files-action-send.html
|
* see https://commonsware.com/blog/2015/10/07/runtime-permissions-files-action-send.html
|
||||||
*/
|
*/
|
||||||
private boolean checkAndRequestReadPermission(Activity activity, final Uri uri) {
|
private boolean checkAndRequestReadPermission(Activity activity, final Uri uri) {
|
||||||
if ( ! "file".equals(uri.getScheme())) {
|
if ( ! ContentResolver.SCHEME_FILE.equals(uri.getScheme())) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -676,7 +677,7 @@ public class DecryptListFragment
|
|||||||
Iterator<Uri> it = mCancelledInputUris.iterator();
|
Iterator<Uri> it = mCancelledInputUris.iterator();
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
Uri uri = it.next();
|
Uri uri = it.next();
|
||||||
if ( ! "file".equals(uri.getScheme())) {
|
if ( ! ContentResolver.SCHEME_FILE.equals(uri.getScheme())) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
it.remove();
|
it.remove();
|
||||||
@@ -694,7 +695,7 @@ public class DecryptListFragment
|
|||||||
Iterator<Uri> it = mPendingInputUris.iterator();
|
Iterator<Uri> it = mPendingInputUris.iterator();
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
Uri uri = it.next();
|
Uri uri = it.next();
|
||||||
if ( ! "file".equals(uri.getScheme())) {
|
if ( ! ContentResolver.SCHEME_FILE.equals(uri.getScheme())) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
it.remove();
|
it.remove();
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ import android.annotation.TargetApi;
|
|||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.ClipData;
|
import android.content.ClipData;
|
||||||
import android.content.ClipboardManager;
|
import android.content.ClipboardManager;
|
||||||
|
import android.content.ContentResolver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
@@ -55,6 +56,7 @@ import android.view.ViewGroup;
|
|||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
import org.sufficientlysecure.keychain.Constants;
|
import org.sufficientlysecure.keychain.Constants;
|
||||||
import org.sufficientlysecure.keychain.R;
|
import org.sufficientlysecure.keychain.R;
|
||||||
@@ -267,7 +269,7 @@ public class EncryptFilesFragment
|
|||||||
* see https://commonsware.com/blog/2015/10/07/runtime-permissions-files-action-send.html
|
* see https://commonsware.com/blog/2015/10/07/runtime-permissions-files-action-send.html
|
||||||
*/
|
*/
|
||||||
private boolean checkAndRequestReadPermission(final Uri uri) {
|
private boolean checkAndRequestReadPermission(final Uri uri) {
|
||||||
if ( ! "file".equals(uri.getScheme())) {
|
if ( ! ContentResolver.SCHEME_FILE.equals(uri.getScheme())) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -305,8 +307,9 @@ public class EncryptFilesFragment
|
|||||||
// permission granted -> restart processing uris
|
// permission granted -> restart processing uris
|
||||||
processPendingInputUris();
|
processPendingInputUris();
|
||||||
} else {
|
} else {
|
||||||
// permission denied ->
|
Toast.makeText(getActivity(), R.string.error_denied_storage_permission, Toast.LENGTH_LONG).show();
|
||||||
|
getActivity().setResult(Activity.RESULT_CANCELED);
|
||||||
|
getActivity().finish();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -161,7 +161,7 @@ public class FileHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static long getFileSize(Context context, Uri uri, long def) {
|
public static long getFileSize(Context context, Uri uri, long def) {
|
||||||
if ("file".equals(uri.getScheme())) {
|
if (ContentResolver.SCHEME_FILE.equals(uri.getScheme())) {
|
||||||
long size = new File(uri.getPath()).length();
|
long size = new File(uri.getPath()).length();
|
||||||
if (size == 0) {
|
if (size == 0) {
|
||||||
size = def;
|
size = def;
|
||||||
@@ -293,7 +293,7 @@ public class FileHelper {
|
|||||||
}
|
}
|
||||||
out.close();
|
out.close();
|
||||||
|
|
||||||
if ("file".equals(uri.getScheme())) {
|
if (ContentResolver.SCHEME_FILE.equals(uri.getScheme())) {
|
||||||
return new File(uri.getPath()).delete() ? 1 : 0;
|
return new File(uri.getPath()).delete() ? 1 : 0;
|
||||||
} else {
|
} else {
|
||||||
return resolver.delete(uri, null, null);
|
return resolver.delete(uri, null, null);
|
||||||
|
|||||||
@@ -1,3 +1,20 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2015 Dominik Schürmann <dominik@dominikschuermann.de>
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
package org.sufficientlysecure.keychain.util;
|
package org.sufficientlysecure.keychain.util;
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -375,6 +375,7 @@
|
|||||||
<string name="error_nothing_import_selected">"No keys selected for import!"</string>
|
<string name="error_nothing_import_selected">"No keys selected for import!"</string>
|
||||||
<string name="error_contacts_key_id_missing">"Retrieving the key ID from contacts failed!"</string>
|
<string name="error_contacts_key_id_missing">"Retrieving the key ID from contacts failed!"</string>
|
||||||
<string name="error_generic_report_bug">"A generic error occurred, please create a new bug report for OpenKeychain."</string>
|
<string name="error_generic_report_bug">"A generic error occurred, please create a new bug report for OpenKeychain."</string>
|
||||||
|
<string name="error_denied_storage_permission">"Can not read files from storage because access has been denied!"</string>
|
||||||
|
|
||||||
<!-- results shown after decryption/verification -->
|
<!-- results shown after decryption/verification -->
|
||||||
<string name="decrypt_result_no_signature">"Not Signed"</string>
|
<string name="decrypt_result_no_signature">"Not Signed"</string>
|
||||||
|
|||||||
Reference in New Issue
Block a user