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

Commit cdd20d98 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Fix DEBUG constant for ContextualSearchManagerService" into main

parents 51918f15 81d5177c
Loading
Loading
Loading
Loading
+19 −16
Original line number Diff line number Diff line
@@ -98,6 +98,8 @@ public class ContextualSearchManagerService extends SystemService {
    private static final int MSG_INVALIDATE_TOKEN = 1;
    private static final int MAX_TOKEN_VALID_DURATION_MS = 1_000 * 60 * 10; // 10 minutes

    private static final boolean DEBUG = false;

    private final Context mContext;
    private final ActivityTaskManagerInternal mAtmInternal;
    private final PackageManagerInternal mPackageManager;
@@ -121,6 +123,7 @@ public class ContextualSearchManagerService extends SystemService {
                        final Bundle data,
                        final int activityIndex,
                        final int activityCount) {

                    final IContextualSearchCallback callback;
                    synchronized (mLock) {
                        callback = mStateCallback;
@@ -160,7 +163,7 @@ public class ContextualSearchManagerService extends SystemService {

    public ContextualSearchManagerService(@NonNull Context context) {
        super(context);
        if (DEBUG_USER) Log.d(TAG, "ContextualSearchManagerService created");
        if (DEBUG) Log.d(TAG, "ContextualSearchManagerService created");
        mContext = context;
        mAtmInternal = Objects.requireNonNull(
                LocalServices.getService(ActivityTaskManagerInternal.class));
@@ -206,7 +209,7 @@ public class ContextualSearchManagerService extends SystemService {
                mTemporaryHandler.removeMessages(MSG_RESET_TEMPORARY_PACKAGE);
                mTemporaryHandler = null;
            }
            if (DEBUG_USER) Log.d(TAG, "mTemporaryPackage reset.");
            if (DEBUG) Log.d(TAG, "mTemporaryPackage reset.");
            mTemporaryPackage = null;
            updateSecureSetting();
        }
@@ -239,7 +242,7 @@ public class ContextualSearchManagerService extends SystemService {
            mTemporaryPackage = temporaryPackage;
            updateSecureSetting();
            mTemporaryHandler.sendEmptyMessageDelayed(MSG_RESET_TEMPORARY_PACKAGE, durationMs);
            if (DEBUG_USER) Log.d(TAG, "mTemporaryPackage set to " + mTemporaryPackage);
            if (DEBUG) Log.d(TAG, "mTemporaryPackage set to " + mTemporaryPackage);
        }
    }

@@ -256,7 +259,7 @@ public class ContextualSearchManagerService extends SystemService {
                                + durationMs + ")");
            }
            mTokenValidDurationMs = durationMs;
            if (DEBUG_USER) Log.d(TAG, "mTokenValidDurationMs set to " + durationMs);
            if (DEBUG) Log.d(TAG, "mTokenValidDurationMs set to " + durationMs);
        }
    }

@@ -268,12 +271,12 @@ public class ContextualSearchManagerService extends SystemService {

    private Intent getResolvedLaunchIntent(int userId) {
        synchronized (this) {
            if(DEBUG_USER) Log.d(TAG, "Attempting to getResolvedLaunchIntent");
            if(DEBUG) Log.d(TAG, "Attempting to getResolvedLaunchIntent");
            // If mTemporaryPackage is not null, use it to get the ContextualSearch intent.
            String csPkgName = getContextualSearchPackageName();
            if (csPkgName.isEmpty()) {
                // Return null if csPackageName is not specified.
                if (DEBUG_USER) Log.w(TAG, "getContextualSearchPackageName is empty");
                if (DEBUG) Log.w(TAG, "getContextualSearchPackageName is empty");
                return null;
            }
            Intent launchIntent = new Intent(
@@ -282,12 +285,12 @@ public class ContextualSearchManagerService extends SystemService {
            ResolveInfo resolveInfo = mContext.getPackageManager().resolveActivityAsUser(
                    launchIntent, MATCH_DIRECT_BOOT_AWARE | MATCH_DIRECT_BOOT_UNAWARE, userId);
            if (resolveInfo == null) {
                if (DEBUG_USER) Log.w(TAG, "resolveInfo is null");
                if (DEBUG) Log.w(TAG, "resolveInfo is null");
                return null;
            }
            ComponentName componentName = resolveInfo.getComponentInfo().getComponentName();
            if (componentName == null) {
                if (DEBUG_USER) Log.w(TAG, "componentName is null");
                if (DEBUG) Log.w(TAG, "componentName is null");
                return null;
            }
            launchIntent.setComponent(componentName);
@@ -298,11 +301,11 @@ public class ContextualSearchManagerService extends SystemService {
    private Intent getContextualSearchIntent(int entrypoint, int userId, CallbackToken mToken) {
        final Intent launchIntent = getResolvedLaunchIntent(userId);
        if (launchIntent == null) {
            if (DEBUG_USER) Log.w(TAG, "Failed getContextualSearchIntent: launchIntent is null");
            if (DEBUG) Log.w(TAG, "Failed getContextualSearchIntent: launchIntent is null");
            return null;
        }

        if (DEBUG_USER) Log.d(TAG, "Launch component: " + launchIntent.getComponent());
        if (DEBUG) Log.d(TAG, "Launch component: " + launchIntent.getComponent());
        launchIntent.addFlags(FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_NO_ANIMATION
                | FLAG_ACTIVITY_NO_USER_ACTION | FLAG_ACTIVITY_CLEAR_TASK);
        launchIntent.putExtra(
@@ -355,7 +358,7 @@ public class ContextualSearchManagerService extends SystemService {
                    TYPE_NAVIGATION_BAR_PANEL,
                    TYPE_POINTER));
        } else {
            if (DEBUG_USER) Log.w(TAG, "Can't capture contextual screenshot: mWmInternal is null");
            if (DEBUG) Log.w(TAG, "Can't capture contextual screenshot: mWmInternal is null");
            shb = null;
        }
        final Bitmap bm = shb != null ? shb.asBitmap() : null;
@@ -429,7 +432,7 @@ public class ContextualSearchManagerService extends SystemService {
                    mTokenHandler.removeMessages(MSG_INVALIDATE_TOKEN);
                    mTokenHandler = null;
                }
                if (DEBUG_USER) Log.d(TAG, "mToken invalidated.");
                if (DEBUG) Log.d(TAG, "mToken invalidated.");
                mToken = null;
            }
        }
@@ -459,7 +462,7 @@ public class ContextualSearchManagerService extends SystemService {
        @Override
        public void startContextualSearch(int entrypoint) {
            synchronized (this) {
                if (DEBUG_USER) Log.d(TAG, "startContextualSearch entrypoint: " + entrypoint);
                if (DEBUG) Log.d(TAG, "startContextualSearch entrypoint: " + entrypoint);
                enforcePermission("startContextualSearch");
                final int callingUserId = Binder.getCallingUserHandle().getIdentifier();

@@ -474,7 +477,7 @@ public class ContextualSearchManagerService extends SystemService {
                        getContextualSearchIntent(entrypoint, callingUserId, mToken);
                    if (launchIntent != null) {
                        int result = invokeContextualSearchIntent(launchIntent, callingUserId);
                        if (DEBUG_USER) Log.d(TAG, "Launch result: " + result);
                        if (DEBUG) Log.d(TAG, "Launch result: " + result);
                    }
                });
            }
@@ -484,11 +487,11 @@ public class ContextualSearchManagerService extends SystemService {
        public void getContextualSearchState(
                @NonNull IBinder token,
                @NonNull IContextualSearchCallback callback) {
            if (DEBUG_USER) {
            if (DEBUG) {
                Log.i(TAG, "getContextualSearchState token: " + token + ", callback: " + callback);
            }
            if (mToken == null || !mToken.getToken().equals(token)) {
                if (DEBUG_USER) {
                if (DEBUG) {
                    Log.e(TAG, "getContextualSearchState: invalid token, returning error");
                }
                try {