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

Commit 12e0c5ac authored by Jim Miller's avatar Jim Miller
Browse files

Fix 6504124: Disable assist when ACTION_ASSIST is not available

Change-Id: I2218afa7954961309d8cf2f2be0aff10826b9243
parent c1c14065
Loading
Loading
Loading
Loading
+30 −1
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import android.content.ActivityNotFoundException;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.util.AttributeSet;
import android.util.Log;
import android.util.Slog;
@@ -69,8 +70,36 @@ public class SearchPanelView extends FrameLayout implements

    private SearchManager mSearchManager;

    // This code should be the same as that used in LockScreen.java
    public boolean isAssistantAvailable() {
        return mSearchManager != null && mSearchManager.getGlobalSearchActivity() != null;
        Intent intent = getAssistIntent();
        return intent == null ? false
                : mContext.getPackageManager().queryIntentActivities(intent,
                        PackageManager.MATCH_DEFAULT_ONLY).size() > 0;
    }

    private Intent getAssistIntent() {
        Intent intent = null;
        SearchManager searchManager = getSearchManager();
        if (searchManager != null) {
            ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
            if (globalSearchActivity != null) {
                intent = new Intent(Intent.ACTION_ASSIST);
                intent.setPackage(globalSearchActivity.getPackageName());
            } else {
                Slog.w(TAG, "No global search activity");
            }
        } else {
            Slog.w(TAG, "No SearchManager");
        }
        return intent;
    }

    private SearchManager getSearchManager() {
        if (mSearchManager == null) {
            mSearchManager = (SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE);
        }
        return mSearchManager;
    }

    private void startAssistActivity() {
+2 −1
Original line number Diff line number Diff line
@@ -63,7 +63,8 @@ public class DelegateViewHelper {
                break;
        }
        if (mDelegateView != null) {
            if (mDelegateView.getVisibility() != View.VISIBLE && event.getAction() != MotionEvent.ACTION_CANCEL) {
            if (mDelegateView.getVisibility() != View.VISIBLE
                    && event.getAction() != MotionEvent.ACTION_CANCEL) {
                final boolean isVertical = (mOrientation == Surface.ROTATION_90
                        || mOrientation == Surface.ROTATION_270);
                final int historySize = event.getHistorySize();
+20 −9
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ import android.content.ActivityNotFoundException;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.os.Vibrator;
@@ -45,7 +46,6 @@ import android.util.Slog;
import android.media.AudioManager;
import android.os.RemoteException;
import android.provider.MediaStore;
import android.provider.Settings;

import java.io.File;

@@ -252,13 +252,19 @@ class LockScreen extends LinearLayout implements KeyguardScreen {
        }
    }

    // This code should be the same as that in SearchPanelView
    public boolean isAssistantAvailable() {
        Intent intent = getAssistIntent();
        return intent == null ? false
                : mContext.getPackageManager().queryIntentActivities(intent,
                        PackageManager.MATCH_DEFAULT_ONLY).size() > 0;
    }

    private Intent getAssistIntent() {
        Intent intent = null;
        if (mSearchManager == null) {
            mSearchManager = (SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE);
        }
        if (mSearchManager != null) {
            ComponentName globalSearchActivity = mSearchManager.getGlobalSearchActivity();
        SearchManager searchManager = getSearchManager();
        if (searchManager != null) {
            ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
            if (globalSearchActivity != null) {
                intent = new Intent(Intent.ACTION_ASSIST);
                intent.setPackage(globalSearchActivity.getPackageName());
@@ -271,6 +277,13 @@ class LockScreen extends LinearLayout implements KeyguardScreen {
        return intent;
    }

    private SearchManager getSearchManager() {
        if (mSearchManager == null) {
            mSearchManager = (SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE);
        }
        return mSearchManager;
    }

    class MultiWaveViewMethods implements MultiWaveView.OnTriggerListener,
            UnlockWidgetCommonMethods {
        private final MultiWaveView mMultiWaveView;
@@ -517,14 +530,12 @@ class LockScreen extends LinearLayout implements KeyguardScreen {
                        .isTargetPresent(com.android.internal.R.drawable.ic_lockscreen_search)
                        : false;

        // TODO: test to see if search is available
        boolean searchActionAvailable = true;

        if (disabledByAdmin) {
            Log.v(TAG, "Camera disabled by Device Policy");
        } else if (disabledBySimState) {
            Log.v(TAG, "Camera disabled by Sim State");
        }
        boolean searchActionAvailable = isAssistantAvailable();
        mCameraDisabled = disabledByAdmin || disabledBySimState || !cameraTargetPresent;
        mSearchDisabled = disabledBySimState || !searchActionAvailable || !searchTargetPresent;
        mUnlockWidgetMethods.updateResources();