Loading src/com/android/settings/bluetooth/BluetoothPermissionActivity.java +8 −11 Original line number Diff line number Diff line Loading @@ -16,6 +16,8 @@ package com.android.settings.bluetooth; import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS; import android.bluetooth.BluetoothDevice; import android.content.BroadcastReceiver; import android.content.Context; Loading @@ -30,6 +32,7 @@ import android.view.View; import android.widget.Button; import android.widget.TextView; import com.android.internal.annotations.VisibleForTesting; import com.android.internal.app.AlertActivity; import com.android.internal.app.AlertController; import com.android.settings.R; Loading @@ -37,8 +40,6 @@ import com.android.settingslib.bluetooth.CachedBluetoothDevice; import com.android.settingslib.bluetooth.CachedBluetoothDeviceManager; import com.android.settingslib.bluetooth.LocalBluetoothManager; import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS; /** * BluetoothPermissionActivity shows a dialog for accepting incoming * profile connection request from untrusted devices. Loading @@ -54,8 +55,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() { Loading Loading @@ -92,8 +91,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); Loading Loading @@ -231,14 +228,14 @@ public class BluetoothPermissionActivity extends AlertActivity implements sendReplyIntentToReceiver(false, always); } 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 Loading src/com/android/settings/bluetooth/BluetoothPermissionRequest.java +6 −15 Original line number Diff line number Diff line Loading @@ -49,8 +49,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) { Loading @@ -70,11 +68,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 Loading Loading @@ -103,8 +100,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; Loading Loading @@ -283,10 +278,6 @@ 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); Loading src/com/android/settings/bluetooth/DevicePickerFragment.java +42 −6 Original line number Diff line number Diff line Loading @@ -16,13 +16,23 @@ package com.android.settings.bluetooth; import static android.os.UserManager.DISALLOW_CONFIG_BLUETOOTH; import com.android.internal.annotations.VisibleForTesting; import android.Manifest; import android.app.ActivityManagerNative; import android.app.IActivityManager; import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothDevicePicker; import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.os.IBinder; import android.os.RemoteException; import android.os.UserManager; import android.util.Log; import android.text.TextUtils; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; Loading @@ -31,22 +41,28 @@ import com.android.internal.logging.MetricsProto.MetricsEvent; import com.android.settings.R; import com.android.settingslib.bluetooth.CachedBluetoothDevice; import static android.os.UserManager.DISALLOW_CONFIG_BLUETOOTH; /** * BluetoothSettings is the Settings screen for Bluetooth configuration and * connection management. */ public final class DevicePickerFragment extends DeviceListPreferenceFragment { private static final int MENU_ID_REFRESH = Menu.FIRST; private static final String TAG = "DevicePickerFragment"; public DevicePickerFragment() { super(null /* Not tied to any user restrictions. */); } @VisibleForTesting Context mContext; @VisibleForTesting String mLaunchPackage; @VisibleForTesting String mLaunchClass; @VisibleForTesting String mCallingAppPackageName; private boolean mNeedAuth; private String mLaunchPackage; private String mLaunchClass; private boolean mStartScanOnResume; private boolean mDeviceSelected; Loading Loading @@ -97,6 +113,12 @@ public final class DevicePickerFragment extends DeviceListPreferenceFragment { UserManager um = (UserManager) getSystemService(Context.USER_SERVICE); mStartScanOnResume = !um.hasUserRestriction(DISALLOW_CONFIG_BLUETOOTH) && (savedInstanceState == null); // don't start scan after rotation mCallingAppPackageName = 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); } Loading Loading @@ -165,8 +187,22 @@ 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) { if (TextUtils.equals(mCallingAppPackageName, mLaunchPackage)) { intent.setClassName(mLaunchPackage, mLaunchClass); } getActivity().sendBroadcast(intent); } mContext.sendBroadcast(intent, Manifest.permission.BLUETOOTH_ADMIN); } private String getCallingAppPackageName(IBinder activityToken) { String pkg = null; try { IActivityManager am = ActivityManagerNative.getDefault(); pkg = am.getLaunchedFromPackage(activityToken); } catch (RemoteException e) { Log.v(TAG, "Could not talk to activity manager.", e); } return pkg; } } Loading
src/com/android/settings/bluetooth/BluetoothPermissionActivity.java +8 −11 Original line number Diff line number Diff line Loading @@ -16,6 +16,8 @@ package com.android.settings.bluetooth; import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS; import android.bluetooth.BluetoothDevice; import android.content.BroadcastReceiver; import android.content.Context; Loading @@ -30,6 +32,7 @@ import android.view.View; import android.widget.Button; import android.widget.TextView; import com.android.internal.annotations.VisibleForTesting; import com.android.internal.app.AlertActivity; import com.android.internal.app.AlertController; import com.android.settings.R; Loading @@ -37,8 +40,6 @@ import com.android.settingslib.bluetooth.CachedBluetoothDevice; import com.android.settingslib.bluetooth.CachedBluetoothDeviceManager; import com.android.settingslib.bluetooth.LocalBluetoothManager; import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS; /** * BluetoothPermissionActivity shows a dialog for accepting incoming * profile connection request from untrusted devices. Loading @@ -54,8 +55,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() { Loading Loading @@ -92,8 +91,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); Loading Loading @@ -231,14 +228,14 @@ public class BluetoothPermissionActivity extends AlertActivity implements sendReplyIntentToReceiver(false, always); } 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 Loading
src/com/android/settings/bluetooth/BluetoothPermissionRequest.java +6 −15 Original line number Diff line number Diff line Loading @@ -49,8 +49,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) { Loading @@ -70,11 +68,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 Loading Loading @@ -103,8 +100,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; Loading Loading @@ -283,10 +278,6 @@ 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); Loading
src/com/android/settings/bluetooth/DevicePickerFragment.java +42 −6 Original line number Diff line number Diff line Loading @@ -16,13 +16,23 @@ package com.android.settings.bluetooth; import static android.os.UserManager.DISALLOW_CONFIG_BLUETOOTH; import com.android.internal.annotations.VisibleForTesting; import android.Manifest; import android.app.ActivityManagerNative; import android.app.IActivityManager; import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothDevicePicker; import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.os.IBinder; import android.os.RemoteException; import android.os.UserManager; import android.util.Log; import android.text.TextUtils; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; Loading @@ -31,22 +41,28 @@ import com.android.internal.logging.MetricsProto.MetricsEvent; import com.android.settings.R; import com.android.settingslib.bluetooth.CachedBluetoothDevice; import static android.os.UserManager.DISALLOW_CONFIG_BLUETOOTH; /** * BluetoothSettings is the Settings screen for Bluetooth configuration and * connection management. */ public final class DevicePickerFragment extends DeviceListPreferenceFragment { private static final int MENU_ID_REFRESH = Menu.FIRST; private static final String TAG = "DevicePickerFragment"; public DevicePickerFragment() { super(null /* Not tied to any user restrictions. */); } @VisibleForTesting Context mContext; @VisibleForTesting String mLaunchPackage; @VisibleForTesting String mLaunchClass; @VisibleForTesting String mCallingAppPackageName; private boolean mNeedAuth; private String mLaunchPackage; private String mLaunchClass; private boolean mStartScanOnResume; private boolean mDeviceSelected; Loading Loading @@ -97,6 +113,12 @@ public final class DevicePickerFragment extends DeviceListPreferenceFragment { UserManager um = (UserManager) getSystemService(Context.USER_SERVICE); mStartScanOnResume = !um.hasUserRestriction(DISALLOW_CONFIG_BLUETOOTH) && (savedInstanceState == null); // don't start scan after rotation mCallingAppPackageName = 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); } Loading Loading @@ -165,8 +187,22 @@ 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) { if (TextUtils.equals(mCallingAppPackageName, mLaunchPackage)) { intent.setClassName(mLaunchPackage, mLaunchClass); } getActivity().sendBroadcast(intent); } mContext.sendBroadcast(intent, Manifest.permission.BLUETOOTH_ADMIN); } private String getCallingAppPackageName(IBinder activityToken) { String pkg = null; try { IActivityManager am = ActivityManagerNative.getDefault(); pkg = am.getLaunchedFromPackage(activityToken); } catch (RemoteException e) { Log.v(TAG, "Could not talk to activity manager.", e); } return pkg; } }