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

Commit f56206d6 authored by Arusha Goyal's avatar Arusha Goyal Committed by Linux Build Service Account
Browse files

BoostFramework to enhance performance during critical scenarios

Adding Boost APIs which can ensure the best possible resource
availability during critical UX scenarios. These APIs can be
either turned off or dynamically hooked to OEM specific
performance optimizations

Squashed with change: I90a733d7134d86efffadf6815ce3d2944dd09419

Performance: Make Cached apps limit configurable.

Set it via a target specific property
file. Allows flexibility to set the limit
based on device config

Normally, setting a smaller value for
low-end device helps with performance.

Conflicts:
	core/res/res/values/symbols.xml

Change-Id: I51a83708d145ab8fd780b10c33d40db1291d6edd
parent 9b0499db
Loading
Loading
Loading
Loading
+34 −0
Original line number Diff line number Diff line
@@ -127,6 +127,7 @@ import java.lang.annotation.RetentionPolicy;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import android.util.BoostFramework;

/**
 * An activity is a single, focused thing that the user can do.  Almost all
@@ -689,6 +690,10 @@ public class Activity extends ContextThemeWrapper
        OnCreateContextMenuListener, ComponentCallbacks2,
        Window.OnWindowDismissedCallback, WindowControllerCallback {
    private static final String TAG = "Activity";
    private static BoostFramework mPerf = null;
    private static int mDragBoostPossible = -1;
    private static int mPerfLockDuration = -1;
    private static int mAsParamVal[];
    private static final boolean DEBUG_LIFECYCLE = false;

    /** Standard activity result: operation canceled. */
@@ -3055,6 +3060,35 @@ public class Activity extends ContextThemeWrapper
     * @return boolean Return true if this event was consumed.
     */
    public boolean dispatchTouchEvent(MotionEvent ev) {
        if(mDragBoostPossible == -1) {
            mDragBoostPossible = 0;
            String currentActivity = getPackageName();
            String[] activityList = getResources().getStringArray(
                com.android.internal.R.array.boost_activityList);
            if(activityList != null){
                for (String match : activityList) {
                    if (currentActivity.indexOf(match) != -1){
                        mDragBoostPossible = 1;
                        break;
                    }
                }
            }
        }
        if (mDragBoostPossible == 1) {
            if (mPerf == null){
                mPerf = new BoostFramework();
            }
            if(mPerfLockDuration == -1){
                mPerfLockDuration = getResources().getInteger(
                    com.android.internal.R.integer.ascrollboost_timeout);
                mAsParamVal = getResources().getIntArray(
                    com.android.internal.R.array.ascrollboost_param_value);
            }
            mPerf.perfLockAcquireTouch(ev,
                getResources().getDisplayMetrics(),
                mPerfLockDuration, mAsParamVal);
        }

        if (ev.getAction() == MotionEvent.ACTION_DOWN) {
            onUserInteraction();
        }
+148 −0
Original line number Diff line number Diff line
/*
 * Copyright (c) 2015, The Linux Foundation. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are
 * met:
 *    * Redistributions of source code must retain the above copyright
 *      notice, this list of conditions and the following disclaimer.
 *    * Redistributions in binary form must reproduce the above
 *      copyright notice, this list of conditions and the following
 *      disclaimer in the documentation and/or other materials provided
 *      with the distribution.
 *    * Neither the name of The Linux Foundation nor the names of its
 *      contributors may be used to endorse or promote products derived
 *      from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

package android.util;

import android.util.Log;
import dalvik.system.PathClassLoader;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.lang.System;
import android.view.MotionEvent;
import android.util.DisplayMetrics;

/** @hide */
public class BoostFramework {

    private static final String TAG = "BoostFramework";
    private static final String PERFORMANCE_JAR = "/system/framework/QPerformance.jar";
    private static final String PERFORMANCE_CLASS = "com.qualcomm.qti.Performance";

/** @hide */
    private static boolean mIsLoaded = false;
    private static Method mAcquireFunc = null;
    private static Method mReleaseFunc = null;
    private static Method mAcquireTouchFunc = null;
    private static Constructor<Class> mConstructor = null;

/** @hide */
    private Object mPerf = null;

/** @hide */
    public BoostFramework() {

        if (mIsLoaded == false) {
            try {
                Class perfClass;
                PathClassLoader perfClassLoader;

	        perfClassLoader = new PathClassLoader(PERFORMANCE_JAR,
                                  ClassLoader.getSystemClassLoader());
                perfClass = perfClassLoader.loadClass(PERFORMANCE_CLASS);
                mConstructor = perfClass.getConstructor();

                Class[] argClasses = new Class[] {int.class, int[].class};
                mAcquireFunc =  perfClass.getDeclaredMethod("perfLockAcquire", argClasses);
                Log.v(TAG,"mAcquireFunc method = " + mAcquireFunc);

                argClasses = new Class[] {};
                mReleaseFunc =  perfClass.getDeclaredMethod("perfLockRelease", argClasses);
                Log.v(TAG,"mReleaseFunc method = " + mReleaseFunc);

                argClasses = new Class[] {MotionEvent.class, DisplayMetrics.class, int.class, int[].class};
                mAcquireTouchFunc =  perfClass.getDeclaredMethod("perfLockAcquireTouch", argClasses);
                Log.v(TAG,"mAcquireTouchFunc method = " + mAcquireTouchFunc);

                mIsLoaded = true;
            }
            catch(Exception e) {
                Log.e(TAG,"BoostFramework() : Exception_1 = " + e);
            }
        }

        try {
            if (mConstructor != null) {
                mPerf = mConstructor.newInstance();
            }
        }
        catch(Exception e) {
            Log.e(TAG,"BoostFramework() : Exception_2 = " + e);
        }

        Log.v(TAG,"BoostFramework() : mPerf = " + mPerf);
    }

/** @hide */
/*    private static void loadNative() {
        if(!isLoaded){
            //System.loadLibrary("perf_jni");
            System.loadLibrary("qti_performance");
            isLoaded=true;
        }
        return;
    }
*/

/** @hide */
    public int perfLockAcquire(int duration, int... list) {
        int ret = -1;
        try {
            Object retVal = mAcquireFunc.invoke(mPerf, duration, list);
            ret = (int)retVal;
        } catch(Exception e) {
            Log.e(TAG,"Exception " + e);
        }
        return ret;
    }

/** @hide */
    public int perfLockRelease() {
        int ret = -1;
        try {
            Object retVal = mReleaseFunc.invoke(mPerf);
            ret = (int)retVal;
        } catch(Exception e) {
            Log.e(TAG,"Exception " + e);
        }
        return ret;
    }
/** @hide */
    public int perfLockAcquireTouch(MotionEvent ev, DisplayMetrics metrics,
                                   int duration, int... list) {
        int ret = -1;
        try {
            Object retVal = mAcquireTouchFunc.invoke(mPerf, ev, metrics, duration, list);
            ret = (int)retVal;
        } catch(Exception e) {
            Log.e(TAG,"Exception " + e);
        }
        return ret;
    }

};
+48 −0
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import android.util.Log;
import android.view.ViewConfiguration;
import android.view.animation.AnimationUtils;
import android.view.animation.Interpolator;
import android.util.BoostFramework;

/**
 * This class encapsulates scrolling with the ability to overshoot the bounds
@@ -599,6 +600,18 @@ public class OverScroller {
        private static final int CUBIC = 1;
        private static final int BALLISTIC = 2;

        /*
         * Perf boost related variables
         * Enabled/Disabled using config_enableCpuBoostForOverScrollerFling
         * true value turns it on, by default will be turned off
         */
        private BoostFramework mPerf = null;
        private boolean mIsPerfLockAcquired = false;
        private boolean mIsPerfBoostEnabled = false;
        private int fBoostTimeOut = 0;
        private int flingBoostTimeOut = 0;
        private int fBoostParamVal[];

        static {
            float x_min = 0.0f;
            float y_min = 0.0f;
@@ -643,6 +656,19 @@ public class OverScroller {
                    * 39.37f // inch/meter
                    * ppi
                    * 0.84f; // look and feel tuning

            mIsPerfBoostEnabled = context.getResources().getBoolean(
                   com.android.internal.R.bool.config_enableCpuBoostForOverScrollerFling);
            if (mIsPerfBoostEnabled) {
            fBoostTimeOut = context.getResources().getInteger(
                   com.android.internal.R.integer.flingboost_timeout_param);
            fBoostParamVal = context.getResources().getIntArray(
                        com.android.internal.R.array.flingboost_param_value);
            }

            if (mPerf == null && mIsPerfBoostEnabled) {
                mPerf = new BoostFramework();
            }
        }

        void updateScroll(float q) {
@@ -690,6 +716,11 @@ public class OverScroller {
        }

        void finish() {
            if (mIsPerfLockAcquired && mPerf != null) {
                mPerf.perfLockRelease();
                mIsPerfLockAcquired = false;
            }

            mCurrentPosition = mFinal;
            // Not reset since WebView relies on this value for fast fling.
            // TODO: restore when WebView uses the fast fling implemented in this class.
@@ -749,6 +780,11 @@ public class OverScroller {
            mStartTime = AnimationUtils.currentAnimationTimeMillis();
            mCurrentPosition = mStart = start;

            if (mIsPerfLockAcquired && mPerf != null) {
                mPerf.perfLockRelease();
                mIsPerfLockAcquired = false;
            }

            if (start > max || start < min) {
                startAfterEdge(start, min, max, velocity);
                return;
@@ -913,6 +949,18 @@ public class OverScroller {
                return false;
            }

            if (mPerf != null && !mIsPerfLockAcquired) {
                mIsPerfLockAcquired = true;
                if (0 == fBoostTimeOut) {
                    //config value is not defined
                    flingBoostTimeOut = mDuration;
                } else {
                    //config value is present
                    flingBoostTimeOut = fBoostTimeOut;
                }
                mPerf.perfLockAcquire(flingBoostTimeOut, fBoostParamVal);
            }

            double distance = 0.0;
            switch (mState) {
                case SPLINE: {
+36 −0
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import android.os.Build;
import android.view.ViewConfiguration;
import android.view.animation.AnimationUtils;
import android.view.animation.Interpolator;
import android.util.BoostFramework;


/**
@@ -108,6 +109,17 @@ public class Scroller {
    private float mDeceleration;
    private final float mPpi;

    /*
    * Perf boost related variables
    * Enabled/Disabled using config_enableCpuBoostForScroller
    * true value turns it on, by default will be turned off
    */
    private BoostFramework mPerf = null;
    boolean bIsPerfBoostEnabled = false;
    private int sBoostTimeOut = 0;
    private int scrollBoostTimeOut = 0;
    private int sBoostParamVal[];

    // A context-specific coefficient adjusted to physical values.
    private float mPhysicalCoeff;

@@ -167,6 +179,7 @@ public class Scroller {
     * not to support progressive "flywheel" behavior in flinging.
     */
    public Scroller(Context context, Interpolator interpolator, boolean flywheel) {
        boolean bIsPerfBoostEnabled = false;
        mFinished = true;
        if (interpolator == null) {
            mInterpolator = new ViscousFluidInterpolator();
@@ -178,6 +191,18 @@ public class Scroller {
        mFlywheel = flywheel;

        mPhysicalCoeff = computeDeceleration(0.84f); // look and feel tuning
        bIsPerfBoostEnabled = context.getResources().getBoolean(
             com.android.internal.R.bool.config_enableCpuBoostForScroller);
        if (bIsPerfBoostEnabled) {
        sBoostTimeOut = context.getResources().getInteger(
               com.android.internal.R.integer.scrollboost_timeout_param);
        sBoostParamVal = context.getResources().getIntArray(
               com.android.internal.R.array.scrollboost_param_value);
        }
        if (mPerf == null && bIsPerfBoostEnabled) {
            mPerf = new BoostFramework();
        }

    }

    /**
@@ -395,6 +420,17 @@ public class Scroller {
        mDeltaX = dx;
        mDeltaY = dy;
        mDurationReciprocal = 1.0f / (float) mDuration;

        if ((mPerf != null) && (duration != 0)) {
            if (0 == sBoostTimeOut) {
                //config value is not defined
                scrollBoostTimeOut = mDuration;
            } else {
                //config value is present
                scrollBoostTimeOut = sBoostTimeOut;
            }
            mPerf.perfLockAcquire(scrollBoostTimeOut, sBoostParamVal);
        }
    }

    /**
+36 −0
Original line number Diff line number Diff line
@@ -2482,6 +2482,42 @@
    <!-- Package of the unbundled tv remote service which can connect to tv
         remote provider -->
    <string name="config_tvRemoteServicePackage" translatable="false"></string>
    <!-- Whether cpu boost is enabled for AppLaunch -->
    <bool name="config_enableCpuBoostForAppLaunch">false</bool>
    <integer name="launchboost_timeout_param">0</integer>
    <integer-array name="launchboost_param_value"/>

    <!-- Whether disablepacking is enabled or not -->
    <bool name="config_disablePacking">false</bool>
    <integer name="disablepacking_timeout_param">0</integer>
    <integer-array name="launchboost_packing_param_value"/>

    <!-- Whether cpu boost is enabled for animation. -->
    <bool name="config_enablePerfBoostForAnimation">false</bool>
    <integer name="animationboost_timeout_param">0</integer>
    <integer-array name="animationboost_param_value"/>

    <!-- Whether cpu boost is enabled for overscroller fling. -->
    <bool name="config_enableCpuBoostForOverScrollerFling">false</bool>
    <integer name="flingboost_timeout_param">0</integer>
    <integer-array name="flingboost_param_value"/>

    <!-- Whether cpu boost is enabled for horizontal scroll. -->
    <bool name="config_enableCpuBoostForScroller">false</bool>
    <integer name="scrollboost_timeout_param">0</integer>
    <integer-array name="scrollboost_param_value"/>

    <!-- Activities list for boost -->
    <string-array translatable="false" name="boost_activityList">
    </string-array>

    <!-- Activity scroll boost params -->
    <integer name="ascrollboost_timeout">0</integer>
    <integer-array name="ascrollboost_param_value"/>

    <!-- cpu boost for PanelView fling -->
    <bool name="config_enableCpuBoostForPanelViewFling">false</bool>
    <integer-array name="panelview_flingboost_param_value" />

    <!-- True if the device supports persisting security logs across reboots.
         This requires the device's kernel to have pstore and pmsg enabled,
Loading