Skip to content

Commit

Permalink
[Android] Added ability to set tes variations server prior to the fir…
Browse files Browse the repository at this point in the history
…st time run
  • Loading branch information
samartnik committed Oct 8, 2021
1 parent 4880db9 commit 9c5a1b2
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions android/java/org/chromium/base/BraveCommandLineInitUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,23 @@
import org.chromium.base.CommandLine;
import org.chromium.base.CommandLineInitUtil;
import org.chromium.base.ContextUtils;
import org.chromium.base.Log;
import org.chromium.base.supplier.Supplier;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;

public abstract class BraveCommandLineInitUtil {
private static final String TAG = "BraveCommandLineInitUtil";

// Duplicate constant to avoid pull dependancy into base
private static final String PREF_QA_VLOG_REWARDS = "qa_vlog_rewards";
private static final String PREF_QA_COMMAND_LINE = "qa_command_line";
private static final String TEST_VARIATIONS_SERVER_URL_FILE =
"/data/local/tmp/brave-test-variations-server-url";

public static void initCommandLine(
String fileName, @Nullable Supplier<Boolean> shouldUseDebugFlags) {
Expand All @@ -36,6 +45,25 @@ private static void appendBraveSwitchesAndArguments() {
qaCommandLine +=
" --vmodule=*/bat-native-ads/*=6,*/brave_ads/*=6,*/brave_user_model/*=6,*/bat_ads/*=6,*/bat-native-ledger/*=6,*/brave_rewards/*=6";
}

// For testing we need custom variations server url prior to the first time run, so we try
// to read it from the file.
File variationsServerFile = new File(TEST_VARIATIONS_SERVER_URL_FILE);
if (variationsServerFile.exists()) {
try (BufferedReader reader = new BufferedReader(new FileReader(variationsServerFile))) {
String testVariationsServerUrl = reader.readLine();
if (testVariationsServerUrl != null && !testVariationsServerUrl.isEmpty()) {
Log.w(TAG,
"New test variations server url applied: " + testVariationsServerUrl);
qaCommandLine += " --variations-server-url=" + testVariationsServerUrl;
} else {
Log.w(TAG, "Variations server file appears to be empty");
}
} catch (IOException e) {
Log.e(TAG, "Failed to read variations server file: " + e.getMessage());
}
}

@SuppressLint("VisibleForTests")
String[] args = CommandLine.tokenizeQuotedArguments(qaCommandLine.toCharArray());
CommandLine.getInstance().appendSwitchesAndArguments(args);
Expand Down

0 comments on commit 9c5a1b2

Please sign in to comment.