@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); }
/** **************************************************************** 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(); } } }
@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); } }
@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); }