list = new ArrayList<>(files.length);
105 | for (File f : files) {
106 | Bitmap bitmap = BitmapFactory.decodeFile(f.getAbsolutePath());
107 | list.add(new Image(f.getAbsolutePath(), bitmap));
108 | }
109 | return list;
110 | }
111 |
112 | /**
113 | * Loads the given file as a bitmap.
114 | */
115 | @Override
116 | public Bitmap getImage(String path) {
117 | File file = new File(path);
118 | if (!file.exists()) {
119 | Log.e(TAG, "File could not opened. It does not exist: " + path);
120 |
121 | return null;
122 | }
123 |
124 | return BitmapFactory.decodeFile(file.getAbsolutePath());
125 |
126 | }
127 | }
128 |
--------------------------------------------------------------------------------
/app/src/main/java/com/google/samples/dataprivacy/util/ImageUtils.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Google Inc. All rights reserved.
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.google.samples.dataprivacy.util;
18 |
19 | import android.graphics.Bitmap;
20 | import android.graphics.BitmapFactory;
21 |
22 | /**
23 | * Various handy image utility methods.
24 | */
25 | public class ImageUtils {
26 |
27 | /**
28 | * Calculates the sample size to load an image, described by its
29 | * {@link android.graphics.BitmapFactory.Options}
30 | * into a given width and height.
31 | *
32 | * Source: https://developer.android.com/topic/performance/graphics/load-bitmap.html
33 | */
34 | public static int calculateInSampleSize(
35 | BitmapFactory.Options options, int reqWidth, int reqHeight) {
36 | // Raw height and width of image
37 | final int height = options.outHeight;
38 | final int width = options.outWidth;
39 | int inSampleSize = 1;
40 |
41 | if (height > reqHeight || width > reqWidth) {
42 |
43 | final int halfHeight = height / 2;
44 | final int halfWidth = width / 2;
45 |
46 | // Calculate the largest inSampleSize value that is a power of 2 and keeps both
47 | // height and width larger than the requested height and width.
48 | while ((halfHeight / inSampleSize) >= reqHeight
49 | && (halfWidth / inSampleSize) >= reqWidth) {
50 | inSampleSize *= 2;
51 | }
52 | }
53 |
54 | return inSampleSize;
55 | }
56 |
57 | /**
58 | * Loads an image with a maximum width and height.
59 | *
60 | * Source based on: https://developer.android.com/topic/performance/graphics/load-bitmap.html
61 | */
62 | public static Bitmap decodeSampledBitmapFromFile(String file,
63 | int reqWidth, int reqHeight) {
64 |
65 | // First decode with inJustDecodeBounds=true to check dimensions
66 | final BitmapFactory.Options options = new BitmapFactory.Options();
67 | options.inJustDecodeBounds = true;
68 | BitmapFactory.decodeFile(file, options);
69 |
70 | // Calculate inSampleSize
71 | options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight);
72 |
73 | // Decode bitmap with inSampleSize set
74 | options.inJustDecodeBounds = false;
75 | return BitmapFactory.decodeFile(file, options);
76 | }
77 | }
78 |
--------------------------------------------------------------------------------
/app/src/main/java/com/google/samples/dataprivacy/util/ImageViewHolder.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Google Inc. All rights reserved.
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.google.samples.dataprivacy.util;
18 |
19 | import android.support.annotation.NonNull;
20 | import android.support.v7.widget.RecyclerView;
21 | import android.view.LayoutInflater;
22 | import android.view.View;
23 | import android.view.ViewGroup;
24 | import android.widget.ImageView;
25 |
26 | import com.google.samples.dataprivacy.R;
27 | import com.google.samples.dataprivacy.model.Image;
28 |
29 |
30 | public class ImageViewHolder extends RecyclerView.ViewHolder {
31 |
32 | protected ImageView imageView;
33 |
34 | public ImageViewHolder(View itemView) {
35 | super(itemView);
36 | imageView = (ImageView) itemView.findViewById(R.id.image);
37 | }
38 |
39 | public static ImageViewHolder newInstance(@NonNull ViewGroup parent) {
40 | return new ImageViewHolder(LayoutInflater.from(parent.getContext())
41 | .inflate(R.layout.image_card, parent, false));
42 | }
43 |
44 | public void bind(Image image) {
45 |
46 | imageView.setImageBitmap(image.getImage());
47 | imageView.setTag(image.getSource());
48 |
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/app/src/main/java/com/google/samples/dataprivacy/util/ImagesAdapter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Google Inc. All rights reserved.
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.google.samples.dataprivacy.util;
18 |
19 | import android.support.v7.widget.RecyclerView;
20 | import android.view.View;
21 | import android.view.ViewGroup;
22 | import android.widget.TextView;
23 |
24 | import com.google.samples.dataprivacy.model.Image;
25 |
26 | import java.util.ArrayList;
27 | import java.util.List;
28 |
29 | /**
30 | * A RecyclerView adapter that displays {@link Image}s. Includes a callback for when an item has
31 | * been clicked.
32 | */
33 | public class ImagesAdapter extends RecyclerView.Adapter {
34 | private List mImages = new ArrayList<>(0);
35 | private OnImageItemClickListener mListener;
36 |
37 | public ImagesAdapter() {
38 | }
39 |
40 | public void setImages(List images) {
41 | mImages = images;
42 | notifyDataSetChanged();
43 | }
44 |
45 | public void setOnImageClickListener(OnImageItemClickListener listener) {
46 | mListener = listener;
47 | }
48 |
49 | @Override
50 | public ImageViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
51 | return ImageViewHolder.newInstance(parent);
52 | }
53 |
54 | @Override
55 | public void onBindViewHolder(ImageViewHolder holder, final int position) {
56 | holder.bind(mImages.get(position));
57 | holder.imageView.setOnClickListener(new View.OnClickListener() {
58 | @Override
59 | public void onClick(View v) {
60 | if (mListener == null) {
61 | return;
62 | }
63 | mListener.onImageClick(mImages.get(position).getSource());
64 | }
65 | });
66 | }
67 |
68 | @Override
69 | public int getItemCount() {
70 | return mImages.size();
71 |
72 |
73 | }
74 |
75 | public interface OnImageItemClickListener {
76 | void onImageClick(String path);
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_camera.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 |
22 |
25 |
28 |
29 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_delete.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 |
22 |
25 |
26 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_image.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 |
22 |
25 |
26 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_import.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 |
22 |
25 |
26 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_share.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 |
22 |
25 |
26 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_image_import.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 |
23 |
24 |
28 |
29 |
37 |
38 |
45 |
46 |
52 |
53 |
54 |
55 |
63 |
64 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_image_viewer.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
18 |
19 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_images.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 |
23 |
24 |
28 |
29 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_image_viewer.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 |
24 |
25 |
29 |
30 |
36 |
37 |
38 |
39 |
44 |
45 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_images.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
18 |
19 |
25 |
26 |
30 |
31 |
32 |
50 |
51 |
52 |
66 |
67 |
74 |
75 |
81 |
82 |
83 |
84 |
85 |
98 |
99 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/image_card.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 |
22 |
23 |
29 |
30 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/menu_image_viewer.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 |
36 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/menu_images.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/googlecodelabs/android-storage-permissions/94fc937dbeb84dfa4abde416a24095d3f21c3313/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/googlecodelabs/android-storage-permissions/94fc937dbeb84dfa4abde416a24095d3f21c3313/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/googlecodelabs/android-storage-permissions/94fc937dbeb84dfa4abde416a24095d3f21c3313/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/googlecodelabs/android-storage-permissions/94fc937dbeb84dfa4abde416a24095d3f21c3313/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/googlecodelabs/android-storage-permissions/94fc937dbeb84dfa4abde416a24095d3f21c3313/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/googlecodelabs/android-storage-permissions/94fc937dbeb84dfa4abde416a24095d3f21c3313/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/googlecodelabs/android-storage-permissions/94fc937dbeb84dfa4abde416a24095d3f21c3313/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/googlecodelabs/android-storage-permissions/94fc937dbeb84dfa4abde416a24095d3f21c3313/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/googlecodelabs/android-storage-permissions/94fc937dbeb84dfa4abde416a24095d3f21c3313/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/googlecodelabs/android-storage-permissions/94fc937dbeb84dfa4abde416a24095d3f21c3313/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 |
18 | #673AB7
19 | #512DA8
20 | #D1C4E9
21 | #FFC107
22 | #BDBDBD
23 |
24 | #AAAAAA
25 |
26 |
27 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 |
18 | 16dp
19 |
20 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 |
18 | Data Privacy
19 | Image Viewer
20 | Settings
21 | Import Image
22 | selected image
23 | Share
24 | Delete
25 | This app requires reading storage from external
26 | directories in order to access images from other sources.
27 | Welcome to the data privacy codelab.\nThis application stores
28 | images \'securely\'. Take a photo or import an image to store it within the app.
29 | No images saved yet.\nTake a photo or import an image.
30 | No images available for import.
31 | External storage access is need to store images.
32 | Missing Permissions
33 | Request
34 | No image icon
35 |
36 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 |
18 |
19 |
20 |
26 |
27 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/app/src/main/res/xml/backup_descriptor.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/app/src/test/java/com/google/samples/dataprivacy/page/images/ImagesPresenterTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Google Inc. All rights reserved.
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.google.samples.dataprivacy.page.images;
18 |
19 | import android.graphics.Bitmap;
20 |
21 | import com.google.samples.dataprivacy.storage.ImagesRepository;
22 |
23 | import org.junit.Before;
24 | import org.junit.Test;
25 | import org.mockito.Mock;
26 | import org.mockito.MockitoAnnotations;
27 |
28 | import static org.mockito.Mockito.verify;
29 |
30 | public class ImagesPresenterTest {
31 |
32 |
33 | private ImagesPresenter mPresenter;
34 |
35 | @Mock
36 | private ImagesRepository mRepository;
37 |
38 | @Mock
39 | private ImageImporter mImporter;
40 |
41 | @Mock
42 | private PictureTaker mPictureTaker;
43 |
44 | @Mock
45 | private ImagesContract.View mView;
46 |
47 | @Mock
48 | private Bitmap mMockedBitmap;
49 |
50 | @Before
51 | public void setUp() throws Exception {
52 | // Mockito has a very convenient way to inject mocks by using the @Mock annotation. To
53 | // inject the mocks in the test the initMocks method needs to be called.
54 | MockitoAnnotations.initMocks(this);
55 |
56 | mPresenter = new ImagesPresenter(mRepository, mView);
57 | }
58 |
59 | @Test
60 | public void takePhoto() throws Exception {
61 | mPresenter.setPictureTaker(mPictureTaker);
62 | mPresenter.openTakePhoto();
63 | verify(mPictureTaker).takePicture();
64 | }
65 |
66 | @Test
67 | public void importImage() throws Exception {
68 | mPresenter.setImageImporter(mImporter);
69 | mPresenter.openImportPhoto();
70 |
71 | verify(mImporter).importImage();
72 |
73 | }
74 |
75 | @Test
76 | public void openImage() throws Exception {
77 | final String image = "1.png";
78 | mPresenter.openImage(image);
79 | verify(mView).showImage(image);
80 |
81 | }
82 |
83 | }
--------------------------------------------------------------------------------
/app/src/test/java/com/google/samples/dataprivacy/page/viewimage/ImageViewerPresenterTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Google Inc. All rights reserved.
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.google.samples.dataprivacy.page.viewimage;
18 |
19 | import android.graphics.Bitmap;
20 |
21 | import com.google.samples.dataprivacy.storage.ImagesRepository;
22 |
23 | import org.junit.Before;
24 | import org.junit.Test;
25 | import org.mockito.Mock;
26 | import org.mockito.MockitoAnnotations;
27 |
28 | import static org.mockito.Matchers.any;
29 | import static org.mockito.Matchers.anyString;
30 | import static org.mockito.Mockito.verify;
31 |
32 | public class ImageViewerPresenterTest {
33 |
34 | private ImageViewerPresenter mPresenter;
35 |
36 | @Mock
37 | private ImagesRepository mRepository;
38 |
39 | @Mock
40 | private ImageSharer mSharer;
41 |
42 | @Mock
43 | private ImageViewerContract.View mView;
44 |
45 |
46 | @Before
47 | public void setUp() throws Exception {
48 | // Mockito has a very convenient way to inject mocks by using the @Mock annotation. To
49 | // inject the mocks in the test the initMocks method needs to be called.
50 | MockitoAnnotations.initMocks(this);
51 |
52 | mPresenter = new ImageViewerPresenter(mView, mRepository, mSharer, "1.png");
53 | }
54 |
55 | @Test
56 | public void openImage() throws Exception {
57 | final String image = "1.png";
58 |
59 | mPresenter.showImage();
60 | verify(mView).displayImage(any(Bitmap.class));
61 | }
62 |
63 | @Test
64 | public void deleteImage() throws Exception {
65 | mPresenter.deleteImage();
66 | verify(mRepository).deleteImage(anyString());
67 | }
68 |
69 | @Test
70 | public void shareImage() throws Exception {
71 | mPresenter.shareImage();
72 | verify(mSharer).shareImage(anyString());
73 | }
74 |
75 | }
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Google Inc. All rights reserved.
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 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
18 |
19 | buildscript {
20 | repositories {
21 | jcenter()
22 | maven {
23 | url "https://maven.google.com"
24 | }
25 | }
26 | dependencies {
27 | classpath 'com.android.tools.build:gradle:3.1.2'
28 |
29 | // NOTE: Do not place your application dependencies here; they belong
30 | // in the individual module build.gradle files
31 | }
32 | }
33 |
34 | allprojects {
35 | repositories {
36 | jcenter()
37 | maven {
38 | url "https://maven.google.com"
39 | }
40 | }
41 | }
42 |
43 | task clean(type: Delete) {
44 | delete rootProject.buildDir
45 | }
46 |
47 | // Define versions in a single place
48 | ext {
49 | // Sdk and tools
50 | minSdkVersion = 19
51 | targetSdkVersion = 27
52 | compileSdkVersion = 27
53 | buildToolsVersion = '27.0.3'
54 |
55 | // App dependencies
56 | supportLibraryVersion = '27.1.1'
57 | junitVersion = '4.12'
58 | mockitoVersion = '1.10.19'
59 | powerMockito = '1.7.1'
60 | hamcrestVersion = '1.3'
61 | espressoVersion = '2.2.2'
62 | easypermissionsVersion = '0.4.0'
63 | constraintLayoutVersion = '1.1.0'
64 | }
--------------------------------------------------------------------------------
/data/downloadSampleImages.bat:
--------------------------------------------------------------------------------
1 | rem Copyright 2017 Google Inc.
2 | rem
3 | rem Licensed under the Apache License, Version 2.0 (the "License");
4 | rem you may not use this file except in compliance with the License.
5 | rem You may obtain a copy of the License at
6 | rem
7 | rem http://www.apache.org/licenses/LICENSE-2.0
8 | rem
9 | rem Unless required by applicable law or agreed to in writing, software
10 | rem distributed under the License is distributed on an "AS IS" BASIS,
11 | rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | rem See the License for the specific language governing permissions and
13 | rem limitations under the License.
14 |
15 | rem Trigger a download of 4 files from a server.
16 | adb shell am start -a android.intent.action.VIEW -d https://storage.googleapis.com/network-security-conf-codelab.appspot.com/download-images/1.png
17 | adb shell am start -a android.intent.action.VIEW -d https://storage.googleapis.com/network-security-conf-codelab.appspot.com/download-images/2.png
18 | adb shell am start -a android.intent.action.VIEW -d https://storage.googleapis.com/network-security-conf-codelab.appspot.com/download-images/3.png
19 | adb shell am start -a android.intent.action.VIEW -d https://storage.googleapis.com/network-security-conf-codelab.appspot.com/download-images/4.png
20 |
--------------------------------------------------------------------------------
/data/downloadSampleImages.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | # Copyright 2017 Google Inc.
4 | #
5 | # Licensed under the Apache License, Version 2.0 (the "License");
6 | # you may not use this file except in compliance with the License.
7 | # You may obtain a copy of the License at
8 | #
9 | # http://www.apache.org/licenses/LICENSE-2.0
10 | #
11 | # Unless required by applicable law or agreed to in writing, software
12 | # distributed under the License is distributed on an "AS IS" BASIS,
13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | # See the License for the specific language governing permissions and
15 | # limitations under the License.
16 |
17 | # Trigger a download of 4 files from a server.
18 | adb shell am start -a android.intent.action.VIEW -d https://storage.googleapis.com/network-security-conf-codelab.appspot.com/download-images/1.png
19 | adb shell am start -a android.intent.action.VIEW -d https://storage.googleapis.com/network-security-conf-codelab.appspot.com/download-images/2.png
20 | adb shell am start -a android.intent.action.VIEW -d https://storage.googleapis.com/network-security-conf-codelab.appspot.com/download-images/3.png
21 | adb shell am start -a android.intent.action.VIEW -d https://storage.googleapis.com/network-security-conf-codelab.appspot.com/download-images/4.png
22 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | #
2 | # Copyright 2017 Google Inc. All rights reserved.
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 | # Project-wide Gradle settings.
18 |
19 | # IDE (e.g. Android Studio) users:
20 | # Gradle settings configured through the IDE *will override*
21 | # any settings specified in this file.
22 |
23 | # For more details on how to configure your build environment visit
24 | # http://www.gradle.org/docs/current/userguide/build_environment.html
25 |
26 | # Specifies the JVM arguments used for the daemon process.
27 | # The setting is particularly useful for tweaking memory settings.
28 | org.gradle.jvmargs=-Xmx1536m
29 |
30 | # When configured, Gradle will run in incubating parallel mode.
31 | # This option should only be used with decoupled projects. More details, visit
32 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
33 | # org.gradle.parallel=true
34 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/googlecodelabs/android-storage-permissions/94fc937dbeb84dfa4abde416a24095d3f21c3313/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #
2 | # Copyright 2017 Google Inc. All rights reserved.
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 | #Thu May 03 22:13:55 PDT 2018
18 | distributionBase=GRADLE_USER_HOME
19 | distributionPath=wrapper/dists
20 | zipStoreBase=GRADLE_USER_HOME
21 | zipStorePath=wrapper/dists
22 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
23 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Google Inc. All rights reserved.
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 | include ':app'
18 |
--------------------------------------------------------------------------------