Removed emergency info and add user when locked from Users settings.
In new IA, Emergency Info and Add user when locked has been moved to Users & accounts page. Change-Id: I1a1e4bd801936b654d8a4ede7cfc64e2ac285019 Fix: 33703736 Test: make SettingsTests
This commit is contained in:
@@ -28,14 +28,4 @@
|
|||||||
android:title="@string/user_add_user_or_profile_menu"
|
android:title="@string/user_add_user_or_profile_menu"
|
||||||
android:icon="@drawable/ic_menu_add" />
|
android:icon="@drawable/ic_menu_add" />
|
||||||
|
|
||||||
<PreferenceCategory
|
|
||||||
android:key="lock_screen_settings"
|
|
||||||
android:title="@string/user_lockscreen_settings">
|
|
||||||
<com.android.settingslib.RestrictedSwitchPreference
|
|
||||||
android:key="add_users_when_locked"
|
|
||||||
android:title="@string/user_add_on_lockscreen_menu" />
|
|
||||||
</PreferenceCategory>
|
|
||||||
<Preference
|
|
||||||
android:key="emergency_info"
|
|
||||||
android:title="@string/emergency_info_title" />
|
|
||||||
</PreferenceScreen>
|
</PreferenceScreen>
|
||||||
|
@@ -27,7 +27,6 @@ import android.content.DialogInterface;
|
|||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.content.pm.ResolveInfo;
|
|
||||||
import android.content.pm.UserInfo;
|
import android.content.pm.UserInfo;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
@@ -53,7 +52,6 @@ import android.view.View;
|
|||||||
import android.view.View.OnClickListener;
|
import android.view.View.OnClickListener;
|
||||||
import android.widget.SimpleAdapter;
|
import android.widget.SimpleAdapter;
|
||||||
|
|
||||||
import com.android.internal.annotations.VisibleForTesting;
|
|
||||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||||
import com.android.internal.widget.LockPatternUtils;
|
import com.android.internal.widget.LockPatternUtils;
|
||||||
import com.android.settings.ChooseLockGeneric;
|
import com.android.settings.ChooseLockGeneric;
|
||||||
@@ -63,9 +61,6 @@ import com.android.settings.R;
|
|||||||
import com.android.settings.SettingsActivity;
|
import com.android.settings.SettingsActivity;
|
||||||
import com.android.settings.SettingsPreferenceFragment;
|
import com.android.settings.SettingsPreferenceFragment;
|
||||||
import com.android.settings.Utils;
|
import com.android.settings.Utils;
|
||||||
import com.android.settings.accounts.AddUserWhenLockedPreferenceController;
|
|
||||||
import com.android.settings.accounts.EmergencyInfoPreferenceController;
|
|
||||||
import com.android.settings.overlay.FeatureFactory;
|
|
||||||
import com.android.settings.search.BaseSearchIndexProvider;
|
import com.android.settings.search.BaseSearchIndexProvider;
|
||||||
import com.android.settings.search.Indexable;
|
import com.android.settings.search.Indexable;
|
||||||
import com.android.settings.search.SearchIndexableRaw;
|
import com.android.settings.search.SearchIndexableRaw;
|
||||||
@@ -102,9 +97,6 @@ public class UserSettings extends SettingsPreferenceFragment
|
|||||||
private static final String KEY_USER_LIST = "user_list";
|
private static final String KEY_USER_LIST = "user_list";
|
||||||
private static final String KEY_USER_ME = "user_me";
|
private static final String KEY_USER_ME = "user_me";
|
||||||
private static final String KEY_ADD_USER = "user_add";
|
private static final String KEY_ADD_USER = "user_add";
|
||||||
private static final String KEY_EMERGENCY_INFO = "emergency_info";
|
|
||||||
|
|
||||||
private static final String ACTION_EDIT_EMERGENCY_INFO = "android.settings.EDIT_EMERGENGY_INFO";
|
|
||||||
|
|
||||||
private static final int MENU_REMOVE_USER = Menu.FIRST;
|
private static final int MENU_REMOVE_USER = Menu.FIRST;
|
||||||
|
|
||||||
@@ -136,9 +128,6 @@ public class UserSettings extends SettingsPreferenceFragment
|
|||||||
private PreferenceGroup mUserListCategory;
|
private PreferenceGroup mUserListCategory;
|
||||||
private UserPreference mMePreference;
|
private UserPreference mMePreference;
|
||||||
private DimmableIconPreference mAddUser;
|
private DimmableIconPreference mAddUser;
|
||||||
private PreferenceGroup mLockScreenSettings;
|
|
||||||
private RestrictedSwitchPreference mAddUserWhenLocked;
|
|
||||||
private Preference mEmergencyInfoPreference;
|
|
||||||
private int mRemovingUserId = -1;
|
private int mRemovingUserId = -1;
|
||||||
private int mAddedUserId = 0;
|
private int mAddedUserId = 0;
|
||||||
private boolean mAddingUser;
|
private boolean mAddingUser;
|
||||||
@@ -151,8 +140,6 @@ public class UserSettings extends SettingsPreferenceFragment
|
|||||||
|
|
||||||
private EditUserInfoController mEditUserInfoController =
|
private EditUserInfoController mEditUserInfoController =
|
||||||
new EditUserInfoController();
|
new EditUserInfoController();
|
||||||
private EmergencyInfoPreferenceController mEnergencyInfoController;
|
|
||||||
private AddUserWhenLockedPreferenceController mAddUserWhenLockedController;
|
|
||||||
|
|
||||||
// A place to cache the generated default avatar
|
// A place to cache the generated default avatar
|
||||||
private Drawable mDefaultIconDrawable;
|
private Drawable mDefaultIconDrawable;
|
||||||
@@ -236,14 +223,6 @@ public class UserSettings extends SettingsPreferenceFragment
|
|||||||
mAddUser.setTitle(R.string.user_add_user_menu);
|
mAddUser.setTitle(R.string.user_add_user_menu);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
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);
|
setHasOptionsMenu(true);
|
||||||
IntentFilter filter = new IntentFilter(Intent.ACTION_USER_REMOVED);
|
IntentFilter filter = new IntentFilter(Intent.ACTION_USER_REMOVED);
|
||||||
filter.addAction(Intent.ACTION_USER_INFO_CHANGED);
|
filter.addAction(Intent.ACTION_USER_INFO_CHANGED);
|
||||||
@@ -658,20 +637,6 @@ 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);
|
|
||||||
if (infos == null || infos.isEmpty()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void removeUserNow() {
|
private void removeUserNow() {
|
||||||
if (mRemovingUserId == UserHandle.myUserId()) {
|
if (mRemovingUserId == UserHandle.myUserId()) {
|
||||||
removeThisUser();
|
removeThisUser();
|
||||||
@@ -903,20 +868,6 @@ public class UserSettings extends SettingsPreferenceFragment
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getMaxRealUsers() {
|
private int getMaxRealUsers() {
|
||||||
@@ -997,8 +948,6 @@ public class UserSettings extends SettingsPreferenceFragment
|
|||||||
} else {
|
} else {
|
||||||
onAddUserClicked(USER_TYPE_USER);
|
onAddUserClicked(USER_TYPE_USER);
|
||||||
}
|
}
|
||||||
} else if (mEnergencyInfoController != null) {
|
|
||||||
mEnergencyInfoController.handlePreferenceTreeClick(pref);
|
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -1082,12 +1031,6 @@ public class UserSettings extends SettingsPreferenceFragment
|
|||||||
data.screenTitle = res.getString(R.string.user_settings_title);
|
data.screenTitle = res.getString(R.string.user_settings_title);
|
||||||
result.add(data);
|
result.add(data);
|
||||||
}
|
}
|
||||||
if (emergencyInfoActivityPresent(context)) {
|
|
||||||
data = new SearchIndexableRaw(context);
|
|
||||||
data.title = res.getString(R.string.emergency_info_title);
|
|
||||||
data.screenTitle = res.getString(R.string.emergency_info_title);
|
|
||||||
result.add(data);
|
|
||||||
}
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@@ -0,0 +1,85 @@
|
|||||||
|
/*
|
||||||
|
* 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 android.content.Intent;
|
||||||
|
import android.support.test.filters.SmallTest;
|
||||||
|
import android.support.test.uiautomator.UiDevice;
|
||||||
|
import android.support.test.uiautomator.UiObject;
|
||||||
|
import android.support.test.uiautomator.UiSelector;
|
||||||
|
import android.support.test.uiautomator.UiScrollable;
|
||||||
|
import android.test.InstrumentationTestCase;
|
||||||
|
|
||||||
|
import com.android.settings.R;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
@SmallTest
|
||||||
|
public class UserSettingsTest extends InstrumentationTestCase {
|
||||||
|
|
||||||
|
private static final String USER_AND_ACCOUNTS = "User & accounts";
|
||||||
|
private static final String USERS = "Users";
|
||||||
|
private static final String EMERGNENCY_INFO = "Emergency information";
|
||||||
|
private static final String ADD_USERS_WHEN_LOCKED = "Add users";
|
||||||
|
|
||||||
|
private UiDevice mDevice;
|
||||||
|
private Context mContext;
|
||||||
|
private String mTargetPackage;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void setUp() throws Exception {
|
||||||
|
super.setUp();
|
||||||
|
mDevice = UiDevice.getInstance(getInstrumentation());
|
||||||
|
mContext = getInstrumentation().getTargetContext();
|
||||||
|
mTargetPackage = mContext.getPackageName();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testEmergencyInfoNotExists() throws Exception {
|
||||||
|
launchUserSettings();
|
||||||
|
UiObject emergencyInfoPreference =
|
||||||
|
mDevice.findObject(new UiSelector().text(EMERGNENCY_INFO));
|
||||||
|
assertFalse(emergencyInfoPreference.exists());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testAddUsersWhenLockedNotExists() throws Exception {
|
||||||
|
launchUserSettings();
|
||||||
|
UiObject addUsersPreference =
|
||||||
|
mDevice.findObject(new UiSelector().text(ADD_USERS_WHEN_LOCKED));
|
||||||
|
assertFalse(addUsersPreference.exists());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void launchSettings() {
|
||||||
|
Intent settingsIntent = new Intent(Intent.ACTION_MAIN)
|
||||||
|
.addCategory(Intent.CATEGORY_LAUNCHER)
|
||||||
|
.setPackage(mTargetPackage)
|
||||||
|
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
|
getInstrumentation().getContext().startActivity(settingsIntent);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void launchUserSettings() throws Exception {
|
||||||
|
launchSettings();
|
||||||
|
final UiScrollable settings = new UiScrollable(
|
||||||
|
new UiSelector().packageName(mTargetPackage).scrollable(true));
|
||||||
|
final String titleUsersAndAccounts = USER_AND_ACCOUNTS;
|
||||||
|
settings.scrollTextIntoView(titleUsersAndAccounts);
|
||||||
|
mDevice.findObject(new UiSelector().text(titleUsersAndAccounts)).click();
|
||||||
|
mDevice.findObject(new UiSelector().text(USERS)).click();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -1,65 +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.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();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
Reference in New Issue
Block a user