Jason Monk | 1d9632d | 2017-02-09 13:20:04 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
| 15 | package com.android.systemui.utils.leaks; |
| 16 | |
Jason Monk | 340b0e5 | 2017-03-08 14:57:56 -0500 | [diff] [blame] | 17 | import android.testing.LeakCheck; |
| 18 | import android.testing.LeakCheck.Tracker; |
Jason Monk | 1d9632d | 2017-02-09 13:20:04 -0800 | [diff] [blame] | 19 | |
| 20 | import com.android.systemui.statusbar.policy.ExtensionController; |
| 21 | |
| 22 | import java.util.function.Consumer; |
| 23 | import java.util.function.Supplier; |
| 24 | |
| 25 | public class FakeExtensionController implements ExtensionController { |
| 26 | |
| 27 | private final Tracker mTracker; |
| 28 | |
Jason Monk | 340b0e5 | 2017-03-08 14:57:56 -0500 | [diff] [blame] | 29 | public FakeExtensionController(LeakCheck test) { |
Jason Monk | 1d9632d | 2017-02-09 13:20:04 -0800 | [diff] [blame] | 30 | mTracker = test.getTracker("extension"); |
| 31 | } |
| 32 | |
| 33 | @Override |
| 34 | public <T> ExtensionBuilder<T> newExtension(Class<T> cls) { |
| 35 | final Object o = new Object(); |
| 36 | mTracker.getLeakInfo(o).addAllocation(new Throwable()); |
| 37 | return new FakeExtensionBuilder(o); |
| 38 | } |
| 39 | |
| 40 | private class FakeExtensionBuilder<T> implements ExtensionBuilder<T> { |
| 41 | private final Object mAllocation; |
| 42 | |
| 43 | public FakeExtensionBuilder(Object o) { |
| 44 | mAllocation = o; |
| 45 | } |
| 46 | |
| 47 | @Override |
| 48 | public ExtensionBuilder<T> withTunerFactory(TunerFactory<T> factory) { |
| 49 | return this; |
| 50 | } |
| 51 | |
| 52 | @Override |
| 53 | public <P extends T> ExtensionBuilder<T> withPlugin(Class<P> cls) { |
| 54 | return this; |
| 55 | } |
| 56 | |
| 57 | @Override |
| 58 | public <P extends T> ExtensionBuilder<T> withPlugin(Class<P> cls, String action) { |
| 59 | return this; |
| 60 | } |
| 61 | |
| 62 | @Override |
| 63 | public <P> ExtensionBuilder<T> withPlugin(Class<P> cls, String action, PluginConverter<T, P> converter) { |
| 64 | return this; |
| 65 | } |
| 66 | |
| 67 | @Override |
| 68 | public ExtensionBuilder<T> withDefault(Supplier<T> def) { |
| 69 | return this; |
| 70 | } |
| 71 | |
| 72 | @Override |
| 73 | public ExtensionBuilder<T> withCallback(Consumer<T> callback) { |
| 74 | return this; |
| 75 | } |
| 76 | |
| 77 | @Override |
| 78 | public Extension build() { |
| 79 | return new FakeExtension(mAllocation); |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | private class FakeExtension<T> implements Extension<T> { |
| 84 | private final Object mAllocation; |
| 85 | |
| 86 | public FakeExtension(Object allocation) { |
| 87 | mAllocation = allocation; |
| 88 | } |
| 89 | |
| 90 | @Override |
| 91 | public T get() { |
| 92 | // TODO: Support defaults or things. |
| 93 | return null; |
| 94 | } |
| 95 | |
| 96 | @Override |
| 97 | public void destroy() { |
| 98 | mTracker.getLeakInfo(mAllocation).clearAllocations(); |
| 99 | } |
Jason Monk | a295289 | 2017-05-26 10:38:54 -0400 | [diff] [blame] | 100 | |
| 101 | @Override |
| 102 | public T reload() { |
| 103 | return null; |
| 104 | } |
Jason Monk | 1d9632d | 2017-02-09 13:20:04 -0800 | [diff] [blame] | 105 | } |
| 106 | } |