Build.java revision 54b6cfa9a9e5b861a9930af873580d6dc20f773c
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
17package android.os;
18
19/**
20 * Information about the current build, extracted from system properties.
21 */
22public class Build {
23    /** Value used for when a build property is unknown. */
24    private static final String UNKNOWN = "unknown";
25
26    /** Either a changelist number, or a label like "M4-rc20". */
27    public static final String ID = getString("ro.build.id");
28
29    /** The name of the overall product. */
30    public static final String PRODUCT = getString("ro.product.name");
31
32    /** The name of the industrial design. */
33    public static final String DEVICE = getString("ro.product.device");
34
35    /** The name of the underlying board, like "goldfish". */
36    public static final String BOARD = getString("ro.product.board");
37
38    /** The brand (e.g., carrier) the software is customized for, if any. */
39    public static final String BRAND = getString("ro.product.brand");
40
41    /** The end-user-visible name for the end product. */
42    public static final String MODEL = getString("ro.product.model");
43
44    /** Various version strings. */
45    public static class VERSION {
46        /**
47         * The internal value used by the underlying source control to
48         * represent this build.  E.g., a perforce changelist number
49         * or a git hash.
50         */
51        public static final String INCREMENTAL = getString("ro.build.version.incremental");
52
53        /**
54         * The user-visible version string.  E.g., "1.0" or "3.4b5".
55         */
56        public static final String RELEASE = getString("ro.build.version.release");
57
58        /**
59         * The user-visible SDK version of the framework. It is an integer starting at 1.
60         */
61        public static final String SDK = getString("ro.build.version.sdk");
62    }
63
64    /** The type of build, like "user" or "eng". */
65    public static final String TYPE = getString("ro.build.type");
66
67    /** Comma-separated tags describing the build, like "unsigned,debug". */
68    public static final String TAGS = getString("ro.build.tags");
69
70    /** A string that uniquely identifies this build.  Do not attempt to parse this value. */
71    public static final String FINGERPRINT = getString("ro.build.fingerprint");
72
73    // The following properties only make sense for internal engineering builds.
74    public static final long TIME = getLong("ro.build.date.utc") * 1000;
75    public static final String USER = getString("ro.build.user");
76    public static final String HOST = getString("ro.build.host");
77
78    private static String getString(String property) {
79        return SystemProperties.get(property, UNKNOWN);
80    }
81
82    private static long getLong(String property) {
83        try {
84            return Long.parseLong(SystemProperties.get(property));
85        } catch (NumberFormatException e) {
86            return -1;
87        }
88    }
89}
90