-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Check WebView Version For Login Functionality #12108
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
/* | ||
* Nextcloud Android client application | ||
* | ||
* @author Alper Ozturk | ||
* Copyright (C) 2023 Alper Ozturk | ||
* Copyright (C) 2023 Nextcloud GmbH | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package com.owncloud.android.utils | ||
|
||
import android.content.Context | ||
import android.content.Intent | ||
import android.content.pm.PackageManager | ||
import android.net.Uri | ||
import com.google.android.material.dialog.MaterialAlertDialogBuilder | ||
import com.owncloud.android.R | ||
|
||
class WebViewUtil(private val context: Context) { | ||
|
||
private val packageName = "com.google.android.webview" | ||
|
||
fun checkWebViewVersion() { | ||
if (!isWebViewVersionValid()) { | ||
showUpdateDialog() | ||
} | ||
} | ||
|
||
private fun isWebViewVersionValid(): Boolean { | ||
val currentWebViewVersion = getCurrentWebViewMajorVersion() ?: return true | ||
val minSupportedWebViewVersion: String = getMinimumSupportedMajorWebViewVersion() | ||
return currentWebViewVersion.toInt() >= minSupportedWebViewVersion.toInt() | ||
} | ||
|
||
private fun showUpdateDialog() { | ||
val builder = MaterialAlertDialogBuilder(context) | ||
.setTitle(context.getString(R.string.webview_version_check_alert_dialog_title)) | ||
.setMessage(context.getString(R.string.webview_version_check_alert_dialog_message)) | ||
.setCancelable(false) | ||
.setPositiveButton( | ||
context.getString(R.string.webview_version_check_alert_dialog_positive_button_title) | ||
) { _, _ -> | ||
redirectToAndroidSystemWebViewStorePage() | ||
} | ||
|
||
val dialog = builder.create() | ||
dialog.show() | ||
} | ||
|
||
private fun redirectToAndroidSystemWebViewStorePage() { | ||
val uri = Uri.parse("market://details?id=$packageName") | ||
val intent = Intent(Intent.ACTION_VIEW, uri) | ||
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK | ||
|
||
try { | ||
context.startActivity(intent) | ||
} catch (e: android.content.ActivityNotFoundException) { | ||
redirectToPlayStoreWebsiteForAndroidSystemWebView() | ||
} | ||
} | ||
|
||
private fun redirectToPlayStoreWebsiteForAndroidSystemWebView() { | ||
val playStoreWebUri = Uri.parse("https://play.google.com/store/apps/details?id=$packageName") | ||
val webIntent = Intent(Intent.ACTION_VIEW, playStoreWebUri) | ||
context.startActivity(webIntent) | ||
} | ||
|
||
private fun getCurrentWebViewMajorVersion(): String? { | ||
val pm: PackageManager = context.packageManager | ||
|
||
return try { | ||
val pi = pm.getPackageInfo("com.google.android.webview", 0) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. During my tests, this line consistently throws I've been able to reproduce this using the following configurations:
In that case, one would also have to consider third party SystemWebView implementations, such as Bromite, for example. However, because the calling functions returns |
||
val fullVersion = pi.versionName | ||
|
||
// Split the version string by "." and get the first part | ||
val versionParts = fullVersion.split("\\.".toRegex()).dropLastWhile { it.isEmpty() } | ||
.toTypedArray() | ||
|
||
if (versionParts.isNotEmpty()) { | ||
versionParts[0] | ||
} else { | ||
null | ||
} | ||
} catch (e: PackageManager.NameNotFoundException) { | ||
null | ||
} | ||
} | ||
|
||
/** | ||
* Ideally we should fetch from database, reading actual value | ||
* from PlayStore not feasible due to frequently api changes made by | ||
* | ||
*/ | ||
private fun getMinimumSupportedMajorWebViewVersion(): String { | ||
return "118" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @AndyScherzinger @tobiasKaminsky Can we get that value from backend? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Server doesn't have/know this. So we could for the moment hard-code this on client-side and bump it per major release of the server. |
||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A very similar function already exists in
DrawerActivity.java
, calledopenAppStore()
. Currently its visibility is set to private. Would it be possible to consolidate this functionality?