androidtizensamsung-galaxy-gear

Samsung Accessory Protocol not working after switching target SDK to API level 30?


Our app relies on the Samsung Accessory Protocol to communicate between our Android app and Galaxy Watch app. After upgrading our target and compile SDK from API level 29 to 30 (in preparation for the release of Android 11 in the coming months) the watch and the phone app will no longer connect. No other changes made in-app other than upgrading the SDK. Using the latest version of the Samsung Accessory SDK 2.6.1.

Has anyone found a solution for targetting Android 11? Or do we simply need to wait for Samsung to fix this issue?


Solution

  • The answer provided by Jordan is correct, but I wanted to elaborate a bit to explain why and to add more queries permissions to the manifest.

    Starting from API 30 Android has decided to disallow querying all packages except for Android's system application. Regular applications must provide an explicit permission for each package they want to query. That's just yet another case when we should all collectively thank Google for not caring about backward compatibility at all.

    If you decompile SAP code, you'll see querying different kind of packages, e.g.

    public static String a = "com.samsung.accessory";
    PackageManager packageManager = paramContext.getPackageManager();
    try {
      PackageInfo packageInfo;
      if ((packageInfo = packageManager.getPackageInfo(a, 0)) != null) {
    ...
      try {
        int i = (paramContext.getPackageManager().getPackageInfo("com.samsung.android.providers.context", 128)).versionCode;
    ...
    etc.
    

    Since I didn't have enough time to analyze all possible cases and scenarios when that SAP code can be called, and wanted to be rather safe than sorry because of frustrated users, I've simply added all of them, so my query permissions looks as follows:

      <queries>
        <package android:name="com.samsung.accessory" />
        <package android:name="com.samsung.android.providers.context" />
        <package android:name="com.samsung.android.app.watchmanager" />
        <package android:name="com.samsung.accessory.safiletransfer" />
        <package android:name="com.samsung.accessory.goproviders" />
        <package android:name="com.samsung.accessory.saproviders" />
    </queries>