mirror of
https://github.com/MaintainTeam/LastPipeBender.git
synced 2025-03-01 05:48:22 +03:00
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:
parent
3df1047d91
commit
db53faa50d
2 changed files with 22 additions and 2 deletions
|
@ -1,5 +1,6 @@
|
||||||
package org.schabi.newpipe;
|
package org.schabi.newpipe;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
|
|
||||||
import org.conscrypt.Conscrypt;
|
import org.conscrypt.Conscrypt;
|
||||||
|
@ -10,10 +11,13 @@ import java.security.Security;
|
||||||
import androidx.multidex.MultiDexApplication;
|
import androidx.multidex.MultiDexApplication;
|
||||||
|
|
||||||
public class BraveApp extends MultiDexApplication {
|
public class BraveApp extends MultiDexApplication {
|
||||||
|
private static Context appContext;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate() {
|
public void onCreate() {
|
||||||
super.onCreate();
|
super.onCreate();
|
||||||
Security.insertProviderAt(Conscrypt.newProvider(), 1);
|
Security.insertProviderAt(Conscrypt.newProvider(), 1);
|
||||||
|
appContext = getApplicationContext();
|
||||||
|
|
||||||
// enable TLS1.2/1.3 for <=kitkat devices, to fix download and play for
|
// enable TLS1.2/1.3 for <=kitkat devices, to fix download and play for
|
||||||
// media.ccc.de, rumble, soundcloud, peertube sources
|
// media.ccc.de, rumble, soundcloud, peertube sources
|
||||||
|
@ -21,4 +25,20 @@ public class BraveApp extends MultiDexApplication {
|
||||||
BraveTLSSocketFactory.setAsDefault();
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@ package org.schabi.newpipe.util;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import org.schabi.newpipe.App;
|
import org.schabi.newpipe.BraveApp;
|
||||||
import org.schabi.newpipe.BraveTag;
|
import org.schabi.newpipe.BraveTag;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
|
@ -121,7 +121,7 @@ public class BraveTrustManagerFactoryHelper {
|
||||||
final String rawFile)
|
final String rawFile)
|
||||||
throws IOException, CertificateException {
|
throws IOException, CertificateException {
|
||||||
|
|
||||||
final Context context = App.getApp().getApplicationContext();
|
final Context context = BraveApp.getAppContext();
|
||||||
final InputStream inputStream = context.getResources().openRawResource(
|
final InputStream inputStream = context.getResources().openRawResource(
|
||||||
context.getResources().getIdentifier(rawFile,
|
context.getResources().getIdentifier(rawFile,
|
||||||
"raw", context.getPackageName()));
|
"raw", context.getPackageName()));
|
||||||
|
|
Loading…
Add table
Reference in a new issue