Skip to content

Commit 99104fc

Browse files
litetexStypox
authored andcommitted
Clean up pre-Lollipop checks
1 parent 7cb137a commit 99104fc

73 files changed

Lines changed: 59 additions & 425 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

app/src/main/java/org/schabi/newpipe/DownloaderImpl.java

Lines changed: 0 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package org.schabi.newpipe;
22

33
import android.content.Context;
4-
import android.os.Build;
54

65
import androidx.annotation.NonNull;
76
import androidx.annotation.Nullable;
@@ -14,33 +13,18 @@
1413
import org.schabi.newpipe.extractor.exceptions.ReCaptchaException;
1514
import org.schabi.newpipe.util.CookieUtils;
1615
import org.schabi.newpipe.util.InfoCache;
17-
import org.schabi.newpipe.util.TLSSocketFactoryCompat;
1816

1917
import java.io.IOException;
20-
import java.security.KeyManagementException;
21-
import java.security.KeyStore;
22-
import java.security.KeyStoreException;
23-
import java.security.NoSuchAlgorithmException;
2418
import java.util.ArrayList;
25-
import java.util.Arrays;
2619
import java.util.HashMap;
2720
import java.util.List;
2821
import java.util.Map;
2922
import java.util.concurrent.TimeUnit;
3023

31-
import javax.net.ssl.SSLSocketFactory;
32-
import javax.net.ssl.TrustManager;
33-
import javax.net.ssl.TrustManagerFactory;
34-
import javax.net.ssl.X509TrustManager;
35-
36-
import okhttp3.CipherSuite;
37-
import okhttp3.ConnectionSpec;
3824
import okhttp3.OkHttpClient;
3925
import okhttp3.RequestBody;
4026
import okhttp3.ResponseBody;
4127

42-
import static org.schabi.newpipe.MainActivity.DEBUG;
43-
4428
public final class DownloaderImpl extends Downloader {
4529
public static final String USER_AGENT
4630
= "Mozilla/5.0 (Windows NT 10.0; rv:91.0) Gecko/20100101 Firefox/91.0";
@@ -54,9 +38,6 @@ public final class DownloaderImpl extends Downloader {
5438
private final OkHttpClient client;
5539

5640
private DownloaderImpl(final OkHttpClient.Builder builder) {
57-
if (Build.VERSION.SDK_INT == Build.VERSION_CODES.KITKAT) {
58-
enableModernTLS(builder);
59-
}
6041
this.client = builder
6142
.readTimeout(30, TimeUnit.SECONDS)
6243
// .cache(new Cache(new File(context.getExternalCacheDir(), "okhttp"),
@@ -81,55 +62,6 @@ public static DownloaderImpl getInstance() {
8162
return instance;
8263
}
8364

84-
/**
85-
* Enable TLS 1.2 and 1.1 on Android Kitkat. This function is mostly taken
86-
* from the documentation of OkHttpClient.Builder.sslSocketFactory(_,_).
87-
* <p>
88-
* If there is an error, the function will safely fall back to doing nothing
89-
* and printing the error to the console.
90-
* </p>
91-
*
92-
* @param builder The HTTPClient Builder on which TLS is enabled on (will be modified in-place)
93-
*/
94-
private static void enableModernTLS(final OkHttpClient.Builder builder) {
95-
try {
96-
// get the default TrustManager
97-
final TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(
98-
TrustManagerFactory.getDefaultAlgorithm());
99-
trustManagerFactory.init((KeyStore) null);
100-
final TrustManager[] trustManagers = trustManagerFactory.getTrustManagers();
101-
if (trustManagers.length != 1 || !(trustManagers[0] instanceof X509TrustManager)) {
102-
throw new IllegalStateException("Unexpected default trust managers:"
103-
+ Arrays.toString(trustManagers));
104-
}
105-
final X509TrustManager trustManager = (X509TrustManager) trustManagers[0];
106-
107-
// insert our own TLSSocketFactory
108-
final SSLSocketFactory sslSocketFactory = TLSSocketFactoryCompat.getInstance();
109-
110-
builder.sslSocketFactory(sslSocketFactory, trustManager);
111-
112-
// This will try to enable all modern CipherSuites(+2 more)
113-
// that are supported on the device.
114-
// Necessary because some servers (e.g. Framatube.org)
115-
// don't support the old cipher suites.
116-
// https://github.com/square/okhttp/issues/4053#issuecomment-402579554
117-
final List<CipherSuite> cipherSuites =
118-
new ArrayList<>(ConnectionSpec.MODERN_TLS.cipherSuites());
119-
cipherSuites.add(CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA);
120-
cipherSuites.add(CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA);
121-
final ConnectionSpec legacyTLS = new ConnectionSpec.Builder(ConnectionSpec.MODERN_TLS)
122-
.cipherSuites(cipherSuites.toArray(new CipherSuite[0]))
123-
.build();
124-
125-
builder.connectionSpecs(Arrays.asList(legacyTLS, ConnectionSpec.CLEARTEXT));
126-
} catch (final KeyManagementException | NoSuchAlgorithmException | KeyStoreException e) {
127-
if (DEBUG) {
128-
e.printStackTrace();
129-
}
130-
}
131-
}
132-
13365
public String getCookies(final String url) {
13466
final List<String> resultCookies = new ArrayList<>();
13567
if (url.contains(YOUTUBE_DOMAIN)) {

app/src/main/java/org/schabi/newpipe/ExitActivity.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import android.annotation.SuppressLint;
44
import android.app.Activity;
55
import android.content.Intent;
6-
import android.os.Build;
76
import android.os.Bundle;
87

98
import org.schabi.newpipe.util.NavigationHelper;
@@ -44,11 +43,7 @@ public static void exitAndRemoveFromRecentApps(final Activity activity) {
4443
protected void onCreate(final Bundle savedInstanceState) {
4544
super.onCreate(savedInstanceState);
4645

47-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
48-
finishAndRemoveTask();
49-
} else {
50-
finish();
51-
}
46+
finishAndRemoveTask();
5247

5348
NavigationHelper.restartApp(this);
5449
}

app/src/main/java/org/schabi/newpipe/MainActivity.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import android.content.IntentFilter;
2929
import android.content.SharedPreferences;
3030
import android.content.pm.PackageManager;
31-
import android.os.Build;
3231
import android.os.Bundle;
3332
import android.os.Handler;
3433
import android.os.Looper;
@@ -86,7 +85,6 @@
8685
import org.schabi.newpipe.util.SerializedCache;
8786
import org.schabi.newpipe.util.ServiceHelper;
8887
import org.schabi.newpipe.util.StateSaver;
89-
import org.schabi.newpipe.util.TLSSocketFactoryCompat;
9088
import org.schabi.newpipe.util.ThemeHelper;
9189
import org.schabi.newpipe.views.FocusOverlayView;
9290

@@ -131,11 +129,6 @@ protected void onCreate(final Bundle savedInstanceState) {
131129
+ "savedInstanceState = [" + savedInstanceState + "]");
132130
}
133131

134-
// enable TLS1.1/1.2 for kitkat devices, to fix download and play for media.ccc.de sources
135-
if (Build.VERSION.SDK_INT == Build.VERSION_CODES.KITKAT) {
136-
TLSSocketFactoryCompat.setAsDefault();
137-
}
138-
139132
ThemeHelper.setDayNightMode(this);
140133
ThemeHelper.setTheme(this, ServiceHelper.getSelectedServiceId(this));
141134

app/src/main/java/org/schabi/newpipe/PanicResponderActivity.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import android.annotation.SuppressLint;
44
import android.app.Activity;
55
import android.content.Intent;
6-
import android.os.Build;
76
import android.os.Bundle;
87

98
/*
@@ -40,10 +39,6 @@ protected void onCreate(final Bundle savedInstanceState) {
4039
ExitActivity.exitAndRemoveFromRecentApps(this);
4140
}
4241

43-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
44-
finishAndRemoveTask();
45-
} else {
46-
finish();
47-
}
42+
finishAndRemoveTask();
4843
}
4944
}

app/src/main/java/org/schabi/newpipe/error/ReCaptchaActivity.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import android.annotation.SuppressLint;
44
import android.content.Intent;
55
import android.content.SharedPreferences;
6-
import android.os.Build;
76
import android.os.Bundle;
87
import android.util.Log;
98
import android.view.Menu;
@@ -107,12 +106,7 @@ public void onPageFinished(final WebView view, final String url) {
107106
// cleaning cache, history and cookies from webView
108107
recaptchaBinding.reCaptchaWebView.clearCache(true);
109108
recaptchaBinding.reCaptchaWebView.clearHistory();
110-
final CookieManager cookieManager = CookieManager.getInstance();
111-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
112-
cookieManager.removeAllCookies(value -> { });
113-
} else {
114-
cookieManager.removeAllCookie();
115-
}
109+
CookieManager.getInstance().removeAllCookies(null);
116110

117111
recaptchaBinding.reCaptchaWebView.loadUrl(url);
118112
}

app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1922,13 +1922,7 @@ public void onFullscreenStateChanged(final boolean fullscreen) {
19221922
}
19231923
scrollToTop();
19241924

1925-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
1926-
addVideoPlayerView();
1927-
} else {
1928-
// KitKat needs a delay before addVideoPlayerView call or it reports wrong height in
1929-
// activity.getWindow().getDecorView().getHeight()
1930-
new Handler().post(this::addVideoPlayerView);
1931-
}
1925+
addVideoPlayerView();
19321926
}
19331927

19341928
@Override
@@ -1991,10 +1985,8 @@ private void showSystemUi() {
19911985
}
19921986
activity.getWindow().getDecorView().setSystemUiVisibility(0);
19931987
activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
1994-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
1995-
activity.getWindow().setStatusBarColor(ThemeHelper.resolveColorFromAttr(
1996-
requireContext(), android.R.attr.colorPrimary));
1997-
}
1988+
activity.getWindow().setStatusBarColor(ThemeHelper.resolveColorFromAttr(
1989+
requireContext(), android.R.attr.colorPrimary));
19981990
}
19991991

20001992
private void hideSystemUi() {
@@ -2025,8 +2017,7 @@ private void hideSystemUi() {
20252017
}
20262018
activity.getWindow().getDecorView().setSystemUiVisibility(visibility);
20272019

2028-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP
2029-
&& (isInMultiWindow || (isPlayerAvailable() && player.isFullscreen()))) {
2020+
if (isInMultiWindow || (isPlayerAvailable() && player.isFullscreen())) {
20302021
activity.getWindow().setStatusBarColor(Color.TRANSPARENT);
20312022
activity.getWindow().setNavigationBarColor(Color.TRANSPARENT);
20322023
}

app/src/main/java/org/schabi/newpipe/fragments/list/search/SearchFragment.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -497,9 +497,6 @@ private void showSearchOnStart() {
497497
+ lastSearchedString);
498498
}
499499
searchEditText.setText(searchString);
500-
if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.LOLLIPOP) {
501-
searchEditText.setHintTextColor(searchEditText.getTextColors().withAlpha(128));
502-
}
503500

504501
if (TextUtils.isEmpty(searchString) || TextUtils.isEmpty(searchEditText.getText())) {
505502
searchToolbarContainer.setTranslationX(100);

app/src/main/java/org/schabi/newpipe/local/subscription/dialog/FeedGroupDialog.kt

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,10 @@ import android.view.View
88
import android.view.ViewGroup
99
import android.view.inputmethod.InputMethodManager
1010
import android.widget.Toast
11-
import androidx.appcompat.content.res.AppCompatResources
1211
import androidx.core.content.getSystemService
1312
import androidx.core.os.bundleOf
1413
import androidx.core.view.isGone
1514
import androidx.core.view.isVisible
16-
import androidx.core.widget.ImageViewCompat
1715
import androidx.core.widget.doOnTextChanged
1816
import androidx.fragment.app.DialogFragment
1917
import androidx.lifecycle.Observer
@@ -124,14 +122,6 @@ class FeedGroupDialog : DialogFragment(), BackPressable {
124122
_feedGroupCreateBinding = DialogFeedGroupCreateBinding.bind(view)
125123
_searchLayoutBinding = feedGroupCreateBinding.subscriptionsHeaderSearchContainer
126124

127-
if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.LOLLIPOP) {
128-
// KitKat doesn't apply container's theme to <include> content
129-
val contrastColor = AppCompatResources.getColorStateList(requireContext(), R.color.contrastColor)
130-
searchLayoutBinding.toolbarSearchEditText.setTextColor(contrastColor)
131-
searchLayoutBinding.toolbarSearchEditText.setHintTextColor(contrastColor.withAlpha(128))
132-
ImageViewCompat.setImageTintList(searchLayoutBinding.toolbarSearchClearIcon, contrastColor)
133-
}
134-
135125
viewModel = ViewModelProvider(
136126
this,
137127
FeedGroupDialogViewModel.Factory(

app/src/main/java/org/schabi/newpipe/player/Player.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1963,10 +1963,9 @@ private void showOrHideButtons() {
19631963
private void showSystemUIPartially() {
19641964
final AppCompatActivity activity = getParentActivity();
19651965
if (isFullscreen && activity != null) {
1966-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
1967-
activity.getWindow().setStatusBarColor(Color.TRANSPARENT);
1968-
activity.getWindow().setNavigationBarColor(Color.TRANSPARENT);
1969-
}
1966+
activity.getWindow().setStatusBarColor(Color.TRANSPARENT);
1967+
activity.getWindow().setNavigationBarColor(Color.TRANSPARENT);
1968+
19701969
final int visibility = View.SYSTEM_UI_FLAG_LAYOUT_STABLE
19711970
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
19721971
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;

app/src/main/java/org/schabi/newpipe/settings/AppearanceSettingsFragment.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ private void applyThemeChange(final String beginningThemeKey,
7474
defaultPreferences.edit().putBoolean(Constants.KEY_THEME_CHANGE, true).apply();
7575
defaultPreferences.edit().putString(themeKey, newValue.toString()).apply();
7676

77-
ThemeHelper.setDayNightMode(getContext(), newValue.toString());
77+
ThemeHelper.setDayNightMode(requireContext(), newValue.toString());
7878

7979
if (!newValue.equals(beginningThemeKey) && getActivity() != null) {
8080
// if it's not the current theme

0 commit comments

Comments
 (0)