1 /* 2 * Copyright (C) 2024 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.systemui.car.wm.activity; 18 19 import android.app.Activity; 20 import android.app.ActivityOptions; 21 import android.content.Intent; 22 import android.os.Bundle; 23 import android.util.Log; 24 import android.util.Slog; 25 26 import com.android.internal.annotations.VisibleForTesting; 27 import com.android.systemui.R; 28 29 /** 30 * Router activity used to launch the intended activity on the desired private display. 31 */ 32 public class LaunchOnPrivateDisplayRouterActivity extends Activity { 33 private static final String TAG = "LaunchRouterActivity"; 34 private static final boolean DBG = Log.isLoggable(TAG, Log.DEBUG); 35 private static final String NAMESPACE_KEY = "com.android.car.app.private_display"; 36 @VisibleForTesting 37 static final String LAUNCH_ACTIVITY = NAMESPACE_KEY + ".launch_activity"; 38 @VisibleForTesting 39 static final String LAUNCH_ACTIVITY_OPTIONS = 40 NAMESPACE_KEY + ".launch_activity_options"; 41 @VisibleForTesting 42 static final String LAUNCH_ACTIVITY_DISPLAY_ID = 43 NAMESPACE_KEY + ".launch_activity_display_id"; 44 45 @Override onCreate(Bundle savedInstanceState)46 public void onCreate(Bundle savedInstanceState) { 47 super.onCreate(savedInstanceState); 48 setContentView(R.layout.launch_on_private_display_router_activity); 49 50 Intent launchIntent = getIntent(); 51 if (launchIntent != null && launchIntent.hasExtra(LAUNCH_ACTIVITY)) { 52 int launchDisplayId = launchIntent.getExtras().getInt(LAUNCH_ACTIVITY_DISPLAY_ID); 53 Intent appIntent = (Intent) launchIntent.getExtras().get(LAUNCH_ACTIVITY); 54 Bundle options; 55 if (launchIntent.hasExtra(LAUNCH_ACTIVITY_OPTIONS)) { 56 options = launchIntent.getBundleExtra(LAUNCH_ACTIVITY_OPTIONS); 57 } else { 58 options = ActivityOptions.makeBasic().toBundle(); 59 } 60 ActivityOptions activityOptions = ActivityOptions.fromBundle(options); 61 activityOptions.setLaunchDisplayId(launchDisplayId); 62 appIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 63 if (DBG) { 64 Slog.d(TAG, "launchDisplayId: " + launchDisplayId + ", appIntent: " + appIntent); 65 } 66 startActivity(appIntent, activityOptions.toBundle()); 67 } else { 68 Slog.e(TAG, "failed to dispatch intent " + getIntent() 69 + " since key for launching on the private display does not exist."); 70 } 71 finish(); 72 } 73 } 74