• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 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.server.am;
18 
19 import android.app.WindowConfiguration;
20 import android.app.nano.WindowConfigurationProto;
21 import android.content.nano.ConfigurationProto;
22 import android.content.res.Configuration;
23 import android.graphics.Rect;
24 import android.graphics.nano.RectProto;
25 
26 /**
27  * Utility class for extracting some common framework object from nano proto objects.
28  * Normally the extractors will be in the framework object class, but we don't want the framework to
29  * depend on nano proto due to size cost.
30  * TODO: This class should probably be in frameworks/base/lib project so it can be used
31  * outside of CTS.
32  */
33 public class ProtoExtractors {
extract(ConfigurationProto proto)34     public static Configuration extract(ConfigurationProto proto) {
35         final Configuration config = new Configuration();
36         if (proto == null) {
37             return config;
38         }
39         config.windowConfiguration.setTo(extract(proto.windowConfiguration));
40         config.densityDpi = proto.densityDpi;
41         config.orientation = proto.orientation;
42         config.screenHeightDp = proto.screenHeightDp;
43         config.screenWidthDp = proto.screenWidthDp;
44         config.smallestScreenWidthDp = proto.smallestScreenWidthDp;
45         config.screenLayout = proto.screenLayout;
46         config.uiMode = proto.uiMode;
47         return config;
48     }
49 
extract(WindowConfigurationProto proto)50     public static WindowConfiguration extract(WindowConfigurationProto proto) {
51         final WindowConfiguration config = new WindowConfiguration();
52         if (proto == null) {
53             return config;
54         }
55         config.setAppBounds(extract(proto.appBounds));
56         config.setWindowingMode(proto.windowingMode);
57         config.setActivityType(proto.activityType);
58         return config;
59     }
60 
extract(RectProto proto)61     public static Rect extract(RectProto proto) {
62         if (proto == null) {
63             return null;
64         }
65         return new Rect(proto.left, proto.top, proto.right, proto.bottom);
66     }
67 }
68