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

Commit 0c3a49a5 authored by Shashi Shekar Shankar's avatar Shashi Shekar Shankar Committed by Linux Build Service Account
Browse files

BoostFramework to enchance 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

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


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


@@ -2759,6 +2764,35 @@ public class Activity extends ContextThemeWrapper
     * @return boolean Return true if this event was consumed.
     * @return boolean Return true if this event was consumed.
     */
     */
    public boolean dispatchTouchEvent(MotionEvent ev) {
    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) {
        if (ev.getAction() == MotionEvent.ACTION_DOWN) {
            onUserInteraction();
            onUserInteraction();
        }
        }
+148 −0
Original line number Original line 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;
    }

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


/**
/**
 * This class encapsulates scrolling with the ability to overshoot the bounds
 * This class encapsulates scrolling with the ability to overshoot the bounds
@@ -599,6 +600,17 @@ public class OverScroller {
        private static final int CUBIC = 1;
        private static final int CUBIC = 1;
        private static final int BALLISTIC = 2;
        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 fBoostParamVal[];

        static {
        static {
            float x_min = 0.0f;
            float x_min = 0.0f;
            float y_min = 0.0f;
            float y_min = 0.0f;
@@ -643,6 +655,15 @@ public class OverScroller {
                    * 39.37f // inch/meter
                    * 39.37f // inch/meter
                    * ppi
                    * ppi
                    * 0.84f; // look and feel tuning
                    * 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);
            }
        }
        }


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


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

            mCurrentPosition = mFinal;
            mCurrentPosition = mFinal;
            // Not reset since WebView relies on this value for fast fling.
            // Not reset since WebView relies on this value for fast fling.
            // TODO: restore when WebView uses the fast fling implemented in this class.
            // TODO: restore when WebView uses the fast fling implemented in this class.
@@ -760,6 +786,17 @@ public class OverScroller {
            if (velocity != 0) {
            if (velocity != 0) {
                mDuration = mSplineDuration = getSplineFlingDuration(velocity);
                mDuration = mSplineDuration = getSplineFlingDuration(velocity);
                totalDistance = getSplineFlingDistance(velocity);
                totalDistance = getSplineFlingDistance(velocity);
                if (mPerf == null && mIsPerfBoostEnabled) {
                    mPerf = new BoostFramework();
                }

                if (mPerf != null) {
                    mIsPerfLockAcquired = true;
                    if (0 == fBoostTimeOut) {
                        fBoostTimeOut = mDuration;
                    }
                    mPerf.perfLockAcquire(fBoostTimeOut, fBoostParamVal);
                }
            }
            }


            mSplineDistance = (int) (totalDistance * Math.signum(velocity));
            mSplineDistance = (int) (totalDistance * Math.signum(velocity));
+31 −0
Original line number Original line Diff line number Diff line
@@ -22,6 +22,7 @@ import android.os.Build;
import android.view.ViewConfiguration;
import android.view.ViewConfiguration;
import android.view.animation.AnimationUtils;
import android.view.animation.AnimationUtils;
import android.view.animation.Interpolator;
import android.view.animation.Interpolator;
import android.util.BoostFramework;




/**
/**
@@ -108,6 +109,16 @@ public class Scroller {
    private float mDeceleration;
    private float mDeceleration;
    private final float mPpi;
    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 sBoostParamVal[];

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


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


        mPhysicalCoeff = computeDeceleration(0.84f); // look and feel tuning
        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 +419,13 @@ public class Scroller {
        mDeltaX = dx;
        mDeltaX = dx;
        mDeltaY = dy;
        mDeltaY = dy;
        mDurationReciprocal = 1.0f / (float) mDuration;
        mDurationReciprocal = 1.0f / (float) mDuration;

        if ((mPerf != null) && (duration != 0)) {
            if (0 == sBoostTimeOut) {
                sBoostTimeOut = mDuration;
            }
            mPerf.perfLockAcquire(sBoostTimeOut, sBoostParamVal);
        }
    }
    }


    /**
    /**
+30 −0
Original line number Original line Diff line number Diff line
@@ -2276,4 +2276,34 @@
    <string-array name="config_cell_retries_per_error_code">
    <string-array name="config_cell_retries_per_error_code">
    </string-array>
    </string-array>


    <!-- Whether cpu boost is enabled for AppLaunch -->
    <bool name="config_enableCpuBoostForAppLaunch">false</bool>
    <integer name="disablepacking_timeout_param">0</integer>
    <integer-array name="launchboost_packing_param_value"/>
    <integer name="launchboost_timeout_param">0</integer>
    <integer-array name="launchboost_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"/>

</resources>
</resources>
Loading