Loading core/java/com/android/internal/util/cm/QSConstants.java +2 −0 Original line number Diff line number Diff line Loading @@ -38,6 +38,7 @@ public class QSConstants { public static final String TILE_APN = "apn"; public static final String TILE_PROFILES = "profiles"; public static final String TILE_PERFORMANCE = "performance"; public static final String TILE_ADB_NETWORK = "adb_network"; // Order matters protected static final ArrayList<String> TILES_DEFAULT = new ArrayList<String>(); Loading Loading @@ -66,5 +67,6 @@ public class QSConstants { TILES_AVAILABLE.add(TILE_APN); TILES_AVAILABLE.add(TILE_PROFILES); TILES_AVAILABLE.add(TILE_PERFORMANCE); TILES_AVAILABLE.add(TILE_ADB_NETWORK); } } packages/SystemUI/res/values/cm_strings.xml +3 −0 Original line number Diff line number Diff line Loading @@ -102,4 +102,7 @@ <string name="left_shortcut_hint">Swipe right for %1$s</string> <string name="right_shortcut_hint">Swipe left for %1$s</string> <string name="quick_settings_network_adb_enabled_label">Enabled</string> <string name="quick_settings_network_adb_disabled_label">Disabled</string> </resources> packages/SystemUI/src/com/android/systemui/qs/tiles/AdbOverNetworkTile.java 0 → 100644 +123 −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.systemui.qs.tiles; import android.content.Context; import android.content.Intent; import android.database.ContentObserver; import android.net.NetworkUtils; import android.net.Uri; import android.net.wifi.WifiInfo; import android.net.wifi.WifiManager; import android.os.UserHandle; import android.provider.Settings; import com.android.systemui.R; import com.android.systemui.qs.QSTile; import java.net.InetAddress; public class AdbOverNetworkTile extends QSTile<QSTile.BooleanState> { private static final Intent SETTINGS_DEVELOPMENT = new Intent(Settings.ACTION_APPLICATION_DEVELOPMENT_SETTINGS); @Override protected BooleanState newTileState() { return new BooleanState(); } @Override protected void handleClick() { Settings.Secure.putIntForUser(mContext.getContentResolver(), Settings.Secure.ADB_PORT, getState().value ? -1 : 5555, UserHandle.USER_CURRENT); } @Override protected void handleLongClick() { mHost.startSettingsActivity(SETTINGS_DEVELOPMENT); } @Override protected void handleUpdateState(BooleanState state, Object arg) { state.visible = isAdbEnabled(); if (!state.visible) { return; } state.value = isAdbNetworkEnabled(); state.iconId = R.drawable.ic_qs_flashlight_on; if (state.value) { WifiManager wifiManager = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE); WifiInfo wifiInfo = wifiManager.getConnectionInfo(); if (wifiInfo != null) { // if wifiInfo is not null, set the label to "hostAddress" InetAddress address = NetworkUtils.intToInetAddress(wifiInfo.getIpAddress()); state.label = address.getHostAddress(); } else { //if wifiInfo is null, set the enabled label without host address state.label = mContext.getString(R.string.quick_settings_network_adb_enabled_label); } state.iconId = R.drawable.ic_qs_network_adb_on; } else { // Otherwise set the disabled label and icon state.label = mContext.getString(R.string.quick_settings_network_adb_disabled_label); state.iconId = R.drawable.ic_qs_network_adb_off; } } private boolean isAdbEnabled() { return Settings.Secure.getInt(mContext.getContentResolver(), Settings.Global.ADB_ENABLED, 0) > 0; } private boolean isAdbNetworkEnabled() { return Settings.Secure.getInt(mContext.getContentResolver(), Settings.Secure.ADB_PORT, 0) > 0; } public AdbOverNetworkTile(Host host) { super(host); } private ContentObserver mObserver = new ContentObserver(mHandler) { @Override public void onChange(boolean selfChange, Uri uri) { refreshState(); } }; @Override public void destroy() { mContext.getContentResolver().unregisterContentObserver(mObserver); } @Override public void setListening(boolean listening) { if (listening) { mContext.getContentResolver().registerContentObserver( Settings.Secure.getUriFor(Settings.Secure.ADB_PORT), false, mObserver); mContext.getContentResolver().registerContentObserver( Settings.Secure.getUriFor(Settings.Global.ADB_ENABLED), false, mObserver); } else { mContext.getContentResolver().unregisterContentObserver(mObserver); } } } packages/SystemUI/src/com/android/systemui/statusbar/phone/QSTileHost.java +3 −0 Original line number Diff line number Diff line Loading @@ -33,6 +33,7 @@ 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.AdbOverNetworkTile; import com.android.systemui.qs.tiles.AirplaneModeTile; import com.android.systemui.qs.tiles.ApnTile; import com.android.systemui.qs.tiles.BluetoothTile; Loading Loading @@ -306,6 +307,8 @@ public class QSTileHost implements QSTile.Host { return new ProfilesTile(this); case QSConstants.TILE_PERFORMANCE: return new PerfProfileTile(this); case QSConstants.TILE_ADB_NETWORK: return new AdbOverNetworkTile(this); default: throw new IllegalArgumentException("Bad tile spec: " + tileSpec); } Loading Loading
core/java/com/android/internal/util/cm/QSConstants.java +2 −0 Original line number Diff line number Diff line Loading @@ -38,6 +38,7 @@ public class QSConstants { public static final String TILE_APN = "apn"; public static final String TILE_PROFILES = "profiles"; public static final String TILE_PERFORMANCE = "performance"; public static final String TILE_ADB_NETWORK = "adb_network"; // Order matters protected static final ArrayList<String> TILES_DEFAULT = new ArrayList<String>(); Loading Loading @@ -66,5 +67,6 @@ public class QSConstants { TILES_AVAILABLE.add(TILE_APN); TILES_AVAILABLE.add(TILE_PROFILES); TILES_AVAILABLE.add(TILE_PERFORMANCE); TILES_AVAILABLE.add(TILE_ADB_NETWORK); } }
packages/SystemUI/res/values/cm_strings.xml +3 −0 Original line number Diff line number Diff line Loading @@ -102,4 +102,7 @@ <string name="left_shortcut_hint">Swipe right for %1$s</string> <string name="right_shortcut_hint">Swipe left for %1$s</string> <string name="quick_settings_network_adb_enabled_label">Enabled</string> <string name="quick_settings_network_adb_disabled_label">Disabled</string> </resources>
packages/SystemUI/src/com/android/systemui/qs/tiles/AdbOverNetworkTile.java 0 → 100644 +123 −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.systemui.qs.tiles; import android.content.Context; import android.content.Intent; import android.database.ContentObserver; import android.net.NetworkUtils; import android.net.Uri; import android.net.wifi.WifiInfo; import android.net.wifi.WifiManager; import android.os.UserHandle; import android.provider.Settings; import com.android.systemui.R; import com.android.systemui.qs.QSTile; import java.net.InetAddress; public class AdbOverNetworkTile extends QSTile<QSTile.BooleanState> { private static final Intent SETTINGS_DEVELOPMENT = new Intent(Settings.ACTION_APPLICATION_DEVELOPMENT_SETTINGS); @Override protected BooleanState newTileState() { return new BooleanState(); } @Override protected void handleClick() { Settings.Secure.putIntForUser(mContext.getContentResolver(), Settings.Secure.ADB_PORT, getState().value ? -1 : 5555, UserHandle.USER_CURRENT); } @Override protected void handleLongClick() { mHost.startSettingsActivity(SETTINGS_DEVELOPMENT); } @Override protected void handleUpdateState(BooleanState state, Object arg) { state.visible = isAdbEnabled(); if (!state.visible) { return; } state.value = isAdbNetworkEnabled(); state.iconId = R.drawable.ic_qs_flashlight_on; if (state.value) { WifiManager wifiManager = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE); WifiInfo wifiInfo = wifiManager.getConnectionInfo(); if (wifiInfo != null) { // if wifiInfo is not null, set the label to "hostAddress" InetAddress address = NetworkUtils.intToInetAddress(wifiInfo.getIpAddress()); state.label = address.getHostAddress(); } else { //if wifiInfo is null, set the enabled label without host address state.label = mContext.getString(R.string.quick_settings_network_adb_enabled_label); } state.iconId = R.drawable.ic_qs_network_adb_on; } else { // Otherwise set the disabled label and icon state.label = mContext.getString(R.string.quick_settings_network_adb_disabled_label); state.iconId = R.drawable.ic_qs_network_adb_off; } } private boolean isAdbEnabled() { return Settings.Secure.getInt(mContext.getContentResolver(), Settings.Global.ADB_ENABLED, 0) > 0; } private boolean isAdbNetworkEnabled() { return Settings.Secure.getInt(mContext.getContentResolver(), Settings.Secure.ADB_PORT, 0) > 0; } public AdbOverNetworkTile(Host host) { super(host); } private ContentObserver mObserver = new ContentObserver(mHandler) { @Override public void onChange(boolean selfChange, Uri uri) { refreshState(); } }; @Override public void destroy() { mContext.getContentResolver().unregisterContentObserver(mObserver); } @Override public void setListening(boolean listening) { if (listening) { mContext.getContentResolver().registerContentObserver( Settings.Secure.getUriFor(Settings.Secure.ADB_PORT), false, mObserver); mContext.getContentResolver().registerContentObserver( Settings.Secure.getUriFor(Settings.Global.ADB_ENABLED), false, mObserver); } else { mContext.getContentResolver().unregisterContentObserver(mObserver); } } }
packages/SystemUI/src/com/android/systemui/statusbar/phone/QSTileHost.java +3 −0 Original line number Diff line number Diff line Loading @@ -33,6 +33,7 @@ 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.AdbOverNetworkTile; import com.android.systemui.qs.tiles.AirplaneModeTile; import com.android.systemui.qs.tiles.ApnTile; import com.android.systemui.qs.tiles.BluetoothTile; Loading Loading @@ -306,6 +307,8 @@ public class QSTileHost implements QSTile.Host { return new ProfilesTile(this); case QSConstants.TILE_PERFORMANCE: return new PerfProfileTile(this); case QSConstants.TILE_ADB_NETWORK: return new AdbOverNetworkTile(this); default: throw new IllegalArgumentException("Bad tile spec: " + tileSpec); } Loading