OSDN Git Service

rev version;
[android-x86/external-koush-Superuser.git] / Superuser / src / com / koushikdutta / superuser / SuReceiver.java
index 81a1e7d..5bc49b4 100644 (file)
 
 package com.koushikdutta.superuser;
 
-import java.util.Random;
-
 import android.app.NotificationManager;
+import android.app.PendingIntent;
 import android.content.BroadcastReceiver;
 import android.content.Context;
 import android.content.Intent;
-import android.os.Handler;
 import android.support.v4.app.NotificationCompat;
 import android.widget.Toast;
 
 import com.koushikdutta.superuser.db.LogEntry;
-import com.koushikdutta.superuser.db.SuDatabaseHelper;
+import com.koushikdutta.superuser.db.SuperuserDatabaseHelper;
 import com.koushikdutta.superuser.db.UidPolicy;
 import com.koushikdutta.superuser.util.Settings;
 
@@ -60,18 +58,9 @@ public class SuReceiver extends BroadcastReceiver {
         le.desiredName = desiredName;
         le.username = fromName;
         le.date = (int)(System.currentTimeMillis() / 1000);
-        SuDatabaseHelper.getPackageInfoForUid(context, le);
-        // wait a bit before logging... lots of concurrent su requests at the same time
-        // cause a db lock
-        new Handler().postDelayed(new Runnable() {
-            public void run() {
-                try {
-                    SuDatabaseHelper.addLog(context, le);
-                }
-                catch (Exception e) {
-                }
-            };
-        }, 5000L);
+        le.getPackageInfo(context);
+
+        UidPolicy u = SuperuserDatabaseHelper.addLog(context, le);
 
         String toast;
         if (UidPolicy.ALLOW.equals(action)) {
@@ -81,10 +70,15 @@ public class SuReceiver extends BroadcastReceiver {
             toast = context.getString(R.string.superuser_denied, le.getName());
         }
 
+        if (u != null && !u.notification)
+            return;
+
         switch (Settings.getNotificationType(context)) {
         case Settings.NOTIFICATION_TYPE_NOTIFICATION:
             NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
             builder.setTicker(toast)
+            .setAutoCancel(true)
+            .setContentIntent(PendingIntent.getActivity(context, 0, new Intent(), 0))
             .setContentTitle(context.getString(R.string.superuser))
             .setContentText(toast)
             .setSmallIcon(R.drawable.ic_stat_notification);