Skip to content

Commit 4454aed

Browse files
committed
cleaner way to excange notification texts and colors
1 parent c28b927 commit 4454aed

3 files changed

Lines changed: 38 additions & 64 deletions

File tree

cSploit/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,4 +511,5 @@
511511
<string name="new_apk_found">App verision %s is available, do you want to upgrade ?</string>
512512
<string name="new_ruby_found">A new version for ruby is available, do you want to upgrade ?</string>
513513
<string name="new_msf_found">A new msf version is available, do you want to upgrade ?</string>
514+
<string name="msf_status">MetaSploit Status</string>
514515
</resources>

cSploit/src/org/csploit/android/services/MsfRpcdService.java

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,37 @@ public void buildMenuItem(MenuItem item) {
5858
}
5959

6060
public enum Status {
61-
STARTING,
62-
CONNECTED,
63-
DISCONNECTED,
64-
STOPPED,
65-
KILLED,
66-
START_FAILED,
67-
CONNECTION_FAILED,
61+
STARTING(R.string.rpcd_starting, R.color.selectable_blue),
62+
CONNECTED(R.string.connected_msf, R.color.green),
63+
DISCONNECTED(R.string.msfrpc_disconnected, R.color.purple),
64+
STOPPED(R.string.rpcd_stopped, R.color.purple),
65+
KILLED(R.string.msfrpcd_killed, R.color.purple),
66+
START_FAILED(R.string.msfrcd_start_failed, R.color.red),
67+
CONNECTION_FAILED(R.string.msf_connection_failed, R.color.red);
68+
69+
private final int text;
70+
private final int color;
71+
72+
Status(int text, int color) {
73+
this.text = text;
74+
this.color = color;
75+
}
76+
77+
public boolean inProgress() {
78+
return text == R.string.rpcd_starting;
79+
}
80+
81+
public boolean isError() {
82+
return color == R.color.red;
83+
}
84+
85+
public int getText() {
86+
return text;
87+
}
88+
89+
public int getColor() {
90+
return color;
91+
}
6892
}
6993

7094
public MsfRpcdService(Context context) {

cSploit/src/org/csploit/android/services/receivers/MsfRpcdServiceReceiver.java

Lines changed: 6 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -62,68 +62,17 @@ public void run() {
6262
}
6363

6464
private void showToastForStatus(Context context, MsfRpcdService.Status status) {
65-
switch (status) {
66-
case STARTING:
67-
Toast.makeText(context, R.string.rpcd_starting, Toast.LENGTH_SHORT).show();
68-
break;
69-
case CONNECTED:
70-
Toast.makeText(context, R.string.connected_msf, Toast.LENGTH_SHORT).show();
71-
break;
72-
case DISCONNECTED:
73-
Toast.makeText(context, R.string.msfrpc_disconnected, Toast.LENGTH_SHORT).show();
74-
break;
75-
case STOPPED:
76-
Toast.makeText(context, R.string.rpcd_stopped, Toast.LENGTH_SHORT).show();
77-
break;
78-
case KILLED:
79-
Toast.makeText(context, R.string.msfrpcd_killed, Toast.LENGTH_SHORT).show();
80-
break;
81-
case START_FAILED:
82-
Toast.makeText(context, R.string.msfrcd_start_failed, Toast.LENGTH_LONG).show();
83-
break;
84-
case CONNECTION_FAILED:
85-
Toast.makeText(context, R.string.msf_connection_failed, Toast.LENGTH_LONG).show();
86-
break;
87-
}
65+
Toast.makeText(context, status.getText(), (status.isError() ? Toast.LENGTH_LONG : Toast.LENGTH_SHORT)).show();
8866
}
8967

9068
private void updateNotificationForStatus(Context context, MsfRpcdService.Status status) {
9169
NotificationCompat.Builder mBuilder =
9270
new NotificationCompat.Builder(context)
93-
.setSmallIcon(R.drawable.exploit_msf)
94-
.setContentTitle("MetaSploit RPCD Status");
95-
mBuilder.setProgress(0, 0, false);
96-
switch (status) {
97-
case STARTING:
98-
mBuilder.setContentText(context.getResources().getText(R.string.rpcd_starting));
99-
mBuilder.setProgress(0, 0, true);
100-
mBuilder.setColor(ContextCompat.getColor(context, R.color.selectable_blue));
101-
break;
102-
case CONNECTED:
103-
mBuilder.setContentText(context.getResources().getText(R.string.connected_msf));
104-
mBuilder.setColor(ContextCompat.getColor(context, R.color.green));
105-
break;
106-
case DISCONNECTED:
107-
mBuilder.setContentText(context.getResources().getText(R.string.msfrpc_disconnected));
108-
mBuilder.setColor(ContextCompat.getColor(context, R.color.purple));
109-
break;
110-
case STOPPED:
111-
mBuilder.setContentText(context.getResources().getText(R.string.rpcd_stopped));
112-
mBuilder.setColor(ContextCompat.getColor(context, R.color.purple));
113-
break;
114-
case KILLED:
115-
mBuilder.setContentText(context.getResources().getText(R.string.msfrpcd_killed));
116-
mBuilder.setColor(ContextCompat.getColor(context, R.color.purple));
117-
break;
118-
case START_FAILED:
119-
mBuilder.setContentText(context.getResources().getText(R.string.msfrcd_start_failed));
120-
mBuilder.setColor(ContextCompat.getColor(context, R.color.red));
121-
break;
122-
case CONNECTION_FAILED:
123-
mBuilder.setContentText(context.getResources().getText(R.string.msf_connection_failed));
124-
mBuilder.setColor(ContextCompat.getColor(context, R.color.red));
125-
break;
126-
}
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()));
12776

12877
NotificationManager mNotificationManager =
12978
(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

0 commit comments

Comments
 (0)