Merge "Disable changing lock when device is not provisioned." into oc-mr1-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
38b9504a41
@@ -322,7 +322,7 @@ public class SettingsActivity extends SettingsDrawerActivity
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (mIsShowingDashboard) {
|
if (mIsShowingDashboard) {
|
||||||
findViewById(R.id.search_bar).setVisibility(View.VISIBLE);
|
setSearchBarVisibility();
|
||||||
findViewById(R.id.action_bar).setVisibility(View.GONE);
|
findViewById(R.id.action_bar).setVisibility(View.GONE);
|
||||||
Toolbar toolbar = findViewById(R.id.search_action_bar);
|
Toolbar toolbar = findViewById(R.id.search_action_bar);
|
||||||
toolbar.setOnClickListener(this);
|
toolbar.setOnClickListener(this);
|
||||||
@@ -406,6 +406,12 @@ public class SettingsActivity extends SettingsDrawerActivity
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@VisibleForTesting
|
||||||
|
void setSearchBarVisibility() {
|
||||||
|
findViewById(R.id.search_bar).setVisibility(
|
||||||
|
Utils.isDeviceProvisioned(this) ? View.VISIBLE : View.INVISIBLE);
|
||||||
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
void launchSettingFragment(String initialFragmentName, boolean isSubSettings, Intent intent) {
|
void launchSettingFragment(String initialFragmentName, boolean isSubSettings, Intent intent) {
|
||||||
if (!mIsShowingDashboard && initialFragmentName != null) {
|
if (!mIsShowingDashboard && initialFragmentName != null) {
|
||||||
|
@@ -164,6 +164,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());
|
||||||
@@ -248,6 +253,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);
|
||||||
|
@@ -129,6 +129,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.
|
||||||
|
@@ -35,12 +35,11 @@ import android.content.Context;
|
|||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.Menu;
|
import android.provider.Settings.Global;
|
||||||
|
import android.view.View;
|
||||||
|
|
||||||
import com.android.settings.search.SearchActivity;
|
import com.android.settings.search.SearchActivity;
|
||||||
import com.android.settings.testutils.FakeFeatureFactory;
|
|
||||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
@@ -56,23 +55,44 @@ import org.robolectric.util.ReflectionHelpers;
|
|||||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||||
public class SettingsActivityTest {
|
public class SettingsActivityTest {
|
||||||
|
|
||||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
|
||||||
private Context mContext;
|
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private FragmentManager mFragmentManager;
|
private FragmentManager mFragmentManager;
|
||||||
@Mock
|
@Mock
|
||||||
private ActivityManager.TaskDescription mTaskDescription;
|
private ActivityManager.TaskDescription mTaskDescription;
|
||||||
@Mock
|
@Mock
|
||||||
private Bitmap mBitmap;
|
private Bitmap mBitmap;
|
||||||
|
@Mock
|
||||||
|
private View mSearchBar;
|
||||||
private SettingsActivity mActivity;
|
private SettingsActivity mActivity;
|
||||||
|
private Context mContext;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
MockitoAnnotations.initMocks(this);
|
MockitoAnnotations.initMocks(this);
|
||||||
|
|
||||||
|
mContext = RuntimeEnvironment.application;
|
||||||
mActivity = spy(new SettingsActivity());
|
mActivity = spy(new SettingsActivity());
|
||||||
doReturn(mBitmap).when(mActivity).getBitmapFromXmlResource(anyInt());
|
doReturn(mBitmap).when(mActivity).getBitmapFromXmlResource(anyInt());
|
||||||
|
doReturn(mContext.getContentResolver()).when(mActivity).getContentResolver();
|
||||||
|
doReturn(mSearchBar).when(mActivity).findViewById(R.id.search_bar);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void setSearchBarVisibility_deviceNotProvisioned_shouldDisableSearch() {
|
||||||
|
Global.putInt(mContext.getContentResolver(), Global.DEVICE_PROVISIONED, 0);
|
||||||
|
|
||||||
|
mActivity.setSearchBarVisibility();
|
||||||
|
|
||||||
|
verify(mSearchBar).setVisibility(View.INVISIBLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void setSearchBarVisibility_deviceProvisioned_shouldEnableSearch() {
|
||||||
|
Global.putInt(mContext.getContentResolver(), Global.DEVICE_PROVISIONED, 1);
|
||||||
|
|
||||||
|
mActivity.setSearchBarVisibility();
|
||||||
|
|
||||||
|
verify(mSearchBar).setVisibility(View.VISIBLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@@ -0,0 +1,97 @@
|
|||||||
|
/*
|
||||||
|
* 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.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.TestConfig;
|
||||||
|
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.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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Reference in New Issue
Block a user