First commit

This commit is contained in:
Manos 2015-10-29 02:57:02 +02:00
parent 026af69731
commit becb99211e
132 changed files with 11200 additions and 0 deletions

1
.idea/.name Normal file
View File

@ -0,0 +1 @@
EasyHarvestClient

22
.idea/compiler.xml Normal file
View File

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<resourceExtensions />
<wildcardResourcePatterns>
<entry name="!?*.java" />
<entry name="!?*.form" />
<entry name="!?*.class" />
<entry name="!?*.groovy" />
<entry name="!?*.scala" />
<entry name="!?*.flex" />
<entry name="!?*.kt" />
<entry name="!?*.clj" />
<entry name="!?*.aj" />
</wildcardResourcePatterns>
<annotationProcessing>
<profile default="true" name="Default" enabled="false">
<processorPath useClasspath="true" />
</profile>
</annotationProcessing>
</component>
</project>

View File

@ -0,0 +1,3 @@
<component name="CopyrightManager">
<settings default="" />
</component>

6
.idea/encodings.xml Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding">
<file url="PROJECT" charset="UTF-8" />
</component>
</project>

18
.idea/gradle.xml Normal file
View File

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="GradleSettings">
<option name="linkedExternalProjectsSettings">
<GradleProjectSettings>
<option name="distributionType" value="DEFAULT_WRAPPED" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="gradleJvm" value="1.8" />
<option name="modules">
<set>
<option value="$PROJECT_DIR$" />
<option value="$PROJECT_DIR$/app" />
</set>
</option>
</GradleProjectSettings>
</option>
</component>
</project>

View File

@ -0,0 +1,10 @@
<component name="libraryTable">
<library name="android-maps-utils-0.4">
<CLASSES>
<root url="jar://$PROJECT_DIR$/app/build/intermediates/exploded-aar/com.google.maps.android/android-maps-utils/0.4/jars/classes.jar!/" />
<root url="file://$PROJECT_DIR$/app/build/intermediates/exploded-aar/com.google.maps.android/android-maps-utils/0.4/res" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>

View File

@ -0,0 +1,15 @@
<component name="libraryTable">
<library name="appcompat-v7-22.2.0">
<ANNOTATIONS>
<root url="jar://$PROJECT_DIR$/app/build/intermediates/exploded-aar/com.android.support/appcompat-v7/22.2.0/annotations.zip!/" />
</ANNOTATIONS>
<CLASSES>
<root url="jar://$PROJECT_DIR$/app/build/intermediates/exploded-aar/com.android.support/appcompat-v7/22.2.0/jars/classes.jar!/" />
<root url="file://$PROJECT_DIR$/app/build/intermediates/exploded-aar/com.android.support/appcompat-v7/22.2.0/res" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="jar://C:/Program Files (x86)/Android/android-sdk/extras/android/m2repository/com/android/support/appcompat-v7/22.2.0/appcompat-v7-22.2.0-sources.jar!/" />
</SOURCES>
</library>
</component>

View File

@ -0,0 +1,9 @@
<component name="libraryTable">
<library name="commons-io-2.4">
<CLASSES>
<root url="jar://$PROJECT_DIR$/app/libs/commons-io-2.4.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>

View File

@ -0,0 +1,9 @@
<component name="libraryTable">
<library name="httpclient-4.2.5">
<CLASSES>
<root url="jar://$PROJECT_DIR$/app/libs/httpclient-4.2.5.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>

View File

@ -0,0 +1,9 @@
<component name="libraryTable">
<library name="httpcore-4.2.4">
<CLASSES>
<root url="jar://$PROJECT_DIR$/app/libs/httpcore-4.2.4.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>

View File

@ -0,0 +1,16 @@
<component name="libraryTable">
<library name="mediarouter-v7-22.2.0">
<ANNOTATIONS>
<root url="jar://$PROJECT_DIR$/app/build/intermediates/exploded-aar/com.android.support/mediarouter-v7/22.2.0/annotations.zip!/" />
</ANNOTATIONS>
<CLASSES>
<root url="jar://$PROJECT_DIR$/app/build/intermediates/exploded-aar/com.android.support/mediarouter-v7/22.2.0/jars/libs/internal_impl-22.2.0.jar!/" />
<root url="jar://$PROJECT_DIR$/app/build/intermediates/exploded-aar/com.android.support/mediarouter-v7/22.2.0/jars/classes.jar!/" />
<root url="file://$PROJECT_DIR$/app/build/intermediates/exploded-aar/com.android.support/mediarouter-v7/22.2.0/res" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="jar://C:/Program Files (x86)/Android/android-sdk/extras/android/m2repository/com/android/support/mediarouter-v7/22.2.0/mediarouter-v7-22.2.0-sources.jar!/" />
</SOURCES>
</library>
</component>

View File

@ -0,0 +1,10 @@
<component name="libraryTable">
<library name="play-services-7.8.0">
<CLASSES>
<root url="file://$PROJECT_DIR$/app/build/intermediates/exploded-aar/com.google.android.gms/play-services/7.8.0/res" />
<root url="jar://$PROJECT_DIR$/app/build/intermediates/exploded-aar/com.google.android.gms/play-services/7.8.0/jars/classes.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>

View File

@ -0,0 +1,10 @@
<component name="libraryTable">
<library name="play-services-ads-7.8.0">
<CLASSES>
<root url="file://$PROJECT_DIR$/app/build/intermediates/exploded-aar/com.google.android.gms/play-services-ads/7.8.0/res" />
<root url="jar://$PROJECT_DIR$/app/build/intermediates/exploded-aar/com.google.android.gms/play-services-ads/7.8.0/jars/classes.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>

View File

@ -0,0 +1,10 @@
<component name="libraryTable">
<library name="play-services-analytics-7.8.0">
<CLASSES>
<root url="file://$PROJECT_DIR$/app/build/intermediates/exploded-aar/com.google.android.gms/play-services-analytics/7.8.0/res" />
<root url="jar://$PROJECT_DIR$/app/build/intermediates/exploded-aar/com.google.android.gms/play-services-analytics/7.8.0/jars/classes.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>

View File

@ -0,0 +1,10 @@
<component name="libraryTable">
<library name="play-services-appindexing-7.8.0">
<CLASSES>
<root url="file://$PROJECT_DIR$/app/build/intermediates/exploded-aar/com.google.android.gms/play-services-appindexing/7.8.0/res" />
<root url="jar://$PROJECT_DIR$/app/build/intermediates/exploded-aar/com.google.android.gms/play-services-appindexing/7.8.0/jars/classes.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>

View File

@ -0,0 +1,10 @@
<component name="libraryTable">
<library name="play-services-appinvite-7.8.0">
<CLASSES>
<root url="file://$PROJECT_DIR$/app/build/intermediates/exploded-aar/com.google.android.gms/play-services-appinvite/7.8.0/res" />
<root url="jar://$PROJECT_DIR$/app/build/intermediates/exploded-aar/com.google.android.gms/play-services-appinvite/7.8.0/jars/classes.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>

View File

@ -0,0 +1,10 @@
<component name="libraryTable">
<library name="play-services-appstate-7.8.0">
<CLASSES>
<root url="jar://$PROJECT_DIR$/app/build/intermediates/exploded-aar/com.google.android.gms/play-services-appstate/7.8.0/jars/classes.jar!/" />
<root url="file://$PROJECT_DIR$/app/build/intermediates/exploded-aar/com.google.android.gms/play-services-appstate/7.8.0/res" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>

View File

@ -0,0 +1,10 @@
<component name="libraryTable">
<library name="play-services-base-7.8.0">
<CLASSES>
<root url="jar://$PROJECT_DIR$/app/build/intermediates/exploded-aar/com.google.android.gms/play-services-base/7.8.0/jars/classes.jar!/" />
<root url="file://$PROJECT_DIR$/app/build/intermediates/exploded-aar/com.google.android.gms/play-services-base/7.8.0/res" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>

View File

@ -0,0 +1,10 @@
<component name="libraryTable">
<library name="play-services-cast-7.8.0">
<CLASSES>
<root url="jar://$PROJECT_DIR$/app/build/intermediates/exploded-aar/com.google.android.gms/play-services-cast/7.8.0/jars/classes.jar!/" />
<root url="file://$PROJECT_DIR$/app/build/intermediates/exploded-aar/com.google.android.gms/play-services-cast/7.8.0/res" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>

View File

@ -0,0 +1,10 @@
<component name="libraryTable">
<library name="play-services-drive-7.8.0">
<CLASSES>
<root url="file://$PROJECT_DIR$/app/build/intermediates/exploded-aar/com.google.android.gms/play-services-drive/7.8.0/res" />
<root url="jar://$PROJECT_DIR$/app/build/intermediates/exploded-aar/com.google.android.gms/play-services-drive/7.8.0/jars/classes.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>

View File

@ -0,0 +1,10 @@
<component name="libraryTable">
<library name="play-services-fitness-7.8.0">
<CLASSES>
<root url="jar://$PROJECT_DIR$/app/build/intermediates/exploded-aar/com.google.android.gms/play-services-fitness/7.8.0/jars/classes.jar!/" />
<root url="file://$PROJECT_DIR$/app/build/intermediates/exploded-aar/com.google.android.gms/play-services-fitness/7.8.0/res" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>

View File

@ -0,0 +1,10 @@
<component name="libraryTable">
<library name="play-services-games-7.8.0">
<CLASSES>
<root url="jar://$PROJECT_DIR$/app/build/intermediates/exploded-aar/com.google.android.gms/play-services-games/7.8.0/jars/classes.jar!/" />
<root url="file://$PROJECT_DIR$/app/build/intermediates/exploded-aar/com.google.android.gms/play-services-games/7.8.0/res" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>

View File

@ -0,0 +1,10 @@
<component name="libraryTable">
<library name="play-services-gcm-7.8.0">
<CLASSES>
<root url="file://$PROJECT_DIR$/app/build/intermediates/exploded-aar/com.google.android.gms/play-services-gcm/7.8.0/res" />
<root url="jar://$PROJECT_DIR$/app/build/intermediates/exploded-aar/com.google.android.gms/play-services-gcm/7.8.0/jars/classes.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>

View File

@ -0,0 +1,10 @@
<component name="libraryTable">
<library name="play-services-identity-7.8.0">
<CLASSES>
<root url="jar://$PROJECT_DIR$/app/build/intermediates/exploded-aar/com.google.android.gms/play-services-identity/7.8.0/jars/classes.jar!/" />
<root url="file://$PROJECT_DIR$/app/build/intermediates/exploded-aar/com.google.android.gms/play-services-identity/7.8.0/res" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>

View File

@ -0,0 +1,10 @@
<component name="libraryTable">
<library name="play-services-location-7.8.0">
<CLASSES>
<root url="file://$PROJECT_DIR$/app/build/intermediates/exploded-aar/com.google.android.gms/play-services-location/7.8.0/res" />
<root url="jar://$PROJECT_DIR$/app/build/intermediates/exploded-aar/com.google.android.gms/play-services-location/7.8.0/jars/classes.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>

View File

@ -0,0 +1,10 @@
<component name="libraryTable">
<library name="play-services-maps-7.8.0">
<CLASSES>
<root url="jar://$PROJECT_DIR$/app/build/intermediates/exploded-aar/com.google.android.gms/play-services-maps/7.8.0/jars/classes.jar!/" />
<root url="file://$PROJECT_DIR$/app/build/intermediates/exploded-aar/com.google.android.gms/play-services-maps/7.8.0/res" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>

View File

@ -0,0 +1,10 @@
<component name="libraryTable">
<library name="play-services-nearby-7.8.0">
<CLASSES>
<root url="file://$PROJECT_DIR$/app/build/intermediates/exploded-aar/com.google.android.gms/play-services-nearby/7.8.0/res" />
<root url="jar://$PROJECT_DIR$/app/build/intermediates/exploded-aar/com.google.android.gms/play-services-nearby/7.8.0/jars/classes.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>

View File

@ -0,0 +1,10 @@
<component name="libraryTable">
<library name="play-services-panorama-7.8.0">
<CLASSES>
<root url="jar://$PROJECT_DIR$/app/build/intermediates/exploded-aar/com.google.android.gms/play-services-panorama/7.8.0/jars/classes.jar!/" />
<root url="file://$PROJECT_DIR$/app/build/intermediates/exploded-aar/com.google.android.gms/play-services-panorama/7.8.0/res" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>

View File

@ -0,0 +1,10 @@
<component name="libraryTable">
<library name="play-services-plus-7.8.0">
<CLASSES>
<root url="jar://$PROJECT_DIR$/app/build/intermediates/exploded-aar/com.google.android.gms/play-services-plus/7.8.0/jars/classes.jar!/" />
<root url="file://$PROJECT_DIR$/app/build/intermediates/exploded-aar/com.google.android.gms/play-services-plus/7.8.0/res" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>

View File

@ -0,0 +1,10 @@
<component name="libraryTable">
<library name="play-services-safetynet-7.8.0">
<CLASSES>
<root url="file://$PROJECT_DIR$/app/build/intermediates/exploded-aar/com.google.android.gms/play-services-safetynet/7.8.0/res" />
<root url="jar://$PROJECT_DIR$/app/build/intermediates/exploded-aar/com.google.android.gms/play-services-safetynet/7.8.0/jars/classes.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>

View File

@ -0,0 +1,10 @@
<component name="libraryTable">
<library name="play-services-vision-7.8.0">
<CLASSES>
<root url="jar://$PROJECT_DIR$/app/build/intermediates/exploded-aar/com.google.android.gms/play-services-vision/7.8.0/jars/classes.jar!/" />
<root url="file://$PROJECT_DIR$/app/build/intermediates/exploded-aar/com.google.android.gms/play-services-vision/7.8.0/res" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>

View File

@ -0,0 +1,10 @@
<component name="libraryTable">
<library name="play-services-wallet-7.8.0">
<CLASSES>
<root url="jar://$PROJECT_DIR$/app/build/intermediates/exploded-aar/com.google.android.gms/play-services-wallet/7.8.0/jars/classes.jar!/" />
<root url="file://$PROJECT_DIR$/app/build/intermediates/exploded-aar/com.google.android.gms/play-services-wallet/7.8.0/res" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>

View File

@ -0,0 +1,10 @@
<component name="libraryTable">
<library name="play-services-wearable-7.8.0">
<CLASSES>
<root url="jar://$PROJECT_DIR$/app/build/intermediates/exploded-aar/com.google.android.gms/play-services-wearable/7.8.0/jars/classes.jar!/" />
<root url="file://$PROJECT_DIR$/app/build/intermediates/exploded-aar/com.google.android.gms/play-services-wearable/7.8.0/res" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>

View File

@ -0,0 +1,11 @@
<component name="libraryTable">
<library name="support-annotations-23.0.1">
<CLASSES>
<root url="jar://C:/Program Files (x86)/Android/android-sdk/extras/android/m2repository/com/android/support/support-annotations/23.0.1/support-annotations-23.0.1.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="jar://C:/Program Files (x86)/Android/android-sdk/extras/android/m2repository/com/android/support/support-annotations/23.0.1/support-annotations-23.0.1-sources.jar!/" />
</SOURCES>
</library>
</component>

View File

@ -0,0 +1,16 @@
<component name="libraryTable">
<library name="support-v4-23.0.1">
<ANNOTATIONS>
<root url="jar://$PROJECT_DIR$/app/build/intermediates/exploded-aar/com.android.support/support-v4/23.0.1/annotations.zip!/" />
</ANNOTATIONS>
<CLASSES>
<root url="jar://$PROJECT_DIR$/app/build/intermediates/exploded-aar/com.android.support/support-v4/23.0.1/jars/libs/internal_impl-23.0.1.jar!/" />
<root url="file://$PROJECT_DIR$/app/build/intermediates/exploded-aar/com.android.support/support-v4/23.0.1/res" />
<root url="jar://$PROJECT_DIR$/app/build/intermediates/exploded-aar/com.android.support/support-v4/23.0.1/jars/classes.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="jar://C:/Program Files (x86)/Android/android-sdk/extras/android/m2repository/com/android/support/support-v4/23.0.1/support-v4-23.0.1-sources.jar!/" />
</SOURCES>
</library>
</component>

62
.idea/misc.xml Normal file
View File

@ -0,0 +1,62 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="EntryPointsManager">
<entry_points version="2.0" />
</component>
<component name="NullableNotNullManager">
<option name="myDefaultNullable" value="android.support.annotation.Nullable" />
<option name="myDefaultNotNull" value="android.support.annotation.NonNull" />
<option name="myNullables">
<value>
<list size="4">
<item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.Nullable" />
<item index="1" class="java.lang.String" itemvalue="javax.annotation.Nullable" />
<item index="2" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.Nullable" />
<item index="3" class="java.lang.String" itemvalue="android.support.annotation.Nullable" />
</list>
</value>
</option>
<option name="myNotNulls">
<value>
<list size="4">
<item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.NotNull" />
<item index="1" class="java.lang.String" itemvalue="javax.annotation.Nonnull" />
<item index="2" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.NonNull" />
<item index="3" class="java.lang.String" itemvalue="android.support.annotation.NonNull" />
</list>
</value>
</option>
</component>
<component name="ProjectLevelVcsManager" settingsEditedManually="false">
<OptionsSetting value="true" id="Add" />
<OptionsSetting value="true" id="Remove" />
<OptionsSetting value="true" id="Checkout" />
<OptionsSetting value="true" id="Update" />
<OptionsSetting value="true" id="Status" />
<OptionsSetting value="true" id="Edit" />
<ConfirmationsSetting value="0" id="Add" />
<ConfirmationsSetting value="0" id="Remove" />
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">
<option name="id" value="Android" />
</component>
<component name="masterDetails">
<states>
<state key="ProjectJDKs.UI">
<settings>
<last-edited>1.8</last-edited>
<splitter-proportions>
<option name="proportions">
<list>
<option value="0.2" />
</list>
</option>
</splitter-proportions>
</settings>
</state>
</states>
</component>
</project>

9
.idea/modules.xml Normal file
View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/EasyHarvestClient.iml" filepath="$PROJECT_DIR$/EasyHarvestClient.iml" />
<module fileurl="file://$PROJECT_DIR$/app/app.iml" filepath="$PROJECT_DIR$/app/app.iml" />
</modules>
</component>
</project>

View File

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RunConfigurationProducerService">
<option name="ignoredProducers">
<set>
<option value="org.jetbrains.plugins.gradle.execution.test.runner.AllInPackageGradleConfigurationProducer" />
<option value="org.jetbrains.plugins.gradle.execution.test.runner.TestClassGradleConfigurationProducer" />
<option value="org.jetbrains.plugins.gradle.execution.test.runner.TestMethodGradleConfigurationProducer" />
</set>
</option>
</component>
</project>

6
.idea/vcs.xml Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="" />
</component>
</project>

2124
.idea/workspace.xml Normal file

File diff suppressed because it is too large Load Diff

19
EasyHarvestClient.iml Normal file
View File

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<module external.linked.project.id="EasyHarvestClient" 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_7" 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>

148
app/app.iml Normal file
View File

@ -0,0 +1,148 @@
<?xml version="1.0" encoding="UTF-8"?>
<module external.linked.project.id=":app" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="EasyHarvestClient" 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=":app" />
</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/resValues/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/resValues/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/appcompat-v7/22.2.0/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/mediarouter-v7/22.2.0/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/support-v4/23.0.1/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.google.android.gms/play-services-ads/7.8.0/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.google.android.gms/play-services-analytics/7.8.0/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.google.android.gms/play-services-appindexing/7.8.0/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.google.android.gms/play-services-appinvite/7.8.0/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.google.android.gms/play-services-appstate/7.8.0/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.google.android.gms/play-services-base/7.8.0/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.google.android.gms/play-services-cast/7.8.0/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.google.android.gms/play-services-drive/7.8.0/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.google.android.gms/play-services-fitness/7.8.0/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.google.android.gms/play-services-games/7.8.0/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.google.android.gms/play-services-gcm/7.8.0/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.google.android.gms/play-services-identity/7.8.0/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.google.android.gms/play-services-location/7.8.0/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.google.android.gms/play-services-maps/7.8.0/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.google.android.gms/play-services-nearby/7.8.0/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.google.android.gms/play-services-panorama/7.8.0/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.google.android.gms/play-services-plus/7.8.0/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.google.android.gms/play-services-safetynet/7.8.0/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.google.android.gms/play-services-vision/7.8.0/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.google.android.gms/play-services-wallet/7.8.0/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.google.android.gms/play-services-wearable/7.8.0/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.google.android.gms/play-services/7.8.0/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.google.maps.android/android-maps-utils/0.4/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/tmp" />
</content>
<orderEntry type="jdk" jdkName="Android API 23 Platform" jdkType="Android SDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" exported="" name="mediarouter-v7-22.2.0" level="project" />
<orderEntry type="library" exported="" name="play-services-cast-7.8.0" level="project" />
<orderEntry type="library" exported="" name="play-services-gcm-7.8.0" level="project" />
<orderEntry type="library" exported="" name="commons-io-2.4" level="project" />
<orderEntry type="library" exported="" name="play-services-games-7.8.0" level="project" />
<orderEntry type="library" exported="" name="play-services-wallet-7.8.0" level="project" />
<orderEntry type="library" exported="" name="play-services-drive-7.8.0" level="project" />
<orderEntry type="library" exported="" name="play-services-ads-7.8.0" level="project" />
<orderEntry type="library" exported="" name="appcompat-v7-22.2.0" level="project" />
<orderEntry type="library" exported="" name="play-services-analytics-7.8.0" level="project" />
<orderEntry type="library" exported="" name="play-services-appindexing-7.8.0" level="project" />
<orderEntry type="library" exported="" name="play-services-appinvite-7.8.0" level="project" />
<orderEntry type="library" exported="" name="play-services-safetynet-7.8.0" level="project" />
<orderEntry type="library" exported="" name="android-maps-utils-0.4" level="project" />
<orderEntry type="library" exported="" name="httpclient-4.2.5" level="project" />
<orderEntry type="library" exported="" name="support-v4-23.0.1" level="project" />
<orderEntry type="library" exported="" name="play-services-7.8.0" level="project" />
<orderEntry type="library" exported="" name="play-services-base-7.8.0" level="project" />
<orderEntry type="library" exported="" name="support-annotations-23.0.1" level="project" />
<orderEntry type="library" exported="" name="play-services-fitness-7.8.0" level="project" />
<orderEntry type="library" exported="" name="play-services-vision-7.8.0" level="project" />
<orderEntry type="library" exported="" name="httpcore-4.2.4" level="project" />
<orderEntry type="library" exported="" name="play-services-nearby-7.8.0" level="project" />
<orderEntry type="library" exported="" name="play-services-location-7.8.0" level="project" />
<orderEntry type="library" exported="" name="play-services-appstate-7.8.0" level="project" />
<orderEntry type="library" exported="" name="play-services-wearable-7.8.0" level="project" />
<orderEntry type="library" exported="" name="play-services-identity-7.8.0" level="project" />
<orderEntry type="library" exported="" name="play-services-panorama-7.8.0" level="project" />
<orderEntry type="library" exported="" name="play-services-plus-7.8.0" level="project" />
<orderEntry type="library" exported="" name="play-services-maps-7.8.0" level="project" />
</component>
</module>

33
app/build.gradle Normal file
View File

@ -0,0 +1,33 @@
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "com.www.client"
minSdkVersion 16
targetSdkVersion 23
}
buildTypes {
release {
minifyEnabled false
debuggable true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
packagingOptions {
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
}
}
dependencies {
compile 'com.android.support:support-v4:+'
compile 'com.google.maps.android:android-maps-utils:+'
compile 'com.google.android.gms:play-services:+'
compile fileTree(dir: 'libs', include: '*.jar')
}

BIN
app/libs/commons-io-2.4.jar Normal file

Binary file not shown.

Binary file not shown.

BIN
app/libs/httpcore-4.2.4.jar Normal file

Binary file not shown.

3
app/lint.xml Normal file
View File

@ -0,0 +1,3 @@
<?xml version="1.0" encoding="UTF-8"?>
<lint>
</lint>

View File

@ -0,0 +1,215 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.www.client"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="16"
android:targetSdkVersion="22" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.AUTHENTICATE_ACCOUNTS" />
<uses-permission android:name="android.permission.BATTERY_STATS" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.BROADCAST_STICKY" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.CHANGE_CONFIGURATION" />
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.CLEAR_APP_CACHE" />
<uses-permission android:name="android.permission.DISABLE_KEYGUARD" />
<uses-permission android:name="android.permission.EXPAND_STATUS_BAR" />
<uses-permission android:name="android.permission.FLASHLIGHT" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.GET_PACKAGE_SIZE" />
<uses-permission android:name="android.permission.GET_TASKS" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESSES" />
<uses-permission android:name="android.permission.MANAGE_ACCOUNTS" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.MOUNT_FORMAT_FILESYSTEMS" />
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" />
<uses-permission android:name="android.permission.NFC" />
<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS" />
<uses-permission android:name="android.permission.READ_CALENDAR" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.READ_HISTORY_BOOKMARKS" />
<uses-permission android:name="android.permission.READ_LOGS" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.READ_SMS" />
<uses-permission android:name="android.permission.READ_SYNC_SETTINGS" />
<uses-permission android:name="android.permission.READ_SYNC_STATS" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.RECEIVE_MMS" />
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.RECEIVE_WAP_PUSH" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.REORDER_TASKS" />
<uses-permission android:name="android.permission.RESTART_PACKAGES" />
<uses-permission android:name="android.permission.SEND_SMS" />
<uses-permission android:name="android.permission.SET_ALARM" />
<uses-permission android:name="android.permission.SET_ALWAYS_FINISH" />
<uses-permission android:name="android.permission.SET_ANIMATION_SCALE" />
<uses-permission android:name="android.permission.SET_DEBUG_APP" />
<uses-permission android:name="android.permission.SET_PROCESS_LIMIT" />
<uses-permission android:name="android.permission.SET_TIME_ZONE" />
<uses-permission android:name="android.permission.SET_WALLPAPER" />
<uses-permission android:name="android.permission.SET_WALLPAPER_HINTS" />
<uses-permission android:name="android.permission.SIGNAL_PERSISTENT_PROCESSES" />
<uses-permission android:name="android.permission.SUBSCRIBED_FEEDS_READ" />
<uses-permission android:name="android.permission.SUBSCRIBED_FEEDS_WRITE" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<uses-permission android:name="android.permission.USE_CREDENTIALS" />
<uses-permission android:name="android.permission.USE_SIP" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.WRITE_CALENDAR" />
<uses-permission android:name="android.permission.WRITE_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_HISTORY_BOOKMARKS" />
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
<uses-permission android:name="android.permission.WRITE_SMS" />
<uses-permission android:name="android.permission.WRITE_SYNC_SETTINGS" />
<uses-permission android:name="android.permission.BIND_ACCESSIBILITY_SERVICE" />
<uses-permission android:name="android.permission.PERSISTENT_ACTIVITY" />
<uses-permission android:name="android.permission.READ_CALL_LOG" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="com.android.browser.permission.READ_HISTORY_BOOKMARKS" />
<uses-permission android:name="android.permission.READ_PROFILE" />
<uses-permission android:name="android.permission.READ_SOCIAL_STREAM" />
<uses-permission android:name="android.permission.READ_USER_DICTIONARY" />
<uses-permission android:name="com.android.alarm.permission.SET_ALARM" />
<uses-permission android:name="android.permission.WRITE_CALL_LOG" />
<uses-permission android:name="com.android.browser.permission.WRITE_HISTORY_BOOKMARKS" />
<uses-permission android:name="android.permission.WRITE_PROFILE" />
<uses-permission android:name="android.permission.WRITE_SOCIAL_STREAM" />
<uses-permission android:name="android.permission.WRITE_USER_DICTIONARY" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<application
android:allowBackup="true"
android:debuggable="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="@string/maps_api_key" />
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<activity
android:name=".ClientActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service
android:name=".TaskService"
android:enabled="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
</service>
<receiver
android:name=".BootReceiver"
android:enabled="false" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" >
</action>
</intent-filter>
</receiver>
<receiver android:name=".TimeReceiver" >
</receiver>
<activity
android:name=".SettingsActivity"
android:label="@string/title_activity_client_settings"
android:parentActivityName=".ClientActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.www.client.ClientActivity" />
<intent-filter>
<action android:name="android.intent.action.MANAGE_NETWORK_USAGE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".pr.PrivacyRegionsActivity"
android:label="@string/title_activity_privacy_regions"
android:parentActivityName=".SettingsActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.www.client.SettingsActivity" />
</activity>
<activity
android:name=".pr.AddPrivacyRegionActivity"
android:label="@string/title_activity_new_privacy_region"
android:parentActivityName=".pr.PrivacyRegionsActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".pr.PrivacyRegionsActivity" />
</activity>
<activity
android:name=".pr.ViewPrivacyRegionActivity"
android:label="@string/title_activity_view_privacy_region"
android:parentActivityName=".pr.PrivacyRegionsActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".pr.PrivacyRegionsActivity" />
</activity>
<activity
android:name=".pr.EditPrivacyRegionActivity"
android:label="@string/title_activity_edit_privacy_region"
android:parentActivityName=".pr.PrivacyRegionsActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".pr.PrivacyRegionsActivity" />
</activity>
<activity
android:name=".pm.PrivacyMechanismsActivity"
android:label="@string/title_activity_privacy_mechanisms"
android:parentActivityName=".SettingsActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.www.client.SettingsActivity" />
</activity>
<activity
android:name=".pm.ListPrivacyMechanismsActivity"
android:label="@string/title_activity_get_privacy_mechanism"
android:parentActivityName=".pm.PrivacyMechanismsActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.www.client.pm.PrivacyMechanismsActivity" />
</activity>
<activity
android:name=".pm.ViewPrivacyMechanismActivity"
android:label="@string/title_activity_view_privacy_mechanism"
android:parentActivityName=".pm.PrivacyMechanismsActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.www.client.pm.PrivacyMechanismsActivity" />
</activity>
</application>
</manifest>

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

View File

@ -0,0 +1,18 @@
package com.www.client;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
public class AppendingObjectOutputStream extends ObjectOutputStream {
public AppendingObjectOutputStream(OutputStream out) throws IOException {
super(out);
}
@Override
protected void writeStreamHeader() throws IOException {
reset();
}
}

View File

@ -0,0 +1,21 @@
package com.www.client;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
public class BootReceiver extends BroadcastReceiver {
private static final String TAG = "BootReceiver";
@Override
public void onReceive(Context context, Intent intent) {
Log.i(TAG, "onReceive: " + "...");
if (intent.getAction().equals("android.intent.action.BOOT_COMPLETED")) {
//context.startService(new Intent(context, TaskService.class));
context.startService(new Intent(context, TaskService.class));
}
}
}

View File

@ -0,0 +1,329 @@
package com.www.client;
import android.app.Activity;
import android.app.ActivityManager;
import android.app.ActivityManager.RunningServiceInfo;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.graphics.Color;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Bundle;
import android.os.Environment;
import android.preference.PreferenceManager;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.SeekBar;
import android.widget.TextView;
import com.www.client.pm.EasyPrivacy;
import com.www.client.pm.PrivacyMechanism;
import java.io.File;
import java.io.IOException;
public class ClientActivity extends Activity implements SeekBar.OnSeekBarChangeListener {
private static final String SDCARD_DIR = Environment.getExternalStorageDirectory().getPath();
public static final String CLIENT_DIR = SDCARD_DIR + "/Client";
private static Context context;
private static ConnectivityManager connectivityManager;
public static boolean restartService = false;
SeekBar seekBar;
TextView statusText;
TextView levelText;
TextView commentText;
public static SharedPreferences sharedPref = null;
public static SharedPreferences.Editor editor = null;
PrivacyMechanism pm;
@Override
protected void onCreate(Bundle savedInstanceState) {
String TAG = getClass().getName() + "@onCreate: ";
super.onCreate(savedInstanceState);
Log.wtf(TAG, "...");
setContentView(R.layout.activity_client);
ClientActivity.context = getApplicationContext();
connectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
editor = sharedPref.edit();
seekBar = (SeekBar) findViewById(R.id.levelService);
seekBar.setOnSeekBarChangeListener(this);
statusText = (TextView) findViewById(R.id.status);
levelText = (TextView) findViewById(R.id.level);
commentText = (TextView) findViewById(R.id.comment);
Button ok = (Button) findViewById(R.id.okButton);
Button cancel = (Button) findViewById(R.id.cancelButton);
ok.setOnClickListener(okListener);
cancel.setOnClickListener(cancelListener);
}
@Override
protected void onStart() {
String TAG = getClass().getName() + "@onStart: ";
super.onStart();
Log.wtf(TAG, "onStart: " + "...");
if (sharedPref.getString("username", null) == null) {
mkdirs();
editor.putInt("serviceLevel", 0);
editor.commit();
statusText.setTextColor(Color.rgb(255, 0, 0));
statusText.setText("OFF");
commentText.setTextColor(Color.rgb(100, 100, 100));
commentText.setText("Slide the bar right to turn the service on & set the desired level of activity...");
} else {
seekBar.setProgress(sharedPref.getInt("serviceLevel", 0));
seekBar.setSecondaryProgress(sharedPref.getInt("serviceLevel", 0));
if (sharedPref.getInt("serviceLevel", 0) > 0) {
statusText.setTextColor(Color.rgb(0, 255, 0));
statusText.setText("ON");
commentText.setTextColor(Color.rgb(255, 255, 255));
commentText.setText("The service will download tasks from the server, execute them & send the results back.");
if (!isServiceRunning()) {
Log.wtf(TAG, "onStart: Restarting...");
startService(new Intent(ClientActivity.this, TaskService.class));
}
} else {
statusText.setTextColor(Color.rgb(255, 0, 0));
statusText.setText("OFF");
commentText.setTextColor(Color.rgb(100, 100, 100));
commentText.setText("Nothing to do.");
}
}
/*
* Do not comment out!
*/
onTest();
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
onResume();
}
private void onTest() {
String TAG = getClass().getName() + "@onTest: ";
editor.putString("username", "emkatsom");
// editor.putString("taskID", "1");
/**/
// editor.putBoolean(Globals.easy_privacy, false);
editor.putBoolean(Globals.easy_privacy, true);
// editor.putString("deviceID", "1234");
//
// editor.putString(Globals.pm_id, "13");
// editor.putInt(Globals.privacy_level, 24);
/**/
editor.commit();
// startActivity(new Intent(getBaseContext(), SettingsActivity.class));
// startActivity(new Intent(getBaseContext(), PrivacyRegionsActivity.class));
// startActivity(new Intent(getBaseContext(), AddPrivacyRegionActivity.class));
// startActivity(new Intent(getBaseContext(), com.www.client.pm.PrivacyMechanismsActivity.class));
// startActivity(new Intent(getBaseContext(), com.www.client.pm.ListPrivacyMechanismsActivity.class));
}
private OnClickListener okListener = new OnClickListener() {
public void onClick(View v) {
/**/
if (seekBar.getProgress() > 0 && sharedPref.getInt("serviceLevel", 0) == 0) {
SharedPreferences.Editor editor = sharedPref.edit();
editor.putInt("serviceLevel", seekBar.getProgress());
editor.commit();
seekBar.setSecondaryProgress(seekBar.getProgress());
enableBootReceiver();
startService(new Intent(ClientActivity.this, TaskService.class));
} else if (seekBar.getProgress() == 0) {
SharedPreferences.Editor editor = sharedPref.edit();
editor.putInt("serviceLevel", seekBar.getProgress());
editor.commit();
seekBar.setSecondaryProgress(seekBar.getProgress());
disableBootReceiver();
stopService(new Intent(ClientActivity.this, TaskService.class));
} else {
SharedPreferences.Editor editor = sharedPref.edit();
editor.putInt("serviceLevel", seekBar.getProgress());
editor.commit();
seekBar.setSecondaryProgress(seekBar.getProgress());
}
/**/
/*
if(pm != null) {
// pm.onStart();
} else {
pm = new PrivacyMechanism(
getApplicationContext(),
Integer.valueOf(sharedPref.getString(Globals.pm_id, "0")),
Integer.valueOf(sharedPref.getString(Globals.st_id, "0")));
// pm.onStart();
}
/**/
}
};
private OnClickListener cancelListener = new OnClickListener() {
public void onClick(View v) {
seekBar.setProgress(sharedPref.getInt("serviceLevel", 0));
seekBar.setSecondaryProgress(sharedPref.getInt("serviceLevel", 0));
levelText.setText(null);
/*
if(pm != null) {
pm.onStop();
pm = null;
}
/**/
}
};
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_client, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.menu_settings:
Intent i = new Intent(this, SettingsActivity.class);
startActivity(i);
return true;
default:
return super.onOptionsItemSelected(item);
}
}
@Override
public void onProgressChanged(SeekBar arg0, int arg1, boolean arg2) {
int c = (int) (100 + arg0.getProgress() * 1.55);
levelText.setTextColor(Color.rgb(c, c, c));
levelText.setText(arg0.getProgress() + "%");
if (arg1 == 0) {
statusText.setTextColor(Color.rgb(255, 0, 0));
statusText.setText("OFF");
commentText.setTextColor(Color.rgb(100, 100, 100));
commentText.setText("Nothing to do.");
} else {
statusText.setTextColor(Color.rgb(0, 255, 0));
statusText.setText("ON");
commentText.setTextColor(Color.rgb(255, 255, 255));
commentText.setText("The service will download tasks from the server, execute them & send the results back.");
}
}
@Override
public void onStartTrackingTouch(SeekBar arg0) {
int c = (int) (100 + arg0.getProgress() * 1.55);
levelText.setTextColor(Color.rgb(c, c, c));
levelText.setText(arg0.getProgress() + "%");
}
@Override
public void onStopTrackingTouch(SeekBar arg0) {
levelText.setText(null);
}
private void enableBootReceiver() {
ComponentName receiver = new ComponentName(context, BootReceiver.class);
PackageManager pm = context.getPackageManager();
pm.setComponentEnabledSetting(receiver,
PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
PackageManager.DONT_KILL_APP);
}
private void disableBootReceiver() {
ComponentName receiver = new ComponentName(context, BootReceiver.class);
PackageManager pm = context.getPackageManager();
pm.setComponentEnabledSetting(receiver,
PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
PackageManager.DONT_KILL_APP);
}
public static Context getContext() {
return ClientActivity.context;
}
public static boolean isOnline() {
Boolean wifiConnected, mobileConnected;
NetworkInfo activeInfo = connectivityManager.getActiveNetworkInfo();
if (activeInfo != null && activeInfo.isConnected()) {
wifiConnected = activeInfo.getType() == ConnectivityManager.TYPE_WIFI;
mobileConnected = activeInfo.getType() == ConnectivityManager.TYPE_MOBILE;
} else {
wifiConnected = false;
mobileConnected = false;
}
if (((ClientActivity.sharedPref.getString("listPref", "Wi-Fi").equals("Any")) && (wifiConnected || mobileConnected))
|| ((ClientActivity.sharedPref.getString("listPref", "Wi-Fi").equals("Wi-Fi")) && (wifiConnected))) {
return true;
} else {
return false;
}
}
private boolean isServiceRunning() {
ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
if (TaskService.class.getName().equals(service.service.getClassName())) {
return true;
}
}
return false;
}
private void mkdirs() {
String TAG = getClass().getName() + "@mkdirs: ";
File clientDir = new File(CLIENT_DIR);
File settingsDir = new File(CLIENT_DIR + "/Settings");
File pmsDir = new File(CLIENT_DIR + "/PMs");
Utils.delete(clientDir);
Utils.delete(settingsDir);
Utils.delete(pmsDir);
if(clientDir.mkdir()) {
Log.wtf(TAG, "Created " + clientDir.getPath());
} else {
Log.wtf(TAG, "Could not create Client directory.");
}
if(settingsDir.mkdir()) {
Log.wtf(TAG, "Created " + settingsDir.getPath());
} else {
Log.wtf(TAG, "Could not create Settings directory.");
}
if(pmsDir.mkdir()) {
Log.wtf(TAG, "Created " + pmsDir.getPath());
} else {
Log.wtf(TAG, "Could not create PMs directory.");
}
}
}

View File

@ -0,0 +1,82 @@
package com.www.client;
import android.os.Environment;
public class Globals {
/**
* Evaluation
*/
// public static boolean eval_status = true;
public static boolean eval_status = false;
// Beauty
// public static String eval_dev = "MID7188";
// public static String eval_ip = "192.168.49.1";
// Nexus
// public static String eval_dev = "occam";
// public static String eval_ip = "192.168.49.75";
/**
* Description: device URLS.
* Changelog : - .
*/
public static String sdcard_dir = Environment.getExternalStorageDirectory().getPath();
public static String client_dir = sdcard_dir + "/Client";
public static String pms_dir = client_dir + "/PMs";
/**
* Description: URLS.
* Changelog : - .
*/
public static String server_url = "http://83.212.109.118:8080/Server/webresources";
// public static String server_url = "http://192.168.2.2:8084/Server/webresources";
// public static String server_url = "http://10.64.83.194:8084/Server/webresources";
public static String devs_url = server_url + "/devs";
public static String tasks_url = server_url + "/tasks";
public static String pms_url = server_url + "/pms";
public static int pm_port = 4545;
/**
* Description: Time latency in ms.
* Changelog : - .
*/
public static int task_latency = 10 * 100 * 1000;
public static int pm_latency = 1 * 100 * 1000;
/**
* Description: EasyHarvest client shared preferences labels.
* Changelog : - .
*/
public static String shr_user = "username"; // string
public static String shr_dev_id = "deviceID"; // string
/**
* Description: Sensing tasks shared preferences labels.
* Changelog : - .
*/
public static String st_id = "taskID"; // string
/**
* Description: Privacy mechanisms shared preferences labels.
* Changelog : - .
*/
public static String easy_privacy = "EasyPrivacy"; // boolean
public static String privacy_level = "privacyLevel"; // integer
public static String pm_name = "pmName"; // string
public static String pm_clss = "pmClss"; //
public static String pm_id = "pmID"; //
public static String pm_vers = "pmVersion"; //
public static String pm_st_id = "pmTaskId"; //
public static String pm_user = "pmUser"; //
public static String pm_desc = "pmDescription"; //
public static String pm_date = "pmDate"; //
public static String pm_time = "pmTime"; //
public static String pm_size = "pmSize"; //
}

View File

@ -0,0 +1,36 @@
package com.www.client;
public class Item {
String text = "";
int image = 0;
public Item(String text, int image) {
this.text = text;
this.image = image;
}
public Item(String text) {
this.text = text;
}
public int getImage() {
return image;
}
public void setImage(int image) {
this.image = image;
}
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
@Override
public String toString() {
return text;
}
}

View File

@ -0,0 +1,56 @@
package com.www.client;
import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.List;
public class ItemArrayAdapter extends ArrayAdapter<JSONObject> {
private static final String TAG = "ItemArrayAdapter";
Context context;
public ItemArrayAdapter(Context context, int resourceId, List<JSONObject> items) {
super(context, resourceId, items);
this.context = context;
}
/*private view holder class*/
private class ViewHolder {
TextView textView;
ImageView imageView;
}
public View getView(int position, View view, ViewGroup group) {
ViewHolder holder = null;
JSONObject item = getItem(position);
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
if (view == null) {
view = inflater.inflate(R.layout.item, null);
holder = new ViewHolder();
holder.textView = (TextView) view.findViewById(R.id.text);
view.setTag(holder);
}
else {
holder = (ViewHolder) view.getTag();
}
try {
holder.textView.setText(item.getString("label"));
} catch (JSONException e) {
e.printStackTrace();
}
return view;
}
}

View File

@ -0,0 +1,244 @@
package com.www.client;
import android.app.ActivityManager;
import android.app.ActivityManager.RunningServiceInfo;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import android.os.AsyncTask;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceClickListener;
import android.preference.PreferenceActivity;
import android.preference.PreferenceManager;
import android.preference.PreferenceScreen;
import android.util.Log;
import android.widget.Toast;
import com.www.client.pm.PrivacyMechanismsActivity;
import com.www.client.pr.PrivacyRegionsActivity;
import org.apache.commons.io.FileUtils;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import java.io.File;
import java.io.IOException;
public class SettingsActivity extends PreferenceActivity implements OnSharedPreferenceChangeListener, OnPreferenceClickListener, Preference.OnPreferenceChangeListener {
private static final String TAG = "SettingsActivity";
public static PreferenceScreen prefScreen = null;
public static SharedPreferences sp = null;
public static SharedPreferences.Editor spEditor = null;
SwitchPref privacyRegions = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
//Log.wtf(TAG, "onCreate");
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences);
/*
* Privacy regions switch listener.
*/
privacyRegions = (SwitchPref) findPreference(getResources().getString((R.string.privacy_regions_status)));
privacyRegions.setOnPreferenceClickListener(this);
privacyRegions.setOnPreferenceChangeListener(this);
/*
* Set preference item listeners.
*/
findPreference(getResources().getString((R.string.privacy_mechanisms_key))).setOnPreferenceClickListener(this);
findPreference("device_unregister").setOnPreferenceClickListener(this);
}
@Override
protected void onResume() {
//Log.wtf(TAG, "onResume");
super.onResume();
if (sp == null) {
//Log.wtf(TAG, "onResume: " + "sp == null");
sp = PreferenceManager.getDefaultSharedPreferences(this);
spEditor = sp.edit();
sp.registerOnSharedPreferenceChangeListener(this);
} else {
//Log.wtf(TAG, "onResume: " + "sp != null");
}
privacyRegions.setChecked(sp.getBoolean(getResources().getString((R.string.privacy_regions_status)), false));
//this.onContentChanged();
}
@Override
protected void onPause() {
//Log.wtf(TAG, "onPause");
super.onPause();
if (sp != null) {
sp.unregisterOnSharedPreferenceChangeListener(this);
sp = null;
}
}/**/
@Override
protected void onStop() {
//Log.wtf(TAG, "onStop");
super.onStop();
if (sp != null) {
sp.unregisterOnSharedPreferenceChangeListener(this);
sp = null;
}
//finish();
}/**/
/*@Override
protected void onDestroy() {
Log.wtf(TAG, "onDestroy");
super.onDestroy();
sp.unregisterOnSharedPreferenceChangeListener(this);
sp = null;
}/**/
/*@Override
public void onConfigurationChanged(Configuration newConfig) {
Log.wtf(TAG, "onConfigurationChanged");
super.onConfigurationChanged(newConfig);
//onResume();
}*/
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
// Toast.makeText(getApplicationContext(), "onSharedPreferenceChanged: " + key, Toast.LENGTH_SHORT).show();
Log.wtf(TAG, "onSharedPreferenceChanged: " + sharedPreferences.getAll());
if (key.equals("listPref") || key.equals(getResources().getString((R.string.privacy_regions_status)))) {
// ClientActivity.restartService = true;
Toast.makeText(getApplicationContext(), "Restarting...", Toast.LENGTH_SHORT).show();
if (isServiceRunning()) {
Log.wtf(TAG, "onSharedPreferenceChanged: " + "Restarting service...");
stopService(new Intent(this, TaskService.class));
startService(new Intent(this, TaskService.class));
}
}
}
/*
* Control action when a preference is clicked.
*/
@Override
public boolean onPreferenceClick(Preference preference) {
// Toast.makeText(getApplicationContext(), "onPreferenceClick: " + preference.getKey(), Toast.LENGTH_SHORT).show();
/*
* Launch Privacy Regions activity.
*/
if (getResources().getString((R.string.privacy_regions_status)).equals(preference.getKey())) {
// Toast.makeText(ClientActivity.getContext(), "onPreferenceClick: " + preference.getKey(), Toast.LENGTH_SHORT).show();
Intent i = new Intent(this, PrivacyRegionsActivity.class);
startActivity(i);
}
/*
* Launch Privacy Mechanisms activity.
*/
if (getResources().getString((R.string.privacy_mechanisms_key)).equals(preference.getKey())) {
// Toast.makeText(ClientActivity.getContext(), "onPreferenceClick: " + preference.getKey(), Toast.LENGTH_SHORT).show();
Intent i = new Intent(this, PrivacyMechanismsActivity.class);
startActivity(i);
}
/*
* Unregister the device.
*/
if ("device_unregister".equals(preference.getKey())) {
Toast.makeText(ClientActivity.getContext(), "Unregistering...", Toast.LENGTH_SHORT).show();
String deviceID = ClientActivity.sharedPref.getString("deviceID", null);
if (deviceID != null) {
if (ClientActivity.isOnline()) {
Log.wtf(TAG, "deviceUnregister: " + "Online.");
String url = Globals.devs_url + "/" + deviceID + "/unregister";
Log.wtf(TAG, "deviceUnregister: " + "" + deviceID + "/unregister");
new DeviceUnregister().execute(url);
} else {
Log.wtf(TAG, "deviceUnregister: " + "Offline.");
Toast.makeText(ClientActivity.getContext(), "No internet connection", Toast.LENGTH_SHORT).show();
}
} else {
Toast.makeText(ClientActivity.getContext(), "Not registered", Toast.LENGTH_SHORT).show();
}
}
return false;
}
@Override
public boolean onPreferenceChange(Preference preference, Object o) {
//Toast.makeText(getApplicationContext(), "onPreferenceChange: " + preference.getKey(), Toast.LENGTH_SHORT).show();
if ("privacyRegionsStatus".equals(preference.getKey())) {
//Toast.makeText(getApplicationContext(), "onPreferenceChange: " + preference.getKey() + " = " + o.toString(), Toast.LENGTH_SHORT).show();
}
return true;
}
private class DeviceUnregister extends AsyncTask<String, Void, String> {
private static final String TAG = "DeviceUnregister";
private HttpClient client;
@Override
protected String doInBackground(String... urls) {
Log.wtf(TAG, "doInBackground: " + "...");
client = new DefaultHttpClient();
HttpGet request = new HttpGet(urls[0]);
HttpResponse response = null;
String result = "oops";
try {
response = client.execute(request);
} catch (Exception e) {
//e.printStackTrace();
}
if (response != null) {
try {
result = Utils.writeToString(response.getEntity().getContent());
} catch (Exception e) {
}
}
return result;
}
protected void onPostExecute(String result) {
Log.wtf(TAG, "onPostExecute: " + result + ".");
if (result.equals("OK") || result.equals("Not registered")) {
Toast.makeText(getApplicationContext(), result, Toast.LENGTH_SHORT).show();
stopService(new Intent(getApplicationContext(), TaskService.class));
spEditor.putInt("serviceLevel", 0);
spEditor.putString("deviceID", null);
spEditor.putString("username", null);
spEditor.putString("serviceStatus", "get");
spEditor.putString("getStatus", "getTaskInfo");
spEditor.commit();
try {
FileUtils.cleanDirectory(new File(ClientActivity.CLIENT_DIR));
} catch (IOException e) {
e.printStackTrace();
}
} else {
Toast.makeText(getApplicationContext(), "Oops!", Toast.LENGTH_SHORT).show();
}
}
}
private boolean isServiceRunning() {
ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
if (TaskService.class.getName().equals(service.service.getClassName())) {
return true;
}
}
return false;
}
}

View File

@ -0,0 +1,25 @@
package com.www.client;
import android.content.Context;
import android.preference.SwitchPreference;
import android.util.AttributeSet;
public class SwitchPref extends SwitchPreference {
public SwitchPref(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
public SwitchPref(Context context, AttributeSet attrs) {
super(context, attrs);
}
public SwitchPref(Context context) {
super(context);
}
@Override
protected void onClick() {
//super.onClick();
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,23 @@
package com.www.client;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
public class TimeReceiver extends BroadcastReceiver {
private static final String TAG = "TimeReceiver";
@Override
public void onReceive(Context context, Intent intent) {
Log.i(TAG, "onReceive: " + "...");
if (intent.getAction().equals("TASK_SERVICE_ON")) {
context.startService(new Intent(context, TaskService.class));
}
else if (intent.getAction().equals("TASK_SERVICE_OFF")) {
context.startService(new Intent(context, TaskService.class));
}
}
}

View File

@ -0,0 +1,533 @@
package com.www.client;
import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.util.Log;
import org.apache.commons.io.FileUtils;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.Closeable;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.io.RandomAccessFile;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.util.ArrayList;
import java.util.List;
public class Utils {
private static final String TAG = "Utils";
public static HttpResponse response(String url, String task) {
HttpClient client = new DefaultHttpClient();
HttpResponse response = null;
try {
if("get".equals(task)) {
response = client.execute(new HttpGet(url));
}
}
catch (Exception e) {
Log.e(TAG, e.getLocalizedMessage(), e);
}
return response;
}
public static HttpResponse httpResponse(String url, ArrayList<NameValuePair> params) {
Log.i(TAG, "response: " + params);
HttpClient httpClient = new DefaultHttpClient();
HttpResponse httpResponse = null;
try {
HttpPost httppost = new HttpPost(url);
httppost.setEntity(new UrlEncodedFormEntity(params));
httpResponse = httpClient.execute(httppost);
}
catch (Exception e) {
Log.e(TAG, e.getLocalizedMessage(), e);
}
return httpResponse;
}
public static File returnFileFrom(String url, String type) {
String TAG = "Utils.returnFileFrom: ";
Log.wtf(TAG, url + " with type " + type);
File folder = new File(url);
String fileName;
File file = null;
if (folder.exists()) {
File[] listOfFiles = folder.listFiles();
for (int i = 0; i < listOfFiles.length; i++) {
if (listOfFiles[i].isFile()) {
fileName = listOfFiles[i].getName();
if (fileName.endsWith(type)) {
file = new File(url + "/" + fileName);
Log.wtf(TAG, "found " + fileName);
break;
}
}
}
}
return file;
}
public static void returnPart(RandomAccessFile input, OutputStream output, long start) throws IOException {
int read;
byte[] buffer = new byte[1024];
input.seek(start);
while ((read = input.read(buffer)) > 0) {
output.write(buffer, 0, read);
}
close(output);
close(input);
}
/**
* Description: Read an input stream and covert it to readable string.
* Parameters : - InputStream: The stream to convert to string.
* Changelog : - 150615: Remove throws clause and add appropriate log.
*/
public static String writeToString(InputStream input) {
String TAG = Utils.class.getName() + "@writeToString: ";
InputStreamReader isr = new InputStreamReader(input);
BufferedReader br = new BufferedReader(isr);
StringBuilder sb = new StringBuilder();
String line;
try {
while ((line = br.readLine()) != null) {
sb.append(line);
}
} catch (IOException e) {
Log.e(TAG, e.getMessage());
}
String result = sb.toString();
close(br);
close(isr);
close(input);
return result;
}
public static void writeToFile(InputStream input, String url) {
File file = new File(url);
long seek = file.length();
RandomAccessFile output = null;
/*long skip = 0;
skip += input.skip(seek);
Log.i(TAG, "writeToFile: before " + skip + " - " + seek);
while(skip < seek) {
skip += input.skip(1);
}
Log.i(TAG, "writeToFile: after " + skip);/**/
try {
output = new RandomAccessFile(file, "rw");
output.seek(seek);
int read = 0;
byte[] buffer = new byte[1024];
while((read = input.read(buffer)) > 0) {
output.write(buffer, 0, read);
}
} catch (Exception e) {
//e.printStackTrace();
}
close(output);
close(input);/**/
}
public static void delete(File file) {
if(file.exists()) {
if(file.isDirectory()){
if(file.list().length==0){
file.delete();
}
else {
String files[] = file.list();
for (String temp : files) {
File fileDelete = new File(file, temp);
delete(fileDelete);
}
if(file.list().length==0){
file.delete();
}
}
}
else {
file.delete();
}
}
}
public static void writeJSONtoFile(JSONObject json, File file) {
FileWriter fw = null;
try {
if (file.exists()) {
fw = new FileWriter(file, true);
//json.put("id", countLines(file));
}
else {
fw = new FileWriter(file);
//json.put("id", 0);
}
fw.write(json.toString() + "\n");
close(fw);
} catch (IOException e) {
e.printStackTrace();
}
//System.out.println("json: " + json);
//System.out.println("string: " + json.toString());
//System.out.println("file: " + FileUtils.readFileToString(file));
}
public static void overwriteJSONtoFile(ArrayList<JSONObject> arrayList, File file) {
FileWriter fw = null;
try {
fw = new FileWriter(file);
for (JSONObject jsonObject : arrayList) {
fw.write(jsonObject.toString() + "\n");
}
close(fw);
} catch (IOException e) {
e.printStackTrace();
}
}
public static int countLines(File file) {
int lines = 0;
try {
lines = countLines(FileUtils.readFileToString(file));
} catch (IOException e) {
e.printStackTrace();
}
return lines;
}
public static int countLines(String str){
String[] lines = str.split("\r\n|\r|\n");
return lines.length;
}
public static ArrayList<JSONObject> fileToJSON(File file) {
ArrayList<JSONObject> arrayList = new ArrayList<JSONObject>();
if (file.exists()) {
BufferedReader br = null;
try {
br = new BufferedReader(new FileReader(file));
String line;
while ((line = br.readLine()) != null) {
//System.out.println("line: " + line);
arrayList.add(new JSONObject(line));
}
close(br);
//System.out.println("array: " + arrayList.toString());
} catch (IOException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
}
return arrayList;
}
public static void removePM(Context c, int id) {
String TAG = Utils.class.getName() + "@removePM: ";
Log.wtf(TAG, "Removing PM " + id + "...");
delete(new File(Globals.pms_dir + "/" + id));
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(c);
SharedPreferences.Editor ed = sp.edit();
ed.putString(Globals.pm_id, null);
ed.putString(Globals.pm_name, null);
ed.putString(Globals.pm_vers, null);
//
// class name
ed.putString(Globals.pm_clss, null);
//
// sensing task id
ed.putString(Globals.pm_st_id, null);
//
ed.putString(Globals.pm_desc, null);
ed.putString(Globals.pm_user, null);
ed.putString(Globals.pm_date, null);
ed.putString(Globals.pm_time, null);
ed.putString(Globals.pm_size, null);
ed.commit();
}
public static void close(Closeable resource) {
if (resource != null) {
try {
resource.close();
} catch (IOException ignore) {
}
}
}
// Data related functions
//
//
public static boolean saveData(List data, String taskID) {
String TAG = "Utils@saveData: ";
String ext = ".dat";
String url = Globals.client_dir + "/" + taskID + "/" + taskID;
int i = 1;
File file = new File(url + ext);
// while(file.exists() || new File(url + ".dat").exists()) {
// TODO: EVAL
/*
if (file.exists() || new File(url + ".dat").exists()) {
url = Globals.client_dir + "/" + taskID + "/" + taskID + "(" + i + ")";
file = new File(url + ext);
i++;
}
*/
// /TODO: EVAL
url += ext;
FileOutputStream fos;
ObjectOutputStream oos;
try {
Log.wtf(TAG, "Saving data to " + url);
List<Object> oldData = Utils.getData(url);
if (!oldData.isEmpty()) {
oldData.addAll(data);
data = oldData;
}
fos = new FileOutputStream(url);
oos = new ObjectOutputStream(fos);
oos.writeObject(data);
close(oos);
close(fos);
} catch (Exception ex) {
Log.wtf(TAG, ex.getMessage());
return false;
}
Log.wtf(TAG, "OK");
return true;
}
//
public static void mergeData(String dataSrc, String dataDst) {
String TAG = "Utils@mergeData: ";
if(new File(dataDst).exists()) {
Log.wtf(TAG, "Merging data with " + dataDst);
List<Object> oldData = Utils.getData(dataDst);
List<Object> newData = Utils.getData(dataSrc);
oldData.addAll(newData);
new File(dataSrc).delete();
new File(dataDst).delete();
try {
FileOutputStream fos = new FileOutputStream(dataDst);
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeObject(oldData);
close(oos);
close(fos);
} catch (Exception ex) {
Log.wtf(TAG, ex.getMessage());
}
} else {
Log.wtf(TAG, "Moving data to " + dataDst);
new File(dataSrc).renameTo(new File(dataDst));
new File(dataSrc).delete();
}
}
//
public static List<Object> getData(String url) {
String TAG = "Utils@getData: ";
FileInputStream fis;
ObjectInputStream ois;
List<Object> data = new ArrayList<>();
try {
Log.wtf(TAG, "Returning data " + url);
if (new File(url).exists()) {
fis = new FileInputStream(url);
ois = new ObjectInputStream(fis);
data = (List<Object>) ois.readObject();
close(ois);
close(fis);
} else {
Log.wtf(TAG, "File does not exist");
}
} catch (Exception ex) {
Log.wtf(TAG, ex.getMessage());
}
Log.wtf(TAG, "OK");
return data;
}
public static ObjectInputStream getData(List<Object> data) {
String TAG = "Utils@getDataFrom: ";
Log.wtf(TAG, "...");
ObjectInputStream ois = null;
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(data);
Utils.close(oos);
InputStream is = new ByteArrayInputStream(baos.toByteArray());
ois = new ObjectInputStream(is);
} catch (IOException e) {
Log.wtf(TAG, e.getMessage());
}
return ois;
}
//
public static ObjectOutputStream putData (String url) {
String TAG = "Utils@putDataTo: ";
Log.wtf(TAG, "...");
FileOutputStream fos;
ObjectOutputStream oos = null;
try {
// Log.wtf(TAG, "Saving data to " + url);
fos = new FileOutputStream(url);
oos = new ObjectOutputStream(fos);
} catch (Exception ex) {
Log.wtf(TAG, ex.getMessage());
}
return oos;
}
// TODO
public static String getNewDataPath (int stId) {
String TAG = "Utils@getNewDataPath: ";
String ext = ".dat";
String url = Globals.client_dir + "/" + stId + "/" + stId;
int i = 1;
File file = new File(url + ext);
while(file.exists() || new File(url + ".dat").exists()) {
url = Globals.client_dir + "/" + stId + "/" + stId + "(" + i + ")";
file = new File(url + ext);
i++;
}
file = new File(url + ext + ".tmp");
while(file.exists() || new File(url + ".dat" + ".tmp").exists()) {
url = Globals.client_dir + "/" + stId + "/" + stId + "(" + i + ")";
file = new File(url + ext);
i++;
}
url += ext + ".tmp";
return url;
}
// State related functions
//
// getStateFrom the pm directory
public static ObjectInputStream getStateFrom (int id) {
final String TAG = "Utils@getStateFrom: ";
FileInputStream fis;
ObjectInputStream ois = null;
String url = Globals.pms_dir + "/" + id + "/" + id + ".sav";
Log.wtf(TAG, "" + url);
if(new File(url).exists()) {
Log.wtf(TAG, "" + "OK");
try {
fis = new FileInputStream(url);
ois = new ObjectInputStream(fis);
} catch (Exception e) {
Log.wtf(TAG, e.getMessage());
}
} else {
Log.wtf(TAG, "No saved state found");
}
return ois;
}
// putStateTo the pm directory
public static ObjectOutputStream putStateTo (String url) {
String TAG = "Utils@putStateTo: ";
Log.wtf(TAG, url);
FileOutputStream fos;
ObjectOutputStream oos = null;
try {
fos = new FileOutputStream(url);
oos = new ObjectOutputStream(fos);
} catch (Exception ex) {
Log.wtf(TAG, ex.getMessage());
}
return oos;
}
}

View File

@ -0,0 +1,336 @@
package com.www.client.pm;
import com.www.client.Globals;
import com.www.client.R;
import android.content.*;
import android.net.NetworkInfo;
import android.net.wifi.p2p.*;
import android.net.wifi.p2p.WifiP2pManager.*;
import android.net.wifi.p2p.nsd.WifiP2pDnsSdServiceInfo;
import android.preference.PreferenceManager;
import android.util.*;
import java.io.IOException;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.util.*;
public class EasyPrivacy
extends BroadcastReceiver
implements PeerListListener, ConnectionInfoListener {
Context context;
public static SharedPreferences shrPrf = null;
private final IntentFilter intentFilter;
Channel channel;
WifiP2pManager manager;
private boolean wiFiP2pStatus;
private List<Object> peers;
private ServerSocket serverSocket;
private ServerSocket clientSocket;
public EasyPrivacy(Context c) {
String TAG = getClass().getName() + "@EasyPrivacy: ";
Log.wtf(TAG, "...");
context = c;
shrPrf = PreferenceManager.getDefaultSharedPreferences(c);
intentFilter = new IntentFilter();
// Indicates a change in the Wi-Fi P2P status.
intentFilter.addAction(WifiP2pManager.WIFI_P2P_STATE_CHANGED_ACTION);
// Indicates a change in the list of available peers.
intentFilter.addAction(WifiP2pManager.WIFI_P2P_PEERS_CHANGED_ACTION);
// Indicates the state of Wi-Fi P2P connectivity has changed.
intentFilter.addAction(WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION);
// Indicates this device's details have changed.
intentFilter.addAction(WifiP2pManager.WIFI_P2P_THIS_DEVICE_CHANGED_ACTION);
manager = (WifiP2pManager) c.getSystemService(Context.WIFI_P2P_SERVICE);
channel = manager.initialize(c, c.getMainLooper(), null);
peers = new ArrayList<>();
Log.wtf(TAG, "OK");
}
public void onStart() {
String TAG = getClass().getName() + "@onStart: ";
Log.wtf(TAG, "...");
context.registerReceiver(this, intentFilter);
// Detect available peers that are in range. The call to this function is
// asynchronous and a success or failure is communicated to the application
// with onSuccess() and onFailure(). The onSuccess() method only notifies you
// that the discovery process succeeded and does not provide any information
// about the actual peers that it discovered, if any.
manager.discoverPeers(channel, new ActionListener() {
@Override
public void onSuccess() {
// Command successful! Code isn't necessarily needed here,
// Unless you want to update the UI or add logging statements.
String TAG = getClass().getName() + "@onSuccess: ";
Log.wtf(TAG, "OK");
}
@Override
public void onFailure(int arg0) {
// Command failed. Check for P2P_UNSUPPORTED, ERROR, or BUSY
String TAG = getClass().getName() + "@onFailure: ";
Log.wtf(TAG, "Oops!");
}
});
Log.wtf(TAG, "OK");
}
public void onStop() {
String TAG = getClass().getName() + "@onStop: ";
Log.wtf(TAG, "...");
context.unregisterReceiver(this);
Log.wtf(TAG, "OK");
}
// Register the PM service
// TODO to be called in PrivacyMecanism() if pm is collaborative
// Create a string map containing information about your service.
// Map record = new HashMap();
// record.put("listenport", String.valueOf(SERVER_PORT));
// record.put("buddyname", "John Doe" + (int) (Math.random() * 1000));
// record.put("available", "visible");
// public void startRegistration(Map record) {
public void startRegistration() {
// Create a string map containing information about your service.
// TODO pass it as a parameter
Map record = new HashMap();
// record.put("listenport", String.valueOf(SERVER_PORT));
try {
serverSocket = new ServerSocket(0);
} catch (IOException e) {
e.printStackTrace();
}
record.put("port", String.valueOf(serverSocket.getLocalPort()));
// record.put("buddyname", "John Doe" + (int) (Math.random() * 1000));
record.put("usr", shrPrf.getString(Globals.shr_user, "user") + shrPrf.getString(Globals.shr_dev_id, "0"));
record.put("dev", shrPrf.getString(Globals.shr_dev_id, "0"));
record.put("pm", shrPrf.getString(Globals.pm_id, "0"));
record.put("prv", shrPrf.getString(Globals.privacy_level, "0"));
// record.put("available", "visible");
// Service information. Pass it an instance name, service type
// _protocol._transportlayer , and the map containing
// information other devices will want once they connect to this one.
WifiP2pDnsSdServiceInfo serviceInfo =
WifiP2pDnsSdServiceInfo.newInstance("_test", "_presence._tcp", record);
// Add the local service, sending the service info, network channel,
// and listener that will be used to indicate success or failure of
// the request.
manager.addLocalService(channel, serviceInfo, new ActionListener() {
@Override
public void onSuccess() {
// Command successful! Code isn't necessarily needed here,
// Unless you want to update the UI or add logging statements.
String TAG = getClass().getName() + "@onSuccess: ";
Log.wtf(TAG, "OK");
}
@Override
public void onFailure(int arg0) {
// Command failed. Check for P2P_UNSUPPORTED, ERROR, or BUSY
String TAG = getClass().getName() + "@onFailure: ";
Log.wtf(TAG, "Oops!");
}
});
}
// Get notified about WifiP2P network changes.
// - Peers have changed
// -> Request the new peer list
// (get it at onPeersAvailable)
// - A connection has been established
// -> Request connection info
// (get it at onConnectionInfoAvailable)
@Override
public void onReceive(Context c, Intent intent) {
String TAG = getClass().getName() + "@onReceive: ";
String action = intent.getAction();
if (WifiP2pManager.WIFI_P2P_STATE_CHANGED_ACTION.equals(action)) {
// Determine if Wifi P2P mode is enabled or not, alert the Activity.
Log.wtf(TAG, "WifP2P state changed...");
int state = intent.getIntExtra(WifiP2pManager.EXTRA_WIFI_STATE, -1);
if (state == WifiP2pManager.WIFI_P2P_STATE_ENABLED) {
Log.wtf(TAG, "WifiP2P enabled");
this.setWiFiP2pStatus(true);
} else {
Log.wtf(TAG, "WifiP2P disabled");
this.setWiFiP2pStatus(false);
}
} else if (WifiP2pManager.WIFI_P2P_PEERS_CHANGED_ACTION.equals(action)) {
// The peer list has changed! We should probably do something about that.
Log.wtf(TAG, "WifiP2P peers changed...");
// Request available peers from the wifi p2p manager. This is an
// asynchronous call and the calling activity is notified with a
// callback on PeerListListener.onPeersAvailable()
if (manager != null) {
manager.requestPeers(channel, this);
}
} else if (WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION.equals(action)) {
// Connection state changed! We should probably do something about that.
Log.wtf(TAG, "WifiP2P connection changed...");
if (manager != null) {
NetworkInfo networkInfo = (NetworkInfo) intent.getParcelableExtra(WifiP2pManager.EXTRA_NETWORK_INFO);
if (networkInfo.isConnected()) {
// We are connected with the other device, request connection
// info to find group owner IP
Log.wtf(TAG, "Connected");
manager.requestConnectionInfo(channel, this);
}
}
} else if (WifiP2pManager.WIFI_P2P_THIS_DEVICE_CHANGED_ACTION.equals(action)) {
Log.wtf(TAG, "WifiP2P this device changed...");
}
}
// Tne WifiP2pManager.requestPeers(Channel, PeerListListener) returns the new
// WifiP2pDeviceList.
//
// Updates the:
// - Peers list
// - Service (PM) list
@Override
public void onPeersAvailable(WifiP2pDeviceList peers) {
String TAG = getClass().getName() + "@onPeersAvailable: ";
Log.wtf(TAG, "...");
// Out with the old, in with the new.
this.peers.clear();
// TODO
// Update the peer list
this.peers.addAll(peers.getDeviceList());
// TODO
// If an AdapterView is backed by this data, notify it
// of the change. For instance, if you have a ListView of available
// peers, trigger an update.
if (this.peers.size() == 0) {
Log.wtf(TAG, "No devices found");
} else {
Log.wtf(TAG, this.peers.toString());
}
}
// Tne WifiP2pManager.requestConnectionInfo(Channel, ConnectionInfoListener)
// returns connection info.
@Override
public void onConnectionInfoAvailable(WifiP2pInfo info) {
String TAG = getClass().getName() + "@onConnectionInfoAvailable: ";
Log.wtf(TAG, "...");
// InetAddress from WifiP2pInfo struct.
// InetAddress groupOwnerAddress = info.groupOwnerAddress.getHostAddress();
// After the group negotiation, we can determine the group owner.
if (info.groupFormed && info.isGroupOwner) {
// Do whatever tasks are specific to the group owner.
// One common case is creating a server thread and accepting
// incoming connections.
} else if (info.groupFormed) {
// The other device acts as the client. In this case,
// you'll want to create a client thread that connects to the group
// owner.
}
}
private void setWiFiP2pStatus(boolean status) {
wiFiP2pStatus = status;
}
private boolean isWiFiP2pEnabled(boolean status) {
return wiFiP2pStatus;
}
}

View File

@ -0,0 +1,223 @@
package com.www.client.pm;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.TextView;
import com.www.client.ClientActivity;
import com.www.client.Globals;
import com.www.client.R;
import com.www.client.Utils;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONArray;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public class ListPrivacyMechanismsActivity extends Activity implements AdapterView.OnItemClickListener {
SharedPreferences sp;
SharedPreferences.Editor spEditor;
TextView textView;
ListView listView;
List<String> list;
@Override
protected void onCreate(Bundle savedInstanceState) {
String TAG = ListPrivacyMechanismsActivity.class.getName() + "@onCreate: ";
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_list_privacy_mechanisms);
sp = PreferenceManager.getDefaultSharedPreferences(this);
spEditor = sp.edit();
// getList();
}
@Override
protected void onResume() {
//Log.i(TAG, "onResume: ...");
super.onResume();
getList();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_list_privacy_mechanisms, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.get_privacy_mechanism_action_refresh) {
// Toast.makeText(getApplicationContext(), "refresh", Toast.LENGTH_SHORT).show();
getList();
return true;
}
return super.onOptionsItemSelected(item);
}
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
String TAG = getClass().getName() + "@onItemClick: ";
JSONObject choice = null;
try {
choice = new JSONObject(list.get(position));
// Toast.makeText(getApplicationContext(), choice.toString(), Toast.LENGTH_SHORT).show();
// Log.wtf(TAG, choice.toString());
Intent intent = new Intent(this, ViewPrivacyMechanismActivity.class);
intent.putExtra("intent", "get");
intent.putExtra("id", choice.getJSONArray("id").getString(0));
intent.putExtra("name", choice.getJSONArray("name").getString(0));
// class name
intent.putExtra("class", choice.getJSONArray("class").getString(0));
//
intent.putExtra("version", choice.getJSONArray("version").getString(0));
intent.putExtra("description", choice.getJSONArray("description").getString(0));
intent.putExtra("user", choice.getJSONArray("user").getString(0));
intent.putExtra("date", choice.getJSONArray("date").getString(0));
intent.putExtra("time", choice.getJSONArray("time").getString(0));
intent.putExtra("size", choice.getJSONArray("size").getString(0));
startActivity(intent);
} catch (JSONException e) {
e.printStackTrace();
}
}
private void getList() {
String TAG = getClass().getName() + "@getList: ";
// Toast.makeText(getApplicationContext(), "Getting list...", Toast.LENGTH_SHORT).show();
listView = (ListView) findViewById(R.id.listView);
listView.setVisibility(View.INVISIBLE);
list = new ArrayList<>();
textView = (TextView) findViewById(R.id.textView);
textView.setText("Please wait...");
textView.setVisibility(View.VISIBLE);
String stID = sp.getString("taskID", null);
String deviceID = sp.getString("deviceID", null);
if (deviceID != null && stID != null) {
if (ClientActivity.isOnline()) {
String url = Globals.pms_url + "/getlist/" + stID + "/" + deviceID;
Log.wtf(TAG, url);
// Toast.makeText(getApplicationContext(), url, Toast.LENGTH_SHORT).show();
new GetList().execute(url);
} else {
Log.wtf(TAG, "Offline.");
// Toast.makeText(getApplicationContext(), "Offline", Toast.LENGTH_SHORT).show();
textView.setText("No network connection");
}
} else {
Log.wtf(TAG, "Not registered yet");
// Toast.makeText(getApplicationContext(), "Not registered yet", Toast.LENGTH_SHORT).show();
textView.setText("Not registered yet");
}
}
private class GetList extends AsyncTask<String, Void, String> {
@Override
protected String doInBackground(String... params) {
String TAG = GetList.class.getName() + "@doInBackground: ";
Log.wtf(TAG, "...");
HttpClient client = new DefaultHttpClient();
HttpGet request = new HttpGet(params[0]);
HttpResponse response = null;
String result = "Oops!";
try {
response = client.execute(request);
if (response != null) {
result = Utils.writeToString(response.getEntity().getContent());
}
} catch (IOException e) {
Log.e(TAG, e.getMessage());
}
return result;
}
protected void onPostExecute(String result) {
String TAG = GetList.class.getName() + "@onPostExecute: ";
try {
JSONArray jsonArray = new JSONArray(result);
for (int i = 0; i < jsonArray.length(); i++) {
list.add(jsonArray.getString(i));
}
} catch (Exception ex) {
Log.e(TAG, ex.getMessage());
}
Log.wtf(TAG, result);
boolean error = true;
try {
if (list.size() > 0) {
JSONObject o = new JSONObject(list.get(0));
o.getJSONArray("Error").getString(0);
}
} catch (JSONException e) {
error = false;
}
if ("Oops!".equals(result)) {
textView.setText("Oops, something went wrong");
} else if (list.size() == 0) {
textView.setText("There are no privacy mechanisms available");
} else if (error) {
textView.setText("Not registered yet");
} else {
textView.setVisibility(View.INVISIBLE);
/*
* List
*/
PrivacyMechanismArrayAdapter adapter = new PrivacyMechanismArrayAdapter(getApplicationContext(), R.layout.item, list);
listView.setAdapter(adapter);
listView.setOnItemClickListener(ListPrivacyMechanismsActivity.this);
listView.setVisibility(View.VISIBLE);
}
}
}
}

View File

@ -0,0 +1,88 @@
package com.www.client.pm;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.NetworkInfo;
import android.net.wifi.p2p.*;
import android.net.wifi.p2p.WifiP2pManager.*;
import android.util.Log;
public class PmBroadcastReceiver extends BroadcastReceiver {
WifiP2pManager manager;
Channel channel;
PmP2p pmP2p;
//
public PmBroadcastReceiver(WifiP2pManager manager, Channel channel, PmP2p pmP2p) {
this.manager = manager;
this.channel = channel;
this.pmP2p = pmP2p;
}
// Get notified about WifiP2P network changes.
// - Peers have changed
// -> Request the new peer list
// (get it @PmP2p.onPeersAvailable)
// - A connection has been established
// -> Request connection info
// (get it @PmP2p.onConnectionInfoAvailable)
@Override
public void onReceive(Context context, Intent intent) {
String TAG = getClass().getName() + "@onReceive: ";
String action = intent.getAction();
if (WifiP2pManager.WIFI_P2P_STATE_CHANGED_ACTION.equals(action)) {
// Determine if Wifi P2P mode is enabled or not, alert the Activity.
Log.wtf(TAG, "WifP2P state changed...");
int state = intent.getIntExtra(WifiP2pManager.EXTRA_WIFI_STATE, -1);
if (state == WifiP2pManager.WIFI_P2P_STATE_ENABLED) {
Log.wtf(TAG, "WifiP2P enabled");
pmP2p.setWifiP2pStatus(true);
} else {
Log.wtf(TAG, "WifiP2P disabled");
pmP2p.setWifiP2pStatus(false);
}
} else if (WifiP2pManager.WIFI_P2P_PEERS_CHANGED_ACTION.equals(action)) {
// The peer list has changed! We should probably do something about that.
Log.wtf(TAG, "WifiP2P peers changed...");
// Request available peers from the wifi p2p manager. This is an
// asynchronous call and the calling activity is notified with a
// callback on PeerListListener.onPeersAvailable()
if (manager != null) {
manager.requestPeers(channel, pmP2p);
}
} else if (WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION.equals(action)) {
// Connection state changed! We should probably do something about that.
Log.wtf(TAG, "WifiP2P connection changed...");
if (manager != null) {
NetworkInfo networkInfo = (NetworkInfo) intent.getParcelableExtra(WifiP2pManager.EXTRA_NETWORK_INFO);
if (networkInfo.isConnected()) {
// We are connected with the other device, request connection
// info to find group owner IP
Log.wtf(TAG, "Connected");
manager.requestConnectionInfo(channel, pmP2p);
} else {
Log.wtf(TAG, "Disconnected");
pmP2p.disconnect();
}
}
} else if (WifiP2pManager.WIFI_P2P_THIS_DEVICE_CHANGED_ACTION.equals(action)) {
Log.wtf(TAG, "WifiP2P this device changed...");
}
}
}

View File

@ -0,0 +1,141 @@
package com.www.client.pm;
import android.os.AsyncTask;
import android.util.Log;
import com.www.client.Globals;
import com.www.client.Utils;
import java.io.*;
import java.net.*;
import java.util.Map;
//public class PmClient extends AsyncTask {
public class PmClient implements Runnable {
Map<String, String> peer;
PrivacyMechanism pm;
public PmClient(Map<String, String> peer, PrivacyMechanism privacyMechanism) {
this.peer = peer;
this.pm = privacyMechanism;
}
@Override
public void run() {
String TAG = getClass().getName() + "@doInBackground: ";
Log.wtf(TAG, "...");
Socket socket = new Socket();
Log.wtf(TAG, peer.toString());
try {
socket.bind(null);
socket.connect((new InetSocketAddress(peer.get("ip"),
// Integer.valueOf(peer.get("port")))), 500);
Globals.pm_port)), 500);
OutputStream os = socket.getOutputStream();
File data = new File(Globals.pms_dir + "/" + pm.getId() + "/" + peer.get("dev") + ".dat");
if(data.exists()) {
Log.wtf(TAG, "Sending " + data.getPath());
RandomAccessFile raf = new RandomAccessFile(data, "r");
Utils.returnPart(raf, os, 0);
Utils.close(os);
Utils.close(raf);
data.delete();
} else {
Log.wtf(TAG, "No data " + data.getPath());
}
} catch (FileNotFoundException e) {
Log.wtf(TAG, e.getMessage());
} catch (IOException e) {
Log.wtf(TAG, e.getMessage());
} finally {
if (socket != null) {
if (socket.isConnected()) {
try {
Log.wtf(TAG, "Closing socket...");
socket.close();
} catch (IOException e) {
Log.wtf(TAG, e.getMessage());
}
}
}
}
}
// @Override
// protected Object doInBackground(Object[] params) {
// String TAG = getClass().getName() + "@doInBackground: ";
//
// Log.wtf(TAG, "...");
//
// Socket socket = new Socket();
//
// Log.wtf(TAG, peer.toString());
//
// try {
// socket.bind(null);
// socket.connect((new InetSocketAddress(peer.get("ip"),
// Integer.valueOf(peer.get("port")))), 500);
//
// OutputStream os = socket.getOutputStream();
//
//// String dir = Globals.pms_dir + "/" + pm.getId();
//// File data = null;
//// for(File file : new File(dir).listFiles()) {
//// if(file.getName().endsWith(".dat.tmp")) {
//// data = file;
//// break;
//// }
//// }
//
// File data = new File(Globals.pms_dir + "/" + pm.getId() + "/" + peer.get("dev") + ".dat");
//
// if(data.exists()) {
// Log.wtf(TAG, "Sending " + data.getPath());
//
// RandomAccessFile raf = new RandomAccessFile(data, "r");
// Utils.returnPart(raf, os, 0);
//
// Utils.close(os);
// Utils.close(raf);
//
// data.delete();
// } else {
// Log.wtf(TAG, "No data " + data.getPath());
// }
//
// } catch (FileNotFoundException e) {
// Log.wtf(TAG, e.getMessage());
// } catch (IOException e) {
// Log.wtf(TAG, e.getMessage());
// }
//
// finally {
// if (socket != null) {
// if (socket.isConnected()) {
// try {
// socket.close();
// } catch (IOException e) {
// Log.wtf(TAG, e.getMessage());
// }
// }
// }
// }
//
// return null;
// }
}

View File

@ -0,0 +1,660 @@
package com.www.client.pm;
import android.content.Context;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.net.wifi.WpsInfo;
import android.net.wifi.p2p.*;
import android.net.wifi.p2p.WifiP2pManager.*;
import android.net.wifi.p2p.nsd.WifiP2pDnsSdServiceInfo;
import android.net.wifi.p2p.nsd.WifiP2pDnsSdServiceRequest;
import android.os.Build;
import android.preference.PreferenceManager;
import android.util.*;
import com.www.client.Globals;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.util.*;
import java.util.concurrent.ThreadPoolExecutor;
public class PmP2p implements PeerListListener, ConnectionInfoListener {
Context context;
PrivacyMechanism pm;
private SharedPreferences shrPrf;
private PmBroadcastReceiver receiver;
private IntentFilter intentFilter;
private Channel channel;
private WifiP2pManager manager;
private WifiP2pDnsSdServiceInfo serviceInfo;
private boolean wifiP2pStatus;
private boolean connectionStatus;
private List<Map<String, String>> peers;
// ServerSocket serverSocket;
Map<String, String> serverPeer;
Thread server, client;
//
public PmP2p(Context context, PrivacyMechanism pm) {
String TAG = getClass().getName() + "@PmP2p: ";
Log.wtf(TAG, "...");
this.context = context;
this.pm = pm;
Log.wtf(TAG, "1/8");
shrPrf = PreferenceManager.getDefaultSharedPreferences(context);
Log.wtf(TAG, "2/8");
// Create the intent filter
intentFilter = new IntentFilter();
// Indicates a change in the Wi-Fi P2P status.
intentFilter.addAction(WifiP2pManager.WIFI_P2P_STATE_CHANGED_ACTION);
// Indicates a change in the list of available peers.
intentFilter.addAction(WifiP2pManager.WIFI_P2P_PEERS_CHANGED_ACTION);
// Indicates the state of Wi-Fi P2P connectivity has changed.
intentFilter.addAction(WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION);
// Indicates this device's details have changed.
intentFilter.addAction(WifiP2pManager.WIFI_P2P_THIS_DEVICE_CHANGED_ACTION);
Log.wtf(TAG, "3/8");
// WifiP2pManager
manager = (WifiP2pManager) context.getSystemService(Context.WIFI_P2P_SERVICE);
channel = manager.initialize(context, context.getMainLooper(), null);
Log.wtf(TAG, "4/8");
// Detect available peers that are in range.
// get the list @onPeersAvailable
peers = new ArrayList<>();
serverPeer = new HashMap<>();
manager.discoverPeers(channel, new ActionListener() {
@Override
public void onSuccess() {
// Command successful! Code isn't necessarily needed here,
// Unless you want to update the UI or add logging statements.
String TAG = getClass().getName() + "discoverPeers@onSuccess: ";
Log.wtf(TAG, "OK");
}
@Override
public void onFailure(int arg0) {
// Command failed. Check for P2P_UNSUPPORTED, ERROR, or BUSY
String TAG = getClass().getName() + "discoverPeers@onFailure: ";
Log.wtf(TAG, "Oops!");
}
});
Log.wtf(TAG, "5/8");
registerService();
Log.wtf(TAG, "6/8");
discoverService();
Log.wtf(TAG, "7/8");
// BroadcastReceiver
receiver = new PmBroadcastReceiver(manager, channel, this);
context.registerReceiver(receiver, intentFilter);
Log.wtf(TAG, "8/8");
// TODO
// try {
// server = new Thread(new PmServer(this.pm));
// server.start();
// } catch (IOException e) {
// Log.wtf(TAG, e.getMessage());
// }
// TODO
Log.wtf(TAG, "OK");
}
//
public void onStop() {
String TAG = getClass().getName() + "@onStop: ";
Log.wtf(TAG, "...");
disconnect();
//// TODO
// if(server != null) {
// Log.wtf(TAG, "server");
// server.cancel(true);
// server = null;
//
//// serverSocket = null;
//
// }
manager.stopPeerDiscovery(channel, new ActionListener() {
@Override
public void onSuccess() {
String TAG = getClass().getName() + "stopPeerDiscovery@onSuccess: ";
Log.wtf(TAG, "OK");
}
@Override
public void onFailure(int reason) {
String TAG = getClass().getName() + "stopPeerDiscovery@onFailure: ";
Log.wtf(TAG, "Oops!");
}
});
manager.cancelConnect(channel, new ActionListener() {
@Override
public void onSuccess() {
String TAG = getClass().getName() + "cancelConnect@onSuccess: ";
Log.wtf(TAG, "OK");
}
@Override
public void onFailure(int reason) {
String TAG = getClass().getName() + "cancelConnect@onFailure: ";
Log.wtf(TAG, "Oops!");
}
});
manager.removeGroup(channel, new ActionListener() {
@Override
public void onSuccess() {
String TAG = getClass().getName() + "removeGroup@onSuccess: ";
Log.wtf(TAG, "OK");
}
@Override
public void onFailure(int reason) {
String TAG = getClass().getName() + "removeGroup@onFailure: ";
Log.wtf(TAG, "Oops!");
}
});
if (serviceInfo != null) {
manager.removeLocalService(channel, serviceInfo, new ActionListener() {
@Override
public void onSuccess() {
String TAG = getClass().getName() + "removeLocalService@onSuccess: ";
Log.wtf(TAG, "OK");
}
@Override
public void onFailure(int reason) {
String TAG = getClass().getName() + "removeLocalService@onFailure: ";
Log.wtf(TAG, "Oops!");
}
});
}
manager.clearServiceRequests(channel, new ActionListener() {
@Override
public void onSuccess() {
String TAG = getClass().getName() + "clearServiceRequests@onSuccess: ";
Log.wtf(TAG, "OK");
}
@Override
public void onFailure(int reason) {
String TAG = getClass().getName() + "clearServiceRequests@onFailure: ";
Log.wtf(TAG, "Oops!");
}
});
manager.clearLocalServices(channel, new ActionListener() {
@Override
public void onSuccess() {
String TAG = getClass().getName() + "clearLocalServices@onSuccess: ";
Log.wtf(TAG, "OK");
}
@Override
public void onFailure(int reason) {
String TAG = getClass().getName() + "clearLocalServices@onFailure: ";
Log.wtf(TAG, "Oops!");
}
});
context.unregisterReceiver(receiver);
Log.wtf(TAG, "OK");
}
// Register the PM service
private void registerService() {
String TAG = getClass().getName() + "@registerService: ";
Map record = new HashMap();
Log.wtf(TAG, "...");
// try {
// serverSocket = new ServerSocket(0);
// serverSocket = new ServerSocket(Globals.pm_port);
// serverSocket = new ServerSocket(); // <-- create an unbound socket first
// serverSocket.setReuseAddress(true);
// serverSocket.bind(new InetSocketAddress(Globals.pm_port)); // <-- now bind it
// Log.wtf(TAG, serverSocket.toString());
// record.put("port", String.valueOf(serverSocket.getLocalPort()));
record.put("usr", shrPrf.getString(Globals.shr_user, "user"));
record.put("dev", shrPrf.getString(Globals.shr_dev_id, "0"));
record.put("pm", String.valueOf(pm.getId()));
record.put("pref", String.valueOf(pm.getPreferences()));
Log.wtf(TAG, record.toString());
// } catch (IOException e) {
// Log.wtf(TAG, e.getMessage());
// }
// Service information. Pass it an instance name, service type
// _protocol._transportlayer , and the map containing
// information other devices will want once they connect to this one.
serviceInfo = WifiP2pDnsSdServiceInfo.newInstance("_eh", "_ftp._tcp", record);
Log.wtf(TAG, "Adding service...");
// Add the local service, sending the service info, network channel,
// and listener that will be used to indicate success or failure of
// the request.
manager.addLocalService(channel, serviceInfo, new ActionListener() {
@Override
public void onSuccess() {
String TAG = getClass().getName() + "addLocalService@onSuccess: ";
Log.wtf(TAG, "OK");
}
@Override
public void onFailure(int reason) {
String TAG = getClass().getName() + "addLocalService@onFailure: ";
Log.wtf(TAG, "Oops!");
}
});
}
//
private void discoverService() {
/**
* Register listeners for DNS-SD services. These are callbacks invoked
* by the system when a service is actually discovered.
*/
manager.setDnsSdResponseListeners(channel,
new DnsSdServiceResponseListener() {
@Override
public void onDnsSdServiceAvailable(String name, String type, WifiP2pDevice device) {
// A service has been discovered. Is this our app?
String TAG = getClass().getName() + "@onDnsSdServiceAvailable: ";
Log.wtf(TAG, "...");
Log.wtf(TAG, name + "" + type + "" + device.toString());
}
}, new DnsSdTxtRecordListener() {
// A new TXT record is available. Pick up the advertised name.
@Override
public void onDnsSdTxtRecordAvailable(String domain, Map<String, String> record, WifiP2pDevice device) {
String TAG = getClass().getName() + "@onDnsSdTxtRecordAvailable: ";
Log.wtf(TAG, "...");
Log.wtf(TAG, "Found " + domain.toString() + record.toString() + device.toString());
if (record.containsKey("pm") && record.get("pm") != null &&
String.valueOf(pm.getId()).equals(record.get("pm"))) {
Map<String, String> m = new HashMap<>();
m.put("mac", device.deviceAddress);
m.putAll(record);
Log.wtf(TAG, "Checking " + m);
if (!peers.contains(m)) {
for (Map p : peers) {
if (p.get("dev").equals(m.get("dev"))) {
Log.wtf(TAG, "Updating " + m);
p.putAll(m);
return;
}
}
Log.wtf(TAG, "Adding " + m);
peers.add(m);
}
pm.onPeersChanged(peers);
}
}
}
);
/**
* After attaching listeners, create a service request and initiate
* discovery.
*/
WifiP2pDnsSdServiceRequest serviceRequest = WifiP2pDnsSdServiceRequest.newInstance();
manager.addServiceRequest(channel, serviceRequest, new ActionListener() {
@Override
public void onSuccess() {
String TAG = getClass().getName() + "addServiceRequest@onSuccess: ";
Log.wtf(TAG, "OK");
}
@Override
public void onFailure(int reason) {
String TAG = getClass().getName() + "addServiceRequest@onFailure: ";
Log.wtf(TAG, "Oops!");
}
});
manager.discoverServices(channel, new ActionListener() {
@Override
public void onSuccess() {
String TAG = getClass().getName() + "discoverServices@onSuccess: ";
Log.wtf(TAG, "OK");
}
@Override
public void onFailure(int reason) {
String TAG = getClass().getName() + "discoverServices@onFailure: ";
Log.wtf(TAG, "Oops!");
}
});
}
/**
* Read an input stream and covert it to readable string.
*
* @param deviceAddress the MAC address of the peer.
*/
public void sendToPeer(String deviceAddress) {
String TAG = getClass().getName() + "@sendToPeer: ";
Log.wtf(TAG, deviceAddress);
Map<String, String> peer = getPeer(deviceAddress);
if (isConnected() && peer != null) {
Log.wtf(TAG, peer.toString());
serverPeer.putAll(peer);
Log.wtf(TAG, serverPeer.toString());
// client = new PmClient(serverPeer, pm);
// client.execute();
client = new Thread(new PmClient(serverPeer, this.pm));
client.start();
} else {
connect(deviceAddress);
}
}
/**
*
*/
public void connect(String deviceAddress) {
String TAG = getClass().getName() + "@connect: ";
Log.wtf(TAG, "Connecting to " + deviceAddress);
WifiP2pConfig config = new WifiP2pConfig();
config.deviceAddress = deviceAddress;
config.wps.setup = WpsInfo.PBC;
Log.wtf(TAG, "Config " + config.toString());
Map<String, String> peer = getPeer(deviceAddress);
if (peer != null) {
serverPeer.putAll(peer);
Log.wtf(TAG, "serverPeer == " + serverPeer.toString());
manager.connect(channel, config, new ActionListener() {
@Override
public void onSuccess() {
String TAG = getClass().getName() + "@connect: ";
Log.wtf(TAG, "OK");
}
@Override
public void onFailure(int reason) {
String TAG = getClass().getName() + "@connect: ";
Log.wtf(TAG, "error" + reason);
}
});
}
}
/**
*
*/
public void disconnect() {
String TAG = getClass().getName() + "@disconnect: ";
Log.wtf(TAG, "...");
setConnectionStatus(false);
if (client != null) {
Log.wtf(TAG, "client");
client.interrupt();
client = null;
// serverPeer = null;
}
if (server != null) {
Log.wtf(TAG, "server");
server.interrupt();
server = null;
// serverSocket = null;
}
}
/**
*
*/
public void setWifiP2pStatus(boolean status) {
wifiP2pStatus = status;
}
/**
*
*/
public boolean isWifiP2pEnabled() {
return wifiP2pStatus;
}
/**
*
*/
public void setConnectionStatus(boolean status) {
this.connectionStatus = status;
}
/**
*
*/
public boolean isConnected() {
return this.connectionStatus;
}
/**
* Tne WifiP2pManager.requestConnectionInfo(Channel, ConnectionInfoListener)
* returns connection info.
*/
@Override
public void onConnectionInfoAvailable(WifiP2pInfo info) {
String TAG = getClass().getName() + "@onConnectionInfoAvailable: ";
Log.wtf(TAG, "...");
Log.wtf(TAG, info.toString());
setConnectionStatus(true);
// TODO: EVAL
if (info.isGroupOwner) {
// if(Build.PRODUCT.equals(Globals.eval_dev)) {
// TODO: /EVAL
Log.wtf(TAG, "Connected as server");
/*
if (serverSocket != null) {
Log.wtf(TAG, "Executing server...");
server = new PmServer(serverSocket, pm);
server = new PmServer(pm);
server.execute();
} else {
Log.wtf(TAG, "No server socket");
}
*/
server = new Thread(new PmServer(this.pm));
server.start();
} else {
Log.wtf(TAG, "Connected as client");
/*
if (serverPeer != null) {
Log.wtf(TAG, "Executing client...");
serverPeer.put("ip", info.groupOwnerAddress.getHostAddress());
Log.wtf(TAG, "serverPeer " + serverPeer.toString());
sendToPeer(info.groupOwnerAddress.getHostAddress());
} else {
Log.wtf(TAG, "No server peer");
}
*/
if (serverPeer != null) {
Log.wtf(TAG, "Executing client...");
// TODO: EVAL
serverPeer.put("ip", info.groupOwnerAddress.getHostAddress()); //
// serverPeer.put("ip", Globals.eval_ip);
Log.wtf(TAG, "serverPeer " + serverPeer.toString());
sendToPeer(info.groupOwnerAddress.getHostAddress()); //
// sendToPeer(serverPeer.get("ip"));
// TODO: /EVAL
} else {
Log.wtf(TAG, "No server peer");
}
}
}
/**
* Tne WifiP2pManager.requestPeers(Channel, PeerListListener) returns the new
* WifiP2pDeviceList.
* <p/>
* Updates the:
* - Peers list
* - Service (PM) list
*/
@Override
public void onPeersAvailable(WifiP2pDeviceList peers) {
String TAG = getClass().getName() + "@onPeersAvailable: ";
Log.wtf(TAG, "...");
boolean update = false;
if (peers.getDeviceList().size() == 0) {
Log.wtf(TAG, "No devices found");
this.peers = new ArrayList<>();
update = true;
} else {
// Update the peers list
for (Map m : this.peers) {
boolean remove = true;
for (WifiP2pDevice d : peers.getDeviceList()) {
Log.wtf(TAG, m.get("mac") + " - " + d.deviceAddress);
if (m.get("mac").equals(d.deviceAddress)) {
Log.wtf(TAG, "Validated " + m);
remove = false;
break;
}
}
if (remove) {
Log.wtf(TAG, "Removing " + m);
this.peers.remove(m);
update = true;
}
}
}
if (update) {
Log.wtf(TAG, "Going to update peers...");
pm.onPeersChanged(this.peers);
} else {
Log.wtf(TAG, "Nothing changed");
}
}
//
public String getPeerAddress(int id) {
String TAG = getClass().getName() + "@getPeerAddress: ";
Log.wtf(TAG, "...");
for (Map m : this.peers) {
Log.wtf(TAG, m.get("dev") + " - " + id);
if (Integer.parseInt((String) m.get("dev")) == id) {
Log.wtf(TAG, m.get("mac").toString());
return m.get("mac").toString();
}
}
return "";
}
//
public Map<String, String> getPeer(String deviceAddress) {
String TAG = getClass().getName() + "@getPeer: ";
Log.wtf(TAG, "...");
Log.wtf(TAG, "Finding peer with address " + deviceAddress);
for (Map m : this.peers) {
Log.wtf(TAG, "" + deviceAddress + " - " + m.get("mac"));
if (m.get("mac").equals(deviceAddress)) {
Log.wtf(TAG, "Returning " + m.toString());
return m;
}
}
Log.wtf(TAG, "Could not find peer with address " + deviceAddress);
return null;
}
}

View File

@ -0,0 +1,92 @@
package com.www.client.pm;
import android.os.AsyncTask;
import android.os.Handler;
import android.util.Log;
import com.www.client.Globals;
import com.www.client.Utils;
import java.io.*;
import java.net.*;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
//public class PmServer extends AsyncTask {
public class PmServer implements Runnable {
ServerSocket ss;
PrivacyMechanism pm;
public PmServer(PrivacyMechanism pm) {
String TAG = getClass().getName() + "";
this.pm = pm;
try {
this.ss = new ServerSocket(Globals.pm_port);
Log.wtf(TAG, "Socket opened");
} catch (IOException e) {
// Log.wtf(TAG, e.getMessage());
e.printStackTrace();
}
}
@Override
public void run() {
String TAG = getClass().getName() + "@run";
while (!Thread.currentThread().isInterrupted()) {
try {
Log.wtf(TAG, "Waiting for client...");
Socket s = ss.accept();
try {
// Read from the InputStream
Log.wtf(TAG, "1/6");
InputStream is = s.getInputStream();
Log.wtf(TAG, "2/6");
pm.aggregateData(is);
Log.wtf(TAG, "3/6");
Utils.close(is);
Log.wtf(TAG, "4/6");
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
s.close();
Log.wtf(TAG, "5/6");
} catch (IOException e) {
e.printStackTrace();
}
}
} catch (IOException e) {
try {
Log.wtf(TAG, "6/6");
if (ss != null && !ss.isClosed()) {
ss.close();
}
} catch (IOException ioe) {
ioe.printStackTrace();
}
e.printStackTrace();
break;
}
}
}
}

View File

@ -0,0 +1,458 @@
package com.www.client.pm;
import com.www.client.Globals;
import com.www.client.Utils;
import android.content.*;
import android.net.Uri;
import android.os.AsyncTask;
import android.preference.*;
import android.util.Log;
import org.apache.commons.io.FilenameUtils;
import java.io.*;
import java.lang.reflect.*;
import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.*;
import dalvik.system.*;
public class PrivacyMechanism implements SharedPreferences.OnSharedPreferenceChangeListener {
private static Context context;
private static SharedPreferences sp;
private static SharedPreferences.OnSharedPreferenceChangeListener spLsnr;
private int stId, pmId, pmPreferences;
private String pmClssName;
private Class<Object> pmClss;
private Object pmInst;
private Method pmMthd;
PmP2p pmP2p;
public PrivacyMechanism (Context c, int pm, int st) {
final String TAG = getClass().getName() + "@PrivacyMechanism: ";
context = c;
sp = PreferenceManager.getDefaultSharedPreferences(c);
pmId = pm;
stId = st;
String pmDir = Globals.pms_dir + "/" + pmId;
String stDir = Globals.client_dir + "/" + stId;
/**/
pmClssName = sp.getString(Globals.pm_clss, null);
String pmZipUrl = pmDir + "/" + pmId + ".zip";
File dex = c.getDir("dex", 0);
DexClassLoader classLoader = new DexClassLoader(pmZipUrl, dex.getAbsolutePath(), null, this.getClass().getClassLoader());
try {
if (pmClss == null) {
Log.wtf(TAG, "Instantiating PM " + pmId + " with class '" + pmClssName + "' for ST " + stId + " from " + pmZipUrl);
pmClss = (Class<Object>) classLoader.loadClass(pmClssName);
pmInst = pmClss.newInstance();
} else {
Log.wtf(TAG, "PM " + pmId + " with class '" + pmClssName + "' for ST " + stId + " already instantiated.");
}
} catch (Exception e) {
Log.wtf(TAG, e.getMessage());
}
/**/
}
/**
* PrivacyMechanism functions
*/
/**
* void onStart (Context, int, ObjectInputStream)
*/
public void onStart () {
final String TAG = getClass().getName() + "@onStart: ";
Log.wtf(TAG, "...");
sp.registerOnSharedPreferenceChangeListener(this);
pmPreferences = sp.getInt(Globals.privacy_level, 0);
try {
ObjectInputStream ois = Utils.getStateFrom(getId());
// void onStart (Context, int, ObjectInputStream)
pmMthd = pmClss.getMethod(
"onStart",
Context.class,
int.class,
ObjectInputStream.class);
pmMthd.invoke(
pmInst,
context,
sp.getInt(Globals.privacy_level, 0),
ois);
Utils.close(ois);
// Collaborative staff
/**/
try {
// void onPeersChanged (List<Map<String, String>>
pmClss.getMethod("onPeersChanged",
List.class);
pmP2p = new PmP2p(context, this);
} catch (NoSuchMethodException e) {
Log.wtf(TAG, "Could not find " + e.getMessage());
}
try {
// boolean aggregateData (ObjectInputStream, ObjectOutputStream)
pmClss.getMethod("aggregateData",
ObjectInputStream.class,
ObjectOutputStream.class);
if(pmP2p == null) {
pmP2p = new PmP2p(context, this);
}
} catch (NoSuchMethodException e) {
Log.wtf(TAG, "Could not find " + e.getMessage());
}
/**/
} catch (Exception e) {
Log.wtf(TAG, e.getMessage());
}
}
/**
* void onStop ()
*/
public void onStop () {
final String TAG = getClass().getName() + "@onStop: ";
Log.wtf(TAG, "...");
if(pmP2p != null) {
pmP2p.onStop();
pmP2p = null;
}
/**/
sp.unregisterOnSharedPreferenceChangeListener(this);
// save state
saveState();
// stop
try {
// void onStop ()
pmMthd = pmClss.getMethod(
"onStop");
pmMthd.invoke(
pmInst);
} catch (Exception e) {
Log.wtf(TAG, e.getMessage());
}
pmClss = null;
/**/
}
/**
* int processData (ObjectInputStream, ObjectOutputStream)
* @param data
*/
public void processData (List<Object> data) {
String TAG = getClass().getName() + "@processData: ";
Log.wtf(TAG, "...");
/*
* process data
*/
int devId = 0;
String dataPath = Utils.getNewDataPath(getStId());
Log.wtf(TAG, "Saving data to " + dataPath);
ObjectInputStream ois = Utils.getData(data);
ObjectOutputStream oos = Utils.putData(dataPath);
try {
// int processData (ObjectInputStream, ObjectOutputStream)
pmMthd = pmClss.getMethod(
"processData",
ObjectInputStream.class,
ObjectOutputStream.class);
devId = (int) pmMthd.invoke(
pmInst,
ois,
oos);
Utils.close(oos);
Utils.close(ois);
} catch (Exception e) {
Log.wtf(TAG, e.getMessage());
}
// saveState(getId());
/**
* Send to server or aggregator
*/
Log.wtf(TAG, "devId == " + devId);
if (devId == 0) {
Log.wtf(TAG, "1");
// Log.wtf(TAG, "Renaming data to " + new File(FilenameUtils.removeExtension(dataPath)).getPath());
// new File(dataPath).renameTo(new File(FilenameUtils.removeExtension(dataPath)));
Utils.saveData(Utils.getData(dataPath), String.valueOf(getStId()));
new File(dataPath).delete();
} else if (devId < 0) {
Log.wtf(TAG, "2");
Log.wtf(TAG, "Deleting data " + dataPath);
new File(dataPath).delete();
} else {
Log.wtf(TAG, "3");
String address = pmP2p.getPeerAddress(devId);
if(pmP2p.isWifiP2pEnabled() && !address.isEmpty()) {
Log.wtf(TAG, "Sending data to " + devId);
Utils.mergeData(dataPath, Globals.pms_dir + "/" + pmId + "/" + devId + ".dat");
pmP2p.sendToPeer(address);
} else {
Log.wtf(TAG, pmP2p.isWifiP2pEnabled() + " | " + address);
Utils.saveData(Utils.getData(dataPath), String.valueOf(getStId()));
new File(dataPath).delete();
}
}
}
/**
* boolean saveState (ObjectOutputStream)
* Called in:
* - onStop
* - processData
* - aggregateData
*/
private void saveState() {
String TAG = getClass().getName() + "@saveState: ";
Log.wtf(TAG, "...");
String url = Globals.pms_dir + "/" + getId() + "/" + getId() + ".sav";
Log.wtf(TAG, url);
try {
ObjectOutputStream oos = Utils.putStateTo(url);
// boolean saveState (ObjectOutputStream)
pmMthd = pmClss.getMethod(
"saveState",
ObjectOutputStream.class);
boolean flag = (boolean) pmMthd.invoke(
pmInst,
oos);
Utils.close(oos);
if (flag) {
Log.wtf(TAG, "OK");
} else {
Log.wtf(TAG, "No state saved");
new File(url).delete();
}
} catch (Exception e) {
Log.wtf(TAG, e.getMessage());
}
}
/**
* void onPreferenceChanged (int)
* Monitor if user changes the privacy level and inform the PM
* @param sharedPreferences
* @param key
*/
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
final String TAG = getClass().getName() + "@onSharedPreferenceChanged: ";
if (Globals.privacy_level.equals(key)) {
Log.wtf(TAG, "new privacy level " + sp.getInt(Globals.privacy_level, 0));
pmPreferences = sp.getInt(Globals.privacy_level, 0);
/*
* Call onPreferencesChanged
*/
try {
// void onPreferenceChanged (int)
pmMthd = pmClss.getMethod(
"onPreferenceChanged",
int.class);
pmMthd.invoke(
pmInst,
sp.getInt(Globals.privacy_level, 0));
} catch (Exception e) {
Log.wtf(TAG, "" + e.getMessage());
}
}
}
/**
* void onPeersChanged (List<Map<String, String>>)
* @param peers
*/
void onPeersChanged (List<Map<String, String>> peers) {
String TAG = getClass().getName() + "@onPeersChanged: ";
Log.wtf(TAG, "...");
List<Map<String, String>> list = new ArrayList<>();
for (Map<String, String> p : peers) {
Map<String, String> m = new HashMap<>();
m.put("id", p.get("dev"));
m.put("pref", p.get("pref"));
list.add(m);
}
Log.wtf(TAG, list.toString());
try {
// void onPeersChanged (List<Map<String, String>>)
pmMthd = pmClss.getMethod(
"onPeersChanged",
List.class);
pmMthd.invoke(
pmInst,
list);
} catch (Exception e) {
Log.wtf(TAG, e.getMessage());
}
}
/**
* boolean aggregateData (ObjectInputStream, ObjectOutputStream)
* Called by PmP2p > connect > onConnectionInfoAvailable > PmServer
* @param is
*/
public void aggregateData(InputStream is) {
String TAG = getClass().getName() + "@aggregateData: ";
Log.wtf(TAG, "...");
try {
Log.wtf(TAG, "1");
ObjectInputStream ois = new ObjectInputStream(is);
Log.wtf(TAG, "2");
String dataPath = Utils.getNewDataPath(getStId());
Log.wtf(TAG, "3");
ObjectOutputStream oos = Utils.putData(dataPath);
Log.wtf(TAG, "4");
boolean flag = false;
try {
// boolean aggregateData (ObjectInputStream, ObjectOutputStream)
pmMthd = pmClss.getMethod(
"aggregateData",
ObjectInputStream.class,
ObjectOutputStream.class);
Log.wtf(TAG, "5");
flag = (boolean) pmMthd.invoke(
pmInst,
ois,
oos);
Log.wtf(TAG, "6");
} catch (Exception e) {
Log.wtf(TAG, e.getMessage());
}
Log.wtf(TAG, "7");
Utils.close(oos);
Utils.close(ois);
Utils.close(is);
Log.wtf(TAG, "8");
if (flag) {
Utils.saveData(Utils.getData(dataPath), String.valueOf(getStId()));
}
Log.wtf(TAG, "9");
new File(dataPath).delete();
Log.wtf(TAG, "10");
saveState();
Log.wtf(TAG, "11");
} catch (Exception e) {
Log.wtf(TAG, e.getMessage());
}
Log.wtf(TAG, "OK");
}
/**
* Misc.
*/
public int getId () {
final String TAG = getClass().getName() + "@getId: ";
return pmId;
}
public int getVersion() {
//TODO
return 0;
}
public int getPreferences() {
String TAG = getClass().getName() + "@getPreferences: ";
return pmPreferences;
}
public int getStId () {
String TAG = getClass().getName() + "@getStId: ";
return stId;
}
}

View File

@ -0,0 +1,76 @@
package com.www.client.pm;
import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import com.www.client.ClientActivity;
import com.www.client.R;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.List;
public class PrivacyMechanismArrayAdapter extends ArrayAdapter<String> {
private static final String TAG = "PrivacyMechanismArrayAdapter";
Context context;
public PrivacyMechanismArrayAdapter(Context context, int resourceId, List<String> items) {
super(context, resourceId, items);
this.context = context;
}
/*private view holder class*/
private class ViewHolder {
TextView nameView;
TextView userView;
TextView statusView;
}
public View getView(int position, View view, ViewGroup group) {
ViewHolder holder = null;
JSONObject item = null;
try {
item = new JSONObject(getItem(position));
} catch (JSONException e) {
e.printStackTrace();
}
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
if (view == null) {
view = inflater.inflate(R.layout.privacy_mechanism_item, null);
holder = new ViewHolder();
holder.nameView = (TextView) view.findViewById(R.id.name);
holder.userView = (TextView) view.findViewById(R.id.user);
holder.statusView = (TextView) view.findViewById(R.id.status);
view.setTag(holder);
}
else {
holder = (ViewHolder) view.getTag();
}
try {
if (item != null) {
holder.nameView.setText(item.getJSONArray("name").getString(0));
holder.userView.setText("by " + item.getJSONArray("user").getString(0));
if(ClientActivity.sharedPref.getString("pmID", null) != null &&
item.getJSONArray("id").getString(0).equals(ClientActivity.sharedPref.getString("pmID", null))) {
holder.statusView.setText("INSTALLED");
} else {
holder.statusView.setText(" ");
}
}
} catch (Exception e) {
e.printStackTrace();
}
return view;
}
}

View File

@ -0,0 +1,184 @@
package com.www.client.pm;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.net.ConnectivityManager;
import android.os.Bundle;
import android.os.Environment;
import android.preference.PreferenceManager;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.SeekBar;
import android.widget.TextView;
import com.www.client.Globals;
import com.www.client.R;
public class PrivacyMechanismsActivity extends Activity implements SeekBar.OnSeekBarChangeListener {
private static final String TAG = "PrivacyMechanismsActivity";
private static final String SDCARD = Environment.getExternalStorageDirectory().getPath();
public static final String CLIENT = SDCARD + "/Client";
private static ConnectivityManager cm;
public static SharedPreferences sp = null;
public static SharedPreferences.Editor spEditor = null;
SeekBar seekBar;
TextView statusText;
TextView levelText;
TextView commentText;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_privacy_mechanisms);
cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
sp = PreferenceManager.getDefaultSharedPreferences(this);
spEditor = sp.edit();
statusText = (TextView) findViewById(R.id.status);
statusText.setText("LOW");
statusText.setTextColor(Color.rgb(255, 0, 0));
levelText = (TextView) findViewById(R.id.level);
commentText = (TextView) findViewById(R.id.comment);
seekBar = (SeekBar) findViewById(R.id.level_bar);
seekBar.setOnSeekBarChangeListener(this);
seekBar.setProgress(sp.getInt(Globals.privacy_level, 0));
seekBar.setSecondaryProgress(sp.getInt(Globals.privacy_level, 0));
levelText.setText("");
/*
* Buttons
*/
findViewById(R.id.ok_btn).setOnClickListener(okListener);
findViewById(R.id.cancel_btn).setOnClickListener(cancelListener);;
// install
// Button getListBtn = (Button)findViewById(R.id.get_list_btn);
// getListBtn.setOnClickListener(new View.OnClickListener() {
// public void onClick(View v) {
//// startActivity(new Intent(getBaseContext(), AddPrivacyRegionActivity.class));
// Toast.makeText(getApplicationContext(), "list", Toast.LENGTH_SHORT).show();
// }
// });
// view installed
// Button viewBtn = (Button)findViewById(R.id.view_btn);
// viewBtn.setOnClickListener(new View.OnClickListener() {
// public void onClick(View v) {
//// startActivity(new Intent(getBaseContext(), AddPrivacyRegionActivity.class));
// Toast.makeText(getApplicationContext(), "view", Toast.LENGTH_SHORT).show();
// }
// });
}
/*
* Action bar menu methods
*/
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_privacy_mechanisms, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.privacy_mechanisms_get_list) {
// Toast.makeText(getApplicationContext(), "list", Toast.LENGTH_SHORT).show();
Intent i = new Intent(this, ListPrivacyMechanismsActivity.class);
startActivity(i);
return true;
}
if (id == R.id.privacy_mechanisms_view_installed) {
// Toast.makeText(getApplicationContext(), "in", Toast.LENGTH_SHORT).show();
Intent i = new Intent(this, ViewPrivacyMechanismActivity.class);
i.putExtra("intent", "view");
startActivity(i);
return true;
}
return super.onOptionsItemSelected(item);
}
/*
* Seekbar methods
*/
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
int r = (255 * (100 - progress)) / 100;
int g = (255 * progress) / 100;
int b = 0;
levelText.setTextColor(Color.rgb(r, g, b));
levelText.setText(progress + "%");
statusText.setTextColor(Color.rgb(r, g, b));
if (progress < 33) {
statusText.setText("LOW");
} else if (progress >= 33 && progress <66) {
statusText.setText("MEDIUM");
} else {
statusText.setText("HIGH");
}
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
levelText.setText("");
}
private void updateContentView(int i) {
}
/*
* Buttons
*/
private View.OnClickListener okListener = new View.OnClickListener() {
// OK button
public void onClick(View v) {
String TAG = getClass().getName() + "@onClick: ";
seekBar.setSecondaryProgress(seekBar.getProgress());
spEditor.putInt(Globals.privacy_level, seekBar.getProgress());
spEditor.commit();
Log.wtf(TAG, Globals.privacy_level + " -> " + seekBar.getProgress());
}
};
private View.OnClickListener cancelListener = new View.OnClickListener() {
// Cancel button
public void onClick(View v) {
seekBar.setProgress(sp.getInt(Globals.privacy_level, 0));
seekBar.setSecondaryProgress(sp.getInt(Globals.privacy_level, 0));
levelText.setText("");
}
};
}

View File

@ -0,0 +1,333 @@
package com.www.client.pm;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.os.Environment;
import android.preference.PreferenceManager;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.ListView;
import android.widget.ScrollView;
import android.widget.TextView;
import android.widget.Toast;
import com.www.client.ClientActivity;
import com.www.client.Globals;
import com.www.client.R;
import com.www.client.Utils;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.File;
import java.io.IOException;
import java.text.DecimalFormat;
import java.util.ArrayList;
public class ViewPrivacyMechanismActivity extends Activity {
String sdcard = Environment.getExternalStorageDirectory().getPath();
String clientDir = sdcard + "/Client";
String pmsDir = clientDir + "/PMs";
SharedPreferences sp = null;
SharedPreferences.Editor spEditor = null;
String parentActivity = "";
TextView textView;
Button button;
ScrollView scrollView;
@Override
protected void onCreate(Bundle savedInstanceState) {
String TAG = ViewPrivacyMechanismActivity.class.getName() + "@onCreate: ";
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_view_privacy_mechanism);
sp = PreferenceManager.getDefaultSharedPreferences(this);
spEditor = sp.edit();
final Intent i = getIntent();
button = (Button)findViewById(R.id.button);
button.setText("Install");
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
button.setEnabled(false);
if("Install".equals(button.getText())) {
button.setText("Installing...");
Toast.makeText(getApplicationContext(), "Installing...", Toast.LENGTH_SHORT).show();
/*
* Remove previous PM
*/
if(sp.getString("pmID", null) != null) {
removePM(sp.getString("pmID", null));
}
spEditor.putString("pmID", i.getStringExtra("id"));
spEditor.putString("pmName", i.getStringExtra("name"));
spEditor.putString("pmVersion", i.getStringExtra("version"));
//
// class name
//
spEditor.putString(Globals.pm_clss, i.getStringExtra("class"));
//
// st id
//
spEditor.putString(Globals.pm_st_id, sp.getString(Globals.st_id, "0"));
//
//
//
spEditor.putString("pmDescription", i.getStringExtra("description"));
spEditor.putString("pmUser", i.getStringExtra("user"));
spEditor.putString("pmDate", i.getStringExtra("date"));
spEditor.putString("pmTime", i.getStringExtra("time"));
spEditor.putString("pmSize", i.getStringExtra("size"));
spEditor.commit();
getPM();
// Toast.makeText(getApplicationContext(), "Done", Toast.LENGTH_SHORT).show();
// button.setText("Uninstall");
} else {
button.setText("Uninstalling...");
Toast.makeText(getApplicationContext(), "Uninstalling...", Toast.LENGTH_SHORT).show();
removePM(sp.getString("pmID", null));
Toast.makeText(getApplicationContext(), "Done", Toast.LENGTH_SHORT).show();
// button.setText("Install");
// returnToParent();
finish();
}
// button.setEnabled(true);
}
});
if("get".equals(i.getStringExtra("intent"))) {
// Came here from the list
parentActivity = "ListPrivacyMechanismsActivity";
textView = (TextView) findViewById(R.id.message);
textView.setVisibility(View.INVISIBLE);
if(i.getStringExtra("id").equals(sp.getString("pmID", null))) {
button.setText("Uninstall");
}
textView = (TextView) findViewById(R.id.name);
textView.setText(i.getStringExtra("name"));
setTitle(i.getStringExtra("name"));
textView = (TextView) findViewById(R.id.version);
textView.setText("version " + i.getStringExtra("version") + ".0");
textView = (TextView) findViewById(R.id.user);
textView.setText("by " + i.getStringExtra("user"));
textView = (TextView) findViewById(R.id.description);
textView.setText(i.getStringExtra("description"));
textView = (TextView) findViewById(R.id.date_time);
textView.setText(i.getStringExtra("date") + "\n" + i.getStringExtra("time"));
textView = (TextView) findViewById(R.id.size);
// textView.setText(i.getStringExtra("size") + "b");
textView.setText(String.format( "%.2f", Float.valueOf(i.getStringExtra("size")) /1000) + " KB");
textView = (TextView) findViewById(R.id.id);
textView.setText(i.getStringExtra("id"));
} else {
// Came here from the PM settings
parentActivity = "PrivacyMechanismsActivity";
if(sp.getString("pmID", null) != null) {
textView = (TextView) findViewById(R.id.message);
textView.setVisibility(View.INVISIBLE);
button.setText("Uninstall");
textView = (TextView) findViewById(R.id.name);
textView.setText(sp.getString("pmName", ""));
setTitle(sp.getString("pmName", ""));
textView = (TextView) findViewById(R.id.version);
textView.setText("version " + sp.getString("pmVersion", "") + ".0");
textView = (TextView) findViewById(R.id.user);
textView.setText("by " + sp.getString("pmUser", ""));
textView = (TextView) findViewById(R.id.description);
textView.setText(sp.getString("pmDescription", ""));
textView = (TextView) findViewById(R.id.date_time);
textView.setText(sp.getString("pmDate", "") + "\n" + sp.getString("pm_time", ""));
textView = (TextView) findViewById(R.id.size);
textView.setText(String.format( "%.2f", Float.valueOf(sp.getString("pmSize", "0"))/1000) + " KB");
textView = (TextView) findViewById(R.id.id);
textView.setText(sp.getString("pmID", ""));
} else {
scrollView = (ScrollView) findViewById(R.id.content);
scrollView.setVisibility(View.INVISIBLE);
textView = (TextView) findViewById(R.id.message);
textView.setText("No privacy mechanism installed");
}
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
// getMenuInflater().inflate(R.menu.menu_view_privacy_mechanism, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
// Respond to the action bar's Up/Home button
if (id == android.R.id.home) {
returnToParent();
}
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
private boolean returnToParent() {
Intent i = null;
try {
i = new Intent(this, Class.forName("com.www.client.pm." + parentActivity));
startActivity(i);
finish();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
return true;
}
private void getPM() {
String TAG = ViewPrivacyMechanismActivity.class.getName() + "@getPM: ";
// Toast.makeText(getApplicationContext(), "Getting list...", Toast.LENGTH_SHORT).show();
String deviceID = sp.getString("deviceID", null);
String pmID = sp.getString("pmID", null);
if (deviceID != null && pmID != null) {
if (ClientActivity.isOnline()) {
String url = Globals.pms_url + "/" + pmID + "/getbin/" + deviceID;
Log.wtf(TAG, url);
// Toast.makeText(getApplicationContext(), url, Toast.LENGTH_SHORT).show();
new GetPM().execute(url);
} else {
Log.wtf(TAG, "Offline.");
Toast.makeText(getApplicationContext(), "No network connection", Toast.LENGTH_SHORT).show();
}
} else {
Log.wtf(TAG, "Not registered yet");
Toast.makeText(getApplicationContext(), "Not registered yet", Toast.LENGTH_SHORT).show();
}
}
private class GetPM extends AsyncTask<String, Void, String> {
@Override
protected String doInBackground(String... params) {
String TAG = GetPM.class.getName() + "@doInBackground: ";
Log.wtf(TAG, "...");
HttpClient client = new DefaultHttpClient();
HttpGet request = new HttpGet(params[0]);
HttpResponse response = null;
String result = "Oops!";
try {
response = client.execute(request);
if (response != null) {
String dir = pmsDir + "/" + sp.getString("pmID", null);
Log.wtf(TAG, dir);
new File(dir).mkdir();
String url = dir + "/" + sp.getString("pmID", null) + ".zip";
Log.wtf(TAG, url);
Utils.writeToFile(response.getEntity().getContent(), url);
Log.wtf(TAG, Long.toString(new File(url).length()) + " == " + sp.getString("pmSize", null));
if(new File(url).length() == Long.valueOf(sp.getString("pmSize", null))) {
result = "OK";
}
}
} catch (IOException e) {
Log.e(TAG, e.getMessage());
}
return result;
}
protected void onPostExecute(String result) {
String TAG = GetPM.class.getName() + "@onPostExecute: ";
Log.wtf(TAG, result);
if(!"OK".equals(result)) {
Toast.makeText(getApplicationContext(), result, Toast.LENGTH_SHORT).show();
removePM(sp.getString("pmID", null));
button.setText("Install");
button.setEnabled(true);
} else {
Toast.makeText(getApplicationContext(), "Done", Toast.LENGTH_SHORT).show();
// returnToParent();
finish();
}
}
}
private void removePM(String id) {
Utils.delete(new File(pmsDir + "/" + id.toString()));
spEditor.putString("pmID", null);
spEditor.putString("pmName", null);
spEditor.putString("pmVersion", null);
//
// class name
spEditor.putString(Globals.pm_clss, null);
//
// sensing task id
spEditor.putString(Globals.pm_st_id, null);
//
spEditor.putString("pmDescription", null);
spEditor.putString("pmUser", null);
spEditor.putString("pmDate", null);
spEditor.putString("pmTime", null);
spEditor.putString("pmSize", null);
spEditor.commit();
}
}

View File

@ -0,0 +1,152 @@
package com.www.client.pr;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.GoogleMapOptions;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.model.LatLngBounds;
import com.www.client.R;
import com.www.client.Utils;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;
public class AddPrivacyRegionActivity extends Activity {
private static final String TAG = "AddPrivacyRegionActivity";
private GoogleMap regionMap = null;
private EditText region_label = null;
private static final String SDCARD = Environment.getExternalStorageDirectory().getPath();
public static final String CLIENT = SDCARD + "/Client";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_add_privacy_region);
GoogleMapOptions mapOptions = new GoogleMapOptions();
regionMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.region_map)).getMap();
region_label = (EditText) findViewById(R.id.region_label);
//region_label.setImeActionLabel("OK", EditorInfo.IME_ACTION_DONE);
region_label.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
region_label.setError(null);
}
});/**/
/*region_label.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
region_label.setError(null);
}
@Override
public void afterTextChanged(Editable editable) {}
});
/*region_label.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_DONE) {
addPrivacyRegion();
}
return false;
}
});/**/
//region_label.setImeActionLabel("OK", KeyEvent.KEYCODE_ENTER);
final TextView info = (TextView) findViewById(R.id.info);
info.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
info.setVisibility(View.GONE);
}
});/**/
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.add_privacy_region, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_ok) {
//Toast.makeText(getApplicationContext(), "onOptionsItemSelected: " + "OK", Toast.LENGTH_SHORT).show();
addPrivacyRegion();
return true;
}/**/
if (id == R.id.action_cancel) {
//Toast.makeText(getApplicationContext(), "onOptionsItemSelected: " + "CANCEL", Toast.LENGTH_SHORT).show();
finish();
return true;
}/**/
return super.onOptionsItemSelected(item);
}
public void addPrivacyRegion() {
if(region_label.getText().toString().trim().equals("")) {
region_label.setError("Region label is required!");
}
else {
region_label.setError(null);
LatLngBounds bounds = regionMap.getProjection().getVisibleRegion().latLngBounds;
String label = region_label.getText().toString();
/*Toast.makeText(getApplicationContext(), region_label.getText().toString() + "\n"
+ bounds.northeast.latitude + " - " + bounds.northeast.longitude + "\n"
+ bounds.southwest.latitude + " - " + bounds.southwest.longitude, Toast.LENGTH_SHORT).show();/**/
JSONObject region = new JSONObject();
try {
region.put("label", label);
SimpleDateFormat sdf = new SimpleDateFormat("yyMMdd_HHmmss");
region.put("id", sdf.format(new Date()));
region.put("ne_lat", bounds.northeast.latitude);
region.put("ne_lng", bounds.northeast.longitude);
region.put("sw_lat", bounds.southwest.latitude);
region.put("sw_lng", bounds.southwest.longitude);
Log.i(TAG, "addPrivacyRegion: " + region.toString());
} catch (JSONException e) {
e.printStackTrace();
}
Utils.writeJSONtoFile(region, new File(CLIENT + "/" + "Settings" + "/" + "PrivacyRegions"));
try {
Toast.makeText(getApplicationContext(), "\"" + region.getString("label") + "\" " + " has been added.", Toast.LENGTH_SHORT).show();
} catch (JSONException e) {
e.printStackTrace();
}
/**/
startActivity(new Intent(getBaseContext(), PrivacyRegionsActivity.class));
}
}
}

View File

@ -0,0 +1,142 @@
package com.www.client.pr;
import java.util.*;
import java.io.*;
import android.content.Context;
import android.util.*;
@SuppressWarnings("unchecked")
public class Demo {
private Context context;
private int pref;
private List <Object> state;
private List<Map<String, String>> peers;
public void onStart (Context c, int i, ObjectInputStream ois) throws Exception {
String TAG = getClass().getName() + "@onStart: ";
Log.wtf(TAG, "...");
// get application context
context = c;
// get privacy preferences
pref = i;
// restore state
if (ois != null) {
Log.wtf(TAG, "Restoring state...");
state = (List<Object>) ois.readObject();
} else {
Log.wtf(TAG, "Initializing state...");
state = new ArrayList<>();
}
peers = new ArrayList<>();
}
public void onStop () {
String TAG = getClass().getName() + "@onStop: ";
Log.wtf(TAG, "...");
}
public void onPreferenceChanged (int i) {
String TAG = getClass().getName() + "@onPreferenceChanged: ";
Log.wtf(TAG, "" + i);
pref = i;
}
public boolean saveState (ObjectOutputStream oos) {
String TAG = getClass().getName() + "@saveState: ";
Log.wtf(TAG, "...");
// s.writeObject(state);
return false;
}
public int processData (ObjectInputStream ois, ObjectOutputStream oos) throws Exception {
String TAG = getClass().getName() + "@processData: ";
Log.wtf(TAG, "...");
// get list of data
List <Object> list = (List<Object>) ois.readObject();
// edit each data entry of the data list
for (Object o : list) {
Map data = (Map) o;
data.put("device", data.get("device"));
data.put("task", data.get("task"));
data.put("sensor", data.get("sensor"));
data.put("values", data.get("values"));
float min = -1;
float max = 1;
Random r = new Random();
float d = min + (max - min) * r.nextFloat(); // -1 < d < 1
long var = (long) (((float) pref / 10) * d * 3600000000000L); // (pref/10) * random * (1hr)
data.put("timestamp", (Long) data.get("timestamp") + var);
}
oos.writeObject(list);
// If a peer is present
Log.wtf(TAG, "Returning...");
if(!peers.isEmpty()) {
// Collaborate
Log.wtf(TAG, peers.get(0).get("id"));
return Integer.parseInt(peers.get(0).get("id"));
}
Log.wtf(TAG, "No peers");
return 0;
}
/*
* Collaborative stuff
*/
/**/
public void onPeersChanged (List<Map<String, String>> peers) {
String TAG = getClass().getName() + "@onPeersChanged: ";
Log.wtf(TAG, "...");
this.peers = peers;
Log.wtf(TAG, peers.toString());
}
public boolean aggregateData (ObjectInputStream ois, ObjectOutputStream oos) throws Exception {
String TAG = getClass().getName() + "@aggregateData: ";
Log.wtf(TAG, "...");
// Read input stream
List <Object> data = (List<Object>) ois.readObject();
// Write to output stream
oos.writeObject(data);
return true;
}
/**/
}

View File

@ -0,0 +1,188 @@
package com.www.client.pr;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewTreeObserver;
import android.widget.EditText;
import android.widget.Toast;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.LatLngBounds;
import com.www.client.R;
import com.www.client.Utils;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
public class EditPrivacyRegionActivity extends Activity {
private static final String TAG = "EditPrivacyRegionActivity";
private JSONObject privacyRegion = null;
private GoogleMap regionMap = null;
private EditText region_label = null;
private static final String SDCARD = Environment.getExternalStorageDirectory().getPath();
public static final String CLIENT = SDCARD + "/Client";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_edit_privacy_region);
try {
privacyRegion = new JSONObject((String) getIntent().getSerializableExtra("privacyRegion"));
//Log.i(TAG, privacyRegion.toString());
setTitle(privacyRegion.getString("label"));
} catch (JSONException e) {
e.printStackTrace();
}
regionMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.region_map)).getMap();
final View mapView = getFragmentManager().findFragmentById(R.id.region_map).getView();
LatLngBounds.Builder bounds;
bounds = new LatLngBounds.Builder();
if (mapView.getViewTreeObserver().isAlive()) {
mapView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@SuppressLint("NewApi") // We check which build version we are using.
@Override
public void onGlobalLayout() {
LatLngBounds bounds = null;
try {
bounds = new LatLngBounds.Builder()
.include(new LatLng(privacyRegion.getDouble("ne_lat"), privacyRegion.getDouble("ne_lng")))
.include(new LatLng(privacyRegion.getDouble("sw_lat"), privacyRegion.getDouble("sw_lng")))
.build();
} catch (JSONException e) {
e.printStackTrace();
}
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
mapView.getViewTreeObserver().removeGlobalOnLayoutListener(this);
} else {
mapView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
}
regionMap.moveCamera(CameraUpdateFactory.newLatLngBounds(bounds, 0));
}
});
}
region_label = (EditText) findViewById(R.id.region_label);
try {
region_label.setText(privacyRegion.getString("label"));
} catch (JSONException e) {
e.printStackTrace();
}
//region_label.setImeActionLabel("OK", EditorInfo.IME_ACTION_DONE);
region_label.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
region_label.setError(null);
}
});/**/
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.edit_privacy_region, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_ok) {
//Toast.makeText(getApplicationContext(), "onOptionsItemSelected: " + "OK", Toast.LENGTH_SHORT).show();
editPrivacyRegion();
return true;
}/**/
if (id == R.id.action_cancel) {
//Toast.makeText(getApplicationContext(), "onOptionsItemSelected: " + "CANCEL", Toast.LENGTH_SHORT).show();
finish();
return true;
}/**/
return super.onOptionsItemSelected(item);
}
public void editPrivacyRegion() {
if(region_label.getText().toString().trim().equals("")) {
region_label.setError("Region label is required!");
}
else {
region_label.setError(null);
LatLngBounds bounds = regionMap.getProjection().getVisibleRegion().latLngBounds;
String label = region_label.getText().toString();
/*Toast.makeText(getApplicationContext(), region_label.getText().toString() + "\n"
+ bounds.northeast.latitude + " - " + bounds.northeast.longitude + "\n"
+ bounds.southwest.latitude + " - " + bounds.southwest.longitude, Toast.LENGTH_SHORT).show();/**/
JSONObject region = new JSONObject();
try {
region.put("label", label);
SimpleDateFormat sdf = new SimpleDateFormat("yyMMdd_HHmmss");
region.put("id", sdf.format(new Date()));
region.put("ne_lat", bounds.northeast.latitude);
region.put("ne_lng", bounds.northeast.longitude);
region.put("sw_lat", bounds.southwest.latitude);
region.put("sw_lng", bounds.southwest.longitude);
//Log.i(TAG, "editPrivacyRegion: " + region.toString());
} catch (JSONException e) {
e.printStackTrace();
}
ArrayList<JSONObject> privacyRegions = new ArrayList<JSONObject>();
privacyRegions = Utils.fileToJSON(new File(CLIENT + "/" + "Settings" + "/" + "PrivacyRegions"));
int i = 0;
for (JSONObject jsonObject : privacyRegions) {
try {
if (jsonObject.getString("id").equals(privacyRegion.getString("id"))
&& jsonObject.getString("label").equals(privacyRegion.getString("label"))) {
//Toast.makeText(getApplicationContext(), jsonObject.getString("label"), Toast.LENGTH_SHORT).show();
privacyRegions.set(i, region);
break;
}
} catch (JSONException e) {
e.printStackTrace();
}
i++;
}
Utils.overwriteJSONtoFile(privacyRegions, new File(CLIENT + "/" + "Settings" + "/" + "PrivacyRegions"));
try {
Toast.makeText(getApplicationContext(), "\"" + privacyRegion.getString("label") + "\" " + "has been edited.", Toast.LENGTH_SHORT).show();
} catch (JSONException e) {
e.printStackTrace();
}
finish();
/*Intent intent = new Intent(this, ViewPrivacyRegionActivity.class);
intent.putExtra("privacyRegion", region.toString());
startActivity(intent);/**/
}
}
}

View File

@ -0,0 +1,174 @@
package com.www.client.pr;
import android.app.Activity;
import android.app.ActivityManager;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.os.Bundle;
import android.os.Environment;
import android.preference.PreferenceManager;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.ListView;
import android.widget.Switch;
import android.widget.TextView;
import android.widget.Toast;
import com.www.client.ClientActivity;
import com.www.client.ItemArrayAdapter;
import com.www.client.R;
import com.www.client.TaskService;
import com.www.client.Utils;
import org.json.JSONObject;
import java.io.File;
import java.util.ArrayList;
public class PrivacyRegionsActivity extends Activity implements CompoundButton.OnCheckedChangeListener, AdapterView.OnItemClickListener {
private static final String TAG = "PrivacyRegionsActivity";
private static final String SDCARD = Environment.getExternalStorageDirectory().getPath();
public static final String CLIENT = SDCARD + "/Client";
public static SharedPreferences sp = null;
public static SharedPreferences.Editor spEditor = null;
Switch actionBarSwitch;
ArrayList<JSONObject> privacyRegions = null;
ListView listView;
TextView textView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_privacy_regions);
setTitle(getResources().getString((R.string.privacy_regions_title)));
sp = PreferenceManager.getDefaultSharedPreferences(this);
spEditor = sp.edit();
Button addNewButton = (Button)findViewById(R.id.add_new);
addNewButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v){
startActivity(new Intent(getBaseContext(), AddPrivacyRegionActivity.class));
}
});
}
@Override
protected void onResume() {
//Log.i(TAG, "onResume: ...");
super.onResume();
loadList();
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
onResume();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_privacy_regions, menu);
actionBarSwitch = (Switch)menu.findItem(R.id.action_bar_switch).getActionView().findViewById(R.id.switch_button);
actionBarSwitch.setChecked(sp.getBoolean(getResources().getString((R.string.privacy_regions_status)), false));
actionBarSwitch.setOnCheckedChangeListener(this);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
switch (item.getItemId()) {
case R.id.switch_button:
Toast.makeText(ClientActivity.getContext(), "onOptionsItemSelected: " + item.toString(), Toast.LENGTH_SHORT).show();
return true;
default:return super.onOptionsItemSelected(item);
}
}
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
//Toast.makeText(getApplicationContext(), "onCheckedChanged: " + compoundButton, Toast.LENGTH_SHORT).show();
if (compoundButton == actionBarSwitch) {
//Toast.makeText(getApplicationContext(), "onCheckedChanged: " + compoundButton + " = " + b, Toast.LENGTH_SHORT).show();
spEditor.putBoolean(getResources().getString((R.string.privacy_regions_status)), b);
spEditor.commit();
//Log.i(TAG, "onCheckedChanged: " + sp.getAll());
//restart service
//Toast.makeText(getApplicationContext(), "Restarting...", Toast.LENGTH_SHORT).show();
if(isServiceRunning()) {
Log.i(TAG, "onCheckedChanged: " + "Restarting service...");
stopService(new Intent(this, TaskService.class));
startService(new Intent(this, TaskService.class));
}/**/
}
}
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
JSONObject choice = privacyRegions.get(i);
//Toast.makeText(getApplicationContext(), choice.toString(), Toast.LENGTH_SHORT).show();
//Log.i(TAG, choice.toString());
Intent intent = new Intent(this, ViewPrivacyRegionActivity.class);
intent.putExtra("privacyRegion", choice.toString());
startActivity(intent);
}
private void loadList() {
//Log.i(TAG, "loadList: ... ");
privacyRegions = Utils.fileToJSON(new File(CLIENT + "/" + "Settings" + "/" + "PrivacyRegions"));
textView = (TextView) findViewById(R.id.info);
listView = (ListView) findViewById(R.id.list);
//Log.i(TAG, "loadList: " + privacyRegions.toString());
if (privacyRegions.isEmpty()) {
//Log.i(TAG, "privacyRegions is empty");
listView.setVisibility(View.GONE);
textView.setVisibility(View.VISIBLE);
}
else {
//Log.i(TAG, "privacyRegions not empty");
textView.setVisibility(View.GONE);
/*for (JSONObject privacyRegion : privacyRegions) {
Log.i(TAG, "loadList: " + privacyRegion.toString());
}/**/
listView = (ListView) findViewById(R.id.list);
ItemArrayAdapter adapter = new ItemArrayAdapter(this, R.layout.item, privacyRegions);
listView.setAdapter(adapter);
listView.setOnItemClickListener(this);
}
}
private boolean isServiceRunning() {
ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
if (TaskService.class.getName().equals(service.service.getClassName())) {
return true;
}
}
return false;
}
}

View File

@ -0,0 +1,142 @@
package com.www.client.pr;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewTreeObserver;
import android.widget.Toast;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.LatLngBounds;
import com.www.client.R;
import com.www.client.Utils;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.File;
import java.util.ArrayList;
public class ViewPrivacyRegionActivity extends Activity {
private static final String TAG = "ViewPrivacyRegionActivity";
private JSONObject privacyRegion = null;
private GoogleMap regionMap = null;
private static final String SDCARD = Environment.getExternalStorageDirectory().getPath();
public static final String CLIENT = SDCARD + "/Client";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_view_privacy_region);
try {
privacyRegion = new JSONObject((String) getIntent().getSerializableExtra("privacyRegion"));
//Log.i(TAG, privacyRegion.toString());
setTitle(privacyRegion.getString("label"));
} catch (JSONException e) {
e.printStackTrace();
}
regionMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.region_map)).getMap();
final View mapView = getFragmentManager().findFragmentById(R.id.region_map).getView();
regionMap.getUiSettings().setZoomControlsEnabled(false);
regionMap.getUiSettings().setCompassEnabled(false);
regionMap.getUiSettings().setAllGesturesEnabled(false);
regionMap.getUiSettings().setMyLocationButtonEnabled(false);/**/
LatLngBounds.Builder bounds;
bounds = new LatLngBounds.Builder();
if (mapView.getViewTreeObserver().isAlive()) {
mapView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@SuppressLint("NewApi") // We check which build version we are using.
@Override
public void onGlobalLayout() {
LatLngBounds bounds = null;
try {
bounds = new LatLngBounds.Builder()
.include(new LatLng(privacyRegion.getDouble("ne_lat"), privacyRegion.getDouble("ne_lng")))
.include(new LatLng(privacyRegion.getDouble("sw_lat"), privacyRegion.getDouble("sw_lng")))
.build();
} catch (JSONException e) {
e.printStackTrace();
}
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
mapView.getViewTreeObserver().removeGlobalOnLayoutListener(this);
} else {
mapView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
}
regionMap.moveCamera(CameraUpdateFactory.newLatLngBounds(bounds, 0));
}
});
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.view_privacy_region, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_edit) {
Intent intent = new Intent(this, EditPrivacyRegionActivity.class);
intent.putExtra("privacyRegion", privacyRegion.toString());
startActivity(intent);
return true;
}
if (id == R.id.action_delete) {
//Toast.makeText(getApplicationContext(), "onOptionsItemSelected: " + "DELETE", Toast.LENGTH_SHORT).show();
ArrayList<JSONObject> privacyRegions = new ArrayList<JSONObject>();
privacyRegions = Utils.fileToJSON(new File(CLIENT + "/" + "Settings" + "/" + "PrivacyRegions"));
for (JSONObject jsonObject : privacyRegions) {
try {
if (jsonObject.getString("id").equals(privacyRegion.getString("id"))
&& jsonObject.getString("label").equals(privacyRegion.getString("label"))) {
//Toast.makeText(getApplicationContext(), jsonObject.getString("label"), Toast.LENGTH_SHORT).show();
privacyRegions.remove(jsonObject);
break;
}
} catch (JSONException e) {
e.printStackTrace();
}
}
Utils.overwriteJSONtoFile(privacyRegions, new File(CLIENT + "/" + "Settings" + "/" + "PrivacyRegions"));
try {
Toast.makeText(getApplicationContext(), "\"" + privacyRegion.getString("label") + "\" " + " has been deleted.", Toast.LENGTH_SHORT).show();
} catch (JSONException e) {
e.printStackTrace();
}
finish();
return true;
}
return super.onOptionsItemSelected(item);
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 401 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 353 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 450 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 765 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 506 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 505 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 246 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 272 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 324 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 522 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 297 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 313 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 475 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 543 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 994 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 637 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 645 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

@ -0,0 +1,69 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.www.client.pr.AddPrivacyRegionActivity">
<fragment
android:id="@+id/region_map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.MapFragment"
/>
<TextView
android:id="@+id/info"
android:text="Select the privacy region, type a label and then tap to save or cancel your preferences."
android:gravity="center"
android:padding="16dp"
android:background="@color/black_trans5"
android:textColor="@color/white"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<EditText
android:id="@+id/region_label"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:textColor="@color/black"
android:hint="Type privacy region label..."
android:layout_marginBottom="32dp"
android:layout_marginLeft="2dp"
android:layout_marginRight="60dp"
android:singleLine="true"
/>
<!--
<Button
android:id="@+id/okButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginBottom="16dp"
android:layout_alignLeft="@+id/text"
android:layout_alignParentBottom="true"
android:layout_alignRight="@+id/mid"
android:text="@string/ok" />
<LinearLayout
android:id="@+id/mid"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:gravity="center" >
</LinearLayout>
<Button
android:id="@+id/cancelButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="16dp"
android:layout_marginBottom="16dp"
android:layout_alignLeft="@+id/mid"
android:layout_alignParentBottom="true"
android:layout_alignRight="@+id/text"
android:text="@string/cancel" />
-->
</RelativeLayout>

View File

@ -0,0 +1,89 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".ClientActivity" >
<TextView
android:id="@+id/textview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true" />
<TextView
android:id="@+id/status"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/comment"
android:layout_alignRight="@+id/comment"
android:gravity="center"
android:textStyle="bold"
android:text="Status"
android:textAppearance="?android:attr/textAppearanceLarge"
/>
<TextView
android:id="@+id/comment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/levelService"
android:layout_alignRight="@+id/levelService"
android:layout_below="@+id/status"
android:layout_marginTop="16dp"
android:text="Comment"
android:gravity="center" />
<TextView
android:id="@+id/level"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/levelService"
android:layout_alignLeft="@+id/levelService"
android:layout_alignRight="@+id/levelService"
android:gravity="center" />
<SeekBar
android:id="@+id/levelService"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:max="100"
android:progress="0"
android:secondaryProgress="0"
android:layout_marginTop="16dp"
android:layout_marginBottom="16dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignRight="@+id/textview"
android:layout_alignEnd="@+id/textview" />
<View
android:layout_width="1dp"
android:layout_height="fill_parent"
android:layout_centerHorizontal="true"
android:id="@+id/center_vertical" />
<Button
android:id="@+id/okButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/ok"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_toLeftOf="@+id/center_vertical"
android:layout_toStartOf="@+id/center_vertical" />
<Button
android:id="@+id/cancelButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/cancel"
android:layout_alignParentBottom="true"
android:layout_alignRight="@+id/textview"
android:layout_alignEnd="@+id/textview"
android:layout_toRightOf="@+id/center_vertical"
android:layout_toEndOf="@+id/center_vertical" />
</RelativeLayout>

View File

@ -0,0 +1,27 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.www.client.pr.EditPrivacyRegionActivity">
<fragment
android:id="@+id/region_map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.MapFragment"
/>
<EditText
android:id="@+id/region_label"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:textColor="@color/black"
android:hint="Type privacy region label..."
android:layout_marginBottom="32dp"
android:layout_marginLeft="2dp"
android:layout_marginRight="60dp"
android:singleLine="true"
/>
</RelativeLayout>

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