Browse files

adding updated files

  • Loading branch information...
1 parent 9dc2798 commit 6cf350115aa4aa64e5f277047e0f367035a93f21 @phil-brown committed Dec 4, 2011
View
7 .classpath
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="src" path="gen"/>
+ <classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
View
33 .project
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>PermissionsChecker</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>com.android.ide.eclipse.adt.ApkBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>com.android.ide.eclipse.adt.AndroidNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
View
36 AndroidManifest.xml
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- author: Phil Brown -->
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="net.csci5271.group3d"
+ android:versionCode="1"
+ android:versionName="1.0">
+ <uses-sdk android:minSdkVersion="4" />
+ <uses-permission android:name="android.permission.INTERNET"></uses-permission>
+ <application android:icon="@drawable/warning"
+ android:label="@string/app_name"
+ android:debuggable="true"
+ android:name=".Init">
+ <activity android:name=".Main"
+ android:label="@string/app_name"
+ android:theme="@android:style/Theme.Dialog">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ <category android:name="android.intent.category.LAUNCHER" />
+ </intent-filter>
+ </activity>
+ <activity android:name=".PermissionsDialog"
+ android:label="Permissions Checker"
+ android:launchMode="singleTask" >
+ </activity>
+ <activity android:name=".Settings"
+ android:label="Permissions Checker" >
+ </activity>
+ <receiver android:name=".PackageHandler">
+ <intent-filter>
+ <action android:name="android.intent.action.PACKAGE_ADDED" />
+ <data android:scheme="package" />
+ </intent-filter>
+ </receiver>
+
+ </application>
+</manifest>
View
11 default.properties
@@ -0,0 +1,11 @@
+# This file is automatically generated by Android Tools.
+# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
+#
+# This file must be checked in Version Control Systems.
+#
+# To customize properties used by the Ant build system use,
+# "build.properties", and override values to adapt the script to your
+# project structure.
+
+# Project target.
+target=android-8
View
55 gen/net/csci5271/group3d/R.java
@@ -0,0 +1,55 @@
+/* AUTO-GENERATED FILE. DO NOT MODIFY.
+ *
+ * This class was automatically generated by the
+ * aapt tool from the resource data it found. It
+ * should not be modified by hand.
+ */
+
+package net.csci5271.group3d;
+
+public final class R {
+ public static final class array {
+ public static final int danger_level_values=0x7f050001;
+ public static final int danger_levels=0x7f050000;
+ public static final int layout_id_values=0x7f050003;
+ public static final int layout_ids=0x7f050002;
+ }
+ public static final class attr {
+ }
+ public static final class drawable {
+ public static final int checked_shield_green=0x7f020000;
+ public static final int danger=0x7f020001;
+ public static final int shield_red=0x7f020002;
+ public static final int shield_yellow=0x7f020003;
+ public static final int warning=0x7f020004;
+ }
+ public static final class id {
+ public static final int about_btn=0x7f070004;
+ public static final int danger_rating=0x7f070007;
+ public static final int i_dont_care=0x7f070008;
+ public static final int image_alert=0x7f070005;
+ public static final int main_text=0x7f070002;
+ public static final int message=0x7f070006;
+ public static final int permission_descr=0x7f070001;
+ public static final int permission_name=0x7f070000;
+ public static final int progress_bar=0x7f07000a;
+ public static final int progress_text=0x7f07000b;
+ public static final int remove_app=0x7f070009;
+ public static final int settings_btn=0x7f070003;
+ }
+ public static final class layout {
+ public static final int list_item=0x7f030000;
+ public static final int main=0x7f030001;
+ public static final int permissions_layout=0x7f030002;
+ public static final int perms2=0x7f030003;
+ public static final int perms3=0x7f030004;
+ public static final int progress_window=0x7f030005;
+ }
+ public static final class string {
+ public static final int app_name=0x7f060001;
+ public static final int hello=0x7f060000;
+ }
+ public static final class xml {
+ public static final int settings=0x7f040000;
+ }
+}
View
40 proguard.cfg
@@ -0,0 +1,40 @@
+-optimizationpasses 5
+-dontusemixedcaseclassnames
+-dontskipnonpubliclibraryclasses
+-dontpreverify
+-verbose
+-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
+
+-keep public class * extends android.app.Activity
+-keep public class * extends android.app.Application
+-keep public class * extends android.app.Service
+-keep public class * extends android.content.BroadcastReceiver
+-keep public class * extends android.content.ContentProvider
+-keep public class * extends android.app.backup.BackupAgentHelper
+-keep public class * extends android.preference.Preference
+-keep public class com.android.vending.licensing.ILicensingService
+
+-keepclasseswithmembernames class * {
+ native <methods>;
+}
+
+-keepclasseswithmembers class * {
+ public <init>(android.content.Context, android.util.AttributeSet);
+}
+
+-keepclasseswithmembers class * {
+ public <init>(android.content.Context, android.util.AttributeSet, int);
+}
+
+-keepclassmembers class * extends android.app.Activity {
+ public void *(android.view.View);
+}
+
+-keepclassmembers enum * {
+ public static **[] values();
+ public static ** valueOf(java.lang.String);
+}
+
+-keep class * implements android.os.Parcelable {
+ public static final android.os.Parcelable$Creator *;
+}
View
BIN res/drawable/checked_shield_green.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN res/drawable/danger.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN res/drawable/shield_red.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN res/drawable/shield_yellow.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN res/drawable/warning.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
21 res/layout/list_item.xml
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- author: Phil Brown -->
+<LinearLayout
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:orientation="vertical"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent">
+ <TextView
+ android:id="@+id/permission_name"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:textSize="16sp"
+ android:textStyle="bold"
+ android:textColor="#999999" />
+ <TextView
+ android:id="@+id/permission_descr"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:textSize="12sp"
+ android:textColor="#CCCCCC" />
+</LinearLayout>
View
35 res/layout/main.xml
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- author: Phil Brown -->
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:orientation="vertical"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent" >
+ <TextView
+ android:id="@+id/main_text"
+ android:text="description"
+ android:textSize="16sp"
+ android:gravity="center_horizontal"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content" />
+ <View
+ android:background="#666666"
+ android:layout_width="fill_parent"
+ android:layout_height="2dp"
+ android:layout_marginBottom="10dp" />
+ <Button
+ android:id="@+id/settings_btn"
+ android:text="Settings"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:gravity="center"
+ android:padding="5dp"
+ android:layout_margin="10dp" />
+ <Button
+ android:id="@+id/about_btn"
+ android:text="About Permissions Checker"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:gravity="center"
+ android:padding="5dp"
+ android:layout_margin="10dp" />
+</LinearLayout>
View
69 res/layout/permissions_layout.xml
@@ -0,0 +1,69 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- author: Phil Brown -->
+<RelativeLayout
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:orientation="vertical"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent">
+ <ImageView
+ android:id="@+id/image_alert"
+ android:adjustViewBounds="true"
+ android:src="@drawable/warning"
+ android:layout_width="130dp"
+ android:layout_height="wrap_content"
+ android:layout_alignParentLeft="true"
+ android:layout_alignParentTop="true"
+ android:layout_margin="10dp"
+ android:padding="5dp" />
+ <TextView
+ android:id="@+id/message"
+ android:text="Alert Message"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_alignParentRight="true"
+ android:layout_alignParentTop="true"
+ android:layout_alignBottom="@id/image_alert"
+ android:layout_toRightOf="@id/image_alert"
+ android:layout_margin="10dp"
+ android:padding="5dp" />
+ <TextView
+ android:id="@+id/danger_rating"
+ android:text="Danger Rating"
+ android:textColor="#FF0000"
+ android:textSize="18sp"
+ android:textStyle="bold"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:layout_below="@id/message"
+ android:layout_marginTop="5dp"
+ android:layout_marginBottom="5dp"
+ android:padding="10dp" />
+ <ListView
+ android:id="@android:id/list"
+ android:layout_width="wrap_content"
+ android:layout_height="fill_parent"
+ android:layout_below="@id/danger_rating"
+ android:layout_above="@+id/i_dont_care"
+ android:layout_margin="10dp"
+ android:padding="5dp" />
+ <Button
+ android:id="@+id/remove_app"
+ android:text="Uninstall Application"
+ android:background="#33FF00"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_alignParentRight="true"
+ android:layout_alignParentBottom="true"
+ android:layout_margin="10dp"
+ android:padding="10dp" />
+ <Button
+ android:id="@+id/i_dont_care"
+ android:text="Keep Application"
+ android:background="#FFFF00"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_alignParentRight="true"
+ android:layout_above="@id/remove_app"
+ android:layout_margin="10dp"
+ android:padding="10dp" />
+</RelativeLayout>
View
56 res/layout/perms2.xml
@@ -0,0 +1,56 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- author: Phil Brown -->
+<RelativeLayout
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:orientation="vertical"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent">
+ <TextView
+ android:id="@+id/message"
+ android:text="Alert Message"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_alignParentTop="true"
+ android:layout_margin="10dp"
+ android:padding="5dp" />
+ <TextView
+ android:id="@+id/danger_rating"
+ android:text="Danger Rating"
+ android:textColor="#FF0000"
+ android:textSize="18sp"
+ android:textStyle="bold"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:layout_below="@id/message"
+ android:layout_marginTop="5dp"
+ android:layout_marginBottom="5dp"
+ android:padding="10dp" />
+ <ListView
+ android:id="@android:id/list"
+ android:layout_width="wrap_content"
+ android:layout_height="fill_parent"
+ android:layout_below="@id/danger_rating"
+ android:layout_above="@+id/i_dont_care"
+ android:layout_margin="10dp"
+ android:padding="5dp" />
+ <Button
+ android:id="@+id/remove_app"
+ android:text="Uninstall Application"
+ android:background="#33FF00"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_alignParentRight="true"
+ android:layout_alignParentBottom="true"
+ android:layout_margin="10dp"
+ android:padding="10dp" />
+ <Button
+ android:id="@+id/i_dont_care"
+ android:text="Keep Application"
+ android:background="#FFFF00"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_alignParentRight="true"
+ android:layout_above="@id/remove_app"
+ android:layout_margin="10dp"
+ android:padding="10dp" />
+</RelativeLayout>
View
84 res/layout/perms3.xml
@@ -0,0 +1,84 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- author: Phil Brown
+icons are from http://www.softicons.com/free-icons/toolbar-icons/vista-base-software-icons-2-by-icons-land -->
+<RelativeLayout
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:orientation="vertical"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent" >
+ <LinearLayout
+ android:id="@+id/image_alert"
+ android:orientation="horizontal"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content" >
+ <ImageView
+ android:src="@drawable/checked_shield_green"
+ android:adjustViewBounds="true"
+ android:padding="10dp"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:layout_weight="1" />
+ <ImageView
+ android:src="@drawable/shield_yellow"
+ android:adjustViewBounds="true"
+ android:padding="10dp"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:layout_weight="1" />
+ <ImageView
+ android:src="@drawable/shield_red"
+ android:adjustViewBounds="true"
+ android:padding="10dp"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:layout_weight="1" />
+ </LinearLayout>
+ <TextView
+ android:id="@+id/message"
+ android:text="Alert Message"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_below="@id/image_alert"
+ android:layout_margin="10dp"
+ android:padding="5dp" />
+ <TextView
+ android:id="@+id/danger_rating"
+ android:text="Danger Rating"
+ android:textColor="#FF0000"
+ android:textSize="18sp"
+ android:textStyle="bold"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:layout_below="@id/message"
+ android:layout_marginTop="5dp"
+ android:layout_marginBottom="5dp"
+ android:padding="10dp" />
+ <ListView
+ android:id="@android:id/list"
+ android:layout_width="wrap_content"
+ android:layout_height="fill_parent"
+ android:layout_below="@id/danger_rating"
+ android:layout_above="@+id/i_dont_care"
+ android:layout_margin="10dp"
+ android:padding="5dp" />
+ <Button
+ android:id="@+id/remove_app"
+ android:text="Uninstall Application"
+ android:background="#33FF00"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_alignParentRight="true"
+ android:layout_alignParentBottom="true"
+ android:layout_margin="10dp"
+ android:padding="10dp" />
+ <Button
+ android:id="@+id/i_dont_care"
+ android:text="Keep Application"
+ android:background="#FFFF00"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_alignParentRight="true"
+ android:layout_above="@id/remove_app"
+ android:layout_margin="10dp"
+ android:padding="10dp" />
+</RelativeLayout>
View
22 res/layout/progress_window.xml
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- author: Phil Brown -->
+<LinearLayout
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:orientation="horizontal"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent">
+ <ProgressBar
+ android:id="@+id/progress_bar"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:padding="5dp"
+ android:layout_margin="10dp" />
+ <TextView
+ android:id="@+id/progress_text"
+ android:text="Permissions Checker"
+ android:textColor="#FFFFFF"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:padding="5dp"
+ android:layout_margin="10dp" />
+</LinearLayout>
View
61 res/values/arrays.xml
@@ -0,0 +1,61 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- author: Phil Brown -->
+<resources>
+ <string-array name="danger_levels">
+ <item>0.0 No Threat</item>
+ <item>0.5</item>
+ <item>1</item>
+ <item>1.5</item>
+ <item>2</item>
+ <item>2.5</item>
+ <item>3</item>
+ <item>3.5</item>
+ <item>4</item>
+ <item>4.5 Moderately Dangerous</item>
+ <item>5</item>
+ <item>5.5</item>
+ <item>6</item>
+ <item>6.5</item>
+ <item>7</item>
+ <item>7.5</item>
+ <item>8</item>
+ <item>8.5</item>
+ <item>9 Very Dangerous</item>
+ </string-array>
+
+ <string-array name="danger_level_values">
+ <item>0.0</item>
+ <item>0.5</item>
+ <item>1</item>
+ <item>1.5</item>
+ <item>2</item>
+ <item>2.5</item>
+ <item>3</item>
+ <item>3.5</item>
+ <item>4</item>
+ <item>4.5</item>
+ <item>5</item>
+ <item>5.5</item>
+ <item>6</item>
+ <item>6.5</item>
+ <item>7</item>
+ <item>7.5</item>
+ <item>8</item>
+ <item>8.5</item>
+ <item>9</item>
+ </string-array>
+
+ <string-array name="layout_ids">
+ <item>random</item>
+ <item>1</item>
+ <item>2</item>
+ <item>3</item>
+ </string-array>
+
+ <string-array name="layout_id_values">
+ <item>-1</item>
+ <item>0</item>
+ <item>1</item>
+ <item>2</item>
+ </string-array>
+</resources>
View
6 res/values/strings.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- author: Phil Brown -->
+<resources>
+ <string name="hello">Hello World, PermissionsChecker!</string>
+ <string name="app_name">Permissions Checker</string>
+</resources>
View
21 res/xml/settings.xml
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="utf-8"?>
+<PreferenceScreen
+ xmlns:android="http://schemas.android.com/apk/res/android">
+ <PreferenceCategory android:title="Settings" >
+ <ListPreference
+ android:title="Minimum Danger Level"
+ android:summary="Set the minumum danger level needed for Permissions Checker to display."
+ android:key="minimum_danger_level"
+ android:defaultValue="1"
+ android:entries="@array/danger_levels"
+ android:entryValues="@array/danger_level_values" />
+ <ListPreference
+ android:title="Permissions Checker Layout"
+ android:summary="Set the layout to be displayed by Permissions Checker (debug)."
+ android:key="layout_id"
+ android:defaultValue="random"
+ android:entries="@array/layout_ids"
+ android:entryValues="@array/layout_id_values" />
+ </PreferenceCategory>
+
+</PreferenceScreen>
View
133 src/net/csci5271/group3d/H.java
@@ -0,0 +1,133 @@
+package net.csci5271.group3d;
+
+import java.util.List;
+
+import android.app.Notification;
+import android.app.NotificationManager;
+import android.app.PendingIntent;
+import android.content.Context;
+import android.content.Intent;
+import android.content.SharedPreferences;
+import android.content.pm.PackageInfo;
+import android.content.pm.PackageManager;
+import android.content.pm.PackageManager.NameNotFoundException;
+import android.content.pm.PermissionInfo;
+import android.net.Uri;
+import android.util.Log;
+
+/**
+ * Contains static variables and methods used commonly throughout the application.
+ * @author Phil Brown
+ */
+public class H {
+
+ /** This should be adjustable in user settings.
+ * TODO what is this based off of and what is the max?*/
+ public static float MINIMUM_DANGER_LEVEL = 1;
+ /** The base URL of where the server is hosted. */
+ public static final String BASE_URL = "http://www-users.cs.umn.edu/~zerbe/droidperm/";
+ /** Used for adding extras to {@link Intent}. */
+ public static final String RESPONSE = "data", PACKAGE = "package", NOTIFICATION_ID = "n_id";
+ /** {@link Intent} action for showing the dialog for a notification.*/
+ public static final String SHOW_DIALOG = "show_new_dialog";
+ /** The context used for reading package information and launching {@link PermissionsDialog}*/
+ public static Context context;
+ /** Used for showing notifications in Android */
+ public static NotificationManager nManager;
+ /** This is used so that no two {@link Notification}s have the same ID (thus they
+ * won't all cancel when one is clicked). */
+ public static List<Integer> notificationIDs;
+ /** Saves the user preferences across sessions*/
+ public static SharedPreferences prefs;
+ /** Provides edit access the {@link #prefs}.*/
+ public static SharedPreferences.Editor preferences_editor;
+
+ /** This method handles the majority of the work. */
+ public static void handleEverything(Intent intent) {
+ PackageManager manager = context.getPackageManager();
+ H.MINIMUM_DANGER_LEVEL = H.prefs.getFloat("minimum_danger_level", 1);
+ nManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
+ try {
+ Log.i("PERMISSION", intent.getDataString());
+ final PackageInfo info = manager.getPackageInfo(intent.getData().getSchemeSpecificPart(),
+ PackageManager.GET_PERMISSIONS);
+ String pkg = info.applicationInfo.packageName;
+ PermissionInfo[] permissions = info.permissions;
+ String data = H.BASE_URL + "?package=" + pkg;
+ if (permissions != null) {
+ data += "&perms=";
+ for (int i = 0; i < permissions.length; i++) {
+ Log.i("PERMISSION " + i, permissions[i].packageName);
+ data += permissions[i].packageName + ",";
+ }
+ }
+ new Request(context, Request.GET, data, null, new Request.Callback() {
+
+ @Override
+ public void invoke(String s) {
+ String[]lines = s.split("\\s+");
+ for (String line: lines) {
+ if (line.contains("danger_level")) {
+ float danger = Float.parseFloat(line.split("=")[1]);
+ //only open dangerous apps (minimum risk set in user settings).
+ if (danger < H.MINIMUM_DANGER_LEVEL) {
+ String message = "Danger Level of " + danger + " detected. ";
+ Notification notification;
+ notification = new Notification(R.drawable.warning,
+ message,
+ System.currentTimeMillis());
+ notification.flags = Notification.FLAG_AUTO_CANCEL;
+ String contentTitle = context.getString(R.string.app_name);
+ Intent intent = new Intent(context, PermissionsDialog.class);
+ intent.putExtra(H.RESPONSE, s);
+ intent.putExtra(H.PACKAGE, info);
+ intent.setAction(H.SHOW_DIALOG);
+ //used to fix notification identiy problem
+ intent.setData((Uri.parse("custom://"+System.currentTimeMillis())));
+ //next, figure out the notification ID to use so as not to use one already in use.
+ int index = 0;
+ boolean newId = false;
+ while (index < notificationIDs.size()) {
+ if (notificationIDs.contains(index)) {
+ index++;
+ }
+ else {
+ notificationIDs.add(index);
+ newId = true;
+ break;
+ }
+ }
+ if (!newId) {
+ notificationIDs.add(index + 1);
+ index = index + 1;
+ }
+ //Add notificatio ID to intent (so it can be cleared later)
+ intent.putExtra(H.NOTIFICATION_ID, index);
+ //show notification
+ PendingIntent pIntent;
+ pIntent = PendingIntent.getActivity(context, 0, intent, Intent.FLAG_ACTIVITY_NEW_TASK);
+ notification.setLatestEventInfo(context, contentTitle, message, pIntent);
+ nManager.notify(index, notification);
+ //save notification id
+ String savedNotificationIDs = "";
+ for (int i : notificationIDs) {
+ savedNotificationIDs += i + ",";
+ }
+ H.preferences_editor.putString("notificationIDs", savedNotificationIDs);
+ H.preferences_editor.commit();
+ return;
+ }
+ }
+ }
+ Intent intent = new Intent(context, PermissionsDialog.class);
+ intent.putExtra(H.RESPONSE, s);
+ intent.putExtra(H.PACKAGE, info);
+ intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ context.startActivity(intent);
+ }
+ }).execute();
+ } catch (NameNotFoundException e) {
+ e.printStackTrace();
+ }
+ }//handleEverything
+}//H
View
32 src/net/csci5271/group3d/Init.java
@@ -0,0 +1,32 @@
+package net.csci5271.group3d;
+
+import java.util.ArrayList;
+
+import android.app.Application;
+import android.content.Context;
+
+/**
+ * This class is run as soon as the app is launched, and initializes some static
+ * variables
+ * @author Phil Brown
+ */
+public class Init extends Application {
+
+ @Override
+ public void onCreate() {
+ H.context = getApplicationContext();
+
+ H.prefs = this.getSharedPreferences("preferences", Context.MODE_PRIVATE);
+ H.preferences_editor = H.prefs.edit();
+ String notificationIDs = H.prefs.getString("notificationIDs", null);
+ H.notificationIDs = new ArrayList<Integer>();
+ if (notificationIDs != null) {
+ String[] ids = notificationIDs.split(",");
+ //ids in format 1,2,3,4,5,
+ for (int i = 0; i < ids.length - 1; i++) {
+ H.notificationIDs.add(Integer.parseInt(ids[i]));
+ }
+ }
+
+ }//onCreate
+}//Init
View
59 src/net/csci5271/group3d/Main.java
@@ -0,0 +1,59 @@
+package net.csci5271.group3d;
+
+import android.app.Activity;
+import android.app.AlertDialog;
+import android.content.DialogInterface;
+import android.content.Intent;
+import android.os.Bundle;
+import android.view.View;
+import android.widget.Button;
+import android.widget.TextView;
+
+/**
+ * This class contains the welcome message. It may become something more later.
+ * @author Phil Brown
+ */
+public class Main extends Activity {
+
+ @Override
+ public void onCreate(Bundle b) {
+ super.onCreate(b);
+ setContentView(R.layout.main);
+ TextView descr = (TextView) findViewById(R.id.main_text);
+ descr.setText("Welcome to Permissions Checker. Permissions Checker is an app " +
+ "that simply notifies you, the user, of strange or dangerous permissions requests " +
+ "that you may have overlooked during download. This feature is meant to provide " +
+ "you with a better knowledge of what permissions to be wary of, as well as a better " +
+ "awareness of what you are downloading. ");
+ Button settings = (Button) findViewById(R.id.settings_btn);
+ settings.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ Intent intent = new Intent(Main.this, Settings.class);
+ startActivity(intent);
+ }
+ });
+ Button about = (Button) findViewById(R.id.about_btn);
+ about.setOnClickListener(new View.OnClickListener() {
+
+ @Override
+ public void onClick(View v) {
+ AlertDialog.Builder builder = new AlertDialog.Builder(Main.this);
+ builder.setTitle("Permissions Checker")
+ .setMessage("Android: Written by Phil Brown. Source is available at " +
+ "https://github.com/phil-brown.\n\n" +
+ "PHP Server: Written by Jason Zerbe. Code is available at " +
+ "https://github.com/jzerbe/droidperm_web.\n\n" +
+ "Permissions Checker is part of a group project at the University of Minnesota." +
+ " Project collaborators include Edward Stanley, Nathan Hammernik, David Salm, " +
+ "& Michael O'keefe.")
+ .setNeutralButton("Cool!", new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ dialog.dismiss();
+ }
+ }).show();
+ }
+ });
+ }//onCreate
+}//Main
View
18 src/net/csci5271/group3d/PackageHandler.java
@@ -0,0 +1,18 @@
+package net.csci5271.group3d;
+
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+
+/**
+ * This class is called when a new application is downloaded to the Android
+ * device. Next, it passes off the intent it received to {@link H#handleEverything(Intent)},
+ * which does everything else.
+ * @author Phil Brown
+ */
+public class PackageHandler extends BroadcastReceiver {
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ H.handleEverything(intent);
+ }//onReceive
+}//PermissionChecker
View
60 src/net/csci5271/group3d/PermissionsAdapter.java
@@ -0,0 +1,60 @@
+package net.csci5271.group3d;
+
+import android.content.Context;
+import android.content.pm.PackageManager;
+import android.content.pm.PackageManager.NameNotFoundException;
+import android.content.pm.PermissionInfo;
+import android.util.Log;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.ArrayAdapter;
+import android.widget.TextView;
+
+/**
+ * List Item Adapter
+ * @author Phil Brown
+ */
+public class PermissionsAdapter extends ArrayAdapter<String>{
+
+ /** The permissions retrieved from the server*/
+ private String[] perms;
+ /** Context for inflating the view */
+ private Context c;
+
+ /**
+ * Constructs a new PermissionsAdapter
+ * @param context
+ * @param permissions
+ */
+ public PermissionsAdapter(Context context, String[] permissions) {
+ super(context, 0, permissions);
+ this.perms = permissions;
+ this.c = context;
+ }//PermissionsAdapter
+
+ @Override
+ public View getView(int position, View convertView, ViewGroup parent) {
+ View v = convertView;
+ if (v == null) {
+ LayoutInflater vi =
+ (LayoutInflater)c.getSystemService(
+ Context.LAYOUT_INFLATER_SERVICE);
+ v = vi.inflate(R.layout.list_item, null);
+ }
+
+ PackageManager pm = c.getPackageManager();
+ String description = null;
+ try {
+ PermissionInfo p = pm.getPermissionInfo(perms[position], 0);
+ description = p.loadDescription(pm).toString();
+ } catch (NameNotFoundException e) {
+ Log.e("PERMISSION", "Permission not found");
+ }
+ TextView name = (TextView) v.findViewById(R.id.permission_name);
+ name.setText("¥ " + perms[position].replace("android.permission.", ""));
+ TextView descr = (TextView) v.findViewById(R.id.permission_descr);
+ descr.setText(description);
+ return v;
+ }//getView
+}//PermissionsAdapter
View
171 src/net/csci5271/group3d/PermissionsDialog.java
@@ -0,0 +1,171 @@
+package net.csci5271.group3d;
+
+import android.app.ListActivity;
+import android.content.Intent;
+import android.net.Uri;
+import android.os.Bundle;
+import android.util.Log;
+import android.view.KeyEvent;
+import android.view.View;
+import android.widget.Button;
+import android.widget.TextView;
+
+/** Handles the string intent received by the HTTP GET request
+ * @author Phil Brown*/
+public class PermissionsDialog extends ListActivity {
+
+ /** The response string retrieved from the server*/
+ protected String response;
+ /** The package name of the app*/
+ protected String app_name;
+ /** The category the app belongs to*/
+ protected String app_category;
+ /** The permissions that the app is requesting*/
+ protected String[] permissions;
+ /** The danger level that has been calculated for this app*/
+ protected float danger_level;
+ /** A description about what the danger level means.*/
+ protected String danger_about;
+ /** Layout reference IDs*/
+ protected int[] layouts = new int[]{R.layout.permissions_layout,
+ R.layout.perms2,
+ R.layout.perms3};
+ /** These are used to log the ID. Each integer is associtaed with the index
+ * of the layout in {@link layouts}.*/
+ protected int[] layout_ids = new int[]{0, 1, 2};
+ /** The selected layout id. Used for logging.
+ * @see #logSelection(boolean) */
+ protected int final_layout_id;
+ /** Used to notify this activity when it is being opened after the app has
+ * has been uninstalled. */
+ public static final int REQUEST_CODE_DELETE = 0;
+
+ @Override
+ protected void onActivityResult(int requestCode, int resultCode, Intent data){
+ if (requestCode == REQUEST_CODE_DELETE) {
+ finish();
+ }
+ }//onActivityResult
+
+ @Override
+ public void onNewIntent(Intent intent) {
+ if (intent.getAction().equals(H.SHOW_DIALOG)) {
+ int n_id = intent.getIntExtra(H.NOTIFICATION_ID, -1);
+ //if the notification id is valid, remove it from the saved ids list.
+ if (n_id != -1) {
+ H.notificationIDs.remove(n_id);
+ H.nManager.cancel(n_id);
+ }
+ }
+ }//onNewIntent
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ this.handleIntent(this.getIntent());
+ int layout_id = H.prefs.getInt("layout_id", -1);
+ if (layout_id == -1) {
+ final_layout_id = (int) (Math.random() * layouts.length);
+ setContentView(layouts[final_layout_id]);
+ }
+ else {
+ final_layout_id = layout_id;
+ setContentView(layouts[layout_id]);
+ }
+ TextView tv = (TextView) findViewById(R.id.message);
+ String body = "The application ";
+ if (this.response != null) {
+ String[] lines = response.split("\\s+");
+ for (String line: lines) {
+ Log.i("PERMISSION", line);
+ String[] s = line.split("=");
+ String key = s[0];
+ String value = null;
+ if (s.length == 2) {
+ value = s[1];
+ }
+ if (key.equals("name")) {
+ this.app_name = value;
+ }
+ else if (key.equals("category")) {
+ this.app_category = value;
+ }
+ else if (key.equals("perms")) {
+ this.permissions = value.split(",");
+ }
+ else if (key.equals("danger_level")) {
+ this.danger_level = Float.parseFloat(value);
+ }
+ else if (key.equals("danger_about")) {
+ this.danger_about = value;
+ }
+ }
+ body += this.app_name + " has requested dangerous " +
+ "permissions. Permissions Checker suggests a danger rating of " +
+ this.danger_level + ". Details below.";
+ }
+ else {
+ body = "Permissions Checker was unable to verify the package. " +
+ "you have downloaded. It may be dangerous. Be sure to read" +
+ "over all of its permissions before use.";
+ }
+ tv.setText(body);
+ setListAdapter(new PermissionsAdapter(this, permissions));
+ TextView dRating = (TextView) findViewById(R.id.danger_rating);
+ dRating.setText("Danger Level: " + this.danger_level);
+ Button soWhat = (Button) findViewById(R.id.i_dont_care);
+ soWhat.setText("Keep " + this.app_name);
+ soWhat.setOnClickListener(new View.OnClickListener() {
+
+ @Override
+ public void onClick(View v) {
+ logSelection(false);
+ finish();
+ }
+ });
+ Button uninstall = (Button) findViewById(R.id.remove_app);
+ uninstall.setText("Uninstall " + this.app_name);
+ uninstall.setOnClickListener(new View.OnClickListener() {
+
+ @Override
+ public void onClick(View v) {
+ logSelection(true);
+ Uri packageURI = Uri.parse("package:" + app_name);
+ Intent rm_pkg = new Intent(Intent.ACTION_DELETE, packageURI);
+ startActivityForResult(rm_pkg, REQUEST_CODE_DELETE);
+ }
+ });
+ }//onCreate
+
+ public void handleIntent(Intent intent) {
+ if (intent == null) {
+ return;
+ }
+ this.response = intent.getStringExtra(H.RESPONSE);
+ }//handleIntent
+
+ /** Registers the user's selction if he or she simply exits the app without
+ * selecting a button.*/
+ @Override
+ public boolean onKeyDown(int keyCode, KeyEvent event) {
+ if (keyCode == KeyEvent.KEYCODE_BACK) {
+ this.logSelection(false);
+ }
+ return super.onKeyDown(keyCode, event);
+ }//onKeyDown
+
+ /** Post the user's decision (keep or uninstall) to the server<br>
+ * POST arguments: interface_id (int), package (name), installed (yes/no)*/
+ public void logSelection(boolean heededWarning) {
+ String data = H.BASE_URL + "?interface_id=" + final_layout_id +
+ "&package=" + app_name +
+ "&installed=" + (heededWarning? 1 : 0);
+ new Request(this, Request.POST, data, null, new Request.Callback() {
+ @Override
+ public void invoke(String s) {
+ return;
+ }
+ }).execute();
+ }//logSelection
+
+}//PermissionsDialog
View
103 src/net/csci5271/group3d/Request.java
@@ -0,0 +1,103 @@
+package net.csci5271.group3d;
+
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+
+import org.apache.http.client.ClientProtocolException;
+import org.apache.http.client.HttpClient;
+import org.apache.http.client.ResponseHandler;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.entity.StringEntity;
+import org.apache.http.impl.client.BasicResponseHandler;
+import org.apache.http.impl.client.DefaultHttpClient;
+
+import android.content.Context;
+import android.os.AsyncTask;
+
+/**
+ * HTTP Request
+ * @author Phil Brown
+ */
+public class Request extends AsyncTask<Void, String, String> {
+
+ /** GET or POST request */
+ private int requestType;
+ /** The URL to access */
+ private String URL;
+ /** The data to append to the URL*/
+ private String data;
+ /** The method to call after the request has completed*/
+ private Callback callback;
+ /** The client used for sending the request to the server*/
+ private HttpClient client;
+ /** Used for get requests*/
+ private HttpGet get;
+ /** Used for post requests*/
+ private HttpPost post;
+
+ /** Type of post */
+ public static final int POST = 0, GET = 1;
+
+ /** Constructs a new Request */
+ public Request(Context context, int requestType, String url, String data, Callback callback) {
+ this.requestType = requestType;
+ this.URL = url;
+ this.data = data;
+ this.callback = callback;
+ }//Request
+
+ @Override
+ public void onPreExecute() {
+ client = new DefaultHttpClient();
+ post = new HttpPost(this.URL);
+ get = new HttpGet(this.URL);
+ }//onPreExecute
+
+ @Override
+ protected String doInBackground(Void... arg0) {
+
+ ResponseHandler<String> handler = new BasicResponseHandler();
+ if (this.requestType == GET) {
+
+ try {
+ return client.execute(get, handler);
+ } catch (ClientProtocolException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ else if (this.requestType == POST) {
+
+ try {
+ if (data != null) {
+ StringEntity entity = new StringEntity(this.data);
+ entity.setContentType("text/plain");
+ post.setEntity(entity);
+ }
+ return client.execute(post, handler);
+ } catch (UnsupportedEncodingException e) {
+ e.printStackTrace();
+ } catch (ClientProtocolException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ return null;
+ }//doInBackground
+
+ @Override
+ public void onPostExecute(String response) {
+ if (this.callback != null) {
+ callback.invoke(response);
+ }
+ }//onPostExecute
+
+ /** Returns the response received from the server. */
+ public interface Callback {
+ public void invoke(String s);
+ }//Callback
+
+}//Request
View
34 src/net/csci5271/group3d/Settings.java
@@ -0,0 +1,34 @@
+package net.csci5271.group3d;
+
+import android.os.Bundle;
+import android.preference.ListPreference;
+import android.preference.PreferenceActivity;
+
+/**
+ * User Settings
+ * @author Phil Brown
+ */
+public class Settings extends PreferenceActivity {
+
+ /** The list preference used for the minimum danger level setting.*/
+ private ListPreference mdl;
+ /** The list preference used for the layout ID to use. This is best kept
+ * for debugging (for now).*/
+ private ListPreference layoutID;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ addPreferencesFromResource(R.xml.settings);
+ mdl = (ListPreference) this.findPreference("minimum_danger_level");
+ layoutID = (ListPreference) this.findPreference("layout_id");
+ }//onCreate
+
+ @Override
+ public void onStop() {
+ super.onStop();
+ H.preferences_editor.putFloat("minimum_danger_level", Float.parseFloat(mdl.getValue().toString()));
+ H.preferences_editor.putInt("layout_id", Integer.parseInt(layoutID.getValue().toString()));
+ H.preferences_editor.commit();
+ }//onStop
+}//Settings

0 comments on commit 6cf3501

Please sign in to comment.