Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
acowart
Posts: 163
Registered: ‎07-16-2008
My Device: Not Specified
My Carrier: Sprint

How to determine whether Mass Storage Mode is enabled?

I have an application that writes to the SD card, and would like to message the user if Mass Storage Mode is enabled to let them know that they'll need to unplug their device from the computer.

 

I thought the right way would be to check USBPort.getConnectionState(), but that always returns the value "19", whether the device is in mass storage mode or just connected for charging with mass storage mode disabled.

 

What's the right way to detect mass storage mode?

 

Thanks

Andrew Cowart | Metova
www.metova.com
Please use plain text.
Administrator (Retired)
mkirkup
Posts: 179
Registered: ‎07-14-2008
My Device: Not Specified

Re: How to determine whether Mass Storage Mode is enabled?

Andrew,

 

If the device is currently operating in Mass Storage Mode you should be able to detect this using the FileConnection by determining that the SD card is simply no longer available.

 

 

Mike Kirkup
Director, Developer Relations
Please use plain text.
Developer
acowart
Posts: 163
Registered: ‎07-16-2008
My Device: Not Specified
My Carrier: Sprint

Re: How to determine whether Mass Storage Mode is enabled?

Mike,

 

Thank you for the idea.  Since originally posting I have switched to using the following logic -

*  If SDCard root is available, the app can use the SD card.

*  If SDCard root is not available and the device is connected via USB, the user may or may not have an SD card.  Message the user to disconnect the USB cable or turn mass storage off.

*  If SDCard root is not available and not connected via USB, no SD card is inserted.

 

Is there a way to check the middle case better - To determine whether a user has an SD card, but it is unavailable due to mass storage mode being enabled?

 

Thanks,

Andrew Cowart | Metova
www.metova.com
Please use plain text.
Administrator
MSohm
Posts: 14,241
Registered: ‎07-09-2008
My Device: BlackBerry Z30, BlackBerry PlayBook
My Carrier: Bell

Re: How to determine whether Mass Storage Mode is enabled?

You can bitwise-and the integer returned from USBPort.getConnectionState() with both the USB_STATE_ENUMERATED and USB_STATE_MS_INTERFACE_ENUMERATED constants defined in SystemListener2.  If both expressions evaluate to non-zero then the BlackBerry is connected to a PC and has been enumerated as a mass-storage device.
Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Please use plain text.
Developer
acowart
Posts: 163
Registered: ‎07-16-2008
My Device: Not Specified
My Carrier: Sprint

Re: How to determine whether Mass Storage Mode is enabled?

Mark,

 

Thank you for your reply.  I have tried this, but USBPort.getConnectionState() always seems to be returning the integer 19 when the device is plugged in via USB, whether mass storage mode is enabled or disabled.  Even when I change "Mass Storage Mode Support" to off, the flag "USB_STATE_MS_INTERFACE_ENUMERATED" still gets set.

 

I am seeing this behavior on a Sprint 8330 Curve with OS 4.5.0.97 and a T-Mobile 8320 Curve with OS 4.5.0.81.

Andrew Cowart | Metova
www.metova.com
Please use plain text.
Administrator
MSohm
Posts: 14,241
Registered: ‎07-09-2008
My Device: BlackBerry Z30, BlackBerry PlayBook
My Carrier: Bell

Re: How to determine whether Mass Storage Mode is enabled?

You are correct.  This does return true when USB mass storage mode is enumerated/available but not turned on (user says No to the enable MS mode or escapee on the password entry box).  The media card is available to the application in this scenario.  I think you've found the best approach using what you describe in the thread above.

Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Please use plain text.
Developer
myraddin
Posts: 405
Registered: ‎09-12-2008
My Device: 9000 9810

Re: How to determine whether Mass Storage Mode is enabled?

Hi.

So is there a way to know whether Mass storage is turned on or off ?

I am using Bold (4.6) and I always get a 19 (USBPort.getConnectionState()).
My background app needs to write trace information to the file (storage, not the SDcard).
So when the USB is plugged in, the app must be stopped.

Are current file connections destroyed when the user plugs in the USB in MS mode ?


"Listen carefully, I shall say this only once"
Please use plain text.
Developer
myraddin
Posts: 405
Registered: ‎09-12-2008
My Device: 9000 9810

Re: How to determine whether Mass Storage Mode is enabled?

Strange indeed. This is what my Bold outputted:

 

SystemListener2.USB_STATE_CABLE_CONNECTED 1
SystemListener2.USB_STATE_ENUMERATED 2
SystemListener2.USB_STATE_CABLE_DISCONNECTED 4
SystemListener2.USB_STATE_NOT_ENUMERATED 8
SystemListener2.USB_STATE_MS_INTERFACE_ENUMERATED 16

 

And (as previousely posted) when the USB is plugged in, I allway get  USBPort.getConnectionState() = 19 (whether the MS is ON/OFF). 

 

This looks like a bug to me...

Any comments ?


 

 



"Listen carefully, I shall say this only once"
Please use plain text.
Developer
myraddin
Posts: 405
Registered: ‎09-12-2008
My Device: 9000 9810

Re: How to determine whether Mass Storage Mode is enabled?

Still nothing ;(

 

But there's a workaround to use until we get an 'offical' response to this question.

 

I discovered that when Mass storage is turned off you do get the famous 19 (which is wrong, we should probably get a 3) but you will have access to the storage so I made a simple test that proved to be working on Bold (v4.6)

 

 

FileConnection file = (FileConnection)Connector.open("file:///store/home/user/", Connector.READ); if (file.canRead()) { // we have file access result = true; }

 

... // tidy up and return

 

 

Another note: I thought maybe the developers give us the permission to read while the files are locked by mass storage. But unfortunately, this was not the case.

 

That's why this simple test is enough to check whether we have file access or not.

 

 



"Listen carefully, I shall say this only once"
Please use plain text.
Developer
Kenjkelly01
Posts: 64
Registered: ‎01-12-2009
My Device: Blackberry Storm, Curve, Tour
My Carrier: Verizon

Re: How to determine whether Mass Storage Mode is enabled?

 

 

To further complicate this, on the Tour, Mass Storage only affects the SDCard, so I can and should use the store ONLY IF the SDcard is not really installed, regardless of MS. 

 

For a good design, I should only prompt the user if I know there is an SDCard and MS is active.  I need that information.

 

 

1) Since the USB bits won't tell if MS is enabled for real, is there a way to determine what the user selected in Options regarding Mass Storage?

 

B) Has anyone determined a way to detect if the SDCard is present in the socket, even when it isn't mounted? Is there a hardware bit available?  Is there a secret API for getting that low level info?

 

 

Ken J Kelly
Please use plain text.