1// Copyright 2014 The Chromium Authors 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5package org.chromium.net; 6 7/** 8 * Build version information for Cronet API code. 9 * 10 * <p>Note that this class will not necessarily return the same information as 11 * {@link org.chromium.net.impl.ImplVersion}. Notably, in the case of Cronet 12 * being loaded via Google Play Services, the API and impl are shipped 13 * separately and the app can end up running impl code that was not built from 14 * the same version as the API code. 15 * 16 * <p>CAUTION: this class is part of Cronet API code, but is called directly 17 * from impl code - be very careful when changing the API/ABI of this class, and 18 * keep in mind the caller code is not necessarily built from the same version 19 * as this code. 20 * 21 * @see org.chromium.net.impl.ImplVersion 22 * {@hide as it's only used internally} 23 */ 24public class ApiVersion { 25 private static final String CRONET_VERSION = "@MAJOR@.@MINOR@.@BUILD@.@PATCH@"; 26 private static final int API_LEVEL = @API_LEVEL@; 27 /** 28 * The minimum API level of implementations that are compatible with this API. 29 * The last API level which broke backwards API compatibility. In other words, the 30 * Cronet API that this class is part of won't work with Cronet implementations that implement 31 * API levels less than this value. That is if 32 * ImplVersion.getApiLevel() < ApiVersion.getApiLevel(), then the Cronet implementation 33 * providing ImplVersion cannot be used with the Cronet API providing ApiVersion; if they are 34 * used together various unexpected Errors, like AbstractMethodError, may result. 35 */ 36 private static final int MIN_COMPATIBLE_API_LEVEL = 3; 37 private static final String LAST_CHANGE = "@LASTCHANGE@"; 38 39 /** 40 * Private constructor. All members of this class should be static. 41 */ 42 private ApiVersion() {} 43 44 public static String getCronetVersionWithLastChange() { 45 return CRONET_VERSION + "@" + LAST_CHANGE.substring(0, 8); 46 } 47 48 /** 49 * Returns API level of the API linked into the application. This is the maximum API 50 * level the application can use, even if the application is run with a newer implementation. 51 */ 52 public static int getMaximumAvailableApiLevel() { 53 return API_LEVEL; 54 } 55 56 /** 57 * The *minimum* API level of implementations that are compatible with this API. 58 * Not to be confused with the *current* API level, which is returned by {@link 59 * #getMaximumAvailableApiLevel}. 60 * Returns the last API level which broke backwards API compatibility. In other words, the 61 * Cronet API that this class is part of won't work with Cronet implementations that implement 62 * API levels less than this value. That is if 63 * ImplVersion.getApiLevel() < ApiVersion.getApiLevel(), then the Cronet implementation 64 * providing ImplVersion cannot be used with the Cronet API providing ApiVersion; if they are 65 * used together various unexpected Errors, like AbstractMethodError, may result. 66 */ 67 public static int getApiLevel() { 68 return MIN_COMPATIBLE_API_LEVEL; 69 } 70 71 public static String getCronetVersion() { 72 return CRONET_VERSION; 73 } 74 75 public static String getLastChange() { 76 return LAST_CHANGE; 77 } 78} 79