Home | History | Annotate | Download | only in app
      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.app.AlertDialog;
     23 import android.os.Bundle;
     24 import android.view.View;
     25 import android.view.WindowManager;
     26 import android.widget.Button;
     27 
     28 /**
     29  * <h3>Secure Dialog Activity</h3>
     30  *
     31  * <p>
     32  * This activity demonstrates how to create a dialog whose window is backed by
     33  * a secure surface using {@link WindowManager.LayoutParams#FLAG_SECURE}.
     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 SecureDialogActivity extends Activity
     54         implements View.OnClickListener {
     55     /**
     56      * Initialization of the Activity after it is first created.  Must at least
     57      * call {@link android.app.Activity#setContentView setContentView()} to
     58      * describe what is to be displayed in the screen.
     59      */
     60     @Override
     61     protected void onCreate(Bundle savedInstanceState) {
     62         // Be sure to call the super class.
     63         super.onCreate(savedInstanceState);
     64 
     65         // See assets/res/any/layout/secure_dialog_activity.xml for this
     66         // view layout definition, which is being set here as
     67         // the content of our screen.
     68         setContentView(R.layout.secure_dialog_activity);
     69 
     70         // Handle click events on the button to show the dialog.
     71         Button button = (Button)findViewById(R.id.show);
     72         button.setOnClickListener(this);
     73     }
     74 
     75     /**
     76      * Called when the button to show the dialog is clicked.
     77      */
     78     @Override
     79     public void onClick(View v) {
     80         // Create a dialog.
     81         AlertDialog dialog = new AlertDialog.Builder(this)
     82                 .setPositiveButton(android.R.string.ok, null)
     83                 .setMessage(R.string.secure_dialog_dialog_text)
     84                 .create();
     85 
     86         // Make the dialog secure.  This must be done at the time the dialog is
     87         // created.  It cannot be changed after the dialog has been shown.
     88         dialog.getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE,
     89                 WindowManager.LayoutParams.FLAG_SECURE);
     90 
     91         // Show the dialog.
     92         dialog.show();
     93     }
     94 }
     95