blob: c0f578373fe4488967be644ddde422ef831a21ef [file] [log] [blame]
Jason Monk1d9632d2017-02-09 13:20:04 -08001/*
2 * Copyright (C) 2017 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
5 * except in compliance with the License. You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software distributed under the
10 * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
11 * KIND, either express or implied. See the License for the specific language governing
12 * permissions and limitations under the License.
13 */
14
15package com.android.systemui.utils.leaks;
16
17import static org.mockito.Mockito.mock;
18
19import com.android.systemui.statusbar.policy.ExtensionController;
20
21import java.util.function.Consumer;
22import java.util.function.Supplier;
23
24public class FakeExtensionController implements ExtensionController {
25
26 private final Tracker mTracker;
27
28 public FakeExtensionController(LeakCheckedTest test) {
29 mTracker = test.getTracker("extension");
30 }
31
32 @Override
33 public <T> ExtensionBuilder<T> newExtension(Class<T> cls) {
34 final Object o = new Object();
35 mTracker.getLeakInfo(o).addAllocation(new Throwable());
36 return new FakeExtensionBuilder(o);
37 }
38
39 private class FakeExtensionBuilder<T> implements ExtensionBuilder<T> {
40 private final Object mAllocation;
41
42 public FakeExtensionBuilder(Object o) {
43 mAllocation = o;
44 }
45
46 @Override
47 public ExtensionBuilder<T> withTunerFactory(TunerFactory<T> factory) {
48 return this;
49 }
50
51 @Override
52 public <P extends T> ExtensionBuilder<T> withPlugin(Class<P> cls) {
53 return this;
54 }
55
56 @Override
57 public <P extends T> ExtensionBuilder<T> withPlugin(Class<P> cls, String action) {
58 return this;
59 }
60
61 @Override
62 public <P> ExtensionBuilder<T> withPlugin(Class<P> cls, String action, PluginConverter<T, P> converter) {
63 return this;
64 }
65
66 @Override
67 public ExtensionBuilder<T> withDefault(Supplier<T> def) {
68 return this;
69 }
70
71 @Override
72 public ExtensionBuilder<T> withCallback(Consumer<T> callback) {
73 return this;
74 }
75
76 @Override
77 public Extension build() {
78 return new FakeExtension(mAllocation);
79 }
80 }
81
82 private class FakeExtension<T> implements Extension<T> {
83 private final Object mAllocation;
84
85 public FakeExtension(Object allocation) {
86 mAllocation = allocation;
87 }
88
89 @Override
90 public T get() {
91 // TODO: Support defaults or things.
92 return null;
93 }
94
95 @Override
96 public void destroy() {
97 mTracker.getLeakInfo(mAllocation).clearAllocations();
98 }
99 }
100}