-
Notifications
You must be signed in to change notification settings - Fork 1
add sms interception example #15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
IliaEremin
wants to merge
2
commits into
master
Choose a base branch
from
example/sms-interception
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| Приложение для перехвата и анализа входящих СМС | ||
| ================================================ | ||
| Приложение состоит из одного экрана, где можно указать номер телефона, смс от которого необходимо перехватывать. | ||
|
|
||
|  | ||
|
|
||
| **Как импортировать в свой проект?** | ||
|
|
||
| Вся логика происходит в классе SmsListener.</br> | ||
| Его необходимо скопировать и добавить в AndroidManifest.xml своего проекта | ||
| Также на устройствах начиная от 6.0 для чтения входящих смс необходимо получить разрешение от пользователя | ||
| на чтение смс `Manifest.permission.RECEIVE_SMS`. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| /build |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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' | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 *; | ||
| #} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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> |
27 changes: 27 additions & 0 deletions
27
SmsInterceptor/app/src/main/java/com/example/ereminilya/smsinterceptor/App.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| } | ||
| } |
37 changes: 37 additions & 0 deletions
37
SmsInterceptor/app/src/main/java/com/example/ereminilya/smsinterceptor/Settings.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
| } | ||
| } |
91 changes: 91 additions & 0 deletions
91
SmsInterceptor/app/src/main/java/com/example/ereminilya/smsinterceptor/SettingsScreen.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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(); | ||
| } | ||
|
|
||
| // Пользователь может внести телефон отправителя, смс от которого нужно перехватывать. | ||
| // Сообщение перехватывается и открывается экран с текстом этого сообщения. | ||
| // Приложении деплоить и описание в один из репозиториев примеров. | ||
| } |
56 changes: 56 additions & 0 deletions
56
SmsInterceptor/app/src/main/java/com/example/ereminilya/smsinterceptor/SmsListener.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 { | ||
|
|
||
| @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(); | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Проверить, всегда ли приходит номер
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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(); | ||
| } | ||
| } | ||
13 changes: 13 additions & 0 deletions
13
SmsInterceptor/app/src/main/java/com/example/ereminilya/smsinterceptor/utils/Strings.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
| } | ||
| } |
20 changes: 20 additions & 0 deletions
20
...ceptor/app/src/main/java/com/example/ereminilya/smsinterceptor/utils/di/AppComponent.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Проверить возможность съедать нотификейшены, чтобы смс приходила тихо