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;
}
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;
}
Aggregations