<commit_before>package com.ionic.deploy;

import android.content.Context;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.util.Log;
import android.content.res.AssetManager;

import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaInterface;
import org.apache.cordova.CordovaPlugin;
import org.apache.cordova.CordovaWebView;
import org.apache.cordova.PluginResult;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.HashSet;
import java.util.Set;
import java.util.Iterator;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import java.util.zip.ZipInputStream;

class JsonHttpResponse {
    String message;
    JSONObject json;
}

public class IonicDeploy extends CordovaPlugin {
    String server = "https://apps.ionic.io";
    Context myContext = null;
    String app_id = null;
    boolean debug = true;

    /**
     * Sets the context of the Command. This can then be used to do things like
     * get file paths associated with the Activity.
     *
     * @param cordova The context of the main Activity.
     * @param webView The CordovaWebView Cordova is running in.
     */
    public void initialize(CordovaInterface cordova, CordovaWebView webView) {
        super.initialize(cordova, webView);

        this.myContext = this.cordova.getActivity().getApplicationContext();
        SharedPreferences prefs = getPreferences();

        this.app_id = prefs.getString("app_id", "");
    }

    /**
     * Executes the request and returns PluginResult.
     *
     * @param action            The action to execute.
     * @param args              JSONArry of arguments for the plugin.
     * @param callbackContext   The callback id used when calling back into JavaScript.
     * @return                  True if the action was valid, false if not.
     */
    public boolean execute(String action, JSONArray args, final CallbackContext callbackContext) throws JSONException {
        if (action.equals("initialize")) {
            // Save the app id if it's not already set
            this.app_id = args.getString(0);

            initApp(this.app_id);
            return true;
        } else if (action.equals("check")) {
            SharedPreferences prefs = getPreferences();

            logMessage("CHECK", "Checking for updates");

            // We do this on every call to make sure it is here, because we dont want to have the initialize function
            this.app_id = args.getString(0);
            initApp(this.app_id);

            // Check for updates in a background thread
            cordova.getThreadPool().execute(new Runnable() {
                public void run() {
                    checkForUpdates(callbackContext);
                }
            });
            return true;
        } else if (action.equals("download")) {
            // Download in a background thread

            // We do this on every call to make sure it is here, because we dont want to have the initialize function
            this.app_id = args.getString(0);
            initApp(this.app_id);
            
            cordova.getThreadPool().execute(new Runnable() {
                public void run() {
                    downloadUpdate(callbackContext);
                }
            });

            return true;
        } else if (action.equals("extract")) {
            // Extract in a background thread
            
            // We do this on every call to make sure it is here, because we dont want to have the initialize function
            this.app_id = args.getString(0);
            initApp(this.app_id);

            cordova.getThreadPool().execute(new Runnable() {
                public void run() {
                    SharedPreferences prefs = getPreferences();

                    // Set the saved uuid to the most recently acquired upstream_uuid
                    String uuid = prefs.getString("uuid", "");

                    unzip("www.zip", uuid, callbackContext);
                }
            });
            return true;
        } else if (action.equals("redirect")) {
            SharedPreferences prefs = getPreferences();

            // We do this on every call to make sure it is here, because we dont want to have the initialize function
            this.app_id = args.getString(0);
            initApp(this.app_id);

            String uuid = prefs.getString("uuid", "");
            final File versionDir = this.myContext.getDir(uuid, Context.MODE_PRIVATE);

            logMessage("REDIRECT_1", versionDir.getAbsolutePath().toString() + "index.html");
            logMessage("REDIRECT", versionDir.toURI() + "index.html");

            cordova.getActivity().runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    webView.loadUrl(versionDir.toURI() + "index.html");
                    webView.reload();
                }
            });

            return true;
        } else {
            return false;<commit_msg>removing reload()<commit_after>package com.ionic.deploy;

import android.content.Context;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.util.Log;
import android.content.res.AssetManager;

import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaInterface;
import org.apache.cordova.CordovaPlugin;
import org.apache.cordova.CordovaWebView;
import org.apache.cordova.PluginResult;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.HashSet;
import java.util.Set;
import java.util.Iterator;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import java.util.zip.ZipInputStream;

class JsonHttpResponse {
    String message;
    JSONObject json;
}

public class IonicDeploy extends CordovaPlugin {
    String server = "https://apps.ionic.io";
    Context myContext = null;
    String app_id = null;
    boolean debug = true;

    /**
     * Sets the context of the Command. This can then be used to do things like
     * get file paths associated with the Activity.
     *
     * @param cordova The context of the main Activity.
     * @param webView The CordovaWebView Cordova is running in.
     */
    public void initialize(CordovaInterface cordova, CordovaWebView webView) {
        super.initialize(cordova, webView);

        this.myContext = this.cordova.getActivity().getApplicationContext();
        SharedPreferences prefs = getPreferences();

        this.app_id = prefs.getString("app_id", "");
    }

    /**
     * Executes the request and returns PluginResult.
     *
     * @param action            The action to execute.
     * @param args              JSONArry of arguments for the plugin.
     * @param callbackContext   The callback id used when calling back into JavaScript.
     * @return                  True if the action was valid, false if not.
     */
    public boolean execute(String action, JSONArray args, final CallbackContext callbackContext) throws JSONException {
        if (action.equals("initialize")) {
            // Save the app id if it's not already set
            this.app_id = args.getString(0);

            initApp(this.app_id);
            return true;
        } else if (action.equals("check")) {
            SharedPreferences prefs = getPreferences();

            logMessage("CHECK", "Checking for updates");

            // We do this on every call to make sure it is here, because we dont want to have the initialize function
            this.app_id = args.getString(0);
            initApp(this.app_id);

            // Check for updates in a background thread
            cordova.getThreadPool().execute(new Runnable() {
                public void run() {
                    checkForUpdates(callbackContext);
                }
            });
            return true;
        } else if (action.equals("download")) {
            // Download in a background thread

            // We do this on every call to make sure it is here, because we dont want to have the initialize function
            this.app_id = args.getString(0);
            initApp(this.app_id);
            
            cordova.getThreadPool().execute(new Runnable() {
                public void run() {
                    downloadUpdate(callbackContext);
                }
            });

            return true;
        } else if (action.equals("extract")) {
            // Extract in a background thread
            
            // We do this on every call to make sure it is here, because we dont want to have the initialize function
            this.app_id = args.getString(0);
            initApp(this.app_id);

            cordova.getThreadPool().execute(new Runnable() {
                public void run() {
                    SharedPreferences prefs = getPreferences();

                    // Set the saved uuid to the most recently acquired upstream_uuid
                    String uuid = prefs.getString("uuid", "");

                    unzip("www.zip", uuid, callbackContext);
                }
            });
            return true;
        } else if (action.equals("redirect")) {
            SharedPreferences prefs = getPreferences();

            // We do this on every call to make sure it is here, because we dont want to have the initialize function
            this.app_id = args.getString(0);
            initApp(this.app_id);

            String uuid = prefs.getString("uuid", "");
            final File versionDir = this.myContext.getDir(uuid, Context.MODE_PRIVATE);

            logMessage("REDIRECT_1", versionDir.getAbsolutePath().toString() + "index.html");
            logMessage("REDIRECT", versionDir.toURI() + "index.html");

            cordova.getActivity().runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    webView.loadUrl(versionDir.toURI() + "index.html");
                }
            });

            return true;
        } else {
            return false;
{'fraction_non_alphanumeric': 0.09174990751017388, 'fraction_numerical': 0.0011098779134295228, 'mean_word_length': 2.1915584415584415, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4484991', 'n_tokens_mistral': 2819, 'n_tokens_neox': 2727, 'n_words': 825}