Add ApiDemos for secure surfaces.

Added three ApiDemos for secure surfaces.  One for Activity,
one for Dialog and one for SurfaceView.  The mechanism is the
same in each case but the API is a little different.

Bug: 7368436
Change-Id: I78bc2a456b4c0f1a553120d72f433095ba7e038c
This commit is contained in:
Jeff Brown
2012-10-23 20:40:38 -07:00
parent dc14aa6f1c
commit c875f9321a
10 changed files with 409 additions and 3 deletions

View File

@@ -64,9 +64,10 @@ public class PresentationActivity extends Activity
// The content that we want to show on the presentation.
private static final int[] CHANNELS = new int[] {
R.drawable.sample_4, R.drawable.frantic, R.drawable.beach,
R.drawable.frantic,
R.drawable.photo1, R.drawable.photo2, R.drawable.photo3,
R.drawable.photo4, R.drawable.photo5, R.drawable.photo6,
R.drawable.sample_4,
};
private DisplayManager mDisplayManager;
@@ -182,8 +183,9 @@ public class PresentationActivity extends Activity
}
private int getNextChannel() {
final int channel = mNextChannelNumber;
mNextChannelNumber = (mNextChannelNumber + 1) % CHANNELS.length;
return mNextChannelNumber;
return channel;
}
@Override

View File

@@ -0,0 +1,94 @@
/*
* Copyright (C) 2012 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.example.android.apis.app;
import com.example.android.apis.R;
import android.app.Activity;
import android.app.AlertDialog;
import android.os.Bundle;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
/**
* <h3>Secure Dialog Activity</h3>
*
* <p>
* This activity demonstrates how to create a dialog whose window is backed by
* a secure surface using {@link WindowManager.LayoutParams#FLAG_SECURE}.
* Because the surface is secure, its contents cannot be captured in screenshots
* and will not be visible on non-secure displays even when mirrored.
* </p><p>
* Here are a few things you can do to experiment with secure surfaces and
* observe their behavior.
* <ul>
* <li>Try taking a screenshot. Either the system will prevent you from taking
* a screenshot altogether or the screenshot should not contain the contents
* of the secure surface.
* <li>Try mirroring the secure surface onto a non-secure display such as an
* "Overlay Display" created using the "Simulate secondary displays" option in
* the "Developer options" section of the Settings application. The non-secure
* secondary display should not show the contents of the secure surface.
* <li>Try mirroring the secure surface onto a secure display such as an
* HDMI display with HDCP enabled. The contents of the secure surface should appear
* on the display.
* </ul>
* </p>
*/
public class SecureDialogActivity extends Activity
implements View.OnClickListener {
/**
* Initialization of the Activity after it is first created. Must at least
* call {@link android.app.Activity#setContentView setContentView()} to
* describe what is to be displayed in the screen.
*/
@Override
protected void onCreate(Bundle savedInstanceState) {
// Be sure to call the super class.
super.onCreate(savedInstanceState);
// See assets/res/any/layout/secure_dialog_activity.xml for this
// view layout definition, which is being set here as
// the content of our screen.
setContentView(R.layout.secure_dialog_activity);
// Handle click events on the button to show the dialog.
Button button = (Button)findViewById(R.id.show);
button.setOnClickListener(this);
}
/**
* Called when the button to show the dialog is clicked.
*/
@Override
public void onClick(View v) {
// Create a dialog.
AlertDialog dialog = new AlertDialog.Builder(this)
.setPositiveButton(android.R.string.ok, null)
.setMessage(R.string.secure_dialog_dialog_text)
.create();
// Make the dialog secure. This must be done at the time the dialog is
// created. It cannot be changed after the dialog has been shown.
dialog.getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE,
WindowManager.LayoutParams.FLAG_SECURE);
// Show the dialog.
dialog.show();
}
}

View File

@@ -0,0 +1,81 @@
/*
* Copyright (C) 2012 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.example.android.apis.app;
import com.example.android.apis.R;
import com.example.android.apis.graphics.CubeRenderer;
import android.app.Activity;
import android.opengl.GLSurfaceView;
import android.os.Bundle;
import android.view.SurfaceView;
import android.view.WindowManager;
/**
* <h3>Secure Window Activity</h3>
*
* <p>
* This activity demonstrates how to create a {@link SurfaceView} backed by
* a secure surface using {@link SurfaceView#setSecure}.
* Because the surface is secure, its contents cannot be captured in screenshots
* and will not be visible on non-secure displays even when mirrored.
* </p><p>
* Here are a few things you can do to experiment with secure surfaces and
* observe their behavior.
* <ul>
* <li>Try taking a screenshot. Either the system will prevent you from taking
* a screenshot altogether or the screenshot should not contain the contents
* of the secure surface.
* <li>Try mirroring the secure surface onto a non-secure display such as an
* "Overlay Display" created using the "Simulate secondary displays" option in
* the "Developer options" section of the Settings application. The non-secure
* secondary display should not show the contents of the secure surface.
* <li>Try mirroring the secure surface onto a secure display such as an
* HDMI display with HDCP enabled. The contents of the secure surface should appear
* on the display.
* </ul>
* </p>
*/
public class SecureSurfaceViewActivity extends Activity {
/**
* Initialization of the Activity after it is first created. Must at least
* call {@link android.app.Activity#setContentView setContentView()} to
* describe what is to be displayed in the screen.
*/
@Override
protected void onCreate(Bundle savedInstanceState) {
// Be sure to call the super class.
super.onCreate(savedInstanceState);
// See assets/res/any/layout/secure_surface_view_activity.xml for this
// view layout definition, which is being set here as
// the content of our screen.
setContentView(R.layout.secure_surface_view_activity);
// Set up the surface view.
// We use a GLSurfaceView in this demonstration but ordinary
// SurfaceViews also support the same secure surface functionality.
GLSurfaceView surfaceView = (GLSurfaceView)findViewById(R.id.surface_view);
surfaceView.setRenderer(new CubeRenderer(false));
// Make the surface view secure. This must be done at the time the surface view
// is created before the surface view's containing window is attached to
// the window manager which happens after onCreate returns.
// It cannot be changed later.
surfaceView.setSecure(true);
}
}

View File

@@ -0,0 +1,71 @@
/*
* Copyright (C) 2012 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.example.android.apis.app;
import com.example.android.apis.R;
import android.app.Activity;
import android.os.Bundle;
import android.view.WindowManager;
/**
* <h3>Secure Window Activity</h3>
*
* <p>
* This activity demonstrates how to create an activity whose window is backed by
* a secure surface using {@link WindowManager.LayoutParams#FLAG_SECURE}.
* Because the surface is secure, its contents cannot be captured in screenshots
* and will not be visible on non-secure displays even when mirrored.
* </p><p>
* Here are a few things you can do to experiment with secure surfaces and
* observe their behavior.
* <ul>
* <li>Try taking a screenshot. Either the system will prevent you from taking
* a screenshot altogether or the screenshot should not contain the contents
* of the secure surface.
* <li>Try mirroring the secure surface onto a non-secure display such as an
* "Overlay Display" created using the "Simulate secondary displays" option in
* the "Developer options" section of the Settings application. The non-secure
* secondary display should not show the contents of the secure surface.
* <li>Try mirroring the secure surface onto a secure display such as an
* HDMI display with HDCP enabled. The contents of the secure surface should appear
* on the display.
* </ul>
* </p>
*/
public class SecureWindowActivity extends Activity {
/**
* Initialization of the Activity after it is first created. Must at least
* call {@link android.app.Activity#setContentView setContentView()} to
* describe what is to be displayed in the screen.
*/
@Override
protected void onCreate(Bundle savedInstanceState) {
// Be sure to call the super class.
super.onCreate(savedInstanceState);
// See assets/res/any/layout/secure_window_activity.xml for this
// view layout definition, which is being set here as
// the content of our screen.
setContentView(R.layout.secure_window_activity);
// Make the window secure. This must be done at the time the activity
// is created. It cannot be changed later.
getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE,
WindowManager.LayoutParams.FLAG_SECURE);
}
}

View File

@@ -25,7 +25,7 @@ import android.opengl.GLSurfaceView;
* Render a pair of tumbling cubes.
*/
class CubeRenderer implements GLSurfaceView.Renderer {
public class CubeRenderer implements GLSurfaceView.Renderer {
public CubeRenderer(boolean useTranslucentBackground) {
mTranslucentBackground = useTranslucentBackground;
mCube = new Cube();