Pebble: use also the device address as seed to store app configuration

This is not needed as long as one GB instance is used to manage a single pebble device, if multiple devices are managed the stored watchapp configuration could be messed up.
This commit is contained in:
Daniele Gobbetti 2016-11-27 11:31:03 +01:00
parent fa8df9f552
commit 84327a5b86
2 changed files with 23 additions and 2 deletions

View File

@ -1,5 +1,5 @@
if (window.Storage){ if (window.Storage){
var prefix = GBjs.getAppUUID(); var prefix = GBjs.getAppLocalstoragePrefix();
GBjs.gbLog("redefining local storage with prefix: " + prefix); GBjs.gbLog("redefining local storage with prefix: " + prefix);
Storage.prototype.setItem = (function(key, value) { Storage.prototype.setItem = (function(key, value) {
@ -85,7 +85,6 @@ function gbPebble() {
} }
self.evaluate = function(name, args) { self.evaluate = function(name, args) {
console.log(args);
if (!self.events.hasOwnProperty(name)) if (!self.events.hasOwnProperty(name))
return; return;

View File

@ -24,7 +24,10 @@ import java.io.BufferedWriter;
import java.io.File; import java.io.File;
import java.io.FileWriter; import java.io.FileWriter;
import java.io.IOException; import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.io.Writer; import java.io.Writer;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Iterator; import java.util.Iterator;
import java.util.Scanner; import java.util.Scanner;
import java.util.UUID; import java.util.UUID;
@ -274,6 +277,25 @@ public class ExternalPebbleJSActivity extends GBActivity {
return appUuid.toString(); return appUuid.toString();
} }
@JavascriptInterface
public String getAppLocalstoragePrefix() {
String prefix = mGBDevice.getAddress() + appUuid.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 (int i = 0; i < bytes.length; i++) {
sb.append(String.format("%02X", bytes[i]));
}
return sb.toString().toLowerCase();
} catch (NoSuchAlgorithmException | UnsupportedEncodingException e) {
e.printStackTrace();
return prefix;
}
}
@JavascriptInterface @JavascriptInterface
public String getWatchToken() { public String getWatchToken() {
//specification says: A string that is is guaranteed to be identical for each Pebble device for the same app across different mobile devices. The token is unique to your app and cannot be used to track Pebble devices across applications. see https://developer.pebble.com/docs/js/Pebble/ //specification says: A string that is is guaranteed to be identical for each Pebble device for the same app across different mobile devices. The token is unique to your app and cannot be used to track Pebble devices across applications. see https://developer.pebble.com/docs/js/Pebble/