Skip to content

Commit

Permalink
Remove code for API level 20 and below
Browse files Browse the repository at this point in the history
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
  • Loading branch information
JoshuaGross authored and facebook-github-bot committed Oct 21, 2020
1 parent a17ff44 commit 49f10fd
Show file tree
Hide file tree
Showing 12 changed files with 177 additions and 349 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,7 @@ public AccessibilityInfoModule(ReactApplicationContext context) {
mContentResolver = getReactApplicationContext().getContentResolver();
mTouchExplorationEnabled = mAccessibilityManager.isTouchExplorationEnabled();
mReduceMotionEnabled = this.getIsReduceMotionEnabledValue();

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
mTouchExplorationStateChangeListener = new ReactTouchExplorationStateChangeListener();
}
mTouchExplorationStateChangeListener = new ReactTouchExplorationStateChangeListener();
}

@Override
Expand Down Expand Up @@ -142,10 +139,8 @@ public void onHostResume() {
mAccessibilityManager.addTouchExplorationStateChangeListener(
mTouchExplorationStateChangeListener);

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
Uri transitionUri = Settings.Global.getUriFor(Settings.Global.TRANSITION_ANIMATION_SCALE);
mContentResolver.registerContentObserver(transitionUri, false, animationScaleObserver);
}
Uri transitionUri = Settings.Global.getUriFor(Settings.Global.TRANSITION_ANIMATION_SCALE);
mContentResolver.registerContentObserver(transitionUri, false, animationScaleObserver);

updateAndSendTouchExplorationChangeEvent(mAccessibilityManager.isTouchExplorationEnabled());
updateAndSendReduceMotionChangeEvent();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import android.content.DialogInterface;
import android.content.DialogInterface.OnDismissListener;
import android.graphics.drawable.ColorDrawable;
import android.os.Build;
import android.os.Bundle;
import android.widget.DatePicker;
import androidx.annotation.Nullable;
Expand Down Expand Up @@ -57,52 +56,37 @@ public Dialog onCreateDialog(Bundle savedInstanceState) {

DatePickerDialog dialog = null;

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
switch (mode) {
case CALENDAR:
dialog =
new DismissableDatePickerDialog(
activityContext,
activityContext
.getResources()
.getIdentifier(
"CalendarDatePickerDialog", "style", activityContext.getPackageName()),
onDateSetListener,
year,
month,
day);
break;
case SPINNER:
dialog =
new DismissableDatePickerDialog(
activityContext,
android.R.style.Theme_Holo_Light_Dialog,
onDateSetListener,
year,
month,
day);
dialog
.getWindow()
.setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
break;
case DEFAULT:
dialog =
new DismissableDatePickerDialog(activityContext, onDateSetListener, year, month, day);
break;
}
} else {
dialog =
new DismissableDatePickerDialog(activityContext, onDateSetListener, year, month, day);

switch (mode) {
case CALENDAR:
dialog.getDatePicker().setCalendarViewShown(true);
dialog.getDatePicker().setSpinnersShown(false);
break;
case SPINNER:
dialog.getDatePicker().setCalendarViewShown(false);
break;
}
switch (mode) {
case CALENDAR:
dialog =
new DismissableDatePickerDialog(
activityContext,
activityContext
.getResources()
.getIdentifier(
"CalendarDatePickerDialog", "style", activityContext.getPackageName()),
onDateSetListener,
year,
month,
day);
break;
case SPINNER:
dialog =
new DismissableDatePickerDialog(
activityContext,
android.R.style.Theme_Holo_Light_Dialog,
onDateSetListener,
year,
month,
day);
dialog
.getWindow()
.setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
break;
case DEFAULT:
dialog =
new DismissableDatePickerDialog(activityContext, onDateSetListener, year, month, day);
break;
}

final DatePicker datePicker = dialog.getDatePicker();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,7 @@ public DismissableDatePickerDialog(
protected void onStop() {
// do *not* call super.onStop() on KitKat on lower, as that would erroneously call the
// OnDateSetListener when the dialog is dismissed, or call it twice when "OK" is pressed.
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT) {
super.onStop();
}
super.onStop();
}

private void fixSpinner(Context context, int year, int month, int dayOfMonth) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,10 @@
import android.os.Message;
import android.text.TextUtils;
import android.webkit.CookieManager;
import android.webkit.CookieSyncManager;
import android.webkit.ValueCallback;
import androidx.annotation.Nullable;
import com.facebook.react.bridge.Callback;
import com.facebook.react.bridge.GuardedAsyncTask;
import com.facebook.react.bridge.GuardedResultAsyncTask;
import com.facebook.react.bridge.ReactContext;
import java.io.IOException;
import java.net.CookieHandler;
Expand All @@ -40,10 +38,6 @@ public class ForwardingCookieHandler extends CookieHandler {
private static final String VERSION_ONE_HEADER = "Set-cookie2";
private static final String COOKIE_HEADER = "Cookie";

// As CookieManager was synchronous before API 21 this class emulates the async behavior on < 21.
private static final boolean USES_LEGACY_STORE =
Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP;

private final CookieSaver mCookieSaver;
private final ReactContext mContext;
private @Nullable CookieManager mCookieManager;
Expand Down Expand Up @@ -79,26 +73,7 @@ public void put(URI uri, Map<String, List<String>> headers) throws IOException {
}

public void clearCookies(final Callback callback) {
if (USES_LEGACY_STORE) {
new GuardedResultAsyncTask<Boolean>(mContext) {
@Override
protected Boolean doInBackgroundGuarded() {
CookieManager cookieManager = getCookieManager();
if (cookieManager != null) {
cookieManager.removeAllCookie();
}
mCookieSaver.onCookiesModified();
return true;
}

@Override
protected void onPostExecuteGuarded(Boolean result) {
callback.invoke(result);
}
}.execute();
} else {
clearCookiesAsync(callback);
}
clearCookiesAsync(callback);
}

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
Expand All @@ -116,38 +91,17 @@ public void onReceiveValue(Boolean value) {
}
}

public void destroy() {
if (USES_LEGACY_STORE) {
CookieManager cookieManager = getCookieManager();
if (cookieManager != null) {
cookieManager.removeExpiredCookie();
}
mCookieSaver.persistCookies();
}
}
public void destroy() {}

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

if (USES_LEGACY_STORE) {
runInBackground(
new Runnable() {
@Override
public void run() {
for (String cookie : cookies) {
cookieManager.setCookie(url, cookie);
}
mCookieSaver.onCookiesModified();
}
});
} else {
for (String cookie : cookies) {
addCookieAsync(url, cookie);
}
cookieManager.flush();
mCookieSaver.onCookiesModified();
for (String cookie : cookies) {
addCookieAsync(url, cookie);
}
cookieManager.flush();
mCookieSaver.onCookiesModified();
}

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
Expand Down Expand Up @@ -199,24 +153,12 @@ protected void doInBackgroundGuarded(Void... params) {
throw exception;
}
}

if (USES_LEGACY_STORE) {
mCookieManager.removeExpiredCookie();
}
}

return mCookieManager;
}

private static void possiblyWorkaroundSyncManager(Context context) {
if (USES_LEGACY_STORE) {
// This is to work around a bug where CookieManager may fail to instantiate if
// CookieSyncManager has never been created. Note that the sync() may not be required but is
// here of legacy reasons.
CookieSyncManager syncManager = CookieSyncManager.createInstance(context);
syncManager.sync();
}
}
private static void possiblyWorkaroundSyncManager(Context context) {}

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

public void onCookiesModified() {
if (USES_LEGACY_STORE) {
mHandler.sendEmptyMessageDelayed(MSG_PERSIST_COOKIES, TIMEOUT);
}
}
public void onCookiesModified() {}

public void persistCookies() {
mHandler.removeMessages(MSG_PERSIST_COOKIES);
runInBackground(
new Runnable() {
@Override
public void run() {
if (USES_LEGACY_STORE) {
CookieSyncManager syncManager = CookieSyncManager.getInstance();
syncManager.sync();
} else {
flush();
}
flush();
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,13 @@
package com.facebook.react.modules.network;

import android.content.Context;
import android.os.Build;
import androidx.annotation.Nullable;
import com.facebook.common.logging.FLog;
import java.io.File;
import java.security.Provider;
import java.security.Security;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;
import okhttp3.Cache;
import okhttp3.ConnectionSpec;
import okhttp3.OkHttpClient;
import okhttp3.TlsVersion;

/**
* Helper class that provides the same OkHttpClient instance that will be used for all networking
Expand Down Expand Up @@ -101,26 +95,6 @@ public static OkHttpClient.Builder createClientBuilder(Context context, int cach
enables it.
*/
public static OkHttpClient.Builder enableTls12OnPreLollipop(OkHttpClient.Builder client) {
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT) {
try {
client.sslSocketFactory(new TLSSocketFactory());

ConnectionSpec cs =
new ConnectionSpec.Builder(ConnectionSpec.MODERN_TLS)
.tlsVersions(TlsVersion.TLS_1_2)
.build();

List<ConnectionSpec> specs = new ArrayList<>();
specs.add(cs);
specs.add(ConnectionSpec.COMPATIBLE_TLS);
specs.add(ConnectionSpec.CLEARTEXT);

client.connectionSpecs(specs);
} catch (Exception ex) {
FLog.e("OkHttpClientProvider", "Error while enabling TLS 1.2", ex);
}
}

return client;
}
}
Loading

0 comments on commit 49f10fd

Please sign in to comment.