Skip to content

Commit

Permalink
Remove webview auth code for iOS and Android (#3502)
Browse files Browse the repository at this point in the history
* Remove iOS webview auth code

* Remove android webview auth code
  • Loading branch information
bakulf authored May 11, 2022
1 parent 17466b5 commit a973713
Show file tree
Hide file tree
Showing 18 changed files with 4 additions and 1,017 deletions.
65 changes: 0 additions & 65 deletions android/src/org/mozilla/firefox/vpn/qt/PackageManagerHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import android.net.Uri;
import android.os.Build;
import android.util.Log;
import android.webkit.WebView;

import org.json.JSONException;
import org.json.JSONObject;
Expand All @@ -31,10 +30,6 @@
// Gets used by /platforms/android/androidAppListProvider.cpp
public class PackageManagerHelper {
final static String TAG = "PackageManagerHelper";
final static int MIN_CHROME_VERSION = 65;

final static List<String> CHROME_BROWSERS = Arrays.asList(
new String[] {"com.google.android.webview", "com.android.webview", "com.google.chrome"});

private static String getAllAppNames(Context ctx) {
JSONObject output = new JSONObject();
Expand Down Expand Up @@ -126,64 +121,4 @@ private static List<String> getBrowserIDs(PackageManager pm) {
}
return browsers;
}

// Gets called in AndroidAuthenticationListener;
public static boolean isWebViewSupported(Context ctx) {
Log.v(TAG, "Checking if installed Webview is compatible with FxA");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
// The default Webview is able do to FXA
return true;
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
PackageInfo pi = WebView.getCurrentWebViewPackage();
if (CHROME_BROWSERS.contains(pi.packageName)) {
return isSupportedChromeBrowser(pi);
}
return isNotAncientBrowser(pi);
}

// Before O the webview is hardcoded, but we dont know which package it is.
// Check if com.google.android.webview is installed
PackageManager pm = ctx.getPackageManager();
try {
PackageInfo pi = pm.getPackageInfo("com.google.android.webview", 0);
return isSupportedChromeBrowser(pi);
} catch (PackageManager.NameNotFoundException e) {
}
// Otherwise check com.android.webview
try {
PackageInfo pi = pm.getPackageInfo("com.android.webview", 0);
return isSupportedChromeBrowser(pi);
} catch (PackageManager.NameNotFoundException e) {
}
Log.e(TAG, "Android System WebView is not found");
// Giving up :(
return false;
}

private static boolean isSupportedChromeBrowser(PackageInfo pi) {
Log.d(TAG, "Checking Chrome Based Browser: " + pi.packageName);
Log.d(TAG, "version name: " + pi.versionName);
Log.d(TAG, "version code: " + pi.versionCode);
try {
String versionCode = pi.versionName.split(Pattern.quote(" "))[0];
String majorVersion = versionCode.split(Pattern.quote("."))[0];
int version = Integer.parseInt(majorVersion);
return version >= MIN_CHROME_VERSION;
} catch (Exception e) {
Log.e(TAG, "Failed to check Chrome Version Code " + pi.versionName);
return false;
}
}

private static boolean isNotAncientBrowser(PackageInfo pi) {
// Not a google chrome - So the version name is worthless
// Lets just make sure the WebView
// used is not ancient ==> Was updated in at least the last 365 days
Log.d(TAG, "Checking Chrome Based Browser: " + pi.packageName);
Log.d(TAG, "version name: " + pi.versionName);
Log.d(TAG, "version code: " + pi.versionCode);
double oneYearInMillis = 31536000000L;
return pi.lastUpdateTime > (System.currentTimeMillis() - oneYearInMillis);
}
}
166 changes: 0 additions & 166 deletions android/src/org/mozilla/firefox/vpn/qt/VPNWebView.java

This file was deleted.

13 changes: 4 additions & 9 deletions src/authenticationlistener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,7 @@
#include "networkmanager.h"
#include "networkrequest.h"

#if defined(MVPN_ANDROID)
# include "platforms/android/androidauthenticationlistener.h"
#elif defined(MVPN_IOS)
# include "platforms/ios/iosauthenticationlistener.h"
#elif defined(MVPN_MACOS)
#if defined(MVPN_MACOS)
# include "platforms/macos/macosauthenticationlistener.h"
#elif defined(MVPN_WASM)
# include "platforms/wasm/wasmauthenticationlistener.h"
Expand All @@ -35,10 +31,9 @@ AuthenticationListener* AuthenticationListener::create(
QObject* parent, MozillaVPN::AuthenticationType authenticationType) {
switch (authenticationType) {
case MozillaVPN::AuthenticationInBrowser:
#if defined(MVPN_ANDROID)
return new AndroidAuthenticationListener(parent);
#elif defined(MVPN_IOS)
return new IOSAuthenticationListener(parent);
#if defined(MVPN_ANDROID) or defined(MVPN_IOS)
logger.error() << "Something went totally wrong";
Q_ASSERT(false);
#elif defined(MVPN_MACOS)
return new MacosAuthenticationListener(parent);
#elif defined(MVPN_WASM)
Expand Down
3 changes: 0 additions & 3 deletions src/commands/commandui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@

#ifdef MVPN_ANDROID
# include "platforms/android/androidutils.h"
# include "platforms/android/androidwebview.h"
#endif

#ifndef Q_OS_WIN
Expand Down Expand Up @@ -437,8 +436,6 @@ int CommandUI::run(QStringList& tokens) {
QQmlEngine::setObjectOwnership(obj, QQmlEngine::CppOwnership);
return obj;
});

qmlRegisterType<AndroidWebView>("Mozilla.VPN", 1, 0, "VPNAndroidWebView");
#endif

if (FeatureInAppPurchase::instance()->isSupported()) {
Expand Down
4 changes: 0 additions & 4 deletions src/mozillavpn.h
Original file line number Diff line number Diff line change
Expand Up @@ -414,10 +414,6 @@ class MozillaVPN final : public QObject {

void aboutToQuit();

// This is used only on android but, if we use #ifdef MVPN_ANDROID, qml engine
// complains...
void loadAndroidAuthenticationView();

void logsReady(const QString& logs);

void currentViewChanged();
Expand Down
54 changes: 0 additions & 54 deletions src/platforms/android/androidauthenticationlistener.cpp

This file was deleted.

23 changes: 0 additions & 23 deletions src/platforms/android/androidauthenticationlistener.h

This file was deleted.

Loading

0 comments on commit a973713

Please sign in to comment.