Fields Summary |
---|
private static final String | TAG |
private static final String | MEMORY_SD_SIZE |
private static final String | MEMORY_SD_AVAIL |
private static final String | MEMORY_SD_UNMOUNT |
private static final String | MEMORY_SD_FORMAT |
private android.content.res.Resources | mRes |
private android.preference.Preference | mSdSize |
private android.preference.Preference | mSdAvail |
private android.preference.Preference | mSdUnmount |
private android.preference.Preference | mSdFormat |
private android.os.IMountService | mMountService |
private final android.content.BroadcastReceiver | mReceiver |
Methods Summary |
---|
private java.lang.String | formatSize(long size)
String suffix = null;
// add KB or MB suffix if size is greater than 1K or 1M
if (size >= 1024) {
suffix = " KB";
size /= 1024;
if (size >= 1024) {
suffix = " MB";
size /= 1024;
}
}
DecimalFormat formatter = new DecimalFormat();
formatter.setGroupingSize(3);
String result = formatter.format(size);
if (suffix != null)
result = result + suffix;
return result;
|
private synchronized android.os.IMountService | getMountService()
if (mMountService == null) {
IBinder service = ServiceManager.getService("mount");
if (service != null) {
mMountService = IMountService.Stub.asInterface(service);
} else {
Log.e(TAG, "Can't get mount service");
}
}
return mMountService;
|
protected void | onCreate(android.os.Bundle icicle)
super.onCreate(icicle);
addPreferencesFromResource(R.xml.device_info_memory);
mRes = getResources();
mSdSize = findPreference(MEMORY_SD_SIZE);
mSdAvail = findPreference(MEMORY_SD_AVAIL);
mSdUnmount = findPreference(MEMORY_SD_UNMOUNT);
mSdFormat = findPreference(MEMORY_SD_FORMAT);
|
protected void | onPause()
super.onPause();
unregisterReceiver(mReceiver);
|
public boolean | onPreferenceTreeClick(android.preference.PreferenceScreen preferenceScreen, android.preference.Preference preference)
if (preference == mSdUnmount) {
unmount();
return true;
} else if (preference == mSdFormat) {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setClass(this, com.android.settings.MediaFormat.class);
startActivity(intent);
return true;
}
return false;
|
protected void | onResume()
super.onResume();
IntentFilter intentFilter = new IntentFilter(Intent.ACTION_MEDIA_REMOVED);
intentFilter.addAction(Intent.ACTION_MEDIA_UNMOUNTED);
intentFilter.addAction(Intent.ACTION_MEDIA_MOUNTED);
intentFilter.addAction(Intent.ACTION_MEDIA_SHARED);
intentFilter.addAction(Intent.ACTION_MEDIA_BAD_REMOVAL);
intentFilter.addAction(Intent.ACTION_MEDIA_UNMOUNTABLE);
intentFilter.addAction(Intent.ACTION_MEDIA_NOFS);
intentFilter.addAction(Intent.ACTION_MEDIA_SCANNER_STARTED);
intentFilter.addAction(Intent.ACTION_MEDIA_SCANNER_FINISHED);
intentFilter.addDataScheme("file");
registerReceiver(mReceiver, intentFilter);
updateMemoryStatus();
|
private void | unmount()
IMountService mountService = getMountService();
try {
if (mountService != null) {
mountService.unmountMedia(Environment.getExternalStorageDirectory().toString());
} else {
Log.e(TAG, "Mount service is null, can't unmount");
}
} catch (RemoteException ex) {
// Failed for some reason, try to update UI to actual state
updateMemoryStatus();
}
|
private void | updateMemoryStatus()
String status = Environment.getExternalStorageState();
String readOnly = "";
if (status.equals(Environment.MEDIA_MOUNTED_READ_ONLY)) {
status = Environment.MEDIA_MOUNTED;
readOnly = mRes.getString(R.string.read_only);
}
mSdFormat.setEnabled(false);
if (status.equals(Environment.MEDIA_MOUNTED)) {
try {
File path = Environment.getExternalStorageDirectory();
StatFs stat = new StatFs(path.getPath());
long blockSize = stat.getBlockSize();
long totalBlocks = stat.getBlockCount();
long availableBlocks = stat.getAvailableBlocks();
mSdSize.setSummary(formatSize(totalBlocks * blockSize));
mSdAvail.setSummary(formatSize(availableBlocks * blockSize) + readOnly);
mSdUnmount.setEnabled(true);
} catch (IllegalArgumentException e) {
// this can occur if the SD card is removed, but we haven't received the
// ACTION_MEDIA_REMOVED Intent yet.
status = Environment.MEDIA_REMOVED;
}
} else {
mSdSize.setSummary(mRes.getString(R.string.sd_unavailable));
mSdAvail.setSummary(mRes.getString(R.string.sd_unavailable));
mSdUnmount.setEnabled(false);
if (status.equals(Environment.MEDIA_UNMOUNTED) ||
status.equals(Environment.MEDIA_NOFS) ||
status.equals(Environment.MEDIA_UNMOUNTABLE) ) {
mSdFormat.setEnabled(true);
}
}
File path = Environment.getDataDirectory();
StatFs stat = new StatFs(path.getPath());
long blockSize = stat.getBlockSize();
long availableBlocks = stat.getAvailableBlocks();
findPreference("memory_internal_avail").setSummary(formatSize(availableBlocks * blockSize));
|