Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
/.idea/workspace.xml
/.idea/navEditor.xml
/.idea/assetWizardSettings.xml
.idea
.DS_Store
/build
/captures
Expand Down
10 changes: 0 additions & 10 deletions .idea/codeStyles/Project.xml

This file was deleted.

5 changes: 0 additions & 5 deletions .idea/codeStyles/codeStyleConfig.xml

This file was deleted.

4 changes: 0 additions & 4 deletions .idea/encodings.xml

This file was deleted.

18 changes: 0 additions & 18 deletions .idea/gradle.xml

This file was deleted.

9 changes: 0 additions & 9 deletions .idea/misc.xml

This file was deleted.

12 changes: 0 additions & 12 deletions .idea/runConfigurations.xml

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/vcs.xml

This file was deleted.

3 changes: 2 additions & 1 deletion slaask/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.slaask.sdk">

<uses-permission android:name="android.permission.INTERNET"/>

<application>
<activity
android:name=".ui.SlaaskActivity"
android:screenOrientation="portrait"
android:theme="@android:style/Theme.NoTitleBar"/>
</application>

</manifest>
39 changes: 26 additions & 13 deletions slaask/src/main/java/com/slaask/sdk/Slaask.java
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -92,10 +109,6 @@ public String getApiKey() {
return apiKey;
}

public String getSecretKey() {
return secretKey;
}

public void setRandomToken(String tokenId) {
this.randomToken = randomToken;
}
Expand Down
51 changes: 4 additions & 47 deletions slaask/src/main/java/com/slaask/sdk/SlaaskIdentity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
}
}
}
21 changes: 17 additions & 4 deletions slaask/src/main/java/com/slaask/sdk/ui/SlaaskViewFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -68,22 +72,31 @@ 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")) {
handleMailToLink(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);
Expand Down