Created
May 30, 2015 03:24
-
-
Save anta40/2a8d6d8c79e4fa1530cf to your computer and use it in GitHub Desktop.
Transport manager
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.semymegis.apps.pingmishop.net; | |
import java.io.IOException; | |
import java.rmi.ServerException; | |
import javax.microedition.io.Connection; | |
import javax.microedition.io.Connector; | |
import net.rim.device.api.servicebook.ServiceBook; | |
import net.rim.device.api.servicebook.ServiceRecord; | |
import net.rim.device.api.system.CoverageInfo; | |
import net.rim.device.api.system.CoverageStatusListener; | |
import net.rim.device.api.system.DeviceInfo; | |
import net.rim.device.api.system.GlobalEventListener; | |
import net.rim.device.api.system.RadioInfo; | |
import net.rim.device.api.system.WLANInfo; | |
import net.rim.device.api.ui.component.Dialog; | |
public class TransportManager implements CoverageStatusListener, GlobalEventListener { | |
private TransportManager() | |
{ | |
setCoverage(); | |
} | |
public static TransportManager getInstance() | |
{ | |
if(_manager == null) | |
_manager = new TransportManager(); | |
return _manager; | |
} | |
private boolean isWifi() | |
{ | |
boolean wifi; | |
if(WLANInfo.getWLANState() == WLANInfo.WLAN_STATE_CONNECTED) | |
wifi = true; | |
else | |
wifi = false; | |
return wifi; | |
} | |
public Connection getConnection(String name, int mode, boolean timeouts) | |
throws IOException | |
{ | |
if(DeviceInfo.isSimulator()){ | |
System.out.println("TransportManager: simulator"); | |
name = name.concat(";deviceside=true;ConnectionTimeout=20000"); | |
} | |
else if(isWifi()){ | |
System.out.println("TransportManager: WiFi"); | |
name = name.concat(";interface=wifi"); | |
} | |
else if(_mdsSupport){ | |
System.out.println("TransportManager: MDS"); | |
name = name.concat(";deviceside=false"); | |
} | |
else if(_bisSupport){ | |
System.out.println("TransportManager: BIS"); | |
name = name.concat(";deviceside=false;ConnectionType=mds-public;EndToEndRequired;ConnectionTimeout=45000"); | |
} | |
else if(!_wapSupport){ | |
System.out.println("TransportManager: WAP"); | |
name = name.concat(";deviceside=true"); | |
} | |
return Connector.open(name, mode, timeouts); | |
} | |
// public String getConnectionType() | |
// { | |
// if(_mdsSupport) | |
// return "MDS"; | |
// if(_bisSupport) | |
// return "BIS-B"; | |
// if(_wapSupport) | |
// return "WAP"; | |
// else | |
// return "Direct TCP"; | |
// } | |
private void setCoverage() | |
{ | |
if(CoverageInfo.isCoverageSufficient(2)) | |
_mdsSupport = true; | |
if(CoverageInfo.isCoverageSufficient(4)) | |
_bisSupport = true; | |
} | |
public void coverageStatusChanged(int newCoverage) | |
{ | |
if((newCoverage & 2) == 2) | |
_mdsSupport = true; | |
if((newCoverage & 4) == 4) | |
_bisSupport = true; | |
} | |
private void parseServiceBooks() | |
{ | |
ServiceBook sb = ServiceBook.getSB(); | |
ServiceRecord records[] = sb.findRecordsByCid(IPPP); | |
if(records == null) | |
return; | |
int numRecords = records.length; | |
for(int i = 0; i < numRecords; i++) | |
{ | |
ServiceRecord myRecord = records[i]; | |
String name = myRecord.getName(); | |
String uid = myRecord.getUid(); | |
if(!myRecord.isValid() || myRecord.isDisabled()) | |
continue; | |
int encryptionMode = myRecord.getEncryptionMode(); | |
if(encryptionMode == 2) | |
_mdsSupport = true; | |
else | |
_bisSupport = true; | |
} | |
} | |
public void eventOccurred(long guid, int data0, int data1, Object object0, Object object1) | |
{ | |
if(guid == 0xc56f572fa6bb41faL || guid == 0x73071ed24deea8fdL || guid == 0xb70eaf0364976928L || guid == 0x563b18cc6bc68309L || guid == 0x230322fc7183d35eL) | |
{ | |
Dialog.inform("Service Book Global Event Received"); | |
parseServiceBooks(); | |
} | |
} | |
private static ServiceRecord getBIBSRecord() | |
{ | |
ServiceRecord ippps[] = ServiceBook.getSB().getRecords(); | |
for(int i = 0; i < ippps.length; i++) | |
if(ippps[i].getCid().equals("IPPP") && ippps[i].getName().indexOf("BIBS") >= 0) | |
return ippps[i]; | |
return null; | |
} | |
private static final long ID = 0x1431cf6271d3b1edL; | |
private static String IPPP = "IPPP"; | |
private static TransportManager _manager; | |
private boolean _isSimulator; | |
private boolean _mdsSupport; | |
private boolean _bisSupport; | |
private boolean _wapSupport; | |
private boolean _wifiSupport; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment