| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
package android.window; |
| 17 |
|
| 18 |
import static android.view.WindowManagerImpl.createWindowContextWindowManager; |
| 19 |
|
| 20 |
import static com.android.internal.annotations.VisibleForTesting.Visibility.PACKAGE; |
| 21 |
|
| 22 |
import android.annotation.NonNull; |
| 23 |
import android.annotation.Nullable; |
| 24 |
import android.annotation.UiContext; |
| 25 |
import android.content.ComponentCallbacks; |
| 26 |
import android.content.ComponentCallbacksController; |
| 27 |
import android.content.Context; |
| 28 |
import android.content.ContextWrapper; |
| 29 |
import android.content.res.Configuration; |
| 30 |
import android.os.Bundle; |
| 31 |
import android.view.Display; |
| 32 |
import android.view.WindowManager; |
| 33 |
|
| 34 |
import com.android.internal.annotations.VisibleForTesting; |
| 35 |
|
| 36 |
import java.lang.ref.Reference; |
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
@UiContext |
| 48 |
public class WindowContext extends ContextWrapper implements WindowProvider { |
| 49 |
private final WindowManager mWindowManager; |
| 50 |
@WindowManager.LayoutParams.WindowType |
| 51 |
private final int mType; |
| 52 |
@Nullable |
| 53 |
private final Bundle mOptions; |
| 54 |
private final ComponentCallbacksController mCallbacksController = |
| 55 |
new ComponentCallbacksController(); |
| 56 |
private final WindowContextController mController; |
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
public WindowContext(@NonNull Context base, int type, @Nullable Bundle options) { |
| 77 |
super(base); |
| 78 |
|
| 79 |
mType = type; |
| 80 |
mOptions = options; |
| 81 |
mWindowManager = createWindowContextWindowManager(this); |
| 82 |
WindowTokenClient token = (WindowTokenClient) getWindowContextToken(); |
| 83 |
mController = new WindowContextController(token); |
| 84 |
|
| 85 |
Reference.reachabilityFence(this); |
| 86 |
} |
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
public void attachToDisplayArea() { |
| 94 |
mController.attachToDisplayArea(mType, getDisplayId(), mOptions); |
| 95 |
} |
| 96 |
|
| 97 |
@Override |
| 98 |
public Object getSystemService(String name) { |
| 99 |
if (WINDOW_SERVICE.equals(name)) { |
| 100 |
return mWindowManager; |
| 101 |
} |
| 102 |
return super.getSystemService(name); |
| 103 |
} |
| 104 |
|
| 105 |
@Override |
| 106 |
protected void finalize() throws Throwable { |
| 107 |
release(); |
| 108 |
super.finalize(); |
| 109 |
} |
| 110 |
|
| 111 |
|
| 112 |
@VisibleForTesting |
| 113 |
public void release() { |
| 114 |
mController.detachIfNeeded(); |
| 115 |
destroy(); |
| 116 |
} |
| 117 |
|
| 118 |
@Override |
| 119 |
public void destroy() { |
| 120 |
try { |
| 121 |
mCallbacksController.clearCallbacks(); |
| 122 |
|
| 123 |
getBaseContext().destroy(); |
| 124 |
} finally { |
| 125 |
Reference.reachabilityFence(this); |
| 126 |
} |
| 127 |
} |
| 128 |
|
| 129 |
@Override |
| 130 |
public void registerComponentCallbacks(@NonNull ComponentCallbacks callback) { |
| 131 |
mCallbacksController.registerCallbacks(callback); |
| 132 |
} |
| 133 |
|
| 134 |
@Override |
| 135 |
public void unregisterComponentCallbacks(@NonNull ComponentCallbacks callback) { |
| 136 |
mCallbacksController.unregisterCallbacks(callback); |
| 137 |
} |
| 138 |
|
| 139 |
|
| 140 |
@VisibleForTesting(visibility = PACKAGE) |
| 141 |
public void dispatchConfigurationChanged(@NonNull Configuration newConfig) { |
| 142 |
mCallbacksController.dispatchConfigurationChanged(newConfig); |
| 143 |
} |
| 144 |
|
| 145 |
@Override |
| 146 |
public int getWindowType() { |
| 147 |
return mType; |
| 148 |
} |
| 149 |
|
| 150 |
@Nullable |
| 151 |
@Override |
| 152 |
public Bundle getWindowContextOptions() { |
| 153 |
return mOptions; |
| 154 |
} |
| 155 |
} |