aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Gultsch <daniel@gultsch.de>2016-02-27 11:25:56 +0100
committerDaniel Gultsch <daniel@gultsch.de>2016-02-27 11:25:56 +0100
commit3cf21e2d3712f40659afbf44296c8ea571d9f7a3 (patch)
tree0998789ed09c18f7859df518fc85deaa2583a47d
parentc393e6089177f31683c4cecfdb359802de1b5e0c (diff)
parente1a2f248afcc9fd884015da78decd5c0c8c83552 (diff)
Merge pull request #1721 from fiaxh/export_logs_storage_permission
Request WRITE_EXTERNAL_STORAGE for ExportLogsPreference in >= M
-rw-r--r--src/main/java/eu/siacs/conversations/services/ExportLogsService.java2
-rw-r--r--src/main/java/eu/siacs/conversations/ui/ExportLogsPreference.java7
-rw-r--r--src/main/java/eu/siacs/conversations/ui/SettingsActivity.java26
3 files changed, 34 insertions, 1 deletions
diff --git a/src/main/java/eu/siacs/conversations/services/ExportLogsService.java b/src/main/java/eu/siacs/conversations/services/ExportLogsService.java
index 76983a90..87e65931 100644
--- a/src/main/java/eu/siacs/conversations/services/ExportLogsService.java
+++ b/src/main/java/eu/siacs/conversations/services/ExportLogsService.java
@@ -45,9 +45,9 @@ public class ExportLogsService extends Service {
new Thread(new Runnable() {
@Override
public void run() {
- running.set(false);
export();
stopForeground(true);
+ running.set(false);
stopSelf();
}
}).start();
diff --git a/src/main/java/eu/siacs/conversations/ui/ExportLogsPreference.java b/src/main/java/eu/siacs/conversations/ui/ExportLogsPreference.java
index a4e178bd..bedb4172 100644
--- a/src/main/java/eu/siacs/conversations/ui/ExportLogsPreference.java
+++ b/src/main/java/eu/siacs/conversations/ui/ExportLogsPreference.java
@@ -1,7 +1,10 @@
package eu.siacs.conversations.ui;
+import android.Manifest;
import android.content.Context;
import android.content.Intent;
+import android.content.pm.PackageManager;
+import android.os.Build;
import android.preference.Preference;
import android.util.AttributeSet;
@@ -22,6 +25,10 @@ public class ExportLogsPreference extends Preference {
}
protected void onClick() {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M
+ && getContext().checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
+ return;
+ }
final Intent startIntent = new Intent(getContext(), ExportLogsService.class);
getContext().startService(startIntent);
super.onClick();
diff --git a/src/main/java/eu/siacs/conversations/ui/SettingsActivity.java b/src/main/java/eu/siacs/conversations/ui/SettingsActivity.java
index 07c328b9..c028d0d6 100644
--- a/src/main/java/eu/siacs/conversations/ui/SettingsActivity.java
+++ b/src/main/java/eu/siacs/conversations/ui/SettingsActivity.java
@@ -3,8 +3,10 @@ package eu.siacs.conversations.ui;
import android.app.AlertDialog;
import android.app.FragmentManager;
import android.content.DialogInterface;
+import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
+import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Bundle;
import android.preference.ListPreference;
@@ -25,10 +27,13 @@ import de.duenndns.ssl.MemorizingTrustManager;
import eu.siacs.conversations.Config;
import eu.siacs.conversations.R;
import eu.siacs.conversations.entities.Account;
+import eu.siacs.conversations.services.ExportLogsService;
import eu.siacs.conversations.xmpp.XmppConnection;
public class SettingsActivity extends XmppActivity implements
OnSharedPreferenceChangeListener {
+
+ public static final int REQUEST_WRITE_LOGS = 0xbf8701;
private SettingsFragment mSettingsFragment;
@Override
@@ -130,6 +135,15 @@ public class SettingsActivity extends XmppActivity implements
return true;
}
});
+
+ final Preference exportLogsPreference = mSettingsFragment.findPreference("export_logs");
+ exportLogsPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
+ @Override
+ public boolean onPreferenceClick(Preference preference) {
+ hasStoragePermission(REQUEST_WRITE_LOGS);
+ return true;
+ }
+ });
}
@Override
@@ -179,6 +193,18 @@ public class SettingsActivity extends XmppActivity implements
}
+ @Override
+ public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
+ if (grantResults.length > 0)
+ if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
+ if (requestCode == REQUEST_WRITE_LOGS) {
+ getApplicationContext().startService(new Intent(getApplicationContext(), ExportLogsService.class));
+ }
+ } else {
+ Toast.makeText(this, R.string.no_storage_permission, Toast.LENGTH_SHORT).show();
+ }
+ }
+
private void displayToast(final String msg) {
runOnUiThread(new Runnable() {
@Override