// Path: app/src/main/java/it/unisannio/security/DoApp/model/IntentDataInfo.java
// public class IntentDataInfo extends IntentFilter.IntentData{
// 
//     private AndroidComponent component;
//     private String packageName;
//     private IntentFilter filter; //intent-filter in which is declared the <data> field
// 
//     public IntentDataInfo(IntentFilter.IntentData data, AndroidComponent component, String packageName, IntentFilter filter) {
//         super(data.scheme, data.host, data.port, data.path, data.pathPattern, data.pathPrefix, data.mimeType, data.type);
//         this.component = component;
//         this.packageName = packageName;
//         this.filter = filter;
//     }
// 
//     public AndroidComponent getComponent(){
//         return component;
//     }
// 
//     public void setComponent(AndroidComponent component){
//         this.component = component;
//     }
// 
//     public String getPackageName() {
//         return packageName;
//     }
// 
//     public void setPackageName(String packageName) {
//         this.packageName = packageName;
//     }
// 
//     public IntentFilter getFilter() {
//         return filter;
//     }
// 
//     public void setFilter(IntentFilter filter) {
//         this.filter = filter;
//     }
// }


import android.content.Context;
import android.content.pm.PackageManager;
import android.util.Log;
import it.unisannio.security.DoApp.model.IntentDataInfo;
import com.jaredrummler.apkparser.ApkParser;
import com.jaredrummler.apkparser.model.AndroidComponent;
import com.jaredrummler.apkparser.model.AndroidManifest;
import com.jaredrummler.apkparser.model.IntentFilter;
import java.io.IOException;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
package it.unisannio.security.DoApp.util;




/**
 * Created by antonio on 05/01/17.
 */

public class PackageInfoExtractor {

    private Context context;
    private String pkgname;

    public PackageInfoExtractor(Context context, String pkgname){
        this.context = context;
        this.pkgname = pkgname;
    }

    public List<AndroidComponent> extractComponents(){
        ApkParser manifestParser = null;
        List<AndroidComponent> components = new ArrayList<AndroidComponent>();
        try {
            manifestParser = ApkParser.create(context.getPackageManager(), pkgname);
            AndroidManifest manifest = null;
            try{
                manifest = manifestParser.getAndroidManifest();
                components = manifest.getComponents();
            }
            catch (IOException e) {
                e.printStackTrace();
            } catch (ParseException e) {
                e.printStackTrace();
            }

        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }

        return components;
    }

// Path: app/src/main/java/it/unisannio/security/DoApp/model/IntentDataInfo.java
// public class IntentDataInfo extends IntentFilter.IntentData{
// 
//     private AndroidComponent component;
//     private String packageName;
//     private IntentFilter filter; //intent-filter in which is declared the <data> field
// 
//     public IntentDataInfo(IntentFilter.IntentData data, AndroidComponent component, String packageName, IntentFilter filter) {
//         super(data.scheme, data.host, data.port, data.path, data.pathPattern, data.pathPrefix, data.mimeType, data.type);
//         this.component = component;
//         this.packageName = packageName;
//         this.filter = filter;
//     }
// 
//     public AndroidComponent getComponent(){
//         return component;
//     }
// 
//     public void setComponent(AndroidComponent component){
//         this.component = component;
//     }
// 
//     public String getPackageName() {
//         return packageName;
//     }
// 
//     public void setPackageName(String packageName) {
//         this.packageName = packageName;
//     }
// 
//     public IntentFilter getFilter() {
//         return filter;
//     }
// 
//     public void setFilter(IntentFilter filter) {
//         this.filter = filter;
//     }
// }


// Path: app/src/main/java/it/unisannio/security/DoApp/util/PackageInfoExtractor.java
import android.content.Context;
import android.content.pm.PackageManager;
import android.util.Log;
import it.unisannio.security.DoApp.model.IntentDataInfo;
import com.jaredrummler.apkparser.ApkParser;
import com.jaredrummler.apkparser.model.AndroidComponent;
import com.jaredrummler.apkparser.model.AndroidManifest;
import com.jaredrummler.apkparser.model.IntentFilter;
import java.io.IOException;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

package it.unisannio.security.DoApp.util;




/**
 * Created by antonio on 05/01/17.
 */

public class PackageInfoExtractor {

    private Context context;
    private String pkgname;

    public PackageInfoExtractor(Context context, String pkgname){
        this.context = context;
        this.pkgname = pkgname;
    }

    public List<AndroidComponent> extractComponents(){
        ApkParser manifestParser = null;
        List<AndroidComponent> components = new ArrayList<AndroidComponent>();
        try {
            manifestParser = ApkParser.create(context.getPackageManager(), pkgname);
            AndroidManifest manifest = null;
            try{
                manifest = manifestParser.getAndroidManifest();
                components = manifest.getComponents();
            }
            catch (IOException e) {
                e.printStackTrace();
            } catch (ParseException e) {
                e.printStackTrace();
            }

        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }

        return components;
    }

    public List<IntentDataInfo> extractIntentFiltersDataType(){