Loading core/java/com/android/internal/util/cm/QSConstants.java 0 → 100644 +66 −0 Original line number Diff line number Diff line /* * Copyright (C) 2015 The CyanogenMod Open Source 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 com.android.internal.util.cm; import java.util.ArrayList; public class QSConstants { private QSConstants() {} public static final String TILE_WIFI = "wifi"; public static final String TILE_BLUETOOTH = "bt"; public static final String TILE_INVERSION = "inversion"; public static final String TILE_CELLULAR = "cell"; public static final String TILE_AIRPLANE = "airplane"; public static final String TILE_ROTATION = "rotation"; public static final String TILE_FLASHLIGHT = "flashlight"; public static final String TILE_LOCATION = "location"; public static final String TILE_CAST = "cast"; public static final String TILE_HOTSPOT = "hotspot"; public static final String TILE_NOTIFICATIONS = "notifications"; public static final String TILE_DATA = "data"; public static final String TILE_ROAMING = "roaming"; public static final String TILE_DDS = "dds"; public static final String TILE_APN = "apn"; // Order matters protected static final ArrayList<String> TILES_DEFAULT = new ArrayList<String>(); static { TILES_DEFAULT.add(TILE_WIFI); TILES_DEFAULT.add(TILE_BLUETOOTH); TILES_DEFAULT.add(TILE_CELLULAR); TILES_DEFAULT.add(TILE_AIRPLANE); TILES_DEFAULT.add(TILE_ROTATION); TILES_DEFAULT.add(TILE_FLASHLIGHT); TILES_DEFAULT.add(TILE_LOCATION); TILES_DEFAULT.add(TILE_CAST); } protected static final ArrayList<String> TILES_AVAILABLE = new ArrayList<String>(); static { TILES_AVAILABLE.addAll(TILES_DEFAULT); TILES_AVAILABLE.add(TILE_INVERSION); TILES_AVAILABLE.add(TILE_HOTSPOT); TILES_AVAILABLE.add(TILE_NOTIFICATIONS); TILES_AVAILABLE.add(TILE_DATA); TILES_AVAILABLE.add(TILE_ROAMING); TILES_AVAILABLE.add(TILE_DDS); TILES_AVAILABLE.add(TILE_APN); } } core/java/com/android/internal/util/cm/QSUtils.java 0 → 100644 +126 −0 Original line number Diff line number Diff line /* * Copyright (C) 2015 The CyanogenMod Open Source 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 com.android.internal.util.cm; import android.bluetooth.BluetoothAdapter; import android.content.Context; import android.hardware.camera2.CameraAccessException; import android.hardware.camera2.CameraCharacteristics; import android.hardware.camera2.CameraManager; import android.net.ConnectivityManager; import android.telephony.TelephonyManager; import android.text.TextUtils; import java.util.Iterator; import java.util.List; public class QSUtils { private static boolean sAvailableTilesFiltered; private QSUtils() {} public static List<String> getAvailableTiles(Context context) { filterTiles(context); return QSConstants.TILES_AVAILABLE; } public static List<String> getDefaultTiles(Context context) { filterTiles(context); return QSConstants.TILES_DEFAULT; } public static String getDefaultTilesAsString(Context context) { List<String> list = getDefaultTiles(context); return TextUtils.join(",", list); } private static void filterTiles(Context context) { if (!sAvailableTilesFiltered) { boolean deviceSupportsMobile = deviceSupportsMobileData(context); // Tiles that need conditional filtering Iterator<String> iterator = QSConstants.TILES_AVAILABLE.iterator(); while (iterator.hasNext()) { String tileKey = iterator.next(); boolean removeTile = false; switch (tileKey) { case QSConstants.TILE_CELLULAR: case QSConstants.TILE_HOTSPOT: case QSConstants.TILE_DATA: case QSConstants.TILE_ROAMING: case QSConstants.TILE_APN: removeTile = !deviceSupportsMobile; break; case QSConstants.TILE_DDS: removeTile = !deviceSupportsDdsSupported(context); break; case QSConstants.TILE_FLASHLIGHT: removeTile = !deviceSupportsFlashLight(context); break; case QSConstants.TILE_BLUETOOTH: removeTile = !deviceSupportsBluetooth(); break; } if (removeTile) { iterator.remove(); QSConstants.TILES_DEFAULT.remove(tileKey); } } sAvailableTilesFiltered = true; } } private static boolean deviceSupportsDdsSupported(Context context) { TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); return tm.isMultiSimEnabled() && tm.getMultiSimConfiguration() == TelephonyManager.MultiSimVariants.DSDA; } public static boolean deviceSupportsMobileData(Context ctx) { ConnectivityManager cm = (ConnectivityManager) ctx.getSystemService( Context.CONNECTIVITY_SERVICE); return cm.isNetworkSupported(ConnectivityManager.TYPE_MOBILE); } public static boolean deviceSupportsBluetooth() { return BluetoothAdapter.getDefaultAdapter() != null; } public static boolean deviceSupportsFlashLight(Context context) { CameraManager cameraManager = (CameraManager) context.getSystemService( Context.CAMERA_SERVICE); try { String[] ids = cameraManager.getCameraIdList(); for (String id : ids) { CameraCharacteristics c = cameraManager.getCameraCharacteristics(id); Boolean flashAvailable = c.get(CameraCharacteristics.FLASH_INFO_AVAILABLE); Integer lensFacing = c.get(CameraCharacteristics.LENS_FACING); if (flashAvailable != null && flashAvailable && lensFacing != null && lensFacing == CameraCharacteristics.LENS_FACING_BACK) { return true; } } } catch (CameraAccessException e) { // Ignore } return false; } } packages/SystemUI/src/com/android/systemui/statusbar/phone/QSTileHost.java +49 −23 Original line number Diff line number Diff line Loading @@ -30,6 +30,8 @@ import android.provider.Settings; import android.telephony.TelephonyManager; import android.util.Log; import com.android.internal.util.cm.QSConstants; import com.android.internal.util.cm.QSUtils; import com.android.systemui.R; import com.android.systemui.qs.QSTile; import com.android.systemui.qs.tiles.AirplaneModeTile; Loading Loading @@ -247,7 +249,10 @@ public class QSTileHost implements QSTile.Host { } final LinkedHashMap<String, QSTile<?>> newTiles = new LinkedHashMap<>(); for (String tileSpec : tileSpecs) { newTiles.put(tileSpec, createTile(tileSpec)); QSTile<?> t = createTile(tileSpec); if (t != null) { newTiles.put(tileSpec, t); } } mTiles.clear(); Loading @@ -258,28 +263,49 @@ public class QSTileHost implements QSTile.Host { } private QSTile<?> createTile(String tileSpec) { if (tileSpec.equals("wifi")) return new WifiTile(this); else if (tileSpec.equals("bt")) return new BluetoothTile(this); else if (tileSpec.equals("inversion")) return new ColorInversionTile(this); else if (tileSpec.equals("cell")) return new CellularTile(this); else if (tileSpec.equals("airplane")) return new AirplaneModeTile(this); else if (tileSpec.equals("rotation")) return new RotationLockTile(this); else if (tileSpec.equals("flashlight")) return new FlashlightTile(this); else if (tileSpec.equals("location")) return new LocationTile(this); else if (tileSpec.equals("cast")) return new CastTile(this); else if (tileSpec.equals("hotspot")) return new HotspotTile(this); else if (tileSpec.equals("notifications")) return new NotificationsTile(this); else if (tileSpec.equals("data") && mConnectivityManager.isNetworkSupported(ConnectivityManager.TYPE_MOBILE)) if (tileSpec.startsWith(IntentTile.PREFIX)) { return IntentTile.create(this, tileSpec); } // Ensure tile is supported on this device if (!QSUtils.getAvailableTiles(mContext).contains(tileSpec)) { return null; } switch (tileSpec) { case QSConstants.TILE_WIFI: return new WifiTile(this); case QSConstants.TILE_BLUETOOTH: return new BluetoothTile(this); case QSConstants.TILE_INVERSION: return new ColorInversionTile(this); case QSConstants.TILE_CELLULAR: return new CellularTile(this); case QSConstants.TILE_AIRPLANE: return new AirplaneModeTile(this); case QSConstants.TILE_ROTATION: return new RotationLockTile(this); case QSConstants.TILE_FLASHLIGHT: return new FlashlightTile(this); case QSConstants.TILE_LOCATION: return new LocationTile(this); case QSConstants.TILE_CAST: return new CastTile(this); case QSConstants.TILE_HOTSPOT: return new HotspotTile(this); case QSConstants.TILE_NOTIFICATIONS: return new NotificationsTile(this); case QSConstants.TILE_DATA: return new DataTile(this); else if (tileSpec.equals("roaming")) return new RoamingTile(this); else if (tileSpec.equals("dds") && mTelephonyManager.isMultiSimEnabled() && (mTelephonyManager.getMultiSimConfiguration() == TelephonyManager.MultiSimVariants.DSDA)) case QSConstants.TILE_ROAMING: return new RoamingTile(this); case QSConstants.TILE_DDS: return new DdsTile(this); else if (tileSpec.equals("apn")) return new ApnTile(this); else if (tileSpec.startsWith(IntentTile.PREFIX)) return IntentTile.create(this,tileSpec); else throw new IllegalArgumentException("Bad tile spec: " + tileSpec); case QSConstants.TILE_APN: return new ApnTile(this); default: throw new IllegalArgumentException("Bad tile spec: " + tileSpec); } } private List<String> loadTileSpecs() { Loading Loading
core/java/com/android/internal/util/cm/QSConstants.java 0 → 100644 +66 −0 Original line number Diff line number Diff line /* * Copyright (C) 2015 The CyanogenMod Open Source 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 com.android.internal.util.cm; import java.util.ArrayList; public class QSConstants { private QSConstants() {} public static final String TILE_WIFI = "wifi"; public static final String TILE_BLUETOOTH = "bt"; public static final String TILE_INVERSION = "inversion"; public static final String TILE_CELLULAR = "cell"; public static final String TILE_AIRPLANE = "airplane"; public static final String TILE_ROTATION = "rotation"; public static final String TILE_FLASHLIGHT = "flashlight"; public static final String TILE_LOCATION = "location"; public static final String TILE_CAST = "cast"; public static final String TILE_HOTSPOT = "hotspot"; public static final String TILE_NOTIFICATIONS = "notifications"; public static final String TILE_DATA = "data"; public static final String TILE_ROAMING = "roaming"; public static final String TILE_DDS = "dds"; public static final String TILE_APN = "apn"; // Order matters protected static final ArrayList<String> TILES_DEFAULT = new ArrayList<String>(); static { TILES_DEFAULT.add(TILE_WIFI); TILES_DEFAULT.add(TILE_BLUETOOTH); TILES_DEFAULT.add(TILE_CELLULAR); TILES_DEFAULT.add(TILE_AIRPLANE); TILES_DEFAULT.add(TILE_ROTATION); TILES_DEFAULT.add(TILE_FLASHLIGHT); TILES_DEFAULT.add(TILE_LOCATION); TILES_DEFAULT.add(TILE_CAST); } protected static final ArrayList<String> TILES_AVAILABLE = new ArrayList<String>(); static { TILES_AVAILABLE.addAll(TILES_DEFAULT); TILES_AVAILABLE.add(TILE_INVERSION); TILES_AVAILABLE.add(TILE_HOTSPOT); TILES_AVAILABLE.add(TILE_NOTIFICATIONS); TILES_AVAILABLE.add(TILE_DATA); TILES_AVAILABLE.add(TILE_ROAMING); TILES_AVAILABLE.add(TILE_DDS); TILES_AVAILABLE.add(TILE_APN); } }
core/java/com/android/internal/util/cm/QSUtils.java 0 → 100644 +126 −0 Original line number Diff line number Diff line /* * Copyright (C) 2015 The CyanogenMod Open Source 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 com.android.internal.util.cm; import android.bluetooth.BluetoothAdapter; import android.content.Context; import android.hardware.camera2.CameraAccessException; import android.hardware.camera2.CameraCharacteristics; import android.hardware.camera2.CameraManager; import android.net.ConnectivityManager; import android.telephony.TelephonyManager; import android.text.TextUtils; import java.util.Iterator; import java.util.List; public class QSUtils { private static boolean sAvailableTilesFiltered; private QSUtils() {} public static List<String> getAvailableTiles(Context context) { filterTiles(context); return QSConstants.TILES_AVAILABLE; } public static List<String> getDefaultTiles(Context context) { filterTiles(context); return QSConstants.TILES_DEFAULT; } public static String getDefaultTilesAsString(Context context) { List<String> list = getDefaultTiles(context); return TextUtils.join(",", list); } private static void filterTiles(Context context) { if (!sAvailableTilesFiltered) { boolean deviceSupportsMobile = deviceSupportsMobileData(context); // Tiles that need conditional filtering Iterator<String> iterator = QSConstants.TILES_AVAILABLE.iterator(); while (iterator.hasNext()) { String tileKey = iterator.next(); boolean removeTile = false; switch (tileKey) { case QSConstants.TILE_CELLULAR: case QSConstants.TILE_HOTSPOT: case QSConstants.TILE_DATA: case QSConstants.TILE_ROAMING: case QSConstants.TILE_APN: removeTile = !deviceSupportsMobile; break; case QSConstants.TILE_DDS: removeTile = !deviceSupportsDdsSupported(context); break; case QSConstants.TILE_FLASHLIGHT: removeTile = !deviceSupportsFlashLight(context); break; case QSConstants.TILE_BLUETOOTH: removeTile = !deviceSupportsBluetooth(); break; } if (removeTile) { iterator.remove(); QSConstants.TILES_DEFAULT.remove(tileKey); } } sAvailableTilesFiltered = true; } } private static boolean deviceSupportsDdsSupported(Context context) { TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); return tm.isMultiSimEnabled() && tm.getMultiSimConfiguration() == TelephonyManager.MultiSimVariants.DSDA; } public static boolean deviceSupportsMobileData(Context ctx) { ConnectivityManager cm = (ConnectivityManager) ctx.getSystemService( Context.CONNECTIVITY_SERVICE); return cm.isNetworkSupported(ConnectivityManager.TYPE_MOBILE); } public static boolean deviceSupportsBluetooth() { return BluetoothAdapter.getDefaultAdapter() != null; } public static boolean deviceSupportsFlashLight(Context context) { CameraManager cameraManager = (CameraManager) context.getSystemService( Context.CAMERA_SERVICE); try { String[] ids = cameraManager.getCameraIdList(); for (String id : ids) { CameraCharacteristics c = cameraManager.getCameraCharacteristics(id); Boolean flashAvailable = c.get(CameraCharacteristics.FLASH_INFO_AVAILABLE); Integer lensFacing = c.get(CameraCharacteristics.LENS_FACING); if (flashAvailable != null && flashAvailable && lensFacing != null && lensFacing == CameraCharacteristics.LENS_FACING_BACK) { return true; } } } catch (CameraAccessException e) { // Ignore } return false; } }
packages/SystemUI/src/com/android/systemui/statusbar/phone/QSTileHost.java +49 −23 Original line number Diff line number Diff line Loading @@ -30,6 +30,8 @@ import android.provider.Settings; import android.telephony.TelephonyManager; import android.util.Log; import com.android.internal.util.cm.QSConstants; import com.android.internal.util.cm.QSUtils; import com.android.systemui.R; import com.android.systemui.qs.QSTile; import com.android.systemui.qs.tiles.AirplaneModeTile; Loading Loading @@ -247,7 +249,10 @@ public class QSTileHost implements QSTile.Host { } final LinkedHashMap<String, QSTile<?>> newTiles = new LinkedHashMap<>(); for (String tileSpec : tileSpecs) { newTiles.put(tileSpec, createTile(tileSpec)); QSTile<?> t = createTile(tileSpec); if (t != null) { newTiles.put(tileSpec, t); } } mTiles.clear(); Loading @@ -258,28 +263,49 @@ public class QSTileHost implements QSTile.Host { } private QSTile<?> createTile(String tileSpec) { if (tileSpec.equals("wifi")) return new WifiTile(this); else if (tileSpec.equals("bt")) return new BluetoothTile(this); else if (tileSpec.equals("inversion")) return new ColorInversionTile(this); else if (tileSpec.equals("cell")) return new CellularTile(this); else if (tileSpec.equals("airplane")) return new AirplaneModeTile(this); else if (tileSpec.equals("rotation")) return new RotationLockTile(this); else if (tileSpec.equals("flashlight")) return new FlashlightTile(this); else if (tileSpec.equals("location")) return new LocationTile(this); else if (tileSpec.equals("cast")) return new CastTile(this); else if (tileSpec.equals("hotspot")) return new HotspotTile(this); else if (tileSpec.equals("notifications")) return new NotificationsTile(this); else if (tileSpec.equals("data") && mConnectivityManager.isNetworkSupported(ConnectivityManager.TYPE_MOBILE)) if (tileSpec.startsWith(IntentTile.PREFIX)) { return IntentTile.create(this, tileSpec); } // Ensure tile is supported on this device if (!QSUtils.getAvailableTiles(mContext).contains(tileSpec)) { return null; } switch (tileSpec) { case QSConstants.TILE_WIFI: return new WifiTile(this); case QSConstants.TILE_BLUETOOTH: return new BluetoothTile(this); case QSConstants.TILE_INVERSION: return new ColorInversionTile(this); case QSConstants.TILE_CELLULAR: return new CellularTile(this); case QSConstants.TILE_AIRPLANE: return new AirplaneModeTile(this); case QSConstants.TILE_ROTATION: return new RotationLockTile(this); case QSConstants.TILE_FLASHLIGHT: return new FlashlightTile(this); case QSConstants.TILE_LOCATION: return new LocationTile(this); case QSConstants.TILE_CAST: return new CastTile(this); case QSConstants.TILE_HOTSPOT: return new HotspotTile(this); case QSConstants.TILE_NOTIFICATIONS: return new NotificationsTile(this); case QSConstants.TILE_DATA: return new DataTile(this); else if (tileSpec.equals("roaming")) return new RoamingTile(this); else if (tileSpec.equals("dds") && mTelephonyManager.isMultiSimEnabled() && (mTelephonyManager.getMultiSimConfiguration() == TelephonyManager.MultiSimVariants.DSDA)) case QSConstants.TILE_ROAMING: return new RoamingTile(this); case QSConstants.TILE_DDS: return new DdsTile(this); else if (tileSpec.equals("apn")) return new ApnTile(this); else if (tileSpec.startsWith(IntentTile.PREFIX)) return IntentTile.create(this,tileSpec); else throw new IllegalArgumentException("Bad tile spec: " + tileSpec); case QSConstants.TILE_APN: return new ApnTile(this); default: throw new IllegalArgumentException("Bad tile spec: " + tileSpec); } } private List<String> loadTileSpecs() { Loading