Advertisement
anta40

TransportManager.java

Jul 7th, 2012
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.21 KB | None | 0 0
  1. // Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
  2. // Jad home page: http://www.kpdus.com/jad.html
  3. // Decompiler options: packimports(3)
  4. // Source File Name:   TransportManager.java
  5.  
  6. package arkalogic.net.service.rim;
  7.  
  8. import java.io.IOException;
  9. import javax.microedition.io.Connection;
  10. import javax.microedition.io.Connector;
  11. import net.rim.device.api.servicebook.ServiceBook;
  12. import net.rim.device.api.servicebook.ServiceRecord;
  13. import net.rim.device.api.system.*;
  14. import net.rim.device.api.ui.component.Dialog;
  15.  
  16. public class TransportManager
  17.     implements GlobalEventListener, CoverageStatusListener
  18. {
  19.  
  20.     private TransportManager()
  21.     {
  22.         setCoverage();
  23.     }
  24.  
  25.     public static TransportManager getInstance()
  26.     {
  27.         if(_manager == null)
  28.             _manager = new TransportManager();
  29.         return _manager;
  30.     }
  31.  
  32.     private boolean isWifi()
  33.     {
  34.         boolean wifi;
  35.         if(WLANInfo.getWLANState() == 4620)
  36.             wifi = true;
  37.         else
  38.             wifi = false;
  39.         return wifi;
  40.     }
  41.  
  42.     public Connection getConnection(String name, int mode, boolean timeouts)
  43.         throws IOException
  44.     {
  45.         if(DeviceInfo.isSimulator())
  46.             name = name.concat(";deviceside=true;ConnectionTimeout=20000");
  47.         else
  48.         if(isWifi())
  49.             name = name.concat(";deviceside=true;interface=wifi");
  50.         else
  51.         if(_mdsSupport)
  52.             name = name.concat(";deviceside=false");
  53.         else
  54.         if(_bisSupport)
  55.             name = name.concat(";deviceside=false;ConnectionType=mds-public;EndToEndRequired;ConnectionTimeout=45000");
  56.         else
  57.         if(!_wapSupport)
  58.             name = name.concat(";deviceside=true");
  59.         return Connector.open(name, mode, timeouts);
  60.     }
  61.  
  62.     public String getConnectionType()
  63.     {
  64.         if(_mdsSupport)
  65.             return "MDS";
  66.         if(_bisSupport)
  67.             return "BIS-B";
  68.         if(_wapSupport)
  69.             return "WAP";
  70.         else
  71.             return "Direct TCP";
  72.     }
  73.  
  74.     private void setCoverage()
  75.     {
  76.         if(CoverageInfo.isCoverageSufficient(2))
  77.             _mdsSupport = true;
  78.         if(CoverageInfo.isCoverageSufficient(4))
  79.             _bisSupport = true;
  80.     }
  81.  
  82.     public void coverageStatusChanged(int newCoverage)
  83.     {
  84.         if((newCoverage & 2) == 2)
  85.             _mdsSupport = true;
  86.         if((newCoverage & 4) == 4)
  87.             _bisSupport = true;
  88.     }
  89.  
  90.     private void parseServiceBooks()
  91.     {
  92.         ServiceBook sb = ServiceBook.getSB();
  93.         ServiceRecord records[] = sb.findRecordsByCid(IPPP);
  94.         if(records == null)
  95.             return;
  96.         int numRecords = records.length;
  97.         for(int i = 0; i < numRecords; i++)
  98.         {
  99.             ServiceRecord myRecord = records[i];
  100.             String name = myRecord.getName();
  101.             String uid = myRecord.getUid();
  102.             if(!myRecord.isValid() || myRecord.isDisabled())
  103.                 continue;
  104.             int encryptionMode = myRecord.getEncryptionMode();
  105.             if(encryptionMode == 2)
  106.                 _mdsSupport = true;
  107.             else
  108.                 _bisSupport = true;
  109.         }
  110.  
  111.     }
  112.  
  113.     public void eventOccurred(long guid, int data0, int data1, Object object0, Object object1)
  114.     {
  115.         if(guid == 0xc56f572fa6bb41faL || guid == 0x73071ed24deea8fdL || guid == 0xb70eaf0364976928L || guid == 0x563b18cc6bc68309L || guid == 0x230322fc7183d35eL)
  116.         {
  117.             Dialog.inform("Service Book Global Event Received");
  118.             parseServiceBooks();
  119.         }
  120.     }
  121.  
  122.     private static ServiceRecord getBIBSRecord()
  123.     {
  124.         ServiceRecord ippps[] = ServiceBook.getSB().getRecords();
  125.         for(int i = 0; i < ippps.length; i++)
  126.             if(ippps[i].getCid().equals("IPPP") && ippps[i].getName().indexOf("BIBS") >= 0)
  127.                 return ippps[i];
  128.  
  129.         return null;
  130.     }
  131.  
  132.     private static final long ID = 0x1431cf6271d3b1edL;
  133.     private static String IPPP = "IPPP";
  134.     private static TransportManager _manager;
  135.     private boolean _isSimulator;
  136.     private boolean _mdsSupport;
  137.     private boolean _bisSupport;
  138.     private boolean _wapSupport;
  139.     private boolean _wifiSupport;
  140.  
  141. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement