Incoming and outgoing calls tracker Screen on off detector SMS tracker Audio playing and headset tracker Application install and uninstall detector User activity detectorrevert-dabc3590
parent
215fd51ffb
commit
ab418dbde3
@ -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);
|
||||||
|
}
|
||||||
|
}
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -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…
Reference in new issue