Resolve crash fixes for vpn

This commit is contained in:
Deep
2022-05-25 19:55:12 -04:00
parent 8181774349
commit b7f4e8ca71
11 changed files with 80 additions and 67 deletions
@@ -808,7 +808,8 @@ public abstract class BraveActivity<C extends ChromeActivityComponent> extends C
}
}
if (BraveVpnUtils.isBraveVpnFeatureEnable()) {
if (BraveVpnUtils.isBraveVpnFeatureEnable()
&& InAppPurchaseWrapper.getInstance().isSubscriptionSupported()) {
if (BraveVpnPrefUtils.shouldShowCallout() && !BraveVpnPrefUtils.isSubscriptionPurchase()
&& (SharedPreferencesManager.getInstance().readInt(
BravePreferenceKeys.BRAVE_APP_OPEN_COUNT)
@@ -41,6 +41,7 @@ import org.chromium.chrome.browser.ui.appmenu.AppMenuHandler;
import org.chromium.chrome.browser.ui.messages.snackbar.SnackbarManager;
import org.chromium.chrome.browser.vpn.utils.BraveVpnProfileUtils;
import org.chromium.chrome.browser.vpn.utils.BraveVpnUtils;
import org.chromium.chrome.browser.vpn.utils.InAppPurchaseWrapper;
import org.chromium.chrome.features.start_surface.StartSurface;
import org.chromium.ui.modaldialog.ModalDialogManager;
@@ -74,7 +75,8 @@ public class BraveTabbedAppMenuPropertiesDelegate extends TabbedAppMenuPropertie
mMenu = menu;
if (BraveVpnUtils.isBraveVpnFeatureEnable()) {
if (BraveVpnUtils.isBraveVpnFeatureEnable()
&& InAppPurchaseWrapper.getInstance().isSubscriptionSupported()) {
SubMenu vpnSubMenu = menu.findItem(R.id.request_brave_vpn_row_menu_id).getSubMenu();
MenuItem braveVpnSubMenuItem = vpnSubMenu.findItem(R.id.request_brave_vpn_id);
if (shouldShowIconBeforeItem()) {
@@ -34,6 +34,7 @@ import org.chromium.chrome.browser.settings.BraveStatsPreferences;
import org.chromium.chrome.browser.toolbar.bottom.BottomToolbarConfiguration;
import org.chromium.chrome.browser.vpn.utils.BraveVpnPrefUtils;
import org.chromium.chrome.browser.vpn.utils.BraveVpnUtils;
import org.chromium.chrome.browser.vpn.utils.InAppPurchaseWrapper;
import org.chromium.components.browser_ui.settings.ChromeBasePreference;
import org.chromium.components.browser_ui.settings.ChromeSwitchPreference;
import org.chromium.components.browser_ui.settings.SettingsUtils;
@@ -176,7 +177,8 @@ public class BraveMainPreferencesBase
int firstSectionOrder = 0;
if (BraveVpnPrefUtils.shouldShowCallout() && !BraveVpnPrefUtils.isSubscriptionPurchase()
&& BraveVpnUtils.isBraveVpnFeatureEnable()) {
&& BraveVpnUtils.isBraveVpnFeatureEnable()
&& InAppPurchaseWrapper.getInstance().isSubscriptionSupported()) {
VpnCalloutPreference vpnCalloutPreference = new VpnCalloutPreference(getActivity());
vpnCalloutPreference.setKey(PREF_BRAVE_VPN_CALLOUT);
vpnCalloutPreference.setOrder(firstSectionOrder);
@@ -194,7 +196,8 @@ public class BraveMainPreferencesBase
removePreferenceIfPresent(PREF_BRAVE_WALLET);
}
if (BraveVpnUtils.isBraveVpnFeatureEnable()) {
if (BraveVpnUtils.isBraveVpnFeatureEnable()
&& InAppPurchaseWrapper.getInstance().isSubscriptionSupported()) {
findPreference(PREF_BRAVE_VPN).setOrder(++firstSectionOrder);
} else {
removePreferenceIfPresent(PREF_BRAVE_VPN);
@@ -33,15 +33,6 @@ public class VpnCalloutPreference extends Preference {
setLayoutResource(R.layout.vpn_settings_callout_modal_layout);
}
public VpnCalloutPreference(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
public VpnCalloutPreference(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
setLayoutResource(R.layout.vpn_settings_callout_modal_layout);
}
@Override
public void onBindViewHolder(PreferenceViewHolder holder) {
super.onBindViewHolder(holder);
@@ -201,6 +201,7 @@ public abstract class BraveVpnParentActivity
BraveVpnProfileUtils.getInstance().startVpn(BraveVpnParentActivity.this);
finish();
} catch (Exception e) {
BraveVpnUtils.dismissProgressDialog();
Log.e(TAG, e.getMessage());
}
}
@@ -33,6 +33,7 @@ import org.chromium.chrome.browser.vpn.activities.BraveVpnParentActivity;
import org.chromium.chrome.browser.vpn.adapters.BraveVpnPlanPagerAdapter;
import org.chromium.chrome.browser.vpn.utils.BraveVpnUtils;
import org.chromium.chrome.browser.vpn.utils.InAppPurchaseWrapper;
import org.chromium.ui.widget.Toast;
public class BraveVpnPlansActivity extends BraveVpnParentActivity {
private BraveFirstRunFlowSequencer mFirstRunFlowSequencer;
@@ -86,43 +87,50 @@ public class BraveVpnPlansActivity extends BraveVpnParentActivity {
? InAppPurchaseWrapper.RELEASE_MONTHLY_SUBSCRIPTION
: InAppPurchaseWrapper.NIGHTLY_MONTHLY_SUBSCRIPTION);
mMonthlySelectorLayout = findViewById(R.id.monthly_selector_layout);
mMonthlySelectorLayout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
InAppPurchaseWrapper.getInstance().purchase(
BraveVpnPlansActivity.this, monthlySkuDetails);
}
});
TextView monthlySubscriptionAmountText =
findViewById(R.id.monthly_subscription_amount_text);
monthlySubscriptionAmountText.setText(
String.format(getResources().getString(R.string.monthly_subscription_amount),
monthlySkuDetails.getPrice()));
SkuDetails yearlySkuDetails = InAppPurchaseWrapper.getInstance().getSkuDetails(
getPackageName().equals(BraveActivity.BRAVE_PRODUCTION_PACKAGE_NAME)
? InAppPurchaseWrapper.RELEASE_YEARLY_SUBSCRIPTION
: InAppPurchaseWrapper.NIGHTLY_YEARLY_SUBSCRIPTION);
mYearlySelectorLayout = findViewById(R.id.yearly_selector_layout);
mYearlySelectorLayout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
InAppPurchaseWrapper.getInstance().purchase(
BraveVpnPlansActivity.this, yearlySkuDetails);
}
});
if (monthlySkuDetails != null || yearlySkuDetails != null) {
mMonthlySelectorLayout = findViewById(R.id.monthly_selector_layout);
mMonthlySelectorLayout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
InAppPurchaseWrapper.getInstance().purchase(
BraveVpnPlansActivity.this, monthlySkuDetails);
}
});
TextView yearlySubscriptionAmountText = findViewById(R.id.yearly_subscription_amount_text);
yearlySubscriptionAmountText.setText(
String.format(getResources().getString(R.string.yearly_subscription_amount),
yearlySkuDetails.getPrice()));
BraveVpnUtils.showProgressDialog(
BraveVpnPlansActivity.this, getResources().getString(R.string.vpn_connect_text));
mIsVerification = true;
verifySubscription();
TextView monthlySubscriptionAmountText =
findViewById(R.id.monthly_subscription_amount_text);
monthlySubscriptionAmountText.setText(
String.format(getResources().getString(R.string.monthly_subscription_amount),
monthlySkuDetails.getPrice()));
mYearlySelectorLayout = findViewById(R.id.yearly_selector_layout);
mYearlySelectorLayout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
InAppPurchaseWrapper.getInstance().purchase(
BraveVpnPlansActivity.this, yearlySkuDetails);
}
});
TextView yearlySubscriptionAmountText =
findViewById(R.id.yearly_subscription_amount_text);
yearlySubscriptionAmountText.setText(
String.format(getResources().getString(R.string.yearly_subscription_amount),
yearlySkuDetails.getPrice()));
BraveVpnUtils.showProgressDialog(BraveVpnPlansActivity.this,
getResources().getString(R.string.vpn_connect_text));
mIsVerification = true;
verifySubscription();
} else {
Toast.makeText(BraveVpnPlansActivity.this, R.string.purchased_failed, Toast.LENGTH_LONG)
.show();
finish();
}
}
@Override
@@ -13,6 +13,7 @@ import android.app.NotificationManager;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.text.TextUtils;
import android.util.Pair;
@@ -36,6 +37,7 @@ import org.chromium.chrome.browser.vpn.models.BraveVpnServerRegion;
import org.chromium.chrome.browser.vpn.models.BraveVpnWireguardProfileCredentials;
import org.chromium.chrome.browser.vpn.utils.BraveVpnPrefUtils;
import org.chromium.chrome.browser.vpn.utils.BraveVpnProfileUtils;
import org.chromium.chrome.browser.vpn.utils.InAppPurchaseWrapper;
import org.chromium.chrome.browser.vpn.wireguard.WireguardConfigUtils;
import java.util.ArrayList;
@@ -53,16 +55,11 @@ public class BraveVpnUtils {
public static String selectedServerRegion;
private static ProgressDialog mProgressDialog;
public enum AlwaysOnVpnType {
BRAVE_VPN,
OTHER_VPN,
NONE;
}
public static boolean isBraveVpnFeatureEnable() {
if (ContextUtils.getApplicationContext().getPackageName().equals(
BraveActivity.BRAVE_PRODUCTION_PACKAGE_NAME)
|| BraveVpnPrefUtils.isBraveVpnFeatureEnabled()) {
if ((ContextUtils.getApplicationContext().getPackageName().equals(
BraveActivity.BRAVE_PRODUCTION_PACKAGE_NAME)
|| BraveVpnPrefUtils.isBraveVpnFeatureEnabled())
&& Build.VERSION.SDK_INT > Build.VERSION_CODES.M) {
return true;
}
return false;
@@ -25,8 +25,9 @@ import com.android.billingclient.api.PurchasesUpdatedListener;
import com.android.billingclient.api.SkuDetails;
import com.android.billingclient.api.SkuDetailsParams;
import org.chromium.base.Log;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.BraveFeatureList;
import org.chromium.chrome.browser.flags.ChromeFeatureList;
import org.chromium.chrome.browser.vpn.utils.BraveVpnPrefUtils;
import org.chromium.chrome.browser.vpn.utils.BraveVpnUtils;
import org.chromium.ui.widget.Toast;
@@ -88,8 +89,14 @@ public class InAppPurchaseWrapper {
}
}
public BillingClient getBillingClient() {
return mBillingClient;
public boolean isSubscriptionSupported() {
if (mBillingClient != null) {
BillingResult result =
mBillingClient.isFeatureSupported(BillingClient.FeatureType.SUBSCRIPTIONS);
return (result.getResponseCode() == BillingClient.BillingResponseCode.OK
&& ChromeFeatureList.isEnabled(BraveFeatureList.BRAVE_REWARDS));
}
return false;
}
private void querySkuDetailsAsync(List<String> skuList) {
@@ -16,7 +16,7 @@
android:layout_width="match_parent"
android:layout_height="140dp"
android:layout_marginTop="-7dp"
android:src="@drawable/ic_embellishments"
app:srcCompat="@drawable/ic_embellishments"
android:contentDescription="@null"/>
<LinearLayout
@@ -30,7 +30,7 @@
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="8dp"
android:src="@drawable/ic_vpn_shield"
app:srcCompat="@drawable/ic_vpn_shield"
android:contentDescription="@null"/>
<TextView
@@ -118,6 +118,6 @@
android:layout_gravity="end|top"
android:tint="@color/brave_stats_close_button_color"
android:padding="16dp"
android:src="@drawable/btn_close"/>
app:srcCompat="@drawable/btn_close"/>
</FrameLayout>
@@ -23,13 +23,18 @@
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/ic_card_background"
android:padding="16dp">
android:layout_height="wrap_content">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:contentDescription="@null"
app:srcCompat="@drawable/ic_card_background"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp"
android:orientation="vertical">
<TextView
@@ -84,12 +89,13 @@
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/modal_close"
android:padding="16dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@null"
android:layout_gravity="end|top"
android:tint="@android:color/white"
android:src="@drawable/btn_close"/>
app:tint="@android:color/white"
app:srcCompat="@drawable/btn_close"/>
</FrameLayout>
@@ -2344,9 +2344,6 @@ If you don't accept this request, VPN will not reconnect and your internet conne
<message name="IDS_VPN_SUPPORT" desc="Brave VPN settings section text">
VPN Support
</message>
<!-- <message name="IDS_VPN_PROFILE_IS_NOT_CREATED" desc="Brave VPN profile error text">
Vpn profile is not created. Creating a new profile.
</message> -->
<message name="IDS_FAIL_TO_GET_SERVER_LOCATIONS" desc="Brave VPN error text">
Fail to get server location. Please try again later.
</message>