Skip to content

Commit

Permalink
[tinker] Add getTheme() intercept method.
Browse files Browse the repository at this point in the history
  • Loading branch information
tys282000 committed Jul 17, 2024
1 parent 4ae8854 commit 70eb167
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import android.content.res.AssetManager;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.content.res.Resources.Theme;

import com.tencent.tinker.anno.Keep;

/**
Expand Down Expand Up @@ -126,6 +128,9 @@ public Context getBaseContext(Context base) {
return base;
}

@Keep
public Theme getTheme(Theme theme) { return theme; }

@Keep
public int mzNightModeUseOf() {
// Return 1 for default according to MeiZu's announcement.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import android.content.res.AssetManager;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.content.res.Resources.Theme;
import android.os.Handler;
import android.os.Message;
import com.tencent.tinker.anno.Keep;
Expand All @@ -29,6 +30,7 @@
import static com.tencent.tinker.loader.app.TinkerInlineFenceAction.ACTION_GET_CLASSLOADER;
import static com.tencent.tinker.loader.app.TinkerInlineFenceAction.ACTION_GET_RESOURCES;
import static com.tencent.tinker.loader.app.TinkerInlineFenceAction.ACTION_GET_SYSTEM_SERVICE;
import static com.tencent.tinker.loader.app.TinkerInlineFenceAction.ACTION_GET_THEME;
import static com.tencent.tinker.loader.app.TinkerInlineFenceAction.ACTION_MZ_NIGHTMODE_USE_OF;
import static com.tencent.tinker.loader.app.TinkerInlineFenceAction.ACTION_ON_BASE_CONTEXT_ATTACHED;
import static com.tencent.tinker.loader.app.TinkerInlineFenceAction.ACTION_ON_CONFIGURATION_CHANGED;
Expand Down Expand Up @@ -104,15 +106,19 @@ private void handleMessageImpl(Message msg) {
msg.obj = mAppLike.getAssets((AssetManager) msg.obj);
break;
}
case ACTION_GET_RESOURCES : {
case ACTION_GET_RESOURCES: {
msg.obj = mAppLike.getResources((Resources) msg.obj);
break;
}
case ACTION_GET_SYSTEM_SERVICE : {
case ACTION_GET_SYSTEM_SERVICE: {
final Object[] params = (Object[]) msg.obj;
msg.obj = mAppLike.getSystemService((String) params[0], params[1]);
break;
}
case ACTION_GET_THEME: {
msg.obj = mAppLike.getTheme((Theme) msg.obj);
break;
}
case ACTION_MZ_NIGHTMODE_USE_OF: {
msg.obj = mAppLike.mzNightModeUseOf();
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import android.content.res.AssetManager;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.content.res.Resources.Theme;

import com.tencent.tinker.anno.Keep;

Expand Down Expand Up @@ -127,6 +128,9 @@ public Context getBaseContext(Context base) {
return base;
}

@Keep
public Theme getTheme(Theme theme) { return theme; }

@Keep
public int mzNightModeUseOf() {
// Return 1 for default according to MeiZu's announcement.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import android.content.res.AssetManager;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.content.res.Resources.Theme;
import android.os.SystemClock;

import com.tencent.tinker.anno.Keep;
Expand Down Expand Up @@ -217,6 +218,15 @@ public Context getBaseContext() {
}
}

@Override
public Theme getTheme() {
final Theme theme = super.getTheme();
if (mAppLike != null) {
return mAppLike.getTheme(theme);
}
return theme;
}

@Keep
public int mzNightModeUseOf() {
if (mAppLike != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import android.content.res.AssetManager;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.content.res.Resources.Theme;
import android.os.Handler;
import android.os.SystemClock;

Expand Down Expand Up @@ -277,6 +278,15 @@ public Context getBaseContext() {
return TinkerInlineFenceAction.callGetBaseContext(mInlineFence, base);
}

@Override
public Theme getTheme() {
final Theme theme = super.getTheme();
if (mInlineFence == null) {
return theme;
}
return TinkerInlineFenceAction.callGetTheme(mInlineFence, theme);
}

@Keep
public int mzNightModeUseOf() {
if (mInlineFence == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import android.content.res.AssetManager;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.content.res.Resources.Theme;
import android.os.Handler;
import android.os.Message;

Expand All @@ -39,6 +40,7 @@ public final class TinkerInlineFenceAction {
public static final int ACTION_GET_RESOURCES = 10;
public static final int ACTION_GET_SYSTEM_SERVICE = 11;
public static final int ACTION_MZ_NIGHTMODE_USE_OF = 12;
public static final int ACTION_GET_THEME = 13;

static void callOnBaseContextAttached(Handler inlineFence, Context context) {
Message msg = null;
Expand Down Expand Up @@ -155,6 +157,17 @@ static Object callGetSystemService(Handler inlineFence, String name, Object serv
}
}

static Theme callGetTheme(Handler inlineFence, Theme theme) {
Message msg = null;
try {
msg = Message.obtain(inlineFence, ACTION_GET_THEME, theme);
inlineFence.handleMessage(msg);
return (Theme) msg.obj;
} finally {
msg.recycle();
}
}

static int callMZNightModeUseOf(Handler inlineFence) {
Message msg = null;
try {
Expand Down

0 comments on commit 70eb167

Please sign in to comment.