@Override
        public int compare(MergedItem lhs, MergedItem rhs) {
            if (DEBUG_COMPARE) {
                Log.i(TAG, "Comparing " + lhs + " with " + rhs);
                Log.i(TAG, "     Proc " + lhs.mProcess + " with " + rhs.mProcess);
                Log.i(TAG, "   UserId " + lhs.mUserId + " with " + rhs.mUserId);
            }
            if (lhs.mUserId != rhs.mUserId) {
                if (lhs.mUserId == mMyUserId) return -1;
                if (rhs.mUserId == mMyUserId) return 1;
                return lhs.mUserId < rhs.mUserId ? -1 : 1;
            }
            if (lhs.mProcess == rhs.mProcess) {
                if (lhs.mLabel == rhs.mLabel) {
                    return 0;
                }
                return lhs.mLabel != null ? lhs.mLabel.compareTo(rhs.mLabel) : -1;
            }
            if (lhs.mProcess == null) return -1;
            if (rhs.mProcess == null) return 1;
            if (DEBUG_COMPARE) Log.i(TAG, "    Label " + lhs.mProcess.mLabel
                    + " with " + rhs.mProcess.mLabel);
            final RunningAppProcessInfoCompat lhsInfo
                    = lhs.mProcess.mRunningProcessInfo;
            final RunningAppProcessInfoCompat rhsInfo
                    = rhs.mProcess.mRunningProcessInfo;
            final boolean lhsBg = lhsInfo.importance
                    >= ActivityManager.RunningAppProcessInfo.IMPORTANCE_BACKGROUND;
            final boolean rhsBg = rhsInfo.importance
                    >= ActivityManager.RunningAppProcessInfo.IMPORTANCE_BACKGROUND;
            if (DEBUG_COMPARE) Log.i(TAG, "       Bg " + lhsBg + " with " + rhsBg);
            if (lhsBg != rhsBg) {
                return lhsBg ? 1 : -1;
            }
            final boolean lhsA = (lhsInfo.flags
                    & ActivityManager.RunningAppProcessInfo.FLAG_HAS_ACTIVITIES) != 0;
            final boolean rhsA = (rhsInfo.flags
                    & ActivityManager.RunningAppProcessInfo.FLAG_HAS_ACTIVITIES) != 0;
            if (DEBUG_COMPARE) Log.i(TAG, "      Act " + lhsA + " with " + rhsA);
            if (lhsA != rhsA) {
                return lhsA ? -1 : 1;
            }
            if (DEBUG_COMPARE) Log.i(TAG, "      Lru " + lhsInfo.lru + " with " + rhsInfo.lru);
            if (lhsInfo.lru != rhsInfo.lru) {
                return lhsInfo.lru < rhsInfo.lru ? -1 : 1;
            }
            if (lhs.mProcess.mLabel == rhs.mProcess.mLabel) {
                return 0;
            }
            if (lhs.mProcess.mLabel == null) return 1;
            if (rhs.mProcess.mLabel == null) return -1;
            return lhs.mProcess.mLabel.compareTo(rhs.mProcess.mLabel);
        }
Singleton for retrieving and monitoring the state about all running
applications/processes/services.
android/android_framework/base/src/main/java/github/tornaco/android/thanos/core/process/RunningState.java