DO NOT MERGE Disable changing lock when device is not provisioned.

When the device is not yet provisioned and settings is launched:
- disable the entry point for changing device lock
- set display search menu to false
- disallow update to display the search menu

Bug: 110034419
Test: make RunSettingsRoboTests
Change-Id: Ieb7eb0e8699229ec0824ccc19d7b958ac44965a2
Merged-In: Ieb7eb0e8699229ec0824ccc19d7b958ac44965a2
This commit is contained in:
Doris Ling
2018-08-01 17:24:34 -07:00
parent 0e1393ae8c
commit cb68db7d4f
5 changed files with 141 additions and 3 deletions

View File

@@ -141,6 +141,11 @@ public class ChooseLockGeneric extends SettingsActivity {
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
final Activity activity = getActivity();
if (!Utils.isDeviceProvisioned(activity) && !canRunBeforeDeviceProvisioned()) {
activity.finish();
return;
}
String chooseLockAction = getActivity().getIntent().getAction(); String chooseLockAction = getActivity().getIntent().getAction();
mFingerprintManager = Utils.getFingerprintManagerOrNull(getActivity()); mFingerprintManager = Utils.getFingerprintManagerOrNull(getActivity());
@@ -218,6 +223,10 @@ public class ChooseLockGeneric extends SettingsActivity {
addHeaderView(); addHeaderView();
} }
protected boolean canRunBeforeDeviceProvisioned() {
return false;
}
protected void addHeaderView() { protected void addHeaderView() {
if (mForFingerprint) { if (mForFingerprint) {
setHeaderView(R.layout.choose_lock_generic_fingerprint_header); setHeaderView(R.layout.choose_lock_generic_fingerprint_header);

View File

@@ -435,7 +435,7 @@ public class SettingsActivity extends SettingsDrawerActivity
// No UP affordance if we are displaying the main Dashboard // No UP affordance if we are displaying the main Dashboard
mDisplayHomeAsUpEnabled = false; mDisplayHomeAsUpEnabled = false;
// Show Search affordance // Show Search affordance
mDisplaySearch = true; mDisplaySearch = Utils.isDeviceProvisioned(this);
mInitialTitleResId = R.string.dashboard_title; mInitialTitleResId = R.string.dashboard_title;
switchToFragment(DashboardSummary.class.getName(), null /* args */, false, false, switchToFragment(DashboardSummary.class.getName(), null /* args */, false, false,
@@ -444,7 +444,7 @@ public class SettingsActivity extends SettingsDrawerActivity
} }
public void setDisplaySearchMenu(boolean displaySearch) { public void setDisplaySearchMenu(boolean displaySearch) {
if (displaySearch != mDisplaySearch) { if (Utils.isDeviceProvisioned(this) && displaySearch != mDisplaySearch) {
mDisplaySearch = displaySearch; mDisplaySearch = displaySearch;
invalidateOptionsMenu(); invalidateOptionsMenu();
} }

View File

@@ -131,6 +131,11 @@ public class SetupChooseLockGeneric extends ChooseLockGeneric {
return layout.onCreateRecyclerView(inflater, parent, savedInstanceState); return layout.onCreateRecyclerView(inflater, parent, savedInstanceState);
} }
@Override
protected boolean canRunBeforeDeviceProvisioned() {
return true;
}
/*** /***
* Disables preferences that are less secure than required quality and shows only secure * Disables preferences that are less secure than required quality and shows only secure
* screen lock options here. * screen lock options here.

View File

@@ -0,0 +1,95 @@
/*
* Copyright (C) 2018 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 static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.app.Activity;
import android.app.FragmentHostCallback;
import android.content.Context;
import android.os.Bundle;
import android.provider.Settings.Global;
import com.android.settings.ChooseLockGeneric.ChooseLockGenericFragment;
import com.android.settings.testutils.shadow.SettingsShadowResources;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import org.robolectric.util.ReflectionHelpers;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(
manifest = TestConfig.MANIFEST_PATH,
sdk = TestConfig.SDK_VERSION,
shadows = {
SettingsShadowResources.class,
SettingsShadowResources.SettingsShadowTheme.class
})
public class ChooseLockGenericTest {
@Mock
private ChooseLockGeneric mActivity;
private Context mContext;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = RuntimeEnvironment.application;
when(mActivity.getContentResolver()).thenReturn(mContext.getContentResolver());
when(mActivity.getTheme()).thenReturn(mContext.getTheme());
when(mActivity.getResources()).thenReturn(mContext.getResources());
}
@After
public void tearDown() {
Global.putInt(mContext.getContentResolver(), Global.DEVICE_PROVISIONED, 1);
}
@Test
public void onCreate_deviceNotProvisioned_shouldFinishActivity() {
Global.putInt(mContext.getContentResolver(), Global.DEVICE_PROVISIONED, 0);
final ChooseLockGenericFragment fragment = spy(new ChooseLockGenericFragment());
when(fragment.getActivity()).thenReturn(mActivity);
ReflectionHelpers.setField(fragment, "mHost", new TestHostCallbacks());
fragment.onCreate(Bundle.EMPTY);
verify(mActivity).finish();
}
public class TestHostCallbacks extends FragmentHostCallback<Activity> {
public TestHostCallbacks() {
super(mActivity, null /* handler */, 0 /* windowAnimations */);
}
@Override
public Activity onGetHost() {
return mActivity;
}
}
}

View File

@@ -25,6 +25,7 @@ import android.content.Intent;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.os.Bundle; import android.os.Bundle;
import android.provider.Settings.Global;
import android.view.Menu; import android.view.Menu;
import com.android.settings.testutils.FakeFeatureFactory; import com.android.settings.testutils.FakeFeatureFactory;
import org.junit.Before; import org.junit.Before;
@@ -80,11 +81,39 @@ public class SettingsActivityTest {
when(mActivity.getFragmentManager()).thenReturn(mFragmentManager); when(mActivity.getFragmentManager()).thenReturn(mFragmentManager);
when(mFragmentManager.beginTransaction()).thenReturn(mock(FragmentTransaction.class)); when(mFragmentManager.beginTransaction()).thenReturn(mock(FragmentTransaction.class));
doReturn(RuntimeEnvironment.application.getClassLoader()).when(mActivity).getClassLoader(); final Context context = RuntimeEnvironment.application;
doReturn(context.getClassLoader()).when(mActivity).getClassLoader();
doReturn(context.getContentResolver()).when(mActivity).getContentResolver();
mActivity.launchSettingFragment(null, true, mock(Intent.class)); mActivity.launchSettingFragment(null, true, mock(Intent.class));
} }
@Test
public void launchSettingFragment_deviceNotProvisioned_shouldNotShowSearch() {
final Context context = RuntimeEnvironment.application;
Global.putInt(context.getContentResolver(), Global.DEVICE_PROVISIONED, 0);
when(mActivity.getFragmentManager()).thenReturn(mFragmentManager);
when(mFragmentManager.beginTransaction()).thenReturn(mock(FragmentTransaction.class));
doReturn(context.getClassLoader()).when(mActivity).getClassLoader();
doReturn(context.getContentResolver()).when(mActivity).getContentResolver();
mActivity.launchSettingFragment(null, true, mock(Intent.class));
assertThat(mActivity.mDisplaySearch).isFalse();
}
@Test
public void setDisplaySearchMenu_deviceNotProvisioned_shouldNotUpdate() {
final Context context = RuntimeEnvironment.application;
Global.putInt(context.getContentResolver(), Global.DEVICE_PROVISIONED, 0);
doReturn(context.getContentResolver()).when(mActivity).getContentResolver();
mActivity.mDisplaySearch = false;
mActivity.setDisplaySearchMenu(true);
assertThat(mActivity.mDisplaySearch).isFalse();
}
@Test @Test
public void testSetTaskDescription_IconChanged() { public void testSetTaskDescription_IconChanged() {
mActivity.setTaskDescription(mTaskDescription); mActivity.setTaskDescription(mTaskDescription);