<commit_before>package cz.robyer.gamework.scenario.reaction;

import java.util.List;

import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.util.Log;

/**
 * 
 * @author <NAME>
 */
public class ActivityReaction extends Reaction {
	protected String value;
	protected Intent intent;
	
	public ActivityReaction(String id, String value) {
		super(id);
		this.value = value;
	}
	
	@Override
	public boolean onScenarioLoaded() {
		intent = new Intent();
		intent.setClassName(getContext(), value);
		intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
		
		if (!isCallable(intent)) {
			Log.e(TAG, String.format("Activity '%s' is not callable", value));
			intent = null;
			return false;
		}
		
		return true;
	}
	
	@Override
	public void action() {
		if (intent == null) {
			Log.e(TAG, "Intent for startActivity is null");
			return;
		}
		
		getContext().startActivity(intent);
	}
	
	private boolean isCallable(Intent intent) {
        List<ResolveInfo> list = getContext().getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
        return list.size() > 0;
	}<commit_msg>Simplier checking of callability of activity<commit_after>package cz.robyer.gamework.scenario.reaction;

import android.content.Intent;
import android.content.pm.PackageManager;
import android.util.Log;

/**
 * 
 * @author <NAME>
 */
public class ActivityReaction extends Reaction {
	protected String value;
	protected Intent intent;
	
	public ActivityReaction(String id, String value) {
		super(id);
		this.value = value;
	}
	
	@Override
	public boolean onScenarioLoaded() {
		intent = new Intent();
		intent.setClassName(getContext(), value);
		intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
		
		if (!isCallable(intent)) {
			Log.e(TAG, String.format("Activity '%s' is not callable", value));
			intent = null;
			return false;
		}
		
		return true;
	}
	
	@Override
	public void action() {
		if (intent == null) {
			Log.e(TAG, "Intent for startActivity is null");
			return;
		}
		
		getContext().startActivity(intent);
	}
	
	private boolean isCallable(Intent intent) {
        return getContext().getPackageManager().resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY) != null;
	}
{'fraction_non_alphanumeric': 0.1204766107678729, 'fraction_numerical': 0.000441306266548985, 'mean_word_length': 4.235565819861431, 'pattern_counts': {'":': 0, '<': 6, '<?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': '5045383', 'n_tokens_mistral': 772, 'n_tokens_neox': 692, 'n_words': 166}