Search in sources :

Example 1 with AppSource

use of com.michaelcarrano.detectivedroid.model.AppSource in project detective-droid by michaelcarrano.

the class DetectorAsyncTask method detect.

/**
     * Detects all libraries by trying to load the pattern classpath in a given Application
     */
private static AppSource detect(PackageInfo pkg) {
    ArrayList<Library> libraries = new ArrayList<Library>();
    // Loop through known libraries
    for (Library library : Libraries.getInstance().getLibraries()) {
        try {
            Context ctx = mContext.createPackageContext(pkg.packageName, Context.CONTEXT_INCLUDE_CODE | Context.CONTEXT_IGNORE_SECURITY);
            Class<?> clazz = Class.forName(library.getPath(), false, ctx.getClassLoader());
            // Detected a library!!!
            if (clazz != null) {
                libraries.add(library);
            }
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }
    // Only return AppSource if app has a library
    return libraries.size() > 0 ? new AppSource(pkg, libraries) : null;
}
Also used : Context(android.content.Context) PackageManager(android.content.pm.PackageManager) ArrayList(java.util.ArrayList) Library(com.michaelcarrano.detectivedroid.model.Library) AppSource(com.michaelcarrano.detectivedroid.model.AppSource)

Example 2 with AppSource

use of com.michaelcarrano.detectivedroid.model.AppSource in project detective-droid by michaelcarrano.

the class AppSourceAdapter method getView.

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    ViewHolder holder;
    AppSource source = (AppSource) getItem(position);
    if (convertView == null) {
        convertView = mLayoutInflater.inflate(R.layout.list_item_card, parent, false);
        holder = new ViewHolder();
        holder.icon = (ImageView) convertView.findViewById(R.id.img_icon);
        holder.name = (TextView) convertView.findViewById(R.id.text_name);
        convertView.setTag(holder);
    } else {
        holder = (ViewHolder) convertView.getTag();
    }
    PackageManager pm = mContext.getPackageManager();
    PackageInfo pkg = source.getPackageInfo();
    holder.icon.setImageDrawable(pkg.applicationInfo.loadIcon(pm));
    holder.name.setText(pm.getApplicationLabel(pkg.applicationInfo));
    return convertView;
}
Also used : PackageManager(android.content.pm.PackageManager) PackageInfo(android.content.pm.PackageInfo) AppSource(com.michaelcarrano.detectivedroid.model.AppSource)

Example 3 with AppSource

use of com.michaelcarrano.detectivedroid.model.AppSource in project detective-droid by michaelcarrano.

the class DetectorAsyncTask method doInBackground.

@Override
protected List<AppSource> doInBackground(Void... voids) {
    List<AppSource> appSources = new ArrayList<AppSource>();
    // 0: scan system apps, 1: do not scan system apps
    int system = App.getInstance().getPreferenceScanSystemApps();
    for (int i = 0; i < mInstalledApplications.size(); i++) {
        ApplicationInfo appInfo = mInstalledApplications.get(i);
        if ((appInfo.flags & ApplicationInfo.FLAG_SYSTEM) <= 0 || (appInfo.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0 || ((appInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 1 && system == 0)) {
            publishProgress(mInstalledApplications.size(), i);
            try {
                PackageInfo pkgInfo = mPackageManager.getPackageInfo(appInfo.packageName, PackageManager.GET_PERMISSIONS);
                AppSource src = detect(pkgInfo);
                if (src != null) {
                    appSources.add(src);
                }
            } catch (PackageManager.NameNotFoundException e) {
                Log.i(this.getClass().getSimpleName(), "doInBackground: " + e.toString());
            }
        }
    }
    return appSources;
}
Also used : PackageManager(android.content.pm.PackageManager) PackageInfo(android.content.pm.PackageInfo) ArrayList(java.util.ArrayList) ApplicationInfo(android.content.pm.ApplicationInfo) AppSource(com.michaelcarrano.detectivedroid.model.AppSource)

Aggregations

PackageManager (android.content.pm.PackageManager)3 AppSource (com.michaelcarrano.detectivedroid.model.AppSource)3 PackageInfo (android.content.pm.PackageInfo)2 ArrayList (java.util.ArrayList)2 Context (android.content.Context)1 ApplicationInfo (android.content.pm.ApplicationInfo)1 Library (com.michaelcarrano.detectivedroid.model.Library)1