Merge "Update Backup & reset settings to launch the configured activity." into nyc-mr1-dev

This commit is contained in:
Doris Ling
2016-07-01 20:15:59 +00:00
committed by Android (Google) Code Review
4 changed files with 102 additions and 0 deletions

View File

@@ -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();
}
}

View File

@@ -131,6 +131,7 @@ import com.android.settingslib.drawer.DashboardCategory;
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 @@ public class SettingsActivity extends SettingsDrawerActivity
}
}
}
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,