<commit_before>package com.alexbbb.pjsipandroid;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.util.Log;

import com.alexbbb.pjsipandroid.PJSIPAndroidBroadcastEmitter.BroadcastParameters;

import static com.alexbbb.pjsipandroid.PJSIPAndroidBroadcastEmitter.BroadcastAction.CALL_STATE;
import static com.alexbbb.pjsipandroid.PJSIPAndroidBroadcastEmitter.BroadcastAction.INCOMING_CALL;
import static com.alexbbb.pjsipandroid.PJSIPAndroidBroadcastEmitter.BroadcastAction.REGISTRATION;

/**
 * Reference implementation to receive events emitted by the PJSIP Android library.
 * @author alexbbb (<NAME>)
 */
public class PJSIPAndroidBroadcastReceiver extends BroadcastReceiver {

    private static final String LOG_TAG = "PJSIPAndroidBR";

    private Context receiverContext;

    @Override
    public void onReceive(Context context, Intent intent) {
        if (intent == null) return;

        //save context internally for convenience in subclasses, which can get it with
        //getReceiverContext method
        receiverContext = context;

        String action = intent.getAction();
        PJSIPAndroidBroadcastEmitter broadcastEmitter = PJSIPAndroid.getBroadcastEmitter();

        if (action.equals(broadcastEmitter.getAction(REGISTRATION))) {
            onRegistration(intent.getStringExtra(BroadcastParameters.ACCOUNT_ID),
                           intent.getIntExtra(BroadcastParameters.CODE, -1));

        } else if (action.equals(broadcastEmitter.getAction(INCOMING_CALL))) {
            onIncomingCall(intent.getStringExtra(BroadcastParameters.ACCOUNT_ID),
                           intent.getIntExtra(BroadcastParameters.CALL_ID, -1),
                           intent.getStringExtra(BroadcastParameters.DISPLAY_NAME),
                           intent.getStringExtra(BroadcastParameters.REMOTE_URI));

        } else if (action.equals(broadcastEmitter.getAction(CALL_STATE))) {
            onCallState(intent.getStringExtra(BroadcastParameters.ACCOUNT_ID),
                        intent.getIntExtra(BroadcastParameters.CALL_ID, -1),
                        intent.getIntExtra(BroadcastParameters.CALL_STATE, -1));
        }
    }

    protected Context getReceiverContext() {
        return receiverContext;
    }

    /**
     * Register this broadcast receiver.
     * It's recommended to register the receiver in Activity's onResume method.
     *
     * @param context context in which to register this receiver
     */
    public void register(final Context context) {
        PJSIPAndroidBroadcastEmitter broadcastEmitter = PJSIPAndroid.getBroadcastEmitter();

        final IntentFilter intentFilter = new IntentFilter();
        intentFilter.addAction(broadcastEmitter.getAction(REGISTRATION));
        intentFilter.addAction(broadcastEmitter.getAction(INCOMING_CALL));
        intentFilter.addAction(broadcastEmitter.getAction(CALL_STATE));
        context.registerReceiver(this, intentFilter);
    }

    /**
     * Unregister this broadcast receiver.
     * It's recommended to unregister the receiver in Activity's onPause method.
     *
     * @param context context in which to unregister this receiver
     */
    public void unregister(final Context context) {
        context.unregisterReceiver(this);
    }

    public void onRegistration(String accountID, int registrationStateCode) {
        Log.d(LOG_TAG, "onRegistration - accountID: " + accountID +
                       ", registrationStateCode: " + registrationStateCode);
    }

    public void onIncomingCall(String accountID, int callID, String displayName, String remoteUri) {
        Log.d(LOG_TAG, "onIncomingCall - accountID: " + accountID +
                       ", callID: " + callID +
                       ", displayName: " + displayName +
                       ", remoteUri: " + remoteUri);
    }

    public void onCallState(String accountID, int callID, int callStateCode) {
        Log.d(LOG_TAG, "onIncomingCall - accountID: " + accountID +
                       ", callID: " + callID +
                       ", callStateCode: " + callStateCode);
    }
}<commit_msg>pass pjsip enum values to methods instead of integer values for better client code readability<commit_after>package com.alexbbb.pjsipandroid;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.util.Log;

import com.alexbbb.pjsipandroid.PJSIPAndroidBroadcastEmitter.BroadcastParameters;

import org.pjsip.pjsua2.pjsip_inv_state;
import org.pjsip.pjsua2.pjsip_status_code;

import static com.alexbbb.pjsipandroid.PJSIPAndroidBroadcastEmitter.BroadcastAction.CALL_STATE;
import static com.alexbbb.pjsipandroid.PJSIPAndroidBroadcastEmitter.BroadcastAction.INCOMING_CALL;
import static com.alexbbb.pjsipandroid.PJSIPAndroidBroadcastEmitter.BroadcastAction.REGISTRATION;

/**
 * Reference implementation to receive events emitted by the PJSIP Android library.
 * @author alexbbb (<NAME>)
 */
public class PJSIPAndroidBroadcastReceiver extends BroadcastReceiver {

    private static final String LOG_TAG = "PJSIPAndroidBR";

    private Context receiverContext;

    @Override
    public void onReceive(Context context, Intent intent) {
        if (intent == null) return;

        //save context internally for convenience in subclasses, which can get it with
        //getReceiverContext method
        receiverContext = context;

        String action = intent.getAction();
        PJSIPAndroidBroadcastEmitter broadcastEmitter = PJSIPAndroid.getBroadcastEmitter();

        if (action.equals(broadcastEmitter.getAction(REGISTRATION))) {
            int stateCode = intent.getIntExtra(BroadcastParameters.CODE, -1);
            onRegistration(intent.getStringExtra(BroadcastParameters.ACCOUNT_ID),
                           pjsip_status_code.swigToEnum(stateCode));

        } else if (action.equals(broadcastEmitter.getAction(INCOMING_CALL))) {
            onIncomingCall(intent.getStringExtra(BroadcastParameters.ACCOUNT_ID),
                           intent.getIntExtra(BroadcastParameters.CALL_ID, -1),
                           intent.getStringExtra(BroadcastParameters.DISPLAY_NAME),
                           intent.getStringExtra(BroadcastParameters.REMOTE_URI));

        } else if (action.equals(broadcastEmitter.getAction(CALL_STATE))) {
            int callState = intent.getIntExtra(BroadcastParameters.CALL_STATE, -1);
            onCallState(intent.getStringExtra(BroadcastParameters.ACCOUNT_ID),
                        intent.getIntExtra(BroadcastParameters.CALL_ID, -1),
                        pjsip_inv_state.swigToEnum(callState));
        }
    }

    protected Context getReceiverContext() {
        return receiverContext;
    }

    /**
     * Register this broadcast receiver.
     * It's recommended to register the receiver in Activity's onResume method.
     *
     * @param context context in which to register this receiver
     */
    public void register(final Context context) {
        PJSIPAndroidBroadcastEmitter broadcastEmitter = PJSIPAndroid.getBroadcastEmitter();

        final IntentFilter intentFilter = new IntentFilter();
        intentFilter.addAction(broadcastEmitter.getAction(REGISTRATION));
        intentFilter.addAction(broadcastEmitter.getAction(INCOMING_CALL));
        intentFilter.addAction(broadcastEmitter.getAction(CALL_STATE));
        context.registerReceiver(this, intentFilter);
    }

    /**
     * Unregister this broadcast receiver.
     * It's recommended to unregister the receiver in Activity's onPause method.
     *
     * @param context context in which to unregister this receiver
     */
    public void unregister(final Context context) {
        context.unregisterReceiver(this);
    }

    public void onRegistration(String accountID, pjsip_status_code registrationStateCode) {
        Log.d(LOG_TAG, "onRegistration - accountID: " + accountID +
                       ", registrationStateCode: " + registrationStateCode);
    }

    public void onIncomingCall(String accountID, int callID, String displayName, String remoteUri) {
        Log.d(LOG_TAG, "onIncomingCall - accountID: " + accountID +
                       ", callID: " + callID +
                       ", displayName: " + displayName +
                       ", remoteUri: " + remoteUri);
    }

    public void onCallState(String accountID, int callID, pjsip_inv_state callStateCode) {
        Log.d(LOG_TAG, "onIncomingCall - accountID: " + accountID +
                       ", callID: " + callID +
                       ", callStateCode: " + callStateCode);
    }
}
{'fraction_non_alphanumeric': 0.08119266055045872, 'fraction_numerical': 0.0011467889908256881, 'mean_word_length': 3.0676305970149254, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '3959255', 'n_tokens_mistral': 2317, 'n_tokens_neox': 2285, 'n_words': 480}