diff options
author | Dianne Hackborn <hackbod@google.com> | 2010-02-04 17:38:14 -0800 |
---|---|---|
committer | Dianne Hackborn <hackbod@google.com> | 2010-02-09 14:20:55 -0800 |
commit | e83cefcef07f9ac025642c1ffec76b4c7ab39cf2 (patch) | |
tree | 130696ee2a90150129c3ee98544c5814528c90f9 /packages | |
parent | 72e5a8820a996c547eacea534b11b6b8f6eca83b (diff) | |
download | frameworks_base-e83cefcef07f9ac025642c1ffec76b4c7ab39cf2.zip frameworks_base-e83cefcef07f9ac025642c1ffec76b4c7ab39cf2.tar.gz frameworks_base-e83cefcef07f9ac025642c1ffec76b4c7ab39cf2.tar.bz2 |
New external storage APIs.
This implements the spec for external storage organization, and
properly reflects how the media scanner organizes the files it finds.
Also includes package manager support for removing app private
files from external storage when the application is uninstalled.
For the new APIs and paths, the main place to look is Environment
and Context.
Diffstat (limited to 'packages')
-rwxr-xr-x | packages/DefaultContainerService/AndroidManifest.xml | 4 | ||||
-rw-r--r-- | packages/DefaultContainerService/src/com/android/defcontainer/DefaultContainerService.java | 41 |
2 files changed, 41 insertions, 4 deletions
diff --git a/packages/DefaultContainerService/AndroidManifest.xml b/packages/DefaultContainerService/AndroidManifest.xml index 3d72017..5ec72df 100755 --- a/packages/DefaultContainerService/AndroidManifest.xml +++ b/packages/DefaultContainerService/AndroidManifest.xml @@ -5,9 +5,9 @@ <uses-permission android:name="android.permission.ASEC_CREATE"/> <uses-permission android:name="android.permission.ASEC_DESTROY"/> <uses-permission android:name="android.permission.ASEC_MOUNT_UNMOUNT"/> + <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> - <application android:process="def.container.service" - android:label="@string/service_name"> + <application android:label="@string/service_name"> <service android:name=".DefaultContainerService" android:enabled="true" diff --git a/packages/DefaultContainerService/src/com/android/defcontainer/DefaultContainerService.java b/packages/DefaultContainerService/src/com/android/defcontainer/DefaultContainerService.java index fecd366..c418ccb 100644 --- a/packages/DefaultContainerService/src/com/android/defcontainer/DefaultContainerService.java +++ b/packages/DefaultContainerService/src/com/android/defcontainer/DefaultContainerService.java @@ -3,8 +3,11 @@ package com.android.defcontainer; import com.android.internal.app.IMediaContainerService; import android.content.Intent; +import android.content.pm.IPackageManager; +import android.content.pm.PackageManager; import android.net.Uri; import android.os.Debug; +import android.os.Environment; import android.os.IBinder; import android.os.storage.IMountService; import android.os.storage.StorageResultCode; @@ -12,6 +15,7 @@ import android.os.ParcelFileDescriptor; import android.os.Process; import android.os.RemoteException; import android.os.ServiceManager; +import android.app.IntentService; import android.app.Service; import android.util.Log; @@ -25,7 +29,6 @@ import java.io.OutputStream; import android.os.FileUtils; - /* * This service copies a downloaded apk to a file passed in as * a ParcelFileDescriptor or to a newly created container specified @@ -33,7 +36,7 @@ import android.os.FileUtils; * based on its uid. This process also needs the ACCESS_DOWNLOAD_MANAGER * permission to access apks downloaded via the download manager. */ -public class DefaultContainerService extends Service { +public class DefaultContainerService extends IntentService { private static final String TAG = "DefContainer"; private static final boolean localLOGV = false; @@ -78,6 +81,40 @@ public class DefaultContainerService extends Service { } }; + public DefaultContainerService() { + super("DefaultContainerService"); + setIntentRedelivery(true); + } + + @Override + protected void onHandleIntent(Intent intent) { + if (PackageManager.ACTION_CLEAN_EXTERNAL_STORAGE.equals(intent.getAction())) { + IPackageManager pm = IPackageManager.Stub.asInterface( + ServiceManager.getService("package")); + String pkg = null; + try { + while ((pkg=pm.nextPackageToClean(pkg)) != null) { + eraseFiles(Environment.getExternalStorageAppDataDirectory(pkg)); + eraseFiles(Environment.getExternalStorageAppMediaDirectory(pkg)); + } + } catch (RemoteException e) { + } + } + } + + void eraseFiles(File path) { + if (path.isDirectory()) { + String[] files = path.list(); + if (files != null) { + for (String file : files) { + eraseFiles(new File(path, file)); + } + } + } + //Log.i(TAG, "Deleting: " + path); + path.delete(); + } + public IBinder onBind(Intent intent) { return mBinder; } |