• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 import androidx.annotation.Nullable;
24 
25 /** Util class to generate surface view requests and parse responses */
26 public class SurfaceViewUtils {
27 
28     private static final String KEY_HOST_TOKEN = "host_token";
29     private static final String KEY_VIEW_WIDTH = "width";
30     private static final String KEY_VIEW_HEIGHT = "height";
31     private static final String KEY_DISPLAY_ID = "display_id";
32     private static final String KEY_SURFACE_PACKAGE = "surface_package";
33     private static final String KEY_CALLBACK = "callback";
34 
35     /** Create a surface view request. */
createSurfaceViewRequest(SurfaceView surfaceView)36     public static Bundle createSurfaceViewRequest(SurfaceView surfaceView) {
37         return createSurfaceViewRequest(surfaceView, null);
38     }
39 
40     /** Create a surface view request. */
createSurfaceViewRequest( SurfaceView surfaceView, @Nullable Bundle extras)41     public static Bundle createSurfaceViewRequest(
42             SurfaceView surfaceView,
43             @Nullable Bundle extras) {
44         Bundle bundle = new Bundle();
45         bundle.putBinder(KEY_HOST_TOKEN, surfaceView.getHostToken());
46         bundle.putInt(KEY_DISPLAY_ID, surfaceView.getDisplay().getDisplayId());
47         bundle.putInt(KEY_VIEW_WIDTH, surfaceView.getWidth());
48         bundle.putInt(KEY_VIEW_HEIGHT, surfaceView.getHeight());
49         if (extras != null) {
50             bundle.putAll(extras);
51         }
52         return bundle;
53     }
54 
55     /** Return the surface package. */
getSurfacePackage(Bundle bundle)56     public static SurfaceControlViewHost.SurfacePackage getSurfacePackage(Bundle bundle) {
57         return bundle.getParcelable(KEY_SURFACE_PACKAGE);
58     }
59 
60     /** Return the message callback. */
getCallback(Bundle bundle)61     public static Message getCallback(Bundle bundle) {
62         return bundle.getParcelable(KEY_CALLBACK);
63     }
64 }
65