Debian Codegraph @

core/java/android/content/pm/InstallSourceInfo.java

raw symbols SCIP
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 @Nullable private final int mPackageSource;
39
40 /** @hide */
41 public InstallSourceInfo(@Nullable String initiatingPackageName,
42 @Nullable SigningInfo initiatingPackageSigningInfo,
43 @Nullable String originatingPackageName, @Nullable String installingPackageName) {
44 this(initiatingPackageName, initiatingPackageSigningInfo, originatingPackageName,
45 installingPackageName, PackageInstaller.PACKAGE_SOURCE_UNSPECIFIED);
46 }
47
48 /** @hide */
49 public InstallSourceInfo(@Nullable String initiatingPackageName,
50 @Nullable SigningInfo initiatingPackageSigningInfo,
51 @Nullable String originatingPackageName, @Nullable String installingPackageName,
52 int packageSource) {
53 mInitiatingPackageName = initiatingPackageName;
54 mInitiatingPackageSigningInfo = initiatingPackageSigningInfo;
55 mOriginatingPackageName = originatingPackageName;
56 mInstallingPackageName = installingPackageName;
57 mPackageSource = packageSource;
58 }
59
60 @Override
61 public int describeContents() {
62 return mInitiatingPackageSigningInfo == null
63 ? 0 : mInitiatingPackageSigningInfo.describeContents();
64 }
65
66 @Override
67 public void writeToParcel(@NonNull Parcel dest, int flags) {
68 dest.writeString(mInitiatingPackageName);
69 dest.writeParcelable(mInitiatingPackageSigningInfo, flags);
70 dest.writeString(mOriginatingPackageName);
71 dest.writeString(mInstallingPackageName);
72 dest.writeInt(mPackageSource);
73 }
74
75 private InstallSourceInfo(Parcel source) {
76 mInitiatingPackageName = source.readString();
77 mInitiatingPackageSigningInfo = source.readParcelable(SigningInfo.class.getClassLoader(), android.content.pm.SigningInfo.class);
78 mOriginatingPackageName = source.readString();
79 mInstallingPackageName = source.readString();
80 mPackageSource = source.readInt();
81 }
82
83 /**
84 * The name of the package that requested the installation, or null if not available.
85 *
86 * This is normally the same as the installing package name. If the installing package name
87 * is changed, for example by calling
88 * {@link PackageManager#setInstallerPackageName(String, String)}, the initiating package name
89 * remains unchanged. It continues to identify the actual package that performed the install
90 * or update.
91 * <p>
92 * Null may be returned if the app was not installed by a package (e.g. a system app or an app
93 * installed via adb) or if the initiating package has itself been uninstalled.
94 */
95 @Nullable
96 public String getInitiatingPackageName() {
97 return mInitiatingPackageName;
98 }
99
100 /**
101 * Information about the signing certificates used to sign the initiating package, if available.
102 */
103 @Nullable
104 public SigningInfo getInitiatingPackageSigningInfo() {
105 return mInitiatingPackageSigningInfo;
106 }
107
108 /**
109 * The name of the package on behalf of which the initiating package requested the installation,
110 * or null if not available.
111 * <p>
112 * For example if a downloaded APK is installed via the Package Installer this could be the
113 * app that performed the download. This value is provided by the initiating package and not
114 * verified by the framework.
115 * <p>
116 * Note that the {@code InstallSourceInfo} returned by
117 * {@link PackageManager#getInstallSourceInfo(String)} will not have this information
118 * available unless the calling application holds the INSTALL_PACKAGES permission.
119 */
120 @Nullable
121 public String getOriginatingPackageName() {
122 return mOriginatingPackageName;
123 }
124
125 /**
126 * The name of the package responsible for the installation (the installer of record), or null
127 * if not available.
128 * Note that this may differ from the initiating package name and can be modified via
129 * {@link PackageManager#setInstallerPackageName(String, String)}.
130 * <p>
131 * Null may be returned if the app was not installed by a package (e.g. a system app or an app
132 * installed via adb) or if the installing package has itself been uninstalled.
133 */
134 @Nullable
135 public String getInstallingPackageName() {
136 return mInstallingPackageName;
137 }
138
139 /**
140 * Information about the package source when installer installed this app.
141 */
142 public @PackageInstaller.PackageSourceType int getPackageSource() {
143 return mPackageSource;
144 }
145
146 @NonNull
147 public static final Parcelable.Creator<InstallSourceInfo> CREATOR =
148 new Creator<InstallSourceInfo>() {
149 @Override
150 public InstallSourceInfo createFromParcel(Parcel source) {
151 return new InstallSourceInfo(source);
152 }
153
154 @Override
155 public InstallSourceInfo[] newArray(int size) {
156 return new InstallSourceInfo[size];
157 }
158 };
159 }