| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package com.android.wm.shell.sysui; |
| 18 |
|
| 19 |
import static com.android.wm.shell.protolog.ShellProtoLogGroup.WM_SHELL_INIT; |
| 20 |
|
| 21 |
import android.os.Build; |
| 22 |
import android.os.SystemClock; |
| 23 |
import android.util.Pair; |
| 24 |
|
| 25 |
import androidx.annotation.VisibleForTesting; |
| 26 |
|
| 27 |
import com.android.internal.protolog.common.ProtoLog; |
| 28 |
import com.android.wm.shell.common.ShellExecutor; |
| 29 |
|
| 30 |
import java.util.ArrayList; |
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
public class ShellInit { |
| 38 |
private static final String TAG = ShellInit.class.getSimpleName(); |
| 39 |
|
| 40 |
private final ShellExecutor mMainExecutor; |
| 41 |
|
| 42 |
|
| 43 |
private final ArrayList<Pair<String, Runnable>> mInitCallbacks = new ArrayList<>(); |
| 44 |
private boolean mHasInitialized; |
| 45 |
|
| 46 |
|
| 47 |
public ShellInit(ShellExecutor mainExecutor) { |
| 48 |
mMainExecutor = mainExecutor; |
| 49 |
} |
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
public <T extends Object> void addInitCallback(Runnable r, T instance) { |
| 60 |
if (mHasInitialized) { |
| 61 |
if (Build.isDebuggable()) { |
| 62 |
|
| 63 |
throw new IllegalArgumentException("Can not add callback after init"); |
| 64 |
} |
| 65 |
return; |
| 66 |
} |
| 67 |
final String className = instance.getClass().getSimpleName(); |
| 68 |
mInitCallbacks.add(new Pair<>(className, r)); |
| 69 |
ProtoLog.v(WM_SHELL_INIT, "Adding init callback for %s", className); |
| 70 |
} |
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
@VisibleForTesting |
| 76 |
public void init() { |
| 77 |
ProtoLog.v(WM_SHELL_INIT, "Initializing Shell Components: %d", mInitCallbacks.size()); |
| 78 |
|
| 79 |
for (int i = 0; i < mInitCallbacks.size(); i++) { |
| 80 |
final Pair<String, Runnable> info = mInitCallbacks.get(i); |
| 81 |
final long t1 = SystemClock.uptimeMillis(); |
| 82 |
info.second.run(); |
| 83 |
final long t2 = SystemClock.uptimeMillis(); |
| 84 |
ProtoLog.v(WM_SHELL_INIT, "\t%s init took %dms", info.first, (t2 - t1)); |
| 85 |
} |
| 86 |
mInitCallbacks.clear(); |
| 87 |
mHasInitialized = true; |
| 88 |
} |
| 89 |
} |