[Android Software Development] vijendrahs:
I have a ported MIUI 2.8.17 and only major problem is with USB detection, even after following the steps mention in OP I am able to get the USB connected pop-up but on selection of the media type i am getting the errors

When I connect my device using USB cable I get the following.

D/ConnectivityService( 318): ConnectivityChange for mobile: CONNECTED/CONNECTED

E/MediaScannerService( 670): exception in MediaScanner.scan()

E/MediaScannerService( 670): java.lang.ArrayIndexOutOfBoundsException: length=0; index=0

E/MediaScannerService( 670):	at com.android.providers.media.MediaProvider.updateDatabase(MediaProvider.java:1182)

E/MediaScannerService( 670):	at com.android.providers.media.MediaProvider.access$800(MediaProvider.java:116)

E/MediaScannerService( 670):	at com.android.providers.media.MediaProvider$DatabaseHelper.onCreate(MediaProvider.java:365)

E/MediaScannerService( 670):	at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java)

E/MediaScannerService( 670):	at android.database.sqlite.SQLiteOpenHelper.getReadableDatabase(SQLiteOpenHelper.java)

E/MediaScannerService( 670):	at com.android.providers.media.MediaProvider.query(MediaProvider.java:2083)

E/MediaScannerService( 670):	at android.content.ContentProvider.query(ContentProvider.java)

E/MediaScannerService( 670):	at android.content.ContentProvider$Transport.query(ContentProvider.java)

E/MediaScannerService( 670):	at android.media.MediaScanner.prescan(MediaScanner.java)

E/MediaScannerService( 670):	at android.media.MediaScanner.scanDirectories(MediaScanner.java)

E/MediaScannerService( 670):	at com.android.providers.media.MediaScannerService.scan(MediaScannerService.java:106)

E/MediaScannerService( 670):	at com.android.providers.media.MediaScannerService.access$300(MediaScannerService.java:51)

E/MediaScannerService( 670):	at com.android.providers.media.MediaScannerService$ServiceHandler.handleMessage(MediaScannerService.java:268)

E/MediaScannerService( 670):	at android.os.Handler.dispatchMessage(Handler.java)

E/MediaScannerService( 670):	at android.os.Looper.loop(Looper.java)

E/MediaScannerService( 670):	at com.android.providers.media.MediaScannerService.run(MediaScannerService.java:185)

E/MediaScannerService( 670):	at java.lang.Thread.run(Thread.java:856)

When I select the media type i get the following exception.

E/AndroidRuntime( 1527): FATAL EXCEPTION: main

E/AndroidRuntime( 1527): java.lang.NullPointerException

E/AndroidRuntime( 1527):	at android.os.Parcel.readException(Parcel.java)

E/AndroidRuntime( 1527):	at android.os.Parcel.readException(Parcel.java)

E/AndroidRuntime( 1527):	at android.hardware.usb.IUsbManager$Stub$Proxy.setCurrentFunction(IUsbManager.java)

E/AndroidRuntime( 1527):	at android.hardware.usb.UsbManager.setCurrentFunction(UsbManager.java)

E/AndroidRuntime( 1527):	at com.android.settings.deviceinfo.MiuiUsbSettings.onPreferenceTreeClick(MiuiUsbSettings.java:109)

E/AndroidRuntime( 1527):	at android.preference.Preference.performClick(Preference.java)

E/AndroidRuntime( 1527):	at android.preference.CheckBoxPreference$1.onCheckedChanged(CheckBoxPreference.java)

E/AndroidRuntime( 1527):	at miui.widget.SlidingButton.doAnimation(SlidingButton.java)

E/AndroidRuntime( 1527):	at miui.widget.SlidingButton.access$100(SlidingButton.java)

E/AndroidRuntime( 1527):	at miui.widget.SlidingButton$SlidingHandler.handleMessage(SlidingButton.java)

E/AndroidRuntime( 1527):	at android.os.Handler.dispatchMessage(Handler.java)

E/AndroidRuntime( 1527):	at android.os.Looper.loop(Looper.java)

E/AndroidRuntime( 1527):	at android.app.ActivityThread.main(ActivityThread.java)

E/AndroidRuntime( 1527):	at java.lang.reflect.Method.invokeNative(Native Method)

E/AndroidRuntime( 1527):	at java.lang.reflect.Method.invoke(Method.java:511)

E/AndroidRuntime( 1527):	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java)

E/AndroidRuntime( 1527):	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java)

E/AndroidRuntime( 1527):	at dalvik.system.NativeStart.main(Native Method)

W/ActivityManager( 318): Force finishing activity com.android.settings/.UsbSettings