Merge "Move anas out of telephony"
diff --git a/src/com/android/phone/PhoneGlobals.java b/src/com/android/phone/PhoneGlobals.java
index 0e51a11..5282b29 100644
--- a/src/com/android/phone/PhoneGlobals.java
+++ b/src/com/android/phone/PhoneGlobals.java
@@ -62,8 +62,6 @@
 import com.android.internal.telephony.dataconnection.DataConnectionReasons;
 import com.android.internal.telephony.dataconnection.DataConnectionReasons.DataDisallowedReasonType;
 import com.android.internal.util.IndentingPrintWriter;
-import com.android.phone.anas.AlternativeNetworkAccessService;
-import com.android.phone.common.CallLogAsync;
 import com.android.phone.settings.SettingsConstants;
 import com.android.phone.vvm.CarrierVvmPackageInstalledReceiver;
 import com.android.services.telephony.sip.SipAccountRegistry;
@@ -329,7 +327,6 @@
             phoneMgr = PhoneInterfaceManager.init(this, PhoneFactory.getDefaultPhone());
 
             configLoader = CarrierConfigLoader.init(this);
-            AlternativeNetworkAccessService.initInstance(this);
 
             // Create the CallNotifier singleton, which handles
             // asynchronous events from the telephony layer (like
diff --git a/src/com/android/phone/anas/ANASNetworkScanCtlr.java b/src/com/android/phone/anas/ANASNetworkScanCtlr.java
deleted file mode 100644
index 6c75706..0000000
--- a/src/com/android/phone/anas/ANASNetworkScanCtlr.java
+++ /dev/null
@@ -1,312 +0,0 @@
-/*
- * Copyright (C) 2018 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.phone.anas;
-
-import android.content.Context;
-import android.os.Handler;
-import android.os.Message;
-import android.telephony.AccessNetworkConstants;
-import android.telephony.CellInfo;
-import android.telephony.CellInfoLte;
-import android.telephony.NetworkScan;
-import android.telephony.NetworkScanRequest;
-import android.telephony.RadioAccessSpecifier;
-import android.telephony.Rlog;
-import android.telephony.SubscriptionInfo;
-import android.telephony.TelephonyManager;
-import android.telephony.TelephonyScanManager;
-
-import com.android.internal.annotations.VisibleForTesting;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.concurrent.TimeUnit;
-
-/**
- * Network Scan controller class which will scan for the specific bands as requested and
- * provide results to caller when ready.
- */
-public class ANASNetworkScanCtlr {
-    private static final String LOG_TAG = "ANASNetworkScanCtlr";
-    private static final boolean DBG = true;
-    private static final int SEARCH_PERIODICITY_SLOW = (int) TimeUnit.MINUTES.toSeconds(5);
-    private static final int SEARCH_PERIODICITY_FAST = (int) TimeUnit.MINUTES.toSeconds(1);
-    private static final int MAX_SEARCH_TIME = (int) TimeUnit.MINUTES.toSeconds(1);
-    private final Object mLock = new Object();
-
-    /* message  to handle scan responses from modem */
-    private static final int MSG_SCAN_RESULTS_AVAILABLE = 1;
-    private static final int MSG_SCAN_COMPLETE = 2;
-    private static final int MSG_SCAN_ERROR = 3;
-
-    /* scan object to keep track of current scan request */
-    private NetworkScan mCurrentScan;
-    private boolean mIsScanActive;
-    private NetworkScanRequest mCurrentScanRequest;
-    private List<String> mMccMncs;
-    private TelephonyManager mTelephonyManager;
-    @VisibleForTesting
-    protected NetworkAvailableCallBack mNetworkAvailableCallBack;
-
-    private Handler mHandler =  new Handler() {
-        @Override
-        public void handleMessage(Message msg) {
-            switch (msg.what) {
-                case MSG_SCAN_RESULTS_AVAILABLE:
-                    logDebug("Msg received for scan results");
-                    /* Todo: need to aggregate the results */
-                    analyzeScanResults((List<CellInfo>) msg.obj);
-                    break;
-                case MSG_SCAN_COMPLETE:
-                    logDebug("Msg received for scan complete");
-                    restartScan();
-                    break;
-                case MSG_SCAN_ERROR:
-                    logDebug("Msg received for scan error");
-                    invalidateScanOnError((int) msg.obj);
-                    break;
-                default:
-                    log("invalid message");
-                    break;
-            }
-        }
-    };
-
-    @VisibleForTesting
-    public TelephonyScanManager.NetworkScanCallback mNetworkScanCallback =
-            new TelephonyScanManager.NetworkScanCallback() {
-
-        @Override
-        public void onResults(List<CellInfo> results) {
-            logDebug("Total results :" + results.size());
-            for (CellInfo cellInfo : results) {
-                logDebug("cell info: " + cellInfo);
-            }
-
-            Message message = Message.obtain(mHandler, MSG_SCAN_RESULTS_AVAILABLE, results);
-            message.sendToTarget();
-        }
-
-        @Override
-        public void onComplete() {
-            logDebug("Scan completed!");
-            Message message = Message.obtain(mHandler, MSG_SCAN_COMPLETE, NetworkScan.SUCCESS);
-            message.sendToTarget();
-        }
-
-        @Override
-        public void onError(@NetworkScan.ScanErrorCode int error) {
-            logDebug("Scan error " + error);
-            Message message = Message.obtain(mHandler, MSG_SCAN_ERROR, error);
-            message.sendToTarget();
-        }
-    };
-
-    /**
-     * call back for network availability
-     */
-    public interface NetworkAvailableCallBack {
-
-        /**
-         * Returns the scan results to the user, this callback will be called multiple times.
-         */
-        void onNetworkAvailability(List<CellInfo> results);
-
-        /**
-         * on error
-         * @param error
-         */
-        void onError(int error);
-    }
-
-
-    /**
-     * analyze scan results
-     * @param results contains all available cells matching the scan request at current location.
-     */
-    public void analyzeScanResults(List<CellInfo> results) {
-        /* Inform registrants about availability of network */
-        if (results != null) {
-            List<CellInfo> filteredResults = new ArrayList<CellInfo>();
-            synchronized (mLock) {
-                for (CellInfo cellInfo : results) {
-                    if (mMccMncs.contains(getMccMnc(cellInfo))) {
-                        filteredResults.add(cellInfo);
-                    }
-                }
-            }
-
-            if ((filteredResults.size() >= 1) && (mNetworkAvailableCallBack != null)) {
-                /* Todo: change to aggregate results on success. */
-                mNetworkAvailableCallBack.onNetworkAvailability(filteredResults);
-            }
-        }
-    }
-
-    private void invalidateScanOnError(int error) {
-        logDebug("scan invalidated on error");
-        if (mNetworkAvailableCallBack != null) {
-            mNetworkAvailableCallBack.onError(error);
-        }
-
-        synchronized (mLock) {
-            mIsScanActive = false;
-            mCurrentScan = null;
-        }
-    }
-
-    public ANASNetworkScanCtlr(Context c, TelephonyManager telephonyManager,
-            NetworkAvailableCallBack networkAvailableCallBack) {
-        init(c, telephonyManager, networkAvailableCallBack);
-    }
-
-    /**
-     * initialize Network Scan controller
-     * @param c context
-     * @param telephonyManager Telephony manager instance
-     * @param networkAvailableCallBack callback to be called when network selection is done
-     */
-    public void init(Context c, TelephonyManager telephonyManager,
-            NetworkAvailableCallBack networkAvailableCallBack) {
-        log("init called");
-        mTelephonyManager = telephonyManager;
-        mNetworkAvailableCallBack = networkAvailableCallBack;
-    }
-
-    /* get mcc mnc from cell info if the cell is for LTE */
-    private String getMccMnc(CellInfo cellInfo) {
-        if (cellInfo instanceof CellInfoLte) {
-            return ((CellInfoLte) cellInfo).getCellIdentity().getMccString()
-                    + ((CellInfoLte) cellInfo).getCellIdentity().getMncString();
-        }
-
-        return null;
-    }
-
-    private NetworkScanRequest createNetworkScanRequest(List<SubscriptionInfo> subscriptionInfos,
-            int periodicity) {
-        RadioAccessSpecifier[] ras = new RadioAccessSpecifier[1];
-        int[] bands = new int[1];
-
-        /* hardcoding band for now, Todo b/113753823 */
-        bands[0] = AccessNetworkConstants.EutranBand.BAND_48;
-
-        ArrayList<String> mccMncs = new ArrayList<String>();
-        /* retrieve mcc mncs for a subscription id */
-        for (SubscriptionInfo subscriptionInfo : subscriptionInfos) {
-            mccMncs.add(subscriptionInfo.getMccString() + subscriptionInfo.getMncString());
-        }
-
-        /* create network scan request */
-        ras[0] = new RadioAccessSpecifier(AccessNetworkConstants.AccessNetworkType.EUTRAN, bands,
-                null);
-        NetworkScanRequest networkScanRequest = new NetworkScanRequest(
-                NetworkScanRequest.SCAN_TYPE_PERIODIC, ras, periodicity, MAX_SEARCH_TIME, false,
-                NetworkScanRequest.MAX_INCREMENTAL_PERIODICITY_SEC, mccMncs);
-        synchronized (mLock) {
-            mMccMncs = mccMncs;
-        }
-        return networkScanRequest;
-    }
-
-    /**
-     * start high interval network scan
-     * @param subscriptionInfos list of subscriptions for which the scanning needs to be started.
-     * @return true if successfully accepted request.
-     */
-    public boolean startSlowNetworkScan(List<SubscriptionInfo> subscriptionInfos) {
-        NetworkScanRequest networkScanRequest = createNetworkScanRequest(subscriptionInfos,
-                SEARCH_PERIODICITY_SLOW);
-        return startNetworkScan(networkScanRequest);
-    }
-
-    /**
-     * start less interval network scan
-     * @param subscriptionInfos list of subscriptions for which the scanning needs to be started.
-     * @return true if successfully accepted request.
-     */
-    public boolean startFastNetworkScan(List<SubscriptionInfo> subscriptionInfos) {
-        NetworkScanRequest networkScanRequest = createNetworkScanRequest(subscriptionInfos,
-                SEARCH_PERIODICITY_FAST);
-        return startNetworkScan(networkScanRequest);
-    }
-
-
-    private boolean startNetworkScan(NetworkScanRequest networkScanRequest) {
-        NetworkScan networkScan;
-        synchronized (mLock) {
-            /* if the request is same as existing one, then make sure to not proceed */
-            if (mIsScanActive && mCurrentScanRequest.equals(networkScanRequest)) {
-                return true;
-            }
-
-            /* Need to stop current scan if we already have one */
-            stopNetworkScan();
-
-            /* start new scan */
-            networkScan = mTelephonyManager.requestNetworkScan(networkScanRequest,
-                    mNetworkScanCallback);
-
-            mCurrentScan = networkScan;
-            mIsScanActive = true;
-            mCurrentScanRequest = networkScanRequest;
-        }
-
-        logDebug("startNetworkScan " + networkScanRequest);
-        return true;
-    }
-
-    private void restartScan() {
-        NetworkScan networkScan;
-        synchronized (mLock) {
-            if (mCurrentScanRequest != null) {
-                networkScan = mTelephonyManager.requestNetworkScan(mCurrentScanRequest,
-                        mNetworkScanCallback);
-                mIsScanActive = true;
-            }
-        }
-    }
-
-    /**
-     * stop network scan
-     */
-    public void stopNetworkScan() {
-        logDebug("stopNetworkScan");
-        synchronized (mLock) {
-            if (mIsScanActive && mCurrentScan != null) {
-                try {
-                    mCurrentScan.stopScan();
-                } catch (IllegalArgumentException iae) {
-                    logDebug("Scan failed with exception " + iae);
-                }
-                mIsScanActive = false;
-                mCurrentScan = null;
-                mCurrentScanRequest = null;
-            }
-        }
-    }
-
-    private static void log(String msg) {
-        Rlog.d(LOG_TAG, msg);
-    }
-
-    private static void logDebug(String msg) {
-        if (DBG) {
-            Rlog.d(LOG_TAG, msg);
-        }
-    }
-}
diff --git a/src/com/android/phone/anas/ANASProfileSelector.java b/src/com/android/phone/anas/ANASProfileSelector.java
deleted file mode 100644
index d347cba..0000000
--- a/src/com/android/phone/anas/ANASProfileSelector.java
+++ /dev/null
@@ -1,375 +0,0 @@
-/*
- * Copyright (C) 2018 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.phone.anas;
-
-import android.app.PendingIntent;
-import android.content.BroadcastReceiver;
-import android.content.Context;
-import android.content.Intent;
-import android.content.IntentFilter;
-import android.os.AsyncTask;
-import android.os.Handler;
-import android.os.Message;
-import android.telephony.CellInfo;
-import android.telephony.CellInfoGsm;
-import android.telephony.CellInfoLte;
-import android.telephony.CellInfoWcdma;
-import android.telephony.Rlog;
-import android.telephony.SignalStrength;
-import android.telephony.SubscriptionInfo;
-import android.telephony.SubscriptionManager;
-import android.telephony.TelephonyManager;
-import android.text.TextUtils;
-
-import com.android.internal.annotations.VisibleForTesting;
-
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.List;
-
-/**
- * Profile selector class which will select the right profile based upon
- * geographic information input and network scan results.
- */
-public class ANASProfileSelector {
-    private static final String LOG_TAG = "ANASProfileSelector";
-    private static final boolean DBG = true;
-    private final Object mLock = new Object();
-
-    private static final int INVALID_SEQUENCE_ID = -1;
-    private static final int START_SEQUENCE_ID = 1;
-
-    /* message to indicate profile update */
-    private static final int MSG_PROFILE_UPDATE = 1;
-
-    /* message to indicate start of profile selection process */
-    private static final int MSG_START_PROFILE_SELECTION = 2;
-    private boolean mIsEnabled = false;
-
-    @VisibleForTesting
-    protected Context mContext;
-
-    @VisibleForTesting
-    protected TelephonyManager mTelephonyManager;
-
-    @VisibleForTesting
-    protected ANASNetworkScanCtlr mNetworkScanCtlr;
-
-    private SubscriptionManager mSubscriptionManager;
-    private ANASProfileSelectionCallback mProfileSelectionCallback;
-    private int mSequenceId;
-
-    /* monitor the subscription for registration */
-    private ANASServiceStateMonitor mRegMonitor;
-    public static final String ACTION_SUB_SWITCH =
-            "android.intent.action.SUBSCRIPTION_SWITCH_REPLY";
-
-    /* service monitor callback will get called for service state change on a particular subId. */
-    private ANASServiceStateMonitor.ANASServiceMonitorCallback mServiceMonitorCallback =
-            new ANASServiceStateMonitor.ANASServiceMonitorCallback() {
-                @Override
-                public void onServiceMonitorUpdate(int subId, int state) {
-                    switch (state) {
-                        case ANASServiceStateMonitor.EVALUATED_STATE_BAD:
-                            switchPreferredData(subId);
-                            break;
-                        default:
-                            break;
-                    }
-                }
-            };
-
-    private SubscriptionManager.OnOpportunisticSubscriptionsChangedListener mProfileChangeListener =
-            new SubscriptionManager.OnOpportunisticSubscriptionsChangedListener() {
-                @Override
-                public void onOpportunisticSubscriptionsChanged() {
-                    mHandler.sendEmptyMessage(MSG_PROFILE_UPDATE);
-                }
-            };
-
-    @VisibleForTesting
-    protected Handler mHandler = new Handler() {
-        @Override
-        public void handleMessage(Message msg) {
-            switch (msg.what) {
-                case MSG_PROFILE_UPDATE:
-                case MSG_START_PROFILE_SELECTION:
-                    logDebug("Msg received for profile update");
-                    checkProfileUpdate();
-                    break;
-                default:
-                    log("invalid message");
-                    break;
-            }
-        }
-    };
-
-    /**
-     * Broadcast receiver to receive intents
-     */
-    @VisibleForTesting
-    protected final BroadcastReceiver mProfileSelectorBroadcastReceiver =
-            new BroadcastReceiver() {
-                @Override
-                public void onReceive(Context context, Intent intent) {
-                    int sequenceId;
-                    int subId;
-                    String action = intent.getAction();
-                    if (!mIsEnabled || action == null) {
-                        return;
-                    }
-
-                    switch (action) {
-                        case ACTION_SUB_SWITCH:
-                            sequenceId = intent.getIntExtra("sequenceId",  INVALID_SEQUENCE_ID);
-                            subId = intent.getIntExtra("subId",
-                                    SubscriptionManager.INVALID_SUBSCRIPTION_ID);
-                            if (sequenceId != mSequenceId) {
-                                return;
-                            }
-
-                            onSubSwitchComplete(subId);
-                            break;
-                    }
-                }
-            };
-
-    /**
-     * Network scan callback handler
-     */
-    @VisibleForTesting
-    protected ANASNetworkScanCtlr.NetworkAvailableCallBack mNetworkAvailableCallBack =
-            new ANASNetworkScanCtlr.NetworkAvailableCallBack() {
-                @Override
-                public void onNetworkAvailability(List<CellInfo> results) {
-                    /* sort the results according to signal strength level */
-                    Collections.sort(results, new Comparator<CellInfo>() {
-                        @Override
-                        public int compare(CellInfo cellInfo1, CellInfo cellInfo2) {
-                            return getSignalLevel(cellInfo1) - getSignalLevel(cellInfo2);
-                        }
-                    });
-
-                    /* get subscription id for the best network scan result */
-                    int subId = getSubId(getMcc(results.get(0)), getMnc(results.get(0)));
-                    if (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
-                        /* could not find any matching subscriptions */
-                        return;
-                    }
-
-                    /* if subscription is already active, proceed to data switch */
-                    if (mSubscriptionManager.isActiveSubId(subId)) {
-                        /* if subscription already is data subscription,
-                         complete the profile selection process */
-                        /* Todo: change to getPreferredDataSubscriptionId once ready */
-                        if (mSubscriptionManager.getDefaultDataSubscriptionId() == subId) {
-                            mProfileSelectionCallback.onProfileSelectionDone(subId,
-                                    mSubscriptionManager.getDefaultSubscriptionId());
-                        } else {
-                            switchPreferredData(subId);
-                        }
-                    } else {
-                        switchToSubscription(subId);
-                    }
-                }
-
-                @Override
-                public void onError(int error) {
-                    log("Network scan failed with error " + error);
-                }
-            };
-
-    /**
-     * interface call back to confirm profile selection
-     */
-    public interface ANASProfileSelectionCallback {
-
-        /**
-         * interface call back to confirm profile selection
-         */
-        void onProfileSelectionDone(int dataSubId, int voiceSubId);
-    }
-
-    /**
-     * ANASProfileSelector constructor
-     * @param c context
-     * @param profileSelectionCallback callback to be called once selection is done
-     */
-    public ANASProfileSelector(Context c, ANASProfileSelectionCallback profileSelectionCallback) {
-        init(c, profileSelectionCallback);
-        log("ANASProfileSelector init complete");
-    }
-
-    private int getSignalLevel(CellInfo cellInfo) {
-        if (cellInfo != null) {
-            return cellInfo.getCellSignalStrength().getLevel();
-        } else {
-            return SignalStrength.SIGNAL_STRENGTH_NONE_OR_UNKNOWN;
-        }
-    }
-
-    private String getMcc(CellInfo cellInfo) {
-        String mcc = "";
-        if (cellInfo instanceof CellInfoGsm) {
-            mcc = ((CellInfoGsm) cellInfo).getCellIdentity().getMccString();
-        } else if (cellInfo instanceof CellInfoLte) {
-            mcc = ((CellInfoLte) cellInfo).getCellIdentity().getMccString();
-        } else if (cellInfo instanceof CellInfoWcdma) {
-            mcc = ((CellInfoWcdma) cellInfo).getCellIdentity().getMccString();
-        }
-
-        return mcc;
-    }
-
-    private String getMnc(CellInfo cellInfo) {
-        String mnc = "";
-        if (cellInfo instanceof CellInfoGsm) {
-            mnc = ((CellInfoGsm) cellInfo).getCellIdentity().getMncString();
-        } else if (cellInfo instanceof CellInfoLte) {
-            mnc = ((CellInfoLte) cellInfo).getCellIdentity().getMncString();
-        } else if (cellInfo instanceof CellInfoWcdma) {
-            mnc = ((CellInfoWcdma) cellInfo).getCellIdentity().getMncString();
-        }
-
-        return mnc;
-    }
-
-    private int getSubId(String mcc, String mnc) {
-        List<SubscriptionInfo> subscriptionInfos =
-                mSubscriptionManager.getOpportunisticSubscriptions(1);
-        for (SubscriptionInfo subscriptionInfo : subscriptionInfos) {
-            if (TextUtils.equals(subscriptionInfo.getMccString(), mcc)
-                    && TextUtils.equals(subscriptionInfo.getMncString(), mnc)) {
-                return subscriptionInfo.getSubscriptionId();
-            }
-        }
-
-        return SubscriptionManager.INVALID_SUBSCRIPTION_ID;
-    }
-
-    private void switchToSubscription(int subId) {
-        Intent callbackIntent = new Intent(ACTION_SUB_SWITCH);
-        callbackIntent.setClass(mContext, ANASProfileSelector.class);
-        callbackIntent.putExtra("sequenceId", getAndUpdateToken());
-        callbackIntent.putExtra("subId", subId);
-
-        PendingIntent replyIntent = PendingIntent.getService(mContext,
-                1, callbackIntent,
-                Intent.FILL_IN_ACTION);
-        mSubscriptionManager.switchToSubscription(subId, replyIntent);
-    }
-
-    private void switchPreferredData(int subId) {
-        mSubscriptionManager.setPreferredData(mSubscriptionManager.getSlotIndex(subId));
-        onDataSwitchComplete(subId);
-    }
-
-    private void onSubSwitchComplete(int subId) {
-        mRegMonitor.startListeningForNetworkConditionChange(subId);
-    }
-
-    private void onDataSwitchComplete(int subId) {
-        mProfileSelectionCallback.onProfileSelectionDone(subId,
-                mSubscriptionManager.getDefaultSubscriptionId());
-    }
-
-    private int getAndUpdateToken() {
-        synchronized (mLock) {
-            return mSequenceId++;
-        }
-    }
-
-    private void checkProfileUpdate() {
-        List<SubscriptionInfo> subscriptionInfos =
-                mSubscriptionManager.getOpportunisticSubscriptions(1);
-        if (subscriptionInfos == null) {
-            logDebug("received null subscription infos");
-            return;
-        }
-
-        if (subscriptionInfos.size() > 0) {
-            logDebug("opportunistic subscriptions size " + subscriptionInfos.size());
-
-            /* start scan immediately */
-            mNetworkScanCtlr.startFastNetworkScan(subscriptionInfos);
-        } else if (subscriptionInfos.size() == 0) {
-            /* check if no profile */
-            log("checkProfileUpdate 0 out");
-            mNetworkScanCtlr.stopNetworkScan();
-        }
-    }
-
-    /**
-     * start profile selection procedure
-     */
-    public void startProfileSelection() {
-        synchronized (mLock) {
-            if (!mIsEnabled) {
-                mIsEnabled = true;
-                mHandler.sendEmptyMessage(MSG_START_PROFILE_SELECTION);
-            }
-        }
-    }
-
-    /**
-     * select primary profile for data
-     */
-    public void selectPrimaryProfileForData() {
-        mSubscriptionManager.setPreferredData(mSubscriptionManager.getDefaultSubscriptionId());
-    }
-
-    /**
-     * stop profile selection procedure
-     */
-    public void stopProfileSelection() {
-        mNetworkScanCtlr.stopNetworkScan();
-        synchronized (mLock) {
-            mIsEnabled = false;
-        }
-    }
-
-    protected void init(Context c, ANASProfileSelectionCallback profileSelectionCallback) {
-        mContext = c;
-        mNetworkScanCtlr = new ANASNetworkScanCtlr(mContext, mTelephonyManager,
-                mNetworkAvailableCallBack);
-        mSequenceId = START_SEQUENCE_ID;
-        mProfileSelectionCallback = profileSelectionCallback;
-        mTelephonyManager = (TelephonyManager)
-                mContext.getSystemService(Context.TELEPHONY_SERVICE);
-        mSubscriptionManager = (SubscriptionManager)
-                mContext.getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
-        mRegMonitor = new ANASServiceStateMonitor(mContext, mServiceMonitorCallback);
-
-        /* register for profile update events */
-        mSubscriptionManager.addOnOpportunisticSubscriptionsChangedListener(
-                AsyncTask.SERIAL_EXECUTOR, mProfileChangeListener);
-
-        /* register for subscription switch intent */
-        mContext.registerReceiver(mProfileSelectorBroadcastReceiver,
-                new IntentFilter(ACTION_SUB_SWITCH));
-    }
-
-    private void log(String msg) {
-        Rlog.d(LOG_TAG, msg);
-    }
-
-    private void logDebug(String msg) {
-        if (DBG) {
-            Rlog.d(LOG_TAG, msg);
-        }
-    }
-}
diff --git a/src/com/android/phone/anas/ANASServiceStateEvaluator.java b/src/com/android/phone/anas/ANASServiceStateEvaluator.java
deleted file mode 100644
index 23549a4..0000000
--- a/src/com/android/phone/anas/ANASServiceStateEvaluator.java
+++ /dev/null
@@ -1,245 +0,0 @@
-/*
- * Copyright (C) 2018 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.phone.anas;
-
-import android.app.AlarmManager;
-import android.content.Context;
-import android.os.Handler;
-import android.os.Message;
-import android.telephony.Rlog;
-import android.telephony.SubscriptionManager;
-
-import com.android.internal.annotations.VisibleForTesting;
-
-import java.util.concurrent.TimeUnit;
-
-/**
- * ANASServiceStateEvaluator class which will evaluate the data service state of a subId
- * compared to another.
- */
-public class ANASServiceStateEvaluator {
-    private Context mContext;
-    private final Object mLock = new Object();
-    private int mOppDataSubId;
-    private int mPrimarySubId;
-    /* new opportunistic data service state */
-    private int mOppDataNewState = ANASServiceStateMonitor.EVALUATED_STATE_UNKNOWN;
-    private int mPrimaryNewState = ANASServiceStateMonitor.EVALUATED_STATE_UNKNOWN;
-    private boolean mIsWaitingForTimeout = false;
-
-    @VisibleForTesting
-    protected ANASServiceEvaluatorCallback mServiceEvaluatorCallback;
-
-    @VisibleForTesting
-    protected ANASServiceStateMonitor mOppDataSubMonitor;
-
-    @VisibleForTesting
-    protected ANASServiceStateMonitor mPrimarySubMonitor;
-
-    @VisibleForTesting
-    protected AlarmManager mAlarmManager;
-
-    private static final int WAIT_FOR_DATA_SERVICE_PERIOD = (int) TimeUnit.SECONDS.toMillis(10);
-    private static final String LOG_TAG = "ANASServiceStateEvaluator";
-    private static final boolean DBG = true;
-
-    /* message to indicate no data for WAIT_FOR_DATA_SERVICE_PERIOD */
-    private static final int MSG_WAIT_FOR_DATA_SERVICE_TIMOUT = 1;
-
-    /**
-     * call back to confirm service state evaluation
-     */
-    public interface ANASServiceEvaluatorCallback {
-
-        /**
-         * call back to confirm bad service
-         */
-        void onBadDataService();
-    }
-
-    private Handler mHandler = new Handler() {
-            @Override
-            public void handleMessage(Message msg) {
-                switch (msg.what) {
-                    case MSG_WAIT_FOR_DATA_SERVICE_TIMOUT:
-                        mIsWaitingForTimeout = false;
-                        logDebug("Msg received to get data");
-                        evaluateUpdatedState();
-                        break;
-
-                    default:
-                        log("invalid message");
-                        break;
-                }
-            }
-        };
-
-    public final AlarmManager.OnAlarmListener mDataServiceWaitTimer =
-            (AlarmManager.OnAlarmListener) () -> {
-                logDebug("Alarm fired");
-                mHandler.sendEmptyMessage(MSG_WAIT_FOR_DATA_SERVICE_TIMOUT);
-            };
-
-    /**
-     * set alarm to wait for data service
-     */
-    private void setDataServiceWaitAlarm() {
-        mAlarmManager.set(AlarmManager.RTC, System.currentTimeMillis()
-                + WAIT_FOR_DATA_SERVICE_PERIOD, LOG_TAG, mDataServiceWaitTimer, null);
-    }
-
-    /**
-     * stop the alarm
-     */
-    private void stopDataServiceWaitAlarm() {
-        mAlarmManager.cancel(mDataServiceWaitTimer);
-    }
-
-    private boolean evaluateIfBadOpportunisticDataService() {
-        /* if we have not received update on both subId, we can not take decision, yes */
-        log("evaluateIfBadOpportunisticDataService: mPrimaryNewState: "
-                + ANASServiceStateMonitor.getStateString(mPrimaryNewState) + " mOppDataNewState: "
-                + ANASServiceStateMonitor.getStateString(mOppDataNewState));
-
-        if ((mPrimaryNewState == ANASServiceStateMonitor.EVALUATED_STATE_UNKNOWN)
-                || (mOppDataNewState == ANASServiceStateMonitor.EVALUATED_STATE_UNKNOWN)) {
-            return false;
-        }
-
-        /* Evaluate if primary subscription has good service and if
-           opportunistic data subscription is not, if yes return true.
-         */
-        switch (mPrimaryNewState) {
-            case ANASServiceStateMonitor.EVALUATED_STATE_NO_SERVICE:
-                /* no need to make any change */
-                return false;
-            case ANASServiceStateMonitor.EVALUATED_STATE_BAD:
-                if ((mOppDataNewState == ANASServiceStateMonitor.EVALUATED_STATE_BAD)
-                        || (mOppDataNewState == ANASServiceStateMonitor.EVALUATED_STATE_GOOD)) {
-                    return false;
-                }
-
-                break;
-            case ANASServiceStateMonitor.EVALUATED_STATE_GOOD:
-                if (mOppDataNewState == ANASServiceStateMonitor.EVALUATED_STATE_GOOD) {
-                    return false;
-                }
-                break;
-            default:
-                log("invalid state");
-                break;
-        }
-
-        return true;
-    }
-
-    private void evaluateUpdatedState() {
-        logDebug("evaluateUpdatedState " + mIsWaitingForTimeout);
-        if (!mIsWaitingForTimeout && evaluateIfBadOpportunisticDataService()) {
-            mServiceEvaluatorCallback.onBadDataService();
-        }
-    }
-
-    /* service monitor callback will get called for service state change on a particular subId. */
-    ANASServiceStateMonitor.ANASServiceMonitorCallback mServiceMonitorCallback =
-            new ANASServiceStateMonitor.ANASServiceMonitorCallback() {
-                @Override
-                public void onServiceMonitorUpdate(int subId, int state) {
-                    logDebug("onServiceMonitorUpdate subId: " + subId + " state: "
-                            + ANASServiceStateMonitor.getStateString(state));
-                    synchronized (mLock) {
-                        if (mServiceEvaluatorCallback == null) {
-                            return;
-                        }
-
-                        if (subId == mPrimarySubId) {
-                            mPrimaryNewState = state;
-                        } else if (subId == mOppDataSubId) {
-                            mOppDataNewState = state;
-                        } else {
-                            logDebug("invalid sub id");
-                        }
-
-                        evaluateUpdatedState();
-                    }
-                }
-            };
-
-    public ANASServiceStateEvaluator(Context c,
-            ANASServiceEvaluatorCallback serviceEvaluatorCallback) {
-        init(c, serviceEvaluatorCallback);
-    }
-
-    protected void init(Context c, ANASServiceEvaluatorCallback serviceEvaluatorCallback) {
-        mContext = c;
-        mServiceEvaluatorCallback = serviceEvaluatorCallback;
-        mOppDataSubMonitor = new ANASServiceStateMonitor(mContext, mServiceMonitorCallback);
-        mPrimarySubMonitor = new ANASServiceStateMonitor(mContext, mServiceMonitorCallback);
-        mAlarmManager = (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE);
-    }
-
-    /**
-     * start service state evaluation for dataSubId compared to voiceSubId.
-     * This API evaluates the service state conditions of dataSubId and decides whether
-     * data service is bad compared to voiceSubId
-     * @param dataSubId current data subscription id
-     * @param voiceSubId voice subscription id
-     */
-    public void startEvaluation(int dataSubId, int voiceSubId) {
-        logDebug("Start evaluation");
-        /* make sure to clean up if there is any evaluation going on. */
-        stopEvaluation();
-        setDataServiceWaitAlarm();
-        synchronized (mLock) {
-            mIsWaitingForTimeout = true;
-            mOppDataSubId = dataSubId;
-            mPrimarySubId = voiceSubId;
-            mOppDataSubMonitor.startListeningForNetworkConditionChange(dataSubId);
-            mPrimarySubMonitor.startListeningForNetworkConditionChange(voiceSubId);
-        }
-    }
-
-    /**
-     * stop service state evaluation
-     */
-    public void stopEvaluation() {
-        logDebug("Stop evaluation");
-        synchronized (mLock) {
-            mOppDataSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
-            mPrimarySubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
-            if (mIsWaitingForTimeout) {
-                stopDataServiceWaitAlarm();
-            }
-            mIsWaitingForTimeout = false;
-            mOppDataSubMonitor.stopListeningForNetworkConditionChange();
-            mPrimarySubMonitor.stopListeningForNetworkConditionChange();
-            mOppDataNewState = ANASServiceStateMonitor.EVALUATED_STATE_UNKNOWN;
-            mPrimaryNewState = ANASServiceStateMonitor.EVALUATED_STATE_UNKNOWN;
-        }
-    }
-
-
-    private void log(String msg) {
-        Rlog.d(LOG_TAG, msg);
-    }
-
-    private void logDebug(String msg) {
-        if (DBG) {
-            Rlog.d(LOG_TAG, msg);
-        }
-    }
-}
diff --git a/src/com/android/phone/anas/ANASServiceStateMonitor.java b/src/com/android/phone/anas/ANASServiceStateMonitor.java
deleted file mode 100644
index 90a1564..0000000
--- a/src/com/android/phone/anas/ANASServiceStateMonitor.java
+++ /dev/null
@@ -1,300 +0,0 @@
-/*
- * Copyright (C) 2018 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.phone.anas;
-
-import android.annotation.IntDef;
-import android.content.Context;
-import android.net.ConnectivityManager;
-import android.telephony.PhoneStateListener;
-import android.telephony.Rlog;
-import android.telephony.ServiceState;
-import android.telephony.SignalStrength;
-import android.telephony.TelephonyManager;
-
-import com.android.internal.annotations.VisibleForTesting;
-
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-
-/**
- * ANASServiceStateMonitor class which will monitor service state of a given subscription.
- */
-public class ANASServiceStateMonitor {
-    @VisibleForTesting
-    protected Context mContext;
-
-    @VisibleForTesting
-    protected TelephonyManager mTelephonyManager;
-
-    @VisibleForTesting
-    protected ConnectivityManager mConnectivityManager;
-
-    @Retention(RetentionPolicy.SOURCE)
-    @IntDef(prefix = {"EVALUATED_STATE_"},
-            value = {
-                    EVALUATED_STATE_UNKNOWN,
-                    EVALUATED_STATE_NO_SERVICE,
-                    EVALUATED_STATE_BAD,
-                    EVALUATED_STATE_GOOD})
-    public @interface EvaluatedState {}
-
-    /* service states to be used while reporting onServiceMonitorUpdate */
-    public static final int EVALUATED_STATE_UNKNOWN = 0;
-
-    /* network is not available */
-    public static final int EVALUATED_STATE_NO_SERVICE = 1;
-
-    /* network is available but not good */
-    public static final int EVALUATED_STATE_BAD = 2;
-
-    /* network is available and good */
-    public static final int EVALUATED_STATE_GOOD = 3;
-
-    private static final String LOG_TAG = "ANASServiceStateMonitor";
-    private static final boolean DBG = true;
-    private ANASServiceMonitorCallback mServiceMonitorCallback;
-    private PhoneStateListener mPhoneStateListener;
-    private int mSubId;
-    private @EvaluatedState int mSignalStrengthEvaluatedState;
-    private @EvaluatedState int mServiceStateEvaluatedState;
-    private final Object mLock = new Object();
-
-    protected void init(Context c, ANASServiceMonitorCallback serviceMonitorCallback) {
-        mContext = c;
-        mTelephonyManager = TelephonyManager.from(mContext);
-        mConnectivityManager = (ConnectivityManager) mContext.getSystemService(
-                Context.CONNECTIVITY_SERVICE);
-        mSignalStrengthEvaluatedState = EVALUATED_STATE_UNKNOWN;
-        mServiceStateEvaluatedState = EVALUATED_STATE_UNKNOWN;
-        mServiceMonitorCallback = serviceMonitorCallback;
-        logDebug("[ANASServiceStateMonitor] init by Context");
-    }
-
-    /**
-     * get the string name of a state
-     * @param state service state
-     * @return string name of a state
-     */
-    public static String getStateString(@EvaluatedState int state) {
-        switch (state) {
-            case EVALUATED_STATE_NO_SERVICE:
-                return "No Service";
-            case EVALUATED_STATE_BAD:
-                return "Bad Service";
-            case EVALUATED_STATE_GOOD:
-                return "Good Service";
-            default:
-                return "Unknown";
-        }
-    }
-
-    /**
-     * returns whether the fail reason is permanent
-     * @param failCause fail reason
-     * @return true if reason is permanent
-     */
-    @VisibleForTesting
-    public static boolean isFatalFailCause(String failCause) {
-        if (failCause == null || failCause.isEmpty()) {
-            return false;
-        }
-
-        switch (failCause) {
-            case "OPERATOR_BARRED":
-            case "USER_AUTHENTICATION":
-            case "ACTIVATION_REJECT_GGSN":
-            case "SERVICE_OPTION_NOT_SUPPORTED":
-            case "SERVICE_OPTION_NOT_SUBSCRIBED":
-            case "SERVICE_OPTION_OUT_OF_ORDER":
-            case "PROTOCOL_ERRORS":
-                return true;
-            default:
-                return false;
-        }
-    }
-
-    private void updateCallbackOnFinalState() {
-        int evaluatedState = EVALUATED_STATE_UNKNOWN;
-
-        logDebug("mServiceStateEvaluatedState: " + getStateString(mServiceStateEvaluatedState)
-                + " mSignalStrengthEvaluatedState: "
-                + getStateString(mSignalStrengthEvaluatedState));
-
-        /* Service state has highest priority in this validation. If no service, no need to
-           check further. */
-        if (mServiceStateEvaluatedState == EVALUATED_STATE_GOOD) {
-            evaluatedState = EVALUATED_STATE_GOOD;
-        } else if (mServiceStateEvaluatedState == EVALUATED_STATE_NO_SERVICE) {
-            evaluatedState = EVALUATED_STATE_NO_SERVICE;
-            mServiceMonitorCallback.onServiceMonitorUpdate(mSubId, EVALUATED_STATE_NO_SERVICE);
-            return;
-        }
-
-        /* use signal strength to determine service quality only, i.e is good or bad. */
-        if (evaluatedState == EVALUATED_STATE_GOOD) {
-            if (mSignalStrengthEvaluatedState == EVALUATED_STATE_BAD) {
-                evaluatedState = EVALUATED_STATE_BAD;
-            }
-        }
-
-        if (evaluatedState != EVALUATED_STATE_UNKNOWN) {
-            mServiceMonitorCallback.onServiceMonitorUpdate(mSubId, evaluatedState);
-        }
-    }
-
-    private void analyzeSignalStrengthChange(SignalStrength signalStrength) {
-        if (mServiceMonitorCallback == null) {
-            return;
-        }
-
-        if (signalStrength.getLevel() <= SignalStrength.SIGNAL_STRENGTH_POOR) {
-            mSignalStrengthEvaluatedState = EVALUATED_STATE_BAD;
-        } else {
-            mSignalStrengthEvaluatedState = EVALUATED_STATE_GOOD;
-        }
-
-        updateCallbackOnFinalState();
-    }
-
-    private void analyzeServiceStateChange(ServiceState serviceState) {
-        logDebug("analyzeServiceStateChange state:"
-                + serviceState.getDataRegState());
-        if (mServiceMonitorCallback == null) {
-            return;
-        }
-
-        if ((serviceState.getDataRegState() == ServiceState.STATE_OUT_OF_SERVICE)
-                || (serviceState.getState() == ServiceState.STATE_EMERGENCY_ONLY)) {
-            mServiceStateEvaluatedState = EVALUATED_STATE_NO_SERVICE;
-        } else if (serviceState.getDataRegState() == ServiceState.STATE_IN_SERVICE) {
-            mServiceStateEvaluatedState = EVALUATED_STATE_GOOD;
-        }
-
-        updateCallbackOnFinalState();
-    }
-
-    /**
-     * Implements phone state listener
-     */
-    @VisibleForTesting
-    public class PhoneStateListenerImpl extends PhoneStateListener {
-        PhoneStateListenerImpl(int subId) {
-            super(subId);
-        }
-
-        private boolean shouldIgnore() {
-            if (PhoneStateListenerImpl.this.mSubId != ANASServiceStateMonitor.this.mSubId) {
-                return true;
-            }
-
-            return false;
-        }
-
-        @Override
-        public void onSignalStrengthsChanged(SignalStrength signalStrength) {
-            synchronized (mLock) {
-                if (shouldIgnore()) {
-                    return;
-                }
-
-                analyzeSignalStrengthChange(signalStrength);
-            }
-        }
-
-        @Override
-        public void onServiceStateChanged(ServiceState serviceState) {
-            synchronized (mLock) {
-                if (shouldIgnore()) {
-                    return;
-                }
-
-                analyzeServiceStateChange(serviceState);
-            }
-        }
-    };
-
-    /**
-     * get phone state listener instance
-     * @param subId subscription id
-     * @return the listener instance
-     */
-    @VisibleForTesting
-    public PhoneStateListener getPhoneStateListener(int subId) {
-        synchronized (mLock) {
-            if (mPhoneStateListener != null && subId == mSubId) {
-                return mPhoneStateListener;
-            }
-
-            mTelephonyManager.listen(mPhoneStateListener, PhoneStateListener.LISTEN_NONE);
-            mSubId = subId;
-            mPhoneStateListener = (PhoneStateListener) new PhoneStateListenerImpl(subId);
-        }
-        return mPhoneStateListener;
-    }
-
-    /**
-     * call back interface
-     */
-    public interface ANASServiceMonitorCallback {
-        /**
-         * call back interface
-         */
-        void onServiceMonitorUpdate(int subId, @EvaluatedState int state);
-    }
-
-    /**
-     * request to start listening for network changes.
-     */
-    public void startListeningForNetworkConditionChange(int subId) {
-
-        logDebug("start network condition listen for " + subId);
-        /* monitor service state, signal strength and data connection state */
-        synchronized (mLock) {
-            int events = PhoneStateListener.LISTEN_SERVICE_STATE
-                    | PhoneStateListener.LISTEN_SIGNAL_STRENGTH;
-            mTelephonyManager.listen(getPhoneStateListener(subId), events);
-        }
-    }
-
-    /**
-     * request to stop listening for network changes.
-     */
-    public void stopListeningForNetworkConditionChange() {
-        logDebug("stop network condition listen for " + mSubId);
-        synchronized (mLock) {
-            if (mPhoneStateListener != null) {
-                mTelephonyManager.listen(mPhoneStateListener, PhoneStateListener.LISTEN_NONE);
-            }
-            mSignalStrengthEvaluatedState = EVALUATED_STATE_UNKNOWN;
-            mServiceStateEvaluatedState = EVALUATED_STATE_UNKNOWN;
-        }
-    }
-
-    public ANASServiceStateMonitor(Context c, ANASServiceMonitorCallback serviceMonitorCallback) {
-        init(c, serviceMonitorCallback);
-    }
-
-    private static void log(String msg) {
-        Rlog.d(LOG_TAG, msg);
-    }
-
-    private static void logDebug(String msg) {
-        if (DBG) {
-            Rlog.d(LOG_TAG, msg);
-        }
-    }
-}
diff --git a/src/com/android/phone/anas/AlternativeNetworkAccessService.java b/src/com/android/phone/anas/AlternativeNetworkAccessService.java
deleted file mode 100644
index b972813..0000000
--- a/src/com/android/phone/anas/AlternativeNetworkAccessService.java
+++ /dev/null
@@ -1,224 +0,0 @@
-/*
- * Copyright (C) 2018 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.phone.anas;
-
-import android.content.Context;
-import android.content.SharedPreferences;
-import android.os.Binder;
-import android.os.ServiceManager;
-import android.telephony.Rlog;
-import android.telephony.SubscriptionManager;
-import android.telephony.TelephonyManager;
-import android.util.Log;
-
-import com.android.internal.annotations.VisibleForTesting;
-import com.android.internal.telephony.IAnas;
-import com.android.internal.telephony.TelephonyPermissions;
-
-/**
- * AlternativeNetworkAccessService implements ianas.
- * It scans network and matches the results with opportunistic subscriptions.
- * Use the same to provide user opportunistic data in areas with corresponding networks
- */
-public class AlternativeNetworkAccessService extends IAnas.Stub {
-    private Context mContext;
-    private TelephonyManager mTelephonyManager;
-    private SubscriptionManager mSubsriptionManager;
-
-    private final Object mLock = new Object();
-    private boolean mIsEnabled;
-    private ANASProfileSelector mProfileSelector;
-    private ANASServiceStateEvaluator mServiceStateEvaluator;
-    private SharedPreferences mSharedPref;
-
-    /** The singleton instance. */
-    private static AlternativeNetworkAccessService sInstance = null;
-    private static final String TAG = "ANAS";
-    private static final String PREF_NAME = TAG;
-    private static final String PREF_ENABLED = "isEnabled";
-    private static final boolean DBG = true;
-
-    /**
-     * Profile selection callback. Will be called once Profile selector decides on
-     * the opportunistic data profile.
-     */
-    private ANASProfileSelector.ANASProfileSelectionCallback  mProfileSelectionCallback =
-            new ANASProfileSelector.ANASProfileSelectionCallback() {
-
-                @Override
-                public void onProfileSelectionDone(int dataSubId, int voiceSubId) {
-                    logDebug("profile selection done");
-                    mProfileSelector.stopProfileSelection();
-                    mServiceStateEvaluator.startEvaluation(dataSubId, voiceSubId);
-                }
-            };
-
-    /**
-     * Service state evaluator callback. Will be called once service state evaluator thinks
-     * that current opportunistic data is not providing good service.
-     */
-    private ANASServiceStateEvaluator.ANASServiceEvaluatorCallback mServiceEvaluatorCallback =
-            new ANASServiceStateEvaluator.ANASServiceEvaluatorCallback() {
-                @Override
-                public void onBadDataService() {
-                    logDebug("Bad opportunistic data service");
-                    mServiceStateEvaluator.stopEvaluation();
-                    mProfileSelector.selectPrimaryProfileForData();
-                    mProfileSelector.startProfileSelection();
-                }
-            };
-
-    /**
-     * create AlternativeNetworkAccessService instance
-     *
-     * @param c context
-     *
-     */
-    public static void initInstance(Context c) {
-        if (sInstance == null) {
-            sInstance = new AlternativeNetworkAccessService(c);
-        }
-        return;
-    }
-
-    /**
-     * get AlternativeNetworkAccessService instance
-     *
-     */
-    @VisibleForTesting
-    public static AlternativeNetworkAccessService getInstance() {
-        if (sInstance == null) {
-            Log.wtf(TAG, "getInstance null");
-        }
-        return sInstance;
-    }
-
-    /**
-     * Enable or disable Alternative Network Access service.
-     *
-     * This method should be called to enable or disable
-     * AlternativeNetworkAccess service on the device.
-     *
-     * <p>
-     * Requires Permission:
-     *   {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}
-     * Or the calling app has carrier privileges. @see #hasCarrierPrivileges
-     *
-     * @param enable enable(True) or disable(False)
-     * @param callingPackage caller's package name
-     * @return returns true if successfully set.
-     */
-    @Override
-    public boolean setEnable(boolean enable, String callingPackage) {
-        TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
-                mContext, mSubsriptionManager.getDefaultSubscriptionId(), "setEnable");
-        log("setEnable: " + enable);
-
-        final long identity = Binder.clearCallingIdentity();
-        try {
-            enableAlternativeNetworkAccess(enable);
-        } finally {
-            Binder.restoreCallingIdentity(identity);
-        }
-
-        return true;
-    }
-
-    /**
-     * is Alternative Network Access service enabled
-     *
-     * This method should be called to determine if the Alternative Network Access service
-     * is enabled
-     *
-     * <p>
-     * Requires Permission:
-     *   {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
-     * Or the calling app has carrier privileges. @see #hasCarrierPrivileges
-     *
-     * @param callingPackage caller's package name
-     */
-    @Override
-    public boolean isEnabled(String callingPackage) {
-        TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
-                mContext, mSubsriptionManager.getDefaultSubscriptionId(), "isEnabled");
-        return mIsEnabled;
-    }
-
-    /**
-     * initialize ANAS and register as service.
-     * Read persistent state to update enable state
-     * Start sub components if already enabled.
-     * @param context context instance
-     */
-    private void initializeAndRegisterAsService(Context context) {
-        mContext = context;
-        mTelephonyManager = TelephonyManager.from(mContext);
-        mServiceStateEvaluator = new ANASServiceStateEvaluator(mContext, mServiceEvaluatorCallback);
-        mProfileSelector = new ANASProfileSelector(mContext, mProfileSelectionCallback);
-        mSharedPref = mContext.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
-        mSubsriptionManager = (SubscriptionManager) mContext.getSystemService(
-                Context.TELEPHONY_SUBSCRIPTION_SERVICE);
-
-        /* register the service */
-        if (ServiceManager.getService("ianas") == null) {
-            ServiceManager.addService("ianas", this);
-        }
-
-        enableAlternativeNetworkAccess(getPersistentEnableState());
-    }
-
-    private AlternativeNetworkAccessService(Context c) {
-        initializeAndRegisterAsService(c);
-        log("init completed");
-    }
-
-    private boolean getPersistentEnableState() {
-        return mSharedPref.getBoolean(PREF_ENABLED, true);
-    }
-
-    private void updateEnableState(boolean enable) {
-        mIsEnabled = enable;
-        mSharedPref.edit().putBoolean(PREF_ENABLED, mIsEnabled).apply();
-    }
-
-    /**
-     * update the enable state
-     * start profile selection if enabled.
-     * @param enable enable(true) or disable(false)
-     */
-    private void enableAlternativeNetworkAccess(boolean enable) {
-        synchronized (mLock) {
-            if (mIsEnabled != enable) {
-                updateEnableState(enable);
-                if (mIsEnabled) {
-                    mProfileSelector.startProfileSelection();
-                } else {
-                    mProfileSelector.stopProfileSelection();
-                }
-            }
-        }
-        logDebug("service is enable state " + mIsEnabled);
-    }
-
-    private void log(String msg) {
-        Rlog.d(TAG, msg);
-    }
-
-    private void logDebug(String msg) {
-        if (DBG) Rlog.d(TAG, msg);
-    }
-}