Skip to content

Commit 3ef889b

Browse files
committed
Add user control to turn on/off nsd
Change-Id: Ide3cc20adb21ac6dffaf6b9b9136d77a129afa3b
1 parent c5cbcb5 commit 3ef889b

File tree

4 files changed

+386
-146
lines changed

4 files changed

+386
-146
lines changed

core/java/android/net/nsd/INsdManager.aidl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,5 @@ import android.os.Messenger;
2626
interface INsdManager
2727
{
2828
Messenger getMessenger();
29+
void setEnabled(boolean enable);
2930
}

core/java/android/net/nsd/NsdManager.java

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package android.net.nsd;
1818

19+
import android.annotation.SdkConstant;
20+
import android.annotation.SdkConstant.SdkConstantType;
1921
import android.content.Context;
2022
import android.os.Binder;
2123
import android.os.IBinder;
@@ -133,6 +135,44 @@ public class NsdManager {
133135
private static final String TAG = "NsdManager";
134136
INsdManager mService;
135137

138+
/**
139+
* Broadcast intent action to indicate whether network service discovery is
140+
* enabled or disabled. An extra {@link #EXTRA_NSD_STATE} provides the state
141+
* information as int.
142+
*
143+
* @see #EXTRA_NSD_STATE
144+
* @hide
145+
*/
146+
@SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
147+
public static final String NSD_STATE_CHANGED_ACTION =
148+
"android.net.nsd.STATE_CHANGED";
149+
150+
/**
151+
* The lookup key for an int that indicates whether network service discovery is enabled
152+
* or disabled. Retrieve it with {@link android.content.Intent#getIntExtra(String,int)}.
153+
*
154+
* @see #NSD_STATE_DISABLED
155+
* @see #NSD_STATE_ENABLED
156+
* @hide
157+
*/
158+
public static final String EXTRA_NSD_STATE = "nsd_state";
159+
160+
/**
161+
* Network service discovery is disabled
162+
*
163+
* @see #NSD_STATE_CHANGED_ACTION
164+
* @hide
165+
*/
166+
public static final int NSD_STATE_DISABLED = 1;
167+
168+
/**
169+
* Network service discovery is enabled
170+
*
171+
* @see #NSD_STATE_CHANGED_ACTION
172+
* @hide
173+
*/
174+
public static final int NSD_STATE_ENABLED = 2;
175+
136176
private static final int BASE = Protocol.BASE_NSD_MANAGER;
137177

138178
/** @hide */
@@ -188,6 +228,12 @@ public class NsdManager {
188228
/** @hide */
189229
public static final int STOP_RESOLVE_SUCCEEDED = BASE + 23;
190230

231+
/** @hide */
232+
public static final int ENABLE = BASE + 24;
233+
/** @hide */
234+
public static final int DISABLE = BASE + 25;
235+
236+
191237
/**
192238
* Create a new Nsd instance. Applications use
193239
* {@link android.content.Context#getSystemService Context.getSystemService()} to retrieve
@@ -312,8 +358,8 @@ public static class Channel {
312358
private DnsSdResolveListener mDnsSdResolveListener;
313359
private ActionListener mDnsSdStopResolveListener;
314360

315-
AsyncChannel mAsyncChannel;
316-
ServiceHandler mHandler;
361+
private AsyncChannel mAsyncChannel;
362+
private ServiceHandler mHandler;
317363
class ServiceHandler extends Handler {
318364
ServiceHandler(Looper looper) {
319365
super(looper);
@@ -594,6 +640,13 @@ public void stopServiceResolve(Channel c) {
594640
c.mAsyncChannel.sendMessage(STOP_RESOLVE);
595641
}
596642

643+
/** Internal use only @hide */
644+
public void setEnabled(boolean enabled) {
645+
try {
646+
mService.setEnabled(enabled);
647+
} catch (RemoteException e) { }
648+
}
649+
597650
/**
598651
* Get a reference to NetworkService handler. This is used to establish
599652
* an AsyncChannel communication with the service

core/java/android/provider/Settings.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3276,6 +3276,12 @@ public static final String getBluetoothInputDevicePriorityKey(String address) {
32763276
public static final String WIFI_MOBILE_DATA_TRANSITION_WAKELOCK_TIMEOUT_MS =
32773277
"wifi_mobile_data_transition_wakelock_timeout_ms";
32783278

3279+
/**
3280+
* Whether network service discovery is enabled.
3281+
* @hide
3282+
*/
3283+
public static final String NSD_ON = "nsd_on";
3284+
32793285
/**
32803286
* Whether background data usage is allowed by the user. See
32813287
* ConnectivityManager for more info.

0 commit comments

Comments
 (0)