Skip to content

Commit

Permalink
Uplift of #25089 (squashed) to beta
Browse files Browse the repository at this point in the history
  • Loading branch information
brave-builds committed Sep 6, 2024
1 parent 71f7279 commit 2f329ac
Show file tree
Hide file tree
Showing 79 changed files with 3,077 additions and 747 deletions.
5 changes: 4 additions & 1 deletion android/brave_java_resources.gni
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ brave_java_resources = [
"java/res/anim/slide_out_bottom.xml",
"java/res/anim/slide_out_top.xml",
"java/res/color/crypto_wallet_onboarding_button_text_color.xml",
"java/res/color/vpn_server_selection_switch_stroke_color.xml",
"java/res/color/wallet_checkbox_background_color_selector.xml",
"java/res/color/wallet_checkbox_color_selector.xml",
"java/res/color/wallet_onboarding_input_field_stroke_color.xml",
Expand Down Expand Up @@ -452,6 +453,7 @@ brave_java_resources = [
"java/res/drawable/ic_cancel_filled.xml",
"java/res/drawable/ic_carat_down.xml",
"java/res/drawable/ic_carat_down_country_spinner.xml",
"java/res/drawable/ic_carat_right.xml",
"java/res/drawable/ic_card_background.xml",
"java/res/drawable/ic_celo_color.xml",
"java/res/drawable/ic_channel_brave.xml",
Expand Down Expand Up @@ -482,7 +484,6 @@ brave_java_resources = [
"java/res/drawable/ic_channels.xml",
"java/res/drawable/ic_check.xml",
"java/res/drawable/ic_check_white.xml",
"java/res/drawable/ic_checkbox_checked.xml",
"java/res/drawable/ic_checkbox_filled.xml",
"java/res/drawable/ic_checkbox_outline.xml",
"java/res/drawable/ic_chevron_right.xml",
Expand Down Expand Up @@ -769,6 +770,7 @@ brave_java_resources = [
"java/res/layout/activity_tipping_banner_tablet.xml",
"java/res/layout/activity_vpn_always_on.xml",
"java/res/layout/activity_vpn_paywall.xml",
"java/res/layout/activity_vpn_server.xml",
"java/res/layout/activity_vpn_server_selection.xml",
"java/res/layout/activity_welcome_onboarding.xml",
"java/res/layout/application_item_layout.xml",
Expand Down Expand Up @@ -962,6 +964,7 @@ brave_java_resources = [
"java/res/layout/view_holder_onboarding_header_network_selector.xml",
"java/res/layout/view_holder_onboarding_network_selector.xml",
"java/res/layout/vpn_location_menu_item_action_layout.xml",
"java/res/layout/vpn_server_item_layout.xml",
"java/res/layout/vpn_settings_callout_modal_layout.xml",
"java/res/layout/wallet_balance_layout.xml",
"java/res/layout/web_notification_icon_frame_brave.xml",
Expand Down
3 changes: 3 additions & 0 deletions android/brave_java_sources.gni
Original file line number Diff line number Diff line change
Expand Up @@ -455,16 +455,19 @@ brave_java_sources = [
"../../brave/android/java/org/chromium/chrome/browser/util/UsageMonitor.java",
"../../brave/android/java/org/chromium/chrome/browser/vpn/BraveVpnNativeWorker.java",
"../../brave/android/java/org/chromium/chrome/browser/vpn/BraveVpnObserver.java",
"../../brave/android/java/org/chromium/chrome/browser/vpn/BraveVpnServiceFactoryAndroid.java",
"../../brave/android/java/org/chromium/chrome/browser/vpn/DisconnectVpnBroadcastReceiver.java",
"../../brave/android/java/org/chromium/chrome/browser/vpn/activities/BraveVpnParentActivity.java",
"../../brave/android/java/org/chromium/chrome/browser/vpn/activities/BraveVpnProfileActivity.java",
"../../brave/android/java/org/chromium/chrome/browser/vpn/activities/BraveVpnSupportActivity.java",
"../../brave/android/java/org/chromium/chrome/browser/vpn/activities/VpnAlwaysOnActivity.java",
"../../brave/android/java/org/chromium/chrome/browser/vpn/activities/VpnPaywallActivity.java",
"../../brave/android/java/org/chromium/chrome/browser/vpn/activities/VpnServerActivity.java",
"../../brave/android/java/org/chromium/chrome/browser/vpn/activities/VpnServerSelectionActivity.java",
"../../brave/android/java/org/chromium/chrome/browser/vpn/adapters/AlwaysOnPagerAdapter.java",
"../../brave/android/java/org/chromium/chrome/browser/vpn/adapters/BraveVpnPlanPagerAdapter.java",
"../../brave/android/java/org/chromium/chrome/browser/vpn/adapters/BraveVpnServerSelectionAdapter.java",
"../../brave/android/java/org/chromium/chrome/browser/vpn/adapters/VpnServerAdapter.java",
"../../brave/android/java/org/chromium/chrome/browser/vpn/fragments/BraveVpnAlwaysOnErrorDialogFragment.java",
"../../brave/android/java/org/chromium/chrome/browser/vpn/fragments/BraveVpnConfirmDialogFragment.java",
"../../brave/android/java/org/chromium/chrome/browser/vpn/fragments/LinkVpnSubscriptionDialogFragment.java",
Expand Down
6 changes: 6 additions & 0 deletions android/java/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,12 @@
android:screenOrientation="sensorPortrait"
tools:ignore="LockedOrientationActivity,DiscouragedApi"/>

<activity
android:name="org.chromium.chrome.browser.vpn.activities.VpnServerActivity"
android:theme="@style/Theme.Chromium.Activity"
android:screenOrientation="sensorPortrait"
tools:ignore="LockedOrientationActivity,DiscouragedApi"/>

<activity
android:name="org.chromium.chrome.browser.vpn.activities.BraveVpnParentActivity"
android:theme="@style/Theme.Chromium.Activity"
Expand Down
22 changes: 0 additions & 22 deletions android/java/org/chromium/chrome/browser/app/BraveActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,6 @@
import org.chromium.chrome.browser.vpn.BraveVpnObserver;
import org.chromium.chrome.browser.vpn.activities.BraveVpnProfileActivity;
import org.chromium.chrome.browser.vpn.fragments.LinkVpnSubscriptionDialogFragment;
import org.chromium.chrome.browser.vpn.models.BraveVpnServerRegion;
import org.chromium.chrome.browser.vpn.timer.TimerDialogFragment;
import org.chromium.chrome.browser.vpn.utils.BraveVpnApiResponseUtils;
import org.chromium.chrome.browser.vpn.utils.BraveVpnPrefUtils;
Expand Down Expand Up @@ -1160,11 +1159,6 @@ public void finishNativeInitialization() {

checkFingerPrintingOnUpgrade(isFirstInstall);
checkForVpnCallout(isFirstInstall);
if (!isFirstInstall
&& !BraveVpnPrefUtils.isIsoCodeUpgradeDone()
&& BraveVpnPrefUtils.isSubscriptionPurchase()) {
BraveVpnNativeWorker.getInstance().getAllServerRegions();
}

if (ChromeFeatureList.isEnabled(BraveFeatureList.BRAVE_VPN_LINK_SUBSCRIPTION_ANDROID_UI)
&& BraveVpnPrefUtils.isSubscriptionPurchase()
Expand Down Expand Up @@ -1345,22 +1339,6 @@ private void startAppUpdateFlow(AppUpdateInfo appUpdateInfo, int appUpdateType)
}
}

@Override
public void onGetAllServerRegions(String jsonResponse, boolean isSuccess) {
if (isSuccess) {
List<BraveVpnServerRegion> braveVpnServerRegions =
BraveVpnUtils.getServerLocations(jsonResponse);
for (BraveVpnServerRegion braveVpnServerRegion : braveVpnServerRegions) {
if (braveVpnServerRegion.getName().equals(BraveVpnPrefUtils.getServerRegion())) {
BraveVpnPrefUtils.setServerIsoCode(braveVpnServerRegion.getCountryIsoCode());
BraveVpnPrefUtils.setServerNamePretty(braveVpnServerRegion.getNamePretty());
BraveVpnPrefUtils.setIsoCodeUpgrade(true);
break;
}
}
}
}

private void handleDeepLinkVpn() {
mIsDeepLink = true;
BraveVpnUtils.openBraveVpnPlansActivity(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,19 +125,18 @@ public void prepareMenu(Menu menu, AppMenuHandler handler) {
}

if (BraveVpnPrefUtils.isSubscriptionPurchase()
&& !TextUtils.isEmpty(BraveVpnPrefUtils.getServerIsoCode())) {
String serverLocation =
" "
+ BraveVpnUtils.countryCodeToEmoji(
BraveVpnPrefUtils.getServerIsoCode())
+ " "
+ BraveVpnPrefUtils.getServerNamePretty();

&& !TextUtils.isEmpty(BraveVpnPrefUtils.getRegionIsoCode())) {
String serverLocation = " %s %s";
SubMenu vpnLocationSubMenu =
menu.findItem(R.id.request_vpn_location_row_menu_id).getSubMenu();
MenuItem vpnLocationSubMenuItem =
vpnLocationSubMenu.findItem(R.id.request_vpn_location_id);
vpnLocationSubMenuItem.setTitle(serverLocation);
vpnLocationSubMenuItem.setTitle(
String.format(
serverLocation,
BraveVpnUtils.countryCodeToEmoji(
BraveVpnPrefUtils.getRegionIsoCode()),
BraveVpnPrefUtils.getRegionNamePretty()));
MenuItem vpnLocationIconSubMenuItem =
vpnLocationSubMenu.findItem(R.id.request_vpn_location_icon_id);
Drawable drawable = vpnLocationIconSubMenuItem.getIcon();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,6 @@ private void setNativePtr(long nativePtr) {
mNativeBraveVpnNativeWorker = nativePtr;
}

@CalledByNative
public void onGetAllServerRegions(String jsonServerRegions, boolean isSuccess) {
for (BraveVpnObserver observer : mObservers) {
observer.onGetAllServerRegions(jsonServerRegions, isSuccess);
}
}

@CalledByNative
public void onGetTimezonesForRegions(String jsonTimezones, boolean isSuccess) {
for (BraveVpnObserver observer : mObservers) {
Expand Down Expand Up @@ -130,16 +123,13 @@ public void onVerifyPurchaseToken(
}
}

public void getAllServerRegions() {
BraveVpnNativeWorkerJni.get().getAllServerRegions(mNativeBraveVpnNativeWorker);
}

public void getTimezonesForRegions() {
BraveVpnNativeWorkerJni.get().getTimezonesForRegions(mNativeBraveVpnNativeWorker);
}

public void getHostnamesForRegion(String region) {
BraveVpnNativeWorkerJni.get().getHostnamesForRegion(mNativeBraveVpnNativeWorker, region);
public void getHostnamesForRegion(String region, String regionPrecision) {
BraveVpnNativeWorkerJni.get()
.getHostnamesForRegion(mNativeBraveVpnNativeWorker, region, regionPrecision);
}

public void getWireguardProfileCredentials(
Expand Down Expand Up @@ -197,26 +187,58 @@ public void reportForegroundP3A() {
@NativeMethods
interface Natives {
void init(BraveVpnNativeWorker caller);

void destroy(long nativeBraveVpnNativeWorker, BraveVpnNativeWorker caller);
void getAllServerRegions(long nativeBraveVpnNativeWorker);

void getTimezonesForRegions(long nativeBraveVpnNativeWorker);
void getHostnamesForRegion(long nativeBraveVpnNativeWorker, String region);
void getWireguardProfileCredentials(long nativeBraveVpnNativeWorker,
String subscriberCredential, String publicKey, String hostname);
void verifyCredentials(long nativeBraveVpnNativeWorker, String hostname, String clientId,
String subscriberCredential, String apiAuthToken);
void invalidateCredentials(long nativeBraveVpnNativeWorker, String hostname,
String clientId, String subscriberCredential, String apiAuthToken);
void getSubscriberCredential(long nativeBraveVpnNativeWorker, String productType,
String productId, String validationMethod, String purchaseToken,

void getHostnamesForRegion(
long nativeBraveVpnNativeWorker, String region, String regionPrecision);

void getWireguardProfileCredentials(
long nativeBraveVpnNativeWorker,
String subscriberCredential,
String publicKey,
String hostname);

void verifyCredentials(
long nativeBraveVpnNativeWorker,
String hostname,
String clientId,
String subscriberCredential,
String apiAuthToken);

void invalidateCredentials(
long nativeBraveVpnNativeWorker,
String hostname,
String clientId,
String subscriberCredential,
String apiAuthToken);

void getSubscriberCredential(
long nativeBraveVpnNativeWorker,
String productType,
String productId,
String validationMethod,
String purchaseToken,
String packageName);

void verifyPurchaseToken(
long nativeBraveVpnNativeWorker,
String purchaseToken,
String productId,
String productType,
String packageName);
void verifyPurchaseToken(long nativeBraveVpnNativeWorker, String purchaseToken,
String productId, String productType, String packageName);

void reloadPurchasedState(long nativeBraveVpnNativeWorker);

boolean isPurchasedUser(long nativeBraveVpnNativeWorker);

void getSubscriberCredentialV12(long nativeBraveVpnNativeWorker);

void reportBackgroundP3A(
long nativeBraveVpnNativeWorker, long sessionStartTimeMs, long sessionEndTimeMs);

void reportForegroundP3A(long nativeBraveVpnNativeWorker);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
package org.chromium.chrome.browser.vpn;

public interface BraveVpnObserver {
public default void onGetAllServerRegions(String jsonServerRegions, boolean isSuccess) {}
;

public default void onGetTimezonesForRegions(String jsonTimezones, boolean isSuccess) {}
;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/* Copyright (c) 2024 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at https://mozilla.org/MPL/2.0/. */

package org.chromium.chrome.browser.vpn;

import org.jni_zero.JNINamespace;
import org.jni_zero.NativeMethods;

import org.chromium.brave_vpn.mojom.ServiceHandler;
import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.mojo.bindings.ConnectionErrorHandler;
import org.chromium.mojo.bindings.Interface;
import org.chromium.mojo.bindings.Interface.Proxy.Handler;
import org.chromium.mojo.system.MessagePipeHandle;
import org.chromium.mojo.system.impl.CoreImpl;

@JNINamespace("chrome::android")
public class BraveVpnServiceFactoryAndroid {
private static final Object sLock = new Object();
private static BraveVpnServiceFactoryAndroid sInstance;

public static BraveVpnServiceFactoryAndroid getInstance() {
synchronized (sLock) {
if (sInstance == null) {
sInstance = new BraveVpnServiceFactoryAndroid();
}
}
return sInstance;
}

private BraveVpnServiceFactoryAndroid() {}

public ServiceHandler getVpnService(
Profile profile, ConnectionErrorHandler connectionErrorHandler) {
if (profile == null) {
return null;
}
long nativeHandle =
BraveVpnServiceFactoryAndroidJni.get().getInterfaceToVpnService(profile);
if (nativeHandle == -1) {
return null;
}
MessagePipeHandle handle = wrapNativeHandle(nativeHandle);
ServiceHandler serviceHandler = ServiceHandler.MANAGER.attachProxy(handle, 0);
Handler handler = ((Interface.Proxy) serviceHandler).getProxyHandler();
handler.setErrorHandler(connectionErrorHandler);

return serviceHandler;
}

private MessagePipeHandle wrapNativeHandle(long nativeHandle) {
return CoreImpl.getInstance().acquireNativeHandle(nativeHandle).toMessagePipeHandle();
}

@NativeMethods
interface Natives {
long getInterfaceToVpnService(Profile profile);
}
}
Loading

0 comments on commit 2f329ac

Please sign in to comment.