• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 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.Nullable;
20 import android.os.Parcel;
21 import android.os.Parcelable;
22 
23 import java.util.Objects;
24 
25 /**
26  * Information you can retrieve about a particular system
27  * module.
28  */
29 public final class ModuleInfo implements Parcelable {
30 
31      // NOTE: When adding new data members be sure to update the copy-constructor, Parcel
32      // constructor, and writeToParcel.
33 
34     /** Public name of this module. */
35     private CharSequence mName;
36 
37     /** The package name of this module. */
38     private String mPackageName;
39 
40     /**
41      * The name of the APEX this module is distributed as, or null if it is not distributed via
42      * APEX.
43      */
44     @Nullable private String mApexModuleName;
45 
46     /** Whether or not this module is hidden from the user. */
47     private boolean mHidden;
48 
49     // TODO: Decide whether we need an additional metadata bundle to support out of band
50     // updates to ModuleInfo.
51     //
52     // private Bundle mMetadata;
53 
54     /** @hide */
ModuleInfo()55     public ModuleInfo() {
56     }
57 
58     /** @hide */
ModuleInfo(ModuleInfo orig)59     public ModuleInfo(ModuleInfo orig) {
60         mName = orig.mName;
61         mPackageName = orig.mPackageName;
62         mHidden = orig.mHidden;
63         mApexModuleName = orig.mApexModuleName;
64     }
65 
66     /** @hide Sets the public name of this module. */
setName(CharSequence name)67     public ModuleInfo setName(CharSequence name) {
68         mName = name;
69         return this;
70     }
71 
72     /** Gets the public name of this module. */
getName()73     public @Nullable CharSequence getName() {
74         return mName;
75     }
76 
77     /** @hide Sets the package name of this module. */
setPackageName(String packageName)78     public ModuleInfo setPackageName(String packageName) {
79         mPackageName = packageName;
80         return this;
81     }
82 
83     /** Gets the package name of this module. */
getPackageName()84     public @Nullable String getPackageName() {
85         return mPackageName;
86     }
87 
88     /** @hide Sets whether or not this package is hidden. */
setHidden(boolean hidden)89     public ModuleInfo setHidden(boolean hidden) {
90         mHidden = hidden;
91         return this;
92     }
93 
94     /** Gets whether or not this package is hidden. */
isHidden()95     public boolean isHidden() {
96         return mHidden;
97     }
98 
99     /** @hide Sets the apex module name. */
setApexModuleName(@ullable String apexModuleName)100     public ModuleInfo setApexModuleName(@Nullable String apexModuleName) {
101         mApexModuleName = apexModuleName;
102         return this;
103     }
104 
105     /** @hide Gets the apex module name. */
getApexModuleName()106     public @Nullable String getApexModuleName() {
107         return mApexModuleName;
108     }
109 
110     /** Returns a string representation of this object. */
toString()111     public String toString() {
112         return "ModuleInfo{"
113             + Integer.toHexString(System.identityHashCode(this))
114             + " " + mName + "}";
115     }
116 
117     /** Describes the kinds of special objects contained in this object. */
describeContents()118     public int describeContents() {
119         return 0;
120     }
121 
122     @Override
hashCode()123     public int hashCode() {
124         int hashCode = 0;
125         hashCode = 31 * hashCode + Objects.hashCode(mName);
126         hashCode = 31 * hashCode + Objects.hashCode(mPackageName);
127         hashCode = 31 * hashCode + Objects.hashCode(mApexModuleName);
128         hashCode = 31 * hashCode + Boolean.hashCode(mHidden);
129         return hashCode;
130     }
131 
132     @Override
equals(@ullable Object obj)133     public boolean equals(@Nullable Object obj) {
134         if (!(obj instanceof ModuleInfo)) {
135             return false;
136         }
137         final ModuleInfo other = (ModuleInfo) obj;
138         return Objects.equals(mName, other.mName)
139                 && Objects.equals(mPackageName, other.mPackageName)
140                 && Objects.equals(mApexModuleName, other.mApexModuleName)
141                 && mHidden == other.mHidden;
142     }
143 
144     /** Flattens this object into the given {@link Parcel}. */
writeToParcel(Parcel dest, int parcelableFlags)145     public void writeToParcel(Parcel dest, int parcelableFlags) {
146         dest.writeCharSequence(mName);
147         dest.writeString(mPackageName);
148         dest.writeBoolean(mHidden);
149         dest.writeString(mApexModuleName);
150     }
151 
ModuleInfo(Parcel source)152     private ModuleInfo(Parcel source) {
153         mName = source.readCharSequence();
154         mPackageName = source.readString();
155         mHidden = source.readBoolean();
156         mApexModuleName = source.readString();
157     }
158 
159     public static final @android.annotation.NonNull Parcelable.Creator<ModuleInfo> CREATOR =
160             new Parcelable.Creator<ModuleInfo>() {
161         public ModuleInfo createFromParcel(Parcel source) {
162             return new ModuleInfo(source);
163         }
164         public ModuleInfo[] newArray(int size) {
165             return new ModuleInfo[size];
166         }
167     };
168 }
169