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 android.content.pm.overlay; 18 19 import android.annotation.NonNull; 20 import android.annotation.Nullable; 21 22 import com.android.internal.util.DataClass; 23 24 import java.util.ArrayList; 25 import java.util.List; 26 import java.util.Objects; 27 28 /** @hide */ 29 @DataClass(genConstructor = false, genBuilder = false, genHiddenBuilder = false, 30 genEqualsHashCode = true, genToString = true) 31 public class OverlayPaths { 32 /** 33 * Represents {@link android.content.pm.ApplicationInfo#resourceDirs}. 34 * Only contains paths to APKs of overlays that can have their idmap resolved from their base 35 * APK path. Currently all overlay APKs can have their idmap path resolved from their idmap 36 * path. 37 */ 38 @NonNull 39 private final List<String> mResourceDirs = new ArrayList<>(); 40 41 /** 42 * Represents {@link android.content.pm.ApplicationInfo#overlayPaths}. 43 * Contains the contents of {@link #getResourceDirs()} and along with paths for overlays 44 * that are not APKs. 45 */ 46 @NonNull 47 private final List<String> mOverlayPaths = new ArrayList<>(); 48 49 public static class Builder { 50 final OverlayPaths mPaths = new OverlayPaths(); 51 Builder()52 public Builder() {} 53 Builder(@onNull OverlayPaths base)54 public Builder(@NonNull OverlayPaths base) { 55 mPaths.mResourceDirs.addAll(base.getResourceDirs()); 56 mPaths.mOverlayPaths.addAll(base.getOverlayPaths()); 57 } 58 59 /** 60 * Adds a non-APK path to the contents of {@link OverlayPaths#getOverlayPaths()}. 61 */ addNonApkPath(@onNull String idmapPath)62 public Builder addNonApkPath(@NonNull String idmapPath) { 63 mPaths.mOverlayPaths.add(idmapPath); 64 return this; 65 } 66 67 /** 68 * Adds a overlay APK path to the contents of {@link OverlayPaths#getResourceDirs()} and 69 * {@link OverlayPaths#getOverlayPaths()}. 70 */ addApkPath(@onNull String overlayPath)71 public Builder addApkPath(@NonNull String overlayPath) { 72 addUniquePath(mPaths.mResourceDirs, overlayPath); 73 addUniquePath(mPaths.mOverlayPaths, overlayPath); 74 return this; 75 } 76 addAll(@ullable OverlayPaths other)77 public Builder addAll(@Nullable OverlayPaths other) { 78 if (other != null) { 79 for (final String path : other.getResourceDirs()) { 80 addUniquePath(mPaths.mResourceDirs, path); 81 } 82 for (final String path : other.getOverlayPaths()) { 83 addUniquePath(mPaths.mOverlayPaths, path); 84 } 85 } 86 return this; 87 } 88 build()89 public OverlayPaths build() { 90 return mPaths; 91 } 92 addUniquePath(@onNull List<String> paths, @NonNull String path)93 private static void addUniquePath(@NonNull List<String> paths, @NonNull String path) { 94 if (!paths.contains(path)) { 95 paths.add(path); 96 } 97 } 98 } 99 100 /** 101 * Returns whether {@link #getOverlayPaths()} and {@link #getOverlayPaths} are empty. 102 */ isEmpty()103 public boolean isEmpty() { 104 return mResourceDirs.isEmpty() && mOverlayPaths.isEmpty(); 105 } 106 OverlayPaths()107 private OverlayPaths() { 108 } 109 110 111 112 // Code below generated by codegen v1.0.22. 113 // 114 // DO NOT MODIFY! 115 // CHECKSTYLE:OFF Generated code 116 // 117 // To regenerate run: 118 // $ codegen $ANDROID_BUILD_TOP/frameworks/base/core/java/android/content/pm/overlay/OverlayPaths.java 119 // 120 // To exclude the generated code from IntelliJ auto-formatting enable (one-time): 121 // Settings > Editor > Code Style > Formatter Control 122 //@formatter:off 123 124 125 /** 126 * Represents {@link android.content.pm.ApplicationInfo#resourceDirs}. 127 * Only contains paths to APKs of overlays that can have their idmap resolved from their base 128 * APK path. Currently all overlay APKs can have their idmap path resolved from their idmap 129 * path. 130 */ 131 @DataClass.Generated.Member getResourceDirs()132 public @NonNull List<String> getResourceDirs() { 133 return mResourceDirs; 134 } 135 136 /** 137 * Represents {@link android.content.pm.ApplicationInfo#overlayPaths}. 138 * Contains the contents of {@link #getResourceDirs()} and along with paths for overlays 139 * that are not APKs. 140 */ 141 @DataClass.Generated.Member getOverlayPaths()142 public @NonNull List<String> getOverlayPaths() { 143 return mOverlayPaths; 144 } 145 146 @Override 147 @DataClass.Generated.Member toString()148 public String toString() { 149 // You can override field toString logic by defining methods like: 150 // String fieldNameToString() { ... } 151 152 return "OverlayPaths { " + 153 "resourceDirs = " + mResourceDirs + ", " + 154 "overlayPaths = " + mOverlayPaths + 155 " }"; 156 } 157 158 @Override 159 @DataClass.Generated.Member equals(@ndroid.annotation.Nullable Object o)160 public boolean equals(@android.annotation.Nullable Object o) { 161 // You can override field equality logic by defining either of the methods like: 162 // boolean fieldNameEquals(OverlayPaths other) { ... } 163 // boolean fieldNameEquals(FieldType otherValue) { ... } 164 165 if (this == o) return true; 166 if (o == null || getClass() != o.getClass()) return false; 167 @SuppressWarnings("unchecked") 168 OverlayPaths that = (OverlayPaths) o; 169 //noinspection PointlessBooleanExpression 170 return true 171 && Objects.equals(mResourceDirs, that.mResourceDirs) 172 && Objects.equals(mOverlayPaths, that.mOverlayPaths); 173 } 174 175 @Override 176 @DataClass.Generated.Member hashCode()177 public int hashCode() { 178 // You can override field hashCode logic by defining methods like: 179 // int fieldNameHashCode() { ... } 180 181 int _hash = 1; 182 _hash = 31 * _hash + Objects.hashCode(mResourceDirs); 183 _hash = 31 * _hash + Objects.hashCode(mOverlayPaths); 184 return _hash; 185 } 186 187 @DataClass.Generated( 188 time = 1612307813586L, 189 codegenVersion = "1.0.22", 190 sourceFile = "frameworks/base/core/java/android/content/pm/overlay/OverlayPaths.java", 191 inputSignatures = "private final @android.annotation.NonNull java.util.List<java.lang.String> mResourceDirs\nprivate final @android.annotation.NonNull java.util.List<java.lang.String> mOverlayPaths\npublic boolean isEmpty()\nclass OverlayPaths extends java.lang.Object implements []\nfinal android.content.pm.overlay.OverlayPaths mPaths\npublic android.content.pm.overlay.OverlayPaths.Builder addNonApkPath(java.lang.String)\npublic android.content.pm.overlay.OverlayPaths.Builder addApkPath(java.lang.String)\npublic android.content.pm.overlay.OverlayPaths.Builder addAll(android.content.pm.overlay.OverlayPaths)\npublic android.content.pm.overlay.OverlayPaths build()\nprivate static void addUniquePath(java.util.List<java.lang.String>,java.lang.String)\nclass Builder extends java.lang.Object implements []\n@com.android.internal.util.DataClass(genConstructor=false, genBuilder=false, genHiddenBuilder=false, genEqualsHashCode=true, genToString=true)") 192 @Deprecated __metadata()193 private void __metadata() {} 194 195 196 //@formatter:on 197 // End of generated code 198 199 } 200