private final void remove_all_objects(ArrayMap<String, F[]> map, String name, Object object) {
   F[] array = map.get(name);
   if (array != null) {
     int LAST = array.length - 1;
     while (LAST >= 0 && array[LAST] == null) {
       LAST--;
     }
     for (int idx = LAST; idx >= 0; idx--) {
       if (array[idx] == object) {
         final int remain = LAST - idx;
         if (remain > 0) {
           System.arraycopy(array, idx + 1, array, idx, remain);
         }
         array[LAST] = null;
         LAST--;
       }
     }
     if (LAST < 0) {
       map.remove(name);
     } else if (LAST < (array.length / 2)) {
       F[] newa = newArray(LAST + 2);
       System.arraycopy(array, 0, newa, 0, LAST + 1);
       map.put(name, newa);
     }
   }
 }
Beispiel #2
0
  /**
   * Remove process record for voice extension service.
   *
   * @param pid process id
   * @param uid user id
   */
  public void removeProcessRecordLocked(int pid, int uid) {
    ProcessRecord record = mProcessRecords.get(pid);

    if (record != null && record.getUid() == uid) {
      mProcessRecords.remove(pid);
    }
  }
Beispiel #3
0
 public <T extends RxViewDispatch> void unregisterRxError(final T object) {
   String tag = object.getClass().getSimpleName() + "_error";
   Subscription subscription = mRxActionMap.get(tag);
   if (subscription != null && !subscription.isUnsubscribed()) {
     subscription.unsubscribe();
     mRxActionMap.remove(tag);
   }
 }
 private void unregisterClientLocked(IMediaRouterClient client, boolean died) {
     ClientRecord clientRecord = mAllClientRecords.remove(client.asBinder());
     if (clientRecord != null) {
         UserRecord userRecord = clientRecord.mUserRecord;
         userRecord.mClientRecords.remove(clientRecord);
         disposeClientLocked(clientRecord, died);
         disposeUserIfNeededLocked(userRecord); // since client removed from user
     }
 }
 Request removeRequest(IBinder reqInterface) {
   synchronized (this) {
     Request req = mActiveRequests.get(reqInterface);
     if (req != null) {
       mActiveRequests.remove(req);
     }
     return req;
   }
 }
 public boolean isSnoozed(String packageName) {
   final String key = snoozeKey(packageName, mUser);
   Long snoozedUntil = mSnoozedPackages.get(key);
   if (snoozedUntil != null) {
     if (snoozedUntil > SystemClock.elapsedRealtime()) {
       if (DEBUG) Log.v(TAG, key + " snoozed");
       return true;
     }
     mSnoozedPackages.remove(packageName);
   }
   return false;
 }
  private void stopObserving(File file) {
    synchronized (mObservers) {
      DirectoryObserver observer = mObservers.get(file);
      if (observer == null) return;

      observer.mRefCount--;
      if (observer.mRefCount == 0) {
        mObservers.remove(file);
        observer.stopWatching();
      }

      if (LOG_INOTIFY) Log.d(TAG, "after stop: " + observer);
    }
  }
 private void invalidateCache(String key, int userId) {
   synchronized (mCache) {
     // Safe to reuse mCacheKey, because it is not stored in the map.
     mCache.remove(mCacheKey.set(key, userId));
   }
 }
  private void handleReadPrintJobsLocked() {
    // Make a map with the files for a print job since we may have
    // to delete some. One example of getting orphan files if the
    // spooler crashes while constructing a print job. We do not
    // persist partially populated print jobs under construction to
    // avoid special handling for various attributes missing.
    ArrayMap<PrintJobId, File> fileForJobMap = null;
    File[] files = getFilesDir().listFiles();
    if (files != null) {
      final int fileCount = files.length;
      for (int i = 0; i < fileCount; i++) {
        File file = files[i];
        if (file.isFile() && file.getName().startsWith(PRINT_JOB_FILE_PREFIX)) {
          if (fileForJobMap == null) {
            fileForJobMap = new ArrayMap<PrintJobId, File>();
          }
          String printJobIdString =
              file.getName().substring(PRINT_JOB_FILE_PREFIX.length(), file.getName().indexOf('.'));
          PrintJobId printJobId = PrintJobId.unflattenFromString(printJobIdString);
          fileForJobMap.put(printJobId, file);
        }
      }
    }

    final int printJobCount = mPrintJobs.size();
    for (int i = 0; i < printJobCount; i++) {
      PrintJobInfo printJob = mPrintJobs.get(i);

      // We want to have only the orphan files at the end.
      if (fileForJobMap != null) {
        fileForJobMap.remove(printJob.getId());
      }

      switch (printJob.getState()) {
        case PrintJobInfo.STATE_QUEUED:
        case PrintJobInfo.STATE_STARTED:
        case PrintJobInfo.STATE_BLOCKED:
          {
            // We have a print job that was queued or started or blocked in
            // the past but the device battery died or a crash occurred. In
            // this case we assume the print job failed and let the user
            // decide whether to restart the job or just cancel it.
            setPrintJobState(
                printJob.getId(),
                PrintJobInfo.STATE_FAILED,
                getString(R.string.no_connection_to_printer));
          }
          break;
      }
    }

    if (!mPrintJobs.isEmpty()) {
      // Update the notification.
      mNotificationController.onUpdateNotifications(mPrintJobs);
    }

    // Delete the orphan files.
    if (fileForJobMap != null) {
      final int orphanFileCount = fileForJobMap.size();
      for (int i = 0; i < orphanFileCount; i++) {
        File file = fileForJobMap.valueAt(i);
        file.delete();
      }
    }
  }