Todd Kennedy | 3dbf83a | 2018-11-13 13:29:16 -0800 | [diff] [blame] | 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. */ |
Narayan Kamath | acdccf0 | 2019-01-30 19:41:01 +0000 | [diff] [blame] | 35 | private CharSequence mName; |
Todd Kennedy | 3dbf83a | 2018-11-13 13:29:16 -0800 | [diff] [blame] | 36 | |
| 37 | /** The package name of this module. */ |
| 38 | private String mPackageName; |
| 39 | |
| 40 | /** Whether or not this module is hidden from the user. */ |
| 41 | private boolean mHidden; |
| 42 | |
| 43 | // TODO: Decide whether we need an additional metadata bundle to support out of band |
| 44 | // updates to ModuleInfo. |
| 45 | // |
| 46 | // private Bundle mMetadata; |
| 47 | |
| 48 | /** @hide */ |
| 49 | public ModuleInfo() { |
| 50 | } |
| 51 | |
| 52 | /** @hide */ |
| 53 | public ModuleInfo(ModuleInfo orig) { |
| 54 | mName = orig.mName; |
| 55 | mPackageName = orig.mPackageName; |
| 56 | mHidden = orig.mHidden; |
| 57 | } |
| 58 | |
| 59 | /** @hide Sets the public name of this module. */ |
Narayan Kamath | acdccf0 | 2019-01-30 19:41:01 +0000 | [diff] [blame] | 60 | public ModuleInfo setName(CharSequence name) { |
Todd Kennedy | 3dbf83a | 2018-11-13 13:29:16 -0800 | [diff] [blame] | 61 | mName = name; |
| 62 | return this; |
| 63 | } |
| 64 | |
| 65 | /** Gets the public name of this module. */ |
Narayan Kamath | acdccf0 | 2019-01-30 19:41:01 +0000 | [diff] [blame] | 66 | public @Nullable CharSequence getName() { |
Todd Kennedy | 3dbf83a | 2018-11-13 13:29:16 -0800 | [diff] [blame] | 67 | return mName; |
| 68 | } |
| 69 | |
| 70 | /** @hide Sets the package name of this module. */ |
| 71 | public ModuleInfo setPackageName(String packageName) { |
| 72 | mPackageName = packageName; |
| 73 | return this; |
| 74 | } |
| 75 | |
| 76 | /** Gets the package name of this module. */ |
| 77 | public @Nullable String getPackageName() { |
| 78 | return mPackageName; |
| 79 | } |
| 80 | |
| 81 | /** @hide Sets whether or not this package is hidden. */ |
| 82 | public ModuleInfo setHidden(boolean hidden) { |
| 83 | mHidden = hidden; |
| 84 | return this; |
| 85 | } |
| 86 | |
| 87 | /** Gets whether or not this package is hidden. */ |
| 88 | public boolean isHidden() { |
| 89 | return mHidden; |
| 90 | } |
| 91 | |
| 92 | /** Returns a string representation of this object. */ |
| 93 | public String toString() { |
| 94 | return "ModuleInfo{" |
| 95 | + Integer.toHexString(System.identityHashCode(this)) |
| 96 | + " " + mName + "}"; |
| 97 | } |
| 98 | |
| 99 | /** Describes the kinds of special objects contained in this object. */ |
| 100 | public int describeContents() { |
| 101 | return 0; |
| 102 | } |
| 103 | |
| 104 | @Override |
| 105 | public int hashCode() { |
| 106 | int hashCode = 0; |
| 107 | hashCode = 31 * hashCode + Objects.hashCode(mName); |
| 108 | hashCode = 31 * hashCode + Objects.hashCode(mPackageName); |
| 109 | hashCode = 31 * hashCode + Boolean.hashCode(mHidden); |
| 110 | return hashCode; |
| 111 | } |
| 112 | |
| 113 | @Override |
| 114 | public boolean equals(Object obj) { |
| 115 | if (!(obj instanceof ModuleInfo)) { |
| 116 | return false; |
| 117 | } |
| 118 | final ModuleInfo other = (ModuleInfo) obj; |
| 119 | return Objects.equals(mName, other.mName) |
| 120 | && Objects.equals(mPackageName, other.mPackageName) |
| 121 | && mHidden == other.mHidden; |
| 122 | } |
| 123 | |
| 124 | /** Flattens this object into the given {@link Parcel}. */ |
| 125 | public void writeToParcel(Parcel dest, int parcelableFlags) { |
Narayan Kamath | acdccf0 | 2019-01-30 19:41:01 +0000 | [diff] [blame] | 126 | dest.writeCharSequence(mName); |
Todd Kennedy | 3dbf83a | 2018-11-13 13:29:16 -0800 | [diff] [blame] | 127 | dest.writeString(mPackageName); |
| 128 | dest.writeBoolean(mHidden); |
| 129 | } |
| 130 | |
| 131 | private ModuleInfo(Parcel source) { |
Narayan Kamath | acdccf0 | 2019-01-30 19:41:01 +0000 | [diff] [blame] | 132 | mName = source.readCharSequence(); |
Todd Kennedy | 3dbf83a | 2018-11-13 13:29:16 -0800 | [diff] [blame] | 133 | mPackageName = source.readString(); |
| 134 | mHidden = source.readBoolean(); |
| 135 | } |
| 136 | |
Jeff Sharkey | 9e8f83d | 2019-02-28 12:06:45 -0700 | [diff] [blame] | 137 | public static final @android.annotation.NonNull Parcelable.Creator<ModuleInfo> CREATOR = |
Todd Kennedy | 3dbf83a | 2018-11-13 13:29:16 -0800 | [diff] [blame] | 138 | new Parcelable.Creator<ModuleInfo>() { |
| 139 | public ModuleInfo createFromParcel(Parcel source) { |
| 140 | return new ModuleInfo(source); |
| 141 | } |
| 142 | public ModuleInfo[] newArray(int size) { |
| 143 | return new ModuleInfo[size]; |
| 144 | } |
| 145 | }; |
| 146 | } |