├── settings.gradle
├── gradle.properties
├── screenshots
└── android-screenshot-phone.png
├── Packet Sender
├── src
│ └── main
│ │ ├── ic_launcher-web.png
│ │ ├── res
│ │ ├── drawable
│ │ │ ├── rx.png
│ │ │ ├── tx.png
│ │ │ ├── rx_tcp.png
│ │ │ ├── rx_udp.png
│ │ │ ├── tx_tcp.png
│ │ │ ├── tx_udp.png
│ │ │ ├── rx_white.png
│ │ │ ├── rx_yellow.png
│ │ │ ├── moveupdown.png
│ │ │ ├── statusnotification.png
│ │ │ └── ic_launcher_status24.png
│ │ ├── drawable-hdpi
│ │ │ ├── ic_launcher.png
│ │ │ ├── ic_action_new.png
│ │ │ ├── ic_action_accept.png
│ │ │ ├── ic_action_remove.png
│ │ │ ├── ic_action_search.png
│ │ │ ├── ic_action_discard.png
│ │ │ ├── ic_action_refresh.png
│ │ │ ├── ic_launcher_status.png
│ │ │ └── ic_action_network_wifi.png
│ │ ├── drawable-mdpi
│ │ │ ├── ic_launcher.png
│ │ │ ├── ic_action_new.png
│ │ │ ├── ic_action_accept.png
│ │ │ ├── ic_action_remove.png
│ │ │ ├── ic_action_search.png
│ │ │ ├── ic_action_discard.png
│ │ │ ├── ic_action_refresh.png
│ │ │ ├── ic_launcher_status.png
│ │ │ └── ic_action_network_wifi.png
│ │ ├── drawable-xhdpi
│ │ │ ├── ic_action_new.png
│ │ │ ├── ic_launcher.png
│ │ │ ├── ic_action_accept.png
│ │ │ ├── ic_action_discard.png
│ │ │ ├── ic_action_refresh.png
│ │ │ ├── ic_action_remove.png
│ │ │ ├── ic_action_search.png
│ │ │ ├── ic_launcher_status.png
│ │ │ └── ic_action_network_wifi.png
│ │ ├── drawable-xxhdpi
│ │ │ ├── ic_launcher.png
│ │ │ ├── ic_action_new.png
│ │ │ ├── ic_action_accept.png
│ │ │ ├── ic_action_discard.png
│ │ │ ├── ic_action_refresh.png
│ │ │ ├── ic_action_remove.png
│ │ │ ├── ic_action_search.png
│ │ │ ├── ic_launcher_status.png
│ │ │ └── ic_action_network_wifi.png
│ │ ├── xml
│ │ │ ├── searchable.xml
│ │ │ └── packetsenderwidget_provider.xml
│ │ ├── values
│ │ │ ├── styles.xml
│ │ │ ├── dimens.xml
│ │ │ └── strings.xml
│ │ ├── layout
│ │ │ ├── activity_main.xml
│ │ │ ├── activity_new_packet.xml
│ │ │ ├── activity_about.xml
│ │ │ ├── activity_pswidget_on_create.xml
│ │ │ ├── fragment_main.xml
│ │ │ ├── packetlist.xml
│ │ │ ├── widget_layout.xml
│ │ │ ├── fragment_pswidget_on_create.xml
│ │ │ ├── trafficlist.xml
│ │ │ ├── fragment_about.xml
│ │ │ ├── packetrow.xml
│ │ │ ├── settingsform.xml
│ │ │ └── fragment_new_packet.xml
│ │ ├── menu
│ │ │ ├── acceptchangemenu.xml
│ │ │ ├── about.xml
│ │ │ ├── trafficlogmenu.xml
│ │ │ └── packetlistmenu.xml
│ │ └── values-w820dp
│ │ │ └── dimens.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ └── com
│ │ └── packetsender
│ │ └── android
│ │ ├── AboutActivity.java
│ │ ├── PacketAdapter.java
│ │ ├── PSWidgetOnCreate.java
│ │ ├── Packet.java
│ │ ├── NewPacketActivity.java
│ │ ├── PacketSenderWidget.java
│ │ ├── DataStorage.java
│ │ ├── PacketListenerService.java
│ │ └── MainActivity.java
├── proguard-rules.txt
├── build.gradle
└── Packet Sender.iml
├── libraries
├── support_v4_19_0_0.xml
└── support_v13_19_0_0.xml
├── .gitignore
├── modules.xml
├── compiler.xml
├── README.md
├── LICENSE
└── misc.xml
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':Packet Sender'
2 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Set Gradle settings which apply to all modules here.
--------------------------------------------------------------------------------
/screenshots/android-screenshot-phone.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dannagle/PacketSender-Android/HEAD/screenshots/android-screenshot-phone.png
--------------------------------------------------------------------------------
/Packet Sender/src/main/ic_launcher-web.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dannagle/PacketSender-Android/HEAD/Packet Sender/src/main/ic_launcher-web.png
--------------------------------------------------------------------------------
/Packet Sender/src/main/res/drawable/rx.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dannagle/PacketSender-Android/HEAD/Packet Sender/src/main/res/drawable/rx.png
--------------------------------------------------------------------------------
/Packet Sender/src/main/res/drawable/tx.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dannagle/PacketSender-Android/HEAD/Packet Sender/src/main/res/drawable/tx.png
--------------------------------------------------------------------------------
/Packet Sender/src/main/res/drawable/rx_tcp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dannagle/PacketSender-Android/HEAD/Packet Sender/src/main/res/drawable/rx_tcp.png
--------------------------------------------------------------------------------
/Packet Sender/src/main/res/drawable/rx_udp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dannagle/PacketSender-Android/HEAD/Packet Sender/src/main/res/drawable/rx_udp.png
--------------------------------------------------------------------------------
/Packet Sender/src/main/res/drawable/tx_tcp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dannagle/PacketSender-Android/HEAD/Packet Sender/src/main/res/drawable/tx_tcp.png
--------------------------------------------------------------------------------
/Packet Sender/src/main/res/drawable/tx_udp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dannagle/PacketSender-Android/HEAD/Packet Sender/src/main/res/drawable/tx_udp.png
--------------------------------------------------------------------------------
/Packet Sender/src/main/res/drawable/rx_white.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dannagle/PacketSender-Android/HEAD/Packet Sender/src/main/res/drawable/rx_white.png
--------------------------------------------------------------------------------
/Packet Sender/src/main/res/drawable/rx_yellow.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dannagle/PacketSender-Android/HEAD/Packet Sender/src/main/res/drawable/rx_yellow.png
--------------------------------------------------------------------------------
/Packet Sender/src/main/res/drawable/moveupdown.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dannagle/PacketSender-Android/HEAD/Packet Sender/src/main/res/drawable/moveupdown.png
--------------------------------------------------------------------------------
/Packet Sender/src/main/res/drawable-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dannagle/PacketSender-Android/HEAD/Packet Sender/src/main/res/drawable-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/Packet Sender/src/main/res/drawable-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dannagle/PacketSender-Android/HEAD/Packet Sender/src/main/res/drawable-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/Packet Sender/src/main/res/drawable-hdpi/ic_action_new.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dannagle/PacketSender-Android/HEAD/Packet Sender/src/main/res/drawable-hdpi/ic_action_new.png
--------------------------------------------------------------------------------
/Packet Sender/src/main/res/drawable-mdpi/ic_action_new.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dannagle/PacketSender-Android/HEAD/Packet Sender/src/main/res/drawable-mdpi/ic_action_new.png
--------------------------------------------------------------------------------
/Packet Sender/src/main/res/drawable-xhdpi/ic_action_new.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dannagle/PacketSender-Android/HEAD/Packet Sender/src/main/res/drawable-xhdpi/ic_action_new.png
--------------------------------------------------------------------------------
/Packet Sender/src/main/res/drawable-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dannagle/PacketSender-Android/HEAD/Packet Sender/src/main/res/drawable-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/Packet Sender/src/main/res/drawable-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dannagle/PacketSender-Android/HEAD/Packet Sender/src/main/res/drawable-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/Packet Sender/src/main/res/drawable/statusnotification.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dannagle/PacketSender-Android/HEAD/Packet Sender/src/main/res/drawable/statusnotification.png
--------------------------------------------------------------------------------
/Packet Sender/src/main/res/drawable-hdpi/ic_action_accept.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dannagle/PacketSender-Android/HEAD/Packet Sender/src/main/res/drawable-hdpi/ic_action_accept.png
--------------------------------------------------------------------------------
/Packet Sender/src/main/res/drawable-hdpi/ic_action_remove.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dannagle/PacketSender-Android/HEAD/Packet Sender/src/main/res/drawable-hdpi/ic_action_remove.png
--------------------------------------------------------------------------------
/Packet Sender/src/main/res/drawable-hdpi/ic_action_search.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dannagle/PacketSender-Android/HEAD/Packet Sender/src/main/res/drawable-hdpi/ic_action_search.png
--------------------------------------------------------------------------------
/Packet Sender/src/main/res/drawable-mdpi/ic_action_accept.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dannagle/PacketSender-Android/HEAD/Packet Sender/src/main/res/drawable-mdpi/ic_action_accept.png
--------------------------------------------------------------------------------
/Packet Sender/src/main/res/drawable-mdpi/ic_action_remove.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dannagle/PacketSender-Android/HEAD/Packet Sender/src/main/res/drawable-mdpi/ic_action_remove.png
--------------------------------------------------------------------------------
/Packet Sender/src/main/res/drawable-mdpi/ic_action_search.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dannagle/PacketSender-Android/HEAD/Packet Sender/src/main/res/drawable-mdpi/ic_action_search.png
--------------------------------------------------------------------------------
/Packet Sender/src/main/res/drawable-xxhdpi/ic_action_new.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dannagle/PacketSender-Android/HEAD/Packet Sender/src/main/res/drawable-xxhdpi/ic_action_new.png
--------------------------------------------------------------------------------
/Packet Sender/src/main/res/drawable/ic_launcher_status24.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dannagle/PacketSender-Android/HEAD/Packet Sender/src/main/res/drawable/ic_launcher_status24.png
--------------------------------------------------------------------------------
/Packet Sender/src/main/res/drawable-hdpi/ic_action_discard.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dannagle/PacketSender-Android/HEAD/Packet Sender/src/main/res/drawable-hdpi/ic_action_discard.png
--------------------------------------------------------------------------------
/Packet Sender/src/main/res/drawable-hdpi/ic_action_refresh.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dannagle/PacketSender-Android/HEAD/Packet Sender/src/main/res/drawable-hdpi/ic_action_refresh.png
--------------------------------------------------------------------------------
/Packet Sender/src/main/res/drawable-hdpi/ic_launcher_status.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dannagle/PacketSender-Android/HEAD/Packet Sender/src/main/res/drawable-hdpi/ic_launcher_status.png
--------------------------------------------------------------------------------
/Packet Sender/src/main/res/drawable-mdpi/ic_action_discard.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dannagle/PacketSender-Android/HEAD/Packet Sender/src/main/res/drawable-mdpi/ic_action_discard.png
--------------------------------------------------------------------------------
/Packet Sender/src/main/res/drawable-mdpi/ic_action_refresh.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dannagle/PacketSender-Android/HEAD/Packet Sender/src/main/res/drawable-mdpi/ic_action_refresh.png
--------------------------------------------------------------------------------
/Packet Sender/src/main/res/drawable-mdpi/ic_launcher_status.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dannagle/PacketSender-Android/HEAD/Packet Sender/src/main/res/drawable-mdpi/ic_launcher_status.png
--------------------------------------------------------------------------------
/Packet Sender/src/main/res/drawable-xhdpi/ic_action_accept.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dannagle/PacketSender-Android/HEAD/Packet Sender/src/main/res/drawable-xhdpi/ic_action_accept.png
--------------------------------------------------------------------------------
/Packet Sender/src/main/res/drawable-xhdpi/ic_action_discard.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dannagle/PacketSender-Android/HEAD/Packet Sender/src/main/res/drawable-xhdpi/ic_action_discard.png
--------------------------------------------------------------------------------
/Packet Sender/src/main/res/drawable-xhdpi/ic_action_refresh.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dannagle/PacketSender-Android/HEAD/Packet Sender/src/main/res/drawable-xhdpi/ic_action_refresh.png
--------------------------------------------------------------------------------
/Packet Sender/src/main/res/drawable-xhdpi/ic_action_remove.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dannagle/PacketSender-Android/HEAD/Packet Sender/src/main/res/drawable-xhdpi/ic_action_remove.png
--------------------------------------------------------------------------------
/Packet Sender/src/main/res/drawable-xhdpi/ic_action_search.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dannagle/PacketSender-Android/HEAD/Packet Sender/src/main/res/drawable-xhdpi/ic_action_search.png
--------------------------------------------------------------------------------
/Packet Sender/src/main/res/drawable-xhdpi/ic_launcher_status.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dannagle/PacketSender-Android/HEAD/Packet Sender/src/main/res/drawable-xhdpi/ic_launcher_status.png
--------------------------------------------------------------------------------
/Packet Sender/src/main/res/drawable-xxhdpi/ic_action_accept.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dannagle/PacketSender-Android/HEAD/Packet Sender/src/main/res/drawable-xxhdpi/ic_action_accept.png
--------------------------------------------------------------------------------
/Packet Sender/src/main/res/drawable-xxhdpi/ic_action_discard.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dannagle/PacketSender-Android/HEAD/Packet Sender/src/main/res/drawable-xxhdpi/ic_action_discard.png
--------------------------------------------------------------------------------
/Packet Sender/src/main/res/drawable-xxhdpi/ic_action_refresh.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dannagle/PacketSender-Android/HEAD/Packet Sender/src/main/res/drawable-xxhdpi/ic_action_refresh.png
--------------------------------------------------------------------------------
/Packet Sender/src/main/res/drawable-xxhdpi/ic_action_remove.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dannagle/PacketSender-Android/HEAD/Packet Sender/src/main/res/drawable-xxhdpi/ic_action_remove.png
--------------------------------------------------------------------------------
/Packet Sender/src/main/res/drawable-xxhdpi/ic_action_search.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dannagle/PacketSender-Android/HEAD/Packet Sender/src/main/res/drawable-xxhdpi/ic_action_search.png
--------------------------------------------------------------------------------
/Packet Sender/src/main/res/drawable-xxhdpi/ic_launcher_status.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dannagle/PacketSender-Android/HEAD/Packet Sender/src/main/res/drawable-xxhdpi/ic_launcher_status.png
--------------------------------------------------------------------------------
/Packet Sender/src/main/res/drawable-hdpi/ic_action_network_wifi.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dannagle/PacketSender-Android/HEAD/Packet Sender/src/main/res/drawable-hdpi/ic_action_network_wifi.png
--------------------------------------------------------------------------------
/Packet Sender/src/main/res/drawable-mdpi/ic_action_network_wifi.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dannagle/PacketSender-Android/HEAD/Packet Sender/src/main/res/drawable-mdpi/ic_action_network_wifi.png
--------------------------------------------------------------------------------
/Packet Sender/src/main/res/drawable-xhdpi/ic_action_network_wifi.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dannagle/PacketSender-Android/HEAD/Packet Sender/src/main/res/drawable-xhdpi/ic_action_network_wifi.png
--------------------------------------------------------------------------------
/Packet Sender/src/main/res/drawable-xxhdpi/ic_action_network_wifi.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dannagle/PacketSender-Android/HEAD/Packet Sender/src/main/res/drawable-xxhdpi/ic_action_network_wifi.png
--------------------------------------------------------------------------------
/Packet Sender/src/main/res/xml/searchable.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
--------------------------------------------------------------------------------
/Packet Sender/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/Packet Sender/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
7 |
--------------------------------------------------------------------------------
/libraries/support_v4_19_0_0.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/Packet Sender/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
7 |
--------------------------------------------------------------------------------
/libraries/support_v13_19_0_0.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/Packet Sender/src/main/res/layout/activity_new_packet.xml:
--------------------------------------------------------------------------------
1 |
8 |
--------------------------------------------------------------------------------
/Packet Sender/src/main/res/menu/acceptchangemenu.xml:
--------------------------------------------------------------------------------
1 |
9 |
--------------------------------------------------------------------------------
/Packet Sender/src/main/res/layout/activity_about.xml:
--------------------------------------------------------------------------------
1 |
8 |
--------------------------------------------------------------------------------
/Packet Sender/src/main/res/layout/activity_pswidget_on_create.xml:
--------------------------------------------------------------------------------
1 |
8 |
--------------------------------------------------------------------------------
/Packet Sender/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/Packet Sender/src/main/res/xml/packetsenderwidget_provider.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
--------------------------------------------------------------------------------
/Packet Sender/src/main/res/menu/about.xml:
--------------------------------------------------------------------------------
1 |
10 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Built application files
2 | *.apk
3 | *.ap_
4 |
5 | # Files for the Dalvik VM
6 | *.dex
7 |
8 | # Java class files
9 | *.class
10 |
11 | # Generated files
12 | bin/
13 | gen/
14 |
15 | # Gradle files
16 | .gradle/
17 | build/
18 | /*/build/
19 |
20 | # Local configuration file (sdk path, etc)
21 | local.properties
22 |
23 | # Proguard folder generated by Eclipse
24 | proguard/
25 |
26 | # Log Files
27 | *.log
28 |
29 | .DS_Store
30 |
--------------------------------------------------------------------------------
/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/Packet Sender/src/main/res/layout/fragment_main.xml:
--------------------------------------------------------------------------------
1 |
10 |
11 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/Packet Sender/proguard-rules.txt:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in C:/Program Files (x86)/Android/android-studio/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the ProGuard
5 | # include property in project.properties.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
--------------------------------------------------------------------------------
/compiler.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 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | *This repo has been abandoned.* The mobile edition is now a Xamarin project that exists here:
2 | https://github.com/dannagle/Packet_Sender_Mobile
3 |
4 |
5 | # Packet Sender for Android
6 | This was the native Android version of Packet Sender for Desktop. The project is not being actively developed.
7 |
8 |
9 |
10 | ## Parent project
11 | This was originally an attempt to rewrite the GPL-based desktop version:
12 | https://github.com/dannagle/PacketSender
13 |
14 |
15 | ## License
16 |
17 | MIT. Feel free to fork and make it your own.
18 |
19 |
20 | ## Copyright
21 |
22 | Packet Sender is wholly owned and copyright © - [@NagleCode](http://twitter.com/NagleCode) - [DanNagle.com](http://DanNagle.com) - [PacketSender.com](http://PacketSender.com)
23 |
--------------------------------------------------------------------------------
/Packet Sender/src/main/res/layout/packetlist.xml:
--------------------------------------------------------------------------------
1 |
10 |
11 |
12 |
17 |
18 |
19 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/Packet Sender/src/main/res/menu/trafficlogmenu.xml:
--------------------------------------------------------------------------------
1 |
23 |
--------------------------------------------------------------------------------
/Packet Sender/src/main/res/menu/packetlistmenu.xml:
--------------------------------------------------------------------------------
1 |
25 |
--------------------------------------------------------------------------------
/Packet Sender/src/main/res/layout/widget_layout.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
14 |
15 |
26 |
27 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2015 Dan Nagle
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
23 |
--------------------------------------------------------------------------------
/Packet Sender/src/main/res/layout/fragment_pswidget_on_create.xml:
--------------------------------------------------------------------------------
1 |
10 |
11 |
12 |
18 |
19 |
24 |
25 |
26 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/Packet Sender/build.gradle:
--------------------------------------------------------------------------------
1 | buildscript {
2 | repositories {
3 | mavenCentral()
4 | }
5 | dependencies {
6 | classpath 'com.android.tools.build:gradle:0.7.+'
7 | }
8 | }
9 | apply plugin: 'android'
10 |
11 | repositories {
12 | mavenCentral()
13 | }
14 | allprojects {
15 | tasks.withType(Compile) {
16 | options.compilerArgs << "-Xlint:deprecation"
17 | }
18 | }
19 | android {
20 | compileSdkVersion 19
21 | buildToolsVersion "17.0.0"
22 |
23 | signingConfigs {
24 | release {
25 | storeFile file("paydowncalc.keystore")
26 | storePassword "tiasp1814"
27 | keyAlias "paydowncalc"
28 | keyPassword "tiasp1814"
29 | }
30 | }
31 | defaultConfig {
32 | minSdkVersion 14
33 | targetSdkVersion 19
34 | }
35 | buildTypes {
36 | release {
37 | runProguard true
38 | proguardFile getDefaultProguardFile('proguard-android-optimize.txt')
39 | signingConfig signingConfigs.release
40 | }
41 | }
42 | productFlavors {
43 | defaultFlavor {
44 | proguardFile 'proguard-rules.txt'
45 | }
46 | }
47 | }
48 |
49 | dependencies {
50 | compile 'com.android.support:support-v13:+'
51 | }
52 |
--------------------------------------------------------------------------------
/Packet Sender/src/main/res/layout/trafficlist.xml:
--------------------------------------------------------------------------------
1 |
10 |
11 |
12 |
18 |
19 |
24 |
25 |
26 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/Packet Sender/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Packet Sender
5 | Packets
6 | Traffic Log
7 | Settings
8 | About
9 |
10 |
11 | - TCP
12 | - UDP
13 |
14 |
15 | NewPacketActivity
16 | Settings
17 | About Packet Sender
18 |
19 | Packet Sender for Android
21 | Thank you for supporting software that supports you!
22 |
23 |
This app contains :
24 |
25 |
• no ads
26 |
• no bundleware
27 |
• no internal tracking or analytics software
28 |
• no pop-ups begging for likes or reviews
29 |
• only the bare minimum permissions to do its work
30 |
31 |
32 | If you like the mobile version, check out the free desktop version! Also, please
33 | tell your friends about Packet Sender.
34 |
35 |
36 | Packet Sender is wholly owned and © Dan Nagle.
37 |
38 | ]]>
39 |
40 | Packet Sender Widget
41 |
42 |
43 |
--------------------------------------------------------------------------------
/Packet Sender/src/main/res/layout/fragment_about.xml:
--------------------------------------------------------------------------------
1 |
10 |
11 |
16 |
17 |
18 |
19 |
24 |
25 |
26 |
34 |
35 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
--------------------------------------------------------------------------------
/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
19 |
20 |
21 |
22 |
23 |
24 | Android 4.2.2 Platform
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 | 1.6
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
--------------------------------------------------------------------------------
/Packet Sender/src/main/res/layout/packetrow.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
11 |
18 |
19 |
24 |
25 |
32 |
40 |
47 |
48 |
57 |
58 |
59 |
60 |
--------------------------------------------------------------------------------
/Packet Sender/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
9 |
10 |
13 |
14 |
19 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
34 |
35 |
40 |
43 |
44 |
48 |
51 |
52 |
53 |
54 |
57 |
58 |
59 |
60 |
61 |
64 |
65 |
66 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
--------------------------------------------------------------------------------
/Packet Sender/src/main/java/com/packetsender/android/AboutActivity.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2014 Dan Nagle. All rights reserved.
2 | //
3 | // Licensed MIT: https://github.com/dannagle/PacketSender-Android
4 |
5 |
6 | package com.packetsender.android;
7 |
8 | import android.app.Activity;
9 | import android.app.ActionBar;
10 | import android.app.Fragment;
11 | import android.content.Intent;
12 | import android.net.Uri;
13 | import android.os.Bundle;
14 | import android.text.Html;
15 | import android.util.Log;
16 | import android.view.LayoutInflater;
17 | import android.view.Menu;
18 | import android.view.MenuItem;
19 | import android.view.View;
20 | import android.view.ViewGroup;
21 | import android.os.Build;
22 | import android.widget.Button;
23 | import android.widget.TextView;
24 |
25 | public class AboutActivity extends Activity {
26 |
27 | @Override
28 | protected void onCreate(Bundle savedInstanceState) {
29 | super.onCreate(savedInstanceState);
30 | setContentView(R.layout.activity_about);
31 |
32 | if (savedInstanceState == null) {
33 | getFragmentManager().beginTransaction()
34 | .add(R.id.container, new PlaceholderFragment())
35 | .commit();
36 | }
37 |
38 | }
39 |
40 |
41 | @Override
42 | public boolean onCreateOptionsMenu(Menu menu) {
43 |
44 | // Inflate the menu; this adds items to the action bar if it is present.
45 | getMenuInflater().inflate(R.menu.about, menu);
46 | return true;
47 | }
48 |
49 | @Override
50 | public boolean onOptionsItemSelected(MenuItem item) {
51 | // Handle action bar item clicks here. The action bar will
52 | // automatically handle clicks on the Home/Up button, so long
53 | // as you specify a parent activity in AndroidManifest.xml.
54 | int id = item.getItemId();
55 | if (id == R.id.action_settings) {
56 | return true;
57 | }
58 | return super.onOptionsItemSelected(item);
59 | }
60 |
61 | /**
62 | * A placeholder fragment containing a simple view.
63 | */
64 | public static class PlaceholderFragment extends Fragment {
65 |
66 | public PlaceholderFragment() {
67 | }
68 |
69 | @Override
70 | public View onCreateView(LayoutInflater inflater, ViewGroup container,
71 | Bundle savedInstanceState) {
72 | View rootView = inflater.inflate(R.layout.fragment_about, container, false);
73 |
74 | TextView aboutBlurb = (TextView) rootView.findViewById(R.id.aboutBlurb);
75 | aboutBlurb.setText(Html.fromHtml(getString(R.string.about_html)));
76 |
77 | TextView shopAmazonButton = (TextView) rootView.findViewById(R.id.shopAmazonButton);
78 |
79 | shopAmazonButton.setOnClickListener(new Button.OnClickListener() {
80 | public void onClick(View v)
81 | {
82 | //go to dannagle.com/amazon
83 | Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://packetsender.com/"));
84 | startActivity(browserIntent);
85 | }
86 | });
87 |
88 | /*
89 |
90 | TextView packetsenderButton = (TextView) rootView.findViewById(R.id.packetsenderButton);
91 | packetsenderButton.setOnClickListener(new Button.OnClickListener() {
92 | public void onClick(View v)
93 | {
94 | //go to dannagle.com/amazon
95 |
96 | Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://packetsender.com/"));
97 | startActivity(browserIntent);
98 | }
99 | });
100 | */
101 | return rootView;
102 | }
103 | }
104 |
105 | }
106 |
--------------------------------------------------------------------------------
/Packet Sender/src/main/res/layout/settingsform.xml:
--------------------------------------------------------------------------------
1 |
10 |
11 |
12 |
17 |
18 |
23 |
24 |
25 |
32 |
33 |
34 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
52 |
53 |
54 |
59 |
60 |
61 |
62 |
63 |
64 |
69 |
70 |
71 |
72 |
77 |
78 |
85 |
86 |
87 |
88 |
89 |
90 |
95 |
96 |
97 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
113 |
114 |
115 |
116 |
121 |
122 |
129 |
130 |
131 |
132 |
133 |
140 |
141 |
142 |
143 |
144 |
145 |
146 |
--------------------------------------------------------------------------------
/Packet Sender/src/main/java/com/packetsender/android/PacketAdapter.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2014 Dan Nagle. All rights reserved.
2 | //
3 | // Licensed MIT: https://github.com/dannagle/PacketSender-Android
4 | package com.packetsender.android;
5 |
6 | import android.content.Context;
7 | import android.text.Html;
8 | import android.util.Log;
9 | import android.view.LayoutInflater;
10 | import android.view.View;
11 | import android.view.ViewGroup;
12 | import android.widget.ArrayAdapter;
13 | import android.widget.ImageView;
14 | import android.widget.TextView;
15 |
16 | import java.util.ArrayList;
17 | import java.util.Arrays;
18 | import java.util.Collections;
19 | import java.util.List;
20 |
21 |
22 | public class PacketAdapter extends ArrayAdapter {
23 |
24 | private List packets;
25 | private Context ctx;
26 |
27 | private static String[] getObjects(Packet[] thePackets) {
28 |
29 | String [] returnList = new String[thePackets.length];
30 |
31 | for(int i = 0 ; i();
42 | ctx = context;
43 | setList(thePackets);
44 | }
45 |
46 | public void clear() {
47 | packets.clear();
48 | }
49 |
50 | public void setList(Packet [] packetArray) {
51 | packets.clear();
52 | packets.addAll(Arrays.asList(packetArray));
53 | Log.d("adapter", DataStorage.FILE_LINE("List now has " + packets.size() + " packets"));
54 | }
55 |
56 |
57 | public void addPacket(Packet packet) {
58 | Log.d("adapter", DataStorage.FILE_LINE("Adding packet " + packet.name));
59 | packets.add(packet);
60 | }
61 |
62 | public boolean isEmpty() {
63 |
64 | return packets.isEmpty();
65 |
66 | }
67 |
68 |
69 | @Override
70 | public View getView(int position, View convertView, ViewGroup parent) {
71 | LayoutInflater inflater = (LayoutInflater) ctx
72 | .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
73 | View rowView = inflater.inflate(R.layout.packetrow, parent, false);
74 | TextView firstLine = (TextView) rowView.findViewById(R.id.firstLine);
75 | TextView errorLine = (TextView) rowView.findViewById(R.id.errorLine);
76 | TextView middleLine = (TextView) rowView.findViewById(R.id.middleLine);
77 | TextView secondline = (TextView) rowView.findViewById(R.id.secondLine);
78 |
79 | Packet packet = packets.get(position);
80 |
81 | long timestampTest = -1;
82 | try {
83 | timestampTest = Long.parseLong(packet.name);
84 | } catch (NumberFormatException e) {
85 | //Ignore.
86 | timestampTest = -1;
87 | }
88 |
89 |
90 | Log.d("adapter", DataStorage.FILE_LINE("Error string is " + packet.errorString));
91 |
92 | //Rather cheesy to detect traffic log: Setting the name as the timestamp
93 | //If name is a long between a reasonable millisecond epoch, then show a date.
94 |
95 | if(timestampTest > 1380000000000L && timestampTest < 9380000000000L) {
96 | firstLine.setText(packet.timestampString());
97 | if(packet.errorString.isEmpty()) {
98 | errorLine.setVisibility(View.GONE);
99 | } else {
100 | errorLine.setText(packet.errorString);
101 | errorLine.setVisibility(View.VISIBLE);
102 | }
103 | } else {
104 | firstLine.setText(packet.name);
105 | errorLine.setVisibility(View.GONE);
106 | }
107 |
108 | String ascii = packet.toAscii();
109 | if(ascii.length() > 75) {
110 | ascii = ascii.substring(0, Math.min(ascii.length(), 75)) + "...";
111 | }
112 |
113 | secondline.setText(ascii);
114 | // Change the icon for Windows and iPhone
115 |
116 | if(packet.toIP.equalsIgnoreCase("you")) {
117 | middleLine.setText(packet.fromIP + ":" + packet.fromPort + Html.fromHtml(" → ") + "You");
118 | }
119 | if(packet.fromIP.equalsIgnoreCase("you")) {
120 | middleLine.setText("You" + Html.fromHtml(" → ") + packet.toIP + ":" + packet.port);
121 | }
122 |
123 | ImageView icon = (ImageView) rowView.findViewById(R.id.icon);
124 | if(packet.tcpOrUdp.equalsIgnoreCase("udp")) {
125 | if(packet.toIP.equalsIgnoreCase("you")) {
126 | icon.setImageResource(R.drawable.rx_udp);
127 |
128 | } else {
129 | icon.setImageResource(R.drawable.tx_udp);
130 | }
131 | } else {
132 | if(packet.toIP.equalsIgnoreCase("you")) {
133 | icon.setImageResource(R.drawable.rx_tcp);
134 | } else {
135 | icon.setImageResource(R.drawable.tx_tcp);
136 | }
137 | }
138 |
139 | return rowView;
140 | }
141 | }
142 |
--------------------------------------------------------------------------------
/Packet Sender/src/main/res/layout/fragment_new_packet.xml:
--------------------------------------------------------------------------------
1 |
10 |
11 |
15 |
20 |
21 |
22 |
23 |
28 |
29 |
30 |
35 |
36 |
43 |
44 |
45 |
46 |
47 |
52 |
53 |
54 |
55 |
61 |
62 |
70 |
71 |
72 |
73 |
74 |
79 |
80 |
81 |
86 |
87 |
95 |
96 |
97 |
98 |
99 |
100 |
105 |
106 |
107 |
108 |
113 |
114 |
115 |
122 |
123 |
124 |
125 |
130 |
131 |
132 |
133 |
138 |
139 |
140 |
148 |
149 |
150 |
151 |
156 |
157 |
158 |
159 |
164 |
165 |
166 |
167 |
173 |
174 |
175 |
176 |
183 |
190 |
191 |
192 |
198 |
199 |
200 |
201 |
202 |
203 |
--------------------------------------------------------------------------------
/Packet Sender/Packet Sender.iml:
--------------------------------------------------------------------------------
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 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
--------------------------------------------------------------------------------
/Packet Sender/src/main/java/com/packetsender/android/PSWidgetOnCreate.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2014 Dan Nagle. All rights reserved.
2 | //
3 | // Licensed MIT: https://github.com/dannagle/PacketSender-Android
4 | package com.packetsender.android;
5 |
6 | import android.app.Activity;
7 | import android.app.ActionBar;
8 | import android.app.Fragment;
9 | import android.app.PendingIntent;
10 | import android.appwidget.AppWidgetManager;
11 | import android.content.Context;
12 | import android.content.Intent;
13 | import android.os.Bundle;
14 | import android.util.Log;
15 | import android.view.LayoutInflater;
16 | import android.view.Menu;
17 | import android.view.MenuItem;
18 | import android.view.View;
19 | import android.view.ViewGroup;
20 | import android.os.Build;
21 | import android.widget.AdapterView;
22 | import android.widget.Button;
23 | import android.widget.ListView;
24 | import android.widget.RemoteViews;
25 | import android.widget.TextView;
26 | import android.widget.Toast;
27 |
28 | public class PSWidgetOnCreate extends Activity {
29 |
30 |
31 | Button configOkButton;
32 | int mAppWidgetId = AppWidgetManager.INVALID_APPWIDGET_ID;
33 |
34 |
35 | @Override
36 | protected void onCreate(Bundle savedInstanceState) {
37 | super.onCreate(savedInstanceState);
38 |
39 |
40 | setResult(RESULT_CANCELED);
41 |
42 |
43 | Intent intent = getIntent();
44 | Bundle extras = intent.getExtras();
45 | if (extras != null) {
46 | mAppWidgetId = extras.getInt(
47 | AppWidgetManager.EXTRA_APPWIDGET_ID,
48 | AppWidgetManager.INVALID_APPWIDGET_ID);
49 | }
50 |
51 | // If they gave us an intent without the widget id, just bail.
52 | if (mAppWidgetId == AppWidgetManager.INVALID_APPWIDGET_ID) {
53 | finish();
54 | }
55 |
56 | setContentView(R.layout.activity_pswidget_on_create);
57 |
58 |
59 | if (savedInstanceState == null) {
60 | getFragmentManager().beginTransaction()
61 | .add(R.id.container, new PlaceholderFragment())
62 | .commit();
63 | }
64 |
65 |
66 |
67 |
68 | }
69 |
70 | private DataStorage dataStore;
71 |
72 | public void onCreatePacketsList(View rootView) {
73 |
74 |
75 | ListView packetListView = (ListView) rootView.findViewById(R.id.packetlist4widget);
76 |
77 |
78 | dataStore = new DataStorage(
79 | getSharedPreferences(DataStorage.PREFS_SETTINGS_NAME, 0),
80 | getSharedPreferences(DataStorage.PREFS_SAVEDPACKETS_NAME, 0),
81 | getSharedPreferences(DataStorage.PREFS_SERVICELOG_NAME, 0),
82 | getSharedPreferences(DataStorage.PREFS_MAINTRAFFICLOG_NAME, 0)
83 | );
84 |
85 |
86 | final Packet[] packetArray = dataStore.fetchAllSavedPackets();
87 | PacketAdapter packetAdapter = new PacketAdapter(this,packetArray);
88 |
89 |
90 |
91 | if(packetListView != null) {
92 |
93 | packetListView.setAdapter(packetAdapter);
94 | packetAdapter.notifyDataSetChanged();
95 |
96 | TextView noSavedPacketsText =
97 | (TextView) rootView.findViewById(R.id.noSavedPacketsText);
98 |
99 | if(packetAdapter.isEmpty()) {
100 | noSavedPacketsText.setVisibility(View.VISIBLE);
101 | } else {
102 | noSavedPacketsText.setVisibility(View.GONE);
103 | }
104 |
105 |
106 | packetListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
107 |
108 | @Override
109 | public void onItemClick(AdapterView> parent, final View view,
110 | int position, long id) {
111 |
112 | Log.d("psoncreate", DataStorage.FILE_LINE("Clicked " + position));
113 | Packet sendPacket = packetArray[position].duplicate();
114 | Log.d("psoncreate", DataStorage.FILE_LINE("Need to set widget to " + sendPacket.name));
115 | dataStore.setWidgetPacket(mAppWidgetId, sendPacket.name);
116 |
117 | Intent resultValue = new Intent();
118 | resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, mAppWidgetId);
119 | resultValue.setAction(PacketSenderWidget.WIDGET_CLICKED);
120 | setResult(RESULT_OK, resultValue);
121 |
122 | PacketSenderWidget.updateWidgets(getApplicationContext());
123 | /*
124 | AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(getApplicationContext());
125 |
126 | Intent intent = new Intent(getApplicationContext(), PacketSenderWidget.class);
127 | intent.setAction(PacketSenderWidget.WIDGET_CLICKED);
128 | intent.putExtra(PacketSenderWidget.WIDGET_ID, mAppWidgetId);
129 | PendingIntent selfIntent =
130 | PendingIntent.getBroadcast(getApplicationContext(), mAppWidgetId, intent, PendingIntent.FLAG_ONE_SHOT);
131 |
132 | RemoteViews remoteViews;
133 | remoteViews = new RemoteViews(getPackageName(), R.layout.widget_layout);
134 | remoteViews.setTextViewText(R.id.widget_textview, sendPacket.name);
135 | remoteViews.setOnClickPendingIntent(R.id.widget_imagebutton,selfIntent );
136 |
137 |
138 | if(sendPacket.tcpOrUdp.equalsIgnoreCase("tcp")) {
139 | remoteViews.setImageViewResource(R.id.widget_imagebutton, R.drawable.tx_tcp);
140 |
141 | } else {
142 | remoteViews.setImageViewResource(R.id.widget_imagebutton, R.drawable.tx_udp);
143 |
144 | }
145 |
146 | appWidgetManager.updateAppWidget(mAppWidgetId, remoteViews);
147 |
148 | */
149 |
150 | finish();
151 |
152 | }
153 |
154 | });
155 |
156 |
157 |
158 |
159 | }
160 |
161 |
162 |
163 |
164 | }
165 |
166 |
167 |
168 | private Button.OnClickListener configOkButtonOnClickListener
169 | = new Button.OnClickListener(){
170 |
171 | @Override
172 | public void onClick(View arg0) {
173 | // TODO Auto-generated method stub
174 |
175 | final Context context = PSWidgetOnCreate.this;
176 |
177 | AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
178 |
179 | //RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.hellowidget_layout);
180 | //appWidgetManager.updateAppWidget(mAppWidgetId, views);
181 | //PacketSenderWidget.updateAppWidget(context, appWidgetManager, mAppWidgetId);
182 |
183 | Toast.makeText(context, "HelloWidgetConfig.onClick(): " + String.valueOf(mAppWidgetId) , Toast.LENGTH_LONG).show();
184 |
185 | Intent resultValue = new Intent();
186 | resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, mAppWidgetId);
187 | resultValue.setAction(PacketSenderWidget.WIDGET_CLICKED);
188 |
189 | setResult(RESULT_OK, resultValue);
190 | finish();
191 | }
192 | };
193 |
194 |
195 | /*
196 |
197 | @Override
198 | public boolean onCreateOptionsMenu(Menu menu) {
199 |
200 | // Inflate the menu; this adds items to the action bar if it is present.
201 | getMenuInflater().inflate(R.menu.pswidget_on_create, menu);
202 | return true;
203 | }
204 |
205 | @Override
206 | public boolean onOptionsItemSelected(MenuItem item) {
207 | // Handle action bar item clicks here. The action bar will
208 | // automatically handle clicks on the Home/Up button, so long
209 | // as you specify a parent activity in AndroidManifest.xml.
210 | int id = item.getItemId();
211 | if (id == R.id.action_settings) {
212 | return true;
213 | }
214 | return super.onOptionsItemSelected(item);
215 | }
216 | */
217 |
218 | /**
219 | * A placeholder fragment containing a simple view.
220 | */
221 | public static class PlaceholderFragment extends Fragment {
222 |
223 | public PlaceholderFragment() {
224 | }
225 |
226 | @Override
227 | public View onCreateView(LayoutInflater inflater, ViewGroup container,
228 | Bundle savedInstanceState) {
229 | View rootView = inflater.inflate(R.layout.fragment_pswidget_on_create, container, false);
230 |
231 | PSWidgetOnCreate PSOC = (PSWidgetOnCreate) getActivity();
232 | PSOC.configOkButton = (Button)rootView.findViewById(R.id.okconfig);
233 | PSOC.configOkButton.setOnClickListener(PSOC.configOkButtonOnClickListener);
234 | PSOC.configOkButton.setVisibility(View.GONE);
235 | PSOC.onCreatePacketsList(rootView);
236 |
237 |
238 |
239 | return rootView;
240 | }
241 | }
242 |
243 | }
244 |
--------------------------------------------------------------------------------
/Packet Sender/src/main/java/com/packetsender/android/Packet.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2014 Dan Nagle. All rights reserved.
2 | //
3 | // Licensed MIT: https://github.com/dannagle/PacketSender-Android
4 | package com.packetsender.android;
5 |
6 | import android.util.Log;
7 |
8 | import java.text.SimpleDateFormat;
9 | import java.util.ArrayList;
10 | import java.util.Calendar;
11 | import java.util.Date;
12 | import java.util.List;
13 | import java.util.Locale;
14 |
15 |
16 | public class Packet implements Comparable {
17 |
18 |
19 | /*
20 |
21 | QString name;
22 | QString hexString;
23 | QString fromIP;
24 | QString toIP;
25 | QString errorString;
26 | QByteArray response;
27 | unsigned int repeat;
28 | unsigned int port;
29 | unsigned int fromPort;
30 | QString tcpOrUdp;
31 | unsigned int sendResponse;
32 | void init();
33 | void clear();
34 | QDateTime timestamp;
35 | */
36 |
37 | public String name;
38 | public String fromIP;
39 | public String toIP;
40 | public String errorString;
41 | public byte[] response;
42 | public int repeat;
43 | public int port;
44 | public int fromPort;
45 | public String tcpOrUdp;
46 | public byte[] data;
47 | public long timestamp;
48 |
49 |
50 | public Packet(String name) {
51 | this.name = name;
52 | }
53 |
54 | public static long now()
55 | {
56 | return new Date().getTime();
57 |
58 | }
59 |
60 | public void nowMe() {
61 | this.timestamp = now();
62 | this.name = Long.toString(this.timestamp);
63 | }
64 |
65 | public String timestampString() {
66 | Calendar cal = Calendar.getInstance();
67 | cal.setTimeInMillis(timestamp);
68 | SimpleDateFormat sdf = new SimpleDateFormat(DataStorage.DATE_FORMAT, Locale.US);
69 | return sdf.format(cal.getTime()).toLowerCase(Locale.US);
70 | }
71 |
72 |
73 | public Packet() {
74 | this.name = "";
75 | this.tcpOrUdp = "TCP";
76 | this.timestamp = now();
77 | this.fromIP = "192.168.1.23";
78 | this.toIP = "192.168.1.23";
79 | this.fromPort = 50055;
80 | this.port = 50055;
81 | this.data = new byte[10];
82 | this.errorString = "";
83 | }
84 |
85 | public Packet duplicate() {
86 |
87 | Packet newPacket = new Packet();
88 |
89 | newPacket.name = name;
90 | newPacket.fromIP = fromIP;
91 | newPacket.toIP = toIP;
92 | newPacket.errorString = errorString;
93 | newPacket.response = response;
94 | newPacket.repeat = repeat;
95 | newPacket.port = port;
96 | newPacket.fromPort = fromPort;
97 | newPacket.tcpOrUdp = tcpOrUdp;
98 | newPacket.data = new byte[data.length];
99 | System.arraycopy( data, 0, newPacket.data, 0, data.length );
100 | newPacket.timestamp = timestamp;
101 |
102 | return newPacket;
103 |
104 | }
105 |
106 | public String toString()
107 | {
108 | return "name:" + this.name +"\n" +
109 | "tcpudp:" + this.tcpOrUdp + "\n" +
110 | "timestamp:" + this.timestamp+ "\n" +
111 | "fromip:" + this.fromIP + "\n" +
112 | "toip:" + this.toIP + "\n" +
113 | "fromport:" + this.fromPort + "\n" +
114 | "port:" + this.port + "\n" +
115 | "errorString:" + this.errorString + "\n" +
116 | "ascii:" + toAscii() + "\n" +
117 | "hex:" + toHex();
118 |
119 | }
120 |
121 | public static String toAscii(byte[] data)
122 | {
123 | Packet pkt = new Packet();
124 | pkt.data = data;
125 |
126 | return pkt.toAscii();
127 |
128 | }
129 |
130 | public String toAscii()
131 | {
132 | String returnString = "";
133 | for (int item : this.data)
134 | {
135 | if(item == 0x0A)
136 | {
137 | returnString = returnString + "\\n";
138 |
139 | } else if (item == 0x0D) {
140 | returnString = returnString + "\\r";
141 |
142 | } else if (item >= 0x20 && item <= 0x7E) {
143 | returnString = returnString + (char) item;
144 | } else {
145 | String hex = Integer.toHexString(item & 0xff);
146 | if(hex.length() == 1) {
147 | hex = "0" + hex;
148 | }
149 | returnString = returnString + "\\" + hex;
150 | }
151 | }
152 |
153 | return returnString;
154 | }
155 |
156 | private static int iAt(String s, int index) {
157 | if(index < s.length()) {
158 | return (((int) s.charAt(index)) & 0xff);
159 | } else {
160 | return -1;
161 | }
162 |
163 | }
164 |
165 | private static byte[] toByteArray(List list){
166 | byte[] ret = new byte[list.size()];
167 | for(int i = 0;i < ret.length;i++)
168 | ret[i] = list.get(i);
169 | return ret;
170 | }
171 |
172 | public static byte[] asciiToBytes(String ascii) {
173 |
174 | int val1, val2, val3;
175 | char c1, c2;
176 |
177 | List bytes = new ArrayList();
178 |
179 | ascii = ascii.replace("\\r", "\\0d");
180 | ascii = ascii.replace("\\n", "\\0a");
181 |
182 | for(int i=0; i < ascii.length(); i++) {
183 | val1 = iAt(ascii, i);
184 | if (val1 >= 0x20 && val1 <= 0x7E) {
185 |
186 | if(val1 == (((int) '\\') & 0xff)) {
187 | val2 = iAt(ascii, i+1);
188 | val3 = iAt(ascii, i+2);
189 | if(val2 > -1 && val3 > -1) {
190 | c1 = ascii.charAt(i+1);
191 | c2 = ascii.charAt(i+2);
192 |
193 |
194 | try {
195 | Log.d("packet", DataStorage.FILE_LINE("c1,c2 " + c1 + "," + c2));
196 | Log.d("packet", DataStorage.FILE_LINE("val2,val3 " + val2 + "," + val3));
197 | val2 = Integer.parseInt((c1 + "") + (c2 + ""), 16) & 0xff;
198 | val3 = 0;
199 | Log.d("packet", DataStorage.FILE_LINE("val2,val3 " + val2 + "," + val3));
200 |
201 | bytes.add((byte)(val2 + val3));
202 |
203 | } catch (NumberFormatException e) {
204 | Log.d("packet", DataStorage.FILE_LINE("bad conversion"));
205 |
206 | }
207 |
208 | i += 2;
209 | continue;
210 | }
211 |
212 | } else {
213 | val1 = iAt(ascii, i);
214 | bytes.add((byte)(val1));
215 |
216 | }
217 |
218 |
219 |
220 | }
221 |
222 | }
223 |
224 | return toByteArray(bytes);
225 | }
226 |
227 | public static void UnitTest_conversions() {
228 |
229 | String testS[] = new String[2];
230 | String resultS[] = new String[testS.length];
231 | boolean tohex[] = new boolean[testS.length];
232 |
233 | testS[0] = "help\\25";
234 | resultS[0] = "68 65 6c 70 25".toUpperCase(Locale.US);
235 | tohex[0] = true;
236 |
237 | testS[1] = "68 65 6c 70 25";
238 | resultS[1] = "help%";
239 | tohex[1] = false;
240 |
241 |
242 | String test;
243 | for(int i=0; i < testS.length; i++) {
244 | if(tohex[i]) {
245 | test = toHex(asciiToBytes(testS[i]));
246 | } else {
247 | test = toAscii(toBytes(testS[i]));
248 | }
249 |
250 | Log.d("packet", DataStorage.FILE_LINE(test + " == " + resultS[i] + " ?"));
251 |
252 | if(test.equalsIgnoreCase(resultS[i])) {
253 | //passed
254 | Log.d("packet", DataStorage.FILE_LINE("pass, test " + i));
255 |
256 | } else {
257 | Log.d("packet", DataStorage.FILE_LINE("error, " + test.length() + "/" + resultS[i].length()
258 | + " test " + i + ", got\n"
259 | + test + "\nexpected:\n" + resultS[i] + "\n"));
260 |
261 | }
262 | }
263 |
264 |
265 | }
266 |
267 |
268 |
269 | public String toHex()
270 | {
271 | return Packet.toHex(this.data);
272 | }
273 |
274 | public static String toHex(byte[] bytes) {
275 | StringBuffer hexString = new StringBuffer();
276 | for (int i=0;i {
206 | // Do the long-running work in here
207 | protected Void doInBackground(Packet... params) {
208 |
209 | Log.d("SendPacketsTask", DataStorage.FILE_LINE("length" + params.length));
210 |
211 | Packet fetchedPacket = params[0];
212 | Log.d("SendPacketsTask", DataStorage.FILE_LINE("send packet " + fetchedPacket.toString()));
213 |
214 | //if(1+1 == 2) return null;
215 | if(fetchedPacket.tcpOrUdp.equalsIgnoreCase("tcp")) {
216 |
217 |
218 | } else {
219 |
220 |
221 | //dataStore.SavePacket(storepacket);
222 | try {
223 |
224 | ByteBuffer buf = ByteBuffer.allocate(fetchedPacket.data.length);
225 | buf.clear();
226 | buf.put(fetchedPacket.data);
227 | buf.flip();
228 |
229 |
230 | DatagramSocket udpSocket;
231 | DatagramPacket udpPacket;
232 |
233 | byte[] buffer = new byte[2048];
234 | // Create a packet to receive data into the buffer
235 | udpPacket = new DatagramPacket(buf.array(), buf.array().length);
236 | udpSocket = new DatagramSocket(null);
237 | udpSocket.setReuseAddress(true);
238 |
239 | InetSocketAddress clientAddress = new InetSocketAddress(fetchedPacket.toIP, fetchedPacket.port);
240 | udpSocket.connect(clientAddress);
241 | udpSocket.send(udpPacket);
242 | udpSocket.close();
243 |
244 | fetchedPacket.fromIP = "You";
245 | fetchedPacket.nowMe();
246 | dataStore.saveTrafficPacket(fetchedPacket);
247 | Log.d("service", DataStorage.FILE_LINE("sendBroadcast"));
248 |
249 |
250 | } catch (UnknownHostException e) {
251 | e.printStackTrace();
252 | } catch (IOException e) {
253 | e.printStackTrace();
254 | }
255 |
256 | return null;
257 |
258 |
259 | }
260 |
261 |
262 |
263 | try {
264 | Socket clientSocket;
265 | InetSocketAddress translateSocket = new InetSocketAddress(fetchedPacket.toIP, fetchedPacket.port);
266 | clientSocket = new Socket(translateSocket.getHostName(), translateSocket.getPort());
267 | clientSocket.setReuseAddress(true);
268 | clientSocket.setSoTimeout(2000); // 2 second timeout
269 |
270 | DataOutputStream out = new DataOutputStream(
271 | clientSocket.getOutputStream());
272 |
273 | DataInputStream in = new DataInputStream(
274 | clientSocket.getInputStream());
275 |
276 | out.write(fetchedPacket.data);
277 |
278 |
279 | Packet savePacket = fetchedPacket.duplicate();
280 | savePacket.fromIP = "You";
281 | savePacket.nowMe();
282 | dataStore.saveTrafficPacket(savePacket);
283 | Log.d("widget", DataStorage.FILE_LINE("sendBroadcast"));
284 |
285 |
286 | byte[] buffer = new byte[1024];
287 | int received = in.read(buffer);
288 | if(received > 0) {
289 | byte[] bufferConvert = new byte[received];
290 | System.arraycopy(buffer, 0, bufferConvert, 0, received);
291 | Log.i("widget",DataStorage.FILE_LINE("FROM SERVER: " + Packet.toHex(bufferConvert)));
292 |
293 | savePacket = fetchedPacket.duplicate();
294 | savePacket.nowMe();
295 | savePacket.data = bufferConvert;
296 | savePacket.fromIP = fetchedPacket.toIP;
297 | savePacket.fromPort = fetchedPacket.port;
298 | savePacket.toIP = "You";
299 | savePacket.port = fetchedPacket.fromPort;
300 |
301 | fetchedPacket.nowMe();
302 | dataStore.saveTrafficPacket(savePacket);
303 | Log.d("widget", DataStorage.FILE_LINE("sendBroadcast"));
304 |
305 |
306 | }
307 |
308 | out.close();
309 | in.close();
310 | clientSocket.close();
311 |
312 | } catch (SocketTimeoutException e) {
313 | StringWriter sw = new StringWriter();
314 | PrintWriter pw = new PrintWriter(sw);
315 | e.printStackTrace(pw);
316 | Log.w("service",DataStorage.FILE_LINE("SocketTimeoutException: " + sw.toString()));
317 |
318 | } catch (NetworkOnMainThreadException e) {
319 | StringWriter sw = new StringWriter();
320 | PrintWriter pw = new PrintWriter(sw);
321 | e.printStackTrace(pw);
322 | Log.w("service",DataStorage.FILE_LINE("NetworkOnMainThreadException: " + sw.toString()));
323 |
324 | } catch (UnknownHostException e) {
325 | StringWriter sw = new StringWriter();
326 | PrintWriter pw = new PrintWriter(sw);
327 | e.printStackTrace(pw);
328 | Log.w("service", DataStorage.FILE_LINE("UnknownHostException: " + sw.toString()));
329 | Log.d("service",DataStorage.FILE_LINE("Saving the error to packet."));
330 | fetchedPacket.errorString = "Unknown host";
331 | fetchedPacket.nowMe();
332 | dataStore.saveTrafficPacket(fetchedPacket);
333 | } catch (IOException e) {
334 | StringWriter sw = new StringWriter();
335 | PrintWriter pw = new PrintWriter(sw);
336 | e.printStackTrace(pw);
337 | Log.w("service", DataStorage.FILE_LINE("IOException: " + sw.toString())); //failed to connect error.
338 | Log.d("service", DataStorage.FILE_LINE("Saving the error to packet."));
339 | fetchedPacket.errorString = "Connection error";
340 | fetchedPacket.nowMe();
341 | dataStore.saveTrafficPacket(fetchedPacket);
342 |
343 | } catch (Exception e) {
344 | StringWriter sw = new StringWriter();
345 | PrintWriter pw = new PrintWriter(sw);
346 | e.printStackTrace(pw);
347 | Log.w("service",DataStorage.FILE_LINE("Exception: " + sw.toString()));
348 |
349 |
350 | }
351 |
352 |
353 | return null;
354 | }
355 |
356 |
357 | protected void onProgressUpdate()
358 | {
359 | //setProgressPercent(progress[0]);
360 | }
361 |
362 | protected void onPostExecute(boolean result)
363 | {
364 | //showDialog("Downloaded " + result + " bytes");
365 | }
366 | }
367 |
368 | }
369 |
--------------------------------------------------------------------------------
/Packet Sender/src/main/java/com/packetsender/android/DataStorage.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2014 Dan Nagle. All rights reserved.
2 | //
3 | // Licensed MIT: https://github.com/dannagle/PacketSender-Android
4 | package com.packetsender.android;
5 |
6 | import android.content.Context;
7 | import android.content.Intent;
8 | import android.content.SharedPreferences;
9 | import android.net.wifi.WifiInfo;
10 | import android.net.wifi.WifiManager;
11 | import android.util.Log;
12 | import android.view.View;
13 | import android.widget.CheckBox;
14 | import android.widget.EditText;
15 |
16 | import java.net.Inet4Address;
17 | import java.text.SimpleDateFormat;
18 | import java.util.ArrayList;
19 | import java.util.Arrays;
20 | import java.util.Calendar;
21 | import java.util.Collections;
22 | import java.util.List;
23 | import java.util.Locale;
24 |
25 |
26 | public class DataStorage {
27 |
28 | public SharedPreferences settings;
29 | public SharedPreferences servicelog;
30 | public SharedPreferences savedpackets;
31 | public SharedPreferences maintrafficlog;
32 |
33 | public static final String PREFS_SETTINGS_NAME = "PS_Settings";
34 | public static final String PREFS_SERVICELOG_NAME = "PS_Service";
35 | public static final String PREFS_MAINTRAFFICLOG_NAME = "PS_MainTraffic";
36 | public static final String PREFS_SAVEDPACKETS_NAME = "PS_Packets";
37 |
38 | public static final String INTENT_OUT = "packet_out";
39 |
40 | public static final String DATE_FORMAT = "hh:mm:ss.S a";
41 |
42 | DataStorage(SharedPreferences settings,
43 | SharedPreferences savedpackets,
44 | SharedPreferences servicelog,
45 | SharedPreferences maintrafficlog) {
46 |
47 | this.settings = settings;
48 | this.savedpackets = savedpackets;
49 | this.servicelog = servicelog;
50 | this.maintrafficlog = maintrafficlog;
51 |
52 | }
53 |
54 | public int getUDPPort() {
55 |
56 | int udp = settings.getInt("udpPort", 55057);
57 | return udp;
58 | }
59 |
60 | public int getTCPPort() {
61 | int tcp = settings.getInt("tcpPort", 55056);
62 | return tcp;
63 | }
64 |
65 | public boolean udpServerEnable() {
66 | return settings.getBoolean("enableUDPServer", true);
67 | }
68 |
69 | public boolean tcpServerEnable() {
70 | return settings.getBoolean("enableTCPServer", true);
71 | }
72 |
73 | public void putToast(String msg) {
74 | SharedPreferences.Editor editor = servicelog.edit();
75 | editor.putString("toToast", msg);
76 | editor.commit();
77 | }
78 |
79 | public String getToast() {
80 | String msg = servicelog.getString("toToast", "");
81 | putToast("");
82 | return msg;
83 | }
84 |
85 | public void sendPacketToService (Packet packet) {
86 | packet.timestamp = 0;
87 | packet.name = packet.now() + "";
88 | Log.d("store", "send packet " + packet.toString());
89 | depositPacket(packet, servicelog);
90 | }
91 |
92 |
93 | public void clearServicePackets() {
94 | SharedPreferences.Editor editor = servicelog.edit();
95 | editor.clear();
96 | editor.commit();
97 | }
98 |
99 | public void clearTrafficPackets() {
100 | SharedPreferences.Editor editor = maintrafficlog.edit();
101 | editor.clear();
102 | editor.commit();
103 | }
104 |
105 | public Packet getWidgetPacket(int ID) {
106 |
107 | String name = settings.getString("widget/ID/" + ID, "");
108 | if(name.isEmpty()) {
109 | return new Packet();
110 | }
111 |
112 | return fetchStoredPacketByName(name, savedpackets);
113 |
114 | }
115 |
116 | public void setWidgetPacket(int ID, String name) {
117 |
118 | SharedPreferences.Editor editor = settings.edit();
119 | editor.putString("widget/ID/" + ID, name);
120 | editor.commit();
121 |
122 | }
123 |
124 | public Packet[] fetchAllTrafficLogPackets() {
125 |
126 | List packetListL = new ArrayList();
127 | packetListL.addAll(Arrays.asList(fetchAllPackets(maintrafficlog)));
128 |
129 | Collections.sort(packetListL);
130 | Collections.reverse(packetListL);
131 | return packetListL.toArray(new Packet[packetListL.size()]);
132 |
133 | }
134 |
135 | public Packet[] fetchAllServicePackets() {
136 |
137 | List packetListL = new ArrayList();
138 | packetListL.addAll(Arrays.asList(fetchAllPackets(servicelog)));
139 |
140 | Collections.sort(packetListL);
141 |
142 | for (Packet p : packetListL) {
143 | // Log.d("store before", DataStorage.FILE_LINE( p.name));
144 | }
145 |
146 | Collections.reverse(packetListL);
147 |
148 | for (Packet p : packetListL) {
149 | // Log.d("store before", DataStorage.FILE_LINE( p.name));
150 | }
151 |
152 |
153 | return packetListL.toArray(new Packet[packetListL.size()]);
154 |
155 | //TODO sort by timestamp
156 | }
157 |
158 |
159 | public void invalidateLists() {
160 | SharedPreferences.Editor editor = settings.edit();
161 | editor.putBoolean("invalidateLists", true);
162 | editor.commit();
163 |
164 | Log.d("store", DataStorage.FILE_LINE("settings lists invalid"));
165 | }
166 | public boolean isInvalidateLists() {
167 | return settings.getBoolean("invalidateLists", false);
168 | }
169 | public void clearInvalidateLists() {
170 | SharedPreferences.Editor editor = settings.edit();
171 | editor.remove("invalidateLists");
172 | editor.commit();
173 | Log.d("store", DataStorage.FILE_LINE("clear invalid lists."));
174 | }
175 |
176 |
177 | public void prepSettings(View rootView) {
178 |
179 | EditText tcpServerEditText = (EditText) rootView.findViewById(R.id.tcpServerEditText);
180 | EditText udpServerEditText = (EditText) rootView.findViewById(R.id.udpServerEditText);
181 | CheckBox enableUDPServerCheck = (CheckBox) rootView.findViewById(R.id.enableUDPServerCheck);
182 | CheckBox enableTCPServerCheck = (CheckBox) rootView.findViewById(R.id.enableTCPServerCheck);
183 |
184 | tcpServerEditText.setText(getTCPPort() + "");
185 | udpServerEditText.setText(getUDPPort() + "");
186 | enableUDPServerCheck.setChecked(udpServerEnable());
187 | enableTCPServerCheck.setChecked(tcpServerEnable());
188 | }
189 |
190 | public static boolean isWifiActive(Context ctx)
191 | {
192 | WifiManager wifi = (WifiManager) ctx.getSystemService(ctx.WIFI_SERVICE);
193 |
194 | if(wifi.getWifiState() != WifiManager.WIFI_STATE_ENABLED )
195 | {
196 |
197 | return false;
198 | } else {
199 |
200 | if(getIP(ctx).equalsIgnoreCase("0.0.0.0"))
201 | {
202 | return false;
203 |
204 | } else {
205 | return true;
206 | }
207 |
208 |
209 | }
210 | }
211 |
212 |
213 | public static String getIP(Context ctx)
214 | {
215 |
216 | WifiManager wifi = (WifiManager) ctx.getSystemService(ctx.WIFI_SERVICE);
217 |
218 | if(wifi.getWifiState() != WifiManager.WIFI_STATE_ENABLED )
219 | {
220 | return "Wifi Disabled";
221 |
222 | } else {
223 |
224 | WifiInfo info = wifi.getConnectionInfo();
225 | int ipAddressInt = info.getIpAddress();
226 |
227 | //convert it to normal dot notation
228 | String ipBulder = ""+ (((ipAddressInt >>> 24) & 0xFF));
229 | ipBulder = (((ipAddressInt >>> 16) & 0xFF)) + "." + ipBulder;
230 | ipBulder = (((ipAddressInt >>> 8) & 0xFF)) + "." + ipBulder;
231 | ipBulder = ((ipAddressInt & 0xFF)) + "." + ipBulder;
232 |
233 | return ipBulder.trim();
234 |
235 |
236 | }
237 |
238 | }
239 |
240 | public void saveSettings(View rootView) {
241 |
242 | EditText tcpServerEditText = (EditText) rootView.findViewById(R.id.tcpServerEditText);
243 | EditText udpServerEditText = (EditText) rootView.findViewById(R.id.udpServerEditText);
244 | CheckBox enableUDPServerCheck = (CheckBox) rootView.findViewById(R.id.enableUDPServerCheck);
245 | CheckBox enableTCPServerCheck = (CheckBox) rootView.findViewById(R.id.enableTCPServerCheck);
246 |
247 |
248 | SharedPreferences.Editor editor = settings.edit();
249 | editor.putInt("tcpPort", Integer.parseInt(tcpServerEditText.getText().toString()));
250 | editor.putInt("udpPort", Integer.parseInt(udpServerEditText.getText().toString()));
251 | editor.putBoolean("enableUDPServer", enableUDPServerCheck.isChecked());
252 | editor.putBoolean("enableTCPServer", enableTCPServerCheck.isChecked());
253 | editor.commit();
254 | }
255 |
256 | public void DeleteSavedPacket(Packet packet) {
257 | DeletePacket(packet, savedpackets);
258 | }
259 |
260 | public void DeletePacket(Packet packet, SharedPreferences prefs) {
261 |
262 | //find packet first...
263 | Packet findPacket = fetchStoredPacketByName(packet.name, prefs);
264 | if(findPacket.name.isEmpty()) {
265 | return; // packet does not exit
266 | }
267 |
268 |
269 | Packet [] packetListMain = fetchAllPackets(prefs);
270 | List packetListNew = new ArrayList();
271 | for(int i = 0; i < packetListMain.length; i++) {
272 | findPacket = packetListMain[i];
273 | if(findPacket.name.equalsIgnoreCase(packet.name)) {
274 | continue;
275 | }
276 | packetListNew.add(findPacket);
277 | }
278 | SavePacketList(packetListNew.toArray(new Packet[packetListNew.size()]), prefs);
279 |
280 |
281 |
282 | }
283 |
284 | private void SavePacketList(Packet[] packetListNew, SharedPreferences prefs) {
285 |
286 | SharedPreferences.Editor editor = prefs.edit();
287 | editor.clear();
288 | editor.putInt("packetsSize", packetListNew.length);
289 | Log.d("store", "packetsSize is " + packetListNew.length);
290 |
291 | for(int i = 0; i < packetListNew.length; i++) {
292 | Packet packet = packetListNew[i];
293 | storePacket(packet,i, editor);
294 | }
295 | editor.commit();
296 |
297 |
298 |
299 | }
300 |
301 | private Packet fetchStoredPacketByName(String packetName, SharedPreferences prefs) {
302 |
303 | Packet returnPacket = new Packet();
304 |
305 | returnPacket.name = prefs.getString(packetName + "/name", "");;
306 | returnPacket.data = Packet.toBytes(prefs.getString(packetName + "/data", ""));
307 | returnPacket.fromIP = prefs.getString(packetName + "/fromIP", "");
308 | returnPacket.toIP = prefs.getString(packetName + "/toIP", "");
309 | returnPacket.repeat = prefs.getInt(packetName + "/repeat", 0);
310 | returnPacket.port = prefs.getInt(packetName + "/port", 0);
311 | returnPacket.fromPort = prefs.getInt(packetName + "/fromPort", 0);
312 | returnPacket.tcpOrUdp = prefs.getString(packetName + "/tcpOrUdp", "UDP");
313 | returnPacket.timestamp = prefs.getLong(packetName + "/timestamp", 0);
314 | returnPacket.errorString = prefs.getString(packetName + "/error", "");
315 |
316 | return returnPacket;
317 | }
318 |
319 | private void storePacket(Packet packet, int id, SharedPreferences.Editor editor) {
320 | String packetName = packet.name;
321 | Log.d("store", "saving packet " + packetName);
322 | if(id > -1) {
323 | editor.putString(id + "/packetid", packet.name);
324 | }
325 | editor.putString(packetName + "/name", packet.name);
326 | editor.putString(packetName + "/data", Packet.toHex(packet.data));
327 | editor.putString(packetName + "/fromIP", packet.fromIP);
328 | editor.putString(packetName + "/toIP", packet.toIP);
329 | editor.putInt(packetName + "/repeat", packet.repeat);
330 | editor.putInt(packetName + "/port", packet.port);
331 | editor.putInt(packetName + "/fromPort", packet.fromPort);
332 | editor.putString(packetName + "/tcpOrUdp", packet.tcpOrUdp);
333 | editor.putLong(packetName + "/timestamp", packet.timestamp);
334 | editor.putString(packetName + "/error", packet.errorString);
335 | }
336 |
337 |
338 | public static String currentTimeStamp() {
339 | Calendar cal = Calendar.getInstance();
340 | cal.getTime();
341 | SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT, Locale.US);
342 | return sdf.format(cal.getTime()).toLowerCase(Locale.US);
343 | }
344 |
345 | public void depositPacket(Packet packet, SharedPreferences prefs) {
346 |
347 | if(packet.name.isEmpty()) return;
348 |
349 | //find packet first...
350 | String packetName = prefs.getString(packet.name + "/name", "");
351 | if(packetName.isEmpty()) {
352 | //packet does not exit;
353 | Log.d("store", "Packet name " + packet.name + " does not exist");
354 | Packet [] packetListMain = fetchAllPackets(prefs);
355 | Packet [] packetListNew = new Packet[packetListMain.length + 1];
356 | for(int i = 0; i < packetListNew.length; i++) {
357 |
358 | if(i < packetListMain.length ) {
359 | packetListNew[i] = packetListMain[i];
360 | } else {
361 | packetListNew[i] = packet;
362 | }
363 | }
364 |
365 | Log.d("store", "Saving new packet list of size " + packetListNew.length);
366 | SavePacketList(packetListNew, prefs);
367 |
368 |
369 |
370 | } else {
371 | Log.d("store", "Packet name " + packet.name + " exist. Overwrite");
372 |
373 | SharedPreferences.Editor editor = prefs.edit();
374 | storePacket(packet,-1, editor);
375 | editor.commit();
376 | }
377 |
378 |
379 | }
380 |
381 | public static String FILE_LINE(String msg)
382 | {
383 | return new Throwable().getStackTrace()[1].getFileName() +
384 | // "/" + new Throwable().getStackTrace()[1].getClassName() +
385 | // "/" + new Throwable().getStackTrace()[1].getMethodName() +
386 | "(" + new Throwable().getStackTrace()[1].getLineNumber() + "):" + msg;
387 | }
388 |
389 | public void savePacket(Packet packet) {
390 |
391 | depositPacket(packet, savedpackets);
392 | }
393 | /*
394 |
395 | public String name;
396 | public String fromIP;
397 | public String toIP;
398 | public String errorString;
399 | public byte[] response;
400 | public int repeat;
401 | public int port;
402 | public int fromPort;
403 | public String tcpOrUdp;
404 | public byte[] data;
405 | public long timestamp;
406 |
407 |
408 | */
409 |
410 |
411 | public Packet[] fetchAllPackets(SharedPreferences prefs) {
412 |
413 | int packetsSize = prefs.getInt("packetsSize", 0);
414 | Packet[] packetList = new Packet[packetsSize];
415 |
416 |
417 | for(int i= 0; i < packetList.length; i++) {
418 |
419 | Packet returnPacket = new Packet();
420 | String packetName = prefs.getString(i + "/packetid", "");
421 | if(!packetName.isEmpty()) {
422 |
423 | returnPacket = fetchStoredPacketByName(packetName, prefs);
424 | }
425 | packetList[i] = returnPacket;
426 |
427 | }
428 |
429 |
430 | //TODO sort by name
431 |
432 |
433 |
434 |
435 | return packetList;
436 |
437 | }
438 |
439 | void saveTrafficPacket(Packet packet) {
440 | depositPacket(packet, maintrafficlog);
441 | }
442 |
443 | static public Packet getPacketFromIntent ( Intent intent) {
444 | Packet packet = new Packet();
445 |
446 | packet.name = intent.getStringExtra(INTENT_OUT + "/name");
447 | packet.toIP = intent.getStringExtra(INTENT_OUT + "/toIP");
448 | packet.fromIP = intent.getStringExtra(INTENT_OUT + "/fromIP");
449 | packet.port = intent.getIntExtra(INTENT_OUT + "/port", 0);
450 | packet.tcpOrUdp = intent.getStringExtra(INTENT_OUT + "/tcpOrUdp");
451 | packet.fromPort = intent.getIntExtra(INTENT_OUT + "/fromPort", 0);
452 | packet.data = Packet.toBytes(intent.getStringExtra(INTENT_OUT + "/data"));
453 |
454 |
455 | return packet;
456 | }
457 |
458 |
459 | static public Intent populateIntentFromPacket (Intent intent, Packet packet) {
460 |
461 | intent.putExtra(INTENT_OUT + "/name", packet.name);
462 | intent.putExtra(INTENT_OUT + "/toIP", packet.toIP);
463 | intent.putExtra(INTENT_OUT + "/fromIP", packet.fromIP);
464 | intent.putExtra(INTENT_OUT + "/port", packet.port);
465 | intent.putExtra(INTENT_OUT + "/tcpOrUdp", packet.tcpOrUdp);
466 | intent.putExtra(INTENT_OUT + "/fromPort", packet.fromPort);
467 | intent.putExtra(INTENT_OUT + "/data", Packet.toHex(packet.data));
468 |
469 | return intent;
470 | }
471 |
472 |
473 | static public Intent getIntentFromPacket (Packet packet) {
474 |
475 | Intent intent = new Intent();
476 | return populateIntentFromPacket (intent, packet);
477 | }
478 |
479 | public Packet[] fetchAllSavedPackets() {
480 | Packet[] packetList = fetchAllPackets(savedpackets);
481 |
482 |
483 | List packetListL = new ArrayList();
484 |
485 |
486 | for(int i= 0; i < packetList.length; i++) {
487 | packetList[i].fromIP = "You";
488 | packetListL.add(packetList[i]);
489 | }
490 |
491 |
492 | Collections.sort(packetListL);
493 |
494 | return packetListL.toArray(new Packet[packetListL.size()]);
495 | }
496 | }
497 |
--------------------------------------------------------------------------------
/Packet Sender/src/main/java/com/packetsender/android/PacketListenerService.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2014 Dan Nagle. All rights reserved.
2 | //
3 | // Licensed MIT: https://github.com/dannagle/PacketSender-Android
4 | package com.packetsender.android;
5 |
6 | import android.app.IntentService;
7 | import android.app.Notification;
8 | import android.app.NotificationManager;
9 | import android.app.PendingIntent;
10 | import android.app.Service;
11 | import android.content.Context;
12 | import android.content.Intent;
13 | import android.content.SharedPreferences;
14 | import android.graphics.Bitmap;
15 | import android.graphics.BitmapFactory;
16 | import android.os.AsyncTask;
17 | import android.os.Bundle;
18 | import android.os.Handler;
19 | import android.os.IBinder;
20 | import android.os.NetworkOnMainThreadException;
21 | import android.os.SystemClock;
22 | import android.support.v4.app.NotificationCompat;
23 | import android.text.format.DateFormat;
24 | import android.util.Log;
25 |
26 | import java.io.DataInputStream;
27 | import java.io.DataOutputStream;
28 | import java.io.IOException;
29 | import java.io.PrintWriter;
30 | import java.io.StringWriter;
31 | import java.net.BindException;
32 | import java.net.DatagramPacket;
33 | import java.net.DatagramSocket;
34 | import java.net.InetAddress;
35 | import java.net.InetSocketAddress;
36 | import java.net.Socket;
37 | import java.net.SocketAddress;
38 | import java.net.SocketTimeoutException;
39 | import java.net.UnknownHostException;
40 | import java.nio.ByteBuffer;
41 | import java.nio.CharBuffer;
42 | import java.nio.channels.Channel;
43 | import java.nio.channels.DatagramChannel;
44 | import java.nio.channels.SelectionKey;
45 | import java.nio.channels.Selector;
46 | import java.nio.channels.ServerSocketChannel;
47 | import java.nio.channels.SocketChannel;
48 | import java.nio.charset.CharacterCodingException;
49 | import java.nio.charset.Charset;
50 | import java.nio.charset.CharsetEncoder;
51 | import java.util.Iterator;
52 | import java.util.Set;
53 |
54 |
55 | public class PacketListenerService extends IntentService {
56 |
57 | private NotificationManager mNM;
58 | private final int NOTIFICATIONID = 100;
59 | private int listenportTCP = 5000;
60 | private int listenportUDP = 5000;
61 | private Notification updateComplete;
62 | private int packetCounter = 0;
63 | private PendingIntent contentIntent;
64 | private Runnable shutdownListener;
65 | private Runnable sendListener;
66 |
67 | private ServerSocketChannel tcpserver;
68 | private DatagramChannel udpserver;
69 | private final Handler mHandler = new Handler();
70 |
71 | private DataStorage dataStore;
72 |
73 | public static final String PARAM_IN_MSG = "imsg";
74 | public static final String PARAM_OUT_MSG = "omsg";
75 |
76 | public PacketListenerService() {
77 | super("PacketListenerService");
78 | }
79 |
80 | @Override
81 | protected void onHandleIntent(Intent intent) {
82 |
83 |
84 | dataStore = new DataStorage(
85 | getSharedPreferences(DataStorage.PREFS_SETTINGS_NAME, 0),
86 | getSharedPreferences(DataStorage.PREFS_SAVEDPACKETS_NAME, 0),
87 | getSharedPreferences(DataStorage.PREFS_SERVICELOG_NAME, 0),
88 | getSharedPreferences(DataStorage.PREFS_MAINTRAFFICLOG_NAME, 0)
89 | );
90 |
91 |
92 | listenportTCP = dataStore.getTCPPort();
93 | listenportUDP = dataStore.getUDPPort();
94 | Log.i("service", DataStorage.FILE_LINE("TCP: " + listenportTCP + " / UDP: " + listenportUDP));
95 |
96 |
97 | Intent notificationIntent = new Intent(getApplicationContext(), MainActivity.class);
98 |
99 | notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
100 | | Intent.FLAG_ACTIVITY_SINGLE_TOP);
101 |
102 | contentIntent = PendingIntent.getActivity(getApplicationContext(), 0,
103 | notificationIntent, 0);
104 |
105 |
106 | startNotification ();
107 |
108 | CharsetEncoder encoder = Charset.forName("US-ASCII").newEncoder();
109 | ByteBuffer response = null;
110 | try {
111 | response = encoder.encode(CharBuffer.wrap("response"));
112 | } catch (CharacterCodingException e1) {
113 | // TODO Auto-generated catch block
114 | e1.printStackTrace();
115 | }
116 |
117 | try {
118 |
119 | SocketAddress localportTCP = new InetSocketAddress(listenportTCP);
120 | SocketAddress localportUDP = new InetSocketAddress(listenportUDP);
121 |
122 | tcpserver = ServerSocketChannel.open();
123 | tcpserver.socket().bind(localportTCP);
124 |
125 | udpserver = DatagramChannel.open();
126 | udpserver.socket().bind(localportUDP);
127 |
128 | tcpserver.configureBlocking(false);
129 | udpserver.configureBlocking(false);
130 |
131 | Selector selector = Selector.open();
132 |
133 |
134 | tcpserver.register(selector, SelectionKey.OP_ACCEPT);
135 | udpserver.register(selector, SelectionKey.OP_READ);
136 |
137 |
138 | ByteBuffer receiveBuffer = ByteBuffer.allocate(1024);
139 | receiveBuffer.clear();
140 |
141 |
142 | shutdownListener = new Runnable() {
143 | public void run() {
144 |
145 | if(false)
146 | {
147 |
148 | try {
149 | tcpserver.close();
150 | } catch (IOException e) {
151 | }
152 | try {
153 | udpserver.close();
154 | } catch (IOException e) {
155 | }
156 | stopSelf();
157 | } else {
158 | mHandler.postDelayed(shutdownListener,2000);
159 |
160 | }
161 |
162 | }
163 | };
164 |
165 | sendListener = new Runnable() {
166 | public void run() {
167 |
168 | //Packet fetchedPacket = mDbHelper.needSendPacket();
169 | Packet [] fetchedPackets = dataStore.fetchAllServicePackets();
170 |
171 | if(fetchedPackets.length > 0) {
172 | dataStore.clearServicePackets();
173 | Log.d("service", DataStorage.FILE_LINE("sendListener found " + fetchedPackets.length + " packets"));
174 |
175 | for(int i = 0; i < fetchedPackets.length; i++)
176 | {
177 | Packet fetchedPacket = fetchedPackets[i];
178 | Log.d("service", DataStorage.FILE_LINE("send packet " + fetchedPacket.toString()));
179 |
180 | }
181 |
182 | new SendPacketsTask().execute(fetchedPackets);
183 | }
184 |
185 |
186 |
187 | mHandler.postDelayed(sendListener,2000);
188 |
189 | }
190 | };
191 |
192 |
193 | //start shutdown listener
194 | mHandler.postDelayed(shutdownListener,2000);
195 |
196 | //start send listener
197 | mHandler.postDelayed(sendListener,5000);
198 |
199 | while (true) {
200 | try { // Handle per-connection problems below
201 | // Wait for a client to connect
202 | Log.d("service", DataStorage.FILE_LINE("waiting for connection"));
203 | selector.select();
204 | Log.d("service", DataStorage.FILE_LINE("client connection"));
205 |
206 |
207 |
208 | Set keys = selector.selectedKeys();
209 |
210 |
211 | for (Iterator i = keys.iterator(); i.hasNext();) {
212 |
213 | SelectionKey key = (SelectionKey) i.next();
214 | i.remove();
215 |
216 |
217 | Channel c = (Channel) key.channel();
218 |
219 |
220 | if (key.isAcceptable() && c == tcpserver) {
221 |
222 | SocketChannel client = tcpserver.accept();
223 |
224 | if (client != null)
225 | {
226 |
227 | Socket tcpSocket = client.socket();
228 | packetCounter++;
229 |
230 |
231 | DataInputStream in = new DataInputStream (
232 | tcpSocket.getInputStream());
233 |
234 |
235 | byte[] buffer = new byte[1024];
236 | int received = in.read(buffer);
237 | byte[] bufferConvert = new byte[received];
238 | System.arraycopy(buffer, 0, bufferConvert, 0, bufferConvert.length);
239 |
240 |
241 | Packet storepacket = new Packet();
242 | storepacket.tcpOrUdp = "TCP";
243 | storepacket.fromIP = tcpSocket.getInetAddress().getHostAddress();
244 |
245 | storepacket.toIP = "You";
246 | storepacket.fromPort = tcpSocket.getPort();
247 | storepacket.port = tcpSocket.getLocalPort();
248 | storepacket.data = bufferConvert;
249 |
250 | UpdateNotification("TCP:" + storepacket.toAscii(), "From " + storepacket.fromIP);
251 |
252 | Log.i("service", DataStorage.FILE_LINE("Got TCP"));
253 | //dataStore.SavePacket(storepacket);
254 |
255 | /*
256 | Intent tcpIntent = new Intent();
257 | tcpIntent.setAction(ResponseReceiver.ACTION_RESP);
258 | tcpIntent.addCategory(Intent.CATEGORY_DEFAULT);
259 | tcpIntent.putExtra(PARAM_OUT_MSG, storepacket.name);
260 | sendBroadcast(tcpIntent);
261 | */
262 |
263 | storepacket.nowMe();
264 | dataStore.saveTrafficPacket(storepacket);
265 | Log.d("service", DataStorage.FILE_LINE("sendBroadcast"));
266 |
267 |
268 | if(false ) //mDbHelper.getSettings(PSDbAdapter.KEY_SETTINGS_SENDRESPONSE).equalsIgnoreCase("Yes"))
269 | {
270 | storepacket = new Packet();
271 | storepacket.name = dataStore.currentTimeStamp();;
272 | storepacket.tcpOrUdp = "TCP";
273 | storepacket.fromIP = "You";
274 | storepacket.toIP = tcpSocket.getInetAddress().getHostAddress();
275 | storepacket.fromPort = tcpSocket.getLocalPort();
276 | storepacket.port = tcpSocket.getPort();
277 | // storepacket.data = Packet.toBytes(mDbHelper.getSettings(PSDbAdapter.KEY_SETTINGS_SENDRESPONSETEXT));
278 |
279 |
280 | storepacket.nowMe();
281 | dataStore.saveTrafficPacket(storepacket);
282 | Log.d("service", DataStorage.FILE_LINE("sendBroadcast"));
283 |
284 | client.write(response); // send response
285 | }
286 |
287 |
288 | client.close(); // close connection
289 | }
290 | } else if (key.isReadable() && c == udpserver) {
291 |
292 | DatagramSocket udpSocket;
293 | DatagramPacket udpPacket;
294 |
295 | byte[] buffer = new byte[2048];
296 | // Create a packet to receive data into the buffer
297 | udpPacket = new DatagramPacket(buffer, buffer.length);
298 |
299 |
300 | udpSocket = udpserver.socket();
301 |
302 | receiveBuffer.clear();
303 |
304 | InetSocketAddress clientAddress = (InetSocketAddress) udpserver.receive(receiveBuffer);
305 |
306 | if (clientAddress != null)
307 | {
308 |
309 | String fromAddress = clientAddress.getAddress().getHostAddress();
310 |
311 | packetCounter++;
312 |
313 |
314 | int received = receiveBuffer.position();
315 | byte[] bufferConvert = new byte[received];
316 |
317 | System.arraycopy(receiveBuffer.array(), 0, bufferConvert, 0, bufferConvert.length);
318 |
319 | Packet storepacket = new Packet();
320 | storepacket.tcpOrUdp = "UDP";
321 | storepacket.fromIP = clientAddress.getAddress().getHostAddress();
322 |
323 | storepacket.toIP = "You";
324 | storepacket.fromPort = clientAddress.getPort();
325 | storepacket.port = udpSocket.getLocalPort();
326 | storepacket.data = bufferConvert;
327 |
328 | UpdateNotification("UDP:" + storepacket.toAscii(), "From " + storepacket.fromIP);
329 |
330 | //dataStore.SavePacket(storepacket);
331 | storepacket.nowMe();
332 | dataStore.saveTrafficPacket(storepacket);
333 | Log.d("service", DataStorage.FILE_LINE("sendBroadcast"));
334 |
335 |
336 | if(false)//mDbHelper.getSettings(PSDbAdapter.KEY_SETTINGS_SENDRESPONSE).trim().equalsIgnoreCase("Yes"))
337 | {
338 | storepacket = new Packet();
339 | storepacket.name = dataStore.currentTimeStamp();;
340 | storepacket.tcpOrUdp = "UDP";
341 | storepacket.fromIP = "You";
342 | storepacket.toIP = clientAddress.getAddress().getHostAddress();
343 | storepacket.fromPort = udpSocket.getLocalPort();
344 | storepacket.port = clientAddress.getPort();
345 | // storepacket.data = Packet.toBytes(mDbHelper.getSettings(PSDbAdapter.KEY_SETTINGS_SENDRESPONSETEXT));
346 |
347 |
348 | //dataStore.SavePacket(storepacket);
349 | udpserver.send(response, clientAddress);
350 | storepacket.nowMe();
351 | dataStore.saveTrafficPacket(storepacket);
352 | Log.d("service", DataStorage.FILE_LINE("sendBroadcast"));
353 |
354 |
355 | }
356 | }
357 | }
358 | }
359 | } catch (java.io.IOException e) {
360 | Log.i("service",DataStorage.FILE_LINE("IOException "));
361 | } catch (Exception e) {
362 | Log.w("service",DataStorage.FILE_LINE("Fatal Error: " + Log.getStackTraceString(e)));
363 | }
364 | }
365 | } catch (BindException e) {
366 |
367 | //mDbHelper.putServiceError("Error binding to port");
368 | dataStore.putToast("Port already in use.");
369 | Log.w("service",DataStorage.FILE_LINE("Bind Exception: " + Log.getStackTraceString(e)));
370 |
371 |
372 | } catch (Exception e) {
373 | //mDbHelper.putServiceError("Fatal Error starting service");
374 | Log.w("service",DataStorage.FILE_LINE("Startup error: " + Log.getStackTraceString(e)));
375 | }
376 |
377 |
378 | stopNotification();
379 |
380 |
381 |
382 |
383 |
384 |
385 |
386 |
387 |
388 |
389 |
390 | }
391 |
392 |
393 |
394 | public void onDestroy ()
395 | {
396 |
397 | try {
398 | Log.w("service",DataStorage.FILE_LINE("Closing connections"));
399 | tcpserver.close();
400 | udpserver.close();
401 | } catch (IOException e) {
402 | Log.w("service",DataStorage.FILE_LINE("IOException error: " + Log.getStackTraceString(e)));
403 | } catch (NullPointerException e){
404 | Log.w("service",DataStorage.FILE_LINE("NullPointerException error: " + Log.getStackTraceString(e)));
405 | }
406 |
407 | stopNotification();
408 |
409 | }
410 | public void startNotification () {
411 |
412 | UpdateNotification("TCP: " + listenportTCP + " / UDP: " + listenportUDP, "Packet Sender Active");
413 |
414 | }
415 |
416 |
417 | public void stopNotification () {
418 |
419 | mNM.cancelAll();
420 |
421 | }
422 | public void UpdateNotification(String title, String subject) {
423 |
424 | Bitmap bm = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
425 |
426 | NotificationCompat.Builder builder =
427 | new NotificationCompat.Builder(this)
428 | .setSmallIcon(R.drawable.ic_launcher_status24)
429 | .setLargeIcon(bm)
430 | .setContentTitle(title)
431 | .setTicker(title)
432 | .setContentText(subject);
433 |
434 | Intent notificationIntent = new Intent(this, MainActivity.class);
435 | PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent,
436 | PendingIntent.FLAG_UPDATE_CURRENT);
437 | builder.setContentIntent(contentIntent);
438 |
439 | // Add as notification
440 | mNM = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
441 | mNM.notify(NOTIFICATIONID, builder.build());
442 |
443 |
444 | }
445 |
446 |
447 | private class SendPacketsTask extends AsyncTask {
448 | // Do the long-running work in here
449 | protected Void doInBackground(Packet... params) {
450 |
451 | Log.d("SendPacketsTask", DataStorage.FILE_LINE("length" + params.length));
452 |
453 | Packet fetchedPacket = params[0];
454 | Log.d("SendPacketsTask", DataStorage.FILE_LINE("send packet " + fetchedPacket.toString()));
455 |
456 | //if(1+1 == 2) return null;
457 | if(fetchedPacket.tcpOrUdp.equalsIgnoreCase("tcp")) {
458 | UpdateNotification("Send TCP: " + fetchedPacket.toIP, ":" + fetchedPacket.port);
459 |
460 | } else {
461 | UpdateNotification("Send UDP: " + fetchedPacket.toIP, ":" + fetchedPacket.port);
462 |
463 |
464 | //dataStore.SavePacket(storepacket);
465 | try {
466 |
467 | ByteBuffer buf = ByteBuffer.allocate(fetchedPacket.data.length);
468 | buf.clear();
469 | buf.put(fetchedPacket.data);
470 | buf.flip();
471 |
472 | udpserver.send(buf, new InetSocketAddress(fetchedPacket.toIP, fetchedPacket.port));
473 |
474 |
475 | fetchedPacket.fromIP = "You";
476 | fetchedPacket.nowMe();
477 | dataStore.saveTrafficPacket(fetchedPacket);
478 | Log.d("service", DataStorage.FILE_LINE("sendBroadcast"));
479 |
480 |
481 |
482 | } catch (UnknownHostException e) {
483 | e.printStackTrace();
484 | } catch (IOException e) {
485 | e.printStackTrace();
486 | }
487 |
488 | return null;
489 |
490 |
491 | }
492 |
493 |
494 |
495 | try {
496 | Socket clientSocket;
497 | InetSocketAddress translateSocket = new InetSocketAddress(fetchedPacket.toIP, fetchedPacket.port);
498 | clientSocket = new Socket(translateSocket.getHostName(), translateSocket.getPort());
499 | clientSocket.setSoTimeout(2000); // 2 second timeout
500 |
501 | DataOutputStream out = new DataOutputStream(
502 | clientSocket.getOutputStream());
503 |
504 | DataInputStream in = new DataInputStream(
505 | clientSocket.getInputStream());
506 |
507 | out.write(fetchedPacket.data);
508 |
509 |
510 | Packet savePacket = fetchedPacket.duplicate();
511 | savePacket.nowMe();
512 | savePacket.fromIP = "You";
513 | fetchedPacket.nowMe();
514 | dataStore.saveTrafficPacket(savePacket);
515 | Log.d("service", DataStorage.FILE_LINE("sendBroadcast"));
516 |
517 |
518 | byte[] buffer = new byte[1024];
519 | int received = in.read(buffer);
520 | if(received > 0) {
521 | byte[] bufferConvert = new byte[received];
522 | System.arraycopy(buffer, 0, bufferConvert, 0, received);
523 | Log.i("service",DataStorage.FILE_LINE("FROM SERVER: " + Packet.toHex(bufferConvert)));
524 |
525 | savePacket = fetchedPacket.duplicate();
526 | savePacket.nowMe();
527 | savePacket.data = bufferConvert;
528 | savePacket.fromIP = fetchedPacket.toIP;
529 | savePacket.fromPort = fetchedPacket.port;
530 | savePacket.toIP = "You";
531 | savePacket.port = fetchedPacket.fromPort;
532 |
533 | fetchedPacket.nowMe();
534 | dataStore.saveTrafficPacket(savePacket);
535 | Log.d("service", DataStorage.FILE_LINE("sendBroadcast"));
536 |
537 |
538 | }
539 |
540 | out.close();
541 | in.close();
542 | clientSocket.close();
543 |
544 | } catch (SocketTimeoutException e) {
545 | StringWriter sw = new StringWriter();
546 | PrintWriter pw = new PrintWriter(sw);
547 | e.printStackTrace(pw);
548 | Log.i("service", DataStorage.FILE_LINE("SocketTimeoutException: " + sw.toString()));
549 |
550 | } catch (NetworkOnMainThreadException e) {
551 | StringWriter sw = new StringWriter();
552 | PrintWriter pw = new PrintWriter(sw);
553 | e.printStackTrace(pw);
554 | Log.w("service",DataStorage.FILE_LINE("NetworkOnMainThreadException: " + sw.toString()));
555 |
556 | } catch (UnknownHostException e) {
557 | StringWriter sw = new StringWriter();
558 | PrintWriter pw = new PrintWriter(sw);
559 | e.printStackTrace(pw);
560 | Log.i("service", DataStorage.FILE_LINE("UnknownHostException: " + sw.toString()));
561 | Log.i("service", DataStorage.FILE_LINE("Saving the error to packet."));
562 | fetchedPacket.errorString = "Unknown host";
563 | fetchedPacket.nowMe();
564 | dataStore.saveTrafficPacket(fetchedPacket);
565 | } catch (IOException e) {
566 | StringWriter sw = new StringWriter();
567 | PrintWriter pw = new PrintWriter(sw);
568 | e.printStackTrace(pw);
569 | Log.w("service", DataStorage.FILE_LINE("IOException: " + sw.toString())); //failed to connect error.
570 | Log.i("service", DataStorage.FILE_LINE("Saving the error to packet."));
571 | fetchedPacket.errorString = "Connection error";
572 | fetchedPacket.nowMe();
573 | dataStore.saveTrafficPacket(fetchedPacket);
574 |
575 | } catch (Exception e) {
576 | StringWriter sw = new StringWriter();
577 | PrintWriter pw = new PrintWriter(sw);
578 | e.printStackTrace(pw);
579 | Log.w("service",DataStorage.FILE_LINE("Exception: " + sw.toString()));
580 |
581 |
582 | }
583 |
584 |
585 | return null;
586 | }
587 |
588 |
589 | protected void onProgressUpdate()
590 | {
591 | //setProgressPercent(progress[0]);
592 | }
593 |
594 | protected void onPostExecute(boolean result)
595 | {
596 | //showDialog("Downloaded " + result + " bytes");
597 | }
598 | }
599 |
600 |
601 | }
602 |
--------------------------------------------------------------------------------
/Packet Sender/src/main/java/com/packetsender/android/MainActivity.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2014 Dan Nagle. All rights reserved.
2 | //
3 | // Licensed MIT: https://github.com/dannagle/PacketSender-Android
4 | package com.packetsender.android;
5 |
6 | import java.util.ArrayList;
7 | import java.util.Arrays;
8 | import java.util.Collections;
9 | import java.util.List;
10 | import java.util.Locale;
11 |
12 | import android.app.Activity;
13 | import android.app.ActionBar;
14 | import android.app.Application;
15 | import android.app.Fragment;
16 | import android.app.FragmentManager;
17 | import android.app.FragmentTransaction;
18 | import android.app.SearchManager;
19 | import android.app.SearchableInfo;
20 | import android.content.BroadcastReceiver;
21 | import android.content.Context;
22 | import android.content.DialogInterface;
23 | import android.content.Intent;
24 | import android.content.IntentFilter;
25 | import android.os.Handler;
26 | import android.provider.Settings;
27 | import android.support.v13.app.FragmentPagerAdapter;
28 | import android.os.Bundle;
29 | import android.support.v4.view.ViewPager;
30 | import android.text.InputType;
31 | import android.util.Log;
32 | import android.view.Gravity;
33 | import android.view.LayoutInflater;
34 | import android.view.Menu;
35 | import android.view.MenuItem;
36 | import android.view.View;
37 | import android.view.ViewGroup;
38 | import android.widget.AdapterView;
39 | import android.widget.ArrayAdapter;
40 | import android.widget.Button;
41 | import android.widget.CheckBox;
42 | import android.widget.EditText;
43 | import android.widget.ListView;
44 | import android.widget.SearchView;
45 | import android.widget.TextView;
46 | import android.widget.Toast;
47 |
48 | import android.app.ActivityManager;
49 | import android.app.AlertDialog;
50 | import android.app.ActivityManager.RunningServiceInfo;
51 | public class MainActivity extends Activity
52 | implements ActionBar.TabListener, SearchView.OnQueryTextListener
53 | {
54 |
55 | /**
56 | * The {@link android.support.v4.view.PagerAdapter} that will provide
57 | * fragments for each of the sections. We use a
58 | * {@link FragmentPagerAdapter} derivative, which will keep every
59 | * loaded fragment in memory. If this becomes too memory intensive, it
60 | * may be best to switch to a
61 | * {@link android.support.v13.app.FragmentStatePagerAdapter}.
62 | */
63 | SectionsPagerAdapter mSectionsPagerAdapter;
64 |
65 | private static Intent serviceIntent;
66 | private Context mContext;
67 | private DataStorage dataStore;
68 |
69 | private int activeMenu = R.menu.packetlistmenu;
70 |
71 | private SearchView mSearchView;
72 |
73 |
74 | private List trafficLogPackets;
75 | public View trafficFragmentView;
76 | public View packetsFragmentView;
77 |
78 | //Runnable to self update the saved lists...
79 | private Runnable updateSavedLists;
80 |
81 |
82 | private String ipAddress;
83 | private boolean wifiActive;
84 | private Runnable updateWifi;
85 | private Runnable trafficLogPolling;
86 |
87 | private final Handler mHandler = new Handler();
88 |
89 | /**
90 | * The {@link ViewPager} that will host the section contents.
91 | */
92 | ViewPager mViewPager;
93 |
94 | @Override
95 | public void onResume() {
96 | super.onResume();
97 | if(packetsFragmentView != null) {
98 | packetsFragmentView.invalidate();
99 | }
100 | }
101 |
102 | @Override
103 | public void onPause() {
104 | super.onPause();
105 |
106 | }
107 |
108 | public void onDestroy() {
109 |
110 | stopListenerService();
111 | super.onDestroy();
112 | }
113 |
114 | @Override
115 | public boolean onQueryTextSubmit(String s) {
116 |
117 |
118 | Log.d("main", DataStorage.FILE_LINE(s));
119 |
120 | return false;
121 | }
122 |
123 | @Override
124 | public boolean onQueryTextChange(String s) {
125 |
126 | Log.d("main", DataStorage.FILE_LINE(s));
127 |
128 | return false;
129 | }
130 |
131 |
132 | @Override
133 | protected void onCreate(Bundle savedInstanceState) {
134 | super.onCreate(savedInstanceState);
135 | setContentView(R.layout.activity_main);
136 |
137 | mContext = getApplicationContext();
138 | serviceIntent = new Intent(mContext, PacketListenerService.class);
139 | activeMenu = R.menu.packetlistmenu;
140 |
141 |
142 | trafficLogPackets = new ArrayList();
143 |
144 | dataStore = new DataStorage(
145 | getSharedPreferences(DataStorage.PREFS_SETTINGS_NAME, 0),
146 | getSharedPreferences(DataStorage.PREFS_SAVEDPACKETS_NAME, 0),
147 | getSharedPreferences(DataStorage.PREFS_SERVICELOG_NAME, 0),
148 | getSharedPreferences(DataStorage.PREFS_MAINTRAFFICLOG_NAME, 0)
149 | );
150 |
151 | dataStore.clearServicePackets();
152 |
153 | // Set up the action bar.
154 | final ActionBar actionBar = getActionBar();
155 | actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
156 |
157 | // Create the adapter that will return a fragment for each of the three
158 | // primary sections of the activity.
159 | mSectionsPagerAdapter = new SectionsPagerAdapter(getFragmentManager());
160 |
161 | // Set up the ViewPager with the sections adapter.
162 | mViewPager = (ViewPager) findViewById(R.id.pager);
163 | mViewPager.setAdapter(mSectionsPagerAdapter);
164 |
165 | // When swiping between different sections, select the corresponding
166 | // tab. We can also use ActionBar.Tab#select() to do this if we have
167 | // a reference to the Tab.
168 | mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
169 | @Override
170 | public void onPageSelected(int position) {
171 | actionBar.setSelectedNavigationItem(position);
172 | }
173 | });
174 |
175 | // For each of the sections in the app, add a tab to the action bar.
176 | for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) {
177 | // Create a tab with text corresponding to the page title defined by
178 | // the adapter. Also specify this Activity object, which implements
179 | // the TabListener interface, as the callback (listener) for when
180 | // this tab is selected.
181 | actionBar.addTab(
182 | actionBar.newTab()
183 | .setText(mSectionsPagerAdapter.getPageTitle(i))
184 | .setTabListener(this));
185 | }
186 |
187 |
188 | startListenerService();
189 |
190 | wifiActive = DataStorage.isWifiActive(mContext);
191 | ipAddress = "";
192 |
193 | if(wifiActive) {
194 | ipAddress = DataStorage.getIP(mContext);
195 | Toast.makeText(mContext, "Your IP is " + ipAddress, Toast.LENGTH_LONG).show();
196 | } else {
197 | Toast.makeText(mContext, "Send only. Wifi is inactive.", Toast.LENGTH_LONG).show();
198 | }
199 |
200 | //periodically poll the traffic log
201 |
202 | trafficLogPolling = new Runnable() {
203 | public void run() {
204 |
205 | String msg = dataStore.getToast();
206 | if(!msg.isEmpty()) {
207 | Toast.makeText(mContext, msg, Toast.LENGTH_LONG).show();
208 | }
209 |
210 |
211 | Packet[] trafficPackets = dataStore.fetchAllTrafficLogPackets();
212 | if(trafficPackets.length != trafficLogPackets.size()) {
213 | trafficLogPackets.clear();
214 | trafficLogPackets.addAll(Arrays.asList(trafficPackets));
215 | updateTrafficPacketsList(trafficFragmentView);
216 | //trafficFragmentView
217 |
218 | }
219 |
220 | //Log.d("main", DataStorage.FILE_LINE( "trafficLogPolling."));
221 | mHandler.postDelayed(trafficLogPolling,1100);
222 | }
223 | };
224 |
225 |
226 | //periodically monitor Wi-Fi
227 | updateWifi = new Runnable() {
228 | public void run() {
229 |
230 | boolean checkWifi = DataStorage.isWifiActive(mContext);
231 | if(checkWifi != wifiActive) {
232 | if(checkWifi) {
233 | ipAddress = DataStorage.getIP(mContext);
234 | Toast.makeText(mContext, "Your IP is " + ipAddress, Toast.LENGTH_LONG).show();
235 | } else {
236 | Toast.makeText(mContext, "Wifi is not active", Toast.LENGTH_LONG).show();
237 | }
238 |
239 | wifiActive = checkWifi;
240 |
241 | }
242 | mHandler.postDelayed(updateWifi,5000);
243 | }
244 | };
245 |
246 | mHandler.postDelayed(updateWifi,5000);
247 | mHandler.postDelayed(trafficLogPolling, 700);
248 | //setup saved List periodic check
249 | updateSavedLists = new Runnable() {
250 | public void run() {
251 | if(dataStore.isInvalidateLists()) {
252 |
253 | Log.d("main", DataStorage.FILE_LINE( "Found invalid lists."));
254 | updateSavedPacketsList(packetsFragmentView);
255 | dataStore.clearInvalidateLists();
256 | }
257 |
258 | mHandler.postDelayed(updateSavedLists,2000);
259 | }
260 | };
261 |
262 | mHandler.postDelayed(updateSavedLists,7000);
263 |
264 |
265 |
266 |
267 |
268 |
269 |
270 | }
271 |
272 | public AdapterView.OnItemClickListener getTrafficOnClick() {
273 |
274 | final MainActivity Main = this;
275 |
276 | return new AdapterView.OnItemClickListener() {
277 |
278 | @Override
279 | public void onItemClick(AdapterView> parent, final View view,
280 | int position, long id) {
281 | final int finalPosition = position;
282 | Log.d("main", DataStorage.FILE_LINE("Clicked " + position));
283 | final Packet updatePacket = trafficLogPackets.get(position).duplicate();
284 |
285 | updatePacket.name = "save";
286 | AlertDialog.Builder alert = new AlertDialog.Builder(Main);
287 | alert.setTitle("Packet Name?");
288 |
289 |
290 | // Set an EditText view to get user input
291 | final EditText input = new EditText(Main);
292 |
293 | input.setInputType(InputType.TYPE_CLASS_TEXT); //);
294 | alert.setView(input);
295 |
296 | alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
297 | public void onClick(DialogInterface dialog, int whichButton) {
298 | String value = input.getText().toString();
299 | // Do something with value!
300 | updatePacket.name = value;
301 |
302 | Packet tempPacket = updatePacket;
303 | updatePacket.port = tempPacket.fromPort;
304 | updatePacket.toIP = tempPacket.fromIP;
305 |
306 | ////mDBHelper.updatePacket(packet);
307 | //mDBHelper.storemessage(packet);
308 | dataStore.savePacket(updatePacket);
309 | updateSavedPacketsList(packetsFragmentView);
310 |
311 | Toast.makeText(mContext, "Reversed addresses and saved.", Toast.LENGTH_SHORT).show();
312 | }
313 | });
314 |
315 | alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
316 | public void onClick(DialogInterface dialog, int whichButton) {
317 | // Canceled.
318 | }
319 | });
320 |
321 | alert.show();
322 | // see http://androidsnippets.com/prompt-user-input-with-an-alertdialog
323 |
324 |
325 |
326 | }
327 |
328 | };
329 |
330 | }
331 |
332 | public void updateTrafficPacketsList(View rootView) {
333 |
334 | ListView trafficListView = (ListView) rootView.findViewById(R.id.trafficList);
335 | List packetList = new ArrayList();
336 | packetList.addAll(Arrays.asList( trafficLogPackets.toArray(new Packet[trafficLogPackets.size()])));
337 | Collections.sort(packetList);
338 | Collections.reverse(packetList);
339 |
340 | PacketAdapter packetAdapter = new PacketAdapter(this, packetList.toArray(new Packet[packetList.size()]));
341 |
342 |
343 | if(trafficListView != null) {
344 |
345 | trafficListView.setAdapter(packetAdapter);
346 | packetAdapter.notifyDataSetChanged();
347 |
348 | trafficListView.setOnItemClickListener(getTrafficOnClick());
349 |
350 | TextView trafficLogEmptyText =
351 | (TextView) rootView.findViewById(R.id.trafficLogEmptyText);
352 |
353 | Button clearLogButton = (Button) rootView.findViewById(R.id.clearTrafficLogButton);
354 |
355 | if(packetAdapter.isEmpty()) {
356 | trafficLogEmptyText.setVisibility(View.VISIBLE);
357 | clearLogButton.setVisibility(View.GONE);
358 | } else {
359 | clearLogButton.setVisibility(View.VISIBLE);
360 | trafficLogEmptyText.setVisibility(View.GONE);
361 | }
362 |
363 |
364 | }
365 | }
366 |
367 |
368 | public void updateSavedPacketsList(View rootView) {
369 |
370 | ListView packetListView = (ListView) rootView.findViewById(R.id.packetList);
371 |
372 |
373 | final Packet[] packetArray = dataStore.fetchAllSavedPackets();
374 | PacketAdapter packetAdapter = new PacketAdapter(this,packetArray);
375 |
376 |
377 |
378 | if(packetListView != null) {
379 |
380 | packetListView.setAdapter(packetAdapter);
381 | packetAdapter.notifyDataSetChanged();
382 |
383 | TextView noSavedPacketsText =
384 | (TextView) rootView.findViewById(R.id.noSavedPacketsText);
385 |
386 | if(packetAdapter.isEmpty()) {
387 | noSavedPacketsText.setVisibility(View.VISIBLE);
388 | } else {
389 | noSavedPacketsText.setVisibility(View.GONE);
390 | }
391 |
392 |
393 | packetListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
394 |
395 | @Override
396 | public void onItemClick(AdapterView> parent, final View view,
397 | int position, long id) {
398 |
399 | Log.d("main", DataStorage.FILE_LINE("Clicked " + position));
400 |
401 |
402 |
403 | Packet sendPacket = packetArray[position].duplicate();
404 | if(activeMenu == R.menu.acceptchangemenu) {
405 | Log.d("main", DataStorage.FILE_LINE("Need to delete " + sendPacket.name ));
406 | dataStore.DeleteSavedPacket(sendPacket);
407 | updateSavedPacketsList(packetsFragmentView);
408 | } else {
409 | Log.d("main", DataStorage.FILE_LINE("Need to send " + sendPacket.name + " data " + sendPacket.toAscii()));
410 | dataStore.sendPacketToService(sendPacket);
411 |
412 | }
413 |
414 |
415 | }
416 |
417 | });
418 |
419 |
420 | packetListView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
421 | public boolean onItemLongClick(AdapterView> parent, View view, int position, long id) {
422 | Log.d("main", DataStorage.FILE_LINE("long click " + position));
423 |
424 |
425 |
426 | Packet editPacket = packetArray[position].duplicate();
427 | Intent newPacketActivity = DataStorage.getIntentFromPacket(editPacket);
428 | newPacketActivity.setClass(getApplicationContext(), NewPacketActivity.class);
429 | startActivity(newPacketActivity);
430 |
431 | return true;
432 | }
433 | });
434 |
435 |
436 | }
437 |
438 |
439 |
440 |
441 | }
442 |
443 |
444 | public static boolean isMyServiceRunning(Context ctx) {
445 | ActivityManager manager = (ActivityManager) ctx.getSystemService(Context.ACTIVITY_SERVICE);
446 | for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
447 | if ("com.packetsender.android.PacketListenerService".equals(service.service.getClassName())) {
448 | return true;
449 | }
450 | }
451 | return false;
452 | }
453 | public RunningServiceInfo getServiceIntent() {
454 | ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
455 | for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
456 | if ("com.packetsender.android.PacketListenerService".equals(service.service.getClassName())) {
457 | return service;
458 | }
459 | }
460 |
461 | return null;
462 | }
463 |
464 |
465 | public void stopListenerService() {
466 |
467 | if(isMyServiceRunning(mContext))
468 | {
469 | Log.i("main", DataStorage.FILE_LINE("Service is running. Stop it."));
470 | if(serviceIntent != null) {
471 | Log.d("debug", DataStorage.FILE_LINE("serviceIntent is not null."));
472 | }
473 |
474 | mContext.stopService(serviceIntent);
475 | }
476 |
477 | }
478 |
479 | public void startListenerService() {
480 |
481 | if(isMyServiceRunning(mContext))
482 | {
483 | stopListenerService();
484 | // do nothing
485 | } //this.needStop(); //clear out stop commands
486 |
487 | mContext.startService(serviceIntent);
488 |
489 | }
490 |
491 | @Override
492 | public boolean onCreateOptionsMenu(Menu menu) {
493 |
494 | // Inflate the menu; this adds items to the action bar if it is present.
495 | getMenuInflater().inflate(activeMenu, menu);
496 |
497 | if(activeMenu == R.menu.acceptchangemenu) return true;
498 |
499 | //MenuItem searchItem = menu.findItem(R.id.action_search);
500 | // mSearchView = (SearchView) searchItem.getActionView();
501 | // setupSearchView(searchItem);
502 | return true;
503 | }
504 |
505 | private void setupSearchView(MenuItem searchItem) {
506 |
507 | //searchItem.setShowAsActionFlags(MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
508 |
509 | SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
510 | if (searchManager != null) {
511 | List searchables = searchManager.getSearchablesInGlobalSearch();
512 |
513 | SearchableInfo info = searchManager.getSearchableInfo(getComponentName());
514 | for (SearchableInfo inf : searchables) {
515 | if (inf.getSuggestAuthority() != null
516 | && inf.getSuggestAuthority().startsWith("applications")) {
517 | info = inf;
518 | }
519 | }
520 | mSearchView.setSearchableInfo(info);
521 | }
522 |
523 | mSearchView.setOnQueryTextListener(this);
524 | }
525 |
526 | @Override
527 | public boolean onOptionsItemSelected(MenuItem item) {
528 | // Handle action bar item clicks here. The action bar will
529 | // automatically handle clicks on the Home/Up button, so long
530 | // as you specify a parent activity in AndroidManifest.xml.
531 | int id = item.getItemId();
532 |
533 |
534 | activeMenu = R.menu.packetlistmenu;
535 | switch (id) {
536 | case R.id.action_new:
537 |
538 | Intent newPacketActivty = new Intent(this, NewPacketActivity.class);
539 | startActivity(newPacketActivty);
540 |
541 | break;
542 | case R.id.action_discard:
543 | Toast.makeText(this, "Tap to delete.", Toast.LENGTH_SHORT)
544 | .show();
545 | activeMenu = R.menu.acceptchangemenu;
546 | break;
547 | case R.id.action_search:
548 |
549 | break;
550 | case R.id.action_about:
551 |
552 | Intent newAboutActivity = new Intent(this, AboutActivity.class);
553 | startActivity(newAboutActivity);
554 |
555 | break;
556 |
557 | default:
558 | break;
559 | }
560 |
561 |
562 | invalidateOptionsMenu();
563 | return super.onOptionsItemSelected(item);
564 | }
565 |
566 | @Override
567 | public void onTabSelected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) {
568 | // When the given tab is selected, switch to the corresponding page in
569 | // the ViewPager.
570 | mViewPager.setCurrentItem(tab.getPosition());
571 | }
572 |
573 | @Override
574 | public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) {
575 | }
576 |
577 | @Override
578 | public void onTabReselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) {
579 | }
580 |
581 | /**
582 | * A {@link FragmentPagerAdapter} that returns a fragment corresponding to
583 | * one of the sections/tabs/pages.
584 | */
585 | public class SectionsPagerAdapter extends FragmentPagerAdapter {
586 |
587 | public SectionsPagerAdapter(FragmentManager fm) {
588 | super(fm);
589 | }
590 |
591 | @Override
592 | public Fragment getItem(int position) {
593 | // getItem is called to instantiate the fragment for the given page.
594 | // Return a PlaceholderFragment (defined as a static inner class below).
595 | return PlaceholderFragment.newInstance(position + 1);
596 | }
597 |
598 | @Override
599 | public int getCount() {
600 | // Show 3 total pages.
601 | return 3;
602 | }
603 |
604 | @Override
605 | public CharSequence getPageTitle(int position) {
606 | Locale l = Locale.getDefault();
607 | switch (position) {
608 | case 0:
609 | return getString(R.string.title_packets).toUpperCase(l);
610 | case 1:
611 | return getString(R.string.title_trafficlog).toUpperCase(l);
612 | case 2:
613 | return getString(R.string.title_settings).toUpperCase(l);
614 | }
615 | return null;
616 | }
617 | }
618 |
619 | /**
620 | * A placeholder fragment containing a simple view.
621 | */
622 | public static class PlaceholderFragment extends Fragment {
623 | /**
624 | * The fragment argument representing the section number for this
625 | * fragment.
626 | */
627 | private static final String ARG_SECTION_NUMBER = "section_number";
628 |
629 | /**
630 | * Returns a new instance of this fragment for the given section
631 | * number.
632 | */
633 |
634 |
635 |
636 |
637 |
638 | public static PlaceholderFragment newInstance(int sectionNumber) {
639 | PlaceholderFragment fragment = new PlaceholderFragment();
640 | Bundle args = new Bundle();
641 | args.putInt(ARG_SECTION_NUMBER, sectionNumber);
642 | fragment.setArguments(args);
643 | return fragment;
644 | }
645 |
646 | public PlaceholderFragment() {
647 | }
648 |
649 | @Override
650 | public View onCreateView(LayoutInflater inflater, ViewGroup container,
651 | Bundle savedInstanceState) {
652 |
653 |
654 | View rootView = inflater.inflate(R.layout.fragment_main, container, false);
655 | TextView textView = (TextView) rootView.findViewById(R.id.section_label);
656 | textView.setText(Integer.toString(getArguments().getInt(ARG_SECTION_NUMBER)));
657 |
658 | MainActivity Main = (MainActivity)getActivity();
659 |
660 | switch((getArguments().getInt(ARG_SECTION_NUMBER)))
661 | {
662 | case 0:
663 | break;
664 | case 1:
665 | rootView = inflater.inflate(R.layout.packetlist, container, false);
666 | Main.packetsFragmentView = rootView;
667 |
668 | //load saved packets
669 | Main.updateSavedPacketsList(rootView);
670 |
671 | break;
672 | case 2:
673 | rootView = inflater.inflate(R.layout.trafficlist, container, false);
674 | Main.trafficFragmentView = rootView;
675 | //load traffic log packets
676 | Main.updateTrafficPacketsList(rootView);
677 |
678 |
679 | Button clearLogButton = (Button) rootView.findViewById(R.id.clearTrafficLogButton);
680 | clearLogButton.setOnClickListener(new Button.OnClickListener() {
681 | public void onClick(View v)
682 | {
683 | //perform action
684 | MainActivity Main = (MainActivity)getActivity();
685 | Main.dataStore.clearTrafficPackets();
686 | }
687 | });
688 |
689 |
690 |
691 | break;
692 | case 3:
693 | rootView = inflater.inflate(R.layout.settingsform, container, false);
694 | //TODO actually implement the settings stuff
695 |
696 | Button wifiButton = (Button) rootView.findViewById(R.id.setupWifiButton);
697 | wifiButton.setOnClickListener(new Button.OnClickListener() {
698 | public void onClick(View v)
699 | {
700 | //perform action
701 | Log.d("main", DataStorage.FILE_LINE("Do wifiButton button"));
702 | MainActivity Main = (MainActivity)getActivity();
703 | Main.startActivity(new Intent(Settings.ACTION_WIFI_SETTINGS));
704 |
705 | }
706 | });
707 |
708 |
709 |
710 | Main.dataStore.prepSettings(rootView);
711 |
712 | Button applyButton = (Button) rootView.findViewById(R.id.applyButton);
713 | final View finalView = rootView;
714 | applyButton.setOnClickListener(new Button.OnClickListener() {
715 | public void onClick(View v)
716 | {
717 | //perform action
718 | Log.d("main", DataStorage.FILE_LINE("Do apply button"));
719 | MainActivity Main = (MainActivity)getActivity();
720 | Main.dataStore.saveSettings(finalView);
721 | Main.startListenerService();
722 |
723 |
724 |
725 | }
726 | });
727 |
728 | default :
729 | break;
730 |
731 |
732 |
733 |
734 |
735 | }
736 |
737 | return rootView;
738 | }
739 | }
740 |
741 | }
742 |
--------------------------------------------------------------------------------