Skip to content
Permalink
Browse files

Compile with API 29

Fix Lint warnings / compilation issues caused by new nullability annotations.
  • Loading branch information...
ianhanniballake committed Jun 6, 2019
1 parent d476b6a commit c586964f43f01d8efacd9064b216e6d41e6382e3
@@ -65,33 +65,31 @@ class InstalledProvidersLiveData(
val pm = context.packageManager
val resolveInfos = pm.queryIntentContentProviders(queryIntent,
PackageManager.GET_META_DATA)
if (resolveInfos != null) {
val newProviders = HashMap<ComponentName, ProviderInfo>().apply {
putAll(currentProviders)
}
val existingProviders = HashSet(currentProviders.values)
if (packageName != null) {
existingProviders.removeAll {
it.packageName != packageName
}
}
for (ri in resolveInfos) {
val componentName = ri.providerInfo.getComponentName()
existingProviders.removeAll { it.getComponentName() == componentName }
if (ri.providerInfo.enabled) {
newProviders[componentName] = ri.providerInfo
} else {
newProviders.remove(componentName)
}
val newProviders = HashMap<ComponentName, ProviderInfo>().apply {
putAll(currentProviders)
}
val existingProviders = HashSet(currentProviders.values)
if (packageName != null) {
existingProviders.removeAll {
it.packageName != packageName
}
// Remove providers that weren't found in the resolveInfos
existingProviders.forEach {
newProviders.remove(it.getComponentName())
}
for (ri in resolveInfos) {
val componentName = ri.providerInfo.getComponentName()
existingProviders.removeAll { it.getComponentName() == componentName }
if (ri.providerInfo.enabled) {
newProviders[componentName] = ri.providerInfo
} else {
newProviders.remove(componentName)
}
currentProviders.clear()
currentProviders.putAll(newProviders)
postValue(currentProviders.values.toList())
}
// Remove providers that weren't found in the resolveInfos
existingProviders.forEach {
newProviders.remove(it.getComponentName())
}
currentProviders.clear()
currentProviders.putAll(newProviders)
postValue(currentProviders.values.toList())
}

override fun onActive() {
@@ -232,7 +232,7 @@ abstract class MuzeiDatabase : RoomDatabase() {
database.query("SELECT component_name FROM sources WHERE selected=1").use { selectedSource ->
if (selectedSource != null && selectedSource.moveToFirst()) {
val componentName = ComponentName.unflattenFromString(
selectedSource.getString(0))
selectedSource.getString(0))!!
val info = context.packageManager.getServiceInfo(componentName,
PackageManager.GET_META_DATA)
val metadata = info.metaData
@@ -296,15 +296,13 @@ abstract class MuzeiDatabase : RoomDatabase() {
selectedProvider ->
if (selectedProvider.moveToFirst()) {
val componentName = ComponentName.unflattenFromString(
selectedProvider.getString(0))
selectedProvider.getString(0))!!
val supportsNextArtwork = selectedProvider.getInt(1)
val info = context.packageManager.getProviderInfo(componentName, 0)
if (info != null) {
database.execSQL("INSERT INTO provider2 " +
"(authority, supportsNextArtwork) "
+ "VALUES (?, ?)",
arrayOf(info.authority, supportsNextArtwork))
}
database.execSQL("INSERT INTO provider2 " +
"(authority, supportsNextArtwork) "
+ "VALUES (?, ?)",
arrayOf(info.authority, supportsNextArtwork))
}
}
} catch (e: PackageManager.NameNotFoundException) {
@@ -328,7 +326,7 @@ abstract class MuzeiDatabase : RoomDatabase() {
while (artwork.moveToNext()) {
val id = artwork.getLong(0)
val componentName = ComponentName.unflattenFromString(
artwork.getString(1))
artwork.getString(1))!!
val imageUri = artwork.getString(2)
val title = artwork.getString(3)
val byline = artwork.getString(4)
@@ -338,14 +336,12 @@ abstract class MuzeiDatabase : RoomDatabase() {

try {
val info = context.packageManager.getProviderInfo(componentName, 0)
if (info != null) {
database.execSQL("INSERT INTO artwork2 " +
"(_id, providerAuthority, imageUri, " +
"title, byline, attribution, metaFont, date_added) "
+ "VALUES (?, ?, ?, ?, ?, ?, ?, ?)",
arrayOf(id, info.authority, imageUri, title,
byline, attribution, metaFont, dateAdded))
}
database.execSQL("INSERT INTO artwork2 " +
"(_id, providerAuthority, imageUri, " +
"title, byline, attribution, metaFont, date_added) "
+ "VALUES (?, ?, ?, ?, ?, ?, ?, ?)",
arrayOf(id, info.authority, imageUri, title,
byline, attribution, metaFont, dateAdded))
} catch (e: PackageManager.NameNotFoundException) {
// Couldn't find the provider, so there's nothing more to do
}
@@ -16,7 +16,7 @@

buildscript {
ext {
compileSdkVersion = 28
compileSdkVersion = 29
targetSdkVersion = 25

appCompatVersion = '1.1.0-beta01'
@@ -18,11 +18,12 @@ package com.example.muzei.unsplash

import android.app.Service
import android.content.Intent
import android.os.Binder

/**
* This class is kept only to serve as a tombstone to Muzei to know to replace it
* with [UnsplashExampleArtProvider].
*/
class UnsplashExampleArtSource : Service() {
override fun onBind(intent: Intent?) = null
override fun onBind(intent: Intent?): Binder? = null
}
@@ -130,7 +130,7 @@ class LegacySourceManager(private val applicationContext: Context) : DefaultLife
val pm = applicationContext.packageManager
val serviceInfo = pm.queryIntentServices(
Intent(LegacySourceServiceProtocol.LEGACY_SOURCE_ACTION), 0)
?.get(0)
.firstOrNull()
?.serviceInfo
if (serviceInfo == null) {
if (BuildConfig.DEBUG) {
@@ -18,11 +18,12 @@ package com.google.android.apps.muzei.featuredart

import android.app.Service
import android.content.Intent
import android.os.Binder

/**
* This class is kept only to serve as a tombstone to Muzei to know to replace it
* with [FeaturedArtProvider].
*/
class FeaturedArtSource : Service() {
override fun onBind(intent: Intent?) = null
override fun onBind(intent: Intent?): Binder? = null
}
@@ -119,7 +119,7 @@ class FeaturedArtWorker(
title = jsonObject.optString(KEY_TITLE)
byline = jsonObject.optString(KEY_BYLINE)
attribution = jsonObject.optString(KEY_ATTRIBUTION)
webUri = jsonObject.optString(KEY_DETAILS_URI)?.toUri()
webUri = jsonObject.optString(KEY_DETAILS_URI).takeUnless { it.isEmpty() }?.toUri()
}

if (BuildConfig.DEBUG) {
@@ -135,7 +135,7 @@ class FeaturedArtWorker(
return@withContext Result.retry()
}

val nextTime: Date? = jsonObject.optString("nextTime")?.takeUnless {
val nextTime: Date? = jsonObject.optString("nextTime").takeUnless {
it.isEmpty()
}?.run {
if (length > 4 && this[length - 3] == ':') {
@@ -18,11 +18,12 @@ package com.google.android.apps.muzei.gallery

import android.app.Service
import android.content.Intent
import android.os.Binder

/**
* This class is kept only to serve as a tombstone to Muzei to know to replace it
* with [GalleryArtProvider].
*/
class GalleryArtSource : Service() {
override fun onBind(intent: Intent?) = null
override fun onBind(intent: Intent?): Binder? = null
}
@@ -72,20 +72,20 @@ class GallerySettingsViewModel(application: Application) : AndroidViewModel(appl
}
val packageManager = getApplication<Application>().packageManager
val packageName = getApplication<Application>().packageName
value = packageManager.queryIntentActivities(intent, 0)?.asSequence()?.map {
value = packageManager.queryIntentActivities(intent, 0).asSequence().map {
it.activityInfo
}?.filter {
}.filter {
// Filter out the default system UI
it.packageName != "com.android.documentsui"
}?.filter {
}.filter {
// Only show exported activities
it.exported
}?.filter {
}.filter {
// Only show activities that have no permissions or permissions we hold
it.permission?.isEmpty() != false ||
packageManager.checkPermission(it.permission, packageName) ==
PackageManager.PERMISSION_GRANTED
}?.toList()
}.toList()
}
}
}
@@ -18,11 +18,12 @@ package com.google.android.apps.muzei.single

import android.app.Service
import android.content.Intent
import android.os.Binder

/**
* This class is kept only to serve as a tombstone to Muzei to know to replace it
* with [SingleArtProvider].
*/
class SingleArtSource : Service() {
override fun onBind(intent: Intent?) = null
override fun onBind(intent: Intent?): Binder? = null
}
@@ -167,14 +167,14 @@ class MuzeiWatchFace : CanvasWatchFaceService(), LifecycleOwner {
internal var topComplication: ComplicationDrawable? = null
internal var bottomComplication: ComplicationDrawable? = null
private val drawableCallback = object : Drawable.Callback {
override fun invalidateDrawable(who: Drawable?) {
override fun invalidateDrawable(who: Drawable) {
invalidate()
}

override fun scheduleDrawable(who: Drawable?, what: Runnable?, `when`: Long) {
override fun scheduleDrawable(who: Drawable, what: Runnable, `when`: Long) {
}

override fun unscheduleDrawable(who: Drawable?, what: Runnable?) {
override fun unscheduleDrawable(who: Drawable, what: Runnable) {
}
}

0 comments on commit c586964

Please sign in to comment.
You can’t perform that action at this time.