Search in sources :

Example 11 with ProcessInfo

use of edu.berkeley.cs.amplab.carat.thrift.ProcessInfo in project carat by amplab.

the class SamplingLibrary method getInstalledPackages.

/**
	 * Returns a list of installed packages on the device. Will be called for
	 * the first Carat sample on a phone, to get signatures for the malware
	 * detection project. Later on, single package information is got by
	 * receiving the package installed intent.
	 * 
	 * @param context
	 * @param filterSystem
	 *            if true, exclude system packages.
	 * @return a list of installed packages on the device.
	 */
public static Map<String, ProcessInfo> getInstalledPackages(Context context, boolean filterSystem) {
    Map<String, PackageInfo> packageMap = getPackages(context);
    PackageManager pm = context.getPackageManager();
    if (pm == null)
        return null;
    Map<String, ProcessInfo> result = new HashMap<String, ProcessInfo>();
    for (Entry<String, PackageInfo> pentry : packageMap.entrySet()) {
        try {
            String pkg = pentry.getKey();
            PackageInfo pak = pentry.getValue();
            if (pak != null) {
                int vc = pak.versionCode;
                ApplicationInfo appInfo = pak.applicationInfo;
                String label = pm.getApplicationLabel(appInfo).toString();
                // we need application UID to be able to use Android's
                // TrafficStat API
                // in order to get the traffic info of a particular app:
                int appUid = appInfo.uid;
                // get the amount of transmitted and received bytes by an
                // app
                // TODO: disabled for debugging
                //					TrafficRecord trafficRecord = getAppTraffic(appUid);
                int flags = pak.applicationInfo.flags;
                // Check if it is a system app
                boolean isSystemApp = (flags & ApplicationInfo.FLAG_SYSTEM) > 0;
                isSystemApp = isSystemApp || (flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) > 0;
                if (filterSystem & isSystemApp)
                    continue;
                if (pak.signatures.length > 0) {
                    List<String> sigList = getSignatures(pak);
                    ProcessInfo pi = new ProcessInfo();
                    pi.setPName(pkg);
                    pi.setApplicationLabel(label);
                    pi.setVersionCode(vc);
                    pi.setPId(-1);
                    pi.setIsSystemApp(isSystemApp);
                    pi.setAppSignatures(sigList);
                    pi.setImportance(Constants.IMPORTANCE_NOT_RUNNING);
                    pi.setInstallationPkg(pm.getInstallerPackageName(pkg));
                    pi.setVersionName(pak.versionName);
                    //TODO: disbaled for debugging
                    //						pi.setTrafficRecord(trafficRecord);
                    result.put(pkg, pi);
                }
            }
        } catch (Throwable th) {
        // Forget about it...
        }
    }
    return result;
}
Also used : HashMap(java.util.HashMap) PackageInfo(android.content.pm.PackageInfo) ApplicationInfo(android.content.pm.ApplicationInfo) RunningAppProcessInfo(android.app.ActivityManager.RunningAppProcessInfo) ProcessInfo(edu.berkeley.cs.amplab.carat.thrift.ProcessInfo) PackageManager(android.content.pm.PackageManager)

Example 12 with ProcessInfo

use of edu.berkeley.cs.amplab.carat.thrift.ProcessInfo in project carat by amplab.

the class SamplingLibrary method disabledItem.

/**
     * Helper to set application to the disabled state in the Carat sample.
     * @param pname the package that was disabled.
     * @param pref The preference that stored the disabled directive. This preference will be deleted to ensure disabled apps are not sent multiple times.
     * @param e the Editor (passed and not created here for efficiency)
     * @return a new ProcessInfo entry describing the uninstalled item.
     */
private static ProcessInfo disabledItem(String pname, String pref, SharedPreferences.Editor e) {
    ProcessInfo item = new ProcessInfo();
    item.setPName(pname);
    item.setPId(-1);
    item.setImportance(Constants.IMPORTANCE_DISABLED);
    // Remember to remove it so we do not send
    // multiple uninstall events
    e.remove(pref);
    return item;
}
Also used : RunningAppProcessInfo(android.app.ActivityManager.RunningAppProcessInfo) ProcessInfo(edu.berkeley.cs.amplab.carat.thrift.ProcessInfo)

Aggregations

ProcessInfo (edu.berkeley.cs.amplab.carat.thrift.ProcessInfo)12 RunningAppProcessInfo (android.app.ActivityManager.RunningAppProcessInfo)7 PackageInfo (android.content.pm.PackageInfo)4 ApplicationInfo (android.content.pm.ApplicationInfo)3 PackageManager (android.content.pm.PackageManager)3 Feature (edu.berkeley.cs.amplab.carat.thrift.Feature)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 SharedPreferences (android.content.SharedPreferences)2 BatteryDetails (edu.berkeley.cs.amplab.carat.thrift.BatteryDetails)2 CpuStatus (edu.berkeley.cs.amplab.carat.thrift.CpuStatus)2 NetworkDetails (edu.berkeley.cs.amplab.carat.thrift.NetworkDetails)2 Sample (edu.berkeley.cs.amplab.carat.thrift.Sample)2 Sample._Fields (edu.berkeley.cs.amplab.carat.thrift.Sample._Fields)2 LinkedList (java.util.LinkedList)2 FieldMetaData (org.apache.thrift.meta_data.FieldMetaData)2 RunningServiceInfo (android.app.ActivityManager.RunningServiceInfo)1 Editor (android.content.SharedPreferences.Editor)1 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)1 View (android.view.View)1