• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2009 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.sdkuilib.internal.repository;
18 
19 import com.android.sdklib.internal.repository.Archive;
20 
21 import java.util.ArrayList;
22 import java.util.Collection;
23 
24 /**
25  * Represents an archive that we want to install.
26  * Note that the installer deals with archives whereas the user mostly sees packages
27  * but as far as we are concerned for installation there's a 1-to-1 mapping.
28  * <p/>
29  * A new archive is always a remote archive that needs to be downloaded and then
30  * installed. It can replace an existing local one. It can also depends on another
31  * (new or local) archive, which means the dependent archive needs to be successfully
32  * installed first. Finally this archive can also be a dependency for another one.
33  *
34  * @see ArchiveInfo#ArchiveInfo(Archive, Archive, ArchiveInfo)
35  */
36 class ArchiveInfo {
37 
38     private final Archive mNewArchive;
39     private final Archive mReplaced;
40     private final ArchiveInfo mDependsOn;
41     private final ArrayList<ArchiveInfo> mDependencyFor = new ArrayList<ArchiveInfo>();
42     private boolean mAccepted;
43     private boolean mRejected;
44 
45     /**
46      *
47      * @param newArchive A "new archive" to be installed. This is always an archive
48      *          that comes from a remote site. This can not be null.
49      * @param replaced An optional local archive that the new one will replace.
50      *          Can be null if this archive does not replace anything.
51      * @param dependsOn An optional new or local dependency, that is an archive that
52      *          <em>this</em> archive depends upon. In other words, we can only install
53      *          this archive if the dependency has been successfully installed. It also
54      *          means we need to install the dependency first.
55      */
ArchiveInfo(Archive newArchive, Archive replaced, ArchiveInfo dependsOn)56     public ArchiveInfo(Archive newArchive, Archive replaced, ArchiveInfo dependsOn) {
57         mNewArchive = newArchive;
58         mReplaced = replaced;
59         mDependsOn = dependsOn;
60     }
61 
62     /**
63      * Returns the "new archive" to be installed.
64      * This is always an archive that comes from a remote site.
65      */
getNewArchive()66     public Archive getNewArchive() {
67         return mNewArchive;
68     }
69 
70     /**
71      * Returns an optional local archive that the new one will replace.
72      * Can be null if this archive does not replace anything.
73      */
getReplaced()74     public Archive getReplaced() {
75         return mReplaced;
76     }
77 
78     /**
79      * Returns an optional new or local dependency, that is an archive that <em>this</em>
80      * archive depends upon. In other words, we can only install this archive if the
81      * dependency has been successfully installed. It also means we need to install the
82      * dependency first.
83      */
getDependsOn()84     public ArchiveInfo getDependsOn() {
85         return mDependsOn;
86     }
87 
88     /**
89      * Returns true if this new archive is a dependency for <em>another</em> one that we
90      * want to install.
91      */
isDependencyFor()92     public boolean isDependencyFor() {
93         return mDependencyFor.size() > 0;
94     }
95 
96     /**
97      * Adds an {@link ArchiveInfo} for which <em>this</em> package is a dependency.
98      * This means the package added here depends on this package.
99      */
addDependencyFor(ArchiveInfo dependencyFor)100     public void addDependencyFor(ArchiveInfo dependencyFor) {
101         if (!mDependencyFor.contains(dependencyFor)) {
102             mDependencyFor.add(dependencyFor);
103         }
104     }
105 
getDependenciesFor()106     public Collection<ArchiveInfo> getDependenciesFor() {
107         return mDependencyFor;
108     }
109 
110     /**
111      * Sets whether this archive was accepted (either manually by the user or
112      * automatically if it doesn't have a license) for installation.
113      */
setAccepted(boolean accepted)114     public void setAccepted(boolean accepted) {
115         mAccepted = accepted;
116     }
117 
118     /**
119      * Returns whether this archive was accepted (either manually by the user or
120      * automatically if it doesn't have a license) for installation.
121      */
isAccepted()122     public boolean isAccepted() {
123         return mAccepted;
124     }
125 
126     /**
127      * Sets whether this archive was rejected manually by the user.
128      * An archive can neither accepted nor rejected.
129      */
setRejected(boolean rejected)130     public void setRejected(boolean rejected) {
131         mRejected = rejected;
132     }
133 
134     /**
135      * Returns whether this archive was rejected manually by the user.
136      * An archive can neither accepted nor rejected.
137      */
isRejected()138     public boolean isRejected() {
139         return mRejected;
140     }
141 }
142