1

I'm working on an AOSP project and as part of that I'm modifying the Bluetooth SDK. I have made changes in android.bluetooth.BluetoothAdapter::getDefaultAdapter() method and I'd like to know which application has called that method.

There is a mContext member in that class and it's null in most of the cases and sometimes it's package name has values com.android.settings.This I guess is because applications calling BluetoothAdapter::getDefaultAdapter() doesn't have to pass the Context.

  1. So I'd like to know if there are any reliable means of getting the package name of the application that has called the getDefaultAdapter method?

  2. If that's not possible, then the next option is to get the package name of the application that's currently in the foreground. I tried printing the Pid and the Uid of android.os.Process and what I get is the process Id of the 'system' application. Are there any other methods which will help me get the package name of the application in the foreground?

  3. If that's also not possible then the only option left is to exec "dumpsys window windows | grep -E 'mObscuringWindow'" and parse the result. But I'm not quite sure whether this is advisable and reliable.

Any help will be greatly appreciated. Thanks!

1 Answer 1

-1

You haven't mention Android Version Which you are using.

From Aosp Master branch perspective. Try with AttributionSource.myAttributionSource().getPackageName()

@Deprecated

@RequiresNoPermission
public static synchronized BluetoothAdapter getDefaultAdapter() {
    if (sAdapter == null) {
        sAdapter = createAdapter(AttributionSource.myAttributionSource());
    }
    return sAdapter;
}
Sign up to request clarification or add additional context in comments.

4 Comments

We are using HONEYCOMB(11) with API level 30. AttributionSource, I'm afraid is available only from API 31. Are there any other options?
Below method is present in Same Class, Try that
private String getOpPackageName() { // Workaround for legacy API for getting a BluetoothAdapter not // passing a context if (mContext != null) { return mContext.getOpPackageName(); } return ActivityThread.currentOpPackageName(); }
Not sure if you read my question. In 90% of the cases, mContext is null and when it is not, package name is com.android.settings

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.