2 * Copyright (C) 2013 Koushik Dutta (@koush)
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package com.koushikdutta.superuser;
19 import com.koushikdutta.superuser.db.LogEntry;
20 import com.koushikdutta.superuser.db.SuDatabaseHelper;
21 import com.koushikdutta.superuser.db.UidPolicy;
22 import com.koushikdutta.superuser.util.Settings;
24 import android.app.NotificationManager;
25 import android.content.BroadcastReceiver;
26 import android.content.Context;
27 import android.content.Intent;
28 import android.support.v4.app.NotificationCompat;
29 import android.widget.Toast;
31 public class SuReceiver extends BroadcastReceiver {
33 public void onReceive(Context context, Intent intent) {
37 String command = intent.getStringExtra("command");
40 int uid = intent.getIntExtra("uid", -1);
43 int desiredUid = intent.getIntExtra("desired_uid", -1);
46 String action = intent.getStringExtra("action");
49 String fromName = intent.getStringExtra("from_name");
50 String desiredName = intent.getStringExtra("desired_name");
52 LogEntry le = new LogEntry();
56 le.desiredUid = desiredUid;
57 le.desiredName = desiredName;
58 le.username = fromName;
59 SuDatabaseHelper.addLog(context, le);
62 if (UidPolicy.ALLOW.equals(action)) {
63 toast = context.getString(R.string.superuser_granted, le.getName());
66 toast = context.getString(R.string.superuser_denied, le.getName());
69 switch (Settings.getNotificationType(context)) {
70 case Settings.NOTIFICATION_TYPE_NOTIFICATION:
71 NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
72 builder.setTicker(toast)
73 .setContentTitle(context.getString(R.string.superuser))
74 .setContentText(toast)
75 .setSmallIcon(R.drawable.ic_stat_notification);
77 NotificationManager nm = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
78 nm.notify(NOTIFICATION_ID, builder.getNotification());
80 case Settings.NOTIFICATION_TYPE_TOAST:
81 Toast.makeText(context, toast, Toast.LENGTH_SHORT).show();
86 private static final int NOTIFICATION_ID = 4545;