Add app cache clearing mechanism

Adds a dialog, implemented as an activity in MediaProvider, to prompt
the user to clear app cache directories. The dialog is triggered by
starting an activity with the intent action
StorageManager.ACTION_CLEAR_APP_CACHE. The activity will be actually
displayed only if the calling package has MANAGE_EXTERNAL_STORAGE
permission or OP_MANAGE_EXTERNAL_STORAGE allowed.

The activity will return Activity#RESULT_OK if the user allowed the
cache dirs to cleared, and Activity#RESULT_CANCELED in every other case,
including: if the caller doesn't have the right permissions or if the
user decided not to clear app caches.

Bug: 144341120
Test: manual

Change-Id: I2409cc3ad44ae58f1979f23e53adc92814b81b96
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index ecd5943..9935a1f 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -19,6 +19,7 @@
     <uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
     <uses-permission android:name="android.permission.USE_RESERVED_DISK" />
     <uses-permission android:name="android.permission.QUERY_ALL_PACKAGES" />
+    <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
 
     <application
             android:name="com.android.providers.media.MediaApplication"
@@ -96,9 +97,24 @@
         </service>
 
         <activity
-            android:name="com.android.providers.media.PermissionActivity"
-            android:theme="@style/PickerDialogTheme"
-            android:exported="false"
-            android:excludeFromRecents="true" />
+                android:name="com.android.providers.media.PermissionActivity"
+                android:theme="@style/PickerDialogTheme"
+                android:exported="false"
+                android:excludeFromRecents="true" />
+
+        <activity
+                android:name="com.android.providers.media.CacheClearingActivity"
+                android:exported="true"
+                android:theme="@style/CacheClearingAlertDialogTheme"
+                android:finishOnCloseSystemDialogs="true"
+                android:launchMode="singleTop"
+                android:excludeFromRecents="true"
+                android:visibleToInstantApps="true"
+                android:priority="100" >
+            <intent-filter>
+                <action android:name="android.os.storage.action.CLEAR_APP_CACHE" />
+                <category android:name="android.intent.category.DEFAULT" />
+            </intent-filter>
+        </activity>
     </application>
 </manifest>