Skip to content

Commit

Permalink
Updates for 2.4.0 shared library
Browse files Browse the repository at this point in the history
  • Loading branch information
[email protected] authored and [email protected] committed Jul 6, 2012
1 parent 7149bae commit d0b277e
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 70 deletions.
2 changes: 1 addition & 1 deletion samples/HelloSmartcard/HelloSmartcard/.classpath
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="gen"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry kind="output" path="bin"/>
<classpathentry kind="output" path="bin/classes"/>
</classpath>
11 changes: 4 additions & 7 deletions samples/HelloSmartcard/HelloSmartcard/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.gieseckedevrient.android.hellosmartcard"
android:versionCode="1"
android:versionName="1.0">
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.gieseckedevrient.android.hellosmartcard" android:versionCode="1" android:versionName="1.0">
<uses-sdk android:minSdkVersion="4" android:targetSdkVersion="15" />
<uses-permission android:name="org.simalliance.openmobileapi.SMARTCARD"></uses-permission>
<application android:icon="@drawable/icon" android:label="@string/app_name">
<uses-library android:name="org.simalliance.openmobileapi" android:required="true"/>
<activity android:name=".MainActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

</application>
<uses-sdk android:minSdkVersion="4" />
<uses-permission android:name="org.simalliance.openmobileapi.SMARTCARD"/>
</manifest>
13 changes: 0 additions & 13 deletions samples/HelloSmartcard/HelloSmartcard/default.properties

This file was deleted.

16 changes: 16 additions & 0 deletions samples/HelloSmartcard/HelloSmartcard/project.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# This file is automatically generated by Android Tools.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
#
# This file must be checked in Version Control Systems.
#
# To customize properties used by the Ant build system edit
# "ant.properties", and override values to adapt the script to your
# project structure.
#
# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt

# Indicates whether an apk should be generated for each density.
split.density=false
# Project target.
target=Giesecke & Devrient GmbH:Open Mobile API:15
Original file line number Diff line number Diff line change
Expand Up @@ -11,65 +11,60 @@
import android.widget.Toast;
import org.simalliance.openmobileapi.*;

/**
* This is the refactored sample programm using only the new OMA.
*
* @author user
*
*/

public class MainActivity extends Activity implements SEService.CallBack {

final String LOG_TAG = "HelloSmartcard";

/**
* API entry point
*/
private SEService seService;

private Button button;


@Override
public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

// do layout and UI stuff
LinearLayout layout = createLayout();
Button button = createButton();

// the OnClickListener implements the communication with the secure element
LinearLayout layout = new LinearLayout(this);
layout.setLayoutParams(new LayoutParams(
LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));

button = new Button(this);
button.setLayoutParams(new LayoutParams(
LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));

button.setText("Click Me");
button.setEnabled(false);
button.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
try {
Log.d(LOG_TAG, "Getting available readers...");
Log.i(LOG_TAG, "Retrieve available readers...");
Reader[] readers = seService.getReaders();

Log.d(LOG_TAG, "readers.length = " + readers.length);
if (readers.length < 1)
return;

Log.d(LOG_TAG, "Getting Session from the first reader...");
Log.i(LOG_TAG, "Create Session from the first reader...");
Session session = readers[0].openSession();

// Select our applet
Log.d(LOG_TAG,
"Getting logical channel from the session...");
Log.i(LOG_TAG, "Create logical channel within the session...");
Channel channel = session.openLogicalChannel(new byte[] {
(byte) 0xD2, 0x76, 0x00, 0x01, 0x18, 0x00, 0x02,
(byte) 0xFF, 0x49, 0x50, 0x25, (byte) 0x89,
(byte) 0xC0, 0x01, (byte) 0x9B, 0x01 });

// Send our custom hello world command
Log.d(LOG_TAG, "transmit()");
Log.i(LOG_TAG, "Send HelloWorld APDU command");
byte[] respApdu = channel.transmit(new byte[] {
(byte) 0x90, 0x10, 0x00, 0x00, 0x00 });

channel.close();

// Parse response and show String
// Parse response APDU and show text but remove SW1 SW2 first
byte[] helloStr = new byte[respApdu.length - 2];
System.arraycopy(respApdu, 0, helloStr, 0,
respApdu.length - 2);
Toast.makeText(MainActivity.this, new String(helloStr),
Toast.LENGTH_LONG).show();
System.arraycopy(respApdu, 0, helloStr, 0, respApdu.length - 2);
Toast.makeText(MainActivity.this, new String(helloStr), Toast.LENGTH_LONG).show();
} catch (Exception e) {
Log.e(LOG_TAG, "Error occured:", e);
return;
Expand All @@ -80,12 +75,12 @@ public void onClick(View v) {
layout.addView(button);
setContentView(layout);


try {
// create API entry point
Log.i(LOG_TAG, "creating new SEService");
Log.i(LOG_TAG, "creating SEService object");
seService = new SEService(this, this);
} catch (SecurityException e) {
Log.e(LOG_TAG, "Binding not allowed, uses-permission SMARTCARD?");
Log.e(LOG_TAG, "Binding not allowed, uses-permission org.simalliance.openmobileapi.SMARTCARD?");
} catch (Exception e) {
Log.e(LOG_TAG, "Exception: " + e.getMessage());
}
Expand All @@ -100,23 +95,7 @@ protected void onDestroy() {
}

public void serviceConnected(SEService service) {
Log.i(LOG_TAG, "entry: seviceConnected()");

Log.i(LOG_TAG, "seviceConnected()");
button.setEnabled(true);
}

private LinearLayout createLayout() {
LinearLayout layout = new LinearLayout(this);
layout.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));
return layout;
}

private Button createButton() {
Button button = new Button(this);
button.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));
button.setText("Click Me");
return button;
}

}

0 comments on commit d0b277e

Please sign in to comment.