Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 65e13171 authored by Jacek Surazski's avatar Jacek Surazski
Browse files

PackageManager keeps track of who installed what.

Stores the package name of the installer app in packages.xml
parent 21fa8d31
Loading
Loading
Loading
Loading
+29 −1
Original line number Diff line number Diff line
@@ -35526,6 +35526,19 @@
<parameter name="flags" type="int">
</parameter>
</method>
<method name="getInstallerPackageName"
 return="java.lang.String"
 abstract="true"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="packageName" type="java.lang.String">
</parameter>
</method>
<method name="getInstrumentationInfo"
 return="android.content.pm.InstrumentationInfo"
 abstract="true"
@@ -35821,7 +35834,7 @@
</method>
<method name="installPackage"
 return="void"
 abstract="true"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
@@ -114343,6 +114356,19 @@
<parameter name="flags" type="int">
</parameter>
</method>
<method name="getInstallerPackageName"
 return="java.lang.String"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="packageName" type="java.lang.String">
</parameter>
</method>
<method name="getInstrumentationInfo"
 return="android.content.pm.InstrumentationInfo"
 abstract="false"
@@ -114635,6 +114661,8 @@
</parameter>
<parameter name="flags" type="int">
</parameter>
<parameter name="installerPackageName" type="java.lang.String">
</parameter>
</method>
<method name="isSafeMode"
 return="boolean"
+12 −2
Original line number Diff line number Diff line
@@ -579,6 +579,7 @@ public final class Pm {
    
    private void runInstall() {
        int installFlags = 0;
        String installerPackageName = null;

        String opt;
        while ((opt=nextOption()) != null) {
@@ -586,6 +587,13 @@ public final class Pm {
                installFlags |= PackageManager.FORWARD_LOCK_PACKAGE;
            } else if (opt.equals("-r")) {
                installFlags |= PackageManager.REPLACE_EXISTING_PACKAGE;
            } else if (opt.equals("-i")) {
                installerPackageName = nextOptionData();
                if (installerPackageName == null) {
                    System.err.println("Error: no value specified for -i");
                    showUsage();
                    return;
                }
            } else {
                System.err.println("Error: Unknown option: " + opt);
                showUsage();
@@ -603,7 +611,8 @@ public final class Pm {

        PackageInstallObserver obs = new PackageInstallObserver();
        try {
            mPm.installPackage(Uri.fromFile(new File(apkFilePath)), obs, installFlags);
            mPm.installPackage(Uri.fromFile(new File(apkFilePath)), obs, installFlags,
                    installerPackageName);
            
            synchronized (obs) {
                while (!obs.finished) {
@@ -812,7 +821,7 @@ public final class Pm {
        System.err.println("       pm list permissions [-g] [-f] [-d] [-u] [GROUP]");
        System.err.println("       pm list instrumentation [-f] [TARGET-PACKAGE]");        
        System.err.println("       pm path PACKAGE");
        System.err.println("       pm install [-l] [-r] PATH");
        System.err.println("       pm install [-l] [-r] [-i INSTALLER_PACKAGE_NAME] PATH");
        System.err.println("       pm uninstall [-k] PACKAGE");
        System.err.println("       pm enable PACKAGE_OR_COMPONENT");
        System.err.println("       pm disable PACKAGE_OR_COMPONENT");
@@ -840,6 +849,7 @@ public final class Pm {
        System.err.println("The install command installs a package to the system.  Use");
        System.err.println("the -l option to install the package with FORWARD_LOCK. Use");
        System.err.println("the -r option to reinstall an exisiting app, keeping its data.");
        System.err.println("the -i option to specify the installer package name.");
        System.err.println("");
        System.err.println("The uninstall command removes a package from the system. Use");
        System.err.println("the -k option to keep the data and cache directories around");
+13 −2
Original line number Diff line number Diff line
@@ -2326,14 +2326,25 @@ class ApplicationContext extends Context {
        }

        @Override
        public void installPackage(Uri packageURI, IPackageInstallObserver observer, int flags) {
        public void installPackage(Uri packageURI, IPackageInstallObserver observer, int flags,
                String installerPackageName) {
            try {
                mPM.installPackage(packageURI, observer, flags);
                mPM.installPackage(packageURI, observer, flags, installerPackageName);
            } catch (RemoteException e) {
                // Should never happen!
            }
        }

        @Override
        public String getInstallerPackageName(String packageName) {
            try {
                return mPM.getInstallerPackageName(packageName);
            } catch (RemoteException e) {
                // Should never happen!
            }
            return null;
        }

        @Override
        public void deletePackage(String packageName, IPackageDeleteObserver observer, int flags) {
            try {
+6 −1
Original line number Diff line number Diff line
@@ -140,8 +140,11 @@ interface IPackageManager {
     * @param observer a callback to use to notify when the package installation in finished.
     * @param flags - possible values: {@link #FORWARD_LOCK_PACKAGE},
     * {@link #REPLACE_EXISITING_PACKAGE}
     * @param installerPackageName Optional package name of the application that is performing the
     * installation. This identifies which market the package came from.
     */
    void installPackage(in Uri packageURI, IPackageInstallObserver observer, int flags);
    void installPackage(in Uri packageURI, IPackageInstallObserver observer, int flags,
            in String installerPackageName);

    /**
     * Delete a package.
@@ -152,6 +155,8 @@ interface IPackageManager {
     */
    void deletePackage(in String packageName, IPackageDeleteObserver observer, int flags);

    String getInstallerPackageName(in String packageName);

    void addPackageToPreferred(String packageName);
    
    void removePackageFromPreferred(String packageName);
+38 −2
Original line number Diff line number Diff line
@@ -1354,8 +1354,35 @@ public abstract class PackageManager {
     *
     * @see #installPackage(android.net.Uri)
     */
    public void installPackage(
            Uri packageURI, IPackageInstallObserver observer, int flags) {
        installPackage(packageURI, observer, flags, null);
    }

    /**
     * Install a package. Since this may take a little while, the result will
     * be posted back to the given observer.  An installation will fail if the calling context
     * lacks the {@link android.Manifest.permission#INSTALL_PACKAGES} permission, if the
     * package named in the package file's manifest is already installed, or if there's no space
     * available on the device.
     *
     * @param packageURI The location of the package file to install.  This can be a 'file:' or a
     * 'content:' URI.
     * @param observer An observer callback to get notified when the package installation is
     * complete. {@link IPackageInstallObserver#packageInstalled(String, int)} will be
     * called when that happens.  observer may be null to indicate that no callback is desired.
     * @param flags - possible values: {@link #FORWARD_LOCK_PACKAGE},
     * {@link #REPLACE_EXISTING_PACKAGE}
     * @param installerPackageName Optional package name of the application that is performing the
     * installation. This identifies which market the package came from.
     *
     * @see #installPackage(android.net.Uri)
     * 
     * @hide
     */
    public abstract void installPackage(
            Uri packageURI, IPackageInstallObserver observer, int flags);
            Uri packageURI, IPackageInstallObserver observer, int flags,
            String installerPackageName);

    /**
     * Attempts to delete a package.  Since this may take a little while, the result will
@@ -1374,6 +1401,15 @@ public abstract class PackageManager {
     */
    public abstract void deletePackage(
            String packageName, IPackageDeleteObserver observer, int flags);

    /**
     * Retrieve the package name of the application that installed a package. This identifies
     * which market the package came from.
     * 
     * @param packageName The name of the package to query
     */
    public abstract String getInstallerPackageName(String packageName);
    
    /**
     * Attempts to clear the user data directory of an application.
     * Since this may take a little while, the result will
@@ -1483,7 +1519,7 @@ public abstract class PackageManager {
     *
     * @param packageURI The location of the package file to install
     *
     * @see #installPackage(android.net.Uri, IPackageInstallObserver, int)
     * @see #installPackage(android.net.Uri, IPackageInstallObserver, int, String)
     */
    public void installPackage(Uri packageURI) {
        installPackage(packageURI, null, 0);
Loading