1 /*
2  * Copyright (C) 2021 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 com.android.server.pm;
18 
19 import java.io.File;
20 
21 final class OriginInfo {
22     /**
23      * Location where install is coming from, before it has been
24      * copied/renamed into place. This could be a single monolithic APK
25      * file, or a cluster directory. This location may be untrusted.
26      */
27     final File mFile;
28 
29     /**
30      * Flag indicating that {@link #mFile} has already been staged, meaning downstream users
31      * don't need to defensively copy the contents.
32      */
33     final boolean mStaged;
34 
35     /**
36      * Flag indicating that {@link #mFile} is an already installed app that is being moved.
37      */
38     final boolean mExisting;
39 
40     final String mResolvedPath;
41     final File mResolvedFile;
42 
fromNothing()43     static OriginInfo fromNothing() {
44         return new OriginInfo(null, false, false);
45     }
46 
fromExistingFile(File file)47     static OriginInfo fromExistingFile(File file) {
48         return new OriginInfo(file, false, true);
49     }
50 
fromStagedFile(File file)51     static OriginInfo fromStagedFile(File file) {
52         return new OriginInfo(file, true, false);
53     }
54 
OriginInfo(File file, boolean staged, boolean existing)55     private OriginInfo(File file, boolean staged, boolean existing) {
56         mFile = file;
57         mStaged = staged;
58         mExisting = existing;
59 
60         if (file != null) {
61             mResolvedPath = file.getAbsolutePath();
62             mResolvedFile = file;
63         } else {
64             mResolvedPath = null;
65             mResolvedFile = null;
66         }
67     }
68 }
69