diff options
author | Yuncheol Heo <ycheo@google.com> | 2021-06-26 00:24:34 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2021-06-26 00:24:34 +0000 |
commit | 4e903b627d412a1c6eb45bebe53510801f9d48a7 (patch) | |
tree | 2f687e8c9cd820db6d85aeab7abaa00758e22066 | |
parent | 3e8813000e5570315a6001bec5f82dffbfc186fb (diff) | |
parent | d35103f71d3946905bbc1f6e6c96d339686d12eb (diff) | |
download | Cluster-android12-qpr1-d-s1-release.tar.gz |
Merge "Mark FakeFreeNavigationActivity showForAllUsers." into sc-devandroid-12.0.0_r32android-12.0.0_r29android-12.0.0_r28android-12.0.0_r27android-12.0.0_r26android-12.0.0_r21android-12.0.0_r20android-12.0.0_r19android-12.0.0_r18android-12.0.0_r16android12-qpr1-releaseandroid12-qpr1-d-s3-releaseandroid12-qpr1-d-s2-releaseandroid12-qpr1-d-s1-releaseandroid12-qpr1-d-releaseandroid12-dev
3 files changed, 23 insertions, 28 deletions
diff --git a/DirectRenderingCluster/AndroidManifest.xml b/DirectRenderingCluster/AndroidManifest.xml index 57c31c0..5f0230b 100644 --- a/DirectRenderingCluster/AndroidManifest.xml +++ b/DirectRenderingCluster/AndroidManifest.xml @@ -80,6 +80,7 @@ <activity android:name=".FakeFreeNavigationActivity" android:exported="false" + android:showForAllUsers="true" android:theme="@android:style/Theme.NoTitleBar.Fullscreen" android:launchMode="singleInstance" android:resizeableActivity="true" diff --git a/DirectRenderingCluster/src/android/car/cluster/ClusterRenderingService.java b/DirectRenderingCluster/src/android/car/cluster/ClusterRenderingService.java index 11bcfac..331eeee 100644 --- a/DirectRenderingCluster/src/android/car/cluster/ClusterRenderingService.java +++ b/DirectRenderingCluster/src/android/car/cluster/ClusterRenderingService.java @@ -33,6 +33,7 @@ import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; +import android.content.pm.ActivityInfo; import android.graphics.Rect; import android.hardware.display.DisplayManager; import android.hardware.display.DisplayManager.DisplayListener; @@ -209,8 +210,8 @@ public class ClusterRenderingService extends InstrumentClusterRenderingService i } private Intent getNavigationActivityIntent(int displayId) { - ComponentName component = MainClusterActivity.getNavigationActivity(this); - if (component == null) { + ActivityInfo activityInfo = MainClusterActivity.getNavigationActivity(this); + if (activityInfo == null) { Log.e(TAG, "Failed to resolve the navigation activity"); return null; } @@ -223,7 +224,7 @@ public class ClusterRenderingService extends InstrumentClusterRenderingService i setClusterActivityState(ClusterActivityState.create(/* visible= */ true, /* unobscuredBounds= */ new Rect(0, 0, 240, 320))); return new Intent(Intent.ACTION_MAIN) - .setComponent(component) + .setClassName(activityInfo.packageName, activityInfo.name) .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK) .putExtra(Car.CAR_EXTRA_CLUSTER_ACTIVITY_STATE, ClusterActivityState.create(/* visible= */ true, diff --git a/DirectRenderingCluster/src/android/car/cluster/MainClusterActivity.java b/DirectRenderingCluster/src/android/car/cluster/MainClusterActivity.java index f306e94..3b8d225 100644 --- a/DirectRenderingCluster/src/android/car/cluster/MainClusterActivity.java +++ b/DirectRenderingCluster/src/android/car/cluster/MainClusterActivity.java @@ -22,6 +22,7 @@ import static android.content.Intent.ACTION_USER_SWITCHED; import static android.content.Intent.ACTION_USER_UNLOCKED; import static android.content.PermissionChecker.PERMISSION_GRANTED; +import android.annotation.NonNull; import android.app.ActivityManager; import android.app.ActivityOptions; import android.car.Car; @@ -34,6 +35,7 @@ import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.content.ServiceConnection; +import android.content.pm.ActivityInfo; import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; import android.graphics.Rect; @@ -437,13 +439,14 @@ public class MainClusterActivity extends FragmentActivity implements } mHandler.removeCallbacks(mRetryLaunchNavigationActivity); - ComponentName navigationActivity = getNavigationActivity(this); + ActivityInfo activityInfo = getNavigationActivity(this); + ComponentName navigationActivity = new ComponentName(activityInfo.packageName, + activityInfo.name); + int userId = (activityInfo.flags & ActivityInfo.FLAG_SHOW_FOR_ALL_USERS) != 0 + ? UserHandle.USER_SYSTEM : ActivityManager.getCurrentUser(); mClusterViewModel.setFreeNavigationActivity(navigationActivity); try { - if (navigationActivity == null) { - throw new ActivityNotFoundException(); - } ClusterActivityState activityState = ClusterActivityState .create(true, mNavigationDisplay.mUnobscuredBounds); Intent intent = new Intent(Intent.ACTION_MAIN) @@ -452,12 +455,12 @@ public class MainClusterActivity extends FragmentActivity implements .putExtra(Car.CAR_EXTRA_CLUSTER_ACTIVITY_STATE, activityState.toBundle()); - Log.d(TAG, "Launching: " + intent + " on display: " + mNavigationDisplay.mDisplayId); + Log.d(TAG, "Launching: " + intent + " on display" + mNavigationDisplay.mDisplayId + + " as user" + userId); ActivityOptions activityOptions = ActivityOptions.makeBasic() .setLaunchDisplayId(mNavigationDisplay.mDisplayId); - mService.startFixedActivityModeForDisplayAndUser( - intent, activityOptions, ActivityManager.getCurrentUser()); + mService.startFixedActivityModeForDisplayAndUser(intent, activityOptions, userId); } catch (ActivityNotFoundException ex) { // Some activities might not be available right on startup. We will retry. mHandler.postDelayed(mRetryLaunchNavigationActivity, @@ -471,37 +474,27 @@ public class MainClusterActivity extends FragmentActivity implements * Returns a default navigation activity to show in the cluster. * In the current implementation we obtain this activity from an intent defined in a resources * file (which OEMs can overlay). - * Alternatively, other implementations could: - * <ul> - * <li>Dynamically detect what's the default navigation activity the user has selected on the - * head unit, and obtain the activity marked with - * {@link Car#CAR_CATEGORY_NAVIGATION} from the same package. - * <li>Let the user select one from settings. - * </ul> + * When it fails to find, parse or resolve the activity, it'll throw ActivityNotFoundException. */ - static ComponentName getNavigationActivity(Context context) { + static @NonNull ActivityInfo getNavigationActivity(Context context) { PackageManager pm = context.getPackageManager(); - int userId = ActivityManager.getCurrentUser(); String intentString = context.getString(R.string.freeNavigationIntent); if (intentString == null) { - Log.w(TAG, "No free navigation activity defined"); - return null; + throw new ActivityNotFoundException("No free navigation activity defined"); } Log.i(TAG, "Free navigation intent: " + intentString); try { Intent intent = Intent.parseUri(intentString, Intent.URI_INTENT_SCHEME); - ResolveInfo navigationApp = pm.resolveActivityAsUser(intent, - PackageManager.MATCH_DEFAULT_ONLY, userId); + ResolveInfo navigationApp = pm.resolveActivity(intent, + PackageManager.MATCH_DEFAULT_ONLY); if (navigationApp == null) { - return null; + throw new ActivityNotFoundException("Can't resolve freeNavigationIntent"); } - return new ComponentName(navigationApp.activityInfo.packageName, - navigationApp.activityInfo.name); + return navigationApp.activityInfo; } catch (URISyntaxException ex) { - Log.e(TAG, "Unable to parse free navigation activity intent: '" + intentString + "'"); - return null; + throw new ActivityNotFoundException("Unable to parse freeNavigationIntent"); } } |