<commit_before>package com.amplitude.api;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicBoolean;

import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.protocol.HTTP;
import org.apache.http.util.EntityUtils;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.location.Location;
import android.location.LocationManager;
import android.os.Build;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.util.Log;
import android.util.Pair;

public class Amplitude {

  public static final String TAG = "com.amplitude.api.Amplitude";

  private static Context context;
  private static String apiKey;
  private static String userId;
  private static String deviceId;

  private static int versionCode;
  private static String versionName;
  private static int buildVersionSdk;
  private static String buildVersionRelease;
  private static String phoneBrand;
  private static String phoneManufacturer;
  private static String phoneModel;
  private static String phoneCarrier;
  private static String country;
  private static String language;

  private static JSONObject globalProperties;

  private static String campaignInformation;
  private static boolean isCurrentlyTrackingCampaign = false;

  private static long sessionId = -1;
  private static boolean sessionStarted = false;
  private static Runnable setSessionIdRunnable;

  private static AtomicBoolean updateScheduled = new AtomicBoolean(false);
  private static AtomicBoolean uploadingCurrently = new AtomicBoolean(false);

  private Amplitude() {
  }

  public static void initialize(Context context, String apiKey) {
    initialize(context, apiKey, null);
  }

  public static void initialize(Context context, String apiKey, String userId) {
    initialize(context, apiKey, userId, false);
  }

  public static void initialize(Context context, String apiKey, boolean trackCampaignSource) {
    initialize(context, apiKey, null, trackCampaignSource);
  }

  public static void initialize(Context context, String apiKey, String userId,
      boolean trackCampaignSource) {
    if (context == null) {
      Log.e(TAG, "Argument context cannot be null in initialize()");
      return;
    }
    if (TextUtils.isEmpty(apiKey)) {
      Log.e(TAG, "Argument apiKey cannot be null or blank in initialize()");
      return;
    }

    Amplitude.context = context.getApplicationContext();
    Amplitude.apiKey = apiKey;
    SharedPreferences preferences = context.getSharedPreferences(getSharedPreferencesName(),
        Context.MODE_PRIVATE);
    if (userId != null) {
      Amplitude.userId = userId;
      preferences.edit().putString(Constants.PREFKEY_USER_ID, userId).commit();
    } else {
      Amplitude.userId = preferences.getString(Constants.PREFKEY_USER_ID, null);
    }
    Amplitude.deviceId = getDeviceId();
    Amplitude.campaignInformation = preferences.getString(Constants.PREFKEY_CAMPAIGN_INFORMATION,
        "{\"tracked\": false}");

    PackageInfo packageInfo;
    try {
      packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
      versionCode = packageInfo.versionCode;
      versionName = packageInfo.versionName;
    } catch (NameNotFoundException e) {
    }
    buildVersionSdk = Build.VERSION.SDK_INT;
    buildVersionRelease = Build.VERSION.RELEASE;
    phoneBrand = Build.BRAND;
    phoneManufacturer = Build.MANUFACTURER;
    phoneModel = Build.MODEL;
    TelephonyManager manager = (TelephonyManager) context
        .getSystemService(Context.TELEPHONY_SERVICE);
    phoneCarrier = manager.getNetworkOperatorName();
    country = Locale.getDefault().getDisplayCountry();
    language = Locale.getDefault().getDisplayLanguage();

    if (trackCampaignSource) {
      trackCampaignSource();
    }
  }

  public static void enableCampaignTracking(Context context, String apiKey) {
    if (context == null) {
      Log.e(TAG, "Argument context cannot be null in enableCampaignTracking()");
      return;
    }
    if (TextUtils.isEmpty(apiKey)) {
      Log.e(TAG, "Argument apiKey cannot be null or blank in enableCampaignTracking()");
      return;
    }

    Amplitude.context = context.getApplicationContext();
    Amplitude.apiKey = apiKey;
    SharedPreferences preferences = context.getSharedPreferences(getSharedPreferencesName(),
        Context.MODE_PRIVATE);
    Amplitude.campaignInformation = preferences.getString(Constants.PREFKEY_CAMPAIGN_INFORMATION,
        "{\"tracked\": false}");

    trackCampaignSource();
  }

  private static void trackCampaignSource() {
    SharedPreferences sharedPreferences = context.getSharedPreferences(getSharedPreferencesName(),<commit_msg>All methods that use context in initialize now use the global app context<commit_after>package com.amplitude.api;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicBoolean;

import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.protocol.HTTP;
import org.apache.http.util.EntityUtils;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.location.Location;
import android.location.LocationManager;
import android.os.Build;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.util.Log;
import android.util.Pair;

public class Amplitude {

  public static final String TAG = "com.amplitude.api.Amplitude";

  private static Context context;
  private static String apiKey;
  private static String userId;
  private static String deviceId;

  private static int versionCode;
  private static String versionName;
  private static int buildVersionSdk;
  private static String buildVersionRelease;
  private static String phoneBrand;
  private static String phoneManufacturer;
  private static String phoneModel;
  private static String phoneCarrier;
  private static String country;
  private static String language;

  private static JSONObject globalProperties;

  private static String campaignInformation;
  private static boolean isCurrentlyTrackingCampaign = false;

  private static long sessionId = -1;
  private static boolean sessionStarted = false;
  private static Runnable setSessionIdRunnable;

  private static AtomicBoolean updateScheduled = new AtomicBoolean(false);
  private static AtomicBoolean uploadingCurrently = new AtomicBoolean(false);

  private Amplitude() {
  }

  public static void initialize(Context context, String apiKey) {
    initialize(context, apiKey, null);
  }

  public static void initialize(Context context, String apiKey, String userId) {
    initialize(context, apiKey, userId, false);
  }

  public static void initialize(Context context, String apiKey, boolean trackCampaignSource) {
    initialize(context, apiKey, null, trackCampaignSource);
  }

  public static void initialize(Context context, String apiKey, String userId,
      boolean trackCampaignSource) {
    if (context == null) {
      Log.e(TAG, "Argument context cannot be null in initialize()");
      return;
    }
    if (TextUtils.isEmpty(apiKey)) {
      Log.e(TAG, "Argument apiKey cannot be null or blank in initialize()");
      return;
    }

    Amplitude.context = context.getApplicationContext();
    Amplitude.apiKey = apiKey;
    SharedPreferences preferences = context.getSharedPreferences(getSharedPreferencesName(),
        Context.MODE_PRIVATE);
    if (userId != null) {
      Amplitude.userId = userId;
      preferences.edit().putString(Constants.PREFKEY_USER_ID, userId).commit();
    } else {
      Amplitude.userId = preferences.getString(Constants.PREFKEY_USER_ID, null);
    }
    Amplitude.deviceId = getDeviceId();
    Amplitude.campaignInformation = preferences.getString(Constants.PREFKEY_CAMPAIGN_INFORMATION,
        "{\"tracked\": false}");

    PackageInfo packageInfo;
    try {
      packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
      versionCode = packageInfo.versionCode;
      versionName = packageInfo.versionName;
    } catch (NameNotFoundException e) {
    }
    buildVersionSdk = Build.VERSION.SDK_INT;
    buildVersionRelease = Build.VERSION.RELEASE;
    phoneBrand = Build.BRAND;
    phoneManufacturer = Build.MANUFACTURER;
    phoneModel = Build.MODEL;
    TelephonyManager manager = (TelephonyManager) context
        .getSystemService(Context.TELEPHONY_SERVICE);
    phoneCarrier = manager.getNetworkOperatorName();
    country = Locale.getDefault().getDisplayCountry();
    language = Locale.getDefault().getDisplayLanguage();

    if (trackCampaignSource) {
      trackCampaignSource();
    }
  }

  public static void enableCampaignTracking(Context context, String apiKey) {
    if (context == null) {
      Log.e(TAG, "Argument context cannot be null in enableCampaignTracking()");
      return;
    }
    if (TextUtils.isEmpty(apiKey)) {
      Log.e(TAG, "Argument apiKey cannot be null or blank in enableCampaignTracking()");
      return;
    }

    context = context.getApplicationContext();
    Amplitude.context = context;
    Amplitude.apiKey = apiKey;
    SharedPreferences preferences = context.getSharedPreferences(getSharedPreferencesName(),
        Context.MODE_PRIVATE);
    Amplitude.campaignInformation = preferences.getString(Constants.PREFKEY_CAMPAIGN_INFORMATION,
        "{\"tracked\": false}");

    trackCampaignSource();
  }

  private static void trackCampaignSource() {
    SharedPreferences sharedPreferences = context.getSharedPreferences(getSharedPreferencesName(),
{'fraction_non_alphanumeric': 0.08785669277162661, 'fraction_numerical': 0.0003600684129984697, 'mean_word_length': 4.651068158697863, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 3, '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': '2074702', 'n_tokens_mistral': 3051, 'n_tokens_neox': 2984, 'n_words': 745}