aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/pixart/messenger
diff options
context:
space:
mode:
authorChristian Schneppe <christian@pix-art.de>2018-07-09 21:15:56 +0200
committerChristian Schneppe <christian@pix-art.de>2018-07-09 21:15:56 +0200
commit71afe8ed86449aeb3795cef48fe815fd23e388d4 (patch)
tree32f660fe5bde6ef5e3aefe5a2f9cee557ed2dd81 /src/main/java/de/pixart/messenger
parent3ac56bcbdb27be63275c00a60eef32cdd985c827 (diff)
restart file observer when permisson are granted
Diffstat (limited to 'src/main/java/de/pixart/messenger')
-rw-r--r--src/main/java/de/pixart/messenger/services/XmppConnectionService.java11
-rw-r--r--src/main/java/de/pixart/messenger/ui/ConversationFragment.java14
-rw-r--r--src/main/java/de/pixart/messenger/utils/ConversationsFileObserver.java5
3 files changed, 29 insertions, 1 deletions
diff --git a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java
index cca4d5fc2..f45a5ac8e 100644
--- a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java
+++ b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java
@@ -31,6 +31,7 @@ import android.security.KeyChain;
import android.support.annotation.BoolRes;
import android.support.annotation.IntegerRes;
import android.support.v4.app.RemoteInput;
+import android.support.v4.content.ContextCompat;
import android.text.TextUtils;
import android.util.DisplayMetrics;
import android.util.Log;
@@ -1102,7 +1103,10 @@ public class XmppConnectionService extends Service {
restoreFromDatabase();
getContentResolver().registerContentObserver(ContactsContract.Contacts.CONTENT_URI, true, contactObserver);
- new Thread(fileObserver::startWatching).start();
+ if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M || ContextCompat.checkSelfPermission(this, android.Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
+ Log.d(Config.LOGTAG, "starting file observer");
+ new Thread(fileObserver::startWatching).start();
+ }
if (Config.supportOpenPgp()) {
this.pgpServiceConnection = new OpenPgpServiceConnection(this, "org.sufficientlysecure.keychain", new OpenPgpServiceConnection.OnBound() {
@Override
@@ -1161,6 +1165,11 @@ public class XmppConnectionService extends Service {
CancelAutomaticExport(true);
}
+ public void restartFileObserver() {
+ Log.d(Config.LOGTAG, "restarting file observer");
+ new Thread(fileObserver::restartWatching).start();
+ }
+
public void toggleScreenEventReceiver() {
if (awayWhenScreenOff() && !manuallyChangePresence()) {
final IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_ON);
diff --git a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java
index fa2ba5327..2458e4967 100644
--- a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java
+++ b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java
@@ -566,6 +566,15 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
return true;
}
+ private static boolean writeGranted(int[] grantResults, String[] permission) {
+ for (int i = 0; i < grantResults.length; ++i) {
+ if (Manifest.permission.WRITE_EXTERNAL_STORAGE.equals(permission[i])) {
+ return grantResults[i] == PackageManager.PERMISSION_GRANTED;
+ }
+ }
+ return false;
+ }
+
private static String getFirstDenied(int[] grantResults, String[] permissions) {
for (int i = 0; i < grantResults.length; ++i) {
if (grantResults[i] == PackageManager.PERMISSION_DENIED) {
@@ -1618,6 +1627,11 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
Toast.makeText(getActivity(), res, Toast.LENGTH_SHORT).show();
}
}
+ if (writeGranted(grantResults, permissions)) {
+ if (activity != null && activity.xmppConnectionService != null) {
+ activity.xmppConnectionService.restartFileObserver();
+ }
+ }
}
public void startDownloadable(Message message) {
diff --git a/src/main/java/de/pixart/messenger/utils/ConversationsFileObserver.java b/src/main/java/de/pixart/messenger/utils/ConversationsFileObserver.java
index 72a01a13c..4e275df3f 100644
--- a/src/main/java/de/pixart/messenger/utils/ConversationsFileObserver.java
+++ b/src/main/java/de/pixart/messenger/utils/ConversationsFileObserver.java
@@ -80,6 +80,11 @@ public abstract class ConversationsFileObserver {
abstract public void onEvent(int event, String path);
+ public void restartWatching() {
+ stopWatching();
+ startWatching();
+ }
+
private class SingleFileObserver extends FileObserver {
private final String path;