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

Commit c9e35a3e authored by Robin Lee's avatar Robin Lee
Browse files

Disable the legacy TV VIS launch path

This will launch via a VoiceInteractionService if available and an
ACTION_ASSIST Activity if not available.

Test: adb shell input keyevent ASSIST # (on low-ram + high-ram device)
Bug: 157564688
Change-Id: I65f5db69cd99fa62584ac5a177a8da14aa899365
parent 1d22ea4e
Loading
Loading
Loading
Loading
+12 −1
Original line number Diff line number Diff line
@@ -20,18 +20,21 @@ import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.os.Bundle;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.UserHandle;

import com.android.internal.statusbar.IStatusBarService;
import com.android.systemui.SystemUI;
import com.android.systemui.assist.AssistManager;
import com.android.systemui.statusbar.CommandQueue;
import com.android.systemui.statusbar.tv.micdisclosure.AudioRecordingDisclosureBar;

import javax.inject.Inject;
import javax.inject.Singleton;

import dagger.Lazy;

/**
 * Status bar implementation for "large screen" products that mostly present no on-screen nav.
@@ -49,11 +52,14 @@ public class TvStatusBar extends SystemUI implements CommandQueue.Callbacks {
            "com.android.tv.action.OPEN_NOTIFICATIONS_PANEL";

    private final CommandQueue mCommandQueue;
    private final Lazy<AssistManager> mAssistManagerLazy;

    @Inject
    public TvStatusBar(Context context, CommandQueue commandQueue) {
    public TvStatusBar(Context context, CommandQueue commandQueue,
            Lazy<AssistManager> assistManagerLazy) {
        super(context);
        mCommandQueue = commandQueue;
        mAssistManagerLazy = assistManagerLazy;
    }

    @Override
@@ -84,4 +90,9 @@ public class TvStatusBar extends SystemUI implements CommandQueue.Callbacks {
            mContext.startActivityAsUser(intent, UserHandle.CURRENT);
        }
    }

    @Override
    public void startAssist(Bundle args) {
        mAssistManagerLazy.get().startAssist(args);
    }
}
+4 −60
Original line number Diff line number Diff line
@@ -266,68 +266,12 @@ public class SearchManagerService extends ISearchManager.Stub {

    @Override
    public void launchAssist(int userHandle, Bundle args) {
        if ((mContext.getResources().getConfiguration().uiMode
                & Configuration.UI_MODE_TYPE_MASK) == Configuration.UI_MODE_TYPE_TELEVISION) {
            // On TV, use legacy handling until assistants are implemented in the proper way.
            launchLegacyAssist(null, userHandle, args);
        } else {
        StatusBarManagerInternal statusBarManager =
                LocalServices.getService(StatusBarManagerInternal.class);
        if (statusBarManager != null) {
            statusBarManager.startAssist(args);
        }
    }
    }

    // Check and return VIS component
    private ComponentName getLegacyAssistComponent(int userHandle) {
        try {
            userHandle = ActivityManager.handleIncomingUser(Binder.getCallingPid(),
                    Binder.getCallingUid(), userHandle, true, false, "getLegacyAssistComponent",
                    null);
            PackageManager pm = mContext.getPackageManager();
            Intent intentAssistProbe = new Intent(VoiceInteractionService.SERVICE_INTERFACE);
            List<ResolveInfo> infoListVis = pm.queryIntentServicesAsUser(intentAssistProbe,
                    PackageManager.MATCH_SYSTEM_ONLY, userHandle);
            if (infoListVis == null || infoListVis.isEmpty()) {
                return null;
            } else {
                ResolveInfo rInfo = infoListVis.get(0);
                return new ComponentName(
                        rInfo.serviceInfo.applicationInfo.packageName,
                        rInfo.serviceInfo.name);

            }
        } catch (Exception e) {
            Log.e(TAG, "Exception in getLegacyAssistComponent: " + e);
        }
        return null;
    }

    private boolean launchLegacyAssist(String hint, int userHandle, Bundle args) {
        ComponentName comp = getLegacyAssistComponent(userHandle);
        if (comp == null) {
            return false;
        }
        long ident = Binder.clearCallingIdentity();
        try {
            Intent intent = new Intent(VoiceInteractionService.SERVICE_INTERFACE);
            intent.setComponent(comp);

            IActivityTaskManager am = ActivityTaskManager.getService();
            if (args != null) {
                args.putInt(Intent.EXTRA_KEY_EVENT, android.view.KeyEvent.KEYCODE_ASSIST);
            }
            intent.putExtras(args);

            return am.launchAssistIntent(intent, ActivityManager.ASSIST_CONTEXT_BASIC, hint,
                    userHandle, args);
        } catch (RemoteException e) {
        } finally {
            Binder.restoreCallingIdentity(ident);
        }
        return true;
    }

    @Override
    public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {