1
0
Fork 0
mirror of https://github.com/syncthing/syncthing-android.git synced 2024-11-22 04:11:14 +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 Folder mFolder;
// Contains SAF readwrite access URI on API level >= Build.VERSION_CODES.LOLLIPOP (21)
private Uri mFolderUri = null;
// Indicates the result of the write test to mFolder.path on dialog init or after a path change.
Boolean mCanWriteToPath = false;
@ -216,12 +215,6 @@ public class FolderActivity extends SyncthingActivity
*/
@SuppressLint("InlinedAPI")
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.
android.net.Uri externalFilesDirUri = FileUtils.getExternalFilesDirUri(FolderActivity.this);
@ -460,8 +453,7 @@ public class FolderActivity extends SyncthingActivity
.show();
return true;
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP &&
mFolderUri != null) {
if (mFolderUri != null) {
/**
* Normally, syncthing takes care of creating the ".stfolder" marker.
* 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);
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();
if (mFolderUri == null) {
return;

View file

@ -139,11 +139,6 @@ public class Constants {
* to syncthing core v0.14.53+.
*/
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) {
/**
* 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));
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());
}
}

View file

@ -91,11 +91,9 @@ public class RunConditionMonitor {
ReceiverManager.registerReceiver(mContext, new BatteryReceiver(), filter);
// PowerSaveModeChangedReceiver
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
ReceiverManager.registerReceiver(mContext,
new PowerSaveModeChangedReceiver(),
new IntentFilter(PowerManager.ACTION_POWER_SAVE_MODE_CHANGED));
}
ReceiverManager.registerReceiver(mContext,
new PowerSaveModeChangedReceiver(),
new IntentFilter(PowerManager.ACTION_POWER_SAVE_MODE_CHANGED));
// SyncStatusObserver to monitor android's "AutoSync" quick toggle.
mSyncStatusObserverHandle = ContentResolver.addStatusChangeListener(
@ -207,11 +205,9 @@ public class RunConditionMonitor {
}
// Power saving
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
if (prefRespectPowerSaving && isPowerSaving()) {
Log.v(TAG, "decideShouldRun: prefRespectPowerSaving && isPowerSaving");
blockerReasons.add(POWERSAVING_ENABLED);
}
if (prefRespectPowerSaving && isPowerSaving()) {
Log.v(TAG, "decideShouldRun: prefRespectPowerSaving && isPowerSaving");
blockerReasons.add(POWERSAVING_ENABLED);
}
// Android global AutoSync setting.
@ -298,38 +294,14 @@ public class RunConditionMonitor {
* Functions for run condition information retrieval.
*/
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));
int plugged = intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1);
return plugged == BatteryManager.BATTERY_PLUGGED_AC ||
plugged == BatteryManager.BATTERY_PLUGGED_USB ||
plugged == BatteryManager.BATTERY_PLUGGED_WIRELESS;
plugged == BatteryManager.BATTERY_PLUGGED_USB ||
plugged == BatteryManager.BATTERY_PLUGGED_WIRELESS;
}
@TargetApi(21)
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);
if (powerManager == 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";
// TargetApi(21)
private static final Boolean isCompatible = (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP);
private FileUtils() {
// Private constructor to enforce Singleton pattern.
}
@ -36,7 +33,6 @@ public class FileUtils {
private static final String HOME_VOLUME_NAME = "home";
@Nullable
@TargetApi(21)
public static String getAbsolutePathFromSAFUri(Context context, @Nullable final Uri safResultUri) {
Uri treeUri = DocumentsContract.buildDocumentUriUsingTree(safResultUri,
DocumentsContract.getTreeDocumentId(safResultUri));
@ -45,10 +41,6 @@ public class FileUtils {
@Nullable
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) {
Log.w(TAG, "getAbsolutePathFromTreeUri: called with treeUri == null");
return null;
@ -83,13 +75,7 @@ public class FileUtils {
}
}
@SuppressLint("ObsoleteSdkInt")
@TargetApi(21)
private static String getVolumePath(final String volumeId, Context context) {
if (!isCompatible) {
Log.e(TAG, "getVolumePath called on unsupported API level");
return null;
}
try {
if (HOME_VOLUME_NAME.equals(volumeId)) {
Log.v(TAG, "getVolumePath: isHomeVolume");
@ -136,8 +122,6 @@ public class FileUtils {
return null;
}
@SuppressLint("ObsoleteSdkInt")
@TargetApi(21)
private static String volumeToPath(Object storageVolumeElement, Class<?> storageVolumeClazz) throws Exception {
try {
// >= API level 30
@ -159,7 +143,6 @@ public class FileUtils {
* This is crucial to assist the user finding a writeable folder
* to use syncthing's two way sync feature.
*/
@TargetApi(19)
public static android.net.Uri getExternalFilesDirUri(Context context) {
try {
/**
@ -192,7 +175,6 @@ public class FileUtils {
return null;
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private static String getVolumeIdFromTreeUri(final Uri treeUri) {
final String docId = DocumentsContract.getTreeDocumentId(treeUri);
final String[] split = docId.split(":");
@ -203,7 +185,6 @@ public class FileUtils {
}
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private static String getDocumentPathFromTreeUri(final Uri treeUri) {
final String docId = DocumentsContract.getTreeDocumentId(treeUri);
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
* if the language matches the system-wide locale or "System Default" is chosen.
*/
@TargetApi(17)
public void setLanguage(Context context) {
String language = mPreferences.getString(PREFERENCE_LANGUAGE, null);
Locale locale;
@ -89,11 +88,7 @@ public final class Languages {
final Resources resources = context.getResources();
Configuration config = resources.getConfiguration();
if (Build.VERSION.SDK_INT >= 17) {
config.setLocale(locale);
} else {
config.locale = locale;
}
config.setLocale(locale);
resources.updateConfiguration(config, resources.getDisplayMetrics());
}