Add user control to turn on/off nsd

Change-Id: Ide3cc20adb21ac6dffaf6b9b9136d77a129afa3b
This commit is contained in:
Irfan Sheriff
2012-04-17 23:15:29 -07:00
parent 81394337bc
commit 7500665eb7
3 changed files with 396 additions and 162 deletions

View File

@@ -26,4 +26,5 @@ import android.os.Messenger;
interface INsdManager
{
Messenger getMessenger();
void setEnabled(boolean enable);
}

View File

@@ -16,6 +16,8 @@
package android.net.nsd;
import android.annotation.SdkConstant;
import android.annotation.SdkConstant.SdkConstantType;
import android.content.Context;
import android.os.Binder;
import android.os.IBinder;
@@ -133,6 +135,44 @@ public class NsdManager {
private static final String TAG = "NsdManager";
INsdManager mService;
/**
* Broadcast intent action to indicate whether network service discovery is
* enabled or disabled. An extra {@link #EXTRA_NSD_STATE} provides the state
* information as int.
*
* @see #EXTRA_NSD_STATE
* @hide
*/
@SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
public static final String NSD_STATE_CHANGED_ACTION =
"android.net.nsd.STATE_CHANGED";
/**
* The lookup key for an int that indicates whether network service discovery is enabled
* or disabled. Retrieve it with {@link android.content.Intent#getIntExtra(String,int)}.
*
* @see #NSD_STATE_DISABLED
* @see #NSD_STATE_ENABLED
* @hide
*/
public static final String EXTRA_NSD_STATE = "nsd_state";
/**
* Network service discovery is disabled
*
* @see #NSD_STATE_CHANGED_ACTION
* @hide
*/
public static final int NSD_STATE_DISABLED = 1;
/**
* Network service discovery is enabled
*
* @see #NSD_STATE_CHANGED_ACTION
* @hide
*/
public static final int NSD_STATE_ENABLED = 2;
private static final int BASE = Protocol.BASE_NSD_MANAGER;
/** @hide */
@@ -188,6 +228,12 @@ public class NsdManager {
/** @hide */
public static final int STOP_RESOLVE_SUCCEEDED = BASE + 23;
/** @hide */
public static final int ENABLE = BASE + 24;
/** @hide */
public static final int DISABLE = BASE + 25;
/**
* Create a new Nsd instance. Applications use
* {@link android.content.Context#getSystemService Context.getSystemService()} to retrieve
@@ -312,8 +358,8 @@ public class NsdManager {
private DnsSdResolveListener mDnsSdResolveListener;
private ActionListener mDnsSdStopResolveListener;
AsyncChannel mAsyncChannel;
ServiceHandler mHandler;
private AsyncChannel mAsyncChannel;
private ServiceHandler mHandler;
class ServiceHandler extends Handler {
ServiceHandler(Looper looper) {
super(looper);
@@ -594,6 +640,13 @@ public class NsdManager {
c.mAsyncChannel.sendMessage(STOP_RESOLVE);
}
/** Internal use only @hide */
public void setEnabled(boolean enabled) {
try {
mService.setEnabled(enabled);
} catch (RemoteException e) { }
}
/**
* Get a reference to NetworkService handler. This is used to establish
* an AsyncChannel communication with the service