From 1d364a1f5a8322ce8fbe200fcc9f5a41f91b41e8 Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Thu, 13 Jul 2017 15:08:06 -0700 Subject: Only use basic user agent when necessary (#59) * Log more iab and web chrome * Only add basic user string for messages * Clean up logging --- .../com/pitchedapps/frost/facebook/FbConst.kt | 1 + .../kotlin/com/pitchedapps/frost/utils/iab/IAB.kt | 49 ++++++++++++---------- .../com/pitchedapps/frost/web/FrostChromeClient.kt | 8 +--- .../com/pitchedapps/frost/web/FrostWebView.kt | 5 ++- .../pitchedapps/frost/web/FrostWebViewClient.kt | 11 +++++ 5 files changed, 45 insertions(+), 29 deletions(-) (limited to 'app/src/main/kotlin') diff --git a/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbConst.kt b/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbConst.kt index 5c8b0a1a..e5216881 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbConst.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbConst.kt @@ -8,5 +8,6 @@ const val FACEBOOK_COM = "facebook.com" const val FB_URL_BASE = "https://m.facebook.com/" fun PROFILE_PICTURE_URL(id: Long) = "https://graph.facebook.com/$id/picture?type=large" +const val USER_AGENT_BASIC_FULL = "Mozilla/5.0 (Linux; Android 4.4.2; en-us; SAMSUNG SM-G900T Build/KOT49H) AppleWebKit/537.36 (KHTML, like Gecko) Version/1.6 Chrome/28.0.1500.94 Mobile Safari/537.36" const val USER_AGENT_BASIC = "Mozilla/5.0 (Linux; U; Android 2.3.3; en-gb; Nexus S Build/GRI20) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1" const val USER_AGENT_MESSENGER = "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36" \ No newline at end of file diff --git a/app/src/main/kotlin/com/pitchedapps/frost/utils/iab/IAB.kt b/app/src/main/kotlin/com/pitchedapps/frost/utils/iab/IAB.kt index 21326efa..58c748c2 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/utils/iab/IAB.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/utils/iab/IAB.kt @@ -40,10 +40,12 @@ object IAB { onFailed: () -> Unit = {}, onStart: (helper: IabHelper) -> Unit) { with(activity) { - if (isInProgress) if (userRequest) snackbar(R.string.iab_still_in_progress, Snackbar.LENGTH_LONG) - else if (helper?.disposed ?: true) { + if (isInProgress) { + if (userRequest) snackbar(R.string.iab_still_in_progress, Snackbar.LENGTH_LONG) + L.d("Play Store IAB in progress") + } else if (helper?.disposed ?: true) { helper = null - L.d("IAB setup async") + L.d("Play Store IAB setup async") if (!isFrostPlay) { if (mustHavePlayStore) playStoreNotFound() onFailed() @@ -54,12 +56,12 @@ object IAB { helper!!.enableDebugLogging(BuildConfig.DEBUG || Prefs.verboseLogging, "Frost:") helper!!.startSetup { result -> - L.d("IAB setup finished; ${result.isSuccess}") + L.d("Play Store IAB setup finished; ${result.isSuccess}") if (result.isSuccess) { - L.d("IAB setup success") + L.d("Play Store IAB setup success") onStart(helper!!) } else { - L.d("IAB setup fail") + L.d("Play Store IAB setup fail") if (mustHavePlayStore) activity.playStoreGenericError("Setup error: ${result.response} ${result.message}") onFailed() @@ -67,7 +69,7 @@ object IAB { } } } catch (e: Exception) { - L.e(e, "IAB error") + L.e(e, "Play Store IAB error") if (mustHavePlayStore) playStoreGenericError(null) onFailed() @@ -84,17 +86,23 @@ object IAB { * Call this after any execution to dispose the helper */ fun dispose() { - helper?.disposeWhenFinished() - helper = null + synchronized(this) { + L.d("Play Store IAB dispose") + helper?.disposeWhenFinished() + helper = null + } } /** * Dispose given helper and check if it matches with our own helper */ fun dispose(helper: IabHelper) { - helper.disposeWhenFinished() - if (IAB.helper?.disposed ?: true) - this.helper = null + synchronized(this) { + L.d("Play Store IAB helper dispose") + helper.disposeWhenFinished() + if (IAB.helper?.disposed ?: true) + this.helper = null + } } val isInProgress: Boolean @@ -118,7 +126,7 @@ fun SettingsActivity.restorePurchases() { restore.setAction(R.string.kau_close) { restore.dismiss() } //called if inventory is not properly retrieved val reset = { - L.d("Restore reset") + L.d("Play Store Restore reset") if (Prefs.pro) { Prefs.pro = false Prefs.theme = Theme.DEFAULT.ordinal @@ -129,7 +137,7 @@ fun SettingsActivity.restorePurchases() { inv, helper -> val proSku = inv.hasPurchase(FROST_PRO) Prefs.pro = proSku - L.d("Restore found: ${Prefs.pro}") + L.d("Play Store Restore found: ${Prefs.pro}") finishRestore(restore, Prefs.pro) } } @@ -149,11 +157,11 @@ private fun SettingsActivity.finishRestore(snackbar: Snackbar, hasPro: Boolean) * If cache matches result, it finishes silently */ fun Activity.validatePro() { - L.d("Validate pro") + L.d("Play Store Validate pro") getInventory(Prefs.pro, false, { if (Prefs.pro) playStoreNoLongerPro() }) { inv, helper -> val proSku = inv.hasPurchase(FROST_PRO) - L.d("Validation finished: ${Prefs.pro} should be $proSku") + L.d("Play Store Validation finished: ${Prefs.pro} should be $proSku") if (!proSku && Prefs.pro) playStoreNoLongerPro() else if (proSku && !Prefs.pro) playStoreFoundPro() helper.disposeWhenFinished() @@ -169,12 +177,11 @@ fun Activity.getInventory( helper -> helper.queryInventoryAsync { res, inv -> - L.d("Inventory query finished") + L.d("Play Store Inventory query finished") if (res.isFailure || inv == null) { - L.e("Res error ${res.message}") + L.e("Play Store Res error ${res.message}") onFailed() - } - else onSuccess(inv, helper) + } else onSuccess(inv, helper) } } } @@ -188,7 +195,7 @@ fun Activity.openPlayProPurchase(code: Int) { } fun Activity.openPlayPurchase(key: String, code: Int, onSuccess: (key: String) -> Unit) { - L.d("Open play purchase $key $code") + L.d("Play Store open purchase $key $code") getInventory(true, true, { playStoreGenericError("Query res error") }) { inv, helper -> if (inv.hasPurchase(key)) { diff --git a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostChromeClient.kt b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostChromeClient.kt index 363bf795..aab3a165 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostChromeClient.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostChromeClient.kt @@ -1,6 +1,8 @@ package com.pitchedapps.frost.web import android.net.Uri +import android.os.Message +import android.view.View import android.webkit.* import ca.allanwang.kau.utils.snackbar import com.pitchedapps.frost.contracts.ActivityWebContract @@ -39,10 +41,4 @@ class FrostChromeClient(webCore: FrostWebViewCore) : WebChromeClient() { return activityContract != null } - override fun onGeolocationPermissionsShowPrompt(origin: String, callback: GeolocationPermissions.Callback) { - super.onGeolocationPermissionsShowPrompt(origin, callback) - L.d("Geo prompt") - } - - } \ No newline at end of file diff --git a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebView.kt b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebView.kt index 5583c63d..7c0a6597 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebView.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebView.kt @@ -15,6 +15,7 @@ import ca.allanwang.kau.utils.visible import ca.allanwang.kau.utils.withAlpha import com.pitchedapps.frost.R import com.pitchedapps.frost.facebook.FbTab +import com.pitchedapps.frost.facebook.USER_AGENT_BASIC import com.pitchedapps.frost.utils.Prefs import io.reactivex.android.schedulers.AndroidSchedulers @@ -59,9 +60,9 @@ class FrostWebView @JvmOverloads constructor( baseEnum = enum with(settings) { javaScriptEnabled = true - userAgentString = com.pitchedapps.frost.facebook.USER_AGENT_BASIC + if (url.contains("com/message")) + userAgentString = USER_AGENT_BASIC allowFileAccess = true - defaultFontSize textZoom = Prefs.webTextScaling } setLayerType(View.LAYER_TYPE_HARDWARE, null) diff --git a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClient.kt b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClient.kt index 0a254c50..ce2daa07 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClient.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClient.kt @@ -97,4 +97,15 @@ open class FrostWebViewClient(val webCore: FrostWebViewCore) : WebViewClient() { return super.shouldOverrideUrlLoading(view, request) } + override fun onPageCommitVisible(view: WebView?, url: String?) { + L.d("ASDF PCV") + super.onPageCommitVisible(view, url) + } + +// override fun onLoadResource(view: WebView, url: String) { +// L.v("Load resource $url") +// super.onLoadResource(view, url) +// } + + } \ No newline at end of file -- cgit v1.2.3