Misc fixes for User page and my device info page
- Rename UserAndAccountDashboard* to AccountDashboard* - Move emergency info from account to device info page - Move auto sync data toggles (4 of them) from Account page to user page - Move the controllers too. UserSettings is a not a DashboardFragment so I had to manually call each controller method. TODO: refactor UserSettings to a DashboardFragment - Move legal information/regulatory info above advance button within device info page. Fixes: 72523158 Bug: 71871075 Test: robotests Change-Id: I1b8af8af61e49d17926f984978a09a974b6c62e1
This commit is contained in:
@@ -35,10 +35,10 @@ import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class UserAndAccountDashboardFragment extends DashboardFragment {
|
||||
public class AccountDashboardFragment extends DashboardFragment {
|
||||
|
||||
private static final String TAG = "AccountDashboardFrag";
|
||||
|
||||
private static final String TAG = "UserAndAccountDashboard";
|
||||
private static final String KEY_ADD_USER_WHEN_LOCKED = "user_settings_add_users_when_locked";
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
@@ -52,7 +52,7 @@ public class UserAndAccountDashboardFragment extends DashboardFragment {
|
||||
|
||||
@Override
|
||||
protected int getPreferenceScreenResId() {
|
||||
return R.xml.user_and_accounts_settings;
|
||||
return R.xml.accounts_dashboard_settings;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -63,16 +63,7 @@ public class UserAndAccountDashboardFragment extends DashboardFragment {
|
||||
@Override
|
||||
protected List<AbstractPreferenceController> getPreferenceControllers(Context context) {
|
||||
final List<AbstractPreferenceController> controllers = new ArrayList<>();
|
||||
controllers.add(new EmergencyInfoPreferenceController(context));
|
||||
AddUserWhenLockedPreferenceController addUserWhenLockedPrefController =
|
||||
new AddUserWhenLockedPreferenceController(
|
||||
context, KEY_ADD_USER_WHEN_LOCKED);
|
||||
controllers.add(addUserWhenLockedPrefController);
|
||||
getLifecycle().addObserver(addUserWhenLockedPrefController);
|
||||
controllers.add(new AutoSyncDataPreferenceController(context, this));
|
||||
controllers.add(new AutoSyncPersonalDataPreferenceController(context, this));
|
||||
controllers.add(new AutoSyncWorkDataPreferenceController(context, this));
|
||||
String[] authorities = getIntent().getStringArrayExtra(EXTRA_AUTHORITIES);
|
||||
final String[] authorities = getIntent().getStringArrayExtra(EXTRA_AUTHORITIES);
|
||||
final AccountPreferenceController accountPrefController =
|
||||
new AccountPreferenceController(context, this, authorities);
|
||||
getLifecycle().addObserver(accountPrefController);
|
||||
@@ -116,7 +107,7 @@ public class UserAndAccountDashboardFragment extends DashboardFragment {
|
||||
public List<SearchIndexableResource> getXmlResourcesToIndex(
|
||||
Context context, boolean enabled) {
|
||||
final SearchIndexableResource sir = new SearchIndexableResource(context);
|
||||
sir.xmlResId = R.xml.user_and_accounts_settings;
|
||||
sir.xmlResId = R.xml.accounts_dashboard_settings;
|
||||
return Arrays.asList(sir);
|
||||
}
|
||||
};
|
@@ -1,84 +0,0 @@
|
||||
/*
|
||||
* 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.accounts;
|
||||
|
||||
import android.content.Context;
|
||||
import android.provider.Settings.Global;
|
||||
import android.support.v7.preference.Preference;
|
||||
|
||||
import com.android.settings.core.PreferenceControllerMixin;
|
||||
import com.android.settings.users.UserCapabilities;
|
||||
import com.android.settingslib.RestrictedSwitchPreference;
|
||||
import com.android.settingslib.core.AbstractPreferenceController;
|
||||
import com.android.settingslib.core.lifecycle.LifecycleObserver;
|
||||
import com.android.settingslib.core.lifecycle.events.OnPause;
|
||||
import com.android.settingslib.core.lifecycle.events.OnResume;
|
||||
|
||||
public class AddUserWhenLockedPreferenceController extends AbstractPreferenceController
|
||||
implements PreferenceControllerMixin, Preference.OnPreferenceChangeListener,
|
||||
LifecycleObserver, OnPause, OnResume {
|
||||
|
||||
private final String mPrefKey;
|
||||
private final UserCapabilities mUserCaps;
|
||||
private boolean mShouldUpdateUserList;
|
||||
|
||||
public AddUserWhenLockedPreferenceController(Context context, String key) {
|
||||
super(context);
|
||||
mPrefKey = key;
|
||||
mUserCaps = UserCapabilities.create(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateState(Preference preference) {
|
||||
RestrictedSwitchPreference restrictedSwitchPreference =
|
||||
(RestrictedSwitchPreference) preference;
|
||||
int value = Global.getInt(mContext.getContentResolver(), Global.ADD_USERS_WHEN_LOCKED, 0);
|
||||
restrictedSwitchPreference.setChecked(value == 1);
|
||||
restrictedSwitchPreference.setDisabledByAdmin(
|
||||
mUserCaps.disallowAddUser() ? mUserCaps.getEnforcedAdmin() : null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
Boolean value = (Boolean) newValue;
|
||||
Global.putInt(mContext.getContentResolver(),
|
||||
Global.ADD_USERS_WHEN_LOCKED, value != null && value ? 1 : 0);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
mShouldUpdateUserList = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
if (mShouldUpdateUserList) {
|
||||
mUserCaps.updateAddUserCapabilities(mContext);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAvailable() {
|
||||
return mUserCaps.isAdmin() &&
|
||||
(!mUserCaps.disallowAddUser() || mUserCaps.disallowAddUserSetByAdmin());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPreferenceKey() {
|
||||
return mPrefKey;
|
||||
}
|
||||
}
|
@@ -1,164 +0,0 @@
|
||||
/*
|
||||
* 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.accounts;
|
||||
|
||||
import android.app.ActivityManager;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.app.Fragment;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.os.Bundle;
|
||||
import android.os.Process;
|
||||
import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
import android.support.v14.preference.SwitchPreference;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.PreferenceControllerMixin;
|
||||
import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
|
||||
import com.android.settingslib.core.AbstractPreferenceController;
|
||||
|
||||
public class AutoSyncDataPreferenceController extends AbstractPreferenceController
|
||||
implements PreferenceControllerMixin {
|
||||
|
||||
private static final String TAG = "AutoSyncDataController";
|
||||
private static final String TAG_CONFIRM_AUTO_SYNC_CHANGE = "confirmAutoSyncChange";
|
||||
private static final String KEY_AUTO_SYNC_ACCOUNT = "auto_sync_account_data";
|
||||
|
||||
protected final UserManager mUserManager;
|
||||
private final Fragment mParentFragment;
|
||||
|
||||
protected UserHandle mUserHandle;
|
||||
|
||||
public AutoSyncDataPreferenceController(Context context, Fragment parent) {
|
||||
super(context);
|
||||
mUserManager = (UserManager) context.getSystemService(Context.USER_SERVICE);
|
||||
mParentFragment = parent;
|
||||
mUserHandle = Process.myUserHandle();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateState(Preference preference) {
|
||||
SwitchPreference switchPreference = (SwitchPreference) preference;
|
||||
switchPreference.setChecked(ContentResolver.getMasterSyncAutomaticallyAsUser(
|
||||
mUserHandle.getIdentifier()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handlePreferenceTreeClick(Preference preference) {
|
||||
if (getPreferenceKey().equals(preference.getKey())) {
|
||||
SwitchPreference switchPreference = (SwitchPreference) preference;
|
||||
boolean checked = switchPreference.isChecked();
|
||||
switchPreference.setChecked(!checked);
|
||||
if (ActivityManager.isUserAMonkey()) {
|
||||
Log.d(TAG, "ignoring monkey's attempt to flip sync state");
|
||||
} else {
|
||||
ConfirmAutoSyncChangeFragment.show(mParentFragment, checked, mUserHandle,
|
||||
switchPreference);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAvailable() {
|
||||
return !mUserManager.isManagedProfile()
|
||||
&& (mUserManager.isLinkedUser()
|
||||
|| mUserManager.getProfiles(UserHandle.myUserId()).size() == 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPreferenceKey() {
|
||||
return KEY_AUTO_SYNC_ACCOUNT;
|
||||
}
|
||||
|
||||
/**
|
||||
* Dialog to inform user about changing auto-sync setting
|
||||
*/
|
||||
public static class ConfirmAutoSyncChangeFragment extends InstrumentedDialogFragment implements
|
||||
DialogInterface.OnClickListener {
|
||||
private static final String SAVE_ENABLING = "enabling";
|
||||
private static final String SAVE_USER_HANDLE = "userHandle";
|
||||
boolean mEnabling;
|
||||
UserHandle mUserHandle;
|
||||
SwitchPreference mPreference;
|
||||
|
||||
public static void show(Fragment parent, boolean enabling, UserHandle userHandle,
|
||||
SwitchPreference preference) {
|
||||
if (!parent.isAdded()) return;
|
||||
|
||||
final ConfirmAutoSyncChangeFragment dialog = new ConfirmAutoSyncChangeFragment();
|
||||
dialog.mEnabling = enabling;
|
||||
dialog.mUserHandle = userHandle;
|
||||
dialog.setTargetFragment(parent, 0);
|
||||
dialog.mPreference = preference;
|
||||
dialog.show(parent.getFragmentManager(), TAG_CONFIRM_AUTO_SYNC_CHANGE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
final Context context = getActivity();
|
||||
if (savedInstanceState != null) {
|
||||
mEnabling = savedInstanceState.getBoolean(SAVE_ENABLING);
|
||||
mUserHandle = (UserHandle) savedInstanceState.getParcelable(SAVE_USER_HANDLE);
|
||||
}
|
||||
|
||||
final AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
||||
if (!mEnabling) {
|
||||
builder.setTitle(R.string.data_usage_auto_sync_off_dialog_title);
|
||||
builder.setMessage(R.string.data_usage_auto_sync_off_dialog);
|
||||
} else {
|
||||
builder.setTitle(R.string.data_usage_auto_sync_on_dialog_title);
|
||||
builder.setMessage(R.string.data_usage_auto_sync_on_dialog);
|
||||
}
|
||||
|
||||
builder.setPositiveButton(android.R.string.ok, this);
|
||||
builder.setNegativeButton(android.R.string.cancel, null);
|
||||
|
||||
return builder.create();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
outState.putBoolean(SAVE_ENABLING, mEnabling);
|
||||
outState.putParcelable(SAVE_USER_HANDLE, mUserHandle);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
return MetricsProto.MetricsEvent.DIALOG_CONFIRM_AUTO_SYNC_CHANGE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
if (which == DialogInterface.BUTTON_POSITIVE) {
|
||||
ContentResolver.setMasterSyncAutomaticallyAsUser(mEnabling,
|
||||
mUserHandle.getIdentifier());
|
||||
if (mPreference != null) {
|
||||
mPreference.setChecked(mEnabling);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -1,42 +0,0 @@
|
||||
/*
|
||||
* 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.accounts;
|
||||
|
||||
import android.app.Fragment;
|
||||
import android.content.Context;
|
||||
import android.os.UserHandle;
|
||||
|
||||
public class AutoSyncPersonalDataPreferenceController extends AutoSyncDataPreferenceController {
|
||||
|
||||
private static final String TAG = "AutoSyncPersonalData";
|
||||
private static final String KEY_AUTO_SYNC_PERSONAL_ACCOUNT = "auto_sync_personal_account_data";
|
||||
|
||||
public AutoSyncPersonalDataPreferenceController(Context context, Fragment parent) {
|
||||
super(context, parent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAvailable() {
|
||||
return !mUserManager.isManagedProfile() && !mUserManager.isLinkedUser()
|
||||
&& mUserManager.getProfiles(UserHandle.myUserId()).size() > 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPreferenceKey() {
|
||||
return KEY_AUTO_SYNC_PERSONAL_ACCOUNT;
|
||||
}
|
||||
|
||||
}
|
@@ -1,37 +0,0 @@
|
||||
/*
|
||||
* 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.accounts;
|
||||
|
||||
import android.app.Fragment;
|
||||
import android.content.Context;
|
||||
|
||||
import com.android.settings.Utils;
|
||||
|
||||
public class AutoSyncWorkDataPreferenceController extends AutoSyncPersonalDataPreferenceController {
|
||||
|
||||
private static final String TAG = "AutoSyncWorkData";
|
||||
private static final String KEY_AUTO_SYNC_WORK_ACCOUNT = "auto_sync_work_account_data";
|
||||
|
||||
public AutoSyncWorkDataPreferenceController(Context context, Fragment parent) {
|
||||
super(context, parent);
|
||||
mUserHandle = Utils.getManagedProfileWithDisabled(mUserManager);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPreferenceKey() {
|
||||
return KEY_AUTO_SYNC_WORK_ACCOUNT;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user