android.net.wifi.IWifiManager Java Examples

The following examples show how to use android.net.wifi.IWifiManager. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SystemServiceRegistry.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Override
public WifiManager createService(ContextImpl ctx) throws ServiceNotFoundException {
    IBinder b = ServiceManager.getServiceOrThrow(Context.WIFI_SERVICE);
    IWifiManager service = IWifiManager.Stub.asInterface(b);
    return new WifiManager(ctx.getOuterContext(), service,
            ConnectivityThread.getInstanceLooper());
}
 
Example #2
Source File: CmdWifi.java    From PhoneProfilesPlus with Apache License 2.0 5 votes vote down vote up
private static boolean setWifi(boolean enable) {
    final String packageName = PPApplication.PACKAGE_NAME;
    try {
        //PPApplication.logE("CmdWifi.setWifi", "enable="+enable);
        IWifiManager wifiAdapter = IWifiManager.Stub.asInterface(ServiceManager.getService("wifi"));  // service list | grep IWifiManager
        wifiAdapter.setWifiEnabled(packageName, enable);
        return true;
    } catch (Throwable e) {
        //Log.e("CmdWifi.setWifi", Log.getStackTraceString(e));
        PPApplication.recordException(e);
        return false;
    }
}
 
Example #3
Source File: CmdWifiAP.java    From PhoneProfilesPlus with Apache License 2.0 5 votes vote down vote up
static boolean setWifiAP(boolean enable, boolean doNotChangeWifi) {
    //PPApplication.logE("CmdWifiAP.setWifiAP", "START enable="+enable);
    //PPApplication.logE("CmdWifiAP.setWifiAP", "START doNotChangeWifi="+doNotChangeWifi);
    final String packageName = PPApplication.PACKAGE_NAME;
    try {
        IConnectivityManager connectivityAdapter = IConnectivityManager.Stub.asInterface(ServiceManager.getService("connectivity"));  // service list | grep IConnectivityManager
        //PPApplication.logE("CmdWifiAP.setWifiAP", "connectivityAdapter="+connectivityAdapter);
        if (enable) {
            if (!doNotChangeWifi) {
                IWifiManager wifiAdapter = IWifiManager.Stub.asInterface(ServiceManager.getService("wifi"));  // service list | grep IWifiManager
                //PPApplication.logE("CmdWifiAP.setWifiAP", "wifiAdapter="+wifiAdapter);
                int wifiState = wifiAdapter.getWifiEnabledState();
                boolean isWifiEnabled = ((wifiState == WifiManager.WIFI_STATE_ENABLED) || (wifiState == WifiManager.WIFI_STATE_ENABLING));
                //PPApplication.logE("CmdWifiAP.setWifiAP", "isWifiEnabled="+isWifiEnabled);
                if (isWifiEnabled)
                    wifiAdapter.setWifiEnabled(packageName, false);
            }

            ResultReceiver dummyResultReceiver = new ResultReceiver(null);
            connectivityAdapter.startTethering(0, dummyResultReceiver, false, packageName);
        } else {
            connectivityAdapter.stopTethering(0, packageName);
        }

        //PPApplication.logE("CmdWifiAP.setWifiAP", "END=");
        return true;
    } catch (java.lang.SecurityException ee) {
        //Log.e("CmdWifiAP.setWifiAP", Log.getStackTraceString(ee));
        //PPApplication.logToCrashlytics("E/CmdWifiAP.setWifiAP: " + Log.getStackTraceString(ee));
        //PPApplication.recordException(e);
        //PPApplication.logE("CmdWifiAP.setWifiAP", Log.getStackTraceString(e));
        return false;
    } catch (Throwable e) {
        //Log.e("CmdWifiAP.setWifiAP", Log.getStackTraceString(e));
        PPApplication.recordException(e);
        //PPApplication.logE("CmdWifiAP.setWifiAP", Log.getStackTraceString(e));
        return false;
    }
}
 
Example #4
Source File: CmdWifiAP.java    From PhoneProfilesPlus with Apache License 2.0 5 votes vote down vote up
static boolean isEnabled() {
    try {
        boolean enabled;
        IWifiManager adapter = IWifiManager.Stub.asInterface(ServiceManager.getService("wifi"));  // service list | grep IWifiManager
        //PPApplication.logE("CmdWifiAP.isEnabled", "adapter="+adapter);
        enabled = adapter.getWifiApEnabledState() == WifiManager.WIFI_AP_STATE_ENABLED;
        //PPApplication.logE("CmdWifiAP.isEnabled", "enabled="+enabled);
        return enabled;
    } catch (Throwable e) {
        //Log.e("CmdWifiAP.isEnabled", Log.getStackTraceString(e));
        PPApplication.recordException(e);
        return false;
    }
}
 
Example #5
Source File: ContextImpl.java    From AndroidComponentPlugin with Apache License 2.0 4 votes vote down vote up
public Object createService(ContextImpl ctx) {
    IBinder b = ServiceManager.getService(WIFI_SERVICE);
    IWifiManager service = IWifiManager.Stub.asInterface(b);
    return new WifiManager(service, ctx.mMainThread.getHandler());
}
 
Example #6
Source File: ContextImpl.java    From AndroidComponentPlugin with Apache License 2.0 4 votes vote down vote up
public Object createService(ContextImpl ctx) {
    IBinder b = ServiceManager.getService(WIFI_SERVICE);
    IWifiManager service = IWifiManager.Stub.asInterface(b);
    return new WifiManager(service, ctx.mMainThread.getHandler());
}
 
Example #7
Source File: ContextImpl.java    From AndroidComponentPlugin with Apache License 2.0 4 votes vote down vote up
public Object createService(ContextImpl ctx) {
    IBinder b = ServiceManager.getService(WIFI_SERVICE);
    IWifiManager service = IWifiManager.Stub.asInterface(b);
    return new WifiManager(ctx.getOuterContext(), service);
}
 
Example #8
Source File: ContextImpl.java    From AndroidComponentPlugin with Apache License 2.0 4 votes vote down vote up
public Object createService(ContextImpl ctx) {
    IBinder b = ServiceManager.getService(WIFI_SERVICE);
    IWifiManager service = IWifiManager.Stub.asInterface(b);
    return new WifiManager(ctx.getOuterContext(), service);
}
 
Example #9
Source File: ContextImpl.java    From AndroidComponentPlugin with Apache License 2.0 4 votes vote down vote up
public Object createService(ContextImpl ctx) {
    IBinder b = ServiceManager.getService(WIFI_SERVICE);
    IWifiManager service = IWifiManager.Stub.asInterface(b);
    return new WifiManager(ctx.getOuterContext(), service);
}
 
Example #10
Source File: ContextImpl.java    From AndroidComponentPlugin with Apache License 2.0 4 votes vote down vote up
public Object createService(ContextImpl ctx) {
    IBinder b = ServiceManager.getService(WIFI_SERVICE);
    IWifiManager service = IWifiManager.Stub.asInterface(b);
    return new WifiManager(ctx.getOuterContext(), service);
}
 
Example #11
Source File: ContextImpl.java    From AndroidComponentPlugin with Apache License 2.0 4 votes vote down vote up
public Object createService(ContextImpl ctx) {
    IBinder b = ServiceManager.getService(WIFI_SERVICE);
    IWifiManager service = IWifiManager.Stub.asInterface(b);
    return new WifiManager(ctx.getOuterContext(), service);
}