1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458
|
/*
* Copyright (C) 2015 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package android.content.om;
import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.SystemApi;
import android.annotation.UnsupportedAppUsage;
import android.annotation.UserIdInt;
import android.os.Parcel;
import android.os.Parcelable;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.Objects;
/**
* Immutable overlay information about a package. All PackageInfos that
* represent an overlay package will have a corresponding OverlayInfo.
*
* @hide
*/
@SystemApi
public final class OverlayInfo implements Parcelable {
/** @hide */
@IntDef(prefix = "STATE_", value = {
STATE_UNKNOWN,
STATE_MISSING_TARGET,
STATE_NO_IDMAP,
STATE_DISABLED,
STATE_ENABLED,
STATE_ENABLED_STATIC,
// @Deprecated STATE_TARGET_IS_BEING_REPLACED,
STATE_OVERLAY_IS_BEING_REPLACED,
})
/** @hide */
@Retention(RetentionPolicy.SOURCE)
public @interface State {}
/**
* An internal state used as the initial state of an overlay. OverlayInfo
* objects exposed outside the {@link
* com.android.server.om.OverlayManagerService} should never have this
* state.
*
* @hide
*/
public static final int STATE_UNKNOWN = -1;
/**
* The target package of the overlay is not installed. The overlay cannot be enabled.
*
* @hide
*/
public static final int STATE_MISSING_TARGET = 0;
/**
* Creation of idmap file failed (e.g. no matching resources). The overlay
* cannot be enabled.
*
* @hide
*/
public static final int STATE_NO_IDMAP = 1;
/**
* The overlay is currently disabled. It can be enabled.
*
* @see IOverlayManager#setEnabled
* @hide
*/
public static final int STATE_DISABLED = 2;
/**
* The overlay is currently enabled. It can be disabled.
*
* @see IOverlayManager#setEnabled
* @hide
*/
public static final int STATE_ENABLED = 3;
/**
* The target package is currently being upgraded or downgraded; the state
* will change once the package installation has finished.
* @hide
*
* @deprecated No longer used. Caused invalid transitions from enabled -> upgrading -> enabled,
* where an update is propagated when nothing has changed. Can occur during --dont-kill
* installs when code and resources are hot swapped and the Activity should not be relaunched.
* In all other cases, the process and therefore Activity is killed, so the state loop is
* irrelevant.
*/
@Deprecated
public static final int STATE_TARGET_IS_BEING_REPLACED = 4;
/**
* The overlay package is currently being upgraded or downgraded; the state
* will change once the package installation has finished.
* @hide
*/
public static final int STATE_OVERLAY_IS_BEING_REPLACED = 5;
/**
* The overlay package is currently enabled because it is marked as
* 'static'. It cannot be disabled but will change state if for instance
* its target is uninstalled.
* @hide
*/
public static final int STATE_ENABLED_STATIC = 6;
/**
* Overlay category: theme.
* <p>
* Change how Android (including the status bar, dialogs, ...) looks.
*
* @hide
*/
public static final String CATEGORY_THEME = "android.theme";
/**
* Package name of the overlay package
*
* @hide
*/
public final String packageName;
/**
* Package name of the target package
*
* @hide
*/
public final String targetPackageName;
/**
* Name of the target overlayable declaration.
*
* @hide
*/
public final String targetOverlayableName;
/**
* Category of the overlay package
*
* @hide
*/
public final String category;
/**
* Full path to the base APK for this overlay package
* @hide
*/
public final String baseCodePath;
/**
* The state of this OverlayInfo as defined by the STATE_* constants in this class.
* @hide
*/
@UnsupportedAppUsage
public final @State int state;
/**
* User handle for which this overlay applies
* @hide
*/
public final int userId;
/**
* Priority as read from the manifest. Used if isStatic is true. Not
* intended to be exposed to 3rd party.
*
* @hide
*/
public final int priority;
/**
* isStatic as read from the manifest. If true, the overlay is
* unconditionally loaded and cannot be unloaded. Not intended to be
* exposed to 3rd party.
*
* @hide
*/
public final boolean isStatic;
/**
* Create a new OverlayInfo based on source with an updated state.
*
* @param source the source OverlayInfo to base the new instance on
* @param state the new state for the source OverlayInfo
*
* @hide
*/
public OverlayInfo(@NonNull OverlayInfo source, @State int state) {
this(source.packageName, source.targetPackageName, source.targetOverlayableName,
source.category, source.baseCodePath, state, source.userId, source.priority,
source.isStatic);
}
/** @hide */
public OverlayInfo(@NonNull String packageName, @NonNull String targetPackageName,
@Nullable String targetOverlayableName, @Nullable String category,
@NonNull String baseCodePath, int state, int userId,
int priority, boolean isStatic) {
this.packageName = packageName;
this.targetPackageName = targetPackageName;
this.targetOverlayableName = targetOverlayableName;
this.category = category;
this.baseCodePath = baseCodePath;
this.state = state;
this.userId = userId;
this.priority = priority;
this.isStatic = isStatic;
ensureValidState();
}
/** @hide */
public OverlayInfo(Parcel source) {
packageName = source.readString();
targetPackageName = source.readString();
targetOverlayableName = source.readString();
category = source.readString();
baseCodePath = source.readString();
state = source.readInt();
userId = source.readInt();
priority = source.readInt();
isStatic = source.readBoolean();
ensureValidState();
}
/**
* Returns package name of the current overlay.
* @hide
*/
@SystemApi
@NonNull
public String getPackageName() {
return packageName;
}
/**
* Returns the target package name of the current overlay.
* @hide
*/
@SystemApi
@NonNull
public String getTargetPackageName() {
return targetPackageName;
}
/**
* Returns the category of the current overlay.
* @hide\
*/
@SystemApi
@Nullable
public String getCategory() {
return category;
}
/**
* Returns user handle for which this overlay applies to.
* @hide
*/
@SystemApi
@UserIdInt
public int getUserId() {
return userId;
}
/**
* Returns name of the target overlayable declaration.
* @hide
*/
@SystemApi
@Nullable
public String getTargetOverlayableName() {
return targetOverlayableName;
}
private void ensureValidState() {
if (packageName == null) {
throw new IllegalArgumentException("packageName must not be null");
}
if (targetPackageName == null) {
throw new IllegalArgumentException("targetPackageName must not be null");
}
if (baseCodePath == null) {
throw new IllegalArgumentException("baseCodePath must not be null");
}
switch (state) {
case STATE_UNKNOWN:
case STATE_MISSING_TARGET:
case STATE_NO_IDMAP:
case STATE_DISABLED:
case STATE_ENABLED:
case STATE_ENABLED_STATIC:
case STATE_TARGET_IS_BEING_REPLACED:
case STATE_OVERLAY_IS_BEING_REPLACED:
break;
default:
throw new IllegalArgumentException("State " + state + " is not a valid state");
}
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(packageName);
dest.writeString(targetPackageName);
dest.writeString(targetOverlayableName);
dest.writeString(category);
dest.writeString(baseCodePath);
dest.writeInt(state);
dest.writeInt(userId);
dest.writeInt(priority);
dest.writeBoolean(isStatic);
}
public static final @android.annotation.NonNull Parcelable.Creator<OverlayInfo> CREATOR =
new Parcelable.Creator<OverlayInfo>() {
@Override
public OverlayInfo createFromParcel(Parcel source) {
return new OverlayInfo(source);
}
@Override
public OverlayInfo[] newArray(int size) {
return new OverlayInfo[size];
}
};
/**
* Return true if this overlay is enabled, i.e. should be used to overlay
* the resources in the target package.
*
* Disabled overlay packages are installed but are currently not in use.
*
* @return true if the overlay is enabled, else false.
* @hide
*/
@SystemApi
public boolean isEnabled() {
switch (state) {
case STATE_ENABLED:
case STATE_ENABLED_STATIC:
return true;
default:
return false;
}
}
/**
* Translate a state to a human readable string. Only intended for
* debugging purposes.
*
* @return a human readable String representing the state.
* @hide
*/
public static String stateToString(@State int state) {
switch (state) {
case STATE_UNKNOWN:
return "STATE_UNKNOWN";
case STATE_MISSING_TARGET:
return "STATE_MISSING_TARGET";
case STATE_NO_IDMAP:
return "STATE_NO_IDMAP";
case STATE_DISABLED:
return "STATE_DISABLED";
case STATE_ENABLED:
return "STATE_ENABLED";
case STATE_ENABLED_STATIC:
return "STATE_ENABLED_STATIC";
case STATE_TARGET_IS_BEING_REPLACED:
return "STATE_TARGET_IS_BEING_REPLACED";
case STATE_OVERLAY_IS_BEING_REPLACED:
return "STATE_OVERLAY_IS_BEING_REPLACED";
default:
return "<unknown state>";
}
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + userId;
result = prime * result + state;
result = prime * result + ((packageName == null) ? 0 : packageName.hashCode());
result = prime * result + ((targetPackageName == null) ? 0 : targetPackageName.hashCode());
result = prime * result + ((targetOverlayableName == null) ? 0
: targetOverlayableName.hashCode());
result = prime * result + ((category == null) ? 0 : category.hashCode());
result = prime * result + ((baseCodePath == null) ? 0 : baseCodePath.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
OverlayInfo other = (OverlayInfo) obj;
if (userId != other.userId) {
return false;
}
if (state != other.state) {
return false;
}
if (!packageName.equals(other.packageName)) {
return false;
}
if (!targetPackageName.equals(other.targetPackageName)) {
return false;
}
if (!Objects.equals(targetOverlayableName, other.targetOverlayableName)) {
return false;
}
if (!Objects.equals(category, other.category)) {
return false;
}
if (!baseCodePath.equals(other.baseCodePath)) {
return false;
}
return true;
}
@Override
public String toString() {
return "OverlayInfo { overlay=" + packageName + ", targetPackage=" + targetPackageName
+ ((targetOverlayableName == null) ? ""
: ", targetOverlayable=" + targetOverlayableName)
+ ", state=" + state + " (" + stateToString(state) + "), userId=" + userId + " }";
}
}
|