@Override public void start() { mStorageManager = (StorageManager) mContext.getSystemService(Context.STORAGE_SERVICE); final boolean connected = mStorageManager.isUsbMassStorageConnected(); if (DEBUG) Log.d( TAG, String.format( "Startup with UMS connection %s (media state %s)", mUmsAvailable, Environment.getExternalStorageState())); HandlerThread thr = new HandlerThread("SystemUI StorageNotification"); thr.start(); mAsyncEventHandler = new Handler(thr.getLooper()); if (GN_USB_SUPPORT && isFirstBoot()) { setToMtpByDefault(); } mStorageEventlistener = new StorageNotificationEventListener(); mStorageEventlistener.onUsbMassStorageConnectionChanged(connected); mStorageManager.registerListener(mStorageEventlistener); IntentFilter filter = new IntentFilter(); filter.addAction(UsbManager.ACTION_USB_STATE); mContext.registerReceiver(mUsbStateReceiver, filter); }
/** * used to get sds path after this method you can get the sd path through CITTools.SD1Path * CITTools.SD2Path */ public int getSDPaths() { mStorageManager = (StorageManager) (mActivity.getSystemService(Context.STORAGE_SERVICE)); storagePathList = mStorageManager.getVolumePaths(); if (storagePathList != null) { mSystemSDCardMountPointPathList = new File[storagePathList.length]; for (int i = 0; i < storagePathList.length; i++) { mSystemSDCardMountPointPathList[i] = new File(storagePathList[i]); } if (storagePathList.length >= 2) { if (FeatureOption.MTK_2SDCARD_SWAP) { SD1Path = storagePathList[1]; // emmc card SD2Path = storagePathList[0]; // SD card } else { SD1Path = storagePathList[0]; // emmc card SD2Path = storagePathList[1]; // SD card } CITPath = SD2Path + "/CIT"; LOGV(true, TAG, "SDCard path: " + SD1Path); LOGV(true, TAG, "SDCard path: " + SD2Path); } else if (storagePathList.length == 1) { SD1Path = storagePathList[0]; CITPath = SD1Path + "/CIT"; LOGV(true, TAG, "SDCard path: " + SD1Path); } return storagePathList.length; } return 0; }
@Override protected void onDestroy() { if (mStorageManager != null && mStorageListener != null) { mStorageManager.unregisterListener(mStorageListener); } if (mCameraDevice != null) mCameraDevice.release(); super.onDestroy(); }
/** * Method that returns the storage volumes defined in the system. This method uses reflection to * retrieve the method because CM10 has a {@link Context} as first parameter, that AOSP hasn't. * * @param ctx The current context * @return StorageVolume[] The storage volumes defined in the system */ @SuppressWarnings("boxing") public static synchronized StorageVolume[] getStorageVolumes(Context ctx) { if (sStorageVolumes == null) { // IMP!! Android SDK doesn't have a "getVolumeList" but is supported by CM10. // Use reflect to get this value (if possible) try { StorageManager sm = (StorageManager) ctx.getSystemService(Context.STORAGE_SERVICE); Method method = sm.getClass().getMethod("getVolumeList"); // $NON-NLS-1$ sStorageVolumes = (StorageVolume[]) method.invoke(sm); } catch (Exception ex) { // Ignore. Android SDK StorageManager class doesn't have this method // Use default android information from environment try { File externalStorage = Environment.getExternalStorageDirectory(); String path = externalStorage.getCanonicalPath(); String description = null; if (path.toLowerCase().indexOf("usb") != -1) { // $NON-NLS-1$ description = ctx.getString(R.string.usb_storage); } else { description = ctx.getString(R.string.external_storage); } // Android SDK has a different constructor for StorageVolume. In CM10 the // description is a resource id. Create the object by reflection Constructor<StorageVolume> constructor = StorageVolume.class.getConstructor( String.class, String.class, boolean.class, boolean.class, int.class, boolean.class, long.class); StorageVolume sv = constructor.newInstance(path, description, false, false, 0, false, 0); sStorageVolumes = new StorageVolume[] {sv}; } catch (Exception ex2) { /** NON BLOCK* */ } } if (sStorageVolumes == null) { sStorageVolumes = new StorageVolume[] {}; } } return sStorageVolumes; }
@Override protected void onPause() { super.onPause(); unregisterReceiver(mUsbStateReceiver); if (mStorageManager == null && mStorageListener != null) { mStorageManager.unregisterListener(mStorageListener); } }
/** **************************************************************** about DeviceStorage() */ private void InitStorage() { Log.v(TAG, ">>>>>>>>> InitStorage : "); if (mStorageManager == null) { mStorageManager = (StorageManager) getSystemService(Context.STORAGE_SERVICE); mStorageManager.registerListener(mStorageListener); storageVolumes = mStorageManager.getVolumeList(); Log.v(TAG, ">>>>>>>>> InitStorage storageVolumes : " + storageVolumes); if (storageVolumes.length >= 3) { flash_path = storageVolumes[flash_pit].getPath(); sdcard_path = storageVolumes[sdcard_pit].getPath(); usb_path = storageVolumes[usb_pit].getPath(); Log.d(TAG, " >>>>>>> _____ " + flash_path + " " + sdcard_path + " " + usb_path); } else if (storageVolumes.length == 2) { sdcard_path = storageVolumes[flash_pit].getPath(); usb_path = storageVolumes[sdcard_pit].getPath(); } } }
/** * This method checks whether SDcard is mounted or not * * @param mountPoint the mount point that should be checked * @return true if SDcard is mounted, false otherwise */ public boolean checkSDCardMount(String mountPoint) { getSDPaths(); if (mountPoint == null) { return false; } String state = null; state = mStorageManager.getVolumeState(mountPoint); return Environment.MEDIA_MOUNTED.equals(state); }
public String[] getStorageList(Context context) { String[] paths = null; if (context != null) { StorageManager storageMan = (StorageManager) context.getSystemService(Context.STORAGE_SERVICE); try { Method methodGetPaths = storageMan.getClass().getMethod("getVolumePaths"); try { paths = (String[]) methodGetPaths.invoke(storageMan); } catch (Exception e) { e.printStackTrace(); } } catch (NoSuchMethodException e) { e.printStackTrace(); } } return paths; }
public void systemReady() { if (DEBUG) Slog.d(TAG, "systemReady"); mNotificationManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE); // We do not show the USB notification if the primary volume supports mass storage. // The legacy mass storage UI will be used instead. boolean massStorageSupported = false; final StorageManager storageManager = StorageManager.from(mContext); final StorageVolume primary = storageManager.getPrimaryVolume(); massStorageSupported = primary != null && primary.allowMassStorage(); mUseUsbNotification = !massStorageSupported; // make sure the ADB_ENABLED setting value matches the current state Settings.Global.putInt(mContentResolver, Settings.Global.ADB_ENABLED, mAdbEnabled ? 1 : 0); mHandler.sendEmptyMessage(MSG_SYSTEM_READY); }
@Override public void start() { mStorageManager = (StorageManager) mContext.getSystemService(Context.STORAGE_SERVICE); final boolean connected = mStorageManager.isUsbMassStorageConnected(); if (DEBUG) Log.d( TAG, String.format( "Startup with UMS connection %s (media state %s)", mUmsAvailable, Environment.getExternalStorageState())); HandlerThread thr = new HandlerThread("SystemUI StorageNotification"); thr.start(); mAsyncEventHandler = new Handler(thr.getLooper()); StorageNotificationEventListener listener = new StorageNotificationEventListener(); listener.onUsbMassStorageConnectionChanged(connected); mStorageManager.registerListener(listener); }
@Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (UsbManager.ACTION_USB_STATE.equals(action)) { mUsbDeviceConnect = intent.getBooleanExtra(UsbManager.USB_CONNECTED, false); boolean isConnected = mStorageManager.isUsbMassStorageConnected(); Log.v( TAG, "isConnected = " + isConnected + " mUsbDeviceConnect = " + mUsbDeviceConnect); mStorageEventlistener.onUsbMassStorageConnectionChanged(isConnected); } }
/** * 获取多张 sd卡的 路径 * * @return */ public static String[] getSdCardPath() { StorageManager sm = (StorageManager) CKApplication.context.getSystemService(Context.STORAGE_SERVICE); String[] paths = null; try { paths = (String[]) sm.getClass().getMethod("getVolumePaths", null).invoke(sm, null); } catch (IllegalArgumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalAccessException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (InvocationTargetException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (NoSuchMethodException e) { // TODO Auto-generated catch block e.printStackTrace(); } return paths; }
private StorageVolumePreferenceCategory(Context context, StorageVolume volume) { super(context); mVolume = volume; mMeasure = StorageMeasurement.getInstance(context, volume); mResources = context.getResources(); mStorageManager = StorageManager.from(context); mUserManager = (UserManager) context.getSystemService(Context.USER_SERVICE); setTitle( volume != null ? volume.getDescription(context) : context.getText(R.string.internal_storage)); }
public StorageNotification(Context context) { mContext = context; mStorageManager = (StorageManager) context.getSystemService(Context.STORAGE_SERVICE); final boolean connected = mStorageManager.isUsbMassStorageConnected(); Slog.d( TAG, String.format( "Startup with UMS connection %s (media state %s)", mUmsAvailable, Environment.getExternalStorageState())); HandlerThread thr = new HandlerThread("SystemUI StorageNotification"); thr.start(); mAsyncEventHandler = new Handler(thr.getLooper()); onUsbMassStorageConnectionChanged(connected); }
/** * <get all external devices> <Functional Details> * * @return external devices collection. * @see [Class,Class#Method,Class#Member] */ private List<MountInfoBean> getAllMountDevices() { List<MountInfoBean> list = new ArrayList<MountInfoBean>(); MountInfoBean bean = null; String path = null; StorageVolume[] storageVolumes = mStorageManager.getVolumeList(); if (null != storageVolumes) { for (int i = 0; i < storageVolumes.length; i++) { bean = new MountInfoBean(); path = storageVolumes[i].getPath(); bean.setPath(path); bean.setType(getPathType(path)); list.add(bean); } } return list; }
private void updateMemoryStatus(String path) { if (TextUtils.isEmpty(path)) { nandstorage.setText(mRes.getString(R.string.nand_unavailable)); availablenandstorage.setText(mRes.getString(R.string.nand_unavailable)); return; } String status = "" /*mStorageManager.getVolumeState(path)*/; if (path.equals(flash_path)) { status = mStorageManager.getVolumeState(flash_path); } String readOnly = ""; if (status.equals(Environment.MEDIA_MOUNTED_READ_ONLY)) { status = Environment.MEDIA_MOUNTED; readOnly = mRes.getString(R.string.read_only); } if (status.equals(Environment.MEDIA_MOUNTED)) { try { // File path = Environment.getExternalStorageDirectory(); StatFs stat = new StatFs(path); long blockSize = stat.getBlockSize(); long totalBlocks = stat.getBlockCount(); long availableBlocks = stat.getAvailableBlocks(); if (path.equals(flash_path)) { nandstorage.setText( mRes.getString(R.string.total_space) + " : " + formatSize(totalBlocks * blockSize)); availablenandstorage.setText( mRes.getString(R.string.available_space) + " : " + formatSize(availableBlocks * blockSize) + readOnly); } } catch (IllegalArgumentException e) { status = Environment.MEDIA_REMOVED; } } else { if (path.equals(flash_path)) { nandstorage.setText(mRes.getString(R.string.nand_unavailable)); availablenandstorage.setText(mRes.getString(R.string.nand_unavailable)); } } }
@Override protected void onResume() { super.onResume(); mStorageManager.registerListener(mStorageListener); registerReceiver(mUsbStateReceiver, new IntentFilter(UsbManager.ACTION_USB_STATE)); try { mAsyncStorageHandler.post( new Runnable() { @Override public void run() { switchDisplay(mStorageManager.isUsbMassStorageEnabled()); } }); } catch (Exception ex) { Log.e(TAG, "Failed to read UMS enable state", ex); } }
public boolean testSdcard() { try { String externalVolumeState = mStorageManager.getVolumeState(sdcard_path); Log.d( TAG, " __________----------- testSdcard(), externalVolumeState = " + externalVolumeState); if (!externalVolumeState.equals(Environment.MEDIA_MOUNTED)) { return false; } } catch (Exception rex) { rex.printStackTrace(); // test sdcard fail return false; } Log.d(TAG, " __________----------- testSdcard() __ begin test read and write"); // return testReadAndWrite(sdcard_path + "/test"); return testSDCard(sdcard_path); }
/** **************************************************************** about USBHost */ public boolean testUSBHost() { try { String externalVolumeState = mStorageManager.getVolumeState(usb_path).toString(); Log.d( TAG, " __________----------- testUSBHost(), externalVolumeState = " + externalVolumeState); // Toast.makeText(getApplicationContext(), "externalVolumeState = " + externalVolumeState, // Toast.LENGTH_LONG).show(); if (!externalVolumeState.equals(Environment.MEDIA_MOUNTED)) { return false; } else return true; } catch (Exception rex) { rex.printStackTrace(); return false; } // Log.d(TAG, " __________----------- testUSBHost() __ begin test read and write"); // return testReadAndWrite(usb_path + "/test"); }
private void onStorageStateChangedAsync(String path, String oldState, String newState) { if (DEBUG) Log.i( TAG, String.format("Media {%s} state changed from {%s} -> {%s}", path, oldState, newState)); if (newState.equals(Environment.MEDIA_SHARED)) { /* * Storage is now shared. Modify the UMS notification * for stopping UMS. */ Intent intent = new Intent(); intent.setClass(mContext, com.android.systemui.usb.UsbStorageActivity.class); PendingIntent pi = PendingIntent.getActivity(mContext, 0, intent, 0); setUsbStorageNotification( com.android.internal.R.string.usb_storage_stop_notification_title, com.android.internal.R.string.usb_storage_stop_notification_message, com.android.internal.R.drawable.stat_sys_warning, false, true, pi); } else if (newState.equals(Environment.MEDIA_CHECKING)) { /* * Storage is now checking. Update media notification and disable * UMS notification. */ setMediaStorageNotification( com.android.internal.R.string.ext_media_checking_notification_title, com.android.internal.R.string.ext_media_checking_notification_message, com.android.internal.R.drawable.stat_notify_sdcard_prepare, true, false, null); updateUsbMassStorageNotification(false); } else if (newState.equals(Environment.MEDIA_MOUNTED)) { /* * Storage is now mounted. Dismiss any media notifications, * and enable UMS notification if connected. */ setMediaStorageNotification(0, 0, 0, false, false, null); updateUsbMassStorageNotification(mUmsAvailable); } else if (newState.equals(Environment.MEDIA_UNMOUNTED)) { /* * Storage is now unmounted. We may have been unmounted * because the user is enabling/disabling UMS, in which case we don't * want to display the 'safe to unmount' notification. */ if (!mStorageManager.isUsbMassStorageEnabled()) { if (oldState.equals(Environment.MEDIA_SHARED)) { /* * The unmount was due to UMS being enabled. Dismiss any * media notifications, and enable UMS notification if connected */ setMediaStorageNotification(0, 0, 0, false, false, null); updateUsbMassStorageNotification(mUmsAvailable); } else { /* * Show safe to unmount media notification, and enable UMS * notification if connected. */ if (Environment.isExternalStorageRemovable()) { setMediaStorageNotification( com.android.internal.R.string.ext_media_safe_unmount_notification_title, com.android.internal.R.string.ext_media_safe_unmount_notification_message, com.android.internal.R.drawable.stat_notify_sdcard, true, true, null); } else { // This device does not have removable storage, so // don't tell the user they can remove it. setMediaStorageNotification(0, 0, 0, false, false, null); } updateUsbMassStorageNotification(mUmsAvailable); } } else { /* * The unmount was due to UMS being enabled. Dismiss any * media notifications, and disable the UMS notification */ setMediaStorageNotification(0, 0, 0, false, false, null); updateUsbMassStorageNotification(false); } } else if (newState.equals(Environment.MEDIA_NOFS)) { /* * Storage has no filesystem. Show blank media notification, * and enable UMS notification if connected. */ Intent intent = new Intent(); intent.setClass(mContext, com.android.internal.app.ExternalMediaFormatActivity.class); PendingIntent pi = PendingIntent.getActivity(mContext, 0, intent, 0); setMediaStorageNotification( com.android.internal.R.string.ext_media_nofs_notification_title, com.android.internal.R.string.ext_media_nofs_notification_message, com.android.internal.R.drawable.stat_notify_sdcard_usb, true, false, pi); updateUsbMassStorageNotification(mUmsAvailable); } else if (newState.equals(Environment.MEDIA_UNMOUNTABLE)) { /* * Storage is corrupt. Show corrupt media notification, * and enable UMS notification if connected. */ Intent intent = new Intent(); intent.setClass(mContext, com.android.internal.app.ExternalMediaFormatActivity.class); PendingIntent pi = PendingIntent.getActivity(mContext, 0, intent, 0); setMediaStorageNotification( com.android.internal.R.string.ext_media_unmountable_notification_title, com.android.internal.R.string.ext_media_unmountable_notification_message, com.android.internal.R.drawable.stat_notify_sdcard_usb, true, false, pi); updateUsbMassStorageNotification(mUmsAvailable); } else if (newState.equals(Environment.MEDIA_REMOVED)) { /* * Storage has been removed. Show nomedia media notification, * and disable UMS notification regardless of connection state. */ setMediaStorageNotification( com.android.internal.R.string.ext_media_nomedia_notification_title, com.android.internal.R.string.ext_media_nomedia_notification_message, com.android.internal.R.drawable.stat_notify_sdcard_usb, true, false, null); updateUsbMassStorageNotification(false); } else if (newState.equals(Environment.MEDIA_BAD_REMOVAL)) { /* * Storage has been removed unsafely. Show bad removal media notification, * and disable UMS notification regardless of connection state. */ setMediaStorageNotification( com.android.internal.R.string.ext_media_badremoval_notification_title, com.android.internal.R.string.ext_media_badremoval_notification_message, com.android.internal.R.drawable.stat_sys_warning, true, true, null); updateUsbMassStorageNotification(false); } else { Log.w(TAG, String.format("Ignoring unknown state {%s}", newState)); } }
private void updateVolumesLocked() { mRoots.clear(); final int userId = UserHandle.myUserId(); final List<VolumeInfo> volumes = mStorageManager.getVolumes(); for (VolumeInfo volume : volumes) { if (!volume.isMountedReadable()) continue; final String rootId; final String title; if (volume.getType() == VolumeInfo.TYPE_EMULATED) { // We currently only support a single emulated volume mounted at // a time, and it's always considered the primary rootId = ROOT_ID_PRIMARY_EMULATED; if (VolumeInfo.ID_EMULATED_INTERNAL.equals(volume.getId())) { title = getContext().getString(R.string.root_internal_storage); } else { final VolumeInfo privateVol = mStorageManager.findPrivateForEmulated(volume); title = mStorageManager.getBestVolumeDescription(privateVol); } } else if (volume.getType() == VolumeInfo.TYPE_PUBLIC) { rootId = volume.getFsUuid(); title = mStorageManager.getBestVolumeDescription(volume); } else { // Unsupported volume; ignore continue; } if (TextUtils.isEmpty(rootId)) { Log.d(TAG, "Missing UUID for " + volume.getId() + "; skipping"); continue; } if (mRoots.containsKey(rootId)) { Log.w(TAG, "Duplicate UUID " + rootId + " for " + volume.getId() + "; skipping"); continue; } try { final RootInfo root = new RootInfo(); mRoots.put(rootId, root); root.rootId = rootId; root.flags = Root.FLAG_SUPPORTS_CREATE | Root.FLAG_LOCAL_ONLY | Root.FLAG_ADVANCED | Root.FLAG_SUPPORTS_SEARCH | Root.FLAG_SUPPORTS_IS_CHILD; root.title = title; if (volume.getType() == VolumeInfo.TYPE_PUBLIC) { root.flags |= Root.FLAG_HAS_SETTINGS; } if (volume.isVisibleForRead(userId)) { root.visiblePath = volume.getPathForUser(userId); } else { root.visiblePath = null; } root.path = volume.getInternalPathForUser(userId); root.docId = getDocIdForFile(root.path); } catch (FileNotFoundException e) { throw new IllegalStateException(e); } } Log.d(TAG, "After updating volumes, found " + mRoots.size() + " active roots"); // Note this affects content://com.android.externalstorage.documents/root/39BD-07C5 // as well as content://com.android.externalstorage.documents/document/*/children, // so just notify on content://com.android.externalstorage.documents/. getContext().getContentResolver().notifyChange(BASE_URI, null, false); }
private void updatePreferencesFromState() { // Only update for physical volumes if (mVolume == null) return; if (mMountTogglePreference != null) { mMountTogglePreference.setEnabled(true); } final String state = mStorageManager.getVolumeState(mVolume.getPath()); if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) { mItemAvailable.setSummary(R.string.memory_available_read_only); if (mFormatPreference != null) { removePreference(mFormatPreference); } } else { mItemAvailable.setSummary(R.string.memory_available); } if (Environment.MEDIA_MOUNTED.equals(state) || Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) { if (mMountTogglePreference != null) { mMountTogglePreference.setEnabled(true); mMountTogglePreference.setTitle(mResources.getString(R.string.sd_eject)); mMountTogglePreference.setSummary(mResources.getString(R.string.sd_eject_summary)); } } else { if (Environment.MEDIA_UNMOUNTED.equals(state) || Environment.MEDIA_NOFS.equals(state) || Environment.MEDIA_UNMOUNTABLE.equals(state)) { if (mMountTogglePreference != null) { mMountTogglePreference.setEnabled(true); mMountTogglePreference.setTitle(mResources.getString(R.string.sd_mount)); mMountTogglePreference.setSummary(mResources.getString(R.string.sd_mount_summary)); } } else { if (mMountTogglePreference != null) { mMountTogglePreference.setEnabled(false); mMountTogglePreference.setTitle(mResources.getString(R.string.sd_mount)); mMountTogglePreference.setSummary(mResources.getString(R.string.sd_insert_summary)); } } removePreference(mUsageBarPreference); removePreference(mItemTotal); removePreference(mItemAvailable); if (mFormatPreference != null) { removePreference(mFormatPreference); } } if (mUsbConnected && (UsbManager.USB_FUNCTION_MTP.equals(mUsbFunction) || UsbManager.USB_FUNCTION_PTP.equals(mUsbFunction))) { if (mMountTogglePreference != null) { mMountTogglePreference.setEnabled(false); } if (Environment.MEDIA_MOUNTED.equals(state) || Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) { if (mMountTogglePreference != null) { mMountTogglePreference.setSummary(mResources.getString(R.string.mtp_ptp_mode_summary)); } } if (mFormatPreference != null) { mFormatPreference.setEnabled(false); mFormatPreference.setSummary(mResources.getString(R.string.mtp_ptp_mode_summary)); } } else if (mFormatPreference != null) { mFormatPreference.setEnabled(true); mFormatPreference.setSummary(mResources.getString(R.string.sd_format_summary)); } }
private void executeInit(Context context) { StorageManager mStorageManager = (StorageManager) context.getSystemService(Context.STORAGE_SERVICE); if (mStorageManager != null) { Class<?> mStorageVolume = null; Method mGetVolumeListMethod = null; Method mGetVolumeStateMethod = null; Method mGetPathMethod = null; Method mIsRemovableMethod = null; Object[] mStorageVolumeList = null; try { mStorageVolume = Class.forName(CLASS_NAME); mGetVolumeListMethod = mStorageManager.getClass().getMethod(METHOD_GET_VOLUME_LIST, new Class[0]); mGetVolumeStateMethod = mStorageManager .getClass() .getMethod(METHOD_GET_VOLUME_STATE, new Class[] {String.class}); mIsRemovableMethod = mStorageVolume.getMethod(METHOD_IS_REMOVABLE, new Class[0]); mGetPathMethod = mStorageVolume.getMethod(METHOD_GET_PATH, new Class[0]); mStorageVolumeList = (Object[]) mGetVolumeListMethod.invoke(mStorageManager, new Object[0]); boolean mIsRemovable = false; if (mStorageVolumeList != null && mStorageVolumeList.length > 0) { int mStorageVolumeCount = mStorageVolumeList.length; Log.i(TAG, "init() === > StorageVolume Count = " + mStorageVolumeCount); mInternalPathList.clear(); mExternalPathList.clear(); for (int i = 0; i < mStorageVolumeCount; ++i) { String mStoragePath = (String) mGetPathMethod.invoke(mStorageVolumeList[i], new Object[0]); mIsRemovable = ((Boolean) mIsRemovableMethod.invoke(mStorageVolumeList[i], new Object[0])) .booleanValue(); if (!TextUtils.isEmpty(mStoragePath)) { String state = (String) mGetVolumeStateMethod.invoke(mStorageManager, new Object[] {mStoragePath}); if ((state != null) && (state.equals(MOUNTED))) { if (mIsRemovable) { Log.i(TAG, "init() === > external storage path = (" + mStoragePath + ")"); mExternalPathList.add(mStoragePath); } else { Log.i(TAG, "init() === > internal storage path = (" + mStoragePath + ")"); mInternalPathList.add(mStoragePath); } } } } } } catch (ClassNotFoundException e) { handleInvalid(); Log.e(TAG, "init() === > Exception:ClassNotFoundException"); } catch (NoSuchMethodException e) { handleInvalid(); Log.e(TAG, "init() === > Exception:NoSuchMethodException"); } catch (IllegalArgumentException e) { handleInvalid(); Log.e(TAG, "init() === > Exception:IllegalArgumentException"); } catch (IllegalAccessException e) { handleInvalid(); Log.e(TAG, "init() === > Exception:IllegalAccessException"); } catch (InvocationTargetException e) { handleInvalid(); Log.e(TAG, "init() === > Exception:InvocationTargetException"); } } else { handleInvalid(); Log.e(TAG, "init() === > can't get storage manager"); } initSDCardPath(); }