Attempts to make an Instrumentation capable of transforming/redefining classes. @param instrumentation Instrumentation to patch.
(Instrumentation instrumentation)
| 304 | * Instrumentation to patch. |
| 305 | */ |
| 306 | public static void patchInstrumentation(Instrumentation instrumentation) { |
| 307 | try { |
| 308 | Class<?> klass = instrumentation.getClass(); |
| 309 | Field field = klass.getDeclaredField("mEnvironmentSupportsRedefineClasses"); |
| 310 | field.setAccessible(true); |
| 311 | field.setBoolean(instrumentation, true); |
| 312 | (field = klass.getDeclaredField("mEnvironmentSupportsRetransformClassesKnown")).setAccessible(true); |
| 313 | field.setBoolean(instrumentation, true); |
| 314 | (field = klass.getDeclaredField("mEnvironmentSupportsRetransformClasses")).setAccessible(true); |
| 315 | field.setBoolean(instrumentation, true); |
| 316 | } catch (NoSuchFieldException | IllegalAccessException ex) { |
| 317 | Log.error("Could not patch instrumentation instance:", ex); |
| 318 | } |
| 319 | } |
| 320 | |
| 321 | /** |
| 322 | * Attempts to patch {@link ZipOutputStream} to prevent |