mirror of
https://github.com/jrpie/Launcher.git
synced 2025-02-23 06:21:31 +01:00
fix: properly handle AppInfo with unknown user
This commit is contained in:
parent
4ee81bde4d
commit
b67f87e93d
5 changed files with 22 additions and 16 deletions
|
@ -97,9 +97,13 @@ fun getIntent(packageName: String, context: Context): Intent? {
|
|||
}
|
||||
/* --- */
|
||||
|
||||
fun getUserFromId(user: Int?, context: Context): UserHandle? {
|
||||
fun getUserFromId(user: Int?, context: Context): UserHandle {
|
||||
/* TODO: this is an ugly hack.
|
||||
Use userManager#getUserForSerialNumber instead (breaking change to SharedPreferences!)
|
||||
*/
|
||||
val userManager = context.getSystemService(Service.USER_SERVICE) as UserManager
|
||||
return userManager.userProfiles.firstOrNull { it.hashCode() == user }
|
||||
val profiles = userManager.userProfiles
|
||||
return profiles.firstOrNull { it.hashCode() == user } ?: profiles[0]
|
||||
}
|
||||
|
||||
|
||||
|
@ -107,10 +111,10 @@ fun uninstallApp(appInfo: AppInfo, activity: Activity) {
|
|||
val packageName = appInfo.packageName.toString()
|
||||
val user = appInfo.user
|
||||
|
||||
Log.i("Launcher", "uninstalling $packageName ($user)")
|
||||
Log.i("Launcher", "uninstalling $appInfo")
|
||||
val intent = Intent(Intent.ACTION_UNINSTALL_PACKAGE)
|
||||
intent.data = Uri.parse("package:$packageName")
|
||||
getUserFromId(user, activity)?.let { user ->
|
||||
getUserFromId(user, activity).let { user ->
|
||||
intent.putExtra(Intent.EXTRA_USER, user)
|
||||
}
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ interface Action {
|
|||
val id = gesture.id
|
||||
|
||||
val preferences = LauncherPreferences.getSharedPreferences()
|
||||
var actionId = preferences.getString("$id.app", "")!!
|
||||
val actionId = preferences.getString("$id.app", "")!!
|
||||
var u: Int? = preferences.getInt("$id.user", INVALID_USER)
|
||||
u = if (u == INVALID_USER) null else u
|
||||
|
||||
|
@ -48,7 +48,7 @@ interface Action {
|
|||
|
||||
fun resetToDefaultActions(context: Context) {
|
||||
val editor = LauncherPreferences.getSharedPreferences().edit()
|
||||
Gesture.values().forEach { gesture ->
|
||||
Gesture.entries.forEach { gesture ->
|
||||
context.resources
|
||||
.getStringArray(gesture.defaultsResource)
|
||||
.map { fromId(it, null) }
|
||||
|
@ -96,7 +96,7 @@ interface Action {
|
|||
|
||||
fun fromIntent(data: Intent): Action? {
|
||||
val value = data.getStringExtra("action_id") ?: return null
|
||||
var user = data.getIntExtra("user", INVALID_USER)
|
||||
val user = data.getIntExtra("user", INVALID_USER)
|
||||
return fromId(value, user)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import android.app.Service
|
|||
import android.content.Context
|
||||
import android.content.pm.LauncherActivityInfo
|
||||
import android.content.pm.LauncherApps
|
||||
import android.util.Log
|
||||
import de.jrpie.android.launcher.getUserFromId
|
||||
|
||||
/**
|
||||
|
@ -19,13 +20,13 @@ class AppInfo(val packageName: CharSequence, val activityName: CharSequence?, va
|
|||
var ret = "$packageName;$u"
|
||||
activityName?.let { ret += ";$activityName" }
|
||||
|
||||
return ret;
|
||||
return ret
|
||||
}
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if(other is AppInfo) {
|
||||
return other.user == user && other.packageName == packageName
|
||||
&& other.activityName == activityName;
|
||||
&& other.activityName == activityName
|
||||
}
|
||||
return super.equals(other)
|
||||
}
|
||||
|
@ -38,11 +39,10 @@ class AppInfo(val packageName: CharSequence, val activityName: CharSequence?, va
|
|||
context: Context
|
||||
): LauncherActivityInfo? {
|
||||
val launcherApps = context.getSystemService(Service.LAUNCHER_APPS_SERVICE) as LauncherApps
|
||||
return getUserFromId(user, context)?.let { userHandle ->
|
||||
launcherApps.getActivityList(packageName.toString(), userHandle).firstOrNull { app ->
|
||||
app.name == activityName || activityName == null || activityName == ""
|
||||
}
|
||||
}
|
||||
val userHandle = getUserFromId(user, context)
|
||||
val activityList = launcherApps.getActivityList(packageName.toString(), userHandle)
|
||||
return activityList.firstOrNull { app -> app.name == activityName }
|
||||
?: activityList.firstOrNull()
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package de.jrpie.android.launcher.ui.list.apps
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.app.Activity
|
||||
import android.content.Intent
|
||||
import android.graphics.Rect
|
||||
|
@ -36,6 +37,7 @@ import de.jrpie.android.launcher.uninstallApp
|
|||
* @param intention - why the list is displayed ("view", "pick")
|
||||
* @param forGesture - the action which an app is chosen for (when the intention is "pick")
|
||||
*/
|
||||
@SuppressLint("NotifyDataSetChanged")
|
||||
class AppsRecyclerAdapter(
|
||||
val activity: Activity,
|
||||
val root: View,
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
buildscript {
|
||||
ext.kotlin_version = '2.0.0'
|
||||
ext.android_plugin_version = '8.5.1'
|
||||
ext.android_plugin_version = '8.7.0'
|
||||
repositories {
|
||||
google()
|
||||
mavenCentral()
|
||||
|
@ -10,7 +10,7 @@ buildscript {
|
|||
}
|
||||
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:8.5.2'
|
||||
classpath 'com.android.tools.build:gradle:8.7.0'
|
||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||
classpath "com.android.tools.build:gradle:$android_plugin_version"
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue