| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.net; | 5 package org.chromium.net; |
| 6 | 6 |
| 7 import android.content.Context; | 7 import android.content.Context; |
| 8 import android.content.pm.PackageInfo; | 8 import android.content.pm.PackageInfo; |
| 9 import android.content.pm.PackageManager; | 9 import android.content.pm.PackageManager; |
| 10 import android.content.pm.PackageManager.NameNotFoundException; | 10 import android.content.pm.PackageManager.NameNotFoundException; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 builder.append("; "); | 42 builder.append("; "); |
| 43 builder.append(model); | 43 builder.append(model); |
| 44 } | 44 } |
| 45 | 45 |
| 46 String id = Build.ID; | 46 String id = Build.ID; |
| 47 if (id.length() > 0) { | 47 if (id.length() > 0) { |
| 48 builder.append("; Build/"); | 48 builder.append("; Build/"); |
| 49 builder.append(id); | 49 builder.append(id); |
| 50 } | 50 } |
| 51 | 51 |
| 52 builder.append("; Cronet/"); |
| 53 builder.append(Version.CRONET_VERSION); |
| 54 |
| 52 builder.append(')'); | 55 builder.append(')'); |
| 53 | 56 |
| 54 return builder.toString(); | 57 return builder.toString(); |
| 55 } | 58 } |
| 56 | 59 |
| 57 private static int versionFromContext(Context context) { | 60 private static int versionFromContext(Context context) { |
| 58 synchronized (sLock) { | 61 synchronized (sLock) { |
| 59 if (sVersionCode == 0) { | 62 if (sVersionCode == 0) { |
| 60 PackageManager packageManager = context.getPackageManager(); | 63 PackageManager packageManager = context.getPackageManager(); |
| 61 String packageName = context.getPackageName(); | 64 String packageName = context.getPackageName(); |
| 62 try { | 65 try { |
| 63 PackageInfo packageInfo = packageManager.getPackageInfo( | 66 PackageInfo packageInfo = packageManager.getPackageInfo( |
| 64 packageName, 0); | 67 packageName, 0); |
| 65 sVersionCode = packageInfo.versionCode; | 68 sVersionCode = packageInfo.versionCode; |
| 66 } catch (NameNotFoundException e) { | 69 } catch (NameNotFoundException e) { |
| 67 throw new IllegalStateException( | 70 throw new IllegalStateException( |
| 68 "Cannot determine package version"); | 71 "Cannot determine package version"); |
| 69 } | 72 } |
| 70 } | 73 } |
| 71 return sVersionCode; | 74 return sVersionCode; |
| 72 } | 75 } |
| 73 } | 76 } |
| 74 } | 77 } |
| OLD | NEW |