Merge "Move SetupWizardScreenLockActivity off CarSettingActivity" into pi-car-dev
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 3762cd1..d1c09a7 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -122,6 +122,11 @@
<meta-data android:name="distractionOptimized" android:value="true"/>
</activity>
+ <activity android:name=".security.CheckLockActivity"
+ android:configChanges="orientation|keyboardHidden|screenSize"
+ android:windowSoftInputMode="adjustResize">
+ </activity>
+
<service android:name=".bluetooth.BluetoothPairingService" />
<receiver android:name=".bluetooth.BluetoothPairingRequest">
diff --git a/res/layout/checkbox_list_item.xml b/res/layout/checkbox_list_item.xml
index 0292de8..d29a55b 100644
--- a/res/layout/checkbox_list_item.xml
+++ b/res/layout/checkbox_list_item.xml
@@ -14,7 +14,7 @@
limitations under the License.
-->
-<com.android.car.list.InterceptTouchRelativeLayout
+<com.android.car.settings.common.InterceptTouchRelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
style="@style/LineItem.SingleLine" >
@@ -44,4 +44,4 @@
android:background="@color/car_list_divider"
android:layout_width="match_parent"
android:layout_height="@dimen/car_list_divider_height" />
-</com.android.car.list.InterceptTouchRelativeLayout>
+</com.android.car.settings.common.InterceptTouchRelativeLayout>
diff --git a/res/layout/reset_network_confirm_fragment.xml b/res/layout/reset_network_confirm_fragment.xml
new file mode 100644
index 0000000..a8edac7
--- /dev/null
+++ b/res/layout/reset_network_confirm_fragment.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (C) 2018 Google Inc.
+
+ 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.
+-->
+
+<TextView
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/description"
+ style="@style/TextAppearance.Car.Body1"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginEnd="@dimen/car_margin"
+ android:layout_marginStart="@dimen/car_margin"
+ android:paddingTop="@dimen/car_padding_4"/>
diff --git a/res/layout/reset_network_fragment.xml b/res/layout/reset_network_fragment.xml
new file mode 100644
index 0000000..39602af
--- /dev/null
+++ b/res/layout/reset_network_fragment.xml
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (C) 2018 Google Inc.
+
+ 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.
+-->
+
+<LinearLayout
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:layout_marginEnd="@dimen/car_margin"
+ android:layout_marginStart="@dimen/car_margin"
+ android:orientation="vertical">
+ <TextView
+ android:id="@+id/description"
+ style="@style/TextAppearance.Car.Body1"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:paddingTop="@dimen/car_padding_4"/>
+ <TextView
+ android:id="@+id/items"
+ style="@style/TextAppearance.Car.Body1"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:paddingTop="@dimen/car_padding_4"/>
+</LinearLayout>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index e62fb9b..fea3c44 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -301,12 +301,26 @@
<!-- Reset options --><skip />
<!-- Title for a screen containing all device reset options. [CHAR LIMIT=50] -->
<string name="reset_options_title">Reset options</string>
- <!-- Summary text for a screen containing all device reset options. [CHAR LIMIT=None] -->
+ <!-- Summary text for a screen containing all device reset options. [CHAR LIMIT=NONE] -->
<string name="reset_options_summary">Network, apps, or device reset</string>
<!-- Reset Network --><skip />
- <!-- Button title to reset Wi-Fi settings, bluetooth settings. [CHAR LIMIT=40]-->
+ <!-- Button title to reset Wi-Fi settings, bluetooth settings. [CHAR LIMIT=40] -->
<string name="reset_network_title">Reset Wi-Fi, Bluetooth</string>
+ <!-- Message on screen after user selects reset network settings [CHAR LIMIT=NONE] -->
+ <string name="reset_network_desc">This will reset all network settings, including:</string>
+ <!-- List items on screen after user selects reset network settings [CHAR LIMIT=NONE] -->
+ <string name="reset_network_items"><li>Wi\u2011Fi</li>\n<li>Bluetooth</li></string>
+ <!-- Button on screen after user selects reset network settings [CHAR LIMIT=25] -->
+ <string name="reset_network_button_text">Reset settings</string>
+ <!-- Reset settings confirmation screen title [CHAR LIMIT=30] -->
+ <string name="reset_network_confirm_title">Reset?</string>
+ <!-- Message on screen after user selects Reset settings button [CHAR LIMIT=NONE] -->
+ <string name="reset_network_confirm_desc">Reset all network settings? You can\u2019t undo this action!</string>
+ <!-- Button on screen after user selects Reset settings button [CHAR LIMIT=25] -->
+ <string name="reset_network_confirm_button_text">Reset settings</string>
+ <!-- Reset settings complete toast text [CHAR LIMIT=75] -->
+ <string name="reset_network_complete_toast">Network settings have been reset</string>
<!-- Reset apps --><skip />
<!-- Button title to reset all of user's app preferences. [CHAR LIMIT=40] -->
diff --git a/src/com/android/car/settings/common/BaseFragment.java b/src/com/android/car/settings/common/BaseFragment.java
index 430cc62..ac37a77 100644
--- a/src/com/android/car/settings/common/BaseFragment.java
+++ b/src/com/android/car/settings/common/BaseFragment.java
@@ -11,7 +11,7 @@
* 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
+ * limitations under the License.
*/
package com.android.car.settings.common;
diff --git a/src/com/android/car/settings/common/CheckBoxListItem.java b/src/com/android/car/settings/common/CheckBoxListItem.java
index a3a5e3b..2c33269 100644
--- a/src/com/android/car/settings/common/CheckBoxListItem.java
+++ b/src/com/android/car/settings/common/CheckBoxListItem.java
@@ -56,7 +56,7 @@
@Override
public final int getViewType() {
- return CoustomListItemTypes.CHECK_BOX_VIEW_TYPE;
+ return CustomListItemTypes.CHECK_BOX_VIEW_TYPE;
}
@Override
diff --git a/src/com/android/car/settings/common/CoustomListItemTypes.java b/src/com/android/car/settings/common/CustomListItemTypes.java
similarity index 93%
rename from src/com/android/car/settings/common/CoustomListItemTypes.java
rename to src/com/android/car/settings/common/CustomListItemTypes.java
index 8e634f3..395a10d 100644
--- a/src/com/android/car/settings/common/CoustomListItemTypes.java
+++ b/src/com/android/car/settings/common/CustomListItemTypes.java
@@ -18,7 +18,7 @@
/**
* Keeps ViewType ids for all customer ListItems in a centralized location.
*/
-public final class CoustomListItemTypes {
+public final class CustomListItemTypes {
// According to ListItemAdapter, customized view type needs to be negative.
public static final int CHECK_BOX_VIEW_TYPE = -1;
public static final int EDIT_TEXT_VIEW_TYPE = -2;
@@ -29,6 +29,6 @@
/**
* No one should instantiate this class.
*/
- private CoustomListItemTypes() {
+ private CustomListItemTypes() {
}
}
diff --git a/src/com/android/car/settings/common/EditTextListItem.java b/src/com/android/car/settings/common/EditTextListItem.java
index b6c3dcc..715f9b4 100644
--- a/src/com/android/car/settings/common/EditTextListItem.java
+++ b/src/com/android/car/settings/common/EditTextListItem.java
@@ -134,7 +134,7 @@
@Override
public int getViewType() {
- return CoustomListItemTypes.EDIT_TEXT_VIEW_TYPE;
+ return CustomListItemTypes.EDIT_TEXT_VIEW_TYPE;
}
@Override
diff --git a/src/com/android/car/settings/common/InterceptTouchRelativeLayout.java b/src/com/android/car/settings/common/InterceptTouchRelativeLayout.java
new file mode 100644
index 0000000..4110ac7
--- /dev/null
+++ b/src/com/android/car/settings/common/InterceptTouchRelativeLayout.java
@@ -0,0 +1,55 @@
+/*
+ * Copyright (C) 2018 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.car.settings.common;
+
+import android.content.Context;
+import android.util.AttributeSet;
+import android.view.MotionEvent;
+import android.widget.RelativeLayout;
+
+/**
+ * Intercepts all touch event, so they don't pass onto child views. One use case for this is to
+ * make the line item in a list view clickable and control the logic and update the sub view.
+ */
+public class InterceptTouchRelativeLayout extends RelativeLayout {
+
+ public InterceptTouchRelativeLayout(Context context) {
+ super(context);
+ }
+
+ public InterceptTouchRelativeLayout(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ }
+
+ public InterceptTouchRelativeLayout(Context context, AttributeSet attrs, int defStyleAttr) {
+ super(context, attrs, defStyleAttr);
+ }
+
+ public InterceptTouchRelativeLayout(
+ Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
+ super(context, attrs, defStyleAttr, defStyleRes);
+ }
+
+ /**
+ * Intercepts all touch event.
+ * @return true.
+ */
+ @Override
+ public boolean onInterceptTouchEvent(MotionEvent ev) {
+ return true;
+ }
+}
diff --git a/src/com/android/car/settings/common/ListItemSettingsFragment.java b/src/com/android/car/settings/common/ListItemSettingsFragment.java
index ee87955..cf6c491 100644
--- a/src/com/android/car/settings/common/ListItemSettingsFragment.java
+++ b/src/com/android/car/settings/common/ListItemSettingsFragment.java
@@ -47,15 +47,15 @@
super.onActivityCreated(savedInstanceState);
mListAdapter = new ListItemAdapter(getContext(), getItemProvider());
- mListAdapter.registerListItemViewType(CoustomListItemTypes.CHECK_BOX_VIEW_TYPE,
+ mListAdapter.registerListItemViewType(CustomListItemTypes.CHECK_BOX_VIEW_TYPE,
CheckBoxListItem.getViewLayoutId(), CheckBoxListItem::createViewHolder);
- mListAdapter.registerListItemViewType(CoustomListItemTypes.EDIT_TEXT_VIEW_TYPE,
+ mListAdapter.registerListItemViewType(CustomListItemTypes.EDIT_TEXT_VIEW_TYPE,
EditTextListItem.getViewLayoutId(), EditTextListItem::createViewHolder);
- mListAdapter.registerListItemViewType(CoustomListItemTypes.PASSWORD_VIEW_TYPE,
+ mListAdapter.registerListItemViewType(CustomListItemTypes.PASSWORD_VIEW_TYPE,
PasswordListItem.getViewLayoutId(), PasswordListItem::createViewHolder);
- mListAdapter.registerListItemViewType(CoustomListItemTypes.SPINNER_VIEW_TYPE,
+ mListAdapter.registerListItemViewType(CustomListItemTypes.SPINNER_VIEW_TYPE,
SpinnerListItem.getViewLayoutId(), SpinnerListItem::createViewHolder);
- mListAdapter.registerListItemViewType(CoustomListItemTypes.SUGGESTION_VIEW_TYPE,
+ mListAdapter.registerListItemViewType(CustomListItemTypes.SUGGESTION_VIEW_TYPE,
SuggestionLineItem.getViewLayoutId(), SuggestionLineItem::createViewHolder);
PagedListView listView = getView().findViewById(R.id.list);
diff --git a/src/com/android/car/settings/common/PasswordListItem.java b/src/com/android/car/settings/common/PasswordListItem.java
index 46ffc25..fb27697 100644
--- a/src/com/android/car/settings/common/PasswordListItem.java
+++ b/src/com/android/car/settings/common/PasswordListItem.java
@@ -52,7 +52,7 @@
@Override
public final int getViewType() {
- return CoustomListItemTypes.PASSWORD_VIEW_TYPE;
+ return CustomListItemTypes.PASSWORD_VIEW_TYPE;
}
diff --git a/src/com/android/car/settings/common/SpinnerListItem.java b/src/com/android/car/settings/common/SpinnerListItem.java
index a09d978..662c4ee 100644
--- a/src/com/android/car/settings/common/SpinnerListItem.java
+++ b/src/com/android/car/settings/common/SpinnerListItem.java
@@ -78,7 +78,7 @@
@Override
public final int getViewType() {
- return CoustomListItemTypes.SPINNER_VIEW_TYPE;
+ return CustomListItemTypes.SPINNER_VIEW_TYPE;
}
@Override
diff --git a/src/com/android/car/settings/quicksettings/QuickSettingFragment.java b/src/com/android/car/settings/quicksettings/QuickSettingFragment.java
index 9e177c6..aa5baef 100644
--- a/src/com/android/car/settings/quicksettings/QuickSettingFragment.java
+++ b/src/com/android/car/settings/quicksettings/QuickSettingFragment.java
@@ -81,6 +81,7 @@
mUserSwitcherBtn.setOnClickListener(v -> {
getFragmentController().launchFragment(UserSwitcherFragment.newInstance());
});
+ setupUserButton();
View exitBtn = getActivity().findViewById(R.id.exit_button);
exitBtn.setOnClickListener(v -> getFragmentController().goBack());
@@ -100,7 +101,7 @@
mGridAdapter.stop();
}
- private void setupAccountButton() {
+ private void setupUserButton() {
ImageView userIcon = (ImageView) getActivity().findViewById(R.id.user_icon);
UserInfo currentUserInfo = mCarUserManagerHelper.getCurrentForegroundUserInfo();
userIcon.setImageDrawable(mUserIconProvider.getUserIcon(currentUserInfo, getContext()));
diff --git a/src/com/android/car/settings/security/CheckLockActivity.java b/src/com/android/car/settings/security/CheckLockActivity.java
new file mode 100644
index 0000000..6f14910
--- /dev/null
+++ b/src/com/android/car/settings/security/CheckLockActivity.java
@@ -0,0 +1,92 @@
+/*
+ * Copyright (C) 2018 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.car.settings.security;
+
+import android.app.admin.DevicePolicyManager;
+import android.os.Bundle;
+import android.os.UserHandle;
+
+import com.android.car.settings.R;
+import com.android.car.settings.common.BaseFragment;
+import com.android.car.settings.common.CarSettingActivity;
+import com.android.car.settings.common.Logger;
+import com.android.internal.widget.LockPatternUtils;
+
+/**
+ * Prompts the user to enter their pin, password, or pattern lock (if set) and returns
+ * {@link #RESULT_OK} on a successful entry or immediately if the user has no lock setup.
+ */
+public class CheckLockActivity extends CarSettingActivity implements CheckLockListener {
+
+ private static final Logger LOG = new Logger(CheckLockActivity.class);
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ if (savedInstanceState != null) {
+ return;
+ }
+ BaseFragment fragment;
+ int passwordQuality = new LockPatternUtils(this).getKeyguardStoredPasswordQuality(
+ UserHandle.myUserId());
+ switch (passwordQuality) {
+ case DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED:
+ // User has not set a password.
+ setResult(RESULT_OK);
+ finish();
+ return;
+ case DevicePolicyManager.PASSWORD_QUALITY_SOMETHING:
+ fragment = ConfirmLockPatternFragment.newInstance(
+ /* isInSetupWizard= */ false);
+ break;
+ case DevicePolicyManager.PASSWORD_QUALITY_NUMERIC:
+ case DevicePolicyManager.PASSWORD_QUALITY_NUMERIC_COMPLEX:
+ fragment = ConfirmLockPinPasswordFragment.newPinInstance(
+ /* isInSetupWizard= */ false);
+ break;
+ case DevicePolicyManager.PASSWORD_QUALITY_ALPHABETIC:
+ case DevicePolicyManager.PASSWORD_QUALITY_ALPHANUMERIC:
+ fragment = ConfirmLockPinPasswordFragment.newPasswordInstance(
+ /* isInSetupWizard= */ false);
+ break;
+ default:
+ LOG.e("Unexpected password quality: " + String.valueOf(passwordQuality));
+ fragment = ConfirmLockPinPasswordFragment.newPasswordInstance(
+ /* isInSetupWizard= */ false);
+ }
+
+ Bundle bundle = fragment.getArguments();
+ if (bundle == null) {
+ bundle = new Bundle();
+ }
+ bundle.putInt(ChooseLockTypeFragment.EXTRA_CURRENT_PASSWORD_QUALITY, passwordQuality);
+ fragment.setArguments(bundle);
+
+ getSupportFragmentManager()
+ .beginTransaction()
+ .add(R.id.fragment_container, fragment)
+ .addToBackStack(null)
+ .commit();
+ }
+
+ @Override
+ public void onLockVerified(String lock) {
+ setResult(RESULT_OK);
+ finish();
+ }
+}
diff --git a/src/com/android/car/settings/suggestions/SuggestionLineItem.java b/src/com/android/car/settings/suggestions/SuggestionLineItem.java
index ad5426b..bf1600a 100644
--- a/src/com/android/car/settings/suggestions/SuggestionLineItem.java
+++ b/src/com/android/car/settings/suggestions/SuggestionLineItem.java
@@ -28,7 +28,7 @@
import androidx.car.widget.ListItem;
import com.android.car.settings.R;
-import com.android.car.settings.common.CoustomListItemTypes;
+import com.android.car.settings.common.CustomListItemTypes;
/**
* Represents suggestion list item.
@@ -106,7 +106,7 @@
@Override
public final int getViewType() {
- return CoustomListItemTypes.SUGGESTION_VIEW_TYPE;
+ return CustomListItemTypes.SUGGESTION_VIEW_TYPE;
}
/**
diff --git a/src/com/android/car/settings/system/ResetNetworkConfirmFragment.java b/src/com/android/car/settings/system/ResetNetworkConfirmFragment.java
new file mode 100644
index 0000000..57f3817
--- /dev/null
+++ b/src/com/android/car/settings/system/ResetNetworkConfirmFragment.java
@@ -0,0 +1,110 @@
+/*
+ * Copyright (C) 2018 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.car.settings.system;
+
+import static java.util.Objects.requireNonNull;
+
+import android.app.ActivityManager;
+import android.bluetooth.BluetoothAdapter;
+import android.bluetooth.BluetoothManager;
+import android.content.Context;
+import android.net.ConnectivityManager;
+import android.net.wifi.WifiManager;
+import android.os.Bundle;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.Button;
+import android.widget.TextView;
+import android.widget.Toast;
+
+import com.android.car.settings.R;
+import com.android.car.settings.common.BaseFragment;
+
+/**
+ * Final warning presented to user to confirm restoring network settings to the factory default.
+ * If a user confirms, all settings are reset for connectivity, Wi-Fi, and Bluetooth.
+ */
+public class ResetNetworkConfirmFragment extends BaseFragment {
+
+ /**
+ * Creates new instance of {@link ResetNetworkConfirmFragment}.
+ */
+ public static ResetNetworkConfirmFragment newInstance() {
+ ResetNetworkConfirmFragment fragment = new ResetNetworkConfirmFragment();
+ Bundle bundle = BaseFragment.getBundle();
+ bundle.putInt(EXTRA_LAYOUT, R.layout.reset_network_confirm_fragment);
+ bundle.putInt(EXTRA_TITLE_ID, R.string.reset_network_confirm_title);
+ bundle.putInt(EXTRA_ACTION_BAR_LAYOUT, R.layout.action_bar_with_button);
+ fragment.setArguments(bundle);
+ return fragment;
+ }
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container,
+ Bundle savedInstanceState) {
+ View rootView = super.onCreateView(inflater, container, savedInstanceState);
+
+ TextView description = requireNonNull(rootView.findViewById(R.id.description));
+ description.setText(getContext().getString(R.string.reset_network_confirm_desc));
+
+ return rootView;
+ }
+
+ @Override
+ public void onActivityCreated(Bundle savedInstanceState) {
+ super.onActivityCreated(savedInstanceState);
+
+ Button resetSettingsButton = requireNonNull(getActivity()).findViewById(
+ R.id.action_button1);
+ resetSettingsButton.setText(
+ getContext().getString(R.string.reset_network_confirm_button_text));
+ resetSettingsButton.setOnClickListener(v -> resetNetwork());
+ }
+
+ private void resetNetwork() {
+ if (ActivityManager.isUserAMonkey()) {
+ return;
+ }
+
+ Context context = requireNonNull(getActivity()).getApplicationContext();
+
+ ConnectivityManager connectivityManager = (ConnectivityManager)
+ context.getSystemService(Context.CONNECTIVITY_SERVICE);
+ if (connectivityManager != null) {
+ connectivityManager.factoryReset();
+ }
+
+ WifiManager wifiManager = (WifiManager)
+ context.getSystemService(Context.WIFI_SERVICE);
+ if (wifiManager != null) {
+ wifiManager.factoryReset();
+ }
+
+ BluetoothManager btManager = (BluetoothManager)
+ context.getSystemService(Context.BLUETOOTH_SERVICE);
+ if (btManager != null) {
+ BluetoothAdapter btAdapter = btManager.getAdapter();
+ if (btAdapter != null) {
+ btAdapter.factoryReset();
+ }
+ }
+
+ Toast.makeText(requireContext(), R.string.reset_network_complete_toast,
+ Toast.LENGTH_SHORT).show();
+ }
+}
diff --git a/src/com/android/car/settings/system/ResetNetworkFragment.java b/src/com/android/car/settings/system/ResetNetworkFragment.java
new file mode 100644
index 0000000..f5e574d
--- /dev/null
+++ b/src/com/android/car/settings/system/ResetNetworkFragment.java
@@ -0,0 +1,88 @@
+/*
+ * Copyright (C) 2018 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.car.settings.system;
+
+import static android.app.Activity.RESULT_OK;
+
+import static java.util.Objects.requireNonNull;
+
+import android.content.Intent;
+import android.os.Bundle;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.Button;
+import android.widget.TextView;
+
+import com.android.car.settings.R;
+import com.android.car.settings.common.BaseFragment;
+import com.android.car.settings.security.CheckLockActivity;
+
+/**
+ * Presents the user with information about restoring network settings to the factory default
+ * values. If a user confirms, they will first be required to authenticate then presented with a
+ * secondary confirmation: {@link ResetNetworkConfirmFragment}.
+ */
+public class ResetNetworkFragment extends BaseFragment {
+
+ private static final int REQUEST_CODE = 123;
+
+ /**
+ * Creates new instance of {@link ResetNetworkFragment}.
+ */
+ public static ResetNetworkFragment newInstance() {
+ ResetNetworkFragment fragment = new ResetNetworkFragment();
+ Bundle bundle = BaseFragment.getBundle();
+ bundle.putInt(EXTRA_LAYOUT, R.layout.reset_network_fragment);
+ bundle.putInt(EXTRA_TITLE_ID, R.string.reset_network_title);
+ bundle.putInt(EXTRA_ACTION_BAR_LAYOUT, R.layout.action_bar_with_button);
+ fragment.setArguments(bundle);
+ return fragment;
+ }
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container,
+ Bundle savedInstanceState) {
+ View rootView = super.onCreateView(inflater, container, savedInstanceState);
+
+ TextView description = requireNonNull(rootView.findViewById(R.id.description));
+ description.setText(getContext().getString(R.string.reset_network_desc));
+ TextView items = requireNonNull(rootView.findViewById(R.id.items));
+ items.setText(getContext().getString(R.string.reset_network_items));
+
+ return rootView;
+ }
+
+ @Override
+ public void onActivityCreated(Bundle savedInstanceState) {
+ super.onActivityCreated(savedInstanceState);
+
+ Button resetSettingsButton = requireNonNull(getActivity()).findViewById(
+ R.id.action_button1);
+ resetSettingsButton.setText(getContext().getString(R.string.reset_network_button_text));
+ resetSettingsButton.setOnClickListener(v -> startActivityForResult(new Intent(
+ getContext(), CheckLockActivity.class), REQUEST_CODE));
+ }
+
+ @Override
+ public void onActivityResult(int requestCode, int resultCode, Intent data) {
+ super.onActivityResult(requestCode, resultCode, data);
+ if (requestCode == REQUEST_CODE && resultCode == RESULT_OK) {
+ getFragmentController().launchFragment(ResetNetworkConfirmFragment.newInstance());
+ }
+ }
+}
diff --git a/src/com/android/car/settings/system/ResetOptionsFragment.java b/src/com/android/car/settings/system/ResetOptionsFragment.java
index c2df6de..17e1199 100644
--- a/src/com/android/car/settings/system/ResetOptionsFragment.java
+++ b/src/com/android/car/settings/system/ResetOptionsFragment.java
@@ -16,8 +16,10 @@
package com.android.car.settings.system;
+import android.car.user.CarUserManagerHelper;
import android.content.Context;
import android.os.Bundle;
+import android.os.UserManager;
import android.view.View;
import androidx.annotation.StringRes;
@@ -35,6 +37,7 @@
*/
public class ResetOptionsFragment extends ListItemSettingsFragment {
+ private CarUserManagerHelper mCarUserManagerHelper;
private ListItemProvider mItemProvider;
/**
@@ -52,6 +55,7 @@
@Override
public void onAttach(Context context) {
super.onAttach(context);
+ mCarUserManagerHelper = new CarUserManagerHelper(context);
mItemProvider = new ListItemProvider.ListProvider(getListItems());
}
@@ -61,17 +65,25 @@
}
private ArrayList<ListItem> getListItems() {
+ boolean isAdmin = mCarUserManagerHelper.isCurrentProcessAdminUser();
+
ArrayList<ListItem> lineItems = new ArrayList<>();
- lineItems.add(createListItem(R.string.reset_network_title, v -> {
- // TODO: launch reset network.
- }));
+ if (isAdmin && !mCarUserManagerHelper.isCurrentProcessUserHasRestriction(
+ UserManager.DISALLOW_NETWORK_RESET)) {
+ lineItems.add(createListItem(R.string.reset_network_title, v ->
+ getFragmentController().launchFragment(ResetNetworkFragment.newInstance())
+ ));
+ }
lineItems.add(createListItem(R.string.reset_app_preferences_title, v -> {
// TODO: launch reset app preferences.
}));
- lineItems.add(createListItem(R.string.master_clear_title, v -> {
- // TODO: launch master clear.
- }));
+ if (isAdmin && !mCarUserManagerHelper.isCurrentProcessUserHasRestriction(
+ UserManager.DISALLOW_FACTORY_RESET)) {
+ lineItems.add(createListItem(R.string.master_clear_title, v -> {
+ // TODO: launch master clear.
+ }));
+ }
return lineItems;
}