NotificationManagerCompat.java 17.5 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596
package android.support.v4.app;

import android.app.Notification;
import android.app.NotificationManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.content.pm.ServiceInfo;
import android.os.Build.VERSION;
import android.os.Bundle;
import android.os.DeadObjectException;
import android.os.Handler;
import android.os.Handler.Callback;
import android.os.HandlerThread;
import android.os.IBinder;
import android.os.Message;
import android.os.RemoteException;
import android.provider.Settings.Secure;
import android.support.v4.os.BuildCompat;
import android.util.Log;
import ct;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

public final class NotificationManagerCompat
{
  public static final String ACTION_BIND_SIDE_CHANNEL = "android.support.BIND_NOTIFICATION_SIDE_CHANNEL";
  public static final String EXTRA_USE_SIDE_CHANNEL = "android.support.useSideChannel";
  public static final int IMPORTANCE_DEFAULT = 3;
  public static final int IMPORTANCE_HIGH = 4;
  public static final int IMPORTANCE_LOW = 2;
  public static final int IMPORTANCE_MAX = 5;
  public static final int IMPORTANCE_MIN = 1;
  public static final int IMPORTANCE_NONE = 0;
  public static final int IMPORTANCE_UNSPECIFIED = -1000;
  static final int a;
  private static final Object b = new Object();
  private static String c;
  private static Set<String> d = new HashSet();
  private static final Object g = new Object();
  private static i h;
  private static final b i;
  private final Context e;
  private final NotificationManager f;
  
  static
  {
    if (BuildCompat.isAtLeastN()) {
      i = new c();
    }
    for (;;)
    {
      a = i.a();
      return;
      if (Build.VERSION.SDK_INT >= 19) {
        i = new f();
      } else if (Build.VERSION.SDK_INT >= 14) {
        i = new e();
      } else {
        i = new d();
      }
    }
  }
  
  private NotificationManagerCompat(Context paramContext)
  {
    this.e = paramContext;
    this.f = ((NotificationManager)this.e.getSystemService("notification"));
  }
  
  private void a(j paramj)
  {
    synchronized (g)
    {
      if (h == null) {
        h = new i(this.e.getApplicationContext());
      }
      h.a.obtainMessage(0, paramj).sendToTarget();
      return;
    }
  }
  
  public static NotificationManagerCompat from(Context paramContext)
  {
    return new NotificationManagerCompat(paramContext);
  }
  
  public static Set<String> getEnabledListenerPackages(Context paramContext)
  {
    Object localObject1 = Settings.Secure.getString(paramContext.getContentResolver(), "enabled_notification_listeners");
    paramContext = b;
    if (localObject1 != null) {}
    for (;;)
    {
      int j;
      try
      {
        if (!((String)localObject1).equals(c))
        {
          String[] arrayOfString = ((String)localObject1).split(":");
          HashSet localHashSet = new HashSet(arrayOfString.length);
          int k = arrayOfString.length;
          j = 0;
          if (j < k)
          {
            ComponentName localComponentName = ComponentName.unflattenFromString(arrayOfString[j]);
            if (localComponentName != null) {
              localHashSet.add(localComponentName.getPackageName());
            }
          }
          else
          {
            d = localHashSet;
            c = (String)localObject1;
          }
        }
        else
        {
          localObject1 = d;
          return (Set<String>)localObject1;
        }
      }
      finally {}
      j += 1;
    }
  }
  
  public final boolean areNotificationsEnabled()
  {
    return i.a(this.e, this.f);
  }
  
  public final void cancel(int paramInt)
  {
    cancel(null, paramInt);
  }
  
  public final void cancel(String paramString, int paramInt)
  {
    i.a(this.f, paramString, paramInt);
    if (Build.VERSION.SDK_INT <= 19) {
      a(new a(this.e.getPackageName(), paramInt, paramString));
    }
  }
  
  public final void cancelAll()
  {
    this.f.cancelAll();
    if (Build.VERSION.SDK_INT <= 19) {
      a(new a(this.e.getPackageName()));
    }
  }
  
  public final int getImportance()
  {
    return i.a(this.f);
  }
  
  public final void notify(int paramInt, Notification paramNotification)
  {
    notify(null, paramInt, paramNotification);
  }
  
  public final void notify(String paramString, int paramInt, Notification paramNotification)
  {
    Bundle localBundle = NotificationCompat.getExtras(paramNotification);
    if ((localBundle != null) && (localBundle.getBoolean("android.support.useSideChannel"))) {}
    for (int j = 1; j != 0; j = 0)
    {
      a(new g(this.e.getPackageName(), paramInt, paramString, paramNotification));
      i.a(this.f, paramString, paramInt);
      return;
    }
    i.a(this.f, paramString, paramInt, paramNotification);
  }
  
  static final class a
    implements NotificationManagerCompat.j
  {
    final String a;
    final int b;
    final String c;
    final boolean d;
    
    public a(String paramString)
    {
      this.a = paramString;
      this.b = 0;
      this.c = null;
      this.d = true;
    }
    
    public a(String paramString1, int paramInt, String paramString2)
    {
      this.a = paramString1;
      this.b = paramInt;
      this.c = paramString2;
      this.d = false;
    }
    
    public final void a(INotificationSideChannel paramINotificationSideChannel)
      throws RemoteException
    {
      if (this.d)
      {
        paramINotificationSideChannel.cancelAll(this.a);
        return;
      }
      paramINotificationSideChannel.cancel(this.a, this.b, this.c);
    }
    
    public final String toString()
    {
      StringBuilder localStringBuilder = new StringBuilder("CancelTask[");
      localStringBuilder.append("packageName:").append(this.a);
      localStringBuilder.append(", id:").append(this.b);
      localStringBuilder.append(", tag:").append(this.c);
      localStringBuilder.append(", all:").append(this.d);
      localStringBuilder.append("]");
      return localStringBuilder.toString();
    }
  }
  
  static abstract interface b
  {
    public abstract int a();
    
    public abstract int a(NotificationManager paramNotificationManager);
    
    public abstract void a(NotificationManager paramNotificationManager, String paramString, int paramInt);
    
    public abstract void a(NotificationManager paramNotificationManager, String paramString, int paramInt, Notification paramNotification);
    
    public abstract boolean a(Context paramContext, NotificationManager paramNotificationManager);
  }
  
  static final class c
    extends NotificationManagerCompat.f
  {
    public final int a(NotificationManager paramNotificationManager)
    {
      return paramNotificationManager.getImportance();
    }
    
    public final boolean a(Context paramContext, NotificationManager paramNotificationManager)
    {
      return paramNotificationManager.areNotificationsEnabled();
    }
  }
  
  static class d
    implements NotificationManagerCompat.b
  {
    public int a()
    {
      return 1;
    }
    
    public int a(NotificationManager paramNotificationManager)
    {
      return 64536;
    }
    
    public final void a(NotificationManager paramNotificationManager, String paramString, int paramInt)
    {
      paramNotificationManager.cancel(paramString, paramInt);
    }
    
    public final void a(NotificationManager paramNotificationManager, String paramString, int paramInt, Notification paramNotification)
    {
      paramNotificationManager.notify(paramString, paramInt, paramNotification);
    }
    
    public boolean a(Context paramContext, NotificationManager paramNotificationManager)
    {
      return true;
    }
  }
  
  static class e
    extends NotificationManagerCompat.d
  {
    public final int a()
    {
      return 33;
    }
  }
  
  static class f
    extends NotificationManagerCompat.e
  {
    public boolean a(Context paramContext, NotificationManager paramNotificationManager)
    {
      return ct.a(paramContext);
    }
  }
  
  static final class g
    implements NotificationManagerCompat.j
  {
    final String a;
    final int b;
    final String c;
    final Notification d;
    
    public g(String paramString1, int paramInt, String paramString2, Notification paramNotification)
    {
      this.a = paramString1;
      this.b = paramInt;
      this.c = paramString2;
      this.d = paramNotification;
    }
    
    public final void a(INotificationSideChannel paramINotificationSideChannel)
      throws RemoteException
    {
      paramINotificationSideChannel.notify(this.a, this.b, this.c, this.d);
    }
    
    public final String toString()
    {
      StringBuilder localStringBuilder = new StringBuilder("NotifyTask[");
      localStringBuilder.append("packageName:").append(this.a);
      localStringBuilder.append(", id:").append(this.b);
      localStringBuilder.append(", tag:").append(this.c);
      localStringBuilder.append("]");
      return localStringBuilder.toString();
    }
  }
  
  static final class h
  {
    final ComponentName a;
    final IBinder b;
    
    public h(ComponentName paramComponentName, IBinder paramIBinder)
    {
      this.a = paramComponentName;
      this.b = paramIBinder;
    }
  }
  
  static final class i
    implements ServiceConnection, Handler.Callback
  {
    final Handler a;
    private final Context b;
    private final HandlerThread c;
    private final Map<ComponentName, a> d = new HashMap();
    private Set<String> e = new HashSet();
    
    public i(Context paramContext)
    {
      this.b = paramContext;
      this.c = new HandlerThread("NotificationManagerCompat");
      this.c.start();
      this.a = new Handler(this.c.getLooper(), this);
    }
    
    private void a(a parama)
    {
      if (parama.b)
      {
        this.b.unbindService(this);
        parama.b = false;
      }
      parama.c = null;
    }
    
    private void b(a parama)
    {
      if (this.a.hasMessages(3, parama.a)) {
        return;
      }
      parama.e += 1;
      if (parama.e > 6)
      {
        Log.w("NotifManCompat", "Giving up on delivering " + parama.d.size() + " tasks to " + parama.a + " after " + parama.e + " retries");
        parama.d.clear();
        return;
      }
      int i = (1 << parama.e - 1) * 1000;
      if (Log.isLoggable("NotifManCompat", 3)) {
        new StringBuilder("Scheduling retry for ").append(i).append(" ms");
      }
      parama = this.a.obtainMessage(3, parama.a);
      this.a.sendMessageDelayed(parama, i);
    }
    
    private void c(a parama)
    {
      if (Log.isLoggable("NotifManCompat", 3)) {
        new StringBuilder("Processing component ").append(parama.a).append(", ").append(parama.d.size()).append(" queued tasks");
      }
      if (parama.d.isEmpty()) {}
      for (;;)
      {
        return;
        boolean bool;
        if (parama.b)
        {
          bool = true;
          if ((!bool) || (parama.c == null)) {
            b(parama);
          }
        }
        else
        {
          localObject = new Intent("android.support.BIND_NOTIFICATION_SIDE_CHANNEL").setComponent(parama.a);
          parama.b = this.b.bindService((Intent)localObject, this, NotificationManagerCompat.a);
          if (parama.b) {
            parama.e = 0;
          }
          for (;;)
          {
            bool = parama.b;
            break;
            Log.w("NotifManCompat", "Unable to bind to listener " + parama.a);
            this.b.unbindService(this);
          }
        }
        Object localObject = (NotificationManagerCompat.j)parama.d.peek();
        if (localObject != null) {}
        try
        {
          if (Log.isLoggable("NotifManCompat", 3)) {
            new StringBuilder("Sending task ").append(localObject);
          }
          ((NotificationManagerCompat.j)localObject).a(parama.c);
          parama.d.remove();
        }
        catch (DeadObjectException localDeadObjectException)
        {
          if (Log.isLoggable("NotifManCompat", 3)) {
            new StringBuilder("Remote service has died: ").append(parama.a);
          }
          if (parama.d.isEmpty()) {
            continue;
          }
          b(parama);
          return;
        }
        catch (RemoteException localRemoteException)
        {
          for (;;)
          {
            Log.w("NotifManCompat", "RemoteException communicating with " + parama.a, localRemoteException);
          }
        }
      }
    }
    
    public final boolean handleMessage(Message paramMessage)
    {
      Object localObject1;
      switch (paramMessage.what)
      {
      default: 
        return false;
      case 0: 
        paramMessage = (NotificationManagerCompat.j)paramMessage.obj;
        Object localObject2 = NotificationManagerCompat.getEnabledListenerPackages(this.b);
        if (!((Set)localObject2).equals(this.e))
        {
          this.e = ((Set)localObject2);
          Object localObject3 = this.b.getPackageManager().queryIntentServices(new Intent().setAction("android.support.BIND_NOTIFICATION_SIDE_CHANNEL"), 4);
          localObject1 = new HashSet();
          localObject3 = ((List)localObject3).iterator();
          while (((Iterator)localObject3).hasNext())
          {
            ResolveInfo localResolveInfo = (ResolveInfo)((Iterator)localObject3).next();
            if (((Set)localObject2).contains(localResolveInfo.serviceInfo.packageName))
            {
              ComponentName localComponentName = new ComponentName(localResolveInfo.serviceInfo.packageName, localResolveInfo.serviceInfo.name);
              if (localResolveInfo.serviceInfo.permission != null) {
                Log.w("NotifManCompat", "Permission present on component " + localComponentName + ", not adding listener record.");
              } else {
                ((Set)localObject1).add(localComponentName);
              }
            }
          }
          localObject2 = ((Set)localObject1).iterator();
          while (((Iterator)localObject2).hasNext())
          {
            localObject3 = (ComponentName)((Iterator)localObject2).next();
            if (!this.d.containsKey(localObject3))
            {
              if (Log.isLoggable("NotifManCompat", 3)) {
                new StringBuilder("Adding listener record for ").append(localObject3);
              }
              this.d.put(localObject3, new a((ComponentName)localObject3));
            }
          }
          localObject2 = this.d.entrySet().iterator();
          while (((Iterator)localObject2).hasNext())
          {
            localObject3 = (Map.Entry)((Iterator)localObject2).next();
            if (!((Set)localObject1).contains(((Map.Entry)localObject3).getKey()))
            {
              if (Log.isLoggable("NotifManCompat", 3)) {
                new StringBuilder("Removing listener record for ").append(((Map.Entry)localObject3).getKey());
              }
              a((a)((Map.Entry)localObject3).getValue());
              ((Iterator)localObject2).remove();
            }
          }
        }
        localObject1 = this.d.values().iterator();
        while (((Iterator)localObject1).hasNext())
        {
          localObject2 = (a)((Iterator)localObject1).next();
          ((a)localObject2).d.add(paramMessage);
          c((a)localObject2);
        }
        return true;
      case 1: 
        localObject1 = (NotificationManagerCompat.h)paramMessage.obj;
        paramMessage = ((NotificationManagerCompat.h)localObject1).a;
        localObject1 = ((NotificationManagerCompat.h)localObject1).b;
        paramMessage = (a)this.d.get(paramMessage);
        if (paramMessage != null)
        {
          paramMessage.c = INotificationSideChannel.Stub.asInterface((IBinder)localObject1);
          paramMessage.e = 0;
          c(paramMessage);
        }
        return true;
      case 2: 
        paramMessage = (ComponentName)paramMessage.obj;
        paramMessage = (a)this.d.get(paramMessage);
        if (paramMessage != null) {
          a(paramMessage);
        }
        return true;
      }
      paramMessage = (ComponentName)paramMessage.obj;
      paramMessage = (a)this.d.get(paramMessage);
      if (paramMessage != null) {
        c(paramMessage);
      }
      return true;
    }
    
    public final void onServiceConnected(ComponentName paramComponentName, IBinder paramIBinder)
    {
      if (Log.isLoggable("NotifManCompat", 3)) {
        new StringBuilder("Connected to service ").append(paramComponentName);
      }
      this.a.obtainMessage(1, new NotificationManagerCompat.h(paramComponentName, paramIBinder)).sendToTarget();
    }
    
    public final void onServiceDisconnected(ComponentName paramComponentName)
    {
      if (Log.isLoggable("NotifManCompat", 3)) {
        new StringBuilder("Disconnected from service ").append(paramComponentName);
      }
      this.a.obtainMessage(2, paramComponentName).sendToTarget();
    }
    
    static final class a
    {
      public final ComponentName a;
      public boolean b = false;
      public INotificationSideChannel c;
      public LinkedList<NotificationManagerCompat.j> d = new LinkedList();
      public int e = 0;
      
      public a(ComponentName paramComponentName)
      {
        this.a = paramComponentName;
      }
    }
  }
  
  static abstract interface j
  {
    public abstract void a(INotificationSideChannel paramINotificationSideChannel)
      throws RemoteException;
  }
}


/* Location:              /home/merong/decompile/hackery-dex2jar.jar!/android/support/v4/app/NotificationManagerCompat.class
 * Java compiler version: 6 (50.0)
 * JD-Core Version:       0.7.1
 */