aboutsummaryrefslogtreecommitdiff
path: root/bridge/src/com/android/layoutlib/bridge/android/BridgeContext.java
diff options
context:
space:
mode:
Diffstat (limited to 'bridge/src/com/android/layoutlib/bridge/android/BridgeContext.java')
-rw-r--r--bridge/src/com/android/layoutlib/bridge/android/BridgeContext.java51
1 files changed, 43 insertions, 8 deletions
diff --git a/bridge/src/com/android/layoutlib/bridge/android/BridgeContext.java b/bridge/src/com/android/layoutlib/bridge/android/BridgeContext.java
index 1d42d0a316..a0cf2b23b2 100644
--- a/bridge/src/com/android/layoutlib/bridge/android/BridgeContext.java
+++ b/bridge/src/com/android/layoutlib/bridge/android/BridgeContext.java
@@ -72,6 +72,7 @@ import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
import android.hardware.display.DisplayManager;
+import android.hardware.input.InputManager;
import android.media.AudioManager;
import android.net.ConnectivityManager;
import android.net.Uri;
@@ -118,7 +119,6 @@ import java.util.Map;
import java.util.concurrent.Executor;
import static android.os._Original_Build.VERSION_CODES.JELLY_BEAN_MR1;
-import static com.android.layoutlib.bridge.android.RenderParamsFlags.FLAG_KEY_APPLICATION_PACKAGE;
/**
* Custom implementation of Context/Activity to handle non compiled resources.
@@ -128,6 +128,8 @@ public class BridgeContext extends Context {
private static final Map<String, ResourceValue> FRAMEWORK_PATCHED_VALUES = new HashMap<>(2);
private static final Map<String, ResourceValue> FRAMEWORK_REPLACE_VALUES = new HashMap<>(3);
+ private static final int MAX_PARSER_STACK_SIZE = Integer.getInteger(
+ "layoutlib.max.parser.stack.size", 1000);
static {
FRAMEWORK_PATCHED_VALUES.put("animateFirstView",
@@ -162,7 +164,7 @@ public class BridgeContext extends Context {
private Resources mSystemResources;
private final Object mProjectKey;
private final DisplayMetrics mMetrics;
- private final RenderResources mRenderResources;
+ private final DynamicRenderResources mRenderResources;
private final Configuration mConfig;
private final ApplicationInfo mApplicationInfo;
private final LayoutlibCallback mLayoutlibCallback;
@@ -173,6 +175,7 @@ public class BridgeContext extends Context {
private final ActivityManager mActivityManager;
private final ConnectivityManager mConnectivityManager;
private final AudioManager mAudioManager;
+ private final InputManager mInputManager;
private final HashMap<View, Integer> mScrollYPos = new HashMap<>();
private final HashMap<View, Integer> mScrollXPos = new HashMap<>();
@@ -194,6 +197,8 @@ public class BridgeContext extends Context {
private IBinder mBinder;
private PackageManager mPackageManager;
private Boolean mIsThemeAppCompat;
+ private boolean mUseThemedIcon;
+ private Context mApplicationContext;
private final ResourceNamespace mAppCompatNamespace;
private final Map<Key<?>, Object> mUserData = new HashMap<>();
@@ -240,7 +245,7 @@ public class BridgeContext extends Context {
mMetrics = metrics;
mLayoutlibCallback = layoutlibCallback;
- mRenderResources = renderResources;
+ mRenderResources = new DynamicRenderResources(renderResources);
mConfig = config;
AssetManager systemAssetManager = AssetManager.getSystem();
if (systemAssetManager instanceof BridgeAssetManager) {
@@ -263,6 +268,7 @@ public class BridgeContext extends Context {
mActivityManager = ActivityManager_Accessor.getActivityManagerInstance(this);
mConnectivityManager = new ConnectivityManager(this, null);
mAudioManager = new AudioManager(this);
+ mInputManager = new InputManager(this);
if (mLayoutlibCallback.isResourceNamespacingRequired()) {
if (mLayoutlibCallback.hasAndroidXAppCompat()) {
@@ -365,6 +371,9 @@ public class BridgeContext extends Context {
if (ParserFactory.LOG_PARSER) {
System.out.println("PUSH " + parser.getParser().toString());
}
+ if (mParserStack.size() > MAX_PARSER_STACK_SIZE) {
+ throw new RuntimeException("Potential cycle encountered during inflation");
+ }
mParserStack.push(parser);
}
@@ -449,6 +458,15 @@ public class BridgeContext extends Context {
outValue.type = TypedValue.TYPE_INT_BOOLEAN;
outValue.data = "true".equals(stringValue) ? 1 : 0;
}
+ else {
+ try {
+ outValue.data = Integer.parseInt(stringValue);
+ outValue.type = TypedValue.TYPE_INT_DEC;
+ } catch (NumberFormatException e) {
+ outValue.type = TypedValue.TYPE_STRING;
+ outValue.string = stringValue;
+ }
+ }
}
int a = getResourceId(value.asReference(), 0 /*defValue*/);
@@ -669,6 +687,9 @@ public class BridgeContext extends Context {
case AUDIO_SERVICE:
return mAudioManager;
+ case INPUT_SERVICE:
+ return mInputManager;
+
case TEXT_CLASSIFICATION_SERVICE:
case CONTENT_CAPTURE_MANAGER_SERVICE:
case ALARM_SERVICE:
@@ -694,7 +715,7 @@ public class BridgeContext extends Context {
* Same as Context#obtainStyledAttributes. We do not override the base method to give the
* original Context the chance to override the theme when needed.
*/
- @Nullable
+ @NonNull
public final BridgeTypedArray internalObtainStyledAttributes(int resId, int[] attrs)
throws Resources.NotFoundException {
StyleResourceValue style = null;
@@ -711,9 +732,8 @@ public class BridgeContext extends Context {
}
if (style == null) {
- Bridge.getLog().error(ILayoutLog.TAG_RESOURCES_RESOLVE,
+ Bridge.getLog().warning(ILayoutLog.TAG_INFO,
"Failed to find style with " + resId, null, null);
- return null;
}
}
@@ -1018,7 +1038,7 @@ public class BridgeContext extends Context {
@Override
public String getPackageName() {
if (mApplicationInfo.packageName == null) {
- mApplicationInfo.packageName = mLayoutlibCallback.getFlag(FLAG_KEY_APPLICATION_PACKAGE);
+ mApplicationInfo.packageName = mLayoutlibCallback.getApplicationId();
}
return mApplicationInfo.packageName;
}
@@ -1982,7 +2002,10 @@ public class BridgeContext extends Context {
@Override
public Context getApplicationContext() {
- return this;
+ if (mApplicationContext == null) {
+ mApplicationContext = new ApplicationContext(this);
+ }
+ return mApplicationContext;
}
@Override
@@ -2254,4 +2277,16 @@ public class BridgeContext extends Context {
public SessionInteractiveData getSessionInteractiveData() {
return mSessionInteractiveData;
}
+
+ public boolean useThemedIcon() {
+ return mUseThemedIcon && mRenderResources.hasDynamicColors();
+ }
+
+ public void setUseThemedIcon(boolean useThemedIcon) {
+ mUseThemedIcon = useThemedIcon;
+ }
+
+ public void applyWallpaper(String wallpaperPath) {
+ mRenderResources.setWallpaper(wallpaperPath, mConfig.isNightModeActive());
+ }
}