Skip to content

Commit

Permalink
Remove code in outdated version checks (#2038)
Browse files Browse the repository at this point in the history
Refactor code inside `if-else` blocks that checks for versions that are
no longer relevant.
Few lines could be deleted some others were just un-wrapped from the
if-else blocks.
The `if-else` blocks inside `PRNGFixes` file were left out as this file
is should be deleted in
#2036
  • Loading branch information
adamszewe committed Jan 7, 2024
1 parent eb0e1d6 commit 9b04374
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ protected void onCreate(Bundle savedInstanceState) {
}

Boolean prefUseRoot = PreferenceManager.getDefaultSharedPreferences(this).getBoolean(Constants.PREF_USE_ROOT, false);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && !prefUseRoot) {
if (!prefUseRoot) {
Toast.makeText(this, R.string.kitkat_external_storage_warning, Toast.LENGTH_LONG)
.show();
}
Expand All @@ -118,10 +118,8 @@ protected void onCreate(Bundle savedInstanceState) {
@SuppressLint("NewApi")
private void populateRoots() {
ArrayList<File> roots = new ArrayList<>();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
roots.addAll(Arrays.asList(getExternalFilesDirs(null)));
roots.remove(getExternalFilesDir(null));
}
roots.addAll(Arrays.asList(getExternalFilesDirs(null)));
roots.remove(getExternalFilesDir(null));

String rootDir = getIntent().getStringExtra(EXTRA_ROOT_DIRECTORY);
if (getIntent().hasExtra(EXTRA_ROOT_DIRECTORY) && !TextUtils.isEmpty(rootDir)) {
Expand All @@ -132,9 +130,7 @@ private void populateRoots() {
roots.add(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES));
roots.add(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS));
roots.add(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
roots.add(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS));
}
roots.add(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS));

// Add paths that might not be accessible to Syncthing.
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,6 @@ public class WebGuiActivity extends StateDialogActivity
@Override
public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
try {
int sdk = android.os.Build.VERSION.SDK_INT;
if (sdk < Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
// The mX509Certificate field is not available for ICS- devices
Log.w(TAG, "Skipping certificate check for devices <ICS");
handler.proceed();
return;
}
// Use reflection to access the private mX509Certificate field of SslCertificate
SslCertificate sslCert = error.getCertificate();
Field f = sslCert.getClass().getDeclaredField("mX509Certificate");
Expand Down Expand Up @@ -252,11 +245,6 @@ private void loadCaCert() {
*/
@SuppressLint("PrivateApi")
public static boolean setWebViewProxy(Context appContext, String host, int port, String exclusionList) {
if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
// Not supported on android version lower than KitKat.
return false;
}

Properties properties = System.getProperties();
properties.setProperty("http.proxyHost", host);
properties.setProperty("http.proxyPort", Integer.toString(port));
Expand All @@ -282,11 +270,7 @@ public static boolean setWebViewProxy(Context appContext, String host, int port,
Intent intent = new Intent(Proxy.PROXY_CHANGE_ACTION);

String CLASS_NAME;
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT) {
CLASS_NAME = "android.net.ProxyProperties";
} else {
CLASS_NAME = "android.net.ProxyInfo";
}
CLASS_NAME = "android.net.ProxyInfo";
Class cls = Class.forName(CLASS_NAME);
Constructor constructor = cls.getConstructor(String.class, Integer.TYPE, String.class);
constructor.setAccessible(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,10 +284,6 @@ private void doExit() {
}
Log.i(TAG, "Exiting app on user request");
mActivity.stopService(new Intent(mActivity, SyncthingService.class));
if(android.os.Build.VERSION.SDK_INT >= 21) {
mActivity.finishAndRemoveTask();
} else {
mActivity.finish();
}
mActivity.finishAndRemoveTask();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ public static void dismissDialogSafe(Dialog dialog, Activity activity) {
if (activity.isFinishing())
return;

if (Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN && activity.isDestroyed())
if (activity.isDestroyed())
return;

dialog.dismiss();
Expand Down

0 comments on commit 9b04374

Please sign in to comment.