-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
6 changed files
with
136 additions
and
151 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 25 additions & 7 deletions
32
androidsdk/src/main/java/com/bucksapp/androidsdk/BucksappActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,59 @@ | ||
package com.bucksapp.androidsdk | ||
|
||
import android.app.Activity | ||
import androidx.appcompat.app.AppCompatActivity | ||
import android.content.Context | ||
import android.os.Bundle | ||
import android.webkit.CookieManager | ||
import android.webkit.JavascriptInterface | ||
import android.webkit.WebView | ||
import android.webkit.WebViewClient | ||
import androidx.appcompat.app.AppCompatActivity | ||
|
||
/** Instantiate the interface and set the context */ | ||
class WebAppInterface(private val mContext: Context) { | ||
|
||
/** Show a toast from the web page */ | ||
@JavascriptInterface | ||
fun handlerBack() { | ||
val activity = mContext as BucksappActivity | ||
activity.finish() | ||
} | ||
} | ||
|
||
class BucksappActivity : AppCompatActivity() { | ||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContentView(R.layout.activity_bucksapp) | ||
var token: String? = null | ||
var lang: String? = null | ||
var host: String? = null | ||
if (savedInstanceState == null) { | ||
val extras = intent.extras | ||
if (extras != null) { | ||
token = extras.getString("TOKEN") | ||
lang = extras.getString("LANG") | ||
host = extras.getString("HOST") | ||
} | ||
} else { | ||
token = savedInstanceState.getSerializable("TOKEN") as String? | ||
lang = savedInstanceState.getSerializable("LANG") as String? | ||
host = savedInstanceState.getSerializable("HOST") as String? | ||
} | ||
val webView = findViewById<WebView>(R.id.webView) | ||
val webViewClient = WebViewClient() | ||
webView.webViewClient = webViewClient | ||
val cookieManager = CookieManager.getInstance() | ||
cookieManager.setAcceptCookie(true) | ||
cookieManager.removeAllCookie() | ||
cookieManager.setCookie("https://app.dev.bucksapp.com/", String.format("token=%s;", token)) | ||
cookieManager.setCookie(host, String.format("token=%s;", token)) | ||
cookieManager.setCookie( | ||
"https://app.dev.bucksapp.com/", | ||
host, | ||
String.format("NEXT_LOCALE=%s;", lang) | ||
) | ||
webView.loadUrl("https://app.dev.bucksapp.com") | ||
val webSettings = webView.settings | ||
webSettings.javaScriptEnabled = true | ||
if (host != null) { | ||
webView.loadUrl(host) | ||
webView.settings.javaScriptEnabled = true | ||
webView.addJavascriptInterface(WebAppInterface(this), "BucksappAndroid") | ||
} | ||
|
||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
androidsdk/src/main/java/com/bucksapp/androidsdk/SignatureUtil.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package com.bucksapp.androidsdk | ||
|
||
import android.annotation.SuppressLint | ||
import android.content.pm.PackageManager | ||
import android.content.pm.Signature | ||
import android.os.Build | ||
import java.security.MessageDigest | ||
import java.security.NoSuchAlgorithmException | ||
import java.util.* | ||
|
||
object SignatureUtil { | ||
private fun signatureDigest(sig: Signature): String? { | ||
val signature = sig.toByteArray() | ||
return try { | ||
val md = MessageDigest.getInstance("SHA1") | ||
val digest = md.digest(signature) | ||
val hexBuilder = StringBuilder(); | ||
for(b in digest){ | ||
hexBuilder.append(String.format("%02x:", b)); | ||
} | ||
val hexSignature = hexBuilder.toString().toUpperCase(); | ||
hexSignature.dropLast(1) | ||
} catch (e: NoSuchAlgorithmException) { | ||
null | ||
} | ||
} | ||
|
||
|
||
private fun signatureDigest(sigList: Array<Signature>): List<String?> { | ||
val signaturesList: MutableList<String?> = ArrayList() | ||
for (signature in sigList) { | ||
if (signature != null) { | ||
signaturesList.add(signatureDigest(signature)) | ||
} | ||
} | ||
return signaturesList | ||
} | ||
|
||
fun getSignatures(pm: PackageManager, packageName: String): List<String?>? { | ||
return try { | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { | ||
val packageInfo = | ||
pm.getPackageInfo(packageName, PackageManager.GET_SIGNING_CERTIFICATES) | ||
if (packageInfo == null | ||
|| packageInfo.signingInfo == null | ||
) { | ||
return null | ||
} | ||
if (packageInfo.signingInfo.hasMultipleSigners()) { | ||
signatureDigest(packageInfo.signingInfo.apkContentsSigners) | ||
} else { | ||
signatureDigest(packageInfo.signingInfo.signingCertificateHistory) | ||
} | ||
} else { | ||
@SuppressLint("PackageManagerGetSignatures") val packageInfo = | ||
pm.getPackageInfo(packageName, PackageManager.GET_SIGNATURES) | ||
if (packageInfo == null || packageInfo.signatures == null || packageInfo.signatures.size == 0 || packageInfo.signatures[0] == null) { | ||
null | ||
} else signatureDigest(packageInfo.signatures) | ||
} | ||
} catch (e: PackageManager.NameNotFoundException) { | ||
null | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters