| 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 | |
| 19 | import android.app.Activity; |
| 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 | |
| 25 | |
| 26 | /** |
| 27 | * The activity used to launch the configured Backup activity or the preference screen |
| 28 | * if the manufacturer provided their backup settings. |
| 29 | */ |
| 30 | public class BackupSettingsActivity extends Activity { |
| 31 | private static final String TAG = "BackupSettingsActivity"; |
| 32 | |
| 33 | @Override |
| 34 | public void onCreate(Bundle savedInstanceState) { |
| 35 | super.onCreate(savedInstanceState); |
| 36 | |
| 37 | BackupSettingsHelper backupHelper = new BackupSettingsHelper(this); |
| 38 | |
| 39 | if (!backupHelper.isBackupProvidedByManufacturer()) { |
| 40 | // If manufacturer specific backup settings are not provided then launch |
| 41 | // the backup settings provided by backup transport or the default one directly. |
| 42 | if (Log.isLoggable(TAG, Log.DEBUG)) { |
| 43 | Log.d(TAG, |
| 44 | "No manufacturer settings found, launching the backup settings directly"); |
| 45 | } |
| Anton Philippov | 18dd11f | 2017-02-03 16:01:52 +0000 | [diff] [blame^] | 46 | Intent intent = backupHelper.getIntentForBackupSettings(); |
| 47 | // enable the activity before launching it |
| 48 | getPackageManager().setComponentEnabledSetting(intent.getComponent(), |
| 49 | PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP); |
| 50 | |
| Anton Philippov | adfec55 | 2017-01-25 20:37:36 +0000 | [diff] [blame] | 51 | // use startActivityForResult to let the activity check the caller signature |
| Anton Philippov | 18dd11f | 2017-02-03 16:01:52 +0000 | [diff] [blame^] | 52 | startActivityForResult(intent, 1); |
| Anton Philippov | adfec55 | 2017-01-25 20:37:36 +0000 | [diff] [blame] | 53 | finish(); |
| 54 | } else { |
| 55 | if (Log.isLoggable(TAG, Log.DEBUG)) { |
| 56 | Log.d(TAG, "Manufacturer provided backup settings, showing the preference screen"); |
| 57 | } |
| 58 | getFragmentManager().beginTransaction() |
| 59 | .replace(android.R.id.content, new BackupSettingsFragment()) |
| 60 | .commit(); |
| 61 | } |
| 62 | } |
| 63 | } |