Loading services/contextualsearch/java/com/android/server/contextualsearch/ContextualSearchManagerService.java +19 −16 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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; Loading Loading @@ -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)); Loading Loading @@ -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(); } Loading Loading @@ -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); } } Loading @@ -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); } } Loading @@ -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( Loading @@ -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); Loading @@ -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( Loading Loading @@ -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; Loading Loading @@ -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; } } Loading Loading @@ -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(); Loading @@ -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); } }); } Loading @@ -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 { Loading Loading
services/contextualsearch/java/com/android/server/contextualsearch/ContextualSearchManagerService.java +19 −16 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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; Loading Loading @@ -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)); Loading Loading @@ -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(); } Loading Loading @@ -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); } } Loading @@ -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); } } Loading @@ -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( Loading @@ -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); Loading @@ -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( Loading Loading @@ -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; Loading Loading @@ -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; } } Loading Loading @@ -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(); Loading @@ -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); } }); } Loading @@ -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 { Loading