Brian Attwell | 62f8007 | 2015-06-23 23:26:27 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 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 | |
Gary Mai | 0a49afa | 2016-12-05 15:53:58 -0800 | [diff] [blame] | 17 | package com.android.contacts.activities; |
Brian Attwell | 46c6759 | 2015-05-11 17:20:52 -0700 | [diff] [blame] | 18 | |
| 19 | import android.Manifest.permission; |
| 20 | import android.app.Activity; |
Brian Attwell | 46c6759 | 2015-05-11 17:20:52 -0700 | [diff] [blame] | 21 | |
| 22 | /** |
| 23 | * Activity that requests permissions needed for ImportVCardActivity. |
| 24 | */ |
Walter Jang | 69a2cb5 | 2016-02-23 15:38:24 -0800 | [diff] [blame] | 25 | public class RequestImportVCardPermissionsActivity extends RequestPermissionsActivity { |
Brian Attwell | 46c6759 | 2015-05-11 17:20:52 -0700 | [diff] [blame] | 26 | |
Brian Attwell | 62f8007 | 2015-06-23 23:26:27 -0700 | [diff] [blame] | 27 | private static final String[] REQUIRED_PERMISSIONS = new String[] { |
Wenyi Wang | 71c7dbc | 2016-05-04 14:30:57 -0700 | [diff] [blame] | 28 | // Contacts group |
| 29 | permission.GET_ACCOUNTS, |
Brian Attwell | 46c6759 | 2015-05-11 17:20:52 -0700 | [diff] [blame] | 30 | permission.READ_CONTACTS, |
Wenyi Wang | 71c7dbc | 2016-05-04 14:30:57 -0700 | [diff] [blame] | 31 | permission.WRITE_CONTACTS, |
| 32 | // Storage group |
Walter Jang | 8568b59 | 2015-07-23 19:06:36 -0700 | [diff] [blame] | 33 | permission.READ_EXTERNAL_STORAGE, |
Brian Attwell | 46c6759 | 2015-05-11 17:20:52 -0700 | [diff] [blame] | 34 | }; |
| 35 | |
Brian Attwell | 46c6759 | 2015-05-11 17:20:52 -0700 | [diff] [blame] | 36 | @Override |
Walter Jang | bf6fcf9 | 2016-07-08 10:06:17 -0700 | [diff] [blame] | 37 | protected String[] getPermissions() { |
Brian Attwell | 62f8007 | 2015-06-23 23:26:27 -0700 | [diff] [blame] | 38 | return REQUIRED_PERMISSIONS; |
| 39 | } |
| 40 | |
| 41 | /** |
| 42 | * If any permissions the Contacts app needs are missing, open an Activity |
| 43 | * to prompt the user for these permissions. Moreover, finish the current activity. |
| 44 | * |
| 45 | * This is designed to be called inside {@link android.app.Activity#onCreate} |
Walter Jang | 915ccdd | 2016-10-24 12:18:20 -0700 | [diff] [blame] | 46 | * |
| 47 | * @param isCallerSelf whether the vcard import was started from the contacts app itself. |
Brian Attwell | 62f8007 | 2015-06-23 23:26:27 -0700 | [diff] [blame] | 48 | */ |
Walter Jang | 915ccdd | 2016-10-24 12:18:20 -0700 | [diff] [blame] | 49 | public static boolean startPermissionActivity(Activity activity, boolean isCallerSelf) { |
| 50 | return startPermissionActivity(activity, REQUIRED_PERMISSIONS, isCallerSelf, |
Brian Attwell | 62f8007 | 2015-06-23 23:26:27 -0700 | [diff] [blame] | 51 | RequestImportVCardPermissionsActivity.class); |
Brian Attwell | 46c6759 | 2015-05-11 17:20:52 -0700 | [diff] [blame] | 52 | } |
| 53 | } |