Commits

Pedro Lima committed 93eac05

initial upload

  • Participants

Comments (0)

Files changed (28)

+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+	<classpathentry kind="src" path="src"/>
+	<classpathentry kind="src" path="gen"/>
+	<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
+	<classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
+	<classpathentry kind="lib" path="libs/cordova-1.5.0.jar"/>
+	<classpathentry kind="output" path="bin/classes"/>
+</classpath>
+syntax: glob
+.svn
+.DS_Store
+*~
+bin/*
+gen/*
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>SConnect</name>
+	<comment></comment>
+	<projects>
+	</projects>
+	<buildSpec>
+		<buildCommand>
+			<name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+		<buildCommand>
+			<name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+		<buildCommand>
+			<name>org.eclipse.jdt.core.javabuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+		<buildCommand>
+			<name>com.android.ide.eclipse.adt.ApkBuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+	</buildSpec>
+	<natures>
+		<nature>com.android.ide.eclipse.adt.AndroidNature</nature>
+		<nature>org.eclipse.jdt.core.javanature</nature>
+	</natures>
+</projectDescription>

File AndroidManifest.xml

+<?xml version="1.0" encoding="utf-8"?>
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+    package="com.cognitiva.sconnect"
+    android:versionCode="1"
+    android:versionName="1.0" >
+
+<supports-screens
+android:largeScreens="true"
+android:normalScreens="true"
+android:smallScreens="true"
+android:resizeable="true"
+android:anyDensity="true"
+/>
+<uses-permission android:name="android.permission.CAMERA" />
+<!-- <uses-permission android:name="android.permission.VIBRATE" /> -->
+<!-- <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> -->
+<!-- <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> -->
+<!-- <uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" /> -->
+<!-- <uses-permission android:name="android.permission.READ_PHONE_STATE" /> -->
+<uses-permission android:name="android.permission.INTERNET" />
+<!-- <uses-permission android:name="android.permission.RECEIVE_SMS" /> -->
+<!-- <uses-permission android:name="android.permission.RECORD_AUDIO" /> -->
+<!-- <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" /> -->
+<!-- <uses-permission android:name="android.permission.READ_CONTACTS" /> -->
+<!-- <uses-permission android:name="android.permission.WRITE_CONTACTS" /> -->
+<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
+<!-- <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> -->
+<!-- <uses-permission android:name="android.permission.GET_ACCOUNTS" /> -->
+<!-- <uses-permission android:name="android.permission.BROADCAST_STICKY" /> -->
+
+    <uses-sdk android:minSdkVersion="8" />
+
+    <application
+        android:icon="@drawable/ic_launcher"
+        android:label="@string/app_name" 
+        android:debuggable="true" >
+        <activity
+            android:name=".SConnectActivity"
+            android:label="@string/app_name" 
+            android:configChanges="orientation|keyboardHidden" >
+            <intent-filter>
+                <action android:name="android.intent.action.MAIN" />
+                <category android:name="android.intent.category.LAUNCHER" />
+            </intent-filter>
+        </activity>
+        <activity android:name=".AppPreferencesActivity" android:label="@string/app_name">
+        </activity>
+        <activity android:name="org.apache.cordova.DroidGap" 
+                  android:label="@string/app_name" 
+                  android:configChanges="orientation|keyboardHidden"> 
+        	<intent-filter> 
+        	</intent-filter> 
+        </activity>
+        <!-- ZXing activities --> 
+        <activity android:name="com.google.zxing.client.android.CaptureActivity" 
+                  android:screenOrientation="landscape" 
+                  android:configChanges="orientation|keyboardHidden" 
+                  android:theme="@android:style/Theme.NoTitleBar.Fullscreen" 
+                  android:windowSoftInputMode="stateAlwaysHidden"> 
+                  <intent-filter> 
+                     <action android:name="com.phonegap.plugins.barcodescanner.SCAN"/> 
+                     <category android:name="android.intent.category.DEFAULT"/> 
+                  </intent-filter> 
+         </activity> 
+         <activity android:name="com.google.zxing.client.android.encode.EncodeActivity" 
+         		   > 
+         		   <intent-filter> 
+         		      <action android:name="com.phonegap.plugins.barcodescanner.ENCODE"/> 
+         		      <category android:name="android.intent.category.DEFAULT"/> 
+         		   </intent-filter> 
+         </activity>
+        
+    </application>
+
+</manifest>
+===========================
+mobiweaver-sconnect-android
+===========================
+
+This is a PhoneGap application to call directly a Netweaver server using basic authentication.
+
+
+Build instructions
+
+The included Eclipse project needs the Android SDK, PhoneGap/Apache Cordova (tested with version 1.5) [1] and the Barcode Scanner plugin [2].
+
+[1] http://incubator.apache.org/cordova/
+[2] https://github.com/phonegap/phonegap-plugins

File libs/cordova-1.5.0.jar

Binary file added.

File proguard.cfg

+-optimizationpasses 5
+-dontusemixedcaseclassnames
+-dontskipnonpubliclibraryclasses
+-dontpreverify
+-verbose
+-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
+
+-keep public class * extends android.app.Activity
+-keep public class * extends android.app.Application
+-keep public class * extends android.app.Service
+-keep public class * extends android.content.BroadcastReceiver
+-keep public class * extends android.content.ContentProvider
+-keep public class * extends android.app.backup.BackupAgentHelper
+-keep public class * extends android.preference.Preference
+-keep public class com.android.vending.licensing.ILicensingService
+
+-keepclasseswithmembernames class * {
+    native <methods>;
+}
+
+-keepclasseswithmembers class * {
+    public <init>(android.content.Context, android.util.AttributeSet);
+}
+
+-keepclasseswithmembers class * {
+    public <init>(android.content.Context, android.util.AttributeSet, int);
+}
+
+-keepclassmembers class * extends android.app.Activity {
+   public void *(android.view.View);
+}
+
+-keepclassmembers enum * {
+    public static **[] values();
+    public static ** valueOf(java.lang.String);
+}
+
+-keep class * implements android.os.Parcelable {
+  public static final android.os.Parcelable$Creator *;
+}

File project.properties

+# 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 use,
+# "ant.properties", and override values to adapt the script to your
+# project structure.
+
+# Project target.
+target=android-8
+android.library.reference.1=../phonegap-plugins/Android/BarcodeScanner/LibraryProject

File res/drawable-hdpi/backrepeat.xml

+<?xml version="1.0" encoding="utf-8"?>
+<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
+    android:src="@drawable/lghtmesh"
+    android:tileMode="repeat" />

File res/drawable-hdpi/ic_launcher.png

Added
New image

File res/drawable-hdpi/ic_menu_login.png

Added
New image

File res/drawable-hdpi/ic_menu_manage.png

Added
New image

File res/drawable-hdpi/lghtmesh.png

Added
New image

File res/drawable-land-mdpi/splash.png

Added
New image

File res/drawable-ldpi/ic_launcher.png

Added
New image

File res/drawable-mdpi/ic_launcher.png

Added
New image

File res/drawable-mdpi/ic_menu_login.png

Added
New image

File res/drawable-mdpi/ic_menu_manage.png

Added
New image

File res/drawable-mdpi/splash.png

Added
New image

File res/layout/main.xml

+<?xml version="1.0" encoding="utf-8"?>
+
+<ScrollView
+	xmlns:android="http://schemas.android.com/apk/res/android" 
+	android:layout_width="fill_parent"
+	android:layout_height="fill_parent"
+	android:background="@drawable/backrepeat" >
+	
+  <LinearLayout 
+    android:layout_width="fill_parent"
+    android:layout_height="fill_parent"
+    android:padding="20sp"
+    android:orientation="vertical"  >
+
+	<TextView
+        android:layout_width="fill_parent"
+        android:layout_height="70px"
+        android:padding="5px"
+        android:textSize="30sp"
+        android:textColor="#222222"
+        android:paddingTop="20sp"
+        android:paddingBottom="20sp"
+        android:gravity="center_horizontal"
+        android:textStyle="bold"
+        android:text="@string/app_name" />
+
+    <TextView
+        android:layout_width="fill_parent"
+        android:layout_height="wrap_content"
+        android:padding="5px"
+        android:textColor="#333333"
+        android:text="@string/username" />
+    
+    <EditText
+    	android:id="@+id/username"
+    	android:layout_width="fill_parent" 
+    	android:layout_height="wrap_content"
+    	android:singleLine="true" />
+    	
+    <TextView
+        android:layout_width="fill_parent"
+        android:layout_height="wrap_content"
+        android:padding="5px"
+        android:textColor="#333333"
+        android:text="@string/password" />
+    
+    <EditText
+    	android:id="@+id/password"
+    	android:inputType="textPassword"
+    	android:password="true"
+    	android:singleLine="true"
+    	android:layout_width="fill_parent" 
+    	android:layout_height="wrap_content" />
+   
+   <Button
+   		android:id="@+id/loginButton"
+   		android:text="@string/login"
+   		android:padding="5px"
+   		android:onClick="onClickLogin"
+   		android:layout_width="fill_parent"
+   		android:layout_height="wrap_content" />
+   
+</LinearLayout>
+</ScrollView>

File res/menu/menu.xml

+<?xml version="1.0" encoding="utf-8"?>
+<menu xmlns:android="http://schemas.android.com/apk/res/android">
+    <item android:id="@+id/quit"
+        android:title="@string/quit"
+        android:icon="@drawable/ic_menu_login" />
+    <item android:id="@+id/settings"
+        android:title="@string/settings"
+        android:icon="@drawable/ic_menu_manage" />
+</menu>

File res/values/strings.xml

+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+
+    <string name="app_name">S-Connect</string>
+	<string name="quit">Quit</string>
+	<string name="settings">Settings</string>
+	<string name="username">Username</string>
+	<string name="password">Password</string>
+	<string name="login">Login</string>
+	<string name="server">Server</string>
+	<string name="port">Port</string>
+	<string name="save">Save</string>
+	<string name="path">Path</string>
+	<string name="client">Client</string>
+	<string name="https">HTTPS</string>
+
+</resources>

File res/xml/cordova.xml

+<?xml version="1.0" encoding="utf-8"?>
+<cordova>
+    <access origin="http://127.0.0.1*"/>
+    <access origin="http://192.168.1.3*"/>
+    <log level="DEBUG"/>
+</cordova>

File res/xml/plugins.xml

+<?xml version="1.0" encoding="utf-8"?>
+<plugins>
+    <plugin name="App" value="org.apache.cordova.App"/>
+    <plugin name="Geolocation" value="org.apache.cordova.GeoBroker"/>
+    <plugin name="Device" value="org.apache.cordova.Device"/>
+    <plugin name="Accelerometer" value="org.apache.cordova.AccelListener"/>
+    <plugin name="Compass" value="org.apache.cordova.CompassListener"/>
+    <plugin name="Media" value="org.apache.cordova.AudioHandler"/>
+    <plugin name="Camera" value="org.apache.cordova.CameraLauncher"/>
+    <plugin name="Contacts" value="org.apache.cordova.ContactManager"/>
+    <plugin name="File" value="org.apache.cordova.FileUtils"/>
+    <plugin name="Network Status" value="org.apache.cordova.NetworkManager"/>
+    <plugin name="Notification" value="org.apache.cordova.Notification"/>
+    <plugin name="Storage" value="org.apache.cordova.Storage"/>
+    <plugin name="Temperature" value="org.apache.cordova.TempListener"/>
+    <plugin name="FileTransfer" value="org.apache.cordova.FileTransfer"/>
+    <plugin name="Capture" value="org.apache.cordova.Capture"/>
+    <plugin name="Battery" value="org.apache.cordova.BatteryListener"/>
+    <plugin name="BarcodeScanner" value="com.phonegap.plugins.barcodescanner.BarcodeScanner"/>
+</plugins>

File res/xml/preferences.xml

+<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
+
+<EditTextPreference
+	android:key="server"
+	android:title="@string/server"
+	android:summary="Server name"
+	android:dialogTitle="Server name, ex. server.company.com" />
+
+<EditTextPreference
+	android:key="port"
+	android:title="@string/port"
+	android:summary="Port for HTTP/HTTPS connection" 
+	android:dialogTitle="Port for HTTP/HTTPS connection, ex. 8000" />
+
+<EditTextPreference
+	android:key="path"
+	android:title="@string/path"
+	android:summary="Start URL path"
+	android:dialogTitle="Start URL path, ex. /sap/bc/bsp/sap/yapp" />
+
+<EditTextPreference
+	android:key="client"
+	android:title="@string/client"
+	android:summary="Server client number" 
+	android:dialogTitle="Server client number, ex. 800" />
+
+<CheckBoxPreference 
+	android:key="https" 
+	android:title="HTTPS" 
+	android:summary="Use encrypted HTTPS connection" />
+
+</PreferenceScreen>

File src/com/cognitiva/sconnect/AppPreferencesActivity.java

+package com.cognitiva.sconnect;
+
+import android.os.Bundle;
+import android.preference.EditTextPreference;
+import android.preference.PreferenceActivity;
+import android.text.InputType;
+
+public class AppPreferencesActivity extends PreferenceActivity {
+	
+	@Override 
+	public void onCreate(Bundle savedInstanceState) {
+		super.onCreate(savedInstanceState);
+		addPreferencesFromResource(R.xml.preferences);
+		//restrict some preferences to numeric values 
+		EditTextPreference pref = (EditTextPreference)findPreference("port");
+		pref.getEditText().setInputType(InputType.TYPE_CLASS_NUMBER);
+		pref = (EditTextPreference)findPreference("client");
+		pref.getEditText().setInputType(InputType.TYPE_CLASS_NUMBER);
+	}
+}

File src/com/cognitiva/sconnect/SConnectActivity.java

+package com.cognitiva.sconnect;
+
+import java.io.IOException;
+import java.net.Socket;
+import java.net.UnknownHostException;
+import java.security.KeyManagementException;
+import java.security.KeyStore;
+import java.security.KeyStoreException;
+import java.security.NoSuchAlgorithmException;
+import java.security.UnrecoverableKeyException;
+import java.security.cert.CertificateException;
+import java.security.cert.X509Certificate;
+
+import javax.net.ssl.SSLContext;
+import javax.net.ssl.TrustManager;
+import javax.net.ssl.X509TrustManager;
+
+import android.util.Log;
+import android.app.AlertDialog;
+import android.content.DialogInterface;
+import android.content.DialogInterface.OnClickListener;
+import android.content.Intent;
+import android.content.SharedPreferences;
+import android.content.pm.ApplicationInfo;
+import android.content.pm.PackageManager;
+import android.content.pm.PackageManager.NameNotFoundException;
+import android.os.Bundle;
+import android.preference.PreferenceManager;
+import android.view.Menu;
+import android.view.MenuInflater;
+import android.view.MenuItem;
+import android.view.View;
+import android.view.inputmethod.InputMethodManager;
+import android.widget.Button;
+import android.widget.EditText;
+
+import org.apache.cordova.*;
+import org.apache.http.conn.ClientConnectionManager;
+import org.apache.http.HttpResponse;
+import org.apache.http.HttpVersion;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.client.ClientProtocolException;
+import org.apache.http.impl.client.DefaultHttpClient;
+import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
+import org.apache.http.params.BasicHttpParams;
+import org.apache.http.params.HttpParams;
+import org.apache.http.params.HttpProtocolParams;
+import org.apache.http.protocol.HTTP;
+import org.apache.http.auth.AuthScope;
+import org.apache.http.auth.UsernamePasswordCredentials;
+import org.apache.http.conn.ssl.SSLSocketFactory;
+import org.apache.http.conn.scheme.PlainSocketFactory;
+import org.apache.http.conn.scheme.Scheme;
+import org.apache.http.conn.scheme.SchemeRegistry;
+
+public class SConnectActivity extends DroidGap {
+	AuthenticationToken token = new AuthenticationToken();
+	String url;
+	String server;
+	String port;
+	String lastusername;
+	
+    /** Called when the activity is first created. */
+    @Override
+    public void onCreate(Bundle savedInstanceState) {
+    	
+        super.onCreate(savedInstanceState);
+        buildConnectionUrl();
+        lastusername = readLastUsername();
+        super.setContentView(R.layout.main);
+        if (lastusername != "") {
+        	EditText usernameField = (EditText)findViewById(R.id.username);
+        	usernameField.setText(lastusername);
+        }
+    }
+
+    public String readLastUsername() {
+    	SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
+    	return sp.getString("lastusername", "");
+    }
+    
+    public void setLastUsername(String username) {
+    	SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
+    	SharedPreferences.Editor editor = sp.edit();
+    	editor.putString("lastusername", username);
+    	editor.commit();
+    }
+    
+    /** Builds connection URL from settings */
+    public void buildConnectionUrl() {
+    	SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
+    	String server = sp.getString("server", "");
+    	String port = sp.getString("port", "");
+    	String path = sp.getString("path", "");
+    	String client = sp.getString("client", "");
+    	Boolean https = sp.getBoolean("https", false);
+    	this.server = server;
+    	this.port = port;
+    	if (server == "" || port == "" || path == "" || client == "") {
+    		return;
+    	}
+    	if (https) {
+        	url = "https://";
+    	} else {
+    		url = "http://";
+    	}
+    	url += server;
+    	if (port != "80") {
+    		url += ":" + port;
+    	}
+    	url += path;
+    	url += "?sap-client=" + client;
+    	Log.v("Connection URL", url);
+    }
+    
+    public boolean onCreateOptionsMenu(Menu menu) {
+    	MenuInflater inflater = getMenuInflater();
+    	inflater.inflate(R.menu.menu, menu);
+    	return true;
+    }
+    
+    @Override
+    public boolean onOptionsItemSelected(MenuItem item) {
+    	boolean handled = false;
+
+        switch(item.getItemId()) {
+        	case R.id.quit:
+        		this.endActivity();
+        		handled = true;
+        		break;
+        	case R.id.settings:
+        		startActivity(new Intent(this, AppPreferencesActivity.class));
+        		handled = true;
+        	default:
+        		break;
+        }
+        return handled;
+    }
+    
+    public void onClickLogin(View view) {  
+    	buildConnectionUrl();
+    	if (url == "") {
+    		new AlertDialog.Builder(this).setTitle("Missing Configuration")
+			.setMessage("Connection information is missing in the settings.")
+			.setPositiveButton("OK", new OnClickListener() {
+				public void onClick(DialogInterface dialog, int arg1) {
+					dialog.dismiss();
+				}})
+			.show();
+    	} else {
+    	
+    	EditText usernameField = (EditText)findViewById(R.id.username);
+    	EditText passwordField = (EditText)findViewById(R.id.password);
+    	String username = usernameField.getText().toString();
+    	if (username != lastusername) {
+    		setLastUsername(username);
+    	}
+    	
+    	//hide the keyboard
+    	InputMethodManager mgr=(InputMethodManager)getSystemService(INPUT_METHOD_SERVICE);
+    	mgr.hideSoftInputFromWindow(usernameField.getWindowToken(), 0);
+    	mgr.hideSoftInputFromWindow(passwordField.getWindowToken(), 0);
+    	
+    	token.setUserName(username);
+    	token.setPassword(passwordField.getText().toString());
+    	super.setAuthenticationToken(token,"", "");
+    	if (checkAuthentication(token.getUserName(),token.getPassword())) {
+    		super.setIntegerProperty("splashscreen", R.drawable.splash);
+    		super.loadUrl(url);
+    	} else {
+    		new AlertDialog.Builder(this).setTitle("Failed Authentication")
+    				.setMessage("The username/password combination is not valid")
+    				.setPositiveButton("OK", new OnClickListener() {
+    					public void onClick(DialogInterface dialog, int arg1) {
+    						dialog.dismiss();
+    					}})
+    				.show();
+    	}
+    	}
+    }
+    
+    boolean checkAuthentication(String username, String password) {
+    	
+    	int port_number = Integer.parseInt( port );
+    	
+    	if (username.length() == 0 || password.length() == 0) {
+    		return false;
+    	}
+    	
+    	HttpResponse response;
+    	DefaultHttpClient httpclient;
+    	
+    	String packageName = getPackageName();
+    	PackageManager pm = getPackageManager();
+    	try {
+    		ApplicationInfo appInfo = pm.getApplicationInfo(packageName, PackageManager.GET_META_DATA);
+            if ((appInfo.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0) {
+            	// only in debug mode the HTTP client accepts any certificate
+            	httpclient = getNewHttpClient();
+            } else {
+            	httpclient = new DefaultHttpClient();
+            }
+    	} catch (NameNotFoundException e) {
+    		httpclient = new DefaultHttpClient();
+    	}
+    	
+    	try {
+    		httpclient.getCredentialsProvider().setCredentials(
+                    new AuthScope(server, port_number),
+                    new UsernamePasswordCredentials(username, password));
+    		HttpGet httpget = new HttpGet(url);
+    		response = httpclient.execute(httpget);
+    		Log.v("HTTP response", response.getStatusLine().toString());
+    		if (response.getStatusLine().getStatusCode() == 200) {
+    			return true;
+    		} else {
+    			return false;
+    		}
+    	} catch (ClientProtocolException e) {
+    		Log.v("Client protocol exception", e.toString());
+    	} catch (IOException e) {
+    		Log.v("Client protocol exception", e.toString());
+    	} finally {
+    		httpclient.getConnectionManager().shutdown();
+    	}
+      	
+    	return false;
+    }
+    
+    // should not be needed with the current way to start the app
+    boolean isUrlWhiteListed(String url) {
+    	return true;
+    }
+
+    /* this http client follows the phonegap logic of accepting SSL certificates 
+     * when in debug mode.
+     */
+    public DefaultHttpClient getNewHttpClient() {
+        try {
+            KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
+            trustStore.load(null, null);
+
+            SSLSocketFactory sf = new MySSLSocketFactory(trustStore);
+            sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
+
+            HttpParams params = new BasicHttpParams();
+            HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
+            HttpProtocolParams.setContentCharset(params, HTTP.UTF_8);
+
+            SchemeRegistry registry = new SchemeRegistry();
+            registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
+            registry.register(new Scheme("https", sf, 443));
+
+            ClientConnectionManager ccm = new ThreadSafeClientConnManager(params, registry);
+
+            return new DefaultHttpClient(ccm, params);
+        } catch (Exception e) {
+            return new DefaultHttpClient();
+        }
+    }
+    
+}
+
+class MySSLSocketFactory extends SSLSocketFactory {
+    SSLContext sslContext = SSLContext.getInstance("TLS");
+
+    public MySSLSocketFactory(KeyStore truststore) throws NoSuchAlgorithmException, KeyManagementException, KeyStoreException, UnrecoverableKeyException {
+        super(truststore);
+
+        TrustManager tm = new X509TrustManager() {
+            public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
+            }
+
+            public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
+            }
+
+            public X509Certificate[] getAcceptedIssuers() {
+                return null;
+            }
+        };
+
+        sslContext.init(null, new TrustManager[] { tm }, null);
+    }
+
+    @Override
+    public Socket createSocket(Socket socket, String host, int port, boolean autoClose) throws IOException, UnknownHostException {
+        return sslContext.getSocketFactory().createSocket(socket, host, port, autoClose);
+    }
+
+    @Override
+    public Socket createSocket() throws IOException {
+        return sslContext.getSocketFactory().createSocket();
+    }
+}

File src/com/phonegap/plugins/barcodescanner/BarcodeScanner.java

+/**
+ * PhoneGap is available under *either* the terms of the modified BSD license *or* the
+ * MIT License (2008). See http://opensource.org/licenses/alphabetical for full text.
+ *
+ * Copyright (c) Matt Kane 2010
+ * Copyright (c) 2011, IBM Corporation
+ */
+
+package com.phonegap.plugins.barcodescanner;
+
+import org.json.JSONArray;
+import org.json.JSONException;
+import org.json.JSONObject;
+
+import android.app.Activity;
+import android.content.Intent;
+import android.util.Log;
+
+import com.phonegap.api.Plugin;
+import com.phonegap.api.PluginResult;
+
+/**
+ * This calls out to the ZXing barcode reader and returns the result.
+ */
+public class BarcodeScanner extends Plugin {
+    private static final String TEXT_TYPE = "TEXT_TYPE";
+    private static final String EMAIL_TYPE = "EMAIL_TYPE";
+    private static final String PHONE_TYPE = "PHONE_TYPE";
+    private static final String SMS_TYPE = "SMS_TYPE";
+
+    public static final int REQUEST_CODE = 0x0ba7c0de;
+
+    public String callback;
+
+    /**
+     * Constructor.
+     */
+    public BarcodeScanner() {
+    }
+
+    /**
+     * Executes the request and returns PluginResult.
+     *
+     * @param action        The action to execute.
+     * @param args          JSONArray of arguments for the plugin.
+     * @param callbackId    The callback id used when calling back into JavaScript.
+     * @return              A PluginResult object with a status and message.
+     */
+    public PluginResult execute(String action, JSONArray args, String callbackId) {
+        this.callback = callbackId;
+
+        if (action.equals("encode")) {
+            JSONObject obj = args.optJSONObject(0);
+            if (obj != null) {
+                String type = obj.optString("type");
+                String data = obj.optString("data");
+                
+                // If the type is null then force the type to text
+                if (type == null) {
+                    type = TEXT_TYPE;
+                }
+                
+                if (data == null) {
+                    return new PluginResult(PluginResult.Status.ERROR, "User did not specify data to encode");                                            
+                }
+                
+                encode(type, data);                    
+            } else {
+                return new PluginResult(PluginResult.Status.ERROR, "User did not specify data to encode");                    
+            }
+        }
+        else if (action.equals("scan")) {
+            scan();
+        } else {
+            return new PluginResult(PluginResult.Status.INVALID_ACTION);
+        }
+        PluginResult r = new PluginResult(PluginResult.Status.NO_RESULT);
+        r.setKeepCallback(true);
+        return r;
+    }
+
+
+    /**
+     * Starts an intent to scan and decode a barcode.
+     */
+    public void scan() {
+        Intent intentScan = new Intent("com.phonegap.plugins.barcodescanner.SCAN");
+        intentScan.addCategory(Intent.CATEGORY_DEFAULT);
+
+        this.ctx.startActivityForResult((Plugin) this, intentScan, REQUEST_CODE);
+    }
+
+    /**
+     * Called when the barcode scanner intent completes
+     *
+     * @param requestCode       The request code originally supplied to startActivityForResult(),
+     *                          allowing you to identify who this result came from.
+     * @param resultCode        The integer result code returned by the child activity through its setResult().
+     * @param intent            An Intent, which can return result data to the caller (various data can be attached to Intent "extras").
+     */
+    public void onActivityResult(int requestCode, int resultCode, Intent intent) {
+        if (requestCode == REQUEST_CODE) {
+            if (resultCode == Activity.RESULT_OK) {
+                JSONObject obj = new JSONObject();
+                try {
+                    obj.put("text", intent.getStringExtra("SCAN_RESULT"));
+                    obj.put("format", intent.getStringExtra("SCAN_RESULT_FORMAT"));
+                    obj.put("cancelled", false);
+                } catch(JSONException e) {
+                    //Log.d(LOG_TAG, "This should never happen");
+                }
+                this.success(new PluginResult(PluginResult.Status.OK, obj), this.callback);
+            } if (resultCode == Activity.RESULT_CANCELED) {
+                JSONObject obj = new JSONObject();
+                try {
+                    obj.put("text", "");
+                    obj.put("format", "");
+                    obj.put("cancelled", true);
+                } catch(JSONException e) {
+                    //Log.d(LOG_TAG, "This should never happen");
+                }
+                this.success(new PluginResult(PluginResult.Status.OK, obj), this.callback);
+            } else {
+                this.error(new PluginResult(PluginResult.Status.ERROR), this.callback);
+            }
+        }
+    }
+
+    /**
+     * Initiates a barcode encode. 
+     * @param data  The data to encode in the bar code
+     * @param data2 
+     */
+    public void encode(String type, String data) {
+        Intent intentEncode = new Intent("com.phonegap.plugins.barcodescanner.ENCODE");
+        intentEncode.putExtra("ENCODE_TYPE", type);
+        intentEncode.putExtra("ENCODE_DATA", data);
+        
+        this.ctx.startActivity(intentEncode);
+    }
+}