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

Commit 4f42cb85 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Fixed warnings" into main

parents dc3779f0 326495aa
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -328,14 +328,14 @@ public class AccessNetworksManager extends Handler {
            log("onNetworkValidationRequested: networkCapability = ["
                    + DataUtils.networkCapabilityToString(networkCapability) + "]");

            dnc.requestNetworkValidation(networkCapability, new Consumer<Integer>() {
            dnc.requestNetworkValidation(networkCapability, new Consumer<>() {
                @Override
                public void accept(Integer result) {
                    post(() -> {
                        try {
                            log("onNetworkValidationRequestDone:"
                                    + DataServiceCallback.resultCodeToString(result));
                            resultCodeCallback.accept(result.intValue());
                            resultCodeCallback.accept(result);
                        } catch (RemoteException e) {
                            // Ignore if the remote process is no longer available to call back.
                            loge("onNetworkValidationRequestDone RemoteException" + e);
+2 −3
Original line number Diff line number Diff line
@@ -147,8 +147,7 @@ public class CellularDataService extends DataService {
            if (t == null) {
                return RESULT_SUCCESS;
            } else {
                if (t instanceof CommandException) {
                    CommandException ce = (CommandException) t;
                if (t instanceof CommandException ce) {
                    if (ce.getCommandError() == CommandException.Error.REQUEST_NOT_SUPPORTED) {
                        return DataServiceCallback.RESULT_ERROR_UNSUPPORTED;
                    } else {
@@ -229,7 +228,7 @@ public class CellularDataService extends DataService {
                mCallbackMap.put(message, callback);
            }

            mPhone.mCi.setDataProfile(dps.toArray(new DataProfile[dps.size()]), message);
            mPhone.mCi.setDataProfile(dps.toArray(new DataProfile[0]), message);
        }

        @Override
+12 −33
Original line number Diff line number Diff line
@@ -58,9 +58,6 @@ import java.util.concurrent.TimeUnit;
 */
public class CellularNetworkValidator {
    private static final String LOG_TAG = "NetworkValidator";
    // If true, upon validated network cache hit, we report validationDone only when
    // network becomes available. Otherwise, we report validationDone immediately.
    private static boolean sWaitForNetworkAvailableWhenCacheHit = true;

    // States of validator. Only one validation can happen at once.
    // IDLE: no validation going on.
@@ -69,7 +66,7 @@ public class CellularNetworkValidator {
    private static final int STATE_VALIDATING          = 1;
    // VALIDATED: validation is done and successful.
    // Waiting for stopValidation() to release
    // validationg NetworkRequest.
    // validation NetworkRequest.
    private static final int STATE_VALIDATED           = 2;

    // Singleton instance.
@@ -79,13 +76,11 @@ public class CellularNetworkValidator {

    private int mState = STATE_IDLE;
    private int mSubId;
    private long mTimeoutInMs;
    private boolean mReleaseAfterValidation;

    private NetworkRequest mNetworkRequest;
    private ValidationCallback mValidationCallback;
    private Context mContext;
    private ConnectivityManager mConnectivityManager;
    private final Context mContext;
    private final ConnectivityManager mConnectivityManager;
    @VisibleForTesting
    public Handler mHandler = new Handler();
    @VisibleForTesting
@@ -96,18 +91,11 @@ public class CellularNetworkValidator {
        // A cache with fixed size. It remembers 10 most recently successfully validated networks.
        private static final int VALIDATED_NETWORK_CACHE_SIZE = 10;
        private final PriorityQueue<ValidatedNetwork> mValidatedNetworkPQ =
                new PriorityQueue((Comparator<ValidatedNetwork>) (n1, n2) -> {
                    if (n1.mValidationTimeStamp < n2.mValidationTimeStamp) {
                        return -1;
                    } else if (n1.mValidationTimeStamp > n2.mValidationTimeStamp) {
                        return 1;
                    } else {
                        return 0;
                    }
                });
        private final Map<String, ValidatedNetwork> mValidatedNetworkMap = new HashMap();
                new PriorityQueue<>((Comparator<ValidatedNetwork>) Comparator.comparingLong(
                        (ValidatedNetwork n) -> n.mValidationTimeStamp));
        private final Map<String, ValidatedNetwork> mValidatedNetworkMap = new HashMap<>();

        private final class ValidatedNetwork {
        private static final class ValidatedNetwork {
            ValidatedNetwork(String identity, long timeStamp) {
                mValidationIdentity = identity;
                mValidationTimeStamp = timeStamp;
@@ -165,7 +153,6 @@ public class CellularNetworkValidator {

        private String getValidationNetworkIdentity(int subId) {
            if (!SubscriptionManager.isUsableSubscriptionId(subId)) return null;
            if (SubscriptionManagerService.getInstance() == null) return null;
            Phone phone = PhoneFactory.getPhone(SubscriptionManagerService.getInstance()
                    .getPhoneId(subId));
            if (phone == null || phone.getServiceState() == null) return null;
@@ -270,26 +257,18 @@ public class CellularNetworkValidator {
            stopValidation();
        }

        if (!sWaitForNetworkAvailableWhenCacheHit && mValidatedNetworkCache
                .isRecentlyValidated(subId)) {
            callback.onValidationDone(true, subId);
            return;
        }

        mState = STATE_VALIDATING;
        mSubId = subId;
        mTimeoutInMs = timeoutInMs;
        mValidationCallback = callback;
        mReleaseAfterValidation = releaseAfterValidation;
        mNetworkRequest = createNetworkRequest();

        logd("Start validating subId " + mSubId + " mTimeoutInMs " + mTimeoutInMs
        logd("Start validating subId " + mSubId + " timeoutInMs " + timeoutInMs
                + " mReleaseAfterValidation " + mReleaseAfterValidation);

        mNetworkCallback = new ConnectivityNetworkCallback(subId);

        mConnectivityManager.requestNetwork(mNetworkRequest, mNetworkCallback, mHandler);
        mHandler.postDelayed(() -> onValidationTimeout(subId), mTimeoutInMs);
        mConnectivityManager.requestNetwork(createNetworkRequest(), mNetworkCallback, mHandler);
        mHandler.postDelayed(() -> onValidationTimeout(subId), timeoutInMs);
    }

    private synchronized void onValidationTimeout(int subId) {
@@ -351,7 +330,7 @@ public class CellularNetworkValidator {
            mState = STATE_VALIDATED;
            // If validation passed and per request to NOT release after validation, delay cleanup.
            if (!mReleaseAfterValidation && passed) {
                mHandler.postDelayed(()-> stopValidation(), 500);
                mHandler.postDelayed(this::stopValidation, 500);
            } else {
                stopValidation();
            }
+1 −1
Original line number Diff line number Diff line
@@ -418,7 +418,7 @@ public class DataEvaluation {
    public String toString() {
        StringBuilder evaluationStr = new StringBuilder();
        evaluationStr.append("Data evaluation: evaluation reason:" + mDataEvaluationReason + ", ");
        if (mDataDisallowedReasons.size() > 0) {
        if (!mDataDisallowedReasons.isEmpty()) {
            evaluationStr.append("Data disallowed reasons:");
            for (DataDisallowedReason reason : mDataDisallowedReasons) {
                evaluationStr.append(" ").append(reason);
+10 −15
Original line number Diff line number Diff line
@@ -104,7 +104,7 @@ public class DataProfileManager extends Handler {
    private @Nullable DataProfile mPreferredDataProfile = null;

    /** The last data profile that's successful for internet connection by subscription id. */
    private @NonNull LruCache<Integer, DataProfile> mLastInternetDataProfiles =
    private final @NonNull LruCache<Integer, DataProfile> mLastInternetDataProfiles =
            new LruCache<>(256);

    /** Preferred data profile set id. */
@@ -603,7 +603,7 @@ public class DataProfileManager extends Handler {
        // Sort the data profiles so the preferred data profile is at the beginning.
        List<DataProfile> allDataProfiles = mAllDataProfiles.stream()
                .sorted(Comparator.comparing((DataProfile dp) -> !dp.equals(mPreferredDataProfile)))
                .collect(Collectors.toList());
                .toList();
        // Search in the order. "IA" type should be the first from getAllowedInitialAttachApnTypes.
        for (int apnType : mDataConfigManager.getAllowedInitialAttachApnTypes()) {
            initialAttachDataProfile = allDataProfiles.stream()
@@ -799,7 +799,7 @@ public class DataProfileManager extends Handler {
            logv("Satisfied profile: " + dataProfile + ", last setup="
                    + DataUtils.elapsedTimeToString(dataProfile.getLastSetupTimestamp()));
        }
        if (dataProfiles.size() == 0) {
        if (dataProfiles.isEmpty()) {
            log("Can't find any data profile that can satisfy " + networkRequest);
            return null;
        }
@@ -816,16 +816,14 @@ public class DataProfileManager extends Handler {
                                ApnSetting.INFRASTRUCTURE_SATELLITE)) {
                            return false;
                        }
                        if (!isNtn && !dp.getApnSetting().isForInfrastructure(
                                ApnSetting.INFRASTRUCTURE_CELLULAR)) {
                            return false;
                        }
                        return isNtn || dp.getApnSetting().isForInfrastructure(
                                ApnSetting.INFRASTRUCTURE_CELLULAR);
                    }

                    return true;
                })
                .collect(Collectors.toList());
        if (dataProfiles.size() == 0) {
        if (dataProfiles.isEmpty()) {
            String ntnReason = "";
            if (mFeatureFlags.carrierEnabledSatelliteFlag()) {
                ntnReason = " and infrastructure for "
@@ -843,7 +841,7 @@ public class DataProfileManager extends Handler {
                        == Telephony.Carriers.MATCH_ALL_APN_SET_ID
                        || dp.getApnSetting().getApnSetId() == mPreferredDataProfileSetId))
                .collect(Collectors.toList());
        if (dataProfiles.size() == 0) {
        if (dataProfiles.isEmpty()) {
            log("Can't find any data profile has APN set id matched. mPreferredDataProfileSetId="
                    + mPreferredDataProfileSetId);
            return null;
@@ -851,9 +849,10 @@ public class DataProfileManager extends Handler {

        // Check if data profiles are permanently failed.
        dataProfiles = dataProfiles.stream()
                .filter(dp -> ignorePermanentFailure || !dp.getApnSetting().getPermanentFailed())
                .filter(dp -> ignorePermanentFailure || (dp.getApnSetting() != null
                        && !dp.getApnSetting().getPermanentFailed()))
                .collect(Collectors.toList());
        if (dataProfiles.size() == 0) {
        if (dataProfiles.isEmpty()) {
            log("The suitable data profiles are all in permanent failed state.");
            return null;
        }
@@ -1096,10 +1095,6 @@ public class DataProfileManager extends Handler {
     * @return {@code true} if the provided data profile can be still used in current environment.
     */
    public boolean isDataProfileCompatible(@NonNull DataProfile dataProfile) {
        if (dataProfile == null) {
            return false;
        }

        if (dataProfile.getApnSetting() == null && dataProfile.getTrafficDescriptor() != null) {
            // A traffic descriptor only data profile can be always used. Traffic descriptors are
            // always generated on the fly instead loaded from the database.
Loading