Skip to content

Commit 49f10fd

Browse files
JoshuaGrossfacebook-github-bot
authored andcommitted
Remove code for API level 20 and below
Summary: We've deprecated API 20 and below. This is just a cleanup to remove code that assumes API level <21. Changelog: [Android][Deprecated] Deprecate support of Android API levels 19 and 20. Reviewed By: fkgozali Differential Revision: D24380233 fbshipit-source-id: d8f98d7cb19446a60ba36137f1f9290e35f27c02
1 parent a17ff44 commit 49f10fd

12 files changed

+177
-349
lines changed

ReactAndroid/src/main/java/com/facebook/react/modules/accessibilityinfo/AccessibilityInfoModule.java

+3-8
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,7 @@ public AccessibilityInfoModule(ReactApplicationContext context) {
7979
mContentResolver = getReactApplicationContext().getContentResolver();
8080
mTouchExplorationEnabled = mAccessibilityManager.isTouchExplorationEnabled();
8181
mReduceMotionEnabled = this.getIsReduceMotionEnabledValue();
82-
83-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
84-
mTouchExplorationStateChangeListener = new ReactTouchExplorationStateChangeListener();
85-
}
82+
mTouchExplorationStateChangeListener = new ReactTouchExplorationStateChangeListener();
8683
}
8784

8885
@Override
@@ -142,10 +139,8 @@ public void onHostResume() {
142139
mAccessibilityManager.addTouchExplorationStateChangeListener(
143140
mTouchExplorationStateChangeListener);
144141

145-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
146-
Uri transitionUri = Settings.Global.getUriFor(Settings.Global.TRANSITION_ANIMATION_SCALE);
147-
mContentResolver.registerContentObserver(transitionUri, false, animationScaleObserver);
148-
}
142+
Uri transitionUri = Settings.Global.getUriFor(Settings.Global.TRANSITION_ANIMATION_SCALE);
143+
mContentResolver.registerContentObserver(transitionUri, false, animationScaleObserver);
149144

150145
updateAndSendTouchExplorationChangeEvent(mAccessibilityManager.isTouchExplorationEnabled());
151146
updateAndSendReduceMotionChangeEvent();

ReactAndroid/src/main/java/com/facebook/react/modules/datepicker/DatePickerDialogFragment.java

+31-47
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
import android.content.DialogInterface;
1616
import android.content.DialogInterface.OnDismissListener;
1717
import android.graphics.drawable.ColorDrawable;
18-
import android.os.Build;
1918
import android.os.Bundle;
2019
import android.widget.DatePicker;
2120
import androidx.annotation.Nullable;
@@ -57,52 +56,37 @@ public Dialog onCreateDialog(Bundle savedInstanceState) {
5756

5857
DatePickerDialog dialog = null;
5958

60-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
61-
switch (mode) {
62-
case CALENDAR:
63-
dialog =
64-
new DismissableDatePickerDialog(
65-
activityContext,
66-
activityContext
67-
.getResources()
68-
.getIdentifier(
69-
"CalendarDatePickerDialog", "style", activityContext.getPackageName()),
70-
onDateSetListener,
71-
year,
72-
month,
73-
day);
74-
break;
75-
case SPINNER:
76-
dialog =
77-
new DismissableDatePickerDialog(
78-
activityContext,
79-
android.R.style.Theme_Holo_Light_Dialog,
80-
onDateSetListener,
81-
year,
82-
month,
83-
day);
84-
dialog
85-
.getWindow()
86-
.setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
87-
break;
88-
case DEFAULT:
89-
dialog =
90-
new DismissableDatePickerDialog(activityContext, onDateSetListener, year, month, day);
91-
break;
92-
}
93-
} else {
94-
dialog =
95-
new DismissableDatePickerDialog(activityContext, onDateSetListener, year, month, day);
96-
97-
switch (mode) {
98-
case CALENDAR:
99-
dialog.getDatePicker().setCalendarViewShown(true);
100-
dialog.getDatePicker().setSpinnersShown(false);
101-
break;
102-
case SPINNER:
103-
dialog.getDatePicker().setCalendarViewShown(false);
104-
break;
105-
}
59+
switch (mode) {
60+
case CALENDAR:
61+
dialog =
62+
new DismissableDatePickerDialog(
63+
activityContext,
64+
activityContext
65+
.getResources()
66+
.getIdentifier(
67+
"CalendarDatePickerDialog", "style", activityContext.getPackageName()),
68+
onDateSetListener,
69+
year,
70+
month,
71+
day);
72+
break;
73+
case SPINNER:
74+
dialog =
75+
new DismissableDatePickerDialog(
76+
activityContext,
77+
android.R.style.Theme_Holo_Light_Dialog,
78+
onDateSetListener,
79+
year,
80+
month,
81+
day);
82+
dialog
83+
.getWindow()
84+
.setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
85+
break;
86+
case DEFAULT:
87+
dialog =
88+
new DismissableDatePickerDialog(activityContext, onDateSetListener, year, month, day);
89+
break;
10690
}
10791

10892
final DatePicker datePicker = dialog.getDatePicker();

ReactAndroid/src/main/java/com/facebook/react/modules/datepicker/DismissableDatePickerDialog.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,7 @@ public DismissableDatePickerDialog(
5050
protected void onStop() {
5151
// do *not* call super.onStop() on KitKat on lower, as that would erroneously call the
5252
// OnDateSetListener when the dialog is dismissed, or call it twice when "OK" is pressed.
53-
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT) {
54-
super.onStop();
55-
}
53+
super.onStop();
5654
}
5755

5856
private void fixSpinner(Context context, int year, int month, int dayOfMonth) {

ReactAndroid/src/main/java/com/facebook/react/modules/network/ForwardingCookieHandler.java

+9-76
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,10 @@
1515
import android.os.Message;
1616
import android.text.TextUtils;
1717
import android.webkit.CookieManager;
18-
import android.webkit.CookieSyncManager;
1918
import android.webkit.ValueCallback;
2019
import androidx.annotation.Nullable;
2120
import com.facebook.react.bridge.Callback;
2221
import com.facebook.react.bridge.GuardedAsyncTask;
23-
import com.facebook.react.bridge.GuardedResultAsyncTask;
2422
import com.facebook.react.bridge.ReactContext;
2523
import java.io.IOException;
2624
import java.net.CookieHandler;
@@ -40,10 +38,6 @@ public class ForwardingCookieHandler extends CookieHandler {
4038
private static final String VERSION_ONE_HEADER = "Set-cookie2";
4139
private static final String COOKIE_HEADER = "Cookie";
4240

43-
// As CookieManager was synchronous before API 21 this class emulates the async behavior on < 21.
44-
private static final boolean USES_LEGACY_STORE =
45-
Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP;
46-
4741
private final CookieSaver mCookieSaver;
4842
private final ReactContext mContext;
4943
private @Nullable CookieManager mCookieManager;
@@ -79,26 +73,7 @@ public void put(URI uri, Map<String, List<String>> headers) throws IOException {
7973
}
8074

8175
public void clearCookies(final Callback callback) {
82-
if (USES_LEGACY_STORE) {
83-
new GuardedResultAsyncTask<Boolean>(mContext) {
84-
@Override
85-
protected Boolean doInBackgroundGuarded() {
86-
CookieManager cookieManager = getCookieManager();
87-
if (cookieManager != null) {
88-
cookieManager.removeAllCookie();
89-
}
90-
mCookieSaver.onCookiesModified();
91-
return true;
92-
}
93-
94-
@Override
95-
protected void onPostExecuteGuarded(Boolean result) {
96-
callback.invoke(result);
97-
}
98-
}.execute();
99-
} else {
100-
clearCookiesAsync(callback);
101-
}
76+
clearCookiesAsync(callback);
10277
}
10378

10479
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@@ -116,38 +91,17 @@ public void onReceiveValue(Boolean value) {
11691
}
11792
}
11893

119-
public void destroy() {
120-
if (USES_LEGACY_STORE) {
121-
CookieManager cookieManager = getCookieManager();
122-
if (cookieManager != null) {
123-
cookieManager.removeExpiredCookie();
124-
}
125-
mCookieSaver.persistCookies();
126-
}
127-
}
94+
public void destroy() {}
12895

12996
public void addCookies(final String url, final List<String> cookies) {
13097
final CookieManager cookieManager = getCookieManager();
13198
if (cookieManager == null) return;
13299

133-
if (USES_LEGACY_STORE) {
134-
runInBackground(
135-
new Runnable() {
136-
@Override
137-
public void run() {
138-
for (String cookie : cookies) {
139-
cookieManager.setCookie(url, cookie);
140-
}
141-
mCookieSaver.onCookiesModified();
142-
}
143-
});
144-
} else {
145-
for (String cookie : cookies) {
146-
addCookieAsync(url, cookie);
147-
}
148-
cookieManager.flush();
149-
mCookieSaver.onCookiesModified();
100+
for (String cookie : cookies) {
101+
addCookieAsync(url, cookie);
150102
}
103+
cookieManager.flush();
104+
mCookieSaver.onCookiesModified();
151105
}
152106

153107
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@@ -199,24 +153,12 @@ protected void doInBackgroundGuarded(Void... params) {
199153
throw exception;
200154
}
201155
}
202-
203-
if (USES_LEGACY_STORE) {
204-
mCookieManager.removeExpiredCookie();
205-
}
206156
}
207157

208158
return mCookieManager;
209159
}
210160

211-
private static void possiblyWorkaroundSyncManager(Context context) {
212-
if (USES_LEGACY_STORE) {
213-
// This is to work around a bug where CookieManager may fail to instantiate if
214-
// CookieSyncManager has never been created. Note that the sync() may not be required but is
215-
// here of legacy reasons.
216-
CookieSyncManager syncManager = CookieSyncManager.createInstance(context);
217-
syncManager.sync();
218-
}
219-
}
161+
private static void possiblyWorkaroundSyncManager(Context context) {}
220162

221163
/**
222164
* Responsible for flushing cookies to disk. Flushes to disk with a maximum delay of 30 seconds.
@@ -246,24 +188,15 @@ public boolean handleMessage(Message msg) {
246188
});
247189
}
248190

249-
public void onCookiesModified() {
250-
if (USES_LEGACY_STORE) {
251-
mHandler.sendEmptyMessageDelayed(MSG_PERSIST_COOKIES, TIMEOUT);
252-
}
253-
}
191+
public void onCookiesModified() {}
254192

255193
public void persistCookies() {
256194
mHandler.removeMessages(MSG_PERSIST_COOKIES);
257195
runInBackground(
258196
new Runnable() {
259197
@Override
260198
public void run() {
261-
if (USES_LEGACY_STORE) {
262-
CookieSyncManager syncManager = CookieSyncManager.getInstance();
263-
syncManager.sync();
264-
} else {
265-
flush();
266-
}
199+
flush();
267200
}
268201
});
269202
}

ReactAndroid/src/main/java/com/facebook/react/modules/network/OkHttpClientProvider.java

-26
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,13 @@
88
package com.facebook.react.modules.network;
99

1010
import android.content.Context;
11-
import android.os.Build;
1211
import androidx.annotation.Nullable;
13-
import com.facebook.common.logging.FLog;
1412
import java.io.File;
1513
import java.security.Provider;
1614
import java.security.Security;
17-
import java.util.ArrayList;
18-
import java.util.List;
1915
import java.util.concurrent.TimeUnit;
2016
import okhttp3.Cache;
21-
import okhttp3.ConnectionSpec;
2217
import okhttp3.OkHttpClient;
23-
import okhttp3.TlsVersion;
2418

2519
/**
2620
* Helper class that provides the same OkHttpClient instance that will be used for all networking
@@ -101,26 +95,6 @@ public static OkHttpClient.Builder createClientBuilder(Context context, int cach
10195
enables it.
10296
*/
10397
public static OkHttpClient.Builder enableTls12OnPreLollipop(OkHttpClient.Builder client) {
104-
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT) {
105-
try {
106-
client.sslSocketFactory(new TLSSocketFactory());
107-
108-
ConnectionSpec cs =
109-
new ConnectionSpec.Builder(ConnectionSpec.MODERN_TLS)
110-
.tlsVersions(TlsVersion.TLS_1_2)
111-
.build();
112-
113-
List<ConnectionSpec> specs = new ArrayList<>();
114-
specs.add(cs);
115-
specs.add(ConnectionSpec.COMPATIBLE_TLS);
116-
specs.add(ConnectionSpec.CLEARTEXT);
117-
118-
client.connectionSpecs(specs);
119-
} catch (Exception ex) {
120-
FLog.e("OkHttpClientProvider", "Error while enabling TLS 1.2", ex);
121-
}
122-
}
123-
12498
return client;
12599
}
126100
}

0 commit comments

Comments
 (0)