2010-11-13 16:40:56 -05:00
|
|
|
package com.fsck.k9.service;
|
|
|
|
|
|
|
|
import android.content.BroadcastReceiver;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.net.Uri;
|
|
|
|
import android.util.Log;
|
|
|
|
|
|
|
|
import com.fsck.k9.K9;
|
|
|
|
import com.fsck.k9.mail.store.StorageManager;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* That BroadcastReceiver is only interested in UNMOUNT events.
|
|
|
|
*
|
|
|
|
* <p>
|
|
|
|
* Code was separated from {@link StorageReceiver} because we don't want that
|
|
|
|
* receiver to be statically defined in manifest.
|
|
|
|
* </p>
|
|
|
|
*/
|
2011-02-06 17:09:48 -05:00
|
|
|
public class StorageGoneReceiver extends BroadcastReceiver {
|
2010-11-13 16:40:56 -05:00
|
|
|
|
|
|
|
@Override
|
2011-02-06 17:09:48 -05:00
|
|
|
public void onReceive(final Context context, final Intent intent) {
|
2010-11-13 16:40:56 -05:00
|
|
|
final String action = intent.getAction();
|
|
|
|
final Uri uri = intent.getData();
|
|
|
|
|
2011-02-06 17:09:48 -05:00
|
|
|
if (uri == null || uri.getPath() == null) {
|
2010-11-13 16:40:56 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-02-06 17:09:48 -05:00
|
|
|
if (K9.DEBUG) {
|
2010-11-13 16:40:56 -05:00
|
|
|
Log.v(K9.LOG_TAG, "StorageGoneReceiver: " + intent.toString());
|
|
|
|
}
|
|
|
|
|
|
|
|
final String path = uri.getPath();
|
|
|
|
|
2011-02-06 17:09:48 -05:00
|
|
|
if (Intent.ACTION_MEDIA_EJECT.equals(action)) {
|
2010-11-13 16:40:56 -05:00
|
|
|
StorageManager.getInstance(K9.app).onBeforeUnmount(path);
|
2011-02-06 17:09:48 -05:00
|
|
|
} else if (Intent.ACTION_MEDIA_UNMOUNTED.equals(action)) {
|
2010-11-13 16:40:56 -05:00
|
|
|
StorageManager.getInstance(K9.app).onAfterUnmount(path);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|