<commit_before>package com.mixpanel.android.viewcrawler;

import android.annotation.TargetApi;
import android.app.Activity;
import android.app.Application;
import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.BitmapFactory;
import android.hardware.Sensor;
import android.hardware.SensorManager;
import android.os.Bundle;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.Looper;
import android.os.Message;
import android.os.Process;
import android.util.Base64;
import android.util.Log;
import android.view.View;
import android.view.ViewTreeObserver;

import com.mixpanel.android.mpmetrics.MPConfig;
import com.mixpanel.android.mpmetrics.MixpanelAPI;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.lang.ref.WeakReference;
import java.net.Socket;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import javax.net.ssl.SSLSocketFactory;

/**
 * This class is for internal use by the Mixpanel API, and should
 * not be called directly by your code.
 */
@TargetApi(14)
public class ViewCrawler {

    public ViewCrawler(Context context, String token, MixpanelAPI mixpanel) {
        mPersistentChanges = new HashMap<String, List<JSONObject>>();
        mEditorChanges = new HashMap<String, List<JSONObject>>();
        mProtocol = new EditProtocol();

        final Application app = (Application) context.getApplicationContext();
        app.registerActivityLifecycleCallbacks(new LifecycleCallbacks());

        final HandlerThread thread = new HandlerThread(ViewCrawler.class.getCanonicalName());
        thread.setPriority(Process.THREAD_PRIORITY_BACKGROUND);
        thread.start();
        mMessageThreadHandler = new ViewCrawlerHandler(context, token, thread.getLooper());
        mMessageThreadHandler.sendMessage(mMessageThreadHandler.obtainMessage(MESSAGE_INITIALIZE_CHANGES));

        mUiThreadHandler = new Handler(Looper.getMainLooper());
        mMixpanel = mixpanel;
    }

    public Tweaks getTweaks() {
        return mTweaks;
    }

    // Must be called on UI Thread
    private void applyAllChanges() {
        synchronized (mLiveActivities) {
            for (Activity activity : mLiveActivities) {
                final String activityName = activity.getClass().getCanonicalName();

                final List<JSONObject> persistentChanges;
                synchronized (mPersistentChanges) {
                    persistentChanges = mPersistentChanges.get(activityName);
                    applyTheseChanges(activity, persistentChanges);
                }


                final List<JSONObject> editorChanges;
                synchronized (mEditorChanges) {
                    editorChanges = mEditorChanges.get(activityName);
                    applyTheseChanges(activity, editorChanges);
                }
            }
        }
    }

    // Must be called on UI Thread
    private void applyTheseChanges(Activity activity, List<JSONObject> changes) {
        if (null != changes) {
            for (JSONObject j : changes) {<commit_msg>Code style<commit_after>package com.mixpanel.android.viewcrawler;

import android.annotation.TargetApi;
import android.app.Activity;
import android.app.Application;
import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.BitmapFactory;
import android.hardware.Sensor;
import android.hardware.SensorManager;
import android.os.Bundle;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.Looper;
import android.os.Message;
import android.os.Process;
import android.util.Base64;
import android.util.Log;
import android.view.View;
import android.view.ViewTreeObserver;

import com.mixpanel.android.mpmetrics.MPConfig;
import com.mixpanel.android.mpmetrics.MixpanelAPI;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.lang.ref.WeakReference;
import java.net.Socket;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import javax.net.ssl.SSLSocketFactory;

/**
 * This class is for internal use by the Mixpanel API, and should
 * not be called directly by your code.
 */
@TargetApi(14)
public class ViewCrawler {

    public ViewCrawler(Context context, String token, MixpanelAPI mixpanel) {
        mPersistentChanges = new HashMap<String, List<JSONObject>>();
        mEditorChanges = new HashMap<String, List<JSONObject>>();
        mProtocol = new EditProtocol();

        final Application app = (Application) context.getApplicationContext();
        app.registerActivityLifecycleCallbacks(new LifecycleCallbacks());

        final HandlerThread thread = new HandlerThread(ViewCrawler.class.getCanonicalName());
        thread.setPriority(Process.THREAD_PRIORITY_BACKGROUND);
        thread.start();
        mMessageThreadHandler = new ViewCrawlerHandler(context, token, thread.getLooper());
        mMessageThreadHandler.sendMessage(mMessageThreadHandler.obtainMessage(MESSAGE_INITIALIZE_CHANGES));

        mUiThreadHandler = new Handler(Looper.getMainLooper());
        mMixpanel = mixpanel;
    }

    public Tweaks getTweaks() {
        return mTweaks;
    }

    // Must be called on UI Thread
    private void applyAllChanges() {
        synchronized (mLiveActivities) {
            for (Activity activity : mLiveActivities) {
                final String activityName = activity.getClass().getCanonicalName();

                synchronized (mPersistentChanges) {
                    final List<JSONObject> persistentChanges = mPersistentChanges.get(activityName);
                    applyTheseChanges(activity, persistentChanges);
                }

                synchronized (mEditorChanges) {
                    final List<JSONObject> editorChanges = mEditorChanges.get(activityName);
                    applyTheseChanges(activity, editorChanges);
                }
            }
        }
    }

    // Must be called on UI Thread
    private void applyTheseChanges(Activity activity, List<JSONObject> changes) {
        if (null != changes) {
            for (JSONObject j : changes) {
{'fraction_non_alphanumeric': 0.08961550105964275, 'fraction_numerical': 0.0012110202845897668, 'mean_word_length': 3.467207572684246, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5106578', 'n_tokens_mistral': 1795, 'n_tokens_neox': 1758, 'n_words': 405}