summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author David Su <dysu@google.com> 2019-11-22 18:00:23 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2019-11-22 18:00:23 +0000
commit3a9a1fb8f9d0c88c7a15784fc03557093c0f4ee3 (patch)
tree3e982f121672bda26cae5c58aeef662997a068f0
parent9bdff40daca8613fd456997bf66ce27c4764bac2 (diff)
parent409f371488d2ed97101dfb0e42852e89a19147db (diff)
Merge changes from topic "wifi-manager-constructors"
* changes: Removed references to Manager AIDL from constructors Migrate WifiCommand to WifiShellCommand
-rw-r--r--api/system-current.txt4
-rw-r--r--cmds/svc/src/com/android/commands/svc/Svc.java2
-rw-r--r--cmds/svc/src/com/android/commands/svc/WifiCommand.java69
-rwxr-xr-xcmds/svc/svc21
-rw-r--r--core/java/android/app/SystemServiceRegistry.java72
-rw-r--r--wifi/java/android/net/wifi/RttManager.java2
-rw-r--r--wifi/java/android/net/wifi/WifiFrameworkInitializer.java119
-rw-r--r--wifi/java/android/net/wifi/WifiManager.java8
-rw-r--r--wifi/java/android/net/wifi/WifiScanner.java7
-rw-r--r--wifi/java/android/net/wifi/aware/WifiAwareManager.java2
-rw-r--r--wifi/java/android/net/wifi/rtt/WifiRttManager.java2
11 files changed, 160 insertions, 148 deletions
diff --git a/api/system-current.txt b/api/system-current.txt
index 07e46a04f932..77aff8dac3fa 100644
--- a/api/system-current.txt
+++ b/api/system-current.txt
@@ -4853,6 +4853,10 @@ package android.net.wifi {
field @Deprecated public static final int WPA2_PSK = 4; // 0x4
}
+ public class WifiFrameworkInitializer {
+ method public static void registerServiceWrappers();
+ }
+
public class WifiInfo implements android.os.Parcelable {
method @Nullable public String getAppPackageName();
method public double getRxSuccessRate();
diff --git a/cmds/svc/src/com/android/commands/svc/Svc.java b/cmds/svc/src/com/android/commands/svc/Svc.java
index 68fb8e694e6f..e602e2abbe03 100644
--- a/cmds/svc/src/com/android/commands/svc/Svc.java
+++ b/cmds/svc/src/com/android/commands/svc/Svc.java
@@ -94,7 +94,7 @@ public class Svc {
COMMAND_HELP,
new PowerCommand(),
new DataCommand(),
- new WifiCommand(),
+ // `svc wifi` has been migrated to WifiShellCommand
new UsbCommand(),
new NfcCommand(),
new BluetoothCommand(),
diff --git a/cmds/svc/src/com/android/commands/svc/WifiCommand.java b/cmds/svc/src/com/android/commands/svc/WifiCommand.java
deleted file mode 100644
index e31cb5381afc..000000000000
--- a/cmds/svc/src/com/android/commands/svc/WifiCommand.java
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * Copyright (C) 2008 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.android.commands.svc;
-
-import android.os.ServiceManager;
-import android.os.RemoteException;
-import android.net.wifi.IWifiManager;
-import android.content.Context;
-
-public class WifiCommand extends Svc.Command {
- public WifiCommand() {
- super("wifi");
- }
-
- public String shortHelp() {
- return "Control the Wi-Fi manager";
- }
-
- public String longHelp() {
- return shortHelp() + "\n"
- + "\n"
- + "usage: svc wifi [enable|disable]\n"
- + " Turn Wi-Fi on or off.\n\n";
- }
-
- public void run(String[] args) {
- boolean validCommand = false;
- if (args.length >= 2) {
- boolean flag = false;
- if ("enable".equals(args[1])) {
- flag = true;
- validCommand = true;
- } else if ("disable".equals(args[1])) {
- flag = false;
- validCommand = true;
- }
- if (validCommand) {
- IWifiManager wifiMgr
- = IWifiManager.Stub.asInterface(ServiceManager.getService(Context.WIFI_SERVICE));
- if (wifiMgr == null) {
- System.err.println("Wi-Fi service is not ready");
- return;
- }
- try {
- wifiMgr.setWifiEnabled("com.android.shell", flag);
- }
- catch (RemoteException e) {
- System.err.println("Wi-Fi operation failed: " + e);
- }
- return;
- }
- }
- System.err.println(longHelp());
- }
-}
diff --git a/cmds/svc/svc b/cmds/svc/svc
index c122e981e4c7..60c95c7ec855 100755
--- a/cmds/svc/svc
+++ b/cmds/svc/svc
@@ -1,3 +1,24 @@
#!/system/bin/sh
+
+# `svc wifi` has been migrated to WifiShellCommand,
+# simply perform translation to `cmd wifi set-wifi-enabled` here.
+if [ "x$1" == "xwifi" ]; then
+ # `cmd wifi` by convention uses enabled/disabled
+ # instead of enable/disable
+ if [ "x$2" == "xenable" ]; then
+ exec cmd wifi set-wifi-enabled enabled
+ elif [ "x$2" == "xdisable" ]; then
+ exec cmd wifi set-wifi-enabled disabled
+ else
+ echo "Control the Wi-Fi manager"
+ echo ""
+ echo "usage: svc wifi [enable|disable]"
+ echo " Turn Wi-Fi on or off."
+ echo ""
+ fi
+ exit 1
+fi
+
export CLASSPATH=/system/framework/svc.jar
exec app_process /system/bin com.android.commands.svc.Svc "$@"
+
diff --git a/core/java/android/app/SystemServiceRegistry.java b/core/java/android/app/SystemServiceRegistry.java
index 5effa1b99813..0bfd2c6f5f70 100644
--- a/core/java/android/app/SystemServiceRegistry.java
+++ b/core/java/android/app/SystemServiceRegistry.java
@@ -116,16 +116,7 @@ import android.net.lowpan.ILowpanManager;
import android.net.lowpan.LowpanManager;
import android.net.nsd.INsdManager;
import android.net.nsd.NsdManager;
-import android.net.wifi.IWifiScanner;
-import android.net.wifi.RttManager;
-import android.net.wifi.WifiManager;
-import android.net.wifi.WifiScanner;
-import android.net.wifi.aware.IWifiAwareManager;
-import android.net.wifi.aware.WifiAwareManager;
-import android.net.wifi.p2p.IWifiP2pManager;
-import android.net.wifi.p2p.WifiP2pManager;
-import android.net.wifi.rtt.IWifiRttManager;
-import android.net.wifi.rtt.WifiRttManager;
+import android.net.wifi.WifiFrameworkInitializer;
import android.nfc.NfcManager;
import android.os.BatteryManager;
import android.os.BatteryStats;
@@ -691,66 +682,6 @@ public final class SystemServiceRegistry {
ConnectivityThread.getInstanceLooper());
}});
- registerService(Context.WIFI_SERVICE, WifiManager.class,
- new CachedServiceFetcher<WifiManager>() {
- @Override
- public WifiManager createService(ContextImpl ctx) {
- return new WifiManager(ctx.getOuterContext(),
- ConnectivityThread.getInstanceLooper());
- }});
-
- registerService(Context.WIFI_P2P_SERVICE, WifiP2pManager.class,
- new StaticServiceFetcher<WifiP2pManager>() {
- @Override
- public WifiP2pManager createService() throws ServiceNotFoundException {
- IBinder b = ServiceManager.getServiceOrThrow(Context.WIFI_P2P_SERVICE);
- IWifiP2pManager service = IWifiP2pManager.Stub.asInterface(b);
- return new WifiP2pManager(service);
- }});
-
- registerService(Context.WIFI_AWARE_SERVICE, WifiAwareManager.class,
- new CachedServiceFetcher<WifiAwareManager>() {
- @Override
- public WifiAwareManager createService(ContextImpl ctx) throws ServiceNotFoundException {
- IBinder b = ServiceManager.getServiceOrThrow(Context.WIFI_AWARE_SERVICE);
- IWifiAwareManager service = IWifiAwareManager.Stub.asInterface(b);
- if (service == null) {
- return null;
- }
- return new WifiAwareManager(ctx.getOuterContext(), service);
- }});
-
- registerService(Context.WIFI_SCANNING_SERVICE, WifiScanner.class,
- new CachedServiceFetcher<WifiScanner>() {
- @Override
- public WifiScanner createService(ContextImpl ctx) throws ServiceNotFoundException {
- IBinder b = ServiceManager.getServiceOrThrow(Context.WIFI_SCANNING_SERVICE);
- IWifiScanner service = IWifiScanner.Stub.asInterface(b);
- return new WifiScanner(ctx.getOuterContext(), service,
- ConnectivityThread.getInstanceLooper());
- }});
-
- registerService(Context.WIFI_RTT_SERVICE, RttManager.class,
- new CachedServiceFetcher<RttManager>() {
- @Override
- public RttManager createService(ContextImpl ctx) throws ServiceNotFoundException {
- IBinder b = ServiceManager.getServiceOrThrow(Context.WIFI_RTT_RANGING_SERVICE);
- IWifiRttManager service = IWifiRttManager.Stub.asInterface(b);
- return new RttManager(ctx.getOuterContext(),
- new WifiRttManager(ctx.getOuterContext(), service));
- }});
-
- registerService(Context.WIFI_RTT_RANGING_SERVICE, WifiRttManager.class,
- new CachedServiceFetcher<WifiRttManager>() {
- @Override
- public WifiRttManager createService(ContextImpl ctx)
- throws ServiceNotFoundException {
- IBinder b = ServiceManager.getServiceOrThrow(
- Context.WIFI_RTT_RANGING_SERVICE);
- IWifiRttManager service = IWifiRttManager.Stub.asInterface(b);
- return new WifiRttManager(ctx.getOuterContext(), service);
- }});
-
registerService(Context.ETHERNET_SERVICE, EthernetManager.class,
new CachedServiceFetcher<EthernetManager>() {
@Override
@@ -1265,6 +1196,7 @@ public final class SystemServiceRegistry {
BlobStoreManagerFrameworkInitializer.initialize();
TelephonyFrameworkInitializer.registerServiceWrappers();
AppSearchManagerFrameworkInitializer.initialize();
+ WifiFrameworkInitializer.registerServiceWrappers();
} finally {
// If any of the above code throws, we're in a pretty bad shape and the process
// will likely crash, but we'll reset it just in case there's an exception handler...
diff --git a/wifi/java/android/net/wifi/RttManager.java b/wifi/java/android/net/wifi/RttManager.java
index 6a03c73bc3f9..73c52ab0ab1b 100644
--- a/wifi/java/android/net/wifi/RttManager.java
+++ b/wifi/java/android/net/wifi/RttManager.java
@@ -1212,7 +1212,7 @@ public class RttManager {
*
* @hide
*/
- public RttManager(Context context, WifiRttManager service) {
+ public RttManager(@NonNull Context context, @NonNull WifiRttManager service) {
mNewService = service;
mContext = context;
diff --git a/wifi/java/android/net/wifi/WifiFrameworkInitializer.java b/wifi/java/android/net/wifi/WifiFrameworkInitializer.java
new file mode 100644
index 000000000000..775043ae3291
--- /dev/null
+++ b/wifi/java/android/net/wifi/WifiFrameworkInitializer.java
@@ -0,0 +1,119 @@
+/*
+ * Copyright (C) 2019 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 android.net.wifi;
+
+import android.annotation.SystemApi;
+import android.app.SystemServiceRegistry;
+import android.content.Context;
+import android.net.wifi.aware.IWifiAwareManager;
+import android.net.wifi.aware.WifiAwareManager;
+import android.net.wifi.p2p.IWifiP2pManager;
+import android.net.wifi.p2p.WifiP2pManager;
+import android.net.wifi.rtt.IWifiRttManager;
+import android.net.wifi.rtt.WifiRttManager;
+import android.os.HandlerThread;
+import android.os.Looper;
+
+/**
+ * Class for performing registration for all Wifi services.
+ *
+ * @hide
+ */
+@SystemApi
+public class WifiFrameworkInitializer {
+
+ /**
+ * A class implementing the lazy holder idiom: the unique static instance
+ * of {@link #INSTANCE} is instantiated in a thread-safe way (guaranteed by
+ * the language specs) the first time that NoPreloadHolder is referenced in getInstanceLooper().
+ *
+ * This is necessary because we can't spawn a new thread in {@link #registerServiceWrappers()}.
+ * {@link #registerServiceWrappers()} is called during the Zygote phase, which disallows
+ * spawning new threads. Naming the class "NoPreloadHolder" ensures that the classloader will
+ * not preload this class, inadvertently spawning the thread too early.
+ */
+ private static class NoPreloadHolder {
+ private static final HandlerThread INSTANCE = createInstance();
+
+ private static HandlerThread createInstance() {
+ HandlerThread thread = new HandlerThread("WifiManagerThread");
+ thread.start();
+ return thread;
+ }
+ }
+
+ private static Looper getInstanceLooper() {
+ return NoPreloadHolder.INSTANCE.getLooper();
+ }
+
+ private WifiFrameworkInitializer() {}
+
+ /**
+ * Called by {@link SystemServiceRegistry}'s static initializer and registers all Wifi services
+ * to {@link Context}, so that {@link Context#getSystemService} can return them.
+ *
+ * @throws IllegalStateException if this is called from anywhere besides
+ * {@link SystemServiceRegistry}
+ */
+ public static void registerServiceWrappers() {
+ SystemServiceRegistry.registerContextAwareService(
+ Context.WIFI_SERVICE,
+ WifiManager.class,
+ context -> new WifiManager(context, getInstanceLooper())
+ );
+ SystemServiceRegistry.registerStaticService(
+ Context.WIFI_P2P_SERVICE,
+ WifiP2pManager.class,
+ serviceBinder -> {
+ IWifiP2pManager service = IWifiP2pManager.Stub.asInterface(serviceBinder);
+ return new WifiP2pManager(service);
+ }
+ );
+ SystemServiceRegistry.registerContextAwareService(
+ Context.WIFI_AWARE_SERVICE,
+ WifiAwareManager.class,
+ (context, serviceBinder) -> {
+ IWifiAwareManager service = IWifiAwareManager.Stub.asInterface(serviceBinder);
+ return new WifiAwareManager(context, service);
+ }
+ );
+ SystemServiceRegistry.registerContextAwareService(
+ Context.WIFI_SCANNING_SERVICE,
+ WifiScanner.class,
+ (context, serviceBinder) -> {
+ IWifiScanner service = IWifiScanner.Stub.asInterface(serviceBinder);
+ return new WifiScanner(context, service, getInstanceLooper());
+ }
+ );
+ SystemServiceRegistry.registerContextAwareService(
+ Context.WIFI_RTT_SERVICE,
+ RttManager.class,
+ (context, serviceBinder) -> {
+ IWifiRttManager service = IWifiRttManager.Stub.asInterface(serviceBinder);
+ WifiRttManager wifiRttManager = new WifiRttManager(context, service);
+ return new RttManager(context, wifiRttManager);
+ }
+ );
+ SystemServiceRegistry.registerContextAwareService(
+ Context.WIFI_RTT_RANGING_SERVICE,
+ WifiRttManager.class,
+ (context, serviceBinder) -> {
+ IWifiRttManager service = IWifiRttManager.Stub.asInterface(serviceBinder);
+ return new WifiRttManager(context, service);
+ }
+ );
+ }
+}
diff --git a/wifi/java/android/net/wifi/WifiManager.java b/wifi/java/android/net/wifi/WifiManager.java
index 77666b072bff..942d795a45ca 100644
--- a/wifi/java/android/net/wifi/WifiManager.java
+++ b/wifi/java/android/net/wifi/WifiManager.java
@@ -1213,11 +1213,13 @@ public class WifiManager {
* Applications will almost always want to use
* {@link android.content.Context#getSystemService Context.getSystemService()} to retrieve
* the standard {@link android.content.Context#WIFI_SERVICE Context.WIFI_SERVICE}.
+ *
* @param context the application context
- * @hide - hide this because it takes in a parameter of type IWifiManager, which
- * is a system private class.
+ * @param looper the Looper used to deliver callbacks
+ *
+ * @hide
*/
- public WifiManager(Context context, Looper looper) {
+ public WifiManager(@NonNull Context context, @NonNull Looper looper) {
mContext = context;
mLooper = looper;
mTargetSdkVersion = context.getApplicationInfo().targetSdkVersion;
diff --git a/wifi/java/android/net/wifi/WifiScanner.java b/wifi/java/android/net/wifi/WifiScanner.java
index 0d36718f07f1..771f3b819498 100644
--- a/wifi/java/android/net/wifi/WifiScanner.java
+++ b/wifi/java/android/net/wifi/WifiScanner.java
@@ -1291,12 +1291,15 @@ public class WifiScanner {
* Applications will almost always want to use
* {@link android.content.Context#getSystemService Context.getSystemService()} to retrieve
* the standard {@link android.content.Context#WIFI_SERVICE Context.WIFI_SERVICE}.
+ *
* @param context the application context
- * @param service the Binder interface
+ * @param service the Binder interface for {@link Context#WIFI_SCANNING_SERVICE}
* @param looper the Looper used to deliver callbacks
+ *
* @hide
*/
- public WifiScanner(Context context, IWifiScanner service, Looper looper) {
+ public WifiScanner(@NonNull Context context, @NonNull IWifiScanner service,
+ @NonNull Looper looper) {
mContext = context;
mService = service;
diff --git a/wifi/java/android/net/wifi/aware/WifiAwareManager.java b/wifi/java/android/net/wifi/aware/WifiAwareManager.java
index 5aab3470d979..7b37d652426d 100644
--- a/wifi/java/android/net/wifi/aware/WifiAwareManager.java
+++ b/wifi/java/android/net/wifi/aware/WifiAwareManager.java
@@ -158,7 +158,7 @@ public class WifiAwareManager {
private final Object mLock = new Object(); // lock access to the following vars
/** @hide */
- public WifiAwareManager(Context context, IWifiAwareManager service) {
+ public WifiAwareManager(@NonNull Context context, @NonNull IWifiAwareManager service) {
mContext = context;
mService = service;
}
diff --git a/wifi/java/android/net/wifi/rtt/WifiRttManager.java b/wifi/java/android/net/wifi/rtt/WifiRttManager.java
index 770a12096806..cb0c5d41df90 100644
--- a/wifi/java/android/net/wifi/rtt/WifiRttManager.java
+++ b/wifi/java/android/net/wifi/rtt/WifiRttManager.java
@@ -77,7 +77,7 @@ public class WifiRttManager {
"android.net.wifi.rtt.action.WIFI_RTT_STATE_CHANGED";
/** @hide */
- public WifiRttManager(Context context, IWifiRttManager service) {
+ public WifiRttManager(@NonNull Context context, @NonNull IWifiRttManager service) {
mContext = context;
mService = service;
}