Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable Brave vpn on beta & nightly (uplift to 1.61.x) #20974

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ public class BraveQAPreferences extends BravePreferenceFragment
private static final int MAX_ADS = 10;
private static final int DEFAULT_ADS_PER_HOUR = 2;

private ChromeSwitchPreference mBraveVpnFeature;
private ChromeSwitchPreference mVpnLinkSubscriptionOnDev;
private ChromeSwitchPreference mBraveDormantFeatureEngagement;
private ChromeSwitchPreference mIsStagingServer;
Expand All @@ -92,12 +91,6 @@ public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
SettingsUtils.addPreferencesFromResource(this, R.xml.qa_preferences);

mBraveVpnFeature =
(ChromeSwitchPreference) findPreference(BraveVpnPrefUtils.PREF_BRAVE_VPN_FEATURE);
if (mBraveVpnFeature != null) {
mBraveVpnFeature.setOnPreferenceChangeListener(this);
}

mVpnLinkSubscriptionOnDev = (ChromeSwitchPreference) findPreference(
BraveVpnPrefUtils.PREF_BRAVE_VPN_LINK_SUBSCRIPTION_ON_STAGING);
if (mVpnLinkSubscriptionOnDev != null) {
Expand Down Expand Up @@ -261,7 +254,6 @@ public boolean onPreferenceChange(Preference preference, Object newValue) {
} else if (PREF_QA_DEBUG_NTP.equals(preference.getKey())
|| PREF_USE_SYNC_STAGING_SERVER.equals(preference.getKey())
|| PREF_QA_VLOG_REWARDS.equals(preference.getKey())
|| BraveVpnPrefUtils.PREF_BRAVE_VPN_FEATURE.equals(preference.getKey())
|| BraveVpnPrefUtils.PREF_BRAVE_VPN_LINK_SUBSCRIPTION_ON_STAGING.equals(
preference.getKey())
|| OnboardingPrefManager.PREF_DORMANT_USERS_ENGAGEMENT.equals(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,11 @@

public class InAppPurchaseWrapper {
private static final String TAG = "InAppPurchaseWrapper";
public static final String NIGHTLY_MONTHLY_SUBSCRIPTION = "nightly.bravevpn.monthly";
public static final String NIGHTLY_YEARLY_SUBSCRIPTION = "nightly.bravevpn.yearly";
private static final String NIGHTLY_MONTHLY_SUBSCRIPTION = "nightly.bravevpn.monthly";
private static final String NIGHTLY_YEARLY_SUBSCRIPTION = "nightly.bravevpn.yearly";

private static final String BETA_MONTHLY_SUBSCRIPTION = "beta.bravevpn.monthly";
private static final String BETA_YEARLY_SUBSCRIPTION = "beta.bravevpn.yearly";

public static final String RELEASE_MONTHLY_SUBSCRIPTION = "brave.vpn.monthly";
public static final String RELEASE_YEARLY_SUBSCRIPTION = "brave.vpn.yearly";
Expand All @@ -53,7 +56,10 @@ public class InAppPurchaseWrapper {
private static volatile InAppPurchaseWrapper sInAppPurchaseWrapper;
private static Object sMutex = new Object();

public enum SubscriptionType { MONTHLY, YEARLY }
private enum SubscriptionType {
MONTHLY,
YEARLY
}

private MutableLiveData<ProductDetails> mMutableMonthlyProductDetails = new MutableLiveData();
private LiveData<ProductDetails> mMonthlyProductDetails = mMutableMonthlyProductDetails;
Expand Down Expand Up @@ -88,6 +94,7 @@ public static InAppPurchaseWrapper getInstance() {

public boolean isMonthlySubscription(String productId) {
return productId.equals(NIGHTLY_MONTHLY_SUBSCRIPTION)
|| productId.equals(BETA_MONTHLY_SUBSCRIPTION)
|| productId.equals(RELEASE_MONTHLY_SUBSCRIPTION);
}

Expand Down Expand Up @@ -148,11 +155,14 @@ private void endConnection() {
}

public String getProductId(SubscriptionType subscriptionType) {
boolean isReleaseBuild = ContextUtils.getApplicationContext().getPackageName().equals(
BraveConstants.BRAVE_PRODUCTION_PACKAGE_NAME);
if (isReleaseBuild) {
String bravePackageName = ContextUtils.getApplicationContext().getPackageName();
if (bravePackageName.equals(BraveConstants.BRAVE_PRODUCTION_PACKAGE_NAME)) {
return subscriptionType == SubscriptionType.MONTHLY ? RELEASE_MONTHLY_SUBSCRIPTION
: RELEASE_YEARLY_SUBSCRIPTION;
} else if (bravePackageName.equals(BraveConstants.BRAVE_BETA_PACKAGE_NAME)) {
return subscriptionType == SubscriptionType.MONTHLY
? BETA_MONTHLY_SUBSCRIPTION
: BETA_YEARLY_SUBSCRIPTION;
} else {
return subscriptionType == SubscriptionType.MONTHLY ? NIGHTLY_MONTHLY_SUBSCRIPTION
: NIGHTLY_YEARLY_SUBSCRIPTION;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ public class BraveVpnPrefUtils {
private static final String PREF_EXCLUDED_PACKAGES = "excluded_packages";

public static final String PREF_BRAVE_VPN_AUTOMATIC = "automatic";
public static final String PREF_BRAVE_VPN_FEATURE = "brave_vpn_feature";
public static final String PREF_BRAVE_VPN_LINK_SUBSCRIPTION_ON_STAGING =
"brave_vpn_link_subscription_on_staging";
public static final String PREF_BRAVE_VPN_START = "brave_vpn_start";
Expand All @@ -52,111 +51,101 @@ public class BraveVpnPrefUtils {
public static final String PREF_SESSION_END_TIME = "brave_vpn_session_end_time";
private static final String PREF_LINK_SUBSCRIPTION_DIALOG = "link_subscription_dialog";

private static final SharedPreferences mSharedPreferences =
private static final SharedPreferences sSharedPreferences =
ContextUtils.getAppSharedPreferences();

public static boolean isBraveVpnFeatureEnabled() {
return mSharedPreferences.getBoolean(PREF_BRAVE_VPN_FEATURE, false);
}

public static void setBraveVpnFeatureEnabled(boolean newValue) {
SharedPreferences.Editor sharedPreferencesEditor = mSharedPreferences.edit();
sharedPreferencesEditor.putBoolean(PREF_BRAVE_VPN_FEATURE, newValue);
sharedPreferencesEditor.apply();
}

public static boolean isLinkSubscriptionOnStaging() {
return mSharedPreferences.getBoolean(PREF_BRAVE_VPN_LINK_SUBSCRIPTION_ON_STAGING, false);
return sSharedPreferences.getBoolean(PREF_BRAVE_VPN_LINK_SUBSCRIPTION_ON_STAGING, false);
}

public static void setLinkSubscriptionOnStaging(boolean newValue) {
SharedPreferences.Editor sharedPreferencesEditor = mSharedPreferences.edit();
SharedPreferences.Editor sharedPreferencesEditor = sSharedPreferences.edit();
sharedPreferencesEditor.putBoolean(PREF_BRAVE_VPN_LINK_SUBSCRIPTION_ON_STAGING, newValue);
sharedPreferencesEditor.apply();
}

public static boolean isLinkSubscriptionDialogShown() {
return mSharedPreferences.getBoolean(PREF_LINK_SUBSCRIPTION_DIALOG, false);
return sSharedPreferences.getBoolean(PREF_LINK_SUBSCRIPTION_DIALOG, false);
}

public static void setLinkSubscriptionDialogShown(boolean newValue) {
SharedPreferences.Editor sharedPreferencesEditor = mSharedPreferences.edit();
SharedPreferences.Editor sharedPreferencesEditor = sSharedPreferences.edit();
sharedPreferencesEditor.putBoolean(PREF_LINK_SUBSCRIPTION_DIALOG, newValue);
sharedPreferencesEditor.apply();
}

public static boolean shouldShowCallout() {
return mSharedPreferences.getBoolean(PREF_BRAVE_VPN_CALLOUT, true);
return sSharedPreferences.getBoolean(PREF_BRAVE_VPN_CALLOUT, true);
}

public static void setCallout(boolean newValue) {
SharedPreferences.Editor sharedPreferencesEditor = mSharedPreferences.edit();
SharedPreferences.Editor sharedPreferencesEditor = sSharedPreferences.edit();
sharedPreferencesEditor.putBoolean(PREF_BRAVE_VPN_CALLOUT, newValue);
sharedPreferencesEditor.apply();
}

public static boolean shouldShowCalloutSettings() {
return mSharedPreferences.getBoolean(PREF_BRAVE_VPN_CALLOUT_SETTINGS, true);
return sSharedPreferences.getBoolean(PREF_BRAVE_VPN_CALLOUT_SETTINGS, true);
}

public static void setCalloutSettings(boolean newValue) {
SharedPreferences.Editor sharedPreferencesEditor = mSharedPreferences.edit();
SharedPreferences.Editor sharedPreferencesEditor = sSharedPreferences.edit();
sharedPreferencesEditor.putBoolean(PREF_BRAVE_VPN_CALLOUT_SETTINGS, newValue);
sharedPreferencesEditor.apply();
}

public static boolean isSubscriptionPurchase() {
return mSharedPreferences.getBoolean(PREF_BRAVE_VPN_SUBSCRIPTION_PURCHASE, false);
return sSharedPreferences.getBoolean(PREF_BRAVE_VPN_SUBSCRIPTION_PURCHASE, false);
}

public static void setSubscriptionPurchase(boolean newValue) {
SharedPreferences.Editor sharedPreferencesEditor = mSharedPreferences.edit();
SharedPreferences.Editor sharedPreferencesEditor = sSharedPreferences.edit();
sharedPreferencesEditor.putBoolean(PREF_BRAVE_VPN_SUBSCRIPTION_PURCHASE, newValue);
sharedPreferencesEditor.apply();
}

public static void setPaymentState(int newValue) {
SharedPreferences.Editor sharedPreferencesEditor = mSharedPreferences.edit();
SharedPreferences.Editor sharedPreferencesEditor = sSharedPreferences.edit();
sharedPreferencesEditor.putInt(PREF_BRAVE_VPN_PAYMENT_STATE, newValue);
sharedPreferencesEditor.apply();
}

public static boolean isTrialSubscription() {
return mSharedPreferences.getInt(PREF_BRAVE_VPN_PAYMENT_STATE, 0) == 2;
return sSharedPreferences.getInt(PREF_BRAVE_VPN_PAYMENT_STATE, 0) == 2;
}

public static boolean isResetConfiguration() {
return mSharedPreferences.getBoolean(PREF_BRAVE_VPN_RESET_CONFIGURATION, false);
return sSharedPreferences.getBoolean(PREF_BRAVE_VPN_RESET_CONFIGURATION, false);
}

public static void setResetConfiguration(boolean newValue) {
SharedPreferences.Editor sharedPreferencesEditor = mSharedPreferences.edit();
SharedPreferences.Editor sharedPreferencesEditor = sSharedPreferences.edit();
sharedPreferencesEditor.putBoolean(PREF_BRAVE_VPN_RESET_CONFIGURATION, newValue);
sharedPreferencesEditor.apply();
}

public static void setHostname(String value) {
SharedPreferences.Editor sharedPreferencesEditor = mSharedPreferences.edit();
SharedPreferences.Editor sharedPreferencesEditor = sSharedPreferences.edit();
sharedPreferencesEditor.putString(PREF_BRAVE_VPN_HOSTNAME, value);
sharedPreferencesEditor.apply();
}

public static String getHostname() {
return mSharedPreferences.getString(PREF_BRAVE_VPN_HOSTNAME, "");
return sSharedPreferences.getString(PREF_BRAVE_VPN_HOSTNAME, "");
}

public static void setHostnameDisplay(String value) {
SharedPreferences.Editor sharedPreferencesEditor = mSharedPreferences.edit();
SharedPreferences.Editor sharedPreferencesEditor = sSharedPreferences.edit();
sharedPreferencesEditor.putString(PREF_BRAVE_VPN_HOSTNAME_DISPLAY, value);
sharedPreferencesEditor.apply();
}

public static String getHostnameDisplay() {
return mSharedPreferences.getString(PREF_BRAVE_VPN_HOSTNAME_DISPLAY, "");
return sSharedPreferences.getString(PREF_BRAVE_VPN_HOSTNAME_DISPLAY, "");
}

public static void setPurchaseToken(String value) {
SharedPreferences.Editor sharedPreferencesEditor = mSharedPreferences.edit();
SharedPreferences.Editor sharedPreferencesEditor = sSharedPreferences.edit();
sharedPreferencesEditor.putString(PREF_BRAVE_VPN_PURCHASE_TOKEN, value);
sharedPreferencesEditor.apply();
UserPrefs.get(Profile.getLastUsedRegularProfile())
Expand All @@ -167,110 +156,110 @@ public static void setPurchaseToken(String value) {
}

public static String getPurchaseToken() {
return mSharedPreferences.getString(PREF_BRAVE_VPN_PURCHASE_TOKEN, "");
return sSharedPreferences.getString(PREF_BRAVE_VPN_PURCHASE_TOKEN, "");
}

public static void setProductId(String value) {
SharedPreferences.Editor sharedPreferencesEditor = mSharedPreferences.edit();
SharedPreferences.Editor sharedPreferencesEditor = sSharedPreferences.edit();
sharedPreferencesEditor.putString(PREF_BRAVE_VPN_PRODUCT_ID, value);
sharedPreferencesEditor.apply();
UserPrefs.get(Profile.getLastUsedRegularProfile())
.setString(BravePref.BRAVE_VPN_PRODUCT_ID_ANDROID, value);
}

public static String getProductId() {
return mSharedPreferences.getString(PREF_BRAVE_VPN_PRODUCT_ID, "");
return sSharedPreferences.getString(PREF_BRAVE_VPN_PRODUCT_ID, "");
}

public static void setPurchaseExpiry(Long value) {
SharedPreferences.Editor sharedPreferencesEditor = mSharedPreferences.edit();
SharedPreferences.Editor sharedPreferencesEditor = sSharedPreferences.edit();
sharedPreferencesEditor.putLong(PREF_BRAVE_VPN_PURCHASE_EXPIRY, value);
sharedPreferencesEditor.apply();
}

public static Long getPurchaseExpiry() {
return mSharedPreferences.getLong(PREF_BRAVE_VPN_PURCHASE_EXPIRY, 0);
return sSharedPreferences.getLong(PREF_BRAVE_VPN_PURCHASE_EXPIRY, 0);
}

public static void setServerRegions(String value) {
SharedPreferences.Editor sharedPreferencesEditor = mSharedPreferences.edit();
SharedPreferences.Editor sharedPreferencesEditor = sSharedPreferences.edit();
sharedPreferencesEditor.putString(PREF_BRAVE_VPN_SERVER_REGIONS, value);
sharedPreferencesEditor.apply();
}

public static String getServerRegions() {
return mSharedPreferences.getString(PREF_BRAVE_VPN_SERVER_REGIONS, "");
return sSharedPreferences.getString(PREF_BRAVE_VPN_SERVER_REGIONS, "");
}

public static String getServerRegion() {
return mSharedPreferences.getString(
return sSharedPreferences.getString(
PREF_BRAVE_VPN_SERVER_CHANGE_LOCATION, PREF_BRAVE_VPN_AUTOMATIC);
}

public static void setServerRegion(String newValue) {
SharedPreferences.Editor sharedPreferencesEditor = mSharedPreferences.edit();
SharedPreferences.Editor sharedPreferencesEditor = sSharedPreferences.edit();
sharedPreferencesEditor.putString(PREF_BRAVE_VPN_SERVER_CHANGE_LOCATION, newValue);
sharedPreferencesEditor.apply();
}

public static void setApiAuthToken(String value) {
SharedPreferences.Editor sharedPreferencesEditor = mSharedPreferences.edit();
SharedPreferences.Editor sharedPreferencesEditor = sSharedPreferences.edit();
sharedPreferencesEditor.putString(PREF_BRAVE_VPN_API_AUTH_TOKEN, value);
sharedPreferencesEditor.apply();
}

public static String getApiAuthToken() {
return mSharedPreferences.getString(PREF_BRAVE_VPN_API_AUTH_TOKEN, "");
return sSharedPreferences.getString(PREF_BRAVE_VPN_API_AUTH_TOKEN, "");
}

public static void setSubscriberCredential(String value) {
SharedPreferences.Editor sharedPreferencesEditor = mSharedPreferences.edit();
SharedPreferences.Editor sharedPreferencesEditor = sSharedPreferences.edit();
sharedPreferencesEditor.putString(PREF_BRAVE_VPN_SUBSCRIBER_CREDENTIAL, value);
sharedPreferencesEditor.apply();
}

public static String getSubscriberCredential() {
return mSharedPreferences.getString(PREF_BRAVE_VPN_SUBSCRIBER_CREDENTIAL, "");
return sSharedPreferences.getString(PREF_BRAVE_VPN_SUBSCRIBER_CREDENTIAL, "");
}

public static void setClientId(String value) {
SharedPreferences.Editor sharedPreferencesEditor = mSharedPreferences.edit();
SharedPreferences.Editor sharedPreferencesEditor = sSharedPreferences.edit();
sharedPreferencesEditor.putString(PREF_BRAVE_VPN_CLIENT_ID, value);
sharedPreferencesEditor.apply();
}

public static String getClientId() {
return mSharedPreferences.getString(PREF_BRAVE_VPN_CLIENT_ID, "");
return sSharedPreferences.getString(PREF_BRAVE_VPN_CLIENT_ID, "");
}

public static void setIpAddress(String value) {
SharedPreferences.Editor sharedPreferencesEditor = mSharedPreferences.edit();
SharedPreferences.Editor sharedPreferencesEditor = sSharedPreferences.edit();
sharedPreferencesEditor.putString(PREF_BRAVE_VPN_IP_ADDRESS, value);
sharedPreferencesEditor.apply();
}

public static String getIpAddress() {
return mSharedPreferences.getString(PREF_BRAVE_VPN_IP_ADDRESS, "");
return sSharedPreferences.getString(PREF_BRAVE_VPN_IP_ADDRESS, "");
}

public static void setServerPublicKey(String value) {
SharedPreferences.Editor sharedPreferencesEditor = mSharedPreferences.edit();
SharedPreferences.Editor sharedPreferencesEditor = sSharedPreferences.edit();
sharedPreferencesEditor.putString(PREF_BRAVE_VPN_SERVER_PUBLIC_KEY, value);
sharedPreferencesEditor.apply();
}

public static String getServerPublicKey() {
return mSharedPreferences.getString(PREF_BRAVE_VPN_SERVER_PUBLIC_KEY, "");
return sSharedPreferences.getString(PREF_BRAVE_VPN_SERVER_PUBLIC_KEY, "");
}

public static void setClientPrivateKey(String value) {
SharedPreferences.Editor sharedPreferencesEditor = mSharedPreferences.edit();
SharedPreferences.Editor sharedPreferencesEditor = sSharedPreferences.edit();
sharedPreferencesEditor.putString(PREF_BRAVE_VPN_CLIENT_PRIVATE_KEY, value);
sharedPreferencesEditor.apply();
}

public static String getClientPrivateKey() {
return mSharedPreferences.getString(PREF_BRAVE_VPN_CLIENT_PRIVATE_KEY, "");
return sSharedPreferences.getString(PREF_BRAVE_VPN_CLIENT_PRIVATE_KEY, "");
}

public static void setPrefModel(BraveVpnPrefModel braveVpnPrefModel) {
Expand All @@ -286,32 +275,32 @@ public static void setPrefModel(BraveVpnPrefModel braveVpnPrefModel) {
}

public static Set<String> getExcludedPackages() {
return mSharedPreferences.getStringSet(PREF_EXCLUDED_PACKAGES, Collections.emptySet());
return sSharedPreferences.getStringSet(PREF_EXCLUDED_PACKAGES, Collections.emptySet());
}

public static void setExcludedPackages(Set<String> packages) {
SharedPreferences.Editor sharedPreferencesEditor = mSharedPreferences.edit();
SharedPreferences.Editor sharedPreferencesEditor = sSharedPreferences.edit();
sharedPreferencesEditor.putStringSet(PREF_EXCLUDED_PACKAGES, packages);
sharedPreferencesEditor.apply();
}

public static void setSessionEndTimeMs(long timeMs) {
SharedPreferences.Editor sharedPreferencesEditor = mSharedPreferences.edit();
SharedPreferences.Editor sharedPreferencesEditor = sSharedPreferences.edit();
sharedPreferencesEditor.putLong(PREF_SESSION_END_TIME, timeMs);
sharedPreferencesEditor.apply();
}

public static long getSessionEndTimeMs() {
return mSharedPreferences.getLong(PREF_SESSION_END_TIME, -1);
return sSharedPreferences.getLong(PREF_SESSION_END_TIME, -1);
}

public static void setSessionStartTimeMs(long timeMs) {
SharedPreferences.Editor sharedPreferencesEditor = mSharedPreferences.edit();
SharedPreferences.Editor sharedPreferencesEditor = sSharedPreferences.edit();
sharedPreferencesEditor.putLong(PREF_SESSION_START_TIME, timeMs);
sharedPreferencesEditor.apply();
}

public static long getSessionStartTimeMs() {
return mSharedPreferences.getLong(PREF_SESSION_START_TIME, -1);
return sSharedPreferences.getLong(PREF_SESSION_START_TIME, -1);
}
}
Loading