From 2c60996edc7a483ba8bbc07318cda0fdab7df046 Mon Sep 17 00:00:00 2001 From: HyungKyu Song Date: Sat, 16 Feb 2013 00:58:29 +0900 Subject: [PATCH] Tizen 2.0 Release --- AUTHORS | 12 + LICENSE.APLv2 | 206 +++++++ NOTICE | 3 + ei-library/.classpath | 7 + ei-library/.project | 17 + ei-library/.settings/org.eclipse.jdt.core.prefs | 12 + ei-library/build.xml | 67 ++ .../eilib/connection/ConnectionToEmulator.java | 403 ++++++++++++ .../src/org/tizen/eilib/connection/Emulator.java | 378 ++++++++++++ .../org/tizen/eilib/connection/EmulatorList.java | 157 +++++ .../org/tizen/eilib/connection/EventReceiver.java | 124 ++++ .../org/tizen/eilib/connection/EventSocket.java | 149 +++++ .../eilib/connection/IEmulatorChangeListener.java | 35 ++ .../eilib/connection/SDKInstallPathConfig.java | 186 ++++++ .../tizen/eilib/connection/message/ActionID.java | 51 ++ .../eilib/connection/message/EventHeader.java | 99 +++ .../eilib/connection/message/EventMessage.java | 241 ++++++++ .../tizen/eilib/connection/message/EventType.java | 50 ++ .../tizen/eilib/connection/message/GroupID.java | 36 ++ .../tizen/eilib/events/AbstractEventInjector.java | 36 ++ .../tizen/eilib/events/BatteryEventInjector.java | 270 ++++++++ .../src/org/tizen/eilib/events/CallEvent.java | 112 ++++ .../org/tizen/eilib/events/CallEventInjector.java | 597 ++++++++++++++++++ .../src/org/tizen/eilib/events/CallItem.java | 86 +++ .../tizen/eilib/events/EarJackEventInjector.java | 167 +++++ .../tizen/eilib/events/EventInjectorCreator.java | 188 ++++++ .../src/org/tizen/eilib/events/LocationEvent.java | 74 +++ .../tizen/eilib/events/LocationEventInjector.java | 272 ++++++++ .../org/tizen/eilib/events/NfcEventInjector.java | 482 +++++++++++++++ .../src/org/tizen/eilib/events/NfcEventType.java | 55 ++ .../org/tizen/eilib/events/RSSIEventInjector.java | 258 ++++++++ .../src/org/tizen/eilib/events/SDCardEvent.java | 59 ++ .../tizen/eilib/events/SDCardEventInjector.java | 433 +++++++++++++ .../src/org/tizen/eilib/events/SMSEvent.java | 58 ++ .../org/tizen/eilib/events/SMSEventInjector.java | 540 ++++++++++++++++ .../tizen/eilib/events/SensorEventInjector.java | 500 +++++++++++++++ .../org/tizen/eilib/events/USBEventInjector.java | 168 +++++ .../eilib/events/listener/EventListenerList.java | 107 ++++ .../eilib/events/listener/ICallEventListener.java | 54 ++ .../eilib/events/listener/IEventListener.java | 32 + .../events/listener/ISDcardEventListener.java | 56 ++ .../eilib/events/listener/ISMSEventListener.java | 46 ++ .../events/receiver/AbstractEventReceiver.java | 44 ++ .../tizen/eilib/events/receiver/EventReceiver.java | 45 ++ .../eilib/events/receiver/StatusEventReceiver.java | 61 ++ .../eilib/events/sender/AbstractEventSender.java | 53 ++ .../eilib/events/sender/DeviceEventSender.java | 95 +++ .../eilib/events/sender/LocationEventSender.java | 107 ++++ .../eilib/events/sender/ModemEventSender.java | 72 +++ .../tizen/eilib/events/sender/NfcEventSender.java | 106 ++++ .../eilib/events/sender/SDCardEventSender.java | 85 +++ .../events/sender/SDCardStatusCheckSender.java | 149 +++++ .../eilib/events/sender/SensorEventSender.java | 294 +++++++++ .../tizen/eilib/events/type/BatteryCharger.java | 47 ++ .../org/tizen/eilib/events/type/CallErrorCode.java | 47 ++ .../org/tizen/eilib/events/type/CallEventType.java | 31 + .../org/tizen/eilib/events/type/CallStatus.java | 54 ++ .../src/org/tizen/eilib/events/type/CallType.java | 51 ++ .../org/tizen/eilib/events/type/EarJackStatus.java | 49 ++ .../tizen/eilib/events/type/LocationEventMode.java | 50 ++ .../org/tizen/eilib/events/type/MimeTypeList.java | 108 ++++ .../org/tizen/eilib/events/type/MobileType.java | 50 ++ .../tizen/eilib/events/type/MotionEventType.java | 55 ++ .../org/tizen/eilib/events/type/NDEFFormat.java | 58 ++ .../org/tizen/eilib/events/type/NDEFRecord.java | 83 +++ .../org/tizen/eilib/events/type/NfcTagType.java | 57 ++ .../tizen/eilib/events/type/ProximityStatus.java | 49 ++ .../tizen/eilib/events/type/SDCardEventType.java | 36 ++ .../org/tizen/eilib/events/type/SMSEventType.java | 31 + .../src/org/tizen/eilib/events/type/SMSStatus.java | 49 ++ .../tizen/eilib/events/type/SensorEventType.java | 53 ++ .../src/org/tizen/eilib/events/type/USBStatus.java | 49 ++ .../tizen/eilib/exception/CallEventException.java | 43 ++ .../tizen/eilib/exception/ConnectionException.java | 50 ++ .../eilib/exception/DeviceEventException.java | 44 ++ .../src/org/tizen/eilib/exception/EILibError.java | 120 ++++ .../eilib/exception/InjectorLibraryException.java | 52 ++ .../eilib/exception/InvalidTypeException.java | 36 ++ .../tizen/eilib/exception/NfcEventException.java | 45 ++ .../tizen/eilib/exception/SMSEventException.java | 43 ++ .../eilib/exception/SensorEventException.java | 46 ++ .../tizen/eilib/modem/encription/DecodeMsg.java | 684 +++++++++++++++++++++ .../tizen/eilib/modem/encription/EncodeMsg.java | 578 +++++++++++++++++ .../eilib/modem/encription/EnumConstants.java | 107 ++++ .../tizen/eilib/modem/encription/SMS_USERDATA.java | 50 ++ .../eilib/modem/encription/SmsAddressInfo.java | 34 + .../eilib/modem/encription/TPDU_SMS_DELIVER.java | 48 ++ .../eilib/modem/encription/TPDU_SMS_SUBMIT.java | 74 +++ .../modem/encription/TapiNetTextCodingScheme.java | 40 ++ .../eilib/modem/encription/TapiNetTextVP.java | 33 + .../tizen/eilib/modem/encription/TmDateTime.java | 36 ++ .../org/tizen/eilib/modem/protocol/AbstractGA.java | 213 +++++++ .../tizen/eilib/modem/protocol/AbstractItem.java | 53 ++ .../tizen/eilib/modem/protocol/ByteArrayItem.java | 46 ++ .../org/tizen/eilib/modem/protocol/ByteUtil.java | 140 +++++ .../src/org/tizen/eilib/modem/protocol/G01A07.java | 45 ++ .../org/tizen/eilib/modem/protocol/G01A21MO.java | 48 ++ .../org/tizen/eilib/modem/protocol/G01A21MT.java | 51 ++ .../src/org/tizen/eilib/modem/protocol/G01A22.java | 56 ++ .../org/tizen/eilib/modem/protocol/G01A22End.java | 44 ++ .../src/org/tizen/eilib/modem/protocol/G01A23.java | 42 ++ .../src/org/tizen/eilib/modem/protocol/G01A26.java | 56 ++ .../src/org/tizen/eilib/modem/protocol/G01A29.java | 57 ++ .../src/org/tizen/eilib/modem/protocol/G01A62.java | 42 ++ .../src/org/tizen/eilib/modem/protocol/G02A31.java | 54 ++ .../src/org/tizen/eilib/modem/protocol/G04A01.java | 44 ++ .../src/org/tizen/eilib/modem/protocol/G04A05.java | 44 ++ .../org/tizen/eilib/modem/protocol/IntItem.java | 46 ++ .../org/tizen/eilib/modem/protocol/ItemType.java | 31 + .../org/tizen/eilib/modem/protocol/StringUtil.java | 59 ++ .../tizen/eilib/modem/protocol/StructureGA.java | 154 +++++ ei-library/src/org/tizen/eilib/tools/EILogger.java | 196 ++++++ eventinjector-cli/.classpath | 9 + eventinjector-cli/.project | 17 + .../.settings/org.eclipse.jdt.core.prefs | 12 + eventinjector-cli/build.xml | 63 ++ .../src/org/tizen/injector/DeviceList.java | 90 +++ .../src/org/tizen/injector/EventInjector.java | 343 +++++++++++ .../src/org/tizen/injector/EventRecorder.java | 141 +++++ .../src/org/tizen/injector/GlobalOption.java | 141 +++++ .../src/org/tizen/injector/StringResource.java | 185 ++++++ .../src/org/tizen/injector/device/Argument.java | 90 +++ .../src/org/tizen/injector/device/Command.java | 149 +++++ .../src/org/tizen/injector/device/Device.java | 124 ++++ .../org/tizen/injector/device/EmulatorDevice.java | 83 +++ .../src/org/tizen/injector/device/ExitDevice.java | 64 ++ .../src/org/tizen/injector/device/HelpDevice.java | 101 +++ .../src/org/tizen/injector/device/Option.java | 84 +++ .../src/org/tizen/injector/device/Record.java | 91 +++ .../src/org/tizen/injector/device/RecordPlay.java | 152 +++++ .../src/org/tizen/injector/device/RecordStart.java | 144 +++++ .../injector/device/device/ArgBatteryCharger.java | 87 +++ .../injector/device/device/ArgBatteryLevel.java | 111 ++++ .../org/tizen/injector/device/device/Battery.java | 99 +++ .../tizen/injector/device/device/BatteryLevel.java | 80 +++ .../injector/device/device/BatterySetCharger.java | 78 +++ .../org/tizen/injector/device/device/EarJack.java | 93 +++ .../tizen/injector/device/device/EarJackSet.java | 131 ++++ .../src/org/tizen/injector/device/device/RSSI.java | 94 +++ .../org/tizen/injector/device/device/RssiSet.java | 130 ++++ .../org/tizen/injector/device/device/SDCard.java | 46 ++ .../tizen/injector/device/device/SDCardMount.java | 157 +++++ .../tizen/injector/device/device/SDCardStatus.java | 140 +++++ .../injector/device/device/SDCardUnmount.java | 90 +++ .../tizen/injector/device/device/USBDevice.java | 94 +++ .../tizen/injector/device/device/USBDeviceSet.java | 131 ++++ .../tizen/injector/device/location/Location.java | 112 ++++ .../device/location/LocationCoordinate.java | 180 ++++++ .../injector/device/location/LocationLogFile.java | 114 ++++ .../injector/device/location/LocationStop.java | 63 ++ .../tizen/injector/device/modem/ArgCallNumber.java | 75 +++ .../src/org/tizen/injector/device/modem/Call.java | 121 ++++ .../org/tizen/injector/device/modem/CallAlert.java | 73 +++ .../tizen/injector/device/modem/CallConnect.java | 72 +++ .../org/tizen/injector/device/modem/CallDial.java | 79 +++ .../injector/device/modem/CallDisconnect.java | 202 ++++++ .../tizen/injector/device/modem/CallHidden.java | 79 +++ .../src/org/tizen/injector/device/modem/SMS.java | 69 +++ .../org/tizen/injector/device/modem/SmsSend.java | 165 +++++ .../tizen/injector/device/modem/SmsSetStatus.java | 129 ++++ .../injector/device/nfc/ArgMessageEventType.java | 100 +++ .../tizen/injector/device/nfc/ArgMessageIndex.java | 97 +++ .../tizen/injector/device/nfc/ArgNDEFMessage.java | 101 +++ .../tizen/injector/device/nfc/ArgNfcTagEvent.java | 101 +++ .../src/org/tizen/injector/device/nfc/Nfc.java | 125 ++++ .../org/tizen/injector/device/nfc/NfcMessage.java | 181 ++++++ .../src/org/tizen/injector/device/nfc/NfcP2P.java | 263 ++++++++ .../src/org/tizen/injector/device/nfc/NfcTag.java | 254 ++++++++ .../injector/device/sensor/ArgAccelValue.java | 118 ++++ .../tizen/injector/device/sensor/ArgGyroValue.java | 116 ++++ .../injector/device/sensor/ArgLightValue.java | 98 +++ .../injector/device/sensor/ArgMagneticValue.java | 118 ++++ .../injector/device/sensor/ArgProxiValue.java | 78 +++ .../injector/device/sensor/ArgSensorFilePath.java | 84 +++ .../injector/device/sensor/ArgSensorName.java | 125 ++++ .../injector/device/sensor/ArgSensorValue.java | 71 +++ .../org/tizen/injector/device/sensor/Motion.java | 70 +++ .../tizen/injector/device/sensor/MotionSet.java | 129 ++++ .../org/tizen/injector/device/sensor/Sensor.java | 142 +++++ .../tizen/injector/device/sensor/SensorFile.java | 112 ++++ .../tizen/injector/device/sensor/SensorGet.java | 146 +++++ .../tizen/injector/device/sensor/SensorSet.java | 197 ++++++ .../org/tizen/injector/exception/ConsoleError.java | 87 +++ .../tizen/injector/exception/ConsoleException.java | 50 ++ .../org/tizen/injector/parser/ArgCompletor.java | 77 +++ .../src/org/tizen/injector/parser/Args.java | 85 +++ .../tizen/injector/parser/CommandCompletor.java | 88 +++ .../org/tizen/injector/parser/CommandParser.java | 171 ++++++ .../org/tizen/injector/parser/DeviceCompletor.java | 72 +++ .../src/org/tizen/injector/parser/HelpMessage.java | 103 ++++ library/COPYING.BSD | 33 + library/jline-1.0.jar | Bin 0 -> 91183 bytes package/build.linux | 62 ++ package/changelog | 3 + package/pkginfo.manifest | 38 ++ supplement/eventinjector-cli-mac.sh | 22 + supplement/eventinjector-cli.bat | 30 + supplement/eventinjector-cli.sh | 22 + supplement/test.sh | 86 +++ 199 files changed, 21717 insertions(+) create mode 100644 AUTHORS create mode 100644 LICENSE.APLv2 create mode 100644 NOTICE create mode 100644 ei-library/.classpath create mode 100644 ei-library/.project create mode 100644 ei-library/.settings/org.eclipse.jdt.core.prefs create mode 100644 ei-library/build.xml create mode 100644 ei-library/src/org/tizen/eilib/connection/ConnectionToEmulator.java create mode 100644 ei-library/src/org/tizen/eilib/connection/Emulator.java create mode 100644 ei-library/src/org/tizen/eilib/connection/EmulatorList.java create mode 100644 ei-library/src/org/tizen/eilib/connection/EventReceiver.java create mode 100644 ei-library/src/org/tizen/eilib/connection/EventSocket.java create mode 100644 ei-library/src/org/tizen/eilib/connection/IEmulatorChangeListener.java create mode 100644 ei-library/src/org/tizen/eilib/connection/SDKInstallPathConfig.java create mode 100644 ei-library/src/org/tizen/eilib/connection/message/ActionID.java create mode 100644 ei-library/src/org/tizen/eilib/connection/message/EventHeader.java create mode 100644 ei-library/src/org/tizen/eilib/connection/message/EventMessage.java create mode 100644 ei-library/src/org/tizen/eilib/connection/message/EventType.java create mode 100644 ei-library/src/org/tizen/eilib/connection/message/GroupID.java create mode 100644 ei-library/src/org/tizen/eilib/events/AbstractEventInjector.java create mode 100644 ei-library/src/org/tizen/eilib/events/BatteryEventInjector.java create mode 100644 ei-library/src/org/tizen/eilib/events/CallEvent.java create mode 100644 ei-library/src/org/tizen/eilib/events/CallEventInjector.java create mode 100644 ei-library/src/org/tizen/eilib/events/CallItem.java create mode 100644 ei-library/src/org/tizen/eilib/events/EarJackEventInjector.java create mode 100644 ei-library/src/org/tizen/eilib/events/EventInjectorCreator.java create mode 100644 ei-library/src/org/tizen/eilib/events/LocationEvent.java create mode 100644 ei-library/src/org/tizen/eilib/events/LocationEventInjector.java create mode 100644 ei-library/src/org/tizen/eilib/events/NfcEventInjector.java create mode 100644 ei-library/src/org/tizen/eilib/events/NfcEventType.java create mode 100644 ei-library/src/org/tizen/eilib/events/RSSIEventInjector.java create mode 100644 ei-library/src/org/tizen/eilib/events/SDCardEvent.java create mode 100644 ei-library/src/org/tizen/eilib/events/SDCardEventInjector.java create mode 100644 ei-library/src/org/tizen/eilib/events/SMSEvent.java create mode 100644 ei-library/src/org/tizen/eilib/events/SMSEventInjector.java create mode 100644 ei-library/src/org/tizen/eilib/events/SensorEventInjector.java create mode 100644 ei-library/src/org/tizen/eilib/events/USBEventInjector.java create mode 100644 ei-library/src/org/tizen/eilib/events/listener/EventListenerList.java create mode 100644 ei-library/src/org/tizen/eilib/events/listener/ICallEventListener.java create mode 100644 ei-library/src/org/tizen/eilib/events/listener/IEventListener.java create mode 100644 ei-library/src/org/tizen/eilib/events/listener/ISDcardEventListener.java create mode 100644 ei-library/src/org/tizen/eilib/events/listener/ISMSEventListener.java create mode 100644 ei-library/src/org/tizen/eilib/events/receiver/AbstractEventReceiver.java create mode 100644 ei-library/src/org/tizen/eilib/events/receiver/EventReceiver.java create mode 100644 ei-library/src/org/tizen/eilib/events/receiver/StatusEventReceiver.java create mode 100644 ei-library/src/org/tizen/eilib/events/sender/AbstractEventSender.java create mode 100644 ei-library/src/org/tizen/eilib/events/sender/DeviceEventSender.java create mode 100644 ei-library/src/org/tizen/eilib/events/sender/LocationEventSender.java create mode 100644 ei-library/src/org/tizen/eilib/events/sender/ModemEventSender.java create mode 100644 ei-library/src/org/tizen/eilib/events/sender/NfcEventSender.java create mode 100644 ei-library/src/org/tizen/eilib/events/sender/SDCardEventSender.java create mode 100644 ei-library/src/org/tizen/eilib/events/sender/SDCardStatusCheckSender.java create mode 100644 ei-library/src/org/tizen/eilib/events/sender/SensorEventSender.java create mode 100644 ei-library/src/org/tizen/eilib/events/type/BatteryCharger.java create mode 100644 ei-library/src/org/tizen/eilib/events/type/CallErrorCode.java create mode 100644 ei-library/src/org/tizen/eilib/events/type/CallEventType.java create mode 100644 ei-library/src/org/tizen/eilib/events/type/CallStatus.java create mode 100644 ei-library/src/org/tizen/eilib/events/type/CallType.java create mode 100644 ei-library/src/org/tizen/eilib/events/type/EarJackStatus.java create mode 100644 ei-library/src/org/tizen/eilib/events/type/LocationEventMode.java create mode 100644 ei-library/src/org/tizen/eilib/events/type/MimeTypeList.java create mode 100644 ei-library/src/org/tizen/eilib/events/type/MobileType.java create mode 100644 ei-library/src/org/tizen/eilib/events/type/MotionEventType.java create mode 100644 ei-library/src/org/tizen/eilib/events/type/NDEFFormat.java create mode 100644 ei-library/src/org/tizen/eilib/events/type/NDEFRecord.java create mode 100644 ei-library/src/org/tizen/eilib/events/type/NfcTagType.java create mode 100644 ei-library/src/org/tizen/eilib/events/type/ProximityStatus.java create mode 100644 ei-library/src/org/tizen/eilib/events/type/SDCardEventType.java create mode 100644 ei-library/src/org/tizen/eilib/events/type/SMSEventType.java create mode 100644 ei-library/src/org/tizen/eilib/events/type/SMSStatus.java create mode 100644 ei-library/src/org/tizen/eilib/events/type/SensorEventType.java create mode 100644 ei-library/src/org/tizen/eilib/events/type/USBStatus.java create mode 100644 ei-library/src/org/tizen/eilib/exception/CallEventException.java create mode 100644 ei-library/src/org/tizen/eilib/exception/ConnectionException.java create mode 100644 ei-library/src/org/tizen/eilib/exception/DeviceEventException.java create mode 100644 ei-library/src/org/tizen/eilib/exception/EILibError.java create mode 100644 ei-library/src/org/tizen/eilib/exception/InjectorLibraryException.java create mode 100644 ei-library/src/org/tizen/eilib/exception/InvalidTypeException.java create mode 100644 ei-library/src/org/tizen/eilib/exception/NfcEventException.java create mode 100644 ei-library/src/org/tizen/eilib/exception/SMSEventException.java create mode 100644 ei-library/src/org/tizen/eilib/exception/SensorEventException.java create mode 100644 ei-library/src/org/tizen/eilib/modem/encription/DecodeMsg.java create mode 100644 ei-library/src/org/tizen/eilib/modem/encription/EncodeMsg.java create mode 100644 ei-library/src/org/tizen/eilib/modem/encription/EnumConstants.java create mode 100644 ei-library/src/org/tizen/eilib/modem/encription/SMS_USERDATA.java create mode 100644 ei-library/src/org/tizen/eilib/modem/encription/SmsAddressInfo.java create mode 100644 ei-library/src/org/tizen/eilib/modem/encription/TPDU_SMS_DELIVER.java create mode 100644 ei-library/src/org/tizen/eilib/modem/encription/TPDU_SMS_SUBMIT.java create mode 100644 ei-library/src/org/tizen/eilib/modem/encription/TapiNetTextCodingScheme.java create mode 100644 ei-library/src/org/tizen/eilib/modem/encription/TapiNetTextVP.java create mode 100644 ei-library/src/org/tizen/eilib/modem/encription/TmDateTime.java create mode 100644 ei-library/src/org/tizen/eilib/modem/protocol/AbstractGA.java create mode 100644 ei-library/src/org/tizen/eilib/modem/protocol/AbstractItem.java create mode 100644 ei-library/src/org/tizen/eilib/modem/protocol/ByteArrayItem.java create mode 100644 ei-library/src/org/tizen/eilib/modem/protocol/ByteUtil.java create mode 100644 ei-library/src/org/tizen/eilib/modem/protocol/G01A07.java create mode 100644 ei-library/src/org/tizen/eilib/modem/protocol/G01A21MO.java create mode 100644 ei-library/src/org/tizen/eilib/modem/protocol/G01A21MT.java create mode 100644 ei-library/src/org/tizen/eilib/modem/protocol/G01A22.java create mode 100644 ei-library/src/org/tizen/eilib/modem/protocol/G01A22End.java create mode 100644 ei-library/src/org/tizen/eilib/modem/protocol/G01A23.java create mode 100644 ei-library/src/org/tizen/eilib/modem/protocol/G01A26.java create mode 100644 ei-library/src/org/tizen/eilib/modem/protocol/G01A29.java create mode 100644 ei-library/src/org/tizen/eilib/modem/protocol/G01A62.java create mode 100644 ei-library/src/org/tizen/eilib/modem/protocol/G02A31.java create mode 100644 ei-library/src/org/tizen/eilib/modem/protocol/G04A01.java create mode 100644 ei-library/src/org/tizen/eilib/modem/protocol/G04A05.java create mode 100644 ei-library/src/org/tizen/eilib/modem/protocol/IntItem.java create mode 100644 ei-library/src/org/tizen/eilib/modem/protocol/ItemType.java create mode 100644 ei-library/src/org/tizen/eilib/modem/protocol/StringUtil.java create mode 100644 ei-library/src/org/tizen/eilib/modem/protocol/StructureGA.java create mode 100644 ei-library/src/org/tizen/eilib/tools/EILogger.java create mode 100644 eventinjector-cli/.classpath create mode 100644 eventinjector-cli/.project create mode 100644 eventinjector-cli/.settings/org.eclipse.jdt.core.prefs create mode 100644 eventinjector-cli/build.xml create mode 100644 eventinjector-cli/src/org/tizen/injector/DeviceList.java create mode 100644 eventinjector-cli/src/org/tizen/injector/EventInjector.java create mode 100644 eventinjector-cli/src/org/tizen/injector/EventRecorder.java create mode 100644 eventinjector-cli/src/org/tizen/injector/GlobalOption.java create mode 100644 eventinjector-cli/src/org/tizen/injector/StringResource.java create mode 100644 eventinjector-cli/src/org/tizen/injector/device/Argument.java create mode 100644 eventinjector-cli/src/org/tizen/injector/device/Command.java create mode 100644 eventinjector-cli/src/org/tizen/injector/device/Device.java create mode 100644 eventinjector-cli/src/org/tizen/injector/device/EmulatorDevice.java create mode 100644 eventinjector-cli/src/org/tizen/injector/device/ExitDevice.java create mode 100644 eventinjector-cli/src/org/tizen/injector/device/HelpDevice.java create mode 100644 eventinjector-cli/src/org/tizen/injector/device/Option.java create mode 100644 eventinjector-cli/src/org/tizen/injector/device/Record.java create mode 100644 eventinjector-cli/src/org/tizen/injector/device/RecordPlay.java create mode 100644 eventinjector-cli/src/org/tizen/injector/device/RecordStart.java create mode 100644 eventinjector-cli/src/org/tizen/injector/device/device/ArgBatteryCharger.java create mode 100644 eventinjector-cli/src/org/tizen/injector/device/device/ArgBatteryLevel.java create mode 100644 eventinjector-cli/src/org/tizen/injector/device/device/Battery.java create mode 100644 eventinjector-cli/src/org/tizen/injector/device/device/BatteryLevel.java create mode 100644 eventinjector-cli/src/org/tizen/injector/device/device/BatterySetCharger.java create mode 100644 eventinjector-cli/src/org/tizen/injector/device/device/EarJack.java create mode 100644 eventinjector-cli/src/org/tizen/injector/device/device/EarJackSet.java create mode 100644 eventinjector-cli/src/org/tizen/injector/device/device/RSSI.java create mode 100644 eventinjector-cli/src/org/tizen/injector/device/device/RssiSet.java create mode 100644 eventinjector-cli/src/org/tizen/injector/device/device/SDCard.java create mode 100644 eventinjector-cli/src/org/tizen/injector/device/device/SDCardMount.java create mode 100644 eventinjector-cli/src/org/tizen/injector/device/device/SDCardStatus.java create mode 100644 eventinjector-cli/src/org/tizen/injector/device/device/SDCardUnmount.java create mode 100644 eventinjector-cli/src/org/tizen/injector/device/device/USBDevice.java create mode 100644 eventinjector-cli/src/org/tizen/injector/device/device/USBDeviceSet.java create mode 100644 eventinjector-cli/src/org/tizen/injector/device/location/Location.java create mode 100644 eventinjector-cli/src/org/tizen/injector/device/location/LocationCoordinate.java create mode 100644 eventinjector-cli/src/org/tizen/injector/device/location/LocationLogFile.java create mode 100644 eventinjector-cli/src/org/tizen/injector/device/location/LocationStop.java create mode 100644 eventinjector-cli/src/org/tizen/injector/device/modem/ArgCallNumber.java create mode 100644 eventinjector-cli/src/org/tizen/injector/device/modem/Call.java create mode 100644 eventinjector-cli/src/org/tizen/injector/device/modem/CallAlert.java create mode 100644 eventinjector-cli/src/org/tizen/injector/device/modem/CallConnect.java create mode 100644 eventinjector-cli/src/org/tizen/injector/device/modem/CallDial.java create mode 100644 eventinjector-cli/src/org/tizen/injector/device/modem/CallDisconnect.java create mode 100644 eventinjector-cli/src/org/tizen/injector/device/modem/CallHidden.java create mode 100644 eventinjector-cli/src/org/tizen/injector/device/modem/SMS.java create mode 100644 eventinjector-cli/src/org/tizen/injector/device/modem/SmsSend.java create mode 100644 eventinjector-cli/src/org/tizen/injector/device/modem/SmsSetStatus.java create mode 100644 eventinjector-cli/src/org/tizen/injector/device/nfc/ArgMessageEventType.java create mode 100644 eventinjector-cli/src/org/tizen/injector/device/nfc/ArgMessageIndex.java create mode 100644 eventinjector-cli/src/org/tizen/injector/device/nfc/ArgNDEFMessage.java create mode 100644 eventinjector-cli/src/org/tizen/injector/device/nfc/ArgNfcTagEvent.java create mode 100644 eventinjector-cli/src/org/tizen/injector/device/nfc/Nfc.java create mode 100644 eventinjector-cli/src/org/tizen/injector/device/nfc/NfcMessage.java create mode 100644 eventinjector-cli/src/org/tizen/injector/device/nfc/NfcP2P.java create mode 100644 eventinjector-cli/src/org/tizen/injector/device/nfc/NfcTag.java create mode 100644 eventinjector-cli/src/org/tizen/injector/device/sensor/ArgAccelValue.java create mode 100644 eventinjector-cli/src/org/tizen/injector/device/sensor/ArgGyroValue.java create mode 100644 eventinjector-cli/src/org/tizen/injector/device/sensor/ArgLightValue.java create mode 100644 eventinjector-cli/src/org/tizen/injector/device/sensor/ArgMagneticValue.java create mode 100644 eventinjector-cli/src/org/tizen/injector/device/sensor/ArgProxiValue.java create mode 100644 eventinjector-cli/src/org/tizen/injector/device/sensor/ArgSensorFilePath.java create mode 100644 eventinjector-cli/src/org/tizen/injector/device/sensor/ArgSensorName.java create mode 100644 eventinjector-cli/src/org/tizen/injector/device/sensor/ArgSensorValue.java create mode 100644 eventinjector-cli/src/org/tizen/injector/device/sensor/Motion.java create mode 100644 eventinjector-cli/src/org/tizen/injector/device/sensor/MotionSet.java create mode 100644 eventinjector-cli/src/org/tizen/injector/device/sensor/Sensor.java create mode 100644 eventinjector-cli/src/org/tizen/injector/device/sensor/SensorFile.java create mode 100644 eventinjector-cli/src/org/tizen/injector/device/sensor/SensorGet.java create mode 100644 eventinjector-cli/src/org/tizen/injector/device/sensor/SensorSet.java create mode 100644 eventinjector-cli/src/org/tizen/injector/exception/ConsoleError.java create mode 100644 eventinjector-cli/src/org/tizen/injector/exception/ConsoleException.java create mode 100644 eventinjector-cli/src/org/tizen/injector/parser/ArgCompletor.java create mode 100644 eventinjector-cli/src/org/tizen/injector/parser/Args.java create mode 100644 eventinjector-cli/src/org/tizen/injector/parser/CommandCompletor.java create mode 100644 eventinjector-cli/src/org/tizen/injector/parser/CommandParser.java create mode 100644 eventinjector-cli/src/org/tizen/injector/parser/DeviceCompletor.java create mode 100644 eventinjector-cli/src/org/tizen/injector/parser/HelpMessage.java create mode 100644 library/COPYING.BSD create mode 100644 library/jline-1.0.jar create mode 100644 package/build.linux create mode 100644 package/changelog create mode 100644 package/pkginfo.manifest create mode 100755 supplement/eventinjector-cli-mac.sh create mode 100755 supplement/eventinjector-cli.bat create mode 100755 supplement/eventinjector-cli.sh create mode 100755 supplement/test.sh diff --git a/AUTHORS b/AUTHORS new file mode 100644 index 0000000..1722483 --- /dev/null +++ b/AUTHORS @@ -0,0 +1,12 @@ +YeongKyoon Lee +DaiYoung Kim +SeokYeon Hwang +SangJin Kim +KiTae Kim +JinHyung Jo +SungMin Ha +MunKyu Im +JiHye Kim +GiWoong Kim +SooYoung Ha +HyunGoo Kang diff --git a/LICENSE.APLv2 b/LICENSE.APLv2 new file mode 100644 index 0000000..1d4a865 --- /dev/null +++ b/LICENSE.APLv2 @@ -0,0 +1,206 @@ +Copyright (c) 2013 Samsung Electronics Co., Ltd. All rights reserved. + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + + diff --git a/NOTICE b/NOTICE new file mode 100644 index 0000000..04c1aec --- /dev/null +++ b/NOTICE @@ -0,0 +1,3 @@ +Copyright (c) 2013 Samsung Electronics Co., Ltd. All rights reserved. +Except as noted, this software is licensed under Apache License, Version 2. +Please, see the LICENSE.APLv2 file for Apache License Version 2, terms and conditions. diff --git a/ei-library/.classpath b/ei-library/.classpath new file mode 100644 index 0000000..0825831 --- /dev/null +++ b/ei-library/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/ei-library/.project b/ei-library/.project new file mode 100644 index 0000000..d326e1d --- /dev/null +++ b/ei-library/.project @@ -0,0 +1,17 @@ + + + EILibrary + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/ei-library/.settings/org.eclipse.jdt.core.prefs b/ei-library/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..e5232dd --- /dev/null +++ b/ei-library/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,12 @@ +#Mon Sep 24 13:49:36 KST 2012 +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.6 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.6 diff --git a/ei-library/build.xml b/ei-library/build.xml new file mode 100644 index 0000000..c716c21 --- /dev/null +++ b/ei-library/build.xml @@ -0,0 +1,67 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ei-library/src/org/tizen/eilib/connection/ConnectionToEmulator.java b/ei-library/src/org/tizen/eilib/connection/ConnectionToEmulator.java new file mode 100644 index 0000000..ea79ea2 --- /dev/null +++ b/ei-library/src/org/tizen/eilib/connection/ConnectionToEmulator.java @@ -0,0 +1,403 @@ +/* + * EventInjector Library + * + * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * SooYoung Ha + * JiHye Kim + * YeongKyoon Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + +package org.tizen.eilib.connection; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; + +import org.tizen.eilib.connection.message.EventMessage; +import org.tizen.eilib.connection.message.EventType; +import org.tizen.eilib.connection.message.GroupID; +import org.tizen.eilib.connection.EmulatorList; +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.InjectorLibraryException; +import org.tizen.eilib.exception.EILibError; +import org.tizen.eilib.tools.EILogger; +import org.tizen.sdblib.MultiLineReceiver; +import org.tizen.sdblib.SdbCommandRejectedException; +import org.tizen.sdblib.ShellCommandUnresponsiveException; +import org.tizen.sdblib.TimeoutException; +/** + * Instances of this class manages communication with emulator and event injector . + * + */ +public class ConnectionToEmulator { + /** + * Socket to connect with emulator. + */ + private EventSocket socket = null; + + /** + * Receiver of event from the emulator. + */ + private HashMap receiverMap; + + /** + * Running emulator list. + */ + private EmulatorList emList; + + /** + * Current connecting emulator. + */ + private Emulator currentEmulator = null; + + private static String EMULD_VERSION = "0.2.23"; + + /** + * Constructs a new instance of this class make event map and create socket + */ + public ConnectionToEmulator() { + receiverMap = new HashMap(); + addEventReceiver(GroupID.STATUS, new StatusEventReceiver()); + + socket = new EventSocket(receiverMap); + + emList = EmulatorList.getInstance(); + } + + /** + * Add event receiver. + * You can register the event receiver that can receive the message from the emulator. + * @param gID GroupID value, + * @param receiver + */ + public void addEventReceiver(int gID, AbstractEventReceiver receiver) { + receiverMap.put((Integer)gID, receiver); + } + + /** + * Remove event receiver + * + * @param gID GroupID value + */ + public void removeEventReceiver(int gID) { + receiverMap.remove((Integer)gID); + } + + /** + * Find event receiver + * @param gID GroupID value + * @return event receiver + */ + public AbstractEventReceiver findEventReceiver(int gID) { + return receiverMap.get(gID); + } + + /** + * Set IP address. + * Default value is local host (127.0.0.1) + * + * @param ip ip address of emulator (Format : xxx.xxx.xxx.xxx) + */ + public void setIPAdderss(String ip) { + socket.setIP(ip); + } + + /** + * Set port number + * + * Note : Before connect to emulator, set port number. + * If port number is 0 (default), to connect to emulator is failed. + * + * @param port + */ + public void setPort(int port) { + socket.setPort(port); + } + + /** + * Connect to emulator + * + * @exception IOException
    + *
  • If failed to open socket
  • + * @exception UnknownHostException
      + *
    • If port number is not initialized.
    • + * @exception InjectorLibraryException + * + * @return result of connect to emulator. + * @throws InjectorLibraryException + */ + public boolean connect() throws IOException, InjectorLibraryException { + return connect(0); + } + + /** + * Connect to emulator + * + * @exception IOException
        + *
      • If failed to open socket
      • + * @exception UnknownHostException
          + *
        • If port number is not initialized.
        • + * @exception InjectorLibraryException + * + * @param port + * @return result of connect to emulator. + * @throws InjectorLibraryException + */ + public boolean connect(int port) throws IOException, InjectorLibraryException { + if (socket.isConnected()) { + socket.disconnect(); + } + + boolean result = false; + if (port == 0) { + if (socket.getPort() == 0) { + ArrayList list = emList.getEmulatorList(); + if(list.size() == 0) { + throw new InjectorLibraryException(EILibError.EmulatorNotExist); + } else if (list.size() > 1) { + throw new InjectorLibraryException(EILibError.EmulatorNotOne); + } else { + socket.setPort(list.get(0).getPort()); + } + } + result = socket.connect(); + } else { + result = socket.connect(port); + } + + if (result) { + //sendModemInitialize(); + //sendInitializeMessage(); + + int socketPort = socket.getPort(); + ArrayList 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 final static String shellCmd = "rpm -q emuld"; + private String shellResult = null; + private void checkEmuldVersion() throws InjectorLibraryException { + shellResult = null; + String errorMessage = null; + + try { + currentEmulator.getDevice().executeShellCommand(shellCmd, new MultiLineReceiver() { + @Override + 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) { + //emuld-0.2.20-1.1.i586 + 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; + } + + /** + * Disconnect to emulator + * + * @return result + */ + public boolean disconnect() { + return socket.disconnect(); + } + + /** + * Return current state of connection to emulator. + * @return + */ + public boolean isConnect() { + return socket.isConnected(); + } + + public void terminate() { + if (socket.isConnected()) { + socket.disconnect(); + } + } + + private EventInjectorCreator creator = null; + + /** + * Setting the relationship between the 'EventInjectorCreator' and 'ConnectionToEmualtor' + * + * @param creator EventInjectorCreator's instance + */ + public void setEventInjectorCreator(EventInjectorCreator creator) { + this.creator = creator; + } + + /** + * Send message to emulator + * @param message + * @return + * @throws IOException + * @throws ConnectionException + */ + public boolean sendMessage(EventMessage message) throws IOException, ConnectionException { + return socket.sendMessage(message); + } + + private EventMessage initMessage = null; + private byte[] initMsgHeader1 = {0x04, 0x00, 0x40, 0x41}; + private byte[] initMsgData1 = {0x16, 0x00, 0x00, 0x00}; + private byte[] initMsgHeader2 = {0x00, 0x00, 0x40, 0x47}; + private byte[] initMsgData2 = {0x00, 0x00, 0x40, 0x42}; + + private byte[] initAskData = {0x00, 0x00, 0x11, 0x5b}; + + /** + * Send initialize message. Receive call list message from the vmodem. + * + * @throws IOException + * @throws InjectorLibraryException + * @throws ConnectionException + */ + public void sendInitializeMessage() throws IOException, ConnectionException { + if (!socket.isConnected()) { + // TODO : error + EILogger.getLogger().warning("Socket is disconnected.."); + return; + } + + if (initMessage == null) { + initMessage = new EventMessage(128); + initMessage.setEventTypeBuffer(EventType.TELEPHONY); + } + + // #1 + initMessage.clear(); + initMessage.getHeaderBuffer().put(initAskData); + sendMessage(initMessage); + } + + /** + * Send message that initialize the vmodem. + * + * @throws IOException + * @throws InjectorLibraryException + * @throws ConnectionException + */ + public void sendModemInitialize() throws IOException, ConnectionException { + if (!socket.isConnected()) { + // TODO : error + EILogger.getLogger().warning("Socket is disconnected.."); + } + + if (initMessage == null) { + initMessage = new EventMessage(128); + initMessage.setEventTypeBuffer(EventType.TELEPHONY); + } + + // #1 + initMessage.clear(); + initMessage.getHeaderBuffer().put(initMsgHeader1); + initMessage.getDataBuffer().put(initMsgData1); + sendMessage(initMessage); + + // #2 + initMessage.clear(); + initMessage.getHeaderBuffer().put(initMsgHeader2); + initMessage.getDataBuffer().put(initMsgData2); + sendMessage(initMessage); + } + + /** + * Return running emulator list + * @return array of emulator. + */ + public ArrayList getEmulatorList() { + return emList.getEmulatorList(); + } + + /** + * Return current connection emulator. + * @return emulator If running emulator does not exist, null is returned. + */ + public Emulator getCurrentEmulator() { + if (!isConnect()) { + return null; + } + if (emList == null) { + return null; + } + + /* + int socketPort = socket.getPort(); + ArrayList emulators = emList.getEmulatorList(); + for (Emulator e : emulators) { + if (e.getPort() == socketPort) { + return e; + } + } + */ + return currentEmulator; + } + + /** + * + * @param listener + */ + public void addDeviceChangeListener(IEmulatorChangeListener listener) { + emList.setChangeListener(listener); + } +} diff --git a/ei-library/src/org/tizen/eilib/connection/Emulator.java b/ei-library/src/org/tizen/eilib/connection/Emulator.java new file mode 100644 index 0000000..401e2dd --- /dev/null +++ b/ei-library/src/org/tizen/eilib/connection/Emulator.java @@ -0,0 +1,378 @@ +/* + * EventInjector Library + * + * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * SooYoung Ha + * JiHye Kim + * YeongKyoon Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + +package org.tizen.eilib.connection; + +import java.io.IOException; + +import org.tizen.sdblib.FileListingService; +import org.tizen.sdblib.IDevice; +import org.tizen.sdblib.IShellOutputReceiver; +import org.tizen.sdblib.LogReceiver; +import org.tizen.sdblib.SdbCommandRejectedException; +import org.tizen.sdblib.SdbShellProcess; +import org.tizen.sdblib.ShellCommandUnresponsiveException; +import org.tizen.sdblib.SyncService; +import org.tizen.sdblib.TimeoutException; +import org.tizen.sdblib.IDevice.DeviceState; + +/** + * This class have IDevice and additional feather. + * + */ +public class Emulator { + private IDevice device; + private int port; + private boolean isMounted; + private String SDCardName; + + /** + * + * @param device + */ + public Emulator(IDevice device) { + this.device = device; + setPort(Integer.parseInt(device.getSerialNumber().substring(9)) + 3); + isMounted = false; + SDCardName = ""; + } + + /** + * Return emulator's description + * emulator name + serial number + port number + */ + @Override + public String toString() { + return device.getDeviceName() + " " + device.getSerialNumber() + " " + Integer.toString(port); + } + + /** + * If two emulators have the same names, determines that they are same. + */ + @Override + public boolean equals(Object obj) { + if (!(obj instanceof Emulator)) { + return false; + } + + if (((Emulator)obj).getDeviceName().equals(getDeviceName())) { + return true; + } + return false; + } + + /** + * Return IDevice object + * @return + */ + public IDevice getDevice() { + return device; + } + + /** + * + * @param device + */ + public void setDevice(IDevice device) { + this.device = device; + setPort(Integer.parseInt(device.getSerialNumber().substring(9)) + 3); + } + + /** + * Return emulator's emulator daemon port + * @return + */ + public int getPort() { + return port; + } + + /** + * + * @param port emulator daemon port + */ + public void setPort(int port) { + this.port = port; + } + + /** + * Return SD card mount status + * @return + */ + public boolean isMounted() { + return isMounted; + } + + /** + * + * @param isMounted true : mount, false : unmount + */ + public void setMounted(boolean isMounted) { + this.isMounted = isMounted; + } + + /** + * Return mounted SD card name + * @return + */ + public String getSDCardName() { + return SDCardName; + } + + public void setSDCardName(String SDCardName) { + this.SDCardName = SDCardName; + } + + + /** + * Returns the serial number of the device. + */ + public String getSerialNumber() { + return device.getSerialNumber(); + } + + /** + * Returns the name of the device. + */ + public String getDeviceName(){ + return device.getDeviceName(); + } + + /** + * Returns the state of the device. + * @return + */ + public DeviceState getState() { + return device.getState(); + } + + /** + * Returns if the device is ready. + * + * @return true if {@link #getState()} returns {@link DeviceState#ONLINE}. + */ + public boolean isOnline() { + return device.isOnline(); + } + + /** + * Returns true if the device is an emulator. + */ + public boolean isEmulator() { + return device.isEmulator(); + } + + /** + * Returns if the device is offline. + * + * @return true if {@link #getState()} returns {@link DeviceState#OFFLINE}. + */ + public boolean isOffline() { + return device.isOffline(); + } + + /** + * Returns a {@link SyncService} object to push / pull files to and from the device. + * + * @return null if the SyncService couldn't be created. This can happen if sdb + * refuse to open the connection because the {@link IDevice} is invalid + * (or got disconnected). + * @throws TimeoutException in case of timeout on the connection. + * @throws SdbCommandRejectedException if sdb rejects the command + * @throws IOException if the connection with sdb failed. + */ + public SyncService getSyncService() + throws TimeoutException, SdbCommandRejectedException, IOException { + return device.getSyncService(); + } + + /** + * Returns a {@link FileListingService} for this device. + */ + public FileListingService getFileListingService() { + return device.getFileListingService(); + } + + /** + * Executes a shell command on the device and return SdbShellProcess + * + * @param command the shell command to execute + * @throws IOException in case of I/O error on the connection. + * + * @see SdbShellProcess + */ + public SdbShellProcess executeShellCommand(String command) throws IOException { + return device.executeShellCommand(command); + } + + /** + * Executes a shell command on the device, and sends the result to a receiver + *

          This is similar to calling + * executeShellCommand(command, receiver, SdbPreferences.getTimeOut()). + * + * @param command the shell command to execute + * @param receiver the {@link IShellOutputReceiver} that will receives the output of the shell + * command + * @throws TimeoutException in case of timeout on the connection. + * @throws SdbCommandRejectedException if sdb rejects the command + * @throws ShellCommandUnresponsiveException in case the shell command doesn't send output + * for a given time. + * @throws IOException in case of I/O error on the connection. + * + * @see #executeShellCommand(String, IShellOutputReceiver, int) + * @see SdbPreferences#getTimeOut() + */ + public void executeShellCommand(String command, IShellOutputReceiver receiver) + throws TimeoutException, SdbCommandRejectedException, ShellCommandUnresponsiveException, + IOException { + device.executeShellCommand(command, receiver); + } + + /** + * Executes a shell command on the device, and sends the result to a receiver. + *

          maxTimeToOutputResponse is used as a maximum waiting time when expecting the + * command output from the device.
          + * At any time, if the shell command does not output anything for a period longer than + * maxTimeToOutputResponse, then the method will throw + * {@link ShellCommandUnresponsiveException}. + *

          For commands like log output, a maxTimeToOutputResponse value of 0, meaning + * that the method will never throw and will block until the receiver's + * {@link IShellOutputReceiver#isCancelled()} returns true, should be + * used. + * + * @param command the shell command to execute + * @param receiver the {@link IShellOutputReceiver} that will receives the output of the shell + * command + * @param maxTimeToOutputResponse the maximum amount of time during which the command is allowed + * to not output any response. A value of 0 means the method will wait forever + * (until the receiver cancels the execution) for command output and + * never throw. + * @throws TimeoutException in case of timeout on the connection when sending the command. + * @throws SdbCommandRejectedException if sdb rejects the command. + * @throws ShellCommandUnresponsiveException in case the shell command doesn't send any output + * for a period longer than maxTimeToOutputResponse. + * @throws IOException in case of I/O error on the connection. + * + * @see SdbPreferences#getTimeOut() + */ + public void executeShellCommand(String command, IShellOutputReceiver receiver, + int maxTimeToOutputResponse) + throws TimeoutException, SdbCommandRejectedException, ShellCommandUnresponsiveException, + IOException { + device.executeShellCommand(command, receiver, maxTimeToOutputResponse); + } + + /** + * Runs the event log service and outputs the event log to the {@link LogReceiver}. + *

          This call is blocking until {@link LogReceiver#isCancelled()} returns true. + * @param receiver the receiver to receive the event log entries. + * @throws TimeoutException in case of timeout on the connection. This can only be thrown if the + * timeout happens during setup. Once logs start being received, no timeout will occur as it's + * not possible to detect a difference between no log and timeout. + * @throws SdbCommandRejectedException if sdb rejects the command + * @throws IOException in case of I/O error on the connection. + */ + public void runEventLogService(LogReceiver receiver) + throws TimeoutException, SdbCommandRejectedException, IOException { + device.runEventLogService(receiver); + } + + /** + * Runs the log service for the given log and outputs the log to the {@link LogReceiver}. + *

          This call is blocking until {@link LogReceiver#isCancelled()} returns true. + * + * @param logname the logname of the log to read from. + * @param receiver the receiver to receive the event log entries. + * @throws TimeoutException in case of timeout on the connection. This can only be thrown if the + * timeout happens during setup. Once logs start being received, no timeout will + * occur as it's not possible to detect a difference between no log and timeout. + * @throws SdbCommandRejectedException if sdb rejects the command + * @throws IOException in case of I/O error on the connection. + */ + public void runLogService(String logname, LogReceiver receiver) + throws TimeoutException, SdbCommandRejectedException, IOException { + device.runLogService(logname, receiver); + } + + /** + * Creates a port forwarding between a local and a remote port. + * + * @param localPort the local port to forward + * @param remotePort the remote port. + * @return true if success. + * @throws TimeoutException in case of timeout on the connection. + * @throws SdbCommandRejectedException if sdb rejects the command + * @throws IOException in case of I/O error on the connection. + */ + public void createForward(int localPort, int remotePort) + throws TimeoutException, SdbCommandRejectedException, IOException { + device.createForward(localPort, remotePort); + } + + /** + * Removes a port forwarding between a local and a remote port. + * + * @param localPort the local port to forward + * @param remotePort the remote port. + * @return true if success. + * @throws TimeoutException in case of timeout on the connection. + * @throws SdbCommandRejectedException if sdb rejects the command + * @throws IOException in case of I/O error on the connection. + */ + public void removeForward(int localPort, int remotePort) + throws TimeoutException, SdbCommandRejectedException, IOException { + device.removeForward(localPort, remotePort); + } + + /** + * Pushes a file to device + * + * @param localFilePath the absolute path to file on local host + * @return {@link String} destination path on device for file + * @throws TimeoutException in case of timeout on the connection. + * @throws SdbCommandRejectedException if sdb rejects the command + * @throws IOException in case of I/O error on the connection. + */ + public String syncPackageToDevice(String localFilePath) + throws TimeoutException, SdbCommandRejectedException, IOException { + return device.syncPackageToDevice(localFilePath); + } + + /** + * Removes a file from device. + * + * @param remoteFilePath path on device of file to remove + * @throws TimeoutException in case of timeout on the connection. + * @throws SdbCommandRejectedException if sdb rejects the command + * @throws ShellCommandUnresponsiveException if the device didn't respond for long time when + * performing the action. + * @throws IOException if file removal failed + */ + public void removeRemotePackage(String remoteFilePath) + throws TimeoutException, SdbCommandRejectedException, ShellCommandUnresponsiveException, + IOException { + device.removeRemotePackage(remoteFilePath); + } +} diff --git a/ei-library/src/org/tizen/eilib/connection/EmulatorList.java b/ei-library/src/org/tizen/eilib/connection/EmulatorList.java new file mode 100644 index 0000000..15bae62 --- /dev/null +++ b/ei-library/src/org/tizen/eilib/connection/EmulatorList.java @@ -0,0 +1,157 @@ +/* + * EventInjector Library + * + * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * SooYoung Ha + * JiHye Kim + * YeongKyoon Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + + +package org.tizen.eilib.connection; + +import java.util.ArrayList; + +import org.tizen.sdblib.IDevice; +import org.tizen.sdblib.SmartDevelopmentBridge; +import org.tizen.sdblib.SmartDevelopmentBridge.IDeviceChangeListener; + +/** + * Control running emulator list + * + */ +public class EmulatorList implements IDeviceChangeListener { + private static EmulatorList instance = null; + private final ArrayList emulatorList = new ArrayList(); + + /** + * Return instance of EmulatorList. + * To generate 'EmualtorList' instance is impossible. + * @return + */ + public static EmulatorList getInstance() { + if (instance == null) { + instance = new EmulatorList(); + } + + return instance; + } + + /** + * + * @throws InterruptedException + */ + private EmulatorList() { + /* + IDevice[] devices = null; + if (sdbBridge != null) { + devices = sdbBridge.getDevices(); + + if (devices != null && devices.length != 0) { + for (IDevice device : devices) { + this.deviceConnected(device); + } + } + } + */ + } + + private boolean init = false; + /** + * Return list of running emulators. + * @return + */ + public ArrayList getEmulatorList() { + if (!init) { + SmartDevelopmentBridge.init(); + SmartDevelopmentBridge.createBridge(SDKInstallPathConfig.getSDBPath(), true); + + SmartDevelopmentBridge sdbBridge = SmartDevelopmentBridge.getBridge(); + SmartDevelopmentBridge.addDeviceChangeListener(this); + + while (!sdbBridge.hasInitialDeviceList()) { + synchronized(this) { + try { + this.wait(1000); + } catch (InterruptedException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + } + init = true; + } + return emulatorList; + } + + private IEmulatorChangeListener listener = null; + public void setChangeListener(IEmulatorChangeListener listener) { + this.listener = listener; + } + + /** + * + */ + @Override + public void deviceConnected(IDevice device) { + if (device.isOffline()) { + return; + } + + if (!device.isEmulator()) { + return; + } + + Emulator em = new Emulator(device); + emulatorList.add(em); + + if (listener != null) { + listener.deviceConnected(em); + } + } + + /** + * + */ + @Override + public void deviceDisconnected(IDevice device) { + for (Emulator e : emulatorList) { + if (e.getDevice().equals(device)) { + if (listener != null) { + listener.deviceDisconnected(e); + } + + emulatorList.remove(e); + break; + } + } + } + + /** + * + */ + @Override + public void deviceChanged(IDevice device, int changeMask) { + if (changeMask == 1) + { + deviceConnected(device); + } + } +} diff --git a/ei-library/src/org/tizen/eilib/connection/EventReceiver.java b/ei-library/src/org/tizen/eilib/connection/EventReceiver.java new file mode 100644 index 0000000..4544476 --- /dev/null +++ b/ei-library/src/org/tizen/eilib/connection/EventReceiver.java @@ -0,0 +1,124 @@ +/* + * EventInjector Library + * + * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * SooYoung Ha + * JiHye Kim + * YeongKyoon Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + + +package org.tizen.eilib.connection; + +import java.io.IOException; +import java.nio.channels.SocketChannel; +import java.util.HashMap; + +import org.tizen.eilib.connection.message.EventMessage; +import org.tizen.eilib.connection.message.GroupID; +import org.tizen.eilib.events.receiver.AbstractEventReceiver; +import org.tizen.eilib.tools.EILogger; + +class EventReceiver extends Thread { + private SocketChannel socket; + private HashMap receiverMap; + public EventReceiver(SocketChannel socket, HashMap receiverMap) { + this.socket = socket; + this.receiverMap = receiverMap; + this.setDaemon(true); + this.setName("EventReceiver"); + } + + public void run() { + while (socket.isConnected() && this.isAlive() && !this.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 AbstractEventReceiver receiver; + private void forwardingMessage(final EventMessage msg) { + switch(msg.getEventHeader().getGroupID()) { + case GroupID.CALL: + case GroupID.SUPS: + case GroupID.SMS: + case GroupID.SDCARD: + case GroupID.STATUS: + receiver = receiverMap.get(msg.getEventHeader().getGroupID()); + break; + 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()); + } + } +} + +class ExecutorThread extends Thread { + private EventMessage message = null; + private AbstractEventReceiver receiver = null; + + ExecutorThread(AbstractEventReceiver receiver, EventMessage msg) { + this.receiver = receiver; + this.message = msg; + this.setDaemon(true); + this.setName(receiver.getName() + " receiver"); + } + + public void run() { + receiver.run(message); + } +} \ No newline at end of file diff --git a/ei-library/src/org/tizen/eilib/connection/EventSocket.java b/ei-library/src/org/tizen/eilib/connection/EventSocket.java new file mode 100644 index 0000000..5808c67 --- /dev/null +++ b/ei-library/src/org/tizen/eilib/connection/EventSocket.java @@ -0,0 +1,149 @@ +/* + * EventInjector Library + * + * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * SooYoung Ha + * JiHye Kim + * YeongKyoon Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + + +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 org.tizen.eilib.connection.message.EventMessage; +import org.tizen.eilib.events.receiver.AbstractEventReceiver; +import org.tizen.eilib.tools.EILogger; +import org.tizen.eilib.exception.ConnectionException; +import org.tizen.eilib.exception.EILibError; + +public class EventSocket { + private static final String LocalHost = "127.0.0.1"; + private int port = 0; + private String ip = LocalHost; + private SocketChannel socket; + + private EventReceiver receiver = null; + private HashMap receiverMap = null; + public EventSocket(HashMap receiverMap) { + this.receiverMap = receiverMap; + } + + public boolean connect() throws IOException { + return connect(this.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."); + } else { + this.port = port; + } + + if (socket != null) { + disconnect(); + } + + SocketAddress addr = new InetSocketAddress(ip, port); + try { + socket = SocketChannel.open(addr); + } catch (IOException e) { + e.printStackTrace(); + return false; + } + + // Start Receiver Thread + 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); + } else { + EILogger.getLogger().warning(e.getMessage()); + } + throw e; + } + + return true; + } +} diff --git a/ei-library/src/org/tizen/eilib/connection/IEmulatorChangeListener.java b/ei-library/src/org/tizen/eilib/connection/IEmulatorChangeListener.java new file mode 100644 index 0000000..005073a --- /dev/null +++ b/ei-library/src/org/tizen/eilib/connection/IEmulatorChangeListener.java @@ -0,0 +1,35 @@ +/* + * EventInjector Library + * + * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * SooYoung Ha + * JiHye Kim + * YeongKyoon Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + +package org.tizen.eilib.connection; + +public abstract class IEmulatorChangeListener { + public abstract void deviceChanged(Emulator arg0, int arg1); + + public abstract void deviceConnected(Emulator arg0); + + public abstract void deviceDisconnected(Emulator arg0); +} \ No newline at end of file diff --git a/ei-library/src/org/tizen/eilib/connection/SDKInstallPathConfig.java b/ei-library/src/org/tizen/eilib/connection/SDKInstallPathConfig.java new file mode 100644 index 0000000..c06490b --- /dev/null +++ b/ei-library/src/org/tizen/eilib/connection/SDKInstallPathConfig.java @@ -0,0 +1,186 @@ +/* + * EventInjector Library + * + * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * SooYoung Ha + * JiHye Kim + * YeongKyoon Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + +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 org.tizen.eilib.tools.EILogger; + +enum OSType { + WINDOWS, LINUX, MAC; +} + +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 final static String SDKSUFFIX = DIR_SDK_DATA + File.separatorChar + "tizensdkpath"; + + // Registry Key + 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\""; + // Value Column + 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(REGISTRY_PATH_OF_SHELL_FOLDER,REGISTRY_LOCAL_APP_DATA_OF_SHELL_FOLDER) ; + break; + case LINUX: + case MAC: + defaultHomePath = System.getProperty("user.home"); + break; + default: + // TODO : error System.getProperty("os.name") + " is not supported currently." + EILogger.getLogger().warning(System.getProperty("os.name") + " is not supported currently."); + break; + } + + 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."); + // System.exit(0); + } + } + + 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")); + } + } 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(); + } + } + } + + return (contents != null ? contents.toString().trim() : null); + } + + private static String getRegistryValue(String node, String key) { + if (osType != OSType.WINDOWS) { + return null; + } + + BufferedReader br = null; + String 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(); + } + } + } catch (IOException e) { + e.printStackTrace(); + } finally { + if (br != null) { + try { + br.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + + return value; + } + + public static String getSDKPath() { + return sdkInstallPath; + } + + public static String getSDBPath() { + if (sdbPath == null && sdkInstallPath != null) { + sdbPath = getSDKPath() + File.separator + DIR_TOOLS + + File.separator + (osType == OSType.WINDOWS ? "sdb.exe" : "sdb"); + } + + return sdbPath; + } + +} \ No newline at end of file diff --git a/ei-library/src/org/tizen/eilib/connection/message/ActionID.java b/ei-library/src/org/tizen/eilib/connection/message/ActionID.java new file mode 100644 index 0000000..1ae67bf --- /dev/null +++ b/ei-library/src/org/tizen/eilib/connection/message/ActionID.java @@ -0,0 +1,51 @@ +/* + * EventInjector Library + * + * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * SooYoung Ha + * JiHye Kim + * YeongKyoon Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + + +package org.tizen.eilib.connection.message; + +public enum ActionID { + + // DEVICE 100 ~ + BATTERY_LEVEL(100), BATTERY_CHARGER(101), USB_STATUS(102), + EARJACK_STATUS(103), RSSI_LEVEL(104), + // SENSOR 110 ~ + ACCEL_VALUE(110), GYRO_VALUE(111), MAG_VALUE(112), + LIGHT_VALUE(113), PROXI_VALUE(114), MOTION_VALUE(115), + + // ETC 120 ~ + LOCATION_STATUS(120), NFC_STATUS(121); + + int id; + + ActionID(int id) { + this.id = id; + } + + public int getId() { + return id; + } +} \ No newline at end of file diff --git a/ei-library/src/org/tizen/eilib/connection/message/EventHeader.java b/ei-library/src/org/tizen/eilib/connection/message/EventHeader.java new file mode 100644 index 0000000..fb0f275 --- /dev/null +++ b/ei-library/src/org/tizen/eilib/connection/message/EventHeader.java @@ -0,0 +1,99 @@ +/* + * EventInjector Library + * + * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * SooYoung Ha + * JiHye Kim + * YeongKyoon Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + +package org.tizen.eilib.connection.message; + + +/** + * This class is EventMessage's header. + * + */ +public class EventHeader { + private short length = 0; + private int groupID = 0; + private int actionID = 0; + + /** + * Return event data's length + * @return + */ + public short getLength() { + return length; + } + + /** + * Set event data's length + * + * @param length + */ + public void setLength(short length) { + this.length = length; + } + + /** + * Return event's group ID + * + * @return + * + * @see GroupID + */ + public int getGroupID() { + return groupID; + } + + /** + * Set event's group ID + * + * @param groupID + * + * @see GroupID + */ + public void setGroupID(int groupID) { + this.groupID = groupID; + } + + /** + * Return event's action ID + * + * @return + * + * @see ActionID + */ + public int getActionID() { + return actionID; + } + + /** + * Set event's action ID + * + * @param actionID + * + * @see ActionID + */ + public void setActionID(int actionID) { + this.actionID = actionID; + } +} diff --git a/ei-library/src/org/tizen/eilib/connection/message/EventMessage.java b/ei-library/src/org/tizen/eilib/connection/message/EventMessage.java new file mode 100644 index 0000000..c2cc621 --- /dev/null +++ b/ei-library/src/org/tizen/eilib/connection/message/EventMessage.java @@ -0,0 +1,241 @@ +/* + * EventInjector Library + * + * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * SooYoung Ha + * JiHye Kim + * YeongKyoon Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + + +package org.tizen.eilib.connection.message; + +import java.nio.ByteBuffer; +import java.nio.ByteOrder; + + +/** + * This class is used to communicate with emulator. + * + */ +public class EventMessage { + private static final int HEADER_SIZE = 4; + private static final int MAX_DATA_SIZE = 4096; + private int maxDataLength = MAX_DATA_SIZE; + + private EventHeader eventHeader = null; + + private ByteBuffer message = null; + private ByteBuffer type = null; + private ByteBuffer header = null; + private ByteBuffer data = null; + + private int messageLength = 0; + + /** + * Data size is set default max size. + * + */ + public EventMessage() { + this(MAX_DATA_SIZE); + } + + /** + * + * @param size Max size of data + */ + public EventMessage(int size) { + eventHeader = new EventHeader(); + + initEventMessage(size); + } + + /** + * Set EventHeader (length, groupID, actionID) using header buffer + * + * @see EventHeader + */ + // receiver + public void setEventHeader() { + header.clear(); + eventHeader.setLength(header.getShort()); + eventHeader.setGroupID(header.get() & 0xff); + eventHeader.setActionID(header.get() & 0xff); + } + + /** + * Return event header. + * + * @return + * + * @see EventHeader + */ + public EventHeader getEventHeader() { + return eventHeader; + } + + + /** + * Return event type buffer. + * TODO : This buffer is used only while sending message. + * @return + */ + public ByteBuffer getEventTypeBuffer() { + return type; + } + + /** + * Return header buffer. + * This buffer size is 4 + * Note : Check buffer's position before using buffer. + * + * @return header buffer + */ + public ByteBuffer getHeaderBuffer() { + return header; + } + + /** + * Return data buffer + * This buffer is main message data. + * Length variable of EventHeader is this buffer's size. + * Note : Check buffer's position before using buffer. + * + * @return data buffer + */ + public ByteBuffer getDataBuffer() { + return data; + } + + /** + * Return data buffer's capacity. + * You can change buffer capacity using initEventMessage(). + * @return + */ + public int getMaxDataBufferSize() { + return maxDataLength; + } + + /** + * Return data buffer's start position + * @return + */ + public int getDataBufferOffset() { + return EventType.ID_LENGH + HEADER_SIZE; + } + + /** + * + * @param id + * + * @see EventType + */ + public void setEventTypeBuffer(EventType id) { + type.position(0); + type.put(id.getType()); + } + + /** + * + * @param h + * + * @see EventHeader + */ + public void setHeaderBuffer(EventHeader h) { + header.clear(); + header.putShort(h.getLength()); + header.put(((Integer)h.getGroupID()).byteValue()); + header.put(((Integer)h.getActionID()).byteValue()); + } + + /** + * Return message buffer + * This buffer is event type buffer + header buffer + data buffer + * The position of this buffer is always zero whenever the function is called. + * This buffer is used wnen sending the message to the emulator. + * When you write data to the buffer, use each buffer(type, header, data). + * + * @return message buffer + */ + public ByteBuffer getMessage() { + setMessageLength(); + message.position(messageLength); + message.flip(); + message.position(0); + return message; + } + + /** + * Determine the length of a message before sending the message. + * Message length : event type buffer size + header buffer size + data buffer size + */ + public void setMessageLength() { + messageLength = EventType.ID_LENGH + HEADER_SIZE + data.position(); + } + + /** + * + * @return message buffer's length + */ + public int getMessageLength() { + setMessageLength(); + return messageLength; + } + + /** + * Message buffer clear. + * Initialize message buffer prior to use, when reusing 'EventMessage' + * Note : 'Event Type' buffer is not initialized. + */ + public void clear() { + message.clear(); + header.clear(); + data.clear(); + } + + /** + * This class initialize EventMessage class. + * Previously used memory space is discarded and a new memory space is alloacted. + * + * @param size Max size of data + */ + public void initEventMessage(int size) { + if (size >= 0) { + maxDataLength = size; + } + message = ByteBuffer.allocate(EventType.ID_LENGH + HEADER_SIZE + maxDataLength); + message.order(ByteOrder.LITTLE_ENDIAN); + + // sender only use this buffer. + message.limit(EventType.ID_LENGH); + type = message.slice(); + + message.position(message.limit()); + message.limit(message.position() + HEADER_SIZE); + header = message.slice(); + header.order(ByteOrder.LITTLE_ENDIAN); + + message.position(message.limit()); + message.limit(message.capacity()); + data = message.slice(); + data.order(ByteOrder.LITTLE_ENDIAN); + } + +} diff --git a/ei-library/src/org/tizen/eilib/connection/message/EventType.java b/ei-library/src/org/tizen/eilib/connection/message/EventType.java new file mode 100644 index 0000000..9a9b366 --- /dev/null +++ b/ei-library/src/org/tizen/eilib/connection/message/EventType.java @@ -0,0 +1,50 @@ +/* + * EventInjector Library + * + * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * SooYoung Ha + * JiHye Kim + * YeongKyoon Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + +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; + + EventType(String type) { + // ID_LENGTH = 10; + this.type = ByteBuffer.allocate(10); + for (byte c : type.getBytes()) { + this.type.put(c); + } + } + + public ByteBuffer getType() { + this.type.clear(); + return type; + } +} diff --git a/ei-library/src/org/tizen/eilib/connection/message/GroupID.java b/ei-library/src/org/tizen/eilib/connection/message/GroupID.java new file mode 100644 index 0000000..c72089e --- /dev/null +++ b/ei-library/src/org/tizen/eilib/connection/message/GroupID.java @@ -0,0 +1,36 @@ +/* + * EventInjector Library + * + * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * SooYoung Ha + * JiHye Kim + * YeongKyoon Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + + +package org.tizen.eilib.connection.message; + +public class GroupID { + public static final int CALL = 1; + public static final int SUPS = 3; // GSM_SUPS (CALL) + public static final int SMS = 4; + public static final int SDCARD = 11; + public static final int STATUS = 15; +} diff --git a/ei-library/src/org/tizen/eilib/events/AbstractEventInjector.java b/ei-library/src/org/tizen/eilib/events/AbstractEventInjector.java new file mode 100644 index 0000000..a0e0eeb --- /dev/null +++ b/ei-library/src/org/tizen/eilib/events/AbstractEventInjector.java @@ -0,0 +1,36 @@ +/* + * EventInjector Library + * + * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * SooYoung Ha + * JiHye Kim + * YeongKyoon Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + + +package org.tizen.eilib.events; + +public abstract class AbstractEventInjector { + /** + * This method is called when connecting emulator. + * If need initialize variable, use this method. + */ + public abstract void initEventInjector(); +} diff --git a/ei-library/src/org/tizen/eilib/events/BatteryEventInjector.java b/ei-library/src/org/tizen/eilib/events/BatteryEventInjector.java new file mode 100644 index 0000000..21290ed --- /dev/null +++ b/ei-library/src/org/tizen/eilib/events/BatteryEventInjector.java @@ -0,0 +1,270 @@ +/* + * EventInjector Library + * + * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * SooYoung Ha + * JiHye Kim + * YeongKyoon Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + + +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.connection.message.EventMessage; +import org.tizen.eilib.connection.message.GroupID; +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.sender.DeviceEventSender; +import org.tizen.eilib.events.type.BatteryCharger; +import org.tizen.eilib.exception.ConnectionException; +import org.tizen.eilib.exception.EILibError; +import org.tizen.eilib.exception.DeviceEventException; +import org.tizen.eilib.modem.protocol.ByteUtil; +import org.tizen.eilib.tools.EILogger; + + +/** + * Instances of this class send battery event to the emulator. + *

          + *
          Send Events :
          + *
          Battery Level, Battery Charger State
          + *
          + *

          + */ +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(GroupID.STATUS); + if (abReceiver != null && abReceiver instanceof StatusEventReceiver) { + StatusEventReceiver re = (StatusEventReceiver)abReceiver; + re.addStatusEventReceiver(ActionID.BATTERY_LEVEL, receiver); + re.addStatusEventReceiver(ActionID.BATTERY_CHARGER, receiver); + } + } + + /** + * Return max level of battery + * @return + */ + public int getMaxBatteryLevel() { + return MAX_VALUE; + } + + /** + * Return min level of battery + * @return + */ + public int getMinBatteryLevel() { + return MIN_VALUE; + } + + /** + * Change battery level of emulator. + * + * @param level battery level(0 ~ 100) + * @return result + * @throws IOException + * @throws DeviceEventException + * @throws ConnectionException + */ + public boolean setLevel(int level) throws IOException, DeviceEventException, ConnectionException{ + if (level < MIN_VALUE || level > MAX_VALUE) { + throw new DeviceEventException(EILibError.InvalidValue); + } + + return sender.setLevel(level); + } + + /** + * Change charger state of emulator. + * + * @param isCharger battery's charger state + * @return result + * @throws IOException + * @throws DeviceEventException + * @throws ConnectionException + */ + public boolean setChargerState(BatteryCharger charger) throws IOException, DeviceEventException, ConnectionException { + if (charger == null) { + throw new DeviceEventException(EILibError.InvalidValue); + } + return sender.setChargerState(charger); + } + + /** + * Change battery level of emulator. + * + * @return level of battery (0 ~ 100) + * @throws IOException + * @throws ConnectionException + * + */ + public int getLevel() throws IOException, DeviceEventException, ConnectionException { + int level = sender.getLevel(); + + if (level == -1) { // throw error + throw new DeviceEventException(EILibError.FailedGetValue); + } + + return level; + } + + /** + * Change charger state of emulator. + * + * @return battery's charger state. true : charging, false : non charging + * @throws IOException + * @throws ConnectionException + * @throws DeviceEventException + * + */ + public BatteryCharger getChargerState() throws IOException, ConnectionException, DeviceEventException { + BatteryCharger charger = sender.getChargerState(); + if (charger == null) { + throw new DeviceEventException(EILibError.FailedGetValue); + } + + return charger; + } + + @Override + public void initEventInjector() { + // TODO Auto-generated method stub + + } + +} + +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] = SET_LEVEL; + params[1] = level; + makeMessage(BatteryID, params); + return sendMessage(null); + } + + public int getLevel() throws IOException, ConnectionException { + // empty message + makeMessage(BatteryID, null); + sendMessage(ActionID.BATTERY_LEVEL); + + synchronized(this) { + // wait 5 second + try { + this.wait(5000); + } catch (InterruptedException e) { + e.printStackTrace(); + EILogger.getLogger().warning(e.getMessage()); + } + } + + int level = -1; + if (returnMsg != null) { + if (returnMsg.getEventHeader().getActionID() + != ActionID.BATTERY_LEVEL.getId()) { + // TODO : error + EILogger.getLogger().warning("An unexpected event occurs."); + } else { + level = ByteUtil.byte2int + (returnMsg.getDataBuffer().array(), 14); + + if (level < BatteryEventInjector.MIN_VALUE + || level > BatteryEventInjector.MAX_VALUE) { + level = -1; + } + } + returnMsg = null; + } + + return level; + } + + public synchronized boolean setChargerState(BatteryCharger charger) throws IOException, ConnectionException { + params[0] = SET_CHARGER; + params[1] = charger.getValue(); + makeMessage(BatteryID, params); + return sendMessage(null); + } + + public BatteryCharger getChargerState() throws IOException, ConnectionException { + // empty message + makeMessage(BatteryID, null); + sendMessage(ActionID.BATTERY_CHARGER); + + synchronized(this) { + // wait 5 second + try { + this.wait(5000); + } catch (InterruptedException e) { + e.printStackTrace(); + EILogger.getLogger().warning(e.getMessage()); + } + } + + if (returnMsg != null) { + if (returnMsg.getEventHeader().getActionID() + != ActionID.BATTERY_CHARGER.getId()) { + // TODO : error + EILogger.getLogger().warning("An unexpected event occurs."); + } else { + int i = ByteUtil.byte2int + (returnMsg.getDataBuffer().array(), 14); + if (BatteryCharger.CONNECT.getValue() == i) { + return BatteryCharger.CONNECT; + } else if (BatteryCharger.DISCONNECT.getValue() == i) { + return BatteryCharger.DISCONNECT; + } + } + returnMsg = null; + } + + return null; + } + + public void fireEvent(EventMessage message) { + synchronized(this) { + this.returnMsg = message; + this.notifyAll(); + } + } +} diff --git a/ei-library/src/org/tizen/eilib/events/CallEvent.java b/ei-library/src/org/tizen/eilib/events/CallEvent.java new file mode 100644 index 0000000..f64fa52 --- /dev/null +++ b/ei-library/src/org/tizen/eilib/events/CallEvent.java @@ -0,0 +1,112 @@ +/* + * EventInjector Library + * + * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * SooYoung Ha + * JiHye Kim + * YeongKyoon Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + +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 callItemList; + + public String toString() { + String str = "ID: " + callID + + "\nType: " + callType + + "\nStatus: " + callStatus + + "\nNumber: " + callNumber + "\n"; + if (callItemList != null) { + for (CallItem item : callItemList) { + 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 getCallItemList() { + return callItemList; + } + + void setCallItemList(ArrayList callItemList) { + this.callItemList = callItemList; + } + + public CallStatus getCallStatus() { + return callStatus; + } + + void setCallStatus(CallStatus callStatus) { + this.callStatus = callStatus; + } +} diff --git a/ei-library/src/org/tizen/eilib/events/CallEventInjector.java b/ei-library/src/org/tizen/eilib/events/CallEventInjector.java new file mode 100644 index 0000000..7d19594 --- /dev/null +++ b/ei-library/src/org/tizen/eilib/events/CallEventInjector.java @@ -0,0 +1,597 @@ +/* + * EventInjector Library + * + * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * SooYoung Ha + * JiHye Kim + * YeongKyoon Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + +package org.tizen.eilib.events; + +import java.io.IOException; +import java.nio.ByteBuffer; +import java.util.ArrayList; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import org.tizen.eilib.connection.ConnectionToEmulator; +import org.tizen.eilib.connection.message.EventMessage; +import org.tizen.eilib.connection.message.GroupID; +import org.tizen.eilib.events.listener.EventListenerList; +import org.tizen.eilib.events.listener.ICallEventListener; +import org.tizen.eilib.events.receiver.AbstractEventReceiver; +import org.tizen.eilib.events.sender.ModemEventSender; +import org.tizen.eilib.events.type.CallEventType; +import org.tizen.eilib.events.type.CallStatus; +import org.tizen.eilib.events.type.CallType; +import org.tizen.eilib.events.type.MobileType; +import org.tizen.eilib.events.type.CallErrorCode; +import org.tizen.eilib.exception.ConnectionException; +import org.tizen.eilib.exception.EILibError; +import org.tizen.eilib.exception.CallEventException; +import org.tizen.eilib.modem.protocol.AbstractGA; +import org.tizen.eilib.modem.protocol.G01A07; +import org.tizen.eilib.modem.protocol.G01A21MO; +import org.tizen.eilib.modem.protocol.G01A21MT; +import org.tizen.eilib.modem.protocol.G01A22; +import org.tizen.eilib.modem.protocol.G01A22End; +import org.tizen.eilib.modem.protocol.G01A23; +import org.tizen.eilib.modem.protocol.G01A26; +import org.tizen.eilib.modem.protocol.G01A29; +import org.tizen.eilib.modem.protocol.G01A62; +import org.tizen.eilib.modem.protocol.StructureGA; +import org.tizen.eilib.tools.EILogger; + +/** + * Instance of this class send call event to the emulator. + * + */ +public class CallEventInjector extends AbstractEventInjector { + private CallEventSender sender = null; + private CallEventReceiver receiver = null; + private EventListenerList listeners = new EventListenerList(); + + private CallEvent callEvent = null; + private boolean isCallWaiting = true; + private boolean isIncomingCall = false; + private boolean isCalling = false; + + private boolean isDialing = false; + + private boolean isListFull = false; + + CallEventInjector(ConnectionToEmulator connector) { + sender = new CallEventSender(connector); + receiver = new CallEventReceiver(this); + + connector.addEventReceiver(GroupID.CALL, receiver); + connector.addEventReceiver(GroupID.SUPS, receiver); + } + + private RSSIEventInjector rssi; + void setRssiEventInjector(RSSIEventInjector rssi) { + this.rssi = rssi; + } + + /** + * Send call event to the emulator. + * This call is always non hidden call. (????) + * @param number phone number + * @return + * @throws IOException + * @throws ConnectionException + * @throws CallEventException + */ + public boolean calling(String number) throws IOException, ConnectionException, CallEventException { + return calling(number, false); + } + + /** + * Send call event to the emulator + * @param number phone number + * @param isHidden if this value is true, number does not display in window(LCD) of the emulator. + * @return + * @throws IOException + * @throws ConnectionException + * @throws CallEventException + */ + public boolean calling(String number, boolean isHidden) throws IOException, ConnectionException, CallEventException { + // TODO : check rssi Status ?? + if (rssi.isLevelZero()) { + throw new CallEventException(EILibError.RSSIIsZero); + } + + if (isListFull == true) { + throw new CallEventException(EILibError.ListFull); + } + + if (isIncomingCall || isDialing) { + throw new CallEventException(EILibError.IncomingCall); + } + + if (isCalling && !isCallWaiting) { + throw new CallEventException(EILibError.NowBusy); + } + + // throw CallEventException + if (!checkNumber(number)) { + throw new CallEventException(EILibError.NumberFormatError); + } + + G01A21MT ga = new G01A21MT(); + ga.intialize(); + + StructureGA sga = ga.getBody(); + sga.setInt("CALL_TYPE", 0x01); // voice + sga.setInt("FORWARDED_STATUS", 0); + sga.setInt("CLIR_STATUS", isHidden ? 0x01 : 0x00); + sga.setInt("NUM_LEN",number.getBytes().length); + sga.setInt("NUM_TYPE", 0x01); + sga.setInt("CLI_PRESENT_ID", 0x01); + sga.setInt("NO_CLI_CAUSE", 0x00); + sga.setByteArray("CALL_NUMBER", number.getBytes()); + + boolean re = sender.send(ga); + + synchronized(this) { + try { + this.wait(5000); + } catch (InterruptedException e) { + EILogger.getLogger().info(e.getMessage()); + } + } + + return re; + } + + /** + * End call event to the emulator. + * @param number + * @return + * @throws IOException + * @throws CallEventException + * @throws ConnectionException + */ + public boolean disconnectCall(String number) throws IOException, CallEventException, ConnectionException { + if (!checkNumber(number)) { + throw new CallEventException(EILibError.NumberFormatError); + } + + // for getting call item list + synchronized(this) { + try { + this.wait(500); + } catch (InterruptedException e) { + EILogger.getLogger().info(e.getMessage()); + } + } + + if (callEvent != null && callEvent.getCallItemList() != null) { + for (CallItem item : callEvent.getCallItemList()) { + if (item.getNumber().equals(number)) { + return disconnectCall(item.getId()); + } + } + } + // TODO : error item dose not exist.. + throw new CallEventException(EILibError.NumberNotFound); + } + + /** + * End call event to the emulator. + * @param callID + * @return + * @throws IOException + * @throws ConnectionException + * @throws CallEventException + */ + public boolean disconnectCall(int callID) throws IOException, CallEventException, ConnectionException { + return disconnectCall(callID, CallErrorCode.Success); + } + + /** + * End call event to the emulator + * @param callID + * @param code + * @return + * @throws IOException + * @throws ConnectionException + * @throws CallEventException + */ + public boolean disconnectCall(int callID, CallErrorCode code) throws IOException, ConnectionException, CallEventException { + // for getting call item list + synchronized(this) { + try { + this.wait(500); + } catch (InterruptedException e) { + EILogger.getLogger().info(e.getMessage()); + } + } + + boolean isFindID = false; + if (callEvent != null && callEvent.getCallItemList() != null) { + for (CallItem item : callEvent.getCallItemList()) { + if (item.getId() == callID) { + isFindID = true; + break; + } + } + } + if (!isFindID) { + throw new CallEventException(EILibError.NumberNotFound); + } + + // send error code + G01A07 ga1 = new G01A07(); + ga1.intialize(); + + StructureGA sga1 = ga1.getBody(); + sga1.setInt("ERROR_CAUSE_0", code.value() & 0x00ff); + sga1.setInt("ERROR_CAUSE_1", (code.value()>>8) & 0x00ff); + + G01A22End ga2 = new G01A22End(); + ga2.intialize(); + + StructureGA sga2 = ga2.getBody(); + sga2.setInt("CALL_ID", callID); + + sender.send(ga1); + sender.send(ga2); + + isDialing = false; + + synchronized(this) { + try { + this.wait(5000); + } catch (InterruptedException e) { + EILogger.getLogger().info(e.getMessage()); + } + } + return true; + } + + /** + * Alter call status. + * + * @return + * @throws IOException + * @throws CallEventException + * @throws ConnectionException + * @throws InjectorLibraryException + */ + public boolean alterCall() throws IOException, CallEventException, ConnectionException { + // for getting call item list + synchronized(this) { + try { + this.wait(500); + } catch (InterruptedException e) { + EILogger.getLogger().info(e.getMessage()); + } + } + + if (callEvent != null + && callEvent.getCallItemList() != null && !callEvent.getCallItemList().isEmpty()) { + G01A62 ga = new G01A62(); + ga.intialize(); + + boolean re = sender.send(ga); + + synchronized(this) { + try { + this.wait(5000); + } catch (InterruptedException e) { + EILogger.getLogger().info(e.getMessage()); + } + } + + return re; + } else { + throw new CallEventException(EILibError.NotExistCall); + } + } + + /** + * Get the phone + * + * @return + * @throws IOException + * @throws ConnectionException + * @throws CallEventException + */ + public boolean connectCall() throws IOException, ConnectionException, CallEventException { + // for getting call item list + synchronized(this) { + try { + this.wait(500); + } catch (InterruptedException e) { + EILogger.getLogger().info(e.getMessage()); + } + } + + if (callEvent != null + && callEvent.getCallItemList() != null && !callEvent.getCallItemList().isEmpty()) { + G01A23 ga = new G01A23(); + ga.intialize(); + + boolean re = sender.send(ga); + + isDialing = false; + + synchronized(this) { + try { + this.wait(5000); + } catch (InterruptedException e) { + EILogger.getLogger().info(e.getMessage()); + } + } + return re; + } else { + throw new CallEventException(EILibError.NotExistCall); + } + } + + /** + * Last call item list.. + * Call item list received from emulator(vmodem) the most recently . + * + * @return call item list + */ + public ArrayList getCallItemList() { + // for getting call item list + synchronized(this) { + try { + this.wait(500); + } catch (InterruptedException e) { + EILogger.getLogger().info(e.getMessage()); + } + } + + if (callEvent != null) { + return callEvent.getCallItemList(); + } + return null; + } + + /** + * Add call event listener. + * Note: You can receive incoming calls from emulator. + * Note: You can receive current call list from emulator. + * + * @param listener + */ + public void addCallEventListener(ICallEventListener listener) { + listeners.add(listener); + } + + /** + * Remove call event listener. + * + * @param listener + */ + public void removeCallEventListener(ICallEventListener listener) { + listeners.remove(listener); + } + + /** + * + * @return + */ + public boolean isCallWaiting() { + return isCallWaiting; + } + + /** + * + * @param isCallWaiting + */ + void setCallWaiting(boolean isCallWaiting) { + this.isCallWaiting = isCallWaiting; + } + + private boolean checkNumber(String number) throws CallEventException { + if (number == null /*|| number.length() == 0*/) { + throw new CallEventException(EILibError.NumberIsEmpty); + } + + if (number.length() > 15) { + throw new CallEventException(EILibError.NumberIsTooLong); + } + + Pattern tellPattern = Pattern.compile( "[^0-9++]"); + Matcher matcher = tellPattern.matcher(number); + return !matcher.find(); + } + + private CallStatus findCallStatus(int id) { + for (CallStatus status : CallStatus.values()) { + if (status.getID() == id) { + return status; + } + } + return null; + } + + private CallType findCallType(int id) { + for (CallType type : CallType.values()) { + if (type.getID() == id) { + return type; + } + } + return null; + } + + private MobileType findMobileType(int id) { + for (MobileType type : MobileType.values()) { + if (type.getID() == id) { + return type; + } + } + + return null; + } + + void fireCallEvent(G01A21MO ga) { + StructureGA sga = ga.getBody(); + CallEvent event = new CallEvent(); + event.setEventType(CallEventType.INCOMING); + event.setCallID(sga.getInt("CALL_ID")); + event.setCallType(findCallType(sga.getInt("CALL_TYPE"))); + + byte[] temp = sga.getByteArray("CALL_NUMBER"); + event.setCallNumber(new String(temp).trim()); + int s = temp[0]; + event.setCallStatus(findCallStatus(s)); + + isDialing = true; + + this.callEvent = event; + + for (int i = 0 ; i < listeners.size() ; i++) { + final ICallEventListener listener = (ICallEventListener)listeners.getListeners().get(i); + listener.incomingCall(event); + } + } + + void fireCallListEvent(AbstractGA ga, CallEventType eventType) { + StructureGA header = ga.getHeader(); + StructureGA body = ga.getBody(); + + int loopCount = header.getInt("COUNT"); + CallEvent event = new CallEvent(); + event.setEventType(eventType); + event.setCallItemList(new ArrayList()); + isIncomingCall = false; + for (int i = 0; i < loopCount; i++) { + CallItem item = new CallItem(); + item.setId(body.getInt("IDX", i)); + item.setStatus(findCallStatus(body.getInt("STAT", i))); + // TODO + item.setMultiParty((body.getInt("MULTIPARTY", i) == 1 ? true : false)); + item.setMobileType(findMobileType(body.getInt("DIR", i))); + item.setNumber(new String(body.getByteArray("NUMBER", i)).trim()); + if(item.getStatus() == null || item.getStatus() == CallStatus.NONE) { + loopCount++; + continue; + } else if (item.getStatus() == CallStatus.INCOMING + || item.getStatus() == CallStatus.WAITING) { + // TODO + isIncomingCall = true; + } + event.getCallItemList().add(item); + isCalling = true; + } + + if (event.getCallItemList().isEmpty()) { + isIncomingCall = false; + isCalling = false; + isListFull = false; + } else if (event.getCallItemList().size() == 6) { + isListFull = true; + } else { + isListFull = false; + } + + this.callEvent = event; + + synchronized(this) { + this.notifyAll(); + } + + for (int i = 0 ; i < listeners.size() ; i++) { + final ICallEventListener listener = (ICallEventListener)listeners.getListeners().get(i); + listener.receivingCallList(event); + } + } + + @Override + public void initEventInjector() { + // TODO Auto-generated method stub + + } +} + +class CallEventSender extends ModemEventSender { + public CallEventSender(ConnectionToEmulator connector) { + super(connector); + } +} + +class CallEventReceiver extends AbstractEventReceiver { + private CallEventInjector injector; + public CallEventReceiver(CallEventInjector injector) { + super("Call event"); + this.injector = injector; + } + + public void run(EventMessage msg) { + synchronized(this) { + // groupid 3: GSM_SUPS, actionid 73: GSM_SUPS_SET_CW_REQ + if (msg.getEventHeader().getGroupID() == GroupID.SUPS + && msg.getEventHeader().getActionID() == 73) { + ByteBuffer buf = msg.getDataBuffer(); + for (int i = 0; i < msg.getDataBuffer().position(); i++) { + if (buf.get(i) == -1) { // -1 : class id 255 + if (buf.get(i+4) == 3) { // 3 : cw on + injector.setCallWaiting(true); + } else if (buf.get(i+4) == 4) { // 4 : cw off + injector.setCallWaiting(false); + } + } + } + return; + } + + switch(msg.getEventHeader().getActionID()) { + case 0x21: //mo call + { + G01A21MO ga = new G01A21MO(); + ga.intialize(msg.getDataBuffer()); + injector.fireCallEvent(ga); + } + break; + case 0x22: // disconnect + { + G01A22 ga = new G01A22(); + ga.intialize(msg.getDataBuffer()); + injector.fireCallListEvent(ga, CallEventType.LIST22); + } + break; + case 0x26: // connect + { + G01A26 ga = new G01A26(); + ga.intialize(msg.getDataBuffer()); + injector.fireCallListEvent(ga, CallEventType.LIST26); + } + break; + case 0x29: // ring + { + G01A29 ga = new G01A29(); + ga.intialize(msg.getDataBuffer()); + injector.fireCallListEvent(ga, CallEventType.LIST29); + } + break; + default: + break; + } + } + } + +} diff --git a/ei-library/src/org/tizen/eilib/events/CallItem.java b/ei-library/src/org/tizen/eilib/events/CallItem.java new file mode 100644 index 0000000..aa3f0dd --- /dev/null +++ b/ei-library/src/org/tizen/eilib/events/CallItem.java @@ -0,0 +1,86 @@ +/* + * EventInjector Library + * + * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * SooYoung Ha + * JiHye Kim + * YeongKyoon Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + +package org.tizen.eilib.events; + +import org.tizen.eilib.events.type.CallStatus; +import org.tizen.eilib.events.type.MobileType; + + +public class CallItem { + private int id; + private CallStatus status; + private boolean isMultiParty; + private MobileType mType; // MT / MO + private String number; + + public String toString() { + String str = "ID: " + id + + "\nMO-MT: " + mType + + "\nStatus: " + status + + "\nNumber: " + number + "\n"; + return str; + } + public int getId() { + return id; + } + + void setId(int id) { + this.id = id; + } + + public CallStatus getStatus() { + return status; + } + + void setStatus(CallStatus status) { + this.status = status; + } + + public boolean isMultiParty() { + return isMultiParty; + } + + void setMultiParty(boolean isMultiParty) { + this.isMultiParty = isMultiParty; + } + + public MobileType getMobileType() { + return mType; + } + + void setMobileType(MobileType mt) { + this.mType = mt; + } + + public String getNumber() { + return number; + } + + void setNumber(String number) { + this.number = number; + } +} diff --git a/ei-library/src/org/tizen/eilib/events/EarJackEventInjector.java b/ei-library/src/org/tizen/eilib/events/EarJackEventInjector.java new file mode 100644 index 0000000..311c8e2 --- /dev/null +++ b/ei-library/src/org/tizen/eilib/events/EarJackEventInjector.java @@ -0,0 +1,167 @@ +/* + * EventInjector Library + * + * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * SooYoung Ha + * JiHye Kim + * YeongKyoon Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + + +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.connection.message.EventMessage; +import org.tizen.eilib.connection.message.GroupID; +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.sender.DeviceEventSender; +import org.tizen.eilib.events.type.EarJackStatus; +import org.tizen.eilib.exception.ConnectionException; +import org.tizen.eilib.exception.DeviceEventException; +import org.tizen.eilib.exception.EILibError; +import org.tizen.eilib.modem.protocol.ByteUtil; +import org.tizen.eilib.tools.EILogger; + +/** + * Instances of this class send ear jack event to the emulator. + *

          + *
          Send Events :
          + *
          EarJack's status
          + *
          + *

          + */ +public class EarJackEventInjector extends AbstractEventInjector { + private EarJackEventSender sender = null; + + EarJackEventInjector(ConnectionToEmulator connector) { + sender = new EarJackEventSender(connector); + EventReceiver receiver = new EventReceiver("EarJackReceiver", sender); + + AbstractEventReceiver abReceiver = connector.findEventReceiver(GroupID.STATUS); + if (abReceiver != null && abReceiver instanceof StatusEventReceiver) { + StatusEventReceiver re = (StatusEventReceiver)abReceiver; + re.addStatusEventReceiver(ActionID.EARJACK_STATUS, receiver); + } + } + + /** + * Change ear jack status of emulator. + * + * @param status EarJackStatus.DISCONNECT, + * EarJackStatus.WIRE3_CONNECT, EarJackSTatus.WIRE4_CONNECT + * @throws IOException + * @throws ConnectionException + * + */ + public boolean setStatus(EarJackStatus status) throws IOException, ConnectionException { + return sender.sendEarJackstatus(status); + } + + /** + * Get ear jack status of emulator. + * + * @return status of ear jack + * EarJackStatus.DISCONNECT, + * EarJackStatus.WIRE3_CONNECT, EarJackSTatus.WIRE4_CONNECT + * @throws IOException + * @throws ConnectionException + * + */ + public EarJackStatus getStatus() throws IOException, DeviceEventException, ConnectionException { + EarJackStatus status = sender.getStatus(); + if (status == null) { + throw new DeviceEventException(EILibError.FailedGetValue); + } + return status; + } + + @Override + public void initEventInjector() { + // TODO Auto-generated method stub + + } + +} + +class EarJackEventSender extends DeviceEventSender { + private static String EarJackID = "9\n"; + private EventMessage returnMsg = null; + + public EarJackEventSender(ConnectionToEmulator connector) { + super(connector); + } + + public synchronized boolean sendEarJackstatus(EarJackStatus status) throws IOException, ConnectionException { + double params[] = new double[1]; + params[0] = status.getValue(); + makeMessage(EarJackID, params); + return sendMessage(null); + } + + public synchronized EarJackStatus getStatus() throws IOException, ConnectionException { + // empty message + makeMessage(EarJackID, null); + sendMessage(ActionID.EARJACK_STATUS); + + synchronized(this) { + // wait 5 second + try { + this.wait(5000); + } catch (InterruptedException e) { + e.printStackTrace(); + EILogger.getLogger().warning(e.getMessage()); + } + } + + EarJackStatus status = null; + if (returnMsg != null) { + if (returnMsg.getEventHeader().getActionID() + != ActionID.EARJACK_STATUS.getId()) { + // TODO : error + EILogger.getLogger().warning("An unexpected event occurs."); + } else { + int state = ByteUtil.byte2int + (returnMsg.getDataBuffer().array(), 14); + for (EarJackStatus s : EarJackStatus.values()) { + if (s.getValue() == state) { + status = s; + break; + } + } + } + returnMsg = null; + } + + return status; + } + + @Override + public void fireEvent(EventMessage message) { + synchronized(this) { + this.returnMsg = message; + this.notifyAll(); + } + } +} \ No newline at end of file diff --git a/ei-library/src/org/tizen/eilib/events/EventInjectorCreator.java b/ei-library/src/org/tizen/eilib/events/EventInjectorCreator.java new file mode 100644 index 0000000..53ab499 --- /dev/null +++ b/ei-library/src/org/tizen/eilib/events/EventInjectorCreator.java @@ -0,0 +1,188 @@ +/* + * EventInjector Library + * + * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * SooYoung Ha + * JiHye Kim + * YeongKyoon Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + +package org.tizen.eilib.events; + +import java.io.IOException; +import java.util.ArrayList; + +import org.tizen.eilib.connection.ConnectionToEmulator; +import org.tizen.eilib.exception.ConnectionException; +import org.tizen.eilib.exception.DeviceEventException; +import org.tizen.eilib.tools.EILogger; + +public class EventInjectorCreator { + private ConnectionToEmulator connector = null; + private ArrayList injectors = null; + + public EventInjectorCreator(ConnectionToEmulator connector) { + assert connector == null; + + this.connector = connector; + if (this.connector != null) { + this.connector.setEventInjectorCreator(this); + } + + injectors = new ArrayList(); + } + + public void intializeConnectToEmulator() { + for (AbstractEventInjector i : injectors) { + if (i != null) { + i.initEventInjector(); + } + } + } + + private BatteryEventInjector batteryInjector = null; + public BatteryEventInjector getBatteryEventInjector() { + if (batteryInjector == null) { + batteryInjector = new BatteryEventInjector(connector); + injectors.add(batteryInjector); + } + return batteryInjector; + } + + private USBEventInjector USBInjector = null; + public USBEventInjector getUSBEventInjector() { + if (USBInjector == null) { + USBInjector = new USBEventInjector(connector); + injectors.add(USBInjector); + } + return USBInjector; + } + + private EarJackEventInjector earJackInjector = null; + public EarJackEventInjector getEarJackInjector() { + if (earJackInjector == null) { + earJackInjector = new EarJackEventInjector(connector); + injectors.add(earJackInjector); + } + return earJackInjector; + } + + private boolean isInitModem = false; + private CallEventInjector callInjector = null; + public CallEventInjector getCallEventInjector() throws ConnectionException { + if (callInjector == null) { + try { + connector.sendInitializeMessage(); + } catch (IOException e) { + EILogger.getLogger().warning(e.getMessage()); + } + callInjector = new CallEventInjector(connector); + callInjector.setRssiEventInjector(getRssiEventInjector()); + injectors.add(callInjector); + } + + if (!isInitModem) { + try { + connector.sendModemInitialize(); + } catch (IOException e) { + EILogger.getLogger().warning(e.getMessage()); + } + isInitModem = true; + } + + synchronized(this) { + try { + this.wait(500); + } catch (InterruptedException e) { + EILogger.getLogger().warning(e.getMessage()); + } + } + return callInjector; + } + + private SMSEventInjector smsInjector = null; + public SMSEventInjector getSMSEventInjector() throws ConnectionException { + if (smsInjector == null) { + try { + connector.sendInitializeMessage(); + } catch (IOException e) { + EILogger.getLogger().warning(e.getMessage()); + } + smsInjector = new SMSEventInjector(connector); + smsInjector.setRssiEventInjector(getRssiEventInjector()); + injectors.add(smsInjector); + } + if (!isInitModem) { + try { + connector.sendModemInitialize(); + } catch (IOException e) { + EILogger.getLogger().warning(e.getMessage()); + } + isInitModem = true; + } + return smsInjector; + } + + private RSSIEventInjector rssiInjector = null; + public RSSIEventInjector getRssiEventInjector() { + if (rssiInjector == null) { + rssiInjector = new RSSIEventInjector(connector); + injectors.add(rssiInjector); + } + return rssiInjector; + } + + private LocationEventInjector locationInjector = null; + public LocationEventInjector getLocationInjector() { + if (locationInjector == null) { + locationInjector = new LocationEventInjector(connector); + injectors.add(locationInjector); + } + return locationInjector; + } + + private SensorEventInjector sensorInjector = null; + public SensorEventInjector getSensorInjector() { + if (sensorInjector == null) { + sensorInjector = new SensorEventInjector(connector); + injectors.add(sensorInjector); + } + return sensorInjector; + } + + private SDCardEventInjector SDCardInjector = null; + public SDCardEventInjector getSDCardInjector() throws IOException, DeviceEventException, ConnectionException { + if (SDCardInjector == null) { + SDCardInjector = new SDCardEventInjector(connector); + injectors.add(SDCardInjector); + } + return SDCardInjector; + } + + private NfcEventInjector nfcEventInjector = null; + public NfcEventInjector getNfcEventInjector() throws IOException, ConnectionException { + if (nfcEventInjector == null) { + nfcEventInjector = new NfcEventInjector(connector); + injectors.add(SDCardInjector); + } + return nfcEventInjector; + } +} + \ No newline at end of file diff --git a/ei-library/src/org/tizen/eilib/events/LocationEvent.java b/ei-library/src/org/tizen/eilib/events/LocationEvent.java new file mode 100644 index 0000000..f3436d1 --- /dev/null +++ b/ei-library/src/org/tizen/eilib/events/LocationEvent.java @@ -0,0 +1,74 @@ +/* + * EventInjector Library + * + * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * SooYoung Ha + * JiHye Kim + * YeongKyoon Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ +package org.tizen.eilib.events; + +import org.tizen.eilib.events.type.LocationEventMode; + +public class LocationEvent { + private LocationEventMode mode; + private double latitude; + private double logitude; + private String fileName; + + public LocationEvent() { + mode = null; + latitude = 0.0; + logitude = 0.0; + fileName = null; + } + + public LocationEventMode getMode() { + return mode; + } + + void setMode(LocationEventMode mode) { + this.mode = mode; + } + + public double getLatitude() { + return latitude; + } + + void setLatitude(double latitude) { + this.latitude = latitude; + } + + public double getLogitude() { + return logitude; + } + + void setLogitude(double logitude) { + this.logitude = logitude; + } + + public String getFileName() { + return fileName; + } + + void setFileName(String fileName) { + this.fileName = fileName; + } +} diff --git a/ei-library/src/org/tizen/eilib/events/LocationEventInjector.java b/ei-library/src/org/tizen/eilib/events/LocationEventInjector.java new file mode 100644 index 0000000..398b3e3 --- /dev/null +++ b/ei-library/src/org/tizen/eilib/events/LocationEventInjector.java @@ -0,0 +1,272 @@ +/* + * EventInjector Library + * + * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * SooYoung Ha + * JiHye Kim + * YeongKyoon Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + + +package org.tizen.eilib.events; + +import java.io.File; +import java.io.IOException; + +import org.tizen.eilib.connection.ConnectionToEmulator; +import org.tizen.eilib.connection.Emulator; +import org.tizen.eilib.connection.message.ActionID; +import org.tizen.eilib.connection.message.GroupID; +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.sender.LocationEventSender; +import org.tizen.eilib.events.type.LocationEventMode; +import org.tizen.eilib.exception.ConnectionException; +import org.tizen.eilib.exception.EILibError; +import org.tizen.eilib.exception.InjectorLibraryException; +import org.tizen.sdblib.SyncService; +import org.tizen.sdblib.SyncService.SyncResult; + +// TODO RECEIVER +public class LocationEventInjector extends AbstractEventInjector { + private LocationEventSender sender = null; + private LocationEventMode currentMode; + private ConnectionToEmulator connector; + + private static final String logFileName = "nmea_replay.log"; + private static final String remoteFilePath = "/opt/media/gps-manager/replay/" + logFileName; + + LocationEventInjector(ConnectionToEmulator connector) { + sender = new LocationEventSender(connector); + AbstractEventReceiver abReceiver = connector.findEventReceiver(GroupID.STATUS); + if (abReceiver != null && abReceiver instanceof StatusEventReceiver) { + StatusEventReceiver re = (StatusEventReceiver)abReceiver; + re.addStatusEventReceiver(ActionID.LOCATION_STATUS, + new EventReceiver("LocationReceiver", sender)); + } + + this.connector = connector; + initEventInjector(); + } + + /** + * This is set stop mode to the emulator's location mode. Emulator does not read location value after setting stop mode. + * If you no longer need to raise the location event, call this function. + * Otherwise unnecessary work occurs that emulator consistently read the location value. + * @return + * @throws IOException + * @throws ConnectionException + */ + public boolean setStopMode() throws IOException, ConnectionException { + if (currentMode != LocationEventMode.STOPMODE) { + currentMode = LocationEventMode.STOPMODE; + return sender.sendMessage(LocationEventMode.STOPMODE.toString()); + } + return true; + } + + /** + * + * @return + * @throws IOException + * @throws ConnectionException + */ + public boolean setManualMode() throws IOException, ConnectionException { + if (currentMode != LocationEventMode.MANUALMODE) { + currentMode = LocationEventMode.MANUALMODE; + return sender.sendMessage(LocationEventMode.MANUALMODE.toString()); + } + return true; + } + + /** + * Return current event mode + * + * @see LocationEventMode + * @return + */ + public LocationEventMode getEventMode() { + return currentMode; + } + + /** + * Set location information. + * @param latitude -90 ~ 90 + * @param longitude -180 ~ 180 + * @return + * @throws IOException + * @throws InjectorLibraryException + * @throws ConnectionException + */ + public boolean sendLocation(double latitude, double longitude) throws IOException, InjectorLibraryException, ConnectionException { + if (!checkValues(latitude, longitude)) { + throw new InjectorLibraryException(EILibError.InvalidLocationValue); + } + + setManualMode(); + + String msg = currentMode.toString() + "," + latitude + "," + longitude; + return sender.sendMessage(msg); + } + + /** + * Send location log file. + * File format is NMEA + * @param filePath + * @return + * @throws IOException + * @throws InjectorLibraryException + * @throws ConnectionException + */ + public boolean sendLocationFile(String filePath) throws IOException, InjectorLibraryException, ConnectionException { + return sendLocationFile(new File(filePath)); + } + + /** + * Send location log file. + * File format is NMEA + * @param filePath + * @return + * @throws IOException + * @throws ConnectionException + * @throws InjectorLibraryException + */ + public boolean sendLocationFile(File file) throws IOException, ConnectionException, InjectorLibraryException { + file = file.getCanonicalFile(); + + if (!file.exists()) { + throw new InjectorLibraryException(EILibError.NotExistLogFile); + } + + // TODO : PUSH FILE TO EMULATOR + // USING SDB + //sync.pushFile(file.getCanonicalPath(), remoteFilePath..); + Emulator emulator = connector.getCurrentEmulator(); + if (emulator == null) { + // TODO : exception + return false; + } + + SyncService sync = emulator.getSyncService(); + if (sync != null) { + SyncResult result = sync.pushFile(file.getPath(), remoteFilePath, SyncService.getNullProgressMonitor()); + if (result.getCode() != SyncService.RESULT_OK) { + // TODO + return false; + } + } + + currentMode = LocationEventMode.LOGMODE; + return sender.sendMessage(currentMode.toString() + "," + logFileName); + } + + public LocationEvent getLocationStatus() throws IOException, ConnectionException, InjectorLibraryException { + String value = sender.getLocationStatus(); + LocationEvent event = null; + if (value != null) { + event = new LocationEvent(); + String[] vals = value.split(","); + for (LocationEventMode m : LocationEventMode.values()) { + if (m.toString().equals(vals[0])) { + event.setMode(m); + break; + } + } + + if (event.getMode() != null) { + switch (event.getMode()) { + case STOPMODE: + break; + case LOGMODE: + event.setFileName(vals[1]); + break; + case MANUALMODE: + event.setLatitude(Double.valueOf(vals[1])); + event.setLogitude(Double.valueOf(vals[2])); + break; + default: + throw new InjectorLibraryException(EILibError.FailedGetValue); + } + } else { + throw new InjectorLibraryException(EILibError.FailedGetValue); + } + } else { + throw new InjectorLibraryException(EILibError.FailedGetValue); + } + + return event; + } + /** + * Initialize event injector local variable. + */ + @Override + public void initEventInjector() { + currentMode = LocationEventMode.NONE; + } + + private int minLatitude = -90; + private int maxLatitude = 90; + private int minLongitude = -180; + private int maxLongitude = 180; + private boolean checkValues(double latitude, double longitude) { + if (latitude > maxLatitude || latitude < minLatitude) { + return false; + } + + if (longitude > maxLongitude || longitude < minLongitude) { + return false; + } + + return true; + } + + /** + * Return minimum latitude value + * @return + */ + public int getMinLatitude() { + return minLatitude; + } + + /** + * Return maximum latitude value + * @return + */ + public int getMaxLatitude() { + return maxLatitude; + } + + /** + * Return minimum longitude value + * @return + */ + public int getMinLongitude() { + return minLongitude; + } + + /** + * Return maximum longitude value + * @return + */ + public int getMaxLongitude() { + return maxLongitude; + } +} diff --git a/ei-library/src/org/tizen/eilib/events/NfcEventInjector.java b/ei-library/src/org/tizen/eilib/events/NfcEventInjector.java new file mode 100644 index 0000000..aed219b --- /dev/null +++ b/ei-library/src/org/tizen/eilib/events/NfcEventInjector.java @@ -0,0 +1,482 @@ +/* + * EventInjector Library + * + * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * SooYoung Ha + * JiHye Kim + * YeongKyoon Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + + +package org.tizen.eilib.events; + +import java.io.IOException; +import java.util.ArrayList; + +import org.tizen.eilib.connection.ConnectionToEmulator; +import org.tizen.eilib.connection.Emulator; +import org.tizen.eilib.connection.message.ActionID; +import org.tizen.eilib.connection.message.GroupID; +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.sender.NfcEventSender; +import org.tizen.eilib.events.type.NDEFFormat; +import org.tizen.eilib.events.type.NDEFRecord; +import org.tizen.eilib.events.type.NfcTagType; +import org.tizen.eilib.events.type.MimeTypeList; +import org.tizen.eilib.exception.ConnectionException; +import org.tizen.eilib.exception.EILibError; +import org.tizen.eilib.exception.NfcEventException; +import org.tizen.eilib.tools.EILogger; +import org.tizen.sdblib.MultiLineReceiver; +import org.tizen.sdblib.SdbCommandRejectedException; +import org.tizen.sdblib.ShellCommandUnresponsiveException; +import org.tizen.sdblib.TimeoutException; + +/** + * Instance of this class send nfc event to the emulator + * + */ +public class NfcEventInjector extends AbstractEventInjector { + private NfcEventSender sender = null; + private ArrayList recordList; + private ArrayList attachedList; + private ConnectionToEmulator connector; + private static final int MaxRecordListLength = 4096; + private static final int MaxRecordCount = 5; + private static NfcEventType currentEventType = NfcEventType.NONE; + + private int recordListLength = 0; + + NfcEventInjector(ConnectionToEmulator connector) throws IOException, ConnectionException { + sender = new NfcEventSender(connector); + recordList = new ArrayList(); + attachedList = new ArrayList(); + AbstractEventReceiver abReceiver = connector.findEventReceiver(GroupID.STATUS); + if (abReceiver != null && abReceiver instanceof StatusEventReceiver) { + StatusEventReceiver re = (StatusEventReceiver)abReceiver; + re.addStatusEventReceiver(ActionID.NFC_STATUS, + new EventReceiver("NfcReceiver", sender)); + } + + this.connector = connector; + + // get current status + try { + getNfcStatus(); + } catch (NfcEventException e) { + EILogger.getLogger().info(e.getMessage()); + } + } + + public NfcEventType getCurrentEventType() { + return currentEventType; + } + + private int checkRecordListMaxLength() { + int lenList = 0; + for (NDEFRecord record : recordList) { + lenList += 1 + record.toString().length() + 4; + } + + if (lenList > MaxRecordListLength) { + return -1; + } + + return lenList; + } + + public ArrayList getRecordList() { + return recordList; + } + + public int getRecordListLength() { + return recordListLength; + } + + public void addNDEFRecord(NDEFRecord record) throws NfcEventException { + if (record == null) { + throw new NfcEventException(EILibError.NullRecord); + } + if (recordList.size() >= MaxRecordCount) { + throw new NfcEventException(EILibError.RecordCountIsMax); + } + + checkRecordFormat(record); + + recordList.add(record); + + int temp = checkRecordListMaxLength(); + if (temp == -1) { + recordList.remove(record); + throw new NfcEventException(EILibError.NDEFMessageLenIsMax); + } else { + recordListLength = temp; + } + } + + private void checkRecordFormat(NDEFRecord record) throws NfcEventException { + checkInvaildCharacters(record.getId()); + checkInvaildCharacters(record.getTypeName()); + checkInvaildCharacters(record.getPayload()); + + if (record.getFormat() == NDEFFormat.WELL_KNOWN) { + if (!record.getTypeName().equals("U") + && !record.getTypeName().equals("T")) { + throw new NfcEventException(EILibError.InvalidWellKnownType); + } + } else if (record.getFormat() == NDEFFormat.MEDIA) { + if (checkFileTpye(record.getPayload()) == null) { + throw new NfcEventException(EILibError.NotMimeType); + } + if (checktFileSize(record.getPayload()) == false) { + throw new NfcEventException(EILibError.BigSizeFile); + } + } + } + + private boolean checktFileSize(String filePath) throws NfcEventException { + boolean result = false; + shellCmd = "du " + filePath; + try { + connector.getCurrentEmulator().executeShellCommand(shellCmd, new MultiLineReceiver() { + @Override + public void processNewLines(String[] lines) { + shellResult = lines[0]; + } + + }); + } catch (TimeoutException e) { + throw new NfcEventException(EILibError.CheckMediaFileException); + } catch (SdbCommandRejectedException e) { + throw new NfcEventException(EILibError.CheckMediaFileException); + } catch (ShellCommandUnresponsiveException e) { + throw new NfcEventException(EILibError.CheckMediaFileException); + } catch (IOException e) { + throw new NfcEventException(EILibError.CheckMediaFileException); + } + + if (shellResult != null) { + int index = shellResult.indexOf('\t'); + if (index != -1) { + shellResult = shellResult.substring(0, index); + + if (Integer.valueOf(shellResult) <= 10) { + result = true; + } + } + } + + return result; + } + + private String checkFileTpye(String payload) { + int index = payload.lastIndexOf('.'); + String type = null; + if (index != -1) { + String ex = payload.substring(index + 1); + MimeTypeList typelist = MimeTypeList.getInstance(); + + type = typelist.findMimeType(ex); + } + + return type; + } + + private void checkInvaildCharacters(String text) throws NfcEventException { + for (char c : text.toCharArray()) { + if (c == '\n') { + throw new NfcEventException(EILibError.InvalidCharNewLine); + } + + if (c == ',') { + throw new NfcEventException(EILibError.InvalidChar); + } + + if (c >= 0x80) { + throw new NfcEventException(EILibError.InvalidCharAscii); + } + } + } + + public void removeNDEFRecord(NDEFRecord record) throws NfcEventException { + if (record == null) { + throw new NfcEventException(EILibError.NullRecord); + } + + if (!recordList.remove(record)) { + throw new NfcEventException(EILibError.FailedRemoveRecord); + } + checkRecordListMaxLength(); + } + + public void removeNDEFRecord(int index) throws NfcEventException { + try { + recordList.remove(index); + } catch (IndexOutOfBoundsException e) { + throw new NfcEventException(EILibError.FailedRemoveRecord); + } + checkRecordListMaxLength(); + } + + public NDEFRecord getNDEFRecord(NDEFRecord record) { + for (NDEFRecord r : recordList) { + if (r.equals(record)) { + return r; + } + } + return null; + } + + public NDEFRecord getNDEFRecorde(int index) { + return recordList.get(index); + } + + public boolean sendTagDiscovered(NfcTagType tag) throws IOException, NfcEventException, ConnectionException { + if (currentEventType == NfcEventType.TAG_DISCOVERED) { + throw new NfcEventException(EILibError.TagAttachState); + } else if (currentEventType == NfcEventType.P2P_DISCOVERED + || currentEventType == NfcEventType.P2P_SEND) { + throw new NfcEventException(EILibError.P2PAttachState); + } + + if (!avaliableNfc()) { + throw new NfcEventException(EILibError.NFCIsDisable); + } + + if (recordList.size() == 0) { + throw new NfcEventException(EILibError.RecordCountIsZero); + } + + if (tag == null || tag == NfcTagType.P2P) { + throw new NfcEventException(EILibError.SelecTagType); + } + + String message = NfcEventType.TAG_DISCOVERED.getType() + ":" + + tag.getType() + "," + recordList.size(); + for (NDEFRecord record : recordList) { + message += "," + record.getMessage(); + } + + sender.sendMessage(message + "\n"); + + currentEventType = NfcEventType.TAG_DISCOVERED; + + return true; + } + + + public boolean sendTagDetached() throws IOException, NfcEventException, ConnectionException { + if (currentEventType != NfcEventType.TAG_DISCOVERED) { + throw new NfcEventException(EILibError.CanNotDettach); + } + + if (!avaliableNfc()) { + throw new NfcEventException(EILibError.NFCIsDisable); + } + + sender.sendMessage(NfcEventType.TAG_DETACHED.getType() + ":" + "\n"); + + currentEventType = NfcEventType.TAG_DETACHED; + + return true; + } + + public boolean sendP2PDiscovered() throws IOException, NfcEventException, ConnectionException { + if (currentEventType == NfcEventType.TAG_DISCOVERED) { + throw new NfcEventException(EILibError.TagAttachState); + } else if (currentEventType == NfcEventType.P2P_DISCOVERED + || currentEventType == NfcEventType.P2P_SEND) { + throw new NfcEventException(EILibError.P2PAttachState); + } + + if (!avaliableNfc()) { + throw new NfcEventException(EILibError.NFCIsDisable); + } + + sender.sendMessage(NfcEventType.P2P_DISCOVERED.getType() + ":" + "\n"); + + currentEventType = NfcEventType.P2P_DISCOVERED; + + return true; + } + + public boolean sendP2PSend() throws IOException, NfcEventException, ConnectionException { + if (currentEventType != NfcEventType.P2P_DISCOVERED + && currentEventType != NfcEventType.P2P_SEND) { + throw new NfcEventException(EILibError.CanNotSend); + } + + if (!avaliableNfc()) { + throw new NfcEventException(EILibError.NFCIsDisable); + } + + if (recordList.size() == 0) { + throw new NfcEventException(EILibError.RecordCountIsZero); + } + + String message = NfcEventType.P2P_SEND.getType() + ":" + + NfcTagType.P2P.getType() + "," + recordList.size(); + + for (NDEFRecord record : recordList) { + message += "," + record.getMessage(); + } + + sender.sendMessage(message + "\n"); + + currentEventType = NfcEventType.P2P_SEND; + + return true; + } + + public boolean sendP2PDetached() throws IOException, NfcEventException, ConnectionException { + if (currentEventType != NfcEventType.P2P_DISCOVERED + && currentEventType != NfcEventType.P2P_SEND) { + throw new NfcEventException(EILibError.CanNotDettach); + } + + if (!avaliableNfc()) { + throw new NfcEventException(EILibError.NFCIsDisable); + } + + sender.sendMessage(NfcEventType.P2P_DETACHED.getType() + ":" + "\n"); + + currentEventType = NfcEventType.P2P_DETACHED; + + return true; + } + + public ArrayList getAttachedRecordList() { + return attachedList; + } + + public NfcEventType getNfcStatus() throws IOException, ConnectionException, NfcEventException { + if (!avaliableNfc()) { + throw new NfcEventException(EILibError.NFCIsDisable); + } + + String value = sender.getNfcStatus(); + + NfcEventType type = null; + if (value != null) { + String[] vals = value.split(":"); + int temp = Integer.valueOf(vals[0]); + for (NfcEventType t : NfcEventType.values()) { + if (temp == t.getType()) { + currentEventType = type = t; + break; + } + } + + attachedList.clear(); + if (type != null + && (type == NfcEventType.TAG_DISCOVERED + || type == NfcEventType.P2P_SEND)) { + makeNDEFMessage(vals[1]); + } + } + + return type == null ? NfcEventType.NONE : type; + } + + private void makeNDEFMessage(String value) { + if (value.endsWith("\n")) { + value = value.substring(0, value.length() - 1); + } + String[] vals = value.split(","); + + int count = Integer.valueOf(vals[1]); + for (int i = 0; i < count; i++) { + String temp = vals[2 + (4*i)]; + NDEFFormat format = null; + for (NDEFFormat f : NDEFFormat.values()) { + if (f.getFormat().equals(temp)) { + format = f; + break; + } + } + if (format == null) { + continue; + } + attachedList.add + (new NDEFRecord(format, vals[3 + (4*i)], vals[4 + (4*i)], vals[5 + (4*i)])); + } + } + + private String shellCmd = "vconftool get db/nfc/enable"; + private String errorMessage = null; + private String shellResult = null; + public boolean avaliableNfc() throws ConnectionException { + boolean result = true; + shellResult = null; + errorMessage = null; + Emulator emualtor = connector.getCurrentEmulator(); + + try { + emualtor.getDevice().executeShellCommand(shellCmd, new MultiLineReceiver() { + @Override + public void processNewLines(String[] lines) { + shellResult = lines[0]; + } + }); + } catch (TimeoutException e) { + errorMessage = e.getMessage(); + result = false; + } catch (SdbCommandRejectedException e) { + errorMessage = e.getMessage(); + result = false; + } catch (ShellCommandUnresponsiveException e) { + errorMessage = e.getMessage(); + result = false; + } catch (IOException e) { + errorMessage = e.getMessage(); + result = false; + } + + if (result && shellResult != null) { + if (shellResult.indexOf('1') != -1) { + result = true; + } else { + result = false; + } + } else { + EILogger.getLogger().info(errorMessage); + } + + if (!result) { + currentEventType = NfcEventType.NONE; + try { + sender.sendMessage(NfcEventType.TAG_DETACHED.getType() + ":" + "\n"); + } catch (IOException e) { + EILogger.getLogger().info(e.getMessage()); + } + } + + return result; + } + + @Override + public void initEventInjector() { + // TODO Auto-generated method stub + + } + +} diff --git a/ei-library/src/org/tizen/eilib/events/NfcEventType.java b/ei-library/src/org/tizen/eilib/events/NfcEventType.java new file mode 100644 index 0000000..410faee --- /dev/null +++ b/ei-library/src/org/tizen/eilib/events/NfcEventType.java @@ -0,0 +1,55 @@ +/* + * EventInjector Library + * + * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * SooYoung Ha + * JiHye Kim + * YeongKyoon Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + + +package org.tizen.eilib.events; + +public enum NfcEventType +{ + NONE("NFC_NONE", 0), + TAG_DISCOVERED("NFC_TAG_DISCOVERED", 100), + TAG_DETACHED("NFC_TAG_DETACHED", 101), + P2P_DISCOVERED("NFC_P2P_DISCOVERED", 102), + P2P_DETACHED("NFC_P2P_DETACHED", 103), + P2P_SEND("NFC_P2P_SEND", 104); + + int type; + String name; + + NfcEventType(String n, int t) { + type = t; + name = n; + } + + public int getType() { + return type; + } + + @Override + public String toString() { + return name; + } +} diff --git a/ei-library/src/org/tizen/eilib/events/RSSIEventInjector.java b/ei-library/src/org/tizen/eilib/events/RSSIEventInjector.java new file mode 100644 index 0000000..dffa850 --- /dev/null +++ b/ei-library/src/org/tizen/eilib/events/RSSIEventInjector.java @@ -0,0 +1,258 @@ +/* + * EventInjector Library + * + * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * SooYoung Ha + * JiHye Kim + * YeongKyoon Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + +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.connection.message.EventMessage; +import org.tizen.eilib.connection.message.GroupID; +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.sender.DeviceEventSender; +import org.tizen.eilib.events.sender.ModemEventSender; +import org.tizen.eilib.exception.ConnectionException; +import org.tizen.eilib.exception.EILibError; +import org.tizen.eilib.exception.DeviceEventException; +import org.tizen.eilib.modem.protocol.ByteUtil; +import org.tizen.eilib.modem.protocol.G02A31; +import org.tizen.eilib.modem.protocol.StructureGA; +import org.tizen.eilib.tools.EILogger; + +/** + * Instance of this class to control rssi status of emulator. + * + */ +public class RSSIEventInjector extends AbstractEventInjector { + private RSSIEventSender sender = null; + private ModemEventSender modemSender = null; + static final int MIN_VALUE = 0; + static final int MAX_VALUE = 5; + private boolean isLevelZero = false; + + RSSIEventInjector(ConnectionToEmulator connector) { + sender = new RSSIEventSender(connector); + modemSender = new ModemEventSender(connector); + EventReceiver receiver = new EventReceiver("RSSIReceiver", sender); + AbstractEventReceiver abReceiver = connector.findEventReceiver(GroupID.STATUS); + if (abReceiver != null && abReceiver instanceof StatusEventReceiver) { + StatusEventReceiver re = (StatusEventReceiver)abReceiver; + re.addStatusEventReceiver(ActionID.RSSI_LEVEL, receiver); + } + } + + /** + * Return maximum level of rssi + * @return + */ + public int getMaxLevel() { + return MAX_VALUE; + } + + /** + * Return minimim level of rssi + * @return + */ + public int getMinLevel() { + return MIN_VALUE; + } + + /** + * + * @param level + * @return + * @throws IOException + * @throws DeviceEventException + * @throws ConnectionException + */ + public boolean setLevel(int level) throws IOException, DeviceEventException, ConnectionException { + if (level < MIN_VALUE || level > MAX_VALUE) { + throw new DeviceEventException(EILibError.InvalidValue); + } + + if (sender.setLevel(level)) { + if (level == MIN_VALUE) { + if (!isLevelZero) { + sendRssiStatus(); + isLevelZero = true; + } + } else { + if (isLevelZero) { + sendRssiStatus(); + isLevelZero = false; + } + } + } + return sender.setLevel(level); + } + + /** + * + * @return + * @throws IOException + * @throws ConnectionException + * @throws DeviceEventException + */ + public int getLevel() throws IOException, ConnectionException, DeviceEventException { + int level = sender.getLevel(); + + if (level == -1) { + throw new DeviceEventException(EILibError.FailedGetValue); + } + + return level; + } + + /** + * + * @return if this value is true, rssi level is zero. + * If rssi value is 0, the emulator's network does not work. + * So, call ant sms events do not work. + */ + private boolean isInit = false; + public boolean isLevelZero() { + if (!isInit){ + try { + if (getLevel() == 0) { + isLevelZero = true; + } + } catch (DeviceEventException e) { + // TODO Auto-generated catch block + EILogger.getLogger().warning(e.getMessage()); + } catch (IOException e) { + // TODO Auto-generated catch block + EILogger.getLogger().warning(e.getMessage()); + } catch (ConnectionException e) { + EILogger.getLogger().warning(e.getMessage()); + } + isInit = true; + } + return isLevelZero; + } + + private void sendRssiStatus() throws IOException, ConnectionException { + int netType = 0x02; // UMTS + int netServiceDomain = 0x01; // Combined(CS + PS) Mode + int netRegStatus = isLevelZero ? 0x01 : 0x00; + int netEdgeSupport = 0x00; // GSM_NET_EDGE_NOTSUPPORT + int lac0 = 0x11; + int lac1 = 0x20; + int id0 = 0x00; + int id1 = 0x00; + int id2 = 0x00; + int id3 = 0x0A; + int rejCause = 0x00; + + G02A31 ga = new G02A31(); + ga.intialize(); + + StructureGA sga = ga.getBody(); + sga.setInt("NET_ACT_TYPE", netType); + sga.setInt("NET_SVC_DOMAIN", netServiceDomain); + sga.setInt("NET_REG_STATUS", netRegStatus); + sga.setInt("NET_EDGE_SUPPORT", netEdgeSupport); + sga.setInt("LAC0", lac0); + sga.setInt("LAC1", lac1); + sga.setInt("CELL_ID0", id0); + sga.setInt("CELL_ID1", id1); + sga.setInt("CELL_ID2", id2); + sga.setInt("CELL_ID3", id3); + sga.setInt("REJ_CAUSE", rejCause); + + modemSender.send(ga); + } + + @Override + public void initEventInjector() { + // TODO Auto-generated method stub + + } +} + +class RSSIEventSender extends DeviceEventSender { + private EventMessage returnMsg = null; + + public RSSIEventSender(ConnectionToEmulator connector) { + super(connector); + // TODO Auto-generated constructor stub + } + + private static String RSSIID = "11\n"; + private double params[] = new double[1]; + + public synchronized boolean setLevel(int level) throws IOException, ConnectionException { + params[0] = level; + makeMessage(RSSIID, params); + return sendMessage(null); + } + + public synchronized int getLevel() throws IOException, ConnectionException { + // empty message + makeMessage(RSSIID, null); + sendMessage(ActionID.RSSI_LEVEL); + + synchronized(this) { + // wait 5 second + try { + this.wait(5000); + } catch (InterruptedException e) { + e.printStackTrace(); + EILogger.getLogger().warning(e.getMessage()); + } + } + + int level = -1; + if (returnMsg != null) { + if (returnMsg.getEventHeader().getActionID() + != ActionID.RSSI_LEVEL.getId()) { + // TODO : error + EILogger.getLogger().warning("An unexpected event occurs."); + } else { + level = ByteUtil.byte2int + (returnMsg.getDataBuffer().array(), 14); + if (level < RSSIEventInjector.MIN_VALUE + || level > RSSIEventInjector.MAX_VALUE) { + level = -1; + } + } + returnMsg = null; + } + + return level; + } + + @Override + public void fireEvent(EventMessage message) { + synchronized(this) { + this.returnMsg = message; + this.notifyAll(); + } + } + +} diff --git a/ei-library/src/org/tizen/eilib/events/SDCardEvent.java b/ei-library/src/org/tizen/eilib/events/SDCardEvent.java new file mode 100644 index 0000000..64db39c --- /dev/null +++ b/ei-library/src/org/tizen/eilib/events/SDCardEvent.java @@ -0,0 +1,59 @@ +/* + * EventInjector Library + * + * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * SooYoung Ha + * JiHye Kim + * YeongKyoon Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + + +package org.tizen.eilib.events; + +public class SDCardEvent { + private boolean isSucces; + private boolean isMount; + private String SDCardName; + + public boolean isMount() { + return isMount; + } + + void setMount(boolean isMount) { + this.isMount = isMount; + } + + public String getSDCardName() { + return SDCardName; + } + + void setSDCardName(String sDCardName) { + SDCardName = sDCardName; + } + + public boolean isSucces() { + return isSucces; + } + + void setSucces(boolean isSucces) { + this.isSucces = isSucces; + } + +} diff --git a/ei-library/src/org/tizen/eilib/events/SDCardEventInjector.java b/ei-library/src/org/tizen/eilib/events/SDCardEventInjector.java new file mode 100644 index 0000000..afee48d --- /dev/null +++ b/ei-library/src/org/tizen/eilib/events/SDCardEventInjector.java @@ -0,0 +1,433 @@ +/* + * EventInjector Library + * + * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * SooYoung Ha + * JiHye Kim + * YeongKyoon Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + + +package org.tizen.eilib.events; + +import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.util.ArrayList; + +import org.tizen.eilib.connection.ConnectionToEmulator; +import org.tizen.eilib.connection.Emulator; +import org.tizen.eilib.connection.EmulatorList; +import org.tizen.eilib.connection.message.EventMessage; +import org.tizen.eilib.connection.message.GroupID; +import org.tizen.eilib.events.listener.EventListenerList; +import org.tizen.eilib.events.listener.ISDcardEventListener; +import org.tizen.eilib.events.receiver.AbstractEventReceiver; +import org.tizen.eilib.events.sender.SDCardEventSender; +import org.tizen.eilib.events.sender.SDCardStatusCheckSender; +import org.tizen.eilib.events.type.SDCardEventType; +import org.tizen.eilib.exception.ConnectionException; +import org.tizen.eilib.exception.DeviceEventException; +import org.tizen.eilib.exception.EILibError; +import org.tizen.eilib.exception.InjectorLibraryException; +import org.tizen.eilib.tools.EILogger; + +/** + * This class send SD card event to the emulator. + * Using this class, you can mount sdcard or umount sdcard + * + */ +public class SDCardEventInjector extends AbstractEventInjector { + private SDCardStatusCheckSender statusCheckSender = null; + private SDCardEventReceiver receiver = null; + private SDCardEventSender sender = null; + private ConnectionToEmulator connector; + private EventListenerList listeners = new EventListenerList(); + + private boolean isDataWaiting = false; + private boolean isUnmountSuccess = false; + + SDCardEventInjector(ConnectionToEmulator connector) throws IOException, DeviceEventException, ConnectionException { + sender = new SDCardEventSender(connector); + receiver = new SDCardEventReceiver(this); + statusCheckSender = new SDCardStatusCheckSender(connector); + connector.addEventReceiver(GroupID.SDCARD, receiver); + this.connector = connector; + + queryMountStatus(); + //getCurrentMountStatus(true); + } + + @Override + public void initEventInjector() { + try { + queryMountStatus(); + //getCurrentMountStatus(true); + } catch (IOException e) { + EILogger.getLogger().warning(e.getMessage()); + } catch (DeviceEventException e) { + EILogger.getLogger().warning(e.getMessage()); + } catch (ConnectionException e) { + EILogger.getLogger().warning(e.getMessage()); + } + } + + /** + * Find out status sdcard of all running emulator. + * @throws IOException + * @throws ConnectionException + * @throws DeviceEventException + * @throws InjectorLibraryException + */ + public void queryMountStatus() throws IOException, DeviceEventException, ConnectionException { + ArrayList emulators = EmulatorList.getInstance().getEmulatorList(); + for (Emulator emulator : emulators) { + statusCheckSender.sendMountCheck(emulator, true); + } + } + + /** + * Return mount status. + * @return true - mount, false - umount + */ + public boolean isMounted() { + return connector.getCurrentEmulator().isMounted(); + } + + /** + * Return name of sdcard + * @return + */ + public String getMountSDCardName() { + return connector.getCurrentEmulator().getSDCardName(); + } + + /** + * Return whether the operation is success + * @return + */ + public boolean isUnmountSuccess() { + return isUnmountSuccess; + } + + /** + * Return mount status of current emulator. + * This function refresh mount status. + * @param isWait if this value false, this function returns immediately (asynchronous) + * @return + * @throws IOException + * @throws ConnectionException + * @throws DeviceEventException + */ + public boolean getCurrentMountStatus(boolean isWait) throws IOException, ConnectionException, DeviceEventException { + isDataWaiting = true; + if (!sender.getMountStatus()) { + // TODO : exception + return false; + } + + if (isWait) { + synchronized(this) { + try { + this.wait(2000); + } catch (InterruptedException e1) { + EILogger.getLogger().warning(e1.getMessage()); + } + } + if (isDataWaiting) { + throw new DeviceEventException(EILibError.FailedGetValue); + } + } + return true; + } + + /** + * + * @param isWait if this value false, this function returns immediately (asynchronous) + * @return + * @throws IOException + * @throws ConnectionException + */ + public boolean unmount(boolean isWait) throws IOException, ConnectionException { + isUnmountSuccess = false; + + //getCurrentMountStatus(true); + + if (!isMounted()) { + return true; + } + + if (!sender.sendUnmount()) { + // TODO :exception + return false; + } + + if (isWait) { + synchronized(this) { + try { + this.wait(); + } catch (InterruptedException e1) { + EILogger.getLogger().warning(e1.getMessage()); + } + } + + if (isMounted()) { + return false; + } + + if (!isUnmountSuccess()) { + return false; + } + } + return true; + } + + /** + * + * @param SDCardName + * @param isWait if this value false, this function returns immediately (asynchronous) + * @return + * @throws IOException + * @throws InjectorLibraryException + * @throws ConnectionException + */ + public boolean mount(String SDCardName, boolean isWait) + throws IOException, ConnectionException, InjectorLibraryException { + + queryMountStatus(); + //getCurrentMountStatus(true); + + if (isMounted()) { + throw new InjectorLibraryException(EILibError.EmulatorIsMounted); + } + + for (Emulator e : EmulatorList.getInstance().getEmulatorList()) { + if (e.isMounted()) { + if (e.getSDCardName().equals(SDCardName)) { + throw new InjectorLibraryException(EILibError.SDCardIsMounted); + } + } + } + + if (!sender.sendMount(SDCardName)) { + // TODO : exception + return false; + } + + if (isWait) { + synchronized(this) { + try { + this.wait(); + } catch (InterruptedException e1) { + EILogger.getLogger().warning(e1.getMessage()); + } + } + if (!isMounted()) { + return false; + } + } + return true; + } + + /** + * Add SDCard event listener. + * + * @param listener + */ + public void addSDCardEventListener(ISDcardEventListener listener) { + listeners.add(listener); + } + + /** + * Remove SDCard event listener. + * + * @param listener + */ + public void removeSDCardEventListener(ISDcardEventListener listener) { + listeners.remove(listener); + } + + private Emulator emulator = null; + synchronized void fireUnmountSuccess(String name) { + emulator = connector.getCurrentEmulator(); + emulator.setMounted(false); + emulator.setSDCardName(""); + isUnmountSuccess = true; + + synchronized(this) { + this.notifyAll(); + } + + // TODO + SDCardEvent event = new SDCardEvent(); + event.setMount(false); + event.setSucces(true); + event.setSDCardName(name); + + for (int i = 0 ; i < listeners.size() ; i++) { + final ISDcardEventListener listener = (ISDcardEventListener)listeners.getListeners().get(i); + listener.completeUnmount(event); + } + } + + synchronized void fireMountSuccess(String name) { + emulator = connector.getCurrentEmulator(); + emulator.setMounted(true); + emulator.setSDCardName(name); + + synchronized(this) { + this.notifyAll(); + } + + // TODO + SDCardEvent event = new SDCardEvent(); + event.setMount(true); + event.setSucces(true); + event.setSDCardName(name); + + for (int i = 0 ; i < listeners.size() ; i++) { + final ISDcardEventListener listener = (ISDcardEventListener)listeners.getListeners().get(i); + listener.completeMount(event); + } + } + + synchronized void fireUnmountStatus(String name) { + emulator = connector.getCurrentEmulator(); + emulator.setMounted(false); + emulator.setSDCardName(""); + isDataWaiting = false; + + synchronized(this) { + this.notifyAll(); + } + + // TODO + SDCardEvent event = new SDCardEvent(); + event.setMount(false); + event.setSucces(true); + event.setSDCardName(name); + + for (int i = 0 ; i < listeners.size() ; i++) { + final ISDcardEventListener listener = (ISDcardEventListener)listeners.getListeners().get(i); + listener.completeQeueryStatus(event); + } + } + + synchronized void fireMountStatus(String name) { + emulator = connector.getCurrentEmulator(); + emulator.setMounted(true); + emulator.setSDCardName(name); + isDataWaiting = false; + + synchronized(this) { + this.notifyAll(); + } + // TODO + SDCardEvent event = new SDCardEvent(); + event.setMount(true); + event.setSucces(true); + event.setSDCardName(name); + + for (int i = 0 ; i < listeners.size() ; i++) { + final ISDcardEventListener listener = (ISDcardEventListener)listeners.getListeners().get(i); + listener.completeQeueryStatus(event); + } + } + + synchronized void fireUnmountFailed(String name) { + isUnmountSuccess = false; + + synchronized(this) { + this.notifyAll(); + } + + // TODO + SDCardEvent event = new SDCardEvent(); + event.setMount(false); + event.setSucces(false); + event.setSDCardName(name); + + for (int i = 0 ; i < listeners.size() ; i++) { + final ISDcardEventListener listener = (ISDcardEventListener)listeners.getListeners().get(i); + listener.completeUnmount(event); + } + } + + synchronized void fireMountFailed(String name) { + EILogger.getLogger().warning("Fire mount failed :" + name); + + // empty.. + synchronized(this) { + this.notifyAll(); + } + } + + /** + * + * @return + */ + public boolean isDataWaiting() { + return isDataWaiting; + } +} + +class SDCardEventReceiver extends AbstractEventReceiver { + private SDCardEventInjector injector; + public SDCardEventReceiver(SDCardEventInjector injector) { + super("SD card event"); + this.injector = injector; + } + + @Override + public void run(EventMessage message) { + int len = message.getDataBuffer().position(); + String name = ""; + if (len != 0) { + try { + name = new String(message.getDataBuffer().array(), + message.getDataBufferOffset(), len, "US-ASCII"); + } catch (UnsupportedEncodingException e) { + EILogger.getLogger().warning(e.getMessage()); + name = ""; + } + } + switch(message.getEventHeader().getActionID()) { + case SDCardEventType.Action_Unmount: + injector.fireUnmountSuccess(name); + break; + case SDCardEventType.Action_Mount: + injector.fireMountSuccess(name); + break; + case SDCardEventType.Status_Unmount: + injector.fireUnmountStatus(name); + break; + case SDCardEventType.Status_Mount: + injector.fireMountStatus(name); + break; + case SDCardEventType.Fail_Unmount: + injector.fireUnmountFailed(name); + break; + case SDCardEventType.Fail_Mount: + injector.fireMountFailed(name); + break; + default: + // TODO + } + } +} \ No newline at end of file diff --git a/ei-library/src/org/tizen/eilib/events/SMSEvent.java b/ei-library/src/org/tizen/eilib/events/SMSEvent.java new file mode 100644 index 0000000..2322c51 --- /dev/null +++ b/ei-library/src/org/tizen/eilib/events/SMSEvent.java @@ -0,0 +1,58 @@ +/* + * EventInjector Library + * + * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * SooYoung Ha + * JiHye Kim + * YeongKyoon Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + +package org.tizen.eilib.events; + +import org.tizen.eilib.events.type.SMSEventType; + +public class SMSEvent { + private SMSEventType type; + private String number; + private String message; + public SMSEventType getType() { + return type; + } + + void setType(SMSEventType type) { + this.type = type; + } + + public String getNumber() { + return number; + } + + void setNumber(String number) { + this.number = number; + } + + public String getMessage() { + return message; + } + + void setMessage(String message) { + this.message = message; + } +} diff --git a/ei-library/src/org/tizen/eilib/events/SMSEventInjector.java b/ei-library/src/org/tizen/eilib/events/SMSEventInjector.java new file mode 100644 index 0000000..70e1e59 --- /dev/null +++ b/ei-library/src/org/tizen/eilib/events/SMSEventInjector.java @@ -0,0 +1,540 @@ +/* + * EventInjector Library + * + * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * SooYoung Ha + * JiHye Kim + * YeongKyoon Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + + +package org.tizen.eilib.events; + +import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Date; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import org.tizen.eilib.connection.ConnectionToEmulator; +import org.tizen.eilib.connection.message.EventMessage; +import org.tizen.eilib.connection.message.GroupID; +import org.tizen.eilib.events.listener.EventListenerList; +import org.tizen.eilib.events.listener.ISMSEventListener; +import org.tizen.eilib.events.receiver.AbstractEventReceiver; +import org.tizen.eilib.events.sender.ModemEventSender; +import org.tizen.eilib.events.type.SMSStatus; +import org.tizen.eilib.exception.ConnectionException; +import org.tizen.eilib.exception.EILibError; +import org.tizen.eilib.exception.SMSEventException; +import org.tizen.eilib.modem.encription.DecodeMsg; +import org.tizen.eilib.modem.encription.EncodeMsg; +import org.tizen.eilib.modem.encription.EnumConstants; +import org.tizen.eilib.modem.encription.SMS_USERDATA; +import org.tizen.eilib.modem.encription.SmsAddressInfo; +import org.tizen.eilib.modem.encription.TPDU_SMS_DELIVER; +import org.tizen.eilib.modem.encription.TPDU_SMS_SUBMIT; +import org.tizen.eilib.modem.encription.TapiNetTextCodingScheme; +import org.tizen.eilib.modem.encription.TmDateTime; +import org.tizen.eilib.modem.protocol.AbstractGA; +import org.tizen.eilib.modem.protocol.G04A01; +import org.tizen.eilib.modem.protocol.G04A05; +import org.tizen.eilib.modem.protocol.StructureGA; +import org.tizen.eilib.tools.EILogger; + +/** + * Instances of this class send sms event to the emulator. + * + */ +public class SMSEventInjector extends AbstractEventInjector { + private SMSEventSender sender = null; + private SMSEventReceiver receiver = null; + private EventListenerList listeners = new EventListenerList(); + private boolean isMsgReceived = false; + + SMSEventInjector(ConnectionToEmulator connector) { + sender = new SMSEventSender(connector); + receiver = new SMSEventReceiver(this); + + connector.addEventReceiver(GroupID.SMS, receiver); + } + + private RSSIEventInjector rssi; + void setRssiEventInjector(RSSIEventInjector rssi) { + this.rssi = rssi; + } + + /** + * Set sms send status in the emulator. + * If status value is error, to transfer sms from emulator will be failed. + * + * @param status success or fail + * @return result + * @throws IOException + * @throws ConnectionException + */ + public boolean sendStatus(SMSStatus status) throws IOException, ConnectionException { + G04A05 ga = new G04A05(); + ga.intialize(); + + StructureGA sga = ga.getBody(); + sga.setInt("DATA1", status.getValue() & 0x00ff); + sga.setInt("DATA2", (status.getValue() >> 8) & 0x00ff); + + sender.send(ga); + + return true; + } + + /** + * Send SMS to the emulator. + * This function return immediately after sends the message, does not check result of sending message. + * You can check the result to transfer message using 'isMsgReceived()' function. + * + * @param number phone number (sender) + * @param message text message (limit of length is 80) + * @return + * @throws IOException + * @throws SMSEventException + * @throws ConnectionException + */ + public boolean sendMessage(String number, String message) throws IOException, SMSEventException, ConnectionException { + return sendMessage(number, message, false); + } + + /** + * Send SMS to the emulator + * @param number phone number + * @param message text message + * @param isWait if this value is true, wait until arrive return message. + * + * @return + * @throws IOException + * @throws SMSEventException + * @throws ConnectionException + */ + public boolean sendMessage(String number, String message, boolean isWait) throws IOException, SMSEventException, ConnectionException { + // TODO : check rssi Status ?? + if (rssi.isLevelZero()) { + throw new SMSEventException(EILibError.RSSIIsZero); + } + + // throw SMSEventException(); + if (!checkNumber(number)) { + throw new SMSEventException(EILibError.NumberFormatError); + } + + if (message.length() > 80) { + throw new SMSEventException(EILibError.MessageIsTooLong); + } + + char[] packet = new char[500]; + int pid = 0; + int dcs = 0xF0; + + EncodeMsg encode = new EncodeMsg(); + + TPDU_SMS_DELIVER tpdu_deliver = new TPDU_SMS_DELIVER(); + tpdu_deliver.msgType = 0; + tpdu_deliver.mms = false; + tpdu_deliver.rp = false; + tpdu_deliver.udhi = false; + tpdu_deliver.sri = false; + + SmsAddressInfo orgAddr = new SmsAddressInfo(); + orgAddr.diallingNum = number.toCharArray(); + orgAddr.dialnumlen = orgAddr.diallingNum.length; + + tpdu_deliver.orgAddr = orgAddr; + tpdu_deliver.pId = 0; + tpdu_deliver.scts = getDateTime(); + tpdu_deliver.dcs = getScheme(); + tpdu_deliver.udl = 0; + + ArrayList dataArray = getUserData(message); + if (dataArray.size() > 1) { + tpdu_deliver.udhi = true; + } + + for (SMS_USERDATA userData : dataArray) { + tpdu_deliver.userData = userData; + int packet_len = encode.EncodeSmsDeliverTpdu(getSCA(), + tpdu_deliver, packet, pid, dcs); + final byte[] data = convertToByte(packet, packet_len); + + G04A01 ga = new G04A01() { + protected void makeBody() { + StructureGA ga = getBody(); + ga.addByteArrayItem("DATA", data.length); + } + }; + ga.intialize(); + + StructureGA sga = ga.getBody(); + sga.setByteArray("DATA", data); + + // message 전송이 성공하기 전에 여러번 메시지를 보내면 어떻게 되는가??? + // 하나의 message가 전송 완료되기 전에 다음 메시지를 받으면 안될 것 같음... + setMsgReceived(false); + + // SEND DATA + sender.send(ga); + } + + if (isWait) { + synchronized(this) { + try { + // wait 10 second + this.wait(10000); + } catch (InterruptedException e) { + e.printStackTrace(); + EILogger.getLogger().warning(e.getMessage()); + } + } + + if (!isMsgReceived()) { + throw new SMSEventException(EILibError.SendMessageFailed); + } + } + + return true; + } + + /** + * Return sending message status + * + * @return if this value is true, sending message success. + */ + public boolean isMsgReceived() { + return isMsgReceived; + } + + void setMsgReceived(boolean isMsgReceived) { + this.isMsgReceived = isMsgReceived; + } + + /** + * Add sms event listener. + * TODO : You can receive SMS from emulator. + * + * @param listener + */ + public void addSMSEventListener(ISMSEventListener listener) { + listeners.add(listener); + } + + /** + * Remove sms event listener. + * + * @param listener + */ + public void removeSMSEventListener(ISMSEventListener listener) { + listeners.remove(listener); + } + + private SimpleDateFormat yearFormat = new SimpleDateFormat("yyyy"); + private SimpleDateFormat monthFormat = new SimpleDateFormat("MM"); + private SimpleDateFormat dayFormat = new SimpleDateFormat("dd"); + private SimpleDateFormat hourFormat = new SimpleDateFormat("HH"); + private SimpleDateFormat minuteFormat = new SimpleDateFormat("mm"); + private SimpleDateFormat secondFormat = new SimpleDateFormat("ss"); + private TmDateTime getDateTime() { + Date date = new Date(); + TmDateTime tm = new TmDateTime(); + tm.year = Integer.parseInt(yearFormat.format(date).trim()); + tm.month = Integer.parseInt(monthFormat.format(date).trim()); + tm.day = Integer.parseInt(dayFormat.format(date).trim()); + tm.hour = Integer.parseInt(hourFormat.format(date).trim()); + tm.minute = Integer.parseInt(minuteFormat.format(date).trim()); + tm.second = Integer.parseInt(secondFormat.format(date).trim()); + return tm; + } + + private TapiNetTextCodingScheme getScheme() { + TapiNetTextCodingScheme scheme = new TapiNetTextCodingScheme(); + scheme.bCompressed = false; + scheme.bMsgClassSet = false; + scheme.bMsgIndActive = false; + scheme.codingGroupType = EnumConstants.TAPI_NETTEXT_CODGRP_SM_GENERAL_DCS; + scheme.waitingType = EnumConstants.TAPI_NETTEXT_WAITING_VOICE_MSG; + scheme.alphabetType = EnumConstants.TAPI_NETTEXT_ALPHABET_UCS2; +// scheme.alphabetType = EnumConstants.TAPI_NETTEXT_ALPHABET_8BIT; +// scheme.classType = cmbMobileTerminateClassType.getSelectionIndex(); + scheme.classType = 0; + scheme.codingGroup = 0; + scheme.code = 0; + + return scheme; + } + + private SmsAddressInfo SCA = null; + private final char[] SMSC_NUM = {+8, 2, 1, 0, 9, 1, 1, 1, 1}; + private SmsAddressInfo getSCA() { + if (SCA == null) { + SCA = new SmsAddressInfo(); + //SCA.diallingNum = String.format(cmbMobileTerminateUseSMSC.getText()).toCharArray(); + SCA.diallingNum = SMSC_NUM; + SCA.dialnumlen = SCA.diallingNum.length; + } + return SCA; + } + + private void sendDeliveryReport() throws IOException, ConnectionException { + char[] packet = new char[500]; + int pid = 0; + int dcs = 0xF0; + + EncodeMsg encode = new EncodeMsg(); + + TPDU_SMS_DELIVER tpdu_deliver = new TPDU_SMS_DELIVER(); + tpdu_deliver.msgType = 0; + tpdu_deliver.mms = false; + tpdu_deliver.rp = false; + tpdu_deliver.udhi = false; + tpdu_deliver.sri = false; + + SmsAddressInfo orgAddr = new SmsAddressInfo(); + String dstnum = DecodeMsg.deliveryReportNum_set.iterator().next(); + DecodeMsg.deliveryReportNum_set.remove(dstnum); + orgAddr.diallingNum = String.format(dstnum).toCharArray(); +// orgAddr.diallingNum = String.format( +// txtMobileTerminateReceivedNumber.getText()).toCharArray(); + orgAddr.dialnumlen = orgAddr.diallingNum.length; + + tpdu_deliver.orgAddr = orgAddr; + tpdu_deliver.pId = 0; + tpdu_deliver.scts = getDateTime(); + tpdu_deliver.dcs = getScheme(); + tpdu_deliver.udl = 0; + String msg = "Message delivered."; + SMS_USERDATA userData1 = new SMS_USERDATA(); + try { + userData1.data = msg.getBytes("ISO-10646-UCS-2"); + userData1.length = userData1.data.length; + userData1.headerCnt = 0; + userData1.setSMSUDH((char)0x00, (short)0x0000, (char)2, (char)1); + tpdu_deliver.userData = userData1; + } catch (UnsupportedEncodingException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + int packet_len = encode.EncodeSmsDeliverTpdu(getSCA(), + tpdu_deliver, packet, pid, dcs); + final byte[] data = convertToByte(packet, packet_len); + + G04A01 ga = new G04A01() { + protected void makeBody() { + StructureGA ga = getBody(); + ga.addByteArrayItem("DATA", data.length); //$NON-NLS-1$ + } + }; + ga.intialize(); + + StructureGA sga = ga.getBody(); + sga.setByteArray("DATA", data); //$NON-NLS-1$ + + // SEND DATA + sender.send(ga); + } + + private boolean checkNumber(String number) throws SMSEventException { + if (number == null || number.length() == 0) { + throw new SMSEventException(EILibError.NumberIsEmpty); + } + + if (number.length() > 15) { + throw new SMSEventException(EILibError.NumberIsTooLong); + } + + Pattern tellPattern = Pattern.compile( "[^0-9++]"); + Matcher matcher = tellPattern.matcher(number); + return !matcher.find(); + } + + private ArrayList getUserData(String message) { + ArrayList list = new ArrayList(); + int length = 60; //temp length + int count = message.length() / length; + count = count + 1; + int index = 0; + SMS_USERDATA userData; + + for (int i = 0; i < count; i++) { + userData = new SMS_USERDATA(); + try { + int len = index+length > (message.length() - index) ? (message.length() - index) + : index + length; + userData.data = message.substring(index, index + len).getBytes("ISO-10646-UCS-2"); + userData.length = userData.data.length; + userData.headerCnt = 1; + userData.setSMSUDH((char)0x00, (short)0x0000, (char)count, (char)(i+1)); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + continue; + } + if (count == 1) { + userData.headerCnt = 0; + } + list.add(userData); + index = index + length; + } + return list; + } + + private byte[] convertToByte(char[] buf, int length) { + byte[] result = new byte[length]; + for (int i = 0; i < length; i++) { + result[i] = (byte) buf[i]; + } + return result; + } + + private char[] convertToChar(byte[] buf, int start, int length) { + char[] result = new char[length]; + int idx = 0; + for (int i = 0; i < buf.length; i++) { + if (i >= start) { + result[idx++] = (char) buf[i]; + if (idx >= length) { + break; + } + } + } + return result; + } + + void fireSMSEvent(AbstractGA ga) throws IOException, ConnectionException { + StructureGA sga = ga.getBody(); + + TPDU_SMS_SUBMIT tpdu_submit = new TPDU_SMS_SUBMIT(); + byte[] buf = sga.getByteArray("DATA"); + char[] rawdata = convertToChar(buf, 3, buf.length - 3); // new + // change + // May 6 + + // System.out.println(); + // for(int i = 0; i + * JiHye Kim + * YeongKyoon Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + + +package org.tizen.eilib.events; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import org.tizen.eilib.connection.ConnectionToEmulator; +import org.tizen.eilib.connection.Emulator; +import org.tizen.eilib.connection.message.ActionID; +import org.tizen.eilib.connection.message.GroupID; +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.sender.SensorEventSender; +import org.tizen.eilib.tools.EILogger; +import org.tizen.sdblib.SyncService; +import org.tizen.sdblib.SyncService.SyncResult; + +import org.tizen.eilib.events.type.MotionEventType; +import org.tizen.eilib.events.type.ProximityStatus; +import org.tizen.eilib.events.type.SensorEventType; + +import org.tizen.eilib.exception.ConnectionException; +import org.tizen.eilib.exception.EILibError; +import org.tizen.eilib.exception.InjectorLibraryException; +import org.tizen.eilib.exception.SensorEventException; + +/** + * Manual sensor event + * + */ +public class SensorEventInjector extends AbstractEventInjector { + private SensorEventSender sender = null; + private ConnectionToEmulator connector; + private ArrayList logFiles; + + SensorEventInjector(ConnectionToEmulator connector) { + sender = new SensorEventSender(connector); + + EventReceiver receiver = new EventReceiver("SensorReceiver", sender); + + AbstractEventReceiver abReceiver = connector.findEventReceiver(GroupID.STATUS); + if (abReceiver != null && abReceiver instanceof StatusEventReceiver) { + StatusEventReceiver re = (StatusEventReceiver)abReceiver; + re.addStatusEventReceiver(ActionID.ACCEL_VALUE, receiver); + re.addStatusEventReceiver(ActionID.GYRO_VALUE, receiver); + re.addStatusEventReceiver(ActionID.MAG_VALUE, receiver); + re.addStatusEventReceiver(ActionID.LIGHT_VALUE, receiver); + re.addStatusEventReceiver(ActionID.PROXI_VALUE, receiver); + re.addStatusEventReceiver(ActionID.MOTION_VALUE, receiver); + } + + this.connector = connector; + logFiles = new ArrayList(); + } + + private double G = 9.80665; + private double MAX_ACCEL = 2.00; + private double MIN_ACCEL = -2.00; + + /** + * Return minimum acceleration value. + * @return + */ + public double getMinAccelValue() { + return MIN_ACCEL; + } + + /** + * Return maximum acceleration value. + * @return + */ + public double getMaxAccelValue() { + return MAX_ACCEL; + } + + /** + * Send acceleration event to emulator. + * Min value : -2.00 + * Max value : 2.00 + * @param x + * @param y + * @param z + * @return + * @throws IOException + * @throws SensorEventException + * @throws ConnectionException + * @throws InjectorLibraryException + */ + public boolean accelEvent(double x, double y, double z) throws IOException, SensorEventException, ConnectionException { + if (x > MAX_ACCEL || x < MIN_ACCEL) { + throw new SensorEventException(EILibError.InvalidSensorValue); + } + if (y > MAX_ACCEL || y < MIN_ACCEL) { + throw new SensorEventException(EILibError.InvalidSensorValue); + } + if (z > MAX_ACCEL || z < MIN_ACCEL) { + throw new SensorEventException(EILibError.InvalidSensorValue); + } + + return sender.sendManualEvent(SensorEventType.ACCEL, x * G, y * G, z * G); + } + + public double[] getAccelValue() throws IOException, ConnectionException, SensorEventException { + String value = sender.getSensorValue(SensorEventType.ACCEL); + double[] values = null; + if (value != null) { + String[] str = value.split(","); + values = new double[3]; + int i = 0; + try { + for (String v : str) { + double t = Double.valueOf(v); + values[i++] = t / G / 100000; + } + } catch(NumberFormatException t) { + throw new SensorEventException(EILibError.FailedGetValue); + } + } else { + throw new SensorEventException(EILibError.FailedGetValue); + } + + return values; + } + + private double MAX_GYRO = 10.00; + private double MIN_GYRO = -10.00; + private int GYRO_VALUE = 1000; + + /** + * Return minimum gyroscope value + * @return + */ + public double getMinGyroValue() { + return MIN_GYRO; + } + + /** + * Return maximum gyroscope value + * @return + */ + public double getMaxGyroValue() { + return MAX_GYRO; + } + + /** + * Send gyroscope sensor event to emulator + * Min value : -10.00 + * Max value : 10.00 + * @param x + * @param y + * @param z + * @return + * @throws IOException + * @throws ConnectionException + * @throws SensorEventException + */ + public boolean gyroEvent(double x, double y, double z) throws IOException, ConnectionException, SensorEventException { + if (x > MAX_GYRO || x < MIN_GYRO) { + throw new SensorEventException(EILibError.InvalidSensorValue); + } + if (y > MAX_GYRO || y < MIN_GYRO) { + throw new SensorEventException(EILibError.InvalidSensorValue); + } + if (z > MAX_GYRO || z < MIN_GYRO) { + throw new SensorEventException(EILibError.InvalidSensorValue); + } + + return sender.sendManualEvent(SensorEventType.GYRO, x * GYRO_VALUE, y * GYRO_VALUE, z * GYRO_VALUE); + } + + + public double[] getGyroValue() throws IOException, ConnectionException, SensorEventException { + String value = sender.getSensorValue(SensorEventType.GYRO); + double[] values = null; + if (value != null) { + String[] str = value.split(","); + values = new double[3]; + int i = 0; + try { + for (String v : str) { + double t = Double.valueOf(v); + values[i++] = (t * 17.50) / GYRO_VALUE; + } + } catch(NumberFormatException t) { + throw new SensorEventException(EILibError.FailedGetValue); + } + } else { + throw new SensorEventException(EILibError.FailedGetValue); + } + + return values; + } + + private int MAX_MAGNETIC = 2000; + private int MIN_MAGNETIC = -2000; + + /** + * Return minimum magnetic value + * @return + */ + public int getMinMagneticValue() { + return MIN_MAGNETIC; + } + + /** + * Return maximum magnetic value + * @return + */ + public int getMaxMagneticValue() { + return MAX_MAGNETIC; + } + + /** + * Send magnetic sensor event to emulator + * @param x + * @param y + * @param z + * @return + * @throws IOException + * @throws ConnectionException + * @throws SensorEventException + */ + public boolean magneticEvent(int x, int y, int z) throws IOException, ConnectionException, SensorEventException { + if (x > MAX_MAGNETIC || x < MIN_MAGNETIC) { + throw new SensorEventException(EILibError.InvalidSensorValue); + } + if (y > MAX_MAGNETIC || y < MIN_MAGNETIC) { + throw new SensorEventException(EILibError.InvalidSensorValue); + } + if (z > MAX_MAGNETIC || z < MIN_MAGNETIC) { + throw new SensorEventException(EILibError.InvalidSensorValue); + } + + return sender.sendManualEvent(SensorEventType.MAGNETIC, x, y, z); + } + + public int[] getMagneticValue() throws IOException, ConnectionException, SensorEventException{ + String value = sender.getSensorValue(SensorEventType.MAGNETIC); + int[] values = null; + if (value != null) { + String[] str = value.split(" "); + values = new int[3]; + int i = 0; + try { + for (String v : str) { + if (v.endsWith("\n")) { + v = v.substring(0, v.length() - 1); + } + int t = Integer.valueOf(v); + values[i++] = t; + } + } catch(NumberFormatException t) { + throw new SensorEventException(EILibError.FailedGetValue); + } + } else { + throw new SensorEventException(EILibError.FailedGetValue); + } + + return values; + } + + /** + * Send sensor event to emulator using log file. + * @param type + * @param filePath + * @return + * @throws IOException + * @throws ConnectionException + * @throws InjectorLibraryException + */ + public boolean sendLogFileEvent(SensorEventType type, String filePath) throws IOException, ConnectionException { + return sendLogFileEvent(type, filePath, 1); + } + + /** + * Send sensor event to emulator using log file. + * @param type + * @param filePath + * @param repeatCount + * @return + * @throws IOException + * @throws ConnectionException + * @throws InjectorLibraryException + */ + public boolean sendLogFileEvent(SensorEventType type, String filePath, int repeatCount) throws IOException, ConnectionException { + List files = new ArrayList(); + files.add(filePath); + return logFileEvent(type, files, repeatCount); + } + + /** + * Send sensor event to emulator using log file. + * @param type + * @param files + * @return + * @throws IOException + * @throws ConnectionException + * @throws InjectorLibraryException + */ + public boolean sendLogFileEvent(SensorEventType type, List files) throws IOException, ConnectionException { + return sendLogFileEvent(type, files, 1); + } + + /** + * Send sensor event to emulator using log file. + * @param type + * @param files + * @param repeatCount + * @return + * @throws IOException + * @throws ConnectionException + */ + public boolean sendLogFileEvent(SensorEventType type, List files, int repeatCount) throws IOException, ConnectionException { + return logFileEvent(type, files, repeatCount); + } + + private String remoteAccelFilePath = "/opt/sensor/accel/InputFiles/"; + private String remoteGyroFilePath = "/opt/sensor/gyro/InputFiles/"; + private String remoteMagneticFilePath = "/opt/sensor/geo/InputFiles/"; + private boolean logFileEvent(SensorEventType type, List files, int repeatCount) throws IOException, ConnectionException { + logFiles.clear(); + String remoteFilePath = ""; + switch(type) { + case FILE_ACCEL: + remoteFilePath = remoteAccelFilePath; + break; + case FILE_GYRO: + remoteFilePath = remoteGyroFilePath; + break; + case FILE_MAGNETIC: + remoteFilePath = remoteMagneticFilePath; + break; + default: + // TODO : error + return false; + } + + File file = null; + Emulator emulator = connector.getCurrentEmulator(); + if (emulator == null) { + // TODO :exception + return false; + } + + for(String f : files) { + file = new File(f); + if(!file.exists()) { + EILogger.getLogger().warning("File Not Found : " + file.getAbsolutePath()); + continue; + } + + SyncService sync = emulator.getSyncService(); + if (sync != null) { + SyncResult result = sync.pushFile(file.getPath(), remoteFilePath + file.getName() , SyncService.getNullProgressMonitor()); + if (result.getCode() != SyncService.RESULT_OK) { + // TODO + continue; + } + } + logFiles.add(file.getName()); + } + + if (logFiles.isEmpty()) { + // TODO : exception + return false; + } + + return sender.sendLogEvent(type, repeatCount, logFiles); + } + + private int MIN_LUX_DATA = 1; + private int MAX_LUX_DATA = 65535; + private int level = 10; + + /** + * + * @param luxData + * @return + * @throws IOException + * @throws ConnectionException + * @throws InjectorLibraryException + */ + public boolean ligthEvent(int luxData) throws IOException, ConnectionException, InjectorLibraryException { + if (luxData < MIN_LUX_DATA || luxData > MAX_LUX_DATA) { + throw new InjectorLibraryException(EILibError.InvalidSensorValue); + } + + return sender.sendLightEvent(luxData, getLevelData(luxData)); + } + + /** + * + * @return + * @throws IOException + * @throws ConnectionException + * @throws SensorEventException + */ + public int getLightValue() throws IOException, ConnectionException, SensorEventException { + int level = sender.getLightValue(); + + if (level < MIN_LUX_DATA || level > MAX_LUX_DATA) { + throw new SensorEventException(EILibError.FailedGetValue); + } + + return level; + } + + /** + * Return minimum light value + * @return + */ + public int getMinLightValue() { + return MIN_LUX_DATA; + } + + /** + * Return maximum light value + * @return + */ + public int getMaxLightValue() { + return MAX_LUX_DATA; + } + + private int getLevelData(int luxData) { + return (luxData / 6554) % level + 1; // TODO + } + + /** + * + * @param event + * @return + * @throws IOException + * @throws ConnectionException + */ + public boolean motionEvent(MotionEventType event) throws IOException, ConnectionException { + return sender.sendMotionEvent(event); + } + + /** + * + * @param status + * @return + * @throws IOException + * @throws ConnectionException + * @throws InjectorLibraryException + */ + public boolean proximityEvent(ProximityStatus status) throws IOException, ConnectionException { + return sender.sendProximityEvent(status); + } + + /** + * + * @return + * @throws IOException + * @throws ConnectionException + * @throws SensorEventException + */ + public ProximityStatus getProximityStatus() throws IOException, ConnectionException, SensorEventException { + ProximityStatus status = sender.getProxiStatus(); + + if (status == null) { + throw new SensorEventException(EILibError.FailedGetValue); + } + + return status; + } + + @Override + public void initEventInjector() { + } +} diff --git a/ei-library/src/org/tizen/eilib/events/USBEventInjector.java b/ei-library/src/org/tizen/eilib/events/USBEventInjector.java new file mode 100644 index 0000000..c17f125 --- /dev/null +++ b/ei-library/src/org/tizen/eilib/events/USBEventInjector.java @@ -0,0 +1,168 @@ +/* + * EventInjector Library + * + * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * SooYoung Ha + * JiHye Kim + * YeongKyoon Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + +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.connection.message.EventMessage; +import org.tizen.eilib.connection.message.GroupID; +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.sender.DeviceEventSender; +import org.tizen.eilib.events.type.USBStatus; +import org.tizen.eilib.exception.ConnectionException; +import org.tizen.eilib.exception.DeviceEventException; +import org.tizen.eilib.exception.EILibError; +import org.tizen.eilib.modem.protocol.ByteUtil; +import org.tizen.eilib.tools.EILogger; + +/** + * Instances of this class send status of usb event to the emulator. + *

          + *
          Send Events :
          + *
          USB's status
          + *
          + *

          + */ +public class USBEventInjector extends AbstractEventInjector { + private USBEventSender sender = null; + + USBEventInjector(ConnectionToEmulator connector) { + sender = new USBEventSender(connector); + EventReceiver receiver = new EventReceiver("USBReceiver", sender); + + AbstractEventReceiver abReceiver = connector.findEventReceiver(GroupID.STATUS); + if (abReceiver != null && abReceiver instanceof StatusEventReceiver) { + StatusEventReceiver re = (StatusEventReceiver)abReceiver; + re.addStatusEventReceiver(ActionID.USB_STATUS, receiver); + } + } + + /** + * Change usb status of emulator. + * + * @param status USBStatus.DISCONNECT, + * USBStatus.CONNECT + * @throws IOException + * @throws ConnectionException + * + */ + public boolean setStatus(USBStatus status) throws IOException, ConnectionException { + return sender.setStatus(status); + } + + /** + * Get usb status of emulator. + * + * @return status of USB connection + * USBStatus.DISCONNECT, + * USBStatus.CONNECT + * @throws DeviceEventException + * @throws IOException + * @throws ConnectionException + * + */ + public USBStatus getStatus() throws IOException, DeviceEventException, ConnectionException { + USBStatus status = sender.getStatus(); + if (status == null) { + throw new DeviceEventException(EILibError.FailedGetValue); + } + return status; + } + + @Override + public void initEventInjector() { + // TODO Auto-generated method stub + + } +} + +class USBEventSender extends DeviceEventSender { + USBEventSender(ConnectionToEmulator connector) { + super(connector); + } + + private static String USBID = "10\n"; + private EventMessage returnMsg = null; + + public synchronized USBStatus getStatus() throws IOException, ConnectionException { + // empty message + makeMessage(USBID, null); + sendMessage(ActionID.USB_STATUS); + + synchronized(this) { + // wait 5 second + try { + this.wait(5000); + } catch (InterruptedException e) { + e.printStackTrace(); + EILogger.getLogger().warning(e.getMessage()); + } + } + + USBStatus status = null; + if (returnMsg != null) { + if (returnMsg.getEventHeader().getActionID() + != ActionID.USB_STATUS.getId()) { + // TODO : error + EILogger.getLogger().warning("An unexpected event occurs."); + } else { + int state = ByteUtil.byte2int + (returnMsg.getDataBuffer().array(), 14); + for (USBStatus s : USBStatus.values()) { + if (s.getValue() == state) { + status = s; + break; + } + } + } + returnMsg = null; + } + + return status; + } + + public synchronized boolean setStatus(USBStatus status) throws IOException, ConnectionException { + double params[] = new double[1]; + params[0] = status.getValue(); + + makeMessage(USBID, params); + return sendMessage(null); + } + + @Override + public void fireEvent(EventMessage message) { + synchronized(this) { + this.returnMsg = message; + this.notifyAll(); + } + } + +} \ No newline at end of file diff --git a/ei-library/src/org/tizen/eilib/events/listener/EventListenerList.java b/ei-library/src/org/tizen/eilib/events/listener/EventListenerList.java new file mode 100644 index 0000000..b4a45c9 --- /dev/null +++ b/ei-library/src/org/tizen/eilib/events/listener/EventListenerList.java @@ -0,0 +1,107 @@ +/* + * EventInjector Library + * + * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * SooYoung Ha + * JiHye Kim + * YeongKyoon Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + +package org.tizen.eilib.events.listener; + +import java.util.ArrayList; + +public class EventListenerList { + /** + * The list of listeners. + */ + private volatile ArrayList listeners = new ArrayList(); + + /** + * Adds a listener to this list. This method has no effect if the same listener is already registered. + * + * @param listener the non-null listener to add + */ + public synchronized void add(IEventListener listener) { + // This method is synchronized to protect against multiple threads adding + // or removing listeners concurrently. This does not block concurrent readers. + if (listener == null) { + throw new IllegalArgumentException(); + } + // check for duplicates + if (listeners.contains(listener)) { + return; + } + listeners.add(listener); + } + + /** + * Returns an array containing all the registered listeners. + *

          + * Note: Callers of this method must not modify the returned array. + * + * @return the list of registered listeners + */ + public ArrayList getListeners() { + return listeners; + } + + /** + * Returns whether this listener list is empty. + * + * @return true if there are no registered listeners, and + * false otherwise + */ + public boolean isEmpty() { + return listeners.isEmpty(); + } + + /** + * Removes a listener from this list. Has no effect if the same listener was not already registered. + * + * @param listener the non-null listener to remove + */ + public synchronized void remove(Object listener) { + // This method is synchronized to protect against multiple threads adding + // or removing listeners concurrently. This does not block concurrent readers. + if (listener == null) { + throw new IllegalArgumentException(); + } + + listeners.remove(listener); + } + + /** + * Returns the number of registered listeners. + * + * @return the number of registered listeners + */ + public int size() { + return listeners.size(); + } + + /** + * Removes all listeners from this list. + */ + public synchronized void clear() { + listeners.clear(); + } +} + diff --git a/ei-library/src/org/tizen/eilib/events/listener/ICallEventListener.java b/ei-library/src/org/tizen/eilib/events/listener/ICallEventListener.java new file mode 100644 index 0000000..8340af7 --- /dev/null +++ b/ei-library/src/org/tizen/eilib/events/listener/ICallEventListener.java @@ -0,0 +1,54 @@ +/* + * EventInjector Library + * + * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * SooYoung Ha + * JiHye Kim + * YeongKyoon Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + + +package org.tizen.eilib.events.listener; + +import org.tizen.eilib.events.CallEvent; + +/** + * Classes which implement this interface provide methods + * that deal with the events that are generated + * when call event occurs from emulator. + * + */ +public interface ICallEventListener extends IEventListener { + /** + * Sent when arrived call from emulator. + * @param event an event containing information about call. + * + * @see CallEvent + */ + public void incomingCall(CallEvent event); + + /** + * Sent when arrived call list from emulator. + * @param event an event containing information about call list. + * + * @see CallEvent + */ + public void receivingCallList(CallEvent event); +} diff --git a/ei-library/src/org/tizen/eilib/events/listener/IEventListener.java b/ei-library/src/org/tizen/eilib/events/listener/IEventListener.java new file mode 100644 index 0000000..2fc6693 --- /dev/null +++ b/ei-library/src/org/tizen/eilib/events/listener/IEventListener.java @@ -0,0 +1,32 @@ +/* + * EventInjector Library + * + * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * SooYoung Ha + * JiHye Kim + * YeongKyoon Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + + +package org.tizen.eilib.events.listener; + +public interface IEventListener { + +} diff --git a/ei-library/src/org/tizen/eilib/events/listener/ISDcardEventListener.java b/ei-library/src/org/tizen/eilib/events/listener/ISDcardEventListener.java new file mode 100644 index 0000000..38dfc52 --- /dev/null +++ b/ei-library/src/org/tizen/eilib/events/listener/ISDcardEventListener.java @@ -0,0 +1,56 @@ +/* + * EventInjector Library + * + * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * SooYoung Ha + * JiHye Kim + * YeongKyoon Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + + +package org.tizen.eilib.events.listener; + +import org.tizen.eilib.events.SDCardEvent; + +/** + * Classes which implement this interface provide methods + * that deal with the events that are generated + * when sdcard event occurs from emulator + */ +public interface ISDcardEventListener extends IEventListener { + + /** + * Sent when complete mount sd card + * @param event + */ + public void completeMount(SDCardEvent event); + + /** + * Sent when complete unmount sd card. + * @param event + */ + public void completeUnmount(SDCardEvent event); + + /** Send when complete qeuery sd card status. + * + * @param event + */ + public void completeQeueryStatus(SDCardEvent event); +} diff --git a/ei-library/src/org/tizen/eilib/events/listener/ISMSEventListener.java b/ei-library/src/org/tizen/eilib/events/listener/ISMSEventListener.java new file mode 100644 index 0000000..df66ea3 --- /dev/null +++ b/ei-library/src/org/tizen/eilib/events/listener/ISMSEventListener.java @@ -0,0 +1,46 @@ +/* + * EventInjector Library + * + * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * SooYoung Ha + * JiHye Kim + * YeongKyoon Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + + +package org.tizen.eilib.events.listener; + +import org.tizen.eilib.events.SMSEvent; + +/** + * Classes which implement this interface provide methods + * that deal with the events that are generated + * when SMS event occurs from emulator. + * + */ +public interface ISMSEventListener extends IEventListener { + /** + * Sent when arrived SMS from emulator. + * @param event an event containing information about sms. + * + * @see SMSEvent + */ + public void incomingSMS(SMSEvent event); +} diff --git a/ei-library/src/org/tizen/eilib/events/receiver/AbstractEventReceiver.java b/ei-library/src/org/tizen/eilib/events/receiver/AbstractEventReceiver.java new file mode 100644 index 0000000..f6a2047 --- /dev/null +++ b/ei-library/src/org/tizen/eilib/events/receiver/AbstractEventReceiver.java @@ -0,0 +1,44 @@ +/* + * EventInjector Library + * + * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * SooYoung Ha + * JiHye Kim + * YeongKyoon Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + + +package org.tizen.eilib.events.receiver; + +import org.tizen.eilib.connection.message.EventMessage; + +public abstract class AbstractEventReceiver{ + private String name; + + public AbstractEventReceiver(String name) { + this.name = name; + } + + public abstract void run(final EventMessage message); + + public String getName() { + return name; + } +} diff --git a/ei-library/src/org/tizen/eilib/events/receiver/EventReceiver.java b/ei-library/src/org/tizen/eilib/events/receiver/EventReceiver.java new file mode 100644 index 0000000..dce30cd --- /dev/null +++ b/ei-library/src/org/tizen/eilib/events/receiver/EventReceiver.java @@ -0,0 +1,45 @@ +/* + * EventInjector Library + * + * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * SooYoung Ha + * JiHye Kim + * YeongKyoon Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + +package org.tizen.eilib.events.receiver; + +import org.tizen.eilib.connection.message.EventMessage; +import org.tizen.eilib.events.sender.AbstractEventSender; + +public class EventReceiver extends AbstractEventReceiver { + private AbstractEventSender sender; + + public EventReceiver(String name, AbstractEventSender sender) { + super(name); + this.sender = sender; + } + + @Override + public void run(EventMessage message) { + sender.fireEvent(message); + } + +} diff --git a/ei-library/src/org/tizen/eilib/events/receiver/StatusEventReceiver.java b/ei-library/src/org/tizen/eilib/events/receiver/StatusEventReceiver.java new file mode 100644 index 0000000..972a8f2 --- /dev/null +++ b/ei-library/src/org/tizen/eilib/events/receiver/StatusEventReceiver.java @@ -0,0 +1,61 @@ +/* + * EventInjector Library + * + * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * SooYoung Ha + * JiHye Kim + * YeongKyoon Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + +package org.tizen.eilib.events.receiver; + +import java.util.HashMap; + +import org.tizen.eilib.connection.message.ActionID; +import org.tizen.eilib.connection.message.EventMessage; + +public class StatusEventReceiver extends AbstractEventReceiver { + public StatusEventReceiver() { + super("Status event"); + } + + private HashMap receiverMap = new HashMap();; + + public void addStatusEventReceiver(ActionID id, AbstractEventReceiver receiver) { + receiverMap.put((Integer)id.getId(), receiver); + } + + public void run(EventMessage message) { + AbstractEventReceiver receiver = null; + int actionID = message.getEventHeader().getActionID(); + for (ActionID id : ActionID.values()) { + if (id.getId() == actionID) { + receiver = receiverMap.get(actionID); + break; + } + } + + if (receiver != null) { + synchronized(receiver) { + receiver.run(message); + } + } + } +} diff --git a/ei-library/src/org/tizen/eilib/events/sender/AbstractEventSender.java b/ei-library/src/org/tizen/eilib/events/sender/AbstractEventSender.java new file mode 100644 index 0000000..187aab5 --- /dev/null +++ b/ei-library/src/org/tizen/eilib/events/sender/AbstractEventSender.java @@ -0,0 +1,53 @@ +/* + * EventInjector Library + * + * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * SooYoung Ha + * JiHye Kim + * YeongKyoon Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + + +package org.tizen.eilib.events.sender; + +import org.tizen.eilib.connection.ConnectionToEmulator; +import org.tizen.eilib.connection.message.EventMessage; + +public abstract class AbstractEventSender { + private ConnectionToEmulator connector = null; + protected EventMessage message = null; + + public AbstractEventSender(ConnectionToEmulator connector) { + this.connector = connector; + initializeEventMessage(); + } + + abstract void initializeEventMessage(); + + public ConnectionToEmulator getConnector() { + return connector; + } + + public void setConnector(ConnectionToEmulator connector) { + this.connector = connector; + } + + public abstract void fireEvent(EventMessage messate); +} \ No newline at end of file diff --git a/ei-library/src/org/tizen/eilib/events/sender/DeviceEventSender.java b/ei-library/src/org/tizen/eilib/events/sender/DeviceEventSender.java new file mode 100644 index 0000000..1f85ebd --- /dev/null +++ b/ei-library/src/org/tizen/eilib/events/sender/DeviceEventSender.java @@ -0,0 +1,95 @@ +/* + * EventInjector Library + * + * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * SooYoung Ha + * JiHye Kim + * YeongKyoon Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + +package org.tizen.eilib.events.sender; + +import java.io.IOException; +import java.nio.ByteBuffer; + +import org.tizen.eilib.connection.ConnectionToEmulator; +import org.tizen.eilib.connection.message.ActionID; +import org.tizen.eilib.connection.message.EventMessage; +import org.tizen.eilib.connection.message.EventType; +import org.tizen.eilib.connection.message.GroupID; +import org.tizen.eilib.exception.ConnectionException; + +public abstract class DeviceEventSender extends AbstractEventSender { + public DeviceEventSender(ConnectionToEmulator connector) { + super(connector); + } + + private String msg = ""; + private Integer msgLength = new Integer(0); + + protected void makeMessage(String id, double params[]) { + message.clear(); + + if(params == null) { + msgLength = 0; + return; + } + + msg = id + params.length + "\n"; + for( int i = 0 ; i < params.length ; i++) { + msg += (Double.toString(params[i]) + "\n"); + } + + byte[] tmp = msg.getBytes(); + msgLength = tmp.length; + ((ByteBuffer) message.getDataBuffer().clear()).put(tmp); + } + + protected boolean sendMessage(ActionID id) + throws IOException, ConnectionException { + // make header + ByteBuffer header = message.getHeaderBuffer(); + header.clear(); + + if (id != null) { + header.put(msgLength.byteValue()); + header.put((byte)0x00); + header.put(((Integer)GroupID.STATUS).byteValue()); + header.put(((Integer)id.getId()).byteValue()); + } else { + header.put(msgLength.byteValue()); + header.put((byte)0x00); + header.put((byte)0x00); + header.put((byte)0x00); + } + + getConnector().sendMessage(message); + + return true; + } + + @Override + void initializeEventMessage() { + message = new EventMessage(1024); + message.setEventTypeBuffer(EventType.SENSOR); + } + + public abstract void fireEvent(EventMessage message); +} diff --git a/ei-library/src/org/tizen/eilib/events/sender/LocationEventSender.java b/ei-library/src/org/tizen/eilib/events/sender/LocationEventSender.java new file mode 100644 index 0000000..4b77679 --- /dev/null +++ b/ei-library/src/org/tizen/eilib/events/sender/LocationEventSender.java @@ -0,0 +1,107 @@ +/* + * EventInjector Library + * + * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * SooYoung Ha + * JiHye Kim + * YeongKyoon Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + +package org.tizen.eilib.events.sender; + +import java.io.IOException; +import java.nio.ByteBuffer; + +import org.tizen.eilib.connection.ConnectionToEmulator; +import org.tizen.eilib.connection.message.ActionID; +import org.tizen.eilib.connection.message.EventMessage; +import org.tizen.eilib.connection.message.EventType; +import org.tizen.eilib.connection.message.GroupID; +import org.tizen.eilib.exception.ConnectionException; +import org.tizen.eilib.tools.EILogger; + +public class LocationEventSender extends AbstractEventSender { + private EventMessage returnMsg = null; + + public LocationEventSender(ConnectionToEmulator connector) { + super(connector); + } + + public boolean sendMessage(String msg) throws IOException, ConnectionException { + message.clear(); + + ByteBuffer data = message.getDataBuffer(); + data.put(msg.getBytes()); + + ByteBuffer header = message.getHeaderBuffer(); + header.put(((Integer)data.position()).byteValue()); + header.put((byte)0x00); + header.put((byte)0x00); + header.put((byte)0x00); + + return getConnector().sendMessage(message); + } + + public String getLocationStatus() throws IOException, ConnectionException { + message.clear(); + ByteBuffer header = message.getHeaderBuffer(); + header.put((byte)0x00); + header.put((byte)0x00); + header.put(((Integer)GroupID.STATUS).byteValue()); + header.put(((Integer)ActionID.LOCATION_STATUS.getId()).byteValue()); + + getConnector().sendMessage(message); + + synchronized(this) { + // wait 5 second + try { + this.wait(5000); + } catch (InterruptedException e) { + e.printStackTrace(); + EILogger.getLogger().warning(e.getMessage()); + } + } + + String event = null; + if (returnMsg != null) { + if (returnMsg.getDataBuffer().position() != 0) { + event = new String(returnMsg.getDataBuffer().array(), + 14, returnMsg.getDataBuffer().limit()); + } + returnMsg = null; + } + + return event; + } + + public void fireEvent(EventMessage message) { + synchronized(this) { + this.returnMsg = message; + this.notifyAll(); + } + } + + @Override + void initializeEventMessage() { + message = new EventMessage(1024); + message.setEventTypeBuffer(EventType.LOCATION); + } + +} diff --git a/ei-library/src/org/tizen/eilib/events/sender/ModemEventSender.java b/ei-library/src/org/tizen/eilib/events/sender/ModemEventSender.java new file mode 100644 index 0000000..ff58f6b --- /dev/null +++ b/ei-library/src/org/tizen/eilib/events/sender/ModemEventSender.java @@ -0,0 +1,72 @@ +/* + * EventInjector Library + * + * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * SooYoung Ha + * JiHye Kim + * YeongKyoon Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + +package org.tizen.eilib.events.sender; + +import java.io.IOException; + +import org.tizen.eilib.connection.ConnectionToEmulator; +import org.tizen.eilib.connection.message.EventMessage; +import org.tizen.eilib.connection.message.EventType; +import org.tizen.eilib.exception.ConnectionException; +import org.tizen.eilib.modem.protocol.AbstractGA; + +public class ModemEventSender extends AbstractEventSender { + public ModemEventSender(ConnectionToEmulator connector) { + super(connector); + } + + protected void makeMessage(AbstractGA sendObj) { + message.clear(); + sendObj.makeStarterPacket(message); + sendObj.makePacket(message); + } + + + public boolean send(AbstractGA ga) throws IOException, ConnectionException { + makeMessage(ga); + return sendMessage(); + } + + protected boolean sendMessage() throws IOException, ConnectionException { + getConnector().sendMessage(message); + + return true; + } + + @Override + void initializeEventMessage() { + message = new EventMessage(); + message.setEventTypeBuffer(EventType.TELEPHONY); + } + + @Override + public void fireEvent(EventMessage messate) { + // TODO Auto-generated method stub + + } + +} diff --git a/ei-library/src/org/tizen/eilib/events/sender/NfcEventSender.java b/ei-library/src/org/tizen/eilib/events/sender/NfcEventSender.java new file mode 100644 index 0000000..d6346c7 --- /dev/null +++ b/ei-library/src/org/tizen/eilib/events/sender/NfcEventSender.java @@ -0,0 +1,106 @@ +/* + * EventInjector Library + * + * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * SooYoung Ha + * JiHye Kim + * YeongKyoon Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + +package org.tizen.eilib.events.sender; + +import java.io.IOException; +import java.nio.ByteBuffer; + +import org.tizen.eilib.connection.ConnectionToEmulator; +import org.tizen.eilib.connection.message.ActionID; +import org.tizen.eilib.connection.message.EventMessage; +import org.tizen.eilib.connection.message.EventType; +import org.tizen.eilib.connection.message.GroupID; +import org.tizen.eilib.exception.ConnectionException; +import org.tizen.eilib.tools.EILogger; +public class NfcEventSender extends AbstractEventSender { + private EventMessage returnMsg = null; + + public NfcEventSender(ConnectionToEmulator connector) { + super(connector); + } + + public boolean sendMessage(String msg) throws IOException, ConnectionException { + message.clear(); + + byte[] buf = msg.getBytes(); + + message.getDataBuffer().put(buf); + + ByteBuffer header = message.getHeaderBuffer(); + header.putShort((short)buf.length); + header.put((byte)0x00); + header.put((byte)0x00); + + return getConnector().sendMessage(message); + } + + public String getNfcStatus() throws IOException, ConnectionException { + message.clear(); + + ByteBuffer header = message.getHeaderBuffer(); + header.put((byte)0x00); + header.put((byte)0x00); + header.put(((Integer)GroupID.STATUS).byteValue()); + header.put(((Integer)ActionID.NFC_STATUS.getId()).byteValue()); + + getConnector().sendMessage(message); + + synchronized(this) { + // wait 5 second + try { + this.wait(5000); + } catch (InterruptedException e) { + e.printStackTrace(); + EILogger.getLogger().warning(e.getMessage()); + } + } + + String event = null; + if (returnMsg != null) { + if (returnMsg.getDataBuffer().position() != 0) { + event = new String(returnMsg.getDataBuffer().array(), + 14, returnMsg.getDataBuffer().limit()); + } + returnMsg = null; + } + + return event; + } + + @Override + void initializeEventMessage() { + message = new EventMessage(); + message.setEventTypeBuffer(EventType.NFC); + } + + public void fireEvent(EventMessage message) { + synchronized(this) { + this.returnMsg = message; + this.notifyAll(); + } + } +} diff --git a/ei-library/src/org/tizen/eilib/events/sender/SDCardEventSender.java b/ei-library/src/org/tizen/eilib/events/sender/SDCardEventSender.java new file mode 100644 index 0000000..e9fae3a --- /dev/null +++ b/ei-library/src/org/tizen/eilib/events/sender/SDCardEventSender.java @@ -0,0 +1,85 @@ +/* + * EventInjector Library + * + * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * SooYoung Ha + * JiHye Kim + * YeongKyoon Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + +package org.tizen.eilib.events.sender; + +import java.io.IOException; + +import org.tizen.eilib.connection.ConnectionToEmulator; +import org.tizen.eilib.connection.message.EventMessage; +import org.tizen.eilib.connection.message.EventType; +import org.tizen.eilib.events.type.SDCardEventType; +import org.tizen.eilib.exception.ConnectionException; + +public class SDCardEventSender extends AbstractEventSender { + + public SDCardEventSender(ConnectionToEmulator connector) { + super(connector); + } + + public boolean getMountStatus() throws IOException, ConnectionException { + message.clear(); + String msg = SDCardEventType.Status_Unmount + "\n"; + byte[] buf = msg.getBytes(); + message.getDataBuffer().put(buf); + message.getHeaderBuffer().put((byte)buf.length); + + return getConnector().sendMessage(message); + } + + public boolean sendMount(String path) throws IOException, ConnectionException { + message.clear(); + String msg = SDCardEventType.Action_Mount + "\n" + path + "\n"; + byte[] buf = msg.getBytes(); + message.getDataBuffer().put(buf); + message.getHeaderBuffer().put((byte)buf.length); + + return getConnector().sendMessage(message); + } + + public boolean sendUnmount() throws IOException, ConnectionException { + message.clear(); + String msg = SDCardEventType.Action_Unmount + "\n"; + byte[] buf = msg.getBytes(); + message.getDataBuffer().put(buf); + message.getHeaderBuffer().put((byte)buf.length); + + return getConnector().sendMessage(message); + } + + @Override + void initializeEventMessage() { + message = new EventMessage(1024); + message.setEventTypeBuffer(EventType.SDCARD); + } + + @Override + public void fireEvent(EventMessage messate) { + // TODO Auto-generated method stub + + } + +} diff --git a/ei-library/src/org/tizen/eilib/events/sender/SDCardStatusCheckSender.java b/ei-library/src/org/tizen/eilib/events/sender/SDCardStatusCheckSender.java new file mode 100644 index 0000000..8d54ab9 --- /dev/null +++ b/ei-library/src/org/tizen/eilib/events/sender/SDCardStatusCheckSender.java @@ -0,0 +1,149 @@ +/* + * EventInjector Library + * + * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * SooYoung Ha + * JiHye Kim + * YeongKyoon Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + +package org.tizen.eilib.events.sender; + +import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.util.HashMap; + +import org.tizen.eilib.connection.ConnectionToEmulator; +import org.tizen.eilib.connection.Emulator; +import org.tizen.eilib.connection.EventSocket; +import org.tizen.eilib.connection.message.EventMessage; +import org.tizen.eilib.connection.message.EventType; +import org.tizen.eilib.connection.message.GroupID; +import org.tizen.eilib.events.receiver.AbstractEventReceiver; +import org.tizen.eilib.events.type.SDCardEventType; +import org.tizen.eilib.exception.ConnectionException; +import org.tizen.eilib.exception.DeviceEventException; +import org.tizen.eilib.exception.EILibError; + +public class SDCardStatusCheckSender extends AbstractEventSender { + + private HashMap receiverMap = new HashMap(); + private SDCardStatusCheckReceiver receiver; + private EventSocket socket; + + public SDCardStatusCheckSender(ConnectionToEmulator connector) { + super(connector); + receiver = new SDCardStatusCheckReceiver(this); + receiverMap.put(GroupID.SDCARD, receiver); + socket = new EventSocket(receiverMap); + } + + public void sendMountCheck(Emulator emulator, boolean isWait) throws IOException, ConnectionException, DeviceEventException { + receiver.setEmulator(emulator); + + int port = emulator.getPort(); + try { + socket.connect(port); + } catch (IOException e) { + e.printStackTrace(); + } + + message.clear(); + + String sdcardMsg = SDCardEventType.Status_Unmount + "\n"; // query mount status + byte[] buf = sdcardMsg.getBytes(); + message.getDataBuffer().put(buf); + message.getHeaderBuffer().put((byte)buf.length); + + socket.sendMessage(message); + + synchronized(this) { + try { + this.wait(2000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + socket.disconnect(); + if (receiver.isWait()) { + throw new DeviceEventException(EILibError.FailedGetValue); + } + + } + + @Override + void initializeEventMessage() { + message = new EventMessage(); + message.setEventTypeBuffer(EventType.SDCARD); + } + + @Override + public void fireEvent(EventMessage messate) { + synchronized(this) { + this.notifyAll(); + } + } +} + +class SDCardStatusCheckReceiver extends AbstractEventReceiver { + private Emulator emulator; + private SDCardStatusCheckSender sender; + private boolean isWait = false; + public SDCardStatusCheckReceiver(SDCardStatusCheckSender sender) { + super("SD card check"); + this.sender = sender; + } + public void setEmulator(Emulator emulator) { + this.emulator = emulator; + } + + @Override + public void run(EventMessage message) { + isWait = true; + + int actionID = message.getEventHeader().getActionID(); + if (actionID == SDCardEventType.Status_Unmount) { // unmounted status + emulator.setMounted(false); + } else if (actionID == SDCardEventType.Status_Mount) { // mounted status + emulator.setMounted(true); + int len = message.getDataBuffer().position(); + String name = null; + if (len != 0) { + try { + name = new String(message.getDataBuffer().array(), + message.getDataBufferOffset(), len, "US-ASCII"); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } + } + if (name != null) { + emulator.setSDCardName(name); + } + } + + isWait = false; + sender.fireEvent(null); + } + + public boolean isWait() { + return isWait; + } +} diff --git a/ei-library/src/org/tizen/eilib/events/sender/SensorEventSender.java b/ei-library/src/org/tizen/eilib/events/sender/SensorEventSender.java new file mode 100644 index 0000000..5f26685 --- /dev/null +++ b/ei-library/src/org/tizen/eilib/events/sender/SensorEventSender.java @@ -0,0 +1,294 @@ +/* + * EventInjector Library + * + * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * SooYoung Ha + * JiHye Kim + * YeongKyoon Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + +package org.tizen.eilib.events.sender; + +import java.io.IOException; +import java.nio.ByteBuffer; +import java.util.ArrayList; +import org.tizen.eilib.connection.ConnectionToEmulator; +import org.tizen.eilib.connection.message.ActionID; +import org.tizen.eilib.connection.message.EventMessage; +import org.tizen.eilib.connection.message.EventType; +import org.tizen.eilib.connection.message.GroupID; +import org.tizen.eilib.events.type.MotionEventType; +import org.tizen.eilib.events.type.ProximityStatus; +import org.tizen.eilib.events.type.SensorEventType; +import org.tizen.eilib.exception.ConnectionException; +import org.tizen.eilib.modem.protocol.ByteUtil; +import org.tizen.eilib.tools.EILogger; + +public class SensorEventSender extends AbstractEventSender { + private String msg = ""; + private Integer msgLength = new Integer(0); + private EventMessage returnMsg = null; + + public SensorEventSender(ConnectionToEmulator connector) { + super(connector); + } + + public boolean sendManualEvent(SensorEventType type, + double x, double y, double z) throws IOException, ConnectionException { + message.clear(); + + msg = type.getType() + + 3 + "\n" // count of value + + Double.toString(x) + "\n" + + Double.toString(y) + "\n" + + Double.toString(z) + "\n"; + + byte[] tmp = msg.getBytes(); + msgLength = tmp.length; + ((ByteBuffer)message.getDataBuffer().clear()).put(tmp); + + return sendMessage(null); + } + + public boolean sendLogEvent(SensorEventType type, + int repeatCount, ArrayList files) throws IOException, ConnectionException { + message.clear(); + + msg = type.getType() + repeatCount + "\n" + files.size() + "\n"; + for (String name : files) { + msg = msg + name + "\n"; + } + + byte[] tmp = msg.getBytes(); + msgLength = tmp.length; + ((ByteBuffer)message.getDataBuffer().clear()).put(tmp); + + return sendMessage(null); + } + + public boolean sendLightEvent(int luxData, int levelData) throws IOException, ConnectionException { + message.clear(); + + // set level data + msg = SensorEventType.LIGHT.getType() + + 2 + "\n" // count of value + + Integer.toString(1) +"\n" + + Integer.toString(levelData) + "\n"; + + byte[] tmp = msg.getBytes(); + msgLength = tmp.length; + ((ByteBuffer)message.getDataBuffer().clear()).put(tmp); + + if (!sendMessage(null)) { + // TODO + return false; + } + + message.clear(); + + // set lux data + msg = SensorEventType.LIGHT.getType() + + 2 + "\n" // count of value + + Integer.toString(2) +"\n" + + Integer.toString(luxData) + "\n"; + + tmp = msg.getBytes(); + msgLength = tmp.length; + ((ByteBuffer)message.getDataBuffer().clear()).put(tmp); + + return sendMessage(null); + } + + public boolean sendMotionEvent(MotionEventType event) throws IOException, ConnectionException { + message.clear(); + + msg = SensorEventType.MOTION.getType() + + 1 + "\n" // count of value + + Integer.toString(event.getType()) + "\n"; + + byte[] tmp = msg.getBytes(); + msgLength = tmp.length; + ((ByteBuffer)message.getDataBuffer().clear()).put(tmp); + + return sendMessage(null); + } + + + public boolean sendProximityEvent(ProximityStatus status) throws IOException, ConnectionException { + message.clear(); + + msg = SensorEventType.PROXI.getType() + + 1 + "\n" // count of value + + Integer.toString(status.getValue()) + "\n"; + + byte[] tmp = msg.getBytes(); + msgLength = tmp.length; + ((ByteBuffer)message.getDataBuffer().clear()).put(tmp); + + return sendMessage(null); + } + + protected synchronized boolean sendMessage(ActionID id) + throws IOException, ConnectionException { + // make header + ByteBuffer header = message.getHeaderBuffer(); + + header.clear(); + if (id != null) { + header.put(msgLength.byteValue()); + header.put((byte)0x00); + header.put(((Integer)GroupID.STATUS).byteValue()); + header.put(((Integer)id.getId()).byteValue()); + } else { + header.put(msgLength.byteValue()); + header.put((byte)0x00); + header.put((byte)0x00); + header.put((byte)0x00); + } + + getConnector().sendMessage(message); + + return true; + } + + @Override + void initializeEventMessage() { + message = new EventMessage(1024); + message.setEventTypeBuffer(EventType.SENSOR); + } + + // get function + public int getLightValue() throws IOException, ConnectionException { + message.clear(); + msgLength = 0; + sendMessage(ActionID.LIGHT_VALUE); + + synchronized(this) { + // wait 5 second + try { + this.wait(5000); + } catch (InterruptedException e) { + e.printStackTrace(); + EILogger.getLogger().warning(e.getMessage()); + } + } + + int level = -1; + if (returnMsg != null) { + if (returnMsg.getEventHeader().getActionID() + != ActionID.LIGHT_VALUE.getId()) { + EILogger.getLogger().warning("An unexpected event occurs."); + } else { + if (returnMsg.getDataBuffer().position() != 0) { + level = ByteUtil.byte2int + (returnMsg.getDataBuffer().array(), 14); + } + } + returnMsg = null; + } + + return level; + } + + public ProximityStatus getProxiStatus() throws IOException, ConnectionException { + message.clear(); + msgLength = 0; + sendMessage(ActionID.PROXI_VALUE); + + synchronized(this) { + // wait 5 second + try { + this.wait(5000); + } catch (InterruptedException e) { + e.printStackTrace(); + EILogger.getLogger().warning(e.getMessage()); + } + } + + int value = -1; + ProximityStatus status = null; + if (returnMsg != null) { + if (returnMsg.getEventHeader().getActionID() + != ActionID.PROXI_VALUE.getId()) { + EILogger.getLogger().warning("An unexpected event occurs."); + } else { + if (returnMsg.getDataBuffer().position() != 0) { + value = ByteUtil.byte2int + (returnMsg.getDataBuffer().array(), 14); + for (ProximityStatus s : ProximityStatus.values()) { + if (s.getValue() == value) { + status = s; + break; + } + } + } + } + returnMsg = null; + } + + return status; + } + + public String getSensorValue(SensorEventType type) throws IOException, ConnectionException { + message.clear(); + msgLength = 0; + switch(type){ + case ACCEL: + sendMessage(ActionID.ACCEL_VALUE); + break; + case GYRO: + sendMessage(ActionID.GYRO_VALUE); + break; + case MAGNETIC: + sendMessage(ActionID.MAG_VALUE); + break; + default: + return null; + } + + synchronized(this) { + // wait 5 second + try { + this.wait(5000); + } catch (InterruptedException e) { + e.printStackTrace(); + EILogger.getLogger().warning(e.getMessage()); + } + } + + String value = null; + if (returnMsg != null) { + if (returnMsg.getDataBuffer().position() != 0) { + value = new String(returnMsg.getDataBuffer().array(), + 14, returnMsg.getDataBuffer().limit()); + } + returnMsg = null; + } + + return value; + } + + public void fireEvent(EventMessage message) { + synchronized(this) { + this.returnMsg = message; + this.notifyAll(); + } + } +} diff --git a/ei-library/src/org/tizen/eilib/events/type/BatteryCharger.java b/ei-library/src/org/tizen/eilib/events/type/BatteryCharger.java new file mode 100644 index 0000000..3cded83 --- /dev/null +++ b/ei-library/src/org/tizen/eilib/events/type/BatteryCharger.java @@ -0,0 +1,47 @@ +/* + * EventInjector Library + * + * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * SooYoung Ha + * JiHye Kim + * YeongKyoon Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + +package org.tizen.eilib.events.type; + +public enum BatteryCharger { + DISCONNECT(0, "off"), + CONNECT(1, "on"); + + private int value; + private String status; + BatteryCharger(int v, String s) { + this.value = v; + this.status = s; + } + + public int getValue() { + return value; + } + + public String toString() { + return status; + } +} diff --git a/ei-library/src/org/tizen/eilib/events/type/CallErrorCode.java b/ei-library/src/org/tizen/eilib/events/type/CallErrorCode.java new file mode 100644 index 0000000..0bf9937 --- /dev/null +++ b/ei-library/src/org/tizen/eilib/events/type/CallErrorCode.java @@ -0,0 +1,47 @@ +/* + * EventInjector Library + * + * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * SooYoung Ha + * JiHye Kim + * YeongKyoon Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + +package org.tizen.eilib.events.type; + +public enum CallErrorCode { + Success(32768, "success"); + int code; + String str; + + CallErrorCode(int c, String s) { + code = c; + str = s; + } + + public int value() { + return code; + } + + //@Override + public String toString() { + return str; + } +} diff --git a/ei-library/src/org/tizen/eilib/events/type/CallEventType.java b/ei-library/src/org/tizen/eilib/events/type/CallEventType.java new file mode 100644 index 0000000..ac33ae0 --- /dev/null +++ b/ei-library/src/org/tizen/eilib/events/type/CallEventType.java @@ -0,0 +1,31 @@ +/* + * EventInjector Library + * + * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * SooYoung Ha + * JiHye Kim + * YeongKyoon Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + +package org.tizen.eilib.events.type; + +public enum CallEventType { + NONE, INCOMING, LIST22, LIST26, LIST29; +} diff --git a/ei-library/src/org/tizen/eilib/events/type/CallStatus.java b/ei-library/src/org/tizen/eilib/events/type/CallStatus.java new file mode 100644 index 0000000..e569f12 --- /dev/null +++ b/ei-library/src/org/tizen/eilib/events/type/CallStatus.java @@ -0,0 +1,54 @@ +/* + * EventInjector Library + * + * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * SooYoung Ha + * JiHye Kim + * YeongKyoon Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + +package org.tizen.eilib.events.type; + +public enum CallStatus { + NONE(0, "NONE"), + ACTIVE(1, "VOICE"), + HELD(2, "DATA"), + DIALING(3, "DIALING"), + ALERT(4, "ALERT"), + INCOMING(5, "INCOMING"), + WAITING(6, "WATING"), + MAX(7, "MAX"); + + int id; + String value; + + CallStatus(int id, String value) { + this.id = id; + this.value = value; + } + + public int getID() { + return id; + } + + public String toString() { + return value; + } +} diff --git a/ei-library/src/org/tizen/eilib/events/type/CallType.java b/ei-library/src/org/tizen/eilib/events/type/CallType.java new file mode 100644 index 0000000..bd9c3d0 --- /dev/null +++ b/ei-library/src/org/tizen/eilib/events/type/CallType.java @@ -0,0 +1,51 @@ +/* + * EventInjector Library + * + * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * SooYoung Ha + * JiHye Kim + * YeongKyoon Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + +package org.tizen.eilib.events.type; + +public enum CallType { + NONE(0,"NONE"), + VOICE(1,"VOICE"), + DATA(2,"DATA"), + MAX(3,"MAX"), + EMERGENCY(7, "EMERGENCY"); + + int id; + String value; + + CallType(int id, String value) { + this.id = id; + this.value = value; + } + + public int getID() { + return id; + } + + public String toString() { + return value; + } +} diff --git a/ei-library/src/org/tizen/eilib/events/type/EarJackStatus.java b/ei-library/src/org/tizen/eilib/events/type/EarJackStatus.java new file mode 100644 index 0000000..8a6c11e --- /dev/null +++ b/ei-library/src/org/tizen/eilib/events/type/EarJackStatus.java @@ -0,0 +1,49 @@ +/* + * EventInjector Library + * + * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * SooYoung Ha + * JiHye Kim + * YeongKyoon Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + +package org.tizen.eilib.events.type; + +public enum EarJackStatus { + DISCONNECT(0, "off"), + WIRE3_CONNECT(1, "3wire"), + WIRE4_CONNECT(3, "4wire"); + + private int value; + private String status; + EarJackStatus(int i, String s) { + this.value = i; + this.status = s; + } + + public int getValue() { + return value; + } + + @Override + public String toString() { + return status; + } +} diff --git a/ei-library/src/org/tizen/eilib/events/type/LocationEventMode.java b/ei-library/src/org/tizen/eilib/events/type/LocationEventMode.java new file mode 100644 index 0000000..152f056 --- /dev/null +++ b/ei-library/src/org/tizen/eilib/events/type/LocationEventMode.java @@ -0,0 +1,50 @@ +/* + * EventInjector Library + * + * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * SooYoung Ha + * JiHye Kim + * YeongKyoon Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + +package org.tizen.eilib.events.type; + +public enum LocationEventMode { + NONE(-1, "-1"), + STOPMODE(0, "0"), + LOGMODE(1, "1"), + MANUALMODE(2, "2"); + + int mode; + String strMode; + + LocationEventMode(int m, String s) { + mode = m; + strMode = s; + } + + public int getMode() { + return mode; + } + + public String toString() { + return strMode; + } +} diff --git a/ei-library/src/org/tizen/eilib/events/type/MimeTypeList.java b/ei-library/src/org/tizen/eilib/events/type/MimeTypeList.java new file mode 100644 index 0000000..fafb046 --- /dev/null +++ b/ei-library/src/org/tizen/eilib/events/type/MimeTypeList.java @@ -0,0 +1,108 @@ +/* + * EventInjector Library + * + * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * SooYoung Ha + * JiHye Kim + * YeongKyoon Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + + +package org.tizen.eilib.events.type; + +import java.util.ArrayList; + +public class MimeTypeList +{ + private static MimeTypeList typelist = new MimeTypeList(); + private ArrayList list; + + public static MimeTypeList getInstance() + { + return typelist; + } + + private MimeTypeList() + { + list = new ArrayList(); + list.add(new MimeType("vcf", "application/vcard")); + list.add(new MimeType("jpeg", "image/jpeg")); + list.add(new MimeType("mpeg", "image/mpeg")); + list.add(new MimeType("png", "image/png")); + list.add(new MimeType("gif", "image/gif")); + list.add(new MimeType("bmp", "image/bmp")); + list.add(new MimeType("jpg", "image/jpeg")); + list.add(new MimeType("jpe", "image/jpeg")); + list.add(new MimeType("mp3", "audio/mpeg")); + list.add(new MimeType("mid", "audio/midi")); + list.add(new MimeType("wav", "audio/x-wav")); + list.add(new MimeType("mp4", "video/mp4")); + list.add(new MimeType("mpe", "video/mpeg")); + list.add(new MimeType("mpg", "video/mpeg")); + list.add(new MimeType("mov", "video/quicktime")); + list.add(new MimeType("flv", "video/x-flv")); + list.add(new MimeType("asf", "video/x-ms-asf")); + list.add(new MimeType("avi", "video/x-msvideo")); + } + + public String findMimeType(String ex) + { + + for (MimeType mimetype : list) { + if (mimetype.getExtension().equals(ex)) { + return mimetype.getMimetype(); + } + } + + return null; + } +} + +class MimeType +{ + private String extension; + private String mimetype; + + public MimeType(String ex, String type) + { + setExtension(ex); + setMimetype(type); + } + + public String getExtension() + { + return extension; + } + + public void setExtension(String extension) + { + this.extension = extension; + } + + public String getMimetype() + { + return mimetype; + } + + public void setMimetype(String mimetype) + { + this.mimetype = mimetype; + } +} diff --git a/ei-library/src/org/tizen/eilib/events/type/MobileType.java b/ei-library/src/org/tizen/eilib/events/type/MobileType.java new file mode 100644 index 0000000..9ed0561 --- /dev/null +++ b/ei-library/src/org/tizen/eilib/events/type/MobileType.java @@ -0,0 +1,50 @@ +/* + * EventInjector Library + * + * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * SooYoung Ha + * JiHye Kim + * YeongKyoon Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + +package org.tizen.eilib.events.type; + +public enum MobileType { + // Mobile Originated 송신 + MO(1, "MO"), + // Mobile Treminated 수진 + MT(2,"MT"); + + int id; + String value; + + MobileType(int id, String value) { + this.id = id; + this.value = value; + } + + public int getID() { + return id; + } + + public String toString() { + return value; + } +} diff --git a/ei-library/src/org/tizen/eilib/events/type/MotionEventType.java b/ei-library/src/org/tizen/eilib/events/type/MotionEventType.java new file mode 100644 index 0000000..2b465d5 --- /dev/null +++ b/ei-library/src/org/tizen/eilib/events/type/MotionEventType.java @@ -0,0 +1,55 @@ +/* + * EventInjector Library + * + * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * SooYoung Ha + * JiHye Kim + * YeongKyoon Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + +package org.tizen.eilib.events.type; + +public enum MotionEventType { + DoubleTap(1, "double-tab"), + ShakeStart(2, "start-shake"), + ShakeEnd(3, "end-shake"), + SnapXp(4, "snapx+"), + SnapXm(5, "snapx-"), + SnapYp(6, "snapy+"), + SanpYm(7, "snapy-"), + SnapZp(8, "snapz+"), + SnapZm(9, "snapz-"); + + int type; + String event; + MotionEventType(int t, String event) { + type = t; + this.event = event; + } + + public int getType() { + return type; + } + + @Override + public String toString() { + return event; + } +} diff --git a/ei-library/src/org/tizen/eilib/events/type/NDEFFormat.java b/ei-library/src/org/tizen/eilib/events/type/NDEFFormat.java new file mode 100644 index 0000000..44e371c --- /dev/null +++ b/ei-library/src/org/tizen/eilib/events/type/NDEFFormat.java @@ -0,0 +1,58 @@ +/* + * EventInjector Library + * + * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * SooYoung Ha + * JiHye Kim + * YeongKyoon Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + +package org.tizen.eilib.events.type; + +public enum NDEFFormat { + EMPTY("0", "empty", "NDEF_TNF_EMPTY"), + WELL_KNOWN("1", "well-known", "NDEF_TNF_WELL_KNOWN"), + MEDIA("2", "mine-media", "NDEF_TNF_MINE_MEDIA"), + URI("3", "uri", "NDEF_TNF_ABSOLUTE_URI"), + EXTERNAL("4", "external", "NDEF_TNF_EXTERNAL"), + UKNONWN("5", "unknown", "NDEF_TNF_UNKNOWN"); + + String shortName; + String longName; + String format; + + NDEFFormat(String f, String sName, String lName) { + format = f; + shortName = sName; + longName = lName; + } + + public String getFormat() { + return format; + } + + public String getShortName() { + return shortName; + } + + public String toString() { + return longName; + } +} diff --git a/ei-library/src/org/tizen/eilib/events/type/NDEFRecord.java b/ei-library/src/org/tizen/eilib/events/type/NDEFRecord.java new file mode 100644 index 0000000..d2f5ad7 --- /dev/null +++ b/ei-library/src/org/tizen/eilib/events/type/NDEFRecord.java @@ -0,0 +1,83 @@ +/* + * EventInjector Library + * + * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * SooYoung Ha + * JiHye Kim + * YeongKyoon Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + +package org.tizen.eilib.events.type; + +public class NDEFRecord { + private NDEFFormat format = null; + private String typeName = null; + private String id = null; + private String payload = null; + + public NDEFRecord(NDEFFormat f, String name, String id, String payload) { + this.format = f; + this.typeName = name; + this.id = id; + this.payload = payload; + } + + public NDEFFormat getFormat() { + return format; + } + + public void setFormat(NDEFFormat format) { + this.format = format; + } + + public String getTypeName() { + return typeName; + } + + public void setTypeName(String typeName) { + this.typeName = typeName; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getPayload() { + return payload; + } + + public void setPayload(String payload) { + this.payload = payload; + } + + public String getMessage() { + return format.getFormat() + "," + + typeName + "," + id + "," + payload; + } + @Override + public String toString() { + return format.toString() + "(" + format.getShortName() + ")," + + typeName + "," + id + "," + payload; + } +} diff --git a/ei-library/src/org/tizen/eilib/events/type/NfcTagType.java b/ei-library/src/org/tizen/eilib/events/type/NfcTagType.java new file mode 100644 index 0000000..5bc2109 --- /dev/null +++ b/ei-library/src/org/tizen/eilib/events/type/NfcTagType.java @@ -0,0 +1,57 @@ +/* + * EventInjector Library + * + * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * SooYoung Ha + * JiHye Kim + * YeongKyoon Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + +package org.tizen.eilib.events.type; + +public enum NfcTagType { + TYPE1(1, "type1", "Topaz Jewel (Type1)"), + TYPE2(2, "type2", "Mifare UL (Type2)"), + TYPE3(3, "type3", "Felica (Type3)"), + TYPE4(4, "type4", "Mifare Desfiel (Type4)"), + P2P(5, "", ""); + + int type; + String longName; + String shortName; + + NfcTagType(int t, String sName, String lName) { + this.type = t; + shortName = sName; + longName = lName; + } + + public int getType() { + return type; + } + + public String getShortName() { + return shortName; + } + + public String toString() { + return longName; + } +} diff --git a/ei-library/src/org/tizen/eilib/events/type/ProximityStatus.java b/ei-library/src/org/tizen/eilib/events/type/ProximityStatus.java new file mode 100644 index 0000000..4b2e2f3 --- /dev/null +++ b/ei-library/src/org/tizen/eilib/events/type/ProximityStatus.java @@ -0,0 +1,49 @@ +/* + * EventInjector Library + * + * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * SooYoung Ha + * JiHye Kim + * YeongKyoon Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + +package org.tizen.eilib.events.type; + +public enum ProximityStatus { + + ON(0, "on"), + OFF(8, "off"); + + private int status; + private String str; + + ProximityStatus(int i, String s) { + this.status = i; + this.str = s; + } + + public int getValue() { + return status; + } + + public String toString() { + return str; + } +} diff --git a/ei-library/src/org/tizen/eilib/events/type/SDCardEventType.java b/ei-library/src/org/tizen/eilib/events/type/SDCardEventType.java new file mode 100644 index 0000000..67e916a --- /dev/null +++ b/ei-library/src/org/tizen/eilib/events/type/SDCardEventType.java @@ -0,0 +1,36 @@ +/* + * EventInjector Library + * + * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * SooYoung Ha + * JiHye Kim + * YeongKyoon Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + +package org.tizen.eilib.events.type; + +public class SDCardEventType { + public static final int Action_Unmount = 0; + public static final int Action_Mount = 1; + public static final int Status_Unmount = 2; + public static final int Status_Mount = 3; + public static final int Fail_Unmount = 4; + public static final int Fail_Mount = 5; +} diff --git a/ei-library/src/org/tizen/eilib/events/type/SMSEventType.java b/ei-library/src/org/tizen/eilib/events/type/SMSEventType.java new file mode 100644 index 0000000..061f5d7 --- /dev/null +++ b/ei-library/src/org/tizen/eilib/events/type/SMSEventType.java @@ -0,0 +1,31 @@ +/* + * EventInjector Library + * + * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * SooYoung Ha + * JiHye Kim + * YeongKyoon Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + +package org.tizen.eilib.events.type; + +public enum SMSEventType { + +} diff --git a/ei-library/src/org/tizen/eilib/events/type/SMSStatus.java b/ei-library/src/org/tizen/eilib/events/type/SMSStatus.java new file mode 100644 index 0000000..639a43c --- /dev/null +++ b/ei-library/src/org/tizen/eilib/events/type/SMSStatus.java @@ -0,0 +1,49 @@ +/* + * EventInjector Library + * + * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * SooYoung Ha + * JiHye Kim + * YeongKyoon Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + +package org.tizen.eilib.events.type; + +public enum SMSStatus { + OK(0, "available"), + NotAvaliable(1, "unavailable"); + + int value; + String str; + + SMSStatus(int v, String s) { + value = v; + str = s; + } + + public int getValue() { + return value; + } + + //@Override + public String toString() { + return str; + } +} diff --git a/ei-library/src/org/tizen/eilib/events/type/SensorEventType.java b/ei-library/src/org/tizen/eilib/events/type/SensorEventType.java new file mode 100644 index 0000000..e2c03bd --- /dev/null +++ b/ei-library/src/org/tizen/eilib/events/type/SensorEventType.java @@ -0,0 +1,53 @@ +/* + * EventInjector Library + * + * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * SooYoung Ha + * JiHye Kim + * YeongKyoon Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + +package org.tizen.eilib.events.type; + +public enum SensorEventType { + NONE("0\n", ""), ACCEL("1\n", "accel" ), PROXI("2\n", "proxi"), LIGHT("3\n", "light"), + GYRO("4\n", "gyro"), GEO("5\n", "geo"), + MOTION("6\n", "motion"), TILT("12\n", "tilt"), MAGNETIC("13\n", "magnetic"), + FILE_ACCEL("14\n", "accel"), FILE_MAGNETIC("15\n", "magnetic"), FILE_GYRO("16\n", "gyro"); + + String type; + String name; + SensorEventType(String t, String n) { + type = t; + name = n; + } + + public String getName() { + return name; + } + + public String getType() { + return type; + } + + public String toString() { + return name; + } +} diff --git a/ei-library/src/org/tizen/eilib/events/type/USBStatus.java b/ei-library/src/org/tizen/eilib/events/type/USBStatus.java new file mode 100644 index 0000000..cfdeacb --- /dev/null +++ b/ei-library/src/org/tizen/eilib/events/type/USBStatus.java @@ -0,0 +1,49 @@ +/* + * EventInjector Library + * + * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * SooYoung Ha + * JiHye Kim + * YeongKyoon Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + +package org.tizen.eilib.events.type; + +public enum USBStatus { + DISCONNECT(0, "off"), + CONNECT(1, "on"); + + private int value; + private String status; + + USBStatus(int i, String s) { + this.value = i; + this.status = s; + } + + public int getValue() { + return value; + } + + @Override + public String toString() { + return status; + } +} diff --git a/ei-library/src/org/tizen/eilib/exception/CallEventException.java b/ei-library/src/org/tizen/eilib/exception/CallEventException.java new file mode 100644 index 0000000..7036c01 --- /dev/null +++ b/ei-library/src/org/tizen/eilib/exception/CallEventException.java @@ -0,0 +1,43 @@ +/* + * EventInjector Library + * + * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * SooYoung Ha + * JiHye Kim + * YeongKyoon Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + +package org.tizen.eilib.exception; + +public class CallEventException extends InjectorLibraryException { + + /** + * + */ + private static final long serialVersionUID = 6495891796872101374L; + + /** + * Throw error about call event. + * @param message + */ + public CallEventException(EILibError e) { + super(e); + } +} diff --git a/ei-library/src/org/tizen/eilib/exception/ConnectionException.java b/ei-library/src/org/tizen/eilib/exception/ConnectionException.java new file mode 100644 index 0000000..fc1ff0e --- /dev/null +++ b/ei-library/src/org/tizen/eilib/exception/ConnectionException.java @@ -0,0 +1,50 @@ +/* + * EventInjector Library + * + * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * SooYoung Ha + * JiHye Kim + * YeongKyoon Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + +package org.tizen.eilib.exception; + +public class ConnectionException extends Exception { + + private EILibError error; + + public ConnectionException(EILibError e) { + super(e.toString()); + this.error = e; + } + + /** + * + */ + private static final long serialVersionUID = 1L; + + public int getErrorNumber() { + return error.getErrorNumber(); + } + + public EILibError getError() { + return error; + } +} diff --git a/ei-library/src/org/tizen/eilib/exception/DeviceEventException.java b/ei-library/src/org/tizen/eilib/exception/DeviceEventException.java new file mode 100644 index 0000000..a3c55b5 --- /dev/null +++ b/ei-library/src/org/tizen/eilib/exception/DeviceEventException.java @@ -0,0 +1,44 @@ +/* + * EventInjector Library + * + * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * SooYoung Ha + * JiHye Kim + * YeongKyoon Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + +package org.tizen.eilib.exception; + +public class DeviceEventException extends InjectorLibraryException { + + /** + * Throw error about device event. + * @param message + */ + public DeviceEventException(EILibError e) { + super(e); + } + + /** + * + */ + private static final long serialVersionUID = 5262679766405871861L; + +} diff --git a/ei-library/src/org/tizen/eilib/exception/EILibError.java b/ei-library/src/org/tizen/eilib/exception/EILibError.java new file mode 100644 index 0000000..f1077c7 --- /dev/null +++ b/ei-library/src/org/tizen/eilib/exception/EILibError.java @@ -0,0 +1,120 @@ +/* + * EventInjector Library + * + * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * SooYoung Ha + * JiHye Kim + * YeongKyoon Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + +package org.tizen.eilib.exception; + +class ErrorNumber { + public static final int Library = 1000; + public static final int NFC = 1100; + public static final int Device = 1200; + public static final int Modem = 1300; + public static final int Sensor = 1400; + public static final int Location = 1500; +} +public enum EILibError { + Error1(1, "ErrorMessaeg"), + + // Library + EmulatorNotExist(ErrorNumber.Library, "Running Emulator does not exist. Retry after to start emulator."), + EmulatorNotOne(ErrorNumber.Library + 1, "More than one emulator are exist."), + EmuldTerminated(ErrorNumber.Library + 2, "To send event to the emulator is failed. Please check emulator daemon."), + EmuldVersionOld(ErrorNumber.Library + 3, "Emuld version is old version."), + + //NFC + RecordCountIsZero(ErrorNumber.NFC, "List of NDEF record is empty.\nAt least one or more records are required."), + RecordCountIsMax(ErrorNumber.NFC + 1, "The number of NDEF records has reached the maximum limit of 5."), + NDEFMessageLenIsMax(ErrorNumber.NFC + 2,"The length of the NDEF message has reached the maximun limit of 4096 bytes."), + MediaFileException(ErrorNumber.NFC + 3, "The exception has been thrown while selecting media file."), + CheckVconfException(ErrorNumber.NFC + 4, "The exception has been thrown while checking NFC state of emulator."), + SelecTagType(ErrorNumber.NFC + 5, "Tag type can not be null. Select Tag Type!!"), + // check char of NFDE record + InvalidCharNewLine(ErrorNumber.NFC + 6, "You can not enter a newline character."), + InvalidChar(ErrorNumber.NFC + 7, "You can not enter ',' character.\nThis character is used to separator character."), + InvalidCharAscii(ErrorNumber.NFC + 8, "Invalid characters has been entered.\nOnly ASCII characters can be entered."), + // well known + InvalidWellKnownType(ErrorNumber.NFC + 9, "Type name of NDEF_TNF_WELL_KNOWN format is possible only U or T."), + // select media file + NotSelectFile(ErrorNumber.NFC + 10, "Please, input mime media file path."), + CheckMediaFileException(ErrorNumber.NFC + 11, "The exception has been thrown while checking media file size."), + NotMimeType(ErrorNumber.NFC + 12, "Type of selected file is not mime media type."), + BigSizeFile(ErrorNumber.NFC + 13, "Size of selected file is too big.\nAvailable file size is under of 10KB."), + // check vconf + NFCIsDisable(ErrorNumber.NFC + 14, "NFC state is 'Off' in the emulator.\nPlease change NFC state to 'On' on the setting menu."), + + FailedRemoveRecord(ErrorNumber.NFC + 15, "Failed to remove a record."), + TagAttachState(ErrorNumber.NFC + 16, "State of NFC is already tag attch state."), + P2PAttachState(ErrorNumber.NFC + 16, "State of NFC is already p2p attch state."), + CanNotDettach(ErrorNumber.NFC + 17, "State of NFC is already detach state or attach other type's event."), + CanNotSend(ErrorNumber.NFC + 18, "First make state of NFC to the P2P attach state."), + + NullRecord(ErrorNumber.NFC + 19, "Input record is null"), + + // DEVICE + InvalidValue(ErrorNumber.Device, "Input value is not avaliable."), + FailedGetValue(ErrorNumber.Device + 1, "Failed to get value from emulator."), + EmulatorIsMounted(ErrorNumber.Device + 2, "This Emulator has already mounted with SD card."), + SDCardIsMounted(ErrorNumber.Device + 3, "This SD card has been mounted by the other emulator."), + + // MODEM + RSSIIsZero(ErrorNumber.Modem, "RSSI level is zero.\nPlease try again later."), + //BusyMode(ErrorNumber.Modem + 1, "User is busy.\nPlease try again later."), + NumberFormatError(ErrorNumber.Modem + 2, "Format of phone number is wrong."), + NumberIsEmpty(ErrorNumber.Modem + 3, "Phone number is empty."), + NumberIsTooLong(ErrorNumber.Modem + 4, "The maximum length of phone number is 15."), + NumberNotFound(ErrorNumber.Modem + 5, "This phone number does not exist in the call list."), + MessageIsTooLong(ErrorNumber.Modem + 6, "Limit size of text message is 80."), + SendMessageFailed(ErrorNumber.Modem + 7, "Message transmission has been failed"), + NotExistCall(ErrorNumber.Modem + 8, "Avaliable call does not exist."), + IncomingCall(ErrorNumber.Modem + 9, "User is busy.\nPlease try again later."), + NowBusy(ErrorNumber.Modem + 10, "User is busy.\nCall waiting mode of emulator is off. Please try again later."), + ListFull(ErrorNumber.Modem + 11, "There are many pending connections.\nCan't connect anymore."), + // SENSOR + InvalidSensorValue(ErrorNumber.Sensor, "Input sensor's values are not avaliable."), + NotExistLogFile(ErrorNumber.Sensor + 1, "No such log file. Please check your input file path."), + + // Location + InvalidLocationValue(ErrorNumber.Device, "Input location values are not avaliable. Check again value of latitude, longitude."); + + int number; + String message; + + EILibError(int n, String m) { + number = n; + message = m; + } + + public int getErrorNumber() { + return number; + } + + public String getMessage() { + return message; + } + + public String toString() { + return "[" + number + "]" + message; + } +} diff --git a/ei-library/src/org/tizen/eilib/exception/InjectorLibraryException.java b/ei-library/src/org/tizen/eilib/exception/InjectorLibraryException.java new file mode 100644 index 0000000..5dbb877 --- /dev/null +++ b/ei-library/src/org/tizen/eilib/exception/InjectorLibraryException.java @@ -0,0 +1,52 @@ +/* + * EventInjector Library + * + * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * SooYoung Ha + * JiHye Kim + * YeongKyoon Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + +package org.tizen.eilib.exception; + +public class InjectorLibraryException extends Exception { + /** + * + */ + private static final long serialVersionUID = -5585311695949728907L; + + private EILibError error; + /** + * + * @param e + */ + public InjectorLibraryException(EILibError e) { + super(e.toString()); + this.error = e; + } + + public int getErrorNumber() { + return error.getErrorNumber(); + } + + public EILibError getError() { + return error; + } +} diff --git a/ei-library/src/org/tizen/eilib/exception/InvalidTypeException.java b/ei-library/src/org/tizen/eilib/exception/InvalidTypeException.java new file mode 100644 index 0000000..97f9f6f --- /dev/null +++ b/ei-library/src/org/tizen/eilib/exception/InvalidTypeException.java @@ -0,0 +1,36 @@ +/* + * EventInjector Library + * + * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * SooYoung Ha + * JiHye Kim + * YeongKyoon Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + +package org.tizen.eilib.exception; + +@SuppressWarnings("serial") +public class InvalidTypeException extends Exception { + + public InvalidTypeException(String message) { + super(message); + } + +} diff --git a/ei-library/src/org/tizen/eilib/exception/NfcEventException.java b/ei-library/src/org/tizen/eilib/exception/NfcEventException.java new file mode 100644 index 0000000..69fe87b --- /dev/null +++ b/ei-library/src/org/tizen/eilib/exception/NfcEventException.java @@ -0,0 +1,45 @@ +/* + * EventInjector Library + * + * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * SooYoung Ha + * JiHye Kim + * YeongKyoon Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + +package org.tizen.eilib.exception; + +public class NfcEventException extends InjectorLibraryException { + + /** + * + * @param e + */ + public NfcEventException(EILibError e) { + super(e); + // TODO Auto-generated constructor stub + } + + /** + * + */ + private static final long serialVersionUID = 2300982711964476792L; + +} diff --git a/ei-library/src/org/tizen/eilib/exception/SMSEventException.java b/ei-library/src/org/tizen/eilib/exception/SMSEventException.java new file mode 100644 index 0000000..6ecf315 --- /dev/null +++ b/ei-library/src/org/tizen/eilib/exception/SMSEventException.java @@ -0,0 +1,43 @@ +/* + * EventInjector Library + * + * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * SooYoung Ha + * JiHye Kim + * YeongKyoon Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + +package org.tizen.eilib.exception; + +public class SMSEventException extends InjectorLibraryException { + + /** + * + */ + private static final long serialVersionUID = 6495891796872101374L; + + /** + * Throw error about sms event. + * @param message + */ + public SMSEventException(EILibError e) { + super(e); + } +} diff --git a/ei-library/src/org/tizen/eilib/exception/SensorEventException.java b/ei-library/src/org/tizen/eilib/exception/SensorEventException.java new file mode 100644 index 0000000..9eaa8a1 --- /dev/null +++ b/ei-library/src/org/tizen/eilib/exception/SensorEventException.java @@ -0,0 +1,46 @@ +/* + * EventInjector Library + * + * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * SooYoung Ha + * JiHye Kim + * YeongKyoon Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + + +package org.tizen.eilib.exception; + +public class SensorEventException extends InjectorLibraryException { + + /** + * Throw error about sensor event. + * @param e + */ + public SensorEventException(EILibError e) { + super(e); + // TODO Auto-generated constructor stub + } + + /** + * + */ + private static final long serialVersionUID = 1L; + +} diff --git a/ei-library/src/org/tizen/eilib/modem/encription/DecodeMsg.java b/ei-library/src/org/tizen/eilib/modem/encription/DecodeMsg.java new file mode 100644 index 0000000..f9993a2 --- /dev/null +++ b/ei-library/src/org/tizen/eilib/modem/encription/DecodeMsg.java @@ -0,0 +1,684 @@ +/* + * EventInjector Library + * + * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * SooYoung Ha + * JiHye Kim + * YeongKyoon Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + +package org.tizen.eilib.modem.encription; + +import java.io.UnsupportedEncodingException; +import java.util.HashSet; + +public class DecodeMsg { + int ton, npi; + public static boolean deliveryReport = false; + public static char[] smsbuffer = new char[4096]; + public static int smsbuffer_index = 0; + public static boolean relayedsms = false; + public static int relay_cnt = 0; + public static int udhl = 0; + public static HashSet deliveryReportNum_set = new HashSet(); + public static boolean isDecodeEnd = true; + + public void DecodeSmsSubmitTpdu(TPDU_SMS_SUBMIT tpdu_submit, int pdu_len, char[] pPDU) { + isDecodeEnd = false; + int scaAddr_len = 0; + int destAddr_len = 0; + char[] diallingNum = new char[EnumConstants.TAPI_NETTEXT_ADDRESS_LEN_MAX+1]; + char[] scaAddr = new char[EnumConstants.TAPI_NETTEXT_SCADDRESS_LEN_MAX+1]; + char[] destAddr = new char[EnumConstants.TAPI_NETTEXT_ADDRESS_LEN_MAX+1]; +// char[] inData = new char[EnumConstants.TAPI_NETTEXT_SMDATA_SIZE_MAX+1]; + + int position = 0; + + SmsUtilDecodeAddrField_sca(diallingNum, pPDU); + + position += 2; + + scaAddr_len = getSize(diallingNum); + + if ((scaAddr_len % 2) != 0) { + position += scaAddr_len / 2 + 1; + } else { + position += scaAddr_len / 2; + } + + if (ton == EnumConstants.SIM_TON_INTERNATIONAL) { + scaAddr[0] = '+'; + for(int i = 0; i < scaAddr_len; i++) { + scaAddr[i+1] = diallingNum[i]; + scaAddr[scaAddr_len+1] = '\0'; + } + } else { + for(int i = 0; i < scaAddr_len; i++) { + scaAddr[i] = diallingNum[i]; + scaAddr[scaAddr_len] = '\0'; + } + } + + /* TP-MTI, TP-RD, TP-VPF, TP-RP, TP_UDHI, TP-SRR */ + tpdu_submit.msgType = EnumConstants.SMS_TPDU_SUBMIT; + tpdu_submit.rd = ((pPDU[position] & 0x04) != 0) ? true : false; + tpdu_submit.vpf = (pPDU[position] & 0x18) >> 3; + tpdu_submit.srr = ((pPDU[position] & 0x20) != 0) ? true : false; + tpdu_submit.udhi = ((pPDU[position] & 0x40) != 0) ? true : false; + tpdu_submit.rp = ((pPDU[position] & 0x80) != 0) ? true : false; + + position++; + + /* TP-MR */ + tpdu_submit.mr = pPDU[position]; + + position++; + + /* TP-DA */ + for(int i = 0; i < diallingNum.length; i++) { + diallingNum[i] = 0x00; + } + + SmsUtilDecodeAddrField_dst(diallingNum, getCharArray(pPDU, position)); + + position+=2; + + destAddr_len = getSize(diallingNum); + + if((destAddr_len %2) != 0) { + position += destAddr_len / 2 + 1; + } else { + position += destAddr_len / 2; + } + + if (ton == EnumConstants.SIM_TON_INTERNATIONAL) { + destAddr[0] = '+'; + for(int i = 0; i < destAddr_len; i++) { + destAddr[i+1] = diallingNum[i]; + destAddr[destAddr_len+1] = '\0'; + } + tpdu_submit.destAddr.dialnumlen = destAddr_len+1; + for(int i = 0; i < destAddr_len+1; i++) { + tpdu_submit.destAddr.diallingNum[i] = destAddr[i]; + } + } else { + for(int i = 0; i < destAddr_len; i++) { + destAddr[i] = diallingNum[i]; + destAddr[destAddr_len] = '\0'; + } + tpdu_submit.destAddr.dialnumlen = destAddr_len; + for(int i = 0; i < destAddr_len; i++) { + tpdu_submit.destAddr.diallingNum[i] = destAddr[i]; + } + } + + tpdu_submit.destAddr.npi = npi; + tpdu_submit.destAddr.ton = ton; + + /* TP-PID */ + tpdu_submit.pId = pPDU[position]; + position++; + + /* TP DCS */ + SmsUtilDecodeDCS(tpdu_submit.dcs, pPDU[position]); + position++; + + /* TP VP */ +// tpdu_submit.vp.vpType = EnumConstants.TAPI_NETTEXT_VP_RELATIVE; + + switch(tpdu_submit.vp.vpType) { + case EnumConstants.TAPI_NETTEXT_VP_RELATIVE: + tpdu_submit.vp.vpValue = pPDU[position]; + tpdu_submit.vp.vpRelativeType = EnumConstants.TAPI_NETTEXT_VP_REL_1D; + position++; + break; + case EnumConstants.TAPI_NETTEXT_VP_ABSOLUTE: + case EnumConstants.TAPI_NETTEXT_VP_ENHANCED: + position += 7; + break; + default: + break; + } + + /* TP UDL */ + tpdu_submit.udl = pPDU[position] & 0x00FF; + + if(tpdu_submit.udl > EnumConstants.TAPI_NETTEXT_SMDATA_SIZE_MAX) { + tpdu_submit.udl = EnumConstants.TAPI_NETTEXT_SMDATA_SIZE_MAX; + } + + position++; + + /* TP UD */ + if(tpdu_submit.udhi) + { + udhl = pPDU[position]; + int fillbits = 7 - ((pPDU[position] * 8) % 7); + position += udhl; + udhl += fillbits; + + if(pPDU[position] == 1) + { + relay_cnt = pPDU[position - 1]; + for(int i = 0; i < smsbuffer.length; i++) { + smsbuffer[i] = '\0'; + } + } + position++; + + relayedsms = true; + } + else + { + if(relayedsms) + { + for(int i = 0; i < smsbuffer.length; i++) { + smsbuffer[i] = '\0'; + } + + smsbuffer_index = 0; + relayedsms = false; + } + } + + int i = 0; + tpdu_submit.userData = new char[EnumConstants.TAPI_NETTEXT_SMDATA_SIZE_MAX+1]; + //System.out.println("Position : " + position); + if(tpdu_submit.dcs.alphabetType == EnumConstants.TAPI_NETTEXT_ALPHABET_DEFAULT) { + char[] inData = new char[EnumConstants.TAPI_NETTEXT_SMDATA_SIZE_MAX+1]; + for(i = 0; i < tpdu_submit.udl; i++) { + inData[i] = (char)(pPDU[position + i] & 0xff); + if(relay_cnt == 1) // last or single sms + { + if(i == tpdu_submit.udl - udhl) { + break; + } + } + else + { + if(tpdu_submit.udhi == true) + { + if(i == tpdu_submit.udl - udhl) { + break; + } + } + else + { + if(i == tpdu_submit.udl) { + break; + } + } + } + } + + inData[i] = '\0'; + + for(int j = 0; j < i; j++) { + tpdu_submit.userData[j] = inData[j]; + } + + if(relayedsms) + { + String tmp1 = new String(smsbuffer); + String tmp2 = new String(inData); + String tmp3 = tmp1.trim() + tmp2.trim(); + smsbuffer = tmp3.toCharArray(); + } + // SmsUtilUnpackGSMCode(tpdu_submit.userData, inData, tpdu_submit.udl); + } + else if(tpdu_submit.dcs.alphabetType == EnumConstants.TAPI_NETTEXT_ALPHABET_UCS2) + { + byte[] inData = new byte[EnumConstants.TAPI_NETTEXT_SMDATA_SIZE_MAX+1]; + for(i = 0; i < tpdu_submit.udl; i++) { + inData[i] = (byte)(pPDU[position + i] & 0xff); + if(relay_cnt == 1) // last or single sms + { + if(i == tpdu_submit.udl - udhl + 1) { + break; + } + } + else + { + if(tpdu_submit.udhi == true) + { + if(i == tpdu_submit.udl - udhl) { + break; + } + } + else + { + if(i == tpdu_submit.udl) { + break; + } + } + } + } + + try { + inData[i] = '\0'; + tpdu_submit.userData = ucs2ToUTF16(inData, i/2); + } catch (UnsupportedEncodingException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + if(tpdu_submit.srr) + { + // System.out.println("SRR: A status report is requested"); + deliveryReportNum_set.add(String.valueOf(diallingNum).trim()); + deliveryReport = true; + } + else + { + // System.out.println("SRR: A status report is not requested"); + deliveryReport = false; + } + isDecodeEnd = true; + } + + private char[] getCharArray(char[] org, int start) { + int length = org.length - start; + char[] result = new char[length]; + + for(int i = 0; i < length; i++) { + result[i] = org[start + i]; + } + return result; + } + + private void SmsUtilDecodeDCS(TapiNetTextCodingScheme pCodingScheme, char dcs) { + if ( dcs < 0x40 ) { // bits 7..4 = 00xx : general data coding indication + pCodingScheme.codingGroupType = EnumConstants.TAPI_NETTEXT_CODGRP_SM_GENERAL_DCS; + + if ((dcs & 0x20) != 0) {// bit 5 = 1 : indicates the text is compressed + pCodingScheme.bCompressed = true; + } + + if ((dcs & 0x10) != 0) // bit 4 = 1 : indicates that bits 1 to 0 have a message class meaning + { + pCodingScheme.bMsgClassSet = true; + + switch ( dcs & 0x03 ) // bits 1 to 0 : message class + { + case 0x00: + pCodingScheme.classType = EnumConstants.TAPI_NETTEXT_CLASS_0; + break; + case 0x01: + pCodingScheme.classType = EnumConstants.TAPI_NETTEXT_CLASS_1; + break; + case 0x02: + pCodingScheme.classType = EnumConstants.TAPI_NETTEXT_CLASS_2; + break; + case 0x03: + pCodingScheme.classType = EnumConstants.TAPI_NETTEXT_CLASS_3; + break; + default: + break; + } + } + else {// bit 4 = 0 : indicates that bits 1 to 0 are reserved and have no message class meaning + pCodingScheme.classType = EnumConstants.TAPI_NETTEXT_CLASS_NONE; + } + + switch ( dcs & 0x0C ) // bits 4 to 3 : character set + { + case 0x00: + pCodingScheme.alphabetType = EnumConstants.TAPI_NETTEXT_ALPHABET_DEFAULT; + break; + case 0x04: + pCodingScheme.alphabetType = EnumConstants.TAPI_NETTEXT_ALPHABET_8BIT; + break; + case 0x08: + pCodingScheme.alphabetType = EnumConstants.TAPI_NETTEXT_ALPHABET_UCS2; + break; + case 0x0C: + pCodingScheme.alphabetType = EnumConstants.TAPI_NETTEXT_ALPHABET_MAX; + break; + default: + break; + } + } + else if ( dcs >= 0x40 && dcs < 0x80 ) // bits 7..4 = 01xx : message marked for automatic deletion group. bits 5..0 are coded exactly the same as group 00xx + { + pCodingScheme.codingGroupType = EnumConstants.TAPI_NETTEXT_CODGRP_SM_AUTO_DELETION; + + if ((dcs & 0x20) != 0) {// bit 5 = 1 : indicates the text is compressed + pCodingScheme.bCompressed = true; + } + + if ((dcs & 0x10) != 0) // bit 4 = 1 : indicates that bits 1 to 0 have a message class meaning + { + pCodingScheme.bMsgClassSet = true; + + switch ( dcs & 0x03 ) // bits 1 to 0 : message class + { + case 0x00: + pCodingScheme.classType = EnumConstants.TAPI_NETTEXT_CLASS_0; + break; + case 0x01: + pCodingScheme.classType = EnumConstants.TAPI_NETTEXT_CLASS_1; + break; + case 0x02: + pCodingScheme.classType = EnumConstants.TAPI_NETTEXT_CLASS_2; + break; + case 0x03: + pCodingScheme.classType = EnumConstants.TAPI_NETTEXT_CLASS_3; + break; + default: + break; + } + } + else {// bit 4 = 0 : indicates that bits 1 to 0 are reserved and have no message class meaning + pCodingScheme.classType = EnumConstants.TAPI_NETTEXT_CLASS_NONE; + } + + switch ( dcs & 0x0C ) // bits 4 to 3 : character set + { + case 0x00: + pCodingScheme.alphabetType = EnumConstants.TAPI_NETTEXT_ALPHABET_DEFAULT; + break; + case 0x04: + pCodingScheme.alphabetType = EnumConstants.TAPI_NETTEXT_ALPHABET_8BIT; + break; + case 0x08: + pCodingScheme.alphabetType = EnumConstants.TAPI_NETTEXT_ALPHABET_UCS2; + break; + case 0x0C: + pCodingScheme.alphabetType = EnumConstants.TAPI_NETTEXT_ALPHABET_MAX; + break; + default: + break; + } + } + // bits 7..4 = 1000 ~ 1011 : reserved + else if (dcs == 0xC0) // bits 7..4 = 1100 : message waiting indication group, discard message + { + pCodingScheme.codingGroupType = EnumConstants.TAPI_NETTEXT_CODGRP_SM_WAITING_DISCARD; + } + else if (dcs < 0xE0) + { + pCodingScheme.codingGroupType = EnumConstants.TAPI_NETTEXT_CODGRP_SM_WAITING_STORE; + + if ((dcs & 0x08) != 0) { + pCodingScheme.bMsgIndActive = true; + } + + switch (dcs & 0x03) + { + case 0x00: + pCodingScheme.waitingType = EnumConstants.TAPI_NETTEXT_WAITING_VOICE_MSG; + break; + case 0x01: + pCodingScheme.waitingType = EnumConstants.TAPI_NETTEXT_WAITING_FAX_MSG; + break; + case 0x02: + pCodingScheme.waitingType = EnumConstants.TAPI_NETTEXT_WAITING_EMAIL_MSG; + break; + case 0x03: + pCodingScheme.waitingType = EnumConstants.TAPI_NETTEXT_WAITING_OTHER_MSG; + break; + default: + break; + } + } + else if (dcs < 0xF0) + { + pCodingScheme.codingGroupType = EnumConstants.TAPI_NETTEXT_CODGRP_SM_WAITING_STORE_UCS2; + + if ((dcs & 0x08) != 0) { + pCodingScheme.bMsgIndActive = true; + } + + switch (dcs & 0x03) + { + case 0x00: + pCodingScheme.waitingType = EnumConstants.TAPI_NETTEXT_WAITING_VOICE_MSG; + break; + case 0x01: + pCodingScheme.waitingType = EnumConstants.TAPI_NETTEXT_WAITING_FAX_MSG; + break; + case 0x02: + pCodingScheme.waitingType = EnumConstants.TAPI_NETTEXT_WAITING_EMAIL_MSG; + break; + case 0x03: + pCodingScheme.waitingType = EnumConstants.TAPI_NETTEXT_WAITING_OTHER_MSG; + break; + default: + break; + } + } + else + { + pCodingScheme.codingGroupType = EnumConstants.TAPI_NETTEXT_CODGRP_SM_CLASS_CODING; + + if ((dcs & 0x04) != 0) { + pCodingScheme.alphabetType = EnumConstants.TAPI_NETTEXT_ALPHABET_8BIT; + } + + switch (dcs & 0x03) + { + case 0x00: + pCodingScheme.classType = EnumConstants.TAPI_NETTEXT_CLASS_0; + break; + case 0x01: + pCodingScheme.classType = EnumConstants.TAPI_NETTEXT_CLASS_1; + break; + case 0x02: + pCodingScheme.classType = EnumConstants.TAPI_NETTEXT_CLASS_2; + break; + case 0x03: + pCodingScheme.classType = EnumConstants.TAPI_NETTEXT_CLASS_3; + break; + default: + break; + } + } + } + + private void SmsUtilDecodeAddrField_sca(char[] diallingNum, char[] pAddrField) { +// int ton, npi; + int index = 0; + int dialnumLen = 0; + int length = 0; + + ton = (pAddrField[index+1] & 0x70) >> 4; + npi = pAddrField[index+1] & 0x0F; + + if(ton != EnumConstants.SIM_TON_ALPHA_NUMERIC) { + length = pAddrField[index]; + if(length > 1) { + dialnumLen = (pAddrField[index++] - 1) * 2; + } + } else { + dialnumLen = (((pAddrField[index++] + 1) / 2) * 8) / 7; + } + + if(dialnumLen > EnumConstants.SIM_SMSP_ADDRESS_LEN) { + dialnumLen = EnumConstants.SIM_SMSP_ADDRESS_LEN; + } + + // Ignore type of address field + index++; + + if(ton != EnumConstants.SIM_TON_ALPHA_NUMERIC) { + SmsUtilConvertBCD2Digit(diallingNum, getCharArray(pAddrField, index), dialnumLen); + } else { + SmsUtilUnpackGSMCode(diallingNum, getCharArray(pAddrField, index), dialnumLen); + } + } + + private void SmsUtilDecodeAddrField_dst(char[] diallingNum, char[] pAddrField) { +// int ton, npi; + int index = 0; + int dialnumLen = 0; + + ton = (pAddrField[index+1] & 0x70) >> 4; + npi = pAddrField[index+1] & 0x0F; + + if(ton != EnumConstants.SIM_TON_ALPHA_NUMERIC) { + dialnumLen = pAddrField[index++]; + } else { + dialnumLen = (((pAddrField[index++] + 1) / 2) * 8) / 7; + } + if(dialnumLen > EnumConstants.SIM_SMSP_ADDRESS_LEN) { + dialnumLen = EnumConstants.SIM_SMSP_ADDRESS_LEN; + } + // Ignore type of address field + index++; + + if(ton != EnumConstants.SIM_TON_ALPHA_NUMERIC) { + SmsUtilConvertBCD2Digit(diallingNum, getCharArray(pAddrField, index), dialnumLen); + } else { + SmsUtilUnpackGSMCode(diallingNum, getCharArray(pAddrField, index), dialnumLen); + } + //System.out.println(diallingNum); + } + + private void SmsUtilConvertBCD2Digit(char[] pDigits, char[] pBCD, int digitLen) { + int i, bcdLen; + char[] c = {0x00, 0x00}; + char higher, lower; + + if(pBCD == null || pDigits == null) { + return; + //throw new NullPointerException("SmsUtilConvertBCD2Digit"); //$NON-NLS-1$ + } + + + if(digitLen == 0) { + pDigits[0] = 0x00; + return; + } + + if((digitLen % 2) != 0) { + bcdLen = digitLen / 2 + 1; + } else { + bcdLen = digitLen / 2; + } + + for(i = 0; i < bcdLen; i++) { + lower = (char)(pBCD[i] & 0x0F); + + if(lower == 0x0A) { + lower = '*'; + } else if(lower == 0x0B) { + lower = '#'; + } else if(lower == 0x0C) { + lower = 'p'; + } else if(lower == 0x0F) { + lower = 0; + } else { + AcItoa(lower, c, 16); + lower = (char)AcToupper(c[0]); + } + + higher = (char)((pBCD[i] >> 4) & 0x0F); + + if(higher == 0x0A) { + higher = '*'; + } else if(higher == 0x0B) { + higher = '#'; + } else if(higher == 0x0C) { + higher = 'p'; + } else if(higher == 0x0F) { + pDigits[getSize(pDigits)] = lower; + pDigits[bcdLen*2-1] = '\0'; + return; + } + else { + AcItoa(higher, c, 16); + higher = (char)AcToupper(c[0]); + } + pDigits[getSize(pDigits)] = lower; + pDigits[getSize(pDigits)] = higher; + } + pDigits[digitLen] = '\0'; + } + + private int getSize(char[] array) { + int ret = 0; + String str = new String(array); + ret = str.indexOf('\0'); + return ret; + } + + private int AcToupper(int ch) { + return (('a' <= (ch) && (ch) <= 'z') ? ((ch) - ('a' - 'A')) : (ch)); + } + + private void AcItoa(int n, char[] str, int b) { + int i = 0; + String arr = new String("0123456789ABCDEF"); //$NON-NLS-1$ + do + str[i++] = arr.charAt(n%b); + while((n /= b) > 0); + reverse(str, i); + str[i] = '\0'; + } + + private void reverse(char[] x, int len) { + int i, j = len-1; + for(i = 0; i < j; i++) { + char t = x[i]; + x[i] = x[j]; + x[j--] = t; + } + } + + private void SmsUtilUnpackGSMCode(char[] szData, char[] pIn, int in_len) { + int shift = 0; + int pos = 0; + + for(int i = 0; i < in_len; i++, pos++) { + szData[i] = (char)((pIn[pos] << shift) & 0x7F); + if(pos != 0) { + /* except the first byte, a character contains some bits + * from the previous byte + */ + szData[i] |= pIn[pos-1] >> (8-shift); + } + shift++; + + if(shift == 7) { + shift = 0; + /* a possible extra complete character is available */ + i++; + szData[i] = (char)(pIn[pos] >> 1); + /* This is the end of the input, quit */ + if(szData[i] == 0) { + break; + } + } + } + } + + public char[] ucs2ToUTF16(byte[] ucs2Bytes, int length) throws UnsupportedEncodingException{ + String unicode = new String(ucs2Bytes, "UTF-16"); + char[] str = unicode.toCharArray(); + + String tmp1 = new String(smsbuffer); + String tmp2 = unicode.substring(0, length); + String tmp3 = tmp1.trim() + tmp2.trim(); + smsbuffer = tmp3.toCharArray(); + + return str; + } +} diff --git a/ei-library/src/org/tizen/eilib/modem/encription/EncodeMsg.java b/ei-library/src/org/tizen/eilib/modem/encription/EncodeMsg.java new file mode 100644 index 0000000..29b3c9d --- /dev/null +++ b/ei-library/src/org/tizen/eilib/modem/encription/EncodeMsg.java @@ -0,0 +1,578 @@ +/* + * EventInjector Library + * + * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * SooYoung Ha + * JiHye Kim + * YeongKyoon Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + +package org.tizen.eilib.modem.encription; + +public class EncodeMsg { + int index; + + public int EncodeSmsDeliverTpdu(SmsAddressInfo SCA, + TPDU_SMS_DELIVER tpdu_deliver, char[] packet, int pid, int dcs) { + // char tp_dcs; // BYTE + char[] timeStamp = new char[21]; + char[] scaNumber = new char[21]; + char[] orgNumber = new char[21]; + int scaLength; + int orgLength; + int i; + + index = 0; + + if (SCA.diallingNum[0] == '+') { + SCA.ton = 1; + SCA.npi = 1; + for (i = 0; i < SCA.dialnumlen-1; i++) { + scaNumber[i] = SCA.diallingNum[i + 1]; + } + scaLength = SCA.dialnumlen - 1; + scaNumber[scaLength] = '\0'; + } else { + SCA.ton = 0; + SCA.npi = 0; + for (i = 0; i < SCA.dialnumlen; i++) { + scaNumber[i] = SCA.diallingNum[i]; + } + scaLength = SCA.dialnumlen; + scaNumber[scaLength] = '\0'; + } + + SmsUtilEncodeAddrField_sca(packet, scaNumber, scaLength, SCA.ton, SCA.npi); + + tpdu_deliver.msgType = EnumConstants.SMS_TPDU_DELIVER; + + packet[index] = (char) tpdu_deliver.msgType; + packet[index] |= tpdu_deliver.mms ? 0x04 : 0; + packet[index] |= tpdu_deliver.sri ? 0x20 : 0; + packet[index] |= tpdu_deliver.udhi ? 0x40 : 0; + packet[index] |= tpdu_deliver.rp ? 0x80 : 0; + + index++; + + if (tpdu_deliver.orgAddr.diallingNum[0] == '+') { + tpdu_deliver.orgAddr.ton = 1; + tpdu_deliver.orgAddr.npi = 1; + for (i = 0; i < tpdu_deliver.orgAddr.dialnumlen-1; i++) { + orgNumber[i] = tpdu_deliver.orgAddr.diallingNum[i + 1]; + } + orgLength = tpdu_deliver.orgAddr.dialnumlen - 1; + orgNumber[orgLength] = '\0'; + } else { + tpdu_deliver.orgAddr.ton = 0; + tpdu_deliver.orgAddr.npi = 0; + for (i = 0; i < tpdu_deliver.orgAddr.dialnumlen; i++) { + orgNumber[i] = tpdu_deliver.orgAddr.diallingNum[i]; + } + orgLength = tpdu_deliver.orgAddr.dialnumlen; + orgNumber[orgLength] = '\0'; + } + + /* TP-OA */ + SmsUtilEncodeAddrField_dst(packet, orgNumber, orgLength, tpdu_deliver.orgAddr.ton, tpdu_deliver.orgAddr.npi); + + /* TP-PID */ + packet[index++] = (char) pid; + + int tp_dcs = SmsUtilEncodeDCS(tpdu_deliver.dcs); + + packet[index++] = (char) tp_dcs; + + SmsUtilEncodeTimeStamp(tpdu_deliver.scts, timeStamp); + + for (i = 0; i < 7; i++) { + packet[index++] = timeStamp[i]; + } + + /* TP-UD */ + switch(tpdu_deliver.dcs.alphabetType) { + case EnumConstants.TAPI_NETTEXT_ALPHABET_DEFAULT: + /* UDL */ + packet[index++] = (char) tpdu_deliver.userData.data.length; + SmsUtilPackGSMCode(packet, new String(tpdu_deliver.userData.data).toCharArray(), + tpdu_deliver.userData.data.length); + break; + case EnumConstants.TAPI_NETTEXT_ALPHABET_8BIT: + packet[index++] = (char) tpdu_deliver.userData.data.length; + SmsUtilPackGSM8Code(packet, new String(tpdu_deliver.userData.data).toCharArray(), + tpdu_deliver.userData.data.length); + break; + case EnumConstants.TAPI_NETTEXT_ALPHABET_UCS2: + int udhl = 0; + int fillBits = 0; + int tempIndex = index; + + if (tpdu_deliver.userData.headerCnt > 0) { + index = index + 2; + } else { + index = index + 1; + } + + // setting HEADER + int headerLen = 6; + for (i = 0; i < tpdu_deliver.userData.headerCnt; i++) + { + packet[index++] = 0x08; // SMS_UDH_CONCAT_16BIT; + packet[index++] = 0x04; // offset + packet[index++] = (char)(tpdu_deliver.userData.smsUDH.msgRef >> 8); + packet[index++] = (char)(tpdu_deliver.userData.smsUDH.msgRef & 0x00FF); + packet[index++] = tpdu_deliver.userData.smsUDH.totalSeg; + packet[index++] = tpdu_deliver.userData.smsUDH.seqNum; + udhl += headerLen; + } + + if (udhl > 0) { + packet[tempIndex] = (char)((udhl+1) + fillBits + tpdu_deliver.userData.length); + packet[tempIndex+ 1] = (char)udhl; + } else { + packet[tempIndex] = (char)(tpdu_deliver.userData.length); + } + + for(int ind = 0; ind < tpdu_deliver.userData.length; ind++) { + packet[index++] = (char)tpdu_deliver.userData.data[ind]; + } + break; + // throw new NullPointerException(Messages.EncodeMsg_0); + default: + //throw new NullPointerException("Unknown alphabetType UCS2!\n"); + break; + } + + return index; + } + + private void SmsUtilPackGSMCode(char[] pOut, char[] szData, int in_len) { + int shift = 0; + + for (int i = 0; i < in_len; index++, i++) { + /* pack the high bits using the low bits of the next character */ + pOut[index] = (char) (szData[i] >> shift); + if (i + 1 < in_len) { + /* pack the high bits using the low bits of the next character */ + pOut[index] |= szData[i + 1] << (7 - shift); + pOut[index] &= 0xFF; + shift++; + + if (shift == 7) { + shift = 0; + i++; + } + } + } + } + + private void SmsUtilPackGSM8Code(char[] pOut, char[] szData, int in_len) { + for(int i = 0; i < in_len; i++) { + pOut[index++] = szData[i]; + } + } + + private void SmsUtilEncodeTimeStamp(TmDateTime tmDateTime, char[] timeStamp) { + char[] szBuf = null; + char[] tmpBuf = new char[20]; + int year; + + for (int i = 0; i < 7; i++) { + timeStamp[i] = 0x00; + } + + year = tmDateTime.year - 2000; + if (year < 0) { + year += 100; + } + + szBuf = String.format("%02d", year).toCharArray(); //$NON-NLS-1$ + SmsUtilConvertDigit2BCD(tmpBuf, szBuf, 2); + timeStamp[0] = tmpBuf[0]; + szBuf = String.format("%02d", tmDateTime.month).toCharArray(); //$NON-NLS-1$ + SmsUtilConvertDigit2BCD(tmpBuf, szBuf, 2); + timeStamp[1] = tmpBuf[0]; + szBuf = String.format("%02d", tmDateTime.day).toCharArray(); //$NON-NLS-1$ + SmsUtilConvertDigit2BCD(tmpBuf, szBuf, 2); + timeStamp[2] = tmpBuf[0]; + szBuf = String.format("%02d", tmDateTime.hour).toCharArray(); //$NON-NLS-1$ + SmsUtilConvertDigit2BCD(tmpBuf, szBuf, 2); + timeStamp[3] = tmpBuf[0]; + szBuf = String.format("%02d", tmDateTime.minute).toCharArray(); //$NON-NLS-1$ + SmsUtilConvertDigit2BCD(tmpBuf, szBuf, 2); + timeStamp[4] = tmpBuf[0]; + szBuf = String.format("%02d", tmDateTime.second).toCharArray(); //$NON-NLS-1$ + SmsUtilConvertDigit2BCD(tmpBuf, szBuf, 2); + timeStamp[5] = tmpBuf[0]; + szBuf = String.format("%02d", 0x00).toCharArray(); //$NON-NLS-1$ + SmsUtilConvertDigit2BCD(tmpBuf, szBuf, 2); + timeStamp[6] = tmpBuf[0]; + } + + private char SmsUtilEncodeDCS(TapiNetTextCodingScheme codingScheme) { + char dcs = 0x00; + + switch (codingScheme.codingGroupType) { + case EnumConstants.TAPI_NETTEXT_CODGRP_SM_GENERAL_DCS: // bit 7..4 is + // 00xx + { + if (codingScheme.bCompressed) { + dcs |= 0x20; // bit 5 is 1 + } + + if (codingScheme.bMsgClassSet) { + dcs |= 0x10; // bit 4 is 1 + + switch (codingScheme.classType) { + case EnumConstants.TAPI_NETTEXT_CLASS_0: // bit 1..0 is 00 + { + dcs |= 0x00; + break; + } + case EnumConstants.TAPI_NETTEXT_CLASS_1: // bit 1..0 is 01 + { + dcs |= 0x01; + break; + } + case EnumConstants.TAPI_NETTEXT_CLASS_2: // bit 1..0 is 10 + { + dcs |= 0x02; + break; + } + case EnumConstants.TAPI_NETTEXT_CLASS_3: // bit 1..0 is 11 + { + dcs |= 0x03; + break; + } + default: + break; + } + } + + switch (codingScheme.alphabetType) { + case EnumConstants.TAPI_NETTEXT_ALPHABET_DEFAULT: // bit 3..2 is 00 + { + dcs |= 0x00; + break; + } + case EnumConstants.TAPI_NETTEXT_ALPHABET_8BIT: // bit 3..2 is 01 + { + dcs |= 0x04; + break; + } + case EnumConstants.TAPI_NETTEXT_ALPHABET_UCS2: // bit 3..2 is 10 + { + dcs |= 0x08; + break; + } + default: // bit 3..2 is 11 + { + dcs |= 0x0C; + break; + } + } + + break; + } + case EnumConstants.TAPI_NETTEXT_CODGRP_SM_WAITING_DISCARD: // bit 7..4 + // is 1100 + { + dcs |= 0xC0; + + break; + } + case EnumConstants.TAPI_NETTEXT_CODGRP_SM_WAITING_STORE: // bit 7..4 is + // 1101 + { + dcs |= 0xD0; + + if (codingScheme.bMsgIndActive) {// bit 3..2 is 10 + dcs |= 0x08; + } + + switch (codingScheme.waitingType) { + case EnumConstants.TAPI_NETTEXT_WAITING_VOICE_MSG: // bit 1..0 is 00 + { + dcs |= 0x00; + break; + } + case EnumConstants.TAPI_NETTEXT_WAITING_FAX_MSG: // bit 1..0 is 01 + { + dcs |= 0x01; + break; + } + case EnumConstants.TAPI_NETTEXT_WAITING_EMAIL_MSG: // bit 1..0 is 10 + { + dcs |= 0x02; + break; + } + case EnumConstants.TAPI_NETTEXT_WAITING_OTHER_MSG: // bit 1..0 is 11 + { + dcs |= 0x03; + break; + } + default: + break; + } + + break; + } + case EnumConstants.TAPI_NETTEXT_CODGRP_SM_WAITING_STORE_UCS2: // bit + // 7..4 + // is + // 1110 + { + dcs |= 0xE0; + + if (codingScheme.bMsgIndActive) {// bit 3..2 is 10 + dcs |= 0x08; + } + + switch (codingScheme.waitingType) { + case EnumConstants.TAPI_NETTEXT_WAITING_VOICE_MSG: // bit 1..0 is 00 + { + dcs |= 0x00; + break; + } + case EnumConstants.TAPI_NETTEXT_WAITING_FAX_MSG: // bit 1..0 is 01 + { + dcs |= 0x01; + break; + } + case EnumConstants.TAPI_NETTEXT_WAITING_EMAIL_MSG: // bit 1..0 is 10 + { + dcs |= 0x02; + break; + } + case EnumConstants.TAPI_NETTEXT_WAITING_OTHER_MSG: // bit 1..0 is 11 + { + dcs |= 0x03; + break; + } + default: + break; + } + + break; + } + case EnumConstants.TAPI_NETTEXT_CODGRP_SM_CLASS_CODING: // bit 7..4 is + // 1111 + { + dcs |= 0xF0; + + switch (codingScheme.alphabetType) { + case EnumConstants.TAPI_NETTEXT_ALPHABET_DEFAULT: // bit 2 is 0 + { + dcs |= 0x00; + break; + } + case EnumConstants.TAPI_NETTEXT_ALPHABET_8BIT: // bit 2 is 1 + { + dcs |= 0x04; + break; + } + default: + break; + } + + switch (codingScheme.classType) { + case EnumConstants.TAPI_NETTEXT_CLASS_0: // bit 1..0 is 00 + { + break; + } + case EnumConstants.TAPI_NETTEXT_CLASS_1: // bit 1..0 is 01 + { + dcs |= 0x01; + break; + } + case EnumConstants.TAPI_NETTEXT_CLASS_2: // bit 1..0 is 10 + { + dcs |= 0x02; + break; + } + case EnumConstants.TAPI_NETTEXT_CLASS_3: // bit 1..0 is 11 + { + dcs |= 0x03; + break; + } + default: + break; + } + + break; + } + case EnumConstants.TAPI_NETTEXT_CODGRP_SM_RESERVED: // bit 7..4 is 1111 + { + dcs = (char) ((codingScheme.codingGroup << 4) & 0xF0); + dcs |= (codingScheme.code & 0x0F); + break; + } + default: + break; + } + return dcs; + } + + private void SmsUtilEncodeAddrField_sca(char[] pAddrField, char[] diallingNum, + int dialnumLen, int ton, int npi) { +// int index = 0; + + if (pAddrField == null || diallingNum == null) { + return; + //throw new NullPointerException("SmsUtilEncodeAddrField"); //$NON-NLS-1$ + } + + if (ton != EnumConstants.SIM_TON_ALPHA_NUMERIC) { + if((dialnumLen % 2) != 0) { + pAddrField[index++] = (char)(dialnumLen / 2 + 1 + 1); + } else { + pAddrField[index++] = (char)(dialnumLen / 2 + 1); + } + } else { + pAddrField[index] = (char) (((dialnumLen * 7 + 7) / 8) * 2); + if (((dialnumLen * 7) % 8) <= 4) { + pAddrField[index]--; + } + index++; + } + + // SET_TON_NPI + pAddrField[index] = 0x80; + pAddrField[index] |= (ton & 0x07) << 4; + pAddrField[index] |= npi & 0x0F; + + index++; + + if (ton != EnumConstants.SIM_TON_ALPHA_NUMERIC) { + int i, j, k; + char[] tmpBuf = new char[dialnumLen]; + SmsUtilConvertDigit2BCD(tmpBuf, diallingNum, dialnumLen); + j = index; + + if((dialnumLen % 2) != 0) { + index += dialnumLen / 2 + 1; + } + else { + index += dialnumLen / 2; + } + + for(i = j, k = 0; i < index; i++, k++) { + pAddrField[i] = tmpBuf[k]; + } + } else { + SmsUtilPackGSMCode(pAddrField, diallingNum, (int) dialnumLen); + } + } + + private void SmsUtilEncodeAddrField_dst(char[] packet, char[] diallingNum, + int dialnumLen, int ton, int npi) { +// int index = 0; + + if (packet == null || diallingNum == null) { + return; + //throw new NullPointerException("SmsUtilEncodeAddrField"); //$NON-NLS-1$ + } + + if (ton != EnumConstants.SIM_TON_ALPHA_NUMERIC) { + packet[index++] = (char) dialnumLen; + } else { + packet[index] = (char) (((dialnumLen * 7 + 7) / 8) * 2); + if (((dialnumLen * 7) % 8) <= 4) { + packet[index]--; + } + index++; + } + + // SET_TON_NPI + packet[index] = 0x80; + packet[index] |= (ton & 0x07) << 4; + packet[index] |= npi & 0x0F; + + index++; + + if (ton != EnumConstants.SIM_TON_ALPHA_NUMERIC) { + int i, j, k; + char[] tmpBuf = new char[dialnumLen]; + for (i = 0; i < dialnumLen; i++) { + tmpBuf[i] = 0x00; + } + + SmsUtilConvertDigit2BCD(tmpBuf, diallingNum, dialnumLen); + j = index; + + if ((dialnumLen % 2) != 0) { + index += dialnumLen / 2 + 1; + } else { + index += dialnumLen / 2; + } + for (i = j, k = 0; i < index; i++, k++) { + packet[i] = tmpBuf[k]; + } + } else { + SmsUtilPackGSMCode(packet, diallingNum, (int) dialnumLen); + } + } + + private void SmsUtilConvertDigit2BCD(char[] pBCD, char[] pDigits, + long digitLen) { + int i, j, digit; + char higher, lower; + + if (pBCD == null || pDigits == null) { + return; + //throw new NullPointerException("SmsUtilConvertDigit2BCD"); //$NON-NLS-1$ + } + + for (i = 0, j = 0; i < digitLen; i = i + 2, j++) { + if (pDigits[i] == '*') { + digit = 0x0A; + } else if (pDigits[i] == '#') { + digit = 0x0B; + } else if (AcToupper(pDigits[i]) == 'P') { + digit = 0x0C; + } else { + digit = (int) (pDigits[i] - '0'); + } + + lower = (char) (digit & 0x0F); + + if (digitLen != i + 1) { + if (pDigits[i + 1] == '*') { + digit = 0x0A; + } else if (pDigits[i + 1] == '#') { + digit = 0x0B; + } else if (AcToupper(pDigits[i + 1]) == 'P') { + digit = 0x0C; + } else { + digit = (int) (pDigits[i + 1] - '0'); + } + + higher = (char) (digit & 0x0F); + } else { + higher = 0xFF; + } + pBCD[j] = (char) ((higher << 4) | lower); + pBCD[j] &= 0xFF; + } + } + + private int AcToupper(int ch) { + return (('a' <= (ch) && (ch) <= 'z') ? ((ch) - ('a' - 'A')) : (ch)); + } +} diff --git a/ei-library/src/org/tizen/eilib/modem/encription/EnumConstants.java b/ei-library/src/org/tizen/eilib/modem/encription/EnumConstants.java new file mode 100644 index 0000000..36ae9b8 --- /dev/null +++ b/ei-library/src/org/tizen/eilib/modem/encription/EnumConstants.java @@ -0,0 +1,107 @@ +/* + * EventInjector Library + * + * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * SooYoung Ha + * JiHye Kim + * YeongKyoon Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + +package org.tizen.eilib.modem.encription; + +public class EnumConstants { + // SmsTPDUType + public static final int SMS_TPDU_DELIVER = 0x00; + public static final int SMS_TPDU_DELIVER_REPORT = 0x00; + public static final int SMS_TPDU_SUBMIT = 0x01; + public static final int SMS_TPDU_SUBMIT_REPORT = 0x01; + public static final int SMS_TPDU_STATUS_REPORT = 0x02; + public static final int SMS_TPDU_COMMAND = 0x02; + public static final int SMS_PDU_INVALID_TYPE = 0x03; + + // NumberingPlan + public static final int NUMBERING_PLAN_IDENTIFICATION_UNKNOWN = 0x00; + public static final int NUMBERING_PLAN_IDENTIFICATIN_ISDN_TELEPHONE = 0x01; + + // TapiNetTextCodingGroupType + public static final int TAPI_NETTEXT_CODGRP_SM_GENERAL_DCS = 0x00; + public static final int TAPI_NETTEXT_CODGRP_CB_GENERAL_LANG = 0x01; + public static final int TAPI_NETTEXT_CODGRP_CB_ALPHA = 0x02; + public static final int TAPI_NETTEXT_CODGRP_CB_RES1 = 0x03; + public static final int TAPI_NETTEXT_CODGRP_CB_RES2 = 0x04; + public static final int TAPI_NETTEXT_CODGRP_SM_AUTO_DELETION = 0x05; + public static final int TAPI_NETTEXT_CODGRP_CB_GENERAL_DCS = 0x06; + public static final int TAPI_NETTEXT_CODGRP_SM_WAITING_DISCARD = 0x07; + public static final int TAPI_NETTEXT_CODGRP_SM_WAITING_STORE = 0x08; + public static final int TAPI_NETTEXT_CODGRP_SM_WAITING_STORE_UCS2 = 0x09; + public static final int TAPI_NETTEXT_CODGRP_CB_WAP = 0x0A; + public static final int TAPI_NETTEXT_CODGRP_SM_CLASS_CODING = 0x0B; + public static final int TAPI_NETTEXT_CODGRP_CB_CLASS_CODING = 0x0C; + public static final int TAPI_NETTEXT_CODGRP_SM_RESERVED = 0x0D; + public static final int TAPI_NETTEXT_CODGRP_MAX = 0x0E; + + // TapiNetTextWaitingType + public static final int TAPI_NETTEXT_WAITING_VOICE_MSG = 0x00; + public static final int TAPI_NETTEXT_WAITING_FAX_MSG = 0x01; + public static final int TAPI_NETTEXT_WAITING_EMAIL_MSG = 0x02; + public static final int TAPI_NETTEXT_WAITING_OTHER_MSG = 0x03; + public static final int TAPI_NETTEXT_WAITING_MAX = 0x04; + + // TapiNetTextAlphabetType + public static final int TAPI_NETTEXT_ALPHABET_DEFAULT = 0x00; + public static final int TAPI_NETTEXT_ALPHABET_8BIT = 0x01; + public static final int TAPI_NETTEXT_ALPHABET_UCS2 = 0x02; + public static final int TAPI_NETTEXT_ALPHABET_KSC5601 = 0x03; + public static final int TAPI_NETTEXT_ALPHABET_MAX = 0x04; + + // TapiNetTextClasstype + public static final int TAPI_NETTEXT_CLASS_0 = 0x00; + public static final int TAPI_NETTEXT_CLASS_1 = 0x01; + public static final int TAPI_NETTEXT_CLASS_2 = 0x02; + public static final int TAPI_NETTEXT_CLASS_3 = 0x03; + public static final int TAPI_NETTEXT_CLASS_NONE = 0x04; + public static final int TAPI_NETTEXT_CLASS_MAX = 0x05; + + // TapiNetTextVPType + public static final int TAPI_NETTEXT_VP_NOT_USED = 0; + public static final int TAPI_NETTEXT_VP_RELATIVE = 2; + public static final int TAPI_NETTEXT_VP_ABSOLUTE = 3; + public static final int TAPI_NETTEXT_VP_ENHANCED = 1; + public static final int TAPI_NETTEXT_VP_MAX = 4; + + // TapiNetTextVPRelValue; + public static final int TAPI_NETTEXT_VP_REL_1H = 0; + public static final int TAPI_NETTEXT_VP_REL_6H = 1; + public static final int TAPI_NETTEXT_VP_REL_12H = 2; + public static final int TAPI_NETTEXT_VP_REL_1D = 3; + public static final int TAPI_NETTEXT_VP_REL_1W = 4; + public static final int TAPI_NETTEXT_VP_REL_1M = 5; + public static final int TAPI_NETTEXT_VP_REL_MAX = 6; + public static final int TAPI_NETTEXT_SMDATA_SIZE_MAX = 255; + public static final int TAPI_NETTEXT_ADDRESS_LEN_MAX = 255; + public static final int TAPI_NETTEXT_SCADDRESS_LEN_MAX = 20; + + // define + public static final int SIM_TON_INTERNATIONAL = 1; + public static final int SIM_TON_ALPHA_NUMERIC = 5; + public static final int SIM_SMSP_ADDRESS_LEN = 20; + + +} diff --git a/ei-library/src/org/tizen/eilib/modem/encription/SMS_USERDATA.java b/ei-library/src/org/tizen/eilib/modem/encription/SMS_USERDATA.java new file mode 100644 index 0000000..da0014f --- /dev/null +++ b/ei-library/src/org/tizen/eilib/modem/encription/SMS_USERDATA.java @@ -0,0 +1,50 @@ +/* + * EventInjector Library + * + * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * SooYoung Ha + * JiHye Kim + * YeongKyoon Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + +package org.tizen.eilib.modem.encription; + +public class SMS_USERDATA { + public SMS_USERDATA() { + smsUDH = new SMS_UDH(); + } + public void setSMSUDH(char type, short ref, char seg, char num) + { + smsUDH.udhType = type; + smsUDH.msgRef = ref; + smsUDH.totalSeg = seg; + smsUDH.seqNum = num; + } + public int headerCnt; + public SMS_UDH smsUDH; + public int length; + public byte[] data; +} +class SMS_UDH { + public char udhType; + public short msgRef; + public char totalSeg; + public char seqNum; +} \ No newline at end of file diff --git a/ei-library/src/org/tizen/eilib/modem/encription/SmsAddressInfo.java b/ei-library/src/org/tizen/eilib/modem/encription/SmsAddressInfo.java new file mode 100644 index 0000000..cf43ee2 --- /dev/null +++ b/ei-library/src/org/tizen/eilib/modem/encription/SmsAddressInfo.java @@ -0,0 +1,34 @@ +/* + * EventInjector Library + * + * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * SooYoung Ha + * JiHye Kim + * YeongKyoon Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + +package org.tizen.eilib.modem.encription; + +public class SmsAddressInfo { + public int ton; // NumberType + public int npi; // NumberingPlan + public int dialnumlen; // UINT32 + public char diallingNum[] = new char[21]; // unsigned char +} diff --git a/ei-library/src/org/tizen/eilib/modem/encription/TPDU_SMS_DELIVER.java b/ei-library/src/org/tizen/eilib/modem/encription/TPDU_SMS_DELIVER.java new file mode 100644 index 0000000..be66976 --- /dev/null +++ b/ei-library/src/org/tizen/eilib/modem/encription/TPDU_SMS_DELIVER.java @@ -0,0 +1,48 @@ +/* + * EventInjector Library + * + * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * SooYoung Ha + * JiHye Kim + * YeongKyoon Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + +package org.tizen.eilib.modem.encription; + +public class TPDU_SMS_DELIVER { + public int msgType; // SmsTPDUType + public boolean mms; // BOOL + public boolean rp; // BOOL + public boolean udhi; // BOOL + public boolean sri; // BOOL + + public SmsAddressInfo orgAddr; + public byte pId; // BYTE + public TmDateTime scts; + public TapiNetTextCodingScheme dcs; + public int udl; // UINT + //public char[] userData; // byte * + public SMS_USERDATA userData; + public TPDU_SMS_DELIVER() { + orgAddr = new SmsAddressInfo(); + scts = new TmDateTime(); + dcs = new TapiNetTextCodingScheme(); + } +} diff --git a/ei-library/src/org/tizen/eilib/modem/encription/TPDU_SMS_SUBMIT.java b/ei-library/src/org/tizen/eilib/modem/encription/TPDU_SMS_SUBMIT.java new file mode 100644 index 0000000..a570015 --- /dev/null +++ b/ei-library/src/org/tizen/eilib/modem/encription/TPDU_SMS_SUBMIT.java @@ -0,0 +1,74 @@ +/* + * EventInjector Library + * + * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * SooYoung Ha + * JiHye Kim + * YeongKyoon Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ +package org.tizen.eilib.modem.encription; + +public class TPDU_SMS_SUBMIT { + // message type + int msgType; // SmsTPDUType bit 0,1 + + // reject duplicates + boolean rd; // bit 2 + + // validity period format + int vpf; // TapiNetTextVPType bits 3,4 + + // reply path + boolean rp; // bit 7 + + // user data header indication + boolean udhi; // bit 6 + + // status report request + boolean srr; // bit 5 + + /****** BODY *******/ + //message reference + int mr; + + // destination address + public SmsAddressInfo destAddr; + + // protocol identifier + char pId; + + //data coding scheme + TapiNetTextCodingScheme dcs; + + // validity period + TapiNetTextVP vp; + + // user data length + public int udl; + + // user data + public char[] userData; + + public TPDU_SMS_SUBMIT() { + dcs = new TapiNetTextCodingScheme(); + destAddr = new SmsAddressInfo(); + vp = new TapiNetTextVP(); + } +} diff --git a/ei-library/src/org/tizen/eilib/modem/encription/TapiNetTextCodingScheme.java b/ei-library/src/org/tizen/eilib/modem/encription/TapiNetTextCodingScheme.java new file mode 100644 index 0000000..adc487c --- /dev/null +++ b/ei-library/src/org/tizen/eilib/modem/encription/TapiNetTextCodingScheme.java @@ -0,0 +1,40 @@ +/* + * EventInjector Library + * + * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * SooYoung Ha + * JiHye Kim + * YeongKyoon Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + +package org.tizen.eilib.modem.encription; + +public class TapiNetTextCodingScheme { + public boolean bSMSCinSIM; /**< if SMSC is stored in SIM this is TRUE */ + public boolean bCompressed; /**< if text is compressed this is TRUE */ + public boolean bMsgClassSet; /**< message class indication. if TRUE = bits 1..0, if FALSE = reserved */ + public boolean bMsgIndActive; /**< message indication group. if TRUE = on, FALSE = off */ + public int codingGroupType; // TapiNetTextCodingGroupType + public int waitingType; // TapiNetTextWaitingType + public int alphabetType; // TapiNetTextAlphabetType + public int classType; // TapiNetTextClassType + public byte codingGroup; + public byte code; +} diff --git a/ei-library/src/org/tizen/eilib/modem/encription/TapiNetTextVP.java b/ei-library/src/org/tizen/eilib/modem/encription/TapiNetTextVP.java new file mode 100644 index 0000000..5844421 --- /dev/null +++ b/ei-library/src/org/tizen/eilib/modem/encription/TapiNetTextVP.java @@ -0,0 +1,33 @@ +/* + * EventInjector Library + * + * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * SooYoung Ha + * JiHye Kim + * YeongKyoon Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + +package org.tizen.eilib.modem.encription; + +public class TapiNetTextVP { + int vpType; // TapiNetTextVPType + int vpRelativeType; // TapiNetVPRelValue + long vpValue; // UINT32 +} diff --git a/ei-library/src/org/tizen/eilib/modem/encription/TmDateTime.java b/ei-library/src/org/tizen/eilib/modem/encription/TmDateTime.java new file mode 100644 index 0000000..b233c2a --- /dev/null +++ b/ei-library/src/org/tizen/eilib/modem/encription/TmDateTime.java @@ -0,0 +1,36 @@ +/* + * EventInjector Library + * + * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * SooYoung Ha + * JiHye Kim + * YeongKyoon Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + +package org.tizen.eilib.modem.encription; + +public class TmDateTime { + public int year; + public int month; + public int day; + public int hour; + public int minute; + public int second; +} diff --git a/ei-library/src/org/tizen/eilib/modem/protocol/AbstractGA.java b/ei-library/src/org/tizen/eilib/modem/protocol/AbstractGA.java new file mode 100644 index 0000000..0635680 --- /dev/null +++ b/ei-library/src/org/tizen/eilib/modem/protocol/AbstractGA.java @@ -0,0 +1,213 @@ +/* + * EventInjector Library + * + * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * SooYoung Ha + * JiHye Kim + * YeongKyoon Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + +package org.tizen.eilib.modem.protocol; + +import java.nio.ByteBuffer; + +import org.tizen.eilib.connection.message.EventMessage; + + +abstract public class AbstractGA { + + private static final int SINGLE_ROW_INDEX = 0; + + private int groupId; + private int actionId; + private int length = 0; + private StructureGA header; + private StructureGA body; + + public AbstractGA(int groupId, int actionId) { + this.groupId = groupId; + this.actionId = actionId; + } + + abstract protected void makeBody(); + + abstract protected void makeHeader(); + + public void intialize() { + header = new StructureGA(); + makeHeader(); + body = new StructureGA(); + makeBody(); + } + + public void intialize(ByteBuffer packet) { + AbstractItem item = null; + length = packet.position(); + if (length == 0) { + intialize(); + return; + } + + packet.clear(); + + header = new StructureGA(); + makeHeader(); + for (int j = 0; j < header.getItemCount(); j++) { + item = header.getItem(j); + putBufferToItem(item, SINGLE_ROW_INDEX, packet); + } + + body = new StructureGA(); + makeBody(); + + int loopCount = getLoopCount(); + body.setLoopCount(loopCount); + + for (int i = 0; i < loopCount; i++) { + for (int j = 0; j < body.getItemCount(); j++) { + item = body.getItem(j); + putBufferToItem(item, i, packet); + } + } + } + + private int getLoopCount() { + return (int) Math.ceil((double) (length - header.getByteLength()) + / body.getByteLength()); + } + + public void makeStarterPacket(EventMessage message) { + int byteLength = (short)getSendLength(); + + ByteBuffer buffer = message.getHeaderBuffer(); + buffer.clear(); + buffer.putShort((short)byteLength); + buffer.put(((Integer) groupId).byteValue()); + buffer.put(((Integer) actionId).byteValue()); + } + + public void makePacket(EventMessage message) { + ByteBuffer buffer = message.getDataBuffer(); + buffer.clear(); + + AbstractItem item = null; + for (int j = 0; j < header.getItemCount(); j++) { + item = header.getItem(j); + putItemToBuffer(item, SINGLE_ROW_INDEX, buffer); + } + + for (int i = 0; i < body.getLoopCount(); i++) { + for (int j = 0; j < body.getItemCount(); j++) { + item = body.getItem(j); + putItemToBuffer(item, i, buffer); + } + } + } + + private void putItemToBuffer(AbstractItem item, int idx, ByteBuffer buffer) { + ItemType type = item.getType(); + if (type == ItemType.BYTE) { + buffer.put(getIntValue(item, idx).byteValue()); + } else if (type == ItemType.SHORT) { + buffer.putShort(getIntValue(item, idx).shortValue()); + } else if (type == ItemType.INT) { + buffer.putInt(getIntValue(item, idx)); + } else if (type == ItemType.ByteArray) { + if (item instanceof ByteArrayItem) { + byte[] buf = ((ByteArrayItem) item).getValue(idx); + int length = item.getByteLength(); + int pos = buffer.position(); + + if (buf.length > length) { + buffer.put(buf, 0, length); + } else { + buffer.put(buf); + } + + buffer.position(pos + length); + } + } + } + + private Integer getIntValue(AbstractItem item, int idx) { + if (item instanceof IntItem) { + return ((IntItem) item).getValue(idx); + } else { + return null; + } + } + + private void putBufferToItem(AbstractItem item, int idx, ByteBuffer buffer) { + ItemType type = item.getType(); + if (type == ItemType.BYTE) { + if (item instanceof IntItem) { + ((IntItem) item).setValue(idx, buffer.get() & 0xff); + } + } else if (type == ItemType.SHORT) { + if (item instanceof IntItem) { + ((IntItem) item).setValue(idx, buffer.getShort()); + } + } else if (type == ItemType.INT) { + if (item instanceof IntItem) { + ((IntItem) item).setValue(idx, buffer.getInt()); + } + } else if (type == ItemType.ByteArray) { + int length = item.getByteLength(); + int remain = buffer.remaining(); + + byte[] buf = null; + if (length > remain) { + buf = new byte[remain]; + } else { + if(item.getName() == "CALL_NUMBER") { + buf = new byte[remain]; + } else { + buf = new byte[length]; + } + } + + buffer.get(buf, 0, buf.length); + if (item instanceof ByteArrayItem) { + ((ByteArrayItem) item).setValue(idx, buf); + } + } + } + + public String getKey() { + return StringUtil.makeKey(groupId, actionId); + } + + public int getSendLength() { + return header.getByteLength() + body.getByteLength() + * body.getLoopCount(); + } + + public int getReceiveLength() { + return this.length; + } + + public StructureGA getBody() { + return body; + } + + public StructureGA getHeader() { + return header; + } +} diff --git a/ei-library/src/org/tizen/eilib/modem/protocol/AbstractItem.java b/ei-library/src/org/tizen/eilib/modem/protocol/AbstractItem.java new file mode 100644 index 0000000..dbbd7e2 --- /dev/null +++ b/ei-library/src/org/tizen/eilib/modem/protocol/AbstractItem.java @@ -0,0 +1,53 @@ +/* + * EventInjector Library + * + * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * SooYoung Ha + * JiHye Kim + * YeongKyoon Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ +package org.tizen.eilib.modem.protocol; + +public class AbstractItem { + private ItemType type; + private int length; + private String name; + + + public AbstractItem(ItemType type, String name, int length){ +// if(this.type!=ItemType.CHAR) +// throw new InvalidTypeException("CHAR type should be created by the constructor, IntItem(ItemType type, String name, int length)"); + this.type = type; + this.name = name; + this.length = length; + } + + public ItemType getType() { + return type; + } + + public int getByteLength() { + return length; + } + + public String getName() { + return name; + } +} diff --git a/ei-library/src/org/tizen/eilib/modem/protocol/ByteArrayItem.java b/ei-library/src/org/tizen/eilib/modem/protocol/ByteArrayItem.java new file mode 100644 index 0000000..bd3a556 --- /dev/null +++ b/ei-library/src/org/tizen/eilib/modem/protocol/ByteArrayItem.java @@ -0,0 +1,46 @@ +/* + * EventInjector Library + * + * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * SooYoung Ha + * JiHye Kim + * YeongKyoon Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + +package org.tizen.eilib.modem.protocol; + +import java.util.ArrayList; + +public class ByteArrayItem extends AbstractItem { + private ArrayList value; + + public ByteArrayItem(ItemType type, String name, int length) { + super(type, name, length); + this.value = new ArrayList(); + } + + public void setValue(int idx, byte[] value) { + this.value.add(value); + } + + public byte[] getValue(int idx) { + return this.value.get(idx); + } +} diff --git a/ei-library/src/org/tizen/eilib/modem/protocol/ByteUtil.java b/ei-library/src/org/tizen/eilib/modem/protocol/ByteUtil.java new file mode 100644 index 0000000..657e8c5 --- /dev/null +++ b/ei-library/src/org/tizen/eilib/modem/protocol/ByteUtil.java @@ -0,0 +1,140 @@ +/* + * EventInjector Library + * + * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * SooYoung Ha + * JiHye Kim + * YeongKyoon Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + +package org.tizen.eilib.modem.protocol; + +import java.nio.ByteBuffer; +import java.nio.ByteOrder; + +public class ByteUtil { + private static final ByteOrder BYTE_ORDER = ByteOrder.LITTLE_ENDIAN; + public static final int BYTE_LENGTH = 1; + public static final int SHORT_LENGTH = 2; + public static final int INT_LENGTH = 4; + + public static ByteBuffer getByteBuffer(byte[] buf) { + ByteBuffer byteBuffer = ByteBuffer.allocate(buf.length); + byteBuffer.order(BYTE_ORDER); + byteBuffer.put(buf); + byteBuffer.rewind(); + + return byteBuffer; + } + + public static ByteBuffer getByteBuffer(int length) { + ByteBuffer byteBuffer = ByteBuffer.allocate(length); + byteBuffer.order(BYTE_ORDER); + + return byteBuffer; + } + + public static byte[] short2byte(short s) { + byte dest[] = new byte[2]; + dest[1] = (byte) (s & 0xff); + dest[0] = (byte) (s >>> 8 & 0xff); + return dest; + } + + public static byte[] int2byte(int i) { + byte dest[] = new byte[4]; + dest[3] = (byte) (i & 0xff); + dest[2] = (byte) (i >>> 8 & 0xff); + dest[1] = (byte) (i >>> 16 & 0xff); + dest[0] = (byte) (i >>> 24 & 0xff); + return dest; + } + + public static byte[] long2byte(long l) { + byte dest[] = new byte[8]; + dest[7] = (byte) (int) (l & 255L); + dest[6] = (byte) (int) (l >>> 8 & 255L); + dest[5] = (byte) (int) (l >>> 16 & 255L); + dest[4] = (byte) (int) (l >>> 24 & 255L); + dest[3] = (byte) (int) (l >>> 32 & 255L); + dest[2] = (byte) (int) (l >>> 40 & 255L); + dest[1] = (byte) (int) (l >>> 48 & 255L); + dest[0] = (byte) (int) (l >>> 56 & 255L); + return dest; + } + + public static short byte2short(byte src[]) { + return (short) ((src[0] & 0xff) << 8 | src[1] & 0xff); + } + + public static int byte2int(byte src[]) { + return (src[0] & 0xff) << 24 | (src[1] & 0xff) << 16 + | (src[2] & 0xff) << 8 | src[3] & 0xff; + } + + public static int byte2int(byte src[], int offset) { + return (src[offset] & 0xff) << 24 | (src[offset + 1] & 0xff) << 16 + | (src[offset + 2] & 0xff) << 8 | src[offset + 3] & 0xff; + } + + public static long byte2long(byte src[]) { + return (long) byte2int(src) << 32 | (long) byte2int(src, 4) + & 0xffffffffL; + } + + public static String byte2hex(byte[] src) { + if (src == null) { + return null; + } + + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < src.length; i++) { + sb.append(Integer.toHexString(src[i] & 0xff)); + } + return sb.toString(); + } + + public static byte[] hex2byte(String src) { + if (src == null) { + return null; + } + + if (src.length() % 2 != 0) { + src = "0" + src; //$NON-NLS-1$ + } + + byte[] result = new byte[src.length() / 2]; + for (int i = 0; i < result.length; i++) { + result[i] = (byte) Integer.parseInt( + src.substring(2 * i, 2 * i + 2), 16); + } + return result; + } + + // will be removed + /* + public static void printHex(byte[] buf, String flag) { + System.out.print("\n### " + flag + " : "); //$NON-NLS-1$ //$NON-NLS-2$ + for (int i = 0; i < buf.length; i++) { + System.out.format("%02X ", buf[i]); //$NON-NLS-1$ + } + } + */ +} diff --git a/ei-library/src/org/tizen/eilib/modem/protocol/G01A07.java b/ei-library/src/org/tizen/eilib/modem/protocol/G01A07.java new file mode 100644 index 0000000..574eb8e --- /dev/null +++ b/ei-library/src/org/tizen/eilib/modem/protocol/G01A07.java @@ -0,0 +1,45 @@ +/* + * EventInjector Library + * + * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * SooYoung Ha + * JiHye Kim + * YeongKyoon Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + +package org.tizen.eilib.modem.protocol; + +public class G01A07 extends AbstractGA{ + + public G01A07(){ + super(0x01, 0x07); + } + + @Override + protected void makeBody() { + StructureGA ga = getBody(); + ga.addByteItem("ERROR_CAUSE_0"); + ga.addByteItem("ERROR_CAUSE_1"); + } + + @Override + protected void makeHeader() { + } +} diff --git a/ei-library/src/org/tizen/eilib/modem/protocol/G01A21MO.java b/ei-library/src/org/tizen/eilib/modem/protocol/G01A21MO.java new file mode 100644 index 0000000..0e31b4b --- /dev/null +++ b/ei-library/src/org/tizen/eilib/modem/protocol/G01A21MO.java @@ -0,0 +1,48 @@ +/* + * EventInjector Library + * + * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * SooYoung Ha + * JiHye Kim + * YeongKyoon Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + +package org.tizen.eilib.modem.protocol; + +public class G01A21MO extends AbstractGA{ + + public G01A21MO(){ + super(0x01, 0x21); + } + + @Override + protected void makeBody() { + StructureGA ga = getBody(); + ga.addByteItem("CALL_ID"); + ga.addByteItem("CALL_TYPE"); + ga.addByteItem("LEN"); + ga.addByteArrayItem("CALL_NUMBER", 10); + } + + @Override + protected void makeHeader() { + + } +} diff --git a/ei-library/src/org/tizen/eilib/modem/protocol/G01A21MT.java b/ei-library/src/org/tizen/eilib/modem/protocol/G01A21MT.java new file mode 100644 index 0000000..fc65a81 --- /dev/null +++ b/ei-library/src/org/tizen/eilib/modem/protocol/G01A21MT.java @@ -0,0 +1,51 @@ +/* + * EventInjector Library + * + * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * SooYoung Ha + * JiHye Kim + * YeongKyoon Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + +package org.tizen.eilib.modem.protocol; + +public class G01A21MT extends AbstractGA{ + + public G01A21MT(){ + super(0x01, 0x21); + } + + @Override + protected void makeBody() { + StructureGA ga = getBody(); + ga.addByteItem("CALL_TYPE"); + ga.addByteItem("FORWARDED_STATUS"); + ga.addByteItem("CLIR_STATUS"); + ga.addByteItem("NUM_LEN"); + ga.addByteItem("NUM_TYPE"); + ga.addByteItem("CLI_PRESENT_ID"); + ga.addByteItem("NO_CLI_CAUSE"); + ga.addByteArrayItem("CALL_NUMBER", 45); + } + + @Override + protected void makeHeader() { + } +} diff --git a/ei-library/src/org/tizen/eilib/modem/protocol/G01A22.java b/ei-library/src/org/tizen/eilib/modem/protocol/G01A22.java new file mode 100644 index 0000000..55706a1 --- /dev/null +++ b/ei-library/src/org/tizen/eilib/modem/protocol/G01A22.java @@ -0,0 +1,56 @@ +/* + * EventInjector Library + * + * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * SooYoung Ha + * JiHye Kim + * YeongKyoon Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + +package org.tizen.eilib.modem.protocol; + +public class G01A22 extends AbstractGA{ + + public G01A22(){ + super(0x01, 0x22); + } + + @Override + protected void makeBody() { + StructureGA ga = getBody(); + ga.addIntItem("IDX"); + ga.addIntItem("DIR"); + ga.addIntItem("STAT"); + ga.addIntItem("CALL_TYPE"); + ga.addByteItem("MULTIPARTY"); + ga.addByteArrayItem("NUMBER", 32); + ga.addByteArrayItem("dummy", 3); + ga.addIntItem("TYPE"); + ga.addIntItem("NUM_LEN"); + ga.addIntItem("NUM_OF_TYPE"); + ga.addByteArrayItem("ALPHA",32); + } + + @Override + protected void makeHeader() { + StructureGA ga = getHeader(); + ga.addIntItem("COUNT"); + } +} diff --git a/ei-library/src/org/tizen/eilib/modem/protocol/G01A22End.java b/ei-library/src/org/tizen/eilib/modem/protocol/G01A22End.java new file mode 100644 index 0000000..a248c44 --- /dev/null +++ b/ei-library/src/org/tizen/eilib/modem/protocol/G01A22End.java @@ -0,0 +1,44 @@ +/* + * EventInjector Library + * + * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * SooYoung Ha + * JiHye Kim + * YeongKyoon Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + +package org.tizen.eilib.modem.protocol; + +public class G01A22End extends AbstractGA{ + + public G01A22End(){ + super(0x01, 0x22); + } + + @Override + protected void makeBody() { + StructureGA ga = getBody(); + ga.addByteItem("CALL_ID"); + } + + @Override + protected void makeHeader() { + } +} diff --git a/ei-library/src/org/tizen/eilib/modem/protocol/G01A23.java b/ei-library/src/org/tizen/eilib/modem/protocol/G01A23.java new file mode 100644 index 0000000..efc0b33 --- /dev/null +++ b/ei-library/src/org/tizen/eilib/modem/protocol/G01A23.java @@ -0,0 +1,42 @@ +/* + * EventInjector Library + * + * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * SooYoung Ha + * JiHye Kim + * YeongKyoon Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + +package org.tizen.eilib.modem.protocol; + +public class G01A23 extends AbstractGA{ + + public G01A23(){ + super(0x01, 0x23); + } + + @Override + protected void makeBody() { + } + + @Override + protected void makeHeader() { + } +} diff --git a/ei-library/src/org/tizen/eilib/modem/protocol/G01A26.java b/ei-library/src/org/tizen/eilib/modem/protocol/G01A26.java new file mode 100644 index 0000000..39f86e7 --- /dev/null +++ b/ei-library/src/org/tizen/eilib/modem/protocol/G01A26.java @@ -0,0 +1,56 @@ +/* + * EventInjector Library + * + * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * SooYoung Ha + * JiHye Kim + * YeongKyoon Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + +package org.tizen.eilib.modem.protocol; + +public class G01A26 extends AbstractGA{ + + public G01A26(){ + super(0x01, 0x26); + } + + @Override + protected void makeBody() { + StructureGA ga = getBody(); + ga.addIntItem("IDX"); + ga.addIntItem("DIR"); + ga.addIntItem("STAT"); + ga.addIntItem("CALL_TYPE"); + ga.addByteItem("MULTIPARTY"); + ga.addByteArrayItem("NUMBER", 32); + ga.addByteArrayItem("dummy", 3); + ga.addIntItem("TYPE"); + ga.addIntItem("NUM_LEN"); + ga.addIntItem("NUM_OF_TYPE"); + ga.addByteArrayItem("ALPHA",32); + } + + @Override + protected void makeHeader() { + StructureGA ga = getHeader(); + ga.addIntItem("COUNT"); + } +} diff --git a/ei-library/src/org/tizen/eilib/modem/protocol/G01A29.java b/ei-library/src/org/tizen/eilib/modem/protocol/G01A29.java new file mode 100644 index 0000000..1c553db --- /dev/null +++ b/ei-library/src/org/tizen/eilib/modem/protocol/G01A29.java @@ -0,0 +1,57 @@ +/* + * EventInjector Library + * + * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * SooYoung Ha + * JiHye Kim + * YeongKyoon Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + +package org.tizen.eilib.modem.protocol; + +public class G01A29 extends AbstractGA{ + + public G01A29(){ + super(0x01, 0x29); + } + + @Override + protected void makeBody() { + StructureGA ga = getBody(); + ga.addIntItem("IDX"); + ga.addIntItem("DIR"); + ga.addIntItem("STAT"); + ga.addIntItem("CALL_TYPE"); + ga.addByteItem("MULTIPARTY"); + ga.addByteArrayItem("NUMBER", 32); + ga.addByteArrayItem("dummy", 3); + ga.addIntItem("TYPE"); + ga.addIntItem("NUM_LEN"); + ga.addIntItem("NUM_OF_TYPE"); + ga.addByteArrayItem("ALPHA",32); + } + + @Override + protected void makeHeader() { + StructureGA ga = getHeader(); + ga.addIntItem("COUNT"); + } + +} diff --git a/ei-library/src/org/tizen/eilib/modem/protocol/G01A62.java b/ei-library/src/org/tizen/eilib/modem/protocol/G01A62.java new file mode 100644 index 0000000..a344936 --- /dev/null +++ b/ei-library/src/org/tizen/eilib/modem/protocol/G01A62.java @@ -0,0 +1,42 @@ +/* + * EventInjector Library + * + * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * SooYoung Ha + * JiHye Kim + * YeongKyoon Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + +package org.tizen.eilib.modem.protocol; + +public class G01A62 extends AbstractGA{ + + public G01A62(){ + super(0x01, 0x62); + } + + @Override + protected void makeBody() { + } + + @Override + protected void makeHeader() { + } +} diff --git a/ei-library/src/org/tizen/eilib/modem/protocol/G02A31.java b/ei-library/src/org/tizen/eilib/modem/protocol/G02A31.java new file mode 100644 index 0000000..9a73809 --- /dev/null +++ b/ei-library/src/org/tizen/eilib/modem/protocol/G02A31.java @@ -0,0 +1,54 @@ +/* + * EventInjector Library + * + * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * SooYoung Ha + * JiHye Kim + * YeongKyoon Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + +package org.tizen.eilib.modem.protocol; + +public class G02A31 extends AbstractGA{ + + public G02A31(){ + super(0x02, 0x31); + } + + @Override + protected void makeBody() { + StructureGA ga = getBody(); + ga.addByteItem("NET_ACT_TYPE"); + ga.addByteItem("NET_SVC_DOMAIN"); + ga.addByteItem("NET_REG_STATUS"); + ga.addByteItem("NET_EDGE_SUPPORT"); + ga.addByteItem("LAC0"); + ga.addByteItem("LAC1"); + ga.addByteItem("CELL_ID0"); + ga.addByteItem("CELL_ID1"); + ga.addByteItem("CELL_ID2"); + ga.addByteItem("CELL_ID3"); + ga.addByteItem("REJ_CAUSE"); + } + + @Override + protected void makeHeader() { + } +} diff --git a/ei-library/src/org/tizen/eilib/modem/protocol/G04A01.java b/ei-library/src/org/tizen/eilib/modem/protocol/G04A01.java new file mode 100644 index 0000000..659afbe --- /dev/null +++ b/ei-library/src/org/tizen/eilib/modem/protocol/G04A01.java @@ -0,0 +1,44 @@ +/* + * EventInjector Library + * + * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * SooYoung Ha + * JiHye Kim + * YeongKyoon Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + +package org.tizen.eilib.modem.protocol; + +public class G04A01 extends AbstractGA{ + + public G04A01(){ + super(0x04, 0x01); + } + + @Override + protected void makeBody() { + StructureGA ga = getBody(); + ga.addByteArrayItem("DATA",500); //$NON-NLS-1$ + } + + @Override + protected void makeHeader() { + } +} diff --git a/ei-library/src/org/tizen/eilib/modem/protocol/G04A05.java b/ei-library/src/org/tizen/eilib/modem/protocol/G04A05.java new file mode 100644 index 0000000..6c85b41 --- /dev/null +++ b/ei-library/src/org/tizen/eilib/modem/protocol/G04A05.java @@ -0,0 +1,44 @@ +/* + * EventInjector Library + * + * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * SooYoung Ha + * JiHye Kim + * YeongKyoon Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + +package org.tizen.eilib.modem.protocol; + +public class G04A05 extends AbstractGA{ + public G04A05(){ + super(0x04, 0x05); + } + + @Override + protected void makeBody() { + StructureGA ga = getBody(); + ga.addByteItem("DATA1"); //$NON-NLS-1$ + ga.addByteItem("DATA2"); //$NON-NLS-1$ + } + + @Override + protected void makeHeader() { + } +} diff --git a/ei-library/src/org/tizen/eilib/modem/protocol/IntItem.java b/ei-library/src/org/tizen/eilib/modem/protocol/IntItem.java new file mode 100644 index 0000000..49d0d6a --- /dev/null +++ b/ei-library/src/org/tizen/eilib/modem/protocol/IntItem.java @@ -0,0 +1,46 @@ +/* + * EventInjector Library + * + * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * SooYoung Ha + * JiHye Kim + * YeongKyoon Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + +package org.tizen.eilib.modem.protocol; + +import java.util.ArrayList; + +public class IntItem extends AbstractItem { + private ArrayList value; + + public IntItem(ItemType type, String name, int length) { + super(type, name, length); + this.value = new ArrayList(); + } + + public void setValue(int idx, int value) { + this.value.add(value); + } + + public int getValue(int idx) { + return this.value.get(idx); + } +} diff --git a/ei-library/src/org/tizen/eilib/modem/protocol/ItemType.java b/ei-library/src/org/tizen/eilib/modem/protocol/ItemType.java new file mode 100644 index 0000000..b55f0a9 --- /dev/null +++ b/ei-library/src/org/tizen/eilib/modem/protocol/ItemType.java @@ -0,0 +1,31 @@ +/* + * EventInjector Library + * + * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * SooYoung Ha + * JiHye Kim + * YeongKyoon Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + +package org.tizen.eilib.modem.protocol; + +public enum ItemType { + BYTE, SHORT, INT, ByteArray +} diff --git a/ei-library/src/org/tizen/eilib/modem/protocol/StringUtil.java b/ei-library/src/org/tizen/eilib/modem/protocol/StringUtil.java new file mode 100644 index 0000000..adc6637 --- /dev/null +++ b/ei-library/src/org/tizen/eilib/modem/protocol/StringUtil.java @@ -0,0 +1,59 @@ +/* + * EventInjector Library + * + * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * SooYoung Ha + * JiHye Kim + * YeongKyoon Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + +package org.tizen.eilib.modem.protocol; + +public class StringUtil { + public static String lpad(String strSource, int totalLength, String pad) { + if(totalLength <= strSource.length()) { + return strSource; + } + + StringBuilder sb = new StringBuilder(strSource); + for (int i = 0; i < totalLength-sb.length(); i++) { + sb.insert(0, pad); + } + + return sb.toString(); + } + + public static String rpad(String strSource, int totalLength, String pad) { + if(totalLength <= strSource.length()) { + return strSource; + } + + StringBuilder sb = new StringBuilder(strSource); + for (int i = 0; i < totalLength-sb.length(); i++) { + sb.append(pad); + } + + return sb.toString(); + } + + public static String makeKey(int groupId, int actionId) { + return groupId + ":" + actionId; //$NON-NLS-1$ + } +} diff --git a/ei-library/src/org/tizen/eilib/modem/protocol/StructureGA.java b/ei-library/src/org/tizen/eilib/modem/protocol/StructureGA.java new file mode 100644 index 0000000..a078707 --- /dev/null +++ b/ei-library/src/org/tizen/eilib/modem/protocol/StructureGA.java @@ -0,0 +1,154 @@ +/* + * EventInjector Library + * + * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * SooYoung Ha + * JiHye Kim + * YeongKyoon Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + +package org.tizen.eilib.modem.protocol; + +import java.util.ArrayList; + + + +public class StructureGA { + + public static final int SINGLE_ROW_INDEX = 0; + + private int loopCount = 1; + private ArrayList list; + + public StructureGA(){ + list = new ArrayList(); + } + + public void addShortItem(String name) { + list.add(new IntItem(ItemType.SHORT, name, ByteUtil.SHORT_LENGTH)); + } + + public void addByteItem(String name) { + list.add(new IntItem(ItemType.BYTE, name, ByteUtil.BYTE_LENGTH)); + } + + public void addIntItem(String name) { + list.add(new IntItem(ItemType.INT, name, ByteUtil.INT_LENGTH)); + } + + public void addByteArrayItem(String name, int length) { + list.add(new ByteArrayItem(ItemType.ByteArray, name, length)); + } + + public int getByteLength(){ + int sum = 0; + for(int i=0; i + * JiHye Kim + * YeongKyoon Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + +package org.tizen.eilib.tools; + +import java.io.File; +import java.io.IOException; +import java.util.Calendar; +import java.util.logging.FileHandler; +import java.util.logging.Formatter; +import java.util.logging.Handler; +import java.util.logging.Level; +import java.util.logging.LogRecord; +import java.util.logging.Logger; + +/** + * This class is event injector logger class. + *

          + * This class is need initialization using initLogger or + * intiFileLogger. + *

          + */ +public class EILogger { + private static Logger logger = null; + + /** + * Return logger instance. + * logger instance is created using initLogger, initFileLgger + */ + public static Logger getLogger() { + if (logger == null) { + initLogger("Event Injector", Level.OFF); + /* + File log = new File("eilib.log"); + try { + log.createNewFile(); + } catch (IOException e) { + initLogger("Event Injector", Level.OFF); + return logger; + } + initFileLogger(new File("eilib.log"), "Event Injector", Level.WARNING, false); + */ + } + return logger; + } + + /** + * Initialize Logger instance. + * + * @param name logger name + * @param level logger level + * + */ + public static void initLogger(String name, Level level) { + logger = Logger.getLogger(name); + logger.setLevel(level); + + Handler[] logHandlers = logger.getParent().getHandlers(); + + for (Handler handler : logHandlers) { + handler.setFormatter(new ConsoleLoggerFormatter()); + } + } + + /** + * Initialize Logger instance. + * + * @param logFile log file + * @param name logger name + * @param level logger level + * @param onConsoleLog if this value is true, print console log, otherwise does not print console log. + * + * @exception SecurityException

            + * @exception IOException
              + */ + public static void initFileLogger(File logFile, String name, Level level, boolean onConsoleLog) { + initLogger(name, level); + + logger.setUseParentHandlers(onConsoleLog); + + Handler logFileHandler = null; + try { + logFileHandler = new FileHandler(logFile.getAbsolutePath()); + } catch (SecurityException e) { + e.printStackTrace(); + return; + } catch (IOException e) { + e.printStackTrace(); + return; + } + + logFileHandler.setLevel(level); + logFileHandler.setFormatter(new FileLoggerFormatter()); + logger.addHandler(logFileHandler); + } +} + +class FileLoggerFormatter extends Formatter { + public String format(LogRecord record) { + StringBuffer sb = new StringBuffer(); + Calendar cal = Calendar.getInstance(); + cal.setTimeInMillis(record.getMillis()); + + // [YYYY.MM.DD HH:MM:SS][LEVEL][CLASS.METHOD] MESSAGE + sb.append('['); + sb.append(cal.get(Calendar.YEAR)); + sb.append('.'); + sb.append(cal.get(Calendar.MONTH)); + sb.append('.'); + sb.append(cal.get(Calendar.DAY_OF_MONTH)); + sb.append(' '); + sb.append(cal.get(Calendar.HOUR_OF_DAY)); + sb.append(':'); + sb.append(cal.get(Calendar.MINUTE)); + sb.append(':'); + sb.append(cal.get(Calendar.SECOND)); + sb.append(']'); + sb.append('['); + sb.append(record.getLevel()); + sb.append(']'); + sb.append('['); + sb.append(record.getSourceClassName().substring(record.getSourceClassName().lastIndexOf(".") + 1)); + sb.append('.'); + sb.append(record.getSourceMethodName()); + sb.append("] "); + sb.append(record.getMessage()); + + // in case when called Logger.throwing() + Throwable t = record.getThrown(); + if (t != null) { + StackTraceElement[] stacks = t.getStackTrace(); + sb.append('\n'); + sb.append(t.toString()); + for (int i = 0; i < stacks.length; i++) { + sb.append('\n'); + sb.append(stacks[i].toString()); + } + } + sb.append('\n'); + return sb.toString(); + } +} + +class ConsoleLoggerFormatter extends Formatter { + public String format(LogRecord record) { + StringBuffer sb = new StringBuffer(); + + // [LEVEL][CLASS.METHOD] MESSAGE + sb.append('['); + sb.append(record.getLevel()); + sb.append(']'); + sb.append('['); + sb.append(record.getSourceClassName().substring(record.getSourceClassName().lastIndexOf(".") + 1)); + sb.append('.'); + sb.append(record.getSourceMethodName()); + sb.append("] "); + sb.append(record.getMessage()); + + // in case when called Logger.throwing() + Throwable t = record.getThrown(); + if (t != null) { + StackTraceElement[] stacks = t.getStackTrace(); + sb.append('\n'); + sb.append(t.toString()); + for (int i = 0; i < stacks.length; i++) { + sb.append('\n'); + sb.append(stacks[i].toString()); + } + } + sb.append('\n'); + return sb.toString(); + } +} \ No newline at end of file diff --git a/eventinjector-cli/.classpath b/eventinjector-cli/.classpath new file mode 100644 index 0000000..af3ce1e --- /dev/null +++ b/eventinjector-cli/.classpath @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/eventinjector-cli/.project b/eventinjector-cli/.project new file mode 100644 index 0000000..f605fd8 --- /dev/null +++ b/eventinjector-cli/.project @@ -0,0 +1,17 @@ + + + EventInjectorCLI + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/eventinjector-cli/.settings/org.eclipse.jdt.core.prefs b/eventinjector-cli/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..8cf4b08 --- /dev/null +++ b/eventinjector-cli/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,12 @@ +#Mon Oct 22 17:57:04 KST 2012 +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.6 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.6 diff --git a/eventinjector-cli/build.xml b/eventinjector-cli/build.xml new file mode 100644 index 0000000..e40772f --- /dev/null +++ b/eventinjector-cli/build.xml @@ -0,0 +1,63 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/eventinjector-cli/src/org/tizen/injector/DeviceList.java b/eventinjector-cli/src/org/tizen/injector/DeviceList.java new file mode 100644 index 0000000..ff77806 --- /dev/null +++ b/eventinjector-cli/src/org/tizen/injector/DeviceList.java @@ -0,0 +1,90 @@ +/* + * EventInjector CLI Program + * + * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * SooYoung Ha + * JiHye Kim + * YeongKyoon Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + +package org.tizen.injector; + +import java.util.ArrayList; + +import org.tizen.injector.device.Device; +import org.tizen.injector.device.EmulatorDevice; +import org.tizen.injector.device.ExitDevice; +import org.tizen.injector.device.HelpDevice; +import org.tizen.injector.device.Record; +import org.tizen.injector.device.device.Battery; +import org.tizen.injector.device.device.EarJack; +import org.tizen.injector.device.device.RSSI; +import org.tizen.injector.device.device.SDCard; +import org.tizen.injector.device.device.USBDevice; +import org.tizen.injector.device.location.Location; +import org.tizen.injector.device.modem.Call; +import org.tizen.injector.device.modem.SMS; +import org.tizen.injector.device.nfc.Nfc; +import org.tizen.injector.device.sensor.Motion; +import org.tizen.injector.device.sensor.Sensor; + +public class DeviceList { + private ArrayList deviceList = new ArrayList(); + private Nfc nfc = new Nfc(); + public DeviceList() { + initDefalutDeviceList(); + } + + private void initDefalutDeviceList() { + deviceList.add(new Sensor()); + deviceList.add(new Motion()); + deviceList.add(new Battery()); + deviceList.add(new EarJack()); + deviceList.add(new USBDevice()); + deviceList.add(new RSSI()); + deviceList.add(new SDCard()); + deviceList.add(new Location()); + deviceList.add(new SMS()); + deviceList.add(new Call()); + deviceList.add(nfc); + } + + public Device findDevice(String name) { + for(Device d : deviceList) { + if (d.getName().equals(name)) { + return d; + } + } + return null; + } + + public ArrayList getDeviceList() { + return deviceList; + } + + public void startSession() { + nfc.initSessionMode(); + // add emulator, help, exit + deviceList.add(new Record(EventInjector.getInstance().getRecorder())); + deviceList.add(new EmulatorDevice()); + deviceList.add(new HelpDevice()); + deviceList.add(new ExitDevice()); + } +} diff --git a/eventinjector-cli/src/org/tizen/injector/EventInjector.java b/eventinjector-cli/src/org/tizen/injector/EventInjector.java new file mode 100644 index 0000000..981adaa --- /dev/null +++ b/eventinjector-cli/src/org/tizen/injector/EventInjector.java @@ -0,0 +1,343 @@ +/* + * EventInjector CLI Program + * + * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * SooYoung Ha + * JiHye Kim + * YeongKyoon Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + +package org.tizen.injector; + +import java.io.IOException; +import java.util.LinkedList; +import java.util.List; + +import jline.ArgumentCompletor; +import jline.ArgumentCompletor.AbstractArgumentDelimiter; +import jline.Completor; +import jline.ConsoleReader; +import jline.NullCompletor; + +import org.tizen.eilib.connection.ConnectionToEmulator; +import org.tizen.eilib.connection.Emulator; +import org.tizen.eilib.connection.IEmulatorChangeListener; +import org.tizen.eilib.events.EventInjectorCreator; +import org.tizen.eilib.exception.ConnectionException; +import org.tizen.eilib.exception.EILibError; +import org.tizen.eilib.exception.InjectorLibraryException; +import org.tizen.injector.device.Command; +import org.tizen.injector.device.Device; +import org.tizen.injector.exception.ConsoleException; +import org.tizen.injector.parser.ArgCompletor; +import org.tizen.injector.parser.Args; +import org.tizen.injector.parser.CommandCompletor; +import org.tizen.injector.parser.CommandParser; +import org.tizen.injector.parser.DeviceCompletor; +import org.tizen.injector.parser.HelpMessage; + +public class EventInjector { + private static ConnectionToEmulator connector = null; + private static EventInjectorCreator creator = null; + private static Emulator currentEmulator = null; + + private static CommandParser parser = null; + private GlobalOption options = null; + private DeviceList deviceList = null; + private Args argsList = null; + + private static boolean isSession = false; + + private static EventInjector injector = null; + public static EventInjector getInstance() { + return injector; + } + + private EventInjector() { + options = new GlobalOption(); + deviceList = new DeviceList(); + parser = new CommandParser(this); + HelpMessage.setting(options, deviceList); + } + + public static void main(String[] args) { + + + try { + connector = new ConnectionToEmulator(); + creator = new EventInjectorCreator(connector); + + connector.addDeviceChangeListener(new MonitorEmulator()); + + injector = new EventInjector(); + + // global option + injector.argsList = new Args(args); + injector.argsList = parser.parseOptions(injector.argsList); + + if (parser.isHasOptions()) { + parser.getOptions().process(); + } + + if (!parser.isHasOptions() || + (parser.isHasOptions() && parser.getOptions().isHasSessionOption())) { + if (injector.argsList != null) { + injector.OnceSession(); + } else { + injector.Session(); + } + } + + } catch (ConsoleException ce) { + //System.out.println("Error:" + ce.getMessage()); + exitEventInjector(ce.getErrorNumber()); + } catch (InjectorLibraryException ie) { + System.out.println("Error:" + ie.getMessage()); + if (ie.getError() == EILibError.EmulatorNotOne) { + System.out.println("Use --connect | -c option to select emulator."); + } + exitEventInjector(ie.getErrorNumber()); + } catch (Throwable t) { + System.out.println("Error:" + t.getMessage()); + exitEventInjector(1); + } + + exitEventInjector(0); + } + + /** + * + * @param args + * @return error number (exit value) + */ + public int process(Args args) { + Device device = null; + try { + device = parser.parseDevice(args); + } catch (ConsoleException e) { + HelpMessage.printHelp(e, isSession); + return e.getErrorNumber(); + } + + Command command = null; + try { + command = parser.parseCommand(device, args); + } catch (ConsoleException e) { + HelpMessage.printHelp(device, e); + return e.getErrorNumber(); + } + + if (command != null) { + int re = 0; + try { + re = parser.parseArgument(command, args); + + if (re != 0) { + return re; + } + + re = command.process(); + + + } catch (ConnectionException e) { + re = e.getErrorNumber(); + } catch (ConsoleException e) { + re = e.getErrorNumber(); + } + if (re != 0) { + return re; + } + + System.out.println("OK"); + + } else { + HelpMessage.printHelp(device, null); + return 1; + } + + return 0; + } + + private void OnceSession() throws IOException, InjectorLibraryException { + try { + connector.connect(); + } catch (InjectorLibraryException e) { + if (e.getError() == EILibError.EmuldVersionOld) { + System.out.println("Error: " + e.getMessage()); + System.out.println("Some command does not work...!"); + System.out.println("Please update emulator that has emuld over " + connector.getEmuldVersion() + " version"); + } else { + throw e; + } + } + currentEmulator = connector.getCurrentEmulator(); + + int exitValue = process(argsList); + if (exitValue != 0) { + exitEventInjector(exitValue); + } + } + + private static boolean isRecordMode = false; + private static EventRecorder recorder = new EventRecorder(); + private void Session() throws ConsoleException, InjectorLibraryException, IOException { + // init + isSession = true; + deviceList.startSession(); + HelpMessage.setting(options, deviceList); + // + + try { + connector.connect(); + } catch (InjectorLibraryException e) { + if (e.getError() == EILibError.EmuldVersionOld) { + System.out.println("Error: " + e.getMessage()); + System.out.println("Some command does not work...!"); + System.out.println("Please update emulator that has emuld over " + connector.getEmuldVersion() + " version"); + } else { + throw e; + } + } + currentEmulator = connector.getCurrentEmulator(); + + System.out.println("Start event injector.."); + + ConsoleReader reader = new ConsoleReader(); + reader.setBellEnabled(false); + + List completors = new LinkedList(); + + DeviceCompletor dCompletor = new DeviceCompletor(); + completors.add(dCompletor); + CommandCompletor cCompletor = new CommandCompletor(dCompletor); + completors.add(cCompletor); + completors.add(new ArgCompletor(cCompletor, 1)); + completors.add(new ArgCompletor(cCompletor, 2)); + completors.add(new NullCompletor()); + + reader.addCompletor(new ArgumentCompletor(completors)); + + String line; + //PrintWriter out = new PrintWriter(System.out); + while ((line = reader.readLine(">> ")) != null) { + Args args = new Args(line.split(" ")); + if (process(args) == 0) { + if (isRecordMode()) { + recorder.addCommand(line); + } + } + } + } + + public static void exitEventInjector(int exitValue) { + if (connector != null) { + connector.terminate(); + } + + if (injector.isRecordMode()) { + try { + recorder.endRecord(); + } catch (ConsoleException e) { + System.out.println(e.getMessage()); + } + } + + System.exit(exitValue); + } + + public static ConnectionToEmulator getConnector() { + return connector; + } + + public static EventInjectorCreator getCreator() { + return creator; + } + + public static Emulator getCurrentEmulator() { + return currentEmulator; + } + + public static CommandParser getParser() { + return parser; + } + + public GlobalOption getOptions() { + return options; + } + + public DeviceList getDeviceList() { + return deviceList; + } + + public boolean isRecordMode() { + return isRecordMode; + } + + public void setRecordMode(boolean isRecordMode) { + EventInjector.isRecordMode = isRecordMode; + } + + public EventRecorder getRecorder() { + return recorder; + } + + public static boolean isSessionMode() { + return isSession; + } +} + +class MonitorEmulator extends IEmulatorChangeListener { + + @Override + public void deviceConnected(Emulator device) { + // empty function + } + + @Override + public void deviceDisconnected(Emulator device) { + if (EventInjector.getCurrentEmulator() != null) { + if (device.equals(EventInjector.getCurrentEmulator())) { + EventInjector.exitEventInjector(0); + } + } + } + + @Override + public void deviceChanged(Emulator device, int changeMask) { + // empty function + } + +} + +class Delimiter extends AbstractArgumentDelimiter { + + @Override + public boolean isDelimiterChar(String buffer, int pos) { + if (pos <= 0) { + return false; + } + if (buffer.charAt(pos) == ' ') { + return !isDelimiterChar(buffer, pos -1); + } + + return false; + } + +} diff --git a/eventinjector-cli/src/org/tizen/injector/EventRecorder.java b/eventinjector-cli/src/org/tizen/injector/EventRecorder.java new file mode 100644 index 0000000..4b98fa1 --- /dev/null +++ b/eventinjector-cli/src/org/tizen/injector/EventRecorder.java @@ -0,0 +1,141 @@ +/* + * EventInjector CLI Program + * + * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * SooYoung Ha + * JiHye Kim + * YeongKyoon Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ +package org.tizen.injector; + +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Date; +import java.util.Iterator; + +import org.tizen.injector.exception.ConsoleError; +import org.tizen.injector.exception.ConsoleException; + +public class EventRecorder { + private ArrayList commands = null; + private PrintWriter output = null; + private int maxSize = 1000; + + private String fileName = ""; + private String filePath = ""; + private File recordFile = null; + + private boolean isRecording = false; + public EventRecorder() { + commands = new ArrayList(); + } + + public String getFileName() { + return fileName; + } + + public void setFileName(String fileName) { + this.fileName = fileName; + } + + public String getFilePath() { + return filePath; + } + + public void setFilePath(String filePath) { + this.filePath = filePath; + } + + public boolean isRecording() { + return isRecording; + } + + public void addCommand(String command) throws ConsoleException { + if (commands.size() == maxSize) { + throw new ConsoleException(ConsoleError.FullCommandBuffer); + } + + if (!command.startsWith("record")) { + commands.add(command); + } + } + + private SimpleDateFormat dayTime = new SimpleDateFormat("yyMMdd-HHmmss"); + public String startRecord() throws ConsoleException, IOException { + if (isRecording) { + throw new ConsoleException(ConsoleError.AlreadyStartRecording); + } + + String name = ""; + if (fileName.isEmpty()) { + String str = dayTime.format(new Date(System.currentTimeMillis())); + name = "record" + str +".txt"; + } else { + name = fileName; + } + + if (filePath.isEmpty()) { + recordFile = new File(name); + } else { + recordFile = new File(filePath + File.separator + name); + } + + try { + recordFile = recordFile.getCanonicalFile(); + if(!recordFile.exists()) { + recordFile.createNewFile(); + } + this.output = new PrintWriter(new FileWriter(recordFile), true); + } catch (IOException e) { + fileName = ""; + filePath = ""; + throw e; + } + + isRecording = true; + return recordFile.getPath(); + } + + public String endRecord() throws ConsoleException { + if (!isRecording) { + throw new ConsoleException(ConsoleError.AlreadyStopRecording); + } + + if (this.output != null) { + for (Iterator i = commands.iterator(); i.hasNext(); + this.output.println(i.next())) { + ; + } + + this.output.flush(); + this.output.close(); + } + + commands.clear(); + isRecording = false; + fileName = ""; + filePath = ""; + return recordFile.getPath(); + } +} diff --git a/eventinjector-cli/src/org/tizen/injector/GlobalOption.java b/eventinjector-cli/src/org/tizen/injector/GlobalOption.java new file mode 100644 index 0000000..262a022 --- /dev/null +++ b/eventinjector-cli/src/org/tizen/injector/GlobalOption.java @@ -0,0 +1,141 @@ +/* + * EventInjector CLI Program + * + * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * SooYoung Ha + * JiHye Kim + * YeongKyoon Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + +package org.tizen.injector; + +import java.util.ArrayList; +import org.tizen.eilib.connection.Emulator; +import org.tizen.eilib.exception.EILibError; +import org.tizen.eilib.exception.InjectorLibraryException; +import org.tizen.injector.device.Option; +import org.tizen.injector.exception.ConsoleError; +import org.tizen.injector.exception.ConsoleException; +import org.tizen.injector.parser.HelpMessage; + +public class GlobalOption { + private ArrayList