From 9a9f1adb5764b5f8961924e8e3ed8957d911c82b Mon Sep 17 00:00:00 2001 From: RohitKushvaha01 Date: Thu, 26 Feb 2026 14:30:36 +0530 Subject: [PATCH 1/4] feat: secrets api --- .../pluginContext/src/android/Tee.java | 65 +++++++++++++++++++ .../pluginContext/www/PluginContext.js | 25 +++++++ 2 files changed, 90 insertions(+) diff --git a/src/plugins/pluginContext/src/android/Tee.java b/src/plugins/pluginContext/src/android/Tee.java index be6b75f4b..16386b588 100644 --- a/src/plugins/pluginContext/src/android/Tee.java +++ b/src/plugins/pluginContext/src/android/Tee.java @@ -15,6 +15,9 @@ import java.util.Set; import java.util.concurrent.ConcurrentHashMap; +//auth plugin +import com.foxdebug.acode.rk.auth.EncryptedPreferenceManager; + public class Tee extends CordovaPlugin { // pluginId : token @@ -26,10 +29,62 @@ public class Tee extends CordovaPlugin { // token : list of permissions private /*static*/ final Map> permissionStore = new ConcurrentHashMap<>(); + + + private Context context; + + + public void initialize(CordovaInterface cordova, CordovaWebView webView) { + super.initialize(cordova, webView); + this.context = cordova.getContext(); + } + @Override public boolean execute(String action, JSONArray args, CallbackContext callback) throws JSONException { + + if ("get_secret".equals(action)) { + String token = args.getString(0); + String key = args.getString(1); + String defaultValue = args.getString(2); + + String pluginId = getPluginIdFromToken(token); + + if (pluginId == null) { + callback.error("INVALID_TOKEN"); + return true; + } + + EncryptedPreferenceManager prefs = + new EncryptedPreferenceManager(context, pluginId); + + String value = prefs.getString(key, defaultValue); + callback.success(value); + return true; + } + + if ("set_secret".equals(action)) { + String token = args.getString(0); + String key = args.getString(1); + String value = args.getString(2); + + String pluginId = getPluginIdFromToken(token); + + if (pluginId == null) { + callback.error("INVALID_TOKEN"); + return true; + } + + EncryptedPreferenceManager prefs = + new EncryptedPreferenceManager(context, pluginId); + + prefs.setString(key, value); + callback.success(); + return true; + } + + if ("requestToken".equals(action)) { String pluginId = args.getString(0); String pluginJson = args.getString(1); @@ -69,6 +124,16 @@ public boolean execute(String action, JSONArray args, CallbackContext callback) return false; } + + private String getPluginIdFromToken(String token) { + for (Map.Entry entry : tokenStore.entrySet()) { + if (entry.getValue().equals(token)) { + return entry.getKey(); + } + } + return null; + } + //============================================================ //do not change function signatures public boolean isTokenValid(String token, String pluginId) { diff --git a/src/plugins/pluginContext/www/PluginContext.js b/src/plugins/pluginContext/www/PluginContext.js index 380dfbb9b..c7b52df21 100644 --- a/src/plugins/pluginContext/www/PluginContext.js +++ b/src/plugins/pluginContext/www/PluginContext.js @@ -34,6 +34,31 @@ const PluginContext = (function () { exec(resolve, reject, "Tee", "listAllPermissions", [this.uuid]); }); } + + getSecret(token, key, defaultValue = "") { + return new Promise((resolve, reject) => { + exec( + resolve, + reject, + "Tee", + "get_secret", + [token, key, defaultValue] + ); + }); + } + + + setSecret(token, key, value) { + return new Promise((resolve, reject) => { + exec( + resolve, + reject, + "Tee", + "set_secret", + [token, key, value] + ); + }); + } } //Object.freeze(this); From 758cafd5c6600d3fbe48ea30548aca45ce2f6d69 Mon Sep 17 00:00:00 2001 From: RohitKushvaha01 Date: Sat, 28 Feb 2026 11:26:36 +0530 Subject: [PATCH 2/4] feat: add imports --- src/plugins/pluginContext/src/android/Tee.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/plugins/pluginContext/src/android/Tee.java b/src/plugins/pluginContext/src/android/Tee.java index 16386b588..39edb423c 100644 --- a/src/plugins/pluginContext/src/android/Tee.java +++ b/src/plugins/pluginContext/src/android/Tee.java @@ -14,6 +14,8 @@ import java.util.HashSet; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; +import android.content.Context; +import org.apache.cordova.*; //auth plugin import com.foxdebug.acode.rk.auth.EncryptedPreferenceManager; From 62eb92e317e44668ae91fc1bd6070ad45e730f8e Mon Sep 17 00:00:00 2001 From: Rohit Kushvaha Date: Sat, 28 Feb 2026 11:26:56 +0530 Subject: [PATCH 3/4] Update src/plugins/pluginContext/www/PluginContext.js Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com> --- src/plugins/pluginContext/www/PluginContext.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/plugins/pluginContext/www/PluginContext.js b/src/plugins/pluginContext/www/PluginContext.js index c7b52df21..b7630f810 100644 --- a/src/plugins/pluginContext/www/PluginContext.js +++ b/src/plugins/pluginContext/www/PluginContext.js @@ -35,14 +35,14 @@ const PluginContext = (function () { }); } - getSecret(token, key, defaultValue = "") { + getSecret(key, defaultValue = "") { return new Promise((resolve, reject) => { exec( resolve, reject, "Tee", "get_secret", - [token, key, defaultValue] + [this.uuid, key, defaultValue] ); }); } From 728f743ea74d8d76e7c06b628523042514c2c6e6 Mon Sep 17 00:00:00 2001 From: Rohit Kushvaha Date: Sat, 28 Feb 2026 11:27:07 +0530 Subject: [PATCH 4/4] Update src/plugins/pluginContext/www/PluginContext.js Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com> --- src/plugins/pluginContext/www/PluginContext.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/plugins/pluginContext/www/PluginContext.js b/src/plugins/pluginContext/www/PluginContext.js index b7630f810..a2d868d2d 100644 --- a/src/plugins/pluginContext/www/PluginContext.js +++ b/src/plugins/pluginContext/www/PluginContext.js @@ -48,14 +48,14 @@ const PluginContext = (function () { } - setSecret(token, key, value) { + setSecret(key, value) { return new Promise((resolve, reject) => { exec( resolve, reject, "Tee", "set_secret", - [token, key, value] + [this.uuid, key, value] ); }); }