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

Commit bb04422e authored by Danny Baumann's avatar Danny Baumann
Browse files

Apply selected render effect on boot.

Fixes issue #2088.

Change-Id: I61ebd66966a16c3f32e1d874a7fbf0d8be93ac88
parent d42c47e0
Loading
Loading
Loading
Loading
+7 −1
Original line number Diff line number Diff line
@@ -8,6 +8,7 @@
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.HARDWARE_TEST" />
    <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />

    <application android:label="@string/app_name"
        android:icon="@drawable/cm_icon">
@@ -22,6 +23,11 @@
                <action android:name="android.app.NotificationManager.ACTION_NOTIFY" />
            </intent-filter>
        </receiver>
        <receiver android:name=".intents.BootReceiver" android:enabled="true">
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED" />
            </intent-filter>
        </receiver>
        <activity android:name=".activities.MainActivity" android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
+10 −52
Original line number Diff line number Diff line
@@ -17,10 +17,6 @@
package com.cyanogenmod.cmparts.activities;

import android.os.Bundle;
import android.os.IBinder;
import android.os.Parcel;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.preference.CheckBoxPreference;
import android.preference.ListPreference;
import android.preference.Preference;
@@ -31,6 +27,7 @@ import android.preference.PreferenceScreen;
import android.provider.Settings;

import com.cyanogenmod.cmparts.R;
import com.cyanogenmod.cmparts.utils.SurfaceFlingerUtils;

public class UIActivity extends PreferenceActivity implements OnPreferenceChangeListener {

@@ -54,7 +51,7 @@ public class UIActivity extends PreferenceActivity implements OnPreferenceChange
    /* Other */
    private static final String PINCH_REFLOW_PREF = "pref_pinch_reflow";

    private static final String RENDER_EFFECT_PREF = "pref_render_effect";
    public static final String RENDER_EFFECT_PREF = "pref_render_effect";

    private static final String POWER_PROMPT_PREF = "power_dialog_prompt";

@@ -107,7 +104,6 @@ public class UIActivity extends PreferenceActivity implements OnPreferenceChange
        mPowerPromptPref = (CheckBoxPreference) prefSet.findPreference(POWER_PROMPT_PREF);
        mRenderEffectPref = (ListPreference) prefSet.findPreference(RENDER_EFFECT_PREF);
        mRenderEffectPref.setOnPreferenceChangeListener(this);
        updateFlingerOptions();

        /* Share Screenshot */
        mShareScreenshotPref = (CheckBoxPreference) prefSet.findPreference(SHARE_SCREENSHOT_PREF);
@@ -129,6 +125,12 @@ public class UIActivity extends PreferenceActivity implements OnPreferenceChange

    }

    @Override
    protected void onResume() {
        super.onResume();
        mRenderEffectPref.setValue(String.valueOf(SurfaceFlingerUtils.getActiveRenderEffect(this)));
    }

    public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
        boolean value;

@@ -166,7 +168,8 @@ public class UIActivity extends PreferenceActivity implements OnPreferenceChange

    public boolean onPreferenceChange(Preference preference, Object newValue) {
        if (preference == mRenderEffectPref) {
            writeRenderEffect(Integer.valueOf((String) newValue));
            int effectId = Integer.valueOf((String) newValue);
            SurfaceFlingerUtils.setRenderEffect(this, effectId);
            return true;
        } else if (preference == mOverscrollPref) {
            int overscrollEffect = Integer.valueOf((String) newValue);
@@ -182,51 +185,6 @@ public class UIActivity extends PreferenceActivity implements OnPreferenceChange
        return false;
    }

    // Taken from DevelopmentSettings
    private void updateFlingerOptions() {
        // magic communication with surface flinger.
        try {
            IBinder flinger = ServiceManager.getService("SurfaceFlinger");
            if (flinger != null) {
                Parcel data = Parcel.obtain();
                Parcel reply = Parcel.obtain();
                data.writeInterfaceToken("android.ui.ISurfaceComposer");
                flinger.transact(1010, data, reply, 0);
                int v;
                v = reply.readInt();
                // mShowCpuCB.setChecked(v != 0);
                v = reply.readInt();
                // mEnableGLCB.setChecked(v != 0);
                v = reply.readInt();
                // mShowUpdatesCB.setChecked(v != 0);
                v = reply.readInt();
                // mShowBackgroundCB.setChecked(v != 0);

                v = reply.readInt();
                mRenderEffectPref.setValue(String.valueOf(v));

                reply.recycle();
                data.recycle();
            }
        } catch (RemoteException ex) {
        }

    }

    private void writeRenderEffect(int id) {
        try {
            IBinder flinger = ServiceManager.getService("SurfaceFlinger");
            if (flinger != null) {
                Parcel data = Parcel.obtain();
                data.writeInterfaceToken("android.ui.ISurfaceComposer");
                data.writeInt(id);
                flinger.transact(1014, data, null, 0);
                data.recycle();
            }
        } catch (RemoteException ex) {
        }
    }

    ColorPickerDialog.OnColorChangedListener mWidgetColorListener = new ColorPickerDialog.OnColorChangedListener() {
        public void colorChanged(int color) {
            Settings.System.putInt(getContentResolver(),
+39 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2011 The CyanogenMod Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.cyanogenmod.cmparts.intents;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.text.TextUtils;

import com.cyanogenmod.cmparts.activities.UIActivity;
import com.cyanogenmod.cmparts.utils.SurfaceFlingerUtils;

public class BootReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
        String renderEffect = prefs.getString(UIActivity.RENDER_EFFECT_PREF, null);

        if (renderEffect != null && !TextUtils.equals(renderEffect, "0")) {
            SurfaceFlingerUtils.setRenderEffect(context, Integer.valueOf(renderEffect));
        }
    }
}
+78 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2012 The CyanogenMod Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.cyanogenmod.cmparts.utils;

import android.content.Context;
import android.os.IBinder;
import android.os.Parcel;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.util.Log;

public class SurfaceFlingerUtils {
    private static final String TAG = "SurfaceFlingerUtils";

    private SurfaceFlingerUtils() {
    }

    public static int getActiveRenderEffect(Context context) {
        int effectId = 0;

        // Taken from DevelopmentSettings
        // magic communication with surface flinger.
        try {
            IBinder flinger = ServiceManager.getService("SurfaceFlinger");
            if (flinger != null) {
                Parcel data = Parcel.obtain();
                Parcel reply = Parcel.obtain();
                data.writeInterfaceToken("android.ui.ISurfaceComposer");
                flinger.transact(1010, data, reply, 0);
                // boolean: show CPU load
                reply.readInt();
                // boolean: enable GL ES
                reply.readInt();
                // boolean: show updates
                reply.readInt();
                // boolean: show background
                reply.readInt();
                // int: render effect id
                effectId = reply.readInt();
                reply.recycle();
                data.recycle();
            }
        } catch (RemoteException e) {
            Log.e(TAG, "Could not get active render effect", e);
        }

        return effectId;
    }

    public static void setRenderEffect(Context context, int effectId) {
        try {
            IBinder flinger = ServiceManager.getService("SurfaceFlinger");
            if (flinger != null) {
                Parcel data = Parcel.obtain();
                data.writeInterfaceToken("android.ui.ISurfaceComposer");
                data.writeInt(effectId);
                flinger.transact(1014, data, null, 0);
                data.recycle();
            }
        } catch (RemoteException e) {
            Log.e(TAG, "Setting render effect failed", e);
        }
    }
}