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