Merge "Replace com.android.internal.util.Preconditions.checkNotNull with java.util.Objects.requireNonNull"
This commit is contained in:
committed by
Android (Google) Code Review
commit
848cc35375
@@ -14,6 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.android.internal.app;
|
||||
|
||||
import android.annotation.IntDef;
|
||||
import android.annotation.Nullable;
|
||||
import android.content.Context;
|
||||
@@ -23,10 +24,10 @@ import android.view.ViewGroup;
|
||||
|
||||
import com.android.internal.annotations.VisibleForTesting;
|
||||
import com.android.internal.widget.PagerAdapter;
|
||||
|
||||
import com.android.internal.util.Preconditions;
|
||||
import com.android.internal.widget.ViewPager;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Skeletal {@link PagerAdapter} implementation of a work or personal profile page for
|
||||
* intent resolution (including share sheet).
|
||||
@@ -42,7 +43,7 @@ public abstract class AbstractMultiProfilePagerAdapter extends PagerAdapter {
|
||||
private int mCurrentPage;
|
||||
|
||||
AbstractMultiProfilePagerAdapter(Context context, int currentPage) {
|
||||
mContext = Preconditions.checkNotNull(context);
|
||||
mContext = Objects.requireNonNull(context);
|
||||
mCurrentPage = currentPage;
|
||||
}
|
||||
|
||||
|
||||
@@ -28,9 +28,9 @@ import android.os.UserHandle;
|
||||
import android.util.Slog;
|
||||
|
||||
import com.android.internal.os.BackgroundThread;
|
||||
import com.android.internal.util.Preconditions;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Helper class for monitoring the state of packages: adding, removing,
|
||||
@@ -93,7 +93,7 @@ public abstract class PackageMonitor extends android.content.BroadcastReceiver {
|
||||
throw new IllegalStateException("Already registered");
|
||||
}
|
||||
mRegisteredContext = context;
|
||||
mRegisteredHandler = Preconditions.checkNotNull(handler);
|
||||
mRegisteredHandler = Objects.requireNonNull(handler);
|
||||
if (user != null) {
|
||||
context.registerReceiverAsUser(this, user, sPackageFilt, null, mRegisteredHandler);
|
||||
context.registerReceiverAsUser(this, user, sNonDataFilt, null, mRegisteredHandler);
|
||||
|
||||
@@ -32,7 +32,6 @@ import android.text.TextUtils;
|
||||
import android.util.DebugUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.internal.util.Preconditions;
|
||||
import com.android.internal.util.function.pooled.PooledLambda;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
@@ -40,6 +39,7 @@ import java.util.ArrayDeque;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Queue;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.CompletionStage;
|
||||
@@ -352,7 +352,7 @@ public interface ServiceConnector<I extends IInterface> {
|
||||
@Override
|
||||
public <R> CompletionAwareJob<I, R> postForResult(@NonNull Job<I, R> job) {
|
||||
CompletionAwareJob<I, R> task = new CompletionAwareJob<>();
|
||||
task.mDelegate = Preconditions.checkNotNull(job);
|
||||
task.mDelegate = Objects.requireNonNull(job);
|
||||
enqueue(task);
|
||||
return task;
|
||||
}
|
||||
@@ -360,7 +360,7 @@ public interface ServiceConnector<I extends IInterface> {
|
||||
@Override
|
||||
public <R> AndroidFuture<R> postAsync(@NonNull Job<I, CompletableFuture<R>> job) {
|
||||
CompletionAwareJob<I, R> task = new CompletionAwareJob<>();
|
||||
task.mDelegate = Preconditions.checkNotNull((Job) job);
|
||||
task.mDelegate = Objects.requireNonNull((Job) job);
|
||||
task.mAsync = true;
|
||||
enqueue(task);
|
||||
return task;
|
||||
|
||||
@@ -23,10 +23,9 @@ import android.util.ArrayMap;
|
||||
import android.util.ArraySet;
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.internal.util.Preconditions;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Helper class for keeping track of whitelisted packages/activities.
|
||||
@@ -107,7 +106,7 @@ public final class WhitelistHelper {
|
||||
* Returns {@code true} if the entire package is whitelisted.
|
||||
*/
|
||||
public boolean isWhitelisted(@NonNull String packageName) {
|
||||
Preconditions.checkNotNull(packageName);
|
||||
Objects.requireNonNull(packageName);
|
||||
|
||||
if (mWhitelistedPackages == null) return false;
|
||||
|
||||
@@ -119,7 +118,7 @@ public final class WhitelistHelper {
|
||||
* Returns {@code true} if the specified activity is whitelisted.
|
||||
*/
|
||||
public boolean isWhitelisted(@NonNull ComponentName componentName) {
|
||||
Preconditions.checkNotNull(componentName);
|
||||
Objects.requireNonNull(componentName);
|
||||
|
||||
final String packageName = componentName.getPackageName();
|
||||
final ArraySet<ComponentName> whitelistedComponents = getWhitelistedComponents(packageName);
|
||||
@@ -136,7 +135,7 @@ public final class WhitelistHelper {
|
||||
*/
|
||||
@Nullable
|
||||
public ArraySet<ComponentName> getWhitelistedComponents(@NonNull String packageName) {
|
||||
Preconditions.checkNotNull(packageName);
|
||||
Objects.requireNonNull(packageName);
|
||||
|
||||
return mWhitelistedPackages == null ? null : mWhitelistedPackages.get(packageName);
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@ import com.android.internal.util.Preconditions;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.ThreadFactory;
|
||||
|
||||
public class FuseAppLoop implements Handler.Callback {
|
||||
@@ -92,8 +93,8 @@ public class FuseAppLoop implements Handler.Callback {
|
||||
public int registerCallback(@NonNull ProxyFileDescriptorCallback callback,
|
||||
@NonNull Handler handler) throws FuseUnavailableMountException {
|
||||
synchronized (mLock) {
|
||||
Preconditions.checkNotNull(callback);
|
||||
Preconditions.checkNotNull(handler);
|
||||
Objects.requireNonNull(callback);
|
||||
Objects.requireNonNull(handler);
|
||||
Preconditions.checkState(
|
||||
mCallbackMap.size() < Integer.MAX_VALUE - MIN_INODE, "Too many opened files.");
|
||||
Preconditions.checkArgument(
|
||||
@@ -333,8 +334,8 @@ public class FuseAppLoop implements Handler.Callback {
|
||||
boolean opened;
|
||||
|
||||
CallbackEntry(ProxyFileDescriptorCallback callback, Handler handler) {
|
||||
this.callback = Preconditions.checkNotNull(callback);
|
||||
this.handler = Preconditions.checkNotNull(handler);
|
||||
this.callback = Objects.requireNonNull(callback);
|
||||
this.handler = Objects.requireNonNull(handler);
|
||||
}
|
||||
|
||||
long getThreadId() {
|
||||
@@ -368,7 +369,7 @@ public class FuseAppLoop implements Handler.Callback {
|
||||
|
||||
void stopUsing(long threadId) {
|
||||
final BytesMapEntry entry = mEntries.get(threadId);
|
||||
Preconditions.checkNotNull(entry);
|
||||
Objects.requireNonNull(entry);
|
||||
entry.counter--;
|
||||
if (entry.counter <= 0) {
|
||||
mEntries.remove(threadId);
|
||||
|
||||
@@ -27,6 +27,7 @@ import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.Objects;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
|
||||
@@ -96,8 +97,8 @@ public class FileRotator {
|
||||
* may be deleted.
|
||||
*/
|
||||
public FileRotator(File basePath, String prefix, long rotateAgeMillis, long deleteAgeMillis) {
|
||||
mBasePath = Preconditions.checkNotNull(basePath);
|
||||
mPrefix = Preconditions.checkNotNull(prefix);
|
||||
mBasePath = Objects.requireNonNull(basePath);
|
||||
mPrefix = Objects.requireNonNull(prefix);
|
||||
mRotateAgeMillis = rotateAgeMillis;
|
||||
mDeleteAgeMillis = deleteAgeMillis;
|
||||
|
||||
@@ -406,7 +407,7 @@ public class FileRotator {
|
||||
public long endMillis;
|
||||
|
||||
public FileInfo(String prefix) {
|
||||
this.prefix = Preconditions.checkNotNull(prefix);
|
||||
this.prefix = Objects.requireNonNull(prefix);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -19,6 +19,7 @@ package com.android.internal.util;
|
||||
|
||||
import android.annotation.NonNull;
|
||||
import android.annotation.Nullable;
|
||||
import java.util.Objects;
|
||||
|
||||
/** @hide */
|
||||
public class ObjectUtils {
|
||||
@@ -32,7 +33,7 @@ public class ObjectUtils {
|
||||
*/
|
||||
@NonNull
|
||||
public static <T> T firstNotNull(@Nullable T a, @NonNull T b) {
|
||||
return a != null ? a : Preconditions.checkNotNull(b);
|
||||
return a != null ? a : Objects.requireNonNull(b);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -25,7 +25,6 @@ import android.util.Pools;
|
||||
|
||||
import com.android.internal.util.ArrayUtils;
|
||||
import com.android.internal.util.BitUtils;
|
||||
import com.android.internal.util.Preconditions;
|
||||
import com.android.internal.util.function.DecConsumer;
|
||||
import com.android.internal.util.function.DecFunction;
|
||||
import com.android.internal.util.function.DecPredicate;
|
||||
@@ -545,7 +544,7 @@ final class PooledLambdaImpl<R> extends OmniFunction<Object,
|
||||
+ ", k = " + k
|
||||
+ ")");
|
||||
}
|
||||
r.mFunc = Preconditions.checkNotNull(func);
|
||||
r.mFunc = Objects.requireNonNull(func);
|
||||
r.setFlags(MASK_FUNC_TYPE, LambdaType.encode(fNumArgs, fReturnType));
|
||||
r.setFlags(MASK_EXPOSED_AS, LambdaType.encode(numPlaceholders, fReturnType));
|
||||
if (ArrayUtils.size(r.mArgs) < fNumArgs) r.mArgs = new Object[fNumArgs];
|
||||
|
||||
@@ -33,11 +33,11 @@ import android.view.WindowManager;
|
||||
|
||||
import android.widget.PopupWindow;
|
||||
import com.android.internal.R;
|
||||
import com.android.internal.util.Preconditions;
|
||||
import com.android.internal.view.menu.MenuBuilder;
|
||||
import com.android.internal.widget.FloatingToolbar;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Objects;
|
||||
|
||||
public final class FloatingActionMode extends ActionMode {
|
||||
|
||||
@@ -84,8 +84,8 @@ public final class FloatingActionMode extends ActionMode {
|
||||
public FloatingActionMode(
|
||||
Context context, ActionMode.Callback2 callback,
|
||||
View originatingView, FloatingToolbar floatingToolbar) {
|
||||
mContext = Preconditions.checkNotNull(context);
|
||||
mCallback = Preconditions.checkNotNull(callback);
|
||||
mContext = Objects.requireNonNull(context);
|
||||
mCallback = Objects.requireNonNull(callback);
|
||||
mMenu = new MenuBuilder(context).setDefaultShowAsAction(
|
||||
MenuItem.SHOW_AS_ACTION_IF_ROOM);
|
||||
setType(ActionMode.TYPE_FLOATING);
|
||||
@@ -107,14 +107,14 @@ public final class FloatingActionMode extends ActionMode {
|
||||
mViewRectOnScreen = new Rect();
|
||||
mPreviousViewRectOnScreen = new Rect();
|
||||
mScreenRect = new Rect();
|
||||
mOriginatingView = Preconditions.checkNotNull(originatingView);
|
||||
mOriginatingView = Objects.requireNonNull(originatingView);
|
||||
mOriginatingView.getLocationOnScreen(mViewPositionOnScreen);
|
||||
// Allow the content rect to overshoot a little bit beyond the
|
||||
// bottom view bound if necessary.
|
||||
mBottomAllowance = context.getResources()
|
||||
.getDimensionPixelSize(R.dimen.content_rect_bottom_clip_allowance);
|
||||
mDisplaySize = new Point();
|
||||
setFloatingToolbar(Preconditions.checkNotNull(floatingToolbar));
|
||||
setFloatingToolbar(Objects.requireNonNull(floatingToolbar));
|
||||
}
|
||||
|
||||
private void setFloatingToolbar(FloatingToolbar floatingToolbar) {
|
||||
@@ -328,7 +328,7 @@ public final class FloatingActionMode extends ActionMode {
|
||||
private long mLastShowTime;
|
||||
|
||||
public FloatingToolbarVisibilityHelper(FloatingToolbar toolbar) {
|
||||
mToolbar = Preconditions.checkNotNull(toolbar);
|
||||
mToolbar = Objects.requireNonNull(toolbar);
|
||||
}
|
||||
|
||||
public void activate() {
|
||||
|
||||
@@ -35,7 +35,7 @@ import android.widget.TextView;
|
||||
import android.widget.AdapterView.OnItemClickListener;
|
||||
import android.widget.PopupWindow.OnDismissListener;
|
||||
|
||||
import com.android.internal.util.Preconditions;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* A standard menu popup in which when a submenu is opened, it replaces its parent menu in the
|
||||
@@ -113,7 +113,7 @@ final class StandardMenuPopup extends MenuPopup implements OnDismissListener, On
|
||||
|
||||
public StandardMenuPopup(Context context, MenuBuilder menu, View anchorView, int popupStyleAttr,
|
||||
int popupStyleRes, boolean overflowOnly) {
|
||||
mContext = Preconditions.checkNotNull(context);
|
||||
mContext = Objects.requireNonNull(context);
|
||||
mMenu = menu;
|
||||
mOverflowOnly = overflowOnly;
|
||||
final LayoutInflater inflater = LayoutInflater.from(context);
|
||||
|
||||
@@ -155,7 +155,7 @@ public final class FloatingToolbar {
|
||||
// TODO(b/65172902): Pass context in constructor when DecorView (and other callers)
|
||||
// supports multi-display.
|
||||
mContext = applyDefaultTheme(window.getContext());
|
||||
mWindow = Preconditions.checkNotNull(window);
|
||||
mWindow = Objects.requireNonNull(window);
|
||||
mPopup = new FloatingToolbarPopup(mContext, window.getDecorView());
|
||||
}
|
||||
|
||||
@@ -165,7 +165,7 @@ public final class FloatingToolbar {
|
||||
* toolbar.
|
||||
*/
|
||||
public FloatingToolbar setMenu(Menu menu) {
|
||||
mMenu = Preconditions.checkNotNull(menu);
|
||||
mMenu = Objects.requireNonNull(menu);
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -189,7 +189,7 @@ public final class FloatingToolbar {
|
||||
* toolbar.
|
||||
*/
|
||||
public FloatingToolbar setContentRect(Rect rect) {
|
||||
mContentRect.set(Preconditions.checkNotNull(rect));
|
||||
mContentRect.set(Objects.requireNonNull(rect));
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -457,8 +457,8 @@ public final class FloatingToolbar {
|
||||
* from.
|
||||
*/
|
||||
public FloatingToolbarPopup(Context context, View parent) {
|
||||
mParent = Preconditions.checkNotNull(parent);
|
||||
mContext = Preconditions.checkNotNull(context);
|
||||
mParent = Objects.requireNonNull(parent);
|
||||
mContext = Objects.requireNonNull(context);
|
||||
mContentContainer = createContentContainer(context);
|
||||
mPopupWindow = createPopupWindow(mContentContainer);
|
||||
mMarginHorizontal = parent.getResources()
|
||||
@@ -578,7 +578,7 @@ public final class FloatingToolbar {
|
||||
* The specified coordinates may be adjusted to make sure the popup is entirely on-screen.
|
||||
*/
|
||||
public void show(Rect contentRectOnScreen) {
|
||||
Preconditions.checkNotNull(contentRectOnScreen);
|
||||
Objects.requireNonNull(contentRectOnScreen);
|
||||
|
||||
if (isShowing()) {
|
||||
return;
|
||||
@@ -650,7 +650,7 @@ public final class FloatingToolbar {
|
||||
* This is a no-op if this popup is not showing.
|
||||
*/
|
||||
public void updateCoordinates(Rect contentRectOnScreen) {
|
||||
Preconditions.checkNotNull(contentRectOnScreen);
|
||||
Objects.requireNonNull(contentRectOnScreen);
|
||||
|
||||
if (!isShowing() || !mPopupWindow.isShowing()) {
|
||||
return;
|
||||
@@ -1134,11 +1134,11 @@ public final class FloatingToolbar {
|
||||
* Sets the touchable region of this popup to be the area occupied by its content.
|
||||
*/
|
||||
private void setContentAreaAsTouchableSurface() {
|
||||
Preconditions.checkNotNull(mMainPanelSize);
|
||||
Objects.requireNonNull(mMainPanelSize);
|
||||
final int width;
|
||||
final int height;
|
||||
if (mIsOverflowOpen) {
|
||||
Preconditions.checkNotNull(mOverflowPanelSize);
|
||||
Objects.requireNonNull(mOverflowPanelSize);
|
||||
width = mOverflowPanelSize.getWidth();
|
||||
height = mOverflowPanelSize.getHeight();
|
||||
} else {
|
||||
@@ -1183,7 +1183,7 @@ public final class FloatingToolbar {
|
||||
*/
|
||||
public List<MenuItem> layoutMainPanelItems(
|
||||
List<MenuItem> menuItems, final int toolbarWidth) {
|
||||
Preconditions.checkNotNull(menuItems);
|
||||
Objects.requireNonNull(menuItems);
|
||||
|
||||
int availableWidth = toolbarWidth;
|
||||
|
||||
@@ -1555,7 +1555,7 @@ public final class FloatingToolbar {
|
||||
private final FloatingToolbarPopup mPopup;
|
||||
|
||||
OverflowPanel(FloatingToolbarPopup popup) {
|
||||
super(Preconditions.checkNotNull(popup).mContext);
|
||||
super(Objects.requireNonNull(popup).mContext);
|
||||
this.mPopup = popup;
|
||||
setScrollBarDefaultDelayBeforeFade(ViewConfiguration.getScrollDefaultDelay() * 3);
|
||||
setScrollIndicators(View.SCROLL_INDICATOR_TOP | View.SCROLL_INDICATOR_BOTTOM);
|
||||
@@ -1616,7 +1616,7 @@ public final class FloatingToolbar {
|
||||
private final Context mContext;
|
||||
|
||||
public OverflowPanelViewHelper(Context context, int iconTextSpacing) {
|
||||
mContext = Preconditions.checkNotNull(context);
|
||||
mContext = Objects.requireNonNull(context);
|
||||
mIconTextSpacing = iconTextSpacing;
|
||||
mSidePadding = context.getResources()
|
||||
.getDimensionPixelSize(R.dimen.floating_toolbar_overflow_side_padding);
|
||||
@@ -1624,7 +1624,7 @@ public final class FloatingToolbar {
|
||||
}
|
||||
|
||||
public View getView(MenuItem menuItem, int minimumWidth, View convertView) {
|
||||
Preconditions.checkNotNull(menuItem);
|
||||
Objects.requireNonNull(menuItem);
|
||||
if (convertView != null) {
|
||||
updateMenuItemButton(
|
||||
convertView, menuItem, mIconTextSpacing, shouldShowIcon(menuItem));
|
||||
|
||||
@@ -33,6 +33,7 @@ import com.android.internal.util.Preconditions;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* A class representing a lockscreen credential. It can be either an empty password, a pattern
|
||||
@@ -67,7 +68,7 @@ public class LockscreenCredential implements Parcelable, AutoCloseable {
|
||||
* minimize the number of extra copies introduced.
|
||||
*/
|
||||
private LockscreenCredential(int type, byte[] credential) {
|
||||
Preconditions.checkNotNull(credential);
|
||||
Objects.requireNonNull(credential);
|
||||
if (type == CREDENTIAL_TYPE_NONE) {
|
||||
Preconditions.checkArgument(credential.length == 0);
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user