[1725] | 1 | package de.ugoe.cs.autoquest.androidmonitor;
|
---|
| 2 |
|
---|
| 3 | import java.io.File;
|
---|
| 4 | import java.io.IOException;
|
---|
| 5 | import java.io.OutputStreamWriter;
|
---|
| 6 | import java.io.StringWriter;
|
---|
| 7 |
|
---|
| 8 | import org.xmlpull.v1.XmlSerializer;
|
---|
| 9 |
|
---|
| 10 | import android.app.Activity;
|
---|
| 11 | import android.content.Context;
|
---|
| 12 | import android.util.Log;
|
---|
| 13 | import android.util.Xml;
|
---|
| 14 |
|
---|
| 15 | public class AndroidmonitorLogFile extends Activity {
|
---|
| 16 | // extends activity to use the file handling methods of an activity
|
---|
| 17 | private String name;
|
---|
| 18 |
|
---|
| 19 |
|
---|
| 20 | public AndroidmonitorLogFile(String appName, File dir) {
|
---|
| 21 | this.name = appName + "LogFile.xml";
|
---|
| 22 |
|
---|
| 23 | try {
|
---|
| 24 | File file = new File(dir, this.name);
|
---|
| 25 | if (!file.exists()) {
|
---|
| 26 | Log.d("file", this.name + " - is not available");
|
---|
| 27 |
|
---|
| 28 | //create file
|
---|
| 29 | try {
|
---|
| 30 | OutputStreamWriter outputStreamWriter = new OutputStreamWriter(
|
---|
| 31 | openFileOutput(this.name, Context.MODE_PRIVATE));
|
---|
| 32 | outputStreamWriter.write(getDeviceInformation() + getAppInformation());
|
---|
| 33 | outputStreamWriter.close();
|
---|
| 34 | } catch (IOException e) {
|
---|
| 35 | e.printStackTrace();
|
---|
| 36 | Log.e("outputStreamWriter", e.getMessage());
|
---|
| 37 | }
|
---|
| 38 |
|
---|
| 39 |
|
---|
| 40 | }
|
---|
| 41 | } catch (Exception e) {
|
---|
| 42 | e.printStackTrace();
|
---|
| 43 | Log.e("file", e.getMessage());
|
---|
| 44 | }
|
---|
| 45 |
|
---|
| 46 | }
|
---|
| 47 |
|
---|
| 48 | /**
|
---|
| 49 | * get file name
|
---|
| 50 | *
|
---|
| 51 | * @return
|
---|
| 52 | */
|
---|
| 53 | public String getName() {
|
---|
| 54 | return this.name;
|
---|
| 55 | }
|
---|
| 56 |
|
---|
| 57 | private String getAppInformation() {
|
---|
| 58 | // app Name ...
|
---|
| 59 | return "";
|
---|
| 60 | }
|
---|
| 61 |
|
---|
| 62 | private String getDeviceInformation(){
|
---|
| 63 | String deviceInformation = null;
|
---|
| 64 | try {
|
---|
| 65 | XmlSerializer xmlSerializer = Xml.newSerializer();
|
---|
| 66 | StringWriter stringWriter = new StringWriter();
|
---|
| 67 |
|
---|
| 68 | xmlSerializer.setOutput(stringWriter);
|
---|
| 69 | xmlSerializer.startDocument("UTF-8", true);
|
---|
| 70 | xmlSerializer.startTag("", "device");
|
---|
| 71 | xmlSerializer.startTag("", "param");
|
---|
| 72 | xmlSerializer.attribute("", "value", "" + android.os.Build.VERSION.SDK_INT);
|
---|
| 73 | xmlSerializer.attribute("", "name", "sdk_version");
|
---|
| 74 | xmlSerializer.endTag("", "param");
|
---|
| 75 |
|
---|
| 76 | xmlSerializer.startTag("", "param");
|
---|
| 77 | xmlSerializer.attribute("", "value", android.os.Build.DEVICE);
|
---|
| 78 | xmlSerializer.attribute("", "name", "device");
|
---|
| 79 | xmlSerializer.endTag("", "param");
|
---|
| 80 |
|
---|
| 81 | xmlSerializer.startTag("", "param");
|
---|
| 82 | xmlSerializer.attribute("", "value", android.os.Build.MANUFACTURER);
|
---|
| 83 | xmlSerializer.attribute("", "name", "manufacturer");
|
---|
| 84 | xmlSerializer.endTag("", "param");
|
---|
| 85 |
|
---|
| 86 | xmlSerializer.startTag("", "param");
|
---|
| 87 | xmlSerializer.attribute("", "value", android.os.Build.MODEL);
|
---|
| 88 | xmlSerializer.attribute("", "name", "model");
|
---|
| 89 | xmlSerializer.endTag("", "param");
|
---|
| 90 |
|
---|
| 91 | //tbd get resolution ...
|
---|
| 92 |
|
---|
| 93 |
|
---|
| 94 | xmlSerializer.endTag("", "device");
|
---|
| 95 | deviceInformation = stringWriter.toString();
|
---|
| 96 |
|
---|
| 97 | } catch (Exception e) {
|
---|
| 98 | e.printStackTrace();
|
---|
| 99 | Log.e("xmlSerializer", e.getMessage());
|
---|
| 100 | }
|
---|
| 101 |
|
---|
| 102 | return deviceInformation;
|
---|
| 103 | }
|
---|
| 104 |
|
---|
| 105 | public void addComponent(){
|
---|
| 106 | //add component to file
|
---|
| 107 | }
|
---|
| 108 |
|
---|
| 109 | public void addEvent(){
|
---|
| 110 | //add event to file
|
---|
| 111 | }
|
---|
| 112 |
|
---|
| 113 | }
|
---|