Merge "[Multi-user] Change Backup Settings page to support multi-user."
This commit is contained in:
@@ -51,7 +51,6 @@ import androidx.preference.PreferenceManager;
|
||||
import com.android.internal.util.ArrayUtils;
|
||||
import com.android.settings.Settings.WifiSettingsActivity;
|
||||
import com.android.settings.applications.manageapplications.ManageApplications;
|
||||
import com.android.settings.backup.BackupSettingsActivity;
|
||||
import com.android.settings.core.OnActivityResultListener;
|
||||
import com.android.settings.core.SettingsBaseActivity;
|
||||
import com.android.settings.core.SubSettingLauncher;
|
||||
@@ -651,11 +650,6 @@ public class SettingsActivity extends SettingsBaseActivity
|
||||
showDev, isAdmin)
|
||||
|| somethingChanged;
|
||||
|
||||
// Enable/disable backup settings depending on whether the user is admin.
|
||||
somethingChanged = setTileEnabled(changedList, new ComponentName(packageName,
|
||||
BackupSettingsActivity.class.getName()), true, isAdmin)
|
||||
|| somethingChanged;
|
||||
|
||||
somethingChanged = setTileEnabled(changedList, new ComponentName(packageName,
|
||||
Settings.WifiDisplaySettingsActivity.class.getName()),
|
||||
WifiDisplaySettings.isAvailable(this), isAdmin)
|
||||
|
||||
@@ -1,54 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2017 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.backup;
|
||||
|
||||
import android.app.backup.BackupManager;
|
||||
import android.content.Context;
|
||||
import android.os.UserManager;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
|
||||
public class BackupSettingsActivityPreferenceController extends BasePreferenceController {
|
||||
private static final String TAG = "BackupSettingActivityPC";
|
||||
|
||||
|
||||
private final UserManager mUm;
|
||||
private final BackupManager mBackupManager;
|
||||
|
||||
public BackupSettingsActivityPreferenceController(Context context, String key) {
|
||||
super(context, key);
|
||||
mUm = (UserManager) context.getSystemService(Context.USER_SERVICE);
|
||||
mBackupManager = new BackupManager(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
return mUm.isAdminUser()
|
||||
? AVAILABLE_UNSEARCHABLE
|
||||
: UNSUPPORTED_ON_DEVICE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getSummary() {
|
||||
final boolean backupEnabled = mBackupManager.isBackupEnabled();
|
||||
|
||||
return backupEnabled
|
||||
? mContext.getText(R.string.backup_summary_state_on)
|
||||
: mContext.getText(R.string.backup_summary_state_off);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* Copyright (C) 2019 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.backup;
|
||||
|
||||
import android.content.ContentProvider;
|
||||
import android.content.ContentValues;
|
||||
import android.content.UriMatcher;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
|
||||
import static com.android.settingslib.drawer.TileUtils.META_DATA_PREFERENCE_SUMMARY;
|
||||
|
||||
/** Provider stores and manages user interaction feedback for homepage contextual cards. */
|
||||
public class BackupSettingsContentProvider extends ContentProvider {
|
||||
private static final String AUTHORITY =
|
||||
"com.android.settings.backup.BackupSettingsContentProvider";
|
||||
private static final String SUMMARY = "summary";
|
||||
private static final UriMatcher URI_MATCHER = new UriMatcher(UriMatcher.NO_MATCH);
|
||||
static {
|
||||
URI_MATCHER.addURI(AUTHORITY, SUMMARY, 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Bundle call(String method, String uri, Bundle extras) {
|
||||
if (!SUMMARY.equals(method)) {
|
||||
return null;
|
||||
}
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString(META_DATA_PREFERENCE_SUMMARY,
|
||||
new BackupSettingsHelper(getContext()).getSummary());
|
||||
return bundle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreate() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getType(Uri uri) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Uri insert(Uri uri, ContentValues values) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int delete(Uri uri, String selection, String[] selectionArgs) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
@@ -68,7 +68,7 @@ public class BackupSettingsFragment extends DashboardFragment {
|
||||
return controllers;
|
||||
}
|
||||
|
||||
// The intention is to index {@link BackupSettingsActivity} instead of the fragments,
|
||||
// The intention is to index {@link UserBackupSettingsActivity} instead of the fragments,
|
||||
// therefore leaving this index provider empty.
|
||||
public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
|
||||
new BaseSearchIndexProvider() {
|
||||
|
||||
@@ -24,6 +24,7 @@ import android.content.Intent;
|
||||
import android.os.RemoteException;
|
||||
import android.os.ServiceManager;
|
||||
import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
@@ -34,7 +35,7 @@ import com.android.settings.Settings.PrivacySettingsActivity;
|
||||
import java.net.URISyntaxException;
|
||||
|
||||
/**
|
||||
* Helper class for {@link BackupSettingsActivity} that interacts with {@link IBackupManager}.
|
||||
* Helper class for {@link UserBackupSettingsActivity} that interacts with {@link IBackupManager}.
|
||||
*/
|
||||
public class BackupSettingsHelper {
|
||||
private static final String TAG = "BackupSettingsHelper";
|
||||
@@ -48,6 +49,24 @@ public class BackupSettingsHelper {
|
||||
mContext = context;
|
||||
}
|
||||
|
||||
/**
|
||||
* If there is only one profile, show whether the backup is on or off.
|
||||
* Otherwise, show nothing.
|
||||
*/
|
||||
String getSummary() {
|
||||
UserManager userManager = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
|
||||
if (userManager.getUserProfiles().size() == 1) {
|
||||
try {
|
||||
int resId = mBackupManager.isBackupEnabled() ? R.string.backup_summary_state_on
|
||||
: R.string.backup_summary_state_off;
|
||||
return mContext.getText(resId).toString();
|
||||
} catch (RemoteException e) {
|
||||
Log.e(TAG, "Error getting isBackupEnabled", e);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an intent to launch backup settings from backup transport if the intent was provided
|
||||
* by the transport. Otherwise returns the intent to launch the default backup settings screen.
|
||||
|
||||
@@ -20,7 +20,6 @@ import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Bundle;
|
||||
import android.os.UserHandle;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
@@ -40,9 +39,14 @@ import java.util.List;
|
||||
/**
|
||||
* The activity used to launch the configured Backup activity or the preference screen
|
||||
* if the manufacturer provided their backup settings.
|
||||
* Pre-Q, BackupSettingsActivity was disabled for non-system users. Therefore, for phones which
|
||||
* upgrade to Q, BackupSettingsActivity is disabled for those users. However, we cannot simply
|
||||
* enable it in Q since component enable can only be done by the user itself; which is not
|
||||
* enough in Q we want it to be enabled for all profile users of the user.
|
||||
* Therefore, as a simple workaround, we use a new class which is enabled by default.
|
||||
*/
|
||||
@SearchIndexable
|
||||
public class BackupSettingsActivity extends FragmentActivity implements Indexable {
|
||||
public class UserBackupSettingsActivity extends FragmentActivity implements Indexable {
|
||||
private static final String TAG = "BackupSettingsActivity";
|
||||
private FragmentManager mFragmentManager;
|
||||
|
||||
@@ -108,29 +112,13 @@ public class BackupSettingsActivity extends FragmentActivity implements Indexabl
|
||||
data.screenTitle = context.getString(R.string.settings_label);
|
||||
data.keywords = context.getString(R.string.keywords_backup);
|
||||
data.intentTargetPackage = context.getPackageName();
|
||||
data.intentTargetClass = BackupSettingsActivity.class.getName();
|
||||
data.intentTargetClass = com.android.settings.backup.UserBackupSettingsActivity.class.getName();
|
||||
data.intentAction = Intent.ACTION_MAIN;
|
||||
data.key = BACKUP_SEARCH_INDEX_KEY;
|
||||
result.add(data);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getNonIndexableKeys(Context context) {
|
||||
final List<String> keys = super.getNonIndexableKeys(context);
|
||||
|
||||
// For non-primary user, no backup is available, so don't show it in search
|
||||
// TODO: http://b/22388012
|
||||
if (UserHandle.myUserId() != UserHandle.USER_SYSTEM) {
|
||||
if (Log.isLoggable(TAG, Log.DEBUG)) {
|
||||
Log.d(TAG, "Not a system user, not indexing the screen");
|
||||
}
|
||||
keys.add(BACKUP_SEARCH_INDEX_KEY);
|
||||
}
|
||||
|
||||
return keys;
|
||||
}
|
||||
};
|
||||
|
||||
@VisibleForTesting
|
||||
@@ -49,6 +49,7 @@ import com.android.settings.applications.specialaccess.deviceadmin.DeviceAdminSe
|
||||
import com.android.settings.applications.specialaccess.pictureinpicture.PictureInPictureDetails;
|
||||
import com.android.settings.applications.specialaccess.pictureinpicture.PictureInPictureSettings;
|
||||
import com.android.settings.applications.specialaccess.vrlistener.VrListenerSettings;
|
||||
import com.android.settings.backup.UserBackupSettingsActivity;
|
||||
import com.android.settings.backup.PrivacySettings;
|
||||
import com.android.settings.backup.ToggleBackupSettingFragment;
|
||||
import com.android.settings.biometrics.face.FaceSettings;
|
||||
@@ -298,5 +299,6 @@ public class SettingsGateway {
|
||||
Settings.DateTimeSettingsActivity.class.getName(),
|
||||
Settings.EnterprisePrivacySettingsActivity.class.getName(),
|
||||
Settings.MyDeviceInfoActivity.class.getName(),
|
||||
UserBackupSettingsActivity.class.getName(),
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user