packages/apps/Settings
Revisión | a41b6b10517d34e749c414b44510bd6eb9925284 (tree) |
---|---|
Tiempo | 2018-10-09 22:45:15 |
Autor | Chih-Wei Huang <cwhuang@linu...> |
Commiter | Chih-Wei Huang |
Merge tag 'android-8.1.0_r48' into oreo-x86
Android 8.1.0 release 48
@@ -322,7 +322,7 @@ public class SettingsActivity extends SettingsDrawerActivity | ||
322 | 322 | } |
323 | 323 | |
324 | 324 | if (mIsShowingDashboard) { |
325 | - findViewById(R.id.search_bar).setVisibility(View.VISIBLE); | |
325 | + setSearchBarVisibility(); | |
326 | 326 | findViewById(R.id.action_bar).setVisibility(View.GONE); |
327 | 327 | Toolbar toolbar = findViewById(R.id.search_action_bar); |
328 | 328 | toolbar.setOnClickListener(this); |
@@ -407,6 +407,12 @@ public class SettingsActivity extends SettingsDrawerActivity | ||
407 | 407 | } |
408 | 408 | |
409 | 409 | @VisibleForTesting |
410 | + void setSearchBarVisibility() { | |
411 | + findViewById(R.id.search_bar).setVisibility( | |
412 | + Utils.isDeviceProvisioned(this) ? View.VISIBLE : View.INVISIBLE); | |
413 | + } | |
414 | + | |
415 | + @VisibleForTesting | |
410 | 416 | void launchSettingFragment(String initialFragmentName, boolean isSubSettings, Intent intent) { |
411 | 417 | if (!mIsShowingDashboard && initialFragmentName != null) { |
412 | 418 | // UP will be shown only if it is a sub settings |
@@ -164,6 +164,11 @@ public class ChooseLockGeneric extends SettingsActivity { | ||
164 | 164 | @Override |
165 | 165 | public void onCreate(Bundle savedInstanceState) { |
166 | 166 | super.onCreate(savedInstanceState); |
167 | + final Activity activity = getActivity(); | |
168 | + if (!Utils.isDeviceProvisioned(activity) && !canRunBeforeDeviceProvisioned()) { | |
169 | + activity.finish(); | |
170 | + return; | |
171 | + } | |
167 | 172 | |
168 | 173 | String chooseLockAction = getActivity().getIntent().getAction(); |
169 | 174 | mFingerprintManager = Utils.getFingerprintManagerOrNull(getActivity()); |
@@ -248,6 +253,10 @@ public class ChooseLockGeneric extends SettingsActivity { | ||
248 | 253 | addHeaderView(); |
249 | 254 | } |
250 | 255 | |
256 | + protected boolean canRunBeforeDeviceProvisioned() { | |
257 | + return false; | |
258 | + } | |
259 | + | |
251 | 260 | protected void addHeaderView() { |
252 | 261 | if (mForFingerprint) { |
253 | 262 | setHeaderView(R.layout.choose_lock_generic_fingerprint_header); |
@@ -129,6 +129,11 @@ public class SetupChooseLockGeneric extends ChooseLockGeneric { | ||
129 | 129 | return layout.onCreateRecyclerView(inflater, parent, savedInstanceState); |
130 | 130 | } |
131 | 131 | |
132 | + @Override | |
133 | + protected boolean canRunBeforeDeviceProvisioned() { | |
134 | + return true; | |
135 | + } | |
136 | + | |
132 | 137 | /*** |
133 | 138 | * Disables preferences that are less secure than required quality and shows only secure |
134 | 139 | * screen lock options here. |
@@ -35,12 +35,11 @@ import android.content.Context; | ||
35 | 35 | import android.content.Intent; |
36 | 36 | import android.graphics.Bitmap; |
37 | 37 | import android.os.Bundle; |
38 | -import android.view.Menu; | |
38 | +import android.provider.Settings.Global; | |
39 | +import android.view.View; | |
39 | 40 | |
40 | 41 | import com.android.settings.search.SearchActivity; |
41 | -import com.android.settings.testutils.FakeFeatureFactory; | |
42 | 42 | import com.android.settings.testutils.SettingsRobolectricTestRunner; |
43 | - | |
44 | 43 | import org.junit.Before; |
45 | 44 | import org.junit.Test; |
46 | 45 | import org.junit.runner.RunWith; |
@@ -56,23 +55,44 @@ import org.robolectric.util.ReflectionHelpers; | ||
56 | 55 | @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION) |
57 | 56 | public class SettingsActivityTest { |
58 | 57 | |
59 | - @Mock(answer = Answers.RETURNS_DEEP_STUBS) | |
60 | - private Context mContext; | |
61 | - | |
62 | 58 | @Mock |
63 | 59 | private FragmentManager mFragmentManager; |
64 | 60 | @Mock |
65 | 61 | private ActivityManager.TaskDescription mTaskDescription; |
66 | 62 | @Mock |
67 | 63 | private Bitmap mBitmap; |
64 | + @Mock | |
65 | + private View mSearchBar; | |
68 | 66 | private SettingsActivity mActivity; |
67 | + private Context mContext; | |
69 | 68 | |
70 | 69 | @Before |
71 | 70 | public void setUp() { |
72 | 71 | MockitoAnnotations.initMocks(this); |
73 | 72 | |
73 | + mContext = RuntimeEnvironment.application; | |
74 | 74 | mActivity = spy(new SettingsActivity()); |
75 | 75 | doReturn(mBitmap).when(mActivity).getBitmapFromXmlResource(anyInt()); |
76 | + doReturn(mContext.getContentResolver()).when(mActivity).getContentResolver(); | |
77 | + doReturn(mSearchBar).when(mActivity).findViewById(R.id.search_bar); | |
78 | + } | |
79 | + | |
80 | + @Test | |
81 | + public void setSearchBarVisibility_deviceNotProvisioned_shouldDisableSearch() { | |
82 | + Global.putInt(mContext.getContentResolver(), Global.DEVICE_PROVISIONED, 0); | |
83 | + | |
84 | + mActivity.setSearchBarVisibility(); | |
85 | + | |
86 | + verify(mSearchBar).setVisibility(View.INVISIBLE); | |
87 | + } | |
88 | + | |
89 | + @Test | |
90 | + public void setSearchBarVisibility_deviceProvisioned_shouldEnableSearch() { | |
91 | + Global.putInt(mContext.getContentResolver(), Global.DEVICE_PROVISIONED, 1); | |
92 | + | |
93 | + mActivity.setSearchBarVisibility(); | |
94 | + | |
95 | + verify(mSearchBar).setVisibility(View.VISIBLE); | |
76 | 96 | } |
77 | 97 | |
78 | 98 | @Test |
@@ -0,0 +1,97 @@ | ||
1 | +/* | |
2 | + * Copyright (C) 2018 The Android Open Source Project | |
3 | + * | |
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | |
5 | + * you may not use this file except in compliance with the License. | |
6 | + * You may obtain a copy of the License at | |
7 | + * | |
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | |
9 | + * | |
10 | + * Unless required by applicable law or agreed to in writing, software | |
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | |
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
13 | + * See the License for the specific language governing permissions and | |
14 | + * limitations under the License | |
15 | + */ | |
16 | + | |
17 | +package com.android.settings.password; | |
18 | + | |
19 | +import static org.mockito.Mockito.spy; | |
20 | +import static org.mockito.Mockito.verify; | |
21 | +import static org.mockito.Mockito.when; | |
22 | + | |
23 | +import android.app.Activity; | |
24 | +import android.app.FragmentHostCallback; | |
25 | +import android.content.Context; | |
26 | +import android.os.Bundle; | |
27 | +import android.provider.Settings.Global; | |
28 | + | |
29 | +import com.android.settings.TestConfig; | |
30 | +import com.android.settings.password.ChooseLockGeneric.ChooseLockGenericFragment; | |
31 | +import com.android.settings.testutils.SettingsRobolectricTestRunner; | |
32 | +import com.android.settings.testutils.shadow.SettingsShadowResources; | |
33 | + | |
34 | +import org.junit.After; | |
35 | +import org.junit.Before; | |
36 | +import org.junit.Test; | |
37 | +import org.junit.runner.RunWith; | |
38 | +import org.mockito.Mock; | |
39 | +import org.mockito.MockitoAnnotations; | |
40 | +import org.robolectric.RuntimeEnvironment; | |
41 | +import org.robolectric.annotation.Config; | |
42 | +import org.robolectric.util.ReflectionHelpers; | |
43 | + | |
44 | +@RunWith(SettingsRobolectricTestRunner.class) | |
45 | +@Config( | |
46 | + manifest = TestConfig.MANIFEST_PATH, | |
47 | + sdk = TestConfig.SDK_VERSION, | |
48 | + shadows = { | |
49 | + SettingsShadowResources.class, | |
50 | + SettingsShadowResources.SettingsShadowTheme.class | |
51 | + }) | |
52 | +public class ChooseLockGenericTest { | |
53 | + | |
54 | + @Mock | |
55 | + private ChooseLockGeneric mActivity; | |
56 | + | |
57 | + private Context mContext; | |
58 | + | |
59 | + @Before | |
60 | + public void setUp() { | |
61 | + MockitoAnnotations.initMocks(this); | |
62 | + mContext = RuntimeEnvironment.application; | |
63 | + when(mActivity.getContentResolver()).thenReturn(mContext.getContentResolver()); | |
64 | + when(mActivity.getTheme()).thenReturn(mContext.getTheme()); | |
65 | + when(mActivity.getResources()).thenReturn(mContext.getResources()); | |
66 | + } | |
67 | + | |
68 | + @After | |
69 | + public void tearDown() { | |
70 | + Global.putInt(mContext.getContentResolver(), Global.DEVICE_PROVISIONED, 1); | |
71 | + } | |
72 | + | |
73 | + @Test | |
74 | + public void onCreate_deviceNotProvisioned_shouldFinishActivity() { | |
75 | + Global.putInt(mContext.getContentResolver(), Global.DEVICE_PROVISIONED, 0); | |
76 | + final ChooseLockGenericFragment fragment = spy(new ChooseLockGenericFragment()); | |
77 | + when(fragment.getActivity()).thenReturn(mActivity); | |
78 | + ReflectionHelpers.setField(fragment, "mHost", new TestHostCallbacks()); | |
79 | + | |
80 | + fragment.onCreate(Bundle.EMPTY); | |
81 | + | |
82 | + verify(mActivity).finish(); | |
83 | + } | |
84 | + | |
85 | + public class TestHostCallbacks extends FragmentHostCallback<Activity> { | |
86 | + | |
87 | + public TestHostCallbacks() { | |
88 | + super(mActivity, null /* handler */, 0 /* windowAnimations */); | |
89 | + } | |
90 | + | |
91 | + @Override | |
92 | + public Activity onGetHost() { | |
93 | + return mActivity; | |
94 | + } | |
95 | + } | |
96 | + | |
97 | +} |