|
1 | 1 | package org.csploit.android.services.receivers; |
2 | 2 |
|
3 | 3 | import android.app.Activity; |
| 4 | +import android.app.NotificationManager; |
4 | 5 | import android.content.Context; |
5 | 6 | import android.content.Intent; |
6 | 7 | import android.content.IntentFilter; |
| 8 | +import android.content.SharedPreferences; |
| 9 | +import android.support.v4.app.NotificationCompat; |
| 10 | +import android.support.v4.content.ContextCompat; |
7 | 11 | import android.widget.Toast; |
8 | 12 |
|
9 | 13 | import org.csploit.android.R; |
10 | 14 | import org.csploit.android.core.ManagedReceiver; |
| 15 | +import org.csploit.android.core.System; |
11 | 16 | import org.csploit.android.services.MsfRpcdService; |
12 | 17 |
|
13 | 18 | /** |
14 | 19 | * Receive and manage intents from the MsfRpcd service |
15 | 20 | */ |
16 | 21 | public class MsfRpcdServiceReceiver extends ManagedReceiver { |
17 | 22 |
|
| 23 | + final int MSF_NOTIFICATION = 1337; |
18 | 24 | private final IntentFilter filter; |
19 | 25 |
|
20 | 26 | public MsfRpcdServiceReceiver() { |
@@ -47,31 +53,29 @@ public void run() { |
47 | 53 | } else { |
48 | 54 | showToastForStatus(context, status); |
49 | 55 | } |
| 56 | + |
| 57 | + SharedPreferences myPrefs = System.getSettings(); |
| 58 | + if (myPrefs.getBoolean("MSF_NOTIFICATIONS", true)) { |
| 59 | + updateNotificationForStatus(context, status); |
| 60 | + } |
| 61 | + |
50 | 62 | } |
51 | 63 |
|
52 | 64 | private void showToastForStatus(Context context, MsfRpcdService.Status status) { |
53 | | - switch (status) { |
54 | | - case STARTING: |
55 | | - Toast.makeText(context, R.string.rpcd_starting, Toast.LENGTH_SHORT).show(); |
56 | | - break; |
57 | | - case CONNECTED: |
58 | | - Toast.makeText(context, R.string.connected_msf, Toast.LENGTH_SHORT).show(); |
59 | | - break; |
60 | | - case DISCONNECTED: |
61 | | - Toast.makeText(context, R.string.msfrpc_disconnected, Toast.LENGTH_SHORT).show(); |
62 | | - break; |
63 | | - case STOPPED: |
64 | | - Toast.makeText(context, R.string.rpcd_stopped, Toast.LENGTH_SHORT).show(); |
65 | | - break; |
66 | | - case KILLED: |
67 | | - Toast.makeText(context, R.string.msfrpcd_killed, Toast.LENGTH_SHORT).show(); |
68 | | - break; |
69 | | - case START_FAILED: |
70 | | - Toast.makeText(context, R.string.msfrcd_start_failed, Toast.LENGTH_LONG).show(); |
71 | | - break; |
72 | | - case CONNECTION_FAILED: |
73 | | - Toast.makeText(context, R.string.msf_connection_failed, Toast.LENGTH_LONG).show(); |
74 | | - break; |
75 | | - } |
| 65 | + Toast.makeText(context, status.getText(), (status.isError() ? Toast.LENGTH_LONG : Toast.LENGTH_SHORT)).show(); |
| 66 | + } |
| 67 | + |
| 68 | + private void updateNotificationForStatus(Context context, MsfRpcdService.Status status) { |
| 69 | + NotificationCompat.Builder mBuilder = |
| 70 | + new NotificationCompat.Builder(context) |
| 71 | + .setSmallIcon(R.drawable.exploit_msf) |
| 72 | + .setContentTitle(context.getString(R.string.msf_status)) |
| 73 | + .setProgress(0, 0, status.inProgress()) |
| 74 | + .setContentText(context.getString(status.getText())) |
| 75 | + .setColor(ContextCompat.getColor(context, status.getColor())); |
| 76 | + |
| 77 | + NotificationManager mNotificationManager = |
| 78 | + (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); |
| 79 | + mNotificationManager.notify(MSF_NOTIFICATION, mBuilder.build()); |
76 | 80 | } |
77 | 81 | } |
0 commit comments