Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ea1a7cad authored by Daulet Zhanguzin's avatar Daulet Zhanguzin Committed by Tobias Thierer
Browse files

Replace com.android.internal.util.Preconditions.checkNotNull with

java.util.Objects.requireNonNull

Bug: 126528330

Test: Treehugger
Exempt-From-Owner-Approval: Global refactoring.
Change-Id: Idb1b6ba41af3b52f3376b1157259af3c30328c4e
parent 6aefe5f5
Loading
Loading
Loading
Loading
+7 −6
Original line number Diff line number Diff line
@@ -63,6 +63,7 @@ import com.android.server.usage.AppStandbyInternal.AppIdleStateChangeListener;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;

/**
 * Class to keep track of the information related to "force app standby", which includes:
@@ -416,12 +417,12 @@ public class AppStateTracker {
            }
            mStarted = true;

            mIActivityManager = Preconditions.checkNotNull(injectIActivityManager());
            mActivityManagerInternal = Preconditions.checkNotNull(injectActivityManagerInternal());
            mAppOpsManager = Preconditions.checkNotNull(injectAppOpsManager());
            mAppOpsService = Preconditions.checkNotNull(injectIAppOpsService());
            mPowerManagerInternal = Preconditions.checkNotNull(injectPowerManagerInternal());
            mAppStandbyInternal = Preconditions.checkNotNull(injectAppStandbyInternal());
            mIActivityManager = Objects.requireNonNull(injectIActivityManager());
            mActivityManagerInternal = Objects.requireNonNull(injectActivityManagerInternal());
            mAppOpsManager = Objects.requireNonNull(injectAppOpsManager());
            mAppOpsService = Objects.requireNonNull(injectIAppOpsService());
            mPowerManagerInternal = Objects.requireNonNull(injectPowerManagerInternal());
            mAppStandbyInternal = Objects.requireNonNull(injectAppStandbyInternal());

            mFlagsObserver = new FeatureFlagsObserver();
            mFlagsObserver.register();
+11 −13
Original line number Diff line number Diff line
@@ -47,8 +47,6 @@ import static android.os.Process.INVALID_UID;
import static android.system.OsConstants.IPPROTO_TCP;
import static android.system.OsConstants.IPPROTO_UDP;

import static com.android.internal.util.Preconditions.checkNotNull;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.app.BroadcastOptions;
@@ -904,7 +902,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
         * @see IpConnectivityMetrics.Logger
         */
        public IpConnectivityMetrics.Logger getMetricsLogger() {
            return checkNotNull(LocalServices.getService(IpConnectivityMetrics.Logger.class),
            return Objects.requireNonNull(LocalServices.getService(IpConnectivityMetrics.Logger.class),
                    "no IpConnectivityMetrics service");
        }

@@ -933,7 +931,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
            IDnsResolver dnsresolver, IpConnectivityLog logger, INetd netd, Dependencies deps) {
        if (DBG) log("ConnectivityService starting up");

        mDeps = checkNotNull(deps, "missing Dependencies");
        mDeps = Objects.requireNonNull(deps, "missing Dependencies");
        mSystemProperties = mDeps.getSystemProperties();
        mNetIdManager = mDeps.makeNetIdManager();

@@ -962,14 +960,14 @@ public class ConnectivityService extends IConnectivityManager.Stub

        mLingerDelayMs = mSystemProperties.getInt(LINGER_DELAY_PROPERTY, DEFAULT_LINGER_DELAY_MS);

        mContext = checkNotNull(context, "missing Context");
        mNMS = checkNotNull(netManager, "missing INetworkManagementService");
        mStatsService = checkNotNull(statsService, "missing INetworkStatsService");
        mPolicyManager = checkNotNull(policyManager, "missing INetworkPolicyManager");
        mPolicyManagerInternal = checkNotNull(
        mContext = Objects.requireNonNull(context, "missing Context");
        mNMS = Objects.requireNonNull(netManager, "missing INetworkManagementService");
        mStatsService = Objects.requireNonNull(statsService, "missing INetworkStatsService");
        mPolicyManager = Objects.requireNonNull(policyManager, "missing INetworkPolicyManager");
        mPolicyManagerInternal = Objects.requireNonNull(
                LocalServices.getService(NetworkPolicyManagerInternal.class),
                "missing NetworkPolicyManagerInternal");
        mDnsResolver = checkNotNull(dnsresolver, "missing IDnsResolver");
        mDnsResolver = Objects.requireNonNull(dnsresolver, "missing IDnsResolver");
        mProxyTracker = mDeps.makeProxyTracker(mContext, mHandler);

        mNetd = netd;
@@ -5195,7 +5193,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
    @Override
    public NetworkRequest pendingRequestForNetwork(NetworkCapabilities networkCapabilities,
            PendingIntent operation) {
        checkNotNull(operation, "PendingIntent cannot be null.");
        Objects.requireNonNull(operation, "PendingIntent cannot be null.");
        networkCapabilities = new NetworkCapabilities(networkCapabilities);
        enforceNetworkRequestPermissions(networkCapabilities);
        enforceMeteredApnPolicy(networkCapabilities);
@@ -5222,7 +5220,7 @@ public class ConnectivityService extends IConnectivityManager.Stub

    @Override
    public void releasePendingNetworkRequest(PendingIntent operation) {
        checkNotNull(operation, "PendingIntent cannot be null.");
        Objects.requireNonNull(operation, "PendingIntent cannot be null.");
        mHandler.sendMessage(mHandler.obtainMessage(EVENT_RELEASE_NETWORK_REQUEST_WITH_INTENT,
                getCallingUid(), 0, operation));
    }
@@ -5280,7 +5278,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
    @Override
    public void pendingListenForNetwork(NetworkCapabilities networkCapabilities,
            PendingIntent operation) {
        checkNotNull(operation, "PendingIntent cannot be null.");
        Objects.requireNonNull(operation, "PendingIntent cannot be null.");
        if (!hasWifiNetworkListenPermission(networkCapabilities)) {
            enforceAccessPermission();
        }
+4 −3
Original line number Diff line number Diff line
@@ -47,6 +47,7 @@ import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.function.Consumer;

@@ -113,9 +114,9 @@ class ExplicitHealthCheckController {
                Slog.wtf(TAG, "Resetting health check controller callbacks");
            }

            mPassedConsumer = Preconditions.checkNotNull(passedConsumer);
            mSupportedConsumer = Preconditions.checkNotNull(supportedConsumer);
            mNotifySyncRunnable = Preconditions.checkNotNull(notifySyncRunnable);
            mPassedConsumer = Objects.requireNonNull(passedConsumer);
            mSupportedConsumer = Objects.requireNonNull(supportedConsumer);
            mNotifySyncRunnable = Objects.requireNonNull(notifySyncRunnable);
        }
    }

+9 −10
Original line number Diff line number Diff line
@@ -25,8 +25,6 @@ import static android.system.OsConstants.EINVAL;
import static android.system.OsConstants.IPPROTO_UDP;
import static android.system.OsConstants.SOCK_DGRAM;

import static com.android.internal.util.Preconditions.checkNotNull;

import android.annotation.NonNull;
import android.app.AppOpsManager;
import android.content.Context;
@@ -76,6 +74,7 @@ import java.net.InetSocketAddress;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * A service to manage multiple clients that want to access the IpSec API. The service is
@@ -566,7 +565,7 @@ public class IpSecService extends IIpSecService.Stub {
        }

        void put(int key, RefcountedResource<T> obj) {
            checkNotNull(obj, "Null resources cannot be added");
            Objects.requireNonNull(obj, "Null resources cannot be added");
            mArray.put(key, obj);
        }

@@ -1101,7 +1100,7 @@ public class IpSecService extends IIpSecService.Stub {
        if (requestedSpi > 0 && requestedSpi < 256) {
            throw new IllegalArgumentException("ESP SPI must not be in the range of 0-255.");
        }
        checkNotNull(binder, "Null Binder passed to allocateSecurityParameterIndex");
        Objects.requireNonNull(binder, "Null Binder passed to allocateSecurityParameterIndex");

        int callingUid = Binder.getCallingUid();
        UserRecord userRecord = mUserResourceTracker.getUserRecord(callingUid);
@@ -1218,7 +1217,7 @@ public class IpSecService extends IIpSecService.Stub {
            throw new IllegalArgumentException(
                    "Specified port number must be a valid non-reserved UDP port");
        }
        checkNotNull(binder, "Null Binder passed to openUdpEncapsulationSocket");
        Objects.requireNonNull(binder, "Null Binder passed to openUdpEncapsulationSocket");

        int callingUid = Binder.getCallingUid();
        UserRecord userRecord = mUserResourceTracker.getUserRecord(callingUid);
@@ -1278,8 +1277,8 @@ public class IpSecService extends IIpSecService.Stub {
            String localAddr, String remoteAddr, Network underlyingNetwork, IBinder binder,
            String callingPackage) {
        enforceTunnelFeatureAndPermissions(callingPackage);
        checkNotNull(binder, "Null Binder passed to createTunnelInterface");
        checkNotNull(underlyingNetwork, "No underlying network was specified");
        Objects.requireNonNull(binder, "Null Binder passed to createTunnelInterface");
        Objects.requireNonNull(underlyingNetwork, "No underlying network was specified");
        checkInetAddress(localAddr);
        checkInetAddress(remoteAddr);

@@ -1556,7 +1555,7 @@ public class IpSecService extends IIpSecService.Stub {
                    "IPsec Tunnel Mode requires PackageManager.FEATURE_IPSEC_TUNNELS");
        }

        checkNotNull(callingPackage, "Null calling package cannot create IpSec tunnels");
        Objects.requireNonNull(callingPackage, "Null calling package cannot create IpSec tunnels");
        switch (getAppOpsManager().noteOp(TUNNEL_OP, Binder.getCallingUid(), callingPackage)) {
            case AppOpsManager.MODE_DEFAULT:
                mContext.enforceCallingOrSelfPermission(
@@ -1625,12 +1624,12 @@ public class IpSecService extends IIpSecService.Stub {
    @Override
    public synchronized IpSecTransformResponse createTransform(
            IpSecConfig c, IBinder binder, String callingPackage) throws RemoteException {
        checkNotNull(c);
        Objects.requireNonNull(c);
        if (c.getMode() == IpSecTransform.MODE_TUNNEL) {
            enforceTunnelFeatureAndPermissions(callingPackage);
        }
        checkIpSecConfig(c);
        checkNotNull(binder, "Null Binder passed to createTransform");
        Objects.requireNonNull(binder, "Null Binder passed to createTransform");
        final int resourceId = mNextResourceId++;

        UserRecord userRecord = mUserResourceTracker.getUserRecord(Binder.getCallingUid());
+7 −7
Original line number Diff line number Diff line
@@ -23,7 +23,6 @@ import static android.location.LocationManager.NETWORK_PROVIDER;
import static android.location.LocationManager.PASSIVE_PROVIDER;
import static android.os.PowerManager.locationPowerSaveModeToString;

import static com.android.internal.util.Preconditions.checkNotNull;
import static com.android.internal.util.Preconditions.checkState;

import android.Manifest;
@@ -121,6 +120,7 @@ import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
import java.util.concurrent.TimeUnit;

/**
@@ -821,7 +821,7 @@ public class LocationManagerService extends ILocationManager.Stub {

        @GuardedBy("mLock")
        public void attachLocked(AbstractLocationProvider provider) {
            checkNotNull(provider);
            Objects.requireNonNull(provider);
            checkState(mProvider == null);

            if (D) {
@@ -1430,7 +1430,7 @@ public class LocationManagerService extends ILocationManager.Stub {
    @Override
    public boolean addGnssBatchingCallback(IBatchedLocationCallback callback, String packageName,
            String featureId, String listenerIdentifier) {
        Preconditions.checkNotNull(listenerIdentifier);
        Objects.requireNonNull(listenerIdentifier);

        return mGnssManagerService == null ? false : mGnssManagerService.addGnssBatchingCallback(
                callback, packageName, featureId, listenerIdentifier);
@@ -2119,7 +2119,7 @@ public class LocationManagerService extends ILocationManager.Stub {
    public void requestLocationUpdates(LocationRequest request, ILocationListener listener,
            PendingIntent intent, String packageName, String featureId,
            String listenerIdentifier) {
        Preconditions.checkNotNull(listenerIdentifier);
        Objects.requireNonNull(listenerIdentifier);

        synchronized (mLock) {
            if (request == null) request = DEFAULT_LOCATION_REQUEST;
@@ -2470,7 +2470,7 @@ public class LocationManagerService extends ILocationManager.Stub {
    @Override
    public void requestGeofence(LocationRequest request, Geofence geofence, PendingIntent intent,
            String packageName, String featureId, String listenerIdentifier) {
        Preconditions.checkNotNull(listenerIdentifier);
        Objects.requireNonNull(listenerIdentifier);

        if (request == null) request = DEFAULT_LOCATION_REQUEST;
        int allowedResolutionLevel = getCallerAllowedResolutionLevel();
@@ -2567,7 +2567,7 @@ public class LocationManagerService extends ILocationManager.Stub {
    @Override
    public boolean addGnssMeasurementsListener(IGnssMeasurementsListener listener,
            String packageName, String featureId, String listenerIdentifier) {
        Preconditions.checkNotNull(listenerIdentifier);
        Objects.requireNonNull(listenerIdentifier);

        return mGnssManagerService == null ? false
                : mGnssManagerService.addGnssMeasurementsListener(listener, packageName, featureId,
@@ -2600,7 +2600,7 @@ public class LocationManagerService extends ILocationManager.Stub {
    @Override
    public boolean addGnssNavigationMessageListener(IGnssNavigationMessageListener listener,
            String packageName, String featureId, String listenerIdentifier) {
        Preconditions.checkNotNull(listenerIdentifier);
        Objects.requireNonNull(listenerIdentifier);

        return mGnssManagerService == null ? false
                : mGnssManagerService.addGnssNavigationMessageListener(listener, packageName,
Loading