1 /*
2  * Copyright (C) 2020 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 package com.android.wallpaper.util;
17 
18 import android.os.Bundle;
19 import android.os.Message;
20 import android.view.SurfaceControlViewHost;
21 import android.view.SurfaceView;
22 
23 /** Util class to generate surface view requests and parse responses */
24 public class SurfaceViewUtils {
25 
26     private static final String KEY_HOST_TOKEN = "host_token";
27     private static final String KEY_VIEW_WIDTH = "width";
28     private static final String KEY_VIEW_HEIGHT = "height";
29     private static final String KEY_DISPLAY_ID = "display_id";
30     private static final String KEY_SURFACE_PACKAGE = "surface_package";
31     private static final String KEY_CALLBACK = "callback";
32 
33     /** Create a surface view request. */
createSurfaceViewRequest(SurfaceView surfaceView)34     public static Bundle createSurfaceViewRequest(SurfaceView surfaceView) {
35         Bundle bundle = new Bundle();
36         bundle.putBinder(KEY_HOST_TOKEN, surfaceView.getHostToken());
37         bundle.putInt(KEY_DISPLAY_ID, surfaceView.getDisplay().getDisplayId());
38         bundle.putInt(KEY_VIEW_WIDTH, surfaceView.getWidth());
39         bundle.putInt(KEY_VIEW_HEIGHT, surfaceView.getHeight());
40         return bundle;
41     }
42 
43     /** Return the surface package. */
getSurfacePackage(Bundle bundle)44     public static SurfaceControlViewHost.SurfacePackage getSurfacePackage(Bundle bundle) {
45         return bundle.getParcelable(KEY_SURFACE_PACKAGE);
46     }
47 
48     /** Return the message callback. */
getCallback(Bundle bundle)49     public static Message getCallback(Bundle bundle) {
50         return bundle.getParcelable(KEY_CALLBACK);
51     }
52 }
53