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.car.settings.system; 18 19 import static android.app.Activity.RESULT_OK; 20 21 import android.content.Intent; 22 import android.os.Bundle; 23 24 import androidx.annotation.VisibleForTesting; 25 import androidx.annotation.XmlRes; 26 27 import com.android.car.settings.R; 28 import com.android.car.settings.common.SettingsFragment; 29 import com.android.car.settings.security.CheckLockActivity; 30 import com.android.car.ui.toolbar.MenuItem; 31 32 import java.util.Collections; 33 import java.util.List; 34 35 /** 36 * Presents the user with information about restoring network settings to the factory default 37 * values. If a user confirms, they will first be required to authenticate then presented with a 38 * secondary confirmation: {@link ResetNetworkConfirmFragment}. 39 */ 40 public class ResetNetworkFragment extends SettingsFragment { 41 42 // Arbitrary request code for starting CheckLockActivity when the reset button is clicked. 43 @VisibleForTesting 44 static final int REQUEST_CODE = 123; 45 46 private MenuItem mResetButton; 47 48 @Override 49 @XmlRes getPreferenceScreenResId()50 protected int getPreferenceScreenResId() { 51 return R.xml.reset_network_fragment; 52 } 53 54 @Override getToolbarMenuItems()55 public List<MenuItem> getToolbarMenuItems() { 56 return Collections.singletonList(mResetButton); 57 } 58 59 @Override onCreate(Bundle savedInstanceState)60 public void onCreate(Bundle savedInstanceState) { 61 super.onCreate(savedInstanceState); 62 63 mResetButton = new MenuItem.Builder(getContext()) 64 .setTitle(R.string.reset_network_button_text) 65 .setOnClickListener(i -> startActivityForResult( 66 new Intent(getContext(), CheckLockActivity.class), REQUEST_CODE)) 67 .build(); 68 } 69 70 @Override onActivityResult(int requestCode, int resultCode, Intent data)71 public void onActivityResult(int requestCode, int resultCode, Intent data) { 72 super.onActivityResult(requestCode, resultCode, data); 73 if (requestCode == REQUEST_CODE && resultCode == RESULT_OK) { 74 launchFragment(new ResetNetworkConfirmFragment()); 75 } 76 } 77 } 78