[DO NOT MERGE] Fix Build Breakages Backporting sl4a

-Patch to back-port sl4a from internal to aosp master
 A number of API changes have been made that are not yet
 in AOSP. This is a roll-up patchset of all API back-ports.

Change-Id: If897966e39526423b59c3b19f12991ddb4605f93
diff --git a/Common/src/com/googlecode/android_scripting/facade/media/MediaScannerFacade.java b/Common/src/com/googlecode/android_scripting/facade/media/MediaScannerFacade.java
index fd885c7..671bd2a 100644
--- a/Common/src/com/googlecode/android_scripting/facade/media/MediaScannerFacade.java
+++ b/Common/src/com/googlecode/android_scripting/facade/media/MediaScannerFacade.java
@@ -46,7 +46,7 @@
     public MediaScannerFacade(FacadeManager manager) {
         super(manager);
         mService = manager.getService();
-        mScanService = new MediaScanner(mService, "external");
+        mScanService = new MediaScanner(mService);
         mEventFacade = manager.getReceiver(EventFacade.class);
         mReceiver = new MediaScannerReceiver();
     }
diff --git a/Common/src/com/googlecode/android_scripting/facade/telephony/SubscriptionManagerFacade.java b/Common/src/com/googlecode/android_scripting/facade/telephony/SubscriptionManagerFacade.java
index 0031bc1..84f34b8 100644
--- a/Common/src/com/googlecode/android_scripting/facade/telephony/SubscriptionManagerFacade.java
+++ b/Common/src/com/googlecode/android_scripting/facade/telephony/SubscriptionManagerFacade.java
@@ -46,12 +46,12 @@
 
     @Rpc(description = "Return the default subscription ID")
     public Integer subscriptionGetDefaultSubId() {
-        return SubscriptionManager.getDefaultSubscriptionId();
+        return SubscriptionManager.getDefaultSubId();
     }
 
     @Rpc(description = "Return the default data subscription ID")
     public Integer subscriptionGetDefaultDataSubId() {
-        return SubscriptionManager.getDefaultDataSubscriptionId();
+        return SubscriptionManager.getDefaultDataSubId();
     }
 
     @Rpc(description = "Set the default data subscription ID")
@@ -63,7 +63,7 @@
 
     @Rpc(description = "Return the default voice subscription ID")
     public Integer subscriptionGetDefaultVoiceSubId() {
-        return SubscriptionManager.getDefaultVoiceSubscriptionId();
+        return SubscriptionManager.getDefaultVoiceSubId();
     }
 
     @Rpc(description = "Set the default voice subscription ID")
@@ -75,7 +75,7 @@
 
     @Rpc(description = "Return the default sms subscription ID")
     public Integer subscriptionGetDefaultSmsSubId() {
-        return SubscriptionManager.getDefaultSmsSubscriptionId();
+        return SubscriptionManager.getDefaultSmsSubId();
     }
 
     @Rpc(description = "Set the default sms subscription ID")
diff --git a/Common/src/com/googlecode/android_scripting/facade/telephony/TelecomManagerFacade.java b/Common/src/com/googlecode/android_scripting/facade/telephony/TelecomManagerFacade.java
index caa60ab..40d4038 100644
--- a/Common/src/com/googlecode/android_scripting/facade/telephony/TelecomManagerFacade.java
+++ b/Common/src/com/googlecode/android_scripting/facade/telephony/TelecomManagerFacade.java
@@ -74,23 +74,8 @@
     }
 
     @Rpc(description = "If there's a ringing call, accept on behalf of the user.")
-    public void telecomAcceptRingingCall(
-            @RpcOptional
-            String videoState) {
-
-        if (videoState == null) {
-            mTelecomManager.acceptRingingCall();
-        }
-        else {
-            int state = InCallServiceImpl.getVideoCallState(videoState);
-
-            if (state == InCallServiceImpl.STATE_INVALID) {
-                Log.e("telecomAcceptRingingCall: video state is invalid!");
-                return;
-            }
-
-            mTelecomManager.acceptRingingCall(state);
-        }
+    public void telecomAcceptRingingCall() {
+        mTelecomManager.acceptRingingCall();
     }
 
     @Rpc(description = "Removes the missed-call notification if one is present.")
@@ -221,7 +206,7 @@
             @RpcOptional
             Boolean enabled) {
         toggleCallWaitingForSubscription(
-                SubscriptionManager.getDefaultVoiceSubscriptionId(), enabled);
+                SubscriptionManager.getDefaultVoiceSubId(), enabled);
     }
 
     @Rpc(description = "Toggles call waiting feature on or off for specified subscription id.")
diff --git a/Common/src/com/googlecode/android_scripting/facade/telephony/TelephonyManagerFacade.java b/Common/src/com/googlecode/android_scripting/facade/telephony/TelephonyManagerFacade.java
index 333274a..8af0938 100644
--- a/Common/src/com/googlecode/android_scripting/facade/telephony/TelephonyManagerFacade.java
+++ b/Common/src/com/googlecode/android_scripting/facade/telephony/TelephonyManagerFacade.java
@@ -166,7 +166,7 @@
     public boolean telephonySetPreferredNetworkTypes(
         @RpcParameter(name = "nwPreference") String nwPreference) {
         return telephonySetPreferredNetworkTypesForSubscription(nwPreference,
-                SubscriptionManager.getDefaultSubscriptionId());
+                SubscriptionManager.getDefaultSubId());
     }
 
     @Rpc(description = "Set network preference for subscription.")
@@ -186,7 +186,7 @@
     @Rpc(description = "Get network preference.")
     public String telephonyGetPreferredNetworkTypes() {
         return telephonyGetPreferredNetworkTypesForSubscription(
-                SubscriptionManager.getDefaultSubscriptionId());
+                SubscriptionManager.getDefaultSubId());
     }
 
     @Rpc(description = "Get network preference for subscription.")
@@ -199,7 +199,7 @@
     @Rpc(description = "Get current voice network type")
     public String telephonyGetCurrentVoiceNetworkType() {
         return telephonyGetCurrentVoiceNetworkTypeForSubscription(
-                SubscriptionManager.getDefaultSubscriptionId());
+                SubscriptionManager.getDefaultSubId());
     }
 
     @Rpc(description = "Get current voice network type for subscription")
@@ -212,7 +212,7 @@
     @Rpc(description = "Get current data network type")
     public String telephonyGetCurrentDataNetworkType() {
         return telephonyGetCurrentDataNetworkTypeForSubscription(
-                SubscriptionManager.getDefaultSubscriptionId());
+                SubscriptionManager.getDefaultSubId());
     }
 
     @Rpc(description = "Get current data network type for subscription")
@@ -231,7 +231,7 @@
                        "default subscription ID .Return value is integer.")
     public int telephonyGetPreferredNetworkTypeInteger() {
         return telephonyGetPreferredNetworkTypeIntegerForSubscription(
-                                         SubscriptionManager.getDefaultSubscriptionId());
+                                         SubscriptionManager.getDefaultSubId());
     }
 
     @Rpc(description = "Get preferred network setting for " +
@@ -245,7 +245,7 @@
                        "for default subscription ID.")
     public Boolean telephonyStartTrackingCallState() {
         return telephonyStartTrackingCallStateForSubscription(
-                              SubscriptionManager.getDefaultVoiceSubscriptionId());
+                              SubscriptionManager.getDefaultVoiceSubId());
     }
 
     @Rpc(description = "Starts tracking call state change" +
@@ -267,7 +267,7 @@
                        "for default subscription ID.")
     public Boolean telephonyStartTrackingCellInfoChange() {
         return telephonyStartTrackingCellInfoChangeForSubscription(
-                              SubscriptionManager.getDefaultVoiceSubscriptionId());
+                              SubscriptionManager.getDefaultVoiceSubId());
     }
 
     @Rpc(description = "Starts tracking cell info change" +
@@ -290,7 +290,7 @@
     public Boolean telephonyAdjustPreciseCallStateListenLevel(String type,
                                                           Boolean listen) {
         return telephonyAdjustPreciseCallStateListenLevelForSubscription(type, listen,
-                                 SubscriptionManager.getDefaultVoiceSubscriptionId());
+                                 SubscriptionManager.getDefaultVoiceSubId());
     }
 
     @Rpc(description = "Turn on/off precise listening on fore/background or" +
@@ -317,7 +317,7 @@
             "for default voice subscription ID.")
     public Boolean telephonyStopTrackingCellInfoChange() {
         return telephonyStopTrackingCellInfoChangeForSubscription(
-                SubscriptionManager.getDefaultVoiceSubscriptionId());
+                SubscriptionManager.getDefaultVoiceSubId());
     }
 
     @Rpc(description = "Stops tracking cell info change " +
@@ -338,7 +338,7 @@
             "for default voice subscription ID.")
     public Boolean telephonyStopTrackingCallStateChange() {
         return telephonyStopTrackingCallStateChangeForSubscription(
-                SubscriptionManager.getDefaultVoiceSubscriptionId());
+                SubscriptionManager.getDefaultVoiceSubId());
     }
 
     @Rpc(description = "Stops tracking call state change " +
@@ -360,7 +360,7 @@
                        "for default subscription ID.")
     public Boolean telephonyStartTrackingDataConnectionRTInfoChange() {
         return telephonyStartTrackingDataConnectionRTInfoChangeForSubscription(
-                                 SubscriptionManager.getDefaultDataSubscriptionId());
+                                 SubscriptionManager.getDefaultDataSubId());
     }
 
     @Rpc(description = "Starts tracking data connection real time info change" +
@@ -382,7 +382,7 @@
                        "for default subscription ID.")
     public Boolean telephonyStopTrackingDataConnectionRTInfoChange() {
         return telephonyStopTrackingDataConnectionRTInfoChangeForSubscription(
-                                 SubscriptionManager.getDefaultDataSubscriptionId());
+                                 SubscriptionManager.getDefaultDataSubId());
     }
 
     @Rpc(description = "Stops tracking data connection real time info change" +
@@ -404,7 +404,7 @@
                        "for default subscription ID..")
     public Boolean telephonyStartTrackingDataConnectionStateChange() {
         return telephonyStartTrackingDataConnectionStateChangeForSubscription(
-                                 SubscriptionManager.getDefaultDataSubscriptionId());
+                                 SubscriptionManager.getDefaultDataSubId());
     }
 
     @Rpc(description = "Starts tracking data connection state change" +
@@ -426,7 +426,7 @@
                        "for default subscription ID..")
     public Boolean telephonyStopTrackingDataConnectionStateChange() {
         return telephonyStopTrackingDataConnectionStateChangeForSubscription(
-                                 SubscriptionManager.getDefaultDataSubscriptionId());
+                                 SubscriptionManager.getDefaultDataSubId());
     }
 
     @Rpc(description = "Stops tracking data connection state change " +
@@ -448,7 +448,7 @@
                        "for default subscription ID.")
     public Boolean telephonyStartTrackingServiceStateChange() {
         return telephonyStartTrackingServiceStateChangeForSubscription(
-                                 SubscriptionManager.getDefaultSubscriptionId());
+                                 SubscriptionManager.getDefaultSubId());
     }
 
     @Rpc(description = "Starts tracking service state change " +
@@ -470,7 +470,7 @@
                        "for default subscription ID.")
     public Boolean telephonyStopTrackingServiceStateChange() {
         return telephonyStopTrackingServiceStateChangeForSubscription(
-                                 SubscriptionManager.getDefaultSubscriptionId());
+                                 SubscriptionManager.getDefaultSubId());
     }
 
     @Rpc(description = "Stops tracking service state change " +
@@ -492,7 +492,7 @@
                        "for default subscription ID.")
     public Boolean telephonyStartTrackingSignalStrengthChange() {
         return telephonyStartTrackingSignalStrengthChangeForSubscription(
-                                 SubscriptionManager.getDefaultSubscriptionId());
+                                 SubscriptionManager.getDefaultSubId());
     }
 
     @Rpc(description = "Starts tracking signal strength change " +
@@ -514,7 +514,7 @@
                        "for default subscription ID.")
     public Boolean telephonyStopTrackingSignalStrengthChange() {
         return telephonyStopTrackingSignalStrengthChangeForSubscription(
-                                 SubscriptionManager.getDefaultSubscriptionId());
+                                 SubscriptionManager.getDefaultSubId());
     }
 
     @Rpc(description = "Stops tracking signal strength change " +
@@ -536,7 +536,7 @@
                        "for default subscription ID.")
     public Boolean telephonyStartTrackingVoiceMailStateChange() {
         return telephonyStartTrackingVoiceMailStateChangeForSubscription(
-                                 SubscriptionManager.getDefaultSubscriptionId());
+                                 SubscriptionManager.getDefaultSubId());
     }
 
     @Rpc(description = "Starts tracking voice mail state change " +
@@ -558,7 +558,7 @@
                        "for default subscription ID.")
     public Boolean telephonyStopTrackingVoiceMailStateChange() {
         return telephonyStopTrackingVoiceMailStateChangeForSubscription(
-                                 SubscriptionManager.getDefaultSubscriptionId());
+                                 SubscriptionManager.getDefaultSubId());
     }
 
     @Rpc(description = "Stops tracking voice mail state change " +
@@ -591,21 +591,21 @@
                        "for default subscription ID")
     public String telephonyGetNetworkOperator() {
         return telephonyGetNetworkOperatorForSubscription(
-                        SubscriptionManager.getDefaultSubscriptionId());
+                        SubscriptionManager.getDefaultSubId());
     }
 
     @Rpc(description = "Returns the numeric name (MCC+MNC) of registered operator" +
                        "for specified subscription ID.")
     public String telephonyGetNetworkOperatorForSubscription(
                   @RpcParameter(name = "subId") Integer subId) {
-        return mTelephonyManager.getNetworkOperator(subId);
+        return mTelephonyManager.getNetworkOperatorName(subId);
     }
 
     @Rpc(description = "Returns the alphabetic name of current registered operator" +
                        "for specified subscription ID.")
     public String telephonyGetNetworkOperatorName() {
         return telephonyGetNetworkOperatorNameForSubscription(
-                        SubscriptionManager.getDefaultSubscriptionId());
+                        SubscriptionManager.getDefaultSubId());
     }
 
     @Rpc(description = "Returns the alphabetic name of registered operator " +
@@ -624,7 +624,7 @@
                 " or getDataNetworkTpe()");
 
         return telephonyGetNetworkTypeForSubscription(
-                       SubscriptionManager.getDefaultSubscriptionId());
+                       SubscriptionManager.getDefaultSubId());
     }
 
     @Rpc(description = "Returns the current RAT in use on the device" +
@@ -644,7 +644,7 @@
             " the default voice subscription.")
     public String telephonyGetVoiceNetworkType() {
         return telephonyGetVoiceNetworkTypeForSubscription(
-                         SubscriptionManager.getDefaultVoiceSubscriptionId());
+                         SubscriptionManager.getDefaultVoiceSubId());
     }
 
     @Rpc(description = "Returns the current voice RAT for" +
@@ -659,7 +659,7 @@
             " the defaut data subscription")
     public String telephonyGetDataNetworkType() {
         return telephonyGetDataNetworkTypeForSubscription(
-                         SubscriptionManager.getDefaultDataSubscriptionId());
+                         SubscriptionManager.getDefaultDataSubId());
     }
 
     @Rpc(description = "Returns the current data RAT for" +
@@ -679,7 +679,7 @@
     @Rpc(description = "Returns the MCC for default subscription ID")
     public String telephonyGetSimCountryIso() {
          return telephonyGetSimCountryIsoForSubscription(
-                      SubscriptionManager.getDefaultSubscriptionId());
+                      SubscriptionManager.getDefaultSubId());
     }
 
     @Rpc(description = "Get the latest power consumption stats from the modem")
@@ -697,7 +697,7 @@
     @Rpc(description = "Returns the MCC+MNC for default subscription ID")
     public String telephonyGetSimOperator() {
         return telephonyGetSimOperatorForSubscription(
-                  SubscriptionManager.getDefaultSubscriptionId());
+                  SubscriptionManager.getDefaultSubId());
     }
 
     @Rpc(description = "Returns the MCC+MNC for specified subscription ID")
@@ -710,21 +710,21 @@
                        "for default subscription ID")
     public String telephonyGetSimOperatorName() {
         return telephonyGetSimOperatorNameForSubscription(
-                  SubscriptionManager.getDefaultSubscriptionId());
+                  SubscriptionManager.getDefaultSubId());
     }
 
     @Rpc(description = "Returns the Service Provider Name (SPN)" +
                        " for specified subscription ID.")
     public String telephonyGetSimOperatorNameForSubscription(
                   @RpcParameter(name = "subId") Integer subId) {
-        return mTelephonyManager.getSimOperatorName(subId);
+        return mTelephonyManager.getSimOperator(subId);
     }
 
     @Rpc(description = "Returns the serial number of the SIM for " +
                        "default subscription ID, or Null if unavailable")
     public String telephonyGetSimSerialNumber() {
         return telephonyGetSimSerialNumberForSubscription(
-                  SubscriptionManager.getDefaultSubscriptionId());
+                  SubscriptionManager.getDefaultSubId());
     }
 
     @Rpc(description = "Returns the serial number of the SIM for " +
@@ -753,7 +753,7 @@
         @RpcParameter(name = "appType") Integer appType,
             @RpcParameter(name = "hexChallenge") String hexChallenge) {
         return telephonyGetIccSimChallengeResponseForSubscription(
-                SubscriptionManager.getDefaultSubscriptionId(), appType, hexChallenge);
+                SubscriptionManager.getDefaultSubId(), appType, hexChallenge);
     }
 
     @Rpc(description = "Get Authentication Challenge Response from a " +
@@ -778,7 +778,7 @@
             "for default subscription ID, or null if unavailable")
     public String telephonyGetSubscriberId() {
         return telephonyGetSubscriberIdForSubscription(
-                SubscriptionManager.getDefaultSubscriptionId());
+                SubscriptionManager.getDefaultSubId());
     }
 
     @Rpc(description = "Returns the unique subscriber ID (such as IMSI) " +
@@ -792,7 +792,7 @@
                        " voice mail number for default subscription ID.")
     public String telephonyGetVoiceMailAlphaTag() {
         return telephonyGetVoiceMailAlphaTagForSubscription(
-                   SubscriptionManager.getDefaultSubscriptionId());
+                   SubscriptionManager.getDefaultSubId());
     }
 
 
@@ -807,7 +807,7 @@
                        "for default subscription ID; null if unavailable.")
     public String telephonyGetVoiceMailNumber() {
         return telephonyGetVoiceMailNumberForSubscription(
-                   SubscriptionManager.getDefaultSubscriptionId());
+                   SubscriptionManager.getDefaultSubId());
     }
 
     @Rpc(description = "Returns the voice mail number " +
@@ -832,7 +832,7 @@
                        "for default subscription ID")
     public Boolean telephonyCheckNetworkRoaming() {
         return telephonyCheckNetworkRoamingForSubscription(
-                             SubscriptionManager.getDefaultSubscriptionId());
+                             SubscriptionManager.getDefaultSubId());
     }
 
     @Rpc(description = "Returns true if the device is in roaming state " +
@@ -872,7 +872,7 @@
                        "for specified subscription ID; null if unavailable")
     public String telephonyGetLine1NumberForSubscription(
                   @RpcParameter(name = "subId") Integer subId) {
-        return mTelephonyManager.getLine1Number(subId);
+        return mTelephonyManager.getLine1NumberForSubscriber(subId);
     }
 
     @Rpc(description = "Returns the Alpha Tag for the default subscription " +
@@ -885,7 +885,7 @@
                        "ID; null if unavailable")
     public String telephonyGetLine1AlphaTagForSubscription(
                   @RpcParameter(name = "subId") Integer subId) {
-        return mTelephonyManager.getLine1AlphaTag(subId);
+        return mTelephonyManager.getLine1AlphaTagForSubscriber(subId);
     }
 
     @Rpc(description = "Set the Line1-number (phone number) and Alpha Tag" +
@@ -904,7 +904,7 @@
                 @RpcParameter(name = "number") String number,
                 @RpcOptional
                 @RpcParameter(name = "alphaTag") String alphaTag) {
-        return mTelephonyManager.setLine1NumberForDisplay(subId, alphaTag, number);
+        return mTelephonyManager.setLine1NumberForDisplayForSubscriber(subId, alphaTag, number);
     }
 
     @Rpc(description = "Returns the neighboring cell information of the device.")
@@ -930,7 +930,7 @@
                        "default data subscription ID.")
     public Boolean telephonyIsDataEnabled() {
         return telephonyIsDataEnabledForSubscription(
-                   SubscriptionManager.getDefaultDataSubscriptionId());
+                   SubscriptionManager.getDefaultDataSubId());
     }
 
     @Rpc(description = "Returns True if data connection is enabled.")
@@ -945,7 +945,7 @@
                 @RpcParameter(name = "enabled")
                 @RpcOptional Boolean enabled) {
         telephonyToggleDataConnectionForSubscription(
-                         SubscriptionManager.getDefaultDataSubscriptionId(), enabled);
+                         SubscriptionManager.getDefaultDataSubId(), enabled);
     }
 
     @Rpc(description = "Toggles data connection on/off for" +
@@ -1116,7 +1116,7 @@
     public String telephonyGetServiceState() {
         //TODO: b/26273807 need to have framework API to get service state.
         return telephonyGetServiceStateForSubscription(
-                                 SubscriptionManager.getDefaultSubscriptionId());
+                                 SubscriptionManager.getDefaultSubId());
     }
 
     @Rpc(description = "Returns the service state for specified subscription ID")
@@ -1129,7 +1129,7 @@
     @Rpc(description = "Returns the call state for default subscription ID")
     public String telephonyGetCallState() {
         return telephonyGetCallStateForSubscription(
-                               SubscriptionManager.getDefaultSubscriptionId());
+                               SubscriptionManager.getDefaultSubId());
     }
 
     @Rpc(description = "Returns the call state for specified subscription ID")
@@ -1142,7 +1142,7 @@
     @Rpc(description = "Returns current signal strength for default subscription ID.")
     public SignalStrength telephonyGetSignalStrength() {
         return telephonyGetSignalStrengthForSubscription(
-                               SubscriptionManager.getDefaultSubscriptionId());
+                               SubscriptionManager.getDefaultSubId());
     }
 
     @Rpc(description = "Returns current signal strength for specified subscription ID.")
diff --git a/Common/src/com/googlecode/android_scripting/facade/telephony/TelephonyStateListeners.java b/Common/src/com/googlecode/android_scripting/facade/telephony/TelephonyStateListeners.java
index cb9db74..80ee19f 100644
--- a/Common/src/com/googlecode/android_scripting/facade/telephony/TelephonyStateListeners.java
+++ b/Common/src/com/googlecode/android_scripting/facade/telephony/TelephonyStateListeners.java
@@ -50,7 +50,7 @@
         public CallStateChangeListener(EventFacade ef) {
             super();
             mEventFacade = ef;
-            subscriptionId = SubscriptionManager.getDefaultVoiceSubscriptionId();
+            subscriptionId = SubscriptionManager.getDefaultVoiceSubId();
         }
 
         public CallStateChangeListener(EventFacade ef, int subId) {
@@ -109,7 +109,7 @@
         public DataConnectionRealTimeInfoChangeListener(EventFacade ef) {
             super();
             mEventFacade = ef;
-            subscriptionId = SubscriptionManager.getDefaultDataSubscriptionId();
+            subscriptionId = SubscriptionManager.getDefaultDataSubId();
         }
 
         public DataConnectionRealTimeInfoChangeListener(EventFacade ef, int subId) {
@@ -140,7 +140,7 @@
             super();
             mEventFacade = ef;
             mTelephonyManager = tm;
-            subscriptionId = SubscriptionManager.getDefaultDataSubscriptionId();
+            subscriptionId = SubscriptionManager.getDefaultDataSubId();
         }
 
         public DataConnectionStateChangeListener(EventFacade ef, TelephonyManager tm, int subId) {
@@ -170,7 +170,7 @@
         public ServiceStateChangeListener(EventFacade ef) {
             super();
             mEventFacade = ef;
-            subscriptionId = SubscriptionManager.getDefaultDataSubscriptionId();
+            subscriptionId = SubscriptionManager.getDefaultDataSubId();
         }
 
         public ServiceStateChangeListener(EventFacade ef, int subId) {
diff --git a/Common/src/com/googlecode/android_scripting/facade/wifi/WifiNanManagerFacade.java b/Common/src/com/googlecode/android_scripting/facade/wifi/WifiNanManagerFacade.java
deleted file mode 100644
index 5863e8d..0000000
--- a/Common/src/com/googlecode/android_scripting/facade/wifi/WifiNanManagerFacade.java
+++ /dev/null
@@ -1,403 +0,0 @@
-/*
- * Copyright (C) 2016 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.googlecode.android_scripting.facade.wifi;
-
-import android.app.Service;
-import android.content.Context;
-import android.net.ConnectivityManager;
-import android.net.wifi.nan.ConfigRequest;
-import android.net.wifi.nan.PublishData;
-import android.net.wifi.nan.PublishSettings;
-import android.net.wifi.nan.SubscribeData;
-import android.net.wifi.nan.SubscribeSettings;
-import android.net.wifi.nan.TlvBufferUtils;
-import android.net.wifi.nan.WifiNanEventListener;
-import android.net.wifi.nan.WifiNanManager;
-import android.net.wifi.nan.WifiNanSession;
-import android.net.wifi.nan.WifiNanSessionListener;
-import android.os.Bundle;
-import android.os.HandlerThread;
-import android.os.Looper;
-import android.os.RemoteException;
-
-import com.googlecode.android_scripting.facade.EventFacade;
-import com.googlecode.android_scripting.facade.FacadeManager;
-import com.googlecode.android_scripting.jsonrpc.RpcReceiver;
-import com.googlecode.android_scripting.rpc.Rpc;
-import com.googlecode.android_scripting.rpc.RpcParameter;
-
-import org.json.JSONException;
-import org.json.JSONObject;
-
-/**
- * WifiNanManager functions.
- */
-public class WifiNanManagerFacade extends RpcReceiver {
-    private final Service mService;
-    private final EventFacade mEventFacade;
-
-    private WifiNanManager mMgr;
-    private WifiNanSession mSession;
-    private HandlerThread mNanFacadeThread;
-    private ConnectivityManager mConnMgr;
-
-    private static TlvBufferUtils.TlvConstructor getFilterData(JSONObject j) throws JSONException {
-        if (j == null) {
-            return null;
-        }
-
-        TlvBufferUtils.TlvConstructor constructor = new TlvBufferUtils.TlvConstructor(0, 1);
-        constructor.allocate(255);
-
-        if (j.has("int0")) {
-            constructor.putShort(0, (short) j.getInt("int0"));
-        }
-
-        if (j.has("int1")) {
-            constructor.putShort(0, (short) j.getInt("int1"));
-        }
-
-        if (j.has("data0")) {
-            constructor.putString(0, j.getString("data0"));
-        }
-
-        if (j.has("data1")) {
-            constructor.putString(0, j.getString("data1"));
-        }
-
-        return constructor;
-    }
-
-    private static ConfigRequest getConfigRequest(JSONObject j) throws JSONException {
-        if (j == null) {
-            return null;
-        }
-
-        ConfigRequest.Builder builder = new ConfigRequest.Builder();
-
-        if (j.has("Support5gBand")) {
-            builder.setSupport5gBand(j.getBoolean("Support5gBand"));
-        }
-        if (j.has("MasterPreference")) {
-            builder.setMasterPreference(j.getInt("MasterPreference"));
-        }
-        if (j.has("ClusterLow")) {
-            builder.setClusterLow(j.getInt("ClusterLow"));
-        }
-        if (j.has("ClusterHigh")) {
-            builder.setClusterHigh(j.getInt("ClusterHigh"));
-        }
-
-        return builder.build();
-    }
-
-    private static PublishData getPublishData(JSONObject j) throws JSONException {
-        if (j == null) {
-            return null;
-        }
-
-        PublishData.Builder builder = new PublishData.Builder();
-
-        if (j.has("ServiceName")) {
-            builder.setServiceName(j.getString("ServiceName"));
-        }
-
-        if (j.has("ServiceSpecificInfo")) {
-            String ssi = j.getString("ServiceSpecificInfo");
-            builder.setServiceSpecificInfo(ssi.getBytes(), ssi.length());
-        }
-
-        if (j.has("TxFilter")) {
-            TlvBufferUtils.TlvConstructor constructor = getFilterData(j.getJSONObject("TxFilter"));
-            builder.setTxFilter(constructor.getArray(), constructor.getActualLength());
-        }
-
-        if (j.has("RxFilter")) {
-            TlvBufferUtils.TlvConstructor constructor = getFilterData(j.getJSONObject("RxFilter"));
-            builder.setRxFilter(constructor.getArray(), constructor.getActualLength());
-        }
-
-        return builder.build();
-    }
-
-    private static PublishSettings getPublishSettings(JSONObject j) throws JSONException {
-        if (j == null) {
-            return null;
-        }
-
-        PublishSettings.Builder builder = new PublishSettings.Builder();
-
-        if (j.has("PublishType")) {
-            builder.setPublishType(j.getInt("PublishType"));
-        }
-        if (j.has("PublishCount")) {
-            builder.setPublishCount(j.getInt("PublishCount"));
-        }
-        if (j.has("TtlSec")) {
-            builder.setTtlSec(j.getInt("TtlSec"));
-        }
-
-        return builder.build();
-    }
-
-    private static SubscribeData getSubscribeData(JSONObject j) throws JSONException {
-        if (j == null) {
-            return null;
-        }
-
-        SubscribeData.Builder builder = new SubscribeData.Builder();
-
-        if (j.has("ServiceName")) {
-            builder.setServiceName(j.getString("ServiceName"));
-        }
-
-        if (j.has("ServiceSpecificInfo")) {
-            String ssi = j.getString("ServiceSpecificInfo");
-            builder.setServiceSpecificInfo(ssi);
-        }
-
-        if (j.has("TxFilter")) {
-            TlvBufferUtils.TlvConstructor constructor = getFilterData(j.getJSONObject("TxFilter"));
-            builder.setTxFilter(constructor.getArray(), constructor.getActualLength());
-        }
-
-        if (j.has("RxFilter")) {
-            TlvBufferUtils.TlvConstructor constructor = getFilterData(j.getJSONObject("RxFilter"));
-            builder.setRxFilter(constructor.getArray(), constructor.getActualLength());
-        }
-
-        return builder.build();
-    }
-
-    private static SubscribeSettings getSubscribeSettings(JSONObject j) throws JSONException {
-        if (j == null) {
-            return null;
-        }
-
-        SubscribeSettings.Builder builder = new SubscribeSettings.Builder();
-
-        if (j.has("SubscribeType")) {
-            builder.setSubscribeType(j.getInt("SubscribeType"));
-        }
-        if (j.has("SubscribeCount")) {
-            builder.setSubscribeCount(j.getInt("SubscribeCount"));
-        }
-        if (j.has("TtlSec")) {
-            builder.setTtlSec(j.getInt("TtlSec"));
-        }
-
-        return builder.build();
-    }
-
-    public WifiNanManagerFacade(FacadeManager manager) {
-        super(manager);
-        mService = manager.getService();
-
-        mNanFacadeThread = new HandlerThread("nanFacadeThread");
-        mNanFacadeThread.start();
-
-        mMgr = (WifiNanManager) mService.getSystemService(Context.WIFI_NAN_SERVICE);
-        mMgr.connect(new NanEventListenerPostsEvents(mNanFacadeThread.getLooper()),
-                WifiNanEventListener.LISTEN_CONFIG_COMPLETED
-                        | WifiNanEventListener.LISTEN_CONFIG_FAILED
-                        | WifiNanEventListener.LISTEN_NAN_DOWN
-                        | WifiNanEventListener.LISTEN_IDENTITY_CHANGED);
-
-        mConnMgr = (ConnectivityManager) mService.getSystemService(Context.CONNECTIVITY_SERVICE);
-
-        mEventFacade = manager.getReceiver(EventFacade.class);
-    }
-
-    @Override
-    public void shutdown() {
-    }
-
-    @Rpc(description = "Start NAN.")
-    public void wifiNanEnable(@RpcParameter(name = "nanConfig") JSONObject nanConfig)
-            throws RemoteException, JSONException {
-        mMgr.requestConfig(getConfigRequest(nanConfig));
-    }
-
-    @Rpc(description = "Stop NAN.")
-    public void wifiNanDisable() throws RemoteException, JSONException {
-        mMgr.disconnect();
-    }
-
-    @Rpc(description = "Publish.")
-    public void wifiNanPublish(@RpcParameter(name = "publishData") JSONObject publishData,
-            @RpcParameter(name = "publishSettings") JSONObject publishSettings,
-            @RpcParameter(name = "listenerId") Integer listenerId)
-                    throws RemoteException, JSONException {
-        mSession = mMgr.publish(getPublishData(publishData), getPublishSettings(publishSettings),
-                new NanSessionListenerPostsEvents(mNanFacadeThread.getLooper(), listenerId),
-                WifiNanSessionListener.LISTEN_PUBLISH_FAIL
-                        | WifiNanSessionListener.LISTEN_PUBLISH_TERMINATED
-                        | WifiNanSessionListener.LISTEN_SUBSCRIBE_FAIL
-                        | WifiNanSessionListener.LISTEN_SUBSCRIBE_TERMINATED
-                        | WifiNanSessionListener.LISTEN_MATCH
-                        | WifiNanSessionListener.LISTEN_MESSAGE_SEND_SUCCESS
-                        | WifiNanSessionListener.LISTEN_MESSAGE_SEND_FAIL
-                        | WifiNanSessionListener.LISTEN_MESSAGE_RECEIVED);
-    }
-
-    @Rpc(description = "Subscribe.")
-    public void wifiNanSubscribe(@RpcParameter(name = "subscribeData") JSONObject subscribeData,
-            @RpcParameter(name = "subscribeSettings") JSONObject subscribeSettings,
-            @RpcParameter(name = "listenerId") Integer listenerId)
-                    throws RemoteException, JSONException {
-
-        mSession = mMgr.subscribe(getSubscribeData(subscribeData),
-                getSubscribeSettings(subscribeSettings),
-                new NanSessionListenerPostsEvents(mNanFacadeThread.getLooper(), listenerId),
-                WifiNanSessionListener.LISTEN_PUBLISH_FAIL
-                        | WifiNanSessionListener.LISTEN_PUBLISH_TERMINATED
-                        | WifiNanSessionListener.LISTEN_SUBSCRIBE_FAIL
-                        | WifiNanSessionListener.LISTEN_SUBSCRIBE_TERMINATED
-                        | WifiNanSessionListener.LISTEN_MATCH
-                        | WifiNanSessionListener.LISTEN_MESSAGE_SEND_SUCCESS
-                        | WifiNanSessionListener.LISTEN_MESSAGE_SEND_FAIL
-                        | WifiNanSessionListener.LISTEN_MESSAGE_RECEIVED);
-    }
-
-    @Rpc(description = "Send peer-to-peer NAN message")
-    public void wifiNanSendMessage(
-            @RpcParameter(name = "peerId", description = "The ID of the peer being communicated "
-                    + "with. Obtained from a previous message or match session.") Integer peerId,
-            @RpcParameter(name = "message") String message,
-            @RpcParameter(name = "messageId", description = "Arbitrary handle used for "
-                    + "identification of the message in the message status callbacks")
-            Integer messageId)
-                    throws RemoteException {
-        mSession.sendMessage(peerId, message.getBytes(), message.length(), messageId);
-    }
-
-    private class NanEventListenerPostsEvents extends WifiNanEventListener {
-        public NanEventListenerPostsEvents(Looper looper) {
-            super(looper);
-        }
-
-        @Override
-        public void onConfigCompleted(ConfigRequest configRequest) {
-            Bundle mResults = new Bundle();
-            mResults.putParcelable("configRequest", configRequest);
-            mEventFacade.postEvent("WifiNanOnConfigCompleted", mResults);
-        }
-
-        @Override
-        public void onConfigFailed(ConfigRequest failedConfig, int reason) {
-            Bundle mResults = new Bundle();
-            mResults.putParcelable("failedConfig", failedConfig);
-            mResults.putInt("reason", reason);
-            mEventFacade.postEvent("WifiNanOnConfigFailed", mResults);
-        }
-
-        @Override
-        public void onNanDown(int reason) {
-            Bundle mResults = new Bundle();
-            mResults.putInt("reason", reason);
-            mEventFacade.postEvent("WifiNanOnNanDown", mResults);
-        }
-
-        @Override
-        public void onIdentityChanged() {
-            Bundle mResults = new Bundle();
-            mEventFacade.postEvent("WifiNanOnIdentityChanged", mResults);
-        }
-    }
-
-    private class NanSessionListenerPostsEvents extends WifiNanSessionListener {
-        private int mListenerId;
-
-        public NanSessionListenerPostsEvents(Looper looper, int listenerId) {
-            super(looper);
-            mListenerId = listenerId;
-        }
-
-        @Override
-        public void onPublishFail(int reason) {
-            Bundle mResults = new Bundle();
-            mResults.putInt("listenerId", mListenerId);
-            mResults.putInt("reason", reason);
-            mEventFacade.postEvent("WifiNanSessionOnPublishFail", mResults);
-        }
-
-        @Override
-        public void onPublishTerminated(int reason) {
-            Bundle mResults = new Bundle();
-            mResults.putInt("listenerId", mListenerId);
-            mResults.putInt("reason", reason);
-            mEventFacade.postEvent("WifiNanSessionOnPublishTerminated", mResults);
-        }
-
-        @Override
-        public void onSubscribeFail(int reason) {
-            Bundle mResults = new Bundle();
-            mResults.putInt("listenerId", mListenerId);
-            mResults.putInt("reason", reason);
-            mEventFacade.postEvent("WifiNanSessionOnSubscribeFail", mResults);
-        }
-
-        @Override
-        public void onSubscribeTerminated(int reason) {
-            Bundle mResults = new Bundle();
-            mResults.putInt("listenerId", mListenerId);
-            mResults.putInt("reason", reason);
-            mEventFacade.postEvent("WifiNanSessionOnSubscribeTerminated", mResults);
-        }
-
-        @Override
-        public void onMatch(int peerId, byte[] serviceSpecificInfo,
-                int serviceSpecificInfoLength, byte[] matchFilter, int matchFilterLength) {
-            Bundle mResults = new Bundle();
-            mResults.putInt("listenerId", mListenerId);
-            mResults.putInt("peerId", peerId);
-            mResults.putInt("serviceSpecificInfoLength", serviceSpecificInfoLength);
-            mResults.putByteArray("serviceSpecificInfo", serviceSpecificInfo); // TODO: base64
-            mResults.putInt("matchFilterLength", matchFilterLength);
-            mResults.putByteArray("matchFilter", matchFilter); // TODO: base64
-            mEventFacade.postEvent("WifiNanSessionOnMatch", mResults);
-        }
-
-        @Override
-        public void onMessageSendSuccess(int messageId) {
-            Bundle mResults = new Bundle();
-            mResults.putInt("listenerId", mListenerId);
-            mResults.putInt("messageId", messageId);
-            mEventFacade.postEvent("WifiNanSessionOnMessageSendSuccess", mResults);
-        }
-
-        @Override
-        public void onMessageSendFail(int messageId, int reason) {
-            Bundle mResults = new Bundle();
-            mResults.putInt("listenerId", mListenerId);
-            mResults.putInt("messageId", messageId);
-            mResults.putInt("reason", reason);
-            mEventFacade.postEvent("WifiNanSessionOnMessageSendFail", mResults);
-        }
-
-        @Override
-        public void onMessageReceived(int peerId, byte[] message, int messageLength) {
-            Bundle mResults = new Bundle();
-            mResults.putInt("listenerId", mListenerId);
-            mResults.putInt("peerId", peerId);
-            mResults.putInt("messageLength", messageLength);
-            mResults.putByteArray("message", message); // TODO: base64
-            mResults.putString("messageAsString", new String(message, 0, messageLength));
-            mEventFacade.postEvent("WifiNanSessionOnMessageReceived", mResults);
-        }
-    }
-}
diff --git a/Common/src/com/googlecode/android_scripting/facade/wifi/WifiScannerFacade.java b/Common/src/com/googlecode/android_scripting/facade/wifi/WifiScannerFacade.java
index f718b90..96f7edc 100644
--- a/Common/src/com/googlecode/android_scripting/facade/wifi/WifiScannerFacade.java
+++ b/Common/src/com/googlecode/android_scripting/facade/wifi/WifiScannerFacade.java
@@ -351,14 +351,6 @@
         if (j.has("maxScansToCache")) {
             result.maxScansToCache = j.getInt("maxScansToCache");
         }
-        /* periodInMs and reportEvents are required */
-        result.periodInMs = j.getInt("periodInMs");
-        if (j.has("maxPeriodInMs")) {
-            result.maxPeriodInMs = j.getInt("maxPeriodInMs");
-        }
-        if (j.has("stepCount")) {
-            result.stepCount = j.getInt("stepCount");
-        }
         result.reportEvents = j.getInt("reportEvents");
         if (j.has("numBssidsPerScan")) {
             result.numBssidsPerScan = j.getInt("numBssidsPerScan");
diff --git a/ScriptingLayer/src/com/googlecode/android_scripting/facade/FacadeConfiguration.java b/ScriptingLayer/src/com/googlecode/android_scripting/facade/FacadeConfiguration.java
index b297580..a90441e 100644
--- a/ScriptingLayer/src/com/googlecode/android_scripting/facade/FacadeConfiguration.java
+++ b/ScriptingLayer/src/com/googlecode/android_scripting/facade/FacadeConfiguration.java
@@ -55,7 +55,6 @@
 import com.googlecode.android_scripting.facade.ui.UiFacade;
 import com.googlecode.android_scripting.facade.wifi.HttpFacade;
 import com.googlecode.android_scripting.facade.wifi.WifiManagerFacade;
-import com.googlecode.android_scripting.facade.wifi.WifiNanManagerFacade;
 import com.googlecode.android_scripting.facade.wifi.WifiP2pManagerFacade;
 import com.googlecode.android_scripting.facade.wifi.WifiRttManagerFacade;
 import com.googlecode.android_scripting.facade.wifi.WifiScannerFacade;
@@ -134,7 +133,6 @@
         /*Compatibility reset to >= Marshmallow */
         if( sSdkLevel >= 23 ) {
             //add new facades here
-            sFacadeClassList.add(WifiNanManagerFacade.class);
         }
 
         for (Class<? extends RpcReceiver> recieverClass : sFacadeClassList) {