...
 
Commits (3)
  • Rute C.  Sofia's avatar
    - added todo because of the time window which does not reflect the first time we saw a peer · 5d4515be
    Rute C. Sofia authored
    	modified:   cm_Umobile/src/main/java/com/senception/contextualmanager/services/ContextualManagerService.java
    	modified:   cm_Umobile/src/main/aidl/com/senception/contextualmanager/aidl/CManagerInterface.aidl
    	modified:   cm_Umobile/src/main/java/com/senception/contextualmanager/activities/ContextualManagerMainActivity.java
    	modified:   cm_Umobile/src/main/java/com/senception/contextualmanager/communication/ContextualManagerReceive.java
    	modified:   cm_Umobile/src/main/java/com/senception/contextualmanager/communication/ContextualManagerSend.java
    	modified:   cm_Umobile/src/main/java/com/senception/contextualmanager/databases/ContextualManagerDataSource.java
    	modified:   cm_Umobile/src/main/java/com/senception/contextualmanager/databases/ContextualManagerSQLiteHelper.java
    	modified:   cm_Umobile/src/main/java/com/senception/contextualmanager/fragments/ContextualManagerLocationDialogF.java
    	modified:   cm_Umobile/src/main/java/com/senception/contextualmanager/fragments/ContextualManagerUsageStatsDialogF.java
    	modified:   cm_Umobile/src/main/java/com/senception/contextualmanager/inference/ContextualManagerAvailability.java
    	modified:   cm_Umobile/src/main/java/com/senception/contextualmanager/inference/ContextualManagerCentrality.java
    	modified:   cm_Umobile/src/main/java/com/senception/contextualmanager/interfaces/ContextualManagerDataBaseChangeListener.java
    	modified:   cm_Umobile/src/main/java/com/senception/contextualmanager/interfaces/ContextualManagerWifiChangeListener.java
    	modified:   cm_Umobile/src/main/java/com/senception/contextualmanager/interfaces/ContextualManagerWifiP2PChangeListener.java
    	modified:   cm_Umobile/src/main/java/com/senception/contextualmanager/modals/ContextualManagerAP.java
    	modified:   cm_Umobile/src/main/java/com/senception/contextualmanager/modals/ContextualManagerPhysicalUsage.java
    	modified:   cm_Umobile/src/main/java/com/senception/contextualmanager/modals/ContextualManagerVisit.java
    	modified:   cm_Umobile/src/main/java/com/senception/contextualmanager/physical_usage/ContextualManagerBattery.java
    	modified:   cm_Umobile/src/main/java/com/senception/contextualmanager/physical_usage/ContextualManagerCPU.java
    	modified:   cm_Umobile/src/main/java/com/senception/contextualmanager/physical_usage/ContextualManagerMemory.java
    	modified:   cm_Umobile/src/main/java/com/senception/contextualmanager/physical_usage/ContextualManagerPhysicalResourceType.java
    	modified:   cm_Umobile/src/main/java/com/senception/contextualmanager/physical_usage/ContextualManagerStorage.java
    	modified:   cm_Umobile/src/main/java/com/senception/contextualmanager/pipelines/ContextualManagerFusedLocation.java
    	modified:   cm_Umobile/src/main/java/com/senception/contextualmanager/pipelines/ContextualManagerWifiManager.java
    	modified:   cm_Umobile/src/main/java/com/senception/contextualmanager/pipelines/ContextualManagerWifiP2P.java
    	modified:   cm_Umobile/src/main/java/com/senception/contextualmanager/security/MacSecurity.java
    	modified:   cm_Umobile/src/main/java/com/senception/contextualmanager/services/ContextualManagerCaptureService.java
    	modified:   cm_Umobile/src/main/java/com/senception/contextualmanager/services/ContextualManagerInterfaceService.java
    	modified:   cm_Umobile/src/main/java/com/senception/contextualmanager/services/ContextualManagerService.java
    	modified:   cm_Umobile/src/main/java/com/senception/contextualmanager/wifi/Wifi.java
    	modified:   cm_Umobile/src/main/java/com/senception/contextualmanager/wifi/p2p/Identity.java
    	modified:   cm_Umobile/src/main/java/com/senception/contextualmanager/wifi/p2p/WifiP2p.java
    	modified:   cm_Umobile/src/main/java/com/senception/contextualmanager/wifi/p2p/WifiP2pGo.java
    	modified:   cm_Umobile/src/main/java/com/senception/contextualmanager/wifi/p2p/WifiP2pListener.java
    	modified:   cm_Umobile/src/main/java/com/senception/contextualmanager/wifi/p2p/WifiP2pListenerManager.java
    	modified:   cm_Umobile/src/main/java/com/senception/contextualmanager/wifi/p2p/WifiP2pReceiver.java
    	modified:   cm_Umobile/src/main/java/com/senception/contextualmanager/wifi/p2p/WifiP2pScheduler.java
    	modified:   cm_Umobile/src/main/java/com/senception/contextualmanager/wifi/p2p/WifiP2pSearcher.java
    	modified:   cm_Umobile/src/main/java/com/senception/contextualmanager/wifi/p2p/WifiP2pTxtRecord.java
    	modified:   cm_Umobile/src/main/java/com/senception/contextualmanager/wifi/regular/WifiRegular.java
    	modified:   cm_Umobile/src/main/java/com/senception/contextualmanager/wifi/regular/WifiRegularListener.java
    	modified:   cm_Umobile/src/main/java/com/senception/contextualmanager/wifi/regular/WifiRegularListenerManager.java
    	modified:   cm_Umobile/src/main/java/com/senception/contextualmanager/wifi/regular/WifiRegularReceiver.java
    5d4515be
  • Rute C.  Sofia's avatar
    - added todo because of the time window which does not reflect the first time we saw a peer · 559d2c5f
    Rute C. Sofia authored
    	modified:   cm_Umobile/src/main/java/com/senception/contextualmanager/services/ContextualManagerService.java
    	modified:   cm_Umobile/src/main/aidl/com/senception/contextualmanager/aidl/CManagerInterface.aidl
    	modified:   cm_Umobile/src/main/java/com/senception/contextualmanager/activities/ContextualManagerMainActivity.java
    	modified:   cm_Umobile/src/main/java/com/senception/contextualmanager/communication/ContextualManagerReceive.java
    	modified:   cm_Umobile/src/main/java/com/senception/contextualmanager/communication/ContextualManagerSend.java
    	modified:   cm_Umobile/src/main/java/com/senception/contextualmanager/databases/ContextualManagerDataSource.java
    	modified:   cm_Umobile/src/main/java/com/senception/contextualmanager/databases/ContextualManagerSQLiteHelper.java
    	modified:   cm_Umobile/src/main/java/com/senception/contextualmanager/fragments/ContextualManagerLocationDialogF.java
    	modified:   cm_Umobile/src/main/java/com/senception/contextualmanager/fragments/ContextualManagerUsageStatsDialogF.java
    	modified:   cm_Umobile/src/main/java/com/senception/contextualmanager/inference/ContextualManagerAvailability.java
    	modified:   cm_Umobile/src/main/java/com/senception/contextualmanager/inference/ContextualManagerCentrality.java
    	modified:   cm_Umobile/src/main/java/com/senception/contextualmanager/interfaces/ContextualManagerDataBaseChangeListener.java
    	modified:   cm_Umobile/src/main/java/com/senception/contextualmanager/interfaces/ContextualManagerWifiChangeListener.java
    	modified:   cm_Umobile/src/main/java/com/senception/contextualmanager/interfaces/ContextualManagerWifiP2PChangeListener.java
    	modified:   cm_Umobile/src/main/java/com/senception/contextualmanager/modals/ContextualManagerAP.java
    	modified:   cm_Umobile/src/main/java/com/senception/contextualmanager/modals/ContextualManagerPhysicalUsage.java
    	modified:   cm_Umobile/src/main/java/com/senception/contextualmanager/modals/ContextualManagerVisit.java
    	modified:   cm_Umobile/src/main/java/com/senception/contextualmanager/physical_usage/ContextualManagerBattery.java
    	modified:   cm_Umobile/src/main/java/com/senception/contextualmanager/physical_usage/ContextualManagerCPU.java
    	modified:   cm_Umobile/src/main/java/com/senception/contextualmanager/physical_usage/ContextualManagerMemory.java
    	modified:   cm_Umobile/src/main/java/com/senception/contextualmanager/physical_usage/ContextualManagerPhysicalResourceType.java
    	modified:   cm_Umobile/src/main/java/com/senception/contextualmanager/physical_usage/ContextualManagerStorage.java
    	modified:   cm_Umobile/src/main/java/com/senception/contextualmanager/pipelines/ContextualManagerFusedLocation.java
    	modified:   cm_Umobile/src/main/java/com/senception/contextualmanager/pipelines/ContextualManagerWifiManager.java
    	modified:   cm_Umobile/src/main/java/com/senception/contextualmanager/pipelines/ContextualManagerWifiP2P.java
    	modified:   cm_Umobile/src/main/java/com/senception/contextualmanager/security/MacSecurity.java
    	modified:   cm_Umobile/src/main/java/com/senception/contextualmanager/services/ContextualManagerCaptureService.java
    	modified:   cm_Umobile/src/main/java/com/senception/contextualmanager/services/ContextualManagerInterfaceService.java
    	modified:   cm_Umobile/src/main/java/com/senception/contextualmanager/services/ContextualManagerService.java
    	modified:   cm_Umobile/src/main/java/com/senception/contextualmanager/wifi/Wifi.java
    	modified:   cm_Umobile/src/main/java/com/senception/contextualmanager/wifi/p2p/Identity.java
    	modified:   cm_Umobile/src/main/java/com/senception/contextualmanager/wifi/p2p/WifiP2p.java
    	modified:   cm_Umobile/src/main/java/com/senception/contextualmanager/wifi/p2p/WifiP2pGo.java
    	modified:   cm_Umobile/src/main/java/com/senception/contextualmanager/wifi/p2p/WifiP2pListener.java
    	modified:   cm_Umobile/src/main/java/com/senception/contextualmanager/wifi/p2p/WifiP2pListenerManager.java
    	modified:   cm_Umobile/src/main/java/com/senception/contextualmanager/wifi/p2p/WifiP2pReceiver.java
    	modified:   cm_Umobile/src/main/java/com/senception/contextualmanager/wifi/p2p/WifiP2pScheduler.java
    	modified:   cm_Umobile/src/main/java/com/senception/contextualmanager/wifi/p2p/WifiP2pSearcher.java
    	modified:   cm_Umobile/src/main/java/com/senception/contextualmanager/wifi/p2p/WifiP2pTxtRecord.java
    	modified:   cm_Umobile/src/main/java/com/senception/contextualmanager/wifi/regular/WifiRegular.java
    	modified:   cm_Umobile/src/main/java/com/senception/contextualmanager/wifi/regular/WifiRegularListener.java
    	modified:   cm_Umobile/src/main/java/com/senception/contextualmanager/wifi/regular/WifiRegularListenerManager.java
    	modified:   cm_Umobile/src/main/java/com/senception/contextualmanager/wifi/regular/WifiRegularReceiver.java
    559d2c5f
  • Rute C.  Sofia's avatar
package com.senception.contextualmanager.aidl;
/*
* Copyright Senception Lda
* @author Jose Soares (jose.soares@senception.com)
* This aidl file contains all the methods that contextual manager
* provides to clients.
* */
......@@ -10,9 +12,5 @@ interface CManagerInterface {
Map getCentrality(in List<String> peerList);
Map getSimilarity(in List<String> peerList);
//ContextualManagerSimilarity
//double [] getI(TYPE, NODE);
//List<String> getAll(in);
//"A.C.I"
}
\ No newline at end of file
......@@ -34,9 +34,9 @@ import com.senception.contextualmanager.services.ContextualManagerService;
import com.senception.contextualmanager.services.ContextualManagerInterfaceService;
/**
* Copyright (C) 2016 Senception Lda
* Update to Contextual Manager 2017
* @author Igor dos Santos - [email protected]-ception.com
* Copyright (C) Senception Lda
* Update to Contextual Manager 2017-2018
* @author Igor dos Santos - [email protected]
* @author José Soares - [email protected]
* @version 0.1
*
......@@ -55,7 +55,7 @@ public class ContextualManagerMainActivity extends Activity {
private boolean mIsServiceBound = false;
/**
* The Connection to the PerSense Light service.
* The Connection to the CM service.
*/
private ServiceConnection reportConnection = new ServiceConnection() {
......@@ -106,7 +106,11 @@ public class ContextualManagerMainActivity extends Activity {
FragmentManager manager = getFragmentManager();
//Asks user for permission to get usage stats
/*
* Asks user for permission to get usage stats
* Stats are used only LOCALLY, and to compute weights
*/
if(!ContextualManagerPermissions.usageStatsPermission(getApplicationContext())) {
ContextualManagerUsageStatsDialogF usageDialog = ContextualManagerUsageStatsDialogF.newInstance(getString(R.string.usage_stats), getString(R.string.usage_stats_msg));
usageDialog.show(manager, "Dialog");
......@@ -118,6 +122,7 @@ public class ContextualManagerMainActivity extends Activity {
Log.d(TAG, "ContextualManagerCaptureService started.");
//Asks user for permission to get device location
if(!ContextualManagerPermissions.isLocationEnabled(getApplicationContext())){
ContextualManagerLocationDialogF locationDialog = ContextualManagerLocationDialogF.newInstance(getString(R.string.location), getString(R.string.location_msg));
locationDialog.show(manager, "Dialog");
......
......@@ -17,14 +17,15 @@ import java.util.Map;
/**
* Copyright (C) 2016 Senception Lda
* Update to Contextual Manager 2017
* @author Igor dos Santos - [email protected]-ception.com
* Copyright (C) Senception Lda
* Update to Contextual Manager 2018
* @author Igor dos Santos - [email protected]
* @author José Soares - [email protected]
* @version 0.1
*
* @file Contains ContextualManagerReceive. This class is used
* to receive information from contextual managers (A,C)
* to receive information from contextual managers
* We send directly the values A (availability), C (Centrality) and I (similarity)
*/
public class ContextualManagerReceive implements WifiP2pListener.TxtRecordAvailable {
......@@ -33,7 +34,7 @@ public class ContextualManagerReceive implements WifiP2pListener.TxtRecordAvaila
private Context mContext;
/**
* Constructs a contectualManagerReceive that will be attempting to
* Constructs a contextualManagerReceive that will be attempting to
* receive the availability and centrality from other peers that are
* also running the Contextual Manager.
* @param context
......@@ -47,13 +48,12 @@ public class ContextualManagerReceive implements WifiP2pListener.TxtRecordAvaila
@Override
public void onTxtRecordAvailable(String fullDomainName, Map<String, String> txtRecordMap, WifiP2pDevice srcDevice) {
//TODO resolve error: getting txtrecord with a and c null ---> Cannot reproduce error.
if(txtRecordMap != null && txtRecordMap.size() != 0) {
if(txtRecordMap != null && txtRecordMap.size() != 0) {
//Log.d(TAG, "txtRecord: " + txtRecordMap.toString());
Log.d(TAG, "received from" + srcDevice.deviceName);
//Log.d(TAG, "received from" + srcDevice.deviceName);
String a = txtRecordMap.get(Identity.AVAILABILITY);
String c = txtRecordMap.get(Identity.CENTRALITY);
Log.d("teste", "Received a: " + a + "\t c : " + c);
Log.d(TAG, "Received a: " + a + "\t c : " + c);
double A = 0;
double C = 0;
......@@ -63,24 +63,25 @@ public class ContextualManagerReceive implements WifiP2pListener.TxtRecordAvaila
C = Double.parseDouble(c);
}
String hashSrcDeviceBSSID = MacSecurity.md5Hash(srcDevice.deviceAddress);
String hashSrcDeviceHashedMac = MacSecurity.md5Hash(srcDevice.deviceAddress);
//if it's the first time we see this peer we save it
if (!dataSource.hasPeer(hashSrcDeviceBSSID, ContextualManagerService.checkWeek("peers"))) {
if (!dataSource.hasPeer(hashSrcDeviceHashedMac, ContextualManagerService.checkWeek("peers"))) {
ContextualManagerAP peer = new ContextualManagerAP();
peer.setSSID(srcDevice.deviceName);
peer.setBSSID(hashSrcDeviceBSSID);
peer.setHashedMac(hashSrcDeviceHashedMac);
//TODO peer.setLatitude(latitude);
//TODO peer.setLongitude(longitude);
peer.setAvailability(A);
peer.setCentrality(C);
peer.setNumEncounters(1);
peer.setStartEncounter((int)(System.currentTimeMillis()/1000)); //time in seconds System.currentTimeMillis()/1000
//time in seconds System.currentTimeMillis()/1000
peer.setStartEncounter((int)(System.currentTimeMillis()/1000));
dataSource.registerNewPeers(peer, ContextualManagerService.checkWeek("peers"));
} else {
ContextualManagerAP peer = dataSource.getPeer(hashSrcDeviceBSSID, ContextualManagerService.checkWeek("peers"));
ContextualManagerAP peer = dataSource.getPeer(hashSrcDeviceHashedMac, ContextualManagerService.checkWeek("peers"));
peer.setSSID(srcDevice.deviceName);
peer.setBSSID(hashSrcDeviceBSSID);
peer.setHashedMac(hashSrcDeviceHashedMac);
peer.setAvailability(A);
peer.setCentrality(C);
//TODO peer.setLatitude(latitude);
......
......@@ -14,14 +14,16 @@ import java.util.Timer;
import java.util.TimerTask;
/**
* Copyright (C) 2016 Senception Lda
* Copyright (C) Senception Lda
* Update to Contextual Manager 2017
* @author Igor dos Santos - [email protected]-ception.com
* @author Igor dos Santos - [email protected]
* @author José Soares - [email protected]
* @author Rute Sofia
* @version 0.1
*
* @file Contains ContextualManagerSend. This class is used
* to send information to other contextual managers (A,C)
* to send information to other contextual managers, namely values A (Availability, C (Centrality) and I (similarity cost to a peer)
* Check UMOBILE Deliverable D4.5 for details on the cost computation
*/
public class ContextualManagerSend {
......@@ -30,13 +32,13 @@ public class ContextualManagerSend {
/**
* /**
* Constructs a contectualManagerSend that will be attempting to
* send the availability and centrality to other peers that are
* Constructs a contextualManagerSend that will be attempting to
* send the Availability and Centrality to other peers that are
* also running the Contextual Manager.
* This is done directly, via Wi-Fi Direct (or via any other direct connection)
* @param context
*/
public ContextualManagerSend(Context context) {
//TODO resolve error: getting txtrecord with a and c null ---> Cannot reproduce error.
mContext = context;
new Timer().scheduleAtFixedRate(new TimerTask() {
......@@ -51,15 +53,15 @@ public class ContextualManagerSend {
Log.d(TAG, "Sending A: " + A + "\t C: " + C);
String AToSend = String.valueOf(A);
String CToSend = String.valueOf(C);
//Log.d("teste", "AToSend :" + AToSend + "\t CToSend: " + CToSend);//Todo: Find bug - Find out when can A or C null
WifiP2pTxtRecord.setRecord(mContext, Identity.AVAILABILITY, AToSend);
WifiP2pTxtRecord.setRecord(mContext, Identity.CENTRALITY, CToSend);
//Log.d(TAG, "Sent A and C");
Log.d(TAG, "Sent A and C");
}
else{
Log.d(TAG, "Table is still empty so we can't send the availability and centrality.");
}
// TODO adjust the time the data is being sent. Currently it is being sent every 10 seconds for demo purpose only.
}
}, 0, 10*1000); //todo every 5 min
}, 0, 10*1000);
}
}
......@@ -21,10 +21,10 @@ import android.util.Log;
import com.senception.contextualmanager.services.ContextualManagerCaptureService;
/**
* Copyright (C) 2016 Senception Lda
* Copyright (C) Senception Lda
* Author(s): Igor dos Santos - [email protected] *
* José Soares - [email protected]
* Update to Contextual Manager 2017
* Update to Contextual Manager 2018
* @author Igor dos Santos
* @author José Soares
* @version 0.1
......@@ -76,10 +76,13 @@ public class ContextualManagerSQLiteHelper extends SQLiteOpenHelper {
public static final String COLUMN_NUM_ENCOUNTERS = "encounters";
public static final String COLUMN_AVG_ENCOUNTER_DURATION = "avgduration";
public static final String COLUMN_IS_CONNECTED = "connected";
public static final String COLUMN_SIMILARITY = "i"; // Similarity of a node (measures the node's similarity).
// Similarity of a node (measures the node's similarity with a peer)
public static final String COLUMN_SIMILARITY = "i";
//2)PEER (SELF)
public static final String COLUMN_AVAILABILITY = "a"; // Internal Usage weight of a node (measures the availability of the node)
public static final String COLUMN_CENTRALITY = "c"; // Affinity network level of a node (measures node's centrality/popularity).
// Internal Usage weight of a node (measures the availability of the node)
public static final String COLUMN_AVAILABILITY = "a";
// Affinity network level of a node (measures node's centrality/popularity).
public static final String COLUMN_CENTRALITY = "c";
// VISITS
public static final String COLUMN_TIMEON = "timeon";
......@@ -94,11 +97,6 @@ public class ContextualManagerSQLiteHelper extends SQLiteOpenHelper {
public static final String COLUMN_APP_NAME = "appname";
public static final String COLUMN_APP_CATEGORY = "appcategory";
/* Measures the (eigenvector) similarity between the selected resource of node I and j.
For instance, I can provide a measure of battery similarity over time between nodes.
Or, it can provide a measure of similarity between category of applications.*/
//public static final String COLUMN_I = "i"
private static final String CREATE_MONDAY_TABLE = "create table "
+ TABLE_MONDAY + "("
+ COLUMN_ID + " integer primary key autoincrement, "
......
......@@ -10,10 +10,10 @@ import android.provider.Settings;
import com.senception.contextualmanager.R;
/**
* Copyright (C) 2016 Senception Lda
* Author(s): Igor dos Santos - [email protected]-ception.com *
* Copyright (C) Senception Lda
* Author(s): Igor dos Santos - [email protected] *
* José Soares - [email protected]
* Update to Contextual Manager 2017
* Update to Contextual Manager 2018
* @author Igor dos Santos
* @author José Soares
* @version 0.1
......
......@@ -11,10 +11,10 @@ import android.provider.Settings;
import com.senception.contextualmanager.R;
/**
* Copyright (C) 2016 Senception Lda
* Author(s): Igor dos Santos - [email protected]-ception.com *
* Copyright (C) Senception Lda
* Author(s): Igor dos Santos - [email protected] *
* José Soares - [email protected]
* Update to Contextual Manager 2017
* Update to Contextual Manager 2018
* @author Igor dos Santos
* @author José Soares
* @version 0.1
......
......@@ -8,7 +8,7 @@ import com.senception.contextualmanager.services.ContextualManagerCaptureService
import java.util.ArrayList;
/**
* Copyright (C) 2016 Senception Lda
* Copyright (C) Senception Lda
* Author(s): Igor dos Santos - [email protected] *
* José Soares - [email protected]
* Update to Contextual Manager 2017/2018
......@@ -44,9 +44,7 @@ public class ContextualManagerAvailability {
// Availability is an weighted average of all values of r
// @todo improve the average accuracy, by using another type of weighted average
Availability = Availability/t;
Log.d("teste", "r is:"+rList.toString());
Log.d("teste", "t is:"+t);
Log.d("teste", "Availability A = " + Availability);
Log.d("calculateA", "Availability A = " + Availability);
return Availability;
}
......@@ -62,20 +60,21 @@ public class ContextualManagerAvailability {
ArrayList<Double> res = new ArrayList<>();
for (int i = 0; i < usagePerHour1.size(); i++) {
//-1 + -1 = -1
if(usagePerHour1.get(i) == -1 && usagePerHour2.get(i) == -1){
if(usagePerHour1.get(i) == -1 && usagePerHour2.get(i) == -1){
res.add(usagePerHour1.get(i));
}
//-1+30 = 30 --> 30/currentHour
/* for proof-of-concept demo, we are using an array with 60 positions (60 minutes). Originally this was intended for 24 positions
* TODO adjust to the best value e.g., availability per minute, availability per hour, etc
*/
else if ( usagePerHour1.get(i) == -1 && usagePerHour2.get(i) != -1){
res.add(usagePerHour2.get(i) / (System.currentTimeMillis() - ContextualManagerCaptureService.TIMESTAMP)/60*1000);
}
//30+-1 = 30 --> 30/currentHour
else if (usagePerHour2.get(i) == -1 && usagePerHour1.get(i) != -1){
res.add(usagePerHour1.get(i) / (System.currentTimeMillis() - ContextualManagerCaptureService.TIMESTAMP)/60*1000);
}
//30+30 = 60 --> 60/currentHour
else{ // Maybe we should use the time in hours instead of minutes
else{
res.add((usagePerHour1.get(i) + usagePerHour2.get(i)) / ( (System.currentTimeMillis() - ContextualManagerCaptureService.TIMESTAMP)/60*1000)); //todo optimize without dividing for the hour in the sumArrays method
}
}
......@@ -93,15 +92,15 @@ public class ContextualManagerAvailability {
*/
public static ArrayList<Double> calculateR(ArrayList<Double> e, ArrayList<Double>
cpu, ArrayList<Double> mem, ArrayList<Double> storage){
Log.d("teste", "e = " + e.toString());
Log.d("teste", "cpu = " + cpu.toString());
Log.d("teste", "mem = " + mem.toString());
Log.d("teste", "s = " + storage.toString());
ArrayList<Double> e2 = multiplyArrays(e, e); // e square
ArrayList<Double> e2Cpu = multiplyArrays(e2, cpu); // e2 * cpu
ArrayList<Double> memStor = multiplyArrays(mem, storage); // mem * storage
ArrayList<Double> r = multiplyArrays(e2Cpu, memStor);
//todo resources between [0..100], but we need r between [0..1]
Log.d("calculateR", "e = " + e.toString());
Log.d("calculateR", "cpu = " + cpu.toString());
Log.d("calculateR", "mem = " + mem.toString());
Log.d("calculateR", "s = " + storage.toString());
ArrayList<Double> e2 = multiplyArrays(e, e); // battery is squared, as it has more weight than the other values
ArrayList<Double> e2Cpu = multiplyArrays(e2, cpu); // e2cpu concerns available CPU
ArrayList<Double> memStor = multiplyArrays(mem, storage); // memstor multiplies memory and storage
ArrayList<Double> r = multiplyArrays(e2Cpu, memStor); //final result for r
// set r to be between 0 and 1
double d = Math.pow(100,5);
for (int i = 0; i < r.size(); i++) {
if(r.get(i) != -1){
......
......@@ -8,9 +8,9 @@ import java.util.ArrayList;
import static com.senception.contextualmanager.services.ContextualManagerService.checkWeek;
/**
* Copyright (C) 2016 Senception Lda
* Author(s): Igor dos Santos - [email protected] *
* José Soares - [email protected]
* Copyright (C) Senception Lda
* Author(s): Igor dos Santos - [email protected]
* José Soares - [email protected]
* Update to Contextual Manager 2017
* @author Igor dos Santos
* @author José Soares
......@@ -21,7 +21,7 @@ import static com.senception.contextualmanager.services.ContextualManagerService
*/
public class ContextualManagerCentrality {
//Formula: C(i) = 1/λ Σj A(j) * p(j)
//Formula: C(i) = 1/λ Σj A(j) * p(j), see deliverable D4.5 from H2020 UMOBILE
/*
p(j)= (encounter * average_encounter_duration)/ (d(i,j) + 1)
......@@ -41,17 +41,18 @@ public class ContextualManagerCentrality {
* Formula considers, for node i and neighbors j, the numEncounters(i,j) and the
* avgEncounterDuration(i,j)
* it splits the numEncounters*avgEncounterDuration per d, which is the distance in meters
* @todo use the Haversine formula to compute the distance between the two nodes
* TODO use the Haversine formula to compute the distance between the two nodes
* Currently, we have set distance to always be one.
* @param dataSource
* @return centrality - the centrality of the device
*/
//NOTE: In the beginning the calculated C will present often as 0.0
//NOTE: In the beginning the calculated C MAY be 0, as it is based on encounter duration, and peer encounter
public static double calculateC(ContextualManagerDataSource dataSource){
int numEncounters=0;
double avgEncDur=0;
double distance = 1; // we're not taking into consideration the distance in this implementation -> only in the future
// TODO: consider the distance between devices based on their coordinates
double distance = 1;
double lambda = 1;
double i=0;
/* work on peer list
......@@ -65,7 +66,7 @@ public class ContextualManagerCentrality {
i=1;
for (ContextualManagerAP peer : peerList) {
if (peer.getIsConnected() == 1) {
// @todo distance based on Haversive formula
// TODO distance based on Haversive formula
centrality = centrality+(peer.getNumEncounters()*peer.getAvgEncounterDuration())/distance;
++i;
}
......@@ -73,12 +74,12 @@ public class ContextualManagerCentrality {
}
/* simplification of lambda, just the ratio of connected peers against all peers
* the more connected peers, the higher the centrality
* TODO use an eigenvalue formulation for lambda
*/
lambda = i/peerList.size();
}
centrality = centrality * 1/lambda;
// centrality = centrality/(System.currentTimeMillis()- ContextualManagerCaptureService.TIMESTAMP)/60000;
return centrality;
}
}
......@@ -5,10 +5,10 @@ import com.senception.contextualmanager.modals.ContextualManagerAP;
import java.util.List;
/**
* Copyright (C) 2016 Senception Lda
* Author(s): Igor dos Santos - [email protected]-ception.com *
* Copyright (C) Senception Lda
* Author(s): Igor dos Santos - [email protected]ception.com
* José Soares - [email protected]
* Update to Contextual Manager 2017
* Update to Contextual Manager 2017/2018
* @author Igor dos Santos
* @author José Soares
* @version 0.1
......
......@@ -4,15 +4,15 @@ import java.util.List;
import android.net.wifi.ScanResult;
/**
* Copyright (C) 2016 Senception Lda
* Author(s): Igor dos Santos - [email protected]-ception.com *
* Copyright (C) Senception Lda
* Author(s): Igor dos Santos - [email protected] *
* José Soares - [email protected]
* Update to Contextual Manager 2017
* Update to Contextual Manager 2017-2018
* @author Igor dos Santos
* @author José Soares
* @version 0.1
*
* @file Contains PerSenseWifiChangeListener. This class provides an interface that listen Wifi Connection
* @file Contains PerSenseWifiChangeListener. This class provides an interface that listens to the Wi-Fi connection
*
*/
public interface ContextualManagerWifiChangeListener {
......
......@@ -5,10 +5,10 @@ import com.senception.contextualmanager.modals.ContextualManagerAP;
import java.util.ArrayList;
/**
* Copyright (C) 2016 Senception Lda
* Author(s): Igor dos Santos - [email protected]-ception.com *
* Copyright (C) Senception Lda
* Author(s): Igor dos Santos - [email protected] *
* José Soares - [email protected]
* Update to Contextual Manager 2017
* Update to Contextual Manager 2017-2018
* @author Igor dos Santos
* @author José Soares
* @version 0.1
......@@ -17,6 +17,6 @@ import java.util.ArrayList;
*
*/
public interface ContextualManagerWifiP2PChangeListener {
void onFoundPersenceGroup(ArrayList<ContextualManagerAP> disc, ArrayList<ContextualManagerAP> reg);
void onFoundGroup(ArrayList<ContextualManagerAP> disc, ArrayList<ContextualManagerAP> reg);
void onPeersFound(ArrayList<ContextualManagerAP> disc);
}
package com.senception.contextualmanager.modals;
/**
* Copyright (C) 2016 Senception Lda
* Author(s): Igor dos Santos - [email protected]-ception.com *
* Copyright (C) Senception Lda
* Author(s): Igor dos Santos - [email protected]ception.com
* José Soares - [email protected]
* Update to Contextual Manager 2017
* Update to Contextual Manager 2017/2018
* @author Igor dos Santos
* @author José Soares
* @version 0.1
*
* @file Contains ContextualManagerAP. This class represents objects that PerSense Light considers
* @file Contains ContextualManagerAP. This class holds a generic object for a device stored by the CM
*
*/
public class ContextualManagerAP {
private int id;
private String SSID; //Name of the WAP
private String BSSID; //Mac address of the WAP (wireless access point)
private String SSID; //Name of the Device.
private String HashedMac; //MAC address of the device
private double attractiveness; //TODO since it's not used in this vertion, delete.
private String dateTime;
private String DayOfWeek;
......@@ -57,19 +57,19 @@ public class ContextualManagerAP {
}
/**
*Get the bssid of this AP
*@return the bssid
*Get the HashedMac of this AP
*@return the HashedMac
*/
public String getBSSID() {
return BSSID;
public String getHashedMac() {
return HashedMac;
}
/**
*Set the bssid of this AP
*@param bSSID the bssid to set
*Set the HashedMac of this AP
*@param HashedMAC the HashedMac to set
*/
public void setBSSID(String bSSID) {
BSSID = bSSID;
public void setHashedMac(String HashedMAC) {
HashedMac = HashedMAC;
}
/**
......
......@@ -6,10 +6,10 @@ import java.util.ArrayList;
import java.util.Calendar;
/**
* Copyright (C) 2016 Senception Lda
* Author(s): Igor dos Santos - [email protected]-ception.com *
* Copyright (C) Senception Lda
* Author(s): Igor dos Santos - [email protected] *
* José Soares - [email protected]
* Update to Contextual Manager 2017
* Update to Contextual Manager 2017/2018
* @author Igor dos Santos
* @author José Soares
* @version 0.1
......
......@@ -18,7 +18,7 @@ import java.text.SimpleDateFormat;
public class ContextualManagerVisit {
private String SSID;
private String BSSID;
private String HashedMac;
private Long startTime;
private Long endTime;
private int dayOfTheWeek;
......@@ -41,18 +41,18 @@ public class ContextualManagerVisit {
SSID = sSID;
}
/**
* Get bssid of the AP
* @return the BSSID
* Get HashedMac of the AP
* @return the HashedMac
*/
public String getBSSID() {
return BSSID;
public String getHashedMac() {
return HashedMac;
}
/**
* Set the bssid of the AP
* @param bSSID the bssid to set
* Set the HashedMac of the AP
* @param HashedMac the HashedMac to set
*/
public void setBSSID(String bSSID) {
BSSID = bSSID;
public void setHashedMac(String HashedMac) {
HashedMac = HashedMac;
}
/**
* Get start time of the AP
......@@ -124,15 +124,15 @@ public class ContextualManagerVisit {
this.endTime = null;
}
/**
* Update the ssid, bssid, start time and end time of the AP
* Update the ssid, HashedMac, start time and end time of the AP
* @param SSID the ssid to set
* @param BSSID the bssid to set
* @param HashedMac the HashedMac to set
* @param startTime the start time to set
* @param endTime the end time to set
*/
public void update(String SSID, String BSSID, Long startTime, Long endTime){
public void update(String SSID, String HashedMac, Long startTime, Long endTime){
this.SSID = SSID;
this.BSSID = BSSID;
this.HashedMac = HashedMac;
this.startTime = startTime;
this.endTime = endTime;
}
......
......@@ -7,10 +7,10 @@ import android.os.BatteryManager;
import android.util.Log;
/**
* Copyright (C) 2016 Senception Lda
* Author(s): Igor dos Santos - [email protected]-ception.com *
* Copyright (C) Senception Lda
* Author(s): Igor dos Santos - [email protected] *
* José Soares - [email protected]
* Update to Contextual Manager 2017
* Update to Contextual Manager 2017-2018
* @author Igor dos Santos
* @author José Soares
* @version 0.1
......
......@@ -7,10 +7,10 @@ import java.io.IOException;
import java.io.InputStreamReader;
/**
* Copyright (C) 2016 Senception Lda
* Author(s): Igor dos Santos - [email protected]-ception.com *
* Copyright (C) Senception Lda
* Author(s): Igor dos Santos - [email protected] *
* José Soares - [email protected]
* Update to Contextual Manager 2017
* Update to Contextual Manager 2017/2018
* @author Igor dos Santos
* @author José Soares
* @version 0.1
......
......@@ -6,10 +6,10 @@ import android.content.Context;
import static android.content.Context.ACTIVITY_SERVICE;
/**
* Copyright (C) 2016 Senception Lda
* Author(s): Igor dos Santos - [email protected]-ception.com *
* Copyright (C) Senception Lda
* Author(s): Igor dos Santos - [email protected] *
* José Soares - [email protected]
* Update to Contextual Manager 2017
* Update to Contextual Manager 2017/2018
* @author Igor dos Santos
* @author José Soares
* @version 0.1
......
package com.senception.contextualmanager.physical_usage;
/**
* Copyright (C) 2016 Senception Lda
* Author(s): Igor dos Santos - [email protected]-ception.com *
* Copyright (C) Senception Lda
* Author(s): Igor dos Santos - [email protected] *
* José Soares - [email protected]
* Update to Contextual Manager 2017
* Update to Contextual Manager 2017/2018
* @author Igor dos Santos
* @author José Soares
* @version 0.1
......
......@@ -5,10 +5,10 @@ import android.os.Environment;
import android.os.StatFs;
/**
* Copyright (C) 2016 Senception Lda
* Author(s): Igor dos Santos - [email protected]-ception.com *
* Copyright (C) Senception Lda
* Author(s): Igor dos Santos - [email protected] *
* José Soares - [email protected]
* Update to Contextual Manager 2017
* Update to Contextual Manager 2017/2018
* @author Igor dos Santos
* @author José Soares
* @version 0.1
......
......@@ -12,10 +12,10 @@ import android.location.Location;
import android.os.Bundle;
/**
* Copyright (C) 2016 Senception Lda
* Author(s): Igor dos Santos - [email protected]-ception.com *
* Copyright (C) Senception Lda
* Author(s): Igor dos Santos - [email protected] *
* José Soares - [email protected]
* Update to Contextual Manager 2017
* Update to Contextual Manager 2017/2018
* @author Igor dos Santos
* @author José Soares
* @version 0.1
......@@ -104,7 +104,7 @@ public class ContextualManagerFusedLocation implements LocationListener, GoogleA
if(location != null){
mCurrentLocation = location;
String recvBssid = ContextualManagerService.getFusedBssid();
String recvBssid = ContextualManagerService.getFusedHashedMac();
String recvSsid = ContextualManagerService.getFusedSsid();
int recvNoCoor = ContextualManagerService.getNoCoordinate();
if(recvNoCoor == 1 && recvBssid != null && recvSsid != null){
......
......@@ -14,10 +14,10 @@ import android.os.Handler;
import com.senception.contextualmanager.interfaces.ContextualManagerWifiChangeListener;
/**
* Copyright (C) 2016 Senception Lda
* Author(s): Igor dos Santos - [email protected]-ception.com *
* Copyright (C) Senception Lda
* Author(s): Igor dos Santos - [email protected] *
* José Soares - [email protected]
* Update to Contextual Manager 2017
* Update to Contextual Manager 2017/2018
* @author Igor dos Santos
* @author José Soares
* @version 0.1
......
/**
* Copyright (C) 2016 Senception Lda
* Author(s): Igor dos Santos - [email protected]-ception.com *
* Copyright (C) Senception Lda
* Author(s): Igor dos Santos - [email protected] *
* José Soares - [email protected]
* Update to Contextual Manager 2017
* Update to Contextual Manager 2017/2018
* @author Igor dos Santos
* @author José Soares
* @version 0.1
......@@ -77,7 +77,7 @@ public class ContextualManagerWifiP2P extends BroadcastReceiver implements WifiP
ContextualManagerAP peerfound = new ContextualManagerAP();
peerfound.setSSID(dev.deviceName);
peerfound.setBSSID(dev.deviceAddress);
peerfound.setHashedMac(dev.deviceAddress);
peersList.add(peerfound);
}
......
package com.senception.contextualmanager.security;
/**
* Created by Senception on 16/03/2018.
* Copyright (C) Senception Lda
* Author(s):
* José Soares - [email protected]
* Update to Contextual Manager 2017/2018
* @author Igor dos Santos
* @author José Soares
* @version 0.1
*
* @file Class to get the memory usage.
*
*/
public class MacSecurity {
......
......@@ -277,10 +277,10 @@ public class ContextualManagerCaptureService extends Service {
/* Saves A and C into the database */
ContextualManagerAP mySelf = new ContextualManagerAP();
mySelf.setSSID("self");
mySelf.setBSSID(MacSecurity.md5Hash("self"));
mySelf.setHashedMac(MacSecurity.md5Hash("self"));
mySelf.setAvailability(Availability);
mySelf.setCentrality(C);
if(!dataSource.hasPeer(mySelf.getBSSID(), ContextualManagerService.checkWeek("peers"))) {
if(!dataSource.hasPeer(mySelf.getHashedMac(), ContextualManagerService.checkWeek("peers"))) {
dataSource.registerNewPeers(mySelf, ContextualManagerService.checkWeek("peers"));
}
else {
......
......@@ -13,10 +13,10 @@ import java.util.Map;
import static com.senception.contextualmanager.services.ContextualManagerService.checkWeek;
/**
* Copyright (C) 2016 Senception Lda
* Author(s): Igor dos Santos - [email protected]-ception.com *
* Copyright (C) Senception Lda
* Author(s): Igor dos Santos - [email protected] *
* José Soares - [email protected]
* Update to Contextual Manager 2017
* Update to Contextual Manager 2017/2018
* @author Igor dos Santos
* @author José Soares
* @version 0.1
......
......@@ -12,7 +12,7 @@ import com.senception.contextualmanager.wifi.p2p.WifiP2p;
import com.senception.contextualmanager.wifi.regular.WifiRegular;
/**
* 2017 COPELABS/ULHT
* Copyright Senception Lda
* Update to Contextual Manager 2018 Senception Lda
* @author Miguel Tavares (COPELABS/ULHT)
* @author José Soares (Senception Lda) - [email protected]
......
package com.senception.contextualmanager.wifi.p2p;
/**
* Copyright Senception Lda
* Author(s): Miguel Tavares
* José Soares - [email protected]
* Update to Contextual Manager 2018
......@@ -8,7 +9,7 @@ package com.senception.contextualmanager.wifi.p2p;
* @author José Soares (Senception Lda)
* @version 1.1, 2018
*
* @file Used to indentify the peer as cm, and to
* @file Used to indentify the peer as a cm node, and to
* indicate that it will be transmitting the availability,
* centrality and similarity.
*/
......
......@@ -18,7 +18,7 @@ import static android.net.wifi.p2p.WifiP2pManager.WIFI_P2P_STATE_CHANGED_ACTION;
/**
* 2017 COPELABS/ULHT
* Copyright Senception Lda
* Update to Contextual Manager 2018 Senception Lda
* @author Miguel Tavares (COPELABS/ULHT)
* @author José Soares (Senception Lda) - [email protected]n.com
......
......@@ -16,7 +16,7 @@ import android.util.Log;
import java.util.Map;
/**
* 2017 COPELABS/ULHT
* Copyright Senception Lda
* Update to Contextual Manager 2018 Senception Lda
* @author Miguel Tavares (COPELABS/ULHT)
* @author José Soares (Senception Lda) - [email protected]
......
......@@ -13,7 +13,7 @@ import android.net.wifi.p2p.WifiP2pDeviceList;
import java.util.Map;
/**
* 2017 COPELABS/ULHT
* Copyright Senception Lda
* Update to Contextual Manager 2018 Senception Lda
* @author Miguel Tavares (COPELABS/ULHT)
* @author José Soares (Senception Lda) - [email protected]
......
......@@ -16,7 +16,7 @@ import java.util.List;
import java.util.Map;
/**
* 2017 COPELABS/ULHT
* Copyright Senception Lda
* Update to Contextual Manager 2018 Senception Lda
* @author Miguel Tavares (COPELABS/ULHT)
* @author José Soares (Senception Lda) - [email protected]
......
......@@ -21,7 +21,7 @@ import static android.net.wifi.p2p.WifiP2pManager.WIFI_P2P_PEERS_CHANGED_ACTION;
import static android.net.wifi.p2p.WifiP2pManager.WIFI_P2P_STATE_CHANGED_ACTION;
/**
* 2017 COPELABS/ULHT
* Copyright Senception Lda
* Update to Contextual Manager 2018 Senception Lda
* @author Miguel Tavares (COPELABS/ULHT)
* @author José Soares (Senception Lda) - [email protected]
......
......@@ -12,7 +12,7 @@ import android.util.Log;
import java.util.Random;
/**
* 2017 COPELABS/ULHT
* Copyright Senception Lda
* Update to Contextual Manager 2018 Senception Lda
* @author Miguel Tavares (COPELABS/ULHT)
* @author José Soares (Senception Lda) - [email protected]
......
......@@ -22,7 +22,7 @@ import com.senception.contextualmanager.services.ContextualManagerService;
import java.util.Map;
/**
* 2017 COPELABS/ULHT
* Copyright Senception Lda
* Update to Contextual Manager 2018 Senception Lda
* @author Miguel Tavares (COPELABS/ULHT)
* @author José Soares (Senception Lda) - [email protected]
......
......@@ -9,7 +9,7 @@ import java.util.Map;
import static android.content.Context.MODE_PRIVATE;
/**
* 2017 COPELABS/ULHT
* Copyright Senception Lda
* Update to Contextual Manager 2018 Senception Lda
* @author Miguel Tavares (COPELABS/ULHT)
* @author José Soares (Senception Lda) - [email protected]
......
......@@ -4,6 +4,15 @@ import android.content.Context;
import android.content.IntentFilter;
import android.util.Log;
/**
* Copyright (C) Senception Lda
* Update to Contextual Manager 2017-2018
* @author José Soares - [email protected]
* @version 0.1
*
* @file holds WifiRegular, to set the Wi-Fi receiver
*/
import static android.net.wifi.WifiManager.NETWORK_STATE_CHANGED_ACTION;
public class WifiRegular {
......
package com.senception.contextualmanager.wifi.regular;
/**
* Copyright (C) Senception Lda
* Update to Contextual Manager 2017-2018
* @author José Soares - [email protected]
* @version 0.1
*
* @file holds WifiRegular, to set the Wi-Fi
*/
public interface WifiRegularListener {
void onConnected();
......
......@@ -6,6 +6,16 @@ import android.util.Log;
import java.util.ArrayList;
import java.util.List;
/**
* Copyright (C) Senception Lda
* Update to Contextual Manager 2017-2018
* @author José Soares - [email protected]
* @version 0.1
*
* @file holds WifiRegular, to set the Wi-Fi Listener
*/
public class WifiRegularListenerManager {
private static final String TAG = WifiRegularListenerManager.class.getSimpleName();
......
package com.senception.contextualmanager.wifi.regular;
/**
* Copyright (C) Senception Lda
* Update to Contextual Manager 2017-2018
* @author José Soares - [email protected]
* @version 0.1
*
* @file holds WifiRegularReceiver, to set the Wi-Fi Receiver
*/
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
......