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

Commit 3aaee782 authored by Sunmeet Gill's avatar Sunmeet Gill Committed by Ricardo Cerqueira
Browse files

Data+MMS changes: Implementation for Legacy Api

- Add overloaded fucntion
  startUsingNetworkFeatureForSubscription
  stopUsingNetworkFeatureForSubscription
  This change is to allow the legacy MMS app
  to work for Data+MMS feature request.
  The purpose of this feature is to enable
  simultaneous PS ATTACH and PDP ACTIVE
- Fix duplicate requests. Add a check to
  prevent duplicate networkRequests being
  send to networkFactories

Conflicts:
services/core/java/com/android/server/ConnectivityService.java
Change-Id: I50bd6eea889a105a12d8b8d2beef6646675836fe
parent 81e78b89
Loading
Loading
Loading
Loading
+91 −0
Original line number Diff line number Diff line
@@ -909,7 +909,64 @@ public class ConnectivityManager {
            return PhoneConstants.APN_REQUEST_FAILED;
        }
    }
    /**
     * Tells the underlying networking system that the caller wants to
     * begin using the named feature. The interpretation of {@code feature}
     * is completely up to each networking implementation.
     * <p>This method requires the caller to hold the permission
     * {@link android.Manifest.permission#CHANGE_NETWORK_STATE}.
     * @param networkType specifies which network the request pertains to
     * @param feature the name of the feature to be used
     * @param subId the subscription the network is requested
     * @return an integer value representing the outcome of the request.
     * The interpretation of this value is specific to each networking
     * implementation+feature combination, except that the value {@code -1}
     * always indicates failure.
     *
     * @hide
     */
    public int startUsingNetworkFeatureForSubscription(int networkType, String feature,
                                                       String subId) {
        Log.d(TAG, "startUsingNetworkFeatureForSubscription: for " + networkType
                +" feature = " + feature + " subId = " + subId);
        NetworkCapabilities netCap = networkCapabilitiesForFeature(networkType, feature);
        if (netCap == null) {
            Log.d(TAG, "Can't satisfy startUsingNetworkFeature for " + networkType + ", " +
                    feature);
            return PhoneConstants.APN_REQUEST_FAILED;
        }
        netCap.setNetworkSpecifier(subId);
        NetworkRequest request = null;
        synchronized (sLegacyRequests) {
            if (LEGACY_DBG) {
                Log.d(TAG, "Looking for legacyRequest for netCap with hash: " + netCap + " (" +
                        netCap.hashCode() + ")");
                Log.d(TAG, "sLegacyRequests has:");
                for (NetworkCapabilities nc : sLegacyRequests.keySet()) {
                    Log.d(TAG, "  " + nc + " (" + nc.hashCode() + ")");
                }
            }
            LegacyRequest l = sLegacyRequests.get(netCap);
            if (l != null) {
                Log.d(TAG, "renewing startUsingNetworkFeature request " + l.networkRequest);
                renewRequestLocked(l);
                if (l.currentNetwork != null) {
                    return PhoneConstants.APN_ALREADY_ACTIVE;
                } else {
                    return PhoneConstants.APN_REQUEST_STARTED;
                }
            }

            request = requestNetworkForFeatureLocked(netCap);
        }
        if (request != null) {
            Log.d(TAG, "starting startUsingNetworkFeature for request " + request);
            return PhoneConstants.APN_REQUEST_STARTED;
        } else {
            Log.d(TAG, " request Failed");
            return PhoneConstants.APN_REQUEST_FAILED;
        }
    }
    /**
     * Tells the underlying networking system that the caller is finished
     * using the named feature. The interpretation of {@code feature}
@@ -940,6 +997,40 @@ public class ConnectivityManager {
        }
        return 1;
    }
    /**
     * Tells the underlying networking system that the caller is finished
     * using the named feature. The interpretation of {@code feature}
     * is completely up to each networking implementation.
     * <p>This method requires the caller to hold the permission
     * {@link android.Manifest.permission#CHANGE_NETWORK_STATE}.
     * @param networkType specifies which network the request pertains to
     * @param feature the name of the feature that is no longer needed
     * @param subId the subscription the network is requested
     * @return an integer value representing the outcome of the request.
     * The interpretation of this value is specific to each networking
     * implementation+feature combination, except that the value {@code -1}
     * always indicates failure.
     *
     * @hide
     */
    public int stopUsingNetworkFeatureForSubscription(int networkType, String feature,
                                                      String subId) {
        Log.d(TAG, "stopUsingNetworkFeatureForSubscription: for " + networkType +" feature = "
          + feature + " subId = " + subId);
        NetworkCapabilities netCap = networkCapabilitiesForFeature(networkType, feature);
        if (netCap == null) {
            Log.d(TAG, "Can't satisfy stopUsingNetworkFeature for " + networkType + ", " +
                    feature);
            return -1;
        }
        netCap.setNetworkSpecifier(subId);
        NetworkCallback networkCallback = removeRequestForFeature(netCap);
        if (networkCallback != null) {
            Log.d(TAG, "stopUsingNetworkFeature for " + networkType + ", " + feature);
            unregisterNetworkCallback(networkCallback);
        }
        return 1;
    }

    /**
     * Removes the NET_CAPABILITY_NOT_RESTRICTED capability from the given
+26 −23
Original line number Diff line number Diff line
@@ -2160,20 +2160,23 @@ public class ConnectivityService extends IConnectivityManager.Stub {
                }
            }
        }
        if (mNetworkForRequestId.get(nri.request.requestId)!=null) {
            if (DBG) log("ignoring duplicate request");
        } else {
            if (bestNetwork != null) {
            if (DBG) log("using " + bestNetwork.name());
            if (bestNetwork.networkInfo.isConnected()) {
                if (VDBG) log("using " + bestNetwork.name());
                if (nri.isRequest && bestNetwork.networkInfo.isConnected()) {
                    // Cancel any lingering so the linger timeout doesn't teardown this network
                    // even though we have a request for it.
                    bestNetwork.networkLingered.clear();
                    bestNetwork.networkMonitor.sendMessage(NetworkMonitor.CMD_NETWORK_CONNECTED);
                }
            // TODO: This logic may be better replaced with a call to rematchNetworkAndRequests
                bestNetwork.addRequest(nri.request);
                mNetworkForRequestId.put(nri.request.requestId, bestNetwork);
                notifyNetworkCallback(bestNetwork, nri);
            score = bestNetwork.getCurrentScore();
            if (nri.request.legacyType != TYPE_NONE) {
                score = bestNetwork.currentScore;
                if (nri.isRequest && nri.request.legacyType != TYPE_NONE) {
                    //To support legacy calls for network request
                    mLegacyTypeTracker.add(nri.request.legacyType, bestNetwork);
                }
            }
@@ -2181,12 +2184,12 @@ public class ConnectivityService extends IConnectivityManager.Stub {
            if (nri.isRequest) {
                if (DBG) log("sending new NetworkRequest to factories");
                for (NetworkFactoryInfo nfi : mNetworkFactoryInfos.values()) {
                nfi.asyncChannel.sendMessage(android.net.NetworkFactory.CMD_REQUEST_NETWORK, score,
                        0, nri.request);
                    nfi.asyncChannel.sendMessage(android.net.NetworkFactory.CMD_REQUEST_NETWORK,
                            score, 0, nri.request);
                }
            }
        }
    }

    private void handleReleaseNetworkRequest(NetworkRequest request, int callingUid) {
        NetworkRequestInfo nri = mNetworkRequests.get(request);
        if (nri != null) {