445 lines
20 KiB
Diff
445 lines
20 KiB
Diff
From: csagan5 <32685696+csagan5@users.noreply.github.com>
|
|
Date: Sun, 3 Nov 2019 08:22:29 +0100
|
|
Subject: Remove SMS integration
|
|
|
|
License: GPL-3.0-only - https://spdx.org/licenses/GPL-3.0-only.html
|
|
---
|
|
.../browser/language/AppLocaleUtils.java | 46 -------
|
|
.../content/browser/sms/SmsProviderGms.java | 29 +----
|
|
.../browser/sms/SmsUserConsentReceiver.java | 49 +------
|
|
.../browser/sms/SmsVerificationReceiver.java | 122 +-----------------
|
|
.../content/browser/sms/Wrappers.java | 30 +----
|
|
5 files changed, 8 insertions(+), 268 deletions(-)
|
|
|
|
diff --git a/chrome/browser/language/android/java/src/org/chromium/chrome/browser/language/AppLocaleUtils.java b/chrome/browser/language/android/java/src/org/chromium/chrome/browser/language/AppLocaleUtils.java
|
|
--- a/chrome/browser/language/android/java/src/org/chromium/chrome/browser/language/AppLocaleUtils.java
|
|
+++ b/chrome/browser/language/android/java/src/org/chromium/chrome/browser/language/AppLocaleUtils.java
|
|
@@ -127,52 +127,6 @@ public class AppLocaleUtils {
|
|
return Locale.forLanguageTag("en-US");
|
|
}
|
|
|
|
- /**
|
|
- * Download the language split. If successful set the application language shared preference.
|
|
- * If set to null the system language will be used.
|
|
- * @param languageName String BCP-47 code of language to download.
|
|
- */
|
|
- public static void setAppLanguagePref(String languageName) {
|
|
- setAppLanguagePref(languageName, success -> {});
|
|
- }
|
|
-
|
|
- /**
|
|
- * Download the language split using the provided listener for callbacks. If successful set the
|
|
- * application language shared preference. If called from an APK build where no bundle needs to
|
|
- * be downloaded the listener's on complete function is immediately called. If languageName is
|
|
- * null the system language will be used.
|
|
- * @param languageName String BCP-47 code of language to download.
|
|
- * @param listener LanguageSplitInstaller.InstallListener to use for callbacks.
|
|
- */
|
|
- public static void setAppLanguagePref(
|
|
- @Nullable String languageName, LanguageSplitInstaller.InstallListener listener) {
|
|
- // Wrap the install listener so that on success the app override preference is set.
|
|
- LanguageSplitInstaller.InstallListener wrappedListener =
|
|
- (success) -> {
|
|
- if (success) {
|
|
- if (shouldUseSystemManagedLocale()) {
|
|
- setSystemManagedAppLanguage(languageName);
|
|
- } else {
|
|
- ChromeSharedPreferences.getInstance()
|
|
- .writeString(
|
|
- ChromePreferenceKeys.APPLICATION_OVERRIDE_LANGUAGE,
|
|
- languageName);
|
|
- }
|
|
- }
|
|
- listener.onComplete(success);
|
|
- };
|
|
-
|
|
- // If the default system language is being used the language split should not be installed.
|
|
- // Instead indicate that the listener completed successfully since the language resources
|
|
- // will already be present.
|
|
- if (BuildConfig.IS_FOR_TEST || isFollowSystemLanguage(languageName)) {
|
|
- wrappedListener.onComplete(true);
|
|
- } else {
|
|
- assert languageName != null;
|
|
- LanguageSplitInstaller.getInstance().installLanguage(languageName, wrappedListener);
|
|
- }
|
|
- }
|
|
-
|
|
/** Sets the {@link LocaleManager} App language to |languageName|. */
|
|
@RequiresApi(Build.VERSION_CODES.TIRAMISU)
|
|
private static void setSystemManagedAppLanguage(@Nullable String languageName) {
|
|
diff --git a/content/public/android/java/src/org/chromium/content/browser/sms/SmsProviderGms.java b/content/public/android/java/src/org/chromium/content/browser/sms/SmsProviderGms.java
|
|
--- a/content/public/android/java/src/org/chromium/content/browser/sms/SmsProviderGms.java
|
|
+++ b/content/public/android/java/src/org/chromium/content/browser/sms/SmsProviderGms.java
|
|
@@ -6,9 +6,6 @@ package org.chromium.content.browser.sms;
|
|
|
|
import androidx.annotation.VisibleForTesting;
|
|
|
|
-import com.google.android.gms.common.ConnectionResult;
|
|
-import com.google.android.gms.common.GoogleApiAvailability;
|
|
-
|
|
import org.jni_zero.CalledByNative;
|
|
import org.jni_zero.JNINamespace;
|
|
import org.jni_zero.NativeMethods;
|
|
@@ -50,17 +47,11 @@ public class SmsProviderGms {
|
|
public SmsProviderGms(
|
|
long smsProviderGmsAndroid,
|
|
@GmsBackend int backend,
|
|
- boolean isVerificationBackendAvailable) {
|
|
+ boolean ignored) {
|
|
mSmsProviderGmsAndroid = smsProviderGmsAndroid;
|
|
mBackend = backend;
|
|
mContext = new Wrappers.WebOTPServiceContext(ContextUtils.getApplicationContext(), this);
|
|
|
|
- // Creates an mVerificationReceiver regardless of the backend to support requests from
|
|
- // remote devices.
|
|
- if (isVerificationBackendAvailable) {
|
|
- mVerificationReceiver = new SmsVerificationReceiver(this, mContext);
|
|
- }
|
|
-
|
|
if (mBackend == GmsBackend.AUTO || mBackend == GmsBackend.USER_CONSENT) {
|
|
mUserConsentReceiver = new SmsUserConsentReceiver(this, mContext);
|
|
}
|
|
@@ -92,13 +83,7 @@ public class SmsProviderGms {
|
|
@CalledByNative
|
|
private static SmsProviderGms create(long smsProviderGmsAndroid, @GmsBackend int backend) {
|
|
Log.d(TAG, "Creating SmsProviderGms");
|
|
- boolean isVerificationBackendAvailable =
|
|
- GoogleApiAvailability.getInstance()
|
|
- .isGooglePlayServicesAvailable(
|
|
- ContextUtils.getApplicationContext(),
|
|
- MIN_GMS_VERSION_NUMBER_WITH_CODE_BROWSER_BACKEND)
|
|
- == ConnectionResult.SUCCESS;
|
|
- return new SmsProviderGms(smsProviderGmsAndroid, backend, isVerificationBackendAvailable);
|
|
+ return new SmsProviderGms(smsProviderGmsAndroid, backend, false);
|
|
}
|
|
|
|
@CalledByNative
|
|
@@ -194,16 +179,6 @@ public class SmsProviderGms {
|
|
}
|
|
|
|
public Wrappers.SmsRetrieverClientWrapper getClient() {
|
|
- if (mClient != null) {
|
|
- return mClient;
|
|
- }
|
|
- mClient =
|
|
- new Wrappers.SmsRetrieverClientWrapper(
|
|
- mUserConsentReceiver != null ? mUserConsentReceiver.createClient() : null,
|
|
- mVerificationReceiver != null
|
|
- ? mVerificationReceiver.createClient()
|
|
- : null);
|
|
-
|
|
return mClient;
|
|
}
|
|
|
|
diff --git a/content/public/android/java/src/org/chromium/content/browser/sms/SmsUserConsentReceiver.java b/content/public/android/java/src/org/chromium/content/browser/sms/SmsUserConsentReceiver.java
|
|
--- a/content/public/android/java/src/org/chromium/content/browser/sms/SmsUserConsentReceiver.java
|
|
+++ b/content/public/android/java/src/org/chromium/content/browser/sms/SmsUserConsentReceiver.java
|
|
@@ -12,13 +12,6 @@ import android.content.Context;
|
|
import android.content.Intent;
|
|
import android.content.IntentFilter;
|
|
|
|
-import com.google.android.gms.auth.api.phone.SmsRetriever;
|
|
-import com.google.android.gms.auth.api.phone.SmsRetrieverClient;
|
|
-import com.google.android.gms.common.api.CommonStatusCodes;
|
|
-import com.google.android.gms.common.api.Status;
|
|
-import com.google.android.gms.tasks.OnFailureListener;
|
|
-import com.google.android.gms.tasks.Task;
|
|
-
|
|
import org.chromium.base.ContextUtils;
|
|
import org.chromium.base.IntentUtils;
|
|
import org.chromium.base.Log;
|
|
@@ -39,30 +32,12 @@ public class SmsUserConsentReceiver extends BroadcastReceiver {
|
|
mDestroyed = false;
|
|
mProvider = provider;
|
|
mContext = context;
|
|
-
|
|
- // A broadcast receiver is registered upon the creation of this class
|
|
- // which happens when the SMS Retriever API is used for the first time
|
|
- // since chrome last restarted (which, on android, happens frequently).
|
|
- // The broadcast receiver is fairly lightweight (e.g. it responds
|
|
- // quickly without much computation).
|
|
- // If this broadcast receiver becomes more heavyweight, we should make
|
|
- // this registration expire after the SMS message is received.
|
|
- if (DEBUG) Log.d(TAG, "Registering intent filters.");
|
|
- IntentFilter filter = new IntentFilter();
|
|
- filter.addAction(SmsRetriever.SMS_RETRIEVED_ACTION);
|
|
- ContextUtils.registerExportedBroadcastReceiver(
|
|
- mContext, this, filter, SmsRetriever.SEND_PERMISSION);
|
|
- }
|
|
-
|
|
- public SmsRetrieverClient createClient() {
|
|
- return SmsRetriever.getClient(mContext);
|
|
}
|
|
|
|
public void destroy() {
|
|
if (mDestroyed) return;
|
|
if (DEBUG) Log.d(TAG, "Destroying SmsUserConsentReceiver.");
|
|
mDestroyed = true;
|
|
- mContext.unregisterReceiver(this);
|
|
}
|
|
|
|
@Override
|
|
@@ -73,7 +48,7 @@ public class SmsUserConsentReceiver extends BroadcastReceiver {
|
|
return;
|
|
}
|
|
|
|
- if (!SmsRetriever.SMS_RETRIEVED_ACTION.equals(intent.getAction())) {
|
|
+ /*if (!SmsRetriever.SMS_RETRIEVED_ACTION.equals(intent.getAction())) {
|
|
return;
|
|
}
|
|
|
|
@@ -102,30 +77,14 @@ public class SmsUserConsentReceiver extends BroadcastReceiver {
|
|
if (DEBUG) Log.d(TAG, "Timeout");
|
|
mProvider.onTimeout();
|
|
break;
|
|
- }
|
|
+ } */
|
|
}
|
|
|
|
void onConsentResult(int resultCode, @Nullable Intent data) {
|
|
- if (resultCode == Activity.RESULT_OK) {
|
|
- assumeNonNull(data);
|
|
- String message = data.getStringExtra(SmsRetriever.EXTRA_SMS_MESSAGE);
|
|
- mProvider.onReceive(message, GmsBackend.USER_CONSENT);
|
|
- } else if (resultCode == Activity.RESULT_CANCELED) {
|
|
- if (DEBUG) Log.d(TAG, "Activity result cancelled.");
|
|
- mProvider.onCancel();
|
|
- }
|
|
+ if (DEBUG) Log.d(TAG, "Activity result discarded.");
|
|
}
|
|
|
|
public void listen(WindowAndroid windowAndroid) {
|
|
- Task<Void> task = mProvider.getClient().startSmsUserConsent(null);
|
|
-
|
|
- task.addOnFailureListener(
|
|
- new OnFailureListener() {
|
|
- @Override
|
|
- public void onFailure(Exception e) {
|
|
- Log.e(TAG, "Task failed to start", e);
|
|
- }
|
|
- });
|
|
- if (DEBUG) Log.d(TAG, "Installed task");
|
|
+ if (DEBUG) Log.d(TAG, "Ignored task");
|
|
}
|
|
}
|
|
diff --git a/content/public/android/java/src/org/chromium/content/browser/sms/SmsVerificationReceiver.java b/content/public/android/java/src/org/chromium/content/browser/sms/SmsVerificationReceiver.java
|
|
--- a/content/public/android/java/src/org/chromium/content/browser/sms/SmsVerificationReceiver.java
|
|
+++ b/content/public/android/java/src/org/chromium/content/browser/sms/SmsVerificationReceiver.java
|
|
@@ -15,16 +15,6 @@ import android.content.IntentFilter;
|
|
|
|
import androidx.annotation.IntDef;
|
|
|
|
-import com.google.android.gms.auth.api.phone.SmsCodeBrowserClient;
|
|
-import com.google.android.gms.auth.api.phone.SmsCodeRetriever;
|
|
-import com.google.android.gms.auth.api.phone.SmsRetriever;
|
|
-import com.google.android.gms.auth.api.phone.SmsRetrieverStatusCodes;
|
|
-import com.google.android.gms.common.api.ApiException;
|
|
-import com.google.android.gms.common.api.CommonStatusCodes;
|
|
-import com.google.android.gms.common.api.ResolvableApiException;
|
|
-import com.google.android.gms.common.api.Status;
|
|
-import com.google.android.gms.tasks.Task;
|
|
-
|
|
import org.chromium.base.ContextUtils;
|
|
import org.chromium.base.IntentUtils;
|
|
import org.chromium.base.Log;
|
|
@@ -79,61 +69,13 @@ public class SmsVerificationReceiver extends BroadcastReceiver {
|
|
// lightweight (e.g. it responds quickly without much computation). If this broadcast
|
|
// receiver becomes more heavyweight, we should make this registration expire after the SMS
|
|
// message is received.
|
|
- if (DEBUG) Log.i(TAG, "Registering intent filters.");
|
|
- IntentFilter filter = new IntentFilter();
|
|
- filter.addAction(SmsCodeRetriever.SMS_CODE_RETRIEVED_ACTION);
|
|
-
|
|
- // The SEND_PERMISSION permission is not documented to held by the sender of this broadcast,
|
|
- // but it's coming from the same place the UserConsent (SmsRetriever.SMS_RETRIEVED_ACTION)
|
|
- // broadcast is coming from, so the sender will be holding this permission. This prevents
|
|
- // other apps from spoofing verification codes.
|
|
- ContextUtils.registerExportedBroadcastReceiver(
|
|
- mContext, this, filter, SmsRetriever.SEND_PERMISSION);
|
|
- }
|
|
-
|
|
- public SmsCodeBrowserClient createClient() {
|
|
- return SmsCodeRetriever.getBrowserClient(mContext);
|
|
}
|
|
|
|
public void destroy() {
|
|
- if (mDestroyed) return;
|
|
- if (DEBUG) Log.d(TAG, "Destroying SmsVerificationReceiver.");
|
|
- mDestroyed = true;
|
|
- mContext.unregisterReceiver(this);
|
|
}
|
|
|
|
@Override
|
|
public void onReceive(Context context, Intent intent) {
|
|
- if (DEBUG) Log.d(TAG, "Received something!");
|
|
-
|
|
- if (mDestroyed) {
|
|
- return;
|
|
- }
|
|
-
|
|
- if (!SmsCodeRetriever.SMS_CODE_RETRIEVED_ACTION.equals(intent.getAction())) {
|
|
- return;
|
|
- }
|
|
-
|
|
- if (intent.getExtras() == null) {
|
|
- return;
|
|
- }
|
|
-
|
|
- Status status = IntentUtils.safeGetParcelableExtra(intent, SmsRetriever.EXTRA_STATUS);
|
|
- if (status == null) {
|
|
- return;
|
|
- }
|
|
-
|
|
- switch (status.getStatusCode()) {
|
|
- case CommonStatusCodes.SUCCESS:
|
|
- String message = intent.getExtras().getString(SmsCodeRetriever.EXTRA_SMS_CODE_LINE);
|
|
- if (DEBUG) Log.d(TAG, "Got message: %s!", message);
|
|
- mProvider.onReceive(message, GmsBackend.VERIFICATION);
|
|
- break;
|
|
- case CommonStatusCodes.TIMEOUT:
|
|
- if (DEBUG) Log.d(TAG, "Timeout");
|
|
- mProvider.onTimeout();
|
|
- break;
|
|
- }
|
|
}
|
|
|
|
public void onPermissionDone(int resultCode, boolean isLocalRequest) {
|
|
@@ -153,72 +95,10 @@ public class SmsVerificationReceiver extends BroadcastReceiver {
|
|
* task.
|
|
*/
|
|
public void onRetrieverTaskFailure(boolean isLocalRequest, Exception e) {
|
|
- if (DEBUG) Log.d(TAG, "Task failed. Attempting recovery.", e);
|
|
- ApiException exception = (ApiException) e;
|
|
- if (exception.getStatusCode() == SmsRetrieverStatusCodes.API_NOT_CONNECTED) {
|
|
- reportBackendAvailability(BackendAvailability.API_NOT_CONNECTED);
|
|
- mProvider.onMethodNotAvailable(isLocalRequest);
|
|
- Log.d(TAG, "update GMS services.");
|
|
- } else if (exception.getStatusCode() == SmsRetrieverStatusCodes.PLATFORM_NOT_SUPPORTED) {
|
|
- reportBackendAvailability(BackendAvailability.PLATFORM_NOT_SUPPORTED);
|
|
- mProvider.onMethodNotAvailable(isLocalRequest);
|
|
- Log.d(TAG, "old android platform.");
|
|
- } else if (exception.getStatusCode() == SmsRetrieverStatusCodes.API_NOT_AVAILABLE) {
|
|
- reportBackendAvailability(BackendAvailability.API_NOT_AVAILABLE);
|
|
- mProvider.onMethodNotAvailable(isLocalRequest);
|
|
- Log.d(TAG, "not the default browser.");
|
|
- } else if (exception.getStatusCode() == SmsRetrieverStatusCodes.USER_PERMISSION_REQUIRED) {
|
|
- cancelRequestAndReportBackendAvailability();
|
|
- Log.d(TAG, "user permission is required.");
|
|
- } else if (exception.getStatusCode() == CommonStatusCodes.RESOLUTION_REQUIRED) {
|
|
- if (exception instanceof ResolvableApiException) {
|
|
- // This occurs if the default browser is in NONE permission
|
|
- // state. Resolve it by calling PendingIntent.send() method.
|
|
- // This shows the consent dialog to user so they grant
|
|
- // one-time permission. The dialog result will be received
|
|
- // via `onPermissionDone()`
|
|
- ResolvableApiException rex = (ResolvableApiException) exception;
|
|
- try {
|
|
- PendingIntent resolutionIntent = rex.getResolution();
|
|
- assumeNonNull(mProvider.getWindow())
|
|
- .showIntent(
|
|
- resolutionIntent,
|
|
- new WindowAndroid.IntentCallback() {
|
|
- @Override
|
|
- public void onIntentCompleted(
|
|
- int resultCode, @Nullable Intent data) {
|
|
- // Backend availability will be recorded inside
|
|
- // |onPermissionDone|.
|
|
- onPermissionDone(resultCode, isLocalRequest);
|
|
- }
|
|
- },
|
|
- null);
|
|
- } catch (Exception ex) {
|
|
- cancelRequestAndReportBackendAvailability();
|
|
- Log.e(TAG, "Cannot launch user permission", ex);
|
|
- }
|
|
- }
|
|
- } else {
|
|
- Log.w(TAG, "Unexpected exception", e);
|
|
- }
|
|
}
|
|
|
|
public void listen(boolean isLocalRequest) {
|
|
- Wrappers.SmsRetrieverClientWrapper client = mProvider.getClient();
|
|
- Task<Void> task = client.startSmsCodeBrowserRetriever();
|
|
-
|
|
- task.addOnSuccessListener(
|
|
- unused -> {
|
|
- this.reportBackendAvailability(BackendAvailability.AVAILABLE);
|
|
- mProvider.verificationReceiverSucceeded(isLocalRequest);
|
|
- });
|
|
- task.addOnFailureListener(
|
|
- (Exception e) -> {
|
|
- this.onRetrieverTaskFailure(isLocalRequest, e);
|
|
- mProvider.verificationReceiverFailed(isLocalRequest);
|
|
- });
|
|
-
|
|
- if (DEBUG) Log.d(TAG, "Installed task");
|
|
+ if (DEBUG) Log.d(TAG, "Ignored task");
|
|
}
|
|
|
|
public void reportBackendAvailability(@BackendAvailability int availability) {
|
|
diff --git a/content/public/android/java/src/org/chromium/content/browser/sms/Wrappers.java b/content/public/android/java/src/org/chromium/content/browser/sms/Wrappers.java
|
|
--- a/content/public/android/java/src/org/chromium/content/browser/sms/Wrappers.java
|
|
+++ b/content/public/android/java/src/org/chromium/content/browser/sms/Wrappers.java
|
|
@@ -13,11 +13,6 @@ import android.content.Intent;
|
|
import android.content.IntentFilter;
|
|
import android.os.Handler;
|
|
|
|
-import com.google.android.gms.auth.api.phone.SmsCodeBrowserClient;
|
|
-import com.google.android.gms.auth.api.phone.SmsCodeRetriever;
|
|
-import com.google.android.gms.auth.api.phone.SmsRetrieverClient;
|
|
-import com.google.android.gms.tasks.Task;
|
|
-
|
|
import org.chromium.build.annotations.NullMarked;
|
|
import org.chromium.build.annotations.Nullable;
|
|
|
|
@@ -28,17 +23,9 @@ class Wrappers {
|
|
|
|
/** Wraps com.google.android.gms.auth.api.phone.SmsRetrieverClient. */
|
|
static class SmsRetrieverClientWrapper {
|
|
- // Used for user consent flow.
|
|
- private final @Nullable SmsRetrieverClient mSmsRetrieverClient;
|
|
- // Used for browser code flow.
|
|
- private final @Nullable SmsCodeBrowserClient mSmsCodeBrowserClient;
|
|
private @Nullable WebOTPServiceContext mContext;
|
|
|
|
- public SmsRetrieverClientWrapper(
|
|
- @Nullable SmsRetrieverClient smsRetrieverClient,
|
|
- @Nullable SmsCodeBrowserClient smsCodeBrowserClient) {
|
|
- mSmsRetrieverClient = smsRetrieverClient;
|
|
- mSmsCodeBrowserClient = smsCodeBrowserClient;
|
|
+ public SmsRetrieverClientWrapper() {
|
|
}
|
|
|
|
public void setContext(WebOTPServiceContext context) {
|
|
@@ -48,16 +35,6 @@ class Wrappers {
|
|
public @Nullable WebOTPServiceContext getContext() {
|
|
return mContext;
|
|
}
|
|
-
|
|
- public Task<Void> startSmsCodeBrowserRetriever() {
|
|
- assumeNonNull(mSmsCodeBrowserClient);
|
|
- return mSmsCodeBrowserClient.startSmsCodeRetriever();
|
|
- }
|
|
-
|
|
- public Task<Void> startSmsUserConsent(@Nullable String senderAddress) {
|
|
- assumeNonNull(mSmsRetrieverClient);
|
|
- return mSmsRetrieverClient.startSmsUserConsent(senderAddress);
|
|
- }
|
|
}
|
|
|
|
/**
|
|
@@ -87,11 +64,6 @@ class Wrappers {
|
|
}
|
|
|
|
private void onRegisterReceiver(@Nullable BroadcastReceiver receiver, IntentFilter filter) {
|
|
- if (filter.hasAction(SmsCodeRetriever.SMS_CODE_RETRIEVED_ACTION)) {
|
|
- mVerificationReceiver = receiver;
|
|
- } else {
|
|
- mUserConsentReceiver = receiver;
|
|
- }
|
|
}
|
|
|
|
// ---------------------------------------------------------------------
|
|
--
|