diff options
| -rw-r--r-- | core/res/res/values/config.xml | 12 | ||||
| -rw-r--r-- | core/res/res/values/strings.xml | 6 | ||||
| -rw-r--r-- | core/res/res/values/symbols.xml | 4 | ||||
| -rw-r--r-- | packages/SystemUI/AndroidManifest.xml | 19 | ||||
| -rw-r--r-- | packages/SystemUI/res/values/strings.xml | 18 | ||||
| -rw-r--r-- | packages/SystemUI/src/com/android/systemui/wifi/WifiDebuggingActivity.java | 223 | ||||
| -rw-r--r-- | packages/SystemUI/src/com/android/systemui/wifi/WifiDebuggingSecondaryUserActivity.java | 113 |
7 files changed, 395 insertions, 0 deletions
diff --git a/core/res/res/values/config.xml b/core/res/res/values/config.xml index 054195588102..c52c53f9549a 100644 --- a/core/res/res/values/config.xml +++ b/core/res/res/values/config.xml @@ -2718,6 +2718,18 @@ <string name="config_customAdbPublicKeyConfirmationSecondaryUserComponent" >com.android.systemui/com.android.systemui.usb.UsbDebuggingSecondaryUserActivity</string> + <!-- Name of the activity or service that prompts the user to reject, accept, or whitelist + a wireless network for wireless debugging. + Can be customized for other product types --> + <string name="config_customAdbWifiNetworkConfirmationComponent" + >com.android.systemui/com.android.systemui.wifi.WifiDebuggingActivity</string> + + <!-- Name of the activity that prompts the secondary user to acknowledge she/he needs to + switch to the primary user to enable wireless debugging. + Can be customized for other product types --> + <string name="config_customAdbWifiNetworkConfirmationSecondaryUserComponent" + >com.android.systemui/com.android.systemui.wifi.WifiDebuggingSecondaryUserActivity</string> + <!-- Name of the dialog that is used to request the user's consent for a Platform VPN --> <string name="config_platformVpnConfirmDialogComponent" translatable="false" >com.android.vpndialogs/com.android.vpndialogs.PlatformVpnConfirmDialog</string> diff --git a/core/res/res/values/strings.xml b/core/res/res/values/strings.xml index 9bc0d969aed9..175870298f91 100644 --- a/core/res/res/values/strings.xml +++ b/core/res/res/values/strings.xml @@ -3642,6 +3642,12 @@ <!-- Message of notification shown when ADB is actively connected to the phone. --> <string name="adb_active_notification_message">Tap to turn off USB debugging</string> <string name="adb_active_notification_message" product="tv">Select to disable USB debugging.</string> + <!-- Title of notification shown when ADB Wireless is actively connected to the phone. [CHAR LIMIT=NONE] --> + <string name="adbwifi_active_notification_title">Wireless debugging connected</string> + <!-- Message of notification shown when ADB Wireless is actively connected to the phone. [CHAR LIMIT=NONE] --> + <string name="adbwifi_active_notification_message">Tap to turn off wireless debugging</string> + <!-- Message of notification shown when ADB Wireless is actively connected to the TV. [CHAR LIMIT=NONE] --> + <string name="adbwifi_active_notification_message" product="tv">Select to disable wireless debugging.</string> <!-- Title of notification shown when Test Harness Mode is enabled. [CHAR LIMIT=NONE] --> <string name="test_harness_mode_notification_title">Test Harness Mode enabled</string> diff --git a/core/res/res/values/symbols.xml b/core/res/res/values/symbols.xml index d1e449e13e0f..62cc7b3fc65e 100644 --- a/core/res/res/values/symbols.xml +++ b/core/res/res/values/symbols.xml @@ -2090,6 +2090,8 @@ <java-symbol type="string" name="accessibility_binding_label" /> <java-symbol type="string" name="adb_active_notification_message" /> <java-symbol type="string" name="adb_active_notification_title" /> + <java-symbol type="string" name="adbwifi_active_notification_message" /> + <java-symbol type="string" name="adbwifi_active_notification_title" /> <java-symbol type="string" name="test_harness_mode_notification_title" /> <java-symbol type="string" name="test_harness_mode_notification_message" /> <java-symbol type="string" name="taking_remote_bugreport_notification_title" /> @@ -2232,6 +2234,8 @@ <java-symbol type="fraction" name="config_maximumScreenDimRatio" /> <java-symbol type="string" name="config_customAdbPublicKeyConfirmationComponent" /> <java-symbol type="string" name="config_customAdbPublicKeyConfirmationSecondaryUserComponent" /> + <java-symbol type="string" name="config_customAdbWifiNetworkConfirmationComponent" /> + <java-symbol type="string" name="config_customAdbWifiNetworkConfirmationSecondaryUserComponent" /> <java-symbol type="string" name="config_customVpnConfirmDialogComponent" /> <java-symbol type="string" name="config_customVpnAlwaysOnDisconnectedDialogComponent" /> <java-symbol type="string" name="config_platformVpnConfirmDialogComponent" /> diff --git a/packages/SystemUI/AndroidManifest.xml b/packages/SystemUI/AndroidManifest.xml index 262365da3a06..a9fa2ac28e89 100644 --- a/packages/SystemUI/AndroidManifest.xml +++ b/packages/SystemUI/AndroidManifest.xml @@ -430,6 +430,25 @@ android:excludeFromRecents="true"> </activity> + <!-- started from WirelessDebuggingManager --> + <activity android:name=".wifi.WifiDebuggingActivity" + android:permission="android.permission.MANAGE_DEBUGGING" + android:theme="@style/Theme.SystemUI.Dialog.Alert" + android:finishOnCloseSystemDialogs="true" + android:excludeFromRecents="true"> + </activity> + <activity-alias + android:name=".WifiDebuggingActivityAlias" + android:permission="android.permission.DUMP" + android:targetActivity=".wifi.WifiDebuggingActivity" + android:exported="true"> + </activity-alias> + <activity android:name=".wifi.WifiDebuggingSecondaryUserActivity" + android:theme="@style/Theme.SystemUI.Dialog.Alert" + android:finishOnCloseSystemDialogs="true" + android:excludeFromRecents="true"> + </activity> + <!-- started from NetworkPolicyManagerService --> <activity android:name=".net.NetworkOverLimitActivity" diff --git a/packages/SystemUI/res/values/strings.xml b/packages/SystemUI/res/values/strings.xml index d58f83fb8a3b..f5ccc53aaa24 100644 --- a/packages/SystemUI/res/values/strings.xml +++ b/packages/SystemUI/res/values/strings.xml @@ -162,6 +162,24 @@ <!-- Message of notification shown when trying to enable USB debugging but a secondary user is the current foreground user. --> <string name="usb_debugging_secondary_user_message">The user currently signed in to this device can\'t turn on USB debugging. To use this feature, switch to the primary user.</string> + <!-- Title of confirmation dialog for wireless debugging [CHAR LIMIT=NONE] --> + <string name="wifi_debugging_title">Allow wireless debugging on this network?</string> + + <!-- Message of confirmation dialog for wireless debugging [CHAR LIMIT=NONE] --> + <string name="wifi_debugging_message">Network Name (SSID)\n<xliff:g id="ssid" example="My wifi">%1$s</xliff:g>\n\nWi\u2011Fi Address (BSSID)\n<xliff:g id="bssid" example="AB:CD:EF:12:34:56">%2$s</xliff:g></string> + + <!-- Option to always allow wireless debugging on this network [CHAR LIMIT=NONE] --> + <string name="wifi_debugging_always">Always allow on this network</string> + + <!-- Button label for confirming acceptance of enabling wireless debugging [CHAR LIMIT=15] --> + <string name="wifi_debugging_allow">Allow</string> + + <!-- Title of notification shown when trying to enable wireless debugging but a secondary user is the current foreground user. [CHAR LIMIT=NONE] --> + <string name="wifi_debugging_secondary_user_title">Wireless debugging not allowed</string> + + <!-- Message of notification shown when trying to enable wireless debugging but a secondary user is the current foreground user. [CHAR LIMIT=NONE] --> + <string name="wifi_debugging_secondary_user_message">The user currently signed in to this device can\u2019t turn on wireless debugging. To use this feature, switch to the primary user.</string> + <!-- Title of USB contaminant presence dialog [CHAR LIMIT=NONE] --> <string name="usb_contaminant_title">USB port disabled</string> diff --git a/packages/SystemUI/src/com/android/systemui/wifi/WifiDebuggingActivity.java b/packages/SystemUI/src/com/android/systemui/wifi/WifiDebuggingActivity.java new file mode 100644 index 000000000000..a94af24fc843 --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/wifi/WifiDebuggingActivity.java @@ -0,0 +1,223 @@ +/* + * Copyright (C) 2012 The Android 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.wifi; + +import android.app.Activity; +import android.app.AlertDialog; +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.DialogInterface; +import android.content.Intent; +import android.content.IntentFilter; +import android.debug.IAdbManager; +import android.net.ConnectivityManager; +import android.net.NetworkInfo; +import android.net.wifi.WifiInfo; +import android.net.wifi.WifiManager; +import android.os.Bundle; +import android.os.IBinder; +import android.os.ServiceManager; +import android.util.EventLog; +import android.util.Log; +import android.view.LayoutInflater; +import android.view.MotionEvent; +import android.view.View; +import android.view.Window; +import android.view.WindowManager; +import android.widget.CheckBox; +import android.widget.Toast; + +import com.android.internal.app.AlertActivity; +import com.android.internal.app.AlertController; +import com.android.systemui.R; + +/** + * Alerts the user of an untrusted network when enabling wireless debugging. + * The user can either deny, allow, or allow with the "always allow on this + * network" checked. + */ +public class WifiDebuggingActivity extends AlertActivity + implements DialogInterface.OnClickListener { + private static final String TAG = "WifiDebuggingActivity"; + + private CheckBox mAlwaysAllow; + // Notifies when wifi is disabled, or the network changed + private WifiChangeReceiver mWifiChangeReceiver; + private WifiManager mWifiManager; + private String mBssid; + private boolean mClicked = false; + + @Override + public void onCreate(Bundle icicle) { + Window window = getWindow(); + window.addSystemFlags( + WindowManager.LayoutParams.SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS); + window.setType(WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG); + + super.onCreate(icicle); + + + mWifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE); + mWifiChangeReceiver = new WifiChangeReceiver(this); + + Intent intent = getIntent(); + String ssid = intent.getStringExtra("ssid"); + mBssid = intent.getStringExtra("bssid"); + + if (ssid == null || mBssid == null) { + finish(); + return; + } + + final AlertController.AlertParams ap = mAlertParams; + ap.mTitle = getString(R.string.wifi_debugging_title); + ap.mMessage = getString(R.string.wifi_debugging_message, ssid, mBssid); + ap.mPositiveButtonText = getString(R.string.wifi_debugging_allow); + ap.mNegativeButtonText = getString(android.R.string.cancel); + ap.mPositiveButtonListener = this; + ap.mNegativeButtonListener = this; + + // add "always allow" checkbox + LayoutInflater inflater = LayoutInflater.from(ap.mContext); + View checkbox = inflater.inflate(com.android.internal.R.layout.always_use_checkbox, null); + mAlwaysAllow = (CheckBox) checkbox.findViewById(com.android.internal.R.id.alwaysUse); + mAlwaysAllow.setText(getString(R.string.wifi_debugging_always)); + ap.mView = checkbox; + window.setCloseOnTouchOutside(false); + + setupAlert(); + + // adding touch listener on affirmative button - checks if window is obscured + // if obscured, do not let user give permissions (could be tapjacking involved) + final View.OnTouchListener filterTouchListener = (View v, MotionEvent event) -> { + // Filter obscured touches by consuming them. + if (((event.getFlags() & MotionEvent.FLAG_WINDOW_IS_OBSCURED) != 0) + || ((event.getFlags() & MotionEvent.FLAG_WINDOW_IS_PARTIALLY_OBSCURED) != 0)) { + if (event.getAction() == MotionEvent.ACTION_UP) { + // TODO: need a different value for safety net? + EventLog.writeEvent(0x534e4554, "62187985"); // safety net logging + Toast.makeText(v.getContext(), + R.string.touch_filtered_warning, + Toast.LENGTH_SHORT).show(); + } + return true; + } + return false; + }; + mAlert.getButton(BUTTON_POSITIVE).setOnTouchListener(filterTouchListener); + + } + + @Override + public void onWindowAttributesChanged(WindowManager.LayoutParams params) { + super.onWindowAttributesChanged(params); + } + + private class WifiChangeReceiver extends BroadcastReceiver { + private final Activity mActivity; + WifiChangeReceiver(Activity activity) { + mActivity = activity; + } + + @Override + public void onReceive(Context content, Intent intent) { + String action = intent.getAction(); + if (WifiManager.WIFI_STATE_CHANGED_ACTION.equals(action)) { + int state = intent.getIntExtra( + WifiManager.EXTRA_WIFI_STATE, WifiManager.WIFI_STATE_DISABLED); + if (state == WifiManager.WIFI_STATE_DISABLED) { + mActivity.finish(); + } + } else if (WifiManager.NETWORK_STATE_CHANGED_ACTION.equals(action)) { + NetworkInfo networkInfo = (NetworkInfo) intent.getParcelableExtra( + WifiManager.EXTRA_NETWORK_INFO); + if (networkInfo.getType() == ConnectivityManager.TYPE_WIFI) { + if (!networkInfo.isConnected()) { + mActivity.finish(); + return; + } + WifiInfo wifiInfo = mWifiManager.getConnectionInfo(); + if (wifiInfo == null || wifiInfo.getNetworkId() == -1) { + mActivity.finish(); + return; + } + String bssid = wifiInfo.getBSSID(); + if (bssid == null || bssid.isEmpty()) { + mActivity.finish(); + return; + } + if (!bssid.equals(mBssid)) { + mActivity.finish(); + return; + } + } + } + } + } + + @Override + public void onStart() { + super.onStart(); + IntentFilter filter = new IntentFilter(WifiManager.WIFI_STATE_CHANGED_ACTION); + filter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION); + registerReceiver(mWifiChangeReceiver, filter); + } + + @Override + protected void onStop() { + if (mWifiChangeReceiver != null) { + unregisterReceiver(mWifiChangeReceiver); + } + super.onStop(); + } + + @Override + protected void onDestroy() { + super.onDestroy(); + + // In the case where user dismissed the dialog, we don't get an onClick event. + // In that case, tell adb to deny the network connection. + if (!mClicked) { + try { + IBinder b = ServiceManager.getService(ADB_SERVICE); + IAdbManager service = IAdbManager.Stub.asInterface(b); + service.denyWirelessDebugging(); + } catch (Exception e) { + Log.e(TAG, "Unable to notify Adb service", e); + } + } + } + + @Override + public void onClick(DialogInterface dialog, int which) { + mClicked = true; + boolean allow = (which == AlertDialog.BUTTON_POSITIVE); + boolean alwaysAllow = allow && mAlwaysAllow.isChecked(); + try { + IBinder b = ServiceManager.getService(ADB_SERVICE); + IAdbManager service = IAdbManager.Stub.asInterface(b); + if (allow) { + service.allowWirelessDebugging(alwaysAllow, mBssid); + } else { + service.denyWirelessDebugging(); + } + } catch (Exception e) { + Log.e(TAG, "Unable to notify Adb service", e); + } + finish(); + } +} diff --git a/packages/SystemUI/src/com/android/systemui/wifi/WifiDebuggingSecondaryUserActivity.java b/packages/SystemUI/src/com/android/systemui/wifi/WifiDebuggingSecondaryUserActivity.java new file mode 100644 index 000000000000..0266a84503a1 --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/wifi/WifiDebuggingSecondaryUserActivity.java @@ -0,0 +1,113 @@ +/* + * Copyright (C) 2015 The Android 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.wifi; + +import android.app.Activity; +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.DialogInterface; +import android.content.Intent; +import android.content.IntentFilter; +import android.net.ConnectivityManager; +import android.net.NetworkInfo; +import android.net.wifi.WifiInfo; +import android.net.wifi.WifiManager; +import android.os.Bundle; + +import com.android.internal.app.AlertActivity; +import com.android.internal.app.AlertController; +import com.android.systemui.R; + +/** + * Alerts the user that wireless debugging cannot be enabled by a secondary user. + */ +public class WifiDebuggingSecondaryUserActivity extends AlertActivity + implements DialogInterface.OnClickListener { + private WifiChangeReceiver mWifiChangeReceiver; + private WifiManager mWifiManager; + + @Override + public void onCreate(Bundle icicle) { + super.onCreate(icicle); + + mWifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE); + mWifiChangeReceiver = new WifiChangeReceiver(this); + + final AlertController.AlertParams ap = mAlertParams; + ap.mTitle = getString(R.string.wifi_debugging_secondary_user_title); + ap.mMessage = getString(R.string.wifi_debugging_secondary_user_message); + ap.mPositiveButtonText = getString(android.R.string.ok); + ap.mPositiveButtonListener = this; + + setupAlert(); + } + + private class WifiChangeReceiver extends BroadcastReceiver { + private final Activity mActivity; + WifiChangeReceiver(Activity activity) { + mActivity = activity; + } + + @Override + public void onReceive(Context content, Intent intent) { + String action = intent.getAction(); + if (WifiManager.WIFI_STATE_CHANGED_ACTION.equals(action)) { + int state = intent.getIntExtra( + WifiManager.EXTRA_WIFI_STATE, WifiManager.WIFI_STATE_DISABLED); + if (state == WifiManager.WIFI_STATE_DISABLED) { + mActivity.finish(); + } + } else if (WifiManager.NETWORK_STATE_CHANGED_ACTION.equals(action)) { + NetworkInfo networkInfo = (NetworkInfo) intent.getParcelableExtra( + WifiManager.EXTRA_NETWORK_INFO); + if (networkInfo.getType() == ConnectivityManager.TYPE_WIFI) { + if (!networkInfo.isConnected()) { + mActivity.finish(); + return; + } + WifiInfo wifiInfo = mWifiManager.getConnectionInfo(); + if (wifiInfo == null || wifiInfo.getNetworkId() == -1) { + mActivity.finish(); + return; + } + } + } + } + } + + @Override + public void onStart() { + super.onStart(); + + IntentFilter filter = new IntentFilter(WifiManager.WIFI_STATE_CHANGED_ACTION); + filter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION); + registerReceiver(mWifiChangeReceiver, filter); + } + + @Override + protected void onStop() { + if (mWifiChangeReceiver != null) { + unregisterReceiver(mWifiChangeReceiver); + } + super.onStop(); + } + + @Override + public void onClick(DialogInterface dialog, int which) { + finish(); + } +} |