eilib

16:35:32.404 INFO  jd.cli.Main - Decompiling eilib.jar
package org.tizen.eilib.connection;

import org.tizen.sdblib.receiver.MultiLineReceiver;

class ConnectionToEmulator$1
  extends MultiLineReceiver
{
  ConnectionToEmulator$1(ConnectionToEmulator paramConnectionToEmulator) {}
  
  public void processNewLines(String[] lines)
  {
    ConnectionToEmulator.access$002(this$0, lines[0]);
  }
}

/* Location:
 * Qualified Name:     org.tizen.eilib.connection.ConnectionToEmulator.1
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.tizen.eilib.connection;

import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.logging.Logger;
import org.tizen.eilib.connection.message.EventMessage;
import org.tizen.eilib.connection.message.EventType;
import org.tizen.eilib.events.EventInjectorCreator;
import org.tizen.eilib.events.receiver.AbstractEventReceiver;
import org.tizen.eilib.events.receiver.StatusEventReceiver;
import org.tizen.eilib.exception.ConnectionException;
import org.tizen.eilib.exception.EILibError;
import org.tizen.eilib.exception.InjectorLibraryException;
import org.tizen.eilib.tools.EILogger;
import org.tizen.sdblib.IDevice;
import org.tizen.sdblib.exception.SdbCommandRejectedException;
import org.tizen.sdblib.exception.ShellCommandUnresponsiveException;
import org.tizen.sdblib.exception.TimeoutException;
import org.tizen.sdblib.receiver.MultiLineReceiver;

public class ConnectionToEmulator
{
  private EventSocket socket = null;
  private HashMap<Integer, AbstractEventReceiver> receiverMap;
  private EmulatorList emList;
  private Emulator currentEmulator = null;
  private static String EMULD_VERSION = "0.2.23";
  private static final String shellCmd = "rpm -q emuld";
  
  public ConnectionToEmulator()
  {
    receiverMap = new HashMap();
    addEventReceiver(15, new StatusEventReceiver());
    
    socket = new EventSocket(receiverMap);
    
    emList = EmulatorList.getInstance();
  }
  
  public void addEventReceiver(int gID, AbstractEventReceiver receiver)
  {
    receiverMap.put(Integer.valueOf(gID), receiver);
  }
  
  public void removeEventReceiver(int gID)
  {
    receiverMap.remove(Integer.valueOf(gID));
  }
  
  public AbstractEventReceiver findEventReceiver(int gID)
  {
    return (AbstractEventReceiver)receiverMap.get(Integer.valueOf(gID));
  }
  
  public void setIPAdderss(String ip)
  {
    socket.setIP(ip);
  }
  
  public void setPort(int port)
  {
    socket.setPort(port);
  }
  
  public boolean connect()
    throws IOException, InjectorLibraryException
  {
    return connect(0);
  }
  
  public boolean connect(int port)
    throws IOException, InjectorLibraryException
  {
    if (socket.isConnected()) {
      socket.disconnect();
    }
    boolean result = false;
    if (port == 0)
    {
      if (socket.getPort() == 0)
      {
        ArrayList<Emulator> list = emList.getEmulatorList();
        if (list.size() == 0) {
          throw new InjectorLibraryException(EILibError.EmulatorNotExist);
        }
        if (list.size() > 1) {
          throw new InjectorLibraryException(EILibError.EmulatorNotOne);
        }
        socket.setPort(((Emulator)list.get(0)).getPort());
      }
      result = socket.connect();
    }
    else
    {
      result = socket.connect(port);
    }
    if (result)
    {
      int socketPort = socket.getPort();
      ArrayList<Emulator> emulators = emList.getEmulatorList();
      for (Emulator e : emulators) {
        if (e.getPort() == socketPort) {
          currentEmulator = e;
        }
      }
      if (currentEmulator != null) {
        checkEmuldVersion();
      }
    }
    if (creator != null) {
      creator.intializeConnectToEmulator();
    }
    return result;
  }
  
  private String shellResult = null;
  
  private void checkEmuldVersion()
    throws InjectorLibraryException
  {
    shellResult = null;
    String errorMessage = null;
    try
    {
      currentEmulator.getDevice().executeShellCommand("rpm -q emuld", new MultiLineReceiver()
      {
        public void processNewLines(String[] lines)
        {
          shellResult = lines[0];
        }
      });
    }
    catch (TimeoutException e)
    {
      errorMessage = e.getMessage();
    }
    catch (SdbCommandRejectedException e)
    {
      errorMessage = e.getMessage();
    }
    catch (ShellCommandUnresponsiveException e)
    {
      errorMessage = e.getMessage();
    }
    catch (IOException e)
    {
      errorMessage = e.getMessage();
    }
    if ((errorMessage == null) && (shellResult != null))
    {
      String[] vals = shellResult.split("-");
      if (vals.length == 3)
      {
        String version = vals[1];
        if (version.compareTo(EMULD_VERSION) < 0) {
          throw new InjectorLibraryException(EILibError.EmuldVersionOld);
        }
      }
      else
      {
        EILogger.getLogger().warning("Emuld does not installed normal path.");
      }
    }
    else
    {
      EILogger.getLogger().warning(errorMessage);
    }
  }
  
  public String getEmuldVersion()
  {
    return EMULD_VERSION;
  }
  
  public boolean disconnect()
  {
    return socket.disconnect();
  }
  
  public boolean isConnect()
  {
    return socket.isConnected();
  }
  
  public void terminate()
  {
    if (socket.isConnected()) {
      socket.disconnect();
    }
  }
  
  private EventInjectorCreator creator = null;
  
  public void setEventInjectorCreator(EventInjectorCreator creator)
  {
    this.creator = creator;
  }
  
  public boolean sendMessage(EventMessage message)
    throws IOException, ConnectionException
  {
    return socket.sendMessage(message);
  }
  
  private EventMessage initMessage = null;
  private byte[] initMsgHeader1 = { 4, 0, 64, 65 };
  private byte[] initMsgData1 = { 22, 0, 0, 0 };
  private byte[] initMsgHeader2 = { 0, 0, 64, 71 };
  private byte[] initMsgData2 = { 0, 0, 64, 66 };
  private byte[] initAskData = { 0, 0, 17, 91 };
  
  public void sendInitializeMessage()
    throws IOException, ConnectionException
  {
    if (!socket.isConnected())
    {
      EILogger.getLogger().warning("Socket is disconnected..");
      return;
    }
    if (initMessage == null)
    {
      initMessage = new EventMessage(128);
      initMessage.setEventTypeBuffer(EventType.TELEPHONY);
    }
    initMessage.clear();
    initMessage.getHeaderBuffer().put(initAskData);
    sendMessage(initMessage);
  }
  
  public void sendModemInitialize()
    throws IOException, ConnectionException
  {
    if (!socket.isConnected()) {
      EILogger.getLogger().warning("Socket is disconnected..");
    }
    if (initMessage == null)
    {
      initMessage = new EventMessage(128);
      initMessage.setEventTypeBuffer(EventType.TELEPHONY);
    }
    initMessage.clear();
    initMessage.getHeaderBuffer().put(initMsgHeader1);
    initMessage.getDataBuffer().put(initMsgData1);
    sendMessage(initMessage);
    
    initMessage.clear();
    initMessage.getHeaderBuffer().put(initMsgHeader2);
    initMessage.getDataBuffer().put(initMsgData2);
    sendMessage(initMessage);
  }
  
  public ArrayList<Emulator> getEmulatorList()
  {
    return emList.getEmulatorList();
  }
  
  public Emulator getCurrentEmulator()
  {
    if (!isConnect()) {
      return null;
    }
    if (emList == null) {
      return null;
    }
    return currentEmulator;
  }
  
  public void addDeviceChangeListener(IEmulatorChangeListener listener)
  {
    emList.setChangeListener(listener);
  }
}

/* Location:
 * Qualified Name:     org.tizen.eilib.connection.ConnectionToEmulator
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.tizen.eilib.connection;

import java.io.IOException;
import org.tizen.sdblib.DeviceState;
import org.tizen.sdblib.IDevice;
import org.tizen.sdblib.IShellOutputReceiver;
import org.tizen.sdblib.exception.SdbCommandRejectedException;
import org.tizen.sdblib.exception.ShellCommandUnresponsiveException;
import org.tizen.sdblib.exception.TimeoutException;
import org.tizen.sdblib.receiver.NullOutputReceiver;
import org.tizen.sdblib.service.SyncService;
import org.tizen.sdblib.util.DeviceUtil;
import org.tizen.sdblib.util.SdbShellProcess;

public class Emulator
{
  private static final int INSTALL_TIMEOUT = 120000;
  private IDevice device;
  private int port;
  private boolean isMounted;
  private String SDCardName;
  
  public Emulator(IDevice device)
  {
    this.device = device;
    setPort(Integer.parseInt(device.getSerialNumber().substring(9)) + 2);
    isMounted = false;
    SDCardName = "";
  }
  
  public String toString()
  {
    return device.getDeviceName() + " " + device.getSerialNumber() + " " + Integer.toString(port);
  }
  
  public boolean equals(Object obj)
  {
    if (!(obj instanceof Emulator)) {
      return false;
    }
    if (((Emulator)obj).getDeviceName().equals(getDeviceName())) {
      return true;
    }
    return false;
  }
  
  public IDevice getDevice()
  {
    return device;
  }
  
  public void setDevice(IDevice device)
  {
    this.device = device;
    setPort(Integer.parseInt(device.getSerialNumber().substring(9)) + 2);
  }
  
  public int getPort()
  {
    return port;
  }
  
  public void setPort(int port)
  {
    this.port = port;
  }
  
  public boolean isMounted()
  {
    return isMounted;
  }
  
  public void setMounted(boolean isMounted)
  {
    this.isMounted = isMounted;
  }
  
  public String getSDCardName()
  {
    return SDCardName;
  }
  
  public void setSDCardName(String SDCardName)
  {
    this.SDCardName = SDCardName;
  }
  
  public String getSerialNumber()
  {
    return device.getSerialNumber();
  }
  
  public String getDeviceName()
  {
    return device.getDeviceName();
  }
  
  public DeviceState getState()
  {
    return device.getState();
  }
  
  public boolean isOnline()
  {
    return DeviceUtil.isOnline(device);
  }
  
  public boolean isEmulator()
  {
    return device.isEmulator();
  }
  
  public boolean isOffline()
  {
    return !DeviceUtil.isOnline(device);
  }
  
  public SyncService getSyncService()
    throws TimeoutException, SdbCommandRejectedException, IOException
  {
    return device.getSyncService();
  }
  
  public SdbShellProcess executeShellCommand(String command)
    throws IOException
  {
    return device.executeShellCommand(command);
  }
  
  public void executeShellCommand(String command, IShellOutputReceiver receiver)
    throws TimeoutException, SdbCommandRejectedException, ShellCommandUnresponsiveException, IOException
  {
    device.executeShellCommand(command, receiver);
  }
  
  public void executeShellCommand(String command, IShellOutputReceiver receiver, int maxTimeToOutputResponse)
    throws TimeoutException, SdbCommandRejectedException, ShellCommandUnresponsiveException, IOException
  {
    device.executeShellCommand(command, receiver, maxTimeToOutputResponse);
  }
  
  public void createForward(int localPort, int remotePort)
    throws TimeoutException, SdbCommandRejectedException, IOException
  {
    device.createForward(localPort, remotePort);
  }
  
  public void removeForward(int localPort, int remotePort)
    throws TimeoutException, SdbCommandRejectedException, IOException
  {
    device.removeForward(localPort, remotePort);
  }
  
  public String syncPackageToDevice(String localFilePath)
    throws TimeoutException, SdbCommandRejectedException, IOException
  {
    return DeviceUtil.uploadPackage(localFilePath, device);
  }
  
  public void removeRemotePackage(String remoteFilePath)
    throws TimeoutException, SdbCommandRejectedException, ShellCommandUnresponsiveException, IOException
  {
    device.executeShellCommand("rm " + remoteFilePath, NullOutputReceiver.getInstance(), 120000);
  }
}

/* Location:
 * Qualified Name:     org.tizen.eilib.connection.Emulator
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.tizen.eilib.connection;

import java.util.ArrayList;
import org.tizen.sdblib.IDevice;
import org.tizen.sdblib.IDeviceChangeListener;
import org.tizen.sdblib.SmartDevelopmentBridge;
import org.tizen.sdblib.util.DeviceUtil;

public class EmulatorList
  implements IDeviceChangeListener
{
  private static EmulatorList instance = null;
  private final ArrayList<Emulator> emulatorList = new ArrayList();
  
  public static EmulatorList getInstance()
  {
    if (instance == null) {
      instance = new EmulatorList();
    }
    return instance;
  }
  
  private boolean init = false;
  
  public ArrayList<Emulator> getEmulatorList()
  {
    if (!init)
    {
      SmartDevelopmentBridge.createBridge(SDKInstallPathConfig.getSDBPath(), true);
      
      SmartDevelopmentBridge sdbBridge = SmartDevelopmentBridge.getBridge();
      SmartDevelopmentBridge.addDeviceChangeListener(this, true);
      while (!sdbBridge.isDeviceListInitialized()) {
        synchronized (this)
        {
          try
          {
            wait(1000L);
          }
          catch (InterruptedException e)
          {
            e.printStackTrace();
          }
        }
      }
      init = true;
    }
    return emulatorList;
  }
  
  private IEmulatorChangeListener listener = null;
  
  public void setChangeListener(IEmulatorChangeListener listener)
  {
    this.listener = listener;
  }
  
  public void onConnected(IDevice device)
  {
    if (!DeviceUtil.isOnline(device)) {
      return;
    }
    if (!device.isEmulator()) {
      return;
    }
    Emulator em = new Emulator(device);
    emulatorList.add(em);
    if (listener != null) {
      listener.deviceConnected(em);
    }
  }
  
  public void onDisconnected(IDevice device)
  {
    for (Emulator e : emulatorList) {
      if (e.getDevice().equals(device))
      {
        if (listener != null) {
          listener.deviceDisconnected(e);
        }
        emulatorList.remove(e);
        break;
      }
    }
  }
  
  public void onChanged(IDevice device, int changeMask)
  {
    if (changeMask == 1) {
      onConnected(device);
    }
  }
}

/* Location:
 * Qualified Name:     org.tizen.eilib.connection.EmulatorList
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.tizen.eilib.connection;

import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;
import java.util.HashMap;
import java.util.logging.Logger;
import org.tizen.eilib.connection.message.EventHeader;
import org.tizen.eilib.connection.message.EventMessage;
import org.tizen.eilib.events.receiver.AbstractEventReceiver;
import org.tizen.eilib.tools.EILogger;

class EventReceiver
  extends Thread
{
  private SocketChannel socket;
  private HashMap<Integer, AbstractEventReceiver> receiverMap;
  private AbstractEventReceiver receiver;
  
  public EventReceiver(SocketChannel socket, HashMap<Integer, AbstractEventReceiver> receiverMap)
  {
    this.socket = socket;
    this.receiverMap = receiverMap;
    setDaemon(true);
    setName("EventReceiver");
  }
  
  public void run()
  {
    while ((socket.isConnected()) && (isAlive()) && (!isInterrupted()))
    {
      EventMessage msg = new EventMessage(1024);
      try
      {
        socket.read(msg.getHeaderBuffer());
      }
      catch (IOException e)
      {
        if (!socket.isConnected()) {
          EILogger.getLogger().info("Connection is broken.");
        } else {
          EILogger.getLogger().warning(e.getMessage());
        }
      }
      continue;
      
      msg.setEventHeader();
      if (msg.getEventHeader().getLength() != 0)
      {
        msg.getDataBuffer().limit(msg.getEventHeader().getLength());
        try
        {
          socket.read(msg.getDataBuffer());
        }
        catch (IOException e)
        {
          if (!socket.isConnected()) {
            EILogger.getLogger().info("Connection is broken");
          } else {
            EILogger.getLogger().warning(e.getMessage());
          }
        }
        continue;
      }
      forwardingMessage(msg);
    }
  }
  
  private void forwardingMessage(EventMessage msg)
  {
    switch (msg.getEventHeader().getGroupID())
    {
    case 1: 
    case 3: 
    case 4: 
    case 11: 
    case 15: 
      receiver = ((AbstractEventReceiver)receiverMap.get(Integer.valueOf(msg.getEventHeader().getGroupID())));
      break;
    case 2: 
    case 5: 
    case 6: 
    case 7: 
    case 8: 
    case 9: 
    case 10: 
    case 12: 
    case 13: 
    case 14: 
    default: 
      EILogger.getLogger().info("GroupID( " + msg.getEventHeader().getGroupID() + " ) of message does not exist.");
      
      return;
    }
    if (receiver != null) {
      synchronized (receiver)
      {
        new ExecutorThread(receiver, msg).start();
      }
    } else {
      EILogger.getLogger().info("Receiver does not exist. Add Recevier this groupID :" + msg.getEventHeader().getGroupID());
    }
  }
}

/* Location:
 * Qualified Name:     org.tizen.eilib.connection.EventReceiver
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.tizen.eilib.connection;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.net.UnknownHostException;
import java.nio.channels.SocketChannel;
import java.util.HashMap;
import java.util.logging.Logger;
import org.tizen.eilib.connection.message.EventMessage;
import org.tizen.eilib.events.receiver.AbstractEventReceiver;
import org.tizen.eilib.exception.ConnectionException;
import org.tizen.eilib.exception.EILibError;
import org.tizen.eilib.tools.EILogger;

public class EventSocket
{
  private static final String LocalHost = "127.0.0.1";
  private int port = 0;
  private String ip = "127.0.0.1";
  private SocketChannel socket;
  private EventReceiver receiver = null;
  private HashMap<Integer, AbstractEventReceiver> receiverMap = null;
  
  public EventSocket(HashMap<Integer, AbstractEventReceiver> receiverMap)
  {
    this.receiverMap = receiverMap;
  }
  
  public boolean connect()
    throws IOException
  {
    return connect(port);
  }
  
  public boolean connect(int port)
    throws IOException
  {
    if (port <= 0) {
      throw new UnknownHostException("Port number is " + Integer.toString(port) + ".\n" + "Please set port number.");
    }
    this.port = port;
    if (socket != null) {
      disconnect();
    }
    SocketAddress addr = new InetSocketAddress(ip, port);
    try
    {
      socket = SocketChannel.open(addr);
    }
    catch (IOException e)
    {
      e.printStackTrace();
      throw e;
    }
    receiver = new EventReceiver(socket, receiverMap);
    receiver.start();
    
    return true;
  }
  
  public boolean disconnect()
  {
    if (socket.isConnected()) {
      try
      {
        socket.close();
      }
      catch (IOException e)
      {
        e.printStackTrace();
        EILogger.getLogger().warning(e.getMessage());
        return false;
      }
      finally
      {
        receiver.interrupt();
      }
    }
    return true;
  }
  
  public void setPort(int port)
  {
    this.port = port;
  }
  
  public void setIP(String ip)
  {
    this.ip = ip;
  }
  
  public int getPort()
  {
    return port;
  }
  
  public String getIP()
  {
    return ip;
  }
  
  SocketChannel getSocket()
  {
    return socket;
  }
  
  public boolean isConnected()
  {
    if (socket == null) {
      return false;
    }
    return socket.isConnected();
  }
  
  public synchronized boolean sendMessage(EventMessage message)
    throws IOException, ConnectionException
  {
    if (!socket.isConnected()) {
      return false;
    }
    try
    {
      socket.write(message.getMessage());
    }
    catch (IOException e)
    {
      if (!socket.isConnected())
      {
        EILogger.getLogger().info("Connection is broken.");
      }
      else
      {
        if (e.getMessage().equals("Broken pipe")) {
          throw new ConnectionException(EILibError.EmuldTerminated);
        }
        EILogger.getLogger().warning(e.getMessage());
      }
      throw e;
    }
    return true;
  }
}

/* Location:
 * Qualified Name:     org.tizen.eilib.connection.EventSocket
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.tizen.eilib.connection;

import org.tizen.eilib.connection.message.EventMessage;
import org.tizen.eilib.events.receiver.AbstractEventReceiver;

class ExecutorThread
  extends Thread
{
  private EventMessage message = null;
  private AbstractEventReceiver receiver = null;
  
  ExecutorThread(AbstractEventReceiver receiver, EventMessage msg)
  {
    this.receiver = receiver;
    message = msg;
    setDaemon(true);
    setName(receiver.getName() + " receiver");
  }
  
  public void run()
  {
    receiver.run(message);
  }
}

/* Location:
 * Qualified Name:     org.tizen.eilib.connection.ExecutorThread
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.tizen.eilib.connection;

public abstract class IEmulatorChangeListener
{
  public abstract void deviceChanged(Emulator paramEmulator, int paramInt);
  
  public abstract void deviceConnected(Emulator paramEmulator);
  
  public abstract void deviceDisconnected(Emulator paramEmulator);
}

/* Location:
 * Qualified Name:     org.tizen.eilib.connection.IEmulatorChangeListener
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.tizen.eilib.connection;

 enum OSType
{
  WINDOWS,  LINUX,  MAC;
  
  private OSType() {}
}

/* Location:
 * Qualified Name:     org.tizen.eilib.connection.OSType
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.tizen.eilib.connection;

class SDKInstallPathConfig$1 {}

/* Location:
 * Qualified Name:     org.tizen.eilib.connection.SDKInstallPathConfig.1
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.tizen.eilib.connection;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.logging.Logger;
import org.tizen.eilib.tools.EILogger;

final class SDKInstallPathConfig
{
  private static String defaultHomePath = null;
  private static String sdkInstallPath = null;
  private static String sdbPath = null;
  private static final String DIR_TOOLS = "tools";
  private static final String DIR_SDK_DATA = "tizen-sdk-data";
  private static final String SDKSUFFIX = "tizen-sdk-data" + File.separatorChar + "tizensdkpath";
  private static final String REGISTRY_PATH_OF_SHELL_FOLDER = "HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders";
  private static final String REGISTRY_LOCAL_APP_DATA_OF_SHELL_FOLDER = "\"Local AppData\"";
  private static final String REG_SZ = "REG_SZ";
  private static OSType osType;
  
  static
  {
    String os = System.getProperty("os.name").toLowerCase();
    if (os.indexOf("windows") > -1) {
      osType = OSType.WINDOWS;
    } else if (os.indexOf("linux") > -1) {
      osType = OSType.LINUX;
    } else if (os.indexOf("mac") > -1) {
      osType = OSType.MAC;
    }
    switch (osType)
    {
    case WINDOWS: 
      defaultHomePath = getRegistryValue("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders", "\"Local AppData\"");
      break;
    case LINUX: 
    case MAC: 
      defaultHomePath = System.getProperty("user.home");
      break;
    default: 
      EILogger.getLogger().warning(System.getProperty("os.name") + " is not supported currently.");
    }
    loadSdkPath();
  }
  
  private static void loadSdkPath()
  {
    boolean status = false;
    if (defaultHomePath != null)
    {
      String sdkPath = defaultHomePath + File.separatorChar + SDKSUFFIX;
      File sdk = new File(sdkPath);
      if (sdk.exists())
      {
        String[] fileContent = getContents(sdkPath).split("=");
        if ((fileContent != null) && (new File(fileContent[1]).exists()))
        {
          sdkInstallPath = fileContent[1];
          status = true;
        }
      }
    }
    if (!status) {
      EILogger.getLogger().warning("Tizen SDK is not installed properly.");
    }
  }
  
  private static String getContents(String filePath)
  {
    BufferedReader input = null;
    StringBuilder contents = new StringBuilder();
    String line = null;
    try
    {
      input = new BufferedReader(new FileReader(filePath));
      while ((line = input.readLine()) != null)
      {
        contents.append(line);
        contents.append(System.getProperty("line.separator"));
      }
      if (input != null) {
        try
        {
          input.close();
        }
        catch (IOException e)
        {
          e.printStackTrace();
        }
      }
      String str1;
      if (contents == null) {
        break label176;
      }
    }
    catch (FileNotFoundException e)
    {
      e.printStackTrace();
      return null;
    }
    catch (IOException e)
    {
      e.printStackTrace();
      return null;
    }
    finally
    {
      if (input != null) {
        try
        {
          input.close();
        }
        catch (IOException e)
        {
          e.printStackTrace();
        }
      }
    }
    tmpTernaryOp = contents.toString().trim();
    label176:
    return null;
  }
  
  private static String getRegistryValue(String node, String key)
  {
    if (osType != OSType.WINDOWS) {
      return null;
    }
    BufferedReader br = null;
    value = "";
    
    String query = "reg query \"" + node + "\" /v " + key;
    try
    {
      Process process = Runtime.getRuntime().exec(query);
      String encoding = System.getProperty("sun.jnu.encoding");
      br = new BufferedReader(new InputStreamReader(process.getInputStream(), encoding));
      
      String line = null;
      while ((line = br.readLine()) != null)
      {
        int index = line.indexOf("REG_SZ");
        if (index >= 0) {
          value = line.substring(index + "REG_SZ".length()).trim();
        }
      }
      return value;
    }
    catch (IOException e)
    {
      e.printStackTrace();
    }
    finally
    {
      if (br != null) {
        try
        {
          br.close();
        }
        catch (IOException e)
        {
          e.printStackTrace();
        }
      }
    }
  }
  
  public static String getSDKPath()
  {
    return sdkInstallPath;
  }
  
  public static String getSDBPath()
  {
    if ((sdbPath == null) && (sdkInstallPath != null)) {
      sdbPath = getSDKPath() + File.separator + "tools" + File.separator + (osType == OSType.WINDOWS ? "sdb.exe" : "sdb");
    }
    return sdbPath;
  }
}

/* Location:
 * Qualified Name:     org.tizen.eilib.connection.SDKInstallPathConfig
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.tizen.eilib.connection.message;

public enum ActionID
{
  BATTERY_LEVEL(100),  BATTERY_CHARGER(101),  USB_STATUS(102),  EARJACK_STATUS(103),  RSSI_LEVEL(104),  ACCEL_VALUE(110),  GYRO_VALUE(111),  MAG_VALUE(112),  LIGHT_VALUE(113),  PROXI_VALUE(114),  MOTION_VALUE(115),  LOCATION_STATUS(120),  NFC_STATUS(121);
  
  int id;
  
  private ActionID(int id)
  {
    this.id = id;
  }
  
  public int getId()
  {
    return id;
  }
}

/* Location:
 * Qualified Name:     org.tizen.eilib.connection.message.ActionID
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.tizen.eilib.connection.message;

public class EventHeader
{
  private short length = 0;
  private int groupID = 0;
  private int actionID = 0;
  
  public short getLength()
  {
    return length;
  }
  
  public void setLength(short length)
  {
    this.length = length;
  }
  
  public int getGroupID()
  {
    return groupID;
  }
  
  public void setGroupID(int groupID)
  {
    this.groupID = groupID;
  }
  
  public int getActionID()
  {
    return actionID;
  }
  
  public void setActionID(int actionID)
  {
    this.actionID = actionID;
  }
}

/* Location:
 * Qualified Name:     org.tizen.eilib.connection.message.EventHeader
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.tizen.eilib.connection.message;

import java.nio.ByteBuffer;
import java.nio.ByteOrder;

public class EventMessage
{
  private static final int HEADER_SIZE = 4;
  private static final int MAX_DATA_SIZE = 4096;
  private int maxDataLength = 4096;
  private EventHeader eventHeader = null;
  private ByteBuffer message = null;
  private ByteBuffer type = null;
  private ByteBuffer header = null;
  private ByteBuffer data = null;
  private int messageLength = 0;
  
  public EventMessage()
  {
    this(4096);
  }
  
  public EventMessage(int size)
  {
    eventHeader = new EventHeader();
    
    initEventMessage(size);
  }
  
  public void setEventHeader()
  {
    header.clear();
    eventHeader.setLength(header.getShort());
    eventHeader.setGroupID(header.get() & 0xFF);
    eventHeader.setActionID(header.get() & 0xFF);
  }
  
  public EventHeader getEventHeader()
  {
    return eventHeader;
  }
  
  public ByteBuffer getEventTypeBuffer()
  {
    return type;
  }
  
  public ByteBuffer getHeaderBuffer()
  {
    return header;
  }
  
  public ByteBuffer getDataBuffer()
  {
    return data;
  }
  
  public int getMaxDataBufferSize()
  {
    return maxDataLength;
  }
  
  public int getDataBufferOffset()
  {
    return EventType.ID_LENGH + 4;
  }
  
  public void setEventTypeBuffer(EventType id)
  {
    type.position(0);
    type.put(id.getType());
  }
  
  public void setHeaderBuffer(EventHeader h)
  {
    header.clear();
    header.putShort(h.getLength());
    header.put(Integer.valueOf(h.getGroupID()).byteValue());
    header.put(Integer.valueOf(h.getActionID()).byteValue());
  }
  
  public ByteBuffer getMessage()
  {
    setMessageLength();
    message.position(messageLength);
    message.flip();
    message.position(0);
    return message;
  }
  
  public void setMessageLength()
  {
    messageLength = (EventType.ID_LENGH + 4 + data.position());
  }
  
  public int getMessageLength()
  {
    setMessageLength();
    return messageLength;
  }
  
  public void clear()
  {
    message.clear();
    header.clear();
    data.clear();
  }
  
  public void initEventMessage(int size)
  {
    if (size >= 0) {
      maxDataLength = size;
    }
    message = ByteBuffer.allocate(EventType.ID_LENGH + 4 + maxDataLength);
    message.order(ByteOrder.LITTLE_ENDIAN);
    
    message.limit(EventType.ID_LENGH);
    type = message.slice();
    
    message.position(message.limit());
    message.limit(message.position() + 4);
    header = message.slice();
    header.order(ByteOrder.LITTLE_ENDIAN);
    
    message.position(message.limit());
    message.limit(message.capacity());
    data = message.slice();
    data.order(ByteOrder.LITTLE_ENDIAN);
  }
}

/* Location:
 * Qualified Name:     org.tizen.eilib.connection.message.EventMessage
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.tizen.eilib.connection.message;

import java.nio.ByteBuffer;

public enum EventType
{
  TELEPHONY("telephony\n"),  SENSOR("sensor\n"),  NFC("nfc\n"),  LOCATION("location\n"),  SDCARD("sdcard\n");
  
  public static int ID_LENGH = 10;
  private ByteBuffer type = null;
  
  private EventType(String type)
  {
    this.type = ByteBuffer.allocate(10);
    for (byte c : type.getBytes()) {
      this.type.put(c);
    }
  }
  
  public ByteBuffer getType()
  {
    type.clear();
    return type;
  }
}

/* Location:
 * Qualified Name:     org.tizen.eilib.connection.message.EventType
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.tizen.eilib.connection.message;

public class GroupID
{
  public static final int CALL = 1;
  public static final int SUPS = 3;
  public static final int SMS = 4;
  public static final int SDCARD = 11;
  public static final int STATUS = 15;
}

/* Location:
 * Qualified Name:     org.tizen.eilib.connection.message.GroupID
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.tizen.eilib.events;

public abstract class AbstractEventInjector
{
  public abstract void initEventInjector();
}

/* Location:
 * Qualified Name:     org.tizen.eilib.events.AbstractEventInjector
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.tizen.eilib.events;

import java.io.IOException;
import org.tizen.eilib.connection.ConnectionToEmulator;
import org.tizen.eilib.connection.message.ActionID;
import org.tizen.eilib.events.receiver.AbstractEventReceiver;
import org.tizen.eilib.events.receiver.EventReceiver;
import org.tizen.eilib.events.receiver.StatusEventReceiver;
import org.tizen.eilib.events.type.BatteryCharger;
import org.tizen.eilib.exception.ConnectionException;
import org.tizen.eilib.exception.DeviceEventException;
import org.tizen.eilib.exception.EILibError;

public class BatteryEventInjector
  extends AbstractEventInjector
{
  private BatteryEventSender sender = null;
  static final int MIN_VALUE = 1;
  static final int MAX_VALUE = 100;
  
  BatteryEventInjector(ConnectionToEmulator connector)
  {
    sender = new BatteryEventSender(connector);
    EventReceiver receiver = new EventReceiver("BatteryReceiver", sender);
    
    AbstractEventReceiver abReceiver = connector.findEventReceiver(15);
    if ((abReceiver != null) && ((abReceiver instanceof StatusEventReceiver)))
    {
      StatusEventReceiver re = (StatusEventReceiver)abReceiver;
      re.addStatusEventReceiver(ActionID.BATTERY_LEVEL, receiver);
      re.addStatusEventReceiver(ActionID.BATTERY_CHARGER, receiver);
    }
  }
  
  public int getMaxBatteryLevel()
  {
    return 100;
  }
  
  public int getMinBatteryLevel()
  {
    return 1;
  }
  
  public boolean setLevel(int level)
    throws IOException, DeviceEventException, ConnectionException
  {
    if ((level < 1) || (level > 100)) {
      throw new DeviceEventException(EILibError.InvalidValue);
    }
    return sender.setLevel(level);
  }
  
  public boolean setChargerState(BatteryCharger charger)
    throws IOException, DeviceEventException, ConnectionException
  {
    if (charger == null) {
      throw new DeviceEventException(EILibError.InvalidValue);
    }
    return sender.setChargerState(charger);
  }
  
  public int getLevel()
    throws IOException, DeviceEventException, ConnectionException
  {
    int level = sender.getLevel();
    if (level == -1) {
      throw new DeviceEventException(EILibError.FailedGetValue);
    }
    return level;
  }
  
  public BatteryCharger getChargerState()
    throws IOException, ConnectionException, DeviceEventException
  {
    BatteryCharger charger = sender.getChargerState();
    if (charger == null) {
      throw new DeviceEventException(EILibError.FailedGetValue);
    }
    return charger;
  }
  
  public void initEventInjector() {}
}

/* Location:
 * Qualified Name:     org.tizen.eilib.events.BatteryEventInjector
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.tizen.eilib.events;

import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.logging.Logger;
import org.tizen.eilib.connection.ConnectionToEmulator;
import org.tizen.eilib.connection.message.ActionID;
import org.tizen.eilib.connection.message.EventHeader;
import org.tizen.eilib.connection.message.EventMessage;
import org.tizen.eilib.events.sender.DeviceEventSender;
import org.tizen.eilib.events.type.BatteryCharger;
import org.tizen.eilib.exception.ConnectionException;
import org.tizen.eilib.modem.protocol.ByteUtil;
import org.tizen.eilib.tools.EILogger;

class BatteryEventSender
  extends DeviceEventSender
{
  private static String BatteryID = "8\n";
  private static final int SET_LEVEL = 1;
  private static final int SET_CHARGER = 2;
  private double[] params = new double[2];
  private EventMessage returnMsg = null;
  
  BatteryEventSender(ConnectionToEmulator connector)
  {
    super(connector);
  }
  
  public synchronized boolean setLevel(int level)
    throws IOException, ConnectionException
  {
    params[0] = 1.0D;
    params[1] = level;
    makeMessage(BatteryID, params);
    return sendMessage(null);
  }
  
  public int getLevel()
    throws IOException, ConnectionException
  {
    makeMessage(BatteryID, null);
    sendMessage(ActionID.BATTERY_LEVEL);
    synchronized (this)
    {
      try
      {
        wait(5000L);
      }
      catch (InterruptedException e)
      {
        e.printStackTrace();
        EILogger.getLogger().warning(e.getMessage());
      }
    }
    int level = -1;
    if (returnMsg != null)
    {
      if (returnMsg.getEventHeader().getActionID() != ActionID.BATTERY_LEVEL.getId())
      {
        EILogger.getLogger().warning("An unexpected event occurs.");
      }
      else
      {
        level = ByteUtil.byte2int(returnMsg.getDataBuffer().array(), 14);
        if ((level < 1) || (level > 100)) {
          level = -1;
        }
      }
      returnMsg = null;
    }
    return level;
  }
  
  public synchronized boolean setChargerState(BatteryCharger charger)
    throws IOException, ConnectionException
  {
    params[0] = 2.0D;
    params[1] = charger.getValue();
    makeMessage(BatteryID, params);
    return sendMessage(null);
  }
  
  public BatteryCharger getChargerState()
    throws IOException, ConnectionException
  {
    makeMessage(BatteryID, null);
    sendMessage(ActionID.BATTERY_CHARGER);
    synchronized (this)
    {
      try
      {
        wait(5000L);
      }
      catch (InterruptedException e)
      {
        e.printStackTrace();
        EILogger.getLogger().warning(e.getMessage());
      }
    }
    if (returnMsg != null)
    {
      if (returnMsg.getEventHeader().getActionID() != ActionID.BATTERY_CHARGER.getId())
      {
        EILogger.getLogger().warning("An unexpected event occurs.");
      }
      else
      {
        int i = ByteUtil.byte2int(returnMsg.getDataBuffer().array(), 14);
        if (BatteryCharger.CONNECT.getValue() == i) {
          return BatteryCharger.CONNECT;
        }
        if (BatteryCharger.DISCONNECT.getValue() == i) {
          return BatteryCharger.DISCONNECT;
        }
      }
      returnMsg = null;
    }
    return null;
  }
  
  public void fireEvent(EventMessage message)
  {
    synchronized (this)
    {
      returnMsg = message;
      notifyAll();
    }
  }
}

/* Location:
 * Qualified Name:     org.tizen.eilib.events.BatteryEventSender
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.tizen.eilib.events;

import java.util.ArrayList;
import org.tizen.eilib.events.type.CallEventType;
import org.tizen.eilib.events.type.CallStatus;
import org.tizen.eilib.events.type.CallType;

public class CallEvent
{
  private CallEventType eventType;
  private int callID;
  private CallType callType;
  private CallStatus callStatus;
  private String callNumber;
  private ArrayList<CallItem> callItemList;
  
  public String toString()
  {
    String str = "ID: " + callID + "\nType: " + callType + "\nStatus: " + callStatus + "\nNumber: " + callNumber + "\n";
    if (callItemList != null) {
      for (CallItem item : callItemList) {
        str = str + item.toString();
      }
    }
    return str;
  }
  
  public CallEvent()
  {
    eventType = CallEventType.NONE;
    callID = 0;
    callType = CallType.NONE;
    callStatus = CallStatus.NONE;
    callNumber = "";
    callItemList = null;
  }
  
  public CallEventType getEventType()
  {
    return eventType;
  }
  
  void setEventType(CallEventType eventType)
  {
    this.eventType = eventType;
  }
  
  public int getCallID()
  {
    return callID;
  }
  
  void setCallID(int callID)
  {
    this.callID = callID;
  }
  
  public CallType getCallType()
  {
    return callType;
  }
  
  void setCallType(CallType callType)
  {
    this.callType = callType;
  }
  
  public String getCallNumber()
  {
    return callNumber;
  }
  
  void setCallNumber(String callNumber)
  {
    this.callNumber = callNumber;
  }
  
  public ArrayList<CallItem> getCallItemList()
  {
    return callItemList;
  }
  
  void setCallItemList(ArrayList<CallItem> callItemList)
  {
    this.callItemList = callItemList;
  }
  
  public CallStatus getCallStatus()
  {
    return callStatus;
  }
  
 
1 2 3 4 5 6 7

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2017. Infinite Loop Ltd