From b1057d63a18c53c76a3ba1bd3130cd4ca3aa5d19 Mon Sep 17 00:00:00 2001 From: Alan Evans Date: Wed, 8 May 2019 08:45:57 -0300 Subject: [PATCH] Lint. - Check for permissions. - Fix Welsh positional format. - Remove UIThread restriction. - Asynchronous method does not need to be restricted to UIThread and there is no StaticFieldLeak to suppress. - Fix or Ignore New API errors. - Reduce severity of some errors from L10N. --- .gitignore | 1 - lint.xml | 14 ++++++++++++++ res/values-cy/strings.xml | 10 +++++----- res/values/styles.xml | 6 +++--- res/values/text_styles.xml | 10 +++++----- res/values/themes.xml | 2 +- .../securesms/ConfirmIdentityDialog.java | 2 +- .../securesms/audio/AudioSlidePlayer.java | 8 ++++++-- .../securesms/mms/LegacyMmsConnection.java | 19 ++++++++++++++++++- .../securesms/util/IdentityUtil.java | 4 ---- 10 files changed, 53 insertions(+), 23 deletions(-) create mode 100644 lint.xml diff --git a/.gitignore b/.gitignore index b420a5688..4b62fc423 100644 --- a/.gitignore +++ b/.gitignore @@ -8,7 +8,6 @@ gen/ *.iml out tests -lint.xml local.properties ant.properties .DS_Store diff --git a/lint.xml b/lint.xml new file mode 100644 index 000000000..1261b667e --- /dev/null +++ b/lint.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/res/values-cy/strings.xml b/res/values-cy/strings.xml index 0fb18893d..8ec7115db 100644 --- a/res/values-cy/strings.xml +++ b/res/values-cy/strings.xml @@ -85,7 +85,7 @@ Heb ganfod porwr gwe. - Mae\'ch rhif diogelwch gyda %1$s wedi newid. Gall hyn olygu bod rhywun yn ceisio ymyrryd a\'ch cyfathrebu, neu bod % ​2$s wedi cael ei ail-osod. + Mae\'ch rhif diogelwch gyda %1$s wedi newid. Gall hyn olygu bod rhywun yn ceisio ymyrryd a\'ch cyfathrebu, neu bod %2$s wedi cael ei ail-osod. Efallai yr hoffech wirio\'ch rhif diogelwch gyda\'r cyswllt hwn. Derbyn @@ -868,10 +868,10 @@ Send neges heb ei ddiogelu? Mae\'ch rhif diogelwch gyda %1$s wedi newid ac nid yw wedi\'i dilysu bellach. Nid yw eich rhif diogelwch gyda %1$s a %2$s wedi\'i dilysu bellach - Nid yw eich rhifau diogelwch gyda %1$s,%2$s, a %3$s bellach yn cael eu gwirio - Mae\'ch rhif diogelwch gyda %1$s wedi newid ac nid yw wedi\'i dilysu bellach. Gall hyn olygu bod rhywun yn ceisio rhyng-gipio eich cyfathrebu, neu bod %​1$s wedi ail-osod Signal. - Nid yw eich rhif diogelwch gyda %1$s wedi\'i dilysu bellach. Gall hyn olygu bod rhywun yn ceisio rhyng-gipio eich cyfathrebu, neu bod %​1$s wedi ail-osod Signal. - Nid yw eich rhifau diogelwch gyda %1$s, %2$s, a %3$s bellach yn cael eu gwirio. Gall hyn olygu bod rhywun yn ceisio rhyng-gipio eich cyfathrebu, neu bod %​1$s wedi ail-osod Signal. + Nid yw eich rhifau diogelwch gyda %1$s, %2$s, a %3$s bellach yn cael eu gwirio + Mae\'ch rhif diogelwch gyda %1$s wedi newid ac nid yw wedi\'i dilysu bellach. Gall hyn olygu bod rhywun yn ceisio rhyng-gipio eich cyfathrebu, neu bod %1$s wedi ail-osod Signal. + Mae\'ch rhifau diogelwch gyda %1$s a %2$s wedi\'i dilysu bellach. Gall hyn olygu bod rhywun yn ceisio rhyng-gipio eich cyfathrebu, neu bod nhw wedi ail-osod Signal. + Mae\'ch rhifau diogelwch gyda %1$s, %2$s, a %3$s wedi\'i dilysi bellach. Gall hyn olygu bod rhywun yn ceisio rhyng-gipio eich cyfathrebu, neu bod nhw wedi ail-osod Signal. Mae\'ch rhif diogelwch gyda %1$s wedi newid yn ddiweddar. Mae\'ch rhif diogelwch gyda %1$s wedi newid yn ddiweddar. Mae\'ch rhif diogelwch gyda %1$s a %3$s wedi newid. diff --git a/res/values/styles.xml b/res/values/styles.xml index 75d8382c9..a9aaf9d78 100644 --- a/res/values/styles.xml +++ b/res/values/styles.xml @@ -42,7 +42,7 @@ diff --git a/res/values/text_styles.xml b/res/values/text_styles.xml index c020c7bc9..544cd22c7 100644 --- a/res/values/text_styles.xml +++ b/res/values/text_styles.xml @@ -1,10 +1,10 @@ - + diff --git a/res/values/themes.xml b/res/values/themes.xml index f08fd9b7c..093d7a613 100644 --- a/res/values/themes.xml +++ b/res/values/themes.xml @@ -34,7 +34,7 @@ @style/ThemeOverlay.AppCompat.Dark @color/gray95 @color/signal_primary_dark - @color/signal_primary_dark + @color/signal_primary_dark #d00000 #66eeeeee diff --git a/src/org/thoughtcrime/securesms/ConfirmIdentityDialog.java b/src/org/thoughtcrime/securesms/ConfirmIdentityDialog.java index e8d2bc0f8..1615dee48 100644 --- a/src/org/thoughtcrime/securesms/ConfirmIdentityDialog.java +++ b/src/org/thoughtcrime/securesms/ConfirmIdentityDialog.java @@ -48,7 +48,7 @@ public class ConfirmIdentityDialog extends AlertDialog { Recipient recipient = Recipient.from(context, mismatch.getAddress(), false); String name = recipient.toShortString(); - String introduction = String.format(context.getString(R.string.ConfirmIdentityDialog_your_safety_number_with_s_has_changed), name, name); + String introduction = context.getString(R.string.ConfirmIdentityDialog_your_safety_number_with_s_has_changed, name, name); SpannableString spannableString = new SpannableString(introduction + " " + context.getString(R.string.ConfirmIdentityDialog_you_may_wish_to_verify_your_safety_number_with_this_contact)); diff --git a/src/org/thoughtcrime/securesms/audio/AudioSlidePlayer.java b/src/org/thoughtcrime/securesms/audio/AudioSlidePlayer.java index 66d46dd21..9f939feaf 100644 --- a/src/org/thoughtcrime/securesms/audio/AudioSlidePlayer.java +++ b/src/org/thoughtcrime/securesms/audio/AudioSlidePlayer.java @@ -161,7 +161,9 @@ public class AudioSlidePlayer implements SensorEventListener { sensorManager.unregisterListener(AudioSlidePlayer.this); if (wakeLock != null && wakeLock.isHeld()) { - wakeLock.release(PowerManager.RELEASE_FLAG_WAIT_FOR_NO_PROXIMITY); + if (Build.VERSION.SDK_INT >= 21) { + wakeLock.release(PowerManager.RELEASE_FLAG_WAIT_FOR_NO_PROXIMITY); + } } } @@ -187,7 +189,9 @@ public class AudioSlidePlayer implements SensorEventListener { sensorManager.unregisterListener(AudioSlidePlayer.this); if (wakeLock != null && wakeLock.isHeld()) { - wakeLock.release(PowerManager.RELEASE_FLAG_WAIT_FOR_NO_PROXIMITY); + if (Build.VERSION.SDK_INT >= 21) { + wakeLock.release(PowerManager.RELEASE_FLAG_WAIT_FOR_NO_PROXIMITY); + } } } diff --git a/src/org/thoughtcrime/securesms/mms/LegacyMmsConnection.java b/src/org/thoughtcrime/securesms/mms/LegacyMmsConnection.java index 1067978b7..7068c3795 100644 --- a/src/org/thoughtcrime/securesms/mms/LegacyMmsConnection.java +++ b/src/org/thoughtcrime/securesms/mms/LegacyMmsConnection.java @@ -16,10 +16,16 @@ */ package org.thoughtcrime.securesms.mms; +import android.Manifest; +import android.annotation.SuppressLint; import android.content.Context; +import android.content.pm.PackageManager; import android.net.ConnectivityManager; +import android.support.annotation.NonNull; +import android.support.v4.app.ActivityCompat; import android.telephony.TelephonyManager; import android.text.TextUtils; + import org.thoughtcrime.securesms.logging.Log; import org.apache.http.Header; @@ -209,7 +215,7 @@ public abstract class LegacyMmsConnection { } protected List
getBaseHeaders() { - final String number = TelephonyUtil.getManager(context).getLine1Number(); ; + final String number = getLine1Number(context); return new LinkedList
() {{ add(new BasicHeader("Accept", "*/*, application/vnd.wap.mms-message, application/vnd.wap.sic")); @@ -223,6 +229,17 @@ public abstract class LegacyMmsConnection { }}; } + @SuppressLint("HardwareIds") + private static String getLine1Number(@NonNull Context context) { + if (ActivityCompat.checkSelfPermission(context, Manifest.permission.READ_SMS) == PackageManager.PERMISSION_GRANTED || + ActivityCompat.checkSelfPermission(context, Manifest.permission.READ_PHONE_NUMBERS) == PackageManager.PERMISSION_GRANTED || + ActivityCompat.checkSelfPermission(context, Manifest.permission.READ_PHONE_STATE) == PackageManager.PERMISSION_GRANTED) { + return TelephonyUtil.getManager(context).getLine1Number(); + } else { + return ""; + } + } + public static class Apn { public static Apn EMPTY = new Apn("", "", "", "", ""); diff --git a/src/org/thoughtcrime/securesms/util/IdentityUtil.java b/src/org/thoughtcrime/securesms/util/IdentityUtil.java index de458f9ce..89ce2e599 100644 --- a/src/org/thoughtcrime/securesms/util/IdentityUtil.java +++ b/src/org/thoughtcrime/securesms/util/IdentityUtil.java @@ -1,12 +1,10 @@ package org.thoughtcrime.securesms.util; -import android.annotation.SuppressLint; import android.content.Context; import android.os.AsyncTask; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.annotation.StringRes; -import android.support.annotation.UiThread; import org.thoughtcrime.securesms.R; import org.thoughtcrime.securesms.crypto.storage.TextSecureIdentityKeyStore; @@ -47,8 +45,6 @@ public class IdentityUtil { private static final String TAG = IdentityUtil.class.getSimpleName(); - @SuppressLint("StaticFieldLeak") - @UiThread public static ListenableFuture> getRemoteIdentityKey(final Context context, final Recipient recipient) { final SettableFuture> future = new SettableFuture<>();