blob: dcb9a6a3e1f3ff635f29962c7a56a00fe028a1c8 [file] [log] [blame]
Jorim Jaggi04dc5962018-01-29 18:54:13 +01001/*
2 * Copyright (C) 2018 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
Wale Ogunwale59507092018-10-29 09:00:30 -070017package com.android.server.wm;
Jorim Jaggi04dc5962018-01-29 18:54:13 +010018
19import android.annotation.Nullable;
20import android.app.ActivityOptions;
21import android.os.Handler;
22import android.util.ArrayMap;
23import android.view.RemoteAnimationAdapter;
24
Wale Ogunwale59507092018-10-29 09:00:30 -070025import com.android.server.am.ActivityManagerService;
26
Jorim Jaggi04dc5962018-01-29 18:54:13 +010027/**
28 * Registry to keep track of remote animations to be run for activity starts from a certain package.
29 *
30 * @see ActivityManagerService#registerRemoteAnimationForNextActivityStart
31 */
32class PendingRemoteAnimationRegistry {
33
34 private static final long TIMEOUT_MS = 3000;
35
36 private final ArrayMap<String, Entry> mEntries = new ArrayMap<>();
37 private final Handler mHandler;
Wale Ogunwalec9e57de2018-05-08 14:28:07 -070038 private final ActivityTaskManagerService mService;
Jorim Jaggi04dc5962018-01-29 18:54:13 +010039
Wale Ogunwalec9e57de2018-05-08 14:28:07 -070040 PendingRemoteAnimationRegistry(ActivityTaskManagerService service, Handler handler) {
Jorim Jaggi04dc5962018-01-29 18:54:13 +010041 mService = service;
42 mHandler = handler;
43 }
44
45 /**
46 * Adds a remote animation to be run for all activity starts originating from a certain package.
47 */
48 void addPendingAnimation(String packageName, RemoteAnimationAdapter adapter) {
49 mEntries.put(packageName, new Entry(packageName, adapter));
50 }
51
52 /**
53 * Overrides the activity options with a registered remote animation for a certain calling
54 * package if such a remote animation is registered.
55 */
56 ActivityOptions overrideOptionsIfNeeded(String callingPackage,
57 @Nullable ActivityOptions options) {
58 final Entry entry = mEntries.get(callingPackage);
59 if (entry == null) {
60 return options;
61 }
62 if (options == null) {
63 options = ActivityOptions.makeRemoteAnimation(entry.adapter);
64 } else {
65 options.setRemoteAnimationAdapter(entry.adapter);
66 }
67 mEntries.remove(callingPackage);
68 return options;
69 }
70
71 private class Entry {
72 final String packageName;
73 final RemoteAnimationAdapter adapter;
74
75 Entry(String packageName, RemoteAnimationAdapter adapter) {
76 this.packageName = packageName;
77 this.adapter = adapter;
78 mHandler.postDelayed(() -> {
Wale Ogunwalec9e57de2018-05-08 14:28:07 -070079 synchronized (mService.mGlobalLock) {
Jorim Jaggi04dc5962018-01-29 18:54:13 +010080 final Entry entry = mEntries.get(packageName);
81 if (entry == this) {
82 mEntries.remove(packageName);
83 }
84 }
85 }, TIMEOUT_MS);
86 }
87 }
88}