1 /* 2 * Copyright (C) 2020 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.google.android.startop.iorap; 18 19 import android.annotation.NonNull; 20 import android.os.Parcelable; 21 import android.os.Parcel; 22 23 import android.annotation.IntDef; 24 25 import java.lang.annotation.Retention; 26 import java.lang.annotation.RetentionPolicy; 27 import java.util.Objects; 28 29 /** 30 * Notifications for iorapd specifying when a package is updated by dexopt service.<br /><br /> 31 * 32 * @hide 33 */ 34 public class DexOptEvent implements Parcelable { 35 public static final int TYPE_PACKAGE_UPDATE = 0; 36 private static final int TYPE_MAX = 0; 37 38 /** @hide */ 39 @IntDef(flag = true, prefix = { "TYPE_" }, value = { 40 TYPE_PACKAGE_UPDATE, 41 }) 42 @Retention(RetentionPolicy.SOURCE) 43 public @interface Type {} 44 45 @Type public final int type; 46 public final String packageName; 47 48 @NonNull createPackageUpdate(String packageName)49 public static DexOptEvent createPackageUpdate(String packageName) { 50 return new DexOptEvent(TYPE_PACKAGE_UPDATE, packageName); 51 } 52 DexOptEvent(@ype int type, String packageName)53 private DexOptEvent(@Type int type, String packageName) { 54 this.type = type; 55 this.packageName = packageName; 56 57 checkConstructorArguments(); 58 } 59 checkConstructorArguments()60 private void checkConstructorArguments() { 61 CheckHelpers.checkTypeInRange(type, TYPE_MAX); 62 Objects.requireNonNull(packageName, "packageName"); 63 } 64 65 @Override toString()66 public String toString() { 67 return String.format("{DexOptEvent: packageName: %s}", packageName); 68 } 69 70 @Override equals(Object other)71 public boolean equals(Object other) { 72 if (this == other) { 73 return true; 74 } else if (other instanceof DexOptEvent) { 75 return equals((DexOptEvent) other); 76 } 77 return false; 78 } 79 equals(DexOptEvent other)80 private boolean equals(DexOptEvent other) { 81 return packageName.equals(other.packageName); 82 } 83 84 //<editor-fold desc="Binder boilerplate"> 85 @Override writeToParcel(Parcel out, int flags)86 public void writeToParcel(Parcel out, int flags) { 87 out.writeInt(type); 88 out.writeString(packageName); 89 } 90 DexOptEvent(Parcel in)91 private DexOptEvent(Parcel in) { 92 this.type = in.readInt(); 93 this.packageName = in.readString(); 94 95 checkConstructorArguments(); 96 } 97 98 @Override describeContents()99 public int describeContents() { 100 return 0; 101 } 102 103 public static final Parcelable.Creator<DexOptEvent> CREATOR 104 = new Parcelable.Creator<DexOptEvent>() { 105 public DexOptEvent createFromParcel(Parcel in) { 106 return new DexOptEvent(in); 107 } 108 109 public DexOptEvent[] newArray(int size) { 110 return new DexOptEvent[size]; 111 } 112 }; 113 //</editor-fold> 114 } 115