Permalink
Browse files

Added support for Leadbolt, appenda, iac ads

  • Loading branch information...
1 parent c905b9f commit d2cbeb6136672dba5218c058176eedaa36e27304 @dbjorge committed Nov 6, 2011
Showing with 63 additions and 18 deletions.
  1. +1 −1 res/layout/main.xml
  2. +1 −1 res/values/strings.xml
  3. +61 −16 src/com/brosmike/airpushdetector/AirPushDetectorActivity.java
View
@@ -33,7 +33,7 @@
/>
<TextView
android:id="@android:id/empty"
- android:text="@string/no_airpush_apps"
+ android:text="@string/no_ad_apps"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
@@ -2,5 +2,5 @@
<resources>
<string name="app_name">AirPush Detector</string>
<string name="refresh">Refresh</string>
- <string name="no_airpush_apps">No installed AirPush apps detected!</string>
+ <string name="no_ad_apps">No installed notification ad apps detected!</string>
</resources>
@@ -2,8 +2,10 @@
import java.util.ArrayList;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.List;
import java.util.Map;
+import java.util.Set;
import android.app.ListActivity;
import android.content.Intent;
@@ -12,6 +14,7 @@
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
+import android.content.pm.ServiceInfo;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
@@ -20,6 +23,13 @@
import android.widget.SimpleAdapter;
public class AirPushDetectorActivity extends ListActivity {
+ public static final String[] AD_PACKAGE_PREFIXES = {
+ "com.airpush.",
+ "com.Leadbolt.",
+ "com.appenda.",
+ "com.iac.notification."
+ };
+
private static final String TAG = "AirPushDetector";
/** The list of packages currently being displayed. Used in onListItemClick listener */
@@ -52,11 +62,11 @@ public void onRefreshButtonClick(View button) {
/** Populates the main view according to installed AirPush packages */
private void populateView() {
- List<PackageInfo> airPushPackages = getAirPushPackages();
+ List<PackageInfo> adPackages = getAdPackages();
PackageManager pm = getPackageManager();
- List<Map<String, String>> data = new ArrayList<Map<String, String>>(airPushPackages.size());
- for(PackageInfo pkg : airPushPackages) {
+ List<Map<String, String>> data = new ArrayList<Map<String, String>>(adPackages.size());
+ for(PackageInfo pkg : adPackages) {
Map<String, String> attrs = new HashMap<String, String>();
attrs.put("App Name", pm.getApplicationLabel(pkg.applicationInfo).toString());
attrs.put("Package Name", pkg.packageName);
@@ -75,31 +85,66 @@ private void populateView() {
this, data, android.R.layout.two_line_list_item, from, to);
setListAdapter(adapter);
- mPackages = airPushPackages;
+ mPackages = adPackages;
}
- /** Finds all installed packages that look like they include AirPush */
- private List<PackageInfo> getAirPushPackages() {
- List<PackageInfo> airPushPackages = new ArrayList<PackageInfo>();
+ /** Finds all installed packages that look like they include a known ad framework */
+ private List<PackageInfo> getAdPackages() {
+ Set<PackageInfo> adPackages = new HashSet<PackageInfo>();
PackageManager pm = getPackageManager();
//It'd be simpler to just use pm.getInstalledPackages here, but apparently it's broken
List<ApplicationInfo> appInfos = pm.getInstalledApplications(0);
+
for(ApplicationInfo appInfo : appInfos) {
try {
- PackageInfo pkgInfo = pm.getPackageInfo(appInfo.packageName, PackageManager.GET_ACTIVITIES);
- if(pkgInfo.activities == null) continue;
- for(ActivityInfo activity : pkgInfo.activities) {
- if(activity.name.startsWith("com.airpush.")) {
- airPushPackages.add(pkgInfo);
- break;
- }
- }
+ PackageInfo pkgInfo = pm.getPackageInfo(appInfo.packageName,
+ PackageManager.GET_ACTIVITIES |
+ PackageManager.GET_RECEIVERS |
+ PackageManager.GET_SERVICES);
+
+ Log.v(TAG, "Scanning package " + pkgInfo.packageName);
+
+ if(pkgInfo.activities != null) {
+ for(ActivityInfo activity : pkgInfo.activities) {
+ Log.v(TAG, "[ACTIVITY] " + activity.name);
+ for(String adPackagePrefix : AD_PACKAGE_PREFIXES) {
+ if(activity.name.startsWith(adPackagePrefix)) {
+ Log.i(TAG, "Detected ad framework prefix " + adPackagePrefix + " in package " + pkgInfo.packageName + " as activity " + activity.name);
+ adPackages.add(pkgInfo);
+ }
+ }
+ }
+ }
+ if(pkgInfo.receivers != null) {
+ for(ActivityInfo receiver : pkgInfo.receivers) {
+ Log.v(TAG, "[RECEIVER] " + receiver.name);
+ for(String adPackagePrefix : AD_PACKAGE_PREFIXES) {
+ if(receiver.name.startsWith(adPackagePrefix)) {
+ Log.i(TAG, "Detected ad framework prefix " + adPackagePrefix + " in package " + pkgInfo.packageName + " as receiver " + receiver.name);
+ adPackages.add(pkgInfo);
+ break;
+ }
+ }
+ }
+ }
+ if(pkgInfo.services != null) {
+ for(ServiceInfo service : pkgInfo.services) {
+ Log.v(TAG, "[SERVICE] " + service.name);
+ for(String adPackagePrefix : AD_PACKAGE_PREFIXES) {
+ if(service.name.startsWith(adPackagePrefix)) {
+ Log.i(TAG, "Detected ad framework prefix " + adPackagePrefix + " in package " + pkgInfo.packageName + " as service " + service.name);
+ adPackages.add(pkgInfo);
+ break;
+ }
+ }
+ }
+ }
} catch (NameNotFoundException e) {
Log.e(TAG, "Managed to not find a package we know about");
}
}
- return airPushPackages;
+ return new ArrayList<PackageInfo>(adPackages);
}
}

0 comments on commit d2cbeb6

Please sign in to comment.