Android Open Source - FAST App Info






From Project

Back to project page FAST.

License

The source code is released under:

GNU General Public License

If you think the Android project FAST listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package org.ligi.fast.model;
//  w w w .  ja  v a2  s.  com
import android.content.Context;
import android.content.Intent;
import android.content.pm.ResolveInfo;
import android.graphics.drawable.Drawable;

import org.ligi.axt.helpers.ResolveInfoHelper;
import org.ligi.fast.util.UmlautConverter;
import org.ligi.tracedroid.logging.Log;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * Class to Retrieve / Store Application Information needed by this App
 */
public class AppInfo {
    private static final String SEPARATOR = ";;";

    private String label;
    private String alternateLabel;
    private String packageName;
    private String alternatePackageName;
    private String activityName;
    private String hash;
    private int callCount;
    private boolean isValid = true;

    private final AppIconCache iconCache;

    private AppInfo(Context ctx) {
        iconCache = new AppIconCache(ctx, this);
    }

    public AppInfo(Context ctx, String cache_str) {
        this(ctx);

        String[] app_info_str_split = cache_str.split(SEPARATOR);

        if (app_info_str_split.length < 5) {
            isValid = false;
            return;
        }

        hash = app_info_str_split[0];
        label = app_info_str_split[1];
        packageName = app_info_str_split[2];
        activityName = app_info_str_split[3];
        callCount = Integer.parseInt(app_info_str_split[4]);

        calculateAlternateLabelAndPackageName();

    }

    public AppInfo(Context _ctx, ResolveInfo ri) {
        this(_ctx);

        // init attributes
        label = new ResolveInfoHelper(ri).getLabelSafely(_ctx);
        label = label.replace("?", "?").replaceAll("?", "?").replaceAll("?", "?").replaceAll("?", "?").replaceAll("?", "?").replaceAll("??", "?").replaceAll("?", "?").replaceAll("?", "?").replaceAll("?", "?").replaceAll("?", "?").replaceAll("?", "?").replaceAll("?", "?").replaceAll("?", "?").replaceAll("??", "?");
        if (ri.activityInfo != null) {
            packageName = ri.activityInfo.packageName;
            activityName = ri.activityInfo.name;
        } else {
            packageName = "unknown";
            activityName = "unknown";
        }
        callCount = 0;

        hash = calculateTheHash();
        calculateAlternateLabelAndPackageName();
        iconCache.cacheIcon(ri);
    }

    private void calculateAlternateLabelAndPackageName() {
        alternateLabel = UmlautConverter.replaceAllUmlautsReturnNullIfEqual(label);
        alternatePackageName = UmlautConverter.replaceAllUmlautsReturnNullIfEqual(packageName);
    }

    public String toCacheString() {
        return hash + SEPARATOR + label + SEPARATOR + packageName +
                SEPARATOR + activityName + SEPARATOR + callCount;
    }

    private String calculateTheHash() {
        try {
            final MessageDigest md = MessageDigest.getInstance("MD5");
            md.update(packageName.getBytes());
            md.update(activityName.getBytes());

            final byte[] messageDigest = md.digest();

            final StringBuilder hexString = new StringBuilder();
            for (byte digestByte : messageDigest) {
                hexString.append(Integer.toHexString(0xFF & digestByte));
            }
            return hexString.toString();

        } catch (NoSuchAlgorithmException e) {
            Log.w("MD5 not found - having a fallback - but really - no MD5 - where the f** am I?");
            return packageName; // fallback
        }
    }

    public Intent getIntent() {
        Intent intent = new Intent();
        intent.setClassName(packageName, activityName);
        return intent;
    }

    @Override
    public boolean equals(Object o) {
        if (!(o instanceof AppInfo)) {
            return false;
        }

        AppInfo other = (AppInfo) o;
        return toCacheString().equals(other.toCacheString());
    }

    public Drawable getIcon() {
        return iconCache.getIcon();
    }

    public String getPackageName() {
        return packageName;
    }

    public String getActivityName() {
        return packageName;
    }

    public String getLabel() {
        return label;
    }

    public int getCallCount() {
        return callCount;
    }

    public void setCallCount(int count) {
        callCount = count;
    }

    public void incrementCallCount() {
        callCount++;
    }

    public boolean isValid() {
        return isValid;
    }

    public String getHash() {
        return hash;
    }

    public String getAlternateLabel() {
        return alternateLabel;
    }

    public String getAlternatePackageName() {
        return alternatePackageName;
    }

    public void mergeSafe(AppInfo appInfo) {
        final int localCallCount = getCallCount();
        final int remoteCallCount = appInfo.getCallCount();
        setCallCount(Math.max(localCallCount,remoteCallCount));

        label=appInfo.getLabel();
        calculateAlternateLabelAndPackageName();
    }
}




Java Source Code List

org.ligi.axt.helpers.ActivityHelper.java
org.ligi.axt.helpers.ContextHelper.java
org.ligi.axt.helpers.FileHelper.java
org.ligi.axt.helpers.ResolveInfoHelper.java
org.ligi.axt.helpers.ViewHelper.java
org.ligi.axt.simplifications.SimpleTextWatcher.java
org.ligi.fast.App.java
org.ligi.fast.TargetStore.java
org.ligi.fast.TargetStore.java
org.ligi.fast.TargetStore.java
org.ligi.fast.background.AppInstallOrRemoveReceiver.java
org.ligi.fast.background.BackgroundGatherAsyncTask.java
org.ligi.fast.background.BaseAppGatherAsyncTask.java
org.ligi.fast.model.AppIconCache.java
org.ligi.fast.model.AppInfoList.java
org.ligi.fast.model.AppInfoSortByLabelComparator.java
org.ligi.fast.model.AppInfoSortByMostUsedComparator.java
org.ligi.fast.model.AppInfo.java
org.ligi.fast.model.DynamicAppInfoList.java
org.ligi.fast.settings.AndroidFASTSettings.java
org.ligi.fast.settings.FASTSettings.java
org.ligi.fast.testing.AppInfoTestBase.java
org.ligi.fast.testing.MutableFastSettings.java
org.ligi.fast.testing.TheAppIconCache.java
org.ligi.fast.testing.TheAppInfoStore.java
org.ligi.fast.testing.TheAppInfo.java
org.ligi.fast.testing.TheSearchActivity.java
org.ligi.fast.ui.AppActionDialogBuilder.java
org.ligi.fast.ui.AppInfoAdapter.java
org.ligi.fast.ui.FASTSettingsActivity.java
org.ligi.fast.ui.HelpDialog.java
org.ligi.fast.ui.HelpDialog.java
org.ligi.fast.ui.IconDimensions.java
org.ligi.fast.ui.LoadingDialog.java
org.ligi.fast.ui.SearchActivity.java
org.ligi.fast.util.AppInfoListStore.java
org.ligi.fast.util.PackageListSerializer.java
org.ligi.fast.util.StringUtils.java
org.ligi.fast.util.UmlautConverter.java