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

Commit cae316df authored by Alan Stokes's avatar Alan Stokes
Browse files

Add PackageManager#getInstallSourceInfo() to the API.

Adds a new parcelable class InstallSourceInfo and a method to retrieve
it for a given package.

Also deprecates getInstallerPackageName(), which is subsumed by the
new method.

Bug: 134746019
Test: atest PackageManagerTests
Test: atest CtsContentTestCases
Change-Id: I9e5be29cac15a6bbe1482a6fdefca595418e6e66
parent a5ca0cc2
Loading
Loading
Loading
Loading
+11 −1
Original line number Diff line number Diff line
@@ -11358,6 +11358,15 @@ package android.content.pm {
    field public int version;
  }
  public final class InstallSourceInfo implements android.os.Parcelable {
    method public int describeContents();
    method @Nullable public String getInitiatingPackageName();
    method @Nullable public String getInstallingPackageName();
    method @Nullable public String getOriginatingPackageName();
    method public void writeToParcel(@NonNull android.os.Parcel, int);
    field @NonNull public static final android.os.Parcelable.Creator<android.content.pm.InstallSourceInfo> CREATOR;
  }
  public class InstrumentationInfo extends android.content.pm.PackageItemInfo implements android.os.Parcelable {
    ctor public InstrumentationInfo();
    ctor public InstrumentationInfo(android.content.pm.InstrumentationInfo);
@@ -11718,10 +11727,11 @@ package android.content.pm {
    method public abstract int getComponentEnabledSetting(@NonNull android.content.ComponentName);
    method @NonNull public abstract android.graphics.drawable.Drawable getDefaultActivityIcon();
    method @Nullable public abstract android.graphics.drawable.Drawable getDrawable(@NonNull String, @DrawableRes int, @Nullable android.content.pm.ApplicationInfo);
    method @NonNull public android.content.pm.InstallSourceInfo getInstallSourceInfo(@NonNull String) throws android.content.pm.PackageManager.NameNotFoundException;
    method @NonNull public abstract java.util.List<android.content.pm.ApplicationInfo> getInstalledApplications(int);
    method @NonNull public java.util.List<android.content.pm.ModuleInfo> getInstalledModules(int);
    method @NonNull public abstract java.util.List<android.content.pm.PackageInfo> getInstalledPackages(int);
    method @Nullable public abstract String getInstallerPackageName(@NonNull String);
    method @Deprecated @Nullable public abstract String getInstallerPackageName(@NonNull String);
    method @NonNull public abstract byte[] getInstantAppCookie();
    method public abstract int getInstantAppCookieMaxBytes();
    method @NonNull public abstract android.content.pm.InstrumentationInfo getInstrumentationInfo(@NonNull android.content.ComponentName, int) throws android.content.pm.PackageManager.NameNotFoundException;
+17 −1
Original line number Diff line number Diff line
@@ -39,6 +39,7 @@ import android.content.pm.IPackageDeleteObserver;
import android.content.pm.IPackageManager;
import android.content.pm.IPackageMoveObserver;
import android.content.pm.IPackageStatsObserver;
import android.content.pm.InstallSourceInfo;
import android.content.pm.InstantAppInfo;
import android.content.pm.InstrumentationInfo;
import android.content.pm.IntentFilterVerificationInfo;
@@ -2084,6 +2085,21 @@ public class ApplicationPackageManager extends PackageManager {
        }
    }

    @Override
    @NonNull
    public InstallSourceInfo getInstallSourceInfo(String packageName) throws NameNotFoundException {
        final InstallSourceInfo installSourceInfo;
        try {
            installSourceInfo = mPM.getInstallSourceInfo(packageName);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
        if (installSourceInfo == null) {
            throw new NameNotFoundException(packageName);
        }
        return installSourceInfo;
    }

    @Override
    public int getMoveStatus(int moveId) {
        try {
+3 −0
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ import android.content.pm.ChangedPackages;
import android.content.pm.InstantAppInfo;
import android.content.pm.FeatureInfo;
import android.content.pm.IDexModuleRegisterCallback;
import android.content.pm.InstallSourceInfo;
import android.content.pm.IPackageInstaller;
import android.content.pm.IPackageDeleteObserver;
import android.content.pm.IPackageDeleteObserver2;
@@ -237,6 +238,8 @@ interface IPackageManager {
    @UnsupportedAppUsage
    String getInstallerPackageName(in String packageName);

    InstallSourceInfo getInstallSourceInfo(in String packageName);

    void resetApplicationPreferences(int userId);

    @UnsupportedAppUsage
+19 −0
Original line number Diff line number Diff line
/*
 * Copyright 2019 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.content.pm;

parcelable InstallSourceInfo;
+110 −0
Original line number Diff line number Diff line
/*
 * Copyright 2019 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.content.pm;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.os.Parcel;
import android.os.Parcelable;

/**
 * Information about how an app was installed.
 * @see PackageManager#getInstallSourceInfo(String)
 */
public final class InstallSourceInfo implements Parcelable {

    @Nullable private final String mInitiatingPackageName;

    @Nullable private final String mOriginatingPackageName;

    @Nullable private final String mInstallingPackageName;

    /** @hide */
    public InstallSourceInfo(@Nullable String initiatingPackageName,
            @Nullable String originatingPackageName, @Nullable String installingPackageName) {
        this.mInitiatingPackageName = initiatingPackageName;
        this.mOriginatingPackageName = originatingPackageName;
        this.mInstallingPackageName = installingPackageName;
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(@NonNull Parcel dest, int flags) {
        dest.writeString(mInitiatingPackageName);
        dest.writeString(mOriginatingPackageName);
        dest.writeString(mInstallingPackageName);
    }

    private InstallSourceInfo(Parcel source) {
        mInitiatingPackageName = source.readString();
        mOriginatingPackageName = source.readString();
        mInstallingPackageName = source.readString();
    }

    /** The name of the package that requested the installation, or null if not available. */
    @Nullable
    public String getInitiatingPackageName() {
        return mInitiatingPackageName;
    }

    /**
     * The name of the package on behalf of which the initiating package requested the installation,
     * or null if not available.
     * <p>
     * For example if a downloaded APK is installed via the Package Installer this could be the
     * app that performed the download. This value is provided by the initiating package and not
     * verified by the framework.
     * <p>
     * Note that the {@code InstallSourceInfo} returned by
     * {@link PackageManager#getInstallSourceInfo(String)} will not have this information
     * available unless the calling application holds the INSTALL_PACKAGES permission.
     */
    @Nullable
    public String getOriginatingPackageName() {
        return mOriginatingPackageName;
    }

    /**
     * The name of the package responsible for the installation (the installer of record), or null
     * if not available.
     * Note that this may differ from the initiating package name and can be modified.
     *
     * @see PackageManager#setInstallerPackageName(String, String)
     */
    @Nullable
    public String getInstallingPackageName() {
        return mInstallingPackageName;
    }

    @NonNull
    public static final Parcelable.Creator<InstallSourceInfo> CREATOR =
            new Creator<InstallSourceInfo>() {
                @Override
                public InstallSourceInfo createFromParcel(Parcel source) {
                    return new InstallSourceInfo(source);
                }

                @Override
                public InstallSourceInfo[] newArray(int size) {
                    return new InstallSourceInfo[size];
                }
            };
}
Loading