• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2011 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.sdklib.internal.repository.archives;
18 
19 import com.android.sdklib.internal.repository.IDescription;
20 import com.android.sdklib.internal.repository.packages.Package;
21 
22 
23 /**
24  * Represents an archive that we want to install and the archive that it is
25  * going to replace, if any.
26  */
27 public class ArchiveReplacement implements IDescription {
28 
29     private final Archive mNewArchive;
30     private final Archive mReplaced;
31 
32     /**
33      * Creates a new replacement where the {@code newArchive} will replace the
34      * currently installed {@code replaced} archive.
35      * When {@code newArchive} is not intended to replace anything (e.g. because
36      * the user is installing a new package not present on her system yet), then
37      * {@code replace} shall be null.
38      *
39      * @param newArchive A "new archive" to be installed. This is always an archive
40      *          that comes from a remote site. This <em>may</em> be null.
41      * @param replaced An optional local archive that the new one will replace.
42      *          Can be null if this archive does not replace anything.
43      */
ArchiveReplacement(Archive newArchive, Archive replaced)44     public ArchiveReplacement(Archive newArchive, Archive replaced) {
45         mNewArchive = newArchive;
46         mReplaced = replaced;
47     }
48 
49     /**
50      * Returns the "new archive" to be installed.
51      * This <em>may</em> be null for missing archives.
52      */
getNewArchive()53     public Archive getNewArchive() {
54         return mNewArchive;
55     }
56 
57     /**
58      * Returns an optional local archive that the new one will replace.
59      * Can be null if this archive does not replace anything.
60      */
getReplaced()61     public Archive getReplaced() {
62         return mReplaced;
63     }
64 
65     /**
66      * Returns the long description of the parent package of the new archive, if not null.
67      * Otherwise returns an empty string.
68      */
69     @Override
getLongDescription()70     public String getLongDescription() {
71         if (mNewArchive != null) {
72             Package p = mNewArchive.getParentPackage();
73             if (p != null) {
74                 return p.getLongDescription();
75             }
76         }
77         return "";
78     }
79 
80     /**
81      * Returns the short description of the parent package of the new archive, if not null.
82      * Otherwise returns an empty string.
83      */
84     @Override
getShortDescription()85     public String getShortDescription() {
86         if (mNewArchive != null) {
87             Package p = mNewArchive.getParentPackage();
88             if (p != null) {
89                 return p.getShortDescription();
90             }
91         }
92         return "";
93     }
94 
95     /**
96      * Returns the short description of the parent package of the new archive, if not null.
97      * Otherwise returns the default Object toString result.
98      * <p/>
99      * This is mostly helpful for debugging. For UI display, use the {@link IDescription}
100      * interface.
101      */
102     @Override
toString()103     public String toString() {
104         if (mNewArchive != null) {
105             Package p = mNewArchive.getParentPackage();
106             if (p != null) {
107                 return p.getShortDescription();
108             }
109         }
110         return super.toString();
111     }
112 }
113