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

Commit 5d894505 authored by Philip P. Moltmann's avatar Philip P. Moltmann
Browse files

Set assistant as a role

- Register a role observer in VoiceInteractionManagerService. Once the
role is changes map the new role setting onto the old settings.
- As the assistant role is now always set, there is no need to have code
in AssistUtil for the case the assistant setting is not set
- Remove old config option for the default assistant. The default
assistant is not configured via the roles config

Bug: 110557011
Test: - Set, unset and swtiched assistant via the settings UI
        - for voice interaction service
	- for assist activity
      - Booted from freshly wiped device and saw assitant to be set to
        default
Change-Id: I8596f49c6f6496e8b70cf3236aaa7d7557443a93
parent 3c4a4801
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -1052,6 +1052,7 @@ package android.app.role {
    method @RequiresPermission(android.Manifest.permission.MANAGE_ROLE_HOLDERS) public void removeRoleHolderAsUser(@NonNull String, @NonNull String, @NonNull android.os.UserHandle, @NonNull java.util.concurrent.Executor, @NonNull android.app.role.RoleManagerCallback);
    method @RequiresPermission("com.android.permissioncontroller.permission.MANAGE_ROLES_FROM_CONTROLLER") public boolean removeRoleHolderFromController(@NonNull String, @NonNull String);
    method @RequiresPermission("com.android.permissioncontroller.permission.MANAGE_ROLES_FROM_CONTROLLER") public void setRoleNamesFromController(@NonNull java.util.List<java.lang.String>);
    field public static final String ROLE_ASSISTANT = "android.app.role.ASSISTANT";
  }
  public interface RoleManagerCallback {
+5 −0
Original line number Diff line number Diff line
@@ -14,6 +14,10 @@ package android {
    field public static final String WRITE_OBB = "android.permission.WRITE_OBB";
  }

  public static final class R.array {
    field public static final int config_defaultRoleHolders = 17235974; // 0x1070006
  }

}

package android.animation {
@@ -332,6 +336,7 @@ package android.app.role {
    method @NonNull @RequiresPermission("android.permission.MANAGE_ROLE_HOLDERS") public java.util.List<java.lang.String> getRoleHolders(@NonNull String);
    method @NonNull @RequiresPermission("android.permission.MANAGE_ROLE_HOLDERS") public java.util.List<java.lang.String> getRoleHoldersAsUser(@NonNull String, @NonNull android.os.UserHandle);
    method @RequiresPermission("android.permission.MANAGE_ROLE_HOLDERS") public void removeRoleHolderAsUser(@NonNull String, @NonNull String, @NonNull android.os.UserHandle, @NonNull java.util.concurrent.Executor, @NonNull android.app.role.RoleManagerCallback);
    field public static final String ROLE_ASSISTANT = "android.app.role.ASSISTANT";
  }

  public interface RoleManagerCallback {
+9 −0
Original line number Diff line number Diff line
@@ -171,6 +171,15 @@ public final class RoleManager {
     */
    public static final String ROLE_CALL_COMPANION_APP = "android.app.role.CALL_COMPANION_APP";

    /**
     * The name of the assistant app role.
     *
     * @hide
     */
    @SystemApi
    @TestApi
    public static final String ROLE_ASSISTANT = "android.app.role.ASSISTANT";

    /**
     * The action used to request user approval of a role for an application.
     *
+3 −0
Original line number Diff line number Diff line
@@ -7791,6 +7791,9 @@ public final class Settings {
         * or an activity that handles ACTION_ASSIST, or empty which means using the default
         * handling.
         *
         * <p>This should be set indirectly by setting the {@link
         * android.app.role.RoleManager#ROLE_ASSISTANT assistant role}.
         *
         * @hide
         */
        @UnsupportedAppUsage
+1 −42
Original line number Diff line number Diff line
@@ -17,13 +17,10 @@
package com.android.internal.app;

import android.annotation.NonNull;
import android.app.SearchManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.os.Bundle;
import android.os.IBinder;
import android.os.RemoteException;
@@ -31,8 +28,6 @@ import android.os.ServiceManager;
import android.provider.Settings;
import android.util.Log;

import com.android.internal.R;

import java.util.ArrayList;
import java.util.Set;

@@ -44,14 +39,6 @@ public class AssistUtils {

    private static final String TAG = "AssistUtils";

    /**
     * Sentinel value for "no default assistant specified."
     *
     * Empty string is already used to represent an explicit setting of No Assistant. null cannot
     * be used because we can't represent a null value in XML.
     */
    private static final String UNSET = "#+UNSET";

    private final Context mContext;
    private final IVoiceInteractionManagerService mVoiceInteractionManagerService;

@@ -186,37 +173,9 @@ public class AssistUtils {
                Settings.Secure.ASSISTANT, userId);
        if (setting != null) {
            return ComponentName.unflattenFromString(setting);
        }

        final String defaultSetting = mContext.getResources().getString(
                R.string.config_defaultAssistantComponentName);
        if (defaultSetting != null && !defaultSetting.equals(UNSET)) {
            return ComponentName.unflattenFromString(defaultSetting);
        }

        // Fallback to keep backward compatible behavior when there is no user setting.
        if (activeServiceSupportsAssistGesture()) {
            return getActiveServiceComponentName();
        }

        if (UNSET.equals(defaultSetting)) {
            return null;
        }

        final SearchManager searchManager =
                (SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE);
        if (searchManager == null) {
        } else {
            return null;
        }
        final Intent intent = searchManager.getAssistIntent(false);
        PackageManager pm = mContext.getPackageManager();
        ResolveInfo info = pm.resolveActivityAsUser(intent, PackageManager.MATCH_DEFAULT_ONLY,
                userId);
        if (info != null) {
            return new ComponentName(info.activityInfo.applicationInfo.packageName,
                    info.activityInfo.name);
        }
        return null;
    }

    public static boolean isPreinstalledAssistant(Context context, ComponentName assistant) {
Loading