| Anton Philippov | adfec55 | 2017-01-25 20:37:36 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License |
| 15 | */ |
| 16 | |
| 17 | package com.android.settings.backup; |
| 18 | |
| Anton Philippov | 9a5220e | 2017-03-01 21:08:56 +0000 | [diff] [blame] | 19 | import android.content.Context; |
| Anton Philippov | 18dd11f | 2017-02-03 16:01:52 +0000 | [diff] [blame] | 20 | import android.content.Intent; |
| 21 | import android.content.pm.PackageManager; |
| Anton Philippov | adfec55 | 2017-01-25 20:37:36 +0000 | [diff] [blame] | 22 | import android.os.Bundle; |
| 23 | import android.util.Log; |
| 24 | |
| Fan Zhang | 23f8d59 | 2018-08-28 15:11:40 -0700 | [diff] [blame] | 25 | import androidx.annotation.VisibleForTesting; |
| 26 | import androidx.fragment.app.FragmentActivity; |
| 27 | import androidx.fragment.app.FragmentManager; |
| 28 | |
| Anton Philippov | 9a5220e | 2017-03-01 21:08:56 +0000 | [diff] [blame] | 29 | import com.android.settings.R; |
| Anton Philippov | 9a5220e | 2017-03-01 21:08:56 +0000 | [diff] [blame] | 30 | import com.android.settings.search.BaseSearchIndexProvider; |
| 31 | import com.android.settings.search.Indexable; |
| 32 | import com.android.settings.search.SearchIndexableRaw; |
| Tony Mantler | 0fcd6cb | 2018-03-26 15:17:25 -0700 | [diff] [blame] | 33 | import com.android.settingslib.search.SearchIndexable; |
| Anton Philippov | 9a5220e | 2017-03-01 21:08:56 +0000 | [diff] [blame] | 34 | |
| 35 | import java.util.ArrayList; |
| 36 | import java.util.List; |
| 37 | |
| Anton Philippov | adfec55 | 2017-01-25 20:37:36 +0000 | [diff] [blame] | 38 | |
| 39 | /** |
| 40 | * The activity used to launch the configured Backup activity or the preference screen |
| 41 | * if the manufacturer provided their backup settings. |
| Chandan Nath | 0bfef63 | 2019-01-28 21:15:13 +0000 | [diff] [blame] | 42 | * Pre-Q, BackupSettingsActivity was disabled for non-system users. Therefore, for phones which |
| 43 | * upgrade to Q, BackupSettingsActivity is disabled for those users. However, we cannot simply |
| 44 | * enable it in Q since component enable can only be done by the user itself; which is not |
| 45 | * enough in Q we want it to be enabled for all profile users of the user. |
| 46 | * Therefore, as a simple workaround, we use a new class which is enabled by default. |
| Anton Philippov | adfec55 | 2017-01-25 20:37:36 +0000 | [diff] [blame] | 47 | */ |
| Tony Mantler | 0fcd6cb | 2018-03-26 15:17:25 -0700 | [diff] [blame] | 48 | @SearchIndexable |
| Chandan Nath | 0bfef63 | 2019-01-28 21:15:13 +0000 | [diff] [blame] | 49 | public class UserBackupSettingsActivity extends FragmentActivity implements Indexable { |
| Anton Philippov | adfec55 | 2017-01-25 20:37:36 +0000 | [diff] [blame] | 50 | private static final String TAG = "BackupSettingsActivity"; |
| Anton Philippov | f8b3154 | 2017-02-14 10:41:20 +0000 | [diff] [blame] | 51 | private FragmentManager mFragmentManager; |
| Anton Philippov | adfec55 | 2017-01-25 20:37:36 +0000 | [diff] [blame] | 52 | |
| 53 | @Override |
| 54 | public void onCreate(Bundle savedInstanceState) { |
| 55 | super.onCreate(savedInstanceState); |
| 56 | |
| 57 | BackupSettingsHelper backupHelper = new BackupSettingsHelper(this); |
| 58 | |
| 59 | if (!backupHelper.isBackupProvidedByManufacturer()) { |
| 60 | // If manufacturer specific backup settings are not provided then launch |
| 61 | // the backup settings provided by backup transport or the default one directly. |
| 62 | if (Log.isLoggable(TAG, Log.DEBUG)) { |
| 63 | Log.d(TAG, |
| 64 | "No manufacturer settings found, launching the backup settings directly"); |
| 65 | } |
| Anton Philippov | 18dd11f | 2017-02-03 16:01:52 +0000 | [diff] [blame] | 66 | Intent intent = backupHelper.getIntentForBackupSettings(); |
| Bernardo Rufino | 368b5a6 | 2018-03-06 16:07:13 +0000 | [diff] [blame] | 67 | try { |
| 68 | // enable the activity before launching it |
| 69 | getPackageManager().setComponentEnabledSetting( |
| 70 | intent.getComponent(), |
| 71 | PackageManager.COMPONENT_ENABLED_STATE_ENABLED, |
| 72 | PackageManager.DONT_KILL_APP); |
| 73 | } catch (SecurityException e) { |
| 74 | Log.w(TAG, "Trying to enable activity " + intent.getComponent() + " but couldn't: " |
| 75 | + e.getMessage()); |
| 76 | // the activity may already be enabled |
| 77 | } |
| Anton Philippov | 18dd11f | 2017-02-03 16:01:52 +0000 | [diff] [blame] | 78 | |
| Anton Philippov | adfec55 | 2017-01-25 20:37:36 +0000 | [diff] [blame] | 79 | // use startActivityForResult to let the activity check the caller signature |
| Anton Philippov | 18dd11f | 2017-02-03 16:01:52 +0000 | [diff] [blame] | 80 | startActivityForResult(intent, 1); |
| Anton Philippov | adfec55 | 2017-01-25 20:37:36 +0000 | [diff] [blame] | 81 | finish(); |
| 82 | } else { |
| 83 | if (Log.isLoggable(TAG, Log.DEBUG)) { |
| 84 | Log.d(TAG, "Manufacturer provided backup settings, showing the preference screen"); |
| 85 | } |
| Anton Philippov | f8b3154 | 2017-02-14 10:41:20 +0000 | [diff] [blame] | 86 | // mFragmentManager can be set by {@link #setFragmentManager()} for testing |
| 87 | if (mFragmentManager == null) { |
| tmfang | 27c84de | 2018-06-28 11:39:05 +0800 | [diff] [blame] | 88 | mFragmentManager = getSupportFragmentManager(); |
| Anton Philippov | f8b3154 | 2017-02-14 10:41:20 +0000 | [diff] [blame] | 89 | } |
| 90 | mFragmentManager.beginTransaction() |
| Anton Philippov | adfec55 | 2017-01-25 20:37:36 +0000 | [diff] [blame] | 91 | .replace(android.R.id.content, new BackupSettingsFragment()) |
| 92 | .commit(); |
| 93 | } |
| 94 | } |
| Anton Philippov | f8b3154 | 2017-02-14 10:41:20 +0000 | [diff] [blame] | 95 | |
| Anton Philippov | 9a5220e | 2017-03-01 21:08:56 +0000 | [diff] [blame] | 96 | /** |
| 97 | * For Search. |
| 98 | */ |
| 99 | public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER = |
| 100 | new BaseSearchIndexProvider() { |
| Chandan Nath | 826a91c | 2019-04-10 17:02:02 +0100 | [diff] [blame^] | 101 | private static final String BACKUP_SEARCH_INDEX_KEY = "Backup"; |
| Anton Philippov | 9a5220e | 2017-03-01 21:08:56 +0000 | [diff] [blame] | 102 | |
| 103 | @Override |
| 104 | public List<SearchIndexableRaw> getRawDataToIndex(Context context, |
| 105 | boolean enabled) { |
| 106 | |
| 107 | final List<SearchIndexableRaw> result = new ArrayList<>(); |
| 108 | |
| 109 | // Add the activity title |
| 110 | SearchIndexableRaw data = new SearchIndexableRaw(context); |
| Fan Zhang | b473730 | 2017-05-31 12:43:48 -0700 | [diff] [blame] | 111 | data.title = context.getString(R.string.privacy_settings_title); |
| 112 | data.screenTitle = context.getString(R.string.settings_label); |
| 113 | data.keywords = context.getString(R.string.keywords_backup); |
| Anton Philippov | 9a5220e | 2017-03-01 21:08:56 +0000 | [diff] [blame] | 114 | data.intentTargetPackage = context.getPackageName(); |
| Fan Zhang | 03dd39c | 2019-04-02 16:41:01 -0700 | [diff] [blame] | 115 | data.intentTargetClass = UserBackupSettingsActivity.class.getName(); |
| Fan Zhang | b473730 | 2017-05-31 12:43:48 -0700 | [diff] [blame] | 116 | data.intentAction = Intent.ACTION_MAIN; |
| Anton Philippov | 9a5220e | 2017-03-01 21:08:56 +0000 | [diff] [blame] | 117 | data.key = BACKUP_SEARCH_INDEX_KEY; |
| 118 | result.add(data); |
| 119 | |
| 120 | return result; |
| 121 | } |
| Chandan Nath | 826a91c | 2019-04-10 17:02:02 +0100 | [diff] [blame^] | 122 | |
| 123 | @Override |
| 124 | public List<String> getNonIndexableKeys(Context context) { |
| 125 | final List<String> keys = super.getNonIndexableKeys(context); |
| 126 | if (!new BackupSettingsHelper(context).showBackupSettingsForUser()) { |
| 127 | keys.add(BACKUP_SEARCH_INDEX_KEY); |
| 128 | } |
| 129 | return keys; |
| 130 | } |
| Anton Philippov | 9a5220e | 2017-03-01 21:08:56 +0000 | [diff] [blame] | 131 | }; |
| 132 | |
| Anton Philippov | f8b3154 | 2017-02-14 10:41:20 +0000 | [diff] [blame] | 133 | @VisibleForTesting |
| 134 | void setFragmentManager(FragmentManager fragmentManager) { |
| 135 | mFragmentManager = fragmentManager; |
| 136 | } |
| Anton Philippov | adfec55 | 2017-01-25 20:37:36 +0000 | [diff] [blame] | 137 | } |