Merge changes Ia51528f2,Id27a7809 into qt-dev
* changes: RESTRICT AUTOMERGE Fix unable to send file via OPP RESTRICT AUTOMERGE Fix bluetooth settings will broadcast to anywhere when some cases
This commit is contained in:
committed by
Android (Google) Code Review
commit
4074cd5e48
@@ -16,6 +16,8 @@
|
||||
|
||||
package com.android.settings.bluetooth;
|
||||
|
||||
import static android.view.WindowManager.LayoutParams.SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS;
|
||||
|
||||
import android.bluetooth.BluetoothDevice;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
@@ -30,12 +32,11 @@ import android.widget.TextView;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
|
||||
import com.android.internal.annotations.VisibleForTesting;
|
||||
import com.android.internal.app.AlertActivity;
|
||||
import com.android.internal.app.AlertController;
|
||||
import com.android.settings.R;
|
||||
|
||||
import static android.view.WindowManager.LayoutParams.SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS;
|
||||
|
||||
/**
|
||||
* BluetoothPermissionActivity shows a dialog for accepting incoming
|
||||
* profile connection request from untrusted devices.
|
||||
@@ -51,8 +52,6 @@ public class BluetoothPermissionActivity extends AlertActivity implements
|
||||
private TextView messageView;
|
||||
private Button mOkButton;
|
||||
private BluetoothDevice mDevice;
|
||||
private String mReturnPackage = null;
|
||||
private String mReturnClass = null;
|
||||
|
||||
private int mRequestType = 0;
|
||||
private BroadcastReceiver mReceiver = new BroadcastReceiver() {
|
||||
@@ -89,8 +88,6 @@ public class BluetoothPermissionActivity extends AlertActivity implements
|
||||
}
|
||||
|
||||
mDevice = i.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
|
||||
mReturnPackage = i.getStringExtra(BluetoothDevice.EXTRA_PACKAGE_NAME);
|
||||
mReturnClass = i.getStringExtra(BluetoothDevice.EXTRA_CLASS_NAME);
|
||||
mRequestType = i.getIntExtra(BluetoothDevice.EXTRA_ACCESS_REQUEST_TYPE,
|
||||
BluetoothDevice.REQUEST_TYPE_PHONEBOOK_ACCESS);
|
||||
|
||||
@@ -202,14 +199,14 @@ public class BluetoothPermissionActivity extends AlertActivity implements
|
||||
sendReplyIntentToReceiver(false, true);
|
||||
}
|
||||
|
||||
private void sendReplyIntentToReceiver(final boolean allowed, final boolean always) {
|
||||
@VisibleForTesting
|
||||
void sendReplyIntentToReceiver(final boolean allowed, final boolean always) {
|
||||
Intent intent = new Intent(BluetoothDevice.ACTION_CONNECTION_ACCESS_REPLY);
|
||||
|
||||
if (mReturnPackage != null && mReturnClass != null) {
|
||||
intent.setClassName(mReturnPackage, mReturnClass);
|
||||
if (DEBUG) {
|
||||
Log.i(TAG, "sendReplyIntentToReceiver() Request type: " + mRequestType
|
||||
+ " mReturnPackage");
|
||||
}
|
||||
if (DEBUG) Log.i(TAG, "sendReplyIntentToReceiver() Request type: " + mRequestType +
|
||||
" mReturnPackage" + mReturnPackage + " mReturnClass" + mReturnClass);
|
||||
|
||||
intent.putExtra(BluetoothDevice.EXTRA_CONNECTION_ACCESS_RESULT,
|
||||
allowed ? BluetoothDevice.CONNECTION_ACCESS_YES
|
||||
|
@@ -56,8 +56,6 @@ public final class BluetoothPermissionRequest extends BroadcastReceiver {
|
||||
Context mContext;
|
||||
int mRequestType;
|
||||
BluetoothDevice mDevice;
|
||||
String mReturnPackage = null;
|
||||
String mReturnClass = null;
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
@@ -77,11 +75,10 @@ public final class BluetoothPermissionRequest extends BroadcastReceiver {
|
||||
mDevice = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
|
||||
mRequestType = intent.getIntExtra(BluetoothDevice.EXTRA_ACCESS_REQUEST_TYPE,
|
||||
BluetoothDevice.REQUEST_TYPE_PROFILE_CONNECTION);
|
||||
mReturnPackage = intent.getStringExtra(BluetoothDevice.EXTRA_PACKAGE_NAME);
|
||||
mReturnClass = intent.getStringExtra(BluetoothDevice.EXTRA_CLASS_NAME);
|
||||
|
||||
if (DEBUG) Log.d(TAG, "onReceive request type: " + mRequestType + " return "
|
||||
+ mReturnPackage + "," + mReturnClass);
|
||||
if (DEBUG) {
|
||||
Log.d(TAG, "onReceive request type: " + mRequestType);
|
||||
}
|
||||
|
||||
// Even if the user has already made the choice, Bluetooth still may not know that if
|
||||
// the user preference data have not been migrated from Settings app's shared
|
||||
@@ -110,8 +107,6 @@ public final class BluetoothPermissionRequest extends BroadcastReceiver {
|
||||
connectionAccessIntent.putExtra(BluetoothDevice.EXTRA_ACCESS_REQUEST_TYPE,
|
||||
mRequestType);
|
||||
connectionAccessIntent.putExtra(BluetoothDevice.EXTRA_DEVICE, mDevice);
|
||||
connectionAccessIntent.putExtra(BluetoothDevice.EXTRA_PACKAGE_NAME, mReturnPackage);
|
||||
connectionAccessIntent.putExtra(BluetoothDevice.EXTRA_CLASS_NAME, mReturnClass);
|
||||
|
||||
String deviceAddress = mDevice != null ? mDevice.getAddress() : null;
|
||||
String deviceName = mDevice != null ? mDevice.getName() : null;
|
||||
@@ -230,7 +225,7 @@ public final class BluetoothPermissionRequest extends BroadcastReceiver {
|
||||
|
||||
LocalBluetoothManager bluetoothManager = Utils.getLocalBtManager(mContext);
|
||||
CachedBluetoothDeviceManager cachedDeviceManager =
|
||||
bluetoothManager.getCachedDeviceManager();
|
||||
bluetoothManager.getCachedDeviceManager();
|
||||
CachedBluetoothDevice cachedDevice = cachedDeviceManager.findDevice(mDevice);
|
||||
if (cachedDevice == null) {
|
||||
cachedDevice = cachedDeviceManager.addDevice(mDevice);
|
||||
@@ -288,13 +283,9 @@ public final class BluetoothPermissionRequest extends BroadcastReceiver {
|
||||
private void sendReplyIntentToReceiver(final boolean allowed) {
|
||||
Intent intent = new Intent(BluetoothDevice.ACTION_CONNECTION_ACCESS_REPLY);
|
||||
|
||||
if (mReturnPackage != null && mReturnClass != null) {
|
||||
intent.setClassName(mReturnPackage, mReturnClass);
|
||||
}
|
||||
|
||||
intent.putExtra(BluetoothDevice.EXTRA_CONNECTION_ACCESS_RESULT,
|
||||
allowed ? BluetoothDevice.CONNECTION_ACCESS_YES
|
||||
: BluetoothDevice.CONNECTION_ACCESS_NO);
|
||||
allowed ? BluetoothDevice.CONNECTION_ACCESS_YES
|
||||
: BluetoothDevice.CONNECTION_ACCESS_NO);
|
||||
intent.putExtra(BluetoothDevice.EXTRA_DEVICE, mDevice);
|
||||
intent.putExtra(BluetoothDevice.EXTRA_ACCESS_REQUEST_TYPE, mRequestType);
|
||||
mContext.sendBroadcast(intent, android.Manifest.permission.BLUETOOTH_ADMIN);
|
||||
|
@@ -18,6 +18,7 @@ package com.android.settings.bluetooth;
|
||||
|
||||
import static android.os.UserManager.DISALLOW_CONFIG_BLUETOOTH;
|
||||
|
||||
import android.Manifest;
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.bluetooth.BluetoothAdapter;
|
||||
import android.bluetooth.BluetoothDevice;
|
||||
@@ -26,12 +27,15 @@ import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.os.UserManager;
|
||||
import android.util.Log;
|
||||
import android.text.TextUtils;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.password.PasswordUtils;
|
||||
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
|
||||
import com.android.settingslib.core.AbstractPreferenceController;
|
||||
|
||||
@@ -47,10 +51,16 @@ public final class DevicePickerFragment extends DeviceListPreferenceFragment {
|
||||
|
||||
@VisibleForTesting
|
||||
BluetoothProgressCategory mAvailableDevicesCategory;
|
||||
@VisibleForTesting
|
||||
Context mContext;
|
||||
@VisibleForTesting
|
||||
String mLaunchPackage;
|
||||
@VisibleForTesting
|
||||
String mLaunchClass;
|
||||
@VisibleForTesting
|
||||
String mCallingAppPackageName;
|
||||
|
||||
private boolean mNeedAuth;
|
||||
private String mLaunchPackage;
|
||||
private String mLaunchClass;
|
||||
private boolean mScanAllowed;
|
||||
|
||||
public DevicePickerFragment() {
|
||||
@@ -84,6 +94,13 @@ public final class DevicePickerFragment extends DeviceListPreferenceFragment {
|
||||
getActivity().setTitle(getString(R.string.device_picker));
|
||||
UserManager um = (UserManager) getSystemService(Context.USER_SERVICE);
|
||||
mScanAllowed = !um.hasUserRestriction(DISALLOW_CONFIG_BLUETOOTH);
|
||||
mCallingAppPackageName = PasswordUtils.getCallingAppPackageName(
|
||||
getActivity().getActivityToken());
|
||||
if (!TextUtils.equals(mCallingAppPackageName, mLaunchPackage)) {
|
||||
Log.w(TAG, "sendDevicePickedIntent() launch package name is not equivalent to"
|
||||
+ " calling package name!");
|
||||
}
|
||||
mContext = getContext();
|
||||
setHasOptionsMenu(true);
|
||||
}
|
||||
|
||||
@@ -190,8 +207,11 @@ public final class DevicePickerFragment extends DeviceListPreferenceFragment {
|
||||
Intent intent = new Intent(BluetoothDevicePicker.ACTION_DEVICE_SELECTED);
|
||||
intent.putExtra(BluetoothDevice.EXTRA_DEVICE, device);
|
||||
if (mLaunchPackage != null && mLaunchClass != null) {
|
||||
intent.setClassName(mLaunchPackage, mLaunchClass);
|
||||
if (TextUtils.equals(mCallingAppPackageName, mLaunchPackage)) {
|
||||
intent.setClassName(mLaunchPackage, mLaunchClass);
|
||||
}
|
||||
}
|
||||
getActivity().sendBroadcast(intent);
|
||||
|
||||
mContext.sendBroadcast(intent, Manifest.permission.BLUETOOTH_ADMIN);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user