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

Commit fe440be7 authored by Steve Kondik's avatar Steve Kondik
Browse files

wimax: Changes for compatibility with CM WiMAX

 * This should allow Samsung's WiMAX support to coexist with ours.

Change-Id: Ibaeb6e32bbcbd4c1daf6e011945547eebaedc901
parent a26ff2cb
Loading
Loading
Loading
Loading
+14 −0
Original line number Diff line number Diff line
@@ -79,6 +79,8 @@ import android.net.IThrottleManager;
import android.net.Uri;
import android.net.wifi.IWifiManager;
import android.net.wifi.WifiManager;
import android.net.wimax.WimaxHelper;
import android.net.wimax.WimaxManagerConstants;
import android.nfc.NfcManager;
import android.os.Binder;
import android.os.Bundle;
@@ -178,6 +180,7 @@ class ContextImpl extends Context {
    private static ThrottleManager sThrottleManager;
    private static WifiManager sWifiManager;
    private static LocationManager sLocationManager;
    private static Object sWimaxManager;
    private static final HashMap<String, SharedPreferencesImpl> sSharedPrefs =
            new HashMap<String, SharedPreferencesImpl>();

@@ -1008,6 +1011,8 @@ class ContextImpl extends Context {
            return getDownloadManager();
        } else if (NFC_SERVICE.equals(name)) {
            return getNfcManager();
        } else if (WimaxManagerConstants.WIMAX_SERVICE.equals(name)) {
            return getWimaxManager();
        }

        return null;
@@ -1265,6 +1270,15 @@ class ContextImpl extends Context {
        return mNfcManager;
    }

    private Object getWimaxManager() {
        synchronized (sSync) {
            if (sWimaxManager == null) {
                sWimaxManager = WimaxHelper.createWimaxService(this, mMainThread.getHandler());
            }
        }
        return sWimaxManager;
    }

    @Override
    public int checkPermission(String permission, int pid, int uid) {
        if (permission == null) {
+18 −0
Original line number Diff line number Diff line
@@ -113,6 +113,8 @@ public class NetworkInfo implements Parcelable {
     */
    private boolean mIsAvailable;

    private String mInterfaceName;

    /**
     * @param type network type
     * @deprecated
@@ -308,6 +310,20 @@ public class NetworkInfo implements Parcelable {
        return mExtraInfo;
    }

    /**
     * @hide
     */
    public void setInterface(String paramString) {
        this.mInterfaceName = paramString;
    }

    /**
     * @hide
     */
    public String getInterface() {
        return this.mInterfaceName;
    }

    @Override
    public String toString() {
        StringBuilder builder = new StringBuilder("NetworkInfo: ");
@@ -345,6 +361,7 @@ public class NetworkInfo implements Parcelable {
        dest.writeInt(mIsRoaming ? 1 : 0);
        dest.writeString(mReason);
        dest.writeString(mExtraInfo);
        dest.writeString(mInterfaceName);
    }

    /**
@@ -366,6 +383,7 @@ public class NetworkInfo implements Parcelable {
                netInfo.mIsRoaming = in.readInt() != 0;
                netInfo.mReason = in.readString();
                netInfo.mExtraInfo = in.readString();
                netInfo.mInterfaceName = in.readString();
                return netInfo;
            }

+6 −0
Original line number Diff line number Diff line
@@ -155,4 +155,10 @@ public class NetworkUtils {
     * {@hide}
     */
    public native static boolean runDhcpRenew(String interfaceName, DhcpInfo ipInfo);

    /**
     * {@hide}
     */
    public native static int addRoutingRule(String param1, String param2, String param3, int param4);

}
+151 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2011 The CyanogenMod 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.wimax;

import dalvik.system.DexClassLoader;

import android.content.Context;
import android.content.ContextWrapper;
import android.os.Handler;
import android.os.IBinder;
import android.os.ServiceManager;
import android.util.Log;

import java.lang.reflect.Constructor;
import java.lang.reflect.Method;

/**
 * {@hide}
 */
public class WimaxHelper {

    private static final String TAG = "WimaxHelper";

    private static DexClassLoader sWimaxClassLoader;
    
    public static boolean isWimaxSupported(Context context) {
        return context.getResources().getBoolean(
                com.android.internal.R.bool.config_wimaxEnabled);
    }
    
    public static DexClassLoader getWimaxClassLoader(Context context) {
        if (isWimaxSupported(context)) {
            if (sWimaxClassLoader == null) {

                String wimaxJarLocation = context.getResources().getString(
                        com.android.internal.R.string.config_wimaxServiceJarLocation);
                String wimaxLibLocation = context.getResources().getString(
                        com.android.internal.R.string.config_wimaxNativeLibLocation);
                sWimaxClassLoader =  new DexClassLoader(wimaxJarLocation,
                        new ContextWrapper(context).getCacheDir().getAbsolutePath(),
                        wimaxLibLocation,ClassLoader.getSystemClassLoader());
            }
            return sWimaxClassLoader;
        }
        return null;
    }
    
    public static Object createWimaxService(Context context, Handler handler) {
        Object controller = null;
        
        try {
            DexClassLoader wimaxClassLoader = getWimaxClassLoader(context);
            IBinder b = ServiceManager.getService(WimaxManagerConstants.WIMAX_SERVICE);
            if (b != null) {
                Class<?> klass = wimaxClassLoader.loadClass("com.htc.net.wimax.IWimaxController$Stub");
                if (klass != null) {
                    Method asInterface = klass.getMethod("asInterface", IBinder.class);
                    Object wc = asInterface.invoke(null, b);
                    if (wc != null) {
                        klass = wimaxClassLoader.loadClass("com.htc.net.wimax.WimaxController");
                        if (klass != null) {
                            Constructor<?> ctor = klass.getDeclaredConstructors()[1];
                            controller = ctor.newInstance(wc, handler);
                        }
                    }
                }
            }
        } catch (Exception e) {
            Log.e(TAG, "Unable to create WimaxController instance", e);
        }

        return controller;
    }

    public static boolean isWimaxEnabled(Context context) {
        boolean ret = false;
        try {
            Object wimaxService = context.getSystemService(WimaxManagerConstants.WIMAX_SERVICE);
            Method m = wimaxService.getClass().getMethod("isWimaxEnabled");
            ret = (Boolean) m.invoke(wimaxService);
        } catch (Exception e) {
            Log.e(TAG, "Unable to get WiMAX enabled state!", e);
        }
        return ret;
    }

    public static boolean setWimaxEnabled(Context context, boolean enabled) {
        boolean ret = false;
        try {
            Object wimaxService = context.getSystemService(WimaxManagerConstants.WIMAX_SERVICE);
            Method m = wimaxService.getClass().getMethod("setWimaxEnabled", boolean.class);
            ret = (Boolean) m.invoke(wimaxService, enabled);
        } catch (Exception e) {
            Log.e(TAG, "Unable to set WiMAX state!", e);
        }
        return ret;
    }

    public static int getWimaxState(Context context) {
        int ret = 0;
        try {
            Object wimaxService = context.getSystemService(WimaxManagerConstants.WIMAX_SERVICE);
            Method m = wimaxService.getClass().getMethod("getWimaxState");
            ret = (Integer) m.invoke(wimaxService);
        } catch (Exception e) {
            Log.e(TAG, "Unable to get WiMAX state!", e);
        }
        return ret;
    }

    public static boolean wimaxRescan(Context context) {
        boolean ret = false;
        try {
            Object wimaxService = context.getSystemService(WimaxManagerConstants.WIMAX_SERVICE);
            Method wimaxRescan = wimaxService.getClass().getMethod("wimaxRescan");
            if (wimaxRescan != null) {
                wimaxRescan.invoke(wimaxService);
                ret = true;
            }
        } catch (Exception e) {
            Log.e(TAG, "Unable to perform WiMAX rescan!", e);
        }
        return ret;
    }
    
    private static Object getWimaxInfo(Context context) {
        Object wimaxInfo = null;
        try {
            Object wimaxService = context.getSystemService(WimaxManagerConstants.WIMAX_SERVICE);
            Method getConnectionInfo = wimaxService.getClass().getMethod("getConnectionInfo");
            wimaxInfo = getConnectionInfo.invoke(wimaxService);
        } catch (Exception e) {
            Log.e(TAG, "Unable to get a WimaxInfo object!", e);
        }
        return wimaxInfo;
    }
}
+48 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2011 The Android Open Source Project
 * Copyright (C) 2011 The CyanogenMod 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.wimax;

/**
@@ -100,4 +116,36 @@ public class WimaxManagerConstants
     */
    public static final int WIMAX_STATE_DISCONNECTED = 9;


    /**
     * Constants for HTC/SQN WiMAX implementation
     */
    public static final int WIMAX_ENABLED_STATE_DISABLING = 0;

    public static final int WIMAX_ENABLED_STATE_DISABLED = 1;

    public static final int WIMAX_ENABLED_STATE_ENABLING = 2;

    public static final int WIMAX_ENABLED_STATE_ENABLED = 3;

    public static final int WIMAX_ENABLED_STATE_UNKNOWN = 4;

    public static final String WIMAX_ENABLED_CHANGED_ACTION = "com.htc.net.wimax.WIMAX_ENABLED_CHANGED";

    public static final String CURRENT_WIMAX_ENABLED_STATE = "curWimaxEnabledState";

    public static final String PREVIOUS_WIMAX_ENABLED_STATE = "preWimaxEnabledState";

    public static final String NETWORK_STATE_CHANGED_ACTION = "com.htc.net.wimax.STATE_CHANGE";

    public static final String SCAN_RESULTS_AVAILABLE_ACTION = "com.htc.net.wimax.SCAN_RESULTS_AVAILABLE";

    public static final String RSSI_CHANGED_ACTION = "com.htc.net.wimax.RSSI_CHANGED";

    public static final String EXTRA_NETWORK_INFO = "networkInfo";

    public static final String EXTRA_NEW_RSSI_LEVEL = "newRssiLevel";

    public static final String EXTRA_NEW_STATE = "newState";

}
Loading