BraveNewPipeLegacy: use getApplicationContext to have a static variable inside BraveApp

In the App.java from main source set there is the static method App.getApp() from which
many parts of the application get ApplicationContext. But as the class App inherits from
BraveApp and sets the app variable in onCreate() only after the super.onCreate()
from BraveApp is called. Therefore App.getApp() has not yet an initialized variable
thus we need another way to get the ApplicationContext
This commit is contained in:
evermind 2024-04-03 23:19:42 +02:00
parent 3df1047d91
commit db53faa50d
2 changed files with 22 additions and 2 deletions

View file

@ -1,5 +1,6 @@
package org.schabi.newpipe;
import android.content.Context;
import android.os.Build;
import org.conscrypt.Conscrypt;
@ -10,10 +11,13 @@ import java.security.Security;
import androidx.multidex.MultiDexApplication;
public class BraveApp extends MultiDexApplication {
private static Context appContext;
@Override
public void onCreate() {
super.onCreate();
Security.insertProviderAt(Conscrypt.newProvider(), 1);
appContext = getApplicationContext();
// enable TLS1.2/1.3 for <=kitkat devices, to fix download and play for
// media.ccc.de, rumble, soundcloud, peertube sources
@ -21,4 +25,20 @@ public class BraveApp extends MultiDexApplication {
BraveTLSSocketFactory.setAsDefault();
}
}
/**
* Get the application context.
* <p>
* In the {@link App} from main source set there is the static method {@link App#getApp()}
* from which many parts of the application get ApplicationContext. But as the class
* {@link App} inherits from BraveApp and sets the app variable in {@link @App#onCreate()}
* only after the {@link BraveApp#onCreate()} is called. Therefore {@link App#getApp()}
* has not yet an initialized return valule thus we need another way to get the
* ApplicationContext
*
* @return the application context
*/
public static Context getAppContext() {
return appContext;
}
}

View file

@ -3,7 +3,7 @@ package org.schabi.newpipe.util;
import android.content.Context;
import android.util.Log;
import org.schabi.newpipe.App;
import org.schabi.newpipe.BraveApp;
import org.schabi.newpipe.BraveTag;
import java.io.ByteArrayInputStream;
@ -121,7 +121,7 @@ public class BraveTrustManagerFactoryHelper {
final String rawFile)
throws IOException, CertificateException {
final Context context = App.getApp().getApplicationContext();
final Context context = BraveApp.getAppContext();
final InputStream inputStream = context.getResources().openRawResource(
context.getResources().getIdentifier(rawFile,
"raw", context.getPackageName()));