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

Commit a9ff5a97 authored by Alexander Ivanov's avatar Alexander Ivanov Committed by Steve Kondik
Browse files

server: start cne service

Connectivity Engine (CnE) provides advanced network selection per socket,
reduced signalling traffic, and increased power savings.
The service implements the interface defined by CNEManager which Android
applications may use.

Change-Id: I9ffd1f5d60f5e9e185ab482a35b3b07f29a4124c
(cherry picked from commit 3a4e3ba1bc67c460ec3c2fd4ef169ae25e3e69b1)
(cherry picked from commit 1bb0036652318ac8bbecf3e6c810bbc779387c61)
(cherry picked from commit 3c8af4a2546d9b71d113072d680107cb56651e71)
(cherry picked from commit 861a4b062196020bf24a5b3731c717b5b95a7d77)
(cherry picked from commit e3dba9799892f13c5bc2376b81cf5dceae17492c)

Add Connectivity Engine (CnE) WQE support

Enhanced connectivity features viz. Wifi Quality Estimation.
Supports dual network mode - wifi & mobile simultaneously.
Use QcConnectivityService when CnE is enabled for all CnE features.

Change-Id: I14b02e21515bfc1b5fd2fc4f28e5190fa80f83f8

server: Initialize ConnectivityService on low memory device

Skip initialization of QcConnectivityService and
use ConnectivityService.java for a low memory device

CRs-Fixed: 531430

Change-Id: I2111ec32f6e40ca79b7fc91ec4cef97ac27f3b3a

Update CNE feature values.

Start QcConnectivityServices for the new
application traffic profiling feature too.

Change-Id: I52ae76420ebd098d43fe0663f41ce622a407b90e

connectivity: allow inheritance to subclass

set modifier to protected in order to allow
subclass to use the same data and avoid redefinition.

Change-Id: I2dc688d3e433775cb073ec6faae3981807212cc9

Change visibility of methods

Change the visibility of some methods so that
they are accessible to the child class.

Change-Id: Ie1a45978b42742cac0aaedba29fb2375882c0ae4
CRs-Fixed: 611347
parent faae0b41
Loading
Loading
Loading
Loading
+29 −25
Original line number Diff line number Diff line
/*
 * Copyright (c) 2012, 2013. The Linux Foundation. All rights reserved.
 * Not a Contribution.
 * Copyright (C) 2008 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
@@ -170,45 +172,45 @@ import javax.net.ssl.SSLSession;
public class ConnectivityService extends IConnectivityManager.Stub {
    private static final String TAG = "ConnectivityService";

    private static final boolean DBG = true;
    private static final boolean VDBG = false;
    protected static final boolean DBG = true;
    protected static final boolean VDBG = false;

    private static final boolean LOGD_RULES = false;
    protected static final boolean LOGD_RULES = false;

    // TODO: create better separation between radio types and network types

    // how long to wait before switching back to a radio's default network
    private static final int RESTORE_DEFAULT_NETWORK_DELAY = 1 * 60 * 1000;
    protected static final int RESTORE_DEFAULT_NETWORK_DELAY = 1 * 60 * 1000;
    // system property that can override the above value
    private static final String NETWORK_RESTORE_DELAY_PROP_NAME =
    protected static final String NETWORK_RESTORE_DELAY_PROP_NAME =
            "android.telephony.apn-restore";

    // Default value if FAIL_FAST_TIME_MS is not set
    private static final int DEFAULT_FAIL_FAST_TIME_MS = 1 * 60 * 1000;
    protected static final int DEFAULT_FAIL_FAST_TIME_MS = 1 * 60 * 1000;
    // system property that can override DEFAULT_FAIL_FAST_TIME_MS
    private static final String FAIL_FAST_TIME_MS =
    protected static final String FAIL_FAST_TIME_MS =
            "persist.radio.fail_fast_time_ms";

    private static final String ACTION_PKT_CNT_SAMPLE_INTERVAL_ELAPSED =
    protected static final String ACTION_PKT_CNT_SAMPLE_INTERVAL_ELAPSED =
            "android.net.ConnectivityService.action.PKT_CNT_SAMPLE_INTERVAL_ELAPSED";

    private static final int SAMPLE_INTERVAL_ELAPSED_REQUEST_CODE = 0;
    protected static final int SAMPLE_INTERVAL_ELAPSED_REQUEST_CODE = 0;

    private PendingIntent mSampleIntervalElapsedIntent;

    // Set network sampling interval at 12 minutes, this way, even if the timers get
    // aggregated, it will fire at around 15 minutes, which should allow us to
    // aggregate this timer with other timers (specially the socket keep alive timers)
    private static final int DEFAULT_SAMPLING_INTERVAL_IN_SECONDS = (VDBG ? 30 : 12 * 60);
    protected static final int DEFAULT_SAMPLING_INTERVAL_IN_SECONDS = (VDBG ? 30 : 12 * 60);

    // start network sampling a minute after booting ...
    private static final int DEFAULT_START_SAMPLING_INTERVAL_IN_SECONDS = (VDBG ? 30 : 60);
    protected static final int DEFAULT_START_SAMPLING_INTERVAL_IN_SECONDS = (VDBG ? 30 : 60);

    AlarmManager mAlarmManager;

    // used in recursive route setting to add gateways for the host for which
    // a host route was requested.
    private static final int MAX_HOSTROUTE_CYCLE_COUNT = 10;
    protected static final int MAX_HOSTROUTE_CYCLE_COUNT = 10;

    private Tethering mTethering;

@@ -274,17 +276,17 @@ public class ConnectivityService extends IConnectivityManager.Stub {
    private INetworkManagementService mNetd;
    private INetworkPolicyManager mPolicyManager;

    private static final int ENABLED  = 1;
    private static final int DISABLED = 0;
    protected static final int ENABLED  = 1;
    protected static final int DISABLED = 0;

    private static final boolean ADD = true;
    private static final boolean REMOVE = false;
    protected static final boolean ADD = true;
    protected static final boolean REMOVE = false;

    private static final boolean TO_DEFAULT_TABLE = true;
    private static final boolean TO_SECONDARY_TABLE = false;
    protected static final boolean TO_DEFAULT_TABLE = true;
    protected static final boolean TO_SECONDARY_TABLE = false;

    private static final boolean EXEMPT = true;
    private static final boolean UNEXEMPT = false;
    protected static final boolean EXEMPT = true;
    protected static final boolean UNEXEMPT = false;

    /**
     * used internally as a delayed event to make us switch back to the
@@ -401,7 +403,7 @@ public class ConnectivityService extends IConnectivityManager.Stub {
    private Collection<LinkAddress> mExemptAddresses = new ArrayList<LinkAddress>();

    // used in DBG mode to track inet condition reports
    private static final int INET_CONDITION_LOG_MAX_SIZE = 15;
    protected static final int INET_CONDITION_LOG_MAX_SIZE = 15;
    private ArrayList mInetLog;

    // track the current default http proxy - tell the world if we get a new one (real change)
@@ -439,6 +441,8 @@ public class ConnectivityService extends IConnectivityManager.Stub {

    TelephonyManager mTelephonyManager;

    protected ConnectivityService() { }

    public ConnectivityService(Context context, INetworkManagementService netd,
            INetworkStatsService statsService, INetworkPolicyManager policyManager) {
        // Currently, omitting a NetworkFactory will create one internally
@@ -2208,7 +2212,7 @@ public class ConnectivityService extends IConnectivityManager.Stub {
        }
    }

    void systemReady() {
    protected void systemReady() {
        mCaptivePortalTracker = CaptivePortalTracker.makeCaptivePortalTracker(mContext, this);
        loadGlobalProxy();

@@ -3545,7 +3549,7 @@ public class ConnectivityService extends IConnectivityManager.Stub {
        Slog.e(TAG, s);
    }

    int convertFeatureToNetworkType(int networkType, String feature) {
    protected int convertFeatureToNetworkType(int networkType, String feature) {
        int usedNetworkType = networkType;

        if(networkType == ConnectivityManager.TYPE_MOBILE) {
@@ -3722,7 +3726,7 @@ public class ConnectivityService extends IConnectivityManager.Stub {
     * be done whenever a better abstraction is developed.
     */
    public class VpnCallback {
        private VpnCallback() {
        protected VpnCallback() {
        }

        public void onStateChanged(NetworkInfo info) {
@@ -4944,7 +4948,7 @@ public class ConnectivityService extends IConnectivityManager.Stub {
        setAlarm(samplingIntervalInSeconds * 1000, mSampleIntervalElapsedIntent);
    }

    void setAlarm(int timeoutInMilliseconds, PendingIntent intent) {
    protected void setAlarm(int timeoutInMilliseconds, PendingIntent intent) {
        long wakeupTime = SystemClock.elapsedRealtime() + timeoutInMilliseconds;
        mAlarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, wakeupTime, intent);
    }
+64 −15
Original line number Diff line number Diff line
/*
 * Copyright (C) 2006 The Android Open Source Project
 * This code has been modified.  Portions copyright (C) 2010, T-Mobile USA, Inc.
 * Copyright (c) 2012, 2013. The Linux Foundation. All rights reserved.
 * Copyright (c) 2012, 2013, 2014. The Linux Foundation. All rights reserved.
 * Not a Contribution.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
@@ -33,9 +33,13 @@ import android.database.ContentObserver;
import android.media.AudioService;
import android.net.wifi.p2p.WifiP2pService;
import android.os.Environment;
import android.net.INetworkPolicyManager;
import android.net.INetworkStatsService;
import android.os.IBinder;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.Looper;
import android.os.INetworkManagementService;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.StrictMode;
@@ -54,6 +58,7 @@ import android.view.WindowManager;
import com.android.internal.R;
import com.android.internal.os.BinderInternal;
import com.android.internal.os.SamplingProfilerIntegration;
import com.android.internal.util.MemInfoReader;
import com.android.server.accessibility.AccessibilityManagerService;
import com.android.server.accounts.AccountManagerService;
import com.android.server.am.ActivityManagerService;
@@ -86,6 +91,9 @@ import java.io.File;
import java.util.Timer;
import java.util.TimerTask;

import dalvik.system.PathClassLoader;
import java.lang.reflect.Constructor;

class ServerThread {
    private static final String TAG = "SystemServer";
    private static final String ENCRYPTING_STATE = "trigger_restart_min_framework";
@@ -186,6 +194,7 @@ class ServerThread {
        NetworkStatsService networkStats = null;
        NetworkPolicyManagerService networkPolicy = null;
        ConnectivityService connectivity = null;
        Object qcCon = null;
        WifiP2pService wifiP2p = null;
        WifiService wifi = null;
        NsdService serviceDiscovery= null;
@@ -573,15 +582,44 @@ class ServerThread {
                }

               try {
                    Slog.i(TAG, "Connectivity Service");
                    connectivity = new ConnectivityService(
                   int enableCne = 1;
                   if (!deviceHasSufficientMemory()) {
                       enableCne = SystemProperties.getInt("persist.cne.override.memlimit", 0);
                   }
                   int cneFeature = (enableCne == 1) ?
                       SystemProperties.getInt("persist.cne.feature", 0) : 0;

                   try {
                       if ( cneFeature > 0 && cneFeature < 10 ) {
                           Slog.i(TAG, "QcConnectivity Service");
                           PathClassLoader qcsClassLoader =
                               new PathClassLoader("/system/framework/services-ext.jar",
                                       ClassLoader.getSystemClassLoader());
                           Class qcsClass =
                               qcsClassLoader.loadClass("com.android.server.QcConnectivityService");
                           Constructor qcsConstructor = qcsClass.getConstructor
                               (new Class[] {Context.class, INetworkManagementService.class,
                                INetworkStatsService.class, INetworkPolicyManager.class});
                           qcCon = qcsConstructor.newInstance(
                                   context, networkManagement, networkStats, networkPolicy);
                           connectivity = (ConnectivityService) qcCon;
                       } else {
                           Slog.i(TAG, "Connectivity Service");
                           connectivity = new ConnectivityService( context, networkManagement,
                                   networkStats, networkPolicy);
                       }
                   } catch (Throwable e) {
                       connectivity = new ConnectivityService( context, networkManagement,
                               networkStats, networkPolicy);
                   }

                   if (connectivity != null) {
                       ServiceManager.addService(Context.CONNECTIVITY_SERVICE, connectivity);
                       networkStats.bindConnectivityManager(connectivity);
                       networkPolicy.bindConnectivityManager(connectivity);

                    wifiP2p.connectivityServiceReady();
                       wifi.checkAndStartWifi();
                       wifiP2p.connectivityServiceReady();
                   }
               } catch (Throwable e) {
                   reportWtf("starting Connectivity Service", e);
               }
@@ -1264,6 +1302,17 @@ class ServerThread {
        //Slog.d(TAG, "Starting service: " + intent);
        context.startServiceAsUser(intent, UserHandle.OWNER);
    }

    private static final boolean deviceHasSufficientMemory() {
        final long MEMORY_SIZE_MIN = 512 * 1024 * 1024;

        MemInfoReader minfo = new MemInfoReader();
        minfo.readMemInfo();
        if (minfo.getTotalSize() <= MEMORY_SIZE_MIN) {
            return false;
        }
        return true;
    }
}

public class SystemServer {