Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Added some additional information about permissions, Showing only the…

… dangerous permissions, Cleaned up the applicationlayout
  • Loading branch information...
commit d1bb68f6ef75cb22aa513b8805635af1eb74dd34 1 parent 86e481d
Ryan Welton authored March 05, 2012
2  AndroidManifest.xml
@@ -5,7 +5,7 @@
5 5
     android:versionName="1.0" >
6 6
 
7 7
     <uses-sdk android:minSdkVersion="10" />
8  
-
  8
+	<uses-permission android:name="android.permission.REVOKE_PERMISSIONS"></uses-permission>
9 9
     <application
10 10
         android:icon="@drawable/ic_launcher"
11 11
         android:label="@string/app_name" >
6  gen/com/fuzionsoftware/appstats/R.java
@@ -14,12 +14,18 @@
14 14
         public static final int ic_launcher=0x7f020000;
15 15
     }
16 16
     public static final class id {
  17
+        public static final int android_app_name=0x7f050003;
17 18
         public static final int android_info_image=0x7f050000;
  19
+        public static final int android_info_packagename=0x7f050002;
18 20
         public static final int android_info_text=0x7f050001;
  21
+        public static final int android_permission_label=0x7f050006;
  22
+        public static final int android_permission_name=0x7f050005;
  23
+        public static final int application_uses_permission_list_view=0x7f050004;
19 24
     }
20 25
     public static final class layout {
21 26
         public static final int app_layout=0x7f030000;
22 27
         public static final int application_info=0x7f030001;
  28
+        public static final int permission_layout=0x7f030002;
23 29
     }
24 30
     public static final class string {
25 31
         public static final int app_name=0x7f040000;
7  res/layout/app_layout.xml
@@ -9,10 +9,17 @@
9 9
 	android:layout_width="wrap_content"
10 10
 	android:layout_height="wrap_content">
11 11
 	</ImageView>
  12
+
12 13
     <TextView
13 14
         android:id="@+id/android_info_text"
14 15
         android:layout_width="wrap_content"
15 16
         android:layout_height="fill_parent"
16 17
         android:gravity = "center_vertical"
  18
+	/>	
  19
+	<TextView
  20
+        android:id="@+id/android_info_packagename"
  21
+        android:layout_width="wrap_content"
  22
+        android:layout_height="0dp"
  23
+        android:gravity = "center_vertical"
17 24
 	/>
18 25
 </LinearLayout>
23  res/layout/application_info.xml
... ...
@@ -1,18 +1,21 @@
1 1
 <?xml version="1.0" encoding="utf-8"?>
2 2
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3  
-    android:layout_width="fill_parent"
4  
-    android:layout_height="fill_parent"
5  
-    android:orientation="horizontal" >
6  
-	<ImageView
  3
+ 	android:orientation="vertical" 
  4
+ 	android:layout_width="fill_parent"
  5
+  	android:layout_height="fill_parent">
  6
+ 	<ImageView
7 7
 	android:contentDescription="@string/desc"
8 8
 	android:id="@+id/android_info_image"
9 9
 	android:layout_width="wrap_content"
10 10
 	android:layout_height="wrap_content">
11 11
 	</ImageView>
12  
-    <TextView
13  
-        android:id="@+id/android_info_text"
14  
-        android:layout_width="wrap_content"
15  
-        android:layout_height="fill_parent"
16  
-        android:gravity = "center_vertical"
17  
-	/>
  12
+	<TextView
  13
+	  android:id="@+id/android_app_name"
  14
+	  android:layout_height="wrap_content"
  15
+	  android:gravity="center_vertical|center_horizontal"
  16
+	  android:layout_width="wrap_content" />
  17
+  <ListView 
  18
+   android:id="@+id/application_uses_permission_list_view" 
  19
+   android:layout_height="wrap_content"
  20
+   android:layout_width="fill_parent"/>
18 21
 </LinearLayout>
17  res/layout/permission_layout.xml
... ...
@@ -0,0 +1,17 @@
  1
+<?xml version="1.0" encoding="utf-8"?>
  2
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3
+ android:orientation="vertical" 
  4
+ android:layout_width="fill_parent"
  5
+  android:layout_height="fill_parent"
  6
+  android:paddingLeft="50dp">
  7
+  <TextView android:id="@+id/android_permission_name"
  8
+  android:textSize="14sp" 
  9
+  android:textStyle="bold" 
  10
+  android:textColor="#FFFF00" 
  11
+  android:layout_width="wrap_content" 
  12
+  android:layout_height="wrap_content"/>
  13
+ <TextView android:id="@+id/android_permission_label" 
  14
+  android:layout_width="wrap_content" 
  15
+  android:layout_height="wrap_content"/>
  16
+
  17
+</LinearLayout>
106  src/com/fuzionsoftware/appstats/ApplicationInfoActivity.java
... ...
@@ -1,39 +1,111 @@
1 1
 package com.fuzionsoftware.appstats;
2 2
 
  3
+import java.util.Arrays;
  4
+import java.util.List;
  5
+
3 6
 import android.app.Activity;
  7
+import android.content.Context;
4 8
 import android.content.pm.PackageInfo;
5 9
 import android.content.pm.PackageManager;
6 10
 import android.content.pm.PackageManager.NameNotFoundException;
  11
+import android.content.pm.PermissionInfo;
7 12
 import android.os.Bundle;
  13
+import android.view.LayoutInflater;
  14
+import android.view.View;
  15
+import android.view.ViewGroup;
8 16
 import android.view.Window;
  17
+import android.widget.BaseAdapter;
  18
+import android.widget.ImageView;
  19
+import android.widget.ListView;
9 20
 import android.widget.TextView;
10 21
 
  22
+import com.fuzionsoftware.utils.PackageInfoHelper;
  23
+
11 24
 public class ApplicationInfoActivity extends Activity{
  25
+	PackageInfo mPackageInfo;
  26
+	BaseAdapter mReqedPermAdapter;
12 27
     @Override
13 28
     public void onCreate(Bundle savedInstanceState) {
14 29
     	requestWindowFeature(Window.FEATURE_NO_TITLE);
15 30
         super.onCreate(savedInstanceState);
16 31
         setContentView(R.layout.application_info);
  32
+        TextView appName = (TextView) findViewById(R.id.android_app_name);
  33
+        ImageView appIcon = (ImageView) findViewById(R.id.android_info_image);
  34
+        
  35
+        ListView reqPermissionListView = (ListView) findViewById(R.id.application_uses_permission_list_view);
  36
+        
  37
+        
17 38
         Bundle extras = getIntent().getExtras();
18  
-        PackageInfo pi = (PackageInfo) extras.get("PackageName");
19  
-        if(pi == null)
20  
-        	pi = (PackageInfo) savedInstanceState.get("PackageInfo");
  39
+        String pkgName = (String) extras.get("PackageName");
  40
+        if(pkgName == null)
  41
+        	pkgName = (String) savedInstanceState.get("PackageName");
21 42
         
22  
-        StringBuilder sb = new StringBuilder(pi.packageName);
23  
-        sb.append(": ");
24  
-    	PackageManager pm  = getPackageManager();
25  
-    	try {
26  
-			pi = pm.getPackageInfo(pi.packageName, PackageManager.GET_PERMISSIONS);
  43
+        try {
  44
+			mPackageInfo = getPackageManager().getPackageInfo(pkgName, PackageManager.GET_PERMISSIONS);
27 45
 		} catch (NameNotFoundException e) {
28  
-			e.printStackTrace();
  46
+			return;
29 47
 		}
30  
-    	if (pi.requestedPermissions == null)
31  
-    		return;
32  
-        for(String permInfo : pi.requestedPermissions)
33  
-        {
34  
-        	sb.append(" \n" + permInfo);
35  
-        }
36  
-        TextView tv = (TextView) this.findViewById(R.id.android_info_text);
37  
-        tv.setText(sb.toString());
  48
+        
  49
+        mReqedPermAdapter = new RequestedPermissionAdapter(getApplicationContext(), Arrays.asList(mPackageInfo.requestedPermissions));
  50
+        reqPermissionListView.setAdapter(mReqedPermAdapter);	
  51
+        appIcon.setImageDrawable(mPackageInfo.applicationInfo.loadIcon(getPackageManager()));
  52
+        appName.setText(getPackageManager().getApplicationLabel(mPackageInfo.applicationInfo));
38 53
     }
  54
+    
  55
+    
  56
+    public class RequestedPermissionAdapter extends BaseAdapter {
  57
+    	 private List<String> mRequestedPermissions;
  58
+    	 
  59
+    	 private LayoutInflater mInflater;
  60
+
  61
+    	 public RequestedPermissionAdapter(Context context, List<String> reqedPerms) {
  62
+    		 mRequestedPermissions = reqedPerms;
  63
+    		 mInflater = LayoutInflater.from(context);
  64
+    	 }
  65
+
  66
+    	 public int getCount() {
  67
+    	  return mRequestedPermissions.size();
  68
+    	 }
  69
+
  70
+    	 public Object getItem(int position) {
  71
+    	  return mRequestedPermissions.get(position);
  72
+    	 }
  73
+
  74
+    	 public long getItemId(int position) {
  75
+    	  return position;
  76
+    	 }
  77
+
  78
+    	 public View getView(int position, View convertView, ViewGroup parent) {
  79
+    	  ViewHolder holder;
  80
+    	  if (convertView == null) {
  81
+    	   convertView = mInflater.inflate(R.layout.permission_layout, null);
  82
+    	   holder = new ViewHolder();
  83
+    	   holder.txtPermissionName = (TextView) convertView.findViewById(R.id.android_permission_name);
  84
+    	   holder.txtPermissionLabel = (TextView) convertView.findViewById(R.id.android_permission_label);
  85
+
  86
+    	   convertView.setTag(holder);
  87
+    	  } else {
  88
+    	   holder = (ViewHolder) convertView.getTag();
  89
+    	  }
  90
+    	  
  91
+    	  convertView.setPadding(0, 0, 0, 0);
  92
+    	  
  93
+    	  String permissionName = mRequestedPermissions.get(position);
  94
+    	  PermissionInfo permInfo = PackageInfoHelper.mPermissionInfoStringMap.get(permissionName);
  95
+    	  holder.txtPermissionName.setText(permissionName);
  96
+    	  if(permInfo != null)
  97
+    		  holder.txtPermissionLabel.setText(permInfo.loadLabel(getPackageManager()));
  98
+    	  else
  99
+    		  holder.txtPermissionLabel.setText("");
  100
+    	 
  101
+
  102
+    	  return convertView;
  103
+    	 }
  104
+
  105
+    	  class ViewHolder {
  106
+    	  TextView txtPermissionName;
  107
+    	  TextView txtPermissionLabel;
  108
+    	  TextView txtPermissionDescription;
  109
+    	 }
  110
+    	}
39 111
 }
66  src/com/fuzionsoftware/appstats/PermissionAppExpandableAdapter.java
@@ -4,11 +4,12 @@
4 4
 import java.util.Collection;
5 5
 import java.util.HashMap;
6 6
 import java.util.List;
7  
-import java.util.Set;
  7
+import java.util.Map.Entry;
8 8
 
9 9
 import android.app.Activity;
10 10
 import android.content.pm.ApplicationInfo;
11 11
 import android.content.pm.PackageInfo;
  12
+import android.content.pm.PermissionInfo;
12 13
 import android.graphics.drawable.Drawable;
13 14
 import android.view.Gravity;
14 15
 import android.view.View;
@@ -20,18 +21,46 @@
20 21
 
21 22
 public class PermissionAppExpandableAdapter extends BaseExpandableListAdapter {
22 23
     
23  
-	HashMap<String,ArrayList<PackageInfo>> permissionAppMap;	
  24
+	HashMap<String, ArrayList<PackageInfo>> permissionAppMap;	
  25
+	HashMap<String,ArrayList<String>> revokedPermissionMap;
  26
+	HashMap<String,PermissionInfo> permissionStringInfoMap;
24 27
 	Object[] mKeys;
25 28
 	Activity mCTX;
26 29
 	
27  
-	PermissionAppExpandableAdapter( HashMap<String,ArrayList<PackageInfo>> appPermissionMap, Activity context)
  30
+	PermissionAppExpandableAdapter( HashMap<String,ArrayList<PackageInfo>> appPermissionMap, 
  31
+									HashMap<String,ArrayList<String>> revokedPermMap,
  32
+									HashMap<String,PermissionInfo> permStringInfo, 
  33
+									boolean showOnlyDangerous,
  34
+									Activity context)
28 35
 	{
  36
+		revokedPermissionMap = revokedPermMap;
29 37
 		permissionAppMap = appPermissionMap;
30  
-		Set<String> keySet = permissionAppMap.keySet();
31  
-		List<String> sortedList = asSortedList(keySet);
32  
-		mKeys = sortedList.toArray();
  38
+		permissionStringInfoMap = permStringInfo;
  39
+		
  40
+		if(showOnlyDangerous)
  41
+		{
  42
+			mKeys = dangerousPerms();
  43
+		}else
  44
+		{
  45
+			List<String> sortedList = asSortedList(permissionAppMap.keySet());
  46
+			mKeys = sortedList.toArray();
  47
+		}
  48
+
33 49
 		mCTX = context;
34 50
 	}
  51
+	
  52
+	private Object[] dangerousPerms()
  53
+	{	
  54
+		List<String> dangerousPerms = new ArrayList<String>();
  55
+		for(Entry<String,PermissionInfo> entry : permissionStringInfoMap.entrySet())
  56
+		{
  57
+			if(entry.getValue().protectionLevel == PermissionInfo.PROTECTION_DANGEROUS)
  58
+				dangerousPerms.add(entry.getKey());
  59
+		}
  60
+		
  61
+		java.util.Collections.sort(dangerousPerms);
  62
+		return dangerousPerms.toArray();
  63
+	}
35 64
 	public static <T extends Comparable<? super T>> List<T> asSortedList(Collection<T> c) {
36 65
 	  List<T> list = new ArrayList<T>(c);
37 66
 	  java.util.Collections.sort(list);
@@ -42,7 +71,7 @@ public PackageInfo getPackageInfo(int groupPosition, int childPosition)
42 71
 	{
43 72
 		return permissionAppMap.get(mKeys[groupPosition]).get(childPosition);
44 73
 	}
45  
-	
  74
+
46 75
     public Object getChild(int groupPosition, int childPosition) {
47 76
         ApplicationInfo appInfo =  permissionAppMap.get(mKeys[groupPosition]).get(childPosition).applicationInfo;
48 77
         
@@ -73,14 +102,18 @@ public TextView getGenericView() {
73 102
 
74 103
     public View getChildView(int groupPosition, int childPosition, boolean isLastChild,
75 104
             View convertView, ViewGroup parent) {
  105
+    	
76 106
     	Drawable img = permissionAppMap.get(mKeys[groupPosition]).get(childPosition).applicationInfo.loadIcon(mCTX.getPackageManager());
77 107
     	
78 108
     	View view = mCTX.getLayoutInflater().inflate(R.layout.app_layout, null);
79 109
     	TextView textview = (TextView) view.findViewById(R.id.android_info_text);
80 110
     	ImageView imageview = (ImageView) view.findViewById(R.id.android_info_image);
81 111
     	
82  
-    	textview.setText(getChild(groupPosition, childPosition).toString());    
  112
+    	textview.setText(getChild(groupPosition, childPosition).toString());  
  113
+    
83 114
     	imageview.setImageDrawable(img);
  115
+    	if(permissionRevoked(groupPosition, childPosition))
  116
+    		view.setBackgroundColor(0xfff00000);
84 117
         return view;
85 118
     }
86 119
 
@@ -88,7 +121,12 @@ public Object getGroup(int groupPosition) {
88 121
     	String s = (String)mKeys[groupPosition];
89 122
         return s.replaceAll("android.permission.", "");
90 123
     }
91  
-
  124
+  
  125
+    public boolean permissionRevoked(int groupPos, int childPos)
  126
+    {
  127
+    	String pkgName = permissionAppMap.get(mKeys[groupPos]).get(childPos).packageName;
  128
+    	return revokedPermissionMap.get(pkgName).contains(mKeys[groupPos]);
  129
+    }
92 130
     public int getGroupCount() {
93 131
         return mKeys.length;
94 132
     }
@@ -99,9 +137,13 @@ public long getGroupId(int groupPosition) {
99 137
 
100 138
     public View getGroupView(int groupPosition, boolean isExpanded, View convertView,
101 139
             ViewGroup parent) {
102  
-        TextView textView = getGenericView();
103  
-        textView.setText(getGroup(groupPosition).toString());
104  
-        return textView;
  140
+    	View view = mCTX.getLayoutInflater().inflate(R.layout.permission_layout, null);
  141
+    	TextView permissionText = (TextView) view.findViewById(R.id.android_permission_name);
  142
+    	TextView permissionLabelText = (TextView) view.findViewById(R.id.android_permission_label);
  143
+    	CharSequence permissionLabel = permissionStringInfoMap.get(mKeys[groupPosition]).loadLabel(((mCTX.getPackageManager())));
  144
+    	permissionLabelText.setText(permissionLabel);
  145
+    	permissionText.setText(getGroup(groupPosition).toString());
  146
+        return view;
105 147
     }
106 148
 
107 149
     public boolean isChildSelectable(int groupPosition, int childPosition) {
20  src/com/fuzionsoftware/appstats/PermissionAppMapActivity.java
... ...
@@ -1,8 +1,5 @@
1 1
 package com.fuzionsoftware.appstats;
2 2
 
3  
-import java.util.ArrayList;
4  
-import java.util.HashMap;
5  
-
6 3
 import android.app.ExpandableListActivity;
7 4
 import android.content.Intent;
8 5
 import android.content.pm.PackageInfo;
@@ -17,6 +14,7 @@
17 14
 import android.widget.ExpandableListView.OnChildClickListener;
18 15
 import android.widget.Toast;
19 16
 
  17
+import com.fuzionsoftware.utils.CyanogenModHelper;
20 18
 import com.fuzionsoftware.utils.PackageInfoHelper;
21 19
 
22 20
 public class PermissionAppMapActivity extends ExpandableListActivity {
@@ -27,12 +25,12 @@
27 25
     public void onCreate(Bundle savedInstanceState) {
28 26
         requestWindowFeature(Window.FEATURE_NO_TITLE);
29 27
         super.onCreate(savedInstanceState);
30  
-        HashMap<String,ArrayList<PackageInfo>> hMap = PackageInfoHelper.getPermissionAppMap(getApplicationContext());
31  
-        mAdapter = new PermissionAppExpandableAdapter(hMap,this);
  28
+        PackageInfoHelper.setUp(getApplicationContext());
  29
+        mAdapter = new PermissionAppExpandableAdapter(PackageInfoHelper.mPermissionAppMap, PackageInfoHelper.mRevokedPermissionsMap, PackageInfoHelper.mPermissionInfoStringMap, true, this);
32 30
         setListAdapter(mAdapter);
33 31
         getExpandableListView().setOnChildClickListener(mChildClickListener);
34 32
         registerForContextMenu(this.getExpandableListView());
35  
-        CyanogenModCheck.isRunningOnCyanogenmod();
  33
+        CyanogenModHelper.isRunningOnCyanogenmod();
36 34
     }
37 35
     
38 36
     private OnChildClickListener mChildClickListener = new OnChildClickListener() {
@@ -41,7 +39,7 @@ public boolean onChildClick(ExpandableListView parent, View v,
41 39
 
42 40
             Intent intent = new Intent();
43 41
             PackageInfo pi = mAdapter.getPackageInfo(groupPosition,childPosition);
44  
-            intent.putExtra("PackageInfo", pi);
  42
+            intent.putExtra("PackageName", pi.packageName);
45 43
             intent.setClass(PermissionAppMapActivity.this, ApplicationInfoActivity.class);
46 44
             startActivity(intent);
47 45
       
@@ -56,8 +54,14 @@ public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuIn
56 54
 	    
57 55
 	    if (type == ExpandableListView.PACKED_POSITION_TYPE_CHILD) {
58 56
 	        int groupPos = ExpandableListView.getPackedPositionGroup(info.packedPosition); 
  57
+	        int childPos = ExpandableListView.getPackedPositionChild(info.packedPosition); 
59 58
 	        menu.setHeaderTitle((String)mAdapter.getGroup(groupPos));
60  
-	        menu.add("Revoke");
  59
+	        
  60
+	        if(mAdapter.permissionRevoked(groupPos, childPos))
  61
+	        	menu.add("Unrevoke");
  62
+	        else
  63
+	        	menu.add("Revoke");
  64
+	        
61 65
 	        return;
62 66
 	    }
63 67
     }
35  ...com/fuzionsoftware/appstats/CyanogenModCheck.java → src/com/fuzionsoftware/utils/CyanogenModHelper.java
... ...
@@ -1,13 +1,17 @@
1  
-package com.fuzionsoftware.appstats;
  1
+package com.fuzionsoftware.utils;
2 2
 
3 3
 import java.io.BufferedReader;
4 4
 import java.io.IOException;
5 5
 import java.io.InputStreamReader;
  6
+import java.lang.reflect.Method;
6 7
 import java.util.regex.Matcher;
7 8
 import java.util.regex.Pattern;
8 9
 
  10
+import android.content.Context;
  11
+import android.content.pm.PackageManager;
9 12
 
10  
-public class CyanogenModCheck {
  13
+
  14
+public class CyanogenModHelper {
11 15
 	public static final String SYS_PROP_MOD_VERSION = "ro.modversion";
12 16
 	private static String CYANOGEN_VER_REGEX = "CyanogenMod-([^-]*)-.*";
13 17
 	public static boolean isRunningOnCyanogenmod()
@@ -41,6 +45,33 @@ public static boolean hasRevokablePermissions()
41 45
 		}
42 46
 		return false;
43 47
 	}
  48
+	
  49
+    public static String [] getRevokedPerms(String packageName,Context ctx)
  50
+    {
  51
+    	String [] revokedPerms = null;
  52
+    	PackageManager pkgManager = ctx.getPackageManager();
  53
+		Method getRevokedPermissions;
  54
+		try {
  55
+			getRevokedPermissions = pkgManager.getClass().getMethod("getRevokedPermissions",java.lang.String.class);
  56
+			Object[] params = new Object[] { packageName };
  57
+			revokedPerms = (String[]) getRevokedPermissions.invoke(pkgManager, params);
  58
+			if(revokedPerms.length > 0)
  59
+				System.out.println("Package: " + packageName + " has revoked permissions:");
  60
+			for(String revokedPerm : revokedPerms)
  61
+			{
  62
+				System.out.println(revokedPerm);
  63
+			}
  64
+		} catch (Exception e) {
  65
+			// TODO Auto-generated catch block
  66
+			//e.printStackTrace();
  67
+		}
  68
+		return revokedPerms;
  69
+    }
  70
+    
  71
+    public static void setPermissions(String packageName, String [] permissions)
  72
+    {
  73
+
  74
+    }
44 75
 
45 76
 	public static String getSystemProperty(String propName){
46 77
         String line = "";
120  src/com/fuzionsoftware/utils/PackageInfoHelper.java
... ...
@@ -1,35 +1,57 @@
1 1
 package com.fuzionsoftware.utils;
2 2
 
3 3
 import java.util.ArrayList;
  4
+import java.util.Arrays;
4 5
 import java.util.HashMap;
5 6
 import java.util.List;
6 7
 
7 8
 import android.content.Context;
8 9
 import android.content.pm.PackageInfo;
9 10
 import android.content.pm.PackageManager;
  11
+import android.content.pm.PackageManager.NameNotFoundException;
  12
+import android.content.pm.PermissionInfo;
  13
+import android.util.Log;
10 14
 
11 15
 public class PackageInfoHelper {
12  
-	public static HashMap<String,ArrayList<PackageInfo>> mPermissionAppMap;
  16
+	public static HashMap<String, ArrayList<PackageInfo>> mPermissionAppMap;
  17
+	public static HashMap<String, ArrayList<String>> mRevokedPermissionsMap;
  18
+	public static HashMap<String, PermissionInfo> mPermissionInfoStringMap;
13 19
 	public static List<PackageInfo> mPackages;
  20
+	public static PackageManager mPM;
  21
+	public static Context mCTX;
  22
+	private final static String TAG = "PackageInfoHelper";
14 23
 	
15 24
 	public static PackageInfo getPackageInfo(String packageName)
16 25
 	{
17 26
 		for(PackageInfo pi : mPackages)
18 27
 		{
19 28
 			if(pi.packageName == packageName)
20  
-			{
21 29
 				return pi;
22  
-			}
23 30
 		}
24 31
 		return null;
25 32
 	}
26  
-    public static HashMap<String,ArrayList<PackageInfo>> getPermissionAppMap(Context ctx)
  33
+	
  34
+	public static void test()
  35
+	{
  36
+		for(PackageInfo pkg : mPackages)
  37
+		{
  38
+			StringBuilder sb = new StringBuilder(pkg.packageName + " has UID: " + pkg.applicationInfo.uid + " and is part of groups: ");
  39
+			if(pkg.gids == null)
  40
+				continue;
  41
+			for(int gid : pkg.gids)
  42
+			{
  43
+				sb.append(gid + ", ");
  44
+			}
  45
+			System.out.println(sb.toString());
  46
+		}
  47
+	}
  48
+	
  49
+    private static HashMap<String, ArrayList<PackageInfo>> getPermissionAppMap()
27 50
     {
28 51
     	//Permission as the key, array of packages that use that permission
29 52
     	mPermissionAppMap = new HashMap<String,ArrayList<PackageInfo>>(128);    	
30  
-    	PackageManager pm  = ctx.getPackageManager();
31  
-    	mPackages = pm.getInstalledPackages(PackageManager.GET_PERMISSIONS);
32  
-   
  53
+
  54
+    	
33 55
     	for(PackageInfo pi : mPackages)
34 56
     	{
35 57
     		if (pi.requestedPermissions == null)
@@ -45,6 +67,90 @@ public static PackageInfo getPackageInfo(String packageName)
45 67
 	    		mPermissionAppMap.get(permission).add(pi);
46 68
     		}
47 69
     	}    
  70
+
48 71
     	return mPermissionAppMap;
49 72
     }
  73
+    /*
  74
+    private List<PermissionInfo> getPermissionsForPackage(String packageName) {
  75
+        PackageInfo pkgInfo;
  76
+        try {
  77
+            pkgInfo = mPM.getPackageInfo(packageName, PackageManager.GET_PERMISSIONS);
  78
+        } catch (NameNotFoundException e) {
  79
+            Log.w(TAG, "Couldn't retrieve permissions for package:"+packageName);
  80
+            return null;
  81
+        }
  82
+        if ((pkgInfo != null) && (pkgInfo.requestedPermissions != null)) {
  83
+            return extractPerms(pkgInfo.requestedPermissions);
  84
+            
  85
+        }
  86
+        return null;
  87
+    }
  88
+   
  89
+    private static List<PermissionInfo> extractPerms(String strList[]) {
  90
+        if((strList == null) || (strList.length == 0)) {
  91
+            return new ArrayList<PermissionInfo>();
  92
+        }
  93
+        List<PermissionInfo> permissionList = new ArrayList<PermissionInfo>();
  94
+        
  95
+        for(String permName:strList) {
  96
+            try {
  97
+                PermissionInfo tmpPermInfo = mPM.getPermissionInfo(permName, 0);
  98
+                if(tmpPermInfo != null) {
  99
+                	permissionList.add(tmpPermInfo);
  100
+                }
  101
+            } catch (NameNotFoundException e) {
  102
+                Log.i(TAG, "Ignoring unknown permission:"+permName);
  103
+            }
  104
+        }
  105
+        return permissionList;
  106
+    }
  107
+     */
  108
+    private static void getPermissionInfoStringMap()
  109
+    {
  110
+    	if(mPermissionInfoStringMap != null)
  111
+    		return;
  112
+    	
  113
+    	mPermissionInfoStringMap = new HashMap<String,PermissionInfo>();
  114
+    	
  115
+    	for(String permission : mPermissionAppMap.keySet())
  116
+    	{
  117
+	    	try {
  118
+		    		PermissionInfo tmpPermInfo = mPM.getPermissionInfo(permission, 0);
  119
+		    		if(tmpPermInfo != null) {
  120
+		    			mPermissionInfoStringMap.put(permission, tmpPermInfo);
  121
+		    		}
  122
+		        } catch (NameNotFoundException e) {
  123
+		            Log.i(TAG, "Ignoring unknown permission:" + permission);
  124
+		        }
  125
+    	}
  126
+    }
  127
+    
  128
+    public static void setUp(Context ctx)
  129
+    {
  130
+    	 mCTX = ctx;
  131
+    	 mPM  = ctx.getPackageManager();
  132
+    	 mPackages = mPM.getInstalledPackages(PackageManager.GET_PERMISSIONS | PackageManager.GET_GIDS);
  133
+    	 getPermissionAppMap();
  134
+    	 getRevokedPermMap();
  135
+    	 getPermissionInfoStringMap();
  136
+    }
  137
+
  138
+    private static void getRevokedPermMap()
  139
+    {
  140
+    	if(mRevokedPermissionsMap != null)
  141
+    		return;
  142
+    	//if(!(CyanogenModHelper.isRunningOnCyanogenmod() && CyanogenModHelper.hasRevokablePermissions()))
  143
+    	//	return;
  144
+    	mRevokedPermissionsMap = new HashMap<String, ArrayList<String>>();
  145
+    	
  146
+    	for(PackageInfo pi : mPackages)
  147
+    	{
  148
+    		String[] rPerms = CyanogenModHelper.getRevokedPerms(pi.packageName, mCTX);
  149
+    		if(rPerms == null)
  150
+    			rPerms = new String[0];
  151
+    		ArrayList<String> revokedPerms = new ArrayList<String>(Arrays.asList(rPerms));
  152
+    		mRevokedPermissionsMap.put(pi.packageName,revokedPerms);
  153
+    	}  
  154
+    	
  155
+    }
50 156
 }

0 notes on commit d1bb68f

Please sign in to comment.
Something went wrong with that request. Please try again.