diff --git a/.gitignore b/.gitignore index 2b75303..7b8af0d 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,7 @@ /.idea/workspace.xml /.idea/navEditor.xml /.idea/assetWizardSettings.xml +.idea .DS_Store /build /captures diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml deleted file mode 100644 index 1bec35e..0000000 --- a/.idea/codeStyles/Project.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml deleted file mode 100644 index 79ee123..0000000 --- a/.idea/codeStyles/codeStyleConfig.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml deleted file mode 100644 index 15a15b2..0000000 --- a/.idea/encodings.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml deleted file mode 100644 index 4c184c3..0000000 --- a/.idea/gradle.xml +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index 37a7509..0000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml deleted file mode 100644 index 7f68460..0000000 --- a/.idea/runConfigurations.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 94a25f7..0000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/slaask/src/main/AndroidManifest.xml b/slaask/src/main/AndroidManifest.xml index b690c8a..73c9c59 100644 --- a/slaask/src/main/AndroidManifest.xml +++ b/slaask/src/main/AndroidManifest.xml @@ -1,11 +1,12 @@ + + - diff --git a/slaask/src/main/java/com/slaask/sdk/Slaask.java b/slaask/src/main/java/com/slaask/sdk/Slaask.java index 8dd1d6b..6a631ae 100644 --- a/slaask/src/main/java/com/slaask/sdk/Slaask.java +++ b/slaask/src/main/java/com/slaask/sdk/Slaask.java @@ -17,39 +17,56 @@ public class Slaask { private SlaaskIdentity identity; private Boolean identified; private String apiKey; - private String secretKey; private String randomToken; private String locale; private String color = "#e01865"; private Context context; - private Slaask(Context context, String apiKey, String secretKey) { + private Slaask(Context context, String apiKey) { this.context = context; getOrCreateRandomToken(); this.identity = new SlaaskIdentity(); - this.identity.setId(randomToken, secretKey); + this.identity.setId(randomToken); this.identified = false; this.apiKey = apiKey; - this.secretKey = secretKey; } - private Slaask(Context context, String apiKey, SlaaskIdentity identity, String secretKey) { + private Slaask(Context context, String apiKey, SlaaskIdentity identity) { this.context = context; this.apiKey = apiKey; - this.secretKey = secretKey; this.identity = identity; this.identified = true; } + public static void initialize(Context context, String apiKey) { + instance = new Slaask(context, apiKey); + } + + public static void initialize(Context context, String apiKey, SlaaskIdentity identity) { + instance = new Slaask(context, apiKey, identity); + } + + private static void deprecationAlert() { + Log.e(packageName, "The secretKey argument is deprecated. Please see https://xenoapp.help/hc/developers-documentation/android-sdk/automatically-identify-your-users-on-your-android-apps"); + } + + // DEPRECATED + private Slaask(Context context, String apiKey, String secretKey) { + deprecationAlert(); + } + + private Slaask(Context context, String apiKey, SlaaskIdentity identity, String secretKey) { + deprecationAlert(); + } + public static void initialize(Context context, String apiKey, String secretKey) { - instance = new Slaask(context, apiKey, secretKey); + deprecationAlert(); } public static void initialize(Context context, String apiKey, String secretKey, SlaaskIdentity identity) { - instance = new Slaask(context, apiKey, identity, secretKey); + deprecationAlert(); } - public static Slaask getInstance() { if (instance == null) { Log.e(packageName, "You need to call Slaask.initialize(this, \"apiKey\", \"secretKey\") first"); @@ -92,10 +109,6 @@ public String getApiKey() { return apiKey; } - public String getSecretKey() { - return secretKey; - } - public void setRandomToken(String tokenId) { this.randomToken = randomToken; } diff --git a/slaask/src/main/java/com/slaask/sdk/SlaaskIdentity.java b/slaask/src/main/java/com/slaask/sdk/SlaaskIdentity.java index 8acee65..230405d 100644 --- a/slaask/src/main/java/com/slaask/sdk/SlaaskIdentity.java +++ b/slaask/src/main/java/com/slaask/sdk/SlaaskIdentity.java @@ -19,25 +19,11 @@ public SlaaskIdentity() { } public SlaaskIdentity setId(String id) { - try { - setCustomAttribute("user_hash", generateHashWithHmac256(id, Slaask.getInstance().getSecretKey())); - setCustomAttribute("id", id); - } catch (Exception e) { - e.printStackTrace(); - } - - return this; + return setCustomAttribute("id", id); } - public SlaaskIdentity setId(String id, String secretKey) { - try { - setCustomAttribute("user_hash", generateHashWithHmac256(id, secretKey)); - setCustomAttribute("id", id); - } catch (Exception e) { - e.printStackTrace(); - } - - return this; + public SlaaskIdentity setIdentityHash(String hash) { + return setCustomAttribute("user_hash", hash); } public SlaaskIdentity setName(String name) { @@ -64,33 +50,4 @@ public SlaaskIdentity setCustomAttribute(String key, String value) { public String build() { return new JSONObject(attributes).toString(); } - - private String generateHashWithHmac256(String message, String key) { - try { - final String hashingAlgorithm = "HmacSHA256"; - byte[] bytes = hmac(hashingAlgorithm, key.getBytes(), message.getBytes()); - return bytesToHex(bytes); - } catch (Exception e) { - e.printStackTrace(); - } - - return ""; - } - - public static byte[] hmac(String algorithm, byte[] key, byte[] message) throws NoSuchAlgorithmException, InvalidKeyException { - Mac mac = Mac.getInstance(algorithm); - mac.init(new SecretKeySpec(key, algorithm)); - return mac.doFinal(message); - } - - public static String bytesToHex(byte[] bytes) { - final char[] hexArray = "0123456789abcdef".toCharArray(); - char[] hexChars = new char[bytes.length * 2]; - for (int j = 0, v; j < bytes.length; j++) { - v = bytes[j] & 0xFF; - hexChars[j * 2] = hexArray[v >>> 4]; - hexChars[j * 2 + 1] = hexArray[v & 0x0F]; - } - return new String(hexChars); - } -} \ No newline at end of file +} diff --git a/slaask/src/main/java/com/slaask/sdk/ui/SlaaskViewFragment.java b/slaask/src/main/java/com/slaask/sdk/ui/SlaaskViewFragment.java index 4a66295..bc46d2e 100644 --- a/slaask/src/main/java/com/slaask/sdk/ui/SlaaskViewFragment.java +++ b/slaask/src/main/java/com/slaask/sdk/ui/SlaaskViewFragment.java @@ -46,6 +46,10 @@ public class SlaaskViewFragment extends Fragment { public SlaaskViewFragment() { } + private void logger(String message) { + Log.d(">>>>>>>> VIEW >>>>>>>> ", message); + } + @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { @@ -68,6 +72,7 @@ public void onPageFinished(WebView view, String url) { flushQueue(); } + // android.os.Build.VERSION <= 22 (LOLLIPOP) @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { if (url.startsWith("mailto")) { @@ -75,15 +80,23 @@ public boolean shouldOverrideUrlLoading(WebView view, String url) { return true; } + if (url.startsWith("tel:")) { + handleTelToLink(url); + return true; + } + + if (url.startsWith("slaask:")) { + handleSlaaskToLink(url); + return true; + } + return false; } + // android.os.Build.VERSION > 22+ (Marshmallow and latests) @Override public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) { - String url = ""; - if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) { - url = request.getUrl().toString(); - } + String url = request.getUrl().toString(); if (url.startsWith("mailto")) { handleMailToLink(url);