1 /* 2 * Copyright (C) 2022 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.app.job; 18 19 import android.annotation.NonNull; 20 import android.annotation.Nullable; 21 import android.os.Parcel; 22 import android.os.Parcelable; 23 24 import java.util.Objects; 25 26 /** 27 * Summary of a scheduled job that the user is meant to be aware of. 28 * 29 * @hide 30 */ 31 public class UserVisibleJobSummary implements Parcelable { 32 private final int mCallingUid; 33 @NonNull 34 private final String mCallingPackageName; 35 private final int mSourceUserId; 36 @NonNull 37 private final String mSourcePackageName; 38 @Nullable 39 private final String mNamespace; 40 private final int mJobId; 41 UserVisibleJobSummary(int callingUid, @NonNull String callingPackageName, int sourceUserId, @NonNull String sourcePackageName, @Nullable String namespace, int jobId)42 public UserVisibleJobSummary(int callingUid, @NonNull String callingPackageName, 43 int sourceUserId, @NonNull String sourcePackageName, 44 @Nullable String namespace, int jobId) { 45 mCallingUid = callingUid; 46 mCallingPackageName = callingPackageName; 47 mSourceUserId = sourceUserId; 48 mSourcePackageName = sourcePackageName; 49 mNamespace = namespace; 50 mJobId = jobId; 51 } 52 UserVisibleJobSummary(Parcel in)53 protected UserVisibleJobSummary(Parcel in) { 54 mCallingUid = in.readInt(); 55 mCallingPackageName = in.readString(); 56 mSourceUserId = in.readInt(); 57 mSourcePackageName = in.readString(); 58 mNamespace = in.readString(); 59 mJobId = in.readInt(); 60 } 61 62 @NonNull getCallingPackageName()63 public String getCallingPackageName() { 64 return mCallingPackageName; 65 } 66 getCallingUid()67 public int getCallingUid() { 68 return mCallingUid; 69 } 70 getJobId()71 public int getJobId() { 72 return mJobId; 73 } 74 75 @Nullable getNamespace()76 public String getNamespace() { 77 return mNamespace; 78 } 79 getSourceUserId()80 public int getSourceUserId() { 81 return mSourceUserId; 82 } 83 84 @NonNull getSourcePackageName()85 public String getSourcePackageName() { 86 return mSourcePackageName; 87 } 88 89 @Override equals(Object o)90 public boolean equals(Object o) { 91 if (this == o) return true; 92 if (!(o instanceof UserVisibleJobSummary)) return false; 93 UserVisibleJobSummary that = (UserVisibleJobSummary) o; 94 return mCallingUid == that.mCallingUid 95 && mCallingPackageName.equals(that.mCallingPackageName) 96 && mSourceUserId == that.mSourceUserId 97 && mSourcePackageName.equals(that.mSourcePackageName) 98 && Objects.equals(mNamespace, that.mNamespace) 99 && mJobId == that.mJobId; 100 } 101 102 @Override hashCode()103 public int hashCode() { 104 int result = 0; 105 result = 31 * result + mCallingUid; 106 result = 31 * result + mCallingPackageName.hashCode(); 107 result = 31 * result + mSourceUserId; 108 result = 31 * result + mSourcePackageName.hashCode(); 109 if (mNamespace != null) { 110 result = 31 * result + mNamespace.hashCode(); 111 } 112 result = 31 * result + mJobId; 113 return result; 114 } 115 116 @Override toString()117 public String toString() { 118 return "UserVisibleJobSummary{" 119 + "callingUid=" + mCallingUid 120 + ", callingPackageName='" + mCallingPackageName + "'" 121 + ", sourceUserId=" + mSourceUserId 122 + ", sourcePackageName='" + mSourcePackageName + "'" 123 + ", namespace=" + mNamespace 124 + ", jobId=" + mJobId 125 + "}"; 126 } 127 128 @Override describeContents()129 public int describeContents() { 130 return 0; 131 } 132 133 @Override writeToParcel(Parcel dest, int flags)134 public void writeToParcel(Parcel dest, int flags) { 135 dest.writeInt(mCallingUid); 136 dest.writeString(mCallingPackageName); 137 dest.writeInt(mSourceUserId); 138 dest.writeString(mSourcePackageName); 139 dest.writeString(mNamespace); 140 dest.writeInt(mJobId); 141 } 142 143 public static final Creator<UserVisibleJobSummary> CREATOR = 144 new Creator<UserVisibleJobSummary>() { 145 @Override 146 public UserVisibleJobSummary createFromParcel(Parcel in) { 147 return new UserVisibleJobSummary(in); 148 } 149 150 @Override 151 public UserVisibleJobSummary[] newArray(int size) { 152 return new UserVisibleJobSummary[size]; 153 } 154 }; 155 } 156