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 21 import android.app.Activity; 22 import android.os.Bundle; 23 import android.view.WindowManager; 24 25 /** 26 * <h3>Secure Window Activity</h3> 27 * 28 * <p> 29 * This activity demonstrates how to create an activity whose window is backed by 30 * a secure surface using {@link WindowManager.LayoutParams#FLAG_SECURE}. 31 * Because the surface is secure, its contents cannot be captured in screenshots 32 * and will not be visible on non-secure displays even when mirrored. 33 * </p><p> 34 * Here are a few things you can do to experiment with secure surfaces and 35 * observe their behavior. 36 * <ul> 37 * <li>Try taking a screenshot. Either the system will prevent you from taking 38 * a screenshot altogether or the screenshot should not contain the contents 39 * of the secure surface. 40 * <li>Try mirroring the secure surface onto a non-secure display such as an 41 * "Overlay Display" created using the "Simulate secondary displays" option in 42 * the "Developer options" section of the Settings application. The non-secure 43 * secondary display should not show the contents of the secure surface. 44 * <li>Try mirroring the secure surface onto a secure display such as an 45 * HDMI display with HDCP enabled. The contents of the secure surface should appear 46 * on the display. 47 * </ul> 48 * </p> 49 */ 50 public class SecureWindowActivity extends Activity { 51 /** 52 * Initialization of the Activity after it is first created. Must at least 53 * call {@link android.app.Activity#setContentView setContentView()} to 54 * describe what is to be displayed in the screen. 55 */ 56 @Override onCreate(Bundle savedInstanceState)57 protected void onCreate(Bundle savedInstanceState) { 58 // Be sure to call the super class. 59 super.onCreate(savedInstanceState); 60 61 // See assets/res/any/layout/secure_window_activity.xml for this 62 // view layout definition, which is being set here as 63 // the content of our screen. 64 setContentView(R.layout.secure_window_activity); 65 66 // Make the window secure. This must be done at the time the activity 67 // is created. It cannot be changed later. 68 getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE, 69 WindowManager.LayoutParams.FLAG_SECURE); 70 } 71 } 72