3

I'm hooking into SystemUI Quick Toggles Background, and changed it according to selected color, i'm trying to change it to a static color first, not changeable one .

The problem is, when doing this code, sometimes it works, sometimes it won't work, checking the log, it's saying the same i typed .

When i lock the phone, it reverts back to original color .

As you can, it's a view, i have dex2jar the SystemUI, and added it as a library to my APK Project, and implemented the class and modified it .

What's the problem in it ?

import android.graphics.drawable.Drawable;
import android.graphics.drawable.GradientDrawable;
import android.graphics.drawable.InsetDrawable;
import android.util.Log;



import com.android.systemui.qs.QSContainer;

import de.robv.android.xposed.XC_MethodHook;
import de.robv.android.xposed.XposedBridge;
import de.robv.android.xposed.XposedHelpers;


public class Test2 {

private static QSContainer mQSContainer;
static final int mSystemUIPrimaryColor = ColorsUtils.primary;

public static void hook()
{
    try
    {
        XposedHelpers.findAndHookMethod(QSContainer.class, "onFinishInflate", new XC_MethodHook()
        {
            @Override
            protected void afterHookedMethod(MethodHookParam HookParm)
                    throws Throwable {
                mQSContainer = (QSContainer) HookParm.thisObject;
                Log.i(Test1.TAG,"First Hook, Test2");
                SetUpBackground();
            }
        });
    }
    catch (Exception e)
    {
        XposedBridge.log(e);
    }
}


public static void SetUpBackground()
{
    Log.i(Test1.TAG, "SetUpBackground, Test2");
    GradientDrawable localGradientDrawable = new GradientDrawable();
    localGradientDrawable.setCornerRadius(2.0F);
    localGradientDrawable.setColor(mSystemUIPrimaryColor);
    Drawable localObject = new InsetDrawable(localGradientDrawable, 0, -2, 0, 0);
    mQSContainer.setBackground(localObject);

    //mQSContainer.setBackgroundColor(mSystemUIPrimaryColor);

}

}
Andrew Brēza
  • 7,705
  • 3
  • 34
  • 40
Jaeger
  • 1,646
  • 8
  • 27
  • 59

2 Answers2

0

My guess is that onFinishInflate is called only once and thus with subsequent redraws, the original will get redrawn. Try to hook the onDraw method of this class and inject the same modification there.

Kariem
  • 750
  • 5
  • 13
  • I'm gonna check it out and feedback. – Jaeger Apr 03 '16 at 12:21
  • After searching in the related classes, There is no "onDraw" method, check the class here : https://android.googlesource.com/platform/frameworks/base/+/master/packages/SystemUI/src/com/android/systemui/qs/QSContainer.java – Jaeger Apr 04 '16 at 11:41
  • It extends FrameLayout (https://android.googlesource.com/platform/frameworks/base/+/master/core/java/android/widget/FrameLayout.java?autodive=0%2F%2F%2F%2F%2F), which extends ViewGroup(https://android.googlesource.com/platform/frameworks/base/+/master/core/java/android/view/ViewGroup.java?autodive=0%2F%2F%2F%2F%2F), which extends View (https://android.googlesource.com/platform/frameworks/base/+/master/core/java/android/view/View.java?autodive=0%2F%2F%2F%2F%2F), which as an onDraw. You can hook a views on draw and only do your routine if the class of the object is what you want. – Kariem Apr 04 '16 at 12:31
  • The thing is, This code is the same on some ROMs, some devs made it out by adding it to the system itself not by Xposed, using the same code. Also another dev made the same feature of changing SystemUI Quick toggles background, by using the same code, I've saw his code (dex2jar), it's the same as mine, no changes, but his working, mine isn't . – Jaeger Apr 04 '16 at 23:33
0

Try and update background in main thread :

// Get a handler that can be used to post to the main thread
Handler mainHandler = new Handler(context.getMainLooper());

Runnable myRunnable = new Runnable() {
    @Override 
    public void run() {
         SetUpBackground();
    } 
};
mainHandler.post(myRunnable);
atrebbi
  • 553
  • 3
  • 20