Browse Source

Merge tag 'android-9.0.0_r10' into lineage-16.0-android-9.0.0_r10

Android 9.0.0 release 10

* tag 'android-9.0.0_r10':
  Disable changing lock when device is not provisioned.

Change-Id: Ifb9097f14d59e9de98e0a8807f8827dbf44f5c67
Luca Stefani 8 months ago
parent
commit
6241dfc876

+ 3
- 2
src/com/android/settings/SettingsActivity.java View File

@@ -293,8 +293,10 @@ public class SettingsActivity extends SettingsDrawerActivity
293 293
             launchSettingFragment(initialFragmentName, isSubSettings, intent);
294 294
         }
295 295
 
296
+        final boolean deviceProvisioned = Utils.isDeviceProvisioned(this);
296 297
         if (mIsShowingDashboard) {
297
-            findViewById(R.id.search_bar).setVisibility(View.VISIBLE);
298
+            findViewById(R.id.search_bar).setVisibility(
299
+                    deviceProvisioned ? View.VISIBLE : View.INVISIBLE);
298 300
             findViewById(R.id.action_bar).setVisibility(View.GONE);
299 301
             final Toolbar toolbar = findViewById(R.id.search_action_bar);
300 302
             FeatureFactory.getFactory(this).getSearchFeatureProvider()
@@ -313,7 +315,6 @@ public class SettingsActivity extends SettingsDrawerActivity
313 315
 
314 316
         ActionBar actionBar = getActionBar();
315 317
         if (actionBar != null) {
316
-            boolean deviceProvisioned = Utils.isDeviceProvisioned(this);
317 318
             actionBar.setDisplayHomeAsUpEnabled(deviceProvisioned);
318 319
             actionBar.setHomeButtonEnabled(deviceProvisioned);
319 320
             actionBar.setDisplayShowTitleEnabled(!mIsShowingDashboard);

+ 9
- 0
src/com/android/settings/password/ChooseLockGeneric.java View File

@@ -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());
@@ -249,6 +254,10 @@ public class ChooseLockGeneric extends SettingsActivity {
249 254
             addHeaderView();
250 255
         }
251 256
 
257
+        protected boolean canRunBeforeDeviceProvisioned() {
258
+            return false;
259
+        }
260
+
252 261
         protected void addHeaderView() {
253 262
             if (mForFingerprint) {
254 263
                 setHeaderView(R.layout.choose_lock_generic_fingerprint_header);

+ 5
- 0
src/com/android/settings/password/SetupChooseLockGeneric.java View File

@@ -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.

+ 4
- 0
src/com/android/settings/search/actionbar/SearchMenuController.java View File

@@ -25,6 +25,7 @@ import android.view.MenuInflater;
25 25
 import android.view.MenuItem;
26 26
 
27 27
 import com.android.settings.R;
28
+import com.android.settings.Utils;
28 29
 import com.android.settings.overlay.FeatureFactory;
29 30
 import com.android.settings.search.SearchFeatureProvider;
30 31
 import com.android.settingslib.core.lifecycle.LifecycleObserver;
@@ -52,6 +53,9 @@ public class SearchMenuController implements LifecycleObserver, OnCreateOptionsM
52 53
 
53 54
     @Override
54 55
     public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
56
+        if (!Utils.isDeviceProvisioned(mHost.getContext())) {
57
+            return;
58
+        }
55 59
         if (menu == null) {
56 60
             return;
57 61
         }

+ 40
- 0
tests/robotests/src/com/android/settings/SettingsActivityTest.java View File

@@ -16,6 +16,7 @@
16 16
 
17 17
 package com.android.settings;
18 18
 
19
+import static com.google.common.truth.Truth.assertThat;
19 20
 import static org.mockito.ArgumentMatchers.nullable;
20 21
 import static org.mockito.Matchers.anyInt;
21 22
 import static org.mockito.Mockito.doReturn;
@@ -27,17 +28,25 @@ import static org.mockito.Mockito.when;
27 28
 import android.app.ActivityManager;
28 29
 import android.app.FragmentManager;
29 30
 import android.app.FragmentTransaction;
31
+import android.content.Context;
30 32
 import android.content.Intent;
31 33
 import android.graphics.Bitmap;
34
+import android.os.Bundle;
35
+import android.provider.Settings.Global;
36
+import android.view.View;
32 37
 
33 38
 import com.android.settings.testutils.SettingsRobolectricTestRunner;
39
+import com.android.settings.testutils.shadow.SettingsShadowResources;
40
+import com.android.settings.testutils.shadow.SettingsShadowResourcesImpl;
34 41
 
35 42
 import org.junit.Before;
36 43
 import org.junit.Test;
37 44
 import org.junit.runner.RunWith;
38 45
 import org.mockito.Mock;
39 46
 import org.mockito.MockitoAnnotations;
47
+import org.robolectric.Robolectric;
40 48
 import org.robolectric.RuntimeEnvironment;
49
+import org.robolectric.annotation.Config;
41 50
 
42 51
 @RunWith(SettingsRobolectricTestRunner.class)
43 52
 public class SettingsActivityTest {
@@ -49,15 +58,46 @@ public class SettingsActivityTest {
49 58
     @Mock
50 59
     private Bitmap mBitmap;
51 60
     private SettingsActivity mActivity;
61
+    private Context mContext;
52 62
 
53 63
     @Before
54 64
     public void setUp() {
55 65
         MockitoAnnotations.initMocks(this);
56 66
 
67
+        mContext = RuntimeEnvironment.application;
57 68
         mActivity = spy(new SettingsActivity());
58 69
         doReturn(mBitmap).when(mActivity).getBitmapFromXmlResource(anyInt());
59 70
     }
60 71
 
72
+    @Test
73
+    @Config(shadows = {
74
+        SettingsShadowResourcesImpl.class,
75
+        SettingsShadowResources.SettingsShadowTheme.class,
76
+    })
77
+    public void onCreate_deviceNotProvisioned_shouldDisableSearch() {
78
+        Global.putInt(mContext.getContentResolver(), Global.DEVICE_PROVISIONED, 0);
79
+        final Intent intent = new Intent(mContext, Settings.class);
80
+        final SettingsActivity activity =
81
+            Robolectric.buildActivity(SettingsActivity.class, intent).create(Bundle.EMPTY).get();
82
+
83
+        assertThat(activity.findViewById(R.id.search_bar).getVisibility())
84
+            .isEqualTo(View.INVISIBLE);
85
+    }
86
+
87
+    @Test
88
+    @Config(shadows = {
89
+        SettingsShadowResourcesImpl.class,
90
+        SettingsShadowResources.SettingsShadowTheme.class,
91
+    })
92
+    public void onCreate_deviceProvisioned_shouldEnableSearch() {
93
+        Global.putInt(mContext.getContentResolver(), Global.DEVICE_PROVISIONED, 1);
94
+        final Intent intent = new Intent(mContext, Settings.class);
95
+        final SettingsActivity activity =
96
+            Robolectric.buildActivity(SettingsActivity.class, intent).create(Bundle.EMPTY).get();
97
+
98
+        assertThat(activity.findViewById(R.id.search_bar).getVisibility()).isEqualTo(View.VISIBLE);
99
+    }
100
+
61 101
     @Test
62 102
     public void launchSettingFragment_nullExtraShowFragment_shouldNotCrash() {
63 103
         when(mActivity.getFragmentManager()).thenReturn(mFragmentManager);

+ 65
- 0
tests/robotests/src/com/android/settings/password/ChooseLockGenericTest.java View File

@@ -0,0 +1,65 @@
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.mock;
20
+import static org.mockito.Mockito.spy;
21
+import static org.mockito.Mockito.verify;
22
+import static org.mockito.Mockito.when;
23
+
24
+import android.app.Activity;
25
+import android.content.Context;
26
+import android.os.Bundle;
27
+import android.provider.Settings.Global;
28
+
29
+import com.android.settings.password.ChooseLockGeneric.ChooseLockGenericFragment;
30
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
31
+import com.android.settings.testutils.shadow.SettingsShadowResources;
32
+
33
+import org.junit.After;
34
+import org.junit.Test;
35
+import org.junit.runner.RunWith;
36
+import org.robolectric.RuntimeEnvironment;
37
+import org.robolectric.annotation.Config;
38
+
39
+@RunWith(SettingsRobolectricTestRunner.class)
40
+public class ChooseLockGenericTest {
41
+
42
+    @After
43
+    public void tearDown() {
44
+        Global.putInt(RuntimeEnvironment.application.getContentResolver(),
45
+            Global.DEVICE_PROVISIONED, 1);
46
+    }
47
+
48
+    @Test
49
+    @Config(shadows = SettingsShadowResources.SettingsShadowTheme.class)
50
+    public void onCreate_deviceNotProvisioned_shouldFinishActivity() {
51
+        final Context context = RuntimeEnvironment.application;
52
+        Global.putInt(context.getContentResolver(), Global.DEVICE_PROVISIONED, 0);
53
+        final Activity activity = mock(Activity.class);
54
+        when(activity.getContentResolver()).thenReturn(context.getContentResolver());
55
+        when(activity.getTheme()).thenReturn(context.getTheme());
56
+
57
+        final ChooseLockGenericFragment fragment = spy(new ChooseLockGenericFragment());
58
+        when(fragment.getActivity()).thenReturn(activity);
59
+        when(fragment.getArguments()).thenReturn(Bundle.EMPTY);
60
+
61
+        fragment.onCreate(Bundle.EMPTY);
62
+        verify(activity).finish();
63
+    }
64
+
65
+}

+ 23
- 1
tests/robotests/src/com/android/settings/search/actionbar/SearchMenuControllerTest.java View File

@@ -17,11 +17,14 @@
17 17
 package com.android.settings.search.actionbar;
18 18
 
19 19
 import static org.mockito.Mockito.mock;
20
+import static org.mockito.Mockito.spy;
20 21
 import static org.mockito.Mockito.verify;
21 22
 import static org.mockito.Mockito.verifyZeroInteractions;
22 23
 import static org.mockito.Mockito.when;
23 24
 
25
+import android.content.Context;
24 26
 import android.os.Bundle;
27
+import android.provider.Settings.Global;
25 28
 import android.view.Menu;
26 29
 import android.view.MenuItem;
27 30
 
@@ -35,6 +38,7 @@ import org.junit.Test;
35 38
 import org.junit.runner.RunWith;
36 39
 import org.mockito.Mock;
37 40
 import org.mockito.MockitoAnnotations;
41
+import org.robolectric.RuntimeEnvironment;
38 42
 
39 43
 @RunWith(SettingsRobolectricTestRunner.class)
40 44
 public class SearchMenuControllerTest {
@@ -43,12 +47,16 @@ public class SearchMenuControllerTest {
43 47
     private Menu mMenu;
44 48
     private TestPreferenceFragment mPreferenceHost;
45 49
     private ObservableFragment mHost;
50
+    private Context mContext;
46 51
 
47 52
     @Before
48 53
     public void setUp() {
49 54
         MockitoAnnotations.initMocks(this);
50
-        mHost = new ObservableFragment();
55
+        mContext = RuntimeEnvironment.application;
56
+        mHost = spy(new ObservableFragment());
57
+        when(mHost.getContext()).thenReturn(mContext);
51 58
         mPreferenceHost = new TestPreferenceFragment();
59
+        Global.putInt(mContext.getContentResolver(), Global.DEVICE_PROVISIONED, 1);
52 60
 
53 61
         when(mMenu.add(Menu.NONE, Menu.NONE, 0 /* order */, R.string.search_menu))
54 62
                 .thenReturn(mock(MenuItem.class));
@@ -81,9 +89,23 @@ public class SearchMenuControllerTest {
81 89
         verifyZeroInteractions(mMenu);
82 90
     }
83 91
 
92
+    @Test
93
+    public void init_deviceNotProvisioned_shouldNotAddMenu() {
94
+        Global.putInt(mContext.getContentResolver(), Global.DEVICE_PROVISIONED, 0);
95
+        SearchMenuController.init(mHost);
96
+        mHost.getLifecycle().onCreateOptionsMenu(mMenu, null /* inflater */);
97
+
98
+        verifyZeroInteractions(mMenu);
99
+    }
100
+
84 101
     private static class TestPreferenceFragment extends ObservablePreferenceFragment {
85 102
         @Override
86 103
         public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
87 104
         }
105
+
106
+        @Override
107
+        public Context getContext() {
108
+            return RuntimeEnvironment.application;
109
+        }
88 110
     }
89 111
 }