Merge "Create a separate activity for Data warning/limit settings" into pi-car-dev
am: 0a94e6edbe
Change-Id: I35013811ccf40ceb70ca7b3a56c865b0bb176e2d
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 35b0de3..79061ea 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -337,6 +337,13 @@
<meta-data android:name="distractionOptimized" android:value="true"/>
</activity>
+ <activity android:name=".datausage.DataWarningAndLimitActivity"
+ android:configChanges="orientation|keyboardHidden|screenSize"
+ android:windowSoftInputMode="adjustResize"
+ android:exported="true">
+ <meta-data android:name="distractionOptimized" android:value="true"/>
+ </activity>
+
<!-- This logic is copied from phone.-->
<!-- Ensures there's lightweight fallback activity when no other MAIN/HOME activity is present.-->
<activity android:name=".FallbackHome"
diff --git a/res/xml/data_usage_fragment.xml b/res/xml/data_usage_fragment.xml
index fcb5590..6ca27c0 100644
--- a/res/xml/data_usage_fragment.xml
+++ b/res/xml/data_usage_fragment.xml
@@ -28,8 +28,10 @@
android:title="@string/app_data_usage"
settings:controller="com.android.car.settings.datausage.DataUsagePreferenceController"/>
<Preference
- android:fragment="com.android.car.settings.datausage.DataWarningAndLimitFragment"
android:key="@string/pk_data_warning_and_limit"
android:title="@string/data_warning_limit_title"
- settings:controller="com.android.car.settings.common.DefaultRestrictionsPreferenceController"/>
+ settings:controller="com.android.car.settings.common.DefaultRestrictionsPreferenceController">
+ <intent android:targetPackage="com.android.car.settings"
+ android:targetClass="com.android.car.settings.datausage.DataWarningAndLimitActivity"/>
+ </Preference>
</PreferenceScreen>
diff --git a/src/com/android/car/settings/datausage/DataWarningAndLimitActivity.java b/src/com/android/car/settings/datausage/DataWarningAndLimitActivity.java
new file mode 100644
index 0000000..5f0aef2
--- /dev/null
+++ b/src/com/android/car/settings/datausage/DataWarningAndLimitActivity.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2019 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.datausage;
+
+import android.net.NetworkPolicyManager;
+import android.net.NetworkTemplate;
+
+import androidx.annotation.Nullable;
+import androidx.fragment.app.Fragment;
+
+import com.android.car.settings.common.BaseCarSettingsActivity;
+
+/** Separate activity to enter the data warning and limit settings via activity name. */
+public class DataWarningAndLimitActivity extends BaseCarSettingsActivity {
+
+ @Nullable
+ @Override
+ protected Fragment getInitialFragment() {
+ NetworkTemplate template = getIntent().getParcelableExtra(
+ NetworkPolicyManager.EXTRA_NETWORK_TEMPLATE);
+ return DataWarningAndLimitFragment.newInstance(template);
+ }
+}
diff --git a/src/com/android/car/settings/datausage/DataWarningAndLimitFragment.java b/src/com/android/car/settings/datausage/DataWarningAndLimitFragment.java
index 8aa3fc2..c8b172a 100644
--- a/src/com/android/car/settings/datausage/DataWarningAndLimitFragment.java
+++ b/src/com/android/car/settings/datausage/DataWarningAndLimitFragment.java
@@ -19,9 +19,11 @@
import android.content.Context;
import android.net.NetworkPolicyManager;
import android.net.NetworkTemplate;
+import android.os.Bundle;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
+import androidx.annotation.Nullable;
import androidx.annotation.XmlRes;
import com.android.car.settings.R;
@@ -39,6 +41,18 @@
private NetworkPolicyEditor mPolicyEditor;
private NetworkTemplate mNetworkTemplate;
+ /**
+ * Creates a new instance of {@link DataWarningAndLimitFragment} with the given template. If the
+ * template is {@code null}, the fragment will use the default data network template.
+ */
+ public static DataWarningAndLimitFragment newInstance(@Nullable NetworkTemplate template) {
+ DataWarningAndLimitFragment fragment = new DataWarningAndLimitFragment();
+ Bundle args = new Bundle();
+ args.putParcelable(NetworkPolicyManager.EXTRA_NETWORK_TEMPLATE, template);
+ fragment.setArguments(args);
+ return fragment;
+ }
+
@Override
@XmlRes
protected int getPreferenceScreenResId() {
@@ -50,10 +64,14 @@
super.onAttach(context);
mPolicyEditor = new NetworkPolicyEditor(NetworkPolicyManager.from(context));
- mTelephonyManager = context.getSystemService(TelephonyManager.class);
- mSubscriptionManager = context.getSystemService(SubscriptionManager.class);
- mNetworkTemplate = DataUsageUtils.getMobileNetworkTemplate(mTelephonyManager,
- DataUsageUtils.getDefaultSubscriptionId(mSubscriptionManager));
+ mNetworkTemplate = getArguments().getParcelable(
+ NetworkPolicyManager.EXTRA_NETWORK_TEMPLATE);
+ if (mNetworkTemplate == null) {
+ mTelephonyManager = context.getSystemService(TelephonyManager.class);
+ mSubscriptionManager = context.getSystemService(SubscriptionManager.class);
+ mNetworkTemplate = DataUsageUtils.getMobileNetworkTemplate(mTelephonyManager,
+ DataUsageUtils.getDefaultSubscriptionId(mSubscriptionManager));
+ }
// Loads the current policies to the policy editor cache.
mPolicyEditor.read();