1
0
Fork 0
mirror of https://github.com/syncthing/syncthing-android.git synced 2024-11-22 20:31:16 +00:00

Simplify conditions that check for lollipop, api 21, version (#2023)

Lollipop, API 21, has been the min sdk version for over a year in this
project.
There were still some conditions in the code, which checked for api 21,
that can be removed or simplified.
This commit is contained in:
Adam Szewera 2023-12-10 17:15:40 +01:00 committed by GitHub
parent 32ab0ca9d8
commit ae31cedb2c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 11 additions and 79 deletions

View file

@ -81,7 +81,6 @@ public class FolderActivity extends SyncthingActivity
private static final String IGNORE_FILE_NAME = ".stignore"; private static final String IGNORE_FILE_NAME = ".stignore";
private Folder mFolder; private Folder mFolder;
// Contains SAF readwrite access URI on API level >= Build.VERSION_CODES.LOLLIPOP (21)
private Uri mFolderUri = null; private Uri mFolderUri = null;
// Indicates the result of the write test to mFolder.path on dialog init or after a path change. // Indicates the result of the write test to mFolder.path on dialog init or after a path change.
Boolean mCanWriteToPath = false; Boolean mCanWriteToPath = false;
@ -216,12 +215,6 @@ public class FolderActivity extends SyncthingActivity
*/ */
@SuppressLint("InlinedAPI") @SuppressLint("InlinedAPI")
private void onPathViewClick() { private void onPathViewClick() {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
startActivityForResult(FolderPickerActivity.createIntent(this, mFolder.path, null),
FolderPickerActivity.DIRECTORY_REQUEST_CODE);
return;
}
// This has to be android.net.Uri as it implements a Parcelable. // This has to be android.net.Uri as it implements a Parcelable.
android.net.Uri externalFilesDirUri = FileUtils.getExternalFilesDirUri(FolderActivity.this); android.net.Uri externalFilesDirUri = FileUtils.getExternalFilesDirUri(FolderActivity.this);
@ -460,8 +453,7 @@ public class FolderActivity extends SyncthingActivity
.show(); .show();
return true; return true;
} }
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && if (mFolderUri != null) {
mFolderUri != null) {
/** /**
* Normally, syncthing takes care of creating the ".stfolder" marker. * Normally, syncthing takes care of creating the ".stfolder" marker.
* This fails on newer android versions if the syncthing binary only has * This fails on newer android versions if the syncthing binary only has
@ -516,7 +508,6 @@ public class FolderActivity extends SyncthingActivity
super.onActivityResult(requestCode, resultCode, data); super.onActivityResult(requestCode, resultCode, data);
if (resultCode == Activity.RESULT_OK && requestCode == CHOOSE_FOLDER_REQUEST) { if (resultCode == Activity.RESULT_OK && requestCode == CHOOSE_FOLDER_REQUEST) {
// This result case only occurs on API level >= Build.VERSION_CODES.LOLLIPOP (21)
mFolderUri = data.getData(); mFolderUri = data.getData();
if (mFolderUri == null) { if (mFolderUri == null) {
return; return;

View file

@ -139,11 +139,6 @@ public class Constants {
* to syncthing core v0.14.53+. * to syncthing core v0.14.53+.
*/ */
public static Boolean osSupportsTLS12() { public static Boolean osSupportsTLS12() {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
// Pre-Lollipop devices don't support TLS 1.2
return false;
}
if (Build.VERSION.SDK_INT == Build.VERSION_CODES.N) { if (Build.VERSION.SDK_INT == Build.VERSION_CODES.N) {
/** /**
* SSLProtocolException: SSL handshake failed on Android N/7.0, * SSLProtocolException: SSL handshake failed on Android N/7.0,

View file

@ -299,9 +299,7 @@ public class NotificationHandler {
Constants.FLAG_IMMUTABLE | PendingIntent.FLAG_UPDATE_CURRENT)); Constants.FLAG_IMMUTABLE | PendingIntent.FLAG_UPDATE_CURRENT));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
nb.setCategory(Notification.CATEGORY_ERROR); nb.setCategory(Notification.CATEGORY_ERROR);
}
mNotificationManager.notify(ID_STOP_BACKGROUND_WARNING, nb.build()); mNotificationManager.notify(ID_STOP_BACKGROUND_WARNING, nb.build());
} }
} }

View file

@ -91,11 +91,9 @@ public class RunConditionMonitor {
ReceiverManager.registerReceiver(mContext, new BatteryReceiver(), filter); ReceiverManager.registerReceiver(mContext, new BatteryReceiver(), filter);
// PowerSaveModeChangedReceiver // PowerSaveModeChangedReceiver
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
ReceiverManager.registerReceiver(mContext, ReceiverManager.registerReceiver(mContext,
new PowerSaveModeChangedReceiver(), new PowerSaveModeChangedReceiver(),
new IntentFilter(PowerManager.ACTION_POWER_SAVE_MODE_CHANGED)); new IntentFilter(PowerManager.ACTION_POWER_SAVE_MODE_CHANGED));
}
// SyncStatusObserver to monitor android's "AutoSync" quick toggle. // SyncStatusObserver to monitor android's "AutoSync" quick toggle.
mSyncStatusObserverHandle = ContentResolver.addStatusChangeListener( mSyncStatusObserverHandle = ContentResolver.addStatusChangeListener(
@ -207,12 +205,10 @@ public class RunConditionMonitor {
} }
// Power saving // Power saving
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
if (prefRespectPowerSaving && isPowerSaving()) { if (prefRespectPowerSaving && isPowerSaving()) {
Log.v(TAG, "decideShouldRun: prefRespectPowerSaving && isPowerSaving"); Log.v(TAG, "decideShouldRun: prefRespectPowerSaving && isPowerSaving");
blockerReasons.add(POWERSAVING_ENABLED); blockerReasons.add(POWERSAVING_ENABLED);
} }
}
// Android global AutoSync setting. // Android global AutoSync setting.
if (prefRespectMasterSync && !ContentResolver.getMasterSyncAutomatically()) { if (prefRespectMasterSync && !ContentResolver.getMasterSyncAutomatically()) {
@ -298,25 +294,6 @@ public class RunConditionMonitor {
* Functions for run condition information retrieval. * Functions for run condition information retrieval.
*/ */
private boolean isCharging() { private boolean isCharging() {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
// API level < 21
return isCharging_API16();
} else {
// API level >= 21
return isCharging_API17();
}
}
@TargetApi(16)
private boolean isCharging_API16() {
Intent batteryIntent = mContext.registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
int status = batteryIntent.getIntExtra(BatteryManager.EXTRA_STATUS, -1);
return status == BatteryManager.BATTERY_STATUS_CHARGING ||
status == BatteryManager.BATTERY_STATUS_FULL;
}
@TargetApi(17)
private boolean isCharging_API17() {
Intent intent = mContext.registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED)); Intent intent = mContext.registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
int plugged = intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1); int plugged = intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1);
return plugged == BatteryManager.BATTERY_PLUGGED_AC || return plugged == BatteryManager.BATTERY_PLUGGED_AC ||
@ -324,12 +301,7 @@ public class RunConditionMonitor {
plugged == BatteryManager.BATTERY_PLUGGED_WIRELESS; plugged == BatteryManager.BATTERY_PLUGGED_WIRELESS;
} }
@TargetApi(21)
private boolean isPowerSaving() { private boolean isPowerSaving() {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
Log.e(TAG, "isPowerSaving may not be called on pre-lollipop android versions.");
return false;
}
PowerManager powerManager = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE); PowerManager powerManager = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
if (powerManager == null) { if (powerManager == null) {
Log.e(TAG, "getSystemService(POWER_SERVICE) unexpectedly returned NULL."); Log.e(TAG, "getSystemService(POWER_SERVICE) unexpectedly returned NULL.");

View file

@ -24,9 +24,6 @@ public class FileUtils {
private static final String TAG = "FileUtils"; private static final String TAG = "FileUtils";
// TargetApi(21)
private static final Boolean isCompatible = (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP);
private FileUtils() { private FileUtils() {
// Private constructor to enforce Singleton pattern. // Private constructor to enforce Singleton pattern.
} }
@ -36,7 +33,6 @@ public class FileUtils {
private static final String HOME_VOLUME_NAME = "home"; private static final String HOME_VOLUME_NAME = "home";
@Nullable @Nullable
@TargetApi(21)
public static String getAbsolutePathFromSAFUri(Context context, @Nullable final Uri safResultUri) { public static String getAbsolutePathFromSAFUri(Context context, @Nullable final Uri safResultUri) {
Uri treeUri = DocumentsContract.buildDocumentUriUsingTree(safResultUri, Uri treeUri = DocumentsContract.buildDocumentUriUsingTree(safResultUri,
DocumentsContract.getTreeDocumentId(safResultUri)); DocumentsContract.getTreeDocumentId(safResultUri));
@ -45,10 +41,6 @@ public class FileUtils {
@Nullable @Nullable
public static String getAbsolutePathFromTreeUri(Context context, @Nullable final Uri treeUri) { public static String getAbsolutePathFromTreeUri(Context context, @Nullable final Uri treeUri) {
if (!isCompatible) {
Log.e(TAG, "getAbsolutePathFromTreeUri: called on unsupported API level");
return null;
}
if (treeUri == null) { if (treeUri == null) {
Log.w(TAG, "getAbsolutePathFromTreeUri: called with treeUri == null"); Log.w(TAG, "getAbsolutePathFromTreeUri: called with treeUri == null");
return null; return null;
@ -83,13 +75,7 @@ public class FileUtils {
} }
} }
@SuppressLint("ObsoleteSdkInt")
@TargetApi(21)
private static String getVolumePath(final String volumeId, Context context) { private static String getVolumePath(final String volumeId, Context context) {
if (!isCompatible) {
Log.e(TAG, "getVolumePath called on unsupported API level");
return null;
}
try { try {
if (HOME_VOLUME_NAME.equals(volumeId)) { if (HOME_VOLUME_NAME.equals(volumeId)) {
Log.v(TAG, "getVolumePath: isHomeVolume"); Log.v(TAG, "getVolumePath: isHomeVolume");
@ -136,8 +122,6 @@ public class FileUtils {
return null; return null;
} }
@SuppressLint("ObsoleteSdkInt")
@TargetApi(21)
private static String volumeToPath(Object storageVolumeElement, Class<?> storageVolumeClazz) throws Exception { private static String volumeToPath(Object storageVolumeElement, Class<?> storageVolumeClazz) throws Exception {
try { try {
// >= API level 30 // >= API level 30
@ -159,7 +143,6 @@ public class FileUtils {
* This is crucial to assist the user finding a writeable folder * This is crucial to assist the user finding a writeable folder
* to use syncthing's two way sync feature. * to use syncthing's two way sync feature.
*/ */
@TargetApi(19)
public static android.net.Uri getExternalFilesDirUri(Context context) { public static android.net.Uri getExternalFilesDirUri(Context context) {
try { try {
/** /**
@ -192,7 +175,6 @@ public class FileUtils {
return null; return null;
} }
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private static String getVolumeIdFromTreeUri(final Uri treeUri) { private static String getVolumeIdFromTreeUri(final Uri treeUri) {
final String docId = DocumentsContract.getTreeDocumentId(treeUri); final String docId = DocumentsContract.getTreeDocumentId(treeUri);
final String[] split = docId.split(":"); final String[] split = docId.split(":");
@ -203,7 +185,6 @@ public class FileUtils {
} }
} }
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private static String getDocumentPathFromTreeUri(final Uri treeUri) { private static String getDocumentPathFromTreeUri(final Uri treeUri) {
final String docId = DocumentsContract.getTreeDocumentId(treeUri); final String docId = DocumentsContract.getTreeDocumentId(treeUri);
final String[] split = docId.split(":"); final String[] split = docId.split(":");

View file

@ -66,7 +66,6 @@ public final class Languages {
* or different than the current system-wide locale. The preference is cleared * or different than the current system-wide locale. The preference is cleared
* if the language matches the system-wide locale or "System Default" is chosen. * if the language matches the system-wide locale or "System Default" is chosen.
*/ */
@TargetApi(17)
public void setLanguage(Context context) { public void setLanguage(Context context) {
String language = mPreferences.getString(PREFERENCE_LANGUAGE, null); String language = mPreferences.getString(PREFERENCE_LANGUAGE, null);
Locale locale; Locale locale;
@ -89,11 +88,7 @@ public final class Languages {
final Resources resources = context.getResources(); final Resources resources = context.getResources();
Configuration config = resources.getConfiguration(); Configuration config = resources.getConfiguration();
if (Build.VERSION.SDK_INT >= 17) {
config.setLocale(locale); config.setLocale(locale);
} else {
config.locale = locale;
}
resources.updateConfiguration(config, resources.getDisplayMetrics()); resources.updateConfiguration(config, resources.getDisplayMetrics());
} }