Merge branch 'master' of https://github.com/Fenisu/Conversations into Fenisu-master

This commit is contained in:
Daniel Gultsch 2016-12-02 11:25:14 +01:00
commit 6b0242523b
12 changed files with 150 additions and 24 deletions

View file

@ -97,6 +97,8 @@ public final class Config {
public static final boolean X509_VERIFICATION = false; //use x509 certificates to verify OMEMO keys public static final boolean X509_VERIFICATION = false; //use x509 certificates to verify OMEMO keys
public static final boolean ONLY_INTERNAL_STORAGE = true; //use internal storage instead of sdcard to save attachments
public static final boolean IGNORE_ID_REWRITE_IN_MUC = true; public static final boolean IGNORE_ID_REWRITE_IN_MUC = true;
public static final boolean PARSE_REAL_JID_FROM_MUC_MAM = false; //dangerous if server doesnt filter public static final boolean PARSE_REAL_JID_FROM_MUC_MAM = false; //dangerous if server doesnt filter

View file

@ -152,15 +152,27 @@ public class FileBackend {
return true; return true;
} }
public static String getConversationsFileDirectory() { public String getConversationsFileDirectory() {
return Environment.getExternalStorageDirectory().getAbsolutePath()+"/Conversations/"; if (Config.ONLY_INTERNAL_STORAGE) {
return mXmppConnectionService.getFilesDir().getAbsolutePath() + "/Files/";
} else {
return Environment.getExternalStorageDirectory().getAbsolutePath() + "/Conversations/";
}
} }
public static String getConversationsImageDirectory() { public String getConversationsImageDirectory() {
if (Config.ONLY_INTERNAL_STORAGE) {
return mXmppConnectionService.getFilesDir().getAbsolutePath()+"/Pictures/";
} else {
return Environment.getExternalStoragePublicDirectory( return Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_PICTURES).getAbsolutePath() Environment.DIRECTORY_PICTURES).getAbsolutePath()
+ "/Conversations/"; + "/Conversations/";
} }
}
public static String getConversationsLogsDirectory() {
return Environment.getExternalStorageDirectory().getAbsolutePath()+"/Conversations/";
}
public Bitmap resize(Bitmap originalBitmap, int size) { public Bitmap resize(Bitmap originalBitmap, int size) {
int w = originalBitmap.getWidth(); int w = originalBitmap.getWidth();
@ -451,9 +463,14 @@ public class FileBackend {
} }
public Uri getTakePhotoUri() { public Uri getTakePhotoUri() {
File file = new File(getTakePhotoPath()+"IMG_" + this.IMAGE_DATE_FORMAT.format(new Date()) + ".jpg"); File file;
if (Config.ONLY_INTERNAL_STORAGE) {
file = new File(mXmppConnectionService.getCacheDir().getAbsolutePath(), "Camera/IMG_" + this.IMAGE_DATE_FORMAT.format(new Date()) + ".jpg");
} else {
file = new File(getTakePhotoPath() + "IMG_" + this.IMAGE_DATE_FORMAT.format(new Date()) + ".jpg");
}
file.getParentFile().mkdirs(); file.getParentFile().mkdirs();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N || Config.ONLY_INTERNAL_STORAGE) {
return getUriForFile(mXmppConnectionService,file); return getUriForFile(mXmppConnectionService,file);
} else { } else {
return Uri.fromFile(file); return Uri.fromFile(file);
@ -466,7 +483,7 @@ public class FileBackend {
} }
public static Uri getIndexableTakePhotoUri(Uri original) { public static Uri getIndexableTakePhotoUri(Uri original) {
if ("file".equals(original.getScheme())) { if (Config.ONLY_INTERNAL_STORAGE || "file".equals(original.getScheme())) {
return original; return original;
} else { } else {
List<String> segments = original.getPathSegments(); List<String> segments = original.getPathSegments();
@ -712,8 +729,7 @@ public class FileBackend {
} }
public Uri getJingleFileUri(Message message) { public Uri getJingleFileUri(Message message) {
File file = getFile(message); return getUriForFile(mXmppConnectionService,getFile(message));
return Uri.parse("file://" + file.getAbsolutePath());
} }
public void updateFileParams(Message message) { public void updateFileParams(Message message) {

View file

@ -55,7 +55,7 @@ public class AbstractConnectionManager {
} }
public boolean hasStoragePermission() { public boolean hasStoragePermission() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (!Config.ONLY_INTERNAL_STORAGE && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
return mXmppConnectionService.checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED; return mXmppConnectionService.checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED;
} else { } else {
return true; return true;

View file

@ -26,7 +26,7 @@ import eu.siacs.conversations.xmpp.jid.Jid;
public class ExportLogsService extends Service { public class ExportLogsService extends Service {
private static final SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"); private static final SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
private static final String DIRECTORY_STRING_FORMAT = FileBackend.getConversationsFileDirectory() + "/logs/%s"; private static final String DIRECTORY_STRING_FORMAT = FileBackend.getConversationsLogsDirectory() + "/logs/%s";
private static final String MESSAGE_STRING_FORMAT = "(%s) %s: %s\n"; private static final String MESSAGE_STRING_FORMAT = "(%s) %s: %s\n";
private static final int NOTIFICATION_ID = 1; private static final int NOTIFICATION_ID = 1;
private static AtomicBoolean running = new AtomicBoolean(false); private static AtomicBoolean running = new AtomicBoolean(false);

View file

@ -497,6 +497,7 @@ public class ConversationActivity extends XmppActivity
case ATTACHMENT_CHOICE_TAKE_PHOTO: case ATTACHMENT_CHOICE_TAKE_PHOTO:
Uri uri = xmppConnectionService.getFileBackend().getTakePhotoUri(); Uri uri = xmppConnectionService.getFileBackend().getTakePhotoUri();
intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION); intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
intent.setAction(MediaStore.ACTION_IMAGE_CAPTURE); intent.setAction(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, uri); intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
mPendingImageUris.clear(); mPendingImageUris.clear();
@ -551,7 +552,7 @@ public class ConversationActivity extends XmppActivity
public void attachFile(final int attachmentChoice) { public void attachFile(final int attachmentChoice) {
if (attachmentChoice != ATTACHMENT_CHOICE_LOCATION) { if (attachmentChoice != ATTACHMENT_CHOICE_LOCATION) {
if (!hasStoragePermission(attachmentChoice)) { if (!Config.ONLY_INTERNAL_STORAGE && !hasStoragePermission(attachmentChoice)) {
return; return;
} }
} }
@ -648,7 +649,7 @@ public class ConversationActivity extends XmppActivity
} }
public void startDownloadable(Message message) { public void startDownloadable(Message message) {
if (!hasStoragePermission(ConversationActivity.REQUEST_START_DOWNLOAD)) { if (!Config.ONLY_INTERNAL_STORAGE && !hasStoragePermission(ConversationActivity.REQUEST_START_DOWNLOAD)) {
this.mPendingDownloadableMessage = message; this.mPendingDownloadableMessage = message;
return; return;
} }
@ -1417,9 +1418,11 @@ public class ConversationActivity extends XmppActivity
attachImageToConversation(getSelectedConversation(), uri); attachImageToConversation(getSelectedConversation(), uri);
mPendingImageUris.clear(); mPendingImageUris.clear();
} }
if (!Config.ONLY_INTERNAL_STORAGE) {
Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE); Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
intent.setData(uri); intent.setData(uri);
sendBroadcast(intent); sendBroadcast(intent);
}
} else { } else {
mPendingImageUris.clear(); mPendingImageUris.clear();
} }

View file

@ -654,8 +654,7 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
shareIntent.setType("text/plain"); shareIntent.setType("text/plain");
} else { } else {
shareIntent.putExtra(Intent.EXTRA_STREAM, shareIntent.putExtra(Intent.EXTRA_STREAM,
activity.xmppConnectionService.getFileBackend() activity.xmppConnectionService.getFileBackend().getJingleFileUri(message));
.getJingleFileUri(message));
shareIntent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); shareIntent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
String mime = message.getMimeType(); String mime = message.getMimeType();
if (mime == null) { if (mime == null) {

View file

@ -7,6 +7,7 @@ import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener; import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.preference.ListPreference; import android.preference.ListPreference;
@ -14,8 +15,10 @@ import android.preference.Preference;
import android.preference.PreferenceCategory; import android.preference.PreferenceCategory;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.preference.PreferenceScreen; import android.preference.PreferenceScreen;
import android.util.Log;
import android.widget.Toast; import android.widget.Toast;
import java.io.File;
import java.security.KeyStoreException; import java.security.KeyStoreException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
@ -162,6 +165,26 @@ public class SettingsActivity extends XmppActivity implements
} }
}); });
if (Config.ONLY_INTERNAL_STORAGE) {
final Preference cleanCachePreference = mSettingsFragment.findPreference("clean_cache");
cleanCachePreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
cleanCache();
return true;
}
});
final Preference cleanPrivateStoragePreference = mSettingsFragment.findPreference("clean_private_storage");
cleanPrivateStoragePreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
cleanPrivateStorage();
return true;
}
});
}
final Preference deleteOmemoPreference = mSettingsFragment.findPreference("delete_omemo_identities"); final Preference deleteOmemoPreference = mSettingsFragment.findPreference("delete_omemo_identities");
deleteOmemoPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { deleteOmemoPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override @Override
@ -172,6 +195,57 @@ public class SettingsActivity extends XmppActivity implements
}); });
} }
private void cleanCache() {
Intent intent = new Intent(android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
intent.setData(Uri.parse("package:" + getPackageName()));
startActivity(intent);
}
private void cleanPrivateStorage() {
cleanPrivatePictures();
cleanPrivateFiles();
}
private void cleanPrivatePictures() {
try {
File dir = new File(getFilesDir().getAbsolutePath(), "/Pictures/");
File[] array = dir.listFiles();
if (array != null) {
for (int b = 0; b < array.length; b++) {
String name = array[b].getName().toLowerCase();
if (name.equals(".nomedia")) {
continue;
}
if (array[b].isFile()) {
array[b].delete();
}
}
}
} catch (Throwable e) {
Log.e("CleanCache", e.toString());
}
}
private void cleanPrivateFiles() {
try {
File dir = new File(getFilesDir().getAbsolutePath(), "/Files/");
File[] array = dir.listFiles();
if (array != null) {
for (int b = 0; b < array.length; b++) {
String name = array[b].getName().toLowerCase();
if (name.equals(".nomedia")) {
continue;
}
if (array[b].isFile()) {
array[b].delete();
}
}
}
} catch (Throwable e) {
Log.e("CleanCache", e.toString());
}
}
private void deleteOmemoIdentities() { private void deleteOmemoIdentities() {
AlertDialog.Builder builder = new AlertDialog.Builder(this); AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(R.string.pref_delete_omemo_identities); builder.setTitle(R.string.pref_delete_omemo_identities);

View file

@ -3,6 +3,7 @@ package eu.siacs.conversations.ui;
import android.app.Dialog; import android.app.Dialog;
import android.os.Bundle; import android.os.Bundle;
import android.preference.Preference; import android.preference.Preference;
import android.preference.PreferenceCategory;
import android.preference.PreferenceFragment; import android.preference.PreferenceFragment;
import android.preference.PreferenceScreen; import android.preference.PreferenceScreen;
import android.view.View; import android.view.View;
@ -11,6 +12,7 @@ import android.view.ViewParent;
import android.widget.FrameLayout; import android.widget.FrameLayout;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import eu.siacs.conversations.Config;
import eu.siacs.conversations.R; import eu.siacs.conversations.R;
public class SettingsFragment extends PreferenceFragment { public class SettingsFragment extends PreferenceFragment {
@ -52,6 +54,16 @@ public class SettingsFragment extends PreferenceFragment {
// Load the preferences from an XML resource // Load the preferences from an XML resource
addPreferencesFromResource(R.xml.preferences); addPreferencesFromResource(R.xml.preferences);
// Remove from standard preferences if the flag ONLY_INTERNAL_STORAGE is not true
if (!Config.ONLY_INTERNAL_STORAGE) {
PreferenceCategory mCategory = (PreferenceCategory) findPreference("security_options");
Preference mPref1 = findPreference("clean_cache");
Preference mPref2 = findPreference("clean_private_storage");
mCategory.removePreference(mPref1);
mCategory.removePreference(mPref2);
}
} }
@Override @Override

View file

@ -709,12 +709,16 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie
mime = "*/*"; mime = "*/*";
} }
Uri uri; Uri uri;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N || Config.ONLY_INTERNAL_STORAGE) {
try { try {
uri = FileBackend.getUriForFile(activity, file); uri = FileBackend.getUriForFile(activity, file);
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
Toast.makeText(activity,activity.getString(R.string.no_permission_to_access_x,file.getAbsolutePath()), Toast.LENGTH_SHORT).show(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
Toast.makeText(activity, activity.getString(R.string.no_permission_to_access_x, file.getAbsolutePath()), Toast.LENGTH_SHORT).show();
return; return;
} else {
uri = Uri.fromFile(file);
}
} }
openIntent.setDataAndType(uri, mime); openIntent.setDataAndType(uri, mime);
openIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); openIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);

View file

@ -715,4 +715,8 @@
<string name="blindly_trusted_omemo_keys">Blindly trusted OMEMO keys</string> <string name="blindly_trusted_omemo_keys">Blindly trusted OMEMO keys</string>
<string name="not_trusted">Untrusted</string> <string name="not_trusted">Untrusted</string>
<string name="invalid_barcode">Invalid 2D barcode</string> <string name="invalid_barcode">Invalid 2D barcode</string>
<string name="pref_clean_cache_summary">Clean cache folder (used by Camera Application)</string>
<string name="pref_clean_cache">Clean cache</string>
<string name="pref_clean_private_storage">Clean private storage</string>
<string name="pref_clean_private_storage_summary">Clean private storage where files are kept (They can be re-downloaded from the server)</string>
</resources> </resources>

View file

@ -1,4 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<paths> <paths>
<external-path name="external" path="/"/> <external-path name="external" path="/"/>
<files-path path="Pictures/" name="pics" />
<files-path path="Files/" name="files" />
<cache-path path="Camera/" name="cam" />
</paths> </paths>

View file

@ -163,7 +163,8 @@
android:key="expert" android:key="expert"
android:summary="@string/pref_expert_options_summary" android:summary="@string/pref_expert_options_summary"
android:title="@string/pref_expert_options"> android:title="@string/pref_expert_options">
<PreferenceCategory android:title="@string/pref_security_settings"> <PreferenceCategory android:title="@string/pref_security_settings"
android:key="security_options">
<CheckBoxPreference <CheckBoxPreference
android:defaultValue="true" android:defaultValue="true"
android:key="btbv" android:key="btbv"
@ -188,6 +189,14 @@
android:key="allow_message_correction" android:key="allow_message_correction"
android:title="@string/pref_allow_message_correction" android:title="@string/pref_allow_message_correction"
android:summary="@string/pref_allow_message_correction_summary"/> android:summary="@string/pref_allow_message_correction_summary"/>
<Preference
android:key="clean_cache"
android:summary="@string/pref_clean_cache_summary"
android:title="@string/pref_clean_cache"/>
<Preference
android:key="clean_private_storage"
android:summary="@string/pref_clean_private_storage_summary"
android:title="@string/pref_clean_private_storage"/>
<Preference <Preference
android:key="delete_omemo_identities" android:key="delete_omemo_identities"
android:title="@string/pref_delete_omemo_identities" android:title="@string/pref_delete_omemo_identities"