1 /* 2 * Copyright (C) 2007 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.server.data; 18 19 import android.os.Build; 20 21 import java.io.DataInput; 22 import java.io.DataOutput; 23 import java.io.IOException; 24 25 import static com.android.internal.util.Objects.nonNull; 26 27 /** 28 * Build data transfer object. Keep in sync. with the server side version. 29 */ 30 public class BuildData { 31 32 /** The version of the data returned by write() and understood by the constructor. */ 33 private static final int VERSION = 0; 34 35 private final String fingerprint; 36 private final String incrementalVersion; 37 private final long time; // in *seconds* since the epoch (not msec!) 38 BuildData()39 public BuildData() { 40 this.fingerprint = "android:" + Build.FINGERPRINT; 41 this.incrementalVersion = Build.VERSION.INCREMENTAL; 42 this.time = Build.TIME / 1000; // msec -> sec 43 } 44 BuildData(String fingerprint, String incrementalVersion, long time)45 public BuildData(String fingerprint, String incrementalVersion, long time) { 46 this.fingerprint = nonNull(fingerprint); 47 this.incrementalVersion = incrementalVersion; 48 this.time = time; 49 } 50 BuildData(DataInput in)51 /*package*/ BuildData(DataInput in) throws IOException { 52 int dataVersion = in.readInt(); 53 if (dataVersion != VERSION) { 54 throw new IOException("Expected " + VERSION + ". Got: " + dataVersion); 55 } 56 57 this.fingerprint = in.readUTF(); 58 this.incrementalVersion = Long.toString(in.readLong()); 59 this.time = in.readLong(); 60 } 61 write(DataOutput out)62 /*package*/ void write(DataOutput out) throws IOException { 63 out.writeInt(VERSION); 64 out.writeUTF(fingerprint); 65 66 // TODO: change the format/version to expect a string for this field. 67 // Version 0, still used by the server side, expects a long. 68 long changelist; 69 try { 70 changelist = Long.parseLong(incrementalVersion); 71 } catch (NumberFormatException ex) { 72 changelist = -1; 73 } 74 out.writeLong(changelist); 75 out.writeLong(time); 76 } 77 getFingerprint()78 public String getFingerprint() { 79 return fingerprint; 80 } 81 getIncrementalVersion()82 public String getIncrementalVersion() { 83 return incrementalVersion; 84 } 85 getTime()86 public long getTime() { 87 return time; 88 } 89 } 90