Adding a new category to mark car-optimized launcher activity

Test: TBD
Bug: 70681347

Change-Id: I81ea7f9f3021e8a9d25fa980a8687d66765469c5
This commit is contained in:
Roberto Perez
2017-12-04 17:14:33 -08:00
parent 82c264e0f2
commit 7ee1a7acc4
5 changed files with 45 additions and 2 deletions

View File

@@ -222,9 +222,18 @@ public class ApplicationPackageManager extends PackageManager {
@Override
public Intent getLeanbackLaunchIntentForPackage(String packageName) {
// Try to find a main leanback_launcher activity.
return getLaunchIntentForPackageAndCategory(packageName, Intent.CATEGORY_LEANBACK_LAUNCHER);
}
@Override
public Intent getCarLaunchIntentForPackage(String packageName) {
return getLaunchIntentForPackageAndCategory(packageName, Intent.CATEGORY_CAR_LAUNCHER);
}
private Intent getLaunchIntentForPackageAndCategory(String packageName, String category) {
// Try to find a main launcher activity for the given categories.
Intent intentToResolve = new Intent(Intent.ACTION_MAIN);
intentToResolve.addCategory(Intent.CATEGORY_LEANBACK_LAUNCHER);
intentToResolve.addCategory(category);
intentToResolve.setPackage(packageName);
List<ResolveInfo> ris = queryIntentActivities(intentToResolve, 0);

View File

@@ -3926,6 +3926,14 @@ public class Intent implements Parcelable, Cloneable {
*/
@SdkConstant(SdkConstantType.INTENT_CATEGORY)
public static final String CATEGORY_LEANBACK_LAUNCHER = "android.intent.category.LEANBACK_LAUNCHER";
/**
* Indicates the preferred entry-point activity when an application is launched from a Car
* launcher. If not present, Car launcher can optionally use {@link #CATEGORY_LAUNCHER} as a
* fallback, or exclude the application entirely.
* @hide
*/
@SdkConstant(SdkConstantType.INTENT_CATEGORY)
public static final String CATEGORY_CAR_LAUNCHER = "android.intent.category.CAR_LAUNCHER";
/**
* Indicates a Leanback settings activity to be displayed in the Leanback launcher.
* @hide

View File

@@ -3043,6 +3043,21 @@ public abstract class PackageManager {
*/
public abstract @Nullable Intent getLeanbackLaunchIntentForPackage(@NonNull String packageName);
/**
* Return a "good" intent to launch a front-door Car activity in a
* package, for use for example to implement an "open" button when browsing
* through packages. The current implementation will look for a main
* activity in the category {@link Intent#CATEGORY_CAR_LAUNCHER}, or
* return null if no main car activities are found.
*
* @param packageName The name of the package to inspect.
* @return Returns either a fully-qualified Intent that can be used to launch
* the main Car activity in the package, or null if the package
* does not contain such an activity.
* @hide
*/
public abstract @Nullable Intent getCarLaunchIntentForPackage(@NonNull String packageName);
/**
* Return an array of all of the POSIX secondary group IDs that have been
* assigned to the given package.

View File

@@ -86,6 +86,11 @@ public class PackageManagerStub extends PackageManager {
return null;
}
@Override
public Intent getCarLaunchIntentForPackage(String packageName) {
return null;
}
@Override
public int[] getPackageGids(String packageName) throws NameNotFoundException {
return new int[0];

View File

@@ -108,6 +108,12 @@ public class MockPackageManager extends PackageManager {
throw new UnsupportedOperationException();
}
/** @hide */
@Override
public Intent getCarLaunchIntentForPackage(String packageName) {
throw new UnsupportedOperationException();
}
@Override
public int[] getPackageGids(String packageName) throws NameNotFoundException {
throw new UnsupportedOperationException();