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

Commit 673a5898 authored by zfu's avatar zfu Committed by Gerrit - the friendly Code Review server
Browse files

Tunning max allowed boot starting bg services

The serialize running of background services feature
delay some services startup when system bootup.
This feature lead some abnormal behavior at the early of
system startup, some requests can't be responsed in time.
Tunning will be disabled after system complete bootup.

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

    int mAdditionalBootStartingBackground;

    public void onBootCompleted() {
        mAdditionalBootStartingBackground = 0;
    }

    /**
     * Information about services for a single user.
     */
@@ -206,7 +212,7 @@ public final class ActiveServices {
                }
            }
            while (mDelayedStartList.size() > 0
                    && mStartingBackground.size() < mMaxStartingBackground) {
                    && mStartingBackground.size() < mMaxStartingBackground + mAdditionalBootStartingBackground) {
                ServiceRecord r = mDelayedStartList.remove(0);
                if (DEBUG_DELAYED_STATS) Slog.v(TAG, "REM FR DELAY LIST (exec next): " + r);
                if (r.pendingStarts.size() <= 0) {
@@ -232,7 +238,7 @@ public final class ActiveServices {
                Message msg = obtainMessage(MSG_BG_START_TIMEOUT);
                sendMessageAtTime(msg, when);
            }
            if (mStartingBackground.size() < mMaxStartingBackground) {
            if (mStartingBackground.size() < mMaxStartingBackground + mAdditionalBootStartingBackground) {
                mAm.backgroundServicesFinishedLocked(mUserId);
            }
        }
@@ -245,6 +251,10 @@ public final class ActiveServices {
            maxBg = Integer.parseInt(SystemProperties.get("ro.config.max_starting_bg", "0"));
        } catch(RuntimeException e) {
        }
        try {
            mAdditionalBootStartingBackground = Integer.parseInt(SystemProperties.get("persist.added_boot_bgservices", "0"));
        } catch(RuntimeException e) {
        }
        mMaxStartingBackground = maxBg > 0 ? maxBg : ActivityManager.isLowRamDeviceStatic() ? 1 : 3;
    }

@@ -257,7 +267,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 + mAdditionalBootStartingBackground : false;
    }

    private ServiceMap getServiceMap(int callingUser) {
@@ -339,7 +349,7 @@ public final class ActiveServices {
                    if (DEBUG_DELAYED_STATS) Slog.v(TAG, "Continuing to delay: " + r);
                    return r.name;
                }
                if (smap.mStartingBackground.size() >= mMaxStartingBackground) {
                if (smap.mStartingBackground.size() >= mMaxStartingBackground + mAdditionalBootStartingBackground) {
                    // 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
@@ -9346,6 +9346,16 @@ public final class ActivityManagerService extends ActivityManagerNative
        IntentFilter bootFilter = new IntentFilter(AppInterface.CHECK_SCREEN_IDLE_ACTION);
        mContext.registerReceiver(new ScreenStatusReceiver(), bootFilter);
        // 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.