Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 836f19df authored by Hai Zhang's avatar Hai Zhang
Browse files

Add more logging when a package don't qualify for role.

I was debugging assistant fallback for secondary users, and had a hard
time figuring out why assistant lost the role. Adding more log will
help us know why things were happening in the future.

Bug: 124452117
Test: build
Change-Id: I2f21aff2178a4b19df7f9188cc07d9949212cf54
parent ad2474b6
Loading
Loading
Loading
Loading
+12 −1
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ import android.provider.Settings;
import android.service.voice.VoiceInteractionService;
import android.util.ArraySet;
import android.util.AttributeSet;
import android.util.Log;
import android.util.Xml;

import androidx.annotation.NonNull;
@@ -49,6 +50,8 @@ import java.util.Set;
 */
public class AssistantRoleBehavior implements RoleBehavior {

    private static final String LOG_TAG = AssistantRoleBehavior.class.getSimpleName();

    private static final Intent ASSIST_SERVICE_PROBE =
            new Intent(VoiceInteractionService.SERVICE_INTERFACE);
    private static final Intent ASSIST_ACTIVITY_PROBE = new Intent(Intent.ACTION_ASSIST);
@@ -131,8 +134,16 @@ public class AssistantRoleBehavior implements RoleBehavior {
        }

        Intent pkgActivityProbe = new Intent(ASSIST_ACTIVITY_PROBE).setPackage(packageName);
        return !pm.queryIntentActivities(pkgActivityProbe,
        boolean hasAssistantActivity = !pm.queryIntentActivities(pkgActivityProbe,
                PackageManager.MATCH_DEFAULT_ONLY).isEmpty();

        if (!hasAssistantActivity) {
            Log.w(LOG_TAG, "Package " + packageName + " not qualified for " + role.getName()
                    + " due to " + (services.isEmpty() ? "missing service"
                    : "service without qualifying metadata") + " and missing activity");
        }

        return hasAssistantActivity;
    }

    private boolean isAssistantVoiceInteractionService(@NonNull PackageManager pm,
+2 −0
Original line number Diff line number Diff line
@@ -79,6 +79,8 @@ public class ExclusiveDefaultHolderMixin {
        }

        if (!role.isPackageQualified(packageName, context)) {
            Log.w(LOG_TAG, "Default holder does not qualify for the role, config: " + resourceName
                    + ", package: " + packageName);
            return null;
        }
        return packageName;