mirror of https://github.com/NekoX-Dev/NekoX.git
save some files to private directory
...for better privacy?
This commit is contained in:
parent
23761f6865
commit
829026840a
|
@ -587,6 +587,12 @@ public class AndroidUtilities {
|
|||
if (pathString.matches(Pattern.quote(new File(ApplicationLoader.applicationContext.getCacheDir(), "voip_logs").getAbsolutePath()) + "/\\d+\\.log")) {
|
||||
return false;
|
||||
}
|
||||
if (NekoConfig.saveCacheToPrivateDirectory && pathString.startsWith(new File(ApplicationLoader.applicationContext.getCacheDir(), "sdcard").getAbsolutePath())) {
|
||||
return false;
|
||||
}
|
||||
if (NekoConfig.saveCacheToPrivateDirectory && pathString.startsWith(new File(ApplicationLoader.applicationContext.getFilesDir(), "Telegram").getAbsolutePath())) {
|
||||
return false;
|
||||
}
|
||||
int tries = 0;
|
||||
while (true) {
|
||||
if (pathString != null && pathString.length() > 4096) {
|
||||
|
@ -1293,7 +1299,7 @@ public class AndroidUtilities {
|
|||
} catch (Exception e) {
|
||||
FileLog.e(e);
|
||||
}
|
||||
if (state == null || state.startsWith(Environment.MEDIA_MOUNTED)) {
|
||||
if (!NekoConfig.saveCacheToPrivateDirectory && (state == null || state.startsWith(Environment.MEDIA_MOUNTED))) {
|
||||
try {
|
||||
File file = ApplicationLoader.applicationContext.getExternalCacheDir();
|
||||
if (file != null) {
|
||||
|
@ -1306,6 +1312,10 @@ public class AndroidUtilities {
|
|||
try {
|
||||
File file = ApplicationLoader.applicationContext.getCacheDir();
|
||||
if (file != null) {
|
||||
if(NekoConfig.saveCacheToPrivateDirectory) {
|
||||
file = new File(file, "sdcard");
|
||||
file.mkdirs();
|
||||
}
|
||||
return file;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
|
|
@ -66,6 +66,8 @@ import java.util.Locale;
|
|||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import tw.nekomimi.nekogram.NekoConfig;
|
||||
|
||||
public class ImageLoader {
|
||||
|
||||
private HashMap<String, Integer> bitmapUseCounts = new HashMap<>();
|
||||
|
@ -1778,8 +1780,12 @@ public class ImageLoader {
|
|||
}
|
||||
|
||||
try {
|
||||
if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
|
||||
telegramPath = new File(Environment.getExternalStorageDirectory(), "Telegram");
|
||||
if (NekoConfig.saveCacheToPrivateDirectory || Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
|
||||
if (NekoConfig.saveCacheToPrivateDirectory) {
|
||||
telegramPath = new File(ApplicationLoader.applicationContext.getFilesDir(), "Telegram");
|
||||
} else {
|
||||
telegramPath = new File(Environment.getExternalStorageDirectory(), "Telegram");
|
||||
}
|
||||
telegramPath.mkdirs();
|
||||
|
||||
if (telegramPath.isDirectory()) {
|
||||
|
|
|
@ -3062,7 +3062,7 @@ public class MediaController implements AudioManager.OnAudioFocusChangeListener,
|
|||
File file = null;
|
||||
if (!TextUtils.isEmpty(fullPath)) {
|
||||
file = new File(fullPath);
|
||||
if (!file.exists() || AndroidUtilities.isInternalUri(Uri.fromFile(file))) {
|
||||
if (!file.exists()) {
|
||||
file = null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,6 +29,8 @@ import java.util.ArrayList;
|
|||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
|
||||
import tw.nekomimi.nekogram.NekoConfig;
|
||||
|
||||
public class SharedConfig {
|
||||
|
||||
public static String pushString = "";
|
||||
|
@ -772,7 +774,12 @@ public class SharedConfig {
|
|||
|
||||
public static void checkSaveToGalleryFiles() {
|
||||
try {
|
||||
File telegramPath = new File(Environment.getExternalStorageDirectory(), "Telegram");
|
||||
File telegramPath;
|
||||
if (NekoConfig.saveCacheToPrivateDirectory) {
|
||||
telegramPath = new File(ApplicationLoader.applicationContext.getFilesDir(), "Telegram");
|
||||
} else {
|
||||
telegramPath = new File(Environment.getExternalStorageDirectory(), "Telegram");
|
||||
}
|
||||
File imagePath = new File(telegramPath, "Telegram Images");
|
||||
imagePath.mkdir();
|
||||
File videoPath = new File(telegramPath, "Telegram Video");
|
||||
|
|
|
@ -92,6 +92,8 @@ import java.util.HashMap;
|
|||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import tw.nekomimi.nekogram.NekoConfig;
|
||||
|
||||
public class ThemeActivity extends BaseFragment implements NotificationCenter.NotificationCenterDelegate {
|
||||
|
||||
public final static int THEME_TYPE_BASIC = 0;
|
||||
|
@ -389,7 +391,7 @@ public class ThemeActivity extends BaseFragment implements NotificationCenter.No
|
|||
emojiRow = rowCount++;
|
||||
raiseToSpeakRow = rowCount++;
|
||||
sendByEnterRow = rowCount++;
|
||||
saveToGalleryRow = rowCount++;
|
||||
saveToGalleryRow = NekoConfig.saveCacheToPrivateDirectory ? -1 : rowCount++;
|
||||
distanceRow = rowCount++;
|
||||
settings2Row = rowCount++;
|
||||
stickersRow = rowCount++;
|
||||
|
|
|
@ -4,6 +4,7 @@ import android.app.Activity;
|
|||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Build;
|
||||
|
||||
import org.telegram.messenger.ApplicationLoader;
|
||||
import org.telegram.messenger.FileLog;
|
||||
|
@ -21,6 +22,7 @@ public class NekoConfig {
|
|||
public static boolean transparentStatusBar = true;
|
||||
public static boolean residentNotification = false;
|
||||
public static boolean hideProxySponsorChannel = false;
|
||||
public static boolean saveCacheToPrivateDirectory = Build.VERSION.SDK_INT >= 24;
|
||||
|
||||
public static boolean showAddToSavedMessages = true;
|
||||
public static boolean showReport = false;
|
||||
|
@ -57,6 +59,7 @@ public class NekoConfig {
|
|||
editor.putBoolean("transparentStatusBar", transparentStatusBar);
|
||||
editor.putBoolean("residentNotification", residentNotification);
|
||||
editor.putBoolean("hideProxySponsorChannel", hideProxySponsorChannel);
|
||||
editor.putBoolean("saveCacheToPrivateDirectory", saveCacheToPrivateDirectory);
|
||||
editor.putBoolean("showAddToSavedMessages", showAddToSavedMessages);
|
||||
editor.putBoolean("showReport", showReport);
|
||||
editor.putBoolean("showPrPr", showPrPr);
|
||||
|
@ -93,6 +96,7 @@ public class NekoConfig {
|
|||
transparentStatusBar = preferences.getBoolean("transparentStatusBar", true);
|
||||
residentNotification = preferences.getBoolean("residentNotification", false);
|
||||
hideProxySponsorChannel = preferences.getBoolean("hideProxySponsorChannel", false);
|
||||
saveCacheToPrivateDirectory = preferences.getBoolean("saveCacheToPrivateDirectory", Build.VERSION.SDK_INT >= 24);
|
||||
showAddToSavedMessages = preferences.getBoolean("showAddToSavedMessages", true);
|
||||
showReport = preferences.getBoolean("showReport", false);
|
||||
showPrPr = preferences.getBoolean("showPrPr", true);
|
||||
|
@ -252,6 +256,14 @@ public class NekoConfig {
|
|||
editor.commit();
|
||||
}
|
||||
|
||||
public static void toggleSaveCacheToPrivateDirectory() {
|
||||
saveCacheToPrivateDirectory = !saveCacheToPrivateDirectory;
|
||||
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE);
|
||||
SharedPreferences.Editor editor = preferences.edit();
|
||||
editor.putBoolean("saveCacheToPrivateDirectory", saveCacheToPrivateDirectory);
|
||||
editor.commit();
|
||||
}
|
||||
|
||||
public static void toggleXmas() {
|
||||
xmas = !xmas;
|
||||
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE);
|
||||
|
|
|
@ -82,6 +82,7 @@ public class NekoSettingsActivity extends BaseFragment {
|
|||
private int nameOrderRow;
|
||||
private int transparentStatusBarRow;
|
||||
private int hideProxySponsorChannelRow;
|
||||
private int saveCacheToPrivateDirectoryRow;
|
||||
private int forceTabletRow;
|
||||
private int xmasRow;
|
||||
private int newYearRow;
|
||||
|
@ -217,6 +218,11 @@ public class NekoSettingsActivity extends BaseFragment {
|
|||
MessagesController.getInstance(a).checkProxyInfo(true);
|
||||
}
|
||||
}
|
||||
} else if (position == saveCacheToPrivateDirectoryRow) {
|
||||
NekoConfig.toggleSaveCacheToPrivateDirectory();
|
||||
if (view instanceof TextCheckCell) {
|
||||
((TextCheckCell) view).setChecked(NekoConfig.saveCacheToPrivateDirectory);
|
||||
}
|
||||
} else if (position == useSystemEmojiRow) {
|
||||
SharedConfig.useSystemEmoji = !SharedConfig.useSystemEmoji;
|
||||
SharedPreferences.Editor editor = MessagesController.getGlobalMainSettings().edit();
|
||||
|
@ -336,6 +342,7 @@ public class NekoSettingsActivity extends BaseFragment {
|
|||
useSystemEmojiRow = rowCount++;
|
||||
ignoreBlockedRow = rowCount++;
|
||||
hideProxySponsorChannelRow = rowCount++;
|
||||
saveCacheToPrivateDirectoryRow = Build.VERSION.SDK_INT >= 24 ? rowCount++ : -1;
|
||||
mapPreviewRow = rowCount++;
|
||||
chat2Row = rowCount++;
|
||||
messageMenuRow = rowCount++;
|
||||
|
@ -479,6 +486,8 @@ public class NekoSettingsActivity extends BaseFragment {
|
|||
textCell.setTextAndCheck(LocaleController.getString("TransparentStatusBar", R.string.TransparentStatusBar), NekoConfig.transparentStatusBar, true);
|
||||
} else if (position == hideProxySponsorChannelRow) {
|
||||
textCell.setTextAndCheck(LocaleController.getString("HideProxySponsorChannel", R.string.HideProxySponsorChannel), NekoConfig.hideProxySponsorChannel, true);
|
||||
} else if(position == saveCacheToPrivateDirectoryRow) {
|
||||
textCell.setTextAndCheck(LocaleController.getString("saveCacheToPrivateDirectory", R.string.saveCacheToPrivateDirectory), NekoConfig.saveCacheToPrivateDirectory, true);
|
||||
} else if (position == useSystemEmojiRow) {
|
||||
textCell.setTextAndCheck(LocaleController.getString("EmojiUseDefault", R.string.EmojiUseDefault), SharedConfig.useSystemEmoji, true);
|
||||
} else if (position == typefaceRow) {
|
||||
|
@ -530,7 +539,7 @@ public class NekoSettingsActivity extends BaseFragment {
|
|||
position == showPrPrRow || position == showViewHistoryRow || position == showAddToSavedMessagesRow ||
|
||||
position == nameOrderRow || position == forceTabletRow || position == mapPreviewRow ||
|
||||
position == xmasRow || position == newYearRow || position == newYearEveRow || position == fireworksRow ||
|
||||
position == transparentStatusBarRow || position == hideProxySponsorChannelRow;
|
||||
position == transparentStatusBarRow || position == hideProxySponsorChannelRow || position == saveCacheToPrivateDirectoryRow;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -581,7 +590,7 @@ public class NekoSettingsActivity extends BaseFragment {
|
|||
position == transparentStatusBarRow || position == hideProxySponsorChannelRow || position == showViewHistoryRow ||
|
||||
position == ignoreBlockedRow || position == useSystemEmojiRow || position == typefaceRow ||
|
||||
position == forceTabletRow || position == xmasRow || position == newYearRow || position == newYearEveRow ||
|
||||
position == fireworksRow) {
|
||||
position == fireworksRow || position == saveCacheToPrivateDirectoryRow) {
|
||||
return 3;
|
||||
} else if (position == settingsRow || position == connectionRow || position == messageMenuRow || position == chatRow) {
|
||||
return 4;
|
||||
|
|
|
@ -52,4 +52,5 @@
|
|||
<string name="HideProxySponsorChannel">Nascondi canale sponsor proxy</string>
|
||||
<string name="ViewHistory">Visualizza la cronologia</string>
|
||||
<string name="Nya">Miao!</string>
|
||||
<string name="saveCacheToPrivateDirectory">Salva la cache nella directory privata*</string>
|
||||
</resources>
|
||||
|
|
|
@ -52,4 +52,5 @@
|
|||
<string name="HideProxySponsorChannel">Proxy sponsor channel を非表示</string>
|
||||
<string name="ViewHistory">履歴を見る</string>
|
||||
<string name="Nya">にゃ!</string>
|
||||
<string name="saveCacheToPrivateDirectory">Cache を private directory に保存する*</string>
|
||||
</resources>
|
|
@ -52,4 +52,5 @@
|
|||
<string name="HideProxySponsorChannel">隐藏代理赞助商频道</string>
|
||||
<string name="ViewHistory">显示历史消息</string>
|
||||
<string name="Nya">喵!</string>
|
||||
<string name="saveCacheToPrivateDirectory">缓存媒体文件到应用私有目录下*</string>
|
||||
</resources>
|
|
@ -52,4 +52,5 @@
|
|||
<string name="HideProxySponsorChannel">隱藏代理贊助商頻道</string>
|
||||
<string name="ViewHistory">顯示歷史消息</string>
|
||||
<string name="Nya">喵!</string>
|
||||
<string name="saveCacheToPrivateDirectory">緩存媒體文件到應用私有目錄下*</string>
|
||||
</resources>
|
|
@ -57,4 +57,5 @@
|
|||
<string name="HideProxySponsorChannel">Hide proxy sponsor channel</string>
|
||||
<string name="ViewHistory">View history</string>
|
||||
<string name="Nya">Meow!</string>
|
||||
<string name="saveCacheToPrivateDirectory">Save cache to private directory*</string>
|
||||
</resources>
|
|
@ -2,4 +2,6 @@
|
|||
<paths>
|
||||
<external-path name="media" path="."/>
|
||||
<root-path name="external_files" path="/storage/" />
|
||||
<files-path name="fake_sdcard" path="Telegram/"/>
|
||||
<cache-path name="fake_sdcard_cache" path="sdcard/"/>
|
||||
</paths>
|
Loading…
Reference in New Issue