Auto-revoke permissions for unused apps

android.permission.PACKAGE_USAGE_STATS is the minimal required
permission to get app usage stats, as confirmed by the API author
and usage stats is the only place giving us historical app-usage information.

Test: reduce thresholds and test with a toy app
Change-Id: Id8767cab93802d3fc90dc32a93ffb20a53f45ad9
diff --git a/cmds/statsd/src/atoms.proto b/cmds/statsd/src/atoms.proto
index d9b3a6c..1c2b087 100644
--- a/cmds/statsd/src/atoms.proto
+++ b/cmds/statsd/src/atoms.proto
@@ -6336,6 +6336,8 @@
         USER_DENIED_WITH_PREJUDICE_IN_SETTINGS = 14;
         // permission was automatically revoked after one-time permission expired
         AUTO_ONE_TIME_PERMISSION_REVOKED = 15;
+        // permission was automatically revoked for unused app
+        AUTO_UNUSED_APP_PERMISSION_REVOKED = 16;
     }
     // The result of the permission grant
     optional Result result = 6;
diff --git a/data/etc/privapp-permissions-platform.xml b/data/etc/privapp-permissions-platform.xml
index 3677b8f..f52a49d 100644
--- a/data/etc/privapp-permissions-platform.xml
+++ b/data/etc/privapp-permissions-platform.xml
@@ -130,6 +130,7 @@
         <permission name="android.permission.APPROVE_INCIDENT_REPORTS"/>
         <permission name="android.permission.READ_PRIVILEGED_PHONE_STATE" />
         <permission name="android.permission.SUBSTITUTE_NOTIFICATION_APP_NAME" />
+        <permission name="android.permission.PACKAGE_USAGE_STATS" />
     </privapp-permissions>
 
     <privapp-permissions package="com.android.phone">