Program: 199230
Project: 199230
Buggy source:
void enqueueNotificationInternal(final String pkg,final String opPkg,final int callingUid,final int callingPid,final String tag,final int id,final Notification notification,int[] idOut,int incomingUserId){
  if (DBG) {
    Slog.v(TAG,"String_Node_Str" + pkg + "String_Node_Str"+ id+ "String_Node_Str"+ notification);
  }
  checkCallerIsSystemOrSameApp(pkg);
  final boolean isSystemNotification=isUidSystem(callingUid) || ("String_Node_Str".equals(pkg));
  final int userId=ActivityManager.handleIncomingUser(callingPid,callingUid,incomingUserId,true,false,"String_Node_Str",pkg);
  final UserHandle user=new UserHandle(userId);
  if (!isSystemNotification) {
synchronized (mNotificationList) {
      int count=0;
      final int N=mNotificationList.size();
      for (int i=0; i < N; i++) {
        final NotificationRecord r=mNotificationList.get(i);
        if (r.sbn.getPackageName().equals(pkg) && r.sbn.getUserId() == userId) {
          count++;
          if (count >= MAX_PACKAGE_NOTIFICATIONS) {
            Slog.e(TAG,"String_Node_Str" + count + "String_Node_Str"+ pkg);
            return;
          }
        }
      }
    }
  }
  if (!pkg.equals("String_Node_Str") || Log.isLoggable("String_Node_Str",Log.VERBOSE)) {
    EventLogTags.writeNotificationEnqueue(callingUid,callingPid,pkg,id,tag,userId,notification.toString());
  }
  if (pkg == null || notification == null) {
    throw new IllegalArgumentException("String_Node_Str" + pkg + "String_Node_Str"+ id+ "String_Node_Str"+ notification);
  }
  if (notification.icon != 0) {
    if (notification.contentView == null) {
      throw new IllegalArgumentException("String_Node_Str" + pkg + "String_Node_Str"+ id+ "String_Node_Str"+ notification);
    }
  }
  mHandler.post(new Runnable(){
    @Override public void run(){
      notification.priority=clamp(notification.priority,Notification.PRIORITY_MIN,Notification.PRIORITY_MAX);
      if (0 != (notification.flags & Notification.FLAG_HIGH_PRIORITY)) {
        if (notification.priority < Notification.PRIORITY_MAX) {
          notification.priority=Notification.PRIORITY_MAX;
        }
      }
 else       if (SCORE_ONGOING_HIGHER && 0 != (notification.flags & Notification.FLAG_ONGOING_EVENT)) {
        if (notification.priority < Notification.PRIORITY_HIGH) {
          notification.priority=Notification.PRIORITY_HIGH;
        }
      }
      int score=notification.priority * NOTIFICATION_PRIORITY_MULTIPLIER;
      final StatusBarNotification n=new StatusBarNotification(pkg,opPkg,id,tag,callingUid,callingPid,score,notification,user);
      NotificationRecord r=new NotificationRecord(n);
      if (!mSignalExtractors.isEmpty()) {
        for (        NotificationSignalExtractor extractor : mSignalExtractors) {
          try {
            RankingFuture future=extractor.process(r);
            scheduleRankingReconsideration(future);
          }
 catch (          Throwable t) {
            Slog.w(TAG,"String_Node_Str",t);
          }
        }
      }
      if (ENABLE_BLOCKED_NOTIFICATIONS && !noteNotificationOp(pkg,callingUid)) {
        if (!isSystemNotification) {
          score=JUNK_SCORE;
          Slog.e(TAG,"String_Node_Str" + pkg + "String_Node_Str");
        }
      }
      if (score < SCORE_DISPLAY_THRESHOLD) {
        return;
      }
      final boolean intercept=mZenModeHelper.shouldIntercept(pkg,notification);
      notification.extras.putBoolean(EXTRA_INTERCEPT,intercept);
      final boolean canInterrupt=(score >= SCORE_INTERRUPTION_THRESHOLD) && !intercept;
      if (DBG || intercept)       Slog.v(TAG,"String_Node_Str" + pkg + "String_Node_Str"+ canInterrupt+ "String_Node_Str"+ intercept);
synchronized (mNotificationList) {
        NotificationRecord old=null;
        int index=indexOfNotificationLocked(n.getKey());
        if (index < 0) {
          mNotificationList.add(r);
          mUsageStats.registerPostedByApp(r);
        }
 else {
          old=mNotificationList.get(index);
          mNotificationList.set(index,r);
          mUsageStats.registerUpdatedByApp(r,old);
          notification.flags|=old.getNotification().flags & Notification.FLAG_FOREGROUND_SERVICE;
          mNotificationsByKey.remove(old.sbn.getKey());
        }
        mNotificationsByKey.put(n.getKey(),r);
        Collections.sort(mNotificationList,mRankingComparator);
        if ((notification.flags & Notification.FLAG_FOREGROUND_SERVICE) != 0) {
          notification.flags|=Notification.FLAG_ONGOING_EVENT | Notification.FLAG_NO_CLEAR;
        }
        final int currentUser;
        final long token=Binder.clearCallingIdentity();
        try {
          currentUser=ActivityManager.getCurrentUser();
        }
  finally {
          Binder.restoreCallingIdentity(token);
        }
        if (notification.icon != 0) {
          if (old != null && !old.isCanceled) {
            final long identity=Binder.clearCallingIdentity();
            try {
              mStatusBar.updateNotification(n);
            }
  finally {
              Binder.restoreCallingIdentity(identity);
            }
          }
 else {
            final long identity=Binder.clearCallingIdentity();
            try {
              mStatusBar.addNotification(n);
              if ((n.getNotification().flags & Notification.FLAG_SHOW_LIGHTS) != 0 && canInterrupt) {
                mAttentionLight.pulse();
              }
            }
  finally {
              Binder.restoreCallingIdentity(identity);
            }
          }
          if (currentUser == userId) {
            sendAccessibilityEvent(notification,pkg);
          }
          mListeners.notifyPostedLocked(r.sbn,cloneNotificationListLocked());
        }
 else {
          Slog.e(TAG,"String_Node_Str" + notification);
          if (old != null && !old.isCanceled) {
            final long identity=Binder.clearCallingIdentity();
            try {
              mStatusBar.removeNotification(r.getKey());
            }
  finally {
              Binder.restoreCallingIdentity(identity);
            }
            mListeners.notifyRemovedLocked(r.sbn,cloneNotificationListLocked());
          }
          Slog.e(TAG,"String_Node_Str" + n.getPackageName());
        }
        if (!mDisableNotificationAlerts && (!(old != null && (notification.flags & Notification.FLAG_ONLY_ALERT_ONCE) != 0)) && (r.getUserId() == UserHandle.USER_ALL || (r.getUserId() == userId && r.getUserId() == currentUser) || mUserProfiles.isCurrentProfile(r.getUserId()))&& canInterrupt&& mSystemReady&& mAudioManager != null) {
          if (DBG)           Slog.v(TAG,"String_Node_Str");
          final boolean useDefaultSound=(notification.defaults & Notification.DEFAULT_SOUND) != 0 || Settings.System.DEFAULT_NOTIFICATION_URI.equals(notification.sound);
          Uri soundUri=null;
          boolean hasValidSound=false;
          if (useDefaultSound) {
            soundUri=Settings.System.DEFAULT_NOTIFICATION_URI;
            ContentResolver resolver=getContext().getContentResolver();
            hasValidSound=Settings.System.getString(resolver,Settings.System.NOTIFICATION_SOUND) != null;
          }
 else           if (notification.sound != null) {
            soundUri=notification.sound;
            hasValidSound=(soundUri != null);
          }
          if (hasValidSound) {
            boolean looping=(notification.flags & Notification.FLAG_INSISTENT) != 0;
            int audioStreamType;
            if (notification.audioStreamType >= 0) {
              audioStreamType=notification.audioStreamType;
            }
 else {
              audioStreamType=DEFAULT_STREAM_TYPE;
            }
            mSoundNotification=r;
            if ((mAudioManager.getStreamVolume(audioStreamType) != 0) && !mAudioManager.isAudioFocusExclusive()) {
              final long identity=Binder.clearCallingIdentity();
              try {
                final IRingtonePlayer player=mAudioManager.getRingtonePlayer();
                if (player != null) {
                  if (DBG)                   Slog.v(TAG,"String_Node_Str" + soundUri + "String_Node_Str"+ audioStreamType);
                  player.playAsync(soundUri,user,looping,audioStreamType);
                }
              }
 catch (              RemoteException e) {
              }
 finally {
                Binder.restoreCallingIdentity(identity);
              }
            }
          }
          final boolean hasCustomVibrate=notification.vibrate != null;
          final boolean convertSoundToVibration=!hasCustomVibrate && hasValidSound && (mAudioManager.getRingerMode() == AudioManager.RINGER_MODE_VIBRATE);
          final boolean useDefaultVibrate=(notification.defaults & Notification.DEFAULT_VIBRATE) != 0;
          if ((useDefaultVibrate || convertSoundToVibration || hasCustomVibrate) && !(mAudioManager.getRingerMode() == AudioManager.RINGER_MODE_SILENT)) {
            mVibrateNotification=r;
            if (useDefaultVibrate || convertSoundToVibration) {
              long identity=Binder.clearCallingIdentity();
              try {
                mVibrator.vibrate(r.sbn.getUid(),r.sbn.getOpPkg(),useDefaultVibrate ? mDefaultVibrationPattern : mFallbackVibrationPattern,((notification.flags & Notification.FLAG_INSISTENT) != 0) ? 0 : -1,notification.audioStreamType);
              }
  finally {
                Binder.restoreCallingIdentity(identity);
              }
            }
 else             if (notification.vibrate.length > 1) {
              mVibrator.vibrate(r.sbn.getUid(),r.sbn.getOpPkg(),notification.vibrate,((notification.flags & Notification.FLAG_INSISTENT) != 0) ? 0 : -1,notification.audioStreamType);
            }
          }
        }
        mLights.remove(old);
        if (mLedNotification == old) {
          mLedNotification=null;
        }
        if ((notification.flags & Notification.FLAG_SHOW_LIGHTS) != 0 && canInterrupt) {
          mLights.add(r);
          updateLightsLocked();
        }
 else {
          if (old != null && ((old.getFlags() & Notification.FLAG_SHOW_LIGHTS) != 0)) {
            updateLightsLocked();
          }
        }
      }
    }
  }
);
  idOut[0]=id;
}

Fixed version (ground truth):
void enqueueNotificationInternal(final String pkg,final String opPkg,final int callingUid,final int callingPid,final String tag,final int id,final Notification notification,int[] idOut,int incomingUserId){
  if (DBG) {
    Slog.v(TAG,"String_Node_Str" + pkg + "String_Node_Str"+ id+ "String_Node_Str"+ notification);
  }
  checkCallerIsSystemOrSameApp(pkg);
  final boolean isSystemNotification=isUidSystem(callingUid) || ("String_Node_Str".equals(pkg));
  final int userId=ActivityManager.handleIncomingUser(callingPid,callingUid,incomingUserId,true,false,"String_Node_Str",pkg);
  final UserHandle user=new UserHandle(userId);
  if (!isSystemNotification) {
synchronized (mNotificationList) {
      int count=0;
      final int N=mNotificationList.size();
      for (int i=0; i < N; i++) {
        final NotificationRecord r=mNotificationList.get(i);
        if (r.sbn.getPackageName().equals(pkg) && r.sbn.getUserId() == userId) {
          count++;
          if (count >= MAX_PACKAGE_NOTIFICATIONS) {
            Slog.e(TAG,"String_Node_Str" + count + "String_Node_Str"+ pkg);
            return;
          }
        }
      }
    }
  }
  if (!pkg.equals("String_Node_Str") || Log.isLoggable("String_Node_Str",Log.VERBOSE)) {
    EventLogTags.writeNotificationEnqueue(callingUid,callingPid,pkg,id,tag,userId,notification.toString());
  }
  if (pkg == null || notification == null) {
    throw new IllegalArgumentException("String_Node_Str" + pkg + "String_Node_Str"+ id+ "String_Node_Str"+ notification);
  }
  if (notification.icon != 0) {
    if (notification.contentView == null) {
      throw new IllegalArgumentException("String_Node_Str" + pkg + "String_Node_Str"+ id+ "String_Node_Str"+ notification);
    }
  }
  mHandler.post(new Runnable(){
    @Override public void run(){
      notification.priority=clamp(notification.priority,Notification.PRIORITY_MIN,Notification.PRIORITY_MAX);
      if (0 != (notification.flags & Notification.FLAG_HIGH_PRIORITY)) {
        if (notification.priority < Notification.PRIORITY_MAX) {
          notification.priority=Notification.PRIORITY_MAX;
        }
      }
 else       if (SCORE_ONGOING_HIGHER && 0 != (notification.flags & Notification.FLAG_ONGOING_EVENT)) {
        if (notification.priority < Notification.PRIORITY_HIGH) {
          notification.priority=Notification.PRIORITY_HIGH;
        }
      }
      int score=notification.priority * NOTIFICATION_PRIORITY_MULTIPLIER;
      final StatusBarNotification n=new StatusBarNotification(pkg,opPkg,id,tag,callingUid,callingPid,score,notification,user);
      NotificationRecord r=new NotificationRecord(n);
      if (!mSignalExtractors.isEmpty()) {
        for (        NotificationSignalExtractor extractor : mSignalExtractors) {
          try {
            RankingReconsideration recon=extractor.process(r);
            scheduleRankingReconsideration(recon);
          }
 catch (          Throwable t) {
            Slog.w(TAG,"String_Node_Str",t);
          }
        }
      }
      if (ENABLE_BLOCKED_NOTIFICATIONS && !noteNotificationOp(pkg,callingUid)) {
        if (!isSystemNotification) {
          score=JUNK_SCORE;
          Slog.e(TAG,"String_Node_Str" + pkg + "String_Node_Str");
        }
      }
      if (score < SCORE_DISPLAY_THRESHOLD) {
        return;
      }
      final boolean intercept=mZenModeHelper.shouldIntercept(pkg,notification);
      notification.extras.putBoolean(EXTRA_INTERCEPT,intercept);
      final boolean canInterrupt=(score >= SCORE_INTERRUPTION_THRESHOLD) && !intercept;
      if (DBG || intercept)       Slog.v(TAG,"String_Node_Str" + pkg + "String_Node_Str"+ canInterrupt+ "String_Node_Str"+ intercept);
synchronized (mNotificationList) {
        NotificationRecord old=null;
        int index=indexOfNotificationLocked(n.getKey());
        if (index < 0) {
          mNotificationList.add(r);
          mUsageStats.registerPostedByApp(r);
        }
 else {
          old=mNotificationList.get(index);
          mNotificationList.set(index,r);
          mUsageStats.registerUpdatedByApp(r,old);
          notification.flags|=old.getNotification().flags & Notification.FLAG_FOREGROUND_SERVICE;
          mNotificationsByKey.remove(old.sbn.getKey());
        }
        mNotificationsByKey.put(n.getKey(),r);
        Collections.sort(mNotificationList,mRankingComparator);
        if ((notification.flags & Notification.FLAG_FOREGROUND_SERVICE) != 0) {
          notification.flags|=Notification.FLAG_ONGOING_EVENT | Notification.FLAG_NO_CLEAR;
        }
        final int currentUser;
        final long token=Binder.clearCallingIdentity();
        try {
          currentUser=ActivityManager.getCurrentUser();
        }
  finally {
          Binder.restoreCallingIdentity(token);
        }
        if (notification.icon != 0) {
          if (old != null && !old.isCanceled) {
            final long identity=Binder.clearCallingIdentity();
            try {
              mStatusBar.updateNotification(n);
            }
  finally {
              Binder.restoreCallingIdentity(identity);
            }
          }
 else {
            final long identity=Binder.clearCallingIdentity();
            try {
              mStatusBar.addNotification(n);
              if ((n.getNotification().flags & Notification.FLAG_SHOW_LIGHTS) != 0 && canInterrupt) {
                mAttentionLight.pulse();
              }
            }
  finally {
              Binder.restoreCallingIdentity(identity);
            }
          }
          if (currentUser == userId) {
            sendAccessibilityEvent(notification,pkg);
          }
          mListeners.notifyPostedLocked(r.sbn,cloneNotificationListLocked());
        }
 else {
          Slog.e(TAG,"String_Node_Str" + notification);
          if (old != null && !old.isCanceled) {
            final long identity=Binder.clearCallingIdentity();
            try {
              mStatusBar.removeNotification(r.getKey());
            }
  finally {
              Binder.restoreCallingIdentity(identity);
            }
            mListeners.notifyRemovedLocked(r.sbn,cloneNotificationListLocked());
          }
          Slog.e(TAG,"String_Node_Str" + n.getPackageName());
        }
        if (!mDisableNotificationAlerts && (!(old != null && (notification.flags & Notification.FLAG_ONLY_ALERT_ONCE) != 0)) && (r.getUserId() == UserHandle.USER_ALL || (r.getUserId() == userId && r.getUserId() == currentUser) || mUserProfiles.isCurrentProfile(r.getUserId()))&& canInterrupt&& mSystemReady&& mAudioManager != null) {
          if (DBG)           Slog.v(TAG,"String_Node_Str");
          final boolean useDefaultSound=(notification.defaults & Notification.DEFAULT_SOUND) != 0 || Settings.System.DEFAULT_NOTIFICATION_URI.equals(notification.sound);
          Uri soundUri=null;
          boolean hasValidSound=false;
          if (useDefaultSound) {
            soundUri=Settings.System.DEFAULT_NOTIFICATION_URI;
            ContentResolver resolver=getContext().getContentResolver();
            hasValidSound=Settings.System.getString(resolver,Settings.System.NOTIFICATION_SOUND) != null;
          }
 else           if (notification.sound != null) {
            soundUri=notification.sound;
            hasValidSound=(soundUri != null);
          }
          if (hasValidSound) {
            boolean looping=(notification.flags & Notification.FLAG_INSISTENT) != 0;
            int audioStreamType;
            if (notification.audioStreamType >= 0) {
              audioStreamType=notification.audioStreamType;
            }
 else {
              audioStreamType=DEFAULT_STREAM_TYPE;
            }
            mSoundNotification=r;
            if ((mAudioManager.getStreamVolume(audioStreamType) != 0) && !mAudioManager.isAudioFocusExclusive()) {
              final long identity=Binder.clearCallingIdentity();
              try {
                final IRingtonePlayer player=mAudioManager.getRingtonePlayer();
                if (player != null) {
                  if (DBG)                   Slog.v(TAG,"String_Node_Str" + soundUri + "String_Node_Str"+ audioStreamType);
                  player.playAsync(soundUri,user,looping,audioStreamType);
                }
              }
 catch (              RemoteException e) {
              }
 finally {
                Binder.restoreCallingIdentity(identity);
              }
            }
          }
          final boolean hasCustomVibrate=notification.vibrate != null;
          final boolean convertSoundToVibration=!hasCustomVibrate && hasValidSound && (mAudioManager.getRingerMode() == AudioManager.RINGER_MODE_VIBRATE);
          final boolean useDefaultVibrate=(notification.defaults & Notification.DEFAULT_VIBRATE) != 0;
          if ((useDefaultVibrate || convertSoundToVibration || hasCustomVibrate) && !(mAudioManager.getRingerMode() == AudioManager.RINGER_MODE_SILENT)) {
            mVibrateNotification=r;
            if (useDefaultVibrate || convertSoundToVibration) {
              long identity=Binder.clearCallingIdentity();
              try {
                mVibrator.vibrate(r.sbn.getUid(),r.sbn.getOpPkg(),useDefaultVibrate ? mDefaultVibrationPattern : mFallbackVibrationPattern,((notification.flags & Notification.FLAG_INSISTENT) != 0) ? 0 : -1,notification.audioStreamType);
              }
  finally {
                Binder.restoreCallingIdentity(identity);
              }
            }
 else             if (notification.vibrate.length > 1) {
              mVibrator.vibrate(r.sbn.getUid(),r.sbn.getOpPkg(),notification.vibrate,((notification.flags & Notification.FLAG_INSISTENT) != 0) ? 0 : -1,notification.audioStreamType);
            }
          }
        }
        mLights.remove(old);
        if (mLedNotification == old) {
          mLedNotification=null;
        }
        if ((notification.flags & Notification.FLAG_SHOW_LIGHTS) != 0 && canInterrupt) {
          mLights.add(r);
          updateLightsLocked();
        }
 else {
          if (old != null && ((old.getFlags() & Notification.FLAG_SHOW_LIGHTS) != 0)) {
            updateLightsLocked();
          }
        }
      }
    }
  }
);
  idOut[0]=id;
}