diff options
author | DvTonder <david.vantonder@gmail.com> | 2012-07-15 10:28:15 -0400 |
---|---|---|
committer | Ricardo Cerqueira <cyanogenmod@cerqueira.org> | 2012-11-21 00:25:18 +0000 |
commit | 0b636d08439c291322339e02be605be54f589b91 (patch) | |
tree | 1abb1921eab3532617ddda7e07939f99de093280 /core/java/android/net/wimax | |
parent | 8415ee214d09ed7f399d8ff68d4f78c76c68fe08 (diff) | |
download | frameworks_base-0b636d08439c291322339e02be605be54f589b91.zip frameworks_base-0b636d08439c291322339e02be605be54f589b91.tar.gz frameworks_base-0b636d08439c291322339e02be605be54f589b91.tar.bz2 |
Framework: Port CM9 features to CM10
This commit includes:
- Power menu Reboot
- Power menu screenshot
- Profiles
- Lock screen Calendar
- Lock screen Weather
- Notification light customization
- Battery light customization
- IME Selector notification toggle
- and a few more things to support Settings
Change-Id: Ibd63116df90b06f6ce6adb8a0343059bbb999bfb
Diffstat (limited to 'core/java/android/net/wimax')
-rw-r--r-- | core/java/android/net/wimax/WimaxHelper.java | 188 | ||||
-rw-r--r-- | core/java/android/net/wimax/WimaxManagerConstants.java | 15 |
2 files changed, 203 insertions, 0 deletions
diff --git a/core/java/android/net/wimax/WimaxHelper.java b/core/java/android/net/wimax/WimaxHelper.java new file mode 100644 index 0000000..f6c7a40 --- /dev/null +++ b/core/java/android/net/wimax/WimaxHelper.java @@ -0,0 +1,188 @@ +/* + * 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 android.provider.Settings; +import java.lang.reflect.Constructor; +import java.lang.reflect.Method; + +/** + * {@hide} + */ +public class WimaxHelper { + + private static final String TAG = "WimaxHelper"; + + private static final String WIMAX_CONTROLLER_CLASSNAME = "com.htc.net.wimax.WimaxController"; + private static final String WIMAX_MANAGER_CLASSNAME = "android.net.fourG.wimax.Wimax4GManager"; + + private static DexClassLoader sWimaxClassLoader; + private static String sWimaxManagerClassname, sIsWimaxEnabledMethodname, + sSetWimaxEnabledMethodname, sGetWimaxStateMethodname; + + 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) { + sWimaxManagerClassname = context.getResources().getString( + com.android.internal.R.string.config_wimaxManagerClassname); + + // WimaxController::getWimaxState == Wimax4GManager::get4GState. + // However, Wimax4GManager also implements a different getWimaxState + // method, which returns a WimaxState object describing the connection + // state, not the enabled state. Other methods are similarly renamed. + if (sWimaxManagerClassname.equals(WIMAX_CONTROLLER_CLASSNAME)) { + sIsWimaxEnabledMethodname = "isWimaxEnabled"; + sSetWimaxEnabledMethodname = "setWimaxEnabled"; + sGetWimaxStateMethodname = "getWimaxState"; + } else if (sWimaxManagerClassname.equals(WIMAX_MANAGER_CLASSNAME)) { + sIsWimaxEnabledMethodname = "is4GEnabled"; + sSetWimaxEnabledMethodname = "set4GEnabled"; + sGetWimaxStateMethodname = "get4GState"; + } + + 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); + if (sWimaxManagerClassname.equals(WIMAX_CONTROLLER_CLASSNAME)) { + // Load supersonic's and speedy's WimaxController. + 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(WIMAX_CONTROLLER_CLASSNAME); + if (klass != null) { + Constructor<?> ctor = klass.getDeclaredConstructors()[1]; + controller = ctor.newInstance(wc, handler); + } + } + } + } + } else if (sWimaxManagerClassname.equals(WIMAX_MANAGER_CLASSNAME)) { + // Load crespo4g's (and epicmtd's) Wimax4GManager. + // Note that crespo4g's implementation grabs WIMAX_SERVICE internally, so + // it doesn't need to be passed in. Other implementations (may) require + // WIMAX_SERVICE to be grabbed externally, so check Wimax4GManager::<init>. + Class<?> klass = wimaxClassLoader.loadClass(WIMAX_MANAGER_CLASSNAME); + if (klass != null) { + Constructor<?> ctor = klass.getDeclaredConstructors()[0]; + controller = ctor.newInstance(); + } + } + } 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(sIsWimaxEnabledMethodname); + 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(sSetWimaxEnabledMethodname, boolean.class); + ret = (Boolean) m.invoke(wimaxService, enabled); + if (ret) + Settings.Secure.putInt(context.getContentResolver(), + Settings.Secure.WIMAX_ON, (Boolean) enabled ? 1 : 0); + } 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(sGetWimaxStateMethodname); + 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; + } +} diff --git a/core/java/android/net/wimax/WimaxManagerConstants.java b/core/java/android/net/wimax/WimaxManagerConstants.java index b4aaf5b..a8239ba 100644 --- a/core/java/android/net/wimax/WimaxManagerConstants.java +++ b/core/java/android/net/wimax/WimaxManagerConstants.java @@ -67,11 +67,21 @@ public class WimaxManagerConstants public static final int NET_4G_STATE_DISABLED = 1; /** + * Indicatates Wimax is disabling. + */ + public static final int NET_4G_STATE_DISABLING = 0; + + /** * Indicatates Wimax is enabled. */ public static final int NET_4G_STATE_ENABLED = 3; /** + * Indicatates Wimax is enabling. + */ + public static final int NET_4G_STATE_ENABLING = 2; + + /** * Indicatates Wimax status is known. */ public static final int NET_4G_STATE_UNKNOWN = 4; @@ -101,4 +111,9 @@ public class WimaxManagerConstants */ public static final int WIMAX_STATE_DISCONNECTED = 9; + /** + * Constants for HTC/SQN WiMAX implementation + */ + public static final String WIMAX_ENABLED_CHANGED_ACTION = "com.htc.net.wimax.WIMAX_ENABLED_CHANGED"; + public static final String CURRENT_WIMAX_ENABLED_STATE = "curWimaxEnabledState"; } |