Example usage for android.os Build ID

List of usage examples for android.os Build ID

Introduction

In this page you can find the example usage for android.os Build ID.

Prototype

String ID

To view the source code for android.os Build ID.

Click Source Link

Document

Either a changelist number, or a label like "M4-rc20".

Usage

From source file:org.chromium.android_webview.test.AwSettingsTest.java

@SmallTest
@Feature({ "AndroidWebView", "Preferences" })
public void testUserAgentStringDefault() throws Throwable {
    final TestAwContentsClient contentClient = new TestAwContentsClient();
    final AwTestContainerView testContainerView = createAwTestContainerViewOnMainSync(contentClient);
    final AwContents awContents = testContainerView.getAwContents();
    AwSettings settings = getAwSettingsOnUiThread(awContents);
    final String actualUserAgentString = settings.getUserAgentString();
    assertEquals(actualUserAgentString, AwSettings.getDefaultUserAgent());
    final String patternString = "Mozilla/5\\.0 \\(Linux;( U;)? Android ([^;]+);( (\\w+)-(\\w+);)?"
            + "\\s?(.*)\\sBuild/(.+)\\) AppleWebKit/(\\d+)\\.(\\d+) \\(KHTML, like Gecko\\) "
            + "Version/\\d+\\.\\d Chrome/\\d+\\.\\d+\\.\\d+\\.\\d+" + "( Mobile)? Safari/(\\d+)\\.(\\d+)";
    final Pattern userAgentExpr = Pattern.compile(patternString);
    Matcher patternMatcher = userAgentExpr.matcher(actualUserAgentString);
    assertTrue(/*from w w w . j  a v a  2 s.  c o m*/
            String.format("User agent string did not match expected pattern. %nExpected "
                    + "pattern:%n%s%nActual:%n%s", patternString, actualUserAgentString),
            patternMatcher.find());
    // No country-language code token.
    assertEquals(null, patternMatcher.group(3));
    if ("REL".equals(Build.VERSION.CODENAME)) {
        // Model is only added in release builds
        assertEquals(Build.MODEL, patternMatcher.group(6));
        // Release version is valid only in release builds
        assertEquals(Build.VERSION.RELEASE, patternMatcher.group(2));
    }
    assertEquals(Build.ID, patternMatcher.group(7));
}

From source file:de.vanita5.twittnuker.util.Utils.java

public static String generateBrowserUserAgent() {
    return String.format(UA_TEMPLATE, Build.VERSION.RELEASE, Build.MODEL, Build.ID);
}

From source file:es.javocsoft.android.lib.toolbox.ToolBox.java

/**
 * Generates a unique device id using the device 
 * "serial" property if is available. If not, a bunch
 * of device properties will be used to get a reliable
 * unique string key for the device.//ww  w.  ja  v  a  2s. co  m
 * 
 * If there is an error in UUID generation null is
 * returned.
 *    
 * @return   The unique UUID or nul in case of error.
 */
private static UUID generateUniqueDeviceUUIDId() {
    UUID uuid = null;

    try {
        //We generate a unique id
        String serial = null;
        if (Build.VERSION.SDK_INT > Build.VERSION_CODES.FROYO) {
            serial = Build.SERIAL;
            uuid = UUID.nameUUIDFromBytes(serial.getBytes("utf8"));
        } else {
            //This bunch of data should be enough to "ensure" the 
            //uniqueness.
            String m_szDevIDAlterbative = "35" + //To look like a valid IMEI
                    Build.BOARD.length() % 10 + Build.BRAND.length() % 10 + Build.CPU_ABI.length() % 10
                    + Build.DEVICE.length() % 10 + Build.DISPLAY.length() % 10 + Build.HOST.length() % 10
                    + Build.ID.length() % 10 + Build.MANUFACTURER.length() % 10 + Build.MODEL.length() % 10
                    + Build.PRODUCT.length() % 10 + Build.TAGS.length() % 10 + Build.TYPE.length() % 10
                    + Build.USER.length() % 10; //13 digits

            uuid = UUID.nameUUIDFromBytes(m_szDevIDAlterbative.getBytes("utf8"));
        }

    } catch (UnsupportedEncodingException e) {
        Log.e(TAG, "UnsupportedEncodingException (" + e.getMessage() + ").", e);
    }

    return uuid;
}