From 61957c33cd2086ffffa65869ffd46a8e7ae1181b Mon Sep 17 00:00:00 2001 From: Marvin W Date: Tue, 1 Feb 2022 13:24:54 +0100 Subject: [PATCH 1/5] ProfileManager: Allow overriding User-Agent in WebView --- .../gms/firebase/auth/ReCaptchaActivity.kt | 4 ++++ .../gms/firebase/auth/ReCaptchaOverlay.kt | 9 ++++++--- .../kotlin/org/microg/gms/profile/Build.kt | 12 ++++++++---- .../microg/gms/auth/login/LoginActivity.java | 18 ++++++++++-------- .../microg/gms/safetynet/ReCaptchaActivity.kt | 4 ++++ 5 files changed, 32 insertions(+), 15 deletions(-) diff --git a/firebase-auth-core/src/main/kotlin/org/microg/gms/firebase/auth/ReCaptchaActivity.kt b/firebase-auth-core/src/main/kotlin/org/microg/gms/firebase/auth/ReCaptchaActivity.kt index 784d4298..18554037 100644 --- a/firebase-auth-core/src/main/kotlin/org/microg/gms/firebase/auth/ReCaptchaActivity.kt +++ b/firebase-auth-core/src/main/kotlin/org/microg/gms/firebase/auth/ReCaptchaActivity.kt @@ -18,6 +18,8 @@ import android.webkit.WebSettings import android.webkit.WebView import androidx.appcompat.app.AppCompatActivity import org.microg.gms.firebase.auth.core.R +import org.microg.gms.profile.Build +import org.microg.gms.profile.ProfileManager import kotlin.coroutines.resume import kotlin.coroutines.resumeWithException import kotlin.coroutines.suspendCoroutine @@ -47,6 +49,8 @@ class ReCaptchaActivity : AppCompatActivity() { settings.setSupportZoom(false) settings.displayZoomControls = false settings.cacheMode = WebSettings.LOAD_NO_CACHE + ProfileManager.ensureInitialized(this) + settings.userAgentString = Build.generateWebViewUserAgentString(settings.userAgentString) view.addJavascriptInterface(object : Any() { @JavascriptInterface fun onReCaptchaToken(token: String) { diff --git a/firebase-auth-core/src/main/kotlin/org/microg/gms/firebase/auth/ReCaptchaOverlay.kt b/firebase-auth-core/src/main/kotlin/org/microg/gms/firebase/auth/ReCaptchaOverlay.kt index 5af19c68..03da115c 100644 --- a/firebase-auth-core/src/main/kotlin/org/microg/gms/firebase/auth/ReCaptchaOverlay.kt +++ b/firebase-auth-core/src/main/kotlin/org/microg/gms/firebase/auth/ReCaptchaOverlay.kt @@ -7,7 +7,6 @@ package org.microg.gms.firebase.auth import android.content.Context import android.graphics.PixelFormat -import android.os.Build import android.provider.Settings import android.util.DisplayMetrics import android.util.Log @@ -17,6 +16,8 @@ import android.webkit.WebSettings import android.webkit.WebView import android.widget.FrameLayout import org.microg.gms.firebase.auth.core.R +import org.microg.gms.profile.Build +import org.microg.gms.profile.ProfileManager import kotlin.coroutines.Continuation import kotlin.coroutines.resume import kotlin.coroutines.resumeWithException @@ -32,7 +33,7 @@ class ReCaptchaOverlay(val context: Context, val apiKey: String, val hostname: S var container: View? = null private fun show() { - val layoutParamsType = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + val layoutParamsType = if (android.os.Build.VERSION.SDK_INT >= 26) { WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY } else { WindowManager.LayoutParams.TYPE_SYSTEM_ALERT @@ -80,6 +81,8 @@ class ReCaptchaOverlay(val context: Context, val apiKey: String, val hostname: S settings.setSupportZoom(false) settings.displayZoomControls = false settings.cacheMode = WebSettings.LOAD_NO_CACHE + ProfileManager.ensureInitialized(context) + settings.userAgentString = Build.generateWebViewUserAgentString(settings.userAgentString) view.addJavascriptInterface(object : Any() { @JavascriptInterface fun onReCaptchaToken(token: String) { @@ -110,7 +113,7 @@ class ReCaptchaOverlay(val context: Context, val apiKey: String, val hostname: S } companion object { - fun isSupported(context: Context): Boolean = Build.VERSION.SDK_INT < Build.VERSION_CODES.M || Settings.canDrawOverlays(context) + fun isSupported(context: Context): Boolean = android.os.Build.VERSION.SDK_INT < 23 || Settings.canDrawOverlays(context) suspend fun awaitToken(context: Context, apiKey: String, hostname: String? = null) = suspendCoroutine { continuation -> ReCaptchaOverlay(context, apiKey, hostname ?: "localhost:5000", continuation).show() diff --git a/play-services-base-core/src/main/kotlin/org/microg/gms/profile/Build.kt b/play-services-base-core/src/main/kotlin/org/microg/gms/profile/Build.kt index c13a4d5a..a52059a9 100644 --- a/play-services-base-core/src/main/kotlin/org/microg/gms/profile/Build.kt +++ b/play-services-base-core/src/main/kotlin/org/microg/gms/profile/Build.kt @@ -1,14 +1,11 @@ /* - * SPDX-FileCopyrightText: 2021, microG Project Team + * SPDX-FileCopyrightText: 2021 microG Project Team * SPDX-License-Identifier: Apache-2.0 */ package org.microg.gms.profile import android.annotation.TargetApi -import android.content.Context -import android.os.Build -import kotlin.random.Random object Build { @JvmField @@ -94,4 +91,11 @@ object Build { @JvmField var SECURITY_PATCH: String? = null } + + fun generateWebViewUserAgentString(original: String): String { + if (!original.startsWith("Mozilla/5.0 (")) return original + val closeParen: Int = original.indexOf(')') + + return "Mozilla/5.0 (Linux; Android ${VERSION.RELEASE}; $MODEL Build/$ID; wv)${original.substring(closeParen + 1)}" + } } diff --git a/play-services-core/src/main/java/org/microg/gms/auth/login/LoginActivity.java b/play-services-core/src/main/java/org/microg/gms/auth/login/LoginActivity.java index d139f244..7c913e62 100644 --- a/play-services-core/src/main/java/org/microg/gms/auth/login/LoginActivity.java +++ b/play-services-core/src/main/java/org/microg/gms/auth/login/LoginActivity.java @@ -25,7 +25,6 @@ import android.graphics.Color; import android.net.ConnectivityManager; import android.net.NetworkInfo; import android.net.Uri; -import android.os.Build; import android.os.Bundle; import android.text.TextUtils; import android.util.Log; @@ -37,11 +36,11 @@ import android.webkit.CookieManager; import android.webkit.JavascriptInterface; import android.webkit.WebSettings; import android.webkit.WebView; -import android.webkit.WebViewClient; import android.widget.RelativeLayout; import android.widget.TextView; import androidx.annotation.StringRes; +import androidx.webkit.WebViewClientCompat; import com.google.android.gms.R; @@ -55,6 +54,8 @@ import org.microg.gms.checkin.LastCheckinInfo; import org.microg.gms.common.HttpFormClient; import org.microg.gms.common.Utils; import org.microg.gms.people.PeopleManager; +import org.microg.gms.profile.Build; +import org.microg.gms.profile.ProfileManager; import java.io.IOException; import java.util.Locale; @@ -106,7 +107,7 @@ public class LoginActivity extends AssistantActivity { webView.addJavascriptInterface(new JsBridge(), "mm"); authContent = (ViewGroup) findViewById(R.id.auth_content); ((ViewGroup) findViewById(R.id.auth_root)).addView(webView); - webView.setWebViewClient(new WebViewClient() { + webView.setWebViewClient(new WebViewClientCompat() { @Override public void onPageFinished(WebView view, String url) { Log.d(TAG, "pageFinished: " + view.getUrl()); @@ -135,14 +136,14 @@ public class LoginActivity extends AssistantActivity { AccountManager accountManager = AccountManager.get(this); Account account = new Account(getIntent().getStringExtra(EXTRA_EMAIL), accountType); accountManager.addAccountExplicitly(account, getIntent().getStringExtra(EXTRA_TOKEN), null); - if (isAuthVisible(this) && SDK_INT >= Build.VERSION_CODES.O) { + if (isAuthVisible(this) && SDK_INT >= 26) { accountManager.setAccountVisibility(account, PACKAGE_NAME_KEY_LEGACY_NOT_VISIBLE, VISIBILITY_USER_MANAGED_VISIBLE); } retrieveGmsToken(account); } else { retrieveRtToken(getIntent().getStringExtra(EXTRA_TOKEN)); } - } else if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { + } else if (android.os.Build.VERSION.SDK_INT < 21) { init(); } else { setMessage(R.string.auth_before_connect); @@ -200,13 +201,14 @@ public class LoginActivity extends AssistantActivity { webView.setLayoutParams(new RelativeLayout.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); webView.setBackgroundColor(Color.TRANSPARENT); - prepareWebViewSettings(webView.getSettings()); + prepareWebViewSettings(context, webView.getSettings()); return webView; } @SuppressLint("SetJavaScriptEnabled") - private static void prepareWebViewSettings(WebSettings settings) { - settings.setUserAgentString(settings.getUserAgentString() + MAGIC_USER_AGENT); + private static void prepareWebViewSettings(Context context, WebSettings settings) { + ProfileManager.ensureInitialized(context); + settings.setUserAgentString(Build.INSTANCE.generateWebViewUserAgentString(settings.getUserAgentString()) + MAGIC_USER_AGENT); settings.setJavaScriptEnabled(true); settings.setSupportMultipleWindows(false); settings.setSaveFormData(false); diff --git a/play-services-safetynet-core-ui/src/main/kotlin/org/microg/gms/safetynet/ReCaptchaActivity.kt b/play-services-safetynet-core-ui/src/main/kotlin/org/microg/gms/safetynet/ReCaptchaActivity.kt index 9808fcc5..7c512f64 100644 --- a/play-services-safetynet-core-ui/src/main/kotlin/org/microg/gms/safetynet/ReCaptchaActivity.kt +++ b/play-services-safetynet-core-ui/src/main/kotlin/org/microg/gms/safetynet/ReCaptchaActivity.kt @@ -22,6 +22,8 @@ import androidx.lifecycle.lifecycleScope import androidx.webkit.WebViewClientCompat import com.google.android.gms.safetynet.SafetyNetStatusCodes.* import org.microg.gms.droidguard.core.DroidGuardResultCreator +import org.microg.gms.profile.Build +import org.microg.gms.profile.ProfileManager import org.microg.gms.safetynet.core.ui.R import java.io.ByteArrayInputStream import java.net.URLEncoder @@ -92,6 +94,8 @@ class ReCaptchaActivity : AppCompatActivity() { displayZoomControls = false setSupportZoom(false) cacheMode = WebSettings.LOAD_NO_CACHE + ProfileManager.ensureInitialized(this@ReCaptchaActivity) + userAgentString = Build.generateWebViewUserAgentString(userAgentString) } addJavascriptInterface(object { @JavascriptInterface From 75aaeb1fc65c2e349007f78898c04e045e1d830c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Hetk=C3=A4mper?= Date: Tue, 1 Feb 2022 00:06:04 +0100 Subject: [PATCH 2/5] ENF: Fix average RSSI calculation Correctly discard new measurements when the reported timestamp is older than the timestamp in the database. Fixes https://github.com/microg/GmsCore/issues/1655. --- .../microg/gms/nearby/exposurenotification/ExposureDatabase.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/play-services-nearby-core/src/main/kotlin/org/microg/gms/nearby/exposurenotification/ExposureDatabase.kt b/play-services-nearby-core/src/main/kotlin/org/microg/gms/nearby/exposurenotification/ExposureDatabase.kt index a702a74c..c7ad9ab3 100644 --- a/play-services-nearby-core/src/main/kotlin/org/microg/gms/nearby/exposurenotification/ExposureDatabase.kt +++ b/play-services-nearby-core/src/main/kotlin/org/microg/gms/nearby/exposurenotification/ExposureDatabase.kt @@ -181,7 +181,7 @@ class ExposureDatabase private constructor(private val context: Context) : SQLit } fun noteAdvertisement(rpi: ByteArray, aem: ByteArray, rssi: Int, timestamp: Long = Date().time) = writableDatabase.run { - val update = compileStatement("UPDATE $TABLE_ADVERTISEMENTS SET rssi = IFNULL(((rssi * duration) + (? * MIN(0, ? - timestamp - duration))) / MAX(duration, ? - timestamp), -100), duration = MAX(duration, ? - timestamp) WHERE rpi = ? AND timestamp > ? AND timestamp < ?").run { + val update = compileStatement("UPDATE $TABLE_ADVERTISEMENTS SET rssi = IFNULL(((rssi * duration) + (? * MAX(0, ? - timestamp - duration))) / MAX(duration, ? - timestamp), -100), duration = MAX(duration, ? - timestamp) WHERE rpi = ? AND timestamp > ? AND timestamp < ?").run { bindLong(1, rssi.toLong()) bindLong(2, timestamp) bindLong(3, timestamp) From adf534d20a56160b2d62644f44e77426ba42fef1 Mon Sep 17 00:00:00 2001 From: Marvin W Date: Tue, 1 Feb 2022 14:47:52 +0100 Subject: [PATCH 3/5] ENF: Replace invalid RSSI values in database --- .../gms/nearby/exposurenotification/ExposureDatabase.kt | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/play-services-nearby-core/src/main/kotlin/org/microg/gms/nearby/exposurenotification/ExposureDatabase.kt b/play-services-nearby-core/src/main/kotlin/org/microg/gms/nearby/exposurenotification/ExposureDatabase.kt index c7ad9ab3..6c340751 100644 --- a/play-services-nearby-core/src/main/kotlin/org/microg/gms/nearby/exposurenotification/ExposureDatabase.kt +++ b/play-services-nearby-core/src/main/kotlin/org/microg/gms/nearby/exposurenotification/ExposureDatabase.kt @@ -130,6 +130,12 @@ class ExposureDatabase private constructor(private val context: Context) : SQLit Log.d(TAG, "Get rid of isEnabled log entries") db.delete(TABLE_APP_LOG, "method = ?", arrayOf("isEnabled")); } + if (oldVersion == 11) { + Log.d(TAG, "Fixing invalid rssi values from version 11 with release 0.2.23") + // Setting the RSSI to -75. This is obviously not the correct value, but is still way better estimate + // than 0, based on the measurements shown in https://github.com/microg/GmsCore/issues/1655 + db.execSQL("UPDATE $TABLE_ADVERTISEMENTS SET rssi = -75 WHERE rssi = 0 AND duration > 0") + } Log.d(TAG, "Finished database upgrade") } @@ -835,7 +841,7 @@ class ExposureDatabase private constructor(private val context: Context) : SQLit companion object { private const val DB_NAME = "exposure.db" - private const val DB_VERSION = 11 + private const val DB_VERSION = 12 private const val DB_SIZE_TOO_LARGE = 256L * 1024 * 1024 private const val MAX_DELETE_TIME = 5000L private const val TABLE_ADVERTISEMENTS = "advertisements" From 17b8371b489f919d6ff87607c4a289b0af38d159 Mon Sep 17 00:00:00 2001 From: Marvin W Date: Tue, 1 Feb 2022 20:23:12 +0100 Subject: [PATCH 4/5] Update UnifiedNlp version --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 940da53a..dfc12670 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ buildscript { ext.cronetVersion = '91.0.4472.120.1' - ext.nlpVersion = '2.0-alpha7' + ext.nlpVersion = '2.0-alpha8' ext.safeParcelVersion = '1.7.0' ext.wearableVersion = '0.1.1' From a33a62ac79f59bb33945f000be575aac15e24dd0 Mon Sep 17 00:00:00 2001 From: Oizaro <98434320+Oizaro@users.noreply.github.com> Date: Sat, 5 Feb 2022 12:44:50 +0100 Subject: [PATCH 5/5] MicroG 0.2.24.220220 --- build.gradle | 6 +-- .../gms/clearcut/LogEventParcelable.java | 1 - .../framework/media/NotificationOptions.java | 2 - play-services-core/build.gradle | 1 + .../microg/gms/auth/login/LoginActivity.java | 28 +++++------ .../java/org/microg/gms/gcm/McsService.java | 47 ++++++++++++------- .../kotlin/org/microg/gms/profile/Build.kt | 9 +++- .../internal/LocationRequestUpdateData.java | 1 - 8 files changed, 55 insertions(+), 40 deletions(-) diff --git a/build.gradle b/build.gradle index b6dea5be..ffa3adc3 100644 --- a/build.gradle +++ b/build.gradle @@ -14,7 +14,7 @@ buildscript { } dependencies { - classpath 'com.android.tools.build:gradle:7.1.0' + classpath 'com.android.tools.build:gradle:7.1.1' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.10" classpath "com.squareup.wire:wire-gradle-plugin:3.2.2" } @@ -24,8 +24,8 @@ allprojects { apply plugin: 'idea' group = 'org.microg.gms' - version = "0.2.23.220217" - ext.appVersionCode = 220217001 + version = "0.2.24.220220" + ext.appVersionCode = 220220001 ext.isReleaseVersion = false } diff --git a/play-services-api/src/main/java/com/google/android/gms/clearcut/LogEventParcelable.java b/play-services-api/src/main/java/com/google/android/gms/clearcut/LogEventParcelable.java index f275f206..cb9cb2ec 100644 --- a/play-services-api/src/main/java/com/google/android/gms/clearcut/LogEventParcelable.java +++ b/play-services-api/src/main/java/com/google/android/gms/clearcut/LogEventParcelable.java @@ -27,7 +27,6 @@ import org.microg.safeparcel.AutoSafeParcelable; import java.nio.ByteBuffer; import java.nio.CharBuffer; -import java.nio.charset.Charset; import java.nio.charset.CharsetDecoder; import java.nio.charset.StandardCharsets; import java.util.Arrays; diff --git a/play-services-cast-framework-api/src/main/java/com/google/android/gms/cast/framework/media/NotificationOptions.java b/play-services-cast-framework-api/src/main/java/com/google/android/gms/cast/framework/media/NotificationOptions.java index e0949265..b6960149 100644 --- a/play-services-cast-framework-api/src/main/java/com/google/android/gms/cast/framework/media/NotificationOptions.java +++ b/play-services-cast-framework-api/src/main/java/com/google/android/gms/cast/framework/media/NotificationOptions.java @@ -16,8 +16,6 @@ package com.google.android.gms.cast.framework.media; -import com.google.android.gms.cast.framework.media.INotificationActionsProvider; - import org.microg.safeparcel.AutoSafeParcelable; import java.util.List; diff --git a/play-services-core/build.gradle b/play-services-core/build.gradle index 16d32fcd..a5a44232 100644 --- a/play-services-core/build.gradle +++ b/play-services-core/build.gradle @@ -22,6 +22,7 @@ dependencies { implementation 'com.squareup.wire:wire-runtime:3.6.1' implementation 'de.hdodenhof:circleimageview:3.1.0' implementation "info.armills.chromecast-java-api-v2:api-v2-raw-request:0.10.4-raw-request-1" + implementation 'androidx.webkit:webkit:1.4.0' implementation project(':play-services-cronet-core') implementation project(':play-services-core-proto') diff --git a/play-services-core/src/main/java/org/microg/gms/auth/login/LoginActivity.java b/play-services-core/src/main/java/org/microg/gms/auth/login/LoginActivity.java index 7e090360..5b6aaca7 100644 --- a/play-services-core/src/main/java/org/microg/gms/auth/login/LoginActivity.java +++ b/play-services-core/src/main/java/org/microg/gms/auth/login/LoginActivity.java @@ -19,9 +19,6 @@ package org.microg.gms.auth.login; import static android.accounts.AccountManager.PACKAGE_NAME_KEY_LEGACY_NOT_VISIBLE; import static android.accounts.AccountManager.VISIBILITY_USER_MANAGED_VISIBLE; import static android.os.Build.VERSION.SDK_INT; -import static android.os.Build.VERSION_CODES.GINGERBREAD_MR1; -import static android.os.Build.VERSION_CODES.HONEYCOMB; -import static android.os.Build.VERSION_CODES.LOLLIPOP; import static android.telephony.TelephonyManager.SIM_STATE_UNKNOWN; import static android.view.KeyEvent.KEYCODE_BACK; import static android.view.View.INVISIBLE; @@ -37,13 +34,11 @@ import static org.microg.gms.common.Constants.GMS_VERSION_CODE; import android.accounts.Account; import android.accounts.AccountManager; import android.annotation.SuppressLint; -import android.annotation.TargetApi; import android.content.Context; import android.graphics.Color; import android.net.ConnectivityManager; import android.net.NetworkInfo; import android.net.Uri; -import android.os.Build; import android.os.Bundle; import android.text.TextUtils; import android.util.Log; @@ -55,11 +50,11 @@ import android.webkit.CookieManager; import android.webkit.JavascriptInterface; import android.webkit.WebSettings; import android.webkit.WebView; -import android.webkit.WebViewClient; import android.widget.RelativeLayout; import android.widget.TextView; import androidx.annotation.StringRes; +import androidx.webkit.WebViewClientCompat; import com.mgoogle.android.gms.R; @@ -73,6 +68,8 @@ import org.microg.gms.checkin.LastCheckinInfo; import org.microg.gms.common.HttpFormClient; import org.microg.gms.common.Utils; import org.microg.gms.people.PeopleManager; +import org.microg.gms.profile.Build; +import org.microg.gms.profile.ProfileManager; import org.microg.gms.ui.UtilsKt; import java.io.IOException; @@ -113,7 +110,7 @@ public class LoginActivity extends AssistantActivity { webView.addJavascriptInterface(new JsBridge(), "mm"); authContent = (ViewGroup) findViewById(R.id.auth_content); ((ViewGroup) findViewById(R.id.auth_root)).addView(webView); - webView.setWebViewClient(new WebViewClient() { + webView.setWebViewClient(new WebViewClientCompat() { @Override public void onPageFinished(WebView view, String url) { Log.d(TAG, "pageFinished: " + view.getUrl()); @@ -142,7 +139,7 @@ public class LoginActivity extends AssistantActivity { AccountManager accountManager = AccountManager.get(this); Account account = new Account(getIntent().getStringExtra(EXTRA_EMAIL), accountType); accountManager.addAccountExplicitly(account, getIntent().getStringExtra(EXTRA_TOKEN), null); - if (isAuthVisible(this) && SDK_INT >= Build.VERSION_CODES.O) { + if (isAuthVisible(this) && SDK_INT >= 26) { accountManager.setAccountVisibility(account, PACKAGE_NAME_KEY_LEGACY_NOT_VISIBLE, VISIBILITY_USER_MANAGED_VISIBLE); } retrieveGmsToken(account); @@ -162,7 +159,7 @@ public class LoginActivity extends AssistantActivity { super.onHuaweiButtonClicked(); state++; if (state == 1) { - if (SDK_INT >= Build.VERSION_CODES.M) { + if (SDK_INT >= 23) { hideLauncherIcon(this, false); UtilsKt.hideIcon(this, false); } @@ -212,7 +209,7 @@ public class LoginActivity extends AssistantActivity { authContent.addView(loading); setMessage(R.string.auth_connecting); CookieManager.getInstance().setAcceptCookie(true); - if (SDK_INT >= LOLLIPOP) { + if (SDK_INT >= 21) { CookieManager.getInstance().removeAllCookies(value -> start()); } else { //noinspection deprecation @@ -223,7 +220,7 @@ public class LoginActivity extends AssistantActivity { private static WebView createWebView(Context context) { WebView webView = new WebView(context); - if (SDK_INT < LOLLIPOP) { + if (SDK_INT < 21) { webView.setVisibility(VISIBLE); } else { webView.setVisibility(INVISIBLE); @@ -231,13 +228,14 @@ public class LoginActivity extends AssistantActivity { webView.setLayoutParams(new RelativeLayout.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); webView.setBackgroundColor(Color.TRANSPARENT); - prepareWebViewSettings(webView.getSettings()); + prepareWebViewSettings(context, webView.getSettings()); return webView; } @SuppressLint("SetJavaScriptEnabled") - private static void prepareWebViewSettings(WebSettings settings) { - settings.setUserAgentString(settings.getUserAgentString() + MAGIC_USER_AGENT); + private static void prepareWebViewSettings(Context context, WebSettings settings) { + ProfileManager.ensureInitialized(context); + settings.setUserAgentString(Build.INSTANCE.generateWebViewUserAgentString(settings.getUserAgentString()) + MAGIC_USER_AGENT); settings.setJavaScriptEnabled(true); settings.setSupportMultipleWindows(false); settings.setSaveFormData(false); @@ -544,10 +542,8 @@ public class LoginActivity extends AssistantActivity { Log.d(TAG, "JSBridge: setAccountIdentifier"); } - @TargetApi(HONEYCOMB) @JavascriptInterface public final void setBackButtonEnabled(boolean backButtonEnabled) { - if (SDK_INT <= GINGERBREAD_MR1) return; int visibility = getWindow().getDecorView().getSystemUiVisibility(); if (backButtonEnabled) visibility &= -STATUS_BAR_DISABLE_BACK; diff --git a/play-services-core/src/main/java/org/microg/gms/gcm/McsService.java b/play-services-core/src/main/java/org/microg/gms/gcm/McsService.java index 8a67b886..cd6472a3 100644 --- a/play-services-core/src/main/java/org/microg/gms/gcm/McsService.java +++ b/play-services-core/src/main/java/org/microg/gms/gcm/McsService.java @@ -120,7 +120,11 @@ public class McsService extends Service implements Handler.Callback { public static final String FROM_FIELD = "gcm@android.com"; public static final String SERVICE_HOST = "mtalk.google.com"; + // A few ports are available: 443, 5228-5230 but also 5222-5223 + // See https://github.com/microg/GmsCore/issues/408 public static final int SERVICE_PORT = 5228; + // Likely if the main port 5228 is blocked by a firewall, the other 52xx are blocked as well + public static final int SERVICE_PORT_FALLBACK = 443; private static final int WAKELOCK_TIMEOUT = 5000; // On bad mobile network a ping can take >60s, so we wait for an ACK for 90s @@ -440,24 +444,15 @@ public class McsService extends Service implements Handler.Callback { } } - private synchronized void connect() { + private boolean connect(int port) { try { - closeAll(); - ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); - NetworkInfo activeNetworkInfo = cm.getActiveNetworkInfo(); - activeNetworkPref = GcmPrefs.get(this).getNetworkPrefForInfo(activeNetworkInfo); - if (!GcmPrefs.get(this).isEnabledFor(activeNetworkInfo)) { - logd(this, "Don't connect, because disabled for " + activeNetworkInfo.getTypeName()); - scheduleReconnect(this); - return; - } wasTornDown = false; - logd(this, "Starting MCS connection..."); - Socket socket = new Socket(SERVICE_HOST, SERVICE_PORT); - logd(this, "Connected to " + SERVICE_HOST + ":" + SERVICE_PORT); - sslSocket = SSLContext.getDefault().getSocketFactory().createSocket(socket, SERVICE_HOST, SERVICE_PORT, true); - logd(this, "Activated SSL with " + SERVICE_HOST + ":" + SERVICE_PORT); + logd(this, "Starting MCS connection to port " + port + "..."); + Socket socket = new Socket(SERVICE_HOST, port); + logd(this, "Connected to " + SERVICE_HOST + ":" + port); + sslSocket = SSLContext.getDefault().getSocketFactory().createSocket(socket, SERVICE_HOST, port, true); + logd(this, "Activated SSL with " + SERVICE_HOST + ":" + port); inputStream = new McsInputStream(sslSocket.getInputStream(), rootHandler); outputStream = new McsOutputStream(sslSocket.getOutputStream(), rootHandler); inputStream.start(); @@ -469,9 +464,29 @@ public class McsService extends Service implements Handler.Callback { lastIncomingNetworkRealtime = SystemClock.elapsedRealtime(); scheduleHeartbeat(this); } catch (Exception e) { - Log.w(TAG, "Exception while connecting!", e); + Log.w(TAG, "Exception while connecting to " + SERVICE_HOST + ":" + port, e); rootHandler.sendMessage(rootHandler.obtainMessage(MSG_TEARDOWN, e)); + closeAll(); + return false; } + + return true; + } + + private synchronized void connect() { + closeAll(); + + ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); + NetworkInfo activeNetworkInfo = cm.getActiveNetworkInfo(); + activeNetworkPref = GcmPrefs.get(this).getNetworkPrefForInfo(activeNetworkInfo); + if (!GcmPrefs.get(this).isEnabledFor(activeNetworkInfo)) { + logd(this, "Don't connect, because disabled for " + activeNetworkInfo.getTypeName()); + scheduleReconnect(this); + return; + } + + if (!connect(SERVICE_PORT)) + connect(SERVICE_PORT_FALLBACK); } private void handleClose(Close close) { diff --git a/play-services-core/src/main/kotlin/org/microg/gms/profile/Build.kt b/play-services-core/src/main/kotlin/org/microg/gms/profile/Build.kt index ffaeda10..a52059a9 100644 --- a/play-services-core/src/main/kotlin/org/microg/gms/profile/Build.kt +++ b/play-services-core/src/main/kotlin/org/microg/gms/profile/Build.kt @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2021, microG Project Team + * SPDX-FileCopyrightText: 2021 microG Project Team * SPDX-License-Identifier: Apache-2.0 */ @@ -91,4 +91,11 @@ object Build { @JvmField var SECURITY_PATCH: String? = null } + + fun generateWebViewUserAgentString(original: String): String { + if (!original.startsWith("Mozilla/5.0 (")) return original + val closeParen: Int = original.indexOf(')') + + return "Mozilla/5.0 (Linux; Android ${VERSION.RELEASE}; $MODEL Build/$ID; wv)${original.substring(closeParen + 1)}" + } } diff --git a/play-services-location-api/src/main/java/com/google/android/gms/location/internal/LocationRequestUpdateData.java b/play-services-location-api/src/main/java/com/google/android/gms/location/internal/LocationRequestUpdateData.java index 6da81cc3..41c1edb8 100644 --- a/play-services-location-api/src/main/java/com/google/android/gms/location/internal/LocationRequestUpdateData.java +++ b/play-services-location-api/src/main/java/com/google/android/gms/location/internal/LocationRequestUpdateData.java @@ -20,7 +20,6 @@ import android.app.PendingIntent; import com.google.android.gms.location.ILocationCallback; import com.google.android.gms.location.ILocationListener; -import com.google.android.gms.location.internal.IFusedLocationProviderCallback; import org.microg.safeparcel.AutoSafeParcelable; import org.microg.safeparcel.SafeParceled;