Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit adad8427 authored by zfu's avatar zfu Committed by Steve Kondik
Browse files

Tunning max allowed background services

The serialize running of background services feature
delay some services startup when system bootup, and
lead some abnormal behaivor at the early of system startup.
Tunning will be disabled after system complete bootup.

Change-Id: I834607d9156253bee13848586a8136e24760fdf4
parent f5c26310
Loading
Loading
Loading
Loading
+11 −4
Original line number Diff line number Diff line
@@ -141,6 +141,12 @@ public final class ActiveServices {
        long timeoout;
    }

    int additionBgServiceNum;

    public void onBootCompleted() {
        additionBgServiceNum = 0;
    }

    /**
     * Information about services for a single user.
     */
@@ -207,7 +213,7 @@ public final class ActiveServices {
                }
            }
            while (mDelayedStartList.size() > 0
                    && mStartingBackground.size() < mMaxStartingBackground) {
                    && mStartingBackground.size() < mMaxStartingBackground + additionBgServiceNum) {
                ServiceRecord r = mDelayedStartList.remove(0);
                if (DEBUG_DELAYED_STARTS) Slog.v(TAG, "REM FR DELAY LIST (exec next): " + r);
                if (r.pendingStarts.size() <= 0) {
@@ -233,7 +239,7 @@ public final class ActiveServices {
                Message msg = obtainMessage(MSG_BG_START_TIMEOUT);
                sendMessageAtTime(msg, when);
            }
            if (mStartingBackground.size() < mMaxStartingBackground) {
            if (mStartingBackground.size() < mMaxStartingBackground + additionBgServiceNum) {
                mAm.backgroundServicesFinishedLocked(mUserId);
            }
        }
@@ -246,6 +252,7 @@ public final class ActiveServices {
            maxBg = Integer.parseInt(SystemProperties.get("ro.config.max_starting_bg", "0"));
        } catch(RuntimeException e) {
        }
        additionBgServiceNum = 4;
        mMaxStartingBackground = maxBg > 0 ? maxBg : ActivityManager.isLowRamDeviceStatic() ? 1 : 3;
    }

@@ -258,7 +265,7 @@ public final class ActiveServices {

    boolean hasBackgroundServices(int callingUser) {
        ServiceMap smap = mServiceMap.get(callingUser);
        return smap != null ? smap.mStartingBackground.size() >= mMaxStartingBackground : false;
        return smap != null ? smap.mStartingBackground.size() >= mMaxStartingBackground + additionBgServiceNum : false;
    }

    private ServiceMap getServiceMap(int callingUser) {
@@ -340,7 +347,7 @@ public final class ActiveServices {
                    if (DEBUG_DELAYED_STARTS) Slog.v(TAG, "Continuing to delay: " + r);
                    return r.name;
                }
                if (smap.mStartingBackground.size() >= mMaxStartingBackground) {
                if (smap.mStartingBackground.size() >= mMaxStartingBackground + additionBgServiceNum) {
                    // Something else is starting, delay!
                    Slog.i(TAG, "Delaying start of: " + r);
                    smap.mDelayedStartList.add(r);
+10 −0
Original line number Diff line number Diff line
@@ -9459,6 +9459,16 @@ public final class ActivityManagerService extends ActivityManagerNative
        EventLog.writeEvent(EventLogTags.BOOT_PROGRESS_AMS_READY,
            SystemClock.uptimeMillis());
        // Register system boot completed event, set max serial background services num threshold to normal
        IntentFilter filter = new IntentFilter();
        filter.addAction(Intent.ACTION_BOOT_COMPLETED);
        mContext.registerReceiver(new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                mServices.onBootCompleted();
            }
        }, filter);
        synchronized(this) {
            // Make sure we have no pre-ready processes sitting around.