Snap for 6439596 from 2878d14ae7a8599d25b8641367ff103c9cc26450 to qt-aml-tzdata-release
Change-Id: I3d4982e6649d041bd7ad3733590ba5c6d2da00f8
diff --git a/res/values/config.xml b/res/values/config.xml
index 89998f3..d06dff2 100644
--- a/res/values/config.xml
+++ b/res/values/config.xml
@@ -19,4 +19,5 @@
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<!-- Activity to present for free navigation -->
<string name="freeNavigationIntent" translatable="false">intent:#Intent;component=android.car.cluster/.FakeFreeNavigationActivity;launchFlags=0x24000000;end</string>
+ <bool name="navigationOnly">false</bool>
</resources>
diff --git a/src/android/car/cluster/ClusterRenderingService.java b/src/android/car/cluster/ClusterRenderingService.java
index 5770773..8d0cafa 100644
--- a/src/android/car/cluster/ClusterRenderingService.java
+++ b/src/android/car/cluster/ClusterRenderingService.java
@@ -15,21 +15,31 @@
*/
package android.car.cluster;
+import static android.content.Intent.ACTION_USER_SWITCHED;
+import static android.content.Intent.ACTION_USER_UNLOCKED;
import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK;
+import static android.view.Display.INVALID_DISPLAY;
import static java.lang.Integer.parseInt;
+import android.app.ActivityManager;
import android.app.ActivityOptions;
import android.car.CarNotConnectedException;
import android.car.cluster.navigation.NavigationState.NavigationStateProto;
import android.car.cluster.renderer.InstrumentClusterRenderingService;
import android.car.cluster.renderer.NavigationRenderer;
import android.car.navigation.CarNavigationInstrumentCluster;
+import android.content.BroadcastReceiver;
+import android.content.ComponentName;
+import android.content.Context;
import android.content.Intent;
+import android.content.IntentFilter;
import android.graphics.Rect;
+import android.hardware.display.DisplayManager;
import android.hardware.display.DisplayManager.DisplayListener;
import android.os.Binder;
import android.os.Bundle;
+import android.os.Handler;
import android.os.IBinder;
import android.os.SystemClock;
import android.os.UserHandle;
@@ -58,8 +68,7 @@
public class ClusterRenderingService extends InstrumentClusterRenderingService implements
ImageResolver.BitmapFetcher {
private static final String TAG = "Cluster.Service";
-
- private static final int NO_DISPLAY = -1;
+ private static final int NAVIGATION_ACTIVITY_RETRY_INTERVAL_MS = 1000;
static final int NAV_STATE_EVENT_ID = 1;
static final String LOCAL_BINDING_ACTION = "local";
@@ -67,9 +76,17 @@
private List<ServiceClient> mClients = new ArrayList<>();
private ClusterDisplayProvider mDisplayProvider;
- private int mDisplayId = NO_DISPLAY;
+
+ private int mClusterDisplayId = INVALID_DISPLAY;
+
+ private boolean mInstrumentClusterHelperReady;
+
private final IBinder mLocalBinder = new LocalBinder();
private final ImageResolver mImageResolver = new ImageResolver(this);
+ private final Handler mHandler = new Handler();
+ private final Runnable mLaunchMainActivity = this::launchMainActivity;
+
+ private final UserReceiver mUserReceiver = new UserReceiver();
public interface ServiceClient {
void onKeyEvent(KeyEvent keyEvent);
@@ -84,11 +101,15 @@
}
private final DisplayListener mDisplayListener = new DisplayListener() {
+ // Called in the main thread, since ClusterDisplayProvider.DisplayListener was registered
+ // with null handler.
@Override
public void onDisplayAdded(int displayId) {
Log.i(TAG, "Cluster display found, displayId: " + displayId);
- mDisplayId = displayId;
- launchMainActivity();
+ mClusterDisplayId = displayId;
+ if (mInstrumentClusterHelperReady) {
+ mHandler.post(mLaunchMainActivity);
+ }
}
@Override
@@ -104,7 +125,7 @@
public void setActivityLaunchOptions(int displayId, ClusterActivityState state) {
try {
- ActivityOptions options = displayId != Display.INVALID_DISPLAY
+ ActivityOptions options = displayId != INVALID_DISPLAY
? ActivityOptions.makeBasic().setLaunchDisplayId(displayId)
: null;
setClusterActivityLaunchOptions(CarInstrumentClusterManager.CATEGORY_NAVIGATION,
@@ -138,9 +159,15 @@
@Override
public IBinder onBind(Intent intent) {
Log.d(TAG, "onBind, intent: " + intent);
- return LOCAL_BINDING_ACTION.equals(intent.getAction())
- ? mLocalBinder
- : super.onBind(intent);
+ if (LOCAL_BINDING_ACTION.equals(intent.getAction())) {
+ return mLocalBinder;
+ }
+ IBinder binder = super.onBind(intent);
+ mInstrumentClusterHelperReady = true;
+ if (mClusterDisplayId != INVALID_DISPLAY) {
+ mHandler.post(mLaunchMainActivity);
+ }
+ return binder;
}
@Override
@@ -148,15 +175,60 @@
super.onCreate();
Log.d(TAG, "onCreate");
mDisplayProvider = new ClusterDisplayProvider(this, mDisplayListener);
+
+ mUserReceiver.register(this);
+ }
+
+ public void onDestroy() {
+ super.onDestroy();
+ mUserReceiver.unregister(this);
}
private void launchMainActivity() {
+ mHandler.removeCallbacks(mLaunchMainActivity);
ActivityOptions options = ActivityOptions.makeBasic();
- options.setLaunchDisplayId(mDisplayId);
- Intent intent = new Intent(this, MainClusterActivity.class);
- intent.setFlags(FLAG_ACTIVITY_NEW_TASK);
- startActivityAsUser(intent, options.toBundle(), UserHandle.SYSTEM);
- Log.i(TAG, String.format("launching main activity: %s (display: %d)", intent, mDisplayId));
+ options.setLaunchDisplayId(mClusterDisplayId);
+ boolean useNavigationOnly = getResources().getBoolean(R.bool.navigationOnly);
+ Intent intent;
+ int userId = UserHandle.USER_SYSTEM;
+ if (useNavigationOnly) {
+ intent = getNavigationActivityIntent(mClusterDisplayId);
+ if (intent == null) {
+ mHandler.postDelayed(mLaunchMainActivity, NAVIGATION_ACTIVITY_RETRY_INTERVAL_MS);
+ return;
+ }
+ userId = ActivityManager.getCurrentUser();
+ startFixedActivityModeForDisplayAndUser(intent, options, userId);
+ } else {
+ intent = getMainClusterActivityIntent();
+ startActivityAsUser(intent, options.toBundle(), UserHandle.SYSTEM);
+ }
+ Log.i(TAG, "launching main activity=" + intent + ", display=" + mClusterDisplayId
+ + ", userId=" + userId);
+ }
+
+ private Intent getMainClusterActivityIntent() {
+ return new Intent(this, MainClusterActivity.class).setFlags(FLAG_ACTIVITY_NEW_TASK);
+ }
+
+ private Intent getNavigationActivityIntent(int displayId) {
+ ComponentName component = MainClusterActivity.getNavigationActivity(this);
+ if (component == null) {
+ Log.e(TAG, "Failed to resolve the navigation activity");
+ return null;
+ }
+ Rect displaySize = new Rect(0, 0, 320, 240); // Arbitrary size, better than nothing.
+ DisplayManager dm = (DisplayManager) getSystemService(DisplayManager.class);
+ Display display = dm.getDisplay(displayId);
+ if (display != null) {
+ display.getRectSize(displaySize);
+ }
+ return new Intent(Intent.ACTION_MAIN)
+ .setComponent(component)
+ .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
+ .putExtra(CarInstrumentClusterManager.KEY_EXTRA_ACTIVITY_STATE,
+ ClusterActivityState.create(/* visible= */ true,
+ /* unobscuredBounds= */ displaySize).toBundle());
}
@Override
@@ -319,4 +391,27 @@
}
}
}
+
+ private class UserReceiver extends BroadcastReceiver {
+ void register(Context context) {
+ IntentFilter intentFilter = new IntentFilter(ACTION_USER_UNLOCKED);
+ context.registerReceiverAsUser(this, UserHandle.ALL, intentFilter, null, null);
+ }
+
+ void unregister(Context context) {
+ context.unregisterReceiver(this);
+ }
+
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ if (Log.isLoggable(TAG, Log.DEBUG)) {
+ Log.d(TAG, "Broadcast received: " + intent);
+ }
+ int userId = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, UserHandle.USER_NULL);
+ if (userId == ActivityManager.getCurrentUser() &&
+ mInstrumentClusterHelperReady && mClusterDisplayId != INVALID_DISPLAY) {
+ mHandler.post(mLaunchMainActivity);
+ }
+ }
+ }
}
diff --git a/src/android/car/cluster/MainClusterActivity.java b/src/android/car/cluster/MainClusterActivity.java
index e5f1311..5e19a42 100644
--- a/src/android/car/cluster/MainClusterActivity.java
+++ b/src/android/car/cluster/MainClusterActivity.java
@@ -110,7 +110,6 @@
private static final int NAVIGATION_ACTIVITY_RETRY_INTERVAL_MS = 1000;
private static final int NAVIGATION_ACTIVITY_RELAUNCH_DELAY_MS = 5000;
- private UserReceiver mUserReceiver;
private ActivityMonitor mActivityMonitor = new ActivityMonitor();
private final Handler mHandler = new Handler();
private final Runnable mRetryLaunchNavigationActivity = this::tryLaunchNavigationActivity;
@@ -173,33 +172,6 @@
mClusterViewModel.setCurrentNavigationActivity(activity);
};
- private static class UserReceiver extends BroadcastReceiver {
- private WeakReference<MainClusterActivity> mActivity;
-
- UserReceiver(MainClusterActivity activity) {
- mActivity = new WeakReference<>(activity);
- }
-
- public void register(Context context) {
- IntentFilter intentFilter = new IntentFilter(ACTION_USER_UNLOCKED);
- intentFilter.addAction(ACTION_USER_SWITCHED);
- context.registerReceiver(this, intentFilter);
- }
-
- public void unregister(Context context) {
- context.unregisterReceiver(this);
- }
-
- @Override
- public void onReceive(Context context, Intent intent) {
- MainClusterActivity activity = mActivity.get();
- if (Log.isLoggable(TAG, Log.DEBUG)) {
- Log.d(TAG, "Broadcast received: " + intent);
- }
- activity.tryLaunchNavigationActivity();
- }
- }
-
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -258,9 +230,6 @@
mActivityMonitor.start();
- mUserReceiver = new UserReceiver(this);
- mUserReceiver.register(this);
-
InMemoryPhoneBook.init(this);
PhoneFragmentViewModel phoneViewModel = ViewModelProviders.of(this).get(
@@ -294,7 +263,6 @@
protected void onDestroy() {
super.onDestroy();
Log.d(TAG, "onDestroy");
- mUserReceiver.unregister(this);
mActivityMonitor.stop();
if (mService != null) {
mService.unregisterClient(this);
@@ -414,7 +382,7 @@
}
mHandler.removeCallbacks(mRetryLaunchNavigationActivity);
- ComponentName navigationActivity = getNavigationActivity();
+ ComponentName navigationActivity = getNavigationActivity(this);
mClusterViewModel.setFreeNavigationActivity(navigationActivity);
try {
@@ -456,10 +424,10 @@
* <li>Let the user select one from settings.
* </ul>
*/
- private ComponentName getNavigationActivity() {
- PackageManager pm = getPackageManager();
+ static ComponentName getNavigationActivity(Context context) {
+ PackageManager pm = context.getPackageManager();
int userId = ActivityManager.getCurrentUser();
- String intentString = getString(R.string.freeNavigationIntent);
+ String intentString = context.getString(R.string.freeNavigationIntent);
if (intentString == null) {
Log.w(TAG, "No free navigation activity defined");