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.animation; 18 19 import android.util.ArrayMap; 20 import android.view.RemoteAnimationTarget; 21 import android.view.SurfaceControl; 22 import android.window.TransitionInfo; 23 import android.window.TransitionInfo.Change; 24 25 import com.android.wm.shell.shared.TransitionUtil; 26 27 import java.util.ArrayList; 28 import java.util.function.Predicate; 29 30 /** 31 * Some utility methods for creating {@link RemoteAnimationTarget} instances. 32 */ 33 public class RemoteAnimationTargetCompat { 34 35 /** 36 * Represents a TransitionInfo object as an array of old-style app targets 37 * 38 * @param leashMap Temporary map of change leash -> launcher leash. Is an output, so should be 39 * populated by this function. If null, it is ignored. 40 */ wrapApps(TransitionInfo info, SurfaceControl.Transaction t, ArrayMap<SurfaceControl, SurfaceControl> leashMap)41 public static RemoteAnimationTarget[] wrapApps(TransitionInfo info, 42 SurfaceControl.Transaction t, ArrayMap<SurfaceControl, SurfaceControl> leashMap) { 43 // LeafTaskFilter is order-dependent, so the same object needs to be used for all Change 44 // objects. That's why it's constructed here and captured by the lambda instead of building 45 // a new one ad hoc every time. 46 TransitionUtil.LeafTaskFilter taskFilter = new TransitionUtil.LeafTaskFilter(); 47 return wrap(info, t, leashMap, (change) -> { 48 // Intra-task activity -> activity transitions should be categorized as apps. 49 if (change.getActivityComponent() != null) return true; 50 return taskFilter.test(change); 51 }); 52 } 53 54 /** 55 * Represents a TransitionInfo object as an array of old-style non-app targets 56 * 57 * @param wallpapers If true, this will return wallpaper targets; otherwise it returns 58 * non-wallpaper targets. 59 * @param leashMap Temporary map of change leash -> launcher leash. Is an output, so should be 60 * populated by this function. If null, it is ignored. 61 */ wrapNonApps(TransitionInfo info, boolean wallpapers, SurfaceControl.Transaction t, ArrayMap<SurfaceControl, SurfaceControl> leashMap)62 public static RemoteAnimationTarget[] wrapNonApps(TransitionInfo info, boolean wallpapers, 63 SurfaceControl.Transaction t, ArrayMap<SurfaceControl, SurfaceControl> leashMap) { 64 return wrap(info, t, leashMap, (change) -> { 65 // Intra-task activity -> activity transitions should be categorized as apps. 66 if (change.getActivityComponent() != null) return false; 67 return wallpapers 68 ? TransitionUtil.isWallpaper(change) : TransitionUtil.isNonApp(change); 69 }); 70 } 71 72 private static RemoteAnimationTarget[] wrap(TransitionInfo info, 73 SurfaceControl.Transaction t, ArrayMap<SurfaceControl, SurfaceControl> leashMap, 74 Predicate<Change> filter) { 75 final ArrayList<RemoteAnimationTarget> out = new ArrayList<>(); 76 for (int i = 0; i < info.getChanges().size(); i++) { 77 TransitionInfo.Change change = info.getChanges().get(i); 78 if (TransitionUtil.isOrderOnly(change)) continue; 79 if (filter.test(change)) { 80 out.add(TransitionUtil.newTarget( 81 change, info.getChanges().size() - i, info, t, leashMap)); 82 } 83 } 84 return out.toArray(new RemoteAnimationTarget[out.size()]); 85 } 86 } 87