1 /* 2 * Copyright (C) 2025 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.wm.shell.common 18 19 import android.app.ActivityManager 20 import android.app.ActivityOptions 21 import android.app.PendingIntent 22 import android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN 23 import android.content.Context 24 import android.content.Intent 25 import android.os.UserHandle 26 import android.view.Display.DEFAULT_DISPLAY 27 import android.window.WindowContainerTransaction 28 import com.android.window.flags.Flags 29 30 /** Creates home intent **/ 31 class HomeIntentProvider( 32 private val context: Context, 33 ) { addLaunchHomePendingIntentnull34 fun addLaunchHomePendingIntent( 35 wct: WindowContainerTransaction, displayId: Int, userId: Int? = null 36 ) { 37 val userHandle = 38 if (userId != null) UserHandle.of(userId) else UserHandle.of(ActivityManager.getCurrentUser()) 39 40 val launchHomeIntent = Intent(Intent.ACTION_MAIN).apply { 41 if (displayId != DEFAULT_DISPLAY) { 42 addCategory(Intent.CATEGORY_SECONDARY_HOME) 43 } else { 44 addCategory(Intent.CATEGORY_HOME) 45 } 46 } 47 val options = ActivityOptions.makeBasic().apply { 48 launchWindowingMode = WINDOWING_MODE_FULLSCREEN 49 pendingIntentBackgroundActivityStartMode = 50 ActivityOptions.MODE_BACKGROUND_ACTIVITY_START_ALLOW_ALWAYS 51 if (Flags.enablePerDisplayDesktopWallpaperActivity()) { 52 launchDisplayId = displayId 53 } 54 } 55 val pendingIntent = PendingIntent.getActivityAsUser( 56 context, 57 /* requestCode= */ 0, 58 launchHomeIntent, 59 PendingIntent.FLAG_IMMUTABLE, 60 /* options= */ null, 61 userHandle, 62 ) 63 wct.sendPendingIntent(pendingIntent, launchHomeIntent, options.toBundle()) 64 } 65 }