• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2019 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package android.content.pm;
18 
19 import android.annotation.NonNull;
20 import android.annotation.Nullable;
21 import android.os.Parcel;
22 import android.os.Parcelable;
23 
24 /**
25  * Information about how an app was installed.
26  * @see PackageManager#getInstallSourceInfo(String)
27  */
28 public final class InstallSourceInfo implements Parcelable {
29 
30     @Nullable private final String mInitiatingPackageName;
31 
32     @Nullable private final SigningInfo mInitiatingPackageSigningInfo;
33 
34     @Nullable private final String mOriginatingPackageName;
35 
36     @Nullable private final String mInstallingPackageName;
37 
38     /** @hide */
InstallSourceInfo(@ullable String initiatingPackageName, @Nullable SigningInfo initiatingPackageSigningInfo, @Nullable String originatingPackageName, @Nullable String installingPackageName)39     public InstallSourceInfo(@Nullable String initiatingPackageName,
40             @Nullable SigningInfo initiatingPackageSigningInfo,
41             @Nullable String originatingPackageName, @Nullable String installingPackageName) {
42         mInitiatingPackageName = initiatingPackageName;
43         mInitiatingPackageSigningInfo = initiatingPackageSigningInfo;
44         mOriginatingPackageName = originatingPackageName;
45         mInstallingPackageName = installingPackageName;
46     }
47 
48     @Override
describeContents()49     public int describeContents() {
50         return mInitiatingPackageSigningInfo == null
51                 ? 0 : mInitiatingPackageSigningInfo.describeContents();
52     }
53 
54     @Override
writeToParcel(@onNull Parcel dest, int flags)55     public void writeToParcel(@NonNull Parcel dest, int flags) {
56         dest.writeString(mInitiatingPackageName);
57         dest.writeParcelable(mInitiatingPackageSigningInfo, flags);
58         dest.writeString(mOriginatingPackageName);
59         dest.writeString(mInstallingPackageName);
60     }
61 
InstallSourceInfo(Parcel source)62     private InstallSourceInfo(Parcel source) {
63         mInitiatingPackageName = source.readString();
64         mInitiatingPackageSigningInfo = source.readParcelable(SigningInfo.class.getClassLoader());
65         mOriginatingPackageName = source.readString();
66         mInstallingPackageName = source.readString();
67     }
68 
69     /**
70      * The name of the package that requested the installation, or null if not available.
71      *
72      * This is normally the same as the installing package name. If the installing package name
73      * is changed, for example by calling
74      * {@link PackageManager#setInstallerPackageName(String, String)}, the initiating package name
75      * remains unchanged. It continues to identify the actual package that performed the install
76      * or update.
77      * <p>
78      * Null may be returned if the app was not installed by a package (e.g. a system app or an app
79      * installed via adb) or if the initiating package has itself been uninstalled.
80      */
81     @Nullable
getInitiatingPackageName()82     public String getInitiatingPackageName() {
83         return mInitiatingPackageName;
84     }
85 
86     /**
87      * Information about the signing certificates used to sign the initiating package, if available.
88      */
89     @Nullable
getInitiatingPackageSigningInfo()90     public SigningInfo getInitiatingPackageSigningInfo() {
91         return mInitiatingPackageSigningInfo;
92     }
93 
94     /**
95      * The name of the package on behalf of which the initiating package requested the installation,
96      * or null if not available.
97      * <p>
98      * For example if a downloaded APK is installed via the Package Installer this could be the
99      * app that performed the download. This value is provided by the initiating package and not
100      * verified by the framework.
101      * <p>
102      * Note that the {@code InstallSourceInfo} returned by
103      * {@link PackageManager#getInstallSourceInfo(String)} will not have this information
104      * available unless the calling application holds the INSTALL_PACKAGES permission.
105      */
106     @Nullable
getOriginatingPackageName()107     public String getOriginatingPackageName() {
108         return mOriginatingPackageName;
109     }
110 
111     /**
112      * The name of the package responsible for the installation (the installer of record), or null
113      * if not available.
114      * Note that this may differ from the initiating package name and can be modified via
115      * {@link PackageManager#setInstallerPackageName(String, String)}.
116      * <p>
117      * Null may be returned if the app was not installed by a package (e.g. a system app or an app
118      * installed via adb) or if the installing package has itself been uninstalled.
119      */
120     @Nullable
getInstallingPackageName()121     public String getInstallingPackageName() {
122         return mInstallingPackageName;
123     }
124 
125     @NonNull
126     public static final Parcelable.Creator<InstallSourceInfo> CREATOR =
127             new Creator<InstallSourceInfo>() {
128                 @Override
129                 public InstallSourceInfo createFromParcel(Parcel source) {
130                     return new InstallSourceInfo(source);
131                 }
132 
133                 @Override
134                 public InstallSourceInfo[] newArray(int size) {
135                     return new InstallSourceInfo[size];
136                 }
137             };
138 }
139