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

Commit 9b2886e2 authored by Robert Greenwalt's avatar Robert Greenwalt
Browse files

Create new isNetworkSupported API

Useful for checking if on a wifi-only device.
Similar to asking for NetworkInfo for a network type and checking for
null, though here the intent is explicit.

bug:5087537
Change-Id: Ia3ddd09b6b735b8b3ceb7a347891e015fd96b218
parent ac73e4bb
Loading
Loading
Loading
Loading
+18 −0
Original line number Diff line number Diff line
@@ -814,4 +814,22 @@ public class ConnectivityManager {
        } catch (RemoteException e) {
        }
    }

    /**
     * Returns true if the hardware supports the given network type
     * else it returns false.  This doesn't indicate we have coverage
     * or are authorized onto a network, just whether or not the
     * hardware supports it.  For example a gsm phone without a sim
     * should still return true for mobile data, but a wifi only tablet
     * would return false.
     * @param networkType The nework type we'd like to check
     * @return true if supported, else false
     * @hide
     */
    public boolean isNetworkSupported(int networkType) {
        try {
            return mService.isNetworkSupported(networkType);
        } catch (RemoteException e) {}
        return false;
    }
}
+2 −0
Original line number Diff line number Diff line
@@ -43,6 +43,8 @@ interface IConnectivityManager
    NetworkInfo getNetworkInfo(int networkType);
    NetworkInfo[] getAllNetworkInfo();

    boolean isNetworkSupported(int networkType);

    LinkProperties getActiveLinkProperties();
    LinkProperties getLinkProperties(int networkType);

+10 −10
Original line number Diff line number Diff line
@@ -130,6 +130,8 @@ public class NetworkController extends BroadcastReceiver {
    int mLastDataTypeIconId = -1;
    String mLastLabel = "";

    private boolean mHasMobileDataFeature;

    boolean mDataAndWifiStacked = false;

    // yuck -- stop doing this here and put it in the framework
@@ -147,6 +149,10 @@ public class NetworkController extends BroadcastReceiver {
    public NetworkController(Context context) {
        mContext = context;

        ConnectivityManager cm = (ConnectivityManager)mContext.getSystemService(
                Context.CONNECTIVITY_SERVICE);
        mHasMobileDataFeature = cm.isNetworkSupported(ConnectivityManager.TYPE_MOBILE);

        // set up the default wifi icon, used when no radios have ever appeared
        updateWifiIcons();

@@ -229,7 +235,7 @@ public class NetworkController extends BroadcastReceiver {
                mWifiIconId,
                mWifiActivityIconId);
        cluster.setMobileDataIndicators(
                hasMobileDataFeature(),
                mHasMobileDataFeature,
                mPhoneSignalIconId,
                mMobileActivityIconId,
                mDataTypeIconId);
@@ -376,12 +382,6 @@ public class NetworkController extends BroadcastReceiver {
        }
    }

    private boolean hasMobileDataFeature() {
        // XXX: HAX: replace when a more reliable method is available
        return (! "wifi-only".equals(SystemProperties.get("ro.carrier")));
    }


    private void updateAirplaneMode() {
        mAirplaneMode = (Settings.System.getInt(mContext.getContentResolver(),
            Settings.System.AIRPLANE_MODE_ON, 0) == 1);
@@ -828,8 +828,8 @@ public class NetworkController extends BroadcastReceiver {
            label = context.getString(R.string.status_bar_settings_signal_meter_disconnected);
            // On devices without mobile radios, we want to show the wifi icon
            combinedSignalIconId =
                hasMobileDataFeature() ? mDataSignalIconId : mWifiIconId;
            mContentDescriptionCombinedSignal = hasMobileDataFeature()
                mHasMobileDataFeature ? mDataSignalIconId : mWifiIconId;
            mContentDescriptionCombinedSignal = mHasMobileDataFeature
                ? mContentDescriptionDataType : mContentDescriptionWifi;
            mDataTypeIconId = 0;
        }
@@ -866,7 +866,7 @@ public class NetworkController extends BroadcastReceiver {
                        mWifiIconId,
                        mWifiActivityIconId);
                cluster.setMobileDataIndicators(
                        hasMobileDataFeature(),
                        mHasMobileDataFeature,
                        mPhoneSignalIconId,
                        mMobileActivityIconId,
                        mDataTypeIconId);
+6 −0
Original line number Diff line number Diff line
@@ -703,6 +703,12 @@ public class ConnectivityService extends IConnectivityManager.Stub {
        return result.toArray(new NetworkInfo[result.size()]);
    }

    @Override
    public boolean isNetworkSupported(int networkType) {
        enforceAccessPermission();
        return (isNetworkTypeValid(networkType) && (mNetTrackers[networkType] != null));
    }

    /**
     * Return LinkProperties for the active (i.e., connected) default
     * network interface.  It is assumed that at most one default network
+1 −1
Original line number Diff line number Diff line
@@ -350,7 +350,6 @@ class ServerThread extends Thread {
                Slog.i(TAG, "Wi-Fi Service");
                wifi = new WifiService(context);
                ServiceManager.addService(Context.WIFI_SERVICE, wifi);
                wifi.checkAndStartWifi();
            } catch (Throwable e) {
                reportWtf("starting Wi-Fi Service", e);
            }
@@ -361,6 +360,7 @@ class ServerThread extends Thread {
                ServiceManager.addService(Context.CONNECTIVITY_SERVICE, connectivity);
                networkStats.bindConnectivityManager(connectivity);
                networkPolicy.bindConnectivityManager(connectivity);
                wifi.checkAndStartWifi();
                wifiP2p.connectivityServiceReady();
            } catch (Throwable e) {
                reportWtf("starting Connectivity Service", e);
Loading