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

Commit 55fcc742 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Partial refactoring telephony network factory test cases"

parents 5f83b3ec 6d030fc8
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
@@ -259,8 +259,7 @@ public class PhoneFactory {
                sTelephonyNetworkFactories = new TelephonyNetworkFactory[numPhones];
                for (int i = 0; i < numPhones; i++) {
                    sTelephonyNetworkFactories[i] = new TelephonyNetworkFactory(
                            sPhoneSwitcher, sc, sSubscriptionMonitor, Looper.myLooper(),
                            sContext, i, sPhones[i].mDcTracker);
                            sSubscriptionMonitor, Looper.myLooper(), sPhones[i]);
                }
            }
        }
+19 −16
Original line number Diff line number Diff line
@@ -18,7 +18,6 @@ package com.android.internal.telephony.dataconnection;

import static android.telephony.SubscriptionManager.INVALID_SUBSCRIPTION_ID;

import android.content.Context;
import android.net.NetworkCapabilities;
import android.net.NetworkFactory;
import android.net.NetworkRequest;
@@ -29,6 +28,7 @@ import android.os.Message;
import android.telephony.Rlog;
import android.util.LocalLog;

import com.android.internal.telephony.Phone;
import com.android.internal.telephony.PhoneSwitcher;
import com.android.internal.telephony.SubscriptionController;
import com.android.internal.telephony.SubscriptionMonitor;
@@ -52,7 +52,7 @@ public class TelephonyNetworkFactory extends NetworkFactory {
    private final HashMap<NetworkRequest, LocalLog> mSpecificRequests =
            new HashMap<NetworkRequest, LocalLog>();

    private final int mPhoneId;
    private final Phone mPhone;
    // Only when this network factory is active, it will apply any network requests.
    private boolean mIsActive;
    // Whether this network factory is active and should handle default network requests.
@@ -68,28 +68,29 @@ public class TelephonyNetworkFactory extends NetworkFactory {
    private static final int EVENT_NETWORK_REQUEST              = 3;
    private static final int EVENT_NETWORK_RELEASE              = 4;

    public TelephonyNetworkFactory(PhoneSwitcher phoneSwitcher,
            SubscriptionController subscriptionController, SubscriptionMonitor subscriptionMonitor,
            Looper looper, Context context, int phoneId, DcTracker dcTracker) {
        super(looper, context, "TelephonyNetworkFactory[" + phoneId + "]", null);
    public TelephonyNetworkFactory(SubscriptionMonitor subscriptionMonitor, Looper looper,
                                   Phone phone) {
        super(looper, phone.getContext(), "TelephonyNetworkFactory[" + phone.getPhoneId()
                + "]", null);
        mPhone = phone;
        mInternalHandler = new InternalHandler(looper);

        setCapabilityFilter(makeNetworkFilter(subscriptionController, phoneId));
        mSubscriptionController = SubscriptionController.getInstance();

        setCapabilityFilter(makeNetworkFilter(mSubscriptionController, mPhone.getPhoneId()));
        setScoreFilter(TELEPHONY_NETWORK_SCORE);

        mPhoneSwitcher = phoneSwitcher;
        mSubscriptionController = subscriptionController;
        mPhoneSwitcher = PhoneSwitcher.getInstance();
        mSubscriptionMonitor = subscriptionMonitor;
        mPhoneId = phoneId;
        LOG_TAG = "TelephonyNetworkFactory[" + phoneId + "]";
        mDcTracker = dcTracker;
        LOG_TAG = "TelephonyNetworkFactory[" + mPhone.getPhoneId() + "]";
        mDcTracker = mPhone.mDcTracker;

        mIsActive = false;
        mPhoneSwitcher.registerForActivePhoneSwitch(mInternalHandler, EVENT_ACTIVE_PHONE_SWITCH,
                null);

        mSubscriptionId = INVALID_SUBSCRIPTION_ID;
        mSubscriptionMonitor.registerForSubscriptionChanged(mPhoneId, mInternalHandler,
        mSubscriptionMonitor.registerForSubscriptionChanged(mPhone.getPhoneId(), mInternalHandler,
                EVENT_SUBSCRIPTION_CHANGED, null);

        mIsActiveForDefault = false;
@@ -183,9 +184,10 @@ public class TelephonyNetworkFactory extends NetworkFactory {

    // apply or revoke requests if our active-ness changes
    private void onActivePhoneSwitch() {
        final boolean newIsActive = mPhoneSwitcher.shouldApplySpecifiedRequests(mPhoneId);
        final boolean newIsActive = mPhoneSwitcher.shouldApplySpecifiedRequests(
                mPhone.getPhoneId());
        final boolean newIsActiveForDefault =
                mPhoneSwitcher.shouldApplyUnspecifiedRequests(mPhoneId);
                mPhoneSwitcher.shouldApplyUnspecifiedRequests(mPhone.getPhoneId());

        String logString = "onActivePhoneSwitch(newIsActive " + newIsActive + ", "
                + "newIsActiveForDefault " + newIsActiveForDefault + ")";
@@ -202,7 +204,8 @@ public class TelephonyNetworkFactory extends NetworkFactory {
    // watch for phone->subId changes, reapply new filter and let
    // that flow through to apply/revoke of requests
    private void onSubIdChange() {
        final int newSubscriptionId = mSubscriptionController.getSubIdUsingPhoneId(mPhoneId);
        final int newSubscriptionId = mSubscriptionController.getSubIdUsingPhoneId(
                mPhone.getPhoneId());
        if (mSubscriptionId != newSubscriptionId) {
            if (DBG) log("onSubIdChange " + mSubscriptionId + "->" + newSubscriptionId);
            mSubscriptionId = newSubscriptionId;
+177 −223

File changed.

Preview size limit exceeded, changes collapsed.

+0 −170
Original line number Diff line number Diff line
/*
 * Copyright (C) 2006 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.internal.telephony.mocks;

import android.net.LinkProperties;
import android.net.NetworkCapabilities;
import android.net.NetworkRequest;
import android.os.Handler;
import android.os.Message;
import android.util.LocalLog;

import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.telephony.DctConstants;
import com.android.internal.telephony.dataconnection.DcTracker;

import java.util.ArrayList;

public class DcTrackerMock extends DcTracker {
    public DcTrackerMock() {
    }
    @Override
    public void registerServiceStateTrackerEvents() {
        throw new RuntimeException("registerServiceStateTrackerEvents not implemented");
    }
    @Override
    public void unregisterServiceStateTrackerEvents() {
        throw new RuntimeException("Not Implemented");
    }
    @Override
    public void setUserDataEnabled(boolean enable) {
        throw new RuntimeException("Not Implemented");
    }
    @Override
    public long getSubId() {
        throw new RuntimeException("Not Implemented");
    }
    @Override
    public DctConstants.Activity getActivity() {
        throw new RuntimeException("Not Implemented");
    }
    @Override
    public LinkProperties getLinkProperties(String apnType) {
        throw new RuntimeException("Not Implemented");
    }
    @Override
    public NetworkCapabilities getNetworkCapabilities(String apnType) {
        throw new RuntimeException("Not Implemented");
    }
    @Override
    public String[] getActiveApnTypes() {
        throw new RuntimeException("Not Implemented");
    }
    @Override
    public String getActiveApnString(String apnType) {
        throw new RuntimeException("Not Implemented");
    }
    @Override
    public DctConstants.State getState(String apnType) {
        throw new RuntimeException("Not Implemented");
    }
    @Override
    public DctConstants.State getOverallState() {
        throw new RuntimeException("Not Implemented");
    }
    @Override
    public boolean hasMatchedTetherApnSetting() {
        throw new RuntimeException("Not Implemented");
    }
    @Override
    public boolean getAutoAttachOnCreation() {
        throw new RuntimeException("Not Implemented");
    }
    @Override
    public boolean isUserDataEnabled() {
        throw new RuntimeException("Not Implemented");
    }
    @Override
    public boolean isDataEnabled() {
        throw new RuntimeException("Not Implemented");
    }
    @Override
    public void setDataRoamingEnabledByUser(boolean enabled) {
        throw new RuntimeException("Not Implemented");
    }
    @Override
    public boolean getDataRoamingEnabled() {
        throw new RuntimeException("Not Implemented");
    }
    @Override
    public boolean isDisconnected() {
        throw new RuntimeException("Not Implemented");
    }
    @Override
    public void update() {
        throw new RuntimeException("Not Implemented");
    }
    @Override
    public void cleanUpAllConnections(String cause) {
        throw new RuntimeException("Not Implemented");
    }
    @Override
    public void updateRecords() {
        throw new RuntimeException("Not Implemented");
    }
    @Override
    public void cleanUpAllConnections(String cause, Message disconnectAllCompleteMsg) {
        throw new RuntimeException("Not Implemented");
    }
    @Override
    public void registerForAllDataDisconnected(Handler h, int what, Object obj) {
        throw new RuntimeException("Not Implemented");
    }
    @Override
    public void unregisterForAllDataDisconnected(Handler h) {
        throw new RuntimeException("Not Implemented");
    }
    @Override
    public boolean setInternalDataEnabled(boolean enable) {
        throw new RuntimeException("Not Implemented");
    }
    @Override
    public String[] getPcscfAddress(String apnType) {
        throw new RuntimeException("Not Implemented");
    }
    @Override
    public void sendStartNetStatPoll(DctConstants.Activity activity) {
        throw new RuntimeException("Not Implemented");
    }
    @Override
    public void sendStopNetStatPoll(DctConstants.Activity activity) {
        throw new RuntimeException("Not Implemented");
    }

    private final ArrayList<NetworkRequest> mRequestedNetworks = new ArrayList<NetworkRequest>();

    @Override
    public void requestNetwork(NetworkRequest networkRequest, LocalLog log) {
        synchronized (mRequestedNetworks) {
            mRequestedNetworks.add(networkRequest);
        }
    }

    @Override
    public void releaseNetwork(NetworkRequest networkRequest, LocalLog log) {
        synchronized (mRequestedNetworks) {
            mRequestedNetworks.remove(networkRequest);
        }
    }

    @VisibleForTesting
    public int getNumberOfLiveRequests() {
        synchronized (mRequestedNetworks) {
            return mRequestedNetworks.size();
        }
    }
}