1 package com.koushikdutta.superuser;
3 import com.koushikdutta.superuser.db.LogEntry;
4 import com.koushikdutta.superuser.db.SuDatabaseHelper;
5 import com.koushikdutta.superuser.db.UidPolicy;
6 import com.koushikdutta.superuser.util.Settings;
8 import android.app.NotificationManager;
9 import android.content.BroadcastReceiver;
10 import android.content.Context;
11 import android.content.Intent;
12 import android.support.v4.app.NotificationCompat;
13 import android.widget.Toast;
15 public class SuReceiver extends BroadcastReceiver {
17 public void onReceive(Context context, Intent intent) {
21 String command = intent.getStringExtra("command");
24 int uid = intent.getIntExtra("uid", -1);
27 int desiredUid = intent.getIntExtra("desired_uid", -1);
30 String action = intent.getStringExtra("action");
33 String fromName = intent.getStringExtra("from_name");
34 String desiredName = intent.getStringExtra("desired_name");
36 LogEntry le = new LogEntry();
40 le.desiredUid = desiredUid;
41 le.desiredName = desiredName;
42 le.username = fromName;
43 SuDatabaseHelper.addLog(context, le);
46 if (UidPolicy.ALLOW.equals(action)) {
47 toast = context.getString(R.string.superuser_granted, le.getName());
50 toast = context.getString(R.string.superuser_denied, le.getName());
53 switch (Settings.getNotificationType(context)) {
54 case Settings.NOTIFICATION_TYPE_NOTIFICATION:
55 NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
56 builder.setTicker(toast)
57 .setContentTitle(context.getString(R.string.app_name))
58 .setContentText(toast)
59 .setSmallIcon(R.drawable.ic_stat_notification);
61 NotificationManager nm = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
62 nm.notify(NOTIFICATION_ID, builder.getNotification());
64 case Settings.NOTIFICATION_TYPE_TOAST:
65 Toast.makeText(context, toast, Toast.LENGTH_SHORT).show();
70 private static final int NOTIFICATION_ID = 4545;