<commit_before>package com.braintreepayments.api;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;

import com.braintreepayments.api.ClientToken.PayPal;
import com.braintreepayments.api.exceptions.ConfigurationException;
import com.braintreepayments.api.models.PayPalAccountBuilder;
import com.paypal.android.sdk.payments.PayPalAuthorization;
import com.paypal.android.sdk.payments.PayPalConfiguration;
import com.paypal.android.sdk.payments.PayPalFuturePaymentActivity;
import com.paypal.android.sdk.payments.PayPalOAuthScopes;
import com.paypal.android.sdk.payments.PayPalService;
import com.paypal.android.sdk.payments.PayPalTouch;
import com.paypal.android.sdk.payments.PayPalTouchActivity;
import com.paypal.android.sdk.payments.PayPalTouchConfirmation;

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

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

public class PayPalHelper {

    private static final String OFFLINE = "offline";

    protected static boolean sEnableSignatureVerification = true;

    private PayPalHelper() {
        throw new IllegalStateException("Non-instantiable class.");
    }

    protected static void startPaypal(Context context, ClientToken clientToken) {
        context.startService(buildPayPalServiceIntent(context, clientToken));
    }

    protected static void launchPayPal(Activity activity, int requestCode, ClientToken clientToken) {
        Class klass;
        if (PayPalTouch.available(activity.getBaseContext(), sEnableSignatureVerification) &&
                !clientToken.getPayPal().equals(OFFLINE) && !clientToken.getPayPal().getTouchDisabled()) {
            klass = PayPalTouchActivity.class;
        } else {
            klass = PayPalFuturePaymentActivity.class;
        }

        Intent intent = new Intent(activity, klass);
        Set<String> scopes = new HashSet<String>(
                Arrays.asList(
                    PayPalOAuthScopes.PAYPAL_SCOPE_EMAIL,
                    PayPalOAuthScopes.PAYPAL_SCOPE_PROFILE,
                    PayPalOAuthScopes.PAYPAL_SCOPE_FUTURE_PAYMENTS)
        );
        intent.putExtra(PayPalTouchActivity.EXTRA_REQUESTED_SCOPES, new PayPalOAuthScopes(scopes));
        activity.startActivityForResult(intent, requestCode);
    }

    protected static void stopPaypalService(Context context) {<commit_msg>Stop PayPal service pollution; Fix PayPal offline check<commit_after>package com.braintreepayments.api;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;

import com.braintreepayments.api.ClientToken.PayPal;
import com.braintreepayments.api.exceptions.ConfigurationException;
import com.braintreepayments.api.models.PayPalAccountBuilder;
import com.paypal.android.sdk.payments.PayPalAuthorization;
import com.paypal.android.sdk.payments.PayPalConfiguration;
import com.paypal.android.sdk.payments.PayPalFuturePaymentActivity;
import com.paypal.android.sdk.payments.PayPalOAuthScopes;
import com.paypal.android.sdk.payments.PayPalService;
import com.paypal.android.sdk.payments.PayPalTouch;
import com.paypal.android.sdk.payments.PayPalTouchActivity;
import com.paypal.android.sdk.payments.PayPalTouchConfirmation;

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

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

public class PayPalHelper {

    private static final String OFFLINE = "offline";

    protected static boolean sEnableSignatureVerification = true;

    private PayPalHelper() {
        throw new IllegalStateException("Non-instantiable class.");
    }

    protected static void startPaypal(Context context, ClientToken clientToken) {
        stopPaypalService(context);
        context.startService(buildPayPalServiceIntent(context, clientToken));
    }

    protected static void launchPayPal(Activity activity, int requestCode, ClientToken clientToken) {
        Class klass;
        if (PayPalTouch.available(activity.getBaseContext(), sEnableSignatureVerification) &&
                !clientToken.getPayPal().getEnvironment().equals(OFFLINE) &&
                !clientToken.getPayPal().getTouchDisabled()) {
            klass = PayPalTouchActivity.class;
        } else {
            klass = PayPalFuturePaymentActivity.class;
        }

        Intent intent = new Intent(activity, klass);
        Set<String> scopes = new HashSet<String>(
                Arrays.asList(
                    PayPalOAuthScopes.PAYPAL_SCOPE_EMAIL,
                    PayPalOAuthScopes.PAYPAL_SCOPE_PROFILE,
                    PayPalOAuthScopes.PAYPAL_SCOPE_FUTURE_PAYMENTS)
        );
        intent.putExtra(PayPalTouchActivity.EXTRA_REQUESTED_SCOPES, new PayPalOAuthScopes(scopes));
        activity.startActivityForResult(intent, requestCode);
    }

    protected static void stopPaypalService(Context context) {
{'fraction_non_alphanumeric': 0.08534360429758768, 'fraction_numerical': 0.0, 'mean_word_length': 3.993927125506073, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '6347163', 'n_tokens_mistral': 1431, 'n_tokens_neox': 1386, 'n_words': 238}