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
Contributor
Posts: 20
Registered: ‎03-01-2011
My Device: Not Specified

Possible bug on Hotspot API automatic login to open WiFi network

Hi all,

 

I have two BB mobile phones: BB Bold 9700 (OS 5.0 Bundle 1446) and BB Torch 9800 (OS 6.0 Bundle 1907).

 

My problem is as follows: I have an application that uses Hotspot API to choose correct open security network and then does login to it. Now the application works just fine on Bold, but on Torch I never get the system call HotspotAuthenticationAgent.login( ... ). Is there something I do wrong or is this bug on Torch / OS 6.0?

 

To make this problem more accessible to you I made a small application that demonstrates it. All the 5 source classes are included in the end of this post (you need signing capabilities to install it). The application is run as follows:

  1. Make open WiFi network and chande its SSID to "HSClient.java" file to static variable "SSID"

  2. Start 'HotspotTest" -application (or what ever you named it)

  3. Leave application to the background and go to setup

  4. Choose "WiFi connections"

  5. Allow the system to install new WiFi profile (HotspotTest)

  6. Go back to "HotspotTest" -application and choose "Login" from the menu

  7. Now if all goes as should the screen shows text "Login to: xxx"

 

Any help on solving this matter is much appreciated. I tend to believe that this is fault of the system because everything works just as the API promises in OS 5.0, but not in 6.0. Or is there a way to report possible bugs?

 

I am not sure if this should be here or in Java development (as I don't anymore believe that this is 'development' issue), but anyways, the contents of the 5 class required:

 

package HotspotTest;

import net.rim.device.api.ui.UiApplication;

 

class HSApp extends UiApplication {

   HSApp() {

      pushScreen( new HSScreen() );

   }

   

   // Application entry

   public static void main( String argv[] ) {

      HSApp app = new HSApp();

      app.enterEventDispatcher();

   }

}

 

 

package HotspotTest;

import net.rim.device.api.wlan.hotspot.*;

 

class HSAuthAgent extends HotspotAuthenticationAgent {

   private HSScreen _screen;

   private int _state;

 

   HSAuthAgent( HSScreen screen ) {

      this._screen = screen;

      this._state = HotspotAuthenticationAgent.STATE_LOGGED_OUT;

      _screen.printToScreen( "AuthAgent created" );

   }

 

   /* Implemented abstract methods */

   public void login( HotspotInfo hs ) {

      _screen.printToScreen( "Login to: " + hs.getStringProperty( HotspotInfo.PROPERTY_SSID ) );

      _state = HotspotAuthenticationAgent.STATE_LOGGING_IN;

 

      AuthenticationStatusEvent event = new AuthenticationStatusEvent(

            HotspotStatusListener.STATUS_SUCCESS_LOGGED_IN );

      notifyListeners( event );

   }

 

   public void logout( HotspotInfo hs ) {

      if( hs == null )

         _screen.printToScreen( "Manual logout" );

      else

         _screen.printToScreen( "Logout from: " + hs.getStringProperty( HotspotInfo.PROPERTY_SSID ) );

 

      this._state = HotspotAuthenticationAgent.STATE_LOGGED_OUT;

      AuthenticationStatusEvent event = new AuthenticationStatusEvent(

            HotspotStatusListener.STATUS_SUCCESS_LOGGED_OUT );

      notifyListeners( event );

   }

 

   public void cancelLogin( HotspotInfo hs ) {

      _screen.printToScreen( "Cancel logout from: " + hs.getStringProperty( HotspotInfo.PROPERTY_SSID ) );

      this._state = HotspotAuthenticationAgent.STATE_LOGGED_OUT;

   }

 

   public int getSessionState() {

      return _state;

   }

} 

 

 

package HotspotTest;

import net.rim.device.api.wlan.hotspot.*;

import net.rim.device.api.system.WLANInfo;

import net.rim.device.api.system.Radio;

import net.rim.device.api.system.RadioInfo;


class HSClient extends HotspotClient {

   private static String SSID = "ASDF"; // <- CHANGE THIS!

   private HSScreen _screen;

   private boolean _enabled;

 

   HSClient( HotspotCredentialsAgent creAgent,

               HotspotAuthenticationAgent authAgent, HSScreen screen ) {

      super( creAgent, authAgent, HotspotClient.NETWORK_TYPE_AUTOMATIC );

      this._enabled = false;

      this._screen = screen;

      _screen.printToScreen( "HSClient created" );

   }

 

   protected void enableOnce() {

      _enabled = true;

      _screen.printToScreen( "Flipping the radio" );

 

      // To make the system offer APs faster, we flip the radio

      Radio.deactivateWAFs( RadioInfo.WAF_WLAN );

      try {

         Thread.sleep(40);

      } catch (Exception e) {}

      Radio.activateWAFs(RadioInfo.WAF_WLAN);

   }

 

   /* Implementation of abstract methods */

   public String getClientName() { return "Hotspot Test"; }

 

   public HotspotInfo[] getSupportedNetworks( WLANInfo.WLANAPInfo[] networks ) {

      if( _enabled ) {

         _screen.printToScreen( "Client got offer" );

         HotspotInfo[] ret = null;

         for( int i = 0; i < networks.length; ++i ) {

            if( networks[i].getSSID().equals( SSID ) ) {

               _screen.printToScreen( "Correct SSID found" );

               _enabled = false;

               ret = new HotspotInfo[]{ new HotspotInfo( networks[i], true ) };

               return ret;

            }

         }

      }

      return null;

   }

}

 

 

package HotspotTest;

import net.rim.device.api.wlan.hotspot.*;


class HSCredAgent extends HotspotCredentialsAgent {

   private static int _controlPref =

         PREFERENCE_HIDDEN_PASSWORD | PREFERENCE_HIDDEN_USERNAME;

 

   HSCredAgent() { }

 

   /* Implementation of abstract methods */

   public String getPassword() throws HotspotException { return ""; }

   public String getUsername() throws HotspotException { return ""; }

   public void setPassword( String password ) { }

   public void setUsername( String username ) { }

   public int getCredentialsControlPreference() {

      return _controlPref;

   }

   public void setCredentialsControlPreference( int preference ) { }

}

 

 

package HotspotTest;

import net.rim.device.api.system.ApplicationDescriptor;

import net.rim.device.api.ui.MenuItem;

import net.rim.device.api.ui.component.RichTextField;

import net.rim.device.api.ui.container.MainScreen;

import net.rim.device.api.wlan.hotspot.HotspotClientRegistry;


class HSScreen extends MainScreen {

 

   HSScreen() {

      super();

      setTitle( "Hotspot Test App" );

 

      final HSAuthAgent authAgent = new HSAuthAgent( this );

      final HSClient client = new HSClient( new HSCredAgent(), authAgent, this );

      HotspotClientRegistry.add( client, ApplicationDescriptor.currentApplicationDescriptor() );

 

      addMenuItem( new MenuItem( "Login", 110, 10 ) {

            public void run() { client.enableOnce(); }

      } );

      addMenuItem( new MenuItem( "Logout", 110, 10 ) {

            public void run() { authAgent.logout( null ); }

      } );

   }

 

   protected void printToScreen( String text ) {

      add( new RichTextField( text ) );

   }

 

   public boolean onClose() {

      System.exit(0);

      return true;

   }

} 

Contributor
Posts: 20
Registered: ‎03-01-2011
My Device: Not Specified

Re: Possible bug on Hotspot API automatic login to open WiFi network

The quest continues...

 

I was able to find a small bug on the code I pasted. If there is following flag set up when the supported networks are returner:

ret[0].setFlag( HotspotInfo.AUTOMATIC_LOGIN_FLAG, true );

 

This makes the application to function just fine. Well, after a lot of research I found that the reason why my software does not work on Torch as should is that it starts during system bootup. As soon as I modified the code above to start at bootup the problem reappeared (this does not happen in Bold OS 5.0).

 

Also the WiFi setup now shows a prompt where system asks whether I want to login in to this WiFi... This gives a clue that for some reason the system sets my application to manual login mode if it runs on bootup. Any ideas anyone?

 

-Teemu

Contributor
Posts: 20
Registered: ‎03-01-2011
My Device: Not Specified

Re: Possible bug on Hotspot API automatic login to open WiFi network

Plot thickens...

 

It seems I was right; the problem is related to the system bootup. By inducing delay on the actual registry addition I got it working. So simple workaround would be:

 

Timer t = new Timer();       

t.schedule( new TimerTask() {           

   public void run() {

      HotspotClientRegistry.add( _client, ApplicationDescriptor.currentApplicationDescriptor() );

   }

}, 1000 * 10 );

 

This now says to me that there is something wrong with how the system handles addition to this registry during the bootup. I shall next continue on finding if global system events could shed some light to this bootup thing. So does anyone even know how to report bug for BB ?

 

-Teemu 

 

 

New Developer
Posts: 28
Registered: ‎11-04-2009
My Device: Not Specified

Re: Possible bug on Hotspot API automatic login to open WiFi network

Teemu,

I'm trying to do something similar.

 

The problem I have is that every time I do the Hotspot client registration,

HotspotClientRegistry.add( _client, ApplicationDescriptor.currentApplicationDescriptor() );

it overwrites the Wifi profile. And I have to run manually the wizard. 


Is it working like this for you also?

 

Tanks,

Esteban.

I tried to change the world, but I couldn't find the source code
Contributor
Posts: 20
Registered: ‎03-01-2011
My Device: Not Specified

Re: Possible bug on Hotspot API automatic login to open WiFi network

Hi Esteban,

 

It doesn't do that for me. I do the addition of the HotspotClient during the device bootup. So in my device it only requires that manual wizard once and every later bootup it just does it.

 

If you mean that you must do the login procedure always manually, then the problem might be that you must pass "HotspotClient.NETWORK_TYPE_AUTOMATIC" to the super class of your HotspotClient implementation...

 

Br,

Teemu

New Developer
Posts: 28
Registered: ‎11-04-2009
My Device: Not Specified

Re: Possible bug on Hotspot API automatic login to open WiFi network

Thanks Teemu,

I just want to retrieve the list of the available Wifi APs, and read some information, don't need to connect to HS.

 

I'm following the code you posted, is almost the same I did.

So, just for understand.

1) If you open HotspotTest for the first timeit does a HotspotClientRegistry.add( ... ) ,

2) It sends a notification to the OS, and you have to go out of the application, and follow the wizard on config \ wifi

3) When you finish wizard, the application receives getSupportedNetworks callback and you do the desired stuff.

....

4) Supose now you close the application, and then you open it again. It will do a HotspotClientRegistry.add( ... ) again. In this second time, this is without user interaction?  

 

 

Another question,

You hooking this piece of code:

Timer t = new Timer();       
t.schedule( new TimerTask() {           
   public void run() {
      HotspotClientRegistry.add( _client, ApplicationDescriptor.currentApplicationDescriptor() );
   }
}, 1000 * 10 );

 in an altern entry point at system startup, right? If so, I'm wondering if I could receive callbacks on the GUI entry if I register the altern entry point.

 

Thanks!

Esteban. 

I tried to change the world, but I couldn't find the source code
Contributor
Posts: 20
Registered: ‎03-01-2011
My Device: Not Specified

Re: Possible bug on Hotspot API automatic login to open WiFi network

Hi Esteban,

 

This that I say now might not be the factual case but is the best knowledge that I currently poses:

 

1) When you make that HotspotClientRegistry.add(..) for the first time with your application, then the system requires user to approve this action. In my knowledge all later runs on the same application work without that wizard. You can test this out quite easily.

2) Yes.

3) This is a bit more complicated. The system calls for getSupportedNetworks when ever it feels like it, but not if your client is not registered. If you want to force the system to call this function, you can turn WiFi radio off and then on again. This flip-flop causes the radio to do scan and report it to you (empiric observation).

4) This I have not tried out. I just know that when I remove the battery from the device and boot it up again, then the HotspotClientRegistry.add(..) happens without any interaction from the user and my application works just fine. 

 

I didn't understand what you were after with that latter part of your post...

 

-Teemu

New Developer
Posts: 28
Registered: ‎11-04-2009
My Device: Not Specified

Re: Possible bug on Hotspot API automatic login to open WiFi network

Teemu

 

3- Good idea the flip-flop trick Smiley Happy

4- Here is where i'm observing differences. I allways have to run the wizard manually. I'll try to upgrade my device's firmware. BTW, what JDE are you using to compile? I'm using 5.0.0. 


With the latter part, I mean:
First you posted the complete code for the HotspotTest, and then added some extra code with the Timer to resolve an issue. Where should this extra code go?

 

Thanks!

Esteban.

I tried to change the world, but I couldn't find the source code
Highlighted
Contributor
Posts: 20
Registered: ‎03-01-2011
My Device: Not Specified

Re: Possible bug on Hotspot API automatic login to open WiFi network

Hi,

 

Sorry for delayed answer but I left work and just came back Smiley Tongue

 

I am also using JDE 5.0.0 for development.

 

That Timer I placed to the constructor of my application. So when the application is started at bootup, it doesn't make the registry addition in that bootup thread. Instead, it leaves this TimerTask to wait until the bootup has been done and then does the registry addition in different thread.

 

- Teemu

S2
New Contributor
Posts: 8
Registered: ‎03-13-2012
My Device: Blackberry 9900
My Carrier: Airtel

Re: Possible bug on Hotspot API automatic login to open WiFi network

@stenhamm

Teemu hi, i am interested in your app, so your app will enable my bb bold to become a hotspot/modem router, where i can use/connect other pc devices to it - this is the same feature that the os 7.1 has, right?