Bug: 474722 - Migrate Android Service Project to Android Studio / Gradle

Migrated Android Service to Gradle / Android Studio.

Signed-off-by: James Sutton <james.sutton@uk.ibm.com>
This commit is contained in:
James Sutton 2015-08-26 15:50:58 +01:00
parent ea42792dcc
commit 2d5d689ac3
142 changed files with 4852 additions and 5094 deletions

View File

@ -1,8 +1,17 @@
#Android Service Client
#Generate JavaDoc
1. Switch directory to ```cd org.eclipse.paho.android.service```
2. ```android update -p .```
3. Build Android project ```ant debug```
4. Documentation is in ```out\docs```
The Android MQTT Service Project has been restructured to work in Android Studio and use the Gradle Build system.
To get started, download [Android Studio](http://developer.android.com/tools/studio/index.html). You will also need to download the [Android SDK](https://developer.android.com/sdk/installing/adding-packages.html). Currently you will need the SDK for 19,21 and 22, This will hopefully be simplified soon.
## Running the Sample App:
* Open the this current directory in Android Studio (org.eclipse.paho.android.service).
* In the toolbar along the top, there should be a dropdown menu. Make sure that it contains 'org.eclipse.android.sample' then click the Green 'Run' Triangle. It should now build and launch an Virtual Android Device to run the App. If you have an Android device with developer mode turned on plugged in, you will have the oppertunity to run it directly on that.
* If you have any problems, check out the Android Developer Documentation for help: https://developer.android.com
## Building the service locally
* Open a terminal and navigate to this directory (org.eclipse.paho.android.service)
* Run the command ```./gradlew clean assemble exportJar``` or on Windows: ```gradlew.bat clean assemble exportJar```
Once it completes successfully, the service jar will be located in org.eclipse.paho.android/org.eclipse.paho.android.service/release

18
build.gradle Executable file
View File

@ -0,0 +1,18 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.2.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}

18
gradle.properties Executable file
View File

@ -0,0 +1,18 @@
# Project-wide Gradle settings.
# IDE (e.g. Android Studio) users:
# Gradle settings configured through the IDE *will override*
# any settings specified in this file.
# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
# Default value: -Xmx10248m -XX:MaxPermSize=256m
# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true

164
gradlew vendored Executable file
View File

@ -0,0 +1,164 @@
#!/usr/bin/env bash
##############################################################################
##
## Gradle start up script for UN*X
##
##############################################################################
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS=""
APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"
warn ( ) {
echo "$*"
}
die ( ) {
echo
echo "$*"
echo
exit 1
}
# OS specific support (must be 'true' or 'false').
cygwin=false
msys=false
darwin=false
case "`uname`" in
CYGWIN* )
cygwin=true
;;
Darwin* )
darwin=true
;;
MINGW* )
msys=true
;;
esac
# For Cygwin, ensure paths are in UNIX format before anything is touched.
if $cygwin ; then
[ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
fi
# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
# Need this for relative symlinks.
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`"/$link"
fi
done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >&-
APP_HOME="`pwd -P`"
cd "$SAVED" >&-
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD="$JAVA_HOME/jre/sh/java"
else
JAVACMD="$JAVA_HOME/bin/java"
fi
if [ ! -x "$JAVACMD" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
else
JAVACMD="java"
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
# Increase the maximum file descriptors if we can.
if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
MAX_FD_LIMIT=`ulimit -H -n`
if [ $? -eq 0 ] ; then
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
MAX_FD="$MAX_FD_LIMIT"
fi
ulimit -n $MAX_FD
if [ $? -ne 0 ] ; then
warn "Could not set maximum file descriptor limit: $MAX_FD"
fi
else
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
fi
fi
# For Darwin, add options to specify how the application appears in the dock
if $darwin; then
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi
# For Cygwin, switch paths to Windows format before running java
if $cygwin ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
# We build the pattern for arguments to be converted via cygpath
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
SEP=""
for dir in $ROOTDIRSRAW ; do
ROOTDIRS="$ROOTDIRS$SEP$dir"
SEP="|"
done
OURCYGPATTERN="(^($ROOTDIRS))"
# Add a user-defined pattern to the cygpath arguments
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
fi
# Now convert the arguments - kludge to limit ourselves to /bin/sh
i=0
for arg in "$@" ; do
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
else
eval `echo args$i`="\"$arg\""
fi
i=$((i+1))
done
case $i in
(0) set -- ;;
(1) set -- "$args0" ;;
(2) set -- "$args0" "$args1" ;;
(3) set -- "$args0" "$args1" "$args2" ;;
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
esac
fi
# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
function splitJvmOpts() {
JVM_OPTS=("$@")
}
eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"

90
gradlew.bat vendored Executable file
View File

@ -0,0 +1,90 @@
@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS=
set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto init
echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto init
echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:init
@rem Get command-line arguments, handling Windowz variants
if not "%OS%" == "Windows_NT" goto win9xME_args
if "%@eval[2+2]" == "4" goto 4NT_args
:win9xME_args
@rem Slurp the command line arguments.
set CMD_LINE_ARGS=
set _SKIP=2
:win9xME_args_slurp
if "x%~1" == "x" goto execute
set CMD_LINE_ARGS=%*
goto execute
:4NT_args
@rem Get arguments from the 4NT Shell from JP Software
set CMD_LINE_ARGS=%$
:execute
@rem Setup the command line
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd
:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1
:mainEnd
if "%OS%"=="Windows_NT" endlocal
:omega

19
org.eclipse.paho.android.iml Executable file
View File

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<module external.linked.project.id="org.eclipse.paho.android" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" external.system.module.group="" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="java-gradle" name="Java-Gradle">
<configuration>
<option name="BUILD_FOLDER_PATH" value="$MODULE_DIR$/build" />
<option name="BUILDABLE" value="false" />
</configuration>
</facet>
</component>
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_6" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/.gradle" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

1
org.eclipse.paho.android.sample/.gitignore vendored Executable file
View File

@ -0,0 +1 @@
/build

View File

@ -0,0 +1,34 @@
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion '21.1.2'
defaultConfig {
// min and target SDK is not set in Gradle to use the version defined in the android manifest
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
lintOptions {
abortOnError false
}
}
repositories {
maven {
url "https://repo.eclipse.org/content/repositories/paho-releases/"
}
}
dependencies {
compile 'com.android.support:support-v4:22.2.1'
compile (group: 'org.eclipse.paho', name: 'org.eclipse.paho.android.service', version: '1.0.2') {
exclude module: 'support-v4'
}
}

View File

@ -0,0 +1,99 @@
<?xml version="1.0" encoding="UTF-8"?>
<module external.linked.project.id=":org.eclipse.paho.android.sample" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="org.eclipse.paho.android" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="android-gradle" name="Android-Gradle">
<configuration>
<option name="GRADLE_PROJECT_PATH" value=":org.eclipse.paho.android.sample" />
</configuration>
</facet>
<facet type="android" name="Android">
<configuration>
<option name="SELECTED_BUILD_VARIANT" value="debug" />
<option name="SELECTED_TEST_ARTIFACT" value="_android_test_" />
<option name="ASSEMBLE_TASK_NAME" value="assembleDebug" />
<option name="COMPILE_JAVA_TASK_NAME" value="compileDebugSources" />
<option name="ASSEMBLE_TEST_TASK_NAME" value="assembleDebugAndroidTest" />
<option name="COMPILE_JAVA_TEST_TASK_NAME" value="compileDebugAndroidTestSources" />
<afterSyncTasks>
<task>generateDebugAndroidTestSources</task>
<task>generateDebugSources</task>
</afterSyncTasks>
<option name="ALLOW_USER_CONFIGURATION" value="false" />
<option name="MANIFEST_FILE_RELATIVE_PATH" value="/src/main/AndroidManifest.xml" />
<option name="RES_FOLDER_RELATIVE_PATH" value="/src/main/res" />
<option name="RES_FOLDERS_RELATIVE_PATH" value="file://$MODULE_DIR$/src/main/res" />
<option name="ASSETS_FOLDER_RELATIVE_PATH" value="/src/main/assets" />
</configuration>
</facet>
</component>
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_7" inherit-compiler-output="false">
<output url="file://$MODULE_DIR$/build/intermediates/classes/debug" />
<output-test url="file://$MODULE_DIR$/build/intermediates/classes/androidTest/debug" />
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/debug" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/debug" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/debug" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/debug" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/debug" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/generated/debug" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/androidTest/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/androidTest/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/androidTest/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/androidTest/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/androidTest/debug" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/generated/androidTest/debug" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/res" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/assets" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/aidl" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/jni" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/rs" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/res" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/main/assets" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/main/aidl" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/jni" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/rs" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/aidl" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/bundles" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/coverage-instrumented-classes" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dependency-cache" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex-cache" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/support-v4/22.2.1/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/jacoco" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/javaResources" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/libs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/lint" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifests" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/ndk" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/pre-dexed" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/proguard" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" />
<excludeFolder url="file://$MODULE_DIR$/build/outputs" />
<excludeFolder url="file://$MODULE_DIR$/build/reports" />
<excludeFolder url="file://$MODULE_DIR$/build/test-results" />
<excludeFolder url="file://$MODULE_DIR$/build/tmp" />
</content>
<orderEntry type="jdk" jdkName="Android API 21 Platform" jdkType="Android SDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" exported="" name="support-v4-22.2.1" level="project" />
<orderEntry type="library" exported="" name="org.eclipse.paho.client.mqttv3-1.0.2" level="project" />
<orderEntry type="library" exported="" name="support-annotations-22.2.1" level="project" />
<orderEntry type="library" exported="" name="org.eclipse.paho.android.service-1.0.2" level="project" />
</component>
</module>

View File

@ -1,11 +1,8 @@
# To enable ProGuard in your project, edit project.properties
# to define the proguard.config property as described in that file.
#
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in ${sdk.dir}/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the ProGuard
# include property in project.properties.
# in /home/james/Android/Sdk/tools/proguard/proguard-org.eclipse.paho.android.service.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

View File

@ -0,0 +1,13 @@
package org.eclipse.paho.android;
import android.app.Application;
import android.test.ApplicationTestCase;
/**
* <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a>
*/
public class ApplicationTest extends ApplicationTestCase<Application> {
public ApplicationTest() {
super(Application.class);
}
}

View File

@ -1,62 +1,70 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.eclipse.paho.android.service.sample"
package="org.eclipse.paho.android.sample"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="19" />
android:targetSdkVersion="21" />
<!-- Permissions the Application Requires -->
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<!-- Mqtt Service -->
<service android:name="org.eclipse.paho.android.service.MqttService" >
</service>
<!-- Main Activity -->
<activity android:name="org.eclipse.paho.android.service.sample.ClientConnections" >
<intent-filter>
<activity android:name="org.eclipse.paho.android.sample.ClientConnections" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</intent-filter>
</activity>
<!-- New Connection Activity -->
<activity
android:name="org.eclipse.paho.android.service.sample.NewConnection"
android:name="org.eclipse.paho.android.sample.NewConnection"
android:label="@string/title_activity_new_connection" >
</activity>
<!-- Advanced Options Screen -->
<activity
android:name="org.eclipse.paho.android.service.sample.Advanced"
android:name="org.eclipse.paho.android.sample.Advanced"
android:label="@string/title_activity_advanced" >
</activity>
<!-- Last Will Activity -->
<activity
android:name="org.eclipse.paho.android.service.sample.LastWill"
android:name="org.eclipse.paho.android.sample.LastWill"
android:label="@string/title_activity_last_will" >
</activity>
<!-- Connection Details Activity -->
<!-- Connection Details Activity -->
<activity
android:name="org.eclipse.paho.android.service.sample.ConnectionDetails"
android:label="@string/title_activity_connection_details"
>
android:name="org.eclipse.paho.android.sample.ConnectionDetails"
android:label="@string/title_activity_connection_details" >
</activity>
<service
android:name="org.eclipse.paho.android.sample.AndroidMqttService"
android:enabled="true"
android:exported="true" >
</service>
</application>
</manifest>

View File

@ -10,15 +10,15 @@
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*/
package org.eclipse.paho.android.service.sample;
import org.eclipse.paho.android.service.sample.Connection.ConnectionStatus;
import org.eclipse.paho.client.mqttv3.IMqttActionListener;
import org.eclipse.paho.client.mqttv3.IMqttToken;
package org.eclipse.paho.android.sample;
import android.content.Context;
import android.widget.Toast;
import org.eclipse.paho.android.sample.Connection.ConnectionStatus;
import org.eclipse.paho.client.mqttv3.IMqttActionListener;
import org.eclipse.paho.client.mqttv3.IMqttToken;
/**
* This Class handles receiving information from the
* {@link MqttAndroidClient} and updating the {@link Connection} associated with

View File

@ -10,7 +10,7 @@
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*/
package org.eclipse.paho.android.service.sample;
package org.eclipse.paho.android.sample;
import org.eclipse.paho.client.mqttv3.MqttMessage;

View File

@ -10,10 +10,7 @@
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*/
package org.eclipse.paho.android.service.sample;
import java.util.HashMap;
import java.util.Map;
package org.eclipse.paho.android.sample;
import android.app.Activity;
import android.app.Dialog;
@ -28,7 +25,9 @@ import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import org.eclipse.paho.android.service.sample.R;
import java.util.HashMap;
import java.util.Map;
/**
* Advanced connection options activity
@ -203,7 +202,7 @@ public class Advanced extends Activity {
private void lastWill() {
Intent intent = new Intent();
intent.setClassName(advanced, "org.eclipse.paho.android.service.sample.LastWill");
intent.setClassName(advanced, "org.eclipse.paho.android.sample.LastWill");
advanced.startActivityForResult(intent, ActivityConstants.lastWill);
}

View File

@ -0,0 +1,16 @@
package org.eclipse.paho.android.sample;
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
public class AndroidMqttService extends Service {
public AndroidMqttService() {
}
@Override
public IBinder onBind(Intent intent) {
// TODO: Return the communication channel to the service.
throw new UnsupportedOperationException("Not yet implemented");
}
}

View File

@ -10,7 +10,7 @@
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*/
package org.eclipse.paho.android.service.sample;
package org.eclipse.paho.android.sample;
import android.os.Bundle;

View File

@ -10,20 +10,9 @@
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*/
package org.eclipse.paho.android.service.sample;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.Map;
import org.eclipse.paho.android.service.MqttAndroidClient;
import org.eclipse.paho.android.service.sample.Connection.ConnectionStatus;
import org.eclipse.paho.client.mqttv3.MqttConnectOptions;
import org.eclipse.paho.client.mqttv3.MqttException;
import org.eclipse.paho.client.mqttv3.MqttSecurityException;
package org.eclipse.paho.android.sample;
import android.annotation.SuppressLint;
import android.app.AlertDialog;
import android.app.ListActivity;
import android.content.DialogInterface;
@ -42,6 +31,18 @@ import android.widget.AdapterView.OnItemLongClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import org.eclipse.paho.android.service.MqttAndroidClient;
import org.eclipse.paho.android.sample.Connection.ConnectionStatus;
import org.eclipse.paho.client.mqttv3.MqttConnectOptions;
import org.eclipse.paho.client.mqttv3.MqttException;
import org.eclipse.paho.client.mqttv3.MqttSecurityException;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.Map;
/**
* ClientConnections is the main activity for the sample application, it
* displays all the active connections.
@ -52,7 +53,7 @@ public class ClientConnections extends ListActivity {
/**
* Token to pass to the MQTT Service
*/
final static String TOKEN = "org.eclipse.paho.android.service.sample.ClientConnections";
final static String TOKEN = "org.eclipse.paho..service.sample.ClientConnections";
/**
* ArrayAdapter to populate the list view
@ -150,7 +151,7 @@ public class ClientConnections extends ListActivity {
// selected connection
Intent intent = new Intent();
intent.setClassName(getApplicationContext().getPackageName(),
"org.eclipse.paho.android.service.sample.ConnectionDetails");
"org.eclipse.paho.android.sample.ConnectionDetails");
intent.putExtra("handle", c.handle());
startActivity(intent);
}
@ -362,8 +363,9 @@ public class ClientConnections extends ListActivity {
private Connection connection = null;
/* (non-Javadoc)
* @see android.widget.AdapterView.OnItemLongClickListener#onItemLongClick(android.widget.AdapterView, android.view.View, int, long)
* @see org.eclipse.paho.android.service.widget.AdapterView.OnItemLongClickListener#onItemLongClick(org.eclipse.paho.android.service.widget.AdapterView, org.eclipse.paho.android.service.view.View, int, long)
*/
@SuppressLint("InlinedApi")
@Override
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
clientConnections.startActionMode(this);
@ -375,7 +377,7 @@ public class ClientConnections extends ListActivity {
}
/* (non-Javadoc)
* @see android.view.ActionMode.Callback#onActionItemClicked(android.view.ActionMode, android.view.MenuItem)
* @see org.eclipse.paho.android.service.view.ActionMode.Callback#onActionItemClicked(org.eclipse.paho.android.service.view.ActionMode, org.eclipse.paho.android.service.view.MenuItem)
*/
@Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
@ -391,7 +393,7 @@ public class ClientConnections extends ListActivity {
}
/* (non-Javadoc)
* @see android.view.ActionMode.Callback#onCreateActionMode(android.view.ActionMode, android.view.Menu)
* @see org.eclipse.paho.android.service.view.ActionMode.Callback#onCreateActionMode(org.eclipse.paho.android.service.view.ActionMode, org.eclipse.paho.android.service.view.Menu)
*/
@Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
@ -402,7 +404,7 @@ public class ClientConnections extends ListActivity {
}
/* (non-Javadoc)
* @see android.view.ActionMode.Callback#onDestroyActionMode(android.view.ActionMode)
* @see org.eclipse.paho.android.service.view.ActionMode.Callback#onDestroyActionMode(org.eclipse.paho.android.service.view.ActionMode)
*/
@Override
public void onDestroyActionMode(ActionMode mode) {
@ -412,7 +414,7 @@ public class ClientConnections extends ListActivity {
}
/* (non-Javadoc)
* @see android.view.ActionMode.Callback#onPrepareActionMode(android.view.ActionMode, android.view.Menu)
* @see org.eclipse.paho.android.service.view.ActionMode.Callback#onPrepareActionMode(org.eclipse.paho.android.service.view.ActionMode, org.eclipse.paho.android.service.view.Menu)
*/
@Override
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {

View File

@ -10,19 +10,20 @@
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*/
package org.eclipse.paho.android.service.sample;
package org.eclipse.paho.android.sample;
import android.content.Context;
import android.text.Html;
import android.text.Spanned;
import org.eclipse.paho.android.service.MqttAndroidClient;
import org.eclipse.paho.client.mqttv3.MqttConnectOptions;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import org.eclipse.paho.android.service.sample.R;
import org.eclipse.paho.client.mqttv3.MqttConnectOptions;
import android.content.Context;
import android.text.Html;
import android.text.Spanned;
import org.eclipse.paho.android.service.MqttAndroidClient;
/**
*
@ -302,8 +303,8 @@ public class Connection {
}
/**
* Gets the client which communicates with the android service.
* @return the client which communicates with the android service
* Gets the client which communicates with the org.eclipse.paho.android.service service.
* @return the client which communicates with the org.eclipse.paho.android.service service
*/
public MqttAndroidClient getClient() {
return client;

View File

@ -10,12 +10,8 @@
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*/
package org.eclipse.paho.android.service.sample;
package org.eclipse.paho.android.sample;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.ArrayList;
import org.eclipse.paho.android.service.sample.R;
import android.app.ActionBar;
import android.app.FragmentTransaction;
import android.os.Bundle;
@ -26,6 +22,11 @@ import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.Menu;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.ArrayList;
import java.util.Locale;
/**
* The connection details activity operates the fragments that make up the
* connection details screen.
@ -291,11 +292,11 @@ public class ConnectionDetails extends FragmentActivity implements
public CharSequence getPageTitle(int position) {
switch (position) {
case 0 :
return getString(R.string.history).toUpperCase();
return getString(R.string.history).toUpperCase(Locale.ENGLISH);
case 1 :
return getString(R.string.subscribe).toUpperCase();
return getString(R.string.subscribe).toUpperCase(Locale.ENGLISH);
case 2 :
return getString(R.string.publish).toUpperCase();
return getString(R.string.publish).toUpperCase(Locale.ENGLISH);
}
// return null if there is no title matching the position
return null;

View File

@ -10,16 +10,16 @@
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*/
package org.eclipse.paho.android.service.sample;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
package org.eclipse.paho.android.sample;
import android.content.Context;
import org.eclipse.paho.android.service.MqttAndroidClient;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* <code>Connections</code> is a singleton class which stores all the connection objects
* in one central place so they can be passed between activities using a client

View File

@ -10,13 +10,12 @@
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*/
package org.eclipse.paho.android.service.sample;
package org.eclipse.paho.android.sample;
import android.os.Bundle;
import android.support.v4.app.ListFragment;
import android.text.Spanned;
import android.widget.ArrayAdapter;
import org.eclipse.paho.android.service.sample.R;
/**
* This fragment displays the history information for a client

View File

@ -10,7 +10,7 @@
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*/
package org.eclipse.paho.android.service.sample;
package org.eclipse.paho.android.sample;
import android.app.Activity;
import android.content.Intent;
@ -21,7 +21,6 @@ import android.view.MenuItem.OnMenuItemClickListener;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.RadioGroup;
import org.eclipse.paho.android.service.sample.R;
/**
* Activity for setting the last will message for the client

View File

@ -10,19 +10,7 @@
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*/
package org.eclipse.paho.android.service.sample;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.logging.LogManager;
import org.eclipse.paho.android.service.sample.R;
import org.eclipse.paho.client.mqttv3.MqttException;
import org.eclipse.paho.client.mqttv3.MqttSecurityException;
package org.eclipse.paho.android.sample;
import android.content.Context;
import android.content.Intent;
@ -33,9 +21,17 @@ import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.RadioGroup;
import org.eclipse.paho.android.service.sample.ActionListener.Action;
import org.eclipse.paho.android.service.sample.Connection.ConnectionStatus;
import org.eclipse.paho.android.service.MqttAndroidClient;
import org.eclipse.paho.android.sample.ActionListener.Action;
import org.eclipse.paho.android.sample.Connection.ConnectionStatus;
import org.eclipse.paho.client.mqttv3.MqttException;
import org.eclipse.paho.client.mqttv3.MqttSecurityException;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map.Entry;
import java.util.logging.LogManager;
/**
* Deals with actions performed in the {@link ClientConnections} activity
@ -266,7 +262,7 @@ public class Listener implements OnMenuItemClickListener {
createConnection = new Intent();
createConnection.setClassName(
clientConnections.getApplicationContext(),
"org.eclipse.paho.android.service.sample.NewConnection");
"org.eclipse.paho.android.sample.NewConnection");
clientConnections.startActivityForResult(createConnection,
ActivityConstants.connect);

View File

@ -10,15 +10,15 @@
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*/
package org.eclipse.paho.android.service.sample;
package org.eclipse.paho.android.sample;
import org.eclipse.paho.android.service.sample.R;
import android.content.Context;
import android.content.Intent;
import org.eclipse.paho.android.sample.Connection.ConnectionStatus;
import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken;
import org.eclipse.paho.client.mqttv3.MqttCallback;
import org.eclipse.paho.client.mqttv3.MqttMessage;
import android.content.Context;
import android.content.Intent;
import org.eclipse.paho.android.service.sample.Connection.ConnectionStatus;
/**
* Handles call backs from the MQTT Client
@ -62,7 +62,7 @@ public class MqttCallbackHandler implements MqttCallback {
//build intent
Intent intent = new Intent();
intent.setClassName(context, "org.eclipse.paho.android.service.sample.ConnectionDetails");
intent.setClassName(context, "org.eclipse.paho..service.sample.ConnectionDetails");
intent.putExtra("handle", clientHandle);
//notify the user
@ -89,7 +89,7 @@ public class MqttCallbackHandler implements MqttCallback {
//create intent to start activity
Intent intent = new Intent();
intent.setClassName(context, "org.eclipse.paho.android.service.sample.ConnectionDetails");
intent.setClassName(context, "org.eclipse.paho..service.sample.ConnectionDetails");
intent.putExtra("handle", clientHandle);
//format string args

View File

@ -10,12 +10,12 @@
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*/
package org.eclipse.paho.android.service.sample;
import org.eclipse.paho.android.service.MqttTraceHandler;
package org.eclipse.paho.android.sample;
import android.util.Log;
import org.eclipse.paho.android.service.MqttTraceHandler;
public class MqttTraceCallback implements MqttTraceHandler {
public void traceDebug(java.lang.String arg0, java.lang.String arg1) {

View File

@ -10,16 +10,8 @@
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*/
package org.eclipse.paho.android.service.sample;
package org.eclipse.paho.android.sample;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import org.eclipse.paho.android.service.sample.R;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
@ -33,6 +25,14 @@ import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.Toast;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
/**
* Handles collection of user information to create a new MQTT Client
*
@ -187,7 +187,7 @@ public class NewConnection extends Activity {
case R.id.advanced :
//start the advanced options activity
dataBundle.setClassName(newConnection,
"org.eclipse.paho.android.service.sample.Advanced");
"org.eclipse.paho.android.sample.Advanced");
newConnection.startActivityForResult(dataBundle,
ActivityConstants.advancedConnect);

View File

@ -10,10 +10,8 @@
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*/
package org.eclipse.paho.android.service.sample;
package org.eclipse.paho.android.sample;
import java.util.Calendar;
import org.eclipse.paho.android.service.sample.R;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
@ -22,6 +20,8 @@ import android.content.Intent;
import android.support.v4.app.NotificationCompat.Builder;
import android.widget.Toast;
import java.util.Calendar;
/**
* Provides static methods for creating and showing notifications to the user.
*

View File

@ -10,16 +10,9 @@
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*/
package org.eclipse.paho.android.service.sample;
package org.eclipse.paho.android.sample;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
@ -32,6 +25,13 @@ import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.Toast;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
/**
* Add SSL key file selector
* @author foxxiang

View File

@ -10,13 +10,7 @@
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*/
package org.eclipse.paho.android.service.sample;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.paho.client.mqttv3.MqttConnectOptions;
import org.eclipse.paho.client.mqttv3.MqttMessage;
package org.eclipse.paho.android.sample;
import android.content.ContentValues;
import android.content.Context;
@ -25,6 +19,12 @@ import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.provider.BaseColumns;
import org.eclipse.paho.client.mqttv3.MqttConnectOptions;
import org.eclipse.paho.client.mqttv3.MqttMessage;
import java.util.ArrayList;
import java.util.List;
/**
* <code>Persistence</code> deals with interacting with the database to persist
* {@link Connection} objects so created clients survive, the destruction of the
@ -113,7 +113,7 @@ public class Persistence extends SQLiteOpenHelper implements BaseColumns {
}
/* (non-Javadoc)
* @see android.database.sqlite.SQLiteOpenHelper#onCreate(android.database.sqlite.SQLiteDatabase)
* @see org.eclipse.paho.android.service.database.sqlite.SQLiteOpenHelper#onCreate(org.eclipse.paho.android.service.database.sqlite.SQLiteDatabase)
*/
@Override
public void onCreate(SQLiteDatabase db) {
@ -122,7 +122,7 @@ public class Persistence extends SQLiteOpenHelper implements BaseColumns {
}
/* (non-Javadoc)
* @see android.database.sqlite.SQLiteOpenHelper#onUpgrade(android.database.sqlite.SQLiteDatabase, int, int)
* @see org.eclipse.paho.android.service.database.sqlite.SQLiteOpenHelper#onUpgrade(org.eclipse.paho.android.service.database.sqlite.SQLiteDatabase, int, int)
*/
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
@ -131,7 +131,7 @@ public class Persistence extends SQLiteOpenHelper implements BaseColumns {
/*
* (non-Javadoc)
* @see android.database.sqlite.SQLiteOpenHelper#onDowngrade(android.database.sqlite.SQLiteDatabase, int, int)
* @see org.eclipse.paho.android.service.database.sqlite.SQLiteOpenHelper#onDowngrade(org.eclipse.paho.android.service.database.sqlite.SQLiteDatabase, int, int)
*/
@Override
public void onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion) {

View File

@ -10,7 +10,7 @@
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*/
package org.eclipse.paho.android.service.sample;
package org.eclipse.paho.android.sample;
/**
* Persistence Exception, defines an error with persisting a {@link Connection}

View File

@ -10,14 +10,13 @@
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*/
package org.eclipse.paho.android.service.sample;
package org.eclipse.paho.android.sample;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import org.eclipse.paho.android.service.sample.R;
/**
* Fragment for the publish message pane.

View File

@ -10,14 +10,13 @@
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*/
package org.eclipse.paho.android.service.sample;
package org.eclipse.paho.android.sample;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import org.eclipse.paho.android.service.sample.R;
/**
* Fragment for the subscribe pane for the client

View File

Before

Width:  |  Height:  |  Size: 397 B

After

Width:  |  Height:  |  Size: 397 B

View File

Before

Width:  |  Height:  |  Size: 6.1 KiB

After

Width:  |  Height:  |  Size: 6.1 KiB

View File

Before

Width:  |  Height:  |  Size: 209 B

After

Width:  |  Height:  |  Size: 209 B

View File

Before

Width:  |  Height:  |  Size: 2.1 KiB

After

Width:  |  Height:  |  Size: 2.1 KiB

View File

Before

Width:  |  Height:  |  Size: 270 B

After

Width:  |  Height:  |  Size: 270 B

View File

Before

Width:  |  Height:  |  Size: 3.2 KiB

After

Width:  |  Height:  |  Size: 3.2 KiB

View File

Before

Width:  |  Height:  |  Size: 513 B

After

Width:  |  Height:  |  Size: 513 B

View File

Before

Width:  |  Height:  |  Size: 8.8 KiB

After

Width:  |  Height:  |  Size: 8.8 KiB

View File

@ -33,7 +33,7 @@ IBM Corp.
<string name="history">History</string>
<string name="title_activity_history">History</string>
<string name="subscribed">Subscribed to </string>
<string name="token">org.eclipse.paho.android.service.sample.ClientConnections</string>
<string name="token">org.eclipse.paho.android.sample.ClientConnections</string>
<string name="no_status">Unknown connection status to</string>
<string name="connecting">Connecting to</string>
<string name="disconnecting">Disconnecting from</string>

View File

@ -1,10 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="gen"/>
<classpathentry kind="lib" path="libs/android-support-v4.jar"/>
<classpathentry kind="output" path="bin/classes"/>
</classpath>

View File

@ -1,33 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>org.eclipse.paho.android.service.sample</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>

View File

@ -1,92 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project name="ClientConnections" default="help">
<!-- The local.properties file is created and updated by the 'android' tool.
It contains the path to the SDK. It should *NOT* be checked into
Version Control Systems. -->
<property file="local.properties" />
<!-- The ant.properties file can be created by you. It is only edited by the
'android' tool to add properties to it.
This is the place to change some Ant specific build properties.
Here are some properties you may want to change/update:
source.dir
The name of the source directory. Default is 'src'.
out.dir
The name of the output directory. Default is 'bin'.
For other overridable properties, look at the beginning of the rules
files in the SDK, at tools/ant/build.xml
Properties related to the SDK location or the project target should
be updated using the 'android' tool with the 'update' action.
This file is an integral part of the build system for your
application and should be checked into Version Control Systems.
-->
<property file="ant.properties" />
<!-- if sdk.dir was not set from one of the property file, then
get it from the ANDROID_HOME env var.
This must be done before we load project.properties since
the proguard config can use sdk.dir -->
<property environment="env" />
<condition property="sdk.dir" value="${env.ANDROID_HOME}">
<isset property="env.ANDROID_HOME" />
</condition>
<!-- The project.properties file is created and updated by the 'android'
tool, as well as ADT.
This contains project specific properties such as project target, and library
dependencies. Lower level build properties are stored in ant.properties
(or in .classpath for Eclipse projects).
This file is an integral part of the build system for your
application and should be checked into Version Control Systems. -->
<loadproperties srcFile="project.properties" />
<!-- quick check on sdk.dir -->
<fail
message="sdk.dir is missing. Make sure to generate local.properties using 'android update project' or to inject it through the ANDROID_HOME environment variable."
unless="sdk.dir"
/>
<!--
Import per project custom build rules if present at the root of the project.
This is the place to put custom intermediary targets such as:
-pre-build
-pre-compile
-post-compile (This is typically used for code obfuscation.
Compiled code location: ${out.classes.absolute.dir}
If this is not done in place, override ${out.dex.input.absolute.dir})
-post-package
-post-build
-pre-clean
-->
<import file="custom_rules.xml" optional="true" />
<!-- Import the actual build file.
To customize existing targets, there are two options:
- Customize only one target:
- copy/paste the target into this file, *before* the
<import> task.
- customize it to your needs.
- Customize the whole content of build.xml
- copy/paste the content of the rules files (minus the top node)
into this file, replacing the <import> task.
- customize to your needs.
***********************
****** IMPORTANT ******
***********************
In all cases you must update the value of version-tag below to read 'custom' instead of an integer,
in order to avoid having your file be overridden by tools such as "android update project"
-->
<!-- version-tag: 1 -->
<import file="${sdk.dir}/tools/ant/build.xml" />
</project>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 77 KiB

View File

@ -1,14 +0,0 @@
# 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
# Project target.
target=android-19

View File

@ -1,9 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="gen"/>
<classpathentry kind="output" path="bin/classes"/>
</classpath>

View File

@ -1,34 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>org.eclipse.paho.android.service.test</name>
<comment></comment>
<projects>
<project>org.eclipse.paho.android.service</project>
</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>

View File

@ -1,26 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.eclipse.paho.android.service.test"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="9" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<instrumentation
android:name="android.test.InstrumentationTestRunner"
android:targetPackage="org.eclipse.paho.android.service.test" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<uses-library android:name="android.test.runner" />
<service android:name="org.eclipse.paho.android.service.MqttService" >
</service>
</application>
</manifest>

View File

@ -1,92 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project name="org.eclipse.paho.android.service.test" default="help">
<!-- The local.properties file is created and updated by the 'android' tool.
It contains the path to the SDK. It should *NOT* be checked into
Version Control Systems. -->
<property file="local.properties" />
<!-- The ant.properties file can be created by you. It is only edited by the
'android' tool to add properties to it.
This is the place to change some Ant specific build properties.
Here are some properties you may want to change/update:
source.dir
The name of the source directory. Default is 'src'.
out.dir
The name of the output directory. Default is 'bin'.
For other overridable properties, look at the beginning of the rules
files in the SDK, at tools/ant/build.xml
Properties related to the SDK location or the project target should
be updated using the 'android' tool with the 'update' action.
This file is an integral part of the build system for your
application and should be checked into Version Control Systems.
-->
<property file="ant.properties" />
<!-- if sdk.dir was not set from one of the property file, then
get it from the ANDROID_HOME env var.
This must be done before we load project.properties since
the proguard config can use sdk.dir -->
<property environment="env" />
<condition property="sdk.dir" value="${env.ANDROID_HOME}">
<isset property="env.ANDROID_HOME" />
</condition>
<!-- The project.properties file is created and updated by the 'android'
tool, as well as ADT.
This contains project specific properties such as project target, and library
dependencies. Lower level build properties are stored in ant.properties
(or in .classpath for Eclipse projects).
This file is an integral part of the build system for your
application and should be checked into Version Control Systems. -->
<loadproperties srcFile="project.properties" />
<!-- quick check on sdk.dir -->
<fail
message="sdk.dir is missing. Make sure to generate local.properties using 'android update project' or to inject it through the ANDROID_HOME environment variable."
unless="sdk.dir"
/>
<!--
Import per project custom build rules if present at the root of the project.
This is the place to put custom intermediary targets such as:
-pre-build
-pre-compile
-post-compile (This is typically used for code obfuscation.
Compiled code location: ${out.classes.absolute.dir}
If this is not done in place, override ${out.dex.input.absolute.dir})
-post-package
-post-build
-pre-clean
-->
<import file="custom_rules.xml" optional="true" />
<!-- Import the actual build file.
To customize existing targets, there are two options:
- Customize only one target:
- copy/paste the target into this file, *before* the
<import> task.
- customize it to your needs.
- Customize the whole content of build.xml
- copy/paste the content of the rules files (minus the top node)
into this file, replacing the <import> task.
- customize to your needs.
***********************
****** IMPORTANT ******
***********************
In all cases you must update the value of version-tag below to read 'custom' instead of an integer,
in order to avoid having your file be overridden by tools such as "android update project"
-->
<!-- version-tag: 1 -->
<import file="${sdk.dir}/tools/ant/build.xml" />
</project>

View File

@ -1,14 +0,0 @@
# 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
# Project target.
target=android-19

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

View File

@ -1,6 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">Org.eclipse.paho.android.service.testTest</string>
</resources>

View File

@ -1,758 +0,0 @@
/*******************************************************************************
* Copyright (c) 2014 IBM Corp.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Eclipse Distribution License v1.0 which accompany this distribution.
*
* The Eclipse Public License is available at
* http://www.eclipse.org/legal/epl-v10.html
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*/
package org.eclipse.paho.android.service.test;
import java.util.concurrent.TimeUnit;
import junit.framework.Assert;
import org.eclipse.paho.client.mqttv3.IMqttActionListener;
import org.eclipse.paho.client.mqttv3.IMqttAsyncClient;
import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken;
import org.eclipse.paho.client.mqttv3.IMqttToken;
import org.eclipse.paho.client.mqttv3.MqttConnectOptions;
import org.eclipse.paho.client.mqttv3.MqttMessage;
import android.content.Intent;
import android.os.IBinder;
import android.test.ServiceTestCase;
import android.util.Log;
import org.eclipse.paho.android.service.MqttAndroidClient;
/**
* @author Rhys
*
*/
public class AndroidServiceWithActionListenerTest extends ServiceTestCase {
private IBinder binder;
private String serverURI;
private String mqttSSLServerURI;
private int waitForCompletionTime;
private String clientKeyStore;
private String keyStorePwd;
//since we know tokens do not work when an action listener isn't specified
private TestCaseNotifier notifier = new TestCaseNotifier();
private String classCanonicalName = this.getClass().getCanonicalName();
/**
* @param serviceClass
*/
public AndroidServiceWithActionListenerTest() {
super(org.eclipse.paho.android.service.MqttService.class);
}
@Override
protected void setUp() throws Exception {
super.setUp();
Intent intent = new Intent();
intent.setClassName("org.eclipse.paho.android.service", "MqttService");
binder = bindService(intent);
TestProperties properties = new TestProperties(this.getContext());
serverURI = properties.getServerURI();
mqttSSLServerURI = properties.getServerSSLURI();
waitForCompletionTime = properties.getWaitForCompletionTime();
clientKeyStore = properties.getClientKeyStore();
keyStorePwd = properties.getClientKeyStorePassword();
}
public void testConnect() throws Throwable {
IMqttAsyncClient mqttClient = null;
mqttClient = new MqttAndroidClient(mContext, serverURI, "testConnect");
IMqttToken connectToken = null;
IMqttToken disconnectToken = null;
connectToken = mqttClient.connect(null, new ActionListener(notifier));
notifier.waitForCompletion(waitForCompletionTime);
disconnectToken = mqttClient.disconnect(null, new ActionListener(notifier));
notifier.waitForCompletion(waitForCompletionTime);
connectToken = mqttClient.connect(null, new ActionListener(notifier));
notifier.waitForCompletion(waitForCompletionTime);
disconnectToken = mqttClient.disconnect(null, new ActionListener(notifier));
notifier.waitForCompletion(waitForCompletionTime);
}
public void testRemoteConnect() throws Throwable {
String methodName = "testRemoteConnect";
IMqttAsyncClient mqttClient = null;
mqttClient = mqttClient = new MqttAndroidClient(mContext, serverURI, "testRemoteConnect");
IMqttToken connectToken = null;
IMqttToken subToken = null;
IMqttDeliveryToken pubToken = null;
IMqttToken disconnectToken = null;
connectToken = mqttClient.connect(null, new ActionListener(notifier));
notifier.waitForCompletion(waitForCompletionTime);
disconnectToken = mqttClient.disconnect(null, new ActionListener(notifier));
notifier.waitForCompletion(waitForCompletionTime);
MqttV3Receiver mqttV3Receiver = new MqttV3Receiver(mqttClient,
null);
mqttClient.setCallback(mqttV3Receiver);
MqttConnectOptions mqttConnectOptions = new MqttConnectOptions();
mqttConnectOptions.setCleanSession(false);
connectToken = mqttClient.connect(mqttConnectOptions, null, new ActionListener(notifier));
notifier.waitForCompletion(waitForCompletionTime);
String[] topicNames = new String[]{methodName + "/Topic"};
int[] topicQos = {0};
subToken = mqttClient.subscribe(topicNames, topicQos, null, new ActionListener(notifier));
notifier.waitForCompletion(waitForCompletionTime);
byte[] payload = ("Message payload " + classCanonicalName + "." + methodName)
.getBytes();
pubToken = mqttClient.publish(topicNames[0], payload, 1, false, null, new ActionListener(notifier));
notifier.waitForCompletion(waitForCompletionTime);
boolean ok = mqttV3Receiver.validateReceipt(topicNames[0], 0,
payload);
if (!ok) {
Assert.fail("Receive failed");
}
disconnectToken = mqttClient.disconnect(null, new ActionListener(notifier));
notifier.waitForCompletion(waitForCompletionTime);
}
public void testLargeMessage() throws Throwable {
notifier = new TestCaseNotifier();
String methodName = "testLargeMessage";
IMqttAsyncClient mqttClient = null;
try {
mqttClient = new MqttAndroidClient(mContext, serverURI,
"testLargeMessage");
IMqttToken connectToken;
IMqttToken subToken;
IMqttToken unsubToken;
IMqttDeliveryToken pubToken;
MqttV3Receiver mqttV3Receiver = new MqttV3Receiver(mqttClient, null); //TODO do something about this?
mqttClient.setCallback(mqttV3Receiver);
connectToken = mqttClient.connect(null, new ActionListener(notifier));
notifier.waitForCompletion(waitForCompletionTime);
int largeSize = 1000;
String[] topicNames = new String[]{"testLargeMessage" + "/Topic"};
int[] topicQos = {0};
byte[] message = new byte[largeSize];
java.util.Arrays.fill(message, (byte) 's');
subToken = mqttClient.subscribe(topicNames, topicQos, null, new ActionListener(notifier));
notifier.waitForCompletion(waitForCompletionTime);
unsubToken = mqttClient.unsubscribe(topicNames, null, new ActionListener(notifier));
notifier.waitForCompletion(waitForCompletionTime);
subToken = mqttClient.subscribe(topicNames, topicQos, null, new ActionListener(notifier));
notifier.waitForCompletion(waitForCompletionTime);
pubToken = mqttClient.publish(topicNames[0], message, 0, false, null, new ActionListener(notifier));
notifier.waitForCompletion(waitForCompletionTime);
boolean ok = mqttV3Receiver.validateReceipt(topicNames[0], 0,
message);
if (!ok) {
Assert.fail("Receive failed");
}
}
catch (Exception exception) {
Assert.fail("Failed to instantiate:" + methodName + " exception="
+ exception);
}
finally {
try {
IMqttToken disconnectToken;
disconnectToken = mqttClient.disconnect(null, new ActionListener(notifier));
notifier.waitForCompletion(waitForCompletionTime);
mqttClient.close();
}
catch (Exception exception) {
}
}
}
public void testMultipleClients() throws Throwable {
int publishers = 2;
int subscribers = 5;
String methodName = "testMultipleClients";
IMqttAsyncClient[] mqttPublisher = new IMqttAsyncClient[publishers];
IMqttAsyncClient[] mqttSubscriber = new IMqttAsyncClient[subscribers];
IMqttToken connectToken;
IMqttToken subToken;
IMqttDeliveryToken pubToken;
IMqttToken disconnectToken;
String[] topicNames = new String[]{methodName + "/Topic"};
int[] topicQos = {0};
for (int i = 0; i < mqttPublisher.length; i++) {
mqttPublisher[i] = new MqttAndroidClient(mContext,
serverURI, "MultiPub" + i);
connectToken = mqttPublisher[i].connect(null, new ActionListener(notifier));
notifier.waitForCompletion(waitForCompletionTime);
} // for...
MqttV3Receiver[] mqttV3Receiver = new MqttV3Receiver[mqttSubscriber.length];
for (int i = 0; i < mqttSubscriber.length; i++) {
mqttSubscriber[i] = new MqttAndroidClient(mContext,
serverURI, "MultiSubscriber" + i);
mqttV3Receiver[i] = new MqttV3Receiver(mqttSubscriber[i],
null);
mqttSubscriber[i].setCallback(mqttV3Receiver[i]);
connectToken = mqttSubscriber[i].connect(null, new ActionListener(notifier));
notifier.waitForCompletion(waitForCompletionTime);
subToken = mqttSubscriber[i].subscribe(topicNames, topicQos, null, new ActionListener(notifier));
notifier.waitForCompletion(waitForCompletionTime);
} // for...
for (int iMessage = 0; iMessage < 2; iMessage++) {
byte[] payload = ("Message " + iMessage).getBytes();
for (int i = 0; i < mqttPublisher.length; i++) {
pubToken = mqttPublisher[i].publish(topicNames[0], payload, 0, false,
null, new ActionListener(notifier));
notifier.waitForCompletion(waitForCompletionTime);
}
TimeUnit.MILLISECONDS.sleep(30000);
for (int i = 0; i < mqttSubscriber.length; i++) {
for (int ii = 0; ii < mqttPublisher.length; ii++) {
boolean ok = mqttV3Receiver[i].validateReceipt(
topicNames[0], 0, payload);
if (!ok) {
Assert.fail("Receive failed");
}
} // for publishers...
} // for subscribers...
} // for messages...
for (int i = 0; i < mqttPublisher.length; i++) {
disconnectToken = mqttPublisher[i].disconnect(null, null);
disconnectToken.waitForCompletion(waitForCompletionTime);
mqttPublisher[i].close();
}
for (int i = 0; i < mqttSubscriber.length; i++) {
disconnectToken = mqttSubscriber[i].disconnect(null, null);
disconnectToken.waitForCompletion(waitForCompletionTime);
mqttSubscriber[i].close();
}
}
// public void testNonDurableSubs() throws Throwable {
// String methodName = "testNonDurableSubs";
// notifier = new TestCaseNotifier();
// IMqttAsyncClient mqttClient = null;
//
// IMqttToken connectToken;
// IMqttToken subToken;
// IMqttToken unsubToken;
// IMqttDeliveryToken pubToken;
// IMqttToken disconnectToken;
//
// mqttClient = new MqttAndroidClient(mContext, serverURI,
// "testNonDurableSubs");
// MqttV3Receiver mqttV3Receiver = new MqttV3Receiver(mqttClient,
// null);
// mqttClient.setCallback(mqttV3Receiver);
// MqttConnectOptions mqttConnectOptions = new MqttConnectOptions();
// // Clean session true is the default and implies non durable
// // subscriptions.
// mqttConnectOptions.setCleanSession(true);
// connectToken = mqttClient.connect(mqttConnectOptions, null, new ActionListener(notifier));
// notifier.waitForCompletion(1000);
//
// String[] topicNames = new String[]{methodName + "/Topic"};
// int[] topicQos = {2};
// subToken = mqttClient.subscribe(topicNames, topicQos, null, new ActionListener(notifier));
// notifier.waitForCompletion(1000);
//
// byte[] payloadNotRetained = ("Message payload "
// + classCanonicalName + "." + methodName + " not retained")
// .getBytes();
// pubToken = mqttClient.publish(topicNames[0], payloadNotRetained, 2, false,
// null, new ActionListener(notifier));
// notifier.waitForCompletion(1000);
//
// boolean ok = mqttV3Receiver.validateReceipt(topicNames[0], 2,
// payloadNotRetained);
// if (!ok) {
// Assert.fail("Receive failed");
// }
//
// // Retained publications.
// // ----------------------
// byte[] payloadRetained = ("Message payload " + classCanonicalName
// + "." + methodName + " retained").getBytes();
// pubToken = mqttClient.publish(topicNames[0], payloadRetained, 2, true,
// null, new ActionListener(notifier));
// notifier.waitForCompletion(1000);
//
// ok = mqttV3Receiver.validateReceipt(topicNames[0], 2,
// payloadRetained);
// if (!ok) {
// Assert.fail("Receive failed");
// }
//
// // Check that unsubscribe and re subscribe resends the publication.
// unsubToken = mqttClient.unsubscribe(topicNames, null, new ActionListener(notifier));
// notifier.waitForCompletion(1000);
//
// subToken = mqttClient.subscribe(topicNames, topicQos, null, new ActionListener(notifier));
// notifier.waitForCompletion(1000);
//
// ok = mqttV3Receiver.validateReceipt(topicNames[0], 2,
// payloadRetained);
// if (!ok) {
// Assert.fail("Receive failed");
// }
//
// // Check that subscribe without unsubscribe receives the
// // publication.
// subToken = mqttClient.subscribe(topicNames, topicQos, null, new ActionListener(notifier));
// notifier.waitForCompletion(1000);
// ok = mqttV3Receiver.validateReceipt(topicNames[0], 2,
// payloadRetained);
// if (!ok) {
// Assert.fail("Receive failed");
// }
//
// // Disconnect, reconnect and check that the retained publication is
// // still delivered.
// disconnectToken = mqttClient.disconnect(null, new ActionListener(notifier));
// notifier.waitForCompletion(1000);
//
// mqttClient.close();
//
// mqttClient = new MqttAndroidClient(mContext, serverURI,
// "testNonDurableSubs");
//
// mqttV3Receiver = new MqttV3Receiver(mqttClient,
// null);
// mqttClient.setCallback(mqttV3Receiver);
//
// mqttConnectOptions = new MqttConnectOptions();
// mqttConnectOptions.setCleanSession(true);
// connectToken = mqttClient.connect(mqttConnectOptions, null, new ActionListener(notifier));
// connectToken.waitForCompletion(1000);
//
// subToken = mqttClient.subscribe(topicNames, topicQos, null, new ActionListener(notifier));
// notifier.waitForCompletion(1000);
//
// ok = mqttV3Receiver.validateReceipt(topicNames[0], 2,
// payloadRetained);
// if (!ok) {
// Assert.fail("Receive failed");
// }
//
// disconnectToken = mqttClient.disconnect(null, new ActionListener(notifier));
// notifier.waitForCompletion(1000);
//
// mqttClient.close();
//
// }
public void testQoSPreserved() throws Throwable {
IMqttAsyncClient mqttClient = null;
IMqttToken connectToken;
IMqttToken subToken;
IMqttDeliveryToken pubToken;
IMqttToken disconnectToken;
String methodName = "testQoSPreserved";
mqttClient = new MqttAndroidClient(mContext, serverURI, "testQoSPreserved");
MqttV3Receiver mqttV3Receiver = new MqttV3Receiver(mqttClient,
null);
mqttClient.setCallback(mqttV3Receiver);
connectToken = mqttClient.connect(null, new ActionListener(notifier));
notifier.waitForCompletion(waitForCompletionTime);
String[] topicNames = new String[]{methodName + "/Topic0",
methodName + "/Topic1", methodName + "/Topic2"};
int[] topicQos = {0, 1, 2};
subToken = mqttClient.subscribe(topicNames, topicQos, null, new ActionListener(notifier));
notifier.waitForCompletion(waitForCompletionTime);
for (int i = 0; i < topicNames.length; i++) {
byte[] message = ("Message payload " + classCanonicalName + "."
+ methodName + " " + topicNames[i]).getBytes();
for (int iQos = 0; iQos < 3; iQos++) {
pubToken = mqttClient.publish(topicNames[i], message, iQos, false,
null, null);
notifier.waitForCompletion(waitForCompletionTime);
boolean ok = mqttV3Receiver.validateReceipt(topicNames[i],
Math.min(iQos, topicQos[i]), message);
if (!ok) {
Assert.fail("Receive failed sub Qos=" + topicQos[i]
+ " PublishQos=" + iQos);
}
}
}
disconnectToken = mqttClient.disconnect(null, new ActionListener(notifier));
notifier.waitForCompletion(waitForCompletionTime);
}
public void testHAConnect() throws Throwable{
String methodName = "testHAConnect";
IMqttAsyncClient client = null;
try {
try {
String junk = "tcp://junk:123";
client = new MqttAndroidClient(mContext, junk, methodName);
String[] urls = new String[]{"tcp://junk", serverURI};
MqttConnectOptions options = new MqttConnectOptions();
options.setServerURIs(urls);
Log.i(methodName,"HA connect");
IMqttToken connectToken = client.connect(options, null, new ActionListener(notifier));
notifier.waitForCompletion(waitForCompletionTime);
Log.i(methodName,"HA disconnect");
IMqttToken disconnectToken = client.disconnect(null, new ActionListener(notifier));
notifier.waitForCompletion(waitForCompletionTime);
Log.i(methodName,"HA success");
}
catch (Exception e) {
e.printStackTrace();
throw e;
}
}
finally {
if (client != null) {
client.close();
}
}
}
public void testPubSub() throws Throwable{
String methodName = "testPubSub";
IMqttAsyncClient mqttClient = null;
try {
mqttClient = new MqttAndroidClient(mContext, serverURI, methodName);
IMqttToken connectToken;
IMqttToken subToken;
IMqttDeliveryToken pubToken;
MqttV3Receiver mqttV3Receiver = new MqttV3Receiver(mqttClient, null);
mqttClient.setCallback(mqttV3Receiver);
connectToken = mqttClient.connect(null, new ActionListener(notifier));
notifier.waitForCompletion(waitForCompletionTime);
String[] topicNames = new String[]{"testPubSub" + "/Topic"};
int[] topicQos = {0};
MqttMessage mqttMessage = new MqttMessage("message for testPubSub".getBytes());
byte[] message = mqttMessage.getPayload();
subToken = mqttClient.subscribe(topicNames, topicQos, null, new ActionListener(notifier));
notifier.waitForCompletion(waitForCompletionTime);
pubToken = mqttClient.publish(topicNames[0], message, 0, false, null, new ActionListener(notifier));
notifier.waitForCompletion(waitForCompletionTime);
TimeUnit.MILLISECONDS.sleep(3000);
boolean ok = mqttV3Receiver.validateReceipt(topicNames[0], 0, message);
if (!ok) {
Assert.fail("Receive failed");
}
}
catch (Exception exception) {
Assert.fail("Failed to instantiate:" + methodName + " exception="
+ exception);
}
finally {
try {
IMqttToken disconnectToken;
disconnectToken = mqttClient.disconnect(null, new ActionListener(notifier));
notifier.waitForCompletion(waitForCompletionTime);
mqttClient.close();
}
catch (Exception exception) {
}
}
}
public void testRetainedMessage() throws Throwable{
String methodName = "testRetainedMessage";
IMqttAsyncClient mqttClient = null;
IMqttAsyncClient mqttClientRetained = null;
IMqttToken disconnectToken = null;
try {
mqttClient = new MqttAndroidClient(mContext, serverURI, methodName);
IMqttToken connectToken;
IMqttToken subToken;
IMqttDeliveryToken pubToken;
MqttV3Receiver mqttV3Receiver = new MqttV3Receiver(mqttClient, null);
mqttClient.setCallback(mqttV3Receiver);
connectToken = mqttClient.connect(null, new ActionListener(notifier));
notifier.waitForCompletion(waitForCompletionTime);
String[] topicNames = new String[]{"testRetainedMessage" + "/Topic"};
int[] topicQos = {0};
MqttMessage mqttMessage = new MqttMessage("message for testPubSub".getBytes());
byte[] message = mqttMessage.getPayload();
subToken = mqttClient.subscribe(topicNames, topicQos, null, new ActionListener(notifier));
notifier.waitForCompletion(waitForCompletionTime);
pubToken = mqttClient.publish(topicNames[0], message, 0, true, null, new ActionListener(notifier));
notifier.waitForCompletion(waitForCompletionTime);
TimeUnit.MILLISECONDS.sleep(3000);
boolean ok = mqttV3Receiver.validateReceipt(topicNames[0], 0, message);
if (!ok) {
Assert.fail("Receive failed");
}
Log.i(methodName, "First client received message successfully");
disconnectToken = mqttClient.disconnect(null, new ActionListener(notifier));
notifier.waitForCompletion(waitForCompletionTime);
mqttClient.close();
mqttClientRetained = new MqttAndroidClient(mContext, serverURI, "Retained");
Log.i(methodName, "New MqttAndroidClient mqttClientRetained");
MqttV3Receiver mqttV3ReceiverRetained = new MqttV3Receiver(mqttClientRetained, null);
mqttClientRetained.setCallback(mqttV3ReceiverRetained);
Log.i(methodName, "Assigning callback...");
connectToken = mqttClientRetained.connect(null, new ActionListener(notifier));
notifier.waitForCompletion(waitForCompletionTime);
Log.i(methodName, "Connect to mqtt server");
subToken = mqttClientRetained.subscribe(topicNames, topicQos, null, new ActionListener(notifier));
notifier.waitForCompletion(waitForCompletionTime);
Log.i(methodName, "subscribe "+topicNames[0].toString() + " QoS is " + topicQos[0]);
TimeUnit.MILLISECONDS.sleep(3000);
ok = mqttV3ReceiverRetained.validateReceipt(topicNames[0], 0, message);
if (!ok) {
Assert.fail("Receive retained message failed");
}
Log.i(methodName, "Second client received message successfully");
disconnectToken = mqttClientRetained.disconnect(null, new ActionListener(notifier));
notifier.waitForCompletion(waitForCompletionTime);
mqttClientRetained.close();
}
catch (Exception exception) {
Assert.fail("Failed to instantiate:" + methodName + " exception="
+ exception);
}
}
/**
* Tests that a client can be constructed and that it can connect to and
* disconnect from the service via SSL
*
* @throws Exception
*/
public void testSSLConnect() throws Exception {
MqttAndroidClient mqttClient = null;
try {
mqttClient = new MqttAndroidClient(mContext, mqttSSLServerURI, "testSSLConnect");
MqttConnectOptions options = new MqttConnectOptions();
options.setSocketFactory(mqttClient.getSSLSocketFactory(this.getContext().getResources().openRawResource(R.raw.test),keyStorePwd));
IMqttToken connectToken = null;
IMqttToken disconnectToken = null;
connectToken = mqttClient.connect(options, this.getContext(), new ActionListener(notifier));
connectToken.waitForCompletion(waitForCompletionTime);
disconnectToken = mqttClient.disconnect(null, new ActionListener(notifier));
disconnectToken.waitForCompletion(waitForCompletionTime);
connectToken = mqttClient.connect(options, this.getContext(), new ActionListener(notifier));
connectToken.waitForCompletion(waitForCompletionTime);
disconnectToken = mqttClient.disconnect(null, new ActionListener(notifier));
disconnectToken.waitForCompletion(waitForCompletionTime);
}
catch (Exception exception) {
Assert.fail("Failed:" + "testSSLConnect" + " exception=" + exception);
}
finally {
if (mqttClient != null) {
mqttClient.close();
}
}
}
/**
* An SSL connection with server cert authentication, simple pub/sub of an message
*
* @throws Exception
*/
public void testSSLPubSub() throws Exception {
MqttAndroidClient mqttClient = null;
IMqttToken connectToken = null;
IMqttToken disconnectToken = null;
IMqttToken subToken = null;
IMqttDeliveryToken pubToken = null;
try {
mqttClient = new MqttAndroidClient(mContext, mqttSSLServerURI, "testSSLPubSub");
MqttConnectOptions options = new MqttConnectOptions();
options.setSocketFactory(mqttClient.getSSLSocketFactory(this.getContext().getResources().openRawResource(R.raw.test),keyStorePwd));
MqttV3Receiver mqttV3Receiver = new MqttV3Receiver(mqttClient, null);
mqttClient.setCallback(mqttV3Receiver);
connectToken = mqttClient.connect(options,this.getContext(),new ActionListener(notifier));
connectToken.waitForCompletion(waitForCompletionTime);
String[] topicNames = new String[]{"testSSLPubSub"+"/Topic"};
int[] topicQos = {0};
MqttMessage mqttMessage = new MqttMessage(("message for testSSLPubSub").getBytes());
byte[] message = mqttMessage.getPayload();
subToken = mqttClient.subscribe(topicNames, topicQos, null, new ActionListener(notifier));
subToken.waitForCompletion(waitForCompletionTime);
pubToken = mqttClient.publish(topicNames[0], message, 0, false, null, new ActionListener(notifier));
pubToken.waitForCompletion(waitForCompletionTime);
TimeUnit.MILLISECONDS.sleep(6000);
boolean ok = mqttV3Receiver.validateReceipt(topicNames[0], 0, message);
if (!ok) {
Assert.fail("Receive failed");
}
}
catch (Exception exception) {
Assert.fail("Failed:" + "testSSLPubSub" + " exception=" + exception);
}
finally {
disconnectToken = mqttClient.disconnect(null, new ActionListener(notifier));
disconnectToken.waitForCompletion(waitForCompletionTime);
if (mqttClient != null) {
mqttClient.close();
}
}
}
private class ActionListener implements IMqttActionListener {
private TestCaseNotifier notifier = null;
public ActionListener(TestCaseNotifier notifier) {
this.notifier = notifier;
}
/* (non-Javadoc)
* @see org.eclipse.paho.client.mqttv3.IMqttActionListener#onFailure(org.eclipse.paho.client.mqttv3.IMqttToken, java.lang.Throwable)
*/
public void onFailure(IMqttToken token, Throwable exception) {
notifier.storeException(exception);
synchronized (notifier) {
notifier.notifyAll();
}
}
/* (non-Javadoc)
* @see org.eclipse.paho.client.mqttv3.IMqttActionListener#onSuccess(org.eclipse.paho.client.mqttv3.IMqttToken)
*/
public void onSuccess(IMqttToken token) {
synchronized (notifier) {
notifier.notifyAll();
}
}
}
}

View File

@ -1,434 +0,0 @@
/*******************************************************************************
* Copyright (c) 2010, 2014 IBM Corp.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Eclipse Distribution License v1.0 which accompany this distribution.
*
* The Eclipse Public License is available at
* http://www.eclipse.org/legal/epl-v10.html
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*/
package org.eclipse.paho.android.service.test;
import java.io.PrintStream;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Date;
import java.util.concurrent.TimeUnit;
import org.eclipse.paho.client.mqttv3.IMqttAsyncClient;
import org.eclipse.paho.client.mqttv3.IMqttClient;
import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken;
import org.eclipse.paho.client.mqttv3.MqttCallback;
import org.eclipse.paho.client.mqttv3.MqttException;
import org.eclipse.paho.client.mqttv3.MqttMessage;
import android.util.Log;
/**
* Listen for in bound messages and connection loss.
*
* @version %Z% %H%
* @author Andrew_Banks
*/
public class MqttV3Receiver implements MqttCallback {
private final java.io.PrintStream reportStream;
private boolean reportConnectionLoss = true;
private boolean connected = false;
private String clientId;
/**
* For the in bound message.
*/
public class ReceivedMessage {
/** */
public String topic;
/** */
public MqttMessage message;
ReceivedMessage(String topic, MqttMessage message) {
this.topic = topic;
this.message = message;
}
}
java.util.List<ReceivedMessage> receivedMessages = Collections.synchronizedList(new java.util.ArrayList<ReceivedMessage>());
/**
* @param mqttClient
* @param reportStream
*/
public MqttV3Receiver(IMqttClient mqttClient, PrintStream reportStream) {
this.reportStream = reportStream;
connected = true;
clientId = mqttClient.getClientId();
}
public MqttV3Receiver(IMqttAsyncClient mqttClient, PrintStream reportStream) {
this.reportStream = reportStream;
connected = true;
clientId = mqttClient.getClientId();
}
/**
* @return flag
*/
public final boolean isReportConnectionLoss() {
return reportConnectionLoss;
}
/**
* @param reportConnectionLoss
*/
public final void setReportConnectionLoss(boolean reportConnectionLoss) {
this.reportConnectionLoss = reportConnectionLoss;
}
/**
* @param waitMilliseconds
* @return message
* @throws InterruptedException
*/
public ReceivedMessage receiveNext(long waitMilliseconds)
throws InterruptedException {
final String methodName = "receiveNext";
ReceivedMessage receivedMessage = null;
if (receivedMessages.isEmpty()) {
// wait(waitMilliseconds);
TimeUnit.MILLISECONDS.sleep(waitMilliseconds);
}
Log.i(methodName, "receiveNext time is "+new Date().toString());
Log.i(methodName, "receivedMessages = "+receivedMessages.toString());
if (!receivedMessages.isEmpty()) {
Log.i(methodName, "MqttV3Receiver receive message");
receivedMessage = receivedMessages.remove(0);
}
return receivedMessage;
}
/**
* @param sendTopic
* @param expectedQos
* @param sentBytes
* @return flag
* @throws MqttException
* @throws InterruptedException
*/
public boolean validateReceipt(String sendTopic, int expectedQos,
byte[] sentBytes) throws MqttException, InterruptedException {
final String methodName = "validateReceipt";
long waitMilliseconds = 10000;
ReceivedMessage receivedMessage = receiveNext(waitMilliseconds);
if (receivedMessage == null) {
report(" No message received in waitMilliseconds="
+ waitMilliseconds);
return false;
}
if (!sendTopic.equals(receivedMessage.topic)) {
report(" Received invalid topic sent=" + sendTopic
+ " received topic=" + receivedMessage.topic);
return false;
}
if (expectedQos != receivedMessage.message.getQos()) {
report("expectedQos=" + expectedQos + " != Received Qos="
+ receivedMessage.message.getQos());
return false;
}
if (!java.util.Arrays.equals(sentBytes,
receivedMessage.message.getPayload())) {
report("Received invalid payload="
+ receivedMessage.message.getPayload() + "\n" + "Sent:"
+ new String(sentBytes) + "\n" + "Received:"
+ new String(receivedMessage.message.getPayload()));
return false;
}
return true;
}
/**
* Validate receipt of a batch of messages sent to a topic by a number of
* publishers The message payloads are expected to have the format<b>
* "Batch Message payload :<batch>:<publisher>:<messageNumber>:<any additional payload>"
*
* We want to detect excess messages, so we don't just handle a certain
* number. Instead we wait for a timeout period, and exit if no message is
* received in that period.<b> The timeout period can make this test long
* running, so we attempt to dynamically adjust, allowing 10 seconds for the
* first message and then averaging the time taken to receive messages and
* applying some fudge factors.
*
* @param sendTopics
* @param expectedQosList
* @param nPublishers
* @param expectedBatchNumber
* @param sentBytes
* @param expectOrdered
* @return flag
* @throws MqttException
* @throws InterruptedException
*/
public boolean validateReceipt(List<String> sendTopics, List<Integer> expectedQosList,
int expectedBatchNumber, int nPublishers, List<byte[]> sentBytes,
boolean expectOrdered) throws MqttException, InterruptedException {
final String methodName = "validateReceipt";
int expectedMessageNumbers[] = new int[nPublishers];
for (int i = 0; i < nPublishers; i++) {
expectedMessageNumbers[i] = 0;
}
long waitMilliseconds = 10000;
// track time taken to receive messages
long totWait = 0;
int messageNo = 0;
while (true) {
long startWait = System.currentTimeMillis();
ReceivedMessage receivedMessage = receiveNext(waitMilliseconds);
if (receivedMessage == null) {
break;
}
messageNo++;
totWait += (System.currentTimeMillis() - startWait);
// Calculate new wait time based on experience, but not allowing it
// to get too small
waitMilliseconds = Math.max(totWait / messageNo, 500);
byte[] payload = receivedMessage.message.getPayload();
String payloadString = new String(payload);
if (!payloadString.startsWith("Batch Message payload :")) {
report("Received invalid payload\n" + "Received:"
+ payloadString);
report("Payload did not start with {"
+ "Batch Message payload :" + "}");
return false;
}
String[] payloadParts = payloadString.split(":");
if (payloadParts.length != 5) {
report("Received invalid payload\n" + "Received:"
+ payloadString);
report("Payload was not of expected format");
return false;
}
try {
int batchNumber = Integer.parseInt(payloadParts[1]);
if (batchNumber != expectedBatchNumber) {
report("Received invalid payload\n" + "Received:"
+ payloadString);
report("batchnumber" + batchNumber
+ " was not the expected value "
+ expectedBatchNumber);
return false;
}
}
catch (NumberFormatException e) {
report("Received invalid payload\n" + "Received:"
+ payloadString);
report("batchnumber was not a numeric value");
return false;
}
int publisher = -1;
try {
publisher = Integer.parseInt(payloadParts[2]);
if ((publisher < 0) || (publisher >= nPublishers)) {
report("Received invalid payload\n" + "Received:"
+ payloadString);
report("publisher " + publisher
+ " was not in the range 0 - " + (nPublishers - 1));
return false;
}
}
catch (NumberFormatException e) {
report("Received invalid payload\n" + "Received:"
+ payloadString);
report("publisher was not a numeric value");
return false;
}
if (expectOrdered) {
try {
int messageNumber = Integer.parseInt(payloadParts[3]);
if (messageNumber == expectedMessageNumbers[publisher]) {
expectedMessageNumbers[publisher] += 1;
}
else {
report("Received invalid payload\n" + "Received:"
+ payloadString);
report("messageNumber "
+ messageNumber
+ " was received out of sequence - expected value was "
+ expectedMessageNumbers[publisher]);
return false;
}
}
catch (NumberFormatException e) {
report("Received invalid payload\n" + "Received:"
+ payloadString);
report("messageNumber was not a numeric value");
return false;
}
}
int location;
for (location = 0; location < sentBytes.size(); location++) {
if (Arrays.equals(payload, sentBytes.get(location))) {
break;
}
}
String sendTopic = null;
int expectedQos = -1;
if (location < sentBytes.size()) {
sentBytes.remove(location);
sendTopic = sendTopics.remove(location);
expectedQos = expectedQosList.remove(location);
}
else {
report("Received invalid payload\n" + "Received:"
+ payloadString);
for (byte[] expectedPayload : sentBytes) {
report("\texpected message :" + new String(expectedPayload));
}
return false;
}
if (!sendTopic.equals(receivedMessage.topic)) {
report(" Received invalid topic sent=" + sendTopic
+ " received topic=" + receivedMessage.topic);
return false;
}
if (expectedQos != receivedMessage.message.getQos()) {
report("expectedQos=" + expectedQos + " != Received Qos="
+ receivedMessage.message.getQos());
return false;
}
}
if (!sentBytes.isEmpty()) {
for (byte[] missedPayload : sentBytes) {
report("Did not receive message \n" + new String(missedPayload));
}
return false;
}
return true;
}
/**
* @param waitMilliseconds
* @return flag
* @throws InterruptedException
*/
public synchronized boolean waitForConnectionLost(long waitMilliseconds)
throws InterruptedException {
final String methodName = "waitForConnectionLost";
if (connected) {
wait(waitMilliseconds);
}
return connected;
}
/**
* @param cause
*/
public void connectionLost(Throwable cause) {
final String methodName = "connectionLost";
if (reportConnectionLoss) {
report("ConnectionLost: clientId=" + clientId + " cause=" + cause);
}
synchronized (this) {
connected = false;
notifyAll();
}
}
/**
* @param arg0
*/
public void deliveryComplete(IMqttDeliveryToken arg0) {
// Auto-generated method stub
}
/**
* @param arg0
* @param arg1
*/
public void deliveryFailed(IMqttDeliveryToken arg0, MqttException arg1) {
// Auto-generated method stub
}
/**
* @param topic
* @param message
* @throws Exception
*/
public void messageArrived(String topic, MqttMessage message)
throws Exception {
final String methodName = "messageArrived";
Log.i(methodName, "messageArrived "+topic+ " = "+message.toString()+ " clientId = "+this.clientId);
Log.i(methodName, "messageArrived "+new Date().toString());
receivedMessages.add(new ReceivedMessage(topic, message));
Log.i(methodName, "receivedMessages = "+receivedMessages.toString());
// notify();
}
/**
* @param text
* to be written to the report.
*/
public void report(String text) {
Log.e(this.getClass().getCanonicalName(), text);
}
}

View File

@ -1,40 +0,0 @@
/*******************************************************************************
* Copyright (c) 2014 IBM Corp.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Eclipse Distribution License v1.0 which accompany this distribution.
*
* The Eclipse Public License is available at
* http://www.eclipse.org/legal/epl-v10.html
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*/
package org.eclipse.paho.android.service.test;
/**
* @author Rhys
*
*/
public class TestCaseNotifier {
private Throwable exception;
public void storeException(Throwable exception) {
this.exception = exception;
}
public synchronized void waitForCompletion(long timeout) throws Throwable {
try {
wait(timeout);
}
catch (InterruptedException e) {}
if (exception != null) {
throw exception;
}
}
}

View File

@ -1,162 +0,0 @@
/*******************************************************************************
* Copyright (c) 2014 IBM Corp.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Eclipse Distribution License v1.0 which accompany this distribution.
*
* The Eclipse Public License is available at
* http://www.eclipse.org/legal/epl-v10.html
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*/
package org.eclipse.paho.android.service.test;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import android.content.Context;
import android.util.Log;
public class TestProperties {
// public int waitForCompletionTime = 6000;
// public String serverURI = "tcp://9.125.29.127:1883";
// public static String serverURI = "tcp://9.119.156.175:1883";
// public static String sslServerURI = "ssl://9.119.156.175:8892";
// public String sslServerURI = "ssl://9.125.29.12:8892";
private final Class<?> cclass = TestProperties.class;
private final String className = cclass.getName();
public final String KEY_SERVER_URI = "SERVER_URI";
public final String KEY_CLIENT_KEY_STORE = "CLIENT_KEY_STORE";
public final String KEY_CLIENT_KEY_STORE_PASSWORD = "CLIENT_KEY_STORE_PASSWORD";
public final String KEY_SERVER_SSL_URI = "SERVER_SSL_URI";
public final String KEY_WAIT_FOR_COMPLETION_TIME = "WAIT_FOR_COMPLETION_TIME";
private Properties properties = new Properties();
private Context context;
/**
* Reads properties from a properties file
*/
public TestProperties(Context context) {
this.context = context;
InputStream stream = null;
try {
String filename = "test.properties";
stream = getPropertyFileAsStream(filename);
// Read the properties from the property file
if (stream != null) {
Log.i("TestProperties","Loading properties from: '" + filename + "'");
properties.load(stream);
}
} catch (Exception e) {
Log.e("TestProperties", "caught exception:", e);
} finally {
if (stream != null) {
try {
stream.close();
} catch (IOException e) {
Log.e("TestProperties", "caught exception:", e);
}
}
}
}
/**
* @param filename
* @return stream
* @throws IOException
*/
private InputStream getPropertyFileAsStream(String fileName) throws IOException {
InputStream stream = null;
try {
stream = this.context.getResources().getAssets().open(fileName);
}
catch (Exception exception) {
Log.e("TestProperties", "Property file: '" + fileName + "' not found");
}
return stream;
}
/**
* @param key
* @return value
*/
public String getProperty(String key) {
String value = properties.getProperty(key);
return value;
}
/**
* @param key
* @return value
*/
public boolean getBooleanProperty(String key) {
String value = getProperty(key);
return Boolean.parseBoolean(value);
}
/**
* @param key
* @return value
*/
public int getIntProperty(String key) {
String value = getProperty(key);
return Integer.parseInt(value);
}
/**
* @return keystore file name
*/
public String getClientKeyStore() {
return getProperty(KEY_CLIENT_KEY_STORE);
}
/**
* @return keystore file password
*/
public String getClientKeyStorePassword() {
return getProperty(KEY_CLIENT_KEY_STORE_PASSWORD);
}
/**
* @return the SSL url of the server for testing
*/
public String getServerSSLURI() {
return getProperty(KEY_SERVER_SSL_URI);
}
/**
* @return the server url for testing
*/
public String getServerURI() {
return getProperty(KEY_SERVER_URI);
}
public int getWaitForCompletionTime(){
return getIntProperty(KEY_WAIT_FOR_COMPLETION_TIME);
}
}

View File

@ -1,24 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/>
<classpathentry kind="src" output="target/classes" path="src">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="gen"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>

1
org.eclipse.paho.android.service/.gitignore vendored Executable file
View File

@ -0,0 +1 @@
/build

View File

@ -0,0 +1,54 @@
apply plugin: 'com.android.library'
android {
compileSdkVersion 19
buildToolsVersion "22.0.1"
defaultConfig {
minSdkVersion 9
targetSdkVersion 19
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
dexOptions {
preDexLibraries = false
}
lintOptions {
abortOnError false
}
}
repositories {
maven {
url "https://repo.eclipse.org/content/repositories/paho-snapshots/"
}
}
dependencies {
compile('org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.0.3-SNAPSHOT') {
}
compile 'com.android.support:support-v4:22.2.1'
}
//task to delete the old jar
task deleteOldJar(type: Delete) {
delete 'release/org.eclipse.paho.android.service.jar'
}
//task to export contents as jar
task exportJar(type: Copy) {
from('build/intermediates/bundles/release/')
into('release/')
include('classes.jar')
///Give whatever name you want to give
rename('classes.jar', 'org.eclipse.paho.android.service.jar')
}
exportJar.dependsOn(deleteOldJar, build)

View File

@ -1,92 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project name="org.eclipse.paho.android.service" default="help">
<!-- The local.properties file is created and updated by the 'android' tool.
It contains the path to the SDK. It should *NOT* be checked into
Version Control Systems. -->
<property file="local.properties" />
<!-- The ant.properties file can be created by you. It is only edited by the
'android' tool to add properties to it.
This is the place to change some Ant specific build properties.
Here are some properties you may want to change/update:
source.dir
The name of the source directory. Default is 'src'.
out.dir
The name of the output directory. Default is 'bin'.
For other overridable properties, look at the beginning of the rules
files in the SDK, at tools/ant/build.xml
Properties related to the SDK location or the project target should
be updated using the 'android' tool with the 'update' action.
This file is an integral part of the build system for your
application and should be checked into Version Control Systems.
-->
<property file="ant.properties" />
<!-- if sdk.dir was not set from one of the property file, then
get it from the ANDROID_HOME env var.
This must be done before we load project.properties since
the proguard config can use sdk.dir -->
<property environment="env" />
<condition property="sdk.dir" value="${env.ANDROID_HOME}">
<isset property="env.ANDROID_HOME" />
</condition>
<!-- The project.properties file is created and updated by the 'android'
tool, as well as ADT.
This contains project specific properties such as project target, and library
dependencies. Lower level build properties are stored in ant.properties
(or in .classpath for Eclipse projects).
This file is an integral part of the build system for your
application and should be checked into Version Control Systems. -->
<loadproperties srcFile="project.properties" />
<!-- quick check on sdk.dir -->
<fail
message="sdk.dir is missing. Make sure to generate local.properties using 'android update project' or to inject it through the ANDROID_HOME environment variable."
unless="sdk.dir"
/>
<!--
Import per project custom build rules if present at the root of the project.
This is the place to put custom intermediary targets such as:
-pre-build
-pre-compile
-post-compile (This is typically used for code obfuscation.
Compiled code location: ${out.classes.absolute.dir}
If this is not done in place, override ${out.dex.input.absolute.dir})
-post-package
-post-build
-pre-clean
-->
<import file="custom_rules.xml" optional="true" />
<!-- Import the actual build file.
To customize existing targets, there are two options:
- Customize only one target:
- copy/paste the target into this file, *before* the
<import> task.
- customize it to your needs.
- Customize the whole content of build.xml
- copy/paste the content of the rules files (minus the top node)
into this file, replacing the <import> task.
- customize to your needs.
***********************
****** IMPORTANT ******
***********************
In all cases you must update the value of version-tag below to read 'custom' instead of an integer,
in order to avoid having your file be overridden by tools such as "android update project"
-->
<!-- version-tag: 1 -->
<import file="${sdk.dir}/tools/ant/build.xml" />
</project>

View File

@ -1,39 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project name="org.eclipse.paho.android.service.package" default="package_docs">
<description>Builds a redistributable JAR and documentation for the Android Service client.</description>
<target name="package_docs" depends="init_package, generate_javadoc"/>
<!-- init all properties-->
<target name="init_package">
<property name="output.folder" value="${basedir}/out"/>
<property name="docs.dir" value="${output.folder}/docs"/>
<mkdir dir="${docs.dir}"/>
<!-- Peek into manifest xml file, ${mainfest.abs.file} definition is in <android-sdk>/tools/ant/build.xml-->
<xmlproperty file="${manifest.abs.file}" collapseattributes="true"/>
<property name="package.names" value="${manifest.package}"/>
<property name="doc.package.names" value="${package.names}.*"/>
</target>
<target name="generate_javadoc" depends="clean_docs">
<javadoc packagenames="${doc.package.names}"
sourcepath="${source.absolute.dir}"
destdir="${docs.dir}"
verbose="false"
/>
</target>
<target name="clean_docs" description="Clean up docs.">
<echo>Cleaning project...</echo>
<delete dir="${output.folder}" />
</target>
<!-- -post-build is defined in android build.xml-->
<target name="-post-build" depends="package_docs" />
<target name="-pre-clean" depends="clean_docs" />
</project>

View File

@ -1,53 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project name="org.eclipse.paho.android.service" basedir="." default="exportJar">
<property name="src" value="src" />
<property name="classes" value="bin/classes" />
<property name="dist" value="dist" />
<property name="app.name" value="org.eclipse.paho.android.service" />
<property name="app.version" value="1.0" />
<property name="classes.encode" value="GBK" />
<property name="lib" value="libs" />
<property environment="env" />
<condition property="sdk.dir" value="${env.ANDROID_HOME}">
<isset property="env.ANDROID_HOME" />
</condition>
<property name="androidAPILevel" value="19" />
<property name="androidjar" value="${sdk.dir}/platforms/android-${androidAPILevel}"/>
<path id="classpath">
<fileset dir="${lib}">
<include name="*.jar" />
</fileset>
<fileset dir="${androidjar}">
<include name="android.jar" />
</fileset>
</path>
<target name="init">
<!-- Create the time stamp -->
<tstamp />
</target>
<target name="buildFiles" depends="init">
<echo message="start building ....." />
<delete dir="${classes}" />
<mkdir dir="${classes}" />
<javac deprecation="on" debug="on" encoding="${classes.encode}" srcdir="${src}" destdir="${classes}" classpathref="classpath" />
<copy todir="${classes}">
<!-- copy config files -->
<fileset dir="${src}" includes="**/*.properties,**/*.xml,**/*.bsh,**/*.logic, **/*.hbm" />
</copy>
</target>
<target name="exportJar" depends="buildFiles">
<delete dir="${dist}" />
<!-- Create the distribution directory -->
<mkdir dir="${dist}" />
<!-- Put everything in ${classes} into the MyProject-${DSTAMP}.jar file -->
<jar jarfile="${dist}/${app.name}.jar" basedir="${classes}" />
</target>
</project>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 50 KiB

View File

@ -1,76 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.eclipse.paho</groupId>
<artifactId>android-service-parent</artifactId>
<version>1.0.3-SNAPSHOT</version>
</parent>
<artifactId>org.eclipse.paho.android.service</artifactId>
<packaging>jar</packaging>
<build>
<sourceDirectory>${basedir}/src</sourceDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.3</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.9</version>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<!-- http://stackoverflow.com/questions/15886209/maven-is-not-working-in-java-8-when-javadoc-tags-are-incomplete -->
<!-- for java 8 -->
<!--
<additionalparam>-Xdoclint:none</additionalparam>
-->
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.eclipse.paho</groupId>
<artifactId>org.eclipse.paho.client.mqttv3</artifactId>
<version>1.0.3-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.google.android</groupId>
<artifactId>android</artifactId>
</dependency>
<dependency>
<groupId>com.google.android</groupId>
<artifactId>support-v4</artifactId>
<version>r7</version>
</dependency>
</dependencies>
</project>

Some files were not shown because too many files have changed in this diff Show More