<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Yet another web log &#187; Java</title>
	<atom:link href="http://blog.philippheckel.com/tag/java/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.philippheckel.com</link>
	<description>Life, Linux and other things</description>
	<lastBuildDate>Thu, 17 Mar 2011 10:04:42 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Aware Context API (ACAPI) &#8211; Using the sensors in Java ME</title>
		<link>http://blog.philippheckel.com/2010/08/22/aware-context-api-acapi-using-the-sensors-in-java-me/</link>
		<comments>http://blog.philippheckel.com/2010/08/22/aware-context-api-acapi-using-the-sensors-in-java-me/#comments</comments>
		<pubDate>Sun, 22 Aug 2010 05:43:33 +0000</pubDate>
		<dc:creator>Philipp C. Heckel</dc:creator>
				<category><![CDATA[Mobile]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Java ME]]></category>
		<category><![CDATA[Symbian]]></category>

		<guid isPermaLink="false">http://blog.philippheckel.com/?p=481</guid>
		<description><![CDATA[The capabilities of cell phones increased dramatically in the last few years. While in the old days most mobile phones were primarily used to make phone calls, modern smart-phones are mostly all-round devices. With the possibility of accessing the Internet and the availability of various sensors (e.g. location or noise), mobile applications have become interactive [...]]]></description>
			<content:encoded><![CDATA[<p>The capabilities of cell phones increased dramatically in the last few years. While in the old days most mobile phones were primarily used to make phone calls, modern smart-phones are mostly all-round devices. With the possibility of accessing the Internet and the availability of various sensors (e.g. location or noise), mobile applications have become interactive and flexible. The trend towards location-based services and context-awareness allows applications to react on their surroundings and to behave intuitively towards the user.</p>
<p>For developers, context-awareness can be both a blessing and a curse. While the mobile operating systems iPhone OS and Android come with relatively good sensor-support, the vast majority of devices deal with Java ME&#8217;s basic and heterogeneous sensor functionalities.</p>
<p>The <strong>Aware Context API (ACAPI)</strong> aims to bridge this gap by providing a framework for building context aware applications for mobile devices based on Java ME. In this article, I&#8217;d like to introduce ACAPI, its structure and usage briefly. Please feel free to comment.</p>
<p><span id="more-481"></span></p>
<hr />
<b>Contents</b></p>
<div class="toc">
<ol>
<li><a href="http://blog.philippheckel.com/2010/08/22/aware-context-api-acapi-using-the-sensors-in-java-me/#Motivation-and-Goals">1. Motivation and Goals</a></li>
<li><a href="http://blog.philippheckel.com/2010/08/22/aware-context-api-acapi-using-the-sensors-in-java-me/#Development-Team-and-Scope">2. Development Team and Scope</a></li>
<li><a href="http://blog.philippheckel.com/2010/08/22/aware-context-api-acapi-using-the-sensors-in-java-me/#Aware-Context-API-ACAPI">3. Aware Context API (ACAPI)</a>
<ol>
<li><a href="http://blog.philippheckel.com/2010/08/22/aware-context-api-acapi-using-the-sensors-in-java-me/#ACAPI-Structure">3.1. ACAPI Structure</a></li>
<li><a href="http://blog.philippheckel.com/2010/08/22/aware-context-api-acapi-using-the-sensors-in-java-me/#Implemented-Sensors">3.2. Implemented Sensors</a></li>
</ol>
</li>
<li><a href="http://blog.philippheckel.com/2010/08/22/aware-context-api-acapi-using-the-sensors-in-java-me/#Example-Usage">4. Example Usage</a>
<ol>
<li><a href="http://blog.philippheckel.com/2010/08/22/aware-context-api-acapi-using-the-sensors-in-java-me/#Example-Scenario-and-Code">4.1. Example Scenario and Code</a></li>
<li><a href="http://blog.philippheckel.com/2010/08/22/aware-context-api-acapi-using-the-sensors-in-java-me/#Proof-of-Concept-Application">4.2. Proof-of-Concept Application</a></li>
</ol>
</li>
<li><a href="http://blog.philippheckel.com/2010/08/22/aware-context-api-acapi-using-the-sensors-in-java-me/#Future-Work-and-Conclusion">5. Future Work and Conclusion</a></li>
<li><a href="http://blog.philippheckel.com/2010/08/22/aware-context-api-acapi-using-the-sensors-in-java-me/#Download-and-License">A. Download and License</a></li>
</ol>
</div>
<hr />
<h3 id="Motivation-and-Goals" >1. Motivation and Goals</h3>
<p>ACAPI is designed to allow easy and homogeneous access to the different sensors of the mobile device. It creates an abstraction between the available sensors and their usage so that developers can focus on the business logic rather than on how to use the sensor implementations.</p>
<blockquote><p><em>Example:</em> A mobile application shall notify the user if another (previously defined) person comes into his or her range, e.g. if the boss arrives at the office.</p></blockquote>
<p>Using the standard Java ME interfaces, developers have to get to know the different APIs and write a lot of code to solve this or similar problems. In this use case, the application needs to determine its position (<em>the office</em>), monitor the available devices around it (<em>the phone of the boss</em>) and be able to notify the user when both events occur. </p>
<p>The Aware Context API aims to solve this reoccurring problem with an easy-to-use event-based framework that allows defining <em>rules</em> for available sensor data. Using ACAPI, the given example can be solved easily by defining a <em>rule</em> and an <em>action</em> that is triggered when the rule matches:</p>
<ul>
<li><strong>Rule</strong>: Wi-Fi &#8220;OfficeWLAN&#8221; available <em>AND</em> Bluetooth device &#8220;BossPhone&#8221; available</li>
<li><strong>Action</strong>: Notify user, e.g. by playing a sound</li>
</ul>
<h3 id="Development-Team-and-Scope" >2. Development Team and Scope</h3>
<p>The ACAPI project was developed within the scope of a team project as part of the curriculum of a Master of Science Degree at the <a href="http://www.uni-mannheim.de/">University of Mannheim</a>. The project was a team-effort, carried out over a 1-year duration at the <a href="http://wifo1.bwl.uni-mannheim.de/">Chair of Business Administration and Information Systems</a>, under the supervision of <a href="http://wifo1.bwl.uni-mannheim.de/heinzl.html">Prof. Armin Heinzl</a> and his research assistants <a href="http://wifo1.bwl.uni-mannheim.de/hemmer.html">Erik Hemmer</a> and <a href="http://wifo1.bwl.uni-mannheim.de/stuckenberg.html">Sebastian Stuckenberg</a>. </p>
<p>The project team consisted of <a href="https://www.xing.com/profile/Lars_Bakker">Lars Bakker</a>, <a href="https://www.xing.com/profile/Philipp_Heckel">Philipp Heckel</a> (myself), <a href="https://www.xing.com/profile/Obie_Modisane">Obie Modisane</a>, <a href="https://www.xing.com/profile/Benjamin_Schubert13">Benjamin Schubert</a> and <a href="https://www.xing.com/profile/Moritz_Waechter2">Moritz Wächter</a>.</p>
<h3 id="Aware-Context-API-ACAPI" >3. Aware Context API (ACAPI)</h3>
<p>The Aware Context API is well-structured and is very easy to understand. It is easily extendible and supports a broad range of devices. It is mainly based on Java ME, but has native parts whenever needed (e.g. for Wi-Fi, battery or telephony). </p>
<h4 id="ACAPI-Structure" >3.1. ACAPI Structure</h4>
<p>ACAPI is horizontally structured into 3 different layers:</p>
<ul>
<li><strong>Sensor</strong>: On the lowest level, the <em>sensors</em> gather data about the current status and context of the phone. A Wi-Fi sensor, for instance, collects available devices and it issues an event whenever the data changes. Applications can either hook themselves directly into the sensor events or use higher abstractions (conditions and rules).</li>
<li><strong>Condition</strong>: In order to evaluate a single sensor, <em>conditions</em> compare the sensor&#8217;s properties to given values. They can become either <em>true</em> or <em>false</em>. A location condition, for example, becomes <em>true</em> if the phone gets into the range of certain coordinates. Similar to a sensor, a condition issues an event when the value changes (from <em>true</em> to <em>false</em>, or vice versa).</li>
<li><strong>Rule</strong>: To express more than one condition, <em>rules</em> can combine conditions to a more complex logical expression. In the above example, the rule only matches if both conditions match (&#8220;in the office&#8221; and &#8220;boss phone available&#8221;).</li>
</ul>
<p><img src="http://blog.philippheckel.com/wp-content/uploads/2010/08/acapi-structure.png" alt="" title="ACAPI structure" class="aligncenter size-full wp-image-503" style="border: none" /></p>
<p style="font-size: .8em; line-height: 115%"><strong>ACAPI Structure</strong> (simplified and incomplete!): The Aware Context API is layer-based. Each of the components is easily extendible and has event listeners to react on changes. This chart shows the interdependence of the different layers.</p>
<p>Using this layered structure, ACAPI fundamentally changes the development strategy of mobile applications. Instead of predefining a screen and/or process flow, applications are <strong>event-driven</strong>. Whenever a rule changes its state (match vs. no match), the application can react by displaying a different screen, notifying the user, or by performing other actions.</p>
<p>Besides the horizontal division, the API is also vertically divided in the two logical parts <em>Boolean</em> and <em>Fuzzy</em>. While the Boolean part assumes correct sensors, the Fuzzy conditions and rules take measurement errors and inaccuracy into account. While the Boolean conditions and rules can only become <em>true</em> or <em>false</em>, their Fuzzy counterparts implement a score-based system that only triggers when a certain threshold is reached. This is particularly relevant for sensors that supply accuracy data, e.g. GPS sensors.</p>
<h4 id="Implemented-Sensors" >3.2. Implemented Sensors</h4>
<p>The current code base of ACAPI includes several predefined sensors, including the most common: Bluetooth and GPS. Most sensors are entirely based on Java ME and will work on any phone that supports the corresponding JSR. However, since Java ME does not provide access to some functionalities, a few native implementations are required (e.g. for Wi-Fi, battery status or telephony status). </p>
<p>The following sensors are already implemented:</p>
<ul>
<li><strong>Battery Sensor</strong> (native S60): This sensor monitors the status of the battery (%) and the charger (enum value, e.g. on-battery, or plugged-in). There is currently only a Symbian S60 implementation for this sensor since Java ME does not allow access to the battery data.</li>
<li><strong>Bluetooth Sensor</strong>: This sensor monitors available devices, e.g. phones or laptops. It can react on joining or leaving devices. </li>
<li><strong>Custom Sensor</strong>: This sensor allows the integration of business logic in ACAPI, so that rules do not only include actual sensor data, but also virtual business sensor data.</li>
<li><strong>Location Sensor</strong> (GPS and Wi-Fi; partially native S60): This sensor monitors the position and the speed. It uses GPS and Wi-Fi triangulation to get a fast and accurate position. Since Java ME does not allow access to the wireless sensor, the Wi-Fi part is native S60 code.</li>
<li><strong>Noise Level  Sensor</strong>: This sensor monitors the noise level (<em>in decibels</em>) of the surrounding area.</li>
<li><strong>Time Sensor</strong>: This sensor delivers the current time and can react on date and time changes.</li>
<li><strong>Wireless Sensor</strong> (native S60): This sensor monitors the available Wi-Fi devices, i.e. access points. It can react on joining and leaving devices. In combination with a web service, it can be used to estimate the position. </li>
</ul>
<p>There are many other possible sensors that could be implemented using the available abstract classes. Examples include an orientation sensor (<em>react on device movement</em>) or a telephony sensor (<em>react on calls, SMS etc.</em>).</p>
<h3 id="Example-Usage" >4. Example Usage</h3>
<p>Having discussed the structure of the Aware Context API, the following section elaborates the above-mentioned example even further. It explains the scenario and shows specific example code.</p>
<h4 id="Example-Scenario-and-Code" >4.1. Example Scenario and Code</h4>
<p>As already briefly mentioned above, the example scenario for demonstrating the API is very simple: The application shall display a warning message and play a warning sound when the boss arrives at the office. </p>
<p><img src="/wp-content/uploads/2010/08/acapi-usecase.png" alt="" title="Use Case" width="500" height="205" class="aligncenter size-full wp-image-493" style="border: none" /></p>
<p>The two conditions depicted in the diagram above are combined in one Boolean rule, i.e. the rule only becomes <em>true</em> if both of the conditions match.</p>
<p>Similar to the API concept, its actual usage is also very simple. The following code snippet shows how to implement the above example in a regular Java ME application.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// Conditions</span>
Condition inOffice <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> WirelessNearCondition<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;OfficeWLAN&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
Condition bossPhone <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> BluetoothNearCondition<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;BossPhone&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// The two conditions create one rule</span>
Rule bossDetectionRule <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> BooleanRule<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
bossDetectionRule.<span style="color: #006633;">addCondition</span><span style="color: #009900;">&#40;</span>inOffice<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
bossDetectionRule.<span style="color: #006633;">addCondition</span><span style="color: #009900;">&#40;</span>bossPhone<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// React when the rule matches</span>
bossDetectionRule.<span style="color: #006633;">addRuleListener</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> RuleListener<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
   <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> ruleChanged<span style="color: #009900;">&#40;</span>Rule rule, <span style="color: #000066; font-weight: bold;">boolean</span> matches<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
     <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>matches<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        playWarningSound<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        displayWarningMessage<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Warning: boss has arrived!&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Activate rule</span>
bossDetectionRule.<span style="color: #006633;">setActive</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>In lines 2-3, the specific conditions are created. Since both conditions represent very generic cases (Bluetooth/WLAN device in range), ACAPI provides predefined conditions for them. In cases where more complex tests are desired, conditions can be extended via simple Java inheritance. Lines 6-8 combine the two conditions to a single Boolean rule, i.e. a rule that becomes either <em>true</em> or <em>false</em> depending on the status of its conditions. Since the application is supposed to react on changes in this particular rule, it registers itself as a listener in lines 11-17. When the rule is activated (line 20), it tells its conditions to register themselves at the corresponding sensors, which in turn get activated (if not already running). After this initialization, ACAPI notifies all registered listeners whenever the rule changes.</p>
<p>Depending on the status of the rules and conditions, i.e. on the device context, the application can change its appearance, behavior or internal state. In this case, it only plays a warning sound and displays a warning message (lines 14-15).</p>
<h4 id="Proof-of-Concept-Application" >4.2. Proof-of-Concept Application</h4>
<p>In order to test the implemented sensors and the rules engine of ACAPI, we developed a proof-of-concept application that implements a more sophisticated context driven use case.</p>
<p>A field service automation application that reacts upon the context the worker is in at the moment. This can be nicely done with the ACAPI and has a value for businesses. However, as this part of our project is not open source, I will not go into more detail here. </p>
<h3 id="Future-Work-and-Conclusion" >5. Future Work and Conclusion</h3>
<p>The Aware Context API provides a framework for building context-aware applications for mobile devices based on Java ME. By providing uniform interfaces to different sensors, the library allows the development of context-driven applications.</p>
<p>The idea and structure of ACAPI are very solid, however, the actual implementation is in a very early development stage. While most sensors and Boolean conditions/rules are already working on the test devices, the Fuzzy conditions and rules are yet to be implemented. The native part only covers Symbian S60 so far and lacks of stability. Hence, the future work will include the implementation of missing parts, testing as well as the documentation. </p>
<h3 id="Download-and-License" >A. Download and License</h3>
<p>ACAPI will be released as open source, possibly under GPL or a Creative Commons license. Since we have not finished cleaning up the code and commenting everything, the code is not available for download as yet. </p>
<p>However, since it will be open source anyway, I will give out the code upon request.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.philippheckel.com/2010/08/22/aware-context-api-acapi-using-the-sensors-in-java-me/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>KadS: a secure version of the Kademlia protocol</title>
		<link>http://blog.philippheckel.com/2009/03/16/kads-a-secure-version-of-the-kademlia-protocol/</link>
		<comments>http://blog.philippheckel.com/2009/03/16/kads-a-secure-version-of-the-kademlia-protocol/#comments</comments>
		<pubDate>Mon, 16 Mar 2009 15:56:40 +0000</pubDate>
		<dc:creator>Philipp C. Heckel</dc:creator>
				<category><![CDATA[Distributed Systems]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Kademlia]]></category>
		<category><![CDATA[Peer-to-Peer]]></category>
		<category><![CDATA[Security]]></category>

		<guid isPermaLink="false">http://blog.philippheckel.com/2009/03/16/kads-a-secure-version-of-the-kademlia-protocol/</guid>
		<description><![CDATA[There are various peer-to-peer protocols out there. All of them focus the decentralisation of storage and other system resources. Most implement a distributed hash table (DHT) to store information. That is, each node of the network only holds a small part of the hash table but is able to locate and retrieve any requested entry. [...]]]></description>
			<content:encoded><![CDATA[<p>There are various peer-to-peer protocols out there. All of them focus the decentralisation of storage and other system resources. Most implement a distributed hash table (DHT) to store information. That is, each node of the network only holds a small part of the hash table but is able to locate and retrieve any requested entry. <a href="http://pdos.csail.mit.edu/~petar/papers/maymounkov-kademlia-lncs.pdf">Kademlia</a>, a protocol designed by two <a href="http://www.nyu.edu/">NYU</a> students in 2002, is one of them.</p>
<p><span id="more-21"></span></p>
<h3 id="toc-the-kademlia-protocol">The Kademlia Protocol</h3>
<p>Kademlia is based on four simple remote procedure calls (RPCs) and guarantees a very fast and lightweight exchange of information by using the connection-less UDP instead of TCP. Every node as well as every entry of the DHT is tagged with an identifier, called <em>node ID</em> or <em>key</em>. By XORing identifiers, one can calculate the distance between them and is hence able to walk through the network knowing whether one is near or far to a specific node. This so called <em>XOR metric</em> makes it possible to group the entries of the DHT around the K closest nodes to the entry&#8217;s key. An entry with the key 10, for instance, will be stored at the nodes with a node ID close to 10.</p>
<h3 id="toc-kademlia-pki-kads-the-secure-extension">Kademlia + PKI = KadS: The Secure Extension</h3>
<p>In my Bachelor thesis, I am going to extend Kademlia from a simple peer-to-peer protocol to a <em>trusted</em> and <em>secure</em> network. The proposed KadS network is almost identical to the Kademlia network, i.e. it consists of the described RPCs and implements the same XOR metric. The major extension to the protocol is that every node is equipped with a public/private key-pair signed by a trusted CA. This extends the normal Kademlia network to a public key infrastructure (PKI) in which every communication is encrypted, every node can be trusted and only verified nodes can participate in the network.</p>
<p>Every connection is synchronously encrypted with a session key which is created and exchanged in a handshake procedure when two nodes first meet. That is, a node has a different session key for the connection with each node it knows in the network. The handshake is similar to the one used in other software except for the fact that both clients exchange their public key and need to verify each others identity. After a successful handshake, two nodes are able to exchange lightweight encrypted messages using the session key and the basic protocol applies</p>
<h3 id="toc-an-application-the-distributed-url-blacklisting-service">An application: The distributed URL blacklisting service</h3>
<p>As an application to the proposed KadS network, I chose a distributed URL blacklisting service. Please read more in my <a href="/uploads/2009/03/kads-url-blacklisting-2009-thesis-expose.pdf">Bachelor thesis exposé</a>, or simply download the whole thesis: </p>
<p><a href="/uploads/2009/05/Blacklisting-Malicious-Web-Sites-using-a-Secure-Version-of-the-DHT-Protocol-Kademlia.pdf">Blacklisting Malicious Web Sites using a Secure Version of the DHT Protocol Kademlia</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.philippheckel.com/2009/03/16/kads-a-secure-version-of-the-kademlia-protocol/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

