Re: Fusioninventory-devel Digest, Vol 19, Issue 10
Hello,
New version with Login/password and Tag options.
Find in attachment the apk and the patch.
Best regards,
Erufu - Sebastien Lacroix
--------------------------------
Di5 Polytech'Tours
On 24/08/2011 15:14,
fusioninventory-devel-request@... wrote:
> Send Fusioninventory-devel mailing list submissions to
> fusioninventory-devel@...
>
> To subscribe or unsubscribe via the World Wide Web, visit
> http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/fusioninventory-devel
>
> or, via email, send a message with subject or body 'help' to
> fusioninventory-devel-request@...
>
> You can reach the person managing the list at
> fusioninventory-devel-owner@...
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of Fusioninventory-devel digest..."
>
>
> Today's Topics:
>
> 1. Re: Fusioninventory-devel Digest, Vol 19, Issue 9 (Erufu)
>
>
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Wed, 24 Aug 2011 15:13:57 +0200
> From: Erufu<erufu.sennin@...>
> To: fusioninventory-devel@...
> Subject: Re: [Fusioninventory-devel] Fusioninventory-devel Digest, Vol
> 19, Issue 9
> Message-ID:<4E54F915.1060506@...>
> Content-Type: text/plain; charset="iso-8859-1"; Format="flowed"
>
> Hello,
>
> When I checked the apk file it doesn't work ... I forget to modify a
> file in my patch. So please find in attachment the good patch and the
> apk file.
>
> Best regards,
>
> Erufu - Sebastien Lacroix
> --------------------------------
> Di5 Polytech'Tours
> --------------------------------
>
>
> On 24/08/2011 14:00,
> fusioninventory-devel-request@... wrote:
>> Send Fusioninventory-devel mailing list submissions to
>> fusioninventory-devel@...
>>
>> To subscribe or unsubscribe via the World Wide Web, visit
>> http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/fusioninventory-devel
>>
>> or, via email, send a message with subject or body 'help' to
>> fusioninventory-devel-request@...
>>
>> You can reach the person managing the list at
>> fusioninventory-devel-owner@...
>>
>> When replying, please edit your Subject line so it is more specific
>> than "Re: Contents of Fusioninventory-devel digest..."
>>
>>
>> Today's Topics:
>>
>> 1. Re: android agent ui improvements (Gon?ri Le Bouder)
>> 2. Re: android agent ui improvements (Walid nouh)
>>
>>
>> ----------------------------------------------------------------------
>>
>> Message: 1
>> Date: Tue, 23 Aug 2011 23:37:24 +0200
>> From: Gon?ri Le Bouder<goneri@...>
>> To: FusionInventory Developer discussion
>> <fusioninventory-devel@...>
>> Subject: Re: [Fusioninventory-devel] android agent ui improvements
>> Message-ID:
>> <CA+1jmBy0-_fdAi8Xce81_kYJOPeAO-U8fKw2z-pRkDk=Us6XRQ@...>
>> Content-Type: text/plain; charset="utf-8"
>>
>> Hello S?bastien,
>>
>> Thank you for the patch. The Android agent maintainers a too busy this week
>> i'm afraid and I don't have the Android SDK installed to build the agent.
>> Can you please publish a package somewhere so i can have a look on your
>> changes?
>>
>> Best regards,
>> --
>> Gon?ri
>> -------------- next part --------------
>> An HTML attachment was scrubbed...
>> URL:<http://lists.alioth.debian.org/pipermail/fusioninventory-devel/attachments/20110823/32128cac/attachment-0001.html>
>>
>> ------------------------------
>>
>> Message: 2
>> Date: Wed, 24 Aug 2011 09:20:06 +0200
>> From: Walid nouh<walid.nouh@...>
>> To: FusionInventory Developer discussion
>> <fusioninventory-devel@...>
>> Subject: Re: [Fusioninventory-devel] android agent ui improvements
>> Message-ID:<4E54A626.9020703@...>
>> Content-Type: text/plain; charset="utf-8"; Format="flowed"
>>
>> Hi S?bastien,
>>
>> I'm really sorry, I'm a little bit busy this week.
>> I'll check your patch as soon as possible !
>>
>> Thanks a lot for your contributon. As Gon?ri proposed, if you can
>> provide us an apk, it would be great.
>>
>> Walid;
>>
>> On 23/08/2011 23:37, Gon?ri Le Bouder wrote:
>>> Hello S?bastien,
>>>
>>> Thank you for the patch. The Android agent maintainers a too busy this
>>> week i'm afraid and I don't have the Android SDK installed to build
>>> the agent. Can you please publish a package somewhere so i can have a
>>> look on your changes?
>>>
>>> Best regards,
>>> --
>>> Gon?ri
>>>
>>>
>>> _______________________________________________
>>> Fusioninventory-devel mailing list
>>> Fusioninventory-devel@...
>>> http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/fusioninventory-devel
>> -------------- next part --------------
>> An HTML attachment was scrubbed...
>> URL:<http://lists.alioth.debian.org/pipermail/fusioninventory-devel/attachments/20110824/863b7532/attachment-0001.html>
>>
>> ------------------------------
>>
>> _______________________________________________
>> Fusioninventory-devel mailing list
>> Fusioninventory-devel@...
>> http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/fusioninventory-devel
>>
>> End of Fusioninventory-devel Digest, Vol 19, Issue 9
>> ****************************************************
> -------------- next part --------------
> A non-text attachment was scrubbed...
> Name: FusionInventoryPatch.patch
> Type: text/x-patch
> Size: 73139 bytes
> Desc: not available
> URL:<http://lists.alioth.debian.org/pipermail/fusioninventory-devel/attachments/20110824/91c85ee6/attachment.bin>
> -------------- next part --------------
> A non-text attachment was scrubbed...
> Name: fusioninventory.apk
> Type: application/vnd.android.package-archive
> Size: 83662 bytes
> Desc: not available
> URL:<http://lists.alioth.debian.org/pipermail/fusioninventory-devel/attachments/20110824/91c85ee6/attachment.apk>
>
> ------------------------------
>
> _______________________________________________
> Fusioninventory-devel mailing list
> Fusioninventory-devel@...
> http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/fusioninventory-devel
>
> End of Fusioninventory-devel Digest, Vol 19, Issue 10
> *****************************************************
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index c2196ae..dd80a62 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
<at> <at> -31,7 +31,7 <at> <at>
android:name="android.permission.BLUETOOTH" />
<uses-permission
android:name="android.permission.INSTALL_PACKAGES" />
- <uses-permission
+ <uses-permission
android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission
android:name="android.permission.GET_PACKAGE_SIZE" />
<at> <at> -43,7 +43,7 <at> <at>
android:label=" <at> string/app_name"
android:name="FusionInventoryApp" android:debuggable="true" android:vmSafeMode="true" android:icon=" <at> drawable/icon">
<activity
- android:name=".FusionInventory"
+ android:name=".Accueil"
android:label=" <at> string/app_name" android:launchMode="standard">
<intent-filter>
<action
<at> <at> -66,6 +66,19 <at> <at>
android:name="org.fusioninventory.Agent" />
</intent-filter>
</service>
+ <service
+ android:enabled="true"
+ android:label="Agent Auto"
+ android:description=" <at> string/agent_description"
+ android:icon=" <at> drawable/icon"
+ android:name=".AutoInventory"
+ >
+ <!-- android:process=":Auto agent" -->
+ <intent-filter>
+ <action
+ android:name="org.fusioninventory.AutoInventory" />
+ </intent-filter>
+ </service>
<receiver
android:name="BootStartAgent"
>
<at> <at> -83,4 +96,4 <at> <at>
</application>
-</manifest>
\ No newline at end of file
+</manifest>
diff --git a/INSTALL b/INSTALL
new file mode 100644
index 0000000..a45322b
--- /dev/null
+++ b/INSTALL
<at> <at> -0,0 +1,10 <at> <at>
+To build project you need Ant and Android SDK.
+
+To be sure of the content of build.xml you need to perform at the root of the project :
+
+ android update project
+
+Then to build project :
+
+ ant clean debug
+
diff --git a/build.xml b/build.xml
index ea3b9ae..c7ba803 100644
--- a/build.xml
+++ b/build.xml
<at> <at> -1,8 +1,6 <at> <at>
<?xml version="1.0" encoding="UTF-8"?>
-<!--<project name="FusionInventory" default="help">-->
-<project default="help">
+<project name="Accueil" default="help">
- <property name="project.name" value="FusionInventory" />
<!-- The local.properties file is created and updated by the 'android'
tool.
It contains the path to the SDK. It should *NOT* be checked into
<at> <at> -38,25 +36,7 <at> <at>
<!-- Required pre-setup import -->
<import file="${sdk.dir}/tools/ant/pre_setup.xml" />
- <exec outputproperty="build.gitbranch" executable="git">
- <arg line="symbolic-ref HEAD" />
- <redirector>
- <outputfilterchain>
- <tokenfilter>
- <replaceregex pattern="refs/heads/" replace="" flags="" />
- </tokenfilter>
- </outputfilterchain>
- </redirector>
- </exec>
-
- <exec outputproperty="build.gitrev" executable="git">
- <arg line="log -1 --pretty=format:%h ${build.gitbranch}" />
- </exec>
-
- <echo>Git branch ${build.gitbranch}</echo>
- <echo>Git revision ${build.gitrev}</echo>
- <property name="project.suffix" value="-${build.gitbranch} <at> ${build.gitrev}" />
- <property name="ant.project.name" value="${project.name}${project.suffix}" />
+
<!-- extension targets. Uncomment the ones where you want to do custom work
in between standard targets -->
<!--
<at> <at> -94,8 +74,6 <at> <at>
below to <setup import="false" />.
- customize to your needs.
-->
- <echo>${ant.project.name}</echo>
<setup />
- <echo>${ant.project.name}</echo>
</project>
diff --git a/proguard.cfg b/proguard.cfg
index 12dd039..b1cdf17 100644
--- a/proguard.cfg
+++ b/proguard.cfg
<at> <at> -18,14 +18,18 <at> <at>
native <methods>;
}
--keepclasseswithmembernames class * {
+-keepclasseswithmembers class * {
public <init>(android.content.Context, android.util.AttributeSet);
}
--keepclasseswithmembernames class * {
+-keepclasseswithmembers class * {
public <init>(android.content.Context, android.util.AttributeSet, int);
}
+-keepclassmembers class * extends android.app.Activity {
+ public void *(android.view.View);
+}
+
-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 6178c40..2a63d46 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
<at> <at> -2,13 +2,16 <at> <at>
<resources>
<string
name="app_name"
- >FusionInventory</string>
+ >Fusioninventory</string>
<string
name="agent_started"
- >FusionInventory Agent is started</string>
+ >Fusioninventory Agent is started</string>
<string
name="agent_stopped"
- >FusionInventory Agent is stopped</string>
+ >Fusioninventory Agent is stopped</string>
+ <string
+ name="agent_reboot"
+ >Fusioninventory Agent is restarted</string>
<string
name="agent_description"
>The inventory agent running in background</string>
<at> <at> -40,6 +43,9 <at> <at>
name="inventory_started"
>Starting inventory...</string>
<string
+ name="inventory_sended"
+ >Sending inventory...</string>
+ <string
name="inventory_ended"
>End of inventory.</string>
<string
<at> <at> -48,9 +54,21 <at> <at>
<string
name="button_disconnect_agent"
>Disconnect Agent</string>
+ <string
+ name="error_inventory"
+ >Inventory not complet</string>
+ <string
+ name="ok_inventory"
+ >Inventory complet</string>
+ <string
+ name="error_send_inventoryi"
+ >Inventory not send</string>
+ <string
+ name="ok_send_inventory"
+ >Inventory send</string>
<string
name="service_notif_id"
- >FusionInventory Agent</string>
+ >FusioninventoryInventory Agent</string>
<string-array
name="agent_status"
>
diff --git a/res/values/strings_pref_accueil.xml b/res/values/strings_pref_accueil.xml
new file mode 100644
index 0000000..6590c61
--- /dev/null
+++ b/res/values/strings_pref_accueil.xml
<at> <at> -0,0 +1,40 <at> <at>
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+
+<!-- Accueil Preferences -->
+
+ <string name="AccueilTitle">Agent Fusioninventory settings</string>
+
+ <!-- Inventory part -->
+
+ <string name="AccueilInventoryTitle">Inventory</string>
+ <string name="AccueilInventorySummaryOn">Click to disable inventory</string>
+ <string name="AccueilInventorySummaryOff">Click to enable inventory</string>
+ <string name="AccueilInventoryRun">Run inventory</string>
+ <string name="AccueilInventoryRunSummary">Run now</string>
+ <string name="AccueilInventoryParam">Parameters inventory</string>
+ <string name="AccueilInventoryParamSummary">Setup inventory frequencies</string>
+
+ <!-- Remote view part -->
+
+ <string name="AccueilRemoteTitle">Remote view</string>
+ <string name="AccueilRemoteSummaryOn">Click to disable remote view</string>
+ <string name="AccueilRemoteSummaryOff">Click to enable remote view</string>
+ <string name="AccueilRemoteParam">Parameters remote view</string>
+ <string name="AccueilRemoteParamSummary">Setup remote view settings</string>
+
+ <!-- SSH part -->
+
+ <string name="AccueilSshTitle">Secure Shell</string>
+ <string name="AccueilSshSummaryOn">Click to disable SSH</string>
+ <string name="AccueilSshSummaryOff">Click to enable SSH</string>
+
+ <!-- global part -->
+
+ <string name="AccueilGlobalTitle">Global</string>
+ <string name="AccueilGlobalParam">Global settings</string>
+ <string name="AccueilGlobalParamSummary">Setup certificates, server ...</string>
+
+
+
+</resources>
diff --git a/res/values/strings_pref_advanced.xml b/res/values/strings_pref_advanced.xml
new file mode 100644
index 0000000..4628d35
--- /dev/null
+++ b/res/values/strings_pref_advanced.xml
<at> <at> -0,0 +1,26 <at> <at>
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+
+<!-- Advanced settings part -->
+
+ <string name="AdvancedCatDebug">Debug tools</string>
+
+ <string name="AdvancedDaemon">Run daemon as root</string>
+ <string name="AdvancedDaemonSummaryOff">Click to run daemon as user</string>
+ <string name="AdvancedDaemonSummaryOn">Click to run daemon as root</string>
+ <string name="AdvancedNotify">Notify clients connected</string>
+ <string name="AdvancedNotifySummaryOff">Click to enable notifications</string>
+ <string name="AdvancedNotifySummaryOn">Click to disable notifications</string>
+ <string name="AdvancedDebug">Debug messages</string>
+ <string name="AdvancedDebugSummaryOff">Click to enable debug messages</string>
+ <string name="AdvancedDebugSummaryOn">Click to disable debug messages</string>
+
+ <string name="AdvancedCatBin">Path to binaries</string>
+
+ <string name="AdvancedSU">Path to SU</string>
+ <string name="AdvancedSUSummary">Define path to SU binarie</string>
+ <string name="AdvancedSH">Path to SH</string>
+ <string name="AdvancedSHSummary">Define path to SH binarie</string>
+
+
+</resources>
diff --git a/res/values/strings_pref_auth.xml b/res/values/strings_pref_auth.xml
new file mode 100644
index 0000000..aeb8ac9
--- /dev/null
+++ b/res/values/strings_pref_auth.xml
<at> <at> -0,0 +1,22 <at> <at>
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+
+<!-- Auth settings part -->
+
+ <string name="AuthCatCertif">Certificate</string>
+
+ <string name="AuthCertif">User certificate</string>
+ <string name="AuthCertifSummary">Define path to user certificate</string>
+ <string name="AuthCA">CA certificate</string>
+ <string name="AuthCASummary">Define path to CA certificate</string>
+
+
+ <string name="AuthCatPass">Passwords and keys</string>
+
+ <string name="AuthPrivateKey">Private key</string>
+ <string name="AuthPrivateKeySummary">Define path to private key</string>
+ <string name="AuthPrivatePass">Private key password</string>
+ <string name="AuthPrivatePassSummary">Define the private key password</string>
+
+</resources>
+
diff --git a/res/values/strings_pref_global.xml b/res/values/strings_pref_global.xml
new file mode 100644
index 0000000..c44e6c0
--- /dev/null
+++ b/res/values/strings_pref_global.xml
<at> <at> -0,0 +1,30 <at> <at>
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+
+<!-- Global settings part -->
+
+ <string name="GlobalCat">Global</string>
+
+ <string name="GlobalBoot">Boot options</string>
+ <string name="GlobalBootSummaryOn">Click to disable automatic boot</string>
+ <string name="GlobalBootSummaryOff">Click to enable automatic boot</string>
+
+ <string name="GlobalNotif">Notifications</string>
+ <string name="GlobalNotifSummaryOn">Click to disable notifications</string>
+ <string name="GlobalNotifSummaryOff">Click to enable notifications</string>
+
+ <string name="GlobalCatSet">Server settings</string>
+
+ <string name="GlobalServer">Server address</string>
+ <string name="GlobalServerSummary">Define server address</string>
+
+ <string name="GlobalService">Authentication</string>
+ <string name="GlobalServiceSummary">Setup password, public keys ...</string>
+
+ <string name="GlobalCatAdvanced">Advanced settings</string>
+
+ <string name="GlobalAdvanced">Advanced Settings</string>
+ <string name="GlobalAdvancedSummary">Setup daemon settings, path to binaries ...</string>
+
+</resources>
+
diff --git a/res/values/strings_pref_inventory.xml b/res/values/strings_pref_inventory.xml
new file mode 100644
index 0000000..0f68c3a
--- /dev/null
+++ b/res/values/strings_pref_inventory.xml
<at> <at> -0,0 +1,17 <at> <at>
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+
+<!-- Inventory Preferences -->
+
+ <string name="InventoryCat">Inventory</string>
+
+ <string name="InventoryAuto">Automatic inventory</string>
+ <string name="InventoryAutoSummaryOn">Click to disable automatic inventory</string>
+ <string name="InventoryAutoSummaryOff">Click to enable automatic inventory</string>
+
+ <string name="InventoryFrequency">Frequency</string>
+ <string name="InventoryFrequencyDialog">Every :</string>
+ <string name="InventoryFrequencySummary">Define frequency</string>
+
+</resources>
+
diff --git a/res/values/value_time.xml b/res/values/value_time.xml
new file mode 100644
index 0000000..1d198f8
--- /dev/null
+++ b/res/values/value_time.xml
<at> <at> -0,0 +1,14 <at> <at>
+<?xml version="1.0" encoding="utf-8"?>
+ <resources>
+ <string-array name="Time">
+ <item>day</item>
+ <item>week</item>
+ <item>month</item>
+ </string-array>
+ <string-array name="TimeValue">
+ <item>Day</item>
+ <item>Week</item>
+ <item>Month</item>
+ </string-array>
+ </resources>
+
diff --git a/res/xml/accueil.xml b/res/xml/accueil.xml
new file mode 100644
index 0000000..cc6e6a7
--- /dev/null
+++ b/res/xml/accueil.xml
<at> <at> -0,0 +1,94 <at> <at>
+<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
+ android:title=" <at> string/AccueilTitle">
+
+ <PreferenceCategory android:title=" <at> string/AccueilInventoryTitle"/>
+
+ <!-- Inventory part -->
+
+ <CheckBoxPreference
+ android:summary="CheckBox summary"
+ android:title=" <at> string/AccueilInventoryTitle"
+ android:summaryOn=" <at> string/AccueilInventorySummaryOn"
+ android:summaryOff=" <at> string/AccueilInventorySummaryOff"
+ android:key="autoInventory"
+ android:defaultValue="true"
+ />
+ <Preference
+ android:title=" <at> string/AccueilInventoryRun"
+ android:summary=" <at> string/AccueilInventoryRunSummary"
+ android:key="runInventory"
+ android:dependency="autoInventory"
+ />
+ <PreferenceScreen
+ android:title=" <at> string/AccueilInventoryParam"
+ android:summary=" <at> string/AccueilInventoryParamSummary"
+ android:dependency="autoInventory"
+ >
+
+ <PreferenceCategory android:title=" <at> string/InventoryCat"/>
+
+ <CheckBoxPreference
+ android:summary="CheckBox summary"
+ android:title=" <at> string/InventoryAuto"
+ android:summaryOn=" <at> string/InventoryAutoSummaryOn"
+ android:summaryOff=" <at> string/InventoryAutoSummaryOff"
+ android:key="autoStartInventory" android:defaultValue="true"
+ />
+ <ListPreference
+ android:key="timeInventory"
+ android:title=" <at> string/InventoryFrequency"
+ android:dialogTitle=" <at> string/InventoryFrequency"
+ android:dependency="autoStartInventory"
+ android:entries=" <at> array/Time"
+ android:entryValues=" <at> array/TimeValue"
+ android:defaultValue="Week"
+ android:summary=" <at> string/InventoryFrequencySummary"
+ />
+
+ </PreferenceScreen>
+
+ <PreferenceCategory android:title=" <at> string/AccueilGlobalTitle"/>
+
+ <PreferenceScreen
+ android:title=" <at> string/AccueilGlobalParam"
+ android:summary=" <at> string/AccueilGlobalParamSummary">
+
+ <PreferenceCategory android:title=" <at> string/GlobalCat"/>
+
+ <CheckBoxPreference
+ android:summary="CheckBox summary"
+ android:title=" <at> string/GlobalBoot"
+ android:summaryOn=" <at> string/GlobalBootSummaryOn"
+ android:summaryOff=" <at> string/GlobalBootSummaryOff"
+ android:key="boot" android:defaultValue="true"
+ />
+
+ <CheckBoxPreference
+ android:summary="CheckBox summary"
+ android:title=" <at> string/GlobalNotif"
+ android:summaryOn=" <at> string/GlobalNotifSummaryOn"
+ android:summaryOff=" <at> string/GlobalNotifSummaryOff"
+ android:key="notif" android:defaultValue="false"
+ />
+
+ <PreferenceCategory android:title=" <at> string/GlobalCatSet"/>
+
+ <EditTextPreference
+ android:title=" <at> string/GlobalServer"
+ android:key="url"
+ android:summary=" <at> string/GlobalServerSummary"
+ android:persistent="true"
+ />
+ <EditTextPreference android:dialogMessage=" <at> string/tag" android:persistent="true" android:enabled="true" android:selectable="true" android:dialogTitle=" <at> string/tag" android:title=" <at> string/tag" android:key="tag"></EditTextPreference>
+
+
+
+ <PreferenceCategory android:title=" <at> string/authentication_credentials">
+ <EditTextPreference android:dialogMessage=" <at> string/login" android:enabled="true" android:persistent="true" android:title=" <at> string/login" android:key="login"></EditTextPreference>
+ <EditTextPreference android:dialogMessage=" <at> string/password" android:persistent="true" android:title=" <at> string/password" android:key="password" android:enabled="true"></EditTextPreference>
+ </PreferenceCategory>
+
+
+ </PreferenceScreen>
+
+</PreferenceScreen>
diff --git a/src/org/fusioninventory/Accueil.java b/src/org/fusioninventory/Accueil.java
new file mode 100644
index 0000000..cbee4d6
--- /dev/null
+++ b/src/org/fusioninventory/Accueil.java
<at> <at> -0,0 +1,297 <at> <at>
+package org.fusioninventory;
+
+import java.util.Iterator;
+
+import android.content.ComponentName;
+import android.content.Context;
+import android.content.Intent;
+import android.content.ServiceConnection;
+import android.content.SharedPreferences;
+import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
+import android.os.Bundle;
+import android.os.Handler;
+import android.os.IBinder;
+import android.os.Message;
+import android.os.Messenger;
+import android.os.RemoteException;
+import android.preference.EditTextPreference;
+import android.preference.ListPreference;
+import android.preference.Preference;
+import android.preference.PreferenceManager;
+import android.preference.Preference.OnPreferenceChangeListener;
+import android.preference.Preference.OnPreferenceClickListener;
+import android.preference.PreferenceActivity;
+import android.util.Log;
+import android.widget.Toast;
+
+public class Accueil extends PreferenceActivity implements
+OnSharedPreferenceChangeListener {
+
+ private Messenger mAgentService = null;
+
+ private String[] STATUS_AGENT = null;
+ private boolean isAgentOk = false;
+ private String barcode = null;
+
+ private boolean notif = false;
+
+ private boolean ssh = false;
+
+ private SharedPreferences customSharedPreference;
+
+ private static final String TAG = "DroidSSHd";
+ final Handler mHandler = new Handler();
+ private long mUpdateUIdelay = 500L;
+ private Intent mDropbearDaemonHandlerService;
+
+ public Messenger getmAgentService(){
+ return mAgentService;
+ }
+
+ public static void log(Object obj, String msg, int level) {
+ String final_msg = String.format("[%s] %s", obj.getClass().getName(), msg);
+ Log.println(level, "FusionInventory", final_msg);
+ }
+
+ class IncomingHandler
+ extends Handler {
+ <at> Override
+ public void handleMessage(Message msg) {
+ // TODO Auto-generated method stub
+ Accueil.log(this, " message received " + msg.toString(), Log.INFO);
+
+ switch (msg.what) {
+
+ case Agent.MSG_AGENT_STATUS:
+
+ Accueil.log(this, STATUS_AGENT[msg.arg1], Log.INFO);
+ isAgentOk = (msg.arg1 == 0 ? true : false);
+ break;
+ case Agent.MSG_INVENTORY_FINISHED:
+
+ try {
+ mAgentService.send(Message.obtain(null, Agent.MSG_INVENTORY_RESULT));
+ } catch (RemoteException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ break;
+
+ case Agent.MSG_INVENTORY_RESULT:
+ Bundle bXML = msg.peekData();
+ if (bXML != null) {
+ try {
+ mAgentService.send(Message.obtain(null, Agent.MSG_AGENT_STATUS));
+ } catch (RemoteException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ break;
+
+ default:
+ super.handleMessage(msg);
+ }
+ }
+ }
+
+ final Messenger mMessenger = new Messenger(new IncomingHandler());
+
+ private ServiceConnection mConnection = new ServiceConnection() {
+
+ <at> Override
+ public void onServiceConnected(ComponentName name, IBinder service) {
+
+ mAgentService = new Messenger(service);
+
+ try {
+ Message msg = Message.obtain();
+ msg.replyTo = mMessenger;
+ msg.what = Agent.MSG_CLIENT_REGISTER;
+ mAgentService.send(msg);
+
+ mAgentService.send(Message.obtain(null, Agent.MSG_AGENT_STATUS));
+ } catch (RemoteException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ if (notif){
+ Toast.makeText(Accueil.this, R.string.agent_connected, Toast.LENGTH_SHORT).show();
+ }
+ }
+
+ <at> Override
+ public void onServiceDisconnected(ComponentName name) {
+ isAgentOk = false;
+ mAgentService = null;
+
+ if (notif){
+ Toast.makeText(Accueil.this, R.string.agent_disconnected, Toast.LENGTH_SHORT).show();
+ }
+ }
+ };
+
+ private boolean mIsBound = false;
+
+ void doBindService() {
+ // Establish a connection with the service. We use an explicit
+ // class name because we want a specific service implementation that
+ // we know will be running in our own process (and thus won't be
+ // supporting component replacement by other applications).
+
+ // mIsBound = bindService(new Intent(FusionInventory.this, Agent.class),
+ // mConnection, Context.BIND_AUTO_CREATE);
+
+ ComponentName result = startService(new Intent("org.fusioninventory.Agent"));
+ if (result != null) {
+ Accueil.log(this, " Agent started ", Log.INFO);
+ } else {
+ Accueil.log(this, " Agent already started ", Log.ERROR);
+ }
+
+ mIsBound = bindService(new Intent(Accueil.this, Agent.class), mConnection, Context.BIND_NOT_FOREGROUND);
+
+ if (mIsBound) {
+ Accueil.log(this, "Connected sucessfully to Agent service", Log.INFO);
+ } else {
+ Accueil.log(this, "Failed to connect to Agent service", Log.ERROR);
+ }
+
+ }
+
+ void doUnbindService() {
+ if (mIsBound) {
+ // Detach our existing connection.
+ unbindService(mConnection);
+ mIsBound = false;
+ }
+ }
+
+
+ <at> Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ STATUS_AGENT = getResources().getStringArray(R.array.agent_status);
+
+ addPreferencesFromResource(R.xml.accueil);
+
+ doBindService();
+
+ customSharedPreference = PreferenceManager.getDefaultSharedPreferences(this);
+ notif = customSharedPreference.getBoolean("notif", false);
+
+ Preference autoStartInventory = findPreference("autoStartInventory");
+ autoStartInventory.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
+ public boolean onPreferenceChange(Preference arg0,
+ Object arg1) {
+ // TODO Auto-generated method stub
+
+ notif = customSharedPreference.getBoolean("notif", false);
+
+ if (notif){
+ Toast.makeText(getBaseContext(), R.string.agent_reboot, Toast.LENGTH_SHORT).show();
+ }
+
+ stopService(new Intent("org.fusioninventory.Agent"));
+ startService(new Intent("org.fusioninventory.Agent"));
+
+ return true;
+ }
+
+ });
+
+ Preference timeInventory = findPreference("timeInventory");
+ timeInventory.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
+ public boolean onPreferenceChange(Preference arg0,
+ Object arg1) {
+ // TODO Auto-generated method stub
+
+ notif = customSharedPreference.getBoolean("notif", false);
+
+ if (notif){
+ Toast.makeText(getBaseContext(), R.string.agent_reboot,Toast.LENGTH_SHORT).show();
+ }
+
+ stopService(new Intent("org.fusioninventory.Agent"));
+ startService(new Intent("org.fusioninventory.Agent"));
+
+ return true;
+ }
+
+ });
+
+ Preference runInventory = findPreference("runInventory");
+ runInventory.setOnPreferenceClickListener(new OnPreferenceClickListener() {
+ public boolean onPreferenceClick(Preference preference) {
+ Message msg;
+
+ if (isAgentOk) {
+ try {
+
+ Toast.makeText(Accueil.this, R.string.inventory_started, Toast.LENGTH_LONG).show();
+
+ isAgentOk = false;
+
+ msg = Message.obtain(null, Agent.MSG_INVENTORY_START);
+ msg.replyTo = mMessenger;
+ if (barcode != null) {
+ Bundle b = new Bundle();
+ b.putString("BARCODE", barcode);
+ msg.setData(b);
+ }
+ mAgentService.send(msg);
+
+
+ } catch (RemoteException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ isAgentOk = true;
+ }
+
+ if (isAgentOk) {
+
+ isAgentOk = false;
+
+ msg = Message.obtain(null, Agent.MSG_INVENTORY_SEND);
+ msg.replyTo = mMessenger;
+ try {
+ mAgentService.send(msg);
+ } catch (RemoteException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ isAgentOk = true;
+ }
+
+ return true;
+ }
+
+ });
+ }
+
+ protected void onResume() {
+ super.onResume();
+ getPreferenceScreen().getSharedPreferences().registerOnSharedPreferenceChangeListener( this );
+ }
+
+ protected void onPause() {
+ super.onPause();
+ getPreferenceScreen().getSharedPreferences().unregisterOnSharedPreferenceChangeListener( this );
+ }
+
+ public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
+ Preference pref = findPreference(key);
+ if (pref instanceof EditTextPreference) {
+ EditTextPreference editextp = (EditTextPreference) pref;
+ pref.setSummary(editextp.getText());
+ }
+ if (pref instanceof ListPreference) {
+ ListPreference listp = (ListPreference) pref;
+ pref.setSummary(listp.getValue());
+ }
+ }
+}
diff --git a/src/org/fusioninventory/Agent.java b/src/org/fusioninventory/Agent.java
index 36a71b3..e527a62 100644
--- a/src/org/fusioninventory/Agent.java
+++ b/src/org/fusioninventory/Agent.java
<at> <at> -7,6 +7,7 <at> <at> import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.net.URL;
+import java.util.Calendar;
import org.apache.http.Header;
import org.apache.http.HttpException;
<at> <at> -34,11 +35,14 <at> <at> import org.apache.http.protocol.BasicHttpContext;
import org.apache.http.protocol.HttpContext;
import org.fusioninventory.utils.EasySSLSocketFactory;
+import android.app.AlarmManager;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.Service;
+import android.content.Context;
import android.content.Intent;
+import android.content.SharedPreferences;
import android.os.Binder;
import android.os.Bundle;
import android.os.Handler;
<at> <at> -46,11 +50,12 <at> <at> import android.os.IBinder;
import android.os.Message;
import android.os.Messenger;
import android.os.RemoteException;
+import android.preference.PreferenceManager;
import android.util.Log;
import android.widget.Toast;
public class Agent
- extends Service {
+ extends Service {
private NotificationManager mNM;
<at> <at> -85,99 +90,104 <at> <at> public class Agent
private FusionInventoryApp mFusionApp = null;
- class IncomingHandler
- extends Handler {
- <at> Override
- public void handleMessage(Message msg) {
-
- Message reply = Message.obtain();
-
- FusionInventory.log(this, "message received " + msg.toString(), Log.INFO);
-
- switch (msg.what) {
-
- case Agent.MSG_CLIENT_REGISTER:
- client = msg.replyTo;
- break;
-
- case Agent.MSG_AGENT_STATUS:
-
- status_agent = inventory.running ? 1 : 0;
- reply.what = MSG_AGENT_STATUS;
- reply.arg1 = status_agent;
- FusionInventory.log(this, "URL server = " + mFusionApp.getUrl(), Log.VERBOSE);
- FusionInventory.log(this, "shouldAutostart = " + mFusionApp.getShouldAutoStart(), Log.VERBOSE);
- FusionInventory.log(this, "mFusionApp = " + mFusionApp.toString(), Log.VERBOSE);
-
- try {
- FusionInventory.log(this, "message sent " + msg.toString(), Log.INFO);
- if (client != null) {
- client.send(reply);
- } else {
- FusionInventory.log(this, "No client registered", Log.ERROR);
- }
- } catch (RemoteException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- break;
-
- case Agent.MSG_INVENTORY_START:
-
- FusionInventory.log(this, " received starting inventory task", Log.INFO);
-
- if (inventory != null) {
-
- if (inventory.running) {
-
- FusionInventory.log(this, " inventory task is already running ...", Log.WARN);
- } else {
- FusionInventory.log(this, " inventory task not running ...", Log.INFO);
- start_inventory();
- }
- }
-
- break;
- case Agent.MSG_INVENTORY_RESULT:
- if (client != null) {
- reply.what = Agent.MSG_INVENTORY_RESULT;
+ AlarmManager am;
+ private Calendar cal = Calendar.getInstance();
- Bundle bXML = new Bundle();
- bXML.putString("result", lastXMLResult);
- reply.setData(bXML);
- try {
+ private boolean notif = false;
- client.send(reply);
-
- } catch (RemoteException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- break;
-
- case Agent.MSG_INVENTORY_SEND:
- send_inventory();
- if (client != null) {
- reply.what = Agent.MSG_INVENTORY_RESULT;
-
- Bundle bXML = new Bundle();
- bXML.putString("html", lastSendResult);
- reply.setData(bXML);
- try {
-
- client.send(reply);
-
- } catch (RemoteException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ class IncomingHandler
+ extends Handler {
+ <at> Override
+ public void handleMessage(Message msg) {
+
+ Message reply = Message.obtain();
+
+ Accueil.log(this, "message received " + msg.toString(), Log.INFO);
+
+ switch (msg.what) {
+
+ case Agent.MSG_CLIENT_REGISTER:
+ client = msg.replyTo;
+ break;
+
+ case Agent.MSG_AGENT_STATUS:
+
+ status_agent = inventory.running ? 1 : 0;
+ reply.what = MSG_AGENT_STATUS;
+ reply.arg1 = status_agent;
+ Accueil.log(this, "URL server = " + mFusionApp.getUrl(), Log.VERBOSE);
+ Accueil.log(this, "shouldAutostart = " + mFusionApp.getShouldAutoStart(), Log.VERBOSE);
+ Accueil.log(this, "mFusionApp = " + mFusionApp.toString(), Log.VERBOSE);
+
+ try {
+ Accueil.log(this, "message sent " + msg.toString(), Log.INFO);
+ if (client != null) {
+ client.send(reply);
+ } else {
+ Accueil.log(this, "No client registered", Log.ERROR);
+ }
+ } catch (RemoteException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ break;
+
+ case Agent.MSG_INVENTORY_START:
+
+ Accueil.log(this, " received starting inventory task", Log.INFO);
+
+ if (inventory != null) {
+
+ if (inventory.running) {
+
+ Accueil.log(this, " inventory task is already running ...", Log.WARN);
+ } else {
+ Accueil.log(this, " inventory task not running ...", Log.INFO);
+ start_inventory();
+ }
+ }
+
+ break;
+ case Agent.MSG_INVENTORY_RESULT:
+ if (client != null) {
+ reply.what = Agent.MSG_INVENTORY_RESULT;
+
+ Bundle bXML = new Bundle();
+ bXML.putString("result", lastXMLResult);
+ reply.setData(bXML);
+ try {
+
+ client.send(reply);
+
+ } catch (RemoteException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ break;
+
+ case Agent.MSG_INVENTORY_SEND:
+ send_inventory();
+ if (client != null) {
+ reply.what = Agent.MSG_INVENTORY_RESULT;
+
+ Bundle bXML = new Bundle();
+ bXML.putString("html", lastSendResult);
+ reply.setData(bXML);
+ try {
+
+ client.send(reply);
+
+ } catch (RemoteException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ break;
+ default:
+ super.handleMessage(msg);
}
}
- break;
- default:
- super.handleMessage(msg);
- }
- }
}
final Messenger mMessenger = new Messenger(new IncomingHandler());
<at> <at> -186,88 +196,131 <at> <at> public class Agent
public class AgentBinder
extends Binder {
- Agent getService() {
- return Agent.this;
- }
+ Agent getService() {
+ return Agent.this;
+ }
}
<at> Override
- public void onCreate() {
-
- FusionInventory.log(this, "creating inventory task", Log.INFO);
+ public void onCreate() {
+
+ SharedPreferences customSharedPreference = PreferenceManager.getDefaultSharedPreferences(this);
+ boolean autoInventory = customSharedPreference.getBoolean("autoStartInventory", false);
+ String timeInventory = customSharedPreference.getString("timeInventory", "Week");
+ notif = customSharedPreference.getBoolean("notif", false);
+
+ if (autoInventory)
+ {
+ if (timeInventory.equals("Day"))
+ {
+ cal.set(Calendar.HOUR_OF_DAY, 18);
+ cal.set(Calendar.MINUTE, 0);
+ cal.set(Calendar.SECOND, 0);
+ cal.set(Calendar.MILLISECOND, 0);
+ }
+ else if(timeInventory.equals("Week"))
+ {
+ cal.set(Calendar.DAY_OF_WEEK, 1);
+ cal.set(Calendar.HOUR_OF_DAY, 18);
+ cal.set(Calendar.MINUTE, 33);
+ cal.set(Calendar.SECOND, 0);
+ cal.set(Calendar.MILLISECOND, 0);
+ }
+ else if(timeInventory.equals("Month"))
+ {
+ cal.set(Calendar.WEEK_OF_MONTH, 1);
+ cal.set(Calendar.DAY_OF_WEEK, 1);
+ cal.set(Calendar.HOUR_OF_DAY, 18);
+ cal.set(Calendar.MINUTE, 0);
+ cal.set(Calendar.SECOND, 0);
+ cal.set(Calendar.MILLISECOND, 0);
+ }
- mFusionApp = (FusionInventoryApp) getApplication();
- FusionInventory.log(this, "FusionInventoryApp = " + mFusionApp.toString(), Log.VERBOSE);
+ am = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
+ setRepeatingAlarm();
+ }
- inventory = new InventoryTask(this);
+ Accueil.log(this, "creating inventory task", Log.INFO);
- mNM = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
+ mFusionApp = (FusionInventoryApp) getApplication();
+ Accueil.log(this, "FusionInventoryApp = " + mFusionApp.toString(), Log.VERBOSE);
- contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, FusionInventory.class), 0);
+ inventory = new InventoryTask(this);
- notification = new Notification();
- notification.icon = R.drawable.icon;
+ mNM = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
- notification.tickerText = getText(R.string.agent_started).toString();
- updateNotification(getText(R.string.agent_started).toString());
+ contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, Accueil.class), 0);
- mNM.notify(NOTIFICATION, notification);
+ if (notif){
+ notification = new Notification();
+ notification.icon = R.drawable.icon;
- Handler h = new Handler();
- h.postDelayed(new Runnable() {
+ notification.tickerText = getText(R.string.agent_started).toString();
+ updateNotification(getText(R.string.agent_started).toString());
- <at> Override
- public void run() {
- // TODO Auto-generated method stub
- mNM.cancel(NOTIFICATION);
+ mNM.notify(NOTIFICATION, notification);
}
- }, 1000);
- }
+ Handler h = new Handler();
+ h.postDelayed(new Runnable() {
+
+ <at> Override
+ public void run() {
+ // TODO Auto-generated method stub
+ mNM.cancel(NOTIFICATION);
+ }
+ }, 1000);
+
+
+ }
public void updateNotification(String text) {
- notification.setLatestEventInfo(this, getText(R.string.app_name), text, contentIntent);
+ SharedPreferences customSharedPreference = PreferenceManager.getDefaultSharedPreferences(this);
+ notif = customSharedPreference.getBoolean("notif", false);
+
+ if (notif){
+ notification.setLatestEventInfo(this, getText(R.string.app_name), text, contentIntent);
+ }
}
<at> Override
- public int onStartCommand(Intent intent, int flags, int startId) {
- FusionInventory.log(this, "Received start id " + startId + ": " + intent, Log.INFO);
+ public int onStartCommand(Intent intent, int flags, int startId) {
+ Accueil.log(this, "Received start id " + startId + ": " + intent, Log.INFO);
- // We want this service to continue running until it is explicitly
- // stopped, so return sticky.
+ // We want this service to continue running until it is explicitly
+ // stopped, so return sticky.
- // mNM.cancel(NOTIFICATION);
+ // mNM.cancel(NOTIFICATION);
- return START_STICKY;
- }
+ return START_STICKY;
+ }
public void start_inventory() {
- Thread t = new Thread(new Runnable() {
- public void run() {
- inventory.run();
+ inventory.run();
- lastXMLResult = inventory.toXML();
+ lastXMLResult = inventory.toXML();
- if (client != null) {
- try {
- client.send(Message.obtain(null, Agent.MSG_INVENTORY_FINISHED));
- } catch (RemoteException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
+ if (client != null) {
+ try {
+ client.send(Message.obtain(null, Agent.MSG_INVENTORY_FINISHED));
+ } catch (RemoteException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
}
- });
- t.start();
+ }
+
}
public void send_inventory() {
if (lastXMLResult == null) {
- FusionInventory.log(this, "No XML Inventory ", Log.ERROR);
- return;
+ Accueil.log(this, "No XML Inventory ", Log.ERROR);
+ Toast.makeText(this, R.string.error_inventory, Toast.LENGTH_SHORT).show();
+ }
+ else{
+ Toast.makeText(this, R.string.ok_inventory, Toast.LENGTH_SHORT).show();
}
URL url = null;
<at> <at> -275,11 +328,13 <at> <at> public class Agent
url = new URL(mFusionApp.getUrl());
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
- FusionInventory.log(this, "inventory server url is malformed " + e.getLocalizedMessage(), Log.ERROR);
+ Accueil.log(this, "inventory server url is malformed " + e.getLocalizedMessage(), Log.ERROR);
+ Toast.makeText(this, "Server adress is malformed", Toast.LENGTH_SHORT).show();
}
if (url == null) {
- FusionInventory.log(this, "No URL found ", Log.ERROR);
+ Accueil.log(this, "No URL found ", Log.ERROR);
+ Toast.makeText(this, "Server adress not found", Toast.LENGTH_SHORT).show();
return;
}
<at> <at> -292,7 +347,7 <at> <at> public class Agent
HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
HttpProtocolParams.setContentCharset(params, "UTF-8");
HttpProtocolParams.setUseExpectContinue(params, true);
-
+
//Send FusionInventory specific user agent
//TODO get App version from manifest or somewhere else
HttpProtocolParams.setUserAgent(params, "FusionInventory-Agent-Android_v1.0");
<at> <at> -303,11 +358,11 <at> <at> public class Agent
// ignore that the ssl cert is self signed
String login = mFusionApp.getCredentialsLogin();
if (!login.equals("")) {
- FusionInventory.log(this, "HTTP credentials given : use it if necessary", Log.VERBOSE);
+ Accueil.log(this, "HTTP credentials given : use it if necessary", Log.VERBOSE);
CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
credentialsProvider.setCredentials(new AuthScope(url.getHost(), AuthScope.ANY_PORT),
- new UsernamePasswordCredentials(mFusionApp.getCredentialsLogin(),
- mFusionApp.getCredentialsPassword()));
+ new UsernamePasswordCredentials(mFusionApp.getCredentialsLogin(),
+ mFusionApp.getCredentialsPassword()));
context.setAttribute("http.auth.credentials-provider", credentialsProvider);
}
<at> <at> -315,20 +370,20 <at> <at> public class Agent
HttpPost post = new HttpPost(url.toExternalForm());
httpclient.addRequestInterceptor(new HttpRequestInterceptor() {
-
+
<at> Override
public void process(HttpRequest request, HttpContext context) throws HttpException, IOException {
// TODO Auto-generated method stub
-
-
+
+
for( Header h : request.getAllHeaders()) {
-
- FusionInventory.log(this, "HEADER : "+ h.getName() + "=" + h.getValue(), Log.VERBOSE);
+
+ Accueil.log(this, "HEADER : "+ h.getName() + "=" + h.getValue(), Log.VERBOSE);
}
-
+
}
});
-
+
try {
post.setEntity(new StringEntity(lastXMLResult));
} catch (UnsupportedEncodingException e1) {
<at> <at> -340,21 +395,24 <at> <at> public class Agent
response = httpclient.execute(post, context);
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
- FusionInventory.log(this, "Protocol Exception Error : " + e.getLocalizedMessage(), Log.ERROR);
+ Accueil.log(this, "Protocol Exception Error : " + e.getLocalizedMessage(), Log.ERROR);
+ Toast.makeText(this, "Server doesn't reply", Toast.LENGTH_SHORT).show();
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
- FusionInventory.log(this, "IO error : " + e.getLocalizedMessage(), Log.ERROR);
- FusionInventory.log(this, "IO error : " + url.toExternalForm(), Log.ERROR);
+ Accueil.log(this, "IO error : " + e.getLocalizedMessage(), Log.ERROR);
+ Accueil.log(this, "IO error : " + url.toExternalForm(), Log.ERROR);
+ Toast.makeText(this, "Server doesn't reply", Toast.LENGTH_SHORT).show();
e.printStackTrace();
}
if (response == null) {
- FusionInventory.log(this, "No HTTP response ", Log.ERROR);
+ Accueil.log(this, "No HTTP response ", Log.ERROR);
+ Toast.makeText(this, "Server doesn't reply", Toast.LENGTH_SHORT).show();
return;
}
Header[] headers = response.getAllHeaders();
for (Header header : headers) {
- FusionInventory.log(this, header.getName() + " -> " + header.getValue(), Log.INFO);
+ Accueil.log(this, header.getName() + " -> " + header.getValue(), Log.INFO);
}
try {
InputStream mIS = response.getEntity().getContent();
<at> <at> -362,10 +420,10 <at> <at> public class Agent
BufferedReader r = new BufferedReader(new InputStreamReader(mIS));
String line;
StringBuilder sb = new StringBuilder();
-
+
while ((line = r.readLine()) != null) {
//content.append(line);
- FusionInventory.log(this, line, Log.VERBOSE);
+ Accueil.log(this, line, Log.VERBOSE);
sb.append(line + "\n");
}
this.lastSendResult = sb.toString();
<at> <at> -377,23 +435,39 <at> <at> public class Agent
// TODO Auto-generated catch block
e.printStackTrace();
}
+ Toast.makeText(this, "Inventory sent", Toast.LENGTH_SHORT).show();
}
<at> Override
- public void onDestroy() {
- // Cancel the persistent notification.
+ public void onDestroy() {
+ // Cancel the persistent notification.
- mNM.cancel(NOTIFICATION);
+ SharedPreferences customSharedPreference = PreferenceManager.getDefaultSharedPreferences(this);
+ notif = customSharedPreference.getBoolean("notif", false);
- // Tell the user we stopped.
- Toast.makeText(this, R.string.agent_stopped, Toast.LENGTH_SHORT).show();
- }
+ mNM.cancel(NOTIFICATION);
+
+ // Tell the user we stopped.
+ if (notif){
+ Toast.makeText(this, R.string.agent_stopped, Toast.LENGTH_SHORT).show();
+ }
+ }
<at> Override
- public IBinder onBind(Intent intent) {
+ public IBinder onBind(Intent intent) {
+
+ return mMessenger.getBinder();
+ }
+
+ public void setRepeatingAlarm() {
+ Intent intent = new Intent(this, TimeAlarm.class);
+ PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0,
+ intent, PendingIntent.FLAG_CANCEL_CURRENT);
+
+ am.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), pendingIntent);
- return mMessenger.getBinder();
}
+
// private final IBinder mBinder = new AgentBinder();
}
diff --git a/src/org/fusioninventory/AutoInventory.java b/src/org/fusioninventory/AutoInventory.java
new file mode 100644
index 0000000..290efa2
--- /dev/null
+++ b/src/org/fusioninventory/AutoInventory.java
<at> <at> -0,0 +1,378 <at> <at>
+package org.fusioninventory;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.UnsupportedEncodingException;
+import java.net.MalformedURLException;
+import java.net.URL;
+
+import org.apache.http.Header;
+import org.apache.http.HttpException;
+import org.apache.http.HttpRequest;
+import org.apache.http.HttpRequestInterceptor;
+import org.apache.http.HttpResponse;
+import org.apache.http.HttpVersion;
+import org.apache.http.auth.AuthScope;
+import org.apache.http.auth.UsernamePasswordCredentials;
+import org.apache.http.client.ClientProtocolException;
+import org.apache.http.client.CredentialsProvider;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.conn.ClientConnectionManager;
+import org.apache.http.conn.scheme.PlainSocketFactory;
+import org.apache.http.conn.scheme.Scheme;
+import org.apache.http.conn.scheme.SchemeRegistry;
+import org.apache.http.entity.StringEntity;
+import org.apache.http.impl.client.BasicCredentialsProvider;
+import org.apache.http.impl.client.DefaultHttpClient;
+import org.apache.http.impl.conn.SingleClientConnManager;
+import org.apache.http.params.BasicHttpParams;
+import org.apache.http.params.HttpParams;
+import org.apache.http.params.HttpProtocolParams;
+import org.apache.http.protocol.BasicHttpContext;
+import org.apache.http.protocol.HttpContext;
+import org.fusioninventory.utils.EasySSLSocketFactory;
+
+import android.app.Service;
+import android.content.Intent;
+import android.content.SharedPreferences;
+import android.os.Binder;
+import android.os.Bundle;
+import android.os.Handler;
+import android.os.IBinder;
+import android.os.Message;
+import android.os.Messenger;
+import android.os.RemoteException;
+import android.preference.PreferenceManager;
+import android.util.Log;
+import android.widget.Toast;
+
+public class AutoInventory
+ extends Service {
+
+ private Messenger client = null;
+ public InventoryTaskAuto inventory = null;
+
+ static final int MSG_CLIENT_REGISTER = 0;
+ static final int MSG_AGENT_STATUS = 1;
+ static final int MSG_INVENTORY_START = 2;
+ static final int MSG_INVENTORY_PROGRESS = 3;
+ static final int MSG_INVENTORY_FINISHED = 4;
+ static final int MSG_REQUEST_INVENTORY = 5;
+ static final int MSG_INVENTORY_RESULT = 6;
+ static final int MSG_INVENTORY_SEND = 7;
+
+ static final int STATUS_AGENT_IDLE = 0;
+ static final int STATUS_AGENT_WORKING = 1;
+
+ private int status_agent = 0;
+
+ private String lastXMLResult = null;
+ private String lastSendResult = null;
+
+ private ClientConnectionManager clientConnectionManager;
+ private HttpContext context;
+ private HttpParams params;
+ private SchemeRegistry mSchemeRegistry = new SchemeRegistry();
+
+ private FusionInventoryApp mFusionApp = null;
+
+ private boolean notif = false;
+
+ class IncomingHandler
+ extends Handler {
+ <at> Override
+ public void handleMessage(Message msg) {
+
+ Message reply = Message.obtain();
+
+ Accueil.log(this, "message received " + msg.toString(), Log.INFO);
+
+ switch (msg.what) {
+
+ case Agent.MSG_CLIENT_REGISTER:
+ client = msg.replyTo;
+ break;
+
+ case Agent.MSG_AGENT_STATUS:
+
+ status_agent = inventory.running ? 1 : 0;
+ reply.what = MSG_AGENT_STATUS;
+ reply.arg1 = status_agent;
+ Accueil.log(this, "URL server = " + mFusionApp.getUrl(), Log.VERBOSE);
+ Accueil.log(this, "shouldAutostart = " + mFusionApp.getShouldAutoStart(), Log.VERBOSE);
+ Accueil.log(this, "mFusionApp = " + mFusionApp.toString(), Log.VERBOSE);
+
+ try {
+ Accueil.log(this, "message sent " + msg.toString(), Log.INFO);
+ if (client != null) {
+ client.send(reply);
+ } else {
+ Accueil.log(this, "No client registered", Log.ERROR);
+ }
+ } catch (RemoteException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ break;
+
+ case Agent.MSG_INVENTORY_RESULT:
+ if (client != null) {
+ reply.what = Agent.MSG_INVENTORY_RESULT;
+
+ Bundle bXML = new Bundle();
+ bXML.putString("result", lastXMLResult);
+ reply.setData(bXML);
+ try {
+
+ client.send(reply);
+
+ } catch (RemoteException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ break;
+
+ case Agent.MSG_INVENTORY_SEND:
+ send_inventory();
+ if (client != null) {
+ reply.what = Agent.MSG_INVENTORY_RESULT;
+
+ Bundle bXML = new Bundle();
+ bXML.putString("html", lastSendResult);
+ reply.setData(bXML);
+ try {
+
+ client.send(reply);
+
+ } catch (RemoteException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ break;
+ default:
+ super.handleMessage(msg);
+ }
+ }
+ }
+
+ final Messenger mMessenger = new Messenger(new IncomingHandler());
+
+ public class AgentBinder
+ extends Binder {
+ AutoInventory getService() {
+ return AutoInventory.this;
+ }
+ }
+
+ <at> Override
+ public void onCreate() {
+
+ inventory = new InventoryTaskAuto(this);
+
+ mFusionApp = (FusionInventoryApp) getApplication();
+
+ SharedPreferences customSharedPreference =
+ PreferenceManager.getDefaultSharedPreferences(this);
+ boolean notif = customSharedPreference.getBoolean("notif", false);
+
+ if (notif){
+ Toast.makeText(this,R.string.inventory_started,Toast.LENGTH_LONG).show();
+ }
+
+ inventory();
+
+ send_inventory();
+
+ }
+
+
+ <at> Override
+ public int onStartCommand(Intent intent, int flags, int startId) {
+ Accueil.log(this, "Received start id " + startId + ": " + intent, Log.INFO);
+
+ // We want this service to continue running until it is explicitly
+ // stopped, so return sticky.
+
+ // mNM.cancel(NOTIFICATION);
+
+ return START_STICKY;
+ }
+
+ public void send_inventory() {
+
+ SharedPreferences customSharedPreference = PreferenceManager.getDefaultSharedPreferences(this);
+ notif = customSharedPreference.getBoolean("notif", false);
+
+ if (lastXMLResult == null) {
+ Accueil.log(this, "No XML Inventory ", Log.ERROR);
+ if (notif){
+ Toast.makeText(this, R.string.error_inventory, Toast.LENGTH_SHORT).show();
+ }
+ }
+ else{
+ if (notif){
+ Toast.makeText(this, R.string.ok_inventory, Toast.LENGTH_SHORT).show();
+ }
+ }
+ URL url = null;
+
+ try {
+ url = new URL(mFusionApp.getUrl());
+ } catch (MalformedURLException e) {
+ // TODO Auto-generated catch block
+ Accueil.log(this, "inventory server url is malformed " + e.getLocalizedMessage(), Log.ERROR);
+ if (notif){
+ Toast.makeText(this, "Server adress is malformed", Toast.LENGTH_SHORT).show();
+ }
+ }
+
+ if (url == null) {
+ Accueil.log(this, "No URL found ", Log.ERROR);
+ if (notif){
+ Toast.makeText(this, "Server adress not found", Toast.LENGTH_SHORT).show();
+ }
+ return;
+ }
+
+ mSchemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
+ // https scheme
+ mSchemeRegistry.register(new Scheme("https", new EasySSLSocketFactory(), 443));
+
+ params = new BasicHttpParams();
+
+ HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
+ HttpProtocolParams.setContentCharset(params, "UTF-8");
+ HttpProtocolParams.setUseExpectContinue(params, true);
+
+ //Send FusionInventory specific user agent
+ //TODO get App version from manifest or somewhere else
+ HttpProtocolParams.setUserAgent(params, "FusionInventory-Agent-Android_v1.0");
+
+ clientConnectionManager = new SingleClientConnManager(params, mSchemeRegistry);
+ context = new BasicHttpContext();
+
+ // ignore that the ssl cert is self signed
+ String login = mFusionApp.getCredentialsLogin();
+ if (!login.equals("")) {
+ Accueil.log(this, "HTTP credentials given : use it if necessary", Log.VERBOSE);
+ CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
+ credentialsProvider.setCredentials(new AuthScope(url.getHost(), AuthScope.ANY_PORT),
+ new UsernamePasswordCredentials(mFusionApp.getCredentialsLogin(),
+ mFusionApp.getCredentialsPassword()));
+ context.setAttribute("http.auth.credentials-provider", credentialsProvider);
+ }
+
+ DefaultHttpClient httpclient = new DefaultHttpClient(clientConnectionManager, params);
+
+ HttpPost post = new HttpPost(url.toExternalForm());
+ httpclient.addRequestInterceptor(new HttpRequestInterceptor() {
+
+ <at> Override
+ public void process(HttpRequest request, HttpContext context) throws HttpException, IOException {
+ // TODO Auto-generated method stub
+
+
+ for( Header h : request.getAllHeaders()) {
+
+ Accueil.log(this, "HEADER : "+ h.getName() + "=" + h.getValue(), Log.VERBOSE);
+ }
+
+ }
+ });
+
+ try {
+ post.setEntity(new StringEntity(lastXMLResult));
+ } catch (UnsupportedEncodingException e1) {
+ // TODO Auto-generated catch block
+ e1.printStackTrace();
+ }
+ HttpResponse response = null;
+ try {
+ response = httpclient.execute(post, context);
+ } catch (ClientProtocolException e) {
+ // TODO Auto-generated catch block
+ Accueil.log(this, "Protocol Exception Error : " + e.getLocalizedMessage(), Log.ERROR);
+ if (notif){
+ Toast.makeText(this, "Server doesn't reply", Toast.LENGTH_SHORT).show();
+ }
+ e.printStackTrace();
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ Accueil.log(this, "IO error : " + e.getLocalizedMessage(), Log.ERROR);
+ Accueil.log(this, "IO error : " + url.toExternalForm(), Log.ERROR);
+ if (notif){
+ Toast.makeText(this, "Server doesn't reply", Toast.LENGTH_SHORT).show();
+ }
+ e.printStackTrace();
+ }
+ if (response == null) {
+ Accueil.log(this, "No HTTP response ", Log.ERROR);
+ if (notif){
+ Toast.makeText(this, "Server doesn't reply", Toast.LENGTH_SHORT).show();
+ }
+ return;
+ }
+ Header[] headers = response.getAllHeaders();
+ for (Header header : headers) {
+ Accueil.log(this, header.getName() + " -> " + header.getValue(), Log.INFO);
+ }
+ try {
+ InputStream mIS = response.getEntity().getContent();
+ //StringBuilder content = new StringBuilder();
+ BufferedReader r = new BufferedReader(new InputStreamReader(mIS));
+ String line;
+ StringBuilder sb = new StringBuilder();
+
+ while ((line = r.readLine()) != null) {
+ //content.append(line);
+ Accueil.log(this, line, Log.VERBOSE);
+ sb.append(line + "\n");
+ }
+ this.lastSendResult = sb.toString();
+
+ } catch (IllegalStateException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ if (notif){
+ Toast.makeText(this, "Inventory sent", Toast.LENGTH_SHORT).show();
+ }
+ }
+
+ public void inventory() {
+
+ inventory.run();
+
+ lastXMLResult = inventory.toXML();
+
+ if (client != null) {
+ try {
+ client.send(Message.obtain(null, Agent.MSG_INVENTORY_FINISHED));
+ } catch (RemoteException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+ }
+
+ <at> Override
+ public void onDestroy() {
+
+ }
+
+ <at> Override
+ public IBinder onBind(Intent intent) {
+
+ return mMessenger.getBinder();
+ }
+
+ // private final IBinder mBinder = new AgentBinder();
+}
diff --git a/src/org/fusioninventory/FusionInventory.java b/src/org/fusioninventory/FusionInventory.java
index 4d6a52f..c80f9f8 100644
--- a/src/org/fusioninventory/FusionInventory.java
+++ b/src/org/fusioninventory/FusionInventory.java
<at> <at> -1,6 +1,7 <at> <at>
package org.fusioninventory;
import android.app.Activity;
+
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
<at> <at> -31,7 +32,7 <at> <at> public class FusionInventory
private String[] STATUS_AGENT = null;
private boolean isAgentOk = false;
private String barcode = null;
-
+
public static void log(Object obj, String msg, int level) {
String final_msg = String.format("[%s] %s", obj.getClass().getName(), msg);
Log.println(level, "FusionInventory", final_msg);
<at> <at> -160,7 +161,7 <at> <at> public class FusionInventory
<at> Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- STATUS_AGENT = getResources().getStringArray(R.array.agent_status);
+ STATUS_AGENT = getResources().getStringArray(R.array.agent_status);
setContentView(R.layout.main);
diff --git a/src/org/fusioninventory/InventoryTaskAuto.java b/src/org/fusioninventory/InventoryTaskAuto.java
new file mode 100644
index 0000000..cda5d2a
--- /dev/null
+++ b/src/org/fusioninventory/InventoryTaskAuto.java
<at> <at> -0,0 +1,190 <at> <at>
+package org.fusioninventory;
+
+import java.io.StringWriter;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
+import java.util.Date;
+
+import org.fusioninventory.categories.Categories;
+import org.xmlpull.v1.XmlSerializer;
+
+import android.content.Context;
+import android.text.format.DateFormat;
+import android.util.Log;
+import android.util.Xml;
+
+public class InventoryTaskAuto {
+
+ /*
+ * TODO: Implémenter l'inventaire sous forme de Hashmap/Hashtable
+ * <string,string> pour le moment
+ */
+
+ public ArrayList<Categories> mContent = null;
+ public Date mStart = null, mEnd = null;
+ public Context ctx = null;
+ static final int OK = 0;
+ static final int NOK = 1;
+
+ public Boolean running = false;
+ public int progress = 0;
+
+ private AutoInventory mAgent;
+ private FusionInventoryApp mFusionApp;
+
+ public InventoryTaskAuto(AutoInventory test) {
+ mAgent= test;
+ ctx = mAgent.getApplicationContext();
+ mFusionApp = (FusionInventoryApp) mAgent.getApplication();
+ Accueil.log(this, "FusionInventoryApp = " + mFusionApp.toString(), Log.VERBOSE);
+ }
+
+ public String toXML() {
+
+ if (mContent != null) {
+
+ XmlSerializer serializer = Xml.newSerializer();
+ StringWriter writer = new StringWriter();
+
+ try {
+ serializer.setOutput(writer);
+ serializer
+ .setFeature(
+ "http://xmlpull.org/v1/doc/features.html#indent-output",
+ true);
+ // indentation as 3 spaces
+
+ serializer.startDocument("utf-8", true);
+ // Start REQUEST
+ serializer.startTag(null, "REQUEST");
+ // Start CONTENT
+ serializer.startTag(null, "QUERY");
+ serializer.text("INVENTORY");
+ serializer.endTag(null, "QUERY");
+
+ serializer.startTag(null, "DEVICEID");
+ serializer.text(mFusionApp.getDeviceID());
+ serializer.endTag(null, "DEVICEID");
+
+ serializer.startTag(null, "CONTENT");
+ // Start ACCESSLOG
+ serializer.startTag(null, "ACCESSLOG");
+
+ serializer.startTag(null, "LOGDATE");
+
+ serializer.text(DateFormat.format("yyyy-mm-dd hh:MM:ss", mStart)
+ .toString());
+ serializer.endTag(null, "LOGDATE");
+
+ serializer.startTag(null, "USERID");
+ serializer.text("N/A");
+ serializer.endTag(null, "USERID");
+
+ serializer.endTag(null, "ACCESSLOG");
+ // End ACCESSLOG
+
+ //Manage accountinfos :: TAG
+ if (!mFusionApp.getTag().equals("")) {
+ serializer.startTag(null, "ACCOUNTINFO");
+ serializer.startTag(null, "KEYNAME");
+ serializer.text("TAG");
+ serializer.endTag(null, "KEYNAME");
+ serializer.startTag(null, "KEYVALUE");
+ serializer.text(mFusionApp.getTag());
+ serializer.endTag(null, "KEYVALUE");
+ serializer.endTag(null, "ACCOUNTINFO");
+ }
+
+ for (Categories cat : mContent) {
+
+ cat.toXML(serializer);
+ }
+
+ serializer.endTag(null, "CONTENT");
+ serializer.endTag(null, "REQUEST");
+ serializer.endDocument();
+ return (writer.toString());
+ } catch (Exception e) {
+ // TODO: handle exception
+ throw new RuntimeException(e);
+ }
+
+ }
+ return null;
+ }
+
+
+ <at> SuppressWarnings("unchecked")
+ public synchronized void run() {
+
+ running = true;
+ mStart = new Date();
+
+ mContent = new ArrayList<Categories>();
+
+ String [] categories = {
+ // "PhoneStatus",
+ "Hardware",
+ "Bios",
+ "Memory",
+ "Inputs",
+ "Sensors",
+ "Drives",
+ "Cpus",
+ "Simcards",
+ "Videos",
+ "Cameras",
+ "Networks",
+ // "LocationProviders",
+ "Envs",
+ "Jvm",
+ "Softwares"
+ // "Usbs",
+ // "Battery",
+ // "BluetoothAdapterCategory", // <- there is already a BluetoothAdapter class in android SDK
+ };
+
+ Class<Categories> cat_class;
+
+ for(String c : categories) {
+ cat_class = null;
+ Accueil.log(this, String.format("INVENTORY of %s", c),Log.VERBOSE);
+ try {
+ cat_class = (Class <Categories>) Class.forName(String.format("org.fusioninventory.categories.%s",c));
+ } catch (ClassNotFoundException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ if(cat_class!=null) {
+ try {
+ Constructor<Categories> co = cat_class.getConstructor(Context.class);
+ mContent.add(co.newInstance(mFusionApp));
+ } catch (SecurityException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (NoSuchMethodException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (IllegalArgumentException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (InstantiationException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (IllegalAccessException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (InvocationTargetException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ }
+
+
+ Accueil.log(this, "end of inventory", Log.INFO);
+ mEnd = new Date();
+ running = false;
+ }
+}
diff --git a/src/org/fusioninventory/TimeAlarm.java b/src/org/fusioninventory/TimeAlarm.java
new file mode 100644
index 0000000..0786ff2
--- /dev/null
+++ b/src/org/fusioninventory/TimeAlarm.java
<at> <at> -0,0 +1,16 <at> <at>
+package org.fusioninventory;
+
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+
+public class TimeAlarm extends BroadcastReceiver {
+
+ <at> Override
+ public void onReceive(Context context, Intent intent) {
+ Intent serviceIntent = new Intent();
+ serviceIntent.setAction("org.fusioninventory.AutoInventory");
+ context.startService(serviceIntent);
+ context.stopService(serviceIntent);
+ }
+}
_______________________________________________
Fusioninventory-devel mailing list
Fusioninventory-devel@...
http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/fusioninventory-devel