Skip to content

Commit 201ad68

Browse files
committed
fix: sdk 35 support
1 parent 64965a6 commit 201ad68

File tree

10 files changed

+65
-66
lines changed

10 files changed

+65
-66
lines changed

common/src/main/java/dev/funkymuse/common/OtherUtils.kt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ inline fun <K : Any, V : Any> LruCache<K, V>.getOrPut(key: K, defaultValue: () -
276276
*
277277
* This method is thread-safe.
278278
*/
279-
inline fun <K : Any, V> LruCache<K, V>.getOrPutNotNull(key: K, defaultValue: () -> V?): V? {
279+
inline fun <K : Any, V : Any> LruCache<K, V>.getOrPutNotNull(key: K, defaultValue: () -> V?): V? {
280280
synchronized(this) {
281281
this[key]?.let { return it }
282282
return defaultValue()?.apply { put(key, this) }
@@ -286,19 +286,19 @@ inline fun <K : Any, V> LruCache<K, V>.getOrPutNotNull(key: K, defaultValue: ()
286286
/**
287287
* Returns an array containing the keys in the cache.
288288
*/
289-
fun <V> LruCache<Int, V>.keys(): IntArray =
289+
fun <V : Any> LruCache<Int, V>.keys(): IntArray =
290290
snapshot().keys.toIntArray()
291291

292292
/**
293293
* Returns an array containing the keys in the cache.
294294
*/
295-
fun <V> LruCache<Long, V>.keys(): LongArray =
295+
fun <V : Any> LruCache<Long, V>.keys(): LongArray =
296296
snapshot().keys.toLongArray()
297297

298298
/**
299299
* Returns an array containing the keys in the cache.
300300
*/
301-
inline fun <reified K, V> LruCache<K, V>.keys(): Array<K> =
301+
inline fun <reified K : Any, V : Any> LruCache<K, V>.keys(): Array<K> =
302302
snapshot().keys.toTypedArray()
303303

304304
val randomUUIDstring get() = UUID.randomUUID().toString()
@@ -642,6 +642,7 @@ fun <T> lazyFast(operation: () -> T): Lazy<T> = lazy(LazyThreadSafetyMode.NONE)
642642
* @receiver Context
643643
* @return Drawable?
644644
*/
645+
@SuppressLint("MissingPermission")
645646
fun Context.getWallpaperDrawable(): Drawable? = WallpaperManager.getInstance(this).peekDrawable()
646647

647648

context/src/main/java/dev/funkymuse/context/ContextExtensions3.kt

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ fun Context.getAppIcon(pName: String = packageName): Drawable {
117117
* Provide Package or will provide the current App Detail
118118
*/
119119
@Throws(PackageManager.NameNotFoundException::class)
120-
fun Context.getAppVersionName(pName: String = packageName): String {
120+
fun Context.getAppVersionName(pName: String = packageName): String? {
121121
return packageManager.getPackageInfo(pName, 0).versionName
122122
}
123123

@@ -174,17 +174,6 @@ val Context.getAndroidID: String?
174174
}
175175

176176

177-
/**
178-
* get Device IMEI
179-
*
180-
* Requires READ_PHONE_STATE Permission
181-
*/
182-
@RequiresApi(Build.VERSION_CODES.O)
183-
@SuppressLint("HardwareIds")
184-
@RequiresPermission(Manifest.permission.READ_PHONE_STATE)
185-
fun Context.getIMEI() = telephonyManager?.imei
186-
187-
188177
/**
189178
* Reboot the application
190179
*
@@ -516,7 +505,7 @@ val Context.processName: String?
516505
.firstOrNull()
517506

518507

519-
val Context.packageVersionName: String
508+
val Context.packageVersionName: String?
520509
get() = packageManager.getPackageInfo(packageName, 0).versionName
521510

522511

customviews/src/main/java/dev/funkymuse/customviews/WatermarkBitmap.kt

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,17 @@ import androidx.annotation.ColorInt
1313

1414

1515
fun addWatermarkToBitmap(
16-
bitmap: Bitmap,
17-
watermarkText: String,
18-
options: WatermarkOptions = WatermarkOptions()
19-
): Bitmap {
20-
val result = bitmap.copy(bitmap.config, true)
16+
bitmap: Bitmap,
17+
watermarkText: String,
18+
options: WatermarkOptions = WatermarkOptions()
19+
): Bitmap? {
20+
val result = bitmap.config?.let { bitmap.copy(it, true) } ?: return null
2121
val canvas = Canvas(result)
2222
val paint = Paint(ANTI_ALIAS_FLAG or DITHER_FLAG)
2323
paint.textAlign = when (options.corner) {
2424
Corner.TOP_LEFT,
2525
Corner.BOTTOM_LEFT -> Paint.Align.LEFT
26+
2627
Corner.TOP_RIGHT,
2728
Corner.BOTTOM_RIGHT -> Paint.Align.RIGHT
2829
}
@@ -37,21 +38,22 @@ fun addWatermarkToBitmap(
3738
}
3839
val padding = result.width * options.paddingToWidthRatio
3940
val coordinates =
40-
calculateCoordinates(watermarkText, paint, options, canvas.width, canvas.height, padding)
41+
calculateCoordinates(watermarkText, paint, options, canvas.width, canvas.height, padding)
4142
canvas.drawText(watermarkText, coordinates.x, coordinates.y, paint)
4243
return result
4344
}
4445

4546
fun Bitmap.addWatermark(
46-
watermarkText: String,
47-
options: WatermarkOptions = WatermarkOptions()
48-
): Bitmap {
49-
val result = copy(config, true)
47+
watermarkText: String,
48+
options: WatermarkOptions = WatermarkOptions()
49+
): Bitmap? {
50+
val result = config?.let { copy(it, true) } ?: return null
5051
val canvas = Canvas(result)
5152
val paint = Paint(ANTI_ALIAS_FLAG or DITHER_FLAG)
5253
paint.textAlign = when (options.corner) {
5354
Corner.TOP_LEFT,
5455
Corner.BOTTOM_LEFT -> Paint.Align.LEFT
56+
5557
Corner.TOP_RIGHT,
5658
Corner.BOTTOM_RIGHT -> Paint.Align.RIGHT
5759
}
@@ -66,24 +68,25 @@ fun Bitmap.addWatermark(
6668
}
6769
val padding = result.width * options.paddingToWidthRatio
6870
val coordinates =
69-
calculateCoordinates(watermarkText, paint, options, canvas.width, canvas.height, padding)
71+
calculateCoordinates(watermarkText, paint, options, canvas.width, canvas.height, padding)
7072
canvas.drawText(watermarkText, coordinates.x, coordinates.y, paint)
7173
return result
7274
}
7375

7476
private fun calculateCoordinates(
75-
watermarkText: String,
76-
paint: Paint,
77-
options: WatermarkOptions,
78-
width: Int,
79-
height: Int,
80-
padding: Float
77+
watermarkText: String,
78+
paint: Paint,
79+
options: WatermarkOptions,
80+
width: Int,
81+
height: Int,
82+
padding: Float
8183
): PointF {
8284
val x = when (options.corner) {
8385
Corner.TOP_LEFT,
8486
Corner.BOTTOM_LEFT -> {
8587
padding
8688
}
89+
8790
Corner.TOP_RIGHT,
8891
Corner.BOTTOM_RIGHT -> {
8992
width - padding
@@ -94,6 +97,7 @@ private fun calculateCoordinates(
9497
Corner.BOTTOM_RIGHT -> {
9598
height - padding
9699
}
100+
97101
Corner.TOP_LEFT,
98102
Corner.TOP_RIGHT -> {
99103
val bounds = Rect()
@@ -114,10 +118,10 @@ enum class Corner {
114118
}
115119

116120
data class WatermarkOptions(
117-
val corner: Corner = Corner.BOTTOM_RIGHT,
118-
val textSizeToWidthRatio: Float = 0.04f,
119-
val paddingToWidthRatio: Float = 0.03f,
120-
@ColorInt val textColor: Int = Color.WHITE,
121-
@ColorInt val shadowColor: Int? = Color.BLACK,
122-
val typeface: Typeface? = null
121+
val corner: Corner = Corner.BOTTOM_RIGHT,
122+
val textSizeToWidthRatio: Float = 0.04f,
123+
val paddingToWidthRatio: Float = 0.03f,
124+
@ColorInt val textColor: Int = Color.WHITE,
125+
@ColorInt val shadowColor: Int? = Color.BLACK,
126+
val typeface: Typeface? = null
123127
)

gradle.properties

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ org.gradle.caching=true
77
org.gradle.vfs.watch=true
88
org.gradle.configureondemand=true
99
org.gradle.unsafe.configuration-cache=true
10-
org.gradle.unsafe.configuration-cache-problems=warn
10+
org.gradle.unsafe.configuration-cache-problems=warn
11+
org.jetbrains.dokka.experimental.gradle.pluginMode=V2EnabledWithHelpers

gradle/libs.versions.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ gradlePlugins-spotless = "7.0.2"
5454
gradlePlugins-dokka = "2.0.0"
5555
gradlePlugins-maven-publish = "maven-publish"
5656
#Build
57-
app-build-compileSDKVersion = "34"
58-
app-build-targetSDK = "34"
57+
app-build-compileSDKVersion = "35"
58+
app-build-targetSDK = "35"
5959
app-build-minimumSDK = "21"
6060
app-build-testRunner = "androidx.test.runner.AndroidJUnitRunner"
6161
app-build-kotlinJVMTarget = "17"

kotlinextensions/src/main/java/dev/funkymuse/kotlinextensions/bitmap/BitmapExtensions.kt

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import android.graphics.drawable.BitmapDrawable
1111
import android.graphics.drawable.Drawable
1212
import android.graphics.drawable.Icon
1313
import android.net.Uri
14+
import android.os.Build
1415
import android.util.DisplayMetrics
1516
import android.util.Log
1617
import android.widget.ImageView
@@ -28,11 +29,8 @@ import kotlin.math.ceil
2829
import kotlin.math.min
2930

3031

31-
32-
33-
3432
fun Bitmap.overlay(overlay: Bitmap): Bitmap {
35-
val result = Bitmap.createBitmap(width, height, config)
33+
val result = Bitmap.createBitmap(width, height, requireNotNull(config))
3634
val canvas = Canvas(result)
3735
canvas.drawBitmap(this, Matrix(), null)
3836
canvas.drawBitmap(overlay, Matrix(), null)
@@ -169,7 +167,7 @@ fun Bitmap.resize(newWidth: Number, newHeight: Number): Bitmap {
169167
fun Bitmap.toRoundCorner(radius: Float): Bitmap? {
170168
val width = this.width
171169
val height = this.height
172-
val bitmap = Bitmap.createBitmap(width, height, this.config)
170+
val bitmap = this.config?.let { Bitmap.createBitmap(width, height, it) } ?: return null
173171
val paint = Paint()
174172
val canvas = Canvas(bitmap)
175173
val rect = Rect(0, 0, width, height)
@@ -271,7 +269,7 @@ fun Bitmap.isNotRecycled() = !isRecycled
271269
* Greyscale the Image.
272270
*/
273271
fun Bitmap.toGrayScale(recycle: Boolean): Bitmap? {
274-
val ret = Bitmap.createBitmap(width, height, config)
272+
val ret = config?.let { Bitmap.createBitmap(width, height, it) } ?: return null
275273
val canvas = Canvas(ret)
276274
val paint = Paint()
277275
val colorMatrix = ColorMatrix()
@@ -292,11 +290,11 @@ fun Bitmap.toRoundCorner(
292290
borderSize: Float = 0f,
293291
@ColorInt borderColor: Int = 0,
294292
recycle: Boolean = true
295-
): Bitmap {
293+
): Bitmap? {
296294
val width = width
297295
val height = height
298296
val paint = Paint(Paint.ANTI_ALIAS_FLAG)
299-
val ret = Bitmap.createBitmap(width, height, config)
297+
val ret = config?.let { Bitmap.createBitmap(width, height, it) } ?: return null
300298
val shader = BitmapShader(this, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP)
301299
paint.shader = shader
302300
val canvas = Canvas(ret)
@@ -320,12 +318,12 @@ fun Bitmap.toRoundCorner(
320318
/**
321319
* Makes the Bitmap Round with given params
322320
*/
323-
fun Bitmap.toRound(borderSize: Float = 0f, borderColor: Int = 0, recycle: Boolean = true): Bitmap {
321+
fun Bitmap.toRound(borderSize: Float = 0f, borderColor: Int = 0, recycle: Boolean = true): Bitmap? {
324322
val width = width
325323
val height = height
326324
val size = Math.min(width, height)
327325
val paint = Paint(ANTI_ALIAS_FLAG)
328-
val ret = Bitmap.createBitmap(width, height, config)
326+
val ret = config?.let { Bitmap.createBitmap(width, height, it) } ?: return null
329327
val center = size / 2f
330328
val rectF = RectF(0f, 0f, width.toFloat(), height.toFloat())
331329
rectF.inset((width - size) / 2f, (height - size) / 2f)
@@ -623,6 +621,7 @@ infix fun ImageView.set(drawable: Drawable) {
623621
}
624622

625623

624+
@RequiresApi(Build.VERSION_CODES.M)
626625
infix fun ImageView.set(ic: Icon) {
627626
setImageIcon(ic)
628627
}

kotlinextensions/src/main/java/dev/funkymuse/kotlinextensions/packageutils/PackageUtils.kt

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ fun Context.isAppEnabled(packageName: String): Boolean {
3535

3636

3737
fun Context.whoInstalledMyApp(packageName: String) =
38-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
39-
packageManager.getInstallSourceInfo(packageName).installingPackageName
40-
} else {
41-
packageManager.getInstallerPackageName(packageName)
42-
}
38+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
39+
packageManager.getInstallSourceInfo(packageName).installingPackageName
40+
} else {
41+
packageManager.getInstallerPackageName(packageName)
42+
}
4343

4444

4545
fun Context.showAppInfo(packageName: String) {
@@ -84,7 +84,10 @@ inline val Context.installerPackageName: String?
8484
inline val Context.isFromGooglePlay: Boolean
8585
get() {
8686
val installer = installerPackageName
87-
return arrayOf(INSTALLER_GOOGLE_PLAY_FEEDBACK, INSTALLER_GOOGLE_PLAY_VENDING).any { it == installer }
87+
return arrayOf(
88+
INSTALLER_GOOGLE_PLAY_FEEDBACK,
89+
INSTALLER_GOOGLE_PLAY_VENDING
90+
).any { it == installer }
8891
}
8992

9093
fun PackageManager.isIntentSafe(intent: Intent): Boolean {
@@ -99,7 +102,9 @@ fun PackageManager.isIntentSafe(intent: Intent): Boolean {
99102
* @param pkgInfo
100103
* @return
101104
*/
102-
fun isSystemPackage(pkgInfo: PackageInfo) = pkgInfo.applicationInfo.flags and ApplicationInfo.FLAG_SYSTEM != 0
105+
fun isSystemPackage(pkgInfo: PackageInfo): Boolean {
106+
return (pkgInfo.applicationInfo?.flags ?: -1) and ApplicationInfo.FLAG_SYSTEM != 0
107+
}
103108

104109
fun Context.launchAnApp(packageName: String) {
105110
val launchApp = packageManager.getLaunchIntentForPackage(packageName)

kotlinextensions/src/main/java/dev/funkymuse/kotlinextensions/version/VersionExtensions.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ fun Context.getVersionCodeCompat(): Long = if (Build.VERSION.SDK_INT >= Build.VE
6565
packageManager.getPackageInfo(packageName, 0).versionCode.toLong()
6666
}
6767

68-
fun Context.getVersionName(): String = packageManager.getPackageInfo(packageName, 0).versionName
68+
fun Context.getVersionName(): String? = packageManager.getPackageInfo(packageName, 0).versionName
6969

7070
inline fun doWithApi(api: Api, block: () -> Unit) {
7171
doWithApi(api.sdkCode, block)

security/src/main/java/dev/funkymuse/security/MagiskDetector.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class MagiskDetector(context: Context) {
1212
fun checkForMagisk(): Boolean {
1313
for (pkg in packages) {
1414
val pkgName = pkg.packageName
15-
val appInfo = pkg.applicationInfo
15+
val appInfo = pkg.applicationInfo?: return false
1616
if (pkgName == ORIGINAL_PACKAGE) return true
1717

1818
val label = pm.getApplicationLabel(appInfo).toString()

security/src/main/java/dev/funkymuse/security/PiracyCheckers.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,11 @@ fun Context.getSingInfoMD5(pkg: String): String? {
7171
packageManager.getPackageInfo(pkg, PackageManager.GET_SIGNATURES)
7272
}
7373
val signatures = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
74-
packageInfo.signingInfo.signingCertificateHistory
74+
packageInfo.signingInfo?.signingCertificateHistory
7575
} else {
7676
packageInfo.signatures
7777
}
78-
val signature = signatures.firstOrNull() ?: return null
78+
val signature = signatures?.firstOrNull() ?: return null
7979
getMd5(signature)
8080
} catch (e: Exception) {
8181
e.printStackTrace()
@@ -176,12 +176,12 @@ fun Context.getShaSignature(packageName: String): String? {
176176
packageManager.getPackageInfo(packageName, PackageManager.GET_SIGNATURES)
177177
}
178178
val signatures = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
179-
packageInfo.signingInfo.signingCertificateHistory
179+
packageInfo.signingInfo?.signingCertificateHistory
180180
} else {
181181
packageInfo.signatures
182182
}
183183

184-
val signature = signatures.firstOrNull() ?: return null
184+
val signature = signatures?.firstOrNull() ?: return null
185185
val md: MessageDigest = MessageDigest.getInstance("SHA1")
186186
md.update(signature.toByteArray())
187187
return String(Base64.encode(md.digest(), 0))

0 commit comments

Comments
 (0)