/** Called by the Binder stub. */
 void removeUser(int userId) {
   synchronized (mLock) {
     Slog.i(TAG, "Removing user " + userId + " and all data.");
     mUserState.remove(userId);
     cleanUpRemovedUsersLocked();
   }
 }
Пример #2
0
  /* package */ void removeVirtualDisplay(VirtualDisplayAndroid display) {
    DisplayAndroid displayAndroid = mIdMap.get(display.getDisplayId());
    assert displayAndroid == display;

    if (mNativePointer != 0) nativeRemoveDisplay(mNativePointer, display.getDisplayId());
    mIdMap.remove(display.getDisplayId());
  }
 /**
  * 移除事件
  *
  * @param nEventCode
  */
 protected void removeCallbackEventListener(int nEventCode) {
   if (codeToListenerMap == null) {
     return;
   }
   codeToListenerMap.remove(nEventCode);
   AndroidEventManager.getInstance().removeEventListener(nEventCode, this);
 }
Пример #4
0
  private void removeUserStateLocked(final int userHandle) {
    // Cleanup package manager settings
    mPm.cleanUpUserLILPw(userHandle);

    // Remove this user from the list
    mUsers.remove(userHandle);

    // Have user ID linger for several seconds to let external storage VFS
    // cache entries expire. This must be greater than the 'entry_valid'
    // timeout used by the FUSE daemon.
    mHandler.postDelayed(
        new Runnable() {
          @Override
          public void run() {
            synchronized (mPackagesLock) {
              mRemovingUserIds.delete(userHandle);
            }
          }
        },
        MINUTE_IN_MILLIS);

    // Remove user file
    AtomicFile userFile = new AtomicFile(new File(mUsersDir, userHandle + ".xml"));
    userFile.delete();
    // Update the user list
    writeUserListLocked();
    updateUserIdsLocked();
    removeDirectoryRecursive(Environment.getUserSystemDirectory(userHandle));
  }
Пример #5
0
 /** Resets the banning state. */
 void reset() {
   if (sUidToThrottler != null) sUidToThrottler.remove(mUid);
   mSharedPreferences
       .edit()
       .remove(SCORE + mUid)
       .remove(LAST_REQUEST + mUid)
       .remove(BANNED_UNTIL + mUid)
       .apply();
 }
 @SuppressWarnings("unchecked")
 @Override
 public void destroyItem(ViewGroup container, int position, Object object) {
   VH holder = (VH) object;
   mAttached.remove(position);
   container.removeView(holder.itemView);
   mCache.offer(holder);
   onRecycleViewHolder(holder);
 }
Пример #7
0
 public void onUserStopping(int userId) {
   if (userId < 1) return;
   synchronized (mAppWidgetServices) {
     AppWidgetServiceImpl impl = mAppWidgetServices.get(userId);
     if (impl != null) {
       mAppWidgetServices.remove(userId);
       impl.onUserStopping();
     }
   }
 }
 void a(int paramInt) {
   synchronized (c) {
     PowerManager.WakeLock localWakeLock = (PowerManager.WakeLock) c.get(paramInt);
     if (localWakeLock != null) {
       localWakeLock.release();
       c.remove(paramInt);
     }
     return;
   }
 }
Пример #9
0
 public void removePop(int key) {
   PopupWindow popupWindow = getWindow(key);
   if (popupWindow != null) {
     Log.d(TAG, "remove popupWindow.");
     popupWindow.dismiss();
     popupWindows.remove(key);
   } else {
     Log.d(TAG, "remove popupWindow.but popupWindow is null.");
   }
 }
  public static void updateChannels(
      Context context, String inputId, List<XmlTvParser.XmlTvChannel> channels) {
    // Create a map from original network ID to channel row ID for existing channels.
    SparseArray<Long> mExistingChannelsMap = new SparseArray<>();
    Uri channelsUri = TvContract.buildChannelsUriForInput(inputId);
    String[] projection = {Channels._ID, Channels.COLUMN_ORIGINAL_NETWORK_ID};
    Cursor cursor = null;
    ContentResolver resolver = context.getContentResolver();
    try {
      cursor = resolver.query(channelsUri, projection, null, null, null);
      while (cursor != null && cursor.moveToNext()) {
        long rowId = cursor.getLong(0);
        int originalNetworkId = cursor.getInt(1);
        mExistingChannelsMap.put(originalNetworkId, rowId);
      }
    } finally {
      if (cursor != null) {
        cursor.close();
      }
    }

    // If a channel exists, update it. If not, insert a new one.
    ContentValues values = new ContentValues();
    values.put(Channels.COLUMN_INPUT_ID, inputId);
    Map<Uri, String> logos = new HashMap<>();
    for (XmlTvParser.XmlTvChannel channel : channels) {
      values.put(Channels.COLUMN_DISPLAY_NUMBER, channel.displayNumber);
      values.put(Channels.COLUMN_DISPLAY_NAME, channel.displayName);
      values.put(Channels.COLUMN_ORIGINAL_NETWORK_ID, channel.originalNetworkId);
      values.put(Channels.COLUMN_TRANSPORT_STREAM_ID, channel.transportStreamId);
      values.put(Channels.COLUMN_SERVICE_ID, channel.serviceId);
      Long rowId = mExistingChannelsMap.get(channel.originalNetworkId);
      Uri uri;
      if (rowId == null) {
        uri = resolver.insert(TvContract.Channels.CONTENT_URI, values);
      } else {
        uri = TvContract.buildChannelUri(rowId);
        resolver.update(uri, values, null, null);
        mExistingChannelsMap.remove(channel.originalNetworkId);
      }
      if (!TextUtils.isEmpty(channel.icon.src)) {
        logos.put(TvContract.buildChannelLogoUri(uri), channel.icon.src);
      }
    }
    if (!logos.isEmpty()) {
      new InsertLogosTask(context).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, logos);
    }

    // Deletes channels which don't exist in the new feed.
    int size = mExistingChannelsMap.size();
    for (int i = 0; i < size; ++i) {
      Long rowId = mExistingChannelsMap.valueAt(i);
      resolver.delete(TvContract.buildChannelUri(rowId), null, null);
    }
  }
Пример #11
0
 static View retrieveFromScrap(SparseArray<View> scrapViews, int position) {
   int size = scrapViews.size();
   if (size > 0) {
     // See if we still have a view for this position.
     for (int i = 0; i < size; i++) {
       int fromPosition = scrapViews.keyAt(i);
       View view = scrapViews.get(fromPosition);
       if (fromPosition == position) {
         scrapViews.remove(fromPosition);
         return view;
       }
     }
     int index = size - 1;
     View r = scrapViews.valueAt(index);
     scrapViews.remove(scrapViews.keyAt(index));
     return r;
   } else {
     return null;
   }
 }
 public void removeRootView(int rootViewTag) {
   UiThreadUtil.assertOnUiThread();
   if (!mRootTags.get(rootViewTag)) {
     SoftAssertions.assertUnreachable(
         "View with tag " + rootViewTag + " is not registered as a root view");
   }
   View rootView = mTagsToViews.get(rootViewTag);
   dropView(rootView);
   mRootTags.delete(rootViewTag);
   mRootViewsContext.remove(rootViewTag);
 }
  void removeCursorController(GVRBaseController controller) {
    int id = controller.getId();
    controllers.remove(id);

    // stop the thread if no more devices are online
    if (controllers.size() == 0 && threadStarted) {
      Log.d(TAG, "Stopping " + THREAD_NAME);
      thread.quitSafely();
      thread = new EventHandlerThread(THREAD_NAME);
      threadStarted = false;
    }
  }
Пример #14
0
  public void onUserRemoved(int userId) {
    if (userId < 1) return;
    synchronized (mAppWidgetServices) {
      AppWidgetServiceImpl impl = mAppWidgetServices.get(userId);
      mAppWidgetServices.remove(userId);

      if (impl == null) {
        AppWidgetServiceImpl.getSettingsFile(userId).delete();
      } else {
        impl.onUserRemoved();
      }
    }
  }
 /** Releases all references to given native View. */
 private void dropView(View view) {
   UiThreadUtil.assertOnUiThread();
   if (!mRootTags.get(view.getId())) {
     // For non-root views we notify viewmanager with {@link ViewManager#onDropInstance}
     Assertions.assertNotNull(mTagsToViewManagers.get(view.getId()))
         .onDropViewInstance((ThemedReactContext) view.getContext(), view);
   }
   ViewManager viewManager = mTagsToViewManagers.get(view.getId());
   if (view instanceof ViewGroup && viewManager instanceof ViewGroupManager) {
     ViewGroup viewGroup = (ViewGroup) view;
     ViewGroupManager viewGroupManager = (ViewGroupManager) viewManager;
     for (int i = viewGroupManager.getChildCount(viewGroup) - 1; i >= 0; i--) {
       View child = viewGroupManager.getChildAt(viewGroup, i);
       if (mTagsToViews.get(child.getId()) != null) {
         dropView(child);
       }
     }
     viewGroupManager.removeAllViews(viewGroup);
   }
   mTagsToViews.remove(view.getId());
   mTagsToViewManagers.remove(view.getId());
 }
 private void disposeUserIfNeededLocked(UserRecord userRecord) {
     // If there are no records left and the user is no longer current then go ahead
     // and purge the user record and all of its associated state.  If the user is current
     // then leave it alone since we might be connected to a route or want to query
     // the same route information again soon.
     if (userRecord.mUserId != mCurrentUserId
             && userRecord.mClientRecords.isEmpty()) {
         if (DEBUG) {
             Slog.d(TAG, userRecord + ": Disposed");
         }
         mUserRecords.remove(userRecord.mUserId);
         // Note: User already stopped (by switchUser) so no need to send stop message here.
     }
 }
 @Override
 public void onFinished(int sessionId, boolean success) {
   mPendingReplays.remove(sessionId);
   SessionInfo session = mInstaller.getSessionInfo(sessionId);
   if ((session != null) && (session.getAppPackageName() != null)) {
     mPendingBadgeUpdates.remove(session.getAppPackageName());
     // Replay all updates with a one time update for this installed package. No
     // need to store this record for future updates, as the app list will get
     // refreshed on resume.
     replayUpdates(
         new PackageInstallInfo(
             session.getAppPackageName(), success ? STATUS_INSTALLED : STATUS_FAILED, 0));
   }
 }
Пример #18
0
 /**
  * Makes sure that the size of scrapViews does not exceed the size of activeViews. (This can
  * happen if an adapter does not recycle its views).
  */
 private void pruneScrapViews() {
   final int maxViews = activeViews.length;
   final int viewTypeCount = this.viewTypeCount;
   final SparseArray<View>[] scrapViews = this.scrapViews;
   for (int i = 0; i < viewTypeCount; ++i) {
     final SparseArray<View> scrapPile = scrapViews[i];
     int size = scrapPile.size();
     final int extras = size - maxViews;
     size--;
     for (int j = 0; j < extras; j++) {
       scrapPile.remove(scrapPile.keyAt(size--));
     }
   }
 }
Пример #19
0
    public void removeUser(final int id) {
      User user = users.get(id);
      users.remove(id);

      if (user != null && user.getChannel().id == visibleChannel) {
        final int userLocation = Collections.binarySearch(visibleUserList, user, userComparator);

        removeVisibleUser(userLocation);
        super.notifyDataSetChanged();

        if (visibleUsersChangedCallback != null) {
          visibleUsersChangedCallback.run();
        }
      }
    }
 protected static void interactResult(int decisionId, int choice) {
   MTMDecision d;
   synchronized (openDecisions) {
     d = openDecisions.get(decisionId);
     openDecisions.remove(decisionId);
   }
   if (d == null) {
     LOGGER.log(Level.SEVERE, "interactResult: aborting due to stale decision reference!");
     return;
   }
   synchronized (d) {
     d.state = choice;
     d.notify();
   }
 }
Пример #21
0
 /** 停止循环 */
 public static void stopLoop(int requestCode) {
   if (mApp == null) {
     return;
   }
   LoopRunnable loopRunnable = sLoopRunnerMap.get(requestCode);
   sLoopRunnerMap.remove(requestCode);
   Intent intent = new Intent(ACTION_LOOP);
   intent.putExtra("requestCode", requestCode);
   AlarmManager alarmManager = (AlarmManager) mApp.getSystemService(Context.ALARM_SERVICE);
   PendingIntent pendingIntent =
       PendingIntent.getBroadcast(mApp, requestCode, intent, PendingIntent.FLAG_UPDATE_CURRENT);
   alarmManager.cancel(pendingIntent);
   if (loopRunnable != null) {
     loopRunnable.loopEnd();
   }
 }
  @Override
  public Object instantiateItem(ViewGroup container, int position) {
    int realPosition =
        (mAdapter instanceof FragmentPagerAdapter || mAdapter instanceof FragmentStatePagerAdapter)
            ? position
            : toRealPosition(position);

    if (mBoundaryCaching) {
      ToDestroy toDestroy = mToDestroy.get(position);
      if (toDestroy != null) {
        mToDestroy.remove(position);
        return toDestroy.object;
      }
    }
    return mAdapter.instantiateItem(container, realPosition);
  }
 /**
  * 删除一个任务
  *
  * @param downloadId
  */
 public void deleteTask(int downloadId) {
   if (mDbController.deleteTask(downloadId)) {
     FileDownloaderModel model = getFileDownloaderModelById(downloadId);
     if (model != null) { // 删除文件
       new File(model.getPath()).delete();
     }
     pauseTask(downloadId);
     removeDownloadingTask(downloadId);
     removeWaitQueueTask(downloadId);
     try {
       mAllTasks.remove(downloadId);
     } catch (Exception e) {
       ILogger.e(e);
     }
   } else {
     ILogger.e("delete failure");
   }
 }
Пример #24
0
  private FoldableItemLayout getLayoutForItem(int position) {
    FoldableItemLayout layout = foldableItemsMap.get(position);
    if (layout != null) {
      return layout; // We already have layout for this position
    }

    // Trying to free used layout (far enough from currently requested)
    int farthestItem = position;

    int size = foldableItemsMap.size();
    for (int i = 0; i < size; i++) {
      int pos = foldableItemsMap.keyAt(i);
      if (Math.abs(position - pos) > Math.abs(position - farthestItem)) {
        farthestItem = pos;
      }
    }

    if (Math.abs(farthestItem - position) >= MAX_CHILDREN_COUNT) {
      layout = foldableItemsMap.get(farthestItem);
      foldableItemsMap.remove(farthestItem);
      recycleAdapterView(layout);
    }

    if (layout == null) {
      // Trying to find cached layout
      layout = foldableItemsCache.poll();
    }

    if (layout == null) {
      // If still no suited layout - create it
      layout = new FoldableItemLayout(getContext());
      layout.setFoldShading(foldShading);
      addView(layout, PARAMS);
    }

    layout.setAutoScaleEnabled(isAutoScaleEnabled);
    setupAdapterView(layout, position);
    foldableItemsMap.put(position, layout);

    return layout;
  }
  @Implementation
  public void recycle() {
    final StrictEqualityEventWrapper wrapper =
        new StrictEqualityEventWrapper(realAccessibilityEvent);
    if (!obtainedInstances.containsKey(wrapper)) {
      throw new IllegalStateException();
    }

    obtainedInstances.remove(wrapper);
    int keyOfWrapper = -1;
    for (int i = 0; i < orderedInstances.size(); i++) {
      int key = orderedInstances.keyAt(i);
      if (orderedInstances.get(key).equals(wrapper)) {
        keyOfWrapper = key;
        break;
      }
    }
    orderedInstances.remove(keyOfWrapper);
    sAllocationCount--;
    setParcelableData(null);
  }
Пример #26
0
  void removeTimeoutInst(int id) {
    synchronized (mTimeouts) {
      V8Timeout to = mTimeouts.get(id);
      if (to != null) {
        to.setAsDead();
        mHandler.removeCallbacks(to, null);
        if (DEBUG) {
          Log.d(TAG, "Removed timeout (clearTimeout) " + id);
        }
        mTimeouts.remove(id);

        if (mRunningTO != to) {
          mTimeoutsToGC.add(to);
        }
        if (!mHandler.hasMessages(MSG_CLEANUP)) {
          mHandler.sendMessageDelayed(mHandler.obtainMessage(MSG_CLEANUP), DELAY_CLEANUP);
        }
      } else {
        Log.i(TAG, "Couldn't remove timeout (clearTimeout) " + id);
      }
    }
  }
Пример #27
0
 public void remove(Object key) {
   mArray.remove(key.hashCode());
 }
Пример #28
0
  @Override
  public boolean onTouchEvent(MotionEvent event) {
    int pointerIndex = event.getActionIndex();
    int pointerId = event.getPointerId(pointerIndex);
    int maskedAction = event.getActionMasked();

    switch (maskedAction) {
      case MotionEvent.ACTION_DOWN:
      case MotionEvent.ACTION_POINTER_DOWN:
        {
          performClick();

          if (event.getPointerCount() < mMaxTouch) {
            pressCount = event.getPointerCount();

            PointF f = new PointF();
            f.x = event.getX(pointerIndex);
            f.y = event.getY(pointerIndex);

            if (mRect.contains(f)) {
              normalizePoint(f);
              mActivePointers.put(pointerId, f);
              mListener.on(pointerId, ViewUtils.getCell(mn, f.x), mRangeY.fromRelative(f.y));
            }
          }
        }
      case MotionEvent.ACTION_MOVE:
        { // a pointer was moved
          for (int size = event.getPointerCount(), i = 0; i < size; i++) {
            pointerId = event.getPointerId(i);
            PointF point = mActivePointers.get(pointerId);
            if (point != null) {
              point.x = event.getX(i);
              point.y = event.getY(i);

              if (mRect.contains(point)) {
                normalizePoint(point);
                mListener.move(
                    pointerId, ViewUtils.getCell(mn, point.x), mRangeY.fromRelative(point.y));
              } else {
                mActivePointers.remove(pointerId);
                mListener.off(pointerId);
              }
            }
          }
          break;
        }
      case MotionEvent.ACTION_UP:
      case MotionEvent.ACTION_POINTER_UP:
      case MotionEvent.ACTION_CANCEL:
        {
          PointF f = new PointF();
          f.x = event.getX(pointerIndex);
          f.y = event.getY(pointerIndex);

          if (mRect.contains(f)) {
            mActivePointers.remove(pointerId);
            mListener.off(pointerId);
          }
          break;
        }
    }

    invalidate();
    return true;
  }
  private boolean update(Context context, ActivityManager am) {
    final PackageManager pm = context.getPackageManager();

    mSequence++;

    boolean changed = false;

    List<ActivityManager.RunningServiceInfo> services = am.getRunningServices(MAX_SERVICES);
    final int NS = services != null ? services.size() : 0;
    for (int i = 0; i < NS; i++) {
      ActivityManager.RunningServiceInfo si = services.get(i);
      // We are not interested in services that have not been started
      // and don't have a known client, because
      // there is nothing the user can do about them.
      if (!si.started && si.clientLabel == 0) {
        continue;
      }
      // We likewise don't care about services running in a
      // persistent process like the system or phone.
      if ((si.flags & ActivityManager.RunningServiceInfo.FLAG_PERSISTENT_PROCESS) != 0) {
        continue;
      }

      HashMap<String, ProcessItem> procs = mServiceProcessesByName.get(si.uid);
      if (procs == null) {
        procs = new HashMap<String, ProcessItem>();
        mServiceProcessesByName.put(si.uid, procs);
      }
      ProcessItem proc = procs.get(si.process);
      if (proc == null) {
        changed = true;
        proc = new ProcessItem(context, si.uid, si.process);
        procs.put(si.process, proc);
      }

      if (proc.mCurSeq != mSequence) {
        int pid = si.restarting == 0 ? si.pid : 0;
        if (pid != proc.mPid) {
          changed = true;
          if (proc.mPid != pid) {
            if (proc.mPid != 0) {
              mServiceProcessesByPid.remove(proc.mPid);
            }
            if (pid != 0) {
              mServiceProcessesByPid.put(pid, proc);
            }
            proc.mPid = pid;
          }
        }
        proc.mDependentProcesses.clear();
        proc.mCurSeq = mSequence;
      }
      changed |= proc.updateService(context, si);
    }

    // Now update the map of other processes that are running (but
    // don't have services actively running inside them).
    List<ActivityManager.RunningAppProcessInfo> processes = am.getRunningAppProcesses();
    final int NP = processes != null ? processes.size() : 0;
    for (int i = 0; i < NP; i++) {
      ActivityManager.RunningAppProcessInfo pi = processes.get(i);
      ProcessItem proc = mServiceProcessesByPid.get(pi.pid);
      if (proc == null) {
        // This process is not one that is a direct container
        // of a service, so look for it in the secondary
        // running list.
        proc = mRunningProcesses.get(pi.pid);
        if (proc == null) {
          changed = true;
          proc = new ProcessItem(context, pi.uid, pi.processName);
          proc.mPid = pi.pid;
          mRunningProcesses.put(pi.pid, proc);
        }
        proc.mDependentProcesses.clear();
      }

      if (isInterestingProcess(pi)) {
        if (!mInterestingProcesses.contains(proc)) {
          changed = true;
          mInterestingProcesses.add(proc);
        }
        proc.mCurSeq = mSequence;
        proc.ensureLabel(pm);
      }

      proc.mRunningSeq = mSequence;
      proc.mRunningProcessInfo = pi;
    }

    // Build the chains from client processes to the process they are
    // dependent on; also remove any old running processes.
    int NRP = mRunningProcesses.size();
    for (int i = 0; i < NRP; i++) {
      ProcessItem proc = mRunningProcesses.valueAt(i);
      if (proc.mRunningSeq == mSequence) {
        int clientPid = proc.mRunningProcessInfo.importanceReasonPid;
        if (clientPid != 0) {
          ProcessItem client = mServiceProcessesByPid.get(clientPid);
          if (client == null) {
            client = mRunningProcesses.get(clientPid);
          }
          if (client != null) {
            client.mDependentProcesses.put(proc.mPid, proc);
          }
        } else {
          // In this pass the process doesn't have a client.
          // Clear to make sure that, if it later gets the same one,
          // we will detect the change.
          proc.mClient = null;
        }
      } else {
        changed = true;
        mRunningProcesses.remove(mRunningProcesses.keyAt(i));
      }
    }

    // Remove any old interesting processes.
    int NHP = mInterestingProcesses.size();
    for (int i = 0; i < NHP; i++) {
      ProcessItem proc = mInterestingProcesses.get(i);
      if (mRunningProcesses.get(proc.mPid) == null) {
        changed = true;
        mInterestingProcesses.remove(i);
        i--;
        NHP--;
      }
    }

    // Follow the tree from all primary service processes to all
    // processes they are dependent on, marking these processes as
    // still being active and determining if anything has changed.
    final int NAP = mServiceProcessesByPid.size();
    for (int i = 0; i < NAP; i++) {
      ProcessItem proc = mServiceProcessesByPid.valueAt(i);
      if (proc.mCurSeq == mSequence) {
        changed |= proc.buildDependencyChain(context, pm, mSequence);
      }
    }

    // Look for services and their primary processes that no longer exist...
    ArrayList<Integer> uidToDelete = null;
    for (int i = 0; i < mServiceProcessesByName.size(); i++) {
      HashMap<String, ProcessItem> procs = mServiceProcessesByName.valueAt(i);
      Iterator<ProcessItem> pit = procs.values().iterator();
      while (pit.hasNext()) {
        ProcessItem pi = pit.next();
        if (pi.mCurSeq == mSequence) {
          pi.ensureLabel(pm);
          if (pi.mPid == 0) {
            // Sanity: a non-process can't be dependent on
            // anything.
            pi.mDependentProcesses.clear();
          }
        } else {
          changed = true;
          pit.remove();
          if (procs.size() == 0) {
            if (uidToDelete == null) {
              uidToDelete = new ArrayList<Integer>();
            }
            uidToDelete.add(mServiceProcessesByName.keyAt(i));
          }
          if (pi.mPid != 0) {
            mServiceProcessesByPid.remove(pi.mPid);
          }
          continue;
        }
        Iterator<ServiceItem> sit = pi.mServices.values().iterator();
        while (sit.hasNext()) {
          ServiceItem si = sit.next();
          if (si.mCurSeq != mSequence) {
            changed = true;
            sit.remove();
          }
        }
      }
    }

    if (uidToDelete != null) {
      for (int i = 0; i < uidToDelete.size(); i++) {
        int uid = uidToDelete.get(i);
        mServiceProcessesByName.remove(uid);
      }
    }

    if (changed) {
      // First determine an order for the services.
      ArrayList<ProcessItem> sortedProcesses = new ArrayList<ProcessItem>();
      for (int i = 0; i < mServiceProcessesByName.size(); i++) {
        for (ProcessItem pi : mServiceProcessesByName.valueAt(i).values()) {
          pi.mIsSystem = false;
          pi.mIsStarted = true;
          pi.mActiveSince = Long.MAX_VALUE;
          for (ServiceItem si : pi.mServices.values()) {
            if (si.mServiceInfo != null
                && (si.mServiceInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
              pi.mIsSystem = true;
            }
            if (si.mRunningService != null && si.mRunningService.clientLabel != 0) {
              pi.mIsStarted = false;
              if (pi.mActiveSince > si.mRunningService.activeSince) {
                pi.mActiveSince = si.mRunningService.activeSince;
              }
            }
          }
          sortedProcesses.add(pi);
        }
      }

      Collections.sort(sortedProcesses, mServiceProcessComparator);

      ArrayList<BaseItem> newItems = new ArrayList<BaseItem>();
      ArrayList<MergedItem> newMergedItems = new ArrayList<MergedItem>();
      mProcessItems.clear();
      for (int i = 0; i < sortedProcesses.size(); i++) {
        ProcessItem pi = sortedProcesses.get(i);
        pi.mNeedDivider = false;

        int firstProc = mProcessItems.size();
        // First add processes we are dependent on.
        pi.addDependentProcesses(newItems, mProcessItems);
        // And add the process itself.
        newItems.add(pi);
        if (pi.mPid > 0) {
          mProcessItems.add(pi);
        }

        // Now add the services running in it.
        MergedItem mergedItem = null;
        boolean haveAllMerged = false;
        boolean needDivider = false;
        for (ServiceItem si : pi.mServices.values()) {
          si.mNeedDivider = needDivider;
          needDivider = true;
          newItems.add(si);
          if (si.mMergedItem != null) {
            if (mergedItem != null && mergedItem != si.mMergedItem) {
              haveAllMerged = false;
            }
            mergedItem = si.mMergedItem;
          } else {
            haveAllMerged = false;
          }
        }

        if (!haveAllMerged
            || mergedItem == null
            || mergedItem.mServices.size() != pi.mServices.size()) {
          // Whoops, we need to build a new MergedItem!
          mergedItem = new MergedItem();
          for (ServiceItem si : pi.mServices.values()) {
            mergedItem.mServices.add(si);
            si.mMergedItem = mergedItem;
          }
          mergedItem.mProcess = pi;
          mergedItem.mOtherProcesses.clear();
          for (int mpi = firstProc; mpi < (mProcessItems.size() - 1); mpi++) {
            mergedItem.mOtherProcesses.add(mProcessItems.get(mpi));
          }
        }

        mergedItem.update(context, false);
        newMergedItems.add(mergedItem);
      }

      // Finally, interesting processes need to be shown and will
      // go at the top.
      NHP = mInterestingProcesses.size();
      for (int i = 0; i < NHP; i++) {
        ProcessItem proc = mInterestingProcesses.get(i);
        if (proc.mClient == null && proc.mServices.size() <= 0) {
          if (proc.mMergedItem == null) {
            proc.mMergedItem = new MergedItem();
            proc.mMergedItem.mProcess = proc;
          }
          proc.mMergedItem.update(context, false);
          newMergedItems.add(0, proc.mMergedItem);
          mProcessItems.add(proc);
        }
      }

      synchronized (mLock) {
        mItems = newItems;
        mMergedItems = newMergedItems;
      }
    }

    // Count number of interesting other (non-active) processes, and
    // build a list of all processes we will retrieve memory for.
    mAllProcessItems.clear();
    mAllProcessItems.addAll(mProcessItems);
    int numBackgroundProcesses = 0;
    int numForegroundProcesses = 0;
    int numServiceProcesses = 0;
    NRP = mRunningProcesses.size();
    for (int i = 0; i < NRP; i++) {
      ProcessItem proc = mRunningProcesses.valueAt(i);
      if (proc.mCurSeq != mSequence) {
        // We didn't hit this process as a dependency on one
        // of our active ones, so add it up if needed.
        if (proc.mRunningProcessInfo.importance
            >= ActivityManager.RunningAppProcessInfo.IMPORTANCE_BACKGROUND) {
          numBackgroundProcesses++;
          mAllProcessItems.add(proc);
        } else if (proc.mRunningProcessInfo.importance
            <= ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE) {
          numForegroundProcesses++;
          mAllProcessItems.add(proc);
        } else {
          Log.i(
              "RunningState",
              "Unknown non-service process: " + proc.mProcessName + " #" + proc.mPid);
        }
      } else {
        numServiceProcesses++;
      }
    }

    long backgroundProcessMemory = 0;
    long foregroundProcessMemory = 0;
    long serviceProcessMemory = 0;
    ArrayList<MergedItem> newBackgroundItems = null;
    try {
      final int numProc = mAllProcessItems.size();
      int[] pids = new int[numProc];
      for (int i = 0; i < numProc; i++) {
        pids[i] = mAllProcessItems.get(i).mPid;
      }
      Debug.MemoryInfo[] mem = ActivityManagerNative.getDefault().getProcessMemoryInfo(pids);
      int bgIndex = 0;
      for (int i = 0; i < pids.length; i++) {
        ProcessItem proc = mAllProcessItems.get(i);
        changed |= proc.updateSize(context, mem[i], mSequence);
        if (proc.mCurSeq == mSequence) {
          serviceProcessMemory += proc.mSize;
        } else if (proc.mRunningProcessInfo.importance
            >= ActivityManager.RunningAppProcessInfo.IMPORTANCE_BACKGROUND) {
          backgroundProcessMemory += proc.mSize;
          MergedItem mergedItem;
          if (newBackgroundItems != null) {
            mergedItem = proc.mMergedItem = new MergedItem();
            proc.mMergedItem.mProcess = proc;
            newBackgroundItems.add(mergedItem);
          } else {
            if (bgIndex >= mBackgroundItems.size()
                || mBackgroundItems.get(bgIndex).mProcess != proc) {
              newBackgroundItems = new ArrayList<MergedItem>(numBackgroundProcesses);
              for (int bgi = 0; bgi < bgIndex; bgi++) {
                newBackgroundItems.add(mBackgroundItems.get(bgi));
              }
              mergedItem = proc.mMergedItem = new MergedItem();
              proc.mMergedItem.mProcess = proc;
              newBackgroundItems.add(mergedItem);
            } else {
              mergedItem = mBackgroundItems.get(bgIndex);
            }
          }
          mergedItem.update(context, true);
          mergedItem.updateSize(context);
          bgIndex++;
        } else if (proc.mRunningProcessInfo.importance
            <= ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE) {
          foregroundProcessMemory += proc.mSize;
        }
      }
    } catch (RemoteException e) {
    }

    if (newBackgroundItems == null) {
      // One or more at the bottom may no longer exit.
      if (mBackgroundItems.size() > numBackgroundProcesses) {
        newBackgroundItems = new ArrayList<MergedItem>(numBackgroundProcesses);
        for (int bgi = 0; bgi < numBackgroundProcesses; bgi++) {
          newBackgroundItems.add(mBackgroundItems.get(bgi));
        }
      }
    }

    for (int i = 0; i < mMergedItems.size(); i++) {
      mMergedItems.get(i).updateSize(context);
    }

    synchronized (mLock) {
      mNumBackgroundProcesses = numBackgroundProcesses;
      mNumForegroundProcesses = numForegroundProcesses;
      mNumServiceProcesses = numServiceProcesses;
      mBackgroundProcessMemory = backgroundProcessMemory;
      mForegroundProcessMemory = foregroundProcessMemory;
      mServiceProcessMemory = serviceProcessMemory;
      if (newBackgroundItems != null) {
        mBackgroundItems = newBackgroundItems;
        if (mWatchingBackgroundItems) {
          changed = true;
        }
      }
      if (!mHaveData) {
        mHaveData = true;
        mLock.notifyAll();
      }
    }

    return changed;
  }
 // Unregister when the item is inactive
 @Override
 public void destroyItem(ViewGroup container, int position, Object object) {
   registeredFragments.remove(position);
   super.destroyItem(container, position, object);
 }