Ensure Uninstall option appears for Linux apps

Fixes an issue where the Uninstall option would not appear after
installing some Linux apps. This was because the desktop file for the
app was created before the installation was finished. When garcon
noticed the new desktop and asked PackageKit if a package owned the
file, PackageKit said no because the owning package wasn't fully
installed.

Worked around this by adding a post-install hook to dpkg which will
touch a file in the /usr/share/applications directory after each install
is finished. garcon will notice the file change and rescan after the
install is done. The second scan should see that the desktop is owned by
the now-fully-installed package.

Alternatives considered: I tried to have garcon look at the dpkg lock
and only do the scan when dpkg wasn't in the middle of an operation.
This didn't work because garcon doesn't run as root and can't open the
dpkg lock file.

BUG=chromium:898295
TEST=Installed various packages, especially eclipse, both using apt-get
install and right-clicking the .deb file in Files app. Ensured uninstall
option appeared consistently.

Change-Id: I04605356afe7dfdd7bf9c70a4a3982e58b9dc8fa
Reviewed-on: https://chromium-review.googlesource.com/1468041
Commit-Ready: Ian Barkley-Yeung <iby@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
diff --git a/cros-garcon/BUILD b/cros-garcon/BUILD
index ce6075d..7856ece 100644
--- a/cros-garcon/BUILD
+++ b/cros-garcon/BUILD
@@ -1,3 +1,7 @@
+# Copyright 2019 The Chromium OS Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
 load("@bazel_tools//tools/build_defs/pkg:pkg.bzl", "pkg_tar", "pkg_deb")
 
 genrule(
@@ -68,11 +72,20 @@
 )
 
 pkg_tar(
+    name = "cros-garcon-dpkg-config",
+    strip_prefix = "/cros-garcon",
+    package_dir = "/etc/dpkg/dpkg.cfg.d",
+    srcs = ["garcon-hook"],
+    mode = "0644",
+)
+
+pkg_tar(
     name = "debian-data",
     extension = "tar.gz",
     deps = [
         ":cros-garcon-config",
         ":cros-garcon-desktop",
+        ":cros-garcon-dpkg-config",
         ":cros-garcon-etc-skel",
         ":cros-garcon-polkit",
         ":cros-garcon-systemd",
@@ -90,7 +103,7 @@
     maintainer = "The Chromium OS Authors <chromium-os-dev@chromium.org>",
     package = "cros-garcon",
     depends = ["desktop-file-utils","packagekit","xdg-utils"],
-    version = "0.20",
+    version = "0.21",
     section = "misc",
     conffiles_file = "conffiles",
     postinst = "postinst",
diff --git a/cros-garcon/garcon-hook b/cros-garcon/garcon-hook
new file mode 100644
index 0000000..eb389cf
--- /dev/null
+++ b/cros-garcon/garcon-hook
@@ -0,0 +1,8 @@
+# Copyright 2019 The Chromium OS Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+# The launcher will only display apps as uninstallable if the desktop file
+# is owned by a package when garcon scans it. Make sure garcon does its
+# scans after packages have finished installing.
+post-invoke='/usr/bin/touch /usr/share/applications/.garcon_trigger'