aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorHarsh Shandilya <me@msfjarvis.dev>2020-04-15 23:49:57 +0530
committerHarsh Shandilya <me@msfjarvis.dev>2020-04-16 23:21:28 +0530
commitaa2d170653ddfebeb909234eaaaa0c16c49a40bb (patch)
treea8292f051422a4d21752d282a0e18691bb49cb3b
parentui: animate fab scale rather than translation (diff)
downloadwireguard-android-nullity-analysis.tar.xz
wireguard-android-nullity-analysis.zip
WIP nullability cleanupnullity-analysis
Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
-rw-r--r--ui/src/main/java/com/wireguard/android/Application.kt7
-rw-r--r--ui/src/main/java/com/wireguard/android/QuickTileService.kt8
-rw-r--r--ui/src/main/java/com/wireguard/android/activity/BaseActivity.kt2
-rw-r--r--ui/src/main/java/com/wireguard/android/activity/MainActivity.kt7
-rw-r--r--ui/src/main/java/com/wireguard/android/databinding/ItemChangeListener.kt3
-rw-r--r--ui/src/main/java/com/wireguard/android/databinding/ObservableKeyedArrayList.kt2
-rw-r--r--ui/src/main/java/com/wireguard/android/fragment/TunnelDetailFragment.kt18
-rw-r--r--ui/src/main/java/com/wireguard/android/util/BiometricAuthenticator.kt3
-rw-r--r--ui/src/main/java/com/wireguard/android/util/DownloadsFileSaver.kt4
9 files changed, 29 insertions, 25 deletions
diff --git a/ui/src/main/java/com/wireguard/android/Application.kt b/ui/src/main/java/com/wireguard/android/Application.kt
index d533028f..02e0235c 100644
--- a/ui/src/main/java/com/wireguard/android/Application.kt
+++ b/ui/src/main/java/com/wireguard/android/Application.kt
@@ -30,6 +30,7 @@ import com.wireguard.android.util.ToolsInstaller
import java9.util.concurrent.CompletableFuture
import java.lang.ref.WeakReference
import java.util.Locale
+import kotlin.system.exitProcess
class Application : android.app.Application(), OnSharedPreferenceChangeListener {
private val futureBackend = CompletableFuture<Backend>()
@@ -49,7 +50,7 @@ class Application : android.app.Application(), OnSharedPreferenceChangeListener
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK)
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
startActivity(intent)
- System.exit(0)
+ exitProcess(0)
}
if (BuildConfig.DEBUG) {
StrictMode.setVmPolicy(VmPolicy.Builder().detectAll().penaltyLog().build())
@@ -93,7 +94,7 @@ class Application : android.app.Application(), OnSharedPreferenceChangeListener
@JvmStatic
fun get(): Application {
- return weakSelf.get()!!
+ return requireNotNull(weakSelf.get())
}
@JvmStatic
@@ -130,7 +131,7 @@ class Application : android.app.Application(), OnSharedPreferenceChangeListener
}
app.backend = backend
}
- return app.backend!!
+ return requireNotNull(app.backend) { "backend must be initialized at this stage" }
}
}
diff --git a/ui/src/main/java/com/wireguard/android/QuickTileService.kt b/ui/src/main/java/com/wireguard/android/QuickTileService.kt
index 5099668e..f872ba3c 100644
--- a/ui/src/main/java/com/wireguard/android/QuickTileService.kt
+++ b/ui/src/main/java/com/wireguard/android/QuickTileService.kt
@@ -97,12 +97,12 @@ class QuickTileService : TileService() {
override fun onStartListening() {
Application.getTunnelManager().addOnPropertyChangedCallback(onTunnelChangedCallback)
- if (tunnel != null) tunnel!!.addOnPropertyChangedCallback(onStateChangedCallback)
+ tunnel?.addOnPropertyChangedCallback(onStateChangedCallback)
updateTile()
}
override fun onStopListening() {
- if (tunnel != null) tunnel!!.removeOnPropertyChangedCallback(onStateChangedCallback)
+ tunnel?.removeOnPropertyChangedCallback(onStateChangedCallback)
Application.getTunnelManager().removeOnPropertyChangedCallback(onTunnelChangedCallback)
}
@@ -110,9 +110,9 @@ class QuickTileService : TileService() {
// Update the tunnel.
val newTunnel = Application.getTunnelManager().lastUsedTunnel
if (newTunnel != tunnel) {
- if (tunnel != null) tunnel!!.removeOnPropertyChangedCallback(onStateChangedCallback)
+ tunnel?.removeOnPropertyChangedCallback(onStateChangedCallback)
tunnel = newTunnel
- if (tunnel != null) tunnel!!.addOnPropertyChangedCallback(onStateChangedCallback)
+ tunnel?.addOnPropertyChangedCallback(onStateChangedCallback)
}
// Update the tile contents.
val label: String
diff --git a/ui/src/main/java/com/wireguard/android/activity/BaseActivity.kt b/ui/src/main/java/com/wireguard/android/activity/BaseActivity.kt
index 14ab0bdb..d125dca2 100644
--- a/ui/src/main/java/com/wireguard/android/activity/BaseActivity.kt
+++ b/ui/src/main/java/com/wireguard/android/activity/BaseActivity.kt
@@ -46,7 +46,7 @@ abstract class BaseActivity : ThemeChangeAwareActivity() {
}
override fun onSaveInstanceState(outState: Bundle) {
- if (selectedTunnel != null) outState.putString(KEY_SELECTED_TUNNEL, selectedTunnel!!.name)
+ selectedTunnel?.let { outState.putString(KEY_SELECTED_TUNNEL, it.name) }
super.onSaveInstanceState(outState)
}
diff --git a/ui/src/main/java/com/wireguard/android/activity/MainActivity.kt b/ui/src/main/java/com/wireguard/android/activity/MainActivity.kt
index 237a75f4..9566e3a4 100644
--- a/ui/src/main/java/com/wireguard/android/activity/MainActivity.kt
+++ b/ui/src/main/java/com/wireguard/android/activity/MainActivity.kt
@@ -10,7 +10,6 @@ import android.view.Menu
import android.view.MenuItem
import android.view.View
import android.widget.LinearLayout
-import androidx.appcompat.app.ActionBar
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.FragmentTransaction
import com.wireguard.android.R
@@ -24,7 +23,6 @@ import com.wireguard.android.model.ObservableTunnel
* editing the configuration and interface state of WireGuard tunnels.
*/
class MainActivity : BaseActivity(), FragmentManager.OnBackStackChangedListener {
- private var actionBar: ActionBar? = null
private var isTwoPaneLayout = false
override fun onBackPressed() {
@@ -44,17 +42,16 @@ class MainActivity : BaseActivity(), FragmentManager.OnBackStackChangedListener
}
override fun onBackStackChanged() {
- if (actionBar == null) return
+ supportActionBar ?: return
// Do not show the home menu when the two-pane layout is at the detail view (see above).
val backStackEntries = supportFragmentManager.backStackEntryCount
val minBackStackEntries = if (isTwoPaneLayout) 2 else 1
- actionBar!!.setDisplayHomeAsUpEnabled(backStackEntries >= minBackStackEntries)
+ supportActionBar?.setDisplayHomeAsUpEnabled(backStackEntries >= minBackStackEntries)
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.main_activity)
- actionBar = supportActionBar
isTwoPaneLayout = findViewById<View>(R.id.master_detail_wrapper) is LinearLayout
supportFragmentManager.addOnBackStackChangedListener(this)
onBackStackChanged()
diff --git a/ui/src/main/java/com/wireguard/android/databinding/ItemChangeListener.kt b/ui/src/main/java/com/wireguard/android/databinding/ItemChangeListener.kt
index 29784a75..69d19c9c 100644
--- a/ui/src/main/java/com/wireguard/android/databinding/ItemChangeListener.kt
+++ b/ui/src/main/java/com/wireguard/android/databinding/ItemChangeListener.kt
@@ -28,7 +28,8 @@ internal class ItemChangeListener<T>(private val container: ViewGroup, private v
binding = DataBindingUtil.inflate(layoutInflater, layoutId, container, false)
}
require(list != null) { "Trying to get a view while list is still null" }
- binding!!.setVariable(BR.collection, list)
+ require(binding != null) { "binding should not be null"}
+ binding.setVariable(BR.collection, list)
binding.setVariable(BR.item, list!![position])
binding.setVariable(BR.fragment, fragment)
binding.executePendingBindings()
diff --git a/ui/src/main/java/com/wireguard/android/databinding/ObservableKeyedArrayList.kt b/ui/src/main/java/com/wireguard/android/databinding/ObservableKeyedArrayList.kt
index c00f553c..2229ef62 100644
--- a/ui/src/main/java/com/wireguard/android/databinding/ObservableKeyedArrayList.kt
+++ b/ui/src/main/java/com/wireguard/android/databinding/ObservableKeyedArrayList.kt
@@ -24,7 +24,7 @@ open class ObservableKeyedArrayList<K, E : Keyed<out K>> : ObservableArrayList<E
val iterator = listIterator()
while (iterator.hasNext()) {
val index = iterator.nextIndex()
- if (iterator.next()!!.key == key)
+ if (iterator.next().key == key)
return index
}
return -1
diff --git a/ui/src/main/java/com/wireguard/android/fragment/TunnelDetailFragment.kt b/ui/src/main/java/com/wireguard/android/fragment/TunnelDetailFragment.kt
index 2b5a4ba6..418eef93 100644
--- a/ui/src/main/java/com/wireguard/android/fragment/TunnelDetailFragment.kt
+++ b/ui/src/main/java/com/wireguard/android/fragment/TunnelDetailFragment.kt
@@ -68,18 +68,22 @@ class TunnelDetailFragment : BaseFragment() {
override fun onResume() {
super.onResume()
- timer = Timer()
- timer!!.scheduleAtFixedRate(object : TimerTask() {
- override fun run() {
- updateStats()
- }
- }, 0, 1000)
+ timer = Timer().also {
+ it.scheduleAtFixedRate(object : TimerTask() {
+ override fun run() {
+ updateStats()
+ }
+ }, 0, 1000)
+ }
}
override fun onSelectedTunnelChanged(oldTunnel: ObservableTunnel?, newTunnel: ObservableTunnel?) {
binding ?: return
binding!!.tunnel = newTunnel
- if (newTunnel == null) binding!!.config = null else newTunnel.configAsync.thenAccept { config -> binding!!.config = config }
+ if (newTunnel == null)
+ binding!!.config = null
+ else
+ newTunnel.configAsync.thenAccept { config -> binding!!.config = config }
lastState = Tunnel.State.TOGGLE
updateStats()
}
diff --git a/ui/src/main/java/com/wireguard/android/util/BiometricAuthenticator.kt b/ui/src/main/java/com/wireguard/android/util/BiometricAuthenticator.kt
index aed8a4f2..d530de4b 100644
--- a/ui/src/main/java/com/wireguard/android/util/BiometricAuthenticator.kt
+++ b/ui/src/main/java/com/wireguard/android/util/BiometricAuthenticator.kt
@@ -34,7 +34,8 @@ object BiometricAuthenticator {
@SuppressLint("PrivateApi")
private fun isPinEnabled(context: Context): Boolean {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
- return context.getSystemService<KeyguardManager>()!!.isDeviceSecure
+ // Reasonable assumption I suppose
+ return context.getSystemService<KeyguardManager>()?.isDeviceSecure ?: false
return try {
val lockUtilsClass = Class.forName("com.android.internal.widget.LockPatternUtils")
val lockUtils = lockUtilsClass.getConstructor(Context::class.java).newInstance(context)
diff --git a/ui/src/main/java/com/wireguard/android/util/DownloadsFileSaver.kt b/ui/src/main/java/com/wireguard/android/util/DownloadsFileSaver.kt
index a0f0e1fb..36cfd2d3 100644
--- a/ui/src/main/java/com/wireguard/android/util/DownloadsFileSaver.kt
+++ b/ui/src/main/java/com/wireguard/android/util/DownloadsFileSaver.kt
@@ -63,8 +63,8 @@ object DownloadsFileSaver {
class DownloadsFile(private val context: Context, val outputStream: OutputStream, val fileName: String, private val uri: Uri?) {
fun delete() {
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q)
- context.contentResolver.delete(uri!!, null, null)
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q && uri != null)
+ context.contentResolver.delete(uri, null, null)
else
File(fileName).delete()
}