Commit efbac329 authored by Doris Ling's avatar Doris Ling Committed by Simon Shields

BACKPORT: 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
- remove the search panel from settings home page
- remove the search menu

Bug: 110034419
Test: make RunSettingsRoboTests
Change-Id: Ieb7eb0e8699229ec0824ccc19d7b958ac44965a2
Merged-In: Ieb7eb0e8699229ec0824ccc19d7b958ac44965a2
(cherry picked from commit 770f4abf)
CVE-2018-9501
parent 26218427
......@@ -155,6 +155,11 @@ public class ChooseLockGeneric extends SettingsActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final Activity activity = getActivity();
if (!Utils.isDeviceProvisioned(activity) && !canRunBeforeDeviceProvisioned()) {
activity.finish();
return;
}
String chooseLockAction = getActivity().getIntent().getAction();
mFingerprintManager =
......@@ -234,6 +239,10 @@ public class ChooseLockGeneric extends SettingsActivity {
addHeaderView();
}
protected boolean canRunBeforeDeviceProvisioned() {
return false;
}
protected void addHeaderView() {
if (mForFingerprint) {
setHeaderView(R.layout.choose_lock_generic_fingerprint_header);
......
......@@ -649,8 +649,8 @@ public class SettingsActivity extends SettingsDrawerActivity
} else {
// No UP affordance if we are displaying the main Dashboard
mDisplayHomeAsUpEnabled = false;
// Show Search affordance
mDisplaySearch = true;
// Show Search affordance (if device is provisioned)
mDisplaySearch = Utils.isDeviceProvisioned(this);
mInitialTitleResId = R.string.dashboard_title;
// add argument to indicate which settings tab should be initially selected
......
......@@ -138,6 +138,11 @@ public class SetupChooseLockGeneric extends ChooseLockGeneric {
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
* screen lock options here.
......
/*
* 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.password;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.provider.Settings.Global;
import com.android.settings.password.ChooseLockGeneric.ChooseLockGenericFragment;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.testutils.shadow.SettingsShadowResources;
import org.junit.After;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
@RunWith(SettingsRobolectricTestRunner.class)
public class ChooseLockGenericTest {
@After
public void tearDown() {
Global.putInt(RuntimeEnvironment.application.getContentResolver(),
Global.DEVICE_PROVISIONED, 1);
}
@Test
@Config(shadows = SettingsShadowResources.SettingsShadowTheme.class)
public void onCreate_deviceNotProvisioned_shouldFinishActivity() {
final Context context = RuntimeEnvironment.application;
Global.putInt(context.getContentResolver(), Global.DEVICE_PROVISIONED, 0);
final Activity activity = mock(Activity.class);
when(activity.getContentResolver()).thenReturn(context.getContentResolver());
when(activity.getTheme()).thenReturn(context.getTheme());
final ChooseLockGenericFragment fragment = spy(new ChooseLockGenericFragment());
when(fragment.getActivity()).thenReturn(activity);
when(fragment.getArguments()).thenReturn(Bundle.EMPTY);
fragment.onCreate(Bundle.EMPTY);
verify(activity).finish();
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment