Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Capability to display sideloaded apks #3

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Gradle files
.gradle/
build/

# Local configuration file (sdk path, etc)
local.properties

# Log/OS Files
*.log

# Android Studio generated files and folders
captures/
.externalNativeBuild/
.cxx/
*.apk
output.json

# IntelliJ
*.iml
.idea/

# Keystore files
*.jks
*.keystore

# Google Services (e.g. APIs or Firebase)
google-services.json

# Android Profiling
*.hprof
47 changes: 22 additions & 25 deletions app/src/main/java/com/hugegreenbug/launchy/AppManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ package com.hugegreenbug.launchy
import android.annotation.SuppressLint
import android.content.Context
import android.content.Intent
import android.content.pm.ComponentInfo
import android.content.pm.ApplicationInfo
import android.content.pm.PackageItemInfo
import android.content.pm.PackageManager.MATCH_ALL
import android.graphics.drawable.Drawable
import android.util.ArrayMap
Expand All @@ -17,38 +18,34 @@ class AppManager(private val context: Context) {
fun getLaunchableApps(): List<App> {
val intent = Intent(Intent.ACTION_MAIN, null)
intent.addCategory(Intent.CATEGORY_LEANBACK_LAUNCHER)
var list = packageManager.queryIntentActivities(intent, MATCH_ALL)
.map { it.activityInfo }
.map { App(it.packageName, it.loadLabel(packageManager).toString(), it, false) }
val listIter = list.iterator()
while (listIter.hasNext()) {
val app = listIter.next()
val drawable = getAppIcon(app.componentInfo)
if (drawable == null) {
list = list.filterIndexed { _, element ->
element.packageName != app.packageName
}
}
}

val list = ( getAppsThroughPackages() + getAppsThroughIntent(intent) )
.distinctBy { it.packageName }
.sortedBy { it.label }

return list
}

private fun getAppsThroughIntent(intent: Intent) =
packageManager.queryIntentActivities(intent, MATCH_ALL)
.map { it.activityInfo }
.map { App(it.packageName, it.loadLabel(packageManager).toString(), it, false) }

private fun getAppsThroughPackages() = packageManager.getInstalledPackages(0)
.filter { (it.applicationInfo.flags and ApplicationInfo.FLAG_SYSTEM) == 0 }
.map { it.applicationInfo }
.map { App(it.packageName, it.loadLabel(packageManager).toString(), it, false) }

fun startApp(app: App) {
val intent = packageManager.getLeanbackLaunchIntentForPackage(app.packageName)
val intent = packageManager.getLeanbackLaunchIntentForPackage(app.packageName) ?:
packageManager.getLaunchIntentForPackage(app.packageName)
context.startActivity(intent)
}

fun getAppIcon(componentInfo: ComponentInfo): Drawable?
= appIconCache[componentInfo.packageName] ?: loadAppIcon(componentInfo)

private fun loadAppIcon(componentInfo: ComponentInfo): Drawable? {
return try {
val drawable = componentInfo.loadBanner(packageManager) ?: return null
fun getAppIcon(info: PackageItemInfo): Drawable
= appIconCache[info.packageName] ?: loadAppIcon(info)

drawable
} catch (e: SecurityException) {
null
}
private fun loadAppIcon(info: PackageItemInfo): Drawable {
return info.loadBanner(packageManager) ?: info.loadIcon(packageManager)
}
}
4 changes: 2 additions & 2 deletions app/src/main/java/com/hugegreenbug/launchy/Model.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.hugegreenbug.launchy

import android.content.pm.ComponentInfo
import android.content.pm.PackageItemInfo
import android.graphics.Bitmap

data class App(val packageName: String, val label: String,
val componentInfo: ComponentInfo, var favorite: Boolean)
val packageItemInfo: PackageItemInfo, var favorite: Boolean)
data class Unsplash(val author: String, val url: String, val thumb: Bitmap, val name: String)
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,10 @@ class FavoriteAdapter(private val appManager: AppManager, private var list: List
return@setOnClickListener
}

val banner = appManager.getAppIcon(app.componentInfo)
if (banner != null) {
val bannerBmap = BitmapUtils.toBitmap(banner)
val roundedBanner = getRoundedCornerBitmap(bannerBmap)
ivIcon.setImageBitmap(roundedBanner)
}
val banner = appManager.getAppIcon(app.packageItemInfo)
val bannerBmap = BitmapUtils.toBitmap(banner)
val roundedBanner = getRoundedCornerBitmap(bannerBmap)
ivIcon.setImageBitmap(roundedBanner)
if (app.favorite) {
ivFav.visibility = View.VISIBLE
} else {
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ buildscript {
}
}
dependencies {
classpath "com.android.tools.build:gradle:7.0.2"
classpath 'com.android.tools.build:gradle:7.0.4'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.31"

// NOTE: Do not place your application dependencies here; they belong
Expand Down
10 changes: 0 additions & 10 deletions local.properties

This file was deleted.