| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2014 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2014 The WebRTC Project Authors. All rights reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 package org.appspot.apprtc.util; | 11 package org.appspot.apprtc.util; |
| 12 | 12 |
| 13 import android.os.Build; | 13 import android.os.Build; |
| 14 import android.util.Log; | 14 import android.util.Log; |
| 15 | 15 |
| 16 /** | 16 /** |
| 17 * AppRTCUtils provides helper functions for managing thread safety. | 17 * AppRTCUtils provides helper functions for managing thread safety. |
| 18 */ | 18 */ |
| 19 public final class AppRTCUtils { | 19 public final class AppRTCUtils { |
| 20 | 20 |
| 21 private AppRTCUtils() { | 21 private AppRTCUtils() { |
| 22 } | 22 } |
| 23 | 23 |
| 24 /** | |
| 25 * NonThreadSafe is a helper class used to help verify that methods of a | |
| 26 * class are called from the same thread. | |
| 27 */ | |
| 28 public static class NonThreadSafe { | |
| 29 private final Long threadId; | |
| 30 | |
| 31 public NonThreadSafe() { | |
| 32 // Store thread ID of the creating thread. | |
| 33 threadId = Thread.currentThread().getId(); | |
| 34 } | |
| 35 | |
| 36 /** Checks if the method is called on the valid/creating thread. */ | |
| 37 public boolean calledOnValidThread() { | |
| 38 return threadId.equals(Thread.currentThread().getId()); | |
| 39 } | |
| 40 } | |
| 41 | |
| 42 /** Helper method which throws an exception when an assertion has failed. */ | 24 /** Helper method which throws an exception when an assertion has failed. */ |
| 43 public static void assertIsTrue(boolean condition) { | 25 public static void assertIsTrue(boolean condition) { |
| 44 if (!condition) { | 26 if (!condition) { |
| 45 throw new AssertionError("Expected condition to be true"); | 27 throw new AssertionError("Expected condition to be true"); |
| 46 } | 28 } |
| 47 } | 29 } |
| 48 | 30 |
| 49 /** Helper method for building a string of thread information.*/ | 31 /** Helper method for building a string of thread information.*/ |
| 50 public static String getThreadInfo() { | 32 public static String getThreadInfo() { |
| 51 return "@[name=" + Thread.currentThread().getName() | 33 return "@[name=" + Thread.currentThread().getName() |
| 52 + ", id=" + Thread.currentThread().getId() + "]"; | 34 + ", id=" + Thread.currentThread().getId() + "]"; |
| 53 } | 35 } |
| 54 | 36 |
| 55 /** Information about the current build, taken from system properties. */ | 37 /** Information about the current build, taken from system properties. */ |
| 56 public static void logDeviceInfo(String tag) { | 38 public static void logDeviceInfo(String tag) { |
| 57 Log.d(tag, "Android SDK: " + Build.VERSION.SDK_INT + ", " | 39 Log.d(tag, "Android SDK: " + Build.VERSION.SDK_INT + ", " |
| 58 + "Release: " + Build.VERSION.RELEASE + ", " | 40 + "Release: " + Build.VERSION.RELEASE + ", " |
| 59 + "Brand: " + Build.BRAND + ", " | 41 + "Brand: " + Build.BRAND + ", " |
| 60 + "Device: " + Build.DEVICE + ", " | 42 + "Device: " + Build.DEVICE + ", " |
| 61 + "Id: " + Build.ID + ", " | 43 + "Id: " + Build.ID + ", " |
| 62 + "Hardware: " + Build.HARDWARE + ", " | 44 + "Hardware: " + Build.HARDWARE + ", " |
| 63 + "Manufacturer: " + Build.MANUFACTURER + ", " | 45 + "Manufacturer: " + Build.MANUFACTURER + ", " |
| 64 + "Model: " + Build.MODEL + ", " | 46 + "Model: " + Build.MODEL + ", " |
| 65 + "Product: " + Build.PRODUCT); | 47 + "Product: " + Build.PRODUCT); |
| 66 } | 48 } |
| 67 } | 49 } |
| OLD | NEW |