MTP/PTP: disable erasing/unmount operation for SD card while MTP/PTP is active
Check the USB connection status and MTP/PTP setting, if USB connected and MTP/PTP enabled, disable the erasing and umount operation. Judge SD card Mounting status and keep summary string. Change-Id: Iff3e0f25b581bc462c88fff59eb93d765baaddd7 Author: Li Gang <gang.g.li@intel.com> Signed-off-by: Xiaokang Qin <xiaokang.qin@intel.com> Signed-off-by: Bruce Beare <bruce.j.beare@intel.com> Signed-off-by: Jack Ren <jack.ren@intel.com> Author-tracking-BZ: 47043
This commit is contained in:
@@ -24,6 +24,7 @@ import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.res.Resources;
|
||||
import android.hardware.usb.UsbManager;
|
||||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
import android.os.IBinder;
|
||||
@@ -65,6 +66,8 @@ public class Memory extends SettingsPreferenceFragment {
|
||||
|
||||
private StorageManager mStorageManager = null;
|
||||
|
||||
private UsbManager mUsbManager = null;
|
||||
|
||||
private StorageVolumePreferenceCategory mInternalStorageVolumePreferenceCategory;
|
||||
private StorageVolumePreferenceCategory[] mStorageVolumePreferenceCategories;
|
||||
|
||||
@@ -72,6 +75,8 @@ public class Memory extends SettingsPreferenceFragment {
|
||||
public void onCreate(Bundle icicle) {
|
||||
super.onCreate(icicle);
|
||||
|
||||
mUsbManager = (UsbManager)getSystemService(Context.USB_SERVICE);
|
||||
|
||||
if (mStorageManager == null) {
|
||||
mStorageManager = (StorageManager) getSystemService(Context.STORAGE_SERVICE);
|
||||
mStorageManager.registerListener(mStorageListener);
|
||||
@@ -119,6 +124,10 @@ public class Memory extends SettingsPreferenceFragment {
|
||||
intentFilter.addDataScheme("file");
|
||||
getActivity().registerReceiver(mMediaScannerReceiver, intentFilter);
|
||||
|
||||
intentFilter = new IntentFilter();
|
||||
intentFilter.addAction(UsbManager.ACTION_USB_STATE);
|
||||
getActivity().registerReceiver(mMediaScannerReceiver, intentFilter);
|
||||
|
||||
if (mInternalStorageVolumePreferenceCategory != null) {
|
||||
mInternalStorageVolumePreferenceCategory.onResume();
|
||||
}
|
||||
@@ -237,9 +246,18 @@ public class Memory extends SettingsPreferenceFragment {
|
||||
private final BroadcastReceiver mMediaScannerReceiver = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
// mInternalStorageVolumePreferenceCategory is not affected by the media scanner
|
||||
for (int i = 0; i < mStorageVolumePreferenceCategories.length; i++) {
|
||||
mStorageVolumePreferenceCategories[i].onMediaScannerFinished();
|
||||
String action = intent.getAction();
|
||||
if (action.equals(UsbManager.ACTION_USB_STATE)) {
|
||||
boolean isUsbConnected = intent.getBooleanExtra(UsbManager.USB_CONNECTED, false);
|
||||
String usbFunction = mUsbManager.getDefaultFunction();
|
||||
for (int i = 0; i < mStorageVolumePreferenceCategories.length; i++) {
|
||||
mStorageVolumePreferenceCategories[i].onUsbStateChanged(isUsbConnected, usbFunction);
|
||||
}
|
||||
} else if (action.equals(Intent.ACTION_MEDIA_SCANNER_FINISHED)) {
|
||||
// mInternalStorageVolumePreferenceCategory is not affected by the media scanner
|
||||
for (int i = 0; i < mStorageVolumePreferenceCategories.length; i++) {
|
||||
mStorageVolumePreferenceCategories[i].onMediaScannerFinished();
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
Reference in New Issue
Block a user