diff --git a/modules/samples/android_sense/sketch/android_sense.apk b/modules/samples/android_sense/Agent/sketch/android_sense.apk similarity index 100% rename from modules/samples/android_sense/sketch/android_sense.apk rename to modules/samples/android_sense/Agent/sketch/android_sense.apk diff --git a/modules/samples/android_sense/sketch/sketch.properties b/modules/samples/android_sense/Agent/sketch/sketch.properties similarity index 100% rename from modules/samples/android_sense/sketch/sketch.properties rename to modules/samples/android_sense/Agent/sketch/sketch.properties diff --git a/modules/samples/android_sense/Agent/wso2_sense_agent/.svn/entries b/modules/samples/android_sense/Agent/wso2_sense_agent/.svn/entries new file mode 100644 index 00000000..48082f72 --- /dev/null +++ b/modules/samples/android_sense/Agent/wso2_sense_agent/.svn/entries @@ -0,0 +1 @@ +12 diff --git a/modules/samples/android_sense/Agent/wso2_sense_agent/.svn/format b/modules/samples/android_sense/Agent/wso2_sense_agent/.svn/format new file mode 100644 index 00000000..48082f72 --- /dev/null +++ b/modules/samples/android_sense/Agent/wso2_sense_agent/.svn/format @@ -0,0 +1 @@ +12 diff --git a/modules/samples/android_sense/Agent/wso2_sense_agent/.svn/pristine/14/14f0a5921a59d35501854bb5323970db989cb868.svn-base b/modules/samples/android_sense/Agent/wso2_sense_agent/.svn/pristine/14/14f0a5921a59d35501854bb5323970db989cb868.svn-base new file mode 100644 index 00000000..7c9a2c2a --- /dev/null +++ b/modules/samples/android_sense/Agent/wso2_sense_agent/.svn/pristine/14/14f0a5921a59d35501854bb5323970db989cb868.svn-base @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + */ +package org.wso2.carbon.iot.android.sense.events.input.battery; + +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; + +import org.wso2.carbon.iot.android.sense.util.DataMap; + +import java.util.Vector; + +/** + * Whenever battery level changes This receiver will be triggered + */ +public class BatteryDataReceiver extends BroadcastReceiver { + + private Vector batteryDatas = new Vector(); + + @Override + public void onReceive(Context context, Intent intent) { + + + BatteryData bt = new BatteryData(intent); + batteryDatas.add(bt); + + for (BatteryData data : batteryDatas) { + DataMap.getBatteryDataMap().add(data); + } + } + +} diff --git a/modules/samples/android_sense/Agent/wso2_sense_agent/.svn/pristine/18/18a55d5c108b2893416f14b17eadfee4c8415ddf.svn-base b/modules/samples/android_sense/Agent/wso2_sense_agent/.svn/pristine/18/18a55d5c108b2893416f14b17eadfee4c8415ddf.svn-base new file mode 100644 index 00000000..2db0419d --- /dev/null +++ b/modules/samples/android_sense/Agent/wso2_sense_agent/.svn/pristine/18/18a55d5c108b2893416f14b17eadfee4c8415ddf.svn-base @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + */ +package org.wso2.carbon.iot.android.sense.util; + + +import android.content.ContentResolver; +import android.content.Context; +import android.telephony.TelephonyManager; + +import java.util.UUID; + +public class SenseUtils { + + + //http://stackoverflow.com/questions/2785485/is-there-a-unique-android-device-id + public static String generateDeviceId(Context baseContext, ContentResolver contentResolver) { + + final TelephonyManager tm = (TelephonyManager) baseContext.getSystemService(Context.TELEPHONY_SERVICE); + + final String tmDevice, tmSerial, androidId; + tmDevice = "" + tm.getDeviceId(); + tmSerial = "" + tm.getSimSerialNumber(); + androidId = "" + android.provider.Settings.Secure.getString(contentResolver, android.provider.Settings.Secure.ANDROID_ID); + + UUID deviceUuid = new UUID(androidId.hashCode(), ((long) tmDevice.hashCode() << 32) | tmSerial.hashCode()); + return deviceUuid.toString(); + + } +} diff --git a/modules/samples/android_sense/Agent/wso2_sense_agent/.svn/pristine/1a/1a5f9f01c1b6f2ad0cf262ac4a3faee14a7834da.svn-base b/modules/samples/android_sense/Agent/wso2_sense_agent/.svn/pristine/1a/1a5f9f01c1b6f2ad0cf262ac4a3faee14a7834da.svn-base new file mode 100644 index 00000000..041b6c21 --- /dev/null +++ b/modules/samples/android_sense/Agent/wso2_sense_agent/.svn/pristine/1a/1a5f9f01c1b6f2ad0cf262ac4a3faee14a7834da.svn-base @@ -0,0 +1,183 @@ +/* + * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + */ +package org.wso2.carbon.iot.android.sense.events.input.Location; + +import android.content.Context; +import android.location.Location; +import android.location.LocationListener; +import android.location.LocationManager; +import android.os.Bundle; +import android.util.Log; + +import org.wso2.carbon.iot.android.sense.events.input.DataReader; +import org.wso2.carbon.iot.android.sense.util.DataMap; + +import java.util.Vector; +import java.util.concurrent.TimeUnit; + +public class LocationDataReader extends DataReader implements LocationListener { + protected LocationManager locationManager; + private Context mContext; + private boolean canGetLocation = false; + + Location location; // location + double latitude; // latitude + double longitude; // longitude + + private Vector locationDatas = new Vector(); + // The minimum distance to change Updates in meters + // private static final long MIN_DISTANCE_CHANGE_FOR_UPDATES = 10; // 10 meters + + // The minimum time between updates in milliseconds + //private static final long MIN_TIME_BW_UPDATES = 1000 * 60 * 1; // 1 minute + + public LocationDataReader(Context context) { + mContext = context; + getLocation(); + } + + public Location getLocation() { + try { + locationManager = (LocationManager) mContext.getSystemService(mContext.LOCATION_SERVICE); + + // getting GPS status + boolean isGPSEnabled = locationManager + .isProviderEnabled(LocationManager.GPS_PROVIDER); + + // getting network status + boolean isNetworkEnabled = locationManager + .isProviderEnabled(LocationManager.NETWORK_PROVIDER); + + if (!isGPSEnabled && !isNetworkEnabled) { + // no network provider is enabled + } else { + this.canGetLocation = true; + // First get location from Network Provider + if (isNetworkEnabled) { + locationManager.requestLocationUpdates( + LocationManager.NETWORK_PROVIDER, 0, 0, this); + // MIN_TIME_BW_UPDATES, + // MIN_DISTANCE_CHANGE_FOR_UPDATES, this); + + if (locationManager != null) { + location = locationManager + .getLastKnownLocation(LocationManager.NETWORK_PROVIDER); + if (location != null) { + latitude = location.getLatitude(); + longitude = location.getLongitude(); + } + } + } + // if GPS Enabled get lat/long using GPS Services + if (isGPSEnabled) { + if (location == null) { + locationManager.requestLocationUpdates( + LocationManager.GPS_PROVIDER, 0, 0, this); + //MIN_TIME_BW_UPDATES, + //MIN_DISTANCE_CHANGE_FOR_UPDATES, this); + + Log.d(this.getClass().getName(), "GPS Enabled"); + if (locationManager != null) { + location = locationManager + .getLastKnownLocation(LocationManager.GPS_PROVIDER); + if (location != null) { + latitude = location.getLatitude(); + longitude = location.getLongitude(); + } + } + } + } + } + + } catch (Exception e) { + Log.e("Location Sense", "Error O"); + } + + return location; + } + + public boolean canGetLocation() { + return this.canGetLocation; + } + + public void stopUsingGPS() { + if (locationManager != null) { + locationManager.removeUpdates(LocationDataReader.this); + } + } + + public double getLatitude() { + if (location != null) { + latitude = location.getLatitude(); + } + + // return latitude + return latitude; + } + + /** + * Function to get longitude + */ + public double getLongitude() { + if (location != null) { + longitude = location.getLongitude(); + } + + // return longitude + return longitude; + } + + @Override + public void onLocationChanged(Location arg0) { + // TODO Auto-generated method stub + + } + + @Override + public void onProviderDisabled(String arg0) { + // TODO Auto-generated method stub + + } + + @Override + public void onProviderEnabled(String arg0) { + // TODO Auto-generated method stub + + } + + @Override + public void onStatusChanged(String arg0, int arg1, Bundle arg2) { + // TODO Auto-generated method stub + + } + + @Override + public void run() { + Log.d(this.getClass().getSimpleName(), "running -Location"); + try { + TimeUnit.MILLISECONDS.sleep(10000); + locationDatas.add(new LocationData(getLatitude(), getLongitude())); + for (LocationData data : locationDatas) { + DataMap.getLocationDataMap().add(data); + } + + } catch (InterruptedException e) { + Log.i("Location Data", " Location Data Retrieval Failed"); + } + + + } + + +} diff --git a/modules/samples/android_sense/Agent/wso2_sense_agent/.svn/pristine/1d/1d4ff5f74491507580bc2281551125551e28e8de.svn-base b/modules/samples/android_sense/Agent/wso2_sense_agent/.svn/pristine/1d/1d4ff5f74491507580bc2281551125551e28e8de.svn-base new file mode 100644 index 00000000..e7b4def4 --- /dev/null +++ b/modules/samples/android_sense/Agent/wso2_sense_agent/.svn/pristine/1d/1d4ff5f74491507580bc2281551125551e28e8de.svn-base @@ -0,0 +1 @@ +include ':app' diff --git a/modules/samples/android_sense/Agent/wso2_sense_agent/.svn/pristine/38/38ce98bb6ed4ce4824cbadef27c526dedcb1cedb.svn-base b/modules/samples/android_sense/Agent/wso2_sense_agent/.svn/pristine/38/38ce98bb6ed4ce4824cbadef27c526dedcb1cedb.svn-base new file mode 100644 index 00000000..c85c9f11 --- /dev/null +++ b/modules/samples/android_sense/Agent/wso2_sense_agent/.svn/pristine/38/38ce98bb6ed4ce4824cbadef27c526dedcb1cedb.svn-base @@ -0,0 +1,96 @@ +package org.wso2.carbon.iot.android.sense.events.input.Sensor; + +import android.content.Context; +import android.hardware.Sensor; +import android.hardware.SensorEvent; +import android.hardware.SensorEventListener; +import android.hardware.SensorManager; +import android.util.Log; + +import org.wso2.carbon.iot.android.sense.util.DataMap; +import org.wso2.carbon.iot.android.sense.events.input.DataReader; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Vector; +import java.util.concurrent.TimeUnit; + + +public class SensorDataReader extends DataReader implements SensorEventListener { + private SensorManager mSensorManager; + private List mSensors; + private Map senseDataStruct = new HashMap(); + private Vector sensorVector = new Vector(); + Context ctx; + + + + public SensorDataReader(Context context) { + ctx=context; + mSensorManager = (SensorManager) ctx.getSystemService(Context.SENSOR_SERVICE); + mSensors= mSensorManager.getSensorList(Sensor.TYPE_ALL); + for (Sensor sensor : mSensors) + { + mSensorManager.registerListener((SensorEventListener) this, sensor, SensorManager.SENSOR_DELAY_FASTEST); + } + } + + private void collectSensorData(){ + + Log.d(this.getClass().getName(), "Sensor Type"); + for (Sensor sensor : mSensors) + { + try{ + if (senseDataStruct.containsKey(sensor.getName())){ + + SensorData sensorInfo=senseDataStruct.get(sensor.getName()); + sensorVector.add(sensorInfo); + Log.d(this.getClass().getName(),"Sensor Name "+sensor.getName()+", Type "+ sensor.getType() + " " + + ", sensorValue :" + sensorInfo.getSensorValues()); + } + }catch(Throwable e){ + Log.d(this.getClass().getName(),"error on sensors"); + } + + } + mSensorManager.unregisterListener(this); + + + } + + public Vector getSensorData(){ + try { + TimeUnit.MILLISECONDS.sleep(10000); + } catch (InterruptedException e) { + Log.e(SensorDataReader.class.getName(),e.getMessage()); + } + collectSensorData(); + return sensorVector; + + + + + } + + @Override + public void onAccuracyChanged(Sensor sensor, int accuracy) { + } + + @Override + public void onSensorChanged(SensorEvent event) { + senseDataStruct.put(event.sensor.getName(), new SensorData(event)); + } + + @Override + public void run() { + Log.d(this.getClass().getName(),"running -sensor"); + Vector sensorDatas=getSensorData(); + for( SensorData data : sensorDatas){ + DataMap.getSensorDataMap().add(data); + } + + } + + +} diff --git a/modules/samples/android_sense/Agent/wso2_sense_agent/.svn/pristine/3c/3c592ea006c942d118616634e2d3903e11a024ce.svn-base b/modules/samples/android_sense/Agent/wso2_sense_agent/.svn/pristine/3c/3c592ea006c942d118616634e2d3903e11a024ce.svn-base new file mode 100644 index 00000000..be4c3e07 --- /dev/null +++ b/modules/samples/android_sense/Agent/wso2_sense_agent/.svn/pristine/3c/3c592ea006c942d118616634e2d3903e11a024ce.svn-base @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + */ +package org.wso2.carbon.iot.android.sense.service; + +import android.app.Service; +import android.content.Context; +import android.content.Intent; +import android.content.IntentFilter; +import android.os.IBinder; + +import org.wso2.carbon.iot.android.sense.events.input.SenseDataCollector; +import org.wso2.carbon.iot.android.sense.events.input.battery.BatteryDataReceiver; +import org.wso2.carbon.iot.android.sense.util.LocalRegister; +import org.wso2.carbon.iot.android.sense.util.SenseWakeLock; + + +public class SenseService extends Service { + + //private final IBinder senseBinder = new SenseBinder(); + public static Context context; + + @Override + public void onCreate() { + super.onCreate(); + SenseWakeLock.acquireWakeLock(this); + } + + @Override + public IBinder onBind(Intent arg0) { + //return senseBinder; + return null; + } + + @Override + public int onStartCommand(Intent intent, int flags, int startId) { + context = this; + if (!LocalRegister.isExist(context)) return Service.START_NOT_STICKY; + + SenseDataCollector Sensor = new SenseDataCollector(this, SenseDataCollector.DataType.SENSOR); + SenseDataCollector Location = new SenseDataCollector(this, SenseDataCollector.DataType.LOCATION); + registerReceiver(new BatteryDataReceiver(), new IntentFilter(Intent.ACTION_BATTERY_CHANGED)); + //service will not be stopped until we manually stop the service + return Service.START_NOT_STICKY; + } + + + @Override + public void onDestroy() { + SenseWakeLock.releaseCPUWakeLock(); + super.onDestroy(); + } +} \ No newline at end of file diff --git a/modules/samples/android_sense/Agent/wso2_sense_agent/.svn/pristine/41/4189d7def2df99e05852ae26993d9ad9c24b26a8.svn-base b/modules/samples/android_sense/Agent/wso2_sense_agent/.svn/pristine/41/4189d7def2df99e05852ae26993d9ad9c24b26a8.svn-base new file mode 100644 index 00000000..1d4ed478 --- /dev/null +++ b/modules/samples/android_sense/Agent/wso2_sense_agent/.svn/pristine/41/4189d7def2df99e05852ae26993d9ad9c24b26a8.svn-base @@ -0,0 +1,227 @@ +/* + * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + */ +package org.wso2.carbon.iot.android.sense.util; + + +import android.content.Context; +import android.os.AsyncTask; +import android.util.Log; + +import org.wso2.carbon.iot.android.sense.constants.SenseConstants; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.OutputStream; +import java.net.HttpURLConnection; +import java.net.MalformedURLException; +import java.net.URL; +import java.security.KeyManagementException; +import java.security.KeyStore; +import java.security.KeyStoreException; +import java.security.NoSuchAlgorithmException; +import java.security.cert.CertificateException; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.net.ssl.HostnameVerifier; +import javax.net.ssl.HttpsURLConnection; +import javax.net.ssl.SSLContext; +import javax.net.ssl.SSLSession; +import javax.net.ssl.TrustManagerFactory; + +import agent.sense.android.iot.carbon.wso2.org.wso2_senseagent.R; + +public class SenseClientAsyncExecutor extends AsyncTask> { + + private static List cookies; + private Context context; + private final static String TAG = "SenseService Client"; + + public SenseClientAsyncExecutor(Context context) { + this.context = context; + + } + + private HttpsURLConnection getTrustedConnection(HttpsURLConnection conn) { + HttpsURLConnection urlConnection = conn; + try { + KeyStore localTrustStore; + + localTrustStore = KeyStore.getInstance("BKS"); + + InputStream in = context.getResources().openRawResource( + R.raw.client_truststore); + + localTrustStore.load(in, SenseConstants.TRUSTSTORE_PASSWORD.toCharArray()); + + TrustManagerFactory tmf; + tmf = TrustManagerFactory.getInstance(TrustManagerFactory + .getDefaultAlgorithm()); + + tmf.init(localTrustStore); + + SSLContext sslCtx; + + sslCtx = SSLContext.getInstance("TLS"); + + sslCtx.init(null, tmf.getTrustManagers(), null); + + urlConnection.setSSLSocketFactory(sslCtx.getSocketFactory()); + return urlConnection; + } catch (KeyManagementException | NoSuchAlgorithmException | CertificateException | IOException | KeyStoreException e) { + + Log.e(SenseClientAsyncExecutor.class.getName(), "Invalid Certifcate"); + return null; + } + + } + + @Override + protected Map doInBackground(String... parameters) { + if (android.os.Debug.isDebuggerConnected()) + android.os.Debug.waitForDebugger(); + String response = null; + Map response_params = new HashMap(); + + + String endpoint = parameters[0]; + String body = parameters[1]; + String option = parameters[2]; + String jsonBody = parameters[3]; + + if(jsonBody!=null && !jsonBody.isEmpty()){ + body = jsonBody; + } + + URL url; + try { + url = new URL(endpoint); + } catch (MalformedURLException e) { + throw new IllegalArgumentException("invalid url: " + endpoint); + } + + Log.v(TAG, "post'" + body + "'to" + url); + + + HttpURLConnection conn = null; + HttpsURLConnection sConn = null; + try { + + if (url.getProtocol().toLowerCase().equals("https")) { + + sConn = (HttpsURLConnection) url.openConnection(); + sConn = getTrustedConnection(sConn); + sConn.setHostnameVerifier(SERVER_HOST); + conn = sConn; + + } else { + conn = (HttpURLConnection) url.openConnection(); + } + + if (cookies != null) { + for (String cookie : cookies) { + conn.addRequestProperty("Cookie", cookie.split(";", 2)[0]); + } + + } + if (conn == null) { + return null; + + } + + byte[] bytes = body.getBytes(); + conn.setDoOutput(true); + conn.setUseCaches(false); + conn.setFixedLengthStreamingMode(bytes.length); + conn.setRequestMethod(option); + if(jsonBody!=null && !jsonBody.isEmpty()){ + conn.setRequestProperty("Content-Type", "application/json"); + }else { + conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8"); + } + conn.setRequestProperty("Accept", "*/*"); + conn.setRequestProperty("Connection", "close"); + + // post the request + int status = 0; + + if (!option.equals("DELETE")) { + OutputStream out = conn.getOutputStream(); + out.write(bytes); + out.close(); + // handle the response + status = conn.getResponseCode(); + response_params.put("status", String.valueOf(status)); + Log.v("Response Status", status + ""); + + List receivedCookie = conn.getHeaderFields().get("Set-Cookie"); + if(receivedCookie!=null){ + cookies=receivedCookie; + + } + + try { + InputStream inStream = conn.getInputStream(); + BufferedReader reader = new BufferedReader(new InputStreamReader(inStream)); + StringBuilder builder = new StringBuilder(); + String line = null; + try { + while ((line = reader.readLine()) != null) { + builder.append(line); + builder.append("\n"); // append a new line + } + } catch (IOException e) { + } finally { + try { + inStream.close(); + } catch (IOException e) { + } + } + // System.out.println(builder.toString()); + response = builder.toString(); + response_params.put("response", response); + Log.v("Response Message", response); + } catch (IOException ex) { + + + } + + } else { + status = Integer.valueOf(SenseConstants.Request.REQUEST_SUCCESSFUL); + } + + + } catch (Exception e) { + return null; + } finally { + if (conn != null) { + conn.disconnect(); + } + } + return response_params; + } + + public HostnameVerifier SERVER_HOST = new HostnameVerifier() { + //String allowHost = LocalRegister.getServerHost(context); + @Override + public boolean verify(String hostname, SSLSession session) { + HostnameVerifier hv = HttpsURLConnection.getDefaultHostnameVerifier(); + return true; + //return hv.verify(allowHost, session); + } + }; +} diff --git a/modules/samples/android_sense/Agent/wso2_sense_agent/.svn/pristine/41/41dc154e4ffff91ab2b070a4ce0ad15e50571bea.svn-base b/modules/samples/android_sense/Agent/wso2_sense_agent/.svn/pristine/41/41dc154e4ffff91ab2b070a4ce0ad15e50571bea.svn-base new file mode 100644 index 00000000..324e72cd Binary files /dev/null and b/modules/samples/android_sense/Agent/wso2_sense_agent/.svn/pristine/41/41dc154e4ffff91ab2b070a4ce0ad15e50571bea.svn-base differ diff --git a/modules/samples/android_sense/Agent/wso2_sense_agent/.svn/pristine/42/427f266e73eb3669d933f11afd0f3c9eed690326.svn-base b/modules/samples/android_sense/Agent/wso2_sense_agent/.svn/pristine/42/427f266e73eb3669d933f11afd0f3c9eed690326.svn-base new file mode 100644 index 00000000..7d917bf6 --- /dev/null +++ b/modules/samples/android_sense/Agent/wso2_sense_agent/.svn/pristine/42/427f266e73eb3669d933f11afd0f3c9eed690326.svn-base @@ -0,0 +1,76 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/modules/samples/android_sense/Agent/wso2_sense_agent/.svn/pristine/42/42bc867ed3c2a938c2ba7d037ae3e43440e7fec5.svn-base b/modules/samples/android_sense/Agent/wso2_sense_agent/.svn/pristine/42/42bc867ed3c2a938c2ba7d037ae3e43440e7fec5.svn-base new file mode 100644 index 00000000..1d3591c8 --- /dev/null +++ b/modules/samples/android_sense/Agent/wso2_sense_agent/.svn/pristine/42/42bc867ed3c2a938c2ba7d037ae3e43440e7fec5.svn-base @@ -0,0 +1,18 @@ +# Project-wide Gradle settings. + +# IDE (e.g. Android Studio) users: +# Gradle settings configured through the IDE *will override* +# any settings specified in this file. + +# For more details on how to configure your build environment visit +# http://www.gradle.org/docs/current/userguide/build_environment.html + +# Specifies the JVM arguments used for the daemon process. +# The setting is particularly useful for tweaking memory settings. +# Default value: -Xmx10248m -XX:MaxPermSize=256m +# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 + +# When configured, Gradle will run in incubating parallel mode. +# This option should only be used with decoupled projects. More details, visit +# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects +# org.gradle.parallel=true \ No newline at end of file diff --git a/modules/samples/android_sense/Agent/wso2_sense_agent/.svn/pristine/44/446223e9865a320cb76bdf19073a68c3479a4029.svn-base b/modules/samples/android_sense/Agent/wso2_sense_agent/.svn/pristine/44/446223e9865a320cb76bdf19073a68c3479a4029.svn-base new file mode 100644 index 00000000..91a7e269 --- /dev/null +++ b/modules/samples/android_sense/Agent/wso2_sense_agent/.svn/pristine/44/446223e9865a320cb76bdf19073a68c3479a4029.svn-base @@ -0,0 +1,164 @@ +#!/usr/bin/env bash + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS="" + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn ( ) { + echo "$*" +} + +die ( ) { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; +esac + +# For Cygwin, ensure paths are in UNIX format before anything is touched. +if $cygwin ; then + [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` +fi + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >&- +APP_HOME="`pwd -P`" +cd "$SAVED" >&- + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin, switch paths to Windows format before running java +if $cygwin ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=$((i+1)) + done + case $i in + (0) set -- ;; + (1) set -- "$args0" ;; + (2) set -- "$args0" "$args1" ;; + (3) set -- "$args0" "$args1" "$args2" ;; + (4) set -- "$args0" "$args1" "$args2" "$args3" ;; + (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules +function splitJvmOpts() { + JVM_OPTS=("$@") +} +eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS +JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" + +exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" diff --git a/modules/samples/android_sense/Agent/wso2_sense_agent/.svn/pristine/4e/4e1904afba59d31e5cd6133f6a4c360fa9a5913f.svn-base b/modules/samples/android_sense/Agent/wso2_sense_agent/.svn/pristine/4e/4e1904afba59d31e5cd6133f6a4c360fa9a5913f.svn-base new file mode 100644 index 00000000..47c82246 --- /dev/null +++ b/modules/samples/android_sense/Agent/wso2_sense_agent/.svn/pristine/4e/4e1904afba59d31e5cd6133f6a4c360fa9a5913f.svn-base @@ -0,0 +1,5 @@ + + + 16dp + 16dp + diff --git a/modules/samples/android_sense/Agent/wso2_sense_agent/.svn/pristine/4e/4e7023247eba857b18a09f72c680169b11aff002.svn-base b/modules/samples/android_sense/Agent/wso2_sense_agent/.svn/pristine/4e/4e7023247eba857b18a09f72c680169b11aff002.svn-base new file mode 100644 index 00000000..63fc8164 --- /dev/null +++ b/modules/samples/android_sense/Agent/wso2_sense_agent/.svn/pristine/4e/4e7023247eba857b18a09f72c680169b11aff002.svn-base @@ -0,0 +1,6 @@ + + + 64dp + diff --git a/modules/samples/android_sense/Agent/wso2_sense_agent/.svn/pristine/50/508bfbb0b5018dac89e6dab63218f73d2e7f8743.svn-base b/modules/samples/android_sense/Agent/wso2_sense_agent/.svn/pristine/50/508bfbb0b5018dac89e6dab63218f73d2e7f8743.svn-base new file mode 100644 index 00000000..b6ef4241 --- /dev/null +++ b/modules/samples/android_sense/Agent/wso2_sense_agent/.svn/pristine/50/508bfbb0b5018dac89e6dab63218f73d2e7f8743.svn-base @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + */ +package org.wso2.carbon.iot.android.sense.util; + + +import android.content.Context; +import android.os.PowerManager; +import android.util.Log; + +public class SenseWakeLock { + + private static PowerManager.WakeLock wakeLock; + + public static void acquireWakeLock(Context context) { + + Log.i(SenseWakeLock.class.getSimpleName(), "Acquire CPU wakeup lock start"); + + if (wakeLock == null) { + + Log.i(SenseWakeLock.class.getSimpleName(),"CPU wakeUp log is not null"); + + PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); + wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,"SenseWakeLock"); + } + + wakeLock.acquire(); + + } + + public static void releaseCPUWakeLock() { + + if (wakeLock != null) { + + + wakeLock.release(); + wakeLock = null; + } + + Log.i(SenseWakeLock.class.getSimpleName(),"Release wakeup"); + + } + +} diff --git a/modules/samples/android_sense/Agent/wso2_sense_agent/.svn/pristine/54/549f18ba25d7fc7d2c5f4e85c9d70b1ab34f8068.svn-base b/modules/samples/android_sense/Agent/wso2_sense_agent/.svn/pristine/54/549f18ba25d7fc7d2c5f4e85c9d70b1ab34f8068.svn-base new file mode 100644 index 00000000..3b72299d Binary files /dev/null and b/modules/samples/android_sense/Agent/wso2_sense_agent/.svn/pristine/54/549f18ba25d7fc7d2c5f4e85c9d70b1ab34f8068.svn-base differ diff --git a/modules/samples/android_sense/Agent/wso2_sense_agent/.svn/pristine/56/568747c1d8d59b24c0667a7288cb20abc83a2fb9.svn-base b/modules/samples/android_sense/Agent/wso2_sense_agent/.svn/pristine/56/568747c1d8d59b24c0667a7288cb20abc83a2fb9.svn-base new file mode 100644 index 00000000..9c273fa4 --- /dev/null +++ b/modules/samples/android_sense/Agent/wso2_sense_agent/.svn/pristine/56/568747c1d8d59b24c0667a7288cb20abc83a2fb9.svn-base @@ -0,0 +1,17 @@ +# Add project specific ProGuard rules here. +# By default, the flags in this file are appended to flags specified +# in /Users/ayyoobhamza/Library/Android/sdk/tools/proguard/proguard-android.txt +# You can edit the include path and order by changing the proguardFiles +# directive in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# Add any project specific keep options here: + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} diff --git a/modules/samples/android_sense/Agent/wso2_sense_agent/.svn/pristine/5c/5c22d8d526a43e8b0fd173a7d9c87882d4a4ac1c.svn-base b/modules/samples/android_sense/Agent/wso2_sense_agent/.svn/pristine/5c/5c22d8d526a43e8b0fd173a7d9c87882d4a4ac1c.svn-base new file mode 100644 index 00000000..4a2ae7fc --- /dev/null +++ b/modules/samples/android_sense/Agent/wso2_sense_agent/.svn/pristine/5c/5c22d8d526a43e8b0fd173a7d9c87882d4a4ac1c.svn-base @@ -0,0 +1,200 @@ +/* + * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + */ +package org.wso2.carbon.iot.android.sense.util; + + +import android.content.Context; +import android.util.Log; +import android.widget.Toast; + +import org.wso2.carbon.iot.android.sense.constants.SenseConstants; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; +import java.util.concurrent.ExecutionException; + + +public class SenseClient { + + + private final static String TAG = "SenseService Client"; + + private Context context; + + public SenseClient(Context context) { + + this.context = context; + } + + public boolean isAuthenticate(String username, String password) { + Map _response = new HashMap(); + Map params = new HashMap(); + params.put("username", username); + params.put("password", password); + String response = ""; + try { + + String endpoint = LocalRegister.getServerURL(context) + SenseConstants.LOGIN_CONTEXT; + response = sendWithTimeWait(endpoint, params, "POST", null).get("status"); + + if (response.trim().contains(SenseConstants.Request.REQUEST_SUCCESSFUL)) { + + return true; + } else { + //Toast.makeText(context, "Authentication failed, please check your credentials and try again.", Toast.LENGTH_LONG).show(); + + return false; + } + } catch (Exception ex) { + Log.e("Authentication", "Authentication failed due to a connection failure"); + return false; + } + } + + public boolean register(String username, String deviceId) { + Map _response = new HashMap(); + Map params = new HashMap(); + params.put("deviceId", deviceId); + params.put("owner", username); + + try { + String endpoint = LocalRegister.getServerURL(context) + SenseConstants.REGISTER_CONTEXT; + Map response = sendWithTimeWait(endpoint, params, "PUT", null); + + String responseStatus = response.get("status"); + + if (responseStatus.trim().contains(SenseConstants.Request.REQUEST_SUCCESSFUL)) { + + Toast.makeText(context, "Device Registered", Toast.LENGTH_LONG).show(); + + return true; + } else if (responseStatus.trim().contains(SenseConstants.Request.REQUEST_CONFLICT)) { + Toast.makeText(context, "Login Successful", Toast.LENGTH_LONG).show(); + return true; + } else { + Toast.makeText(context, "Authentication failed, please check your credentials and try again.", Toast + .LENGTH_LONG).show(); + + return false; + } + } catch (Exception ex) { + Log.e("Authentication", "Authentication failed due to a connection failure"); + Toast.makeText(context, "Authentication failed due to a connection failure", Toast.LENGTH_LONG).show(); + return false; + } + } + + public Map sendWithTimeWait(String endpoint, Map params, String option, String + jsonBody) { + Map response = null; + Map responseFinal = null; + for (int i = 1; i <= SenseConstants.Request.MAX_ATTEMPTS; i++) { + Log.d(TAG, "Attempt #" + i + " to register"); + try { + + response = sendToServer(endpoint, params, option, jsonBody); + + if (response != null && !response.equals(null)) { + responseFinal = response; + } + + return responseFinal; + } catch (Exception e) { + Log.e(TAG, "Failed to register on attempt " + i, e); + if (i == SenseConstants.Request.MAX_ATTEMPTS) { + break; + } + + return responseFinal; + } + } + + return responseFinal; + } + + public void sendSensorDataToServer(String data) { + String urlString = null; + try { + urlString = LocalRegister.getServerURL(context) + SenseConstants.DATA_ENDPOINT; + Log.i("SENDING DATAs", "SENDING JSON to " + urlString + " : " + data); + Map response = sendWithTimeWait(urlString, null, "POST", data); + String responseStatus = response.get("status"); + + } catch (Exception ex) { + Log.e("Send Sensor Data", "Failure to send data to "+ urlString); + + } + + } + + public Map sendToServer(String endpoint, Map params, + String option, String jsonBody) throws IOException { + String body = null; + if (params != null && !params.isEmpty()) { + StringBuilder bodyBuilder = new StringBuilder(); + Iterator> iterator = params.entrySet().iterator(); + + while (iterator.hasNext()) { + Map.Entry param = iterator.next(); + bodyBuilder.append(param.getKey()).append('=') + .append(param.getValue()); + if (iterator.hasNext()) { + bodyBuilder.append('&'); + } + } + body = bodyBuilder.toString(); + } + + + try { + SenseClientAsyncExecutor senseClientAsyncExecutor = new SenseClientAsyncExecutor(context); + return senseClientAsyncExecutor.execute(endpoint, body, option, jsonBody).get(); + } catch (InterruptedException e) { + Log.e("Send Sensor Data", "Thread Inturption for endpoint " + endpoint); + } catch (ExecutionException e) { + Log.e("Send Sensor Data", "Failed to push data to the endpoint " + endpoint); + } + return null; + } + + private String inputStreamAsString(InputStream in) { + + BufferedReader reader = new BufferedReader(new InputStreamReader(in)); + StringBuilder builder = new StringBuilder(); + String line = null; + try { + while ((line = reader.readLine()) != null) { + builder.append(line); + builder.append("\n"); // append a new line + } + } catch (IOException e) { + Log.e(SenseClient.class.getName(), e.getMessage()); + } finally { + try { + in.close(); + } catch (IOException e) { + Log.e(SenseClient.class.getName(), e.getMessage()); + } + } + // System.out.println(builder.toString()); + return builder.toString(); + } + + +} diff --git a/modules/samples/android_sense/Agent/wso2_sense_agent/.svn/pristine/60/606d70361d280a18cb7f055f5ca63bf481900ffc.svn-base b/modules/samples/android_sense/Agent/wso2_sense_agent/.svn/pristine/60/606d70361d280a18cb7f055f5ca63bf481900ffc.svn-base new file mode 100644 index 00000000..7aa889b9 --- /dev/null +++ b/modules/samples/android_sense/Agent/wso2_sense_agent/.svn/pristine/60/606d70361d280a18cb7f055f5ca63bf481900ffc.svn-base @@ -0,0 +1,143 @@ +/* + * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + */ +package org.wso2.carbon.iot.android.sense.util; + +import android.content.Context; +import android.content.SharedPreferences; +import android.util.Log; + +import java.net.MalformedURLException; +import java.net.URL; + +public class LocalRegister { + + private static final String SENSE_SHARED_PREFERENCES = "senseSharedPreferences"; + private static final String USERNAME_KEY = "usernameKey"; + private static final String DEVICE_ID_KEY = "deviceIdKey"; + private static final String SERVER_HOST_KEY = "serverHostKey"; + private static boolean exists = false; + private static String username; + private static String deviceId; + private static String serverURL; + + public static boolean isExist(Context context){ + if(!exists) { + SharedPreferences sharedpreferences = context.getSharedPreferences(SENSE_SHARED_PREFERENCES, Context.MODE_PRIVATE); + String username = sharedpreferences.getString(USERNAME_KEY, ""); + String deviceId = sharedpreferences.getString(DEVICE_ID_KEY, ""); + exists = (username != null && !username.isEmpty() && deviceId != null && !deviceId.isEmpty()); + } + return exists; + } + + public static void setExist(boolean status){ + exists = status; + } + + + public static void addUsername(Context context, String username){ + SharedPreferences sharedpreferences = context.getSharedPreferences(SENSE_SHARED_PREFERENCES, Context.MODE_PRIVATE); + SharedPreferences.Editor editor = sharedpreferences.edit(); + editor.putString(USERNAME_KEY, username); + editor.commit(); + LocalRegister.username = username; + } + + public static String getUsername(Context context){ + if(LocalRegister.username==null || username.isEmpty()) { + SharedPreferences sharedpreferences = context.getSharedPreferences(SENSE_SHARED_PREFERENCES, Context.MODE_PRIVATE); + LocalRegister.username = sharedpreferences.getString(USERNAME_KEY, ""); + //TODO Throw exception + } + return LocalRegister.username; + } + + public static void removeUsername(Context context){ + SharedPreferences sharedpreferences = context.getSharedPreferences(SENSE_SHARED_PREFERENCES, Context.MODE_PRIVATE); + SharedPreferences.Editor editor = sharedpreferences.edit(); + editor.clear(); + editor.remove(USERNAME_KEY); + editor.commit(); + LocalRegister.username = null; + } + + public static void addDeviceId(Context context, String deviceId){ + SharedPreferences sharedpreferences = context.getSharedPreferences(SENSE_SHARED_PREFERENCES, Context.MODE_PRIVATE); + SharedPreferences.Editor editor = sharedpreferences.edit(); + editor.putString(DEVICE_ID_KEY, deviceId); + editor.commit(); + LocalRegister.deviceId = deviceId; + } + + + + public static void removeDeviceId(Context context){ + SharedPreferences sharedpreferences = context.getSharedPreferences(SENSE_SHARED_PREFERENCES, Context.MODE_PRIVATE); + SharedPreferences.Editor editor = sharedpreferences.edit(); + editor.remove(DEVICE_ID_KEY); + editor.clear(); + editor.commit(); + LocalRegister.deviceId = null; + } + + public static String getDeviceId(Context context){ + if(LocalRegister.deviceId==null || LocalRegister.deviceId.isEmpty()) { + SharedPreferences sharedpreferences = context.getSharedPreferences(SENSE_SHARED_PREFERENCES, Context.MODE_PRIVATE); + LocalRegister.deviceId = sharedpreferences.getString(DEVICE_ID_KEY, ""); + //TODO Throw exception + } + return LocalRegister.deviceId; + } + + public static void addServerURL(Context context, String host){ + SharedPreferences sharedpreferences = context.getSharedPreferences(SENSE_SHARED_PREFERENCES, Context.MODE_PRIVATE); + SharedPreferences.Editor editor = sharedpreferences.edit(); + editor.putString(SERVER_HOST_KEY, host); + editor.commit(); + LocalRegister.serverURL = host; + } + + public static void removeServerURL(Context context){ + SharedPreferences sharedpreferences = context.getSharedPreferences(SENSE_SHARED_PREFERENCES, Context.MODE_PRIVATE); + SharedPreferences.Editor editor = sharedpreferences.edit(); + editor.remove(SERVER_HOST_KEY); + editor.clear(); + editor.commit(); + LocalRegister.serverURL = null; + } + + public static String getServerURL(Context context){ + if(LocalRegister.serverURL ==null || LocalRegister.serverURL.isEmpty()) { + SharedPreferences sharedpreferences = context.getSharedPreferences(SENSE_SHARED_PREFERENCES, Context.MODE_PRIVATE); + LocalRegister.serverURL = sharedpreferences.getString(SERVER_HOST_KEY, ""); + //TODO Throw exception + } + return LocalRegister.serverURL; + } + + public static String getServerHost(Context context){ + + URL url = null; + String urlString = getServerURL(context); + try { + url = new URL(urlString); + return url.getHost(); + } catch (MalformedURLException e) { + Log.e("Host " , "Invalid urlString :" + urlString); + return null; + } + + + } +} diff --git a/modules/samples/android_sense/Agent/wso2_sense_agent/.svn/pristine/62/62c5c52a80b82397571b5ae577f093f81351d4ab.svn-base b/modules/samples/android_sense/Agent/wso2_sense_agent/.svn/pristine/62/62c5c52a80b82397571b5ae577f093f81351d4ab.svn-base new file mode 100644 index 00000000..1ecc8b78 --- /dev/null +++ b/modules/samples/android_sense/Agent/wso2_sense_agent/.svn/pristine/62/62c5c52a80b82397571b5ae577f093f81351d4ab.svn-base @@ -0,0 +1,120 @@ +/* + * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + */ + +package org.wso2.carbon.iot.android.sense.events.input.battery; + +import java.util.Calendar; + +import android.content.Intent; +import android.os.BatteryManager; + +public class BatteryData { + + private int health; + private int level; + private int plugged; + private int present; + private int scale; + private int status; + private int temperature; + private int voltage; + private String timestamp; + + BatteryData(Intent intent) { + timestamp = "" + Calendar.getInstance().getTimeInMillis(); + health = intent.getIntExtra(BatteryManager.EXTRA_HEALTH, 0); + level = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, 0); + plugged = intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, 0); + present = intent.getExtras().getBoolean(BatteryManager.EXTRA_PRESENT) ? 1 : 0; + scale = intent.getIntExtra(BatteryManager.EXTRA_SCALE, 0); + status = intent.getIntExtra(BatteryManager.EXTRA_STATUS, 0); + String technology = intent.getExtras().getString(BatteryManager.EXTRA_TECHNOLOGY); + temperature = intent.getIntExtra(BatteryManager.EXTRA_TEMPERATURE, 0); + voltage = intent.getIntExtra(BatteryManager.EXTRA_VOLTAGE, 0); + + } + + public int getHealth() { + return health; + } + + public void setHealth(int health) { + this.health = health; + } + + public int getLevel() { + return level; + } + + public void setLevel(int level) { + this.level = level; + } + + public int getPlugged() { + return plugged; + } + + public void setPlugged(int plugged) { + this.plugged = plugged; + } + + public int getPresent() { + return present; + } + + public void setPresent(int present) { + this.present = present; + } + + public int getScale() { + return scale; + } + + public void setScale(int scale) { + this.scale = scale; + } + + public int getStatus() { + return status; + } + + public void setStatus(int status) { + this.status = status; + } + + public int getTemperature() { + return temperature; + } + + public void setTemperature(int temperature) { + this.temperature = temperature; + } + + public int getVoltage() { + return voltage; + } + + public void setVoltage(int voltage) { + this.voltage = voltage; + } + + + public String getTimestamp() { + return timestamp; + } + + public void setTimestamp(String timestamp) { + this.timestamp = timestamp; + } +} diff --git a/modules/samples/android_sense/Agent/wso2_sense_agent/.svn/pristine/6a/6a9b52096f1ef015e9fb30ae96329dc4a9d7e642.svn-base b/modules/samples/android_sense/Agent/wso2_sense_agent/.svn/pristine/6a/6a9b52096f1ef015e9fb30ae96329dc4a9d7e642.svn-base new file mode 100644 index 00000000..24534686 --- /dev/null +++ b/modules/samples/android_sense/Agent/wso2_sense_agent/.svn/pristine/6a/6a9b52096f1ef015e9fb30ae96329dc4a9d7e642.svn-base @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + */ + +package org.wso2.carbon.iot.android.sense.register; + +import android.app.Activity; +import android.content.Intent; +import android.os.Bundle; +import android.view.View; +import android.widget.Button; + +import org.wso2.carbon.iot.android.sense.util.LocalRegister; + +import agent.sense.android.iot.carbon.wso2.org.wso2_senseagent.R; + +public class SenseDeEnroll extends Activity { + + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + + if (!LocalRegister.isExist(getApplicationContext())) { + Intent activity = new Intent(getApplicationContext(), RegisterActivity.class); + startActivity(activity); + + + } + + setContentView(R.layout.activity_sense_settings); + Button deviceRegisterButton = (Button) findViewById(R.id.unregister); + deviceRegisterButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + + LocalRegister.removeUsername(getApplicationContext()); + LocalRegister.removeDeviceId(getApplicationContext()); + LocalRegister.removeServerURL(getApplicationContext()); + LocalRegister.setExist(false); + Intent activity = new Intent(getApplicationContext(), RegisterActivity.class); + startActivity(activity); + } + }); + } + + +} diff --git a/modules/samples/android_sense/Agent/wso2_sense_agent/.svn/pristine/6c/6cf0dd85229e4aad8727e584a3e57bcc99f024c1.svn-base b/modules/samples/android_sense/Agent/wso2_sense_agent/.svn/pristine/6c/6cf0dd85229e4aad8727e584a3e57bcc99f024c1.svn-base new file mode 100644 index 00000000..0c71e760 --- /dev/null +++ b/modules/samples/android_sense/Agent/wso2_sense_agent/.svn/pristine/6c/6cf0dd85229e4aad8727e584a3e57bcc99f024c1.svn-base @@ -0,0 +1,6 @@ +#Wed Apr 10 15:27:10 PDT 2013 +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip diff --git a/modules/samples/android_sense/Agent/wso2_sense_agent/.svn/pristine/6f/6f933628dcec9b185fff4d22837b7fb1945da463.svn-base b/modules/samples/android_sense/Agent/wso2_sense_agent/.svn/pristine/6f/6f933628dcec9b185fff4d22837b7fb1945da463.svn-base new file mode 100644 index 00000000..0b3bfedf Binary files /dev/null and b/modules/samples/android_sense/Agent/wso2_sense_agent/.svn/pristine/6f/6f933628dcec9b185fff4d22837b7fb1945da463.svn-base differ diff --git a/modules/samples/android_sense/Agent/wso2_sense_agent/.svn/pristine/78/786f886eb6bc391b7253375ca50ff616c03cab93.svn-base b/modules/samples/android_sense/Agent/wso2_sense_agent/.svn/pristine/78/786f886eb6bc391b7253375ca50ff616c03cab93.svn-base new file mode 100644 index 00000000..0ebc0f43 --- /dev/null +++ b/modules/samples/android_sense/Agent/wso2_sense_agent/.svn/pristine/78/786f886eb6bc391b7253375ca50ff616c03cab93.svn-base @@ -0,0 +1,13 @@ + + + + Username + Password + Register Device + Sign in + + This email address is invalid + This password is too short + This password is incorrect + This field is required + diff --git a/modules/samples/android_sense/Agent/wso2_sense_agent/.svn/pristine/7d/7dec7019b4437160ead14084ca3463b63ab741db.svn-base b/modules/samples/android_sense/Agent/wso2_sense_agent/.svn/pristine/7d/7dec7019b4437160ead14084ca3463b63ab741db.svn-base new file mode 100644 index 00000000..28589d3a --- /dev/null +++ b/modules/samples/android_sense/Agent/wso2_sense_agent/.svn/pristine/7d/7dec7019b4437160ead14084ca3463b63ab741db.svn-base @@ -0,0 +1,7 @@ + + + diff --git a/modules/samples/android_sense/Agent/wso2_sense_agent/.svn/pristine/81/81c1752ea97f1d27b2bcd126ded220df24ce918c.svn-base b/modules/samples/android_sense/Agent/wso2_sense_agent/.svn/pristine/81/81c1752ea97f1d27b2bcd126ded220df24ce918c.svn-base new file mode 100644 index 00000000..d5164787 --- /dev/null +++ b/modules/samples/android_sense/Agent/wso2_sense_agent/.svn/pristine/81/81c1752ea97f1d27b2bcd126ded220df24ce918c.svn-base @@ -0,0 +1,126 @@ +/* + * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + */ + +package org.wso2.carbon.iot.android.sense.scheduler; + +import android.app.Service; +import android.content.Context; +import android.content.Intent; +import android.os.IBinder; +import android.support.annotation.Nullable; +import android.util.Log; +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; +import org.wso2.carbon.iot.android.sense.events.input.Location.LocationData; +import org.wso2.carbon.iot.android.sense.events.input.Sensor.SensorData; +import org.wso2.carbon.iot.android.sense.events.input.battery.BatteryData; +import org.wso2.carbon.iot.android.sense.util.DataMap; +import org.wso2.carbon.iot.android.sense.util.LocalRegister; +import org.wso2.carbon.iot.android.sense.util.SenseClient; +import java.util.List; + + +public class DataUploaderService extends Service { + + public static Context context; + + @Nullable + @Override + public IBinder onBind(Intent intent) { + return null; + } + + @Override + public int onStartCommand(Intent intent, int flags, int startId) { + context = this; + + Log.i("SENDING DATA", "service started"); + + Runnable runnable = new Runnable() { + @Override + public void run() { + + try { + + JSONObject jsonObject = new JSONObject(); + JSONArray sensorJsonArray = new JSONArray(); + + jsonObject.put("owner", LocalRegister.getUsername(context)); + jsonObject.put("deviceId", LocalRegister.getDeviceId(context)); + + boolean noSensorData = false; + boolean noBatteryData = false; + boolean noLocationData = false; + + + List sensorDataMap = DataMap.getSensorDataMap(); + if (sensorDataMap.size() <= 0) { + noSensorData = true; + } + for (SensorData sensorData : sensorDataMap) { + JSONObject sensorJsonObject = new JSONObject(); + sensorJsonObject.put("time", "" + sensorData.getCollectTimestamp()); + sensorJsonObject.put("key", "" + sensorData.getSensorType()); + sensorJsonObject.put("value", sensorData.getSensorValues()); + sensorJsonArray.put(sensorJsonObject); + } + DataMap.resetSensorDataMap(); + + List batteryDataMap = DataMap.getBatteryDataMap(); + if (batteryDataMap.size() <= 0) { + noBatteryData = true; + } + for (BatteryData batteryData : batteryDataMap) { + JSONObject batteryJsonObject = new JSONObject(); + batteryJsonObject.put("time", "" + batteryData.getTimestamp()); + batteryJsonObject.put("key", "battery"); + batteryJsonObject.put("value", batteryData.getLevel()); + sensorJsonArray.put(batteryJsonObject); + } + DataMap.resetBatteryDataMap(); + + List locationDataMap = DataMap.getLocationDataMap(); + if (locationDataMap.size() <= 0) { + noLocationData = true; + } + for (LocationData locationData : locationDataMap) { + JSONObject locationJsonObject = new JSONObject(); + locationJsonObject.put("time", "" + locationData.getTimeStamp()); + locationJsonObject.put("key", "GPS"); + locationJsonObject.put("value", locationData.getLatitude() + "," + locationData.getLongitude()); + sensorJsonArray.put(locationJsonObject); + } + DataMap.resetLocationDataMap(); + + jsonObject.put("values", sensorJsonArray); + + if (!(noSensorData && noBatteryData && noLocationData)) { + SenseClient client = new SenseClient(context); + client.sendSensorDataToServer(jsonObject.toString()); + + } + + } catch (JSONException e) { + Log.i("Data Upload", " Json Data Parsing Exception"); + } + } + }; + + Thread dataUploaderThread = new Thread(runnable); + dataUploaderThread.start(); + + return Service.START_NOT_STICKY; + } +} \ No newline at end of file diff --git a/modules/samples/android_sense/Agent/wso2_sense_agent/.svn/pristine/86/8609c618667f5797ea69b2336159d6e3cac63fe9.svn-base b/modules/samples/android_sense/Agent/wso2_sense_agent/.svn/pristine/86/8609c618667f5797ea69b2336159d6e3cac63fe9.svn-base new file mode 100644 index 00000000..e2295f5a --- /dev/null +++ b/modules/samples/android_sense/Agent/wso2_sense_agent/.svn/pristine/86/8609c618667f5797ea69b2336159d6e3cac63fe9.svn-base @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + */ +package org.wso2.carbon.iot.android.sense.scheduler; + +import android.app.AlarmManager; +import android.app.PendingIntent; +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; + +import java.util.Calendar; + + +public class DataUploaderReceiver extends BroadcastReceiver { + + @Override + public void onReceive(Context context, Intent intent) { + AlarmManager service = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); + Intent i = new Intent(context, DataUploaderService.class); + PendingIntent pending = PendingIntent.getService(context, 0, i, 0); + service.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), 30 * 1000, pending); + + } + +} \ No newline at end of file diff --git a/modules/samples/android_sense/Agent/wso2_sense_agent/.svn/pristine/87/8751d7831ca6cd1cad48e1475a79596b54b48994.svn-base b/modules/samples/android_sense/Agent/wso2_sense_agent/.svn/pristine/87/8751d7831ca6cd1cad48e1475a79596b54b48994.svn-base new file mode 100644 index 00000000..8a0b282a --- /dev/null +++ b/modules/samples/android_sense/Agent/wso2_sense_agent/.svn/pristine/87/8751d7831ca6cd1cad48e1475a79596b54b48994.svn-base @@ -0,0 +1,90 @@ +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS= + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto init + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto init + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:init +@rem Get command-line arguments, handling Windowz variants + +if not "%OS%" == "Windows_NT" goto win9xME_args +if "%@eval[2+2]" == "4" goto 4NT_args + +:win9xME_args +@rem Slurp the command line arguments. +set CMD_LINE_ARGS= +set _SKIP=2 + +:win9xME_args_slurp +if "x%~1" == "x" goto execute + +set CMD_LINE_ARGS=%* +goto execute + +:4NT_args +@rem Get arguments from the 4NT Shell from JP Software +set CMD_LINE_ARGS=%$ + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/modules/samples/android_sense/Agent/wso2_sense_agent/.svn/pristine/87/8769a3e4013be25690649a1b57bc39fe54e412dd.svn-base b/modules/samples/android_sense/Agent/wso2_sense_agent/.svn/pristine/87/8769a3e4013be25690649a1b57bc39fe54e412dd.svn-base new file mode 100644 index 00000000..4f512c2c --- /dev/null +++ b/modules/samples/android_sense/Agent/wso2_sense_agent/.svn/pristine/87/8769a3e4013be25690649a1b57bc39fe54e412dd.svn-base @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + */ +package org.wso2.carbon.iot.android.sense.util; + +import org.wso2.carbon.iot.android.sense.events.input.Location.LocationData; +import org.wso2.carbon.iot.android.sense.events.input.Sensor.SensorData; +import org.wso2.carbon.iot.android.sense.events.input.battery.BatteryData; +import java.util.List; +import java.util.concurrent.CopyOnWriteArrayList; + +public class DataMap { + + private static List sensorDataMap; + private static List batteryDataMap; + private static List locationDataMap; + + + public static List getSensorDataMap(){ + if(sensorDataMap == null){ + sensorDataMap = new CopyOnWriteArrayList(); + } + return sensorDataMap; + } + + public static List getBatteryDataMap(){ + if(batteryDataMap == null){ + batteryDataMap = new CopyOnWriteArrayList(); + } + return batteryDataMap; + } + + public static List getLocationDataMap(){ + if(locationDataMap == null){ + locationDataMap = new CopyOnWriteArrayList(); + } + return locationDataMap; + } + + public static void resetSensorDataMap(){ + sensorDataMap = null; + } + + public static void resetBatteryDataMap(){ + batteryDataMap = null; + } + + public static void resetLocationDataMap(){ + locationDataMap = null; + } + + +} diff --git a/modules/samples/android_sense/Agent/wso2_sense_agent/.svn/pristine/8a/8a903dfca2bb840b0690f23acbffcf39ab53f808.svn-base b/modules/samples/android_sense/Agent/wso2_sense_agent/.svn/pristine/8a/8a903dfca2bb840b0690f23acbffcf39ab53f808.svn-base new file mode 100644 index 00000000..a886c5c8 --- /dev/null +++ b/modules/samples/android_sense/Agent/wso2_sense_agent/.svn/pristine/8a/8a903dfca2bb840b0690f23acbffcf39ab53f808.svn-base @@ -0,0 +1,362 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/modules/samples/android_sense/Agent/wso2_sense_agent/.svn/pristine/8b/8bb15f3f44687265815f33a86e9308867d0ab231.svn-base b/modules/samples/android_sense/Agent/wso2_sense_agent/.svn/pristine/8b/8bb15f3f44687265815f33a86e9308867d0ab231.svn-base new file mode 100644 index 00000000..48894fff --- /dev/null +++ b/modules/samples/android_sense/Agent/wso2_sense_agent/.svn/pristine/8b/8bb15f3f44687265815f33a86e9308867d0ab231.svn-base @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + */ +package org.wso2.carbon.iot.android.sense.events.input.Location; + +import java.util.Calendar; + + +public class LocationData { + private double latitude; // latitude + private double longitude; // longitude + private String TimeStamp; + + LocationData(double latitude, double longitude) { + this.latitude = latitude; + this.longitude = longitude; + TimeStamp = "" + Calendar.getInstance().getTimeInMillis(); + + } + + public double getLatitude() { + return latitude; + } + + public void setLatitude(double latitude) { + this.latitude = latitude; + } + + public double getLongitude() { + return longitude; + } + + public void setLongitude(double longitude) { + this.longitude = longitude; + } + + public String getTimeStamp() { + return TimeStamp; + } + + public void setTimeStamp(String timeStamp) { + TimeStamp = timeStamp; + } +} diff --git a/modules/samples/android_sense/Agent/wso2_sense_agent/.svn/pristine/9b/9ba50ae89ad3a7509bb447f9feacd4b681a1bcc4.svn-base b/modules/samples/android_sense/Agent/wso2_sense_agent/.svn/pristine/9b/9ba50ae89ad3a7509bb447f9feacd4b681a1bcc4.svn-base new file mode 100644 index 00000000..0d81e2ca --- /dev/null +++ b/modules/samples/android_sense/Agent/wso2_sense_agent/.svn/pristine/9b/9ba50ae89ad3a7509bb447f9feacd4b681a1bcc4.svn-base @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + */ + +package org.wso2.carbon.iot.android.sense.events.input; + +public abstract class DataReader implements Runnable { + + +} diff --git a/modules/samples/android_sense/Agent/wso2_sense_agent/.svn/pristine/a7/a78f48fe9f9114f315dc79eff29452e93ffd709a.svn-base b/modules/samples/android_sense/Agent/wso2_sense_agent/.svn/pristine/a7/a78f48fe9f9114f315dc79eff29452e93ffd709a.svn-base new file mode 100644 index 00000000..cde69bcc Binary files /dev/null and b/modules/samples/android_sense/Agent/wso2_sense_agent/.svn/pristine/a7/a78f48fe9f9114f315dc79eff29452e93ffd709a.svn-base differ diff --git a/modules/samples/android_sense/Agent/wso2_sense_agent/.svn/pristine/ac/acf5ae7b1e9f1e62650f1deee03a84515dbe9cd8.svn-base b/modules/samples/android_sense/Agent/wso2_sense_agent/.svn/pristine/ac/acf5ae7b1e9f1e62650f1deee03a84515dbe9cd8.svn-base new file mode 100644 index 00000000..fe44e2d2 --- /dev/null +++ b/modules/samples/android_sense/Agent/wso2_sense_agent/.svn/pristine/ac/acf5ae7b1e9f1e62650f1deee03a84515dbe9cd8.svn-base @@ -0,0 +1,7 @@ + + WSO2-SenseAgent + Sense Settings + Server URL https://host:9443 + Hello world! + Settings + diff --git a/modules/samples/android_sense/Agent/wso2_sense_agent/.svn/pristine/ae/ae86c9f2fefeb0a12f9e350975339bc580efd813.svn-base b/modules/samples/android_sense/Agent/wso2_sense_agent/.svn/pristine/ae/ae86c9f2fefeb0a12f9e350975339bc580efd813.svn-base new file mode 100644 index 00000000..c133a0cb Binary files /dev/null and b/modules/samples/android_sense/Agent/wso2_sense_agent/.svn/pristine/ae/ae86c9f2fefeb0a12f9e350975339bc580efd813.svn-base differ diff --git a/modules/samples/android_sense/Agent/wso2_sense_agent/.svn/pristine/b9/b9a763eba105c1a211983fc9055ba234de6e280b.svn-base b/modules/samples/android_sense/Agent/wso2_sense_agent/.svn/pristine/b9/b9a763eba105c1a211983fc9055ba234de6e280b.svn-base new file mode 100644 index 00000000..715a17bf --- /dev/null +++ b/modules/samples/android_sense/Agent/wso2_sense_agent/.svn/pristine/b9/b9a763eba105c1a211983fc9055ba234de6e280b.svn-base @@ -0,0 +1,11 @@ +## This file is automatically generated by Android Studio. +# Do not modify this file -- YOUR CHANGES WILL BE ERASED! +# +# This file must *NOT* be checked into Version Control Systems, +# as it contains information specific to your local configuration. +# +# Location of the SDK. This is only used by Gradle. +# For customization when using a Version Control System, please read the +# header note. +#Thu Oct 22 22:12:40 IST 2015 +sdk.dir=/Users/ayyoobhamza/Library/Android/sdk diff --git a/modules/samples/android_sense/Agent/wso2_sense_agent/.svn/pristine/c6/c6950f19855fa3b070a1a3f917a04db9be29e9a1.svn-base b/modules/samples/android_sense/Agent/wso2_sense_agent/.svn/pristine/c6/c6950f19855fa3b070a1a3f917a04db9be29e9a1.svn-base new file mode 100644 index 00000000..8a146a5b --- /dev/null +++ b/modules/samples/android_sense/Agent/wso2_sense_agent/.svn/pristine/c6/c6950f19855fa3b070a1a3f917a04db9be29e9a1.svn-base @@ -0,0 +1,102 @@ +/* + * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + */ + +package org.wso2.carbon.iot.android.sense.events.input.Sensor; + +import java.util.Calendar; + +import android.hardware.SensorEvent; + +public class SensorData { + private int sensorType; + private String sensorName; + private String sensorVendor; + private String sensorValues; + private int accuracyStatus; + private String timestamp; + private String collectTimestamp; + + SensorData(SensorEvent event) { + sensorValues = ""; + for (int m = 0; m < event.values.length; m++) { + sensorValues += event.values[m] + ","; + + } + sensorValues = sensorValues.substring(0, sensorValues.length() - 1); + accuracyStatus = event.accuracy; + + collectTimestamp = "" + event.timestamp; + timestamp = "" + Calendar.getInstance().getTimeInMillis(); + sensorName = event.sensor.getName(); + sensorVendor = event.sensor.getVendor(); + sensorType = event.sensor.getType(); + + } + + public int getSensorType() { + return sensorType; + } + + public void setSensorType(int sensorType) { + this.sensorType = sensorType; + } + + public String getSensorName() { + return sensorName; + } + + public void setSensorName(String sensorName) { + this.sensorName = sensorName; + } + + public String getSensorVendor() { + return sensorVendor; + } + + public void setSensorVendor(String sensorVendor) { + this.sensorVendor = sensorVendor; + } + + public String getSensorValues() { + return sensorValues; + } + + public void setSensorValues(String sensorValues) { + this.sensorValues = sensorValues; + } + + public int getAccuracyStatus() { + return accuracyStatus; + } + + public void setAccuracyStatus(int accuracyStatus) { + this.accuracyStatus = accuracyStatus; + } + + public String getTimestamp() { + return timestamp; + } + + public void setTimestamp(String timestamp) { + this.timestamp = timestamp; + } + + public String getCollectTimestamp() { + return collectTimestamp; + } + + public void setCollectTimestamp(String collectTimestamp) { + this.collectTimestamp = collectTimestamp; + } +} diff --git a/modules/samples/android_sense/Agent/wso2_sense_agent/.svn/pristine/ca/cac22ff594b3baf6d111f57405f27b485463a68c.svn-base b/modules/samples/android_sense/Agent/wso2_sense_agent/.svn/pristine/ca/cac22ff594b3baf6d111f57405f27b485463a68c.svn-base new file mode 100644 index 00000000..bfa42f0e Binary files /dev/null and b/modules/samples/android_sense/Agent/wso2_sense_agent/.svn/pristine/ca/cac22ff594b3baf6d111f57405f27b485463a68c.svn-base differ diff --git a/modules/samples/android_sense/Agent/wso2_sense_agent/.svn/pristine/d1/d1575c82f241ab1471cfff4d69e2616fd89d2b42.svn-base b/modules/samples/android_sense/Agent/wso2_sense_agent/.svn/pristine/d1/d1575c82f241ab1471cfff4d69e2616fd89d2b42.svn-base new file mode 100644 index 00000000..b27e499a --- /dev/null +++ b/modules/samples/android_sense/Agent/wso2_sense_agent/.svn/pristine/d1/d1575c82f241ab1471cfff4d69e2616fd89d2b42.svn-base @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + */ +package org.wso2.carbon.iot.android.sense.service; + +import android.app.AlarmManager; +import android.app.PendingIntent; +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; + +import java.util.Calendar; + +public class SenseScheduleReceiver extends BroadcastReceiver { + + @Override + public void onReceive(Context context, Intent intent) { + + AlarmManager service = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); + Intent i = new Intent(context, SenseService.class); + PendingIntent pending = PendingIntent.getService(context, 0, i, 0); + + Calendar cal = Calendar.getInstance(); + + cal.add(Calendar.SECOND, 30); + service.setRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), 20 * 1000, pending); + } + +} diff --git a/modules/samples/android_sense/Agent/wso2_sense_agent/.svn/pristine/d2/d2814c08b2d76584d7c7ebbe3558d1ec72376919.svn-base b/modules/samples/android_sense/Agent/wso2_sense_agent/.svn/pristine/d2/d2814c08b2d76584d7c7ebbe3558d1ec72376919.svn-base new file mode 100644 index 00000000..1222c6de --- /dev/null +++ b/modules/samples/android_sense/Agent/wso2_sense_agent/.svn/pristine/d2/d2814c08b2d76584d7c7ebbe3558d1ec72376919.svn-base @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + */ + +package org.wso2.carbon.iot.android.sense.events.input; + + + +import android.content.Context; + +import org.wso2.carbon.iot.android.sense.events.input.DataReader; +import org.wso2.carbon.iot.android.sense.events.input.Location.LocationDataReader; +import org.wso2.carbon.iot.android.sense.events.input.Sensor.SensorDataReader; + +public class SenseDataCollector { + public enum DataType { + SENSOR ,LOCATION + }; + + public SenseDataCollector(Context ctx, DataType dt) { + + + try{ + DataReader dr=null; + + switch(dt){ + case SENSOR: dr=new SensorDataReader(ctx); + break; + + + case LOCATION: dr=new LocationDataReader(ctx); + break; + } + + Thread DataCollector =new Thread(dr); + DataCollector.start(); + }catch(NullPointerException e){ + + + + } + } +} diff --git a/modules/samples/android_sense/Agent/wso2_sense_agent/.svn/pristine/d3/d37db4d939d6374c32f0242491cf34f22796eba9.svn-base b/modules/samples/android_sense/Agent/wso2_sense_agent/.svn/pristine/d3/d37db4d939d6374c32f0242491cf34f22796eba9.svn-base new file mode 100644 index 00000000..e7f03253 --- /dev/null +++ b/modules/samples/android_sense/Agent/wso2_sense_agent/.svn/pristine/d3/d37db4d939d6374c32f0242491cf34f22796eba9.svn-base @@ -0,0 +1,4 @@ + + + false + \ No newline at end of file diff --git a/modules/samples/android_sense/Agent/wso2_sense_agent/.svn/pristine/d7/d788bdb71cf35278d1f7c4b0ca387ed0e42e05cd.svn-base b/modules/samples/android_sense/Agent/wso2_sense_agent/.svn/pristine/d7/d788bdb71cf35278d1f7c4b0ca387ed0e42e05cd.svn-base new file mode 100644 index 00000000..a0d6920d --- /dev/null +++ b/modules/samples/android_sense/Agent/wso2_sense_agent/.svn/pristine/d7/d788bdb71cf35278d1f7c4b0ca387ed0e42e05cd.svn-base @@ -0,0 +1,186 @@ +/* + * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + */ +package org.wso2.carbon.iot.android.sense.register; + +import android.animation.Animator; +import android.animation.AnimatorListenerAdapter; +import android.annotation.TargetApi; +import android.app.Activity; +import android.content.Context; +import android.content.Intent; +import android.os.Build; +import android.os.Bundle; +import android.text.TextUtils; +import android.view.View; +import android.view.View.OnClickListener; +import android.widget.Button; +import android.widget.EditText; + +import org.wso2.carbon.iot.android.sense.scheduler.DataUploaderReceiver; +import org.wso2.carbon.iot.android.sense.service.SenseScheduleReceiver; +import org.wso2.carbon.iot.android.sense.util.LocalRegister; +import org.wso2.carbon.iot.android.sense.util.SenseClient; +import org.wso2.carbon.iot.android.sense.util.SenseUtils; + +import java.net.CookieHandler; +import java.net.CookieManager; + +import agent.sense.android.iot.carbon.wso2.org.wso2_senseagent.R; + + +/** + * A login screen that offers to register the device. + */ +public class RegisterActivity extends Activity { + + private EditText mUsernameView; + private EditText mPasswordView; + private EditText mHostView; + private View mProgressView; + private View mLoginFormView; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + if (LocalRegister.isExist(getApplicationContext())) { + Intent activity = new Intent(getApplicationContext(), SenseDeEnroll.class); + startActivity(activity); + + } + setContentView(R.layout.activity_register); + mUsernameView = (EditText) findViewById(R.id.username); + mPasswordView = (EditText) findViewById(R.id.password); + mHostView = (EditText) findViewById(R.id.hostname); + + Button deviceRegisterButton = (Button) findViewById(R.id.device_register_button); + deviceRegisterButton.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View view) { + attemptLogin(); + } + }); + + mLoginFormView = findViewById(R.id.login_form); + mProgressView = findViewById(R.id.login_progress); + } + + public void attemptLogin() { + Context context = this; + showProgress(true); + // Reset errors. + mUsernameView.setError(null); + mPasswordView.setError(null); + + // Store values at the time of the login attempt. + String username = mUsernameView.getText().toString(); + String password = mPasswordView.getText().toString(); + String hostname = mHostView.getText().toString(); + + boolean cancel = false; + View focusView = null; + + // Check for a valid password, if the user entered one. + if (!TextUtils.isEmpty(password)) { + // mPasswordView.setError(getString(R.string.error_invalid_password)); + focusView = mPasswordView; + //cancel = true; + } + + // Check for a valid username . + if (TextUtils.isEmpty(username)) { + mUsernameView.setError(getString(R.string.error_field_required)); + focusView = mUsernameView; + cancel = true; + } + + if (TextUtils.isEmpty(username)) { + mHostView.setError(getString(R.string.error_field_required)); + focusView = mHostView; + cancel = true; + } + + if (cancel) { + + focusView.requestFocus(); + } else { + + + SenseClient client = new SenseClient(getApplicationContext()); + LocalRegister.addServerURL(getBaseContext(), hostname); + boolean auth = client.isAuthenticate(username, password); + + if(auth) { + //TODO API SECURITY need to be added. + String deviceId = SenseUtils.generateDeviceId(getBaseContext(), getContentResolver()); + boolean registerStatus=client.register(username, deviceId); + if(registerStatus){ + LocalRegister.addUsername(getApplicationContext(), username); + LocalRegister.addDeviceId(getApplicationContext(), deviceId); + + SenseScheduleReceiver senseScheduleReceiver = new SenseScheduleReceiver(); + senseScheduleReceiver.clearAbortBroadcast(); + senseScheduleReceiver.onReceive(this, null); + + DataUploaderReceiver dataUploaderReceiver = new DataUploaderReceiver(); + dataUploaderReceiver.clearAbortBroadcast(); + dataUploaderReceiver.onReceive(this, null); + + Intent activity = new Intent(getApplicationContext(), SenseDeEnroll.class); + startActivity(activity); + + } + } + showProgress(false); + } + + } + + + @TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2) + public void showProgress(final boolean show) { + // On Honeycomb MR2 we have the ViewPropertyAnimator APIs, which allow + // for very easy animations. If available, use these APIs to fade-in + // the progress spinner. + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) { + int shortAnimTime = getResources().getInteger(android.R.integer.config_shortAnimTime); + + mLoginFormView.setVisibility(show ? View.GONE : View.VISIBLE); + mLoginFormView.animate().setDuration(shortAnimTime).alpha( + show ? 0 : 1).setListener(new AnimatorListenerAdapter() { + @Override + public void onAnimationEnd(Animator animation) { + mLoginFormView.setVisibility(show ? View.GONE : View.VISIBLE); + } + }); + + mProgressView.setVisibility(show ? View.VISIBLE : View.GONE); + mProgressView.animate().setDuration(shortAnimTime).alpha( + show ? 1 : 0).setListener(new AnimatorListenerAdapter() { + @Override + public void onAnimationEnd(Animator animation) { + mProgressView.setVisibility(show ? View.VISIBLE : View.GONE); + } + }); + } else { + // The ViewPropertyAnimator APIs are not available, so simply show + // and hide the relevant UI components. + mProgressView.setVisibility(show ? View.VISIBLE : View.GONE); + mLoginFormView.setVisibility(show ? View.GONE : View.VISIBLE); + } + } + + +} + diff --git a/modules/samples/android_sense/Agent/wso2_sense_agent/.svn/pristine/e2/e22a2984c2aad67d0950e4d34bd7c7016a99db92.svn-base b/modules/samples/android_sense/Agent/wso2_sense_agent/.svn/pristine/e2/e22a2984c2aad67d0950e4d34bd7c7016a99db92.svn-base new file mode 100644 index 00000000..4e2d1f46 --- /dev/null +++ b/modules/samples/android_sense/Agent/wso2_sense_agent/.svn/pristine/e2/e22a2984c2aad67d0950e4d34bd7c7016a99db92.svn-base @@ -0,0 +1,16 @@ + + +