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

fix: package removed after update #47

Open
wants to merge 1 commit 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
Original file line number Diff line number Diff line change
Expand Up @@ -9,53 +9,50 @@ import android.content.IntentFilter
import android.content.pm.LauncherApps
import android.os.Build
import android.os.IBinder
import android.os.Process
import android.os.UserHandle
import androidx.core.app.NotificationCompat

class AppProvider : Service() {
private var packageChangeReceiver: PackageChangeReceiver? = null

override fun onCreate() {
val launcherApps = (getSystemService(LAUNCHER_APPS_SERVICE) as LauncherApps)
val launcherApps = getSystemService(LAUNCHER_APPS_SERVICE) as LauncherApps

launcherApps.registerCallback(
object : LauncherAppsCallback() {
override fun onPackageAdded(
packageName: String,
user: UserHandle,
) {
if (user == Process.myUserHandle()) return

PackageChangeReceiver.handleEvent(
this@AppProvider,
Intent.ACTION_PACKAGE_ADDED,
packageName,
false,
)
}

override fun onPackageChanged(
packageName: String,
user: UserHandle,
) {
if (user == Process.myUserHandle()) return

PackageChangeReceiver.handleEvent(
this@AppProvider,
Intent.ACTION_PACKAGE_CHANGED,
packageName,
true,
)
}

override fun onPackageRemoved(
packageName: String,
user: UserHandle,
) {
if (user == Process.myUserHandle()) return

PackageChangeReceiver.handleEvent(
this@AppProvider,
Intent.ACTION_PACKAGE_REMOVED,
packageName,
false,
)
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class PackageChangeReceiver : BroadcastReceiver() {
context,
action,
packageName,
intent.getBooleanExtra(Intent.EXTRA_REPLACING, false),
)
}

Expand All @@ -31,25 +32,22 @@ class PackageChangeReceiver : BroadcastReceiver() {
context: Context,
action: String,
packageName: String,
replacing: Boolean,
) {
if (action != Intent.ACTION_PACKAGE_ADDED &&
action != Intent.ACTION_PACKAGE_CHANGED &&
action != Intent.ACTION_PACKAGE_REMOVED
) {
return
}

val intent = Intent()
intent.setAction(Constants.PACKAGE_UPDATE_ACTION)
intent.putExtra(Constants.PACKAGE_CHANGE_NAME, packageName)

if (action == Intent.ACTION_PACKAGE_ADDED || action == Intent.ACTION_PACKAGE_CHANGED) {
// Ignore plugin apps
context.packageManager.getLaunchIntentForPackage(packageName) ?: return

intent.putExtra(Constants.PACKAGE_CHANGE_IS_REMOVED, false)
if (Intent.ACTION_PACKAGE_ADDED == action) {
if (!replacing) {
intent.putExtra(Constants.PACKAGE_CHANGE_IS_REMOVED, false)
}
} else if (Intent.ACTION_PACKAGE_REMOVED == action) {
if (!replacing) {
intent.putExtra(Constants.PACKAGE_CHANGE_IS_REMOVED, true)
}
} else {
intent.putExtra(Constants.PACKAGE_CHANGE_IS_REMOVED, true)
intent.putExtra(Constants.PACKAGE_CHANGE_IS_REMOVED, false)
}

context.sendBroadcast(intent)
Expand Down