blob: ce88338834c8bfc7a2eb414346721773f0995c6d [file] [log] [blame]
Zhomart Mukhamejanovf4d280c2018-04-17 13:20:22 -07001/*
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
17package com.example.android.systemupdatersample;
18
19import android.os.UpdateEngine;
20
Zhomart Mukhamejanovf7a70382018-05-02 20:37:12 -070021import java.io.Serializable;
Zhomart Mukhamejanovf4d280c2018-04-17 13:20:22 -070022import java.util.List;
23
24/**
25 * Payload that will be given to {@link UpdateEngine#applyPayload)}.
26 */
Zhomart Mukhamejanovf7a70382018-05-02 20:37:12 -070027public class PayloadSpec implements Serializable {
28
29 private static final long serialVersionUID = 41043L;
Zhomart Mukhamejanovf4d280c2018-04-17 13:20:22 -070030
31 /**
32 * Creates a payload spec {@link Builder}
33 */
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
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
50 public String getUrl() {
51 return mUrl;
52 }
53
54 public long getOffset() {
55 return mOffset;
56 }
57
58 public long getSize() {
59 return mSize;
60 }
61
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
83 public Builder() {
84 }
85
86 /**
87 * set url
88 */
89 public Builder url(String url) {
90 this.mUrl = url;
91 return this;
92 }
93
94 /**
95 * set offset
96 */
97 public Builder offset(long offset) {
98 this.mOffset = offset;
99 return this;
100 }
101
102 /**
103 * set size
104 */
105 public Builder size(long size) {
106 this.mSize = size;
107 return this;
108 }
109
110 /**
111 * set properties
112 */
113 public Builder properties(List<String> properties) {
114 this.mProperties = properties;
115 return this;
116 }
117
118 /**
119 * build {@link PayloadSpec}
120 */
121 public PayloadSpec build() {
122 return new PayloadSpec(this);
123 }
124 }
125}