Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: LGPL 

import java.util.HashSet;

import java.util.Set;

import android.content.Intent;

import android.os.Bundle;
import android.text.TextUtils;

public class Main {
    private final static String keyBaseName = "taintinfo";

    public static void addTaintInformationToIntent(Intent i, HashSet<String> taintCategories) {
        boolean intentHasNoExtras = i.getExtras() == null ? true : false;

        //A bit of limitation here, because we do only care about the extras
        if (!intentHasNoExtras) {
            Bundle extras = i.getExtras();

            String taintKeyName = generateKeyNameForTaintInfo(extras.keySet());

            String taintInformation = null;

            if (taintCategories.size() > 1)
                taintInformation = taintCategories.toString().substring(1, taintCategories.toString().length() - 1);
            else
                taintInformation = taintCategories.iterator().next();

            i.putExtra(taintKeyName, taintInformation);
        }
    }

    private static String generateKeyNameForTaintInfo(Set<String> allIntentKeys) {
        String keyName = keyBaseName;
        int counter = 0;

        for (String intentKey : allIntentKeys) {
            if (intentKey.startsWith(keyBaseName)) {
                String possibleNumber = intentKey.substring(keyBaseName.length());
                if (possibleNumber.length() > 0 && TextUtils.isDigitsOnly(possibleNumber)) {
                    int currentCounter = Integer.parseInt(possibleNumber);
                    counter = currentCounter + 1;
                }
            }
        }

        if (counter != 0)
            keyName += counter;

        return keyName;
    }
}