Merge lp:~ccabessa/ocsinventory-android-agent/ocsinventory into lp:ocsinventory-android-agent

Proposed by Cédric Cabessa
Status: Merged
Merged at revision: 19
Proposed branch: lp:~ccabessa/ocsinventory-android-agent/ocsinventory
Merge into: lp:ocsinventory-android-agent
Diff against target: 433 lines (+98/-72)
11 files modified
AndroidManifest.xml (+2/-1)
src/org/ocsinventory/android/actions/Inventory.java (+2/-2)
src/org/ocsinventory/android/actions/OCSFiles.java (+18/-15)
src/org/ocsinventory/android/actions/OCSProtocol.java (+9/-3)
src/org/ocsinventory/android/actions/Utils.java (+7/-0)
src/org/ocsinventory/android/agent/AboutDialog.java (+6/-6)
src/org/ocsinventory/android/agent/AsyncOperations.java (+2/-2)
src/org/ocsinventory/android/agent/OCSAgentActivity.java (+0/-1)
src/org/ocsinventory/android/agent/OCSAgentService.java (+33/-28)
src/org/ocsinventory/android/agent/OCSEventReceiver.java (+3/-0)
src/org/ocsinventory/android/sections/OCSNetworks.java (+16/-14)
To merge this branch: bzr merge lp:~ccabessa/ocsinventory-android-agent/ocsinventory
Reviewer Review Type Date Requested Status
OCS Inventory Dev Team Pending
Review via email: mp+160645@code.launchpad.net

Description of the change

Hi

Here are more changes!
Feel free to select what you find useful, as always if you think that something can be rewrote in a better way, let me know.

FYI: I'll be unable to answer from the 28 to may 20th

Thank you for your review

To post a comment you must log in.
Revision history for this message
Jean-Côme ESTIENNEY (cdpointpoint) wrote :
Download full text (20.6 KiB)

Hi Cedric,

Thanks again.

After first look at your contribution il think that much and probably allare
very helpful

I will merge all that quitely this WE :-)

Regards...

JCE

2013/4/24 Cédric Cabessa <email address hidden>

> Cédric Cabessa has proposed merging
> lp:~ccabessa/ocsinventory-android-agent/ocsinventory into
> lp:ocsinventory-android-agent.
>
> Requested reviews:
> OCS Inventory Dev Team (ocsinventory-dev)
>
> For more details, see:
>
> https://code.launchpad.net/~ccabessa/ocsinventory-android-agent/ocsinventory/+merge/160645
>
> Hi
>
> Here are more changes!
> Feel free to select what you find useful, as always if you think that
> something can be rewrote in a better way, let me know.
>
> FYI: I'll be unable to answer from the 28 to may 20th
>
> Thank you for your review
> --
>
> https://code.launchpad.net/~ccabessa/ocsinventory-android-agent/ocsinventory/+merge/160645
> Your team OCS Inventory Dev Team is requested to review the proposed merge
> of lp:~ccabessa/ocsinventory-android-agent/ocsinventory into
> lp:ocsinventory-android-agent.
>
> === modified file 'AndroidManifest.xml'
> --- AndroidManifest.xml 2013-04-17 19:35:07 +0000
> +++ AndroidManifest.xml 2013-04-24 13:42:26 +0000
> @@ -64,7 +64,8 @@
>
> <receiver
> android:name=".OCSEventReceiver"
> - android:process=":ocs_process" >
> + android:process=":ocs_process"
> + android:exported="true" >
> </receiver>
> <receiver
> android:name=".OCSBootReceiver"
>
> === modified file 'src/org/ocsinventory/android/actions/Inventory.java'
> --- src/org/ocsinventory/android/actions/Inventory.java 2013-04-08
> 19:17:12 +0000
> +++ src/org/ocsinventory/android/actions/Inventory.java 2013-04-24
> 13:42:26 +0000
> @@ -150,8 +150,8 @@
> instance = new Inventory(ctx);
> else {
> Date now = new Date();
> - long d = (now.getTime() -
> lastDate.getTime())/60000L;
> - android.util.Log.d("OCS","Age du cache (mn) = "+d
> );
> + long d = (now.getTime() - lastDate.getTime());
> + android.util.Log.d("OCS","Age du cache (mn) = "+d
> / 60000L);
> if ( d > dureeCache ) {
> android.util.Log.d("OCS","REFRESH" );
> instance = new Inventory(ctx);
>
> === modified file 'src/org/ocsinventory/android/actions/OCSFiles.java'
> --- src/org/ocsinventory/android/actions/OCSFiles.java 2013-03-19
> 20:49:53 +0000
> +++ src/org/ocsinventory/android/actions/OCSFiles.java 2013-04-24
> 13:42:26 +0000
> @@ -6,8 +6,9 @@
> import java.io.FileNotFoundException;
> import java.io.FileOutputStream;
> import java.io.IOException;
> -import java.io.InputStream;
> -import java.io.OutputStream;
> +import java.util.Date;
> +import java.util.Locale;
> +import java.text.SimpleDateFormat;
> import java.util.zip.GZIPOutputStream;
>
> import android.content.Context;
> @@ -15,25 +16,27 @@
> import android.provider.OpenableColumns;
>
> public class OCSFiles {
> - private static OCSFiles insta...

Revision history for this message
Jean-Côme ESTIENNEY (cdpointpoint) wrote :
Download full text (22.6 KiB)

Hi Cedriic,

I had read your changes and send you, bellow, my notes about each file :

I have few questions before merging :
- how manage you the option save_inventory ( new option on settings ?)
- why add android.exported option in AndroidManifest.xml. May be launch you
the service with a other activity ?
- why drop wifi state enabling if not enabled currently ?

About usage of OCSSettings in OCSAgentService please can you confirm that
all work correctly.
I had used shared_prefs because using OCSSetings an already started service
dont take some settings changes. Il dont remember exaclty. Can you try to
change ie server address with a started service ?

Regards,

JCE

------------------------------------------------------------------------------------------------------------------------------
AndroidManifest.xml
    Add android:exported=true on ".OCSEventReceiver"

src/org/ocsinventory/android/agent/AboutDialog.java
    Use OCSSettings properly

src/org/ocsinventory/android/actions/Inventory.java
    Bug on cache expiration evaluation (unit)

src/org/ocsinventory/android/actions/OCSFiles.java
    Change for usage as an ordinary object (no singleton)
    Impact on getInstance usage in OCSProtocol.java
        and AsyncOperations.java
    File inventory builed whith hostname

src/org/ocsinventory/android/actions/OCSProtocol.java
    new OCSFiles instead of getTnstance.

src/org/ocsinventory/android/agent/AsyncOperations.java
    new OCSFiles instead of getTnstance.

src/org/ocsinventory/android/actions/Utils.java
    Add getHostname function used in OCSFiles.java

src/org/ocsinventory/android/agent/OCSAgentActivity.java
    Suppress initInstance of OCSFiles.java

src/org/ocsinventory/android/agent/OCSAgentService.java
    Usage of OCSSetting class & not sharedprefs directily
    Add extra option force_update & save_inventory

src/org/ocsinventory/android/agent/OCSEventReceiver.java
    put extra options on service call

src/org/ocsinventory/android/sections/OCSNetworks.java
    Proper use SDK constant vs value for wifi state
    Suppress auto wifii enableling

------------------------------------------------------------------------------------------------------------------------------

2013/4/24 Cédric Cabessa <email address hidden>

> Cédric Cabessa has proposed merging
> lp:~ccabessa/ocsinventory-android-agent/ocsinventory into
> lp:ocsinventory-android-agent.
>
> Requested reviews:
> OCS Inventory Dev Team (ocsinventory-dev)
>
> For more details, see:
>
> https://code.launchpad.net/~ccabessa/ocsinventory-android-agent/ocsinventory/+merge/160645
>
> Hi
>
> Here are more changes!
> Feel free to select what you find useful, as always if you think that
> something can be rewrote in a better way, let me know.
>
> FYI: I'll be unable to answer from the 28 to may 20th
>
> Thank you for your review
> --
>
> https://code.launchpad.net/~ccabessa/ocsinventory-android-agent/ocsinventory/+merge/160645
> Your team OCS Inventory Dev Team is requested to review the proposed merge
> of lp:~ccabessa/ocsinventory-android-agent/ocsinventory into
> lp:ocsinventory-android-agent.
>
> === modified file 'AndroidManifest.xml'
> --- AndroidManifest.x...

Revision history for this message
Cédric Cabessa (ccabessa) wrote :

Hi

2013/4/25 Jean-Côme ESTIENNEY <email address hidden>:
>
> I have few questions before merging :
> - how manage you the option save_inventory ( new option on settings ?)
> - why add android.exported option in AndroidManifest.xml. May be launch you
> the service with a other activity ?

Those two points are linked together :
Indeed, I'd like to be able to launch the service from another
activity or even from the command line (with the "am" command).
To give you some background, I work on a project that run a C daemon
on Android and need to start an inventory. So it doesn't use the
"automatic mode", but launch ocs with the "am" command.
It is similar as what we can do on Linux by launching
"ocsinventory-agent" command. The idea is to do the same thing (from
another activity or command line).
So the "save_inventory" option is an extra in the intent to tell the
service to save the inventory on disk (no new option in settings)
Without the extra, the inventory is send on the server as usual.

> - why drop wifi state enabling if not enabled currently ?
>

I think it is not ocsinventory's job to do that. (my opinion, you can
disagree :-))
If wifi is off, I do not have a wifi address, so ocsinventory should
report that.
On linux the client do not try to bring up new interfaces? Why do that
on android?

Moreover when I tried it, it did not work correctly the wifi stay
enabled after the inventory is done. I suspect the wifi process take
too much time and ocs try to disable it before the interface is
completely up. So this "feature" can be hard to implement correctly.

> About usage of OCSSettings in OCSAgentService please can you confirm that
> all work correctly.
> I had used shared_prefs because using OCSSetings an already started service
> dont take some settings changes. Il dont remember exaclty. Can you try to
> change ie server address with a started service ?

Yes, I just tried that I confirm it do not work correctly -:(
I am sorry I did not test it correctly

Sadly I will not have the time to fix it for now, I am on holiday
tonight for 3 weeks.
May be you can drop this part of the patch and apply the rest (or part
of the rest)?
I look at this when I am back.

Regards,

--
Cédric

Revision history for this message
Jean-Côme ESTIENNEY (cdpointpoint) wrote :

I repost my last eveing response for trace on code.launchpad & team
Ok I agree for wifii,
inventory file with the hostname is a good idea. Just i have to verify the
stuff on phone.
I suppose that you test on tab device.
About pb with prefernces sharing between service and activity.
activity & services was'nt working on the same process.
We have to add :
                      android:process=":ocs_process"
on ocsagentactivity & ocsprefsactivity.
I have made some little tests it seems be ok
After confirmation i'll merge of course this part too.
Regards,
JCE

2013/4/26 Cédric Cabessa <email address hidden>

> Hi
>
> 2013/4/25 Jean-Côme ESTIENNEY <email address hidden>:
> >
> > I have few questions before merging :
> > - how manage you the option save_inventory ( new option on settings ?)
> > - why add android.exported option in AndroidManifest.xml. May be launch
> you
> > the service with a other activity ?
>
> Those two points are linked together :
> Indeed, I'd like to be able to launch the service from another
> activity or even from the command line (with the "am" command).
> To give you some background, I work on a project that run a C daemon
> on Android and need to start an inventory. So it doesn't use the
> "automatic mode", but launch ocs with the "am" command.
> It is similar as what we can do on Linux by launching
> "ocsinventory-agent" command. The idea is to do the same thing (from
> another activity or command line).
> So the "save_inventory" option is an extra in the intent to tell the
> service to save the inventory on disk (no new option in settings)
> Without the extra, the inventory is send on the server as usual.
>
> > - why drop wifi state enabling if not enabled currently ?
> >
>
> I think it is not ocsinventory's job to do that. (my opinion, you can
> disagree :-))
> If wifi is off, I do not have a wifi address, so ocsinventory should
> report that.
> On linux the client do not try to bring up new interfaces? Why do that
> on android?
>
> Moreover when I tried it, it did not work correctly the wifi stay
> enabled after the inventory is done. I suspect the wifi process take
> too much time and ocs try to disable it before the interface is
> completely up. So this "feature" can be hard to implement correctly.
>
> > About usage of OCSSettings in OCSAgentService please can you confirm that
> > all work correctly.
> > I had used shared_prefs because using OCSSetings an already started
> service
> > dont take some settings changes. Il dont remember exaclty. Can you try
> to
> > change ie server address with a started service ?
>
> Yes, I just tried that I confirm it do not work correctly -:(
> I am sorry I did not test it correctly
>
> Sadly I will not have the time to fix it for now, I am on holiday
> tonight for 3 weeks.
> May be you can drop this part of the patch and apply the rest (or part
> of the rest)?
> I look at this when I am back.
>
> Regards,
>
> --
> Cédric
>

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'AndroidManifest.xml'
2--- AndroidManifest.xml 2013-04-17 19:35:07 +0000
3+++ AndroidManifest.xml 2013-04-24 13:42:26 +0000
4@@ -64,7 +64,8 @@
5
6 <receiver
7 android:name=".OCSEventReceiver"
8- android:process=":ocs_process" >
9+ android:process=":ocs_process"
10+ android:exported="true" >
11 </receiver>
12 <receiver
13 android:name=".OCSBootReceiver"
14
15=== modified file 'src/org/ocsinventory/android/actions/Inventory.java'
16--- src/org/ocsinventory/android/actions/Inventory.java 2013-04-08 19:17:12 +0000
17+++ src/org/ocsinventory/android/actions/Inventory.java 2013-04-24 13:42:26 +0000
18@@ -150,8 +150,8 @@
19 instance = new Inventory(ctx);
20 else {
21 Date now = new Date();
22- long d = (now.getTime() - lastDate.getTime())/60000L;
23- android.util.Log.d("OCS","Age du cache (mn) = "+d );
24+ long d = (now.getTime() - lastDate.getTime());
25+ android.util.Log.d("OCS","Age du cache (mn) = "+d / 60000L);
26 if ( d > dureeCache ) {
27 android.util.Log.d("OCS","REFRESH" );
28 instance = new Inventory(ctx);
29
30=== modified file 'src/org/ocsinventory/android/actions/OCSFiles.java'
31--- src/org/ocsinventory/android/actions/OCSFiles.java 2013-03-19 20:49:53 +0000
32+++ src/org/ocsinventory/android/actions/OCSFiles.java 2013-04-24 13:42:26 +0000
33@@ -6,8 +6,9 @@
34 import java.io.FileNotFoundException;
35 import java.io.FileOutputStream;
36 import java.io.IOException;
37-import java.io.InputStream;
38-import java.io.OutputStream;
39+import java.util.Date;
40+import java.util.Locale;
41+import java.text.SimpleDateFormat;
42 import java.util.zip.GZIPOutputStream;
43
44 import android.content.Context;
45@@ -15,25 +16,27 @@
46 import android.provider.OpenableColumns;
47
48 public class OCSFiles {
49- private static OCSFiles instance = null;
50 // public String BASE_FILE_NAME = "termadmin";
51 // public String XML_DIR = "/XML/";
52- private static Context appCtx;
53+ private Context appCtx;
54
55- private String inventoryFileName = "inventory.xml";
56+ private String inventoryFileName;
57 private String gzipedFileName = "tmp.gz";
58 private String prologFileName = "prolog.xml";
59
60- public static OCSFiles getInstance() {
61- if (instance == null)
62- instance = new OCSFiles();
63- return instance;
64- }
65- public static void initInstance(Context ctx) {
66- if (instance == null) {
67- appCtx = ctx;
68- instance = new OCSFiles();
69- }
70+ public OCSFiles(Context ctx) {
71+ appCtx = ctx;
72+ StringBuilder filename = new StringBuilder();
73+
74+ filename.append(Utils.getHostname());
75+ filename.append("-");
76+
77+ SimpleDateFormat dt = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss", Locale.US);
78+ filename.append(dt.format(new Date()));
79+
80+ filename.append(".ocs");
81+
82+ inventoryFileName = filename.toString();
83 }
84
85 public File getGzipedFile(File inFile) {
86
87=== modified file 'src/org/ocsinventory/android/actions/OCSProtocol.java'
88--- src/org/ocsinventory/android/actions/OCSProtocol.java 2013-03-19 20:49:53 +0000
89+++ src/org/ocsinventory/android/actions/OCSProtocol.java 2013-04-24 13:42:26 +0000
90@@ -32,15 +32,21 @@
91 import org.apache.http.protocol.HTTP;
92 import org.apache.http.util.EntityUtils;
93
94+import android.content.Context;
95+
96 public class OCSProtocol {
97 private OCSLog ocslog = OCSLog.getInstance();
98+ private OCSFiles ocsfile;
99
100+ public OCSProtocol(Context context) {
101+ ocsfile = new OCSFiles(context);
102+ }
103
104 public String sendPrologueMessage(Inventory inv) throws OCSProtocolException {
105 ocslog.append("Start Sending Prolog...");
106 String repMsg;
107 String reponse;
108- File localFile = OCSFiles.getInstance().getPrologFileXML();
109+ File localFile = ocsfile.getPrologFileXML();
110 String sURL = OCSSettings.getInstance().getServerUrl();
111 // boolean gz = OCSSettings.getInstance().getGzip();
112
113@@ -59,7 +65,7 @@
114 String retour = null;
115 // boolean gz = OCSSettings.getInstance().getGzip();
116
117- File invFile = OCSFiles.getInstance().getInventoryFileXML(inventory);
118+ File invFile = ocsfile.getInventoryFileXML(inventory);
119 String sURL = OCSSettings.getInstance().getServerUrl();
120
121 String repMsg = sendmethod(invFile, sURL, true);
122@@ -125,7 +131,7 @@
123 File fileToPost;
124 if ( gziped ) {
125 ocslog.append("Start compression");
126- fileToPost=OCSFiles.getInstance().getGzipedFile(pFile);
127+ fileToPost=ocsfile.getGzipedFile(pFile);
128 if ( fileToPost == null )
129 throw new OCSProtocolException("Error during temp file creation");
130 ocslog.append("Compression done");
131
132=== modified file 'src/org/ocsinventory/android/actions/Utils.java'
133--- src/org/ocsinventory/android/actions/Utils.java 2013-03-19 20:49:53 +0000
134+++ src/org/ocsinventory/android/actions/Utils.java 2013-04-24 13:42:26 +0000
135@@ -116,4 +116,11 @@
136 }
137 return "";
138 }
139+
140+ public static String getHostname() {
141+ String hostname = readSysCommand("/system/bin/getprop", "net.hostname").trim();
142+ if(hostname.length() == 0)
143+ hostname = "android";
144+ return hostname;
145+ }
146 }
147
148=== modified file 'src/org/ocsinventory/android/agent/AboutDialog.java'
149--- src/org/ocsinventory/android/agent/AboutDialog.java 2013-02-28 20:44:50 +0000
150+++ src/org/ocsinventory/android/agent/AboutDialog.java 2013-04-24 13:42:26 +0000
151@@ -7,9 +7,10 @@
152 import java.text.SimpleDateFormat;
153 import java.util.Date;
154
155+import org.ocsinventory.android.actions.OCSSettings;
156+
157 import android.app.Dialog;
158 import android.content.Context;
159-import android.content.SharedPreferences;
160 import android.content.pm.PackageManager.NameNotFoundException;
161 import android.graphics.Color;
162 import android.os.Bundle;
163@@ -37,11 +38,10 @@
164 @Override
165 public void onCreate(Bundle savedInstanceState) {
166 setContentView(R.layout.about);
167-
168- SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(mContext);
169
170+ OCSSettings ocssettings = OCSSettings.getInstance(mContext);
171
172- long lastUpdt = sp.getLong("k_lastupdt" , 0L);
173+ long lastUpdt = ocssettings.getLastUpdt();
174
175 StringBuffer sb = new StringBuffer("OCS Inventory NG android Agent \n");
176 sb.append("Version :");
177@@ -55,8 +55,8 @@
178 sb.append("Last upload : ");
179 sb.append(sdf.format(new Date(lastUpdt)));
180 sb.append("\n");
181- if ( sp.getBoolean("k_automode", false)) {
182- int freq = Integer.parseInt(sp.getString("k_freqmaj" , ""));
183+ if ( ocssettings.isAutoMode() ) {
184+ int freq = ocssettings.getFreqMaj();
185 long nextUpdt= lastUpdt+freq*3600000L;
186 sb.append("Next upload : ");
187 sb.append(sdf.format(new Date(nextUpdt)));
188
189=== modified file 'src/org/ocsinventory/android/agent/AsyncOperations.java'
190--- src/org/ocsinventory/android/agent/AsyncOperations.java 2013-03-19 20:49:53 +0000
191+++ src/org/ocsinventory/android/agent/AsyncOperations.java 2013-04-24 13:42:26 +0000
192@@ -49,10 +49,10 @@
193
194 Inventory inventory = Inventory.getInstance(activity);
195
196- OCSProtocol ocsproto = new OCSProtocol();
197+ OCSProtocol ocsproto = new OCSProtocol(ctx);
198
199 if ( ! send ) {
200- String status = OCSFiles.getInstance().copyToExternal(inventory);
201+ String status = new OCSFiles(ctx).copyToExternal(inventory);
202 if ( status.equals("OK"))
203 status=ctx.getString(R.string.state_saved);
204 return status;
205
206=== modified file 'src/org/ocsinventory/android/agent/OCSAgentActivity.java'
207--- src/org/ocsinventory/android/agent/OCSAgentActivity.java 2013-03-19 20:49:53 +0000
208+++ src/org/ocsinventory/android/agent/OCSAgentActivity.java 2013-04-24 13:42:26 +0000
209@@ -51,7 +51,6 @@
210 // Initialisation de la configuration
211 settings=OCSSettings.getInstance(this);
212 settings.logSettings();
213- OCSFiles.initInstance(this.getApplicationContext());
214 // logText.append("Init inventaire\n");
215 // new AsyncJob(this).execute();
216
217
218=== modified file 'src/org/ocsinventory/android/agent/OCSAgentService.java'
219--- src/org/ocsinventory/android/agent/OCSAgentService.java 2013-03-19 20:49:53 +0000
220+++ src/org/ocsinventory/android/agent/OCSAgentService.java 2013-04-24 13:42:26 +0000
221@@ -15,8 +15,6 @@
222 import android.app.Service;
223 import android.content.Context;
224 import android.content.Intent;
225-import android.content.SharedPreferences;
226-import android.content.SharedPreferences.Editor;
227 import android.net.ConnectivityManager;
228 import android.net.NetworkInfo;
229 import android.os.AsyncTask;
230@@ -29,7 +27,13 @@
231 @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
232 public class OCSAgentService extends Service {
233
234+ public final static String FORCE_UPDATE = "force_update";
235+ public final static String SAVE_INVENTORY = "save_inventory";
236 private NotificationManager mNM;
237+ private OCSSettings mOcssetting;
238+ boolean mIsForced = false;
239+ boolean mSaveInventory = false;
240+
241
242 /*
243 * Binder juste pour verifier que le service tourne
244@@ -50,34 +54,31 @@
245 @Override
246 public int onStartCommand(final Intent intent, final int flags,
247 final int startId) {
248-
249- SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
250-
251- OCSSettings ocssetting = OCSSettings.getInstance(getApplicationContext());
252+ mOcssetting = OCSSettings.getInstance(getApplicationContext());
253 OCSLog ocslog = OCSLog.getInstance();
254- ocslog.append("ocsservice wake : " + new Date().toString());
255-
256+ ocslog.append("ocsservice wake : " + new Date().toString());
257+ if( intent.getExtras() != null ) {
258+ mIsForced = intent.getExtras().getBoolean(FORCE_UPDATE);
259+ mSaveInventory = intent.getExtras().getBoolean(SAVE_INVENTORY);
260+ }
261 // Au cas ou l'option a changé depuis le lancement du service
262- if ( ! sp.getBoolean("k_automode", false) )
263+ if ( ! mOcssetting.isAutoMode() && ! mIsForced )
264 return Service.START_NOT_STICKY;
265
266 // notify(R.string.not_start_service);
267
268- int freq = Integer.parseInt(sp.getString("k_freqmaj" , ""));
269- long lastUpdt = sp.getLong("k_lastupdt" , 0L);
270+ int freq = mOcssetting.getFreqMaj();
271+ long lastUpdt = mOcssetting.getLastUpdt();
272 long delta = System.currentTimeMillis()- lastUpdt;
273
274 ocslog.append("now : "+System.currentTimeMillis());
275 ocslog.append("last update : "+lastUpdt);
276 ocslog.append("delta laps : "+delta);
277 ocslog.append("freqmaj : "+freq * 3600000L);
278-
279- if ( delta > freq * 3600000L) {
280- if ( isOnline() ) {
281-
282- AsyncCall task = new AsyncCall(this.getApplicationContext());
283- task.execute();
284- }
285+
286+ if ( (delta > freq * 3600000L && isOnline()) || mIsForced ) {
287+ AsyncCall task = new AsyncCall(this.getApplicationContext());
288+ task.execute();
289 }
290
291 return Service.START_NOT_STICKY;
292@@ -87,8 +88,7 @@
293
294 Inventory inventory = Inventory.getInstance(getApplicationContext());
295 // OCSFiles.getInstance().getInventoryFileXML(inventory);
296- OCSFiles.initInstance(getApplicationContext());
297- OCSProtocol ocsproto = new OCSProtocol();
298+ OCSProtocol ocsproto = new OCSProtocol(getApplicationContext());
299 try {
300 ocsproto.sendPrologueMessage(inventory);
301 ocsproto.sendInventoryMessage(inventory);
302@@ -99,19 +99,26 @@
303 return 0;
304 }
305
306+ private int saveInventory() {
307+ Inventory inventory = Inventory.getInstance(getApplicationContext());
308+ new OCSFiles(getApplicationContext()).copyToExternal(inventory);
309+ return 0;
310+ }
311+
312 private class AsyncCall extends AsyncTask<Void, Void, Void> {
313 int status;
314 Context mContext;
315- SharedPreferences mSP ;
316
317 AsyncCall(Context ctx) {
318 mContext = ctx;
319- mSP= PreferenceManager.getDefaultSharedPreferences(ctx);
320 }
321
322 @Override
323 protected Void doInBackground(Void... params) {
324 status = sendInventory();
325+ if(mSaveInventory) {
326+ saveInventory();
327+ }
328
329 return null;
330 }
331@@ -119,12 +126,10 @@
332 @Override
333 protected void onPostExecute(Void result) {
334 if ( status == 0)
335- {
336- notify(R.string.nty_inventory_sent);
337- Editor edt = mSP.edit();
338- edt.putLong("k_lastupdt", System.currentTimeMillis());
339- edt.commit();
340- }
341+ {
342+ notify(R.string.nty_inventory_sent);
343+ mOcssetting.setLastUpdt(System.currentTimeMillis());
344+ }
345 }
346
347 @Override
348
349=== modified file 'src/org/ocsinventory/android/agent/OCSEventReceiver.java'
350--- src/org/ocsinventory/android/agent/OCSEventReceiver.java 2013-02-13 19:25:00 +0000
351+++ src/org/ocsinventory/android/agent/OCSEventReceiver.java 2013-04-24 13:42:26 +0000
352@@ -12,6 +12,9 @@
353 public void onReceive(final Context ctx, final Intent intent) {
354 Log.d(LOGTAG, "Called");
355 Intent eventService = new Intent(ctx, OCSAgentService.class);
356+ eventService.putExtra(OCSAgentService.FORCE_UPDATE, true);
357+ boolean saveInventory = intent.getBooleanExtra(OCSAgentService.SAVE_INVENTORY, false);
358+ eventService.putExtra(OCSAgentService.SAVE_INVENTORY, saveInventory);
359 ctx.startService(eventService);
360 Log.d(LOGTAG, "After start service");
361
362
363=== modified file 'src/org/ocsinventory/android/sections/OCSNetworks.java'
364--- src/org/ocsinventory/android/sections/OCSNetworks.java 2013-03-19 20:49:53 +0000
365+++ src/org/ocsinventory/android/sections/OCSNetworks.java 2013-04-24 13:42:26 +0000
366@@ -31,14 +31,9 @@
367 this.networks= new ArrayList<OCSNetwork>();
368
369 WifiManager wifii= (WifiManager) ctx.getSystemService(Context.WIFI_SERVICE);
370- boolean prevWifiState=false;
371 if ( wifii != null ) {
372- if ( wifii.getWifiState() == 4 )
373+ if ( wifii.getWifiState() == WifiManager.WIFI_STATE_UNKNOWN )
374 return;
375- prevWifiState = wifii.isWifiEnabled();
376- if ( ! wifii.isWifiEnabled() ) {
377- wifii.setWifiEnabled(true);
378- }
379 if ( wifii.isWifiEnabled() ) {
380 DhcpInfo d=wifii.getDhcpInfo();
381
382@@ -69,7 +64,8 @@
383 }
384 }
385
386- // Parcours des intefaces reseau
387+ // Check non wifi address, this method will return less informations, but at least we
388+ // have all the ip
389 Enumeration<NetworkInterface> listeNI;
390 try {
391 listeNI = NetworkInterface.getNetworkInterfaces();
392@@ -87,8 +83,7 @@
393 // android.util.Log.d("OCSNET HAdr", ni.getHardwareAddress());
394 while (listeIPAdr.hasMoreElements()) {
395 InetAddress ipAdr = (InetAddress) listeIPAdr.nextElement();
396-
397- if ( ! ipAdr.isLoopbackAddress() ) {
398+ if ( ! ipAdr.isLoopbackAddress() && ! ipAdr.isLinkLocalAddress() ) {
399 OCSNetwork netw = new OCSNetwork(name);
400 String ipadr = ipAdr.getHostAddress();
401 netw.setIpAdress(ipadr);
402@@ -97,13 +92,20 @@
403 netw.setMacaddr(Utils.bytesToHex(ni.getHardwareAddress()));
404 } catch (SocketException se) {}
405 }
406- networks.add(netw);
407+ // this ip may be already presents as a wifi address
408+ boolean isWifi = false;
409+ for(OCSNetwork tmp : networks) {
410+ if ( tmp.ipAdress.equals(netw.ipAdress) ) {
411+ isWifi = true;
412+ break;
413+ }
414+ }
415+ if (isWifi == false) {
416+ networks.add(netw);
417+ }
418 }
419 }
420 }
421- if ( wifii.isWifiEnabled() && ! prevWifiState)
422- wifii.setWifiEnabled(false);
423-
424 }
425
426 /*
427@@ -153,4 +155,4 @@
428 public String getSectionTag() {
429 return sectionTag;
430 }
431-}
432\ No newline at end of file
433+}

Subscribers

People subscribed via source and target branches