diff --git a/app/src/main/java/org/thoughtcrime/securesms/MediaOverviewActivity.java b/app/src/main/java/org/thoughtcrime/securesms/MediaOverviewActivity.java index 7715eab01e..8cb8fcd195 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/MediaOverviewActivity.java +++ b/app/src/main/java/org/thoughtcrime/securesms/MediaOverviewActivity.java @@ -39,7 +39,9 @@ import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.view.ActionMode; import androidx.appcompat.widget.Toolbar; +import androidx.core.content.ContextCompat; import androidx.fragment.app.Fragment; +import androidx.fragment.app.FragmentActivity; import androidx.fragment.app.FragmentManager; import androidx.fragment.app.FragmentStatePagerAdapter; import androidx.loader.app.LoaderManager; @@ -421,11 +423,13 @@ public class MediaOverviewActivity extends PassphraseRequiredActionBarActivity { mode.getMenuInflater().inflate(R.menu.media_overview_context, menu); mode.setTitle("1"); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { - Window window = getActivity().getWindow(); - originalStatusBarColor = window.getStatusBarColor(); - window.setStatusBarColor(getResources().getColor(R.color.action_mode_status_bar)); - } + FragmentActivity activity = getActivity(); + if (activity == null) return false; + + Window window = activity.getWindow(); + originalStatusBarColor = window.getStatusBarColor(); + window.setStatusBarColor(ContextCompat.getColor(activity, R.color.action_mode_status_bar)); + return true; } @@ -455,11 +459,12 @@ public class MediaOverviewActivity extends PassphraseRequiredActionBarActivity { public void onDestroyActionMode(ActionMode mode) { actionMode = null; getListAdapter().clearSelection(); - ((MediaOverviewActivity) getActivity()).onExitMultiSelect(); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { - getActivity().getWindow().setStatusBarColor(originalStatusBarColor); - } + MediaOverviewActivity activity = ((MediaOverviewActivity) getActivity()); + if(activity == null) return; + + activity.onExitMultiSelect(); + activity.getWindow().setStatusBarColor(originalStatusBarColor); } } } diff --git a/app/src/main/java/org/thoughtcrime/securesms/audio/AudioCodec.java b/app/src/main/java/org/thoughtcrime/securesms/audio/AudioCodec.java index 699e9ba973..64c7ac3df2 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/audio/AudioCodec.java +++ b/app/src/main/java/org/thoughtcrime/securesms/audio/AudioCodec.java @@ -1,22 +1,19 @@ package org.thoughtcrime.securesms.audio; -import android.annotation.TargetApi; import android.media.AudioFormat; import android.media.AudioRecord; import android.media.MediaCodec; import android.media.MediaCodecInfo; import android.media.MediaFormat; import android.media.MediaRecorder; -import android.os.Build; -import org.session.libsignal.utilities.Log; import org.session.libsession.utilities.Util; +import org.session.libsignal.utilities.Log; import java.io.IOException; import java.io.OutputStream; import java.nio.ByteBuffer; -@TargetApi(Build.VERSION_CODES.JELLY_BEAN) public class AudioCodec { private static final String TAG = AudioCodec.class.getSimpleName(); diff --git a/app/src/main/java/org/thoughtcrime/securesms/audio/AudioSlidePlayer.java b/app/src/main/java/org/thoughtcrime/securesms/audio/AudioSlidePlayer.java index 30f7c2303a..fe0f47c950 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/audio/AudioSlidePlayer.java +++ b/app/src/main/java/org/thoughtcrime/securesms/audio/AudioSlidePlayer.java @@ -46,7 +46,7 @@ public class AudioSlidePlayer implements SensorEventListener { private final @NonNull Handler progressEventHandler; private final @NonNull AudioManager audioManager; private final @NonNull SensorManager sensorManager; - private final @NonNull Sensor proximitySensor; + private final Sensor proximitySensor; private final @Nullable WakeLock wakeLock; private @NonNull WeakReference listener; @@ -83,11 +83,7 @@ public class AudioSlidePlayer implements SensorEventListener { this.sensorManager = (SensorManager)context.getSystemService(Context.SENSOR_SERVICE); this.proximitySensor = sensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY); - if (Build.VERSION.SDK_INT >= 21) { - this.wakeLock = ServiceUtil.getPowerManager(context).newWakeLock(PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK, TAG); - } else { - this.wakeLock = null; - } + this.wakeLock = ServiceUtil.getPowerManager(context).newWakeLock(PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK, TAG); } public void play(final double progress) throws IOException { @@ -137,7 +133,9 @@ public class AudioSlidePlayer implements SensorEventListener { mediaPlayer.seekTo((long) (mediaPlayer.getDuration() * progress)); } - sensorManager.registerListener(AudioSlidePlayer.this, proximitySensor, SensorManager.SENSOR_DELAY_NORMAL); + if(proximitySensor != null) { + sensorManager.registerListener(AudioSlidePlayer.this, proximitySensor, SensorManager.SENSOR_DELAY_NORMAL); + } setPlaying(AudioSlidePlayer.this); } @@ -163,9 +161,7 @@ public class AudioSlidePlayer implements SensorEventListener { sensorManager.unregisterListener(AudioSlidePlayer.this); if (wakeLock != null && wakeLock.isHeld()) { - if (Build.VERSION.SDK_INT >= 21) { - wakeLock.release(PowerManager.RELEASE_FLAG_WAIT_FOR_NO_PROXIMITY); - } + wakeLock.release(PowerManager.RELEASE_FLAG_WAIT_FOR_NO_PROXIMITY); } } @@ -190,9 +186,7 @@ public class AudioSlidePlayer implements SensorEventListener { sensorManager.unregisterListener(AudioSlidePlayer.this); if (wakeLock != null && wakeLock.isHeld()) { - if (Build.VERSION.SDK_INT >= 21) { - wakeLock.release(PowerManager.RELEASE_FLAG_WAIT_FOR_NO_PROXIMITY); - } + wakeLock.release(PowerManager.RELEASE_FLAG_WAIT_FOR_NO_PROXIMITY); } } @@ -331,7 +325,11 @@ public class AudioSlidePlayer implements SensorEventListener { int streamType; - if (event.values[0] < 5f && event.values[0] != proximitySensor.getMaximumRange()) { + if ( + proximitySensor != null && + event.values[0] < 5f && + event.values[0] != proximitySensor.getMaximumRange() + ) { streamType = AudioManager.STREAM_VOICE_CALL; } else { streamType = AudioManager.STREAM_MUSIC; diff --git a/app/src/main/java/org/thoughtcrime/securesms/components/AttachmentTypeSelector.java b/app/src/main/java/org/thoughtcrime/securesms/components/AttachmentTypeSelector.java index e56651db25..47f799bf95 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/components/AttachmentTypeSelector.java +++ b/app/src/main/java/org/thoughtcrime/securesms/components/AttachmentTypeSelector.java @@ -126,25 +126,19 @@ public class AttachmentTypeSelector extends PopupWindow { public void onGlobalLayout() { getContentView().getViewTreeObserver().removeGlobalOnLayoutListener(this); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { - animateWindowInCircular(anchor, getContentView()); - } else { - animateWindowInTranslate(getContentView()); - } + animateWindowInCircular(anchor, getContentView()); } }); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { - animateButtonIn(imageButton, ANIMATION_DURATION / 2); - animateButtonIn(cameraButton, ANIMATION_DURATION / 2); + animateButtonIn(imageButton, ANIMATION_DURATION / 2); + animateButtonIn(cameraButton, ANIMATION_DURATION / 2); - animateButtonIn(audioButton, ANIMATION_DURATION / 3); - animateButtonIn(locationButton, ANIMATION_DURATION / 3); - animateButtonIn(documentButton, ANIMATION_DURATION / 4); - animateButtonIn(gifButton, ANIMATION_DURATION / 4); - animateButtonIn(contactButton, 0); - animateButtonIn(closeButton, 0); - } + animateButtonIn(audioButton, ANIMATION_DURATION / 3); + animateButtonIn(locationButton, ANIMATION_DURATION / 3); + animateButtonIn(documentButton, ANIMATION_DURATION / 4); + animateButtonIn(gifButton, ANIMATION_DURATION / 4); + animateButtonIn(contactButton, 0); + animateButtonIn(closeButton, 0); } private void updateHeight() { @@ -159,11 +153,7 @@ public class AttachmentTypeSelector extends PopupWindow { @Override public void dismiss() { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { - animateWindowOutCircular(currentAnchor, getContentView()); - } else { - animateWindowOutTranslate(getContentView()); - } + animateWindowOutCircular(currentAnchor, getContentView()); } public void setListener(@Nullable AttachmentClickedListener listener) { diff --git a/app/src/main/java/org/thoughtcrime/securesms/components/ComposeText.java b/app/src/main/java/org/thoughtcrime/securesms/components/ComposeText.java index 42825360c0..2d9a48a9ea 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/components/ComposeText.java +++ b/app/src/main/java/org/thoughtcrime/securesms/components/ComposeText.java @@ -136,7 +136,6 @@ public class ComposeText extends EmojiEditText { editorInfo.imeOptions &= ~EditorInfo.IME_FLAG_NO_ENTER_ACTION; } - if (Build.VERSION.SDK_INT < 21) return inputConnection; if (mediaListener == null) return inputConnection; if (inputConnection == null) return null; diff --git a/app/src/main/java/org/thoughtcrime/securesms/components/SearchToolbar.java b/app/src/main/java/org/thoughtcrime/securesms/components/SearchToolbar.java index 9032b26a2b..07d0883bd2 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/components/SearchToolbar.java +++ b/app/src/main/java/org/thoughtcrime/securesms/components/SearchToolbar.java @@ -94,15 +94,11 @@ public class SearchToolbar extends LinearLayout { searchItem.expandActionView(); - if (Build.VERSION.SDK_INT >= 21) { - Animator animator = ViewAnimationUtils.createCircularReveal(this, (int)x, (int)y, 0, getWidth()); - animator.setDuration(400); + Animator animator = ViewAnimationUtils.createCircularReveal(this, (int)x, (int)y, 0, getWidth()); + animator.setDuration(400); - setVisibility(View.VISIBLE); - animator.start(); - } else { - setVisibility(View.VISIBLE); - } + setVisibility(View.VISIBLE); + animator.start(); } } @@ -116,19 +112,15 @@ public class SearchToolbar extends LinearLayout { if (listener != null) listener.onSearchClosed(); - if (Build.VERSION.SDK_INT >= 21) { - Animator animator = ViewAnimationUtils.createCircularReveal(this, (int)x, (int)y, getWidth(), 0); - animator.setDuration(400); - animator.addListener(new AnimationCompleteListener() { - @Override - public void onAnimationEnd(Animator animation) { - setVisibility(View.INVISIBLE); - } - }); - animator.start(); - } else { - setVisibility(View.INVISIBLE); - } + Animator animator = ViewAnimationUtils.createCircularReveal(this, (int)x, (int)y, getWidth(), 0); + animator.setDuration(400); + animator.addListener(new AnimationCompleteListener() { + @Override + public void onAnimationEnd(Animator animation) { + setVisibility(View.INVISIBLE); + } + }); + animator.start(); } } diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/input_bar/InputBarButton.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/input_bar/InputBarButton.kt index c88e05dbfb..d2ec4b2d69 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/input_bar/InputBarButton.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/input_bar/InputBarButton.kt @@ -148,11 +148,8 @@ class InputBarButton : RelativeLayout { private fun onDown(event: MotionEvent) { expand() - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - performHapticFeedback(HapticFeedbackConstants.CONTEXT_CLICK) - } else { - performHapticFeedback(HapticFeedbackConstants.LONG_PRESS) - } + performHapticFeedback(HapticFeedbackConstants.CONTEXT_CLICK) + longPressCallback?.let { gestureHandler.removeCallbacks(it) } val newLongPressCallback = Runnable { onLongPress?.invoke() } this.longPressCallback = newLongPressCallback diff --git a/app/src/main/java/org/thoughtcrime/securesms/crypto/AttachmentSecretProvider.java b/app/src/main/java/org/thoughtcrime/securesms/crypto/AttachmentSecretProvider.java index 1602ab3fcf..844ba975f1 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/crypto/AttachmentSecretProvider.java +++ b/app/src/main/java/org/thoughtcrime/securesms/crypto/AttachmentSecretProvider.java @@ -59,25 +59,17 @@ public class AttachmentSecretProvider { { AttachmentSecret attachmentSecret = AttachmentSecret.fromString(unencryptedSecret); - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { - return attachmentSecret; - } else { - KeyStoreHelper.SealedData encryptedSecret = KeyStoreHelper.seal(attachmentSecret.serialize().getBytes()); + KeyStoreHelper.SealedData encryptedSecret = KeyStoreHelper.seal(attachmentSecret.serialize().getBytes()); - TextSecurePreferences.setAttachmentEncryptedSecret(context, encryptedSecret.serialize()); - TextSecurePreferences.setAttachmentUnencryptedSecret(context, null); + TextSecurePreferences.setAttachmentEncryptedSecret(context, encryptedSecret.serialize()); + TextSecurePreferences.setAttachmentUnencryptedSecret(context, null); - return attachmentSecret; - } + return attachmentSecret; } private AttachmentSecret getEncryptedAttachmentSecret(@NonNull String serializedEncryptedSecret) { - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { - throw new AssertionError("OS downgrade not supported. KeyStore sealed data exists on platform < M!"); - } else { - KeyStoreHelper.SealedData encryptedSecret = KeyStoreHelper.SealedData.fromString(serializedEncryptedSecret); - return AttachmentSecret.fromString(new String(KeyStoreHelper.unseal(encryptedSecret))); - } + KeyStoreHelper.SealedData encryptedSecret = KeyStoreHelper.SealedData.fromString(serializedEncryptedSecret); + return AttachmentSecret.fromString(new String(KeyStoreHelper.unseal(encryptedSecret))); } private AttachmentSecret createAndStoreAttachmentSecret(@NonNull Context context) { @@ -91,12 +83,8 @@ public class AttachmentSecretProvider { } private void storeAttachmentSecret(@NonNull Context context, @NonNull AttachmentSecret attachmentSecret) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - KeyStoreHelper.SealedData encryptedSecret = KeyStoreHelper.seal(attachmentSecret.serialize().getBytes()); - TextSecurePreferences.setAttachmentEncryptedSecret(context, encryptedSecret.serialize()); - } else { - TextSecurePreferences.setAttachmentUnencryptedSecret(context, attachmentSecret.serialize()); - } + KeyStoreHelper.SealedData encryptedSecret = KeyStoreHelper.seal(attachmentSecret.serialize().getBytes()); + TextSecurePreferences.setAttachmentEncryptedSecret(context, encryptedSecret.serialize()); } } diff --git a/app/src/main/java/org/thoughtcrime/securesms/crypto/DatabaseSecretProvider.java b/app/src/main/java/org/thoughtcrime/securesms/crypto/DatabaseSecretProvider.java index 44bb33161c..ab79f7ea55 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/crypto/DatabaseSecretProvider.java +++ b/app/src/main/java/org/thoughtcrime/securesms/crypto/DatabaseSecretProvider.java @@ -36,28 +36,20 @@ public class DatabaseSecretProvider { try { DatabaseSecret databaseSecret = new DatabaseSecret(unencryptedSecret); - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { - return databaseSecret; - } else { - KeyStoreHelper.SealedData encryptedSecret = KeyStoreHelper.seal(databaseSecret.asBytes()); + KeyStoreHelper.SealedData encryptedSecret = KeyStoreHelper.seal(databaseSecret.asBytes()); - TextSecurePreferences.setDatabaseEncryptedSecret(context, encryptedSecret.serialize()); - TextSecurePreferences.setDatabaseUnencryptedSecret(context, null); + TextSecurePreferences.setDatabaseEncryptedSecret(context, encryptedSecret.serialize()); + TextSecurePreferences.setDatabaseUnencryptedSecret(context, null); - return databaseSecret; - } + return databaseSecret; } catch (IOException e) { throw new AssertionError(e); } } private DatabaseSecret getEncryptedDatabaseSecret(@NonNull String serializedEncryptedSecret) { - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { - throw new AssertionError("OS downgrade not supported. KeyStore sealed data exists on platform < M!"); - } else { - KeyStoreHelper.SealedData encryptedSecret = KeyStoreHelper.SealedData.fromString(serializedEncryptedSecret); - return new DatabaseSecret(KeyStoreHelper.unseal(encryptedSecret)); - } + KeyStoreHelper.SealedData encryptedSecret = KeyStoreHelper.SealedData.fromString(serializedEncryptedSecret); + return new DatabaseSecret(KeyStoreHelper.unseal(encryptedSecret)); } private DatabaseSecret createAndStoreDatabaseSecret(@NonNull Context context) { @@ -66,12 +58,8 @@ public class DatabaseSecretProvider { DatabaseSecret databaseSecret = new DatabaseSecret(secret); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - KeyStoreHelper.SealedData encryptedSecret = KeyStoreHelper.seal(databaseSecret.asBytes()); - TextSecurePreferences.setDatabaseEncryptedSecret(context, encryptedSecret.serialize()); - } else { - TextSecurePreferences.setDatabaseUnencryptedSecret(context, databaseSecret.asString()); - } + KeyStoreHelper.SealedData encryptedSecret = KeyStoreHelper.seal(databaseSecret.asBytes()); + TextSecurePreferences.setDatabaseEncryptedSecret(context, encryptedSecret.serialize()); return databaseSecret; } diff --git a/app/src/main/java/org/thoughtcrime/securesms/crypto/IdentityKeyUtil.java b/app/src/main/java/org/thoughtcrime/securesms/crypto/IdentityKeyUtil.java index 62aaf58f1a..4db46a3abc 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/crypto/IdentityKeyUtil.java +++ b/app/src/main/java/org/thoughtcrime/securesms/crypto/IdentityKeyUtil.java @@ -129,27 +129,19 @@ public class IdentityKeyUtil { } private static String getUnencryptedSecret(String key, String unencryptedSecret, Context context) { - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { - return unencryptedSecret; - } else { - KeyStoreHelper.SealedData encryptedSecret = KeyStoreHelper.seal(unencryptedSecret.getBytes()); + KeyStoreHelper.SealedData encryptedSecret = KeyStoreHelper.seal(unencryptedSecret.getBytes()); - // save the encrypted suffix secret "key_encrypted" - save(context,key+ENCRYPTED_SUFFIX,encryptedSecret.serialize()); - // delete the regular secret "key" - delete(context,key); + // save the encrypted suffix secret "key_encrypted" + save(context,key+ENCRYPTED_SUFFIX,encryptedSecret.serialize()); + // delete the regular secret "key" + delete(context,key); - return unencryptedSecret; - } + return unencryptedSecret; } private static String getEncryptedSecret(String encryptedSecret) { - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { - throw new AssertionError("OS downgrade not supported. KeyStore sealed data exists on platform < M!"); - } else { - KeyStoreHelper.SealedData sealedData = KeyStoreHelper.SealedData.fromString(encryptedSecret); - return new String(KeyStoreHelper.unseal(sealedData)); - } + KeyStoreHelper.SealedData sealedData = KeyStoreHelper.SealedData.fromString(encryptedSecret); + return new String(KeyStoreHelper.unseal(sealedData)); } @@ -157,17 +149,14 @@ public class IdentityKeyUtil { SharedPreferences preferences = context.getSharedPreferences(MASTER_SECRET_UTIL_PREFERENCES_NAME, 0); Editor preferencesEditor = preferences.edit(); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - boolean isEncryptedSuffix = key.endsWith(ENCRYPTED_SUFFIX); - if (isEncryptedSuffix) { - preferencesEditor.putString(key, value); - } else { - KeyStoreHelper.SealedData encryptedSecret = KeyStoreHelper.seal(value.getBytes()); - preferencesEditor.putString(key+ENCRYPTED_SUFFIX, encryptedSecret.serialize()); - } - } else { + boolean isEncryptedSuffix = key.endsWith(ENCRYPTED_SUFFIX); + if (isEncryptedSuffix) { preferencesEditor.putString(key, value); + } else { + KeyStoreHelper.SealedData encryptedSecret = KeyStoreHelper.seal(value.getBytes()); + preferencesEditor.putString(key+ENCRYPTED_SUFFIX, encryptedSecret.serialize()); } + if (!preferencesEditor.commit()) throw new AssertionError("failed to save identity key/value to shared preferences"); } diff --git a/app/src/main/java/org/thoughtcrime/securesms/database/AttachmentDatabase.java b/app/src/main/java/org/thoughtcrime/securesms/database/AttachmentDatabase.java index 45172e2f6f..5d7301261e 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/database/AttachmentDatabase.java +++ b/app/src/main/java/org/thoughtcrime/securesms/database/AttachmentDatabase.java @@ -966,11 +966,6 @@ public class AttachmentDatabase extends Database { @SuppressLint("NewApi") private ThumbnailData generateVideoThumbnail(AttachmentId attachmentId) { - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { - Log.w(TAG, "Video thumbnails not supported..."); - return null; - } - DataInfo dataInfo = getAttachmentDataFileInfo(attachmentId, DATA); if (dataInfo == null) { diff --git a/app/src/main/java/org/thoughtcrime/securesms/home/PathActivity.kt b/app/src/main/java/org/thoughtcrime/securesms/home/PathActivity.kt index db0c4d11cc..e65f2d2f26 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/home/PathActivity.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/home/PathActivity.kt @@ -15,6 +15,7 @@ import android.widget.RelativeLayout import android.widget.TextView import android.widget.Toast import androidx.annotation.ColorRes +import androidx.core.content.ContextCompat import androidx.localbroadcastmanager.content.LocalBroadcastManager import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.GlobalScope @@ -38,7 +39,6 @@ import org.thoughtcrime.securesms.util.disableClipping import org.thoughtcrime.securesms.util.fadeIn import org.thoughtcrime.securesms.util.fadeOut import org.thoughtcrime.securesms.util.getAccentColor -import org.thoughtcrime.securesms.util.getColorWithID class PathActivity : PassphraseRequiredActionBarActivity() { private lateinit var binding: ActivityPathBinding @@ -283,7 +283,7 @@ class PathActivity : PassphraseRequiredActionBarActivity() { private fun expand() { dotView.animateSizeChange(R.dimen.path_row_dot_size, R.dimen.path_row_expanded_dot_size) @ColorRes val startColorID = if (UiModeUtilities.isDayUiMode(context)) R.color.transparent_black_30 else R.color.black - val startColor = context.resources.getColorWithID(startColorID, context.theme) + val startColor = ContextCompat.getColor(context, startColorID) val endColor = context.getAccentColor() GlowViewUtilities.animateShadowColorChange(dotView, startColor, endColor) } @@ -292,7 +292,7 @@ class PathActivity : PassphraseRequiredActionBarActivity() { dotView.animateSizeChange(R.dimen.path_row_expanded_dot_size, R.dimen.path_row_dot_size) @ColorRes val endColorID = if (UiModeUtilities.isDayUiMode(context)) R.color.transparent_black_30 else R.color.black val startColor = context.getAccentColor() - val endColor = context.resources.getColorWithID(endColorID, context.theme) + val endColor = ContextCompat.getColor(context, endColorID) GlowViewUtilities.animateShadowColorChange(dotView, startColor, endColor) } diff --git a/app/src/main/java/org/thoughtcrime/securesms/home/PathStatusView.kt b/app/src/main/java/org/thoughtcrime/securesms/home/PathStatusView.kt index 7ab7bfb508..1c31a2ee17 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/home/PathStatusView.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/home/PathStatusView.kt @@ -9,6 +9,7 @@ import android.graphics.Paint import android.util.AttributeSet import android.view.View import androidx.annotation.ColorInt +import androidx.core.content.ContextCompat import androidx.lifecycle.coroutineScope import androidx.localbroadcastmanager.content.LocalBroadcastManager import kotlinx.coroutines.Dispatchers @@ -17,7 +18,6 @@ import kotlinx.coroutines.withContext import network.loki.messenger.R import org.session.libsession.snode.OnionRequestAPI import org.thoughtcrime.securesms.conversation.v2.ViewUtil -import org.thoughtcrime.securesms.util.getColorWithID import org.thoughtcrime.securesms.util.toPx class PathStatusView : View { @@ -104,7 +104,7 @@ class PathStatusView : View { sessionShadowColor = hasPathsColor } else { setBackgroundResource(R.drawable.paths_building_dot) - val pathsBuildingColor = resources.getColorWithID(R.color.paths_building, context.theme) + val pathsBuildingColor = ContextCompat.getColor(context, R.color.paths_building) mainColor = pathsBuildingColor sessionShadowColor = pathsBuildingColor } diff --git a/app/src/main/java/org/thoughtcrime/securesms/logging/LogSecretProvider.java b/app/src/main/java/org/thoughtcrime/securesms/logging/LogSecretProvider.java index 763a2a430d..533e1a1d23 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/logging/LogSecretProvider.java +++ b/app/src/main/java/org/thoughtcrime/securesms/logging/LogSecretProvider.java @@ -32,24 +32,16 @@ class LogSecretProvider { } private static byte[] parseEncryptedSecret(String secret) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - KeyStoreHelper.SealedData encryptedSecret = KeyStoreHelper.SealedData.fromString(secret); - return KeyStoreHelper.unseal(encryptedSecret); - } else { - throw new AssertionError("OS downgrade not supported. KeyStore sealed data exists on platform < M!"); - } + KeyStoreHelper.SealedData encryptedSecret = KeyStoreHelper.SealedData.fromString(secret); + return KeyStoreHelper.unseal(encryptedSecret); } private static byte[] createAndStoreSecret(@NonNull Context context) { byte[] secret = new byte[32]; SECURE_RANDOM.nextBytes(secret); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - KeyStoreHelper.SealedData encryptedSecret = KeyStoreHelper.seal(secret); - TextSecurePreferences.setLogEncryptedSecret(context, encryptedSecret.serialize()); - } else { - TextSecurePreferences.setLogUnencryptedSecret(context, Base64.encodeBytes(secret)); - } + KeyStoreHelper.SealedData encryptedSecret = KeyStoreHelper.seal(secret); + TextSecurePreferences.setLogEncryptedSecret(context, encryptedSecret.serialize()); return secret; } diff --git a/app/src/main/java/org/thoughtcrime/securesms/util/FileProviderUtil.java b/app/src/main/java/org/thoughtcrime/securesms/util/FileProviderUtil.java index ed28c7c2e2..c05832352a 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/util/FileProviderUtil.java +++ b/app/src/main/java/org/thoughtcrime/securesms/util/FileProviderUtil.java @@ -14,10 +14,7 @@ public class FileProviderUtil { private static final String AUTHORITY = "network.loki.securesms.fileprovider"; public static Uri getUriFor(@NonNull Context context, @NonNull File file) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) - return FileProvider.getUriForFile(context, AUTHORITY, file); - else - return Uri.fromFile(file); + return FileProvider.getUriForFile(context, AUTHORITY, file); } public static boolean delete(@NonNull Context context, @NonNull Uri uri) { diff --git a/app/src/main/java/org/thoughtcrime/securesms/util/GeneralUtilities.kt b/app/src/main/java/org/thoughtcrime/securesms/util/GeneralUtilities.kt index 9124765763..cc40e0cc92 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/util/GeneralUtilities.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/util/GeneralUtilities.kt @@ -1,20 +1,9 @@ package org.thoughtcrime.securesms.util import android.content.res.Resources -import android.os.Build -import androidx.annotation.ColorRes import androidx.recyclerview.widget.RecyclerView -import kotlin.math.max import kotlin.math.roundToInt -fun Resources.getColorWithID(@ColorRes id: Int, theme: Resources.Theme?): Int { - return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - getColor(id, theme) - } else { - @Suppress("DEPRECATION") getColor(id) - } -} - fun toPx(dp: Int, resources: Resources): Int { return toPx(dp.toFloat(), resources).roundToInt() } diff --git a/app/src/main/java/org/thoughtcrime/securesms/util/GlowView.kt b/app/src/main/java/org/thoughtcrime/securesms/util/GlowView.kt index a0c0da24fe..46ad821233 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/util/GlowView.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/util/GlowView.kt @@ -11,7 +11,6 @@ import android.view.animation.AccelerateDecelerateInterpolator import android.widget.LinearLayout import android.widget.RelativeLayout import androidx.annotation.ColorInt -import androidx.annotation.ColorRes import network.loki.messenger.R import kotlin.math.roundToInt @@ -22,18 +21,6 @@ interface GlowView { object GlowViewUtilities { - fun animateColorIdChange(context: Context, view: GlowView, @ColorRes startColorID: Int, @ColorRes endColorID: Int) { - val startColor = context.resources.getColorWithID(startColorID, context.theme) - val endColor = context.resources.getColorWithID(endColorID, context.theme) - val animation = ValueAnimator.ofObject(ArgbEvaluator(), startColor, endColor) - animation.duration = 250 - animation.addUpdateListener { animator -> - val color = animator.animatedValue as Int - view.mainColor = color - } - animation.start() - } - fun animateColorChange(view: GlowView, @ColorInt startColor: Int, @ColorInt endColor: Int) { val animation = ValueAnimator.ofObject(ArgbEvaluator(), startColor, endColor) animation.duration = 250 @@ -44,18 +31,6 @@ object GlowViewUtilities { animation.start() } - fun animateShadowColorIdChange(context: Context, view: GlowView, @ColorRes startColorID: Int, @ColorRes endColorID: Int) { - val startColor = context.resources.getColorWithID(startColorID, context.theme) - val endColor = context.resources.getColorWithID(endColorID, context.theme) - val animation = ValueAnimator.ofObject(ArgbEvaluator(), startColor, endColor) - animation.duration = 250 - animation.addUpdateListener { animator -> - val color = animator.animatedValue as Int - view.sessionShadowColor = color - } - animation.start() - } - fun animateShadowColorChange( view: GlowView, @ColorInt startColor: Int, diff --git a/app/src/main/java/org/thoughtcrime/securesms/video/EncryptedMediaDataSource.java b/app/src/main/java/org/thoughtcrime/securesms/video/EncryptedMediaDataSource.java index 8a3d2c3f74..78541e02a4 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/video/EncryptedMediaDataSource.java +++ b/app/src/main/java/org/thoughtcrime/securesms/video/EncryptedMediaDataSource.java @@ -1,22 +1,20 @@ package org.thoughtcrime.securesms.video; -import android.annotation.TargetApi; import android.media.MediaDataSource; -import android.os.Build; + import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import org.session.libsession.utilities.Util; import org.thoughtcrime.securesms.crypto.AttachmentSecret; import org.thoughtcrime.securesms.crypto.ClassicDecryptingPartInputStream; import org.thoughtcrime.securesms.crypto.ModernDecryptingPartInputStream; -import org.session.libsession.utilities.Util; import java.io.File; import java.io.IOException; import java.io.InputStream; -@TargetApi(Build.VERSION_CODES.M) public class EncryptedMediaDataSource extends MediaDataSource { private final AttachmentSecret attachmentSecret;