blob: f679936b735999451629aa5cdc9270bc70ce0ccc [file] [log] [blame]
/*
* Copyright (C) 2010 Google Inc.
*
* 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.googlecode.android_scripting.facade;
import android.app.Service;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import com.googlecode.android_scripting.Log;
import com.googlecode.android_scripting.jsonrpc.RpcReceiver;
import com.googlecode.android_scripting.rpc.Rpc;
/**
* Access ConnectivityManager functions.
*/
public class ConnectivityManagerFacade extends RpcReceiver {
class ConnectivityReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (action.equals(ConnectivityManager.CONNECTIVITY_ACTION)) {
Log.d("Connectivity state changed.");
}
}
}
private final ConnectivityManager mCon;
private final Service mService;
public ConnectivityManagerFacade(FacadeManager manager) {
super(manager);
mService = manager.getService();
mCon = (ConnectivityManager) mService.getSystemService(Context.CONNECTIVITY_SERVICE);
}
@Rpc(description = "Get the extra information about the network state provided by lower network layers.")
public String networkGetActiveConnectionExtraInfo() {
NetworkInfo current = mCon.getActiveNetworkInfo();
if (current == null) {
Log.d("No network is active at the moment.");
return null;
}
return current.getExtraInfo();
}
@Rpc(description = "Return the subtype name of the current network, null if not connected")
public String networkGetActiveConnectionSubtypeName() {
NetworkInfo current = mCon.getActiveNetworkInfo();
if (current == null) {
Log.d("No network is active at the moment.");
return null;
}
return current.getSubtypeName();
}
@Rpc(description = "Return a human-readable name describe the type of the network, e.g. WIFI")
public String networkGetActiveConnectionTypeName() {
NetworkInfo current = mCon.getActiveNetworkInfo();
if (current == null) {
Log.d("No network is active at the moment.");
return null;
}
return current.getTypeName();
}
@Rpc(description = "Get connection status information about all network types supported by the device.")
public NetworkInfo[] networkGetAllInfo() {
return mCon.getAllNetworkInfo();
}
@Rpc(description = "Check whether the active network is connected to the Internet.")
public Boolean networkIsConnected() {
NetworkInfo current = mCon.getActiveNetworkInfo();
if (current == null) {
Log.d("No network is active at the moment.");
return false;
}
return current.isConnected();
}
@Override
public void shutdown() {
}
}