Loading core/java/android/companion/AssociationRequest.java +2 −1 Original line number Diff line number Diff line Loading @@ -23,6 +23,7 @@ import android.os.Parcelable; import android.provider.OneTimeUseBuilder; import com.android.internal.util.ArrayUtils; import com.android.internal.util.CollectionUtils; import java.util.ArrayList; import java.util.List; Loading @@ -47,7 +48,7 @@ public final class AssociationRequest implements Parcelable { private AssociationRequest( boolean singleDevice, @Nullable List<DeviceFilter<?>> deviceFilters) { this.mSingleDevice = singleDevice; this.mDeviceFilters = ArrayUtils.emptyIfNull(deviceFilters); this.mDeviceFilters = CollectionUtils.emptyIfNull(deviceFilters); } private AssociationRequest(Parcel in) { Loading core/java/android/companion/BluetoothDeviceFilter.java +3 −2 Original line number Diff line number Diff line Loading @@ -31,6 +31,7 @@ import android.os.ParcelUuid; import android.provider.OneTimeUseBuilder; import com.android.internal.util.ArrayUtils; import com.android.internal.util.CollectionUtils; import java.util.ArrayList; import java.util.List; Loading @@ -53,8 +54,8 @@ public final class BluetoothDeviceFilter implements DeviceFilter<BluetoothDevice List<ParcelUuid> serviceUuidMasks) { mNamePattern = namePattern; mAddress = address; mServiceUuids = ArrayUtils.emptyIfNull(serviceUuids); mServiceUuidMasks = ArrayUtils.emptyIfNull(serviceUuidMasks); mServiceUuids = CollectionUtils.emptyIfNull(serviceUuids); mServiceUuidMasks = CollectionUtils.emptyIfNull(serviceUuidMasks); } private BluetoothDeviceFilter(Parcel in) { Loading core/java/android/os/Binder.java +31 −0 Original line number Diff line number Diff line Loading @@ -26,6 +26,7 @@ import java.io.FileOutputStream; import java.io.PrintWriter; import java.lang.ref.WeakReference; import java.lang.reflect.Modifier; import java.util.function.Supplier; /** * Base class for a remotable object, the core part of a lightweight Loading Loading @@ -246,6 +247,36 @@ public class Binder implements IBinder { */ public static final native void restoreCallingIdentity(long token); /** * Convenience method for running the provided action enclosed in * {@link #clearCallingIdentity}/{@link #restoreCallingIdentity} * * @hide */ public static final void withCleanCallingIdentity(Runnable action) { long callingIdentity = clearCallingIdentity(); try { action.run(); } finally { restoreCallingIdentity(callingIdentity); } } /** * Convenience method for running the provided action enclosed in * {@link #clearCallingIdentity}/{@link #restoreCallingIdentity} returning the result * * @hide */ public static final <T> T withCleanCallingIdentity(Supplier<T> action) { long callingIdentity = clearCallingIdentity(); try { return action.get(); } finally { restoreCallingIdentity(callingIdentity); } } /** * Sets the native thread-local StrictMode policy mask. * Loading core/java/android/os/HandlerThread.java +16 −0 Original line number Diff line number Diff line Loading @@ -16,6 +16,9 @@ package android.os; import android.annotation.NonNull; import android.annotation.Nullable; /** * Handy class for starting a new thread that has a looper. The looper can then be * used to create handler classes. Note that start() must still be called. Loading @@ -24,6 +27,7 @@ public class HandlerThread extends Thread { int mPriority; int mTid = -1; Looper mLooper; private @Nullable Handler mHandler; public HandlerThread(String name) { super(name); Loading Loading @@ -85,6 +89,18 @@ public class HandlerThread extends Thread { return mLooper; } /** * @return a shared {@link Handler} associated with this thread * @hide */ @NonNull public Handler getThreadHandler() { if (mHandler == null) { mHandler = new Handler(getLooper()); } return mHandler; } /** * Quits the handler thread's looper. * <p> Loading core/java/com/android/internal/util/ArrayUtils.java +0 −53 Original line number Diff line number Diff line Loading @@ -31,7 +31,6 @@ import java.util.Collection; import java.util.Collections; import java.util.List; import java.util.Objects; import java.util.function.Function; /** * ArrayUtils contains some methods that you can call to find out Loading Loading @@ -237,35 +236,6 @@ public class ArrayUtils { return false; } @NonNull public static <T> List<T> filter(@Nullable List<?> list, Class<T> c) { if (isEmpty(list)) return Collections.emptyList(); ArrayList<T> result = null; for (int i = 0; i < list.size(); i++) { final Object item = list.get(i); if (c.isInstance(item)) { result = add(result, (T) item); } } return emptyIfNull(result); } public static <T> boolean any(@Nullable List<T> items, java.util.function.Predicate<T> predicate) { return find(items, predicate) != null; } @Nullable public static <T> T find(@Nullable List<T> items, java.util.function.Predicate<T> predicate) { if (isEmpty(items)) return null; for (int i = 0; i < items.size(); i++) { final T item = items.get(i); if (predicate.test(item)) return item; } return null; } public static long total(@Nullable long[] array) { long total = 0; if (array != null) { Loading Loading @@ -504,29 +474,6 @@ public class ArrayUtils { } } public static int size(@Nullable Collection<?> cur) { return cur != null ? cur.size() : 0; } public static @NonNull <I, O> List<O> map(@Nullable List<I> cur, Function<? super I, ? extends O> f) { if (cur == null || cur.isEmpty()) return Collections.emptyList(); final ArrayList<O> result = new ArrayList<>(); for (int i = 0; i < cur.size(); i++) { result.add(f.apply(cur.get(i))); } return result; } /** * Returns the given list, or an immutable empty list if the provided list is null * * @see Collections#emptyList */ public static @NonNull <T> List<T> emptyIfNull(@Nullable List<T> cur) { return cur == null ? Collections.emptyList() : cur; } public static <T> boolean contains(@Nullable Collection<T> cur, T val) { return (cur != null) ? cur.contains(val) : false; } Loading Loading
core/java/android/companion/AssociationRequest.java +2 −1 Original line number Diff line number Diff line Loading @@ -23,6 +23,7 @@ import android.os.Parcelable; import android.provider.OneTimeUseBuilder; import com.android.internal.util.ArrayUtils; import com.android.internal.util.CollectionUtils; import java.util.ArrayList; import java.util.List; Loading @@ -47,7 +48,7 @@ public final class AssociationRequest implements Parcelable { private AssociationRequest( boolean singleDevice, @Nullable List<DeviceFilter<?>> deviceFilters) { this.mSingleDevice = singleDevice; this.mDeviceFilters = ArrayUtils.emptyIfNull(deviceFilters); this.mDeviceFilters = CollectionUtils.emptyIfNull(deviceFilters); } private AssociationRequest(Parcel in) { Loading
core/java/android/companion/BluetoothDeviceFilter.java +3 −2 Original line number Diff line number Diff line Loading @@ -31,6 +31,7 @@ import android.os.ParcelUuid; import android.provider.OneTimeUseBuilder; import com.android.internal.util.ArrayUtils; import com.android.internal.util.CollectionUtils; import java.util.ArrayList; import java.util.List; Loading @@ -53,8 +54,8 @@ public final class BluetoothDeviceFilter implements DeviceFilter<BluetoothDevice List<ParcelUuid> serviceUuidMasks) { mNamePattern = namePattern; mAddress = address; mServiceUuids = ArrayUtils.emptyIfNull(serviceUuids); mServiceUuidMasks = ArrayUtils.emptyIfNull(serviceUuidMasks); mServiceUuids = CollectionUtils.emptyIfNull(serviceUuids); mServiceUuidMasks = CollectionUtils.emptyIfNull(serviceUuidMasks); } private BluetoothDeviceFilter(Parcel in) { Loading
core/java/android/os/Binder.java +31 −0 Original line number Diff line number Diff line Loading @@ -26,6 +26,7 @@ import java.io.FileOutputStream; import java.io.PrintWriter; import java.lang.ref.WeakReference; import java.lang.reflect.Modifier; import java.util.function.Supplier; /** * Base class for a remotable object, the core part of a lightweight Loading Loading @@ -246,6 +247,36 @@ public class Binder implements IBinder { */ public static final native void restoreCallingIdentity(long token); /** * Convenience method for running the provided action enclosed in * {@link #clearCallingIdentity}/{@link #restoreCallingIdentity} * * @hide */ public static final void withCleanCallingIdentity(Runnable action) { long callingIdentity = clearCallingIdentity(); try { action.run(); } finally { restoreCallingIdentity(callingIdentity); } } /** * Convenience method for running the provided action enclosed in * {@link #clearCallingIdentity}/{@link #restoreCallingIdentity} returning the result * * @hide */ public static final <T> T withCleanCallingIdentity(Supplier<T> action) { long callingIdentity = clearCallingIdentity(); try { return action.get(); } finally { restoreCallingIdentity(callingIdentity); } } /** * Sets the native thread-local StrictMode policy mask. * Loading
core/java/android/os/HandlerThread.java +16 −0 Original line number Diff line number Diff line Loading @@ -16,6 +16,9 @@ package android.os; import android.annotation.NonNull; import android.annotation.Nullable; /** * Handy class for starting a new thread that has a looper. The looper can then be * used to create handler classes. Note that start() must still be called. Loading @@ -24,6 +27,7 @@ public class HandlerThread extends Thread { int mPriority; int mTid = -1; Looper mLooper; private @Nullable Handler mHandler; public HandlerThread(String name) { super(name); Loading Loading @@ -85,6 +89,18 @@ public class HandlerThread extends Thread { return mLooper; } /** * @return a shared {@link Handler} associated with this thread * @hide */ @NonNull public Handler getThreadHandler() { if (mHandler == null) { mHandler = new Handler(getLooper()); } return mHandler; } /** * Quits the handler thread's looper. * <p> Loading
core/java/com/android/internal/util/ArrayUtils.java +0 −53 Original line number Diff line number Diff line Loading @@ -31,7 +31,6 @@ import java.util.Collection; import java.util.Collections; import java.util.List; import java.util.Objects; import java.util.function.Function; /** * ArrayUtils contains some methods that you can call to find out Loading Loading @@ -237,35 +236,6 @@ public class ArrayUtils { return false; } @NonNull public static <T> List<T> filter(@Nullable List<?> list, Class<T> c) { if (isEmpty(list)) return Collections.emptyList(); ArrayList<T> result = null; for (int i = 0; i < list.size(); i++) { final Object item = list.get(i); if (c.isInstance(item)) { result = add(result, (T) item); } } return emptyIfNull(result); } public static <T> boolean any(@Nullable List<T> items, java.util.function.Predicate<T> predicate) { return find(items, predicate) != null; } @Nullable public static <T> T find(@Nullable List<T> items, java.util.function.Predicate<T> predicate) { if (isEmpty(items)) return null; for (int i = 0; i < items.size(); i++) { final T item = items.get(i); if (predicate.test(item)) return item; } return null; } public static long total(@Nullable long[] array) { long total = 0; if (array != null) { Loading Loading @@ -504,29 +474,6 @@ public class ArrayUtils { } } public static int size(@Nullable Collection<?> cur) { return cur != null ? cur.size() : 0; } public static @NonNull <I, O> List<O> map(@Nullable List<I> cur, Function<? super I, ? extends O> f) { if (cur == null || cur.isEmpty()) return Collections.emptyList(); final ArrayList<O> result = new ArrayList<>(); for (int i = 0; i < cur.size(); i++) { result.add(f.apply(cur.get(i))); } return result; } /** * Returns the given list, or an immutable empty list if the provided list is null * * @see Collections#emptyList */ public static @NonNull <T> List<T> emptyIfNull(@Nullable List<T> cur) { return cur == null ? Collections.emptyList() : cur; } public static <T> boolean contains(@Nullable Collection<T> cur, T val) { return (cur != null) ? cur.contains(val) : false; } Loading