Add new sensors to the android sense plugin

Incoming and outgoing calls tracker
    Screen on off detector
    SMS tracker
    Audio playing and headset tracker
    Application install and uninstall detector
    User activity detector
revert-dabc3590
Gobinath 8 years ago
parent 215fd51ffb
commit ab418dbde3

@ -61,4 +61,5 @@ dependencies {
compile 'org.altbeacon:android-beacon-library:2.8.1'
compile 'uk.co.alt236:easycursor-android:1.0.0'
compile 'uk.co.alt236:bluetooth-le-library-android:1.0.0'
compile 'com.google.android.gms:play-services-location:9.4.0'
}

@ -11,11 +11,16 @@
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.BATTERY_STATS" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-sdk android:minSdkVersion="19" />
<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="com.google.android.gms.permission.ACTIVITY_RECOGNITION" />
<uses-permission android:name="android.permission.RECEIVE_SMS"/>
<uses-permission android:name="android.permission.READ_SMS" />
<uses-sdk android:minSdkVersion="19" />
<application
android:allowBackup="true"
@ -45,6 +50,8 @@
android:label="@string/app_name" >
</service>
<service android:name="org.wso2.carbon.iot.android.sense.event.streams.activity.ActivityReceiver"/>
<receiver android:name="org.wso2.carbon.iot.android.sense.event.SenseScheduleReceiver" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
@ -53,13 +60,6 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</receiver>
<receiver
android:name="org.wso2.carbon.iot.android.sense.event.streams.battery.BatteryDataReceiver"
android:exported="true" >
<intent-filter>
<action android:name="android.intent.action.BATTERY_CHANGED" />
</intent-filter>
</receiver>
<activity
android:name="org.wso2.carbon.iot.android.sense.realtimeviewer.ActivitySelectSensor"

@ -25,20 +25,24 @@ import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.wso2.carbon.iot.android.sense.beacon.BeaconScanedData;
import org.wso2.carbon.iot.android.sense.constants.SenseConstants;
import org.wso2.carbon.iot.android.sense.data.publisher.mqtt.AndroidSenseMQTTHandler;
import org.wso2.carbon.iot.android.sense.data.publisher.mqtt.transport.MQTTTransportHandler;
import org.wso2.carbon.iot.android.sense.data.publisher.mqtt.transport.TransportHandlerException;
import org.wso2.carbon.iot.android.sense.constants.SenseConstants;
import org.wso2.carbon.iot.android.sense.event.streams.Location.LocationData;
import org.wso2.carbon.iot.android.sense.event.streams.Location.LocationDataReader;
import org.wso2.carbon.iot.android.sense.event.streams.Speed.SpeedData;
import org.wso2.carbon.iot.android.sense.event.streams.Sensor.SensorData;
import org.wso2.carbon.iot.android.sense.event.streams.Speed.SpeedData;
import org.wso2.carbon.iot.android.sense.event.streams.activity.ActivityData;
import org.wso2.carbon.iot.android.sense.event.streams.application.ApplicationData;
import org.wso2.carbon.iot.android.sense.event.streams.audio.AudioData;
import org.wso2.carbon.iot.android.sense.event.streams.battery.BatteryData;
import org.wso2.carbon.iot.android.sense.event.streams.call.CallData;
import org.wso2.carbon.iot.android.sense.event.streams.screen.ScreenData;
import org.wso2.carbon.iot.android.sense.event.streams.sms.SmsData;
import org.wso2.carbon.iot.android.sense.speech.detector.util.ProcessWords;
import org.wso2.carbon.iot.android.sense.speech.detector.util.WordData;
import org.wso2.carbon.iot.android.sense.util.SenseDataHolder;
import org.wso2.carbon.iot.android.sense.util.LocalRegistry;
//import org.wso2.carbon.iot.android.sense.util.SenseClient;
import org.wso2.carbon.iot.android.sense.util.SenseDataHolder;
import java.util.ArrayList;
import java.util.List;
@ -111,17 +115,21 @@ public class DataPublisherService extends Service {
}
SenseDataHolder.resetSensorDataHolder();
//retrieve batter data.
//retrieve battery data.
List<BatteryData> batteryDataMap = SenseDataHolder.getBatteryDataHolder();
if (!batteryDataMap.isEmpty()) {
for (BatteryData batteryData : batteryDataMap) {
Event event = new Event();
event.setTimestamp(batteryData.getTimestamp());
event.setBattery(batteryData.getLevel());
event.setBatteryTemperature(batteryData.getTemperature());
event.setBatteryStatus(batteryData.getStatus());
event.setBatteryState(batteryData.getState().toString());
events.add(event);
}
}
SenseDataHolder.resetBatteryDataHolder();
//retrieve location data.
List<LocationData> locationDataMap = SenseDataHolder.getLocationDataHolder();
@ -186,6 +194,90 @@ public class DataPublisherService extends Service {
}
}
SenseDataHolder.resetWordDataHolder();
// retrieve call data.
List<CallData> callDataList = SenseDataHolder.getCallDataHolder();
if (!callDataList.isEmpty()) {
for (CallData callData : callDataList) {
Event event = new Event();
event.setCallNumber(callData.getPhoneNumber());
event.setCallType(callData.getType().toString().toLowerCase());
event.setCallStartTime(callData.getStartTime());
event.setCallEndTime(callData.getEndTime());
event.setTimestamp(callData.getStartTime());
events.add(event);
}
}
SenseDataHolder.resetCallDataHolder();
// retrieve screen data.
List<ScreenData> screenDataList = SenseDataHolder.getScreenDataHolder();
if (!screenDataList.isEmpty()) {
for (ScreenData screenData : screenDataList) {
Event event = new Event();
event.setScreenState(screenData.getAction());
event.setTimestamp(screenData.getTimestamp());
events.add(event);
}
}
SenseDataHolder.resetScreenDataHolder();
// retrieve audio data.
List<AudioData> audioDataList = SenseDataHolder.getAudioDataHolder();
if (!audioDataList.isEmpty()) {
for (AudioData audioData : audioDataList) {
Event event = new Event();
event.setTimestamp(audioData.getTimestamp());
event.setAudioPlaying(audioData.isPlaying());
event.setHeadsetOn(audioData.isHeadsetOn());
event.setMusicVolume(audioData.getMusicVolume());
events.add(event);
}
}
SenseDataHolder.resetAudioDataHolder();
// retrieve activity data.
List<ActivityData> activityDataList = SenseDataHolder.getActivityDataHolder();
if (!activityDataList.isEmpty()) {
for (ActivityData activityData : activityDataList) {
Event event = new Event();
event.setTimestamp(activityData.getTimestamp());
event.setActivityType(activityData.getActivity());
event.setConfidence(activityData.getConfidence());
events.add(event);
}
}
SenseDataHolder.resetActivityDataHolder();
// retrieve sms data.
List<SmsData> smsDataList = SenseDataHolder.getSmsDataHolder();
if (!smsDataList.isEmpty()) {
for (SmsData smsData : smsDataList) {
Event event = new Event();
event.setTimestamp(smsData.getTimestamp());
event.setSmsNumber(smsData.getPhoneNumber());
events.add(event);
}
}
SenseDataHolder.resetSmsDataHolder();
// retrieve application data.
List<ApplicationData> appDataList = SenseDataHolder.getApplicationDataHolder();
if (!appDataList.isEmpty()) {
for (ApplicationData appData : appDataList) {
Event event = new Event();
event.setTimestamp(appData.getTimestamp());
event.setPackageName(appData.getPackageName());
event.setAction(appData.getAction().toString());
events.add(event);
}
}
SenseDataHolder.resetApplicationDataHolder();
//publish the data
if (events.size() > 0 && LocalRegistry.isEnrolled(context)) {
String user = LocalRegistry.getUsername(context);

@ -16,6 +16,12 @@ public class Event {
private float accelerometer[] = new float[]{0, 0, 0}; //x,y,z
private float magnetic[] = new float[]{0, 0, 0};; //x,y,z
private float gyroscope[] = new float[]{0, 0, 0};; //x,y,z
private int batteryTemperature;
private int batteryStatus;
/**
* LOW or OK
*/
private String batteryState;
private float light;
private float pressure;
private float proximity;
@ -32,8 +38,28 @@ public class Event {
private int beaconMinor;
private int beaconUuid;
private String beaconProximity;
private String callNumber;
private String callType;
private long callStartTime;
private long callEndTime;
/**
* State of the phone display.
* Possible values are:
* on
* off
* unknown
*/
private String screenState;
private boolean audioPlaying;
private boolean headsetOn;
private int musicVolume;
private int activityType;
private int confidence;
private String smsNumber;
private String packageName;
private String action;
private int getBattery() {
return battery;
@ -44,6 +70,33 @@ public class Event {
this.battery = battery;
}
public int getBatteryTemperature() {
return batteryTemperature;
}
public void setBatteryTemperature(int batteryTemperature) {
this.type = "battery"; // Type is battery
this.batteryTemperature = batteryTemperature;
}
public int getBatteryStatus() {
return batteryStatus;
}
public void setBatteryStatus(int batteryStatus) {
this.type = "battery"; // Type is battery
this.batteryStatus = batteryStatus;
}
public String getBatteryState() {
return batteryState != null ? batteryState : "";
}
public void setBatteryState(String batteryState) {
this.type = "battery"; // Type is battery
this.batteryState = batteryState;
}
private double[] getGps() {
return gps;
}
@ -125,6 +178,15 @@ public class Event {
this.rotation = rotation;
}
public void setSmsNumber(String smsNumber) {
this.type = "sms";
this.smsNumber = smsNumber;
}
public String getSmsNumber() {
return smsNumber;
}
private String getWordSessionId() {
return wordSessionId != null ? wordSessionId : "";
}
@ -142,6 +204,24 @@ public class Event {
this.word = word;
}
public String getPackageName() {
return packageName;
}
public void setPackageName(String packageName) {
this.type = "application";
this.packageName = packageName;
}
public String getAction() {
return action;
}
public void setAction(String action) {
this.type = "application";
this.action = action;
}
private long getTimestamp() {
return timestamp;
}
@ -181,6 +261,9 @@ public class Event {
public float getSpeed() {
this.type = "speed";
if (Float.isInfinite(speed) || Float.isNaN(speed)) {
return -1.0f;
}
return speed;
}
@ -192,7 +275,7 @@ public class Event {
public String getTurns() {
if (turn == null || turn.isEmpty() || turn.equals("null")){
if (turn == null || turn.isEmpty() || turn.equals("null")) {
turn = "No Turns";
}
return turn;
@ -234,8 +317,98 @@ public class Event {
}
public String getBeaconProximity() {
this.type = "beaconProximity";
return beaconProximity;
return beaconProximity != null ? beaconProximity : "";
}
public String getCallNumber() {
return callNumber != null ? callNumber : "";
}
public void setCallNumber(String callNumber) {
this.type = "call";
this.callNumber = callNumber;
}
public String getCallType() {
return callType != null ? callType : "";
}
public void setCallType(String callType) {
this.type = "call";
this.callType = callType;
}
public long getCallStartTime() {
return callStartTime;
}
public void setCallStartTime(long callStartTime) {
this.type = "call";
this.callStartTime = callStartTime;
}
public long getCallEndTime() {
return callEndTime;
}
public void setCallEndTime(long callEndTime) {
this.type = "call";
this.callEndTime = callEndTime;
}
public String getScreenState() {
return screenState != null ? screenState : "";
}
public void setScreenState(String screenState) {
this.type = "screen";
this.screenState = screenState;
}
public boolean isAudioPlaying() {
return audioPlaying;
}
public void setAudioPlaying(boolean audioPlaying) {
this.type = "audio";
this.audioPlaying = audioPlaying;
}
public boolean isHeadsetOn() {
return headsetOn;
}
public void setHeadsetOn(boolean headsetOn) {
this.type = "audio";
this.headsetOn = headsetOn;
}
public int getMusicVolume() {
return musicVolume;
}
public void setMusicVolume(int musicVolume) {
this.type = "audio";
this.musicVolume = musicVolume;
}
public int getActivityType() {
return activityType;
}
public void setActivityType(int activityType) {
this.type = "activity";
this.activityType = activityType;
}
public int getConfidence() {
return confidence;
}
public void setConfidence(int confidence) {
// Do not set type here since it can be used for various types.
// However, now it is being used by activity only
this.confidence = confidence;
}
public JSONObject getEvent() throws JSONException {
@ -248,7 +421,13 @@ public class Event {
jsonEvent.put("metaData", jsonMetaData);
JSONObject jsonPayloadData = new JSONObject();
// battery
jsonPayloadData.put("battery", getBattery());
jsonPayloadData.put("battery_state", getBatteryState());
jsonPayloadData.put("battery_status", getBatteryStatus());
jsonPayloadData.put("battery_temperature", getBatteryTemperature());
//gps
double gpsEvents[] = getGps();
jsonPayloadData.put("gps_lat", gpsEvents[0]);
@ -301,6 +480,29 @@ public class Event {
jsonPayloadData.put("word_sessionId", getWordSessionId());
jsonPayloadData.put("word_status", getWordStatus());
// call
jsonPayloadData.put("call_number", getCallNumber());
jsonPayloadData.put("call_type", getCallType());
jsonPayloadData.put("call_start_time", getCallStartTime());
jsonPayloadData.put("call_end_time", getCallEndTime());
// screen
jsonPayloadData.put("screen_state", getScreenState());
// headset
jsonPayloadData.put("audio_playing", isAudioPlaying());
jsonPayloadData.put("headset_on", isHeadsetOn());
jsonPayloadData.put("music_volume", getMusicVolume());
jsonPayloadData.put("activity_type", getActivityType());
jsonPayloadData.put("confidence", getConfidence());
jsonPayloadData.put("sms_number", getSmsNumber());
jsonPayloadData.put("application_name", getPackageName());
jsonPayloadData.put("action", getAction());
jsonEvent.put("payloadData", jsonPayloadData);
return jsonEvent;

@ -16,11 +16,11 @@ package org.wso2.carbon.iot.android.sense.event;
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.event.streams.SenseDataCollector;
import org.wso2.carbon.iot.android.sense.event.streams.battery.BatteryDataReceiver;
import org.wso2.carbon.iot.android.sense.util.LocalRegistry;
import org.wso2.carbon.iot.android.sense.util.SenseDataReceiverManager;
import org.wso2.carbon.iot.android.sense.util.SenseWakeLock;
/**
@ -48,10 +48,14 @@ public class SenseService extends Service {
//Below triggers the data collection for sensors,location and battery.
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));
SenseDataCollector speed = new SenseDataCollector(this, SenseDataCollector.DataType.SPEED);
SenseDataCollector audio = new SenseDataCollector(this, SenseDataCollector.DataType.AUDIO);
SenseDataReceiverManager.registerBatteryDataReceiver(this);
SenseDataReceiverManager.registerScreenDataReceiver(this);
SenseDataReceiverManager.registerCallDataReceiver(this);
SenseDataReceiverManager.registerActivityDataReceiver(this);
SenseDataReceiverManager.registerSmsDataReceiver(this);
SenseDataReceiverManager.registerAppDataReceiver(this);
//service will not be stopped until we manually stop the service
return Service.START_NOT_STICKY;
@ -59,6 +63,13 @@ public class SenseService extends Service {
@Override
public void onDestroy() {
SenseDataReceiverManager.unregisterBatteryDataReceiver(this);
SenseDataReceiverManager.unregisterScreenDataReceiver(this);
SenseDataReceiverManager.unregisterCallDataReceiver(this);
SenseDataReceiverManager.unregisterActivityDataReceiver(this);
SenseDataReceiverManager.unregisterSmsDataReceiver(this);
SenseDataReceiverManager.unregisterAppDataReceiver(this);
SenseWakeLock.releaseCPUWakeLock();
super.onDestroy();
}

@ -19,13 +19,14 @@ import org.wso2.carbon.iot.android.sense.event.streams.Location.LocationDataRead
import org.wso2.carbon.iot.android.sense.event.streams.Sensor.SensorDataReader;
import org.wso2.carbon.iot.android.sense.event.streams.Speed.SpeedDataReader;
import org.wso2.carbon.iot.android.sense.beacon.MonitoringActivity;
import org.wso2.carbon.iot.android.sense.event.streams.audio.AudioDataReader;
/**
* This class triggered by service to collect the sensor data.
*/
public class SenseDataCollector {
public enum DataType {
SENSOR, LOCATION,SPEED
SENSOR, LOCATION,SPEED, AUDIO
}
public SenseDataCollector(Context ctx, DataType dt) {
@ -40,6 +41,9 @@ public class SenseDataCollector {
case SPEED:
dr = new SpeedDataReader(ctx);
break;
case AUDIO:
dr = new AudioDataReader(ctx);
break;
}
if (dr != null) {

@ -0,0 +1,67 @@
/*
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you 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.event.streams.activity;
import java.util.Date;
public class ActivityData {
/**
* 0 - In vehicle
* 1 - Bicycle
* 2 - Foot
* 3 - Still
* 4 - Unknown
* 5 - Tilting
* 7 - Walking
* 8 - Running
*/
private int activity;
private int confidence;
private long timestamp;
ActivityData(int activity, int confidence) {
this.activity = activity;
this.confidence = confidence;
this.timestamp = new Date().getTime();
}
public int getActivity() {
return activity;
}
public void setActivity(int activity) {
this.activity = activity;
}
public int getConfidence() {
return confidence;
}
public void setConfidence(int confidence) {
this.confidence = confidence;
}
public long getTimestamp() {
return timestamp;
}
public void setTimestamp(long timestamp) {
this.timestamp = timestamp;
}
}

@ -0,0 +1,54 @@
/*
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you 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.event.streams.activity;
import android.app.IntentService;
import android.content.Intent;
import com.google.android.gms.location.ActivityRecognitionResult;
import com.google.android.gms.location.DetectedActivity;
import org.wso2.carbon.iot.android.sense.util.SenseDataHolder;
public class ActivityReceiver extends IntentService {
public static final int MINIMUM_CONFIDENCE = 75;
/**
* Retrieve the information for every 10 seconds.
*/
public static final long UPDATE_INTERVAL = 10000;
public ActivityReceiver() {
super(ActivityReceiver.class.getName());
}
@Override
protected void onHandleIntent(Intent intent) {
if (ActivityRecognitionResult.hasResult(intent)) {
ActivityRecognitionResult result = ActivityRecognitionResult.extractResult(intent);
for (DetectedActivity activity : result.getProbableActivities()) {
if (activity.getConfidence() >= MINIMUM_CONFIDENCE) {
ActivityData data = new ActivityData(activity.getType(), activity.getConfidence());
SenseDataHolder.getActivityDataHolder().add(data);
}
}
}
}
}

@ -0,0 +1,61 @@
/*
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you 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.event.streams.application;
import java.util.Date;
public class ApplicationData {
public enum Action {
INSTALL, REMOVE
}
private long timestamp;
private String packageName;
private Action action;
ApplicationData(String packageName, Action action) {
this.packageName = packageName;
this.action = action;
this.timestamp = new Date().getTime();
}
public long getTimestamp() {
return timestamp;
}
public void setTimestamp(long timestamp) {
this.timestamp = timestamp;
}
public String getPackageName() {
return packageName;
}
public void setPackageName(String packageName) {
this.packageName = packageName;
}
public Action getAction() {
return action;
}
public void setAction(Action action) {
this.action = action;
}
}

@ -0,0 +1,45 @@
/*
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you 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.event.streams.application;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import org.wso2.carbon.iot.android.sense.util.SenseDataHolder;
/**
* Currently interested on package add and remove only. Can be extended for modification.
*/
public class ApplicationDataReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
String packageName = intent.getData().toString().substring(8);
ApplicationData appData;
if (Intent.ACTION_PACKAGE_ADDED.equals(intent.getAction())) {
appData = new ApplicationData(packageName, ApplicationData.Action.INSTALL);
} else {
// Removed
appData = new ApplicationData(packageName, ApplicationData.Action.REMOVE);
}
SenseDataHolder.getApplicationDataHolder().add(appData);
}
}

@ -0,0 +1,58 @@
/*
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you 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.event.streams.audio;
public class AudioData {
private long timestamp;
private boolean headsetOn;
private int musicVolume;
private boolean playing;
public long getTimestamp() {
return timestamp;
}
public void setTimestamp(long timestamp) {
this.timestamp = timestamp;
}
public boolean isHeadsetOn() {
return headsetOn;
}
public void setHeadsetOn(boolean headsetOn) {
this.headsetOn = headsetOn;
}
public int getMusicVolume() {
return musicVolume;
}
public void setMusicVolume(int musicVolume) {
this.musicVolume = musicVolume;
}
public boolean isPlaying() {
return playing;
}
public void setPlaying(boolean playing) {
this.playing = playing;
}
}

@ -0,0 +1,50 @@
/*
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you 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.event.streams.audio;
import android.content.Context;
import android.media.AudioManager;
import android.util.Log;
import org.wso2.carbon.iot.android.sense.event.streams.DataReader;
import org.wso2.carbon.iot.android.sense.util.SenseDataHolder;
import java.util.Date;
public class AudioDataReader extends DataReader {
private static final String TAG = AudioDataReader.class.getName();
private Context context;
public AudioDataReader(Context context) {
this.context = context;
}
@Override
public void run() {
Log.d(TAG, "Running AudioDataReader");
AudioManager manager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
AudioData audioData = new AudioData();
audioData.setTimestamp(new Date().getTime());
audioData.setPlaying(manager.isMusicActive());
audioData.setHeadsetOn(manager.isWiredHeadsetOn());
audioData.setMusicVolume(manager.getStreamVolume(AudioManager.STREAM_MUSIC));
SenseDataHolder.getAudioDataHolder().add(audioData);
}
}

@ -25,6 +25,10 @@ import java.util.Date;
*/
public class BatteryData {
public enum State {
LOW, OK
}
private int health;
private int level;
private int plugged;
@ -34,6 +38,7 @@ public class BatteryData {
private int temperature;
private int voltage;
private long timestamp;
private State state;
BatteryData(Intent intent) {
timestamp = new Date().getTime();
@ -46,7 +51,12 @@ public class BatteryData {
String technology = intent.getExtras().getString(BatteryManager.EXTRA_TECHNOLOGY);
temperature = intent.getIntExtra(BatteryManager.EXTRA_TEMPERATURE, 0);
voltage = intent.getIntExtra(BatteryManager.EXTRA_VOLTAGE, 0);
state = State.OK;
}
BatteryData(State state) {
this.timestamp = new Date().getTime();
this.state = state;
}
public int getHealth() {
@ -121,4 +131,12 @@ public class BatteryData {
public void setTimestamp(long timestamp) {
this.timestamp = timestamp;
}
public State getState() {
return state;
}
public void setState(State state) {
this.state = state;
}
}

@ -32,7 +32,13 @@ public class BatteryDataReceiver extends BroadcastReceiver {
*/
@Override
public void onReceive(Context context, Intent intent) {
if (Intent.ACTION_BATTERY_OKAY.equals(intent.getAction())) {
SenseDataHolder.getBatteryDataHolder().add(new BatteryData(BatteryData.State.OK));
} else if (Intent.ACTION_BATTERY_LOW.equals(intent.getAction())) {
SenseDataHolder.getBatteryDataHolder().add(new BatteryData(BatteryData.State.LOW));
} else {
SenseDataHolder.getBatteryDataHolder().add(new BatteryData(intent));
}
}
}

@ -0,0 +1,70 @@
/*
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you 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.event.streams.call;
public class CallData {
public enum Type {
INCOMING, OUTGOING, MISSED;
}
private Type type;
private String phoneNumber;
private long startTime;
private long endTime;
public CallData(Type type, String phoneNumber, long startTime, long endTime) {
this.type = type;
this.phoneNumber = phoneNumber;
this.startTime = startTime;
this.endTime = endTime;
}
public Type getType() {
return type;
}
public void setType(Type type) {
this.type = type;
}
public String getPhoneNumber() {
return phoneNumber;
}
public void setPhoneNumber(String phoneNumber) {
this.phoneNumber = phoneNumber;
}
public long getStartTime() {
return startTime;
}
public void setStartTime(long startTime) {
this.startTime = startTime;
}
public long getEndTime() {
return endTime;
}
public void setEndTime(long endTime) {
this.endTime = endTime;
}
}

@ -0,0 +1,87 @@
/*
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you 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.event.streams.call;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.telephony.TelephonyManager;
import org.wso2.carbon.iot.android.sense.util.SenseDataHolder;
public class CallDataReceiver extends BroadcastReceiver {
private static int lastState = TelephonyManager.CALL_STATE_IDLE;
private static long startTime;
private static boolean isIncoming;
private static String lastNotifiedNumber;
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(Intent.ACTION_NEW_OUTGOING_CALL)) {
lastNotifiedNumber = intent.getExtras().getString(Intent.EXTRA_PHONE_NUMBER);
} else {
String extraState = intent.getExtras().getString(TelephonyManager.EXTRA_STATE);
int state = 0;
if (extraState.equals(TelephonyManager.EXTRA_STATE_IDLE)) {
state = TelephonyManager.CALL_STATE_IDLE;
} else if (extraState.equals(TelephonyManager.EXTRA_STATE_OFFHOOK)) {
state = TelephonyManager.CALL_STATE_OFFHOOK;
} else if (extraState.equals(TelephonyManager.EXTRA_STATE_RINGING)) {
state = TelephonyManager.CALL_STATE_RINGING;
}
if (lastState == state) {
return; // Nothing has been changed
}
switch (state) {
case TelephonyManager.CALL_STATE_RINGING:
// Receiving a call
isIncoming = true;
startTime = System.currentTimeMillis();
// If incoming call, get the incoming number
lastNotifiedNumber = intent.getExtras().getString(TelephonyManager.EXTRA_INCOMING_NUMBER);
break;
case TelephonyManager.CALL_STATE_OFFHOOK:
if (lastState == TelephonyManager.CALL_STATE_RINGING) {
// RINGING -> OFFHOOK = ANSWERED
isIncoming = true;
startTime = System.currentTimeMillis();
} else {
// NOT RINGING -> OFFHOOK = OUTGOING
isIncoming = false;
startTime = System.currentTimeMillis();
}
break;
case TelephonyManager.CALL_STATE_IDLE:
if (lastState == TelephonyManager.CALL_STATE_RINGING) {
// RINGING -> IDLE = MISSED
SenseDataHolder.getCallDataHolder().add(new CallData(CallData.Type.MISSED, lastNotifiedNumber, startTime, System.currentTimeMillis()));
} else if (isIncoming) {
// Incoming (OFFHOOK) -> IDLE = INCOMING CALL ENDED
SenseDataHolder.getCallDataHolder().add(new CallData(CallData.Type.INCOMING, lastNotifiedNumber, startTime, System.currentTimeMillis()));
} else {
// Not Incoming -> IDLE = OUTGOING CALL ENDED
SenseDataHolder.getCallDataHolder().add(new CallData(CallData.Type.OUTGOING, lastNotifiedNumber, startTime, System.currentTimeMillis()));
}
break;
}
lastState = state;
}
}
}

@ -0,0 +1,55 @@
/*
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you 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.event.streams.screen;
import android.content.Intent;
import java.util.Date;
public class ScreenData {
private String action;
private long timestamp;
ScreenData(Intent intent) {
if (Intent.ACTION_SCREEN_ON.equals(intent.getAction())) {
this.action = "on";
} else if (Intent.ACTION_SCREEN_OFF.equals(intent.getAction())) {
this.action = "off";
} else {
this.action = "unknown";
}
this.timestamp = new Date().getTime();
}
public String getAction() {
return action;
}
public void setAction(String action) {
this.action = action;
}
public long getTimestamp() {
return timestamp;
}
public void setTimestamp(long timestamp) {
this.timestamp = timestamp;
}
}

@ -0,0 +1,32 @@
/*
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you 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.event.streams.screen;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import org.wso2.carbon.iot.android.sense.util.SenseDataHolder;
public class ScreenDataReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
SenseDataHolder.getScreenDataHolder().add(new ScreenData(intent));
}
}

@ -0,0 +1,58 @@
/*
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you 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.event.streams.sms;
import java.util.Date;
public class SmsData {
private String phoneNumber;
private long timestamp;
private String message;
SmsData(String phoneNumber, String message) {
this.phoneNumber = phoneNumber;
this.message = message;
this.timestamp = new Date().getTime();
}
public String getPhoneNumber() {
return phoneNumber;
}
public void setPhoneNumber(String phoneNumber) {
this.phoneNumber = phoneNumber;
}
public long getTimestamp() {
return timestamp;
}
public void setTimestamp(long timestamp) {
this.timestamp = timestamp;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
}

@ -0,0 +1,49 @@
/*
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you 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.event.streams.sms;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.SmsMessage;
import org.wso2.carbon.iot.android.sense.util.SenseDataHolder;
public class SmsDataReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
final Bundle bundle = intent.getExtras();
if (bundle != null) {
final Object[] pdusObj = (Object[]) bundle.get("pdus");
for (int i = 0; i < pdusObj.length; i++) {
SmsMessage currentMessage = SmsMessage.createFromPdu((byte[]) pdusObj[i]);
String phoneNumber = currentMessage.getDisplayOriginatingAddress();
String message = currentMessage.getDisplayMessageBody();
SmsData smsData = new SmsData(phoneNumber, message);
SenseDataHolder.getSmsDataHolder().add(smsData);
}
}
}
}

@ -60,6 +60,7 @@ public class SupportedSensors {
sensorList.add("Light");
sensorList.add("Gyroscope");
sensorList.add("Proximity");
sensorList.add("Pedometer");
}
/**
@ -74,6 +75,7 @@ public class SupportedSensors {
sensorTypeMap.put("gyroscope", Sensor.TYPE_GYROSCOPE);
sensorTypeMap.put("light", Sensor.TYPE_LIGHT);
sensorTypeMap.put("proximity", Sensor.TYPE_PROXIMITY);
sensorTypeMap.put("pedometer", Sensor.TYPE_STEP_COUNTER);
}
/**
@ -88,6 +90,7 @@ public class SupportedSensors {
typeSensorMap.put(Sensor.TYPE_GYROSCOPE, "gyroscope");
typeSensorMap.put(Sensor.TYPE_LIGHT, "light");
typeSensorMap.put(Sensor.TYPE_PROXIMITY, "proximity");
typeSensorMap.put(Sensor.TYPE_STEP_COUNTER, "pedometer");
}
/**

@ -17,11 +17,17 @@ import org.wso2.carbon.iot.android.sense.beacon.BeaconScanedData;
import org.wso2.carbon.iot.android.sense.event.streams.Location.LocationData;
import org.wso2.carbon.iot.android.sense.event.streams.Sensor.SensorData;
import org.wso2.carbon.iot.android.sense.event.streams.Speed.SpeedData;
import org.wso2.carbon.iot.android.sense.event.streams.activity.ActivityData;
import org.wso2.carbon.iot.android.sense.event.streams.application.ApplicationData;
import org.wso2.carbon.iot.android.sense.event.streams.audio.AudioData;
import org.wso2.carbon.iot.android.sense.event.streams.battery.BatteryData;
import org.wso2.carbon.iot.android.sense.event.streams.call.CallData;
import org.wso2.carbon.iot.android.sense.event.streams.screen.ScreenData;
import org.wso2.carbon.iot.android.sense.event.streams.sms.SmsData;
import org.wso2.carbon.iot.android.sense.speech.detector.util.WordData;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import android.util.Log;
/**
@ -31,35 +37,47 @@ public class SenseDataHolder {
private static List<SensorData> sensorDataHolder;
private static List<BatteryData> batteryDataHolder;
private static List<CallData> callDataHolder;
private static List<LocationData> locationDataHolder;
private static List<WordData> wordDataHolder;
private static List<SpeedData> speedDataHolder;
private static List<BeaconScanedData> beaconScanedDataHolder;
private static List<ScreenData> screenDataHolder;
private static List<AudioData> audioDataHolder;
private static List<ActivityData> activityDataHolder;
private static List<SmsData> smsDataHolder;
private static List<ApplicationData> applicationDataHolder;
//LocationData gps;
private static final String TAG = SenseDataHolder.class.getName();
public static List<SensorData> getSensorDataHolder(){
if(sensorDataHolder == null){
public static List<SensorData> getSensorDataHolder() {
if (sensorDataHolder == null) {
sensorDataHolder = new CopyOnWriteArrayList<>();
}
return sensorDataHolder;
}
public static List<BatteryData> getBatteryDataHolder(){
if(batteryDataHolder == null){
public static List<BatteryData> getBatteryDataHolder() {
if (batteryDataHolder == null) {
batteryDataHolder = new CopyOnWriteArrayList<>();
}
return batteryDataHolder;
}
public static List<LocationData> getLocationDataHolder(){
public static List<CallData> getCallDataHolder() {
if (callDataHolder == null) {
callDataHolder = new CopyOnWriteArrayList<>();
}
return callDataHolder;
}
public static List<LocationData> getLocationDataHolder() {
if(locationDataHolder == null){
if (locationDataHolder == null) {
locationDataHolder = new CopyOnWriteArrayList<>();
}
@ -67,36 +85,75 @@ public class SenseDataHolder {
}
public static List<WordData> getWordDataHolder(){
if(wordDataHolder == null){
public static List<WordData> getWordDataHolder() {
if (wordDataHolder == null) {
wordDataHolder = new CopyOnWriteArrayList<>();
}
return wordDataHolder;
}
public static List<SpeedData> getSpeedDataHolder(){
if(speedDataHolder == null){
public static List<SpeedData> getSpeedDataHolder() {
if (speedDataHolder == null) {
speedDataHolder = new CopyOnWriteArrayList<>();
}
return speedDataHolder;
}
public static List<BeaconScanedData> getBeaconScanedDataHolder(){
if(beaconScanedDataHolder == null){
public static List<BeaconScanedData> getBeaconScanedDataHolder() {
if (beaconScanedDataHolder == null) {
beaconScanedDataHolder = new CopyOnWriteArrayList<>();
}
return beaconScanedDataHolder;
}
public static void resetSensorDataHolder(){
public static List<ScreenData> getScreenDataHolder() {
if (screenDataHolder == null) {
screenDataHolder = new CopyOnWriteArrayList<>();
}
return screenDataHolder;
}
public static List<AudioData> getAudioDataHolder() {
if (audioDataHolder == null) {
audioDataHolder = new CopyOnWriteArrayList<>();
}
return audioDataHolder;
}
public static List<ActivityData> getActivityDataHolder() {
if (activityDataHolder == null) {
activityDataHolder = new CopyOnWriteArrayList<>();
}
return activityDataHolder;
}
public static List<SmsData> getSmsDataHolder() {
if (smsDataHolder == null) {
smsDataHolder = new CopyOnWriteArrayList<>();
}
return smsDataHolder;
}
public static List<ApplicationData> getApplicationDataHolder() {
if (applicationDataHolder == null) {
applicationDataHolder = new CopyOnWriteArrayList<>();
}
return applicationDataHolder;
}
public static void resetSensorDataHolder() {
sensorDataHolder = null;
}
public static void resetBatteryDataHolder(){
public static void resetBatteryDataHolder() {
batteryDataHolder = null;
}
public static void resetLocationDataHolder(){
public static void resetCallDataHolder() {
callDataHolder = null;
}
public static void resetLocationDataHolder() {
locationDataHolder = null;
}
@ -112,5 +169,23 @@ public class SenseDataHolder {
beaconScanedDataHolder = null;
}
public static void resetScreenDataHolder() {
screenDataHolder = null;
}
public static void resetAudioDataHolder() {
audioDataHolder = null;
}
public static void resetActivityDataHolder() {
activityDataHolder = null;
}
public static void resetSmsDataHolder() {
smsDataHolder = null;
}
public static void resetApplicationDataHolder() {
applicationDataHolder = null;
}
}

@ -0,0 +1,175 @@
/*
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you 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.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.provider.Telephony;
import android.support.annotation.Nullable;
import android.telephony.TelephonyManager;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.location.ActivityRecognition;
import org.wso2.carbon.iot.android.sense.event.streams.activity.ActivityReceiver;
import org.wso2.carbon.iot.android.sense.event.streams.application.ApplicationDataReceiver;
import org.wso2.carbon.iot.android.sense.event.streams.battery.BatteryDataReceiver;
import org.wso2.carbon.iot.android.sense.event.streams.call.CallDataReceiver;
import org.wso2.carbon.iot.android.sense.event.streams.screen.ScreenDataReceiver;
import org.wso2.carbon.iot.android.sense.event.streams.sms.SmsDataReceiver;
public class SenseDataReceiverManager {
private static BroadcastReceiver batteryDataReceiver;
private static BroadcastReceiver screenDataReceiver;
private static BroadcastReceiver callDataReceiver;
private static GoogleApiClient apiClient;
private static SmsDataReceiver smsDataReceiver;
private static ApplicationDataReceiver appDataReceiver;
private SenseDataReceiverManager() {
}
public static void registerBatteryDataReceiver(Context context) {
if (batteryDataReceiver == null) {
batteryDataReceiver = new BatteryDataReceiver();
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(Intent.ACTION_BATTERY_LOW);
intentFilter.addAction(Intent.ACTION_BATTERY_OKAY);
intentFilter.addAction(Intent.ACTION_BATTERY_CHANGED);
context.registerReceiver(batteryDataReceiver, intentFilter);
}
}
public static void unregisterBatteryDataReceiver(Context context) {
if (batteryDataReceiver != null) {
context.unregisterReceiver(batteryDataReceiver);
batteryDataReceiver = null;
}
}
public static void registerScreenDataReceiver(Context context) {
if (screenDataReceiver == null) {
screenDataReceiver = new ScreenDataReceiver();
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(Intent.ACTION_SCREEN_ON);
intentFilter.addAction(Intent.ACTION_SCREEN_OFF);
context.registerReceiver(screenDataReceiver, intentFilter);
}
}
public static void unregisterScreenDataReceiver(Context context) {
if (screenDataReceiver != null) {
context.unregisterReceiver(screenDataReceiver);
screenDataReceiver = null;
}
}
public static void registerCallDataReceiver(Context context) {
if (callDataReceiver == null) {
callDataReceiver = new CallDataReceiver();
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(TelephonyManager.ACTION_PHONE_STATE_CHANGED);
intentFilter.addAction(Intent.ACTION_NEW_OUTGOING_CALL);
context.registerReceiver(callDataReceiver, intentFilter);
}
}
public static void unregisterCallDataReceiver(Context context) {
if (callDataReceiver != null) {
context.unregisterReceiver(callDataReceiver);
callDataReceiver = null;
}
}
public static void registerActivityDataReceiver(Context context) {
if (apiClient == null) {
Intent intent = new Intent(context, ActivityReceiver.class);
final PendingIntent pendingIntent = PendingIntent.getService(context, 888971, intent, PendingIntent.FLAG_UPDATE_CURRENT);
apiClient = new GoogleApiClient.Builder(context)
.addApi(ActivityRecognition.API)
.addConnectionCallbacks(new GoogleApiClient.ConnectionCallbacks() {
@Override
public void onConnected(@Nullable Bundle bundle) {
ActivityRecognition.ActivityRecognitionApi.requestActivityUpdates(apiClient, ActivityReceiver.UPDATE_INTERVAL, pendingIntent);
}
@Override
public void onConnectionSuspended(int i) {
ActivityRecognition.ActivityRecognitionApi.removeActivityUpdates(apiClient, pendingIntent);
}
})
.build();
apiClient.connect();
}
}
public static void unregisterActivityDataReceiver(Context context) {
if (apiClient != null) {
apiClient.disconnect();
apiClient = null;
}
}
public static void registerSmsDataReceiver(Context context) {
if (smsDataReceiver == null) {
smsDataReceiver = new SmsDataReceiver();
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(Telephony.Sms.Intents.SMS_RECEIVED_ACTION);
context.registerReceiver(smsDataReceiver, intentFilter);
}
}
public static void unregisterSmsDataReceiver(Context context) {
if (smsDataReceiver != null) {
context.unregisterReceiver(smsDataReceiver);
smsDataReceiver = null;
}
}
public static void registerAppDataReceiver(Context context) {
if (appDataReceiver == null) {
appDataReceiver = new ApplicationDataReceiver();
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(Intent.ACTION_PACKAGE_ADDED);
intentFilter.addAction(Intent.ACTION_PACKAGE_REMOVED);
context.registerReceiver(appDataReceiver, intentFilter);
}
}
public static void unregisterAppDataReceiver(Context context) {
if (appDataReceiver != null) {
context.unregisterReceiver(appDataReceiver);
appDataReceiver = null;
}
}
}
Loading…
Cancel
Save