Update Backup & reset settings to launch the configured activity.

Check for configured backup settings activity to be used for
Settings->Backup & reset.

Bug: 28942163
Change-Id: I8b937fde5b400afdb81463c9c278b3e3ad42688b
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 1340880..29a7495 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -2937,6 +2937,31 @@
                        android:value="com.android.settings.gestures.GestureSettings" />
         </activity>
 
+        <activity android:name="BackupSettingsActivity"
+                  android:label="@string/privacy_settings_title"
+                  android:icon="@drawable/ic_settings_backup"
+                  android:theme="@android:style/Theme.NoDisplay"
+                  android:taskAffinity="com.android.settings"
+                  android:parentActivityName="Settings">
+            <intent-filter android:priority="1">
+                <action android:name="android.settings.PRIVACY_SETTINGS" />
+                <action android:name="android.settings.BACKUP_AND_RESET_SETTINGS" />
+                <category android:name="android.intent.category.DEFAULT" />
+            </intent-filter>
+            <intent-filter>
+                <action android:name="android.intent.action.MAIN" />
+                <category android:name="android.intent.category.DEFAULT" />
+                <category android:name="android.intent.category.VOICE_LAUNCH" />
+            </intent-filter>
+            <intent-filter android:priority="-2">
+                <action android:name="com.android.settings.action.SETTINGS" />
+            </intent-filter>
+            <meta-data android:name="com.android.settings.category"
+                       android:value="com.android.settings.category.personal" />
+            <meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED"
+                       android:value="true" />
+        </activity>
+
         <service
             android:name=".SettingsDumpService"
             android:exported="true"
diff --git a/res/values/config.xml b/res/values/config.xml
index 2c7a2de..c5cc341 100755
--- a/res/values/config.xml
+++ b/res/values/config.xml
@@ -44,4 +44,7 @@
     <!-- Package name and fully-qualified class name for the wallpaper picker activity. -->
     <string name="config_wallpaper_picker_package" translatable="false">com.android.settings</string>
     <string name="config_wallpaper_picker_class" translatable="false">com.android.settings.Settings$WallpaperSettingsActivity</string>
+
+    <!-- Backup settings to launch -->
+    <string name="config_backup_settings_intent"></string>
 </resources>
diff --git a/src/com/android/settings/BackupSettingsActivity.java b/src/com/android/settings/BackupSettingsActivity.java
new file mode 100644
index 0000000..94e9691
--- /dev/null
+++ b/src/com/android/settings/BackupSettingsActivity.java
@@ -0,0 +1,56 @@
+/*
+ * Copyright (C) 2016 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.android.settings;
+
+import android.app.Activity;
+import android.content.Intent;
+import android.os.Bundle;
+import android.text.TextUtils;
+import android.util.Log;
+
+import com.android.settings.R;
+
+import java.net.URISyntaxException;
+
+/**
+ * A trampoline activity used to launch the configured Backup activity.
+ * This activity used the theme NoDisplay to minimize the flicker that might be seen for the launch-
+ * finsih transition.
+ */
+public class BackupSettingsActivity extends Activity {
+    private static final String TAG = "BackupSettingsActivity";
+
+    @Override
+    public void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        String backup = getResources().getString(R.string.config_backup_settings_intent);
+        if (!TextUtils.isEmpty(backup)) {
+            try {
+                Intent intent = Intent.parseUri(backup, 0);
+                if (intent.resolveActivity(getPackageManager()) != null) {
+                    // use startActivityForResult to let the activity check the caller signature
+                    startActivityForResult(intent, -1);
+                } else {
+                    Log.e(TAG, "Backup component not found!");
+                }
+            } catch (URISyntaxException e) {
+                Log.e(TAG, "Invalid backup component URI!", e);
+            }
+        }
+        finish();
+    }
+}
\ No newline at end of file
diff --git a/src/com/android/settings/SettingsActivity.java b/src/com/android/settings/SettingsActivity.java
index 17ce8a1..8cc9085 100644
--- a/src/com/android/settings/SettingsActivity.java
+++ b/src/com/android/settings/SettingsActivity.java
@@ -131,6 +131,7 @@
 import com.android.settingslib.drawer.SettingsDrawerActivity;
 import com.android.settingslib.drawer.Tile;
 
+import java.net.URISyntaxException;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Set;
@@ -1099,6 +1100,23 @@
                 }
             }
         }
+
+        String backupIntent = getResources().getString(R.string.config_backup_settings_intent);
+        boolean useDefaultBackup = TextUtils.isEmpty(backupIntent);
+        setTileEnabled(new ComponentName(packageName,
+                Settings.PrivacySettingsActivity.class.getName()), useDefaultBackup, isAdmin, pm);
+        boolean hasBackupActivity = false;
+        if (!useDefaultBackup) {
+            try {
+                Intent intent = Intent.parseUri(backupIntent, 0);
+                hasBackupActivity = !getPackageManager().queryIntentActivities(intent, 0).isEmpty();
+            } catch (URISyntaxException e) {
+                Log.e(LOG_TAG, "Invalid backup intent URI!", e);
+            }
+        }
+        setTileEnabled(new ComponentName(packageName,
+                BackupSettingsActivity.class.getName()), hasBackupActivity, isAdmin, pm);
+
     }
 
     private void setTileEnabled(ComponentName component, boolean enabled, boolean isAdmin,