Merge "Add a dialog when turning off oem unlock dialog."
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 237d05c..6acd127 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -8780,7 +8780,8 @@
<string name="oem_unlock_enable_disabled_summary_connectivity_or_locked">Connect to the Internet or contact your carrier</string>
<!-- setting enable OEM unlock Checkbox's summary to explain this Checkbox is disabled because this setting is unavailable on sim-locked devices. [CHAR_LIMIT=60] -->
<string name="oem_unlock_enable_disabled_summary_sim_locked_device">Unavailable on carrier-locked devices</string>
-
+ <!-- Information displayed after user locks OEM lock [Char Limit=None]-->
+ <string name="oem_lock_info_message">Please restart the device to enable device protection feature.</string>
<string name="automatic_storage_manager_freed_bytes"><xliff:g id="size" example="3.25MB">%1$s</xliff:g> total made available\n\nLast ran on <xliff:g id="date" example="Jan 12">%2$s</xliff:g></string>
<!-- Title text for enabling web actions. [CHAR_LIMIT=60] -->
diff --git a/src/com/android/settings/development/OemLockInfoDialog.java b/src/com/android/settings/development/OemLockInfoDialog.java
new file mode 100644
index 0000000..6d75812
--- /dev/null
+++ b/src/com/android/settings/development/OemLockInfoDialog.java
@@ -0,0 +1,53 @@
+/*
+ * Copyright (C) 2017 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.development;
+
+import android.app.AlertDialog;
+import android.app.Dialog;
+import android.app.Fragment;
+import android.app.FragmentManager;
+import android.os.Bundle;
+
+import com.android.internal.logging.nano.MetricsProto;
+import com.android.settings.R;
+import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
+
+public class OemLockInfoDialog extends InstrumentedDialogFragment {
+
+ private static final String TAG = "OemLockInfoDialog";
+
+ public static void show(Fragment host) {
+ final FragmentManager manager = host.getChildFragmentManager();
+ if (manager.findFragmentByTag(TAG) == null) {
+ final OemLockInfoDialog dialog = new OemLockInfoDialog();
+ dialog.show(manager, TAG);
+ }
+ }
+
+ @Override
+ public int getMetricsCategory() {
+ return MetricsProto.MetricsEvent.DIALOG_OEM_LOCK_INFO;
+ }
+
+ @Override
+ public Dialog onCreateDialog(Bundle savedInstanceState) {
+ final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity())
+ .setMessage(R.string.oem_lock_info_message);
+
+ return builder.create();
+ }
+}
diff --git a/src/com/android/settings/development/OemUnlockPreferenceController.java b/src/com/android/settings/development/OemUnlockPreferenceController.java
index 91994c2..f486b3d 100644
--- a/src/com/android/settings/development/OemUnlockPreferenceController.java
+++ b/src/com/android/settings/development/OemUnlockPreferenceController.java
@@ -90,6 +90,7 @@
}
} else {
mOemLockManager.setOemUnlockAllowedByUser(false);
+ OemLockInfoDialog.show(mFragment);
}
return true;
}
diff --git a/tests/robotests/src/com/android/settings/development/OemUnlockPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/development/OemUnlockPreferenceControllerTest.java
index 1367870..f59c29f 100644
--- a/tests/robotests/src/com/android/settings/development/OemUnlockPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/development/OemUnlockPreferenceControllerTest.java
@@ -18,18 +18,17 @@
import static com.android.settings.development.DevelopmentOptionsActivityRequestCodes
.REQUEST_CODE_ENABLE_OEM_UNLOCK;
-
import static com.google.common.truth.Truth.assertThat;
-
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn;
+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.app.FragmentManager;
import android.content.Context;
-import android.content.DialogInterface;
import android.content.res.Resources;
import android.os.UserManager;
import android.service.oemlock.OemLockManager;
@@ -43,6 +42,7 @@
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
+import org.mockito.Answers;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.annotation.Config;
@@ -81,6 +81,8 @@
mController = new OemUnlockPreferenceController(mContext, mActivity, mFragment);
when(mPreferenceScreen.findPreference(mController.getPreferenceKey())).thenReturn(
mPreference);
+ when(mFragment.getChildFragmentManager()).thenReturn(
+ mock(FragmentManager.class, Answers.RETURNS_DEEP_STUBS));
mController.displayPreference(mPreferenceScreen);
}
@@ -114,8 +116,8 @@
@Test
public void onPreferenceChanged_turnOffUnlock() {
mController.onPreferenceChange(null, false);
-
verify(mOemLockManager).setOemUnlockAllowedByUser(false);
+ verify(mFragment).getChildFragmentManager();
}
@Test