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 android.app.blob; 18 19 import android.annotation.CurrentTimeMillisLong; 20 import android.annotation.IdRes; 21 import android.annotation.NonNull; 22 import android.annotation.Nullable; 23 import android.annotation.TestApi; 24 import android.os.Parcel; 25 import android.os.Parcelable; 26 27 import java.util.List; 28 29 /** 30 * Class to provide information about a lease (acquired using 31 * {@link BlobStoreManager#acquireLease(BlobHandle, int)} or one of it's variants) 32 * for a shared blob. 33 * 34 * @hide 35 */ 36 @TestApi 37 public final class LeaseInfo implements Parcelable { 38 private final String mPackageName; 39 private final long mExpiryTimeMillis; 40 private final int mDescriptionResId; 41 private final CharSequence mDescription; 42 LeaseInfo(@onNull String packageName, @CurrentTimeMillisLong long expiryTimeMs, @IdRes int descriptionResId, @Nullable CharSequence description)43 public LeaseInfo(@NonNull String packageName, @CurrentTimeMillisLong long expiryTimeMs, 44 @IdRes int descriptionResId, @Nullable CharSequence description) { 45 mPackageName = packageName; 46 mExpiryTimeMillis = expiryTimeMs; 47 mDescriptionResId = descriptionResId; 48 mDescription = description; 49 } 50 LeaseInfo(Parcel in)51 private LeaseInfo(Parcel in) { 52 mPackageName = in.readString(); 53 mExpiryTimeMillis = in.readLong(); 54 mDescriptionResId = in.readInt(); 55 mDescription = in.readCharSequence(); 56 } 57 58 @NonNull getPackageName()59 public String getPackageName() { 60 return mPackageName; 61 } 62 63 @CurrentTimeMillisLong getExpiryTimeMillis()64 public long getExpiryTimeMillis() { 65 return mExpiryTimeMillis; 66 } 67 68 @IdRes getDescriptionResId()69 public int getDescriptionResId() { 70 return mDescriptionResId; 71 } 72 73 @Nullable getDescription()74 public CharSequence getDescription() { 75 return mDescription; 76 } 77 78 @Override writeToParcel(@onNull Parcel dest, int flags)79 public void writeToParcel(@NonNull Parcel dest, int flags) { 80 dest.writeString(mPackageName); 81 dest.writeLong(mExpiryTimeMillis); 82 dest.writeInt(mDescriptionResId); 83 dest.writeCharSequence(mDescription); 84 } 85 86 @Override toString()87 public String toString() { 88 return "LeaseInfo {" 89 + "package: " + mPackageName + "," 90 + "expiryMs: " + mExpiryTimeMillis + "," 91 + "descriptionResId: " + mDescriptionResId + "," 92 + "description: " + mDescription + "," 93 + "}"; 94 } 95 toShortString()96 private String toShortString() { 97 return mPackageName; 98 } 99 toShortString(List<LeaseInfo> leaseInfos)100 static String toShortString(List<LeaseInfo> leaseInfos) { 101 final StringBuilder sb = new StringBuilder(); 102 sb.append("["); 103 for (int i = 0, size = leaseInfos.size(); i < size; ++i) { 104 sb.append(leaseInfos.get(i).toShortString()); 105 sb.append(","); 106 } 107 sb.append("]"); 108 return sb.toString(); 109 } 110 111 @Override describeContents()112 public int describeContents() { 113 return 0; 114 } 115 116 @NonNull 117 public static final Creator<LeaseInfo> CREATOR = new Creator<LeaseInfo>() { 118 @Override 119 @NonNull 120 public LeaseInfo createFromParcel(Parcel source) { 121 return new LeaseInfo(source); 122 } 123 124 @Override 125 @NonNull 126 public LeaseInfo[] newArray(int size) { 127 return new LeaseInfo[size]; 128 } 129 }; 130 } 131