Merge "Passing caller package name to setBluetoothTethering" am: 751f034b82 am: b2d0c6357c

am: 8e3ad12386

Change-Id: I5f158ae800ee0df5ee44d41a19a37ab90b39fc6b
This commit is contained in:
Mark Chien
2019-08-28 03:24:39 -07:00
committed by android-build-merger
2 changed files with 20 additions and 3 deletions

View File

@@ -118,6 +118,8 @@ public final class BluetoothPan implements BluetoothProfile {
*/ */
public static final int PAN_OPERATION_SUCCESS = 1004; public static final int PAN_OPERATION_SUCCESS = 1004;
private final Context mContext;
private BluetoothAdapter mAdapter; private BluetoothAdapter mAdapter;
private final BluetoothProfileConnector<IBluetoothPan> mProfileConnector = private final BluetoothProfileConnector<IBluetoothPan> mProfileConnector =
new BluetoothProfileConnector(this, BluetoothProfile.PAN, new BluetoothProfileConnector(this, BluetoothProfile.PAN,
@@ -136,6 +138,7 @@ public final class BluetoothPan implements BluetoothProfile {
@UnsupportedAppUsage @UnsupportedAppUsage
/*package*/ BluetoothPan(Context context, ServiceListener listener) { /*package*/ BluetoothPan(Context context, ServiceListener listener) {
mAdapter = BluetoothAdapter.getDefaultAdapter(); mAdapter = BluetoothAdapter.getDefaultAdapter();
mContext = context;
mProfileConnector.connect(context, listener); mProfileConnector.connect(context, listener);
} }
@@ -287,11 +290,12 @@ public final class BluetoothPan implements BluetoothProfile {
@UnsupportedAppUsage @UnsupportedAppUsage
public void setBluetoothTethering(boolean value) { public void setBluetoothTethering(boolean value) {
if (DBG) log("setBluetoothTethering(" + value + ")"); String pkgName = mContext.getOpPackageName();
if (DBG) log("setBluetoothTethering(" + value + "), calling package:" + pkgName);
final IBluetoothPan service = getService(); final IBluetoothPan service = getService();
if (service != null && isEnabled()) { if (service != null && isEnabled()) {
try { try {
service.setBluetoothTethering(value); service.setBluetoothTethering(value, pkgName);
} catch (RemoteException e) { } catch (RemoteException e) {
Log.e(TAG, "Stack:" + Log.getStackTraceString(new Throwable())); Log.e(TAG, "Stack:" + Log.getStackTraceString(new Throwable()));
} }

View File

@@ -455,7 +455,20 @@ public class Tethering extends BaseNetworkObserver {
@Override @Override
public void onServiceConnected(int profile, BluetoothProfile proxy) { public void onServiceConnected(int profile, BluetoothProfile proxy) {
((BluetoothPan) proxy).setBluetoothTethering(enable); // Clear identify is fine because caller already pass tethering permission at
// ConnectivityService#startTethering()(or stopTethering) before the control comes
// here. Bluetooth will check tethering permission again that there is
// Context#getOpPackageName() under BluetoothPan#setBluetoothTethering() to get
// caller's package name for permission check.
// Calling BluetoothPan#setBluetoothTethering() here means the package name always
// be system server. If calling identity is not cleared, that package's uid might
// not match calling uid and end up in permission denied.
final long identityToken = Binder.clearCallingIdentity();
try {
((BluetoothPan) proxy).setBluetoothTethering(enable);
} finally {
Binder.restoreCallingIdentity(identityToken);
}
// TODO: Enabling bluetooth tethering can fail asynchronously here. // TODO: Enabling bluetooth tethering can fail asynchronously here.
// We should figure out a way to bubble up that failure instead of sending success. // We should figure out a way to bubble up that failure instead of sending success.
final int result = (((BluetoothPan) proxy).isTetheringOn() == enable) final int result = (((BluetoothPan) proxy).isTetheringOn() == enable)