• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2019 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 
17 package android.view;
18 
19 import android.annotation.NonNull;
20 import android.annotation.Nullable;
21 import android.graphics.Matrix;
22 import android.os.IBinder;
23 import android.view.accessibility.AccessibilityManager;
24 import android.view.accessibility.IAccessibilityEmbeddedConnection;
25 
26 import java.lang.ref.WeakReference;
27 
28 /**
29  * This class is an interface this ViewRootImpl provides to the host view to the latter
30  * can interact with the view hierarchy in SurfaceControlViewHost.
31  *
32  * @hide
33  */
34 final class AccessibilityEmbeddedConnection extends IAccessibilityEmbeddedConnection.Stub {
35     private final WeakReference<ViewRootImpl> mViewRootImpl;
36     private final Matrix mTmpWindowMatrix = new Matrix();
37 
AccessibilityEmbeddedConnection(ViewRootImpl viewRootImpl)38     AccessibilityEmbeddedConnection(ViewRootImpl viewRootImpl) {
39         mViewRootImpl = new WeakReference<>(viewRootImpl);
40     }
41 
42     @Override
associateEmbeddedHierarchy(@onNull IBinder host, int hostViewId)43     public @Nullable IBinder associateEmbeddedHierarchy(@NonNull IBinder host, int hostViewId) {
44         final ViewRootImpl viewRootImpl = mViewRootImpl.get();
45         if (viewRootImpl != null) {
46             final AccessibilityManager accessibilityManager = AccessibilityManager.getInstance(
47                     viewRootImpl.mContext);
48             viewRootImpl.mAttachInfo.mLeashedParentToken = host;
49             viewRootImpl.mAttachInfo.mLeashedParentAccessibilityViewId = hostViewId;
50             if (accessibilityManager.isEnabled()) {
51                 accessibilityManager.associateEmbeddedHierarchy(host, viewRootImpl.mLeashToken);
52             }
53             return viewRootImpl.mLeashToken;
54         }
55         return null;
56     }
57 
58     @Override
disassociateEmbeddedHierarchy()59     public void disassociateEmbeddedHierarchy() {
60         final ViewRootImpl viewRootImpl = mViewRootImpl.get();
61         if (viewRootImpl != null) {
62             final AccessibilityManager accessibilityManager = AccessibilityManager.getInstance(
63                     viewRootImpl.mContext);
64             viewRootImpl.mAttachInfo.mLeashedParentToken = null;
65             viewRootImpl.mAttachInfo.mLeashedParentAccessibilityViewId = View.NO_ID;
66             if (accessibilityManager.isEnabled()) {
67                 accessibilityManager.disassociateEmbeddedHierarchy(viewRootImpl.mLeashToken);
68             }
69         }
70     }
71 
72     @Override
setWindowMatrix(float[] matrixValues)73     public void setWindowMatrix(float[] matrixValues) {
74         final ViewRootImpl viewRootImpl = mViewRootImpl.get();
75         if (viewRootImpl != null) {
76             mTmpWindowMatrix.setValues(matrixValues);
77             if (viewRootImpl.mAttachInfo.mWindowMatrixInEmbeddedHierarchy == null) {
78                 viewRootImpl.mAttachInfo.mWindowMatrixInEmbeddedHierarchy = new Matrix();
79             }
80             viewRootImpl.mAttachInfo.mWindowMatrixInEmbeddedHierarchy.set(mTmpWindowMatrix);
81         }
82     }
83 }
84