[adbwifi] SysUI: Add WifiDebuggingActivity.
This will prompt the user whether they trust the current wireless access point when enabling wireless debugging. Bug: 147814644 Test: make Exempt-From-Owner-Approval: already approved Change-Id: I56a7c022f26d4e3d93a22d9022f19f1b8d997d70
This commit is contained in:
parent
18797a400b
commit
21819bf32d
@ -2588,6 +2588,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>
|
||||
|
||||
<!-- Component name of the activity that shows the usb containment status. -->
|
||||
<string name="config_usbContaminantActivity" translatable="false"
|
||||
>com.android.systemui/com.android.systemui.usb.UsbContaminantActivity</string>
|
||||
|
@ -3527,6 +3527,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>
|
||||
|
@ -2009,6 +2009,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="console_running_notification_title" />
|
||||
@ -2154,6 +2156,8 @@
|
||||
<java-symbol type="integer" name="config_attentiveWarningDuration" />
|
||||
<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" />
|
||||
|
@ -457,6 +457,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"
|
||||
|
@ -168,6 +168,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>
|
||||
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
@ -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();
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user