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

Commit 409f3714 authored by David Su's avatar David Su
Browse files

Removed references to Manager AIDL from constructors

Converted constructors of Wifi Managers to not reference
their AIDL interfaces since they are @hide and cannot be
referenced by the platform.

Bug: 140299412
Test: atest FrameworksWifiApiTests
Change-Id: If43ce6916ddee5357cdcc8cd27d5620a67d21165
parent 9e365a6d
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -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();
+2 −70
Original line number Diff line number Diff line
@@ -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...
+1 −1
Original line number Diff line number Diff line
@@ -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;

+119 −0
Original line number Diff line number Diff line
/*
 * 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);
                }
        );
    }
}
+5 −3
Original line number Diff line number Diff line
@@ -1215,11 +1215,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;
Loading