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

Commit e4d9a01b authored by Dan Morrill's avatar Dan Morrill
Browse files

Phase 1 of refactoring SystemServer.

SystemServer is currently a monolithic class that brings up key system
services. This change is the first phase of refactoring it to be more
configurable. Specifically, it adds a set of on/off switches used to control
startup of individual services. Future plans include finer grained controls
and a more explicit and consistent startup sequence for these services.

Change-Id: I7299f5ce7d7b74a34eb56dffb788366fbc058532
parent 9bd94043
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package android.os;
import android.os.storage.IMountService;
import android.os.storage.StorageManager;
import android.os.storage.StorageVolume;
import android.os.SystemProperties;
import android.text.TextUtils;
import android.util.Log;

@@ -58,6 +59,10 @@ public class Environment {
    private static volatile StorageVolume sPrimaryVolume;

    private static StorageVolume getPrimaryVolume() {
        if (SystemProperties.getBoolean("config.disable_storage", false)) {
            return null;
        }

        if (sPrimaryVolume == null) {
            synchronized (sLock) {
                if (sPrimaryVolume == null) {
+10 −0
Original line number Diff line number Diff line
@@ -116,6 +116,7 @@ public final class ViewRootImpl implements ViewParent,
     * at 60 Hz. This can be used to measure the potential framerate.
     */
    private static final String PROPERTY_PROFILE_RENDERING = "viewancestor.profile_rendering";
    private static final String PROPERTY_MEDIA_DISABLED = "config.disable_media";
    
    private static final boolean MEASURE_LATENCY = false;
    private static LatencyTimer lt;
@@ -316,6 +317,8 @@ public final class ViewRootImpl implements ViewParent,
    private Choreographer.FrameCallback mRenderProfiler;
    private boolean mRenderProfilingEnabled;

    private boolean mMediaDisabled;

    // Variables to track frames per second, enabled via DEBUG_FPS flag
    private long mFpsStartTime = -1;
    private long mFpsPrevTime = -1;
@@ -4130,6 +4133,10 @@ public final class ViewRootImpl implements ViewParent,
    public void playSoundEffect(int effectId) {
        checkThread();

        if (mMediaDisabled) {
            return;
        }

        try {
            final AudioManager audioManager = getAudioManager();

@@ -4275,6 +4282,9 @@ public final class ViewRootImpl implements ViewParent,
                mProfileRendering = SystemProperties.getBoolean(PROPERTY_PROFILE_RENDERING, false);
                profileRendering(mAttachInfo.mHasWindowFocus);

                // Media (used by sound effects)
                mMediaDisabled = SystemProperties.getBoolean(PROPERTY_MEDIA_DISABLED, false);

                // Hardware rendering
                if (mAttachInfo.mHardwareRenderer != null) {
                    if (mAttachInfo.mHardwareRenderer.loadSystemProperties(mHolder.getSurface())) {
+21 −8
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ import android.graphics.SurfaceTexture;
import android.os.Process;
import android.util.Log;
import android.view.Surface;
import android.os.SystemProperties;



@@ -56,13 +57,14 @@ public class RenderScript {
     * We use a class initializer to allow the native code to cache some
     * field offsets.
     */
    @SuppressWarnings({"FieldCanBeLocal", "UnusedDeclaration"})
    @SuppressWarnings({"FieldCanBeLocal", "UnusedDeclaration"}) // TODO: now used locally; remove?
    static boolean sInitialized;
    native static void _nInit();


    static {
        sInitialized = false;
        if (!SystemProperties.getBoolean("config.disable_renderscript", false)) {
            try {
                System.loadLibrary("rs_jni");
                _nInit();
@@ -72,6 +74,7 @@ public class RenderScript {
                throw new RSRuntimeException("Error loading RS jni library: " + e);
            }
        }
    }

    // Non-threadsafe functions.
    native int  nDeviceCreate();
@@ -97,6 +100,11 @@ public class RenderScript {
     * @param cacheDir A directory the current process can write to
     */
    public static void setupDiskCache(File cacheDir) {
        if (!sInitialized) {
            Log.e(LOG_TAG, "RenderScript.setupDiskCache() called when disabled");
            return;
        }

        File f = new File(cacheDir, CACHE_PATH);
        mCachePath = f.getAbsolutePath();
        f.mkdirs();
@@ -1036,6 +1044,11 @@ public class RenderScript {
     * @return RenderScript
     */
    public static RenderScript create(Context ctx, int sdkVersion, ContextType ct) {
        if (!sInitialized) {
            Log.e(LOG_TAG, "RenderScript.create() called when disabled; someone is likely to crash");
            return null;
        }

        RenderScript rs = new RenderScript(ctx);

        rs.mDev = rs.nDeviceCreate();
+11 −5
Original line number Diff line number Diff line
@@ -51,17 +51,23 @@ ifeq ($(USE_OPENGL_RENDERER),true)
		external/skia/include/images \
		external/skia/src/core \
		external/skia/src/ports \
		external/skia/include/utils \
		$(intermediates) \
		frameworks/rs/cpp \
		frameworks/rs
		external/skia/include/utils

	LOCAL_CFLAGS += -DUSE_OPENGL_RENDERER -DGL_GLEXT_PROTOTYPES
	LOCAL_MODULE_CLASS := SHARED_LIBRARIES
	LOCAL_SHARED_LIBRARIES := libcutils libutils libGLESv2 libskia libui libRS libRScpp
	LOCAL_SHARED_LIBRARIES := libcutils libutils libGLESv2 libskia libui
	LOCAL_MODULE := libhwui
	LOCAL_MODULE_TAGS := optional

        ifneq (false,$(ANDROID_ENABLE_RENDERSCRIPT))
            LOCAL_CFLAGS += -DANDROID_ENABLE_RENDERSCRIPT
            LOCAL_SHARED_LIBRARIES += libRS libRScpp
            LOCAL_C_INCLUDES += \
		$(intermediates) \
		frameworks/rs/cpp \
		frameworks/rs
        endif

	ifndef HWUI_COMPILE_SYMBOLS
		LOCAL_CFLAGS += -fvisibility=hidden
	endif
+39 −29
Original line number Diff line number Diff line
@@ -24,7 +24,9 @@
#include <utils/Functor.h>
#include <utils/Log.h>

#ifdef ANDROID_ENABLE_RENDERSCRIPT
#include <RenderScript.h>
#endif

#include "utils/Blur.h"
#include "utils/Timing.h"
@@ -532,13 +534,18 @@ FontRenderer::DropShadow FontRenderer::renderDropShadow(SkPaint* paint, const ch
    uint32_t paddedWidth = (uint32_t) (bounds.right - bounds.left) + 2 * radius;
    uint32_t paddedHeight = (uint32_t) (bounds.top - bounds.bottom) + 2 * radius;

#ifdef ANDROID_ENABLE_RENDERSCRIPT
    // Align buffers for renderscript usage
    if (paddedWidth & (RS_CPU_ALLOCATION_ALIGNMENT - 1)) {
        paddedWidth += RS_CPU_ALLOCATION_ALIGNMENT - paddedWidth % RS_CPU_ALLOCATION_ALIGNMENT;
    }

    int size = paddedWidth * paddedHeight;
    uint8_t* dataBuffer = (uint8_t*) memalign(RS_CPU_ALLOCATION_ALIGNMENT, size);
#else
    int size = paddedWidth * paddedHeight;
    uint8_t* dataBuffer = (uint8_t*) malloc(size);
#endif

    memset(dataBuffer, 0, size);

    int penX = radius - bounds.left;
@@ -624,19 +631,8 @@ void FontRenderer::removeFont(const Font* font) {
}

void FontRenderer::blurImage(uint8_t** image, int32_t width, int32_t height, int32_t radius) {
    if (width * height * radius < RS_MIN_INPUT_CUTOFF) {
        float *gaussian = new float[2 * radius + 1];
        Blur::generateGaussianWeights(gaussian, radius);

        uint8_t* scratch = new uint8_t[width * height];
        Blur::horizontal(gaussian, radius, *image, scratch, width, height);
        Blur::vertical(gaussian, radius, scratch, *image, width, height);

        delete[] gaussian;
        delete[] scratch;
        return;
    }

#ifdef ANDROID_ENABLE_RENDERSCRIPT
    if (width * height * radius >= RS_MIN_INPUT_CUTOFF) {
        uint8_t* outImage = (uint8_t*) memalign(RS_CPU_ALLOCATION_ALIGNMENT, width * height);

        if (mRs.get() == 0) {
@@ -661,6 +657,20 @@ void FontRenderer::blurImage(uint8_t** image, int32_t width, int32_t height, int
        // replace the original image's pointer, avoiding a copy back to the original buffer
        free(*image);
        *image = outImage;

        return;
    }
#endif

    float *gaussian = new float[2 * radius + 1];
    Blur::generateGaussianWeights(gaussian, radius);

    uint8_t* scratch = new uint8_t[width * height];
    Blur::horizontal(gaussian, radius, *image, scratch, width, height);
    Blur::vertical(gaussian, radius, scratch, *image, width, height);

    delete[] gaussian;
    delete[] scratch;
}

}; // namespace uirenderer
Loading