• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2012 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 com.example.android.apis.app;
18 
19 import com.example.android.apis.R;
20 import com.example.android.apis.graphics.CubeRenderer;
21 
22 import android.app.Activity;
23 import android.opengl.GLSurfaceView;
24 import android.os.Bundle;
25 import android.view.SurfaceView;
26 import android.view.WindowManager;
27 
28 /**
29  * <h3>Secure Window Activity</h3>
30  *
31  * <p>
32  * This activity demonstrates how to create a {@link SurfaceView} backed by
33  * a secure surface using {@link SurfaceView#setSecure}.
34  * Because the surface is secure, its contents cannot be captured in screenshots
35  * and will not be visible on non-secure displays even when mirrored.
36  * </p><p>
37  * Here are a few things you can do to experiment with secure surfaces and
38  * observe their behavior.
39  * <ul>
40  * <li>Try taking a screenshot.  Either the system will prevent you from taking
41  * a screenshot altogether or the screenshot should not contain the contents
42  * of the secure surface.
43  * <li>Try mirroring the secure surface onto a non-secure display such as an
44  * "Overlay Display" created using the "Simulate secondary displays" option in
45  * the "Developer options" section of the Settings application.  The non-secure
46  * secondary display should not show the contents of the secure surface.
47  * <li>Try mirroring the secure surface onto a secure display such as an
48  * HDMI display with HDCP enabled.  The contents of the secure surface should appear
49  * on the display.
50  * </ul>
51  * </p>
52  */
53 public class SecureSurfaceViewActivity extends Activity {
54     private GLSurfaceView mSurfaceView;
55 
56     /**
57      * Initialization of the Activity after it is first created.  Must at least
58      * call {@link android.app.Activity#setContentView setContentView()} to
59      * describe what is to be displayed in the screen.
60      */
61     @Override
onCreate(Bundle savedInstanceState)62     protected void onCreate(Bundle savedInstanceState) {
63         // Be sure to call the super class.
64         super.onCreate(savedInstanceState);
65 
66         // See assets/res/any/layout/secure_surface_view_activity.xml for this
67         // view layout definition, which is being set here as
68         // the content of our screen.
69         setContentView(R.layout.secure_surface_view_activity);
70 
71         // Set up the surface view.
72         // We use a GLSurfaceView in this demonstration but ordinary
73         // SurfaceViews also support the same secure surface functionality.
74         mSurfaceView = (GLSurfaceView)findViewById(R.id.surface_view);
75         mSurfaceView.setRenderer(new CubeRenderer(false));
76 
77         // Make the surface view secure.  This must be done at the time the surface view
78         // is created before the surface view's containing window is attached to
79         // the window manager which happens after onCreate returns.
80         // It cannot be changed later.
81         mSurfaceView.setSecure(true);
82     }
83 
84     @Override
onResume()85     protected void onResume() {
86         // Be sure to call the super class.
87         super.onResume();
88 
89         // Resume rendering.
90         mSurfaceView.onResume();
91     }
92 
93     @Override
onPause()94     protected void onPause() {
95         // Be sure to call the super class.
96         super.onPause();
97 
98         // Pause rendering.
99         mSurfaceView.onPause();
100     }
101 }
102