1/*
2 * Copyright (C) 2007 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
17package android.content.pm;
18
19import android.os.Parcel;
20import android.os.Parcelable;
21import android.util.SparseArray;
22
23/**
24 * Information you can retrieve about a particular piece of test
25 * instrumentation.  This corresponds to information collected
26 * from the AndroidManifest.xml's <instrumentation> tag.
27 */
28public class InstrumentationInfo extends PackageItemInfo implements Parcelable {
29    /**
30     * The name of the application package being instrumented.  From the
31     * "package" attribute.
32     */
33    public String targetPackage;
34
35    /**
36     * Names of the process(es) this instrumentation will run in.  If not specified, only
37     * runs in the main process of the targetPackage.  Can either be a comma-separated list
38     * of process names or '*' for any process that launches to run targetPackage code.
39     */
40    public String targetProcesses;
41
42    /**
43     * Full path to the base APK for this application.
44     */
45    public String sourceDir;
46
47    /**
48     * Full path to the publicly available parts of {@link #sourceDir},
49     * including resources and manifest. This may be different from
50     * {@link #sourceDir} if an application is forward locked.
51     */
52    public String publicSourceDir;
53
54    /**
55     * The names of all installed split APKs, ordered lexicographically.
56     */
57    public String[] splitNames;
58
59    /**
60     * Full paths to zero or more split APKs, indexed by the same order as {@link #splitNames}.
61     */
62    public String[] splitSourceDirs;
63
64    /**
65     * Full path to the publicly available parts of {@link #splitSourceDirs},
66     * including resources and manifest. This may be different from
67     * {@link #splitSourceDirs} if an application is forward locked.
68     *
69     * @see #splitSourceDirs
70     */
71    public String[] splitPublicSourceDirs;
72
73    /**
74     * Maps the dependencies between split APKs. All splits implicitly depend on the base APK.
75     *
76     * Available since platform version O.
77     *
78     * Only populated if the application opts in to isolated split loading via the
79     * {@link android.R.attr.isolatedSplits} attribute in the <manifest> tag of the app's
80     * AndroidManifest.xml.
81     *
82     * The keys and values are all indices into the {@link #splitNames}, {@link #splitSourceDirs},
83     * and {@link #splitPublicSourceDirs} arrays.
84     * Each key represents a split and its value is an array of splits. The first element of this
85     * array is the parent split, and the rest are configuration splits. These configuration splits
86     * have no dependencies themselves.
87     * Cycles do not exist because they are illegal and screened for during installation.
88     *
89     * May be null if no splits are installed, or if no dependencies exist between them.
90     * @hide
91     */
92    public SparseArray<int[]> splitDependencies;
93
94    /**
95     * Full path to a directory assigned to the package for its persistent data.
96     */
97    public String dataDir;
98
99    /** {@hide} */
100    public String deviceProtectedDataDir;
101    /** {@hide} */
102    public String credentialProtectedDataDir;
103
104    /** {@hide} */
105    public String primaryCpuAbi;
106
107    /** {@hide} */
108    public String secondaryCpuAbi;
109
110    /** {@hide} Full path to the directory containing primary ABI native libraries. */
111    public String nativeLibraryDir;
112
113    /** {@hide} Full path to the directory containing secondary ABI native libraries. */
114    public String secondaryNativeLibraryDir;
115
116    /**
117     * Specifies whether or not this instrumentation will handle profiling.
118     */
119    public boolean handleProfiling;
120
121    /** Specifies whether or not to run this instrumentation as a functional test */
122    public boolean functionalTest;
123
124    public InstrumentationInfo() {
125    }
126
127    public InstrumentationInfo(InstrumentationInfo orig) {
128        super(orig);
129        targetPackage = orig.targetPackage;
130        targetProcesses = orig.targetProcesses;
131        sourceDir = orig.sourceDir;
132        publicSourceDir = orig.publicSourceDir;
133        splitNames = orig.splitNames;
134        splitSourceDirs = orig.splitSourceDirs;
135        splitPublicSourceDirs = orig.splitPublicSourceDirs;
136        splitDependencies = orig.splitDependencies;
137        dataDir = orig.dataDir;
138        deviceProtectedDataDir = orig.deviceProtectedDataDir;
139        credentialProtectedDataDir = orig.credentialProtectedDataDir;
140        primaryCpuAbi = orig.primaryCpuAbi;
141        secondaryCpuAbi = orig.secondaryCpuAbi;
142        nativeLibraryDir = orig.nativeLibraryDir;
143        secondaryNativeLibraryDir = orig.secondaryNativeLibraryDir;
144        handleProfiling = orig.handleProfiling;
145        functionalTest = orig.functionalTest;
146    }
147
148    public String toString() {
149        return "InstrumentationInfo{"
150            + Integer.toHexString(System.identityHashCode(this))
151            + " " + packageName + "}";
152    }
153
154    public int describeContents() {
155        return 0;
156    }
157
158    public void writeToParcel(Parcel dest, int parcelableFlags) {
159        super.writeToParcel(dest, parcelableFlags);
160        dest.writeString(targetPackage);
161        dest.writeString(targetProcesses);
162        dest.writeString(sourceDir);
163        dest.writeString(publicSourceDir);
164        dest.writeStringArray(splitNames);
165        dest.writeStringArray(splitSourceDirs);
166        dest.writeStringArray(splitPublicSourceDirs);
167        dest.writeSparseArray((SparseArray) splitDependencies);
168        dest.writeString(dataDir);
169        dest.writeString(deviceProtectedDataDir);
170        dest.writeString(credentialProtectedDataDir);
171        dest.writeString(primaryCpuAbi);
172        dest.writeString(secondaryCpuAbi);
173        dest.writeString(nativeLibraryDir);
174        dest.writeString(secondaryNativeLibraryDir);
175        dest.writeInt((handleProfiling == false) ? 0 : 1);
176        dest.writeInt((functionalTest == false) ? 0 : 1);
177    }
178
179    public static final Parcelable.Creator<InstrumentationInfo> CREATOR
180            = new Parcelable.Creator<InstrumentationInfo>() {
181        public InstrumentationInfo createFromParcel(Parcel source) {
182            return new InstrumentationInfo(source);
183        }
184        public InstrumentationInfo[] newArray(int size) {
185            return new InstrumentationInfo[size];
186        }
187    };
188
189    @SuppressWarnings("unchecked")
190    private InstrumentationInfo(Parcel source) {
191        super(source);
192        targetPackage = source.readString();
193        targetProcesses = source.readString();
194        sourceDir = source.readString();
195        publicSourceDir = source.readString();
196        splitNames = source.readStringArray();
197        splitSourceDirs = source.readStringArray();
198        splitPublicSourceDirs = source.readStringArray();
199        splitDependencies = source.readSparseArray(null);
200        dataDir = source.readString();
201        deviceProtectedDataDir = source.readString();
202        credentialProtectedDataDir = source.readString();
203        primaryCpuAbi = source.readString();
204        secondaryCpuAbi = source.readString();
205        nativeLibraryDir = source.readString();
206        secondaryNativeLibraryDir = source.readString();
207        handleProfiling = source.readInt() != 0;
208        functionalTest = source.readInt() != 0;
209    }
210
211    /** {@hide} */
212    public void copyTo(ApplicationInfo ai) {
213        ai.packageName = packageName;
214        ai.sourceDir = sourceDir;
215        ai.publicSourceDir = publicSourceDir;
216        ai.splitNames = splitNames;
217        ai.splitSourceDirs = splitSourceDirs;
218        ai.splitPublicSourceDirs = splitPublicSourceDirs;
219        ai.splitDependencies = splitDependencies;
220        ai.dataDir = dataDir;
221        ai.deviceProtectedDataDir = deviceProtectedDataDir;
222        ai.credentialProtectedDataDir = credentialProtectedDataDir;
223        ai.primaryCpuAbi = primaryCpuAbi;
224        ai.secondaryCpuAbi = secondaryCpuAbi;
225        ai.nativeLibraryDir = nativeLibraryDir;
226        ai.secondaryNativeLibraryDir = secondaryNativeLibraryDir;
227    }
228}
229