Skip to content

Commit

Permalink
fix: package removed after update
Browse files Browse the repository at this point in the history
  • Loading branch information
razinj committed Jul 1, 2024
1 parent 018491f commit a1097c6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 20 deletions.
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,25 @@ 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
}
// Ignore plugin apps
context.packageManager.getLaunchIntentForPackage(packageName) ?: 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

0 comments on commit a1097c6

Please sign in to comment.