use of android.webkit.JavascriptInterface in project AgentWebX5 by Justson.
the class JsBaseInterfaceHolder method checkObject.
@Override
public boolean checkObject(Object v) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1)
return true;
if (AgentWebX5Config.WEBVIEW_TYPE == AgentWebX5Config.WEBVIEW_AGENTWEB_SAFE_TYPE)
return true;
boolean tag = false;
Class clazz = v.getClass();
Method[] mMethods = clazz.getMethods();
for (Method mMethod : mMethods) {
Annotation[] mAnnotations = mMethod.getAnnotations();
for (Annotation mAnnotation : mAnnotations) {
if (mAnnotation instanceof JavascriptInterface) {
tag = true;
break;
}
}
if (tag)
break;
}
return tag;
}
use of android.webkit.JavascriptInterface in project AgentWeb by Justson.
the class SonicJavaScriptInterface method getPerformance.
@JavascriptInterface
public String getPerformance() {
long clickTime = intent.getLongExtra(PARAM_CLICK_TIME, -1);
long loadUrlTime = intent.getLongExtra(PARAM_LOAD_URL_TIME, -1);
try {
JSONObject result = new JSONObject();
result.put(PARAM_CLICK_TIME, clickTime);
result.put(PARAM_LOAD_URL_TIME, loadUrlTime);
Log.i("Info", "getPerformance");
return result.toString();
} catch (Exception e) {
}
return "";
}
use of android.webkit.JavascriptInterface in project Gadgetbridge by Freeyourgadget.
the class JSInterface method getAppLocalstoragePrefix.
@JavascriptInterface
public String getAppLocalstoragePrefix() {
String prefix = device.getAddress() + this.mUuid.toString();
try {
MessageDigest digest = MessageDigest.getInstance("SHA-1");
byte[] bytes = prefix.getBytes("UTF-8");
digest.update(bytes, 0, bytes.length);
bytes = digest.digest();
final StringBuilder sb = new StringBuilder();
for (byte aByte : bytes) {
sb.append(String.format("%02X", aByte));
}
return sb.toString().toLowerCase();
} catch (NoSuchAlgorithmException | UnsupportedEncodingException e) {
LOG.warn("Error definining local storage prefix", e);
return prefix;
}
}
use of android.webkit.JavascriptInterface in project Gadgetbridge by Freeyourgadget.
the class JSInterface method sendAppMessage.
@JavascriptInterface
public String sendAppMessage(String msg, String needsTransactionMsg) {
boolean needsTransaction = "true".equals(needsTransactionMsg);
LOG.debug("from WEBVIEW: " + msg + " needs a transaction: " + needsTransaction);
JSONObject knownKeys = PebbleUtils.getAppConfigurationKeys(this.mUuid);
if (knownKeys == null) {
LOG.warn("No app configuration keys for: " + mUuid);
return null;
}
try {
JSONObject in = new JSONObject(msg);
JSONObject out = new JSONObject();
String inKey, outKey;
boolean passKey;
for (Iterator<String> key = in.keys(); key.hasNext(); ) {
passKey = false;
inKey = key.next();
outKey = null;
int pebbleAppIndex = knownKeys.optInt(inKey, -1);
if (pebbleAppIndex != -1) {
passKey = true;
outKey = String.valueOf(pebbleAppIndex);
} else {
// do not discard integer keys (see https://developer.pebble.com/guides/communication/using-pebblekit-js/ )
Scanner scanner = new Scanner(inKey);
if (scanner.hasNextInt() && inKey.equals("" + scanner.nextInt())) {
passKey = true;
outKey = inKey;
}
}
if (passKey) {
Object obj = in.get(inKey);
out.put(outKey, obj);
} else {
GB.toast("Discarded key " + inKey + ", not found in the local configuration and is not an integer key.", Toast.LENGTH_SHORT, GB.WARN);
}
}
LOG.info("WEBVIEW message to pebble: " + out.toString());
if (needsTransaction) {
this.lastTransaction++;
GBApplication.deviceService().onAppConfiguration(this.mUuid, out.toString(), this.lastTransaction);
return this.lastTransaction.toString();
} else {
GBApplication.deviceService().onAppConfiguration(this.mUuid, out.toString(), null);
}
} catch (JSONException e) {
LOG.warn("Error building the appmessage JSON object", e);
}
return null;
}
use of android.webkit.JavascriptInterface in project Gadgetbridge by Freeyourgadget.
the class JSInterface method getActiveWatchInfo.
@JavascriptInterface
public String getActiveWatchInfo() {
JSONObject wi = new JSONObject();
try {
wi.put("firmware", device.getFirmwareVersion());
wi.put("platform", PebbleUtils.getPlatformName(device.getModel()));
wi.put("model", PebbleUtils.getModel(device.getModel()));
// TODO: use real info
wi.put("language", "en");
} catch (JSONException e) {
LOG.warn("Error building the ActiveWathcInfo JSON object", e);
}
// Json not supported apparently, we need to cast back and forth
return wi.toString();
}
Aggregations