Apps on sdcard: Add new broadcasts
Add new broadcasts ACTION_MEDIA_RESOURCES_AVAILABLE and ACTION_MEDIA_RESOURCES_UNAVAILABLE that get broadcast by PackageManagerService when sdcard gets mounted/unmounted by MountService so that packages on sdcard get recognized by various system services as being installed/available or removed/unavailable by the system. The broadcasts are sent before the actual package cleanup which includes mounting/unmounting the packages and we force a gc right after so that any lingering file references to resources on sdcard get released.
This commit is contained in:
@ -772,16 +772,33 @@ class AlarmManagerService extends IAlarmManager.Stub {
|
||||
filter.addAction(Intent.ACTION_PACKAGE_RESTARTED);
|
||||
filter.addDataScheme("package");
|
||||
mContext.registerReceiver(this, filter);
|
||||
// Register for events related to sdcard installation.
|
||||
IntentFilter sdFilter = new IntentFilter();
|
||||
sdFilter.addAction(Intent.ACTION_MEDIA_RESOURCES_UNAVAILABLE);
|
||||
mContext.registerReceiver(this, sdFilter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
synchronized (mLock) {
|
||||
Uri data = intent.getData();
|
||||
if (data != null) {
|
||||
String pkg = data.getSchemeSpecificPart();
|
||||
removeLocked(pkg);
|
||||
mBroadcastStats.remove(pkg);
|
||||
String action = intent.getAction();
|
||||
String pkgList[] = null;
|
||||
if (Intent.ACTION_MEDIA_RESOURCES_UNAVAILABLE.equals(action)) {
|
||||
pkgList = intent.getStringArrayExtra(Intent.EXTRA_CHANGED_PACKAGE_LIST);
|
||||
} else {
|
||||
Uri data = intent.getData();
|
||||
if (data != null) {
|
||||
String pkg = data.getSchemeSpecificPart();
|
||||
if (pkg != null) {
|
||||
pkgList = new String[]{pkg};
|
||||
}
|
||||
}
|
||||
}
|
||||
if (pkgList != null && (pkgList.length > 0)) {
|
||||
for (String pkg : pkgList) {
|
||||
removeLocked(pkg);
|
||||
mBroadcastStats.remove(pkg);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user