Merge "Add a dialog when turning off oem unlock dialog."

This commit is contained in:
TreeHugger Robot
2017-10-31 17:11:30 +00:00
committed by Android (Google) Code Review
4 changed files with 62 additions and 5 deletions

View File

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

View File

@@ -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();
}
}

View File

@@ -90,6 +90,7 @@ public class OemUnlockPreferenceController extends DeveloperOptionsPreferenceCon
}
} else {
mOemLockManager.setOemUnlockAllowedByUser(false);
OemLockInfoDialog.show(mFragment);
}
return true;
}

View File

@@ -18,18 +18,17 @@ package com.android.settings.development;
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 com.android.settingslib.RestrictedSwitchPreference;
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 @@ public class OemUnlockPreferenceControllerTest {
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 @@ public class OemUnlockPreferenceControllerTest {
@Test
public void onPreferenceChanged_turnOffUnlock() {
mController.onPreferenceChange(null, false);
verify(mOemLockManager).setOemUnlockAllowedByUser(false);
verify(mFragment).getChildFragmentManager();
}
@Test