1 /* 2 * Copyright (C) 2018 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.example.android.systemupdatersample; 18 19 import android.os.UpdateEngine; 20 21 import java.io.Serializable; 22 import java.util.List; 23 24 /** 25 * Payload that will be given to {@link UpdateEngine#applyPayload)}. 26 */ 27 public class PayloadSpec implements Serializable { 28 29 private static final long serialVersionUID = 41043L; 30 31 /** 32 * Creates a payload spec {@link Builder} 33 */ newBuilder()34 public static Builder newBuilder() { 35 return new Builder(); 36 } 37 38 private String mUrl; 39 private long mOffset; 40 private long mSize; 41 private List<String> mProperties; 42 PayloadSpec(Builder b)43 public PayloadSpec(Builder b) { 44 this.mUrl = b.mUrl; 45 this.mOffset = b.mOffset; 46 this.mSize = b.mSize; 47 this.mProperties = b.mProperties; 48 } 49 getUrl()50 public String getUrl() { 51 return mUrl; 52 } 53 getOffset()54 public long getOffset() { 55 return mOffset; 56 } 57 getSize()58 public long getSize() { 59 return mSize; 60 } 61 getProperties()62 public List<String> getProperties() { 63 return mProperties; 64 } 65 66 /** 67 * payload spec builder. 68 * 69 * <p>Usage:</p> 70 * 71 * {@code 72 * PayloadSpec spec = PayloadSpec.newBuilder() 73 * .url("url") 74 * .build(); 75 * } 76 */ 77 public static class Builder { 78 private String mUrl; 79 private long mOffset; 80 private long mSize; 81 private List<String> mProperties; 82 Builder()83 public Builder() { 84 } 85 86 /** 87 * set url 88 */ url(String url)89 public Builder url(String url) { 90 this.mUrl = url; 91 return this; 92 } 93 94 /** 95 * set offset 96 */ offset(long offset)97 public Builder offset(long offset) { 98 this.mOffset = offset; 99 return this; 100 } 101 102 /** 103 * set size 104 */ size(long size)105 public Builder size(long size) { 106 this.mSize = size; 107 return this; 108 } 109 110 /** 111 * set properties 112 */ properties(List<String> properties)113 public Builder properties(List<String> properties) { 114 this.mProperties = properties; 115 return this; 116 } 117 118 /** 119 * build {@link PayloadSpec} 120 */ build()121 public PayloadSpec build() { 122 return new PayloadSpec(this); 123 } 124 } 125 } 126