summaryrefslogtreecommitdiffstats
path: root/sdk/src/java/cyanogenmod/os/Build.java
blob: cbb83cad3adc13d29b14a2641e6cfd107a291ecb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
/*
 * Copyright (C) 2015 The CyanogenMod Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package cyanogenmod.os;

import android.os.SystemProperties;
import android.text.TextUtils;
import android.util.SparseArray;

/**
 * Information about the current CyanogenMod build, extracted from system properties.
 */
public class Build {
    /** Value used for when a build property is unknown. */
    public static final String UNKNOWN = "unknown";

    /** A build ID utilized to distinguish cyanogenmod versions */
    public static final String CYANOGENMOD_VERSION = getString("ro.cm.version");

    /** A build ID string meant for displaying to the user */
    public static final String CYANOGENMOD_DISPLAY_VERSION = getString("ro.cm.display.version");

    private static final SparseArray<String> sdkMap;
    static
    {
        sdkMap = new SparseArray<String>();
        sdkMap.put(CM_VERSION_CODES.APRICOT, "Apricot");
        sdkMap.put(CM_VERSION_CODES.BOYSENBERRY, "Boysenberry");
        sdkMap.put(CM_VERSION_CODES.CANTALOUPE, "Cantaloupe");
        sdkMap.put(CM_VERSION_CODES.DRAGON_FRUIT, "Dragon Fruit");
        sdkMap.put(CM_VERSION_CODES.ELDERBERRY, "Elderberry");
        sdkMap.put(CM_VERSION_CODES.FIG, "Fig");
    }

    /** Various version strings. */
    public static class CM_VERSION {
        /**
         * The user-visible SDK version of the framework; its possible
         * values are defined in {@link Build.CM_VERSION_CODES}.
         *
         * Will return 0 if the device does not support the CM SDK.
         */
        public static final int SDK_INT = SystemProperties.getInt(
                "ro.cm.build.version.plat.sdk", 0);
    }

    /**
     * Enumeration of the currently known SDK version codes.  These are the
     * values that can be found in {@link CM_VERSION#SDK_INT}.  Version numbers
     * increment monotonically with each official platform release.
     *
     * To programmatically validate that a given API is available for use on the device,
     * you can quickly check if the SDK_INT from the OS is provided and is greater or equal
     * to the API level that your application is targeting.
     *
     * <p>Example for validating that Profiles API is available
     * <pre class="prettyprint">
     * private void removeActiveProfile() {
     *     Make sure we're running on BoysenBerry or higher to use Profiles API
     *     if (Build.CM_VERSION.SDK_INT >= Build.CM_VERSION_CODES.BOYSENBERRY) {
     *         ProfileManager profileManager = ProfileManager.getInstance(this);
     *         Profile activeProfile = profileManager.getActiveProfile();
     *         if (activeProfile != null) {
     *             profileManager.removeProfile(activeProfile);
     *         }
     *     }
     * }
     * </pre>
     */
    public static class CM_VERSION_CODES {
        /**
         * June 2015: The first version of the platform sdk for CyanogenMod
         */
        public static final int APRICOT = 1;

        /**
         * September 2015: The second version of the platform sdk for CyanogenMod
         *
         * <p>Applications targeting this or a later release will get these
         * new features:</p>
         * <ul>
         * <li>Profiles API via {@link cyanogenmod.app.ProfileManager}
         * <li>New Expanded Styles for Custom Tiles via
         * {@link cyanogenmod.app.CustomTile.RemoteExpandedStyle}
         * <li>Hardware Abstraction Framework Access via
         * {@link cyanogenmod.hardware.CMHardwareManager} (Not for use by 3rd parties)
         * <li>MSIM API via {@link cyanogenmod.app.CMTelephonyManager}
         * <li>Interface for partners via {@link cyanogenmod.app.PartnerInterface}
         * <li>Introductory Settings Provider {@link cyanogenmod.providers.CMSettings}
         * <li>AlarmClock API via {@link cyanogenmod.alarmclock.CyanogenModAlarmClock}
         * </ul>
         */
        public static final int BOYSENBERRY = 2;

        /**
         * November - December 2015: The third iteration of the platform sdk for CyanogenMod
         * Transition api level that is mostly 1:1 to {@link #BOYSENBERRY}
         */
        public static final int CANTALOUPE = 3;

        /**
         * January 2016: The 4th iteration of the platform sdk for CyanogenMod
         *
         * <p>Applications targeting this or a later version will get access to these
         * new features:</p>
         * <ul>
         * <li>External views api, and specifically Keyguard interfaces for making
         * live lockscreens via {@link cyanogenmod.externalviews.KeyguardExternalView}</li>
         * <li>Inclusion of the PerformanceManager interfaces, allowing an application to specify
         * the type of mode to have the device be placed in via
         * {@link cyanogenmod.power.PerformanceManager}</li>
         * <li>Numerous new "System" settings exposed via the
         * {@link cyanogenmod.providers.CMSettings.System} interface</li>
         * </ul>
         */
        public static final int DRAGON_FRUIT = 4;

        /**
         * April 2016: The 5th iteration of the platform sdk for CyanogenMod
         *
         * <p>Applications targeting this or a later version will get access to these
         * new features!</p>
         * <ul>
         * <li>Weather request api to fetch weather data from providers on the device
         * {@link cyanogenmod.weather.CMWeatherManager}</li>
         * <li>Weather provider api to provide weather data to any listener on the device
         * {@link cyanogenmod.weatherservice.WeatherProviderService}</li>
         * <li>Extended capabilities of the {@link cyanogenmod.externalviews.KeyguardExternalView}
         * interfaces to provide immersive and interactive experiences on the lockscreen.</li>
         * <li>Themes interfaces have found a new home in the cmsdk, thus we allow access
         * to 3rd parties requesting theme changes on the platform via
         * {@link cyanogenmod.themes.ThemeManager} and
         * {@link cyanogenmod.themes.ThemeChangeRequest}</li>
         * <li>Full access to the {@link cyanogenmod.providers.ThemesContract} and provider</li>
         * <li>Parceling helper class {@link cyanogenmod.os.Concierge} to help with parcel
         * headers and protocol revisions</li>
         * </ul>
         */
        public static final int ELDERBERRY = 5;

        /**
         * August 2016: The 6th iteration of the platform sdk for CyanogenMod
         *
         * <p>Applications targeting this or a later version will get access to these
         * new features!</p>
         * <ul>
         * <li>Ability to query and color balance ranges from the
         * {@link cyanogenmod.hardware.CMHardwareManager}, as well as do picture adjustment</li>
         * <li>Extended capabilities of the LiveDisplay interfaces, now providing
         * {@link cyanogenmod.hardware.LiveDisplayConfig} and a dedicated
         * {@link cyanogenmod.hardware.LiveDisplayManager}</li>
         * <li>Added new settings, such as LOCKSCREEN_ROTATION and DISPLAY_LOW_POWER
         * to {@link cyanogenmod.providers.CMSettings}</li>
         * </ul>
         *
         * Signing out, Adnan \u270C
         */
        public static final int FIG = 6;
    }

    /**
     * Retrieve the name for the SDK int
     * @param sdkInt
     * @return name of the SDK int, {@link #UNKNOWN) if not known
     */
    public static String getNameForSDKInt(int sdkInt) {
        final String name = sdkMap.get(sdkInt);
        if (TextUtils.isEmpty(name)) {
            return UNKNOWN;
        }
        return name;
    }

    private static String getString(String property) {
        return SystemProperties.get(property, UNKNOWN);
    }
}