Removed emergency info and add user when locked from Users settings.

If new IA is enabled,  Emergency Info and Add user when locked has been moved to
Users & accounts page, so Users page should not show them.

Also fix the issue that update for the add user when locked switch does
not persist correctly.

Change-Id: I26d9f59d0f4bf3fd36a7d07d13f95127b40a8a3e
Fix: 33703736
Test: make RunSettingsRoboTests
This commit is contained in:
Doris Ling
2016-12-27 16:18:45 -08:00
parent bdd0f0f66c
commit 34a4c804f8
2 changed files with 94 additions and 13 deletions

View File

@@ -54,6 +54,7 @@ import android.view.View;
import android.view.View.OnClickListener;
import android.widget.SimpleAdapter;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.internal.widget.LockPatternUtils;
import com.android.settings.ChooseLockGeneric;
@@ -66,6 +67,7 @@ import com.android.settings.Utils;
import com.android.settings.accounts.AddUserWhenLockedPreferenceController;
import com.android.settings.accounts.EmergencyInfoPreferenceController;
import com.android.settings.dashboard.SummaryLoader;
import com.android.settings.overlay.FeatureFactory;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settings.search.Indexable;
import com.android.settings.search.SearchIndexableRaw;
@@ -137,6 +139,7 @@ public class UserSettings extends SettingsPreferenceFragment
private UserPreference mMePreference;
private DimmableIconPreference mAddUser;
private PreferenceGroup mLockScreenSettings;
private RestrictedSwitchPreference mAddUserWhenLocked;
private Preference mEmergencyInfoPreference;
private int mRemovingUserId = -1;
private int mAddedUserId = 0;
@@ -235,10 +238,14 @@ public class UserSettings extends SettingsPreferenceFragment
mAddUser.setTitle(R.string.user_add_user_menu);
}
}
mLockScreenSettings = (PreferenceGroup) findPreference("lock_screen_settings");
mEmergencyInfoPreference = findPreference(KEY_EMERGENCY_INFO);
mEnergencyInfoController = new EmergencyInfoPreferenceController(context);
mAddUserWhenLockedController = new AddUserWhenLockedPreferenceController(context);
if (showEmergencyInfoAndAddUsersWhenLock(context)) {
mLockScreenSettings = (PreferenceGroup) findPreference("lock_screen_settings");
mAddUserWhenLocked =
(RestrictedSwitchPreference) findPreference("add_users_when_locked");
mEmergencyInfoPreference = findPreference(KEY_EMERGENCY_INFO);
mEnergencyInfoController = new EmergencyInfoPreferenceController(context);
mAddUserWhenLockedController = new AddUserWhenLockedPreferenceController(context);
}
setHasOptionsMenu(true);
IntentFilter filter = new IntentFilter(Intent.ACTION_USER_REMOVED);
filter.addAction(Intent.ACTION_USER_INFO_CHANGED);
@@ -651,6 +658,11 @@ public class UserSettings extends SettingsPreferenceFragment
}
}
@VisibleForTesting
boolean showEmergencyInfoAndAddUsersWhenLock(Context context) {
return !FeatureFactory.getFactory(context).getDashboardFeatureProvider(context).isEnabled();
}
private static boolean emergencyInfoActivityPresent(Context context) {
Intent intent = new Intent(ACTION_EDIT_EMERGENCY_INFO).setPackage("com.android.emergency");
List<ResolveInfo> infos = context.getPackageManager().queryIntentActivities(intent, 0);
@@ -891,15 +903,19 @@ public class UserSettings extends SettingsPreferenceFragment
}
}
if (mAddUserWhenLockedController.isAvailable()) {
mLockScreenSettings.setOrder(Preference.DEFAULT_ORDER);
preferenceScreen.addPreference(mLockScreenSettings);
}
if (showEmergencyInfoAndAddUsersWhenLock(context)) {
if (mAddUserWhenLockedController.isAvailable()) {
mLockScreenSettings.setOrder(Preference.DEFAULT_ORDER);
preferenceScreen.addPreference(mLockScreenSettings);
mAddUserWhenLockedController.updateState(mAddUserWhenLocked);
mAddUserWhenLocked.setOnPreferenceChangeListener(mAddUserWhenLockedController);
}
if (emergencyInfoActivityPresent(getContext())) {
mEmergencyInfoPreference.setOnPreferenceClickListener(this);
mEmergencyInfoPreference.setOrder(Preference.DEFAULT_ORDER);
preferenceScreen.addPreference(mEmergencyInfoPreference);
if (emergencyInfoActivityPresent(getContext())) {
mEmergencyInfoPreference.setOnPreferenceClickListener(this);
mEmergencyInfoPreference.setOrder(Preference.DEFAULT_ORDER);
preferenceScreen.addPreference(mEmergencyInfoPreference);
}
}
}
@@ -981,7 +997,7 @@ public class UserSettings extends SettingsPreferenceFragment
} else {
onAddUserClicked(USER_TYPE_USER);
}
} else {
} else if (mEnergencyInfoController != null) {
mEnergencyInfoController.handlePreferenceTreeClick(pref);
}
return false;

View File

@@ -0,0 +1,65 @@
/*
* 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.users;
import android.content.Context;
import com.android.settings.SettingsRobolectricTestRunner;
import com.android.settings.TestConfig;
import com.android.settings.testutils.FakeFeatureFactory;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Answers;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.annotation.Config;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.when;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class UserSettingsTest {
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private Context mContext;
private FakeFeatureFactory mFeatureFactory;
private UserSettings mSetting;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
FakeFeatureFactory.setupForTest(mContext);
mFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
mSetting = new UserSettings();
}
@Test
public void testShowEmergencyInfoAndAddUsers_IAEnabled_shouldReturnFalse() {
when(mFeatureFactory.dashboardFeatureProvider.isEnabled()).thenReturn(true);
assertThat(mSetting.showEmergencyInfoAndAddUsersWhenLock(mContext)).isFalse();
}
@Test
public void testShowEmergencyInfoAndAddUsers_IADisabled_shouldReturnTrue() {
when(mFeatureFactory.dashboardFeatureProvider.isEnabled()).thenReturn(false);
assertThat(mSetting.showEmergencyInfoAndAddUsersWhenLock(mContext)).isTrue();
}
}