From 3c2aa1bff663e9d2514087b25fdc81d75cf4dbf4 Mon Sep 17 00:00:00 2001 From: segfault-bilibili Date: Tue, 15 Feb 2022 03:20:47 +0800 Subject: [PATCH] save dataDir; trivial log fix --- .../shadowsocks/plugin/gost/ConfigActivity.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/github/shadowsocks/plugin/gost/ConfigActivity.java b/app/src/main/java/com/github/shadowsocks/plugin/gost/ConfigActivity.java index 55de935..142f1d4 100644 --- a/app/src/main/java/com/github/shadowsocks/plugin/gost/ConfigActivity.java +++ b/app/src/main/java/com/github/shadowsocks/plugin/gost/ConfigActivity.java @@ -3,6 +3,7 @@ import android.annotation.SuppressLint; import android.app.AlertDialog; import android.content.Context; +import android.content.ContextWrapper; import android.content.DialogInterface; import android.content.res.ColorStateList; import android.graphics.Color; @@ -30,6 +31,7 @@ import org.json.JSONException; import org.json.JSONObject; +import java.io.File; import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.HashMap; @@ -394,7 +396,7 @@ private void saveUI() throws NullPointerException, JSONException { for (Long index : cmdArgIdx) { Editable[] oneOrTwoArgsEditable = cmdArgMap.get(index); if (oneOrTwoArgsEditable == null) { - Log.e("ConfigActivity", "promptSaveAndApply encountered oneOrTwoArgs == null"); + Log.e("ConfigActivity", "saveUI encountered oneOrTwoArgs == null"); throw new NullPointerException(); } JSONArray oneOrTwoArgs = new JSONArray(); @@ -429,6 +431,13 @@ private void saveUI() throws NullPointerException, JSONException { } else { this.decodedPluginOptions.remove("legacyCfg"); } + + // (not UI, but also saved here) save app data directory path + File dataDir = new ContextWrapper(getApplicationContext()).getFilesDir(); + if (!dataDir.exists() && !dataDir.mkdirs()) { + Log.e("ConfigActivity", "dataDir.mkdirs() failed"); + } + this.decodedPluginOptions.put("dataDir", dataDir.getAbsolutePath()); } private void populateUI() throws JSONException { // populate linearlayout_cmdargs