Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions SmsInterceptor/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
*.iml
.gradle
/local.properties
/.idea/
/.idea/libraries
.DS_Store
/build
/captures
.externalNativeBuild
12 changes: 12 additions & 0 deletions SmsInterceptor/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Приложение для перехвата и анализа входящих СМС
================================================
Приложение состоит из одного экрана, где можно указать номер телефона, смс от которого необходимо перехватывать.

![Screen_example](arts/screen1.jpg)

**Как импортировать в свой проект?**

Вся логика происходит в классе SmsListener.</br>
Его необходимо скопировать и добавить в AndroidManifest.xml своего проекта
Также на устройствах начиная от 6.0 для чтения входящих смс необходимо получить разрешение от пользователя
на чтение смс `Manifest.permission.RECEIVE_SMS`.
1 change: 1 addition & 0 deletions SmsInterceptor/app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
40 changes: 40 additions & 0 deletions SmsInterceptor/app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
apply plugin: 'com.android.application'
apply plugin: 'me.tatarka.retrolambda'
apply plugin: 'com.neenbedankt.android-apt'

android {
compileSdkVersion 25
buildToolsVersion "25.0.0"
defaultConfig {
applicationId "com.example.ereminilya.smsinterceptor"
minSdkVersion 15
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

}

dependencies {
compile 'com.android.support:appcompat-v7:25.0.0'
compile 'com.jakewharton:butterknife:7.0.0'
compile 'com.karumi:dexter:2.3.1'

compile "com.google.dagger:dagger:2.5"
apt "com.google.dagger:dagger-compiler:2.5"
provided 'javax.annotation:jsr250-api:1.0'

testCompile 'junit:junit:4.12'
}
17 changes: 17 additions & 0 deletions SmsInterceptor/app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in /Users/ereminilya/Library/Android/sdk/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# Add any project specific keep options here:

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
38 changes: 38 additions & 0 deletions SmsInterceptor/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.ereminilya.smsinterceptor"
>

<uses-permission android:name="android.permission.RECEIVE_SMS"/>

<application
android:name=".App"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme"
>

<activity android:name=".SettingsScreen">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>

<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>

<receiver
android:name=".SmsListener"
android:permission="android.permission.BROADCAST_SMS"
>
<intent-filter
android:priority="1000"
>
<action android:name="android.provider.Telephony.SMS_RECEIVED"/>
</intent-filter>
</receiver>

</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.example.ereminilya.smsinterceptor;

import android.app.Application;
import android.support.annotation.NonNull;

import com.example.ereminilya.smsinterceptor.utils.di.AppComponent;
import com.example.ereminilya.smsinterceptor.utils.di.AppModule;
import com.example.ereminilya.smsinterceptor.utils.di.DaggerAppComponent;
import com.karumi.dexter.Dexter;

/**
* Created by ereminilya on 24/11/16.
*/
public class App extends Application {

private AppComponent component;

@Override public void onCreate() {
super.onCreate();
Dexter.initialize(this);
component = DaggerAppComponent.builder().appModule(new AppModule(this)).build();
}

@NonNull public AppComponent getComponent() {
return component;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.example.ereminilya.smsinterceptor;

import android.support.annotation.NonNull;
import android.support.annotation.Nullable;

import com.example.ereminilya.smsinterceptor.utils.storage.Storage;

/**
* Created by ereminilya on 24/11/16.
*/
public class Settings {

private static final String KEY_PHONE_TO_INTERCEPT = "phoneToIntercept";
private static final String KEY_INTERCEPTION_ENABLED = "interceptionEnabled";

private final Storage storage;

public Settings(Storage storage) {
this.storage = storage;
}

public void saveNumber(@NonNull String phone) {
storage.putString(KEY_PHONE_TO_INTERCEPT, phone);
}

public void enableInterception(boolean enabled) {
storage.putBoolean(KEY_INTERCEPTION_ENABLED, enabled);
}

public boolean isInterceptionEnabled() {
return storage.getBoolean(KEY_INTERCEPTION_ENABLED, true);
}

@Nullable public String getPhoneToSpy() {
return storage.getString(KEY_PHONE_TO_INTERCEPT);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
package com.example.ereminilya.smsinterceptor;

import android.Manifest;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.support.v4.app.ActivityCompat;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.SwitchCompat;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import com.example.ereminilya.smsinterceptor.utils.di.Injector;
import com.karumi.dexter.Dexter;
import com.karumi.dexter.PermissionToken;
import com.karumi.dexter.listener.PermissionDeniedResponse;
import com.karumi.dexter.listener.PermissionGrantedResponse;
import com.karumi.dexter.listener.PermissionRequest;
import com.karumi.dexter.listener.single.PermissionListener;

import javax.inject.Inject;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class SettingsScreen extends AppCompatActivity {

@Inject Settings settings;

@Bind(R.id.phone_to_spy) TextView uiPhoneToSpy;
@Bind(R.id.sms_interception_toggle) SwitchCompat uiInterceptionEnabledToggle;
@Bind(R.id.grant_permission) View uiGrantPermissionBtn;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_settings_screen);
ButterKnife.bind(this);
Injector.inject(this);
if (savedInstanceState == null) {
uiInterceptionEnabledToggle.setChecked(settings.isInterceptionEnabled());
String phoneToSpy = settings.getPhoneToSpy();
if (phoneToSpy != null) {
uiPhoneToSpy.setText(phoneToSpy);
}
}
}

@Override protected void onResume() {
super.onResume();
int status = ActivityCompat.checkSelfPermission(this, Manifest.permission.RECEIVE_SMS);
if (status != PackageManager.PERMISSION_GRANTED) {
uiGrantPermissionBtn.setVisibility(View.VISIBLE);
}
}

@OnClick(R.id.grant_permission) void onGrantPermissioClick() {
Dexter.checkPermission(new PermissionListener() {
@Override public void onPermissionGranted(PermissionGrantedResponse response) {
Toast.makeText(SettingsScreen.this, R.string.receive_sms_granted, Toast.LENGTH_SHORT).show();
uiGrantPermissionBtn.setVisibility(View.GONE);
}

@Override public void onPermissionDenied(PermissionDeniedResponse response) {

}

@Override
public void onPermissionRationaleShouldBeShown(PermissionRequest permission, PermissionToken token) {

}
}, Manifest.permission.RECEIVE_SMS);
}

@OnClick(R.id.sms_interception_toggle) void onToggleClick(SwitchCompat toggle) {
boolean finalState = toggle.isChecked();
toggle.setChecked(finalState);
settings.enableInterception(finalState);
}

@OnClick(R.id.save) void onSaveClick() {
String phone = uiPhoneToSpy.getText().toString();
settings.saveNumber(phone);
Toast.makeText(this, getString(R.string.phone_updated, phone), Toast.LENGTH_SHORT).show();
}

// Пользователь может внести телефон отправителя, смс от которого нужно перехватывать.
// Сообщение перехватывается и открывается экран с текстом этого сообщения.
// Приложении деплоить и описание в один из репозиториев примеров.
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package com.example.ereminilya.smsinterceptor;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.telephony.SmsMessage;
import android.widget.Toast;

import com.example.ereminilya.smsinterceptor.utils.Strings;
import com.example.ereminilya.smsinterceptor.utils.di.Injector;

import javax.inject.Inject;

/**
* Created by ereminilya on 24/11/16.
*/

public class SmsListener extends BroadcastReceiver {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Проверить возможность съедать нотификейшены, чтобы смс приходила тихо


@Inject Settings settings;

@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals("android.provider.Telephony.SMS_RECEIVED")) {
Injector.inject(this, context);
Bundle bundle = intent.getExtras();
SmsMessage[] messages;
if (bundle != null) {
try {
Object[] pdus = (Object[]) bundle.get("pdus");
messages = new SmsMessage[pdus.length];
messages[0] = SmsMessage.createFromPdu((byte[]) pdus[0]);
String wholeString = getMessageText(messages[0]);
String sender = messages[0].getOriginatingAddress();
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Проверить, всегда ли приходит номер

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Посмотреть какие еще полезные поля здесь есть

if (Strings.equals(settings.getPhoneToSpy(), sender)) {
Toast.makeText(context, "message from " + sender + " intercepted: " + wholeString,
Toast.LENGTH_SHORT).show();
}
} catch (Exception ignored) {
Toast.makeText(context, "Something went wrong", Toast.LENGTH_SHORT).show();
}
}
}
}

/**
* if you need message body you can get it here
* @param message is intercepted SMS
* @return message text
*/
private String getMessageText(@NonNull SmsMessage message) {
return message.getMessageBody();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.example.ereminilya.smsinterceptor.utils;

import android.support.annotation.Nullable;

/**
* Created by ereminilya on 24/11/16.
*/
public class Strings {

public static boolean equals(@Nullable String str1, @Nullable String str2) {
return !(str1 == null || str2 == null) && str1.equals(str2);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.example.ereminilya.smsinterceptor.utils.di;

import com.example.ereminilya.smsinterceptor.SettingsScreen;
import com.example.ereminilya.smsinterceptor.SmsListener;

import javax.inject.Singleton;

import dagger.Component;

/**
* Created by ereminilya on 24/11/16.
*/
@Singleton
@Component(modules = {AppModule.class})
public interface AppComponent {

void inject(SettingsScreen settingsScreen);

void inject(SmsListener smsListener);
}
Loading