Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Glide.setModulesEnabled API to allow apps to disable Manifest parsing #1753

Closed
wants to merge 2 commits into from

Conversation

joshzana
Copy link

Description

Adding a static flag to Glide to disable parsing the manifest to find configured modules.
Added unit tests.
Fixes #684

Motivation and Context

The Dropbox app has been crashing on launch approximately 9000 times a day due to RuntimeExceptions thrown by PackageManager. We'd like to remove the dependency on PackageManager from our startup path, and we don't use any GlideModules. While #1742 in 4.0 will address this long term, we'd like a short term way to run Glide without runtime manifest parsing.

In order to enable unit testing, I decided to make this a set method that takes a boolean.

Not sure if I found the best way to unit test this. Feel free to propose a cleaner approach.

Copy link
Collaborator

@TWiStErRob TWiStErRob left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The testing approach is indirect, but I think it's OK. Well documented!

I think you made the PR against the wrong branch though. You said you don't want to wait till v4, but master is v4. You want the 3.0 branch. (That said we may keep this as well just to have feature parity between v3 and v4, @sjudd?)

@@ -547,6 +552,44 @@ public void testClone() throws IOException {
verify(secondTarget).onResourceReady(notNull(Drawable.class), isA(Transition.class));
}

@Test
public void testSetModulesEnabledTrue() throws Exception {
// teaDown glide instance first so we have a clean slate and not the Glide.get() call in setUp
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"teaDown"


@Test
public void testSetModulesEnabledFalse() throws Exception {
// teaDown glide instance first so we have a clean slate and not the Glide.get() call in setUp
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"teaDown"

assertEquals(1, modelLoaders.size());
assertTrue(modelLoaders.get(0) instanceof HttpGlideUrlLoader);
} finally {
Glide.setModulesEnabled(true);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be part of Glide.tearDown, it resets Glide to pre-initialized state, which IMO includes both static variables. (It should probably even reset ViewTarget.tagId)

@joshzana
Copy link
Author

Oops, yes. I want this on the v3 branch. Want a separate PR or should we land on master and then cherry-pick?

@TWiStErRob
Copy link
Collaborator

We can't pick it directly, there are breaking changes in v4, though looking at the code this'll only impact a few lines in tests. Probably best to get two PRs in (see for example what I did in #1233... didn't know about cherry back then :)
Let's see what @sjudd thinks as well, he's the mastermind.

@TWiStErRob TWiStErRob requested a review from sjudd February 23, 2017 23:53
@@ -132,6 +137,7 @@ public Boolean answer(InvocationOnMock invocation) throws Throwable {
@After
public void tearDown() {
Glide.tearDown();
Glide.setModulesEnabled(true);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant Glide.tearDown not the @After, though I guess it doesn't matter much.

Copy link
Collaborator

@sjudd sjudd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's fine to submit this for just v3 or for v3 and v4. The changes will probably make cherry picking a bit complicated, but you can try it.

I'm completely fine with this approach, but I'd be curious to get your thoughts on #1742. That would remove the need for manifest parsing entirely.

* Must be called before accessing the Glide singleton; otherwise, has no effect.
*/
public static void setModulesEnabled(boolean enabled) {
synchronized (Glide.class) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd probably add a check here to make sure that the Glide singleton hasn't already been instantiated.

@joshzana
Copy link
Author

OK I just made #1754 against the 3.0 branch. Turns out a lot has changed around the test code, so that part is pretty different.

RE #1742. as I read it, it still parses the manifest every time, so it wouldn't fix #684 even if we were able to ship Glide 4.0 right now. Maybe 4.0 needs its own implementation of this same method?

@sjudd
Copy link
Collaborator

sjudd commented Feb 24, 2017

Yup that's true, but we'd probably enable a parameter similar to the one @TWiStErRob proposed for excluding modules to exclude parsing the manifest entirely.

It's mostly still there to not instantly break everything.

@joshzana
Copy link
Author

OK great. How about I drop this PR, and you add a parameter to your PR?

@TWiStErRob TWiStErRob added this to the 4.0 milestone Feb 25, 2017
@TWiStErRob
Copy link
Collaborator

@joshzana so you want to close this PR in favor of the promise #1742 has?

@TWiStErRob TWiStErRob removed this from the 4.0 milestone Feb 25, 2017
@joshzana
Copy link
Author

Yep! I'll add a comment over there just to make sure this doesn't get lost.

@joshzana joshzana closed this Feb 26, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants