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

Initialize global context before MainApp.onCreate() #3907

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/main/java/com/owncloud/android/MainApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
import com.nextcloud.client.di.DaggerAppComponent;
import com.nextcloud.client.preferences.AppPreferences;
import com.nextcloud.client.preferences.AppPreferencesImpl;
import com.owncloud.android.authentication.AccountUtils;
import com.owncloud.android.authentication.PassCodeManager;
import com.owncloud.android.datamodel.ArbitraryDataProvider;
import com.owncloud.android.datamodel.MediaFolder;
Expand Down Expand Up @@ -163,9 +162,17 @@ public class MainApp extends MultiDexApplication implements
@SuppressWarnings("unused")
private boolean mBound;

/**
* Temporary hack
*/
private static void initGlobalContext(Context context) {
mContext = context;
Copy link
Collaborator Author

@ezaquarii ezaquarii Apr 15, 2019

Choose a reason for hiding this comment

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

getApplicationContext() is null, as the app context is set somewhere between Application.attachBaseContext() and Application.onCreate(). However, because there is only 1 instance of MainApp, there is no leak, so no worries.

Once the base context is attached, the context is basically functional, with some obscure exceptions around Looper and whatnot. Those should be fully initialized before ContentProvider.onCreate() kicks in.

}

@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
initGlobalContext(this);
DaggerAppComponent.builder()
.application(this)
.build()
Expand All @@ -187,7 +194,6 @@ public void onCreate() {
uploadsStorageManager
)
);
MainApp.mContext = getApplicationContext();

new SecurityUtils();
DisplayUtils.useCompatVectorIfNeeded();
Expand Down