Don't show permission with no app ops.

We have some permissions that we will be getting rid of and for
that reason do not have app ops. Such permission were showing in
the UI for legacy apps but changing them has no effect because
there is no app ops support. We are not not showing them in the
UI to avoid user frustration.

bug:21168530

Change-Id: I2b6988f003e27b266fb2b48ddbb692ae5cf131fb
diff --git a/src/com/android/packageinstaller/permission/model/PermissionApps.java b/src/com/android/packageinstaller/permission/model/PermissionApps.java
index d3d46cf..10ec959 100644
--- a/src/com/android/packageinstaller/permission/model/PermissionApps.java
+++ b/src/com/android/packageinstaller/permission/model/PermissionApps.java
@@ -151,6 +151,14 @@
             return mPermissionGroup.isSystemFixed();
         }
 
+        public boolean hasRuntimePermissions() {
+            return mPermissionGroup.hasRuntimePermission();
+        }
+
+        public boolean hasAppOpPermissions() {
+            return mPermissionGroup.hasAppOpPermission();
+        }
+
         public String getPackageName() {
             return mPackageName;
         }
diff --git a/src/com/android/packageinstaller/permission/model/PermissionGroup.java b/src/com/android/packageinstaller/permission/model/PermissionGroup.java
index 9e90d4f..901f1a4 100644
--- a/src/com/android/packageinstaller/permission/model/PermissionGroup.java
+++ b/src/com/android/packageinstaller/permission/model/PermissionGroup.java
@@ -173,8 +173,19 @@
                 : com.android.internal.R.drawable.ic_perm_device_info;
     }
 
-    public boolean isAppOpPermission() {
-        return !mAppSupportsRuntimePermissions;
+    public boolean hasRuntimePermission() {
+        return mAppSupportsRuntimePermissions;
+    }
+
+    public boolean hasAppOpPermission() {
+        final int permissionCount = mPermissions.size();
+        for (int i = 0; i < permissionCount; i++) {
+            Permission permission = mPermissions.valueAt(i);
+            if (permission.getAppOp() != AppOpsManager.OP_NONE) {
+                return true;
+            }
+        }
+        return false;
     }
 
     public PackageInfo getApp() {
@@ -512,7 +523,7 @@
         return builder.toString();
     }
 
-    void addPermission(Permission permission) {
+    private void addPermission(Permission permission) {
         mPermissions.put(permission.getName(), permission);
     }
 }
diff --git a/src/com/android/packageinstaller/permission/ui/AppPermissionsFragment.java b/src/com/android/packageinstaller/permission/ui/AppPermissionsFragment.java
index a7c404c..f0e8dba 100644
--- a/src/com/android/packageinstaller/permission/ui/AppPermissionsFragment.java
+++ b/src/com/android/packageinstaller/permission/ui/AppPermissionsFragment.java
@@ -180,6 +180,14 @@
             if (group.isSystemFixed()) {
                 continue;
             }
+
+            // Yes this is possible. We have leftover permissions that
+            // are not in the final groups and we want to get rid of,
+            // therefore we do not have app ops for legacy support.
+            if (!group.hasRuntimePermission() && !group.hasAppOpPermission()) {
+                continue;
+            }
+
             SwitchPreference preference = new SwitchPreference(activity);
             preference.setOnPreferenceChangeListener(this);
             preference.setKey(group.getName());
@@ -232,7 +240,7 @@
         if (newValue == Boolean.TRUE) {
             group.grantRuntimePermissions(false);
         } else {
-            if (group.isAppOpPermission() && !mHasConfirmedRevoke) {
+            if (group.hasAppOpPermission() && !mHasConfirmedRevoke) {
                 new AlertDialog.Builder(getContext())
                         .setMessage(R.string.old_sdk_deny_warning)
                         .setNegativeButton(R.string.cancel, null)
diff --git a/src/com/android/packageinstaller/permission/ui/PermissionAppsFragment.java b/src/com/android/packageinstaller/permission/ui/PermissionAppsFragment.java
index dae90b9..b8ae369 100644
--- a/src/com/android/packageinstaller/permission/ui/PermissionAppsFragment.java
+++ b/src/com/android/packageinstaller/permission/ui/PermissionAppsFragment.java
@@ -144,6 +144,14 @@
             if (app.isSystemFixed()) {
                 continue;
             }
+
+            // Yes this is possible. We have leftover permissions that
+            // are not in the final groups and we want to get rid of,
+            // therefore we do not have app ops for legacy support.
+            if (!app.hasRuntimePermissions() && !app.hasAppOpPermissions()) {
+                continue;
+            }
+
             SwitchPreference pref = (SwitchPreference) findPreference(app.getKey());
             if (pref == null) {
                 pref = new SwitchPreference(context);