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
richard_puckett
Posts: 191
Registered: ‎04-03-2008
My Device: Bold 9700

Check if Wifi is available

I'm trying to check if Wifi is available on my device before attempting to use it.  It's an 8120/4.3.0.115 with no SIM, but I'd like it to work back to 4.2.0, so no Radio class and no WAFs.  Both Wifi browsing and http over Wifi (with "interface=wifi" extension) work, but my test for Wifi is failing...

 

ServiceBook serviceBook; ServiceRecord serviceRecords[]; serviceBook = ServiceBook.getSB(); serviceRecords = serviceBook.findRecordsByCid("WPTCP"); for (int i = 0; i < serviceRecords.length; i++) { ServiceRecord serviceRecord = serviceRecords[i]; if (!serviceRecord.isValid() || serviceRecord.isDisabled()) { // The one SB entry bails here. continue; } ... }

 

The service book for Wifi Transport is:

Name: Wi-Fi TCP/IP Transport

UID: S TCP-WiFi

CID: WPTCP

 

TIA.

Please use plain text.
Administrator
MSohm
Posts: 14,410
Registered: ‎07-09-2008
My Device: BlackBerry Z30, BlackBerry PlayBook
My Carrier: Bell

Re: Check if Wifi is available

Can you clarify what is failing?  Is the service book not present on the device?  Or is it present and not being returned by findRecordsByCid, or is the record returned invalid or disabled?
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
richard_puckett
Posts: 191
Registered: ‎04-03-2008
My Device: Bold 9700

Re: Check if Wifi is available

[ Edited ]

The service book is present on the device and the CID is being looked up correctly, but it's being flagged as disabled (isValid returns true).

 

Edit: I like the Javadocs for isDisabled().  :smileyhappy:

 

Returns:

    True if this record has no routing information; otherwise, true.

Message Edited by richard_puckett on 07-24-2008 10:27 AM
Message Edited by richard_puckett on 07-24-2008 10:28 AM
Please use plain text.
Administrator
MSohm
Posts: 14,410
Registered: ‎07-09-2008
My Device: BlackBerry Z30, BlackBerry PlayBook
My Carrier: Bell

Re: Check if Wifi is available

That's a definite problem with the JavaDocs.  :smileyhappy: What BlackBerry model and handheld software version are you testing on?  Is the mobile network radio turned on?
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
richard_puckett
Posts: 191
Registered: ‎04-03-2008
My Device: Bold 9700

Re: Check if Wifi is available

It was provided in the original post.  I know what info you like to have.  :smileyhappy:

 

"It's an 8120/4.3.0.115 with no SIM."  The radio is turned on.  The built-in browser works and programmatic HTTP connections work as well if I provide "interface=wifi".

 

To give a little background, this is for my networking class.  What it does is use the chain of responsibility pattern (ported it from Jakarta Commons to BlackBerry) to find a connection method that "works" by trying a list possible connection methods: BES, BIS, WAP2, WAP1, DirectTCP, Wifi (the order is configurable).  Each method is a link in the chain and determining what "works" is done generally by querying the service books, etc. 

 

I'm testing the Wifi link right now but, based on the service books, Wifi should not be deemed as "working" even though it does in fact work.  Maybe the obvious answer is to take out the check for isDisabled(), but isDisabled() should be returning false here anyway, no?  isValid() returns true, so that one's good.  Is isDisabled() basing its decision on the presence of a SIM or something?  Maybe I don't understand what isDisabled() really means?  TIA!

Please use plain text.
Administrator
MSohm
Posts: 14,410
Registered: ‎07-09-2008
My Device: BlackBerry Z30, BlackBerry PlayBook
My Carrier: Bell

Re: Check if Wifi is available

We are aware of an issue where isDisabled can return true for the Wi-Fi service book if the mobile radio is off, even though the Wi-Fi radio is enabled.  So when you are testing, are both the mobile network radio and Wi-Fi radios turned on?  Or is only the Wi-Fi radio enabled?
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
peter_strange
Posts: 19,601
Registered: ‎07-14-2008
My Device: Not Specified

Re: Check if Wifi is available

Sorry don't have an answer, but can say I have also found this confusing in my testing (8820, with 4.2.1 (I think, don't have it with me at present) and 8320, 4.2.2.156).  In my 'connection class', I now assume that the presence of the appropriate service book is good enough to assume that I can try WiFi.  In my experience, to get both isValid() and !isDisabled(), the device must have a Sim in it and have established a wireless connection to its associated BES - then it seems to try to connect to the BES via WiFi and if that it successful, will be isValid() and !isDisabled().  I work in a mainly BES environment, so I can't comment on how these might be set in a BIS setup.

 

Not sure this helps.

 

I do have a problem with the 'connection class' and that is the so-called split-pipe problem.  The proof of the pudding with a 'connection class' is making an actual connection.  If you try a connection, say via BES, then try a connection via an external mechanism, say Direct TCP, then I believe one would get a spilt-pipe problem - basically the BB would reject the connection because the same application was attempting to connect both inside and outside the firewall.  I guess the theory was that the application could pick data off the intranet and feed it to the extra-net (or vice-versa).  But, unless you got into changing policy settings, once the app was in this state, it was time to re-install your BlackBerry OS if you wanted the application to work again.  So if your application uses a 'connection class', which gets it wrong (because the Service books have or have not been updated on the device for some reason), you might be dead in the water.....

 

Have you seen this problem.  Or is this problem just my imagination?

Please use plain text.
Developer
richard_puckett
Posts: 191
Registered: ‎04-03-2008
My Device: Bold 9700

Re: Check if Wifi is available

Ok, I think the issue I'm describing is the same one you're aware of.  The mobile network is indeed displayed as OFF (even when I enable it via Manage Connections).  So I think the lack of a SIM is causing the mobile network to be off (totally reasonable) which is causing the Wifi service record to say it's disabled.  That's good enough, then.  I'll just add in a little extra check to try and get around that condition.  Might introduce some false positives, but that's not horrible.  Thanks!
Please use plain text.
Developer
peter_strange
Posts: 19,601
Registered: ‎07-14-2008
My Device: Not Specified

Re: Check if Wifi is available

Glad you could understood what I was trying to say!

 

I'd be concerned that the false postitives might lead you into the split-pipe problem, hence my bringing it up.  This used to be a serious problem (pre OS 4.1), but I'm not sure it is now and I don't know if it effects WiFi connections anyway.  I was hoping for some comment from Rim, but probably not at this time on a Friday........

 

BTW I use WiFi, without a Sim, for most of my on device testing.  It is fast and free!

Please use plain text.
Developer
richard_puckett
Posts: 191
Registered: ‎04-03-2008
My Device: Bold 9700

Re: Check if Wifi is available

I don't know, I get emails from RIM people at all hours of day and night - they're pretty hardcore.  :smileyhappy:

 

As far as the split-pipe issue: When I cycle through connection methods I don't actually make any connections at that stage; I'm only scanning through service books and trying to ascertain which method would be a good candidate (pasting my command for BES below as FYI).  The ConnectionExtensionRegistry is a registry of, um, connection extensions that get read in from an XML file and subsequently appended to URLs.  If I'm then able to make a successful connection then I persist the connection's ID and give it priority the next time the app starts and needs to locate a connection method.  If the connection fails I then go back and try to find another conenction method candidate.  At *this* point I can see a split-pipe coming into play...  Hm.

 

  Here's an example connection and its associated XML entry:

 

public boolean execute(Context context) throws Exception { if ((CoverageInfo.getCoverageStatus() & CoverageInfo.COVERAGE_MDS) == 0) { return CONTINUE_PROCESSING; } ServiceBook serviceBook; ServiceRecord serviceRecords[]; serviceBook = ServiceBook.getSB(); serviceRecords = serviceBook.findRecordsByCid("IPPP"); for (int i = 0; i < serviceRecords.length; i++) { ServiceRecord serviceRecord = serviceRecords[i]; if (!serviceRecord.isValid() || serviceRecord.isDisabled()) { continue; } int encryptionMode = serviceRecord.getEncryptionMode(); if (encryptionMode == ServiceRecord.ENCRYPT_RIM) { Enumeration connectionExtensions = ConnectionExtensionRegistry.instance.getByType("BES"); ConnectionExtension connectionExtension = (ConnectionExtension) connectionExtensions.nextElement(); String extensionString = connectionExtension.toString(); context.put(URL_EXTENSION, extensionString); return PROCESSING_COMPLETE; } } return CONTINUE_PROCESSING; }

 

 

<connections> <connection id="1" type="BES"> <params> <param name="DeviceSide" value="false" /> </params> </connection> ... </connections>

 

Please use plain text.