diff options
3 files changed, 27 insertions, 7 deletions
diff --git a/packages/SystemUI/res/layout/app_clips_screenshot.xml b/packages/SystemUI/res/layout/app_clips_screenshot.xml index b09d35d46ca0..5191895549b6 100644 --- a/packages/SystemUI/res/layout/app_clips_screenshot.xml +++ b/packages/SystemUI/res/layout/app_clips_screenshot.xml @@ -60,6 +60,7 @@ android:layout_marginStart="16dp" android:checked="true" android:text="@string/backlinks_include_link" + android:textColor="?android:textColorSecondary" android:visibility="gone" app:layout_constraintBottom_toTopOf="@id/preview" app:layout_constraintStart_toEndOf="@id/cancel" @@ -74,6 +75,7 @@ android:drawablePadding="4dp" android:gravity="center" android:paddingHorizontal="8dp" + android:textColor="?android:textColorSecondary" android:visibility="gone" app:layout_constraintBottom_toTopOf="@id/preview" app:layout_constraintStart_toEndOf="@id/backlinks_include_data" diff --git a/packages/SystemUI/src/com/android/systemui/screenshot/appclips/AppClipsViewModel.java b/packages/SystemUI/src/com/android/systemui/screenshot/appclips/AppClipsViewModel.java index 8c833eccb1fb..bd9e295b58f8 100644 --- a/packages/SystemUI/src/com/android/systemui/screenshot/appclips/AppClipsViewModel.java +++ b/packages/SystemUI/src/com/android/systemui/screenshot/appclips/AppClipsViewModel.java @@ -33,6 +33,7 @@ import android.content.ClipData; import android.content.ComponentName; import android.content.Intent; import android.content.pm.PackageManager; +import android.content.pm.ResolveInfo; import android.graphics.Bitmap; import android.graphics.HardwareRenderer; import android.graphics.RecordingCanvas; @@ -267,6 +268,8 @@ final class AppClipsViewModel extends ViewModel { } private boolean canAppStartThroughLauncher(String packageName) { + // Use Intent.resolveActivity API to check if the intent resolves as that is what Android + // uses internally when apps use Context.startActivity. return getMainLauncherIntentForPackage(packageName).resolveActivity(mPackageManager) != null; } @@ -366,10 +369,19 @@ final class AppClipsViewModel extends ViewModel { return taskInfo.topActivityInfo.loadLabel(mPackageManager).toString(); } - private Intent getMainLauncherIntentForPackage(String packageName) { - return new Intent(ACTION_MAIN) - .addCategory(CATEGORY_LAUNCHER) - .setPackage(packageName); + private Intent getMainLauncherIntentForPackage(String pkgName) { + Intent intent = new Intent(ACTION_MAIN).addCategory(CATEGORY_LAUNCHER).setPackage(pkgName); + + // Not all apps use DEFAULT_CATEGORY for their main launcher activity so the exact component + // needs to be queried and set on the Intent in order for note-taking apps to be able to + // start this intent. When starting an activity with an implicit intent, Android adds the + // DEFAULT_CATEGORY flag otherwise it fails to resolve the intent. + ResolveInfo resolvedActivity = mPackageManager.resolveActivity(intent, /* flags= */ 0); + if (resolvedActivity != null) { + intent.setComponent(resolvedActivity.getComponentInfo().getComponentName()); + } + + return intent; } /** Helper factory to help with injecting {@link AppClipsViewModel}. */ diff --git a/packages/SystemUI/tests/src/com/android/systemui/screenshot/appclips/AppClipsViewModelTest.java b/packages/SystemUI/tests/src/com/android/systemui/screenshot/appclips/AppClipsViewModelTest.java index baf1357a1ae0..193d29c1d550 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/screenshot/appclips/AppClipsViewModelTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/screenshot/appclips/AppClipsViewModelTest.java @@ -334,13 +334,17 @@ public final class AppClipsViewModelTest extends SysuiTestCase { } private void resetPackageManagerMockingForUsingFallbackBacklinks() { + ResolveInfo backlinksTaskResolveInfo = createBacklinksTaskResolveInfo(); reset(mPackageManager); when(mPackageManager.loadItemIcon(any(), any())).thenReturn(FAKE_DRAWABLE); when(mPackageManager.resolveActivity(any(Intent.class), anyInt())) - // First the logic queries whether a package has a launcher activity, this should + // Firstly, the logic queries whether a package has a launcher activity, this should // resolve otherwise the logic filters out the task. - .thenReturn(createBacklinksTaskResolveInfo()) - // Then logic queries with the backlinks intent, this should not resolve for the + .thenReturn(backlinksTaskResolveInfo) + // Secondly, the logic builds a fallback main launcher intent, this should also + // resolve for the fallback intent to build correctly. + .thenReturn(backlinksTaskResolveInfo) + // Lastly, logic queries with the backlinks intent, this should not resolve for the // logic to use the fallback intent. .thenReturn(null); } @@ -360,6 +364,8 @@ public final class AppClipsViewModelTest extends SysuiTestCase { assertThat(actualBacklinksIntent.getPackage()).isEqualTo(BACKLINKS_TASK_PACKAGE_NAME); assertThat(actualBacklinksIntent.getAction()).isEqualTo(ACTION_MAIN); assertThat(actualBacklinksIntent.getCategories()).containsExactly(CATEGORY_LAUNCHER); + assertThat(actualBacklinksIntent.getComponent()).isEqualTo( + new ComponentName(BACKLINKS_TASK_PACKAGE_NAME, BACKLINKS_TASK_APP_NAME)); } private static ResolveInfo createBacklinksTaskResolveInfo() { |