Commit de4a4773 authored by EXL's avatar EXL

Refactor code, Add repo stuff, Add License

parent ec3e520c
The MIT License (MIT)
Copyright (c) 2016 S. "EXL" KLS
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Synergy Calls
=============
Synergy Calls is application for Android OS, which logging calls to the server through the [POST](https://en.wikipedia.org/wiki/POST_(HTTP)) request method.
![Synergy Calls Android Screen](https://raw.github.com/EXL/SynergyCalls/master/images/SynergyCalls_Android_Screen.png)
For getting information about calls the application uses the PhoneCallReceiver class, found on [Stack Overflow](http://stackoverflow.com/a/30521544/2467443).
![Konsole Log Linux Screen](https://raw.github.com/EXL/SynergyCalls/master/images/Konsole_Log_Linux_Screen.png)
In order to Android OS does not unload the application from memory, a Service class was used. For the application to be started with the launch of the device, a BroadcastReceiver class was used.
## Download
You can download APK-package for Android OS from the [releases](https://github.com/EXL/SynergyCalls/releases) section.
## Build instructions
For example, GNU/Linux:
* Install the latest [Android SDK](https://developer.android.com/sdk/);
* Clone repository into deploy directory;
```sh
cd ~/Deploy/
git clone https://github.com/EXL/SynergyCalls SynergyCallsAndroid
```
* Build the APK-package into deploy directory with Gradle building script;
```sh
cd ~/Deploy/SynergyCallsAndroid/
ANDROID_HOME="/opt/android/android-sdk/" ./gradlew assembleDebug
```
* Install Synergy Calls APK-package on your Android device via adb;
```sh
cd ~/Deploy/SynergyCallsAndroid/
/opt/android/android-sdk-linux/platform-tools/adb install -r synergy/build/outputs/apk/synergy-debug.apk
```
* Check all the necessary permissions;
* Run and enjoy!
You can also import this project in your favorite IDE: Eclipse or Android Studio and build the APK-package by using these programs.
## More information
Please read [Making Guide (In Russian)](http://exlmoto.ru/new-updates-and-tools) for more info about making Synergy Calls for Android OS.
......@@ -5,7 +5,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.5.0'
classpath 'com.android.tools.build:gradle:2.2.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
......
#Wed Oct 21 11:34:03 PDT 2015
#Sat Feb 04 12:52:01 NOVT 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.8-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
/************************************************************************************
** The MIT License (MIT)
**
** Copyright (c) 2016 S. "EXL" KLS
**
** Permission is hereby granted, free of charge, to any person obtaining a copy
** of this software and associated documentation files (the "Software"), to deal
** in the Software without restriction, including without limitation the rights
** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
** copies of the Software, and to permit persons to whom the Software is
** furnished to do so, subject to the following conditions:
**
** The above copyright notice and this permission notice shall be included in all
** copies or substantial portions of the Software.
**
** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
** IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
** FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
** AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
** LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
** OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
** SOFTWARE.
************************************************************************************/
package ru.exlmoto.synergycalls;
import android.content.BroadcastReceiver;
......@@ -7,6 +31,7 @@ import android.content.Intent;
/**
* Created by exl on 9/12/16.
*/
public class BootReceiver extends BroadcastReceiver {
@Override
......
/************************************************************************************
** The MIT License (MIT)
**
** Copyright (c) 2016 S. "EXL" KLS
**
** Permission is hereby granted, free of charge, to any person obtaining a copy
** of this software and associated documentation files (the "Software"), to deal
** in the Software without restriction, including without limitation the rights
** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
** copies of the Software, and to permit persons to whom the Software is
** furnished to do so, subject to the following conditions:
**
** The above copyright notice and this permission notice shall be included in all
** copies or substantial portions of the Software.
**
** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
** IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
** FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
** AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
** LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
** OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
** SOFTWARE.
************************************************************************************/
package ru.exlmoto.synergycalls;
import android.content.Context;
......@@ -15,7 +39,7 @@ import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
public class CallReceiver extends PhonecallReceiver {
public class CallReceiver extends PhoneCallReceiver {
private class PostClass extends AsyncTask<String, Void, Void> {
......
/************************************************************************************
** The MIT License (MIT)
**
** Copyright (c) 2016 S. "EXL" KLS
**
** Permission is hereby granted, free of charge, to any person obtaining a copy
** of this software and associated documentation files (the "Software"), to deal
** in the Software without restriction, including without limitation the rights
** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
** copies of the Software, and to permit persons to whom the Software is
** furnished to do so, subject to the following conditions:
**
** The above copyright notice and this permission notice shall be included in all
** copies or substantial portions of the Software.
**
** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
** IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
** FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
** AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
** LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
** OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
** SOFTWARE.
************************************************************************************/
package ru.exlmoto.synergycalls;
import android.annotation.TargetApi;
......@@ -67,11 +91,16 @@ public class MainActivity extends Activity {
SharedPreferences.Editor editor = settingStorage.edit();
editor.putString("in", (SynergySettings.in != null && !SynergySettings.in.isEmpty()) ? SynergySettings.in : "http://exlmoto.ru");
editor.putString("inE", (SynergySettings.inE != null && !SynergySettings.inE.isEmpty()) ? SynergySettings.inE : "http://exlmoto.ru");
editor.putString("out", (SynergySettings.out != null && !SynergySettings.out.isEmpty()) ? SynergySettings.out : "http://exlmoto.ru");
editor.putString("outE", (SynergySettings.outE != null && !SynergySettings.outE.isEmpty()) ? SynergySettings.outE : "http://exlmoto.ru");
editor.putString("miss", (SynergySettings.miss != null && !SynergySettings.miss.isEmpty()) ? SynergySettings.miss : "http://exlmoto.ru");
editor.putString("in", (SynergySettings.in != null && !SynergySettings.in.isEmpty()) ?
SynergySettings.in : "http://exlmoto.ru");
editor.putString("inE", (SynergySettings.inE != null && !SynergySettings.inE.isEmpty()) ?
SynergySettings.inE : "http://exlmoto.ru");
editor.putString("out", (SynergySettings.out != null && !SynergySettings.out.isEmpty()) ?
SynergySettings.out : "http://exlmoto.ru");
editor.putString("outE", (SynergySettings.outE != null && !SynergySettings.outE.isEmpty()) ?
SynergySettings.outE : "http://exlmoto.ru");
editor.putString("miss", (SynergySettings.miss != null && !SynergySettings.miss.isEmpty()) ?
SynergySettings.miss : "http://exlmoto.ru");
editor.commit();
......@@ -96,9 +125,9 @@ public class MainActivity extends Activity {
settingStorage = getSharedPreferences("ru.exlmoto.synergycall", MODE_PRIVATE);
// Check the first run
boolean firstRun = false;
// boolean firstRun = false;
if (settingStorage.getBoolean("firstRun", true)) {
firstRun = true;
// firstRun = true;
settingStorage.edit().putBoolean("firstRun", false).commit();
} else {
readSettings();
......
/************************************************************************************
** PhoneCallReceiver class by Gabe Sechan
** http://gabesechansoftware.com/
**
** Answer on StackOverflow by Uma Kanth
** http://stackoverflow.com/a/30521544/2467443
************************************************************************************/
package ru.exlmoto.synergycalls;
import java.util.Date;
......@@ -7,56 +15,51 @@ import android.content.Context;
import android.content.Intent;
import android.telephony.TelephonyManager;
public abstract class PhonecallReceiver extends BroadcastReceiver {
//The receiver will be recreated whenever android feels like it. We need a static variable to remember data between instantiations
public abstract class PhoneCallReceiver extends BroadcastReceiver {
// The receiver will be recreated whenever android feels like it.
// We need a static variable to remember data between instantiations.
private static int lastState = TelephonyManager.CALL_STATE_IDLE;
private static Date callStartTime;
private static boolean isIncoming;
private static String savedNumber; //because the passed incoming is only valid in ringing
private static String savedNumber; // Because the passed incoming is only valid in ringing.
@Override
public void onReceive(Context context, Intent intent) {
// We listen to two intents.
// The new outgoing call only tells us of an outgoing call.
// We use it to get the number.
//We listen to two intents. The new outgoing call only tells us of an outgoing call. We use it to get the number.
if (intent.getAction().equals("android.intent.action.NEW_OUTGOING_CALL")) {
savedNumber = intent.getExtras().getString("android.intent.extra.PHONE_NUMBER");
}
else{
} else {
String stateStr = intent.getExtras().getString(TelephonyManager.EXTRA_STATE);
String number = intent.getExtras().getString(TelephonyManager.EXTRA_INCOMING_NUMBER);
int state = 0;
if(stateStr.equals(TelephonyManager.EXTRA_STATE_IDLE)){
if (stateStr.equals(TelephonyManager.EXTRA_STATE_IDLE)) {
state = TelephonyManager.CALL_STATE_IDLE;
}
else if(stateStr.equals(TelephonyManager.EXTRA_STATE_OFFHOOK)){
} else if (stateStr.equals(TelephonyManager.EXTRA_STATE_OFFHOOK)) {
state = TelephonyManager.CALL_STATE_OFFHOOK;
}
else if(stateStr.equals(TelephonyManager.EXTRA_STATE_RINGING)){
} else if (stateStr.equals(TelephonyManager.EXTRA_STATE_RINGING)) {
state = TelephonyManager.CALL_STATE_RINGING;
}
onCallStateChanged(context, state, number);
}
}
//Derived classes should override these to respond to specific events of interest
protected void onIncomingCallStarted(Context ctx, String number, Date start){}
protected void onOutgoingCallStarted(Context ctx, String number, Date start){}
protected void onIncomingCallEnded(Context ctx, String number, Date start, Date end){}
protected void onOutgoingCallEnded(Context ctx, String number, Date start, Date end){}
protected void onMissedCall(Context ctx, String number, Date start){}
//Deals with actual events
// Derived classes should override these to respond to specific events of interest.
protected void onIncomingCallStarted(Context ctx, String number, Date start) { }
protected void onOutgoingCallStarted(Context ctx, String number, Date start) { }
protected void onIncomingCallEnded(Context ctx, String number, Date start, Date end) { }
protected void onOutgoingCallEnded(Context ctx, String number, Date start, Date end) { }
protected void onMissedCall(Context ctx, String number, Date start) { }
//Incoming call- goes from IDLE to RINGING when it rings, to OFFHOOK when it's answered, to IDLE when its hung up
//Outgoing call- goes from IDLE to OFFHOOK when it dials out, to IDLE when hung up
// Deals with actual events
// Incoming call -- goes from IDLE to RINGING when it rings, to OFFHOOK when it's answered, to IDLE when its hung up.
// Outgoing call -- goes from IDLE to OFFHOOK when it dials out, to IDLE when hung up.
public void onCallStateChanged(Context context, int state, String number) {
if(lastState == state){
//No change, debounce extras
if (lastState == state) {
// No change, debounce extras.
return;
}
switch (state) {
......@@ -67,23 +70,21 @@ public abstract class PhonecallReceiver extends BroadcastReceiver {
onIncomingCallStarted(context, number, callStartTime);
break;
case TelephonyManager.CALL_STATE_OFFHOOK:
//Transition of ringing->offhook are pickups of incoming calls. Nothing done on them
if(lastState != TelephonyManager.CALL_STATE_RINGING){
// Transition of ringing->offhook are pickups of incoming calls. Nothing done on them.
if (lastState != TelephonyManager.CALL_STATE_RINGING) {
isIncoming = false;
callStartTime = new Date();
onOutgoingCallStarted(context, savedNumber, callStartTime);
}
break;
case TelephonyManager.CALL_STATE_IDLE:
//Went to idle- this is the end of a call. What type depends on previous state(s)
if(lastState == TelephonyManager.CALL_STATE_RINGING){
//Ring but no pickup- a miss
// Went to idle -- this is the end of a call. What type depends on previous state(s).
if (lastState == TelephonyManager.CALL_STATE_RINGING) {
// Ring but no pickup -- a miss.
onMissedCall(context, savedNumber, callStartTime);
}
else if(isIncoming){
} else if(isIncoming) {
onIncomingCallEnded(context, savedNumber, callStartTime, new Date());
}
else{
} else {
onOutgoingCallEnded(context, savedNumber, callStartTime, new Date());
}
break;
......
/************************************************************************************
** The MIT License (MIT)
**
** Copyright (c) 2016 S. "EXL" KLS
**
** Permission is hereby granted, free of charge, to any person obtaining a copy
** of this software and associated documentation files (the "Software"), to deal
** in the Software without restriction, including without limitation the rights
** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
** copies of the Software, and to permit persons to whom the Software is
** furnished to do so, subject to the following conditions:
**
** The above copyright notice and this permission notice shall be included in all
** copies or substantial portions of the Software.
**
** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
** IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
** FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
** AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
** LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
** OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
** SOFTWARE.
************************************************************************************/
package ru.exlmoto.synergycalls;
import android.app.Service;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment