aboutsummaryrefslogtreecommitdiff
path: root/system
diff options
context:
space:
mode:
authorJan-Felix Schmakeit <jfschmakeit@google.com>2015-05-26 11:16:46 +1000
committerTrevor Johns <trevorjohns@google.com>2015-05-27 08:54:16 +0000
commit673e5cda8ea0ea0fbeb541a0f0a41daf828b1f86 (patch)
treeb014ffe9af0db3506518fb22fb42af39196a6d2b /system
parent34f15ab80c6ce5485d5c5317c462946d3e61c687 (diff)
downloadandroid-673e5cda8ea0ea0fbeb541a0f0a41daf828b1f86.tar.gz
Adding RuntimePermissionsBasic sample.
It shows the basic use of the runtime permissions API available in Android M. Change-Id: Ia435f7be17d93175c6c1f460f6947e8e4870316b
Diffstat (limited to 'system')
-rw-r--r--system/RuntimePermissionsBasic/Application/.gitignore16
-rw-r--r--system/RuntimePermissionsBasic/Application/proguard-project.txt20
-rw-r--r--system/RuntimePermissionsBasic/Application/src/main/AndroidManifest.xml48
-rw-r--r--system/RuntimePermissionsBasic/Application/src/main/java/com/example/android/basicpermissions/MainActivity.java135
-rw-r--r--system/RuntimePermissionsBasic/Application/src/main/java/com/example/android/basicpermissions/camera/CameraPreview.java142
-rw-r--r--system/RuntimePermissionsBasic/Application/src/main/java/com/example/android/basicpermissions/camera/CameraPreviewActivity.java104
-rw-r--r--system/RuntimePermissionsBasic/Application/src/main/res/layout/activity_camera.xml22
-rw-r--r--system/RuntimePermissionsBasic/Application/src/main/res/layout/activity_camera_unavailable.xml37
-rw-r--r--system/RuntimePermissionsBasic/Application/src/main/res/layout/activity_main.xml40
-rw-r--r--system/RuntimePermissionsBasic/Application/src/main/res/mipmap-hdpi/ic_launcher.pngbin0 -> 3470 bytes
-rw-r--r--system/RuntimePermissionsBasic/Application/src/main/res/mipmap-mdpi/ic_launcher.pngbin0 -> 2206 bytes
-rw-r--r--system/RuntimePermissionsBasic/Application/src/main/res/mipmap-xhdpi/ic_launcher.pngbin0 -> 4395 bytes
-rw-r--r--system/RuntimePermissionsBasic/Application/src/main/res/mipmap-xxhdpi/ic_launcher.pngbin0 -> 6994 bytes
-rw-r--r--system/RuntimePermissionsBasic/Application/src/main/res/mipmap-xxxhdpi/ic_launcher.pngbin0 -> 9911 bytes
-rw-r--r--system/RuntimePermissionsBasic/Application/src/main/res/values/strings.xml6
-rw-r--r--system/RuntimePermissionsBasic/build.gradle11
-rw-r--r--system/RuntimePermissionsBasic/buildSrc/build.gradle15
-rw-r--r--system/RuntimePermissionsBasic/gradle/wrapper/gradle-wrapper.jarbin0 -> 49896 bytes
-rw-r--r--system/RuntimePermissionsBasic/gradle/wrapper/gradle-wrapper.properties6
-rwxr-xr-xsystem/RuntimePermissionsBasic/gradlew164
-rw-r--r--system/RuntimePermissionsBasic/gradlew.bat90
-rw-r--r--system/RuntimePermissionsBasic/screenshots/big_icon.pngbin0 -> 36396 bytes
-rw-r--r--system/RuntimePermissionsBasic/screenshots/screenshot-1.pngbin0 -> 101522 bytes
-rw-r--r--system/RuntimePermissionsBasic/settings.gradle1
-rw-r--r--system/RuntimePermissionsBasic/template-params.xml74
25 files changed, 931 insertions, 0 deletions
diff --git a/system/RuntimePermissionsBasic/Application/.gitignore b/system/RuntimePermissionsBasic/Application/.gitignore
new file mode 100644
index 00000000..6eb878d4
--- /dev/null
+++ b/system/RuntimePermissionsBasic/Application/.gitignore
@@ -0,0 +1,16 @@
+# Copyright 2013 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.
+src/template/
+src/common/
+build.gradle
diff --git a/system/RuntimePermissionsBasic/Application/proguard-project.txt b/system/RuntimePermissionsBasic/Application/proguard-project.txt
new file mode 100644
index 00000000..0d8f171d
--- /dev/null
+++ b/system/RuntimePermissionsBasic/Application/proguard-project.txt
@@ -0,0 +1,20 @@
+ To enable ProGuard in your project, edit project.properties
+# to define the proguard.config property as described in that file.
+#
+# Add project specific ProGuard rules here.
+# By default, the flags in this file are appended to flags specified
+# in ${sdk.dir}/tools/proguard/proguard-android.txt
+# You can edit the include path and order by changing the ProGuard
+# include property in project.properties.
+#
+# For more details, see
+# http://developer.android.com/guide/developing/tools/proguard.html
+
+# Add any project specific keep options here:
+
+# If your project uses WebView with JS, uncomment the following
+# and specify the fully qualified class name to the JavaScript interface
+# class:
+#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
+# public *;
+#}
diff --git a/system/RuntimePermissionsBasic/Application/src/main/AndroidManifest.xml b/system/RuntimePermissionsBasic/Application/src/main/AndroidManifest.xml
new file mode 100644
index 00000000..1f7ea6a1
--- /dev/null
+++ b/system/RuntimePermissionsBasic/Application/src/main/AndroidManifest.xml
@@ -0,0 +1,48 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright 2015 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.
+ -->
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.example.android.basicpermissions">
+
+ <!-- BEGIN_INCLUDE(manifest) -->
+
+ <!-- Note that all required permissions are declared here in the Android manifest.
+ On Android M and above, use of these permissions is only requested at run time. -->
+ <uses-permission android:name="android.permission.CAMERA"/>
+ <!-- END_INCLUDE(manifest) -->
+
+ <application
+ android:allowBackup="true"
+ android:icon="@mipmap/ic_launcher"
+ android:label="@string/app_name"
+ android:theme="@style/AppTheme">
+ <activity
+ android:name=".MainActivity"
+ android:label="@string/app_name">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN"/>
+ <category android:name="android.intent.category.LAUNCHER"/>
+ </intent-filter>
+ </activity>
+
+ <!-- Activity that only displays the camera preview. -->
+ <activity
+ android:name=".camera.CameraPreviewActivity"
+ android:exported="false"/>
+
+ </application>
+
+</manifest>
diff --git a/system/RuntimePermissionsBasic/Application/src/main/java/com/example/android/basicpermissions/MainActivity.java b/system/RuntimePermissionsBasic/Application/src/main/java/com/example/android/basicpermissions/MainActivity.java
new file mode 100644
index 00000000..9de3b018
--- /dev/null
+++ b/system/RuntimePermissionsBasic/Application/src/main/java/com/example/android/basicpermissions/MainActivity.java
@@ -0,0 +1,135 @@
+/*
+* Copyright 2015 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.basicpermissions;
+
+import com.example.android.basicpermissions.camera.CameraPreviewActivity;
+
+import android.Manifest;
+import android.app.Activity;
+import android.content.Intent;
+import android.content.pm.PackageManager;
+import android.os.Build;
+import android.os.Bundle;
+import android.view.View;
+import android.widget.Button;
+import android.widget.Toast;
+
+/**
+ * Launcher Activity that demonstrates the use of runtime permissions for Android M.
+ * This Activity requests permissions to access the camera
+ * ({@link android.Manifest.permission#CAMERA})
+ * when the 'Show Camera Preview' button is clicked to start {@link CameraPreviewActivity} once
+ * the permission has been granted.
+ * <p>
+ * First, the status of the Camera permission is checked using {@link
+ * Activity#checkSelfPermission(String)}.
+ * If it has not been granted ({@link PackageManager#PERMISSION_GRANTED}), it is requested by
+ * calling
+ * {@link Activity#requestPermissions(String[], int)}. The result of the request is returned in
+ * {@link Activity#onRequestPermissionsResult(int, String[], int[])}, which starts {@link
+ * CameraPreviewActivity}
+ * if the permission has been granted.
+ */
+public class MainActivity extends Activity {
+
+ private static final int PERMISSION_REQUEST_CAMERA = 0;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_main);
+
+ // Register a listener for the 'Show Camera Preview' button.
+ Button b = (Button) findViewById(R.id.button_open_camera);
+ b.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ showCameraPreview();
+ }
+ });
+ }
+
+ @Override
+ public void onRequestPermissionsResult(int requestCode, String[] permissions,
+ int[] grantResults) {
+ // BEGIN_INCLUDE(onRequestPermissionsResult)
+ if (requestCode == PERMISSION_REQUEST_CAMERA) {
+ // Request for camera permission.
+ if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
+ // Permission has been granted. Start camera preview Activity.
+ Toast.makeText(this, "Camera permission was granted. Starting preview.",
+ Toast.LENGTH_SHORT)
+ .show();
+ startCamera();
+ } else {
+ // Permission request was denied.
+ Toast.makeText(this, "Camera permission request was denied.", Toast.LENGTH_SHORT)
+ .show();
+ }
+ }
+ // END_INCLUDE(onRequestPermissionsResult)
+ }
+
+ private void showCameraPreview() {
+ // BEGIN_INCLUDE(startCamera)
+ if (isMNC()) {
+ // On Android M and above, need to check if permission has been granted at runtime.
+ if (checkSelfPermission(Manifest.permission.CAMERA)
+ == PackageManager.PERMISSION_GRANTED) {
+ // Permission is available, start camera preview
+ startCamera();
+ Toast.makeText(this,
+ "Camera permission has already been granted. Starting preview.",
+ Toast.LENGTH_SHORT).show();
+ } else {
+ // Permission has not been granted and must be requested.
+ Toast.makeText(this,
+ "Permission is not available. Requesting camera permission.",
+ Toast.LENGTH_SHORT).show();
+ requestPermissions(new String[]{Manifest.permission.CAMERA},
+ PERMISSION_REQUEST_CAMERA);
+ }
+ } else {
+ /*
+ Below Android M all permissions have already been grated at install time and do not
+ need to verified or requested.
+ If a permission has been disabled in the system settings, the API will return
+ unavailable or empty data instead. */
+ Toast.makeText(this,
+ "Requested permissions are granted at install time below M and are always "
+ + "available at runtime.",
+ Toast.LENGTH_SHORT).show();
+ startCamera();
+ }
+ // END_INCLUDE(startCamera)
+ }
+
+ private void startCamera() {
+ Intent intent = new Intent(this, CameraPreviewActivity.class);
+ startActivity(intent);
+ }
+
+ public static boolean isMNC() {
+ /*
+ TODO: In the Android M Preview release, checking if the platform is M is done through
+ the codename, not the version code. Once the API has been finalised, the following check
+ should be used: */
+ // return Build.VERSION.SDK_INT >= Build.VERSION_CODES.MNC
+
+ return "MNC".equals(Build.VERSION.CODENAME);
+ }
+}
diff --git a/system/RuntimePermissionsBasic/Application/src/main/java/com/example/android/basicpermissions/camera/CameraPreview.java b/system/RuntimePermissionsBasic/Application/src/main/java/com/example/android/basicpermissions/camera/CameraPreview.java
new file mode 100644
index 00000000..7abf2d8d
--- /dev/null
+++ b/system/RuntimePermissionsBasic/Application/src/main/java/com/example/android/basicpermissions/camera/CameraPreview.java
@@ -0,0 +1,142 @@
+/*
+* Copyright 2015 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.basicpermissions.camera;
+
+import android.content.Context;
+import android.hardware.Camera;
+import android.util.Log;
+import android.view.Surface;
+import android.view.SurfaceHolder;
+import android.view.SurfaceView;
+
+import java.io.IOException;
+
+/**
+ * Camera preview that displays a {@link Camera}.
+ *
+ * Handles basic lifecycle methods to display and stop the preview.
+ * <p>
+ * Implementation is based directly on the documentation at
+ * http://developer.android.com/guide/topics/media/camera.html
+ */
+public class CameraPreview extends SurfaceView implements SurfaceHolder.Callback {
+
+ private static final String TAG = "CameraPreview";
+ private SurfaceHolder mHolder;
+ private Camera mCamera;
+ private Camera.CameraInfo mCameraInfo;
+ private int mDisplayOrientation;
+
+ public CameraPreview(Context context, Camera camera, Camera.CameraInfo cameraInfo,
+ int displayOrientation) {
+ super(context);
+
+ // Do not initialise if no camera has been set
+ if (camera == null || cameraInfo == null) {
+ return;
+ }
+ mCamera = camera;
+ mCameraInfo = cameraInfo;
+ mDisplayOrientation = displayOrientation;
+
+ // Install a SurfaceHolder.Callback so we get notified when the
+ // underlying surface is created and destroyed.
+ mHolder = getHolder();
+ mHolder.addCallback(this);
+ }
+
+ public void surfaceCreated(SurfaceHolder holder) {
+ // The Surface has been created, now tell the camera where to draw the preview.
+ try {
+ mCamera.setPreviewDisplay(holder);
+ mCamera.startPreview();
+ Log.d(TAG, "Camera preview started.");
+ } catch (IOException e) {
+ Log.d(TAG, "Error setting camera preview: " + e.getMessage());
+ }
+ }
+
+ public void surfaceDestroyed(SurfaceHolder holder) {
+ // empty. Take care of releasing the Camera preview in your activity.
+ }
+
+ public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
+ // If your preview can change or rotate, take care of those events here.
+ // Make sure to stop the preview before resizing or reformatting it.
+
+ if (mHolder.getSurface() == null) {
+ // preview surface does not exist
+ Log.d(TAG, "Preview surface does not exist");
+ return;
+ }
+
+ // stop preview before making changes
+ try {
+ mCamera.stopPreview();
+ Log.d(TAG, "Preview stopped.");
+ } catch (Exception e) {
+ // ignore: tried to stop a non-existent preview
+ Log.d(TAG, "Error starting camera preview: " + e.getMessage());
+ }
+
+ int orientation = calculatePreviewOrientation(mCameraInfo, mDisplayOrientation);
+ mCamera.setDisplayOrientation(orientation);
+
+ try {
+ mCamera.setPreviewDisplay(mHolder);
+ mCamera.startPreview();
+ Log.d(TAG, "Camera preview started.");
+ } catch (Exception e) {
+ Log.d(TAG, "Error starting camera preview: " + e.getMessage());
+ }
+ }
+
+ /**
+ * Calculate the correct orientation for a {@link Camera} preview that is displayed on screen.
+ *
+ * Implementation is based on the sample code provided in
+ * {@link Camera#setDisplayOrientation(int)}.
+ */
+ public static int calculatePreviewOrientation(Camera.CameraInfo info, int rotation) {
+ int degrees = 0;
+
+ switch (rotation) {
+ case Surface.ROTATION_0:
+ degrees = 0;
+ break;
+ case Surface.ROTATION_90:
+ degrees = 90;
+ break;
+ case Surface.ROTATION_180:
+ degrees = 180;
+ break;
+ case Surface.ROTATION_270:
+ degrees = 270;
+ break;
+ }
+
+ int result;
+ if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
+ result = (info.orientation + degrees) % 360;
+ result = (360 - result) % 360; // compensate the mirror
+ } else { // back-facing
+ result = (info.orientation - degrees + 360) % 360;
+ }
+
+ return result;
+ }
+}
diff --git a/system/RuntimePermissionsBasic/Application/src/main/java/com/example/android/basicpermissions/camera/CameraPreviewActivity.java b/system/RuntimePermissionsBasic/Application/src/main/java/com/example/android/basicpermissions/camera/CameraPreviewActivity.java
new file mode 100644
index 00000000..ee589d99
--- /dev/null
+++ b/system/RuntimePermissionsBasic/Application/src/main/java/com/example/android/basicpermissions/camera/CameraPreviewActivity.java
@@ -0,0 +1,104 @@
+/*
+* Copyright 2015 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.basicpermissions.camera;
+
+import com.example.android.basicpermissions.R;
+
+import android.app.Activity;
+import android.hardware.Camera;
+import android.os.Bundle;
+import android.widget.FrameLayout;
+import android.widget.Toast;
+
+/**
+ * Displays a {@link CameraPreview} of the first {@link Camera}.
+ * An error message is displayed if the Camera is not available.
+ * <p>
+ * This Activity is only used to illustrate that access to the Camera API has been granted (or
+ * denied) as part of the runtime permissions model. It is not relevant for the use of the
+ * permissions API.
+ * <p>
+ * Implementation is based directly on the documentation at
+ * http://developer.android.com/guide/topics/media/camera.html
+ */
+public class CameraPreviewActivity extends Activity {
+
+ private static final String TAG = "CameraPreview";
+
+ /**
+ * Id of the camera to access. 0 is the first camera.
+ */
+ private static final int CAMERA_ID = 0;
+
+ private CameraPreview mPreview;
+ private Camera mCamera;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ // Open an instance of the first camera and retrieve its info.
+ mCamera = getCameraInstance(CAMERA_ID);
+ Camera.CameraInfo cameraInfo = new Camera.CameraInfo();
+ Camera.getCameraInfo(CAMERA_ID, cameraInfo);
+
+ if (mCamera == null || cameraInfo == null) {
+ // Camera is not available, display error message
+ Toast.makeText(this, "Camera is not available.", Toast.LENGTH_SHORT).show();
+ setContentView(R.layout.activity_camera_unavailable);
+ } else {
+
+ setContentView(R.layout.activity_camera);
+
+ // Get the rotation of the screen to adjust the preview image accordingly.
+ final int displayRotation = getWindowManager().getDefaultDisplay()
+ .getRotation();
+
+ // Create the Preview view and set it as the content of this Activity.
+ mPreview = new CameraPreview(this, mCamera, cameraInfo, displayRotation);
+ FrameLayout preview = (FrameLayout) findViewById(R.id.camera_preview);
+ preview.addView(mPreview);
+ }
+ }
+
+ @Override
+ public void onPause() {
+ super.onPause();
+ // Stop camera access
+ releaseCamera();
+ }
+
+ /** A safe way to get an instance of the Camera object. */
+ private Camera getCameraInstance(int cameraId) {
+ Camera c = null;
+ try {
+ c = Camera.open(cameraId); // attempt to get a Camera instance
+ } catch (Exception e) {
+ // Camera is not available (in use or does not exist)
+ Toast.makeText(this, "Camera " + cameraId + " is not available: " + e.getMessage(),
+ Toast.LENGTH_SHORT).show();
+ }
+ return c; // returns null if camera is unavailable
+ }
+
+ private void releaseCamera() {
+ if (mCamera != null) {
+ mCamera.release(); // release the camera for other applications
+ mCamera = null;
+ }
+ }
+}
diff --git a/system/RuntimePermissionsBasic/Application/src/main/res/layout/activity_camera.xml b/system/RuntimePermissionsBasic/Application/src/main/res/layout/activity_camera.xml
new file mode 100644
index 00000000..b12eee19
--- /dev/null
+++ b/system/RuntimePermissionsBasic/Application/src/main/res/layout/activity_camera.xml
@@ -0,0 +1,22 @@
+<!--
+ Copyright 2015 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.
+-->
+
+<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/camera_preview"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ android:layout_weight="1"
+ />
diff --git a/system/RuntimePermissionsBasic/Application/src/main/res/layout/activity_camera_unavailable.xml b/system/RuntimePermissionsBasic/Application/src/main/res/layout/activity_camera_unavailable.xml
new file mode 100644
index 00000000..af0efe5d
--- /dev/null
+++ b/system/RuntimePermissionsBasic/Application/src/main/res/layout/activity_camera_unavailable.xml
@@ -0,0 +1,37 @@
+<!--
+ Copyright 2015 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.
+-->
+
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:orientation="vertical"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:paddingLeft="@dimen/horizontal_page_margin"
+ android:paddingRight="@dimen/horizontal_page_margin"
+ android:paddingTop="@dimen/vertical_page_margin"
+ android:paddingBottom="@dimen/vertical_page_margin">
+
+ <ScrollView
+ android:layout_width="match_parent"
+ android:layout_height="fill_parent">
+
+ <TextView
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="@string/camera_unavailable"/>
+
+ </ScrollView>
+
+</LinearLayout> \ No newline at end of file
diff --git a/system/RuntimePermissionsBasic/Application/src/main/res/layout/activity_main.xml b/system/RuntimePermissionsBasic/Application/src/main/res/layout/activity_main.xml
new file mode 100644
index 00000000..c3bf99c5
--- /dev/null
+++ b/system/RuntimePermissionsBasic/Application/src/main/res/layout/activity_main.xml
@@ -0,0 +1,40 @@
+<!--
+ Copyright 2015 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.
+-->
+
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:tools="http://schemas.android.com/tools"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:paddingLeft="@dimen/horizontal_page_margin"
+ android:paddingRight="@dimen/horizontal_page_margin"
+ android:paddingTop="@dimen/vertical_page_margin"
+ android:paddingBottom="@dimen/vertical_page_margin"
+ android:orientation="vertical"
+ tools:context=".MainActivity">
+
+ <TextView
+ android:text="@string/intro"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginBottom="@dimen/horizontal_page_margin"/>
+
+
+ <Button
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="Open Camera Preview"
+ android:id="@+id/button_open_camera"/>
+</LinearLayout>
diff --git a/system/RuntimePermissionsBasic/Application/src/main/res/mipmap-hdpi/ic_launcher.png b/system/RuntimePermissionsBasic/Application/src/main/res/mipmap-hdpi/ic_launcher.png
new file mode 100644
index 00000000..a7cee76c
--- /dev/null
+++ b/system/RuntimePermissionsBasic/Application/src/main/res/mipmap-hdpi/ic_launcher.png
Binary files differ
diff --git a/system/RuntimePermissionsBasic/Application/src/main/res/mipmap-mdpi/ic_launcher.png b/system/RuntimePermissionsBasic/Application/src/main/res/mipmap-mdpi/ic_launcher.png
new file mode 100644
index 00000000..378d0298
--- /dev/null
+++ b/system/RuntimePermissionsBasic/Application/src/main/res/mipmap-mdpi/ic_launcher.png
Binary files differ
diff --git a/system/RuntimePermissionsBasic/Application/src/main/res/mipmap-xhdpi/ic_launcher.png b/system/RuntimePermissionsBasic/Application/src/main/res/mipmap-xhdpi/ic_launcher.png
new file mode 100644
index 00000000..c8987424
--- /dev/null
+++ b/system/RuntimePermissionsBasic/Application/src/main/res/mipmap-xhdpi/ic_launcher.png
Binary files differ
diff --git a/system/RuntimePermissionsBasic/Application/src/main/res/mipmap-xxhdpi/ic_launcher.png b/system/RuntimePermissionsBasic/Application/src/main/res/mipmap-xxhdpi/ic_launcher.png
new file mode 100644
index 00000000..ad4f1df2
--- /dev/null
+++ b/system/RuntimePermissionsBasic/Application/src/main/res/mipmap-xxhdpi/ic_launcher.png
Binary files differ
diff --git a/system/RuntimePermissionsBasic/Application/src/main/res/mipmap-xxxhdpi/ic_launcher.png b/system/RuntimePermissionsBasic/Application/src/main/res/mipmap-xxxhdpi/ic_launcher.png
new file mode 100644
index 00000000..484f298e
--- /dev/null
+++ b/system/RuntimePermissionsBasic/Application/src/main/res/mipmap-xxxhdpi/ic_launcher.png
Binary files differ
diff --git a/system/RuntimePermissionsBasic/Application/src/main/res/values/strings.xml b/system/RuntimePermissionsBasic/Application/src/main/res/values/strings.xml
new file mode 100644
index 00000000..eb0b7c46
--- /dev/null
+++ b/system/RuntimePermissionsBasic/Application/src/main/res/values/strings.xml
@@ -0,0 +1,6 @@
+<resources>
+ <string name="show_camera">Show camera preview</string>
+ <string name="camera_unavailable"><b>Camera could not be opened.</b>\nThis occurs when the camera is not available (for example it is already in use) or if the system has denied access (for example when camera access has been disabled).</string>
+ <string name="intro">This sample shows a basic implementation for requesting permissions at runtime.\nClick the button below to request the Camera permission and open a full-screen camera preview.</string>
+
+</resources>
diff --git a/system/RuntimePermissionsBasic/build.gradle b/system/RuntimePermissionsBasic/build.gradle
new file mode 100644
index 00000000..2b8d1ef1
--- /dev/null
+++ b/system/RuntimePermissionsBasic/build.gradle
@@ -0,0 +1,11 @@
+
+// BEGIN_EXCLUDE
+import com.example.android.samples.build.SampleGenPlugin
+apply plugin: SampleGenPlugin
+
+samplegen {
+ pathToBuild "../../../../build"
+ pathToSamplesCommon "../../common"
+}
+apply from: "../../../../build/build.gradle"
+// END_EXCLUDE
diff --git a/system/RuntimePermissionsBasic/buildSrc/build.gradle b/system/RuntimePermissionsBasic/buildSrc/build.gradle
new file mode 100644
index 00000000..8c294c23
--- /dev/null
+++ b/system/RuntimePermissionsBasic/buildSrc/build.gradle
@@ -0,0 +1,15 @@
+repositories {
+ mavenCentral()
+}
+dependencies {
+ compile 'org.freemarker:freemarker:2.3.20'
+}
+
+sourceSets {
+ main {
+ groovy {
+ srcDir new File(rootDir, "../../../../../build/buildSrc/src/main/groovy")
+ }
+ }
+}
+
diff --git a/system/RuntimePermissionsBasic/gradle/wrapper/gradle-wrapper.jar b/system/RuntimePermissionsBasic/gradle/wrapper/gradle-wrapper.jar
new file mode 100644
index 00000000..8c0fb64a
--- /dev/null
+++ b/system/RuntimePermissionsBasic/gradle/wrapper/gradle-wrapper.jar
Binary files differ
diff --git a/system/RuntimePermissionsBasic/gradle/wrapper/gradle-wrapper.properties b/system/RuntimePermissionsBasic/gradle/wrapper/gradle-wrapper.properties
new file mode 100644
index 00000000..8a27ebfa
--- /dev/null
+++ b/system/RuntimePermissionsBasic/gradle/wrapper/gradle-wrapper.properties
@@ -0,0 +1,6 @@
+#Sun Dec 07 22:52:45 JST 2014
+distributionBase=GRADLE_USER_HOME
+distributionPath=wrapper/dists
+zipStoreBase=GRADLE_USER_HOME
+zipStorePath=wrapper/dists
+distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip
diff --git a/system/RuntimePermissionsBasic/gradlew b/system/RuntimePermissionsBasic/gradlew
new file mode 100755
index 00000000..91a7e269
--- /dev/null
+++ b/system/RuntimePermissionsBasic/gradlew
@@ -0,0 +1,164 @@
+#!/usr/bin/env bash
+
+##############################################################################
+##
+## Gradle start up script for UN*X
+##
+##############################################################################
+
+# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+DEFAULT_JVM_OPTS=""
+
+APP_NAME="Gradle"
+APP_BASE_NAME=`basename "$0"`
+
+# Use the maximum available, or set MAX_FD != -1 to use that value.
+MAX_FD="maximum"
+
+warn ( ) {
+ echo "$*"
+}
+
+die ( ) {
+ echo
+ echo "$*"
+ echo
+ exit 1
+}
+
+# OS specific support (must be 'true' or 'false').
+cygwin=false
+msys=false
+darwin=false
+case "`uname`" in
+ CYGWIN* )
+ cygwin=true
+ ;;
+ Darwin* )
+ darwin=true
+ ;;
+ MINGW* )
+ msys=true
+ ;;
+esac
+
+# For Cygwin, ensure paths are in UNIX format before anything is touched.
+if $cygwin ; then
+ [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
+fi
+
+# Attempt to set APP_HOME
+# Resolve links: $0 may be a link
+PRG="$0"
+# Need this for relative symlinks.
+while [ -h "$PRG" ] ; do
+ ls=`ls -ld "$PRG"`
+ link=`expr "$ls" : '.*-> \(.*\)$'`
+ if expr "$link" : '/.*' > /dev/null; then
+ PRG="$link"
+ else
+ PRG=`dirname "$PRG"`"/$link"
+ fi
+done
+SAVED="`pwd`"
+cd "`dirname \"$PRG\"`/" >&-
+APP_HOME="`pwd -P`"
+cd "$SAVED" >&-
+
+CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
+
+# Determine the Java command to use to start the JVM.
+if [ -n "$JAVA_HOME" ] ; then
+ if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
+ # IBM's JDK on AIX uses strange locations for the executables
+ JAVACMD="$JAVA_HOME/jre/sh/java"
+ else
+ JAVACMD="$JAVA_HOME/bin/java"
+ fi
+ if [ ! -x "$JAVACMD" ] ; then
+ die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+ fi
+else
+ JAVACMD="java"
+ which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+fi
+
+# Increase the maximum file descriptors if we can.
+if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
+ MAX_FD_LIMIT=`ulimit -H -n`
+ if [ $? -eq 0 ] ; then
+ if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
+ MAX_FD="$MAX_FD_LIMIT"
+ fi
+ ulimit -n $MAX_FD
+ if [ $? -ne 0 ] ; then
+ warn "Could not set maximum file descriptor limit: $MAX_FD"
+ fi
+ else
+ warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
+ fi
+fi
+
+# For Darwin, add options to specify how the application appears in the dock
+if $darwin; then
+ GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
+fi
+
+# For Cygwin, switch paths to Windows format before running java
+if $cygwin ; then
+ APP_HOME=`cygpath --path --mixed "$APP_HOME"`
+ CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
+
+ # We build the pattern for arguments to be converted via cygpath
+ ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
+ SEP=""
+ for dir in $ROOTDIRSRAW ; do
+ ROOTDIRS="$ROOTDIRS$SEP$dir"
+ SEP="|"
+ done
+ OURCYGPATTERN="(^($ROOTDIRS))"
+ # Add a user-defined pattern to the cygpath arguments
+ if [ "$GRADLE_CYGPATTERN" != "" ] ; then
+ OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
+ fi
+ # Now convert the arguments - kludge to limit ourselves to /bin/sh
+ i=0
+ for arg in "$@" ; do
+ CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
+ CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
+
+ if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
+ eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
+ else
+ eval `echo args$i`="\"$arg\""
+ fi
+ i=$((i+1))
+ done
+ case $i in
+ (0) set -- ;;
+ (1) set -- "$args0" ;;
+ (2) set -- "$args0" "$args1" ;;
+ (3) set -- "$args0" "$args1" "$args2" ;;
+ (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
+ (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
+ (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
+ (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
+ (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
+ (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
+ esac
+fi
+
+# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
+function splitJvmOpts() {
+ JVM_OPTS=("$@")
+}
+eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
+JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
+
+exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
diff --git a/system/RuntimePermissionsBasic/gradlew.bat b/system/RuntimePermissionsBasic/gradlew.bat
new file mode 100644
index 00000000..aec99730
--- /dev/null
+++ b/system/RuntimePermissionsBasic/gradlew.bat
@@ -0,0 +1,90 @@
+@if "%DEBUG%" == "" @echo off
+@rem ##########################################################################
+@rem
+@rem Gradle startup script for Windows
+@rem
+@rem ##########################################################################
+
+@rem Set local scope for the variables with windows NT shell
+if "%OS%"=="Windows_NT" setlocal
+
+@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+set DEFAULT_JVM_OPTS=
+
+set DIRNAME=%~dp0
+if "%DIRNAME%" == "" set DIRNAME=.
+set APP_BASE_NAME=%~n0
+set APP_HOME=%DIRNAME%
+
+@rem Find java.exe
+if defined JAVA_HOME goto findJavaFromJavaHome
+
+set JAVA_EXE=java.exe
+%JAVA_EXE% -version >NUL 2>&1
+if "%ERRORLEVEL%" == "0" goto init
+
+echo.
+echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:findJavaFromJavaHome
+set JAVA_HOME=%JAVA_HOME:"=%
+set JAVA_EXE=%JAVA_HOME%/bin/java.exe
+
+if exist "%JAVA_EXE%" goto init
+
+echo.
+echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:init
+@rem Get command-line arguments, handling Windowz variants
+
+if not "%OS%" == "Windows_NT" goto win9xME_args
+if "%@eval[2+2]" == "4" goto 4NT_args
+
+:win9xME_args
+@rem Slurp the command line arguments.
+set CMD_LINE_ARGS=
+set _SKIP=2
+
+:win9xME_args_slurp
+if "x%~1" == "x" goto execute
+
+set CMD_LINE_ARGS=%*
+goto execute
+
+:4NT_args
+@rem Get arguments from the 4NT Shell from JP Software
+set CMD_LINE_ARGS=%$
+
+:execute
+@rem Setup the command line
+
+set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
+
+@rem Execute Gradle
+"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
+
+:end
+@rem End local scope for the variables with windows NT shell
+if "%ERRORLEVEL%"=="0" goto mainEnd
+
+:fail
+rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
+rem the _cmd.exe /c_ return code!
+if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
+exit /b 1
+
+:mainEnd
+if "%OS%"=="Windows_NT" endlocal
+
+:omega
diff --git a/system/RuntimePermissionsBasic/screenshots/big_icon.png b/system/RuntimePermissionsBasic/screenshots/big_icon.png
new file mode 100644
index 00000000..14c53b65
--- /dev/null
+++ b/system/RuntimePermissionsBasic/screenshots/big_icon.png
Binary files differ
diff --git a/system/RuntimePermissionsBasic/screenshots/screenshot-1.png b/system/RuntimePermissionsBasic/screenshots/screenshot-1.png
new file mode 100644
index 00000000..6c31c384
--- /dev/null
+++ b/system/RuntimePermissionsBasic/screenshots/screenshot-1.png
Binary files differ
diff --git a/system/RuntimePermissionsBasic/settings.gradle b/system/RuntimePermissionsBasic/settings.gradle
new file mode 100644
index 00000000..9464a359
--- /dev/null
+++ b/system/RuntimePermissionsBasic/settings.gradle
@@ -0,0 +1 @@
+include 'Application'
diff --git a/system/RuntimePermissionsBasic/template-params.xml b/system/RuntimePermissionsBasic/template-params.xml
new file mode 100644
index 00000000..92021d4a
--- /dev/null
+++ b/system/RuntimePermissionsBasic/template-params.xml
@@ -0,0 +1,74 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright 2015 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.
+-->
+<sample>
+ <name>RuntimePermissionsBasic</name>
+ <group>System</group>
+ <package>com.example.android.basicpermissions</package>
+
+ <minSdk>"MNC"</minSdk>
+ <targetSdkVersion>"MNC"</targetSdkVersion>
+ <compileSdkVersion>"android-MNC"</compileSdkVersion>
+
+ <dependency>com.android.support:appcompat-v7:21.+</dependency>
+
+ <strings>
+ <intro>
+ <![CDATA[
+ This sample shows runtime permissions available in the Android M and above.
+ This sample shows a basic implementation for requesting permissions at runtime. Click the button to request the Camera permission and open a full-screen camera preview.
+Note: The "RuntimePermissions" sample provides a more complete overview over the runtime permission features available.
+ ]]>
+ </intro>
+ </strings>
+
+ <template src="base"/>
+
+ <metadata>
+ <status>PUBLISHED</status>
+ <categories>System</categories>
+ <technologies>Android</technologies>
+ <languages>Java</languages>
+ <solutions>Mobile</solutions>
+ <level>BEGINNER</level>
+ <icon>screenshots/big_icon.png</icon>
+ <screenshots>
+ <img>screenshots/screenshot-1.png</img>
+ </screenshots>
+ <api_refs>
+ <android>android.app.Activity</android>
+ <android>android.Manifest.permission</android>
+ </api_refs>
+
+ <description>
+<![CDATA[
+This basic sample shows runtime permissions available in the Android M and above.
+It shows how to use the new runtime permission API to check for and request permissions.
+]]>
+ </description>
+
+ <intro>
+<![CDATA[
+Android M introduced runtime permissions. Applications targeting M and above need to request their
+permissions at runtime.
+This sample introduces the basic use of the runtime permissions API by checking for permissions (Activity#checkSelfPermission(String)), requesting permissions (Activity#requestPermissions(String[],int))
+and handling the permission request callback (Activity#onRequestPermissionsResult(int, permissions[], int[])).
+
+See the "RuntimePermissions" sample for a more complete description and reference implementation.
+]]>
+ </intro>
+ </metadata>
+</sample>