Merge "Remove redundant code"
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index afc4d40..f2ed29c 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -2701,20 +2701,13 @@
<action android:name="android.settings.action.MANAGE_OVERLAY_PERMISSION" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
- <meta-data android:name="com.android.settings.FRAGMENT_CLASS"
- android:value="com.android.settings.applications.manageapplications.ManageApplications" />
- </activity>
-
- <activity
- android:name="Settings$AppDrawOverlaySettingsActivity"
- android:label="@string/draw_overlay">
<intent-filter android:priority="1">
<action android:name="android.settings.action.MANAGE_OVERLAY_PERMISSION" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="package" />
</intent-filter>
<meta-data android:name="com.android.settings.FRAGMENT_CLASS"
- android:value="com.android.settings.applications.appinfo.DrawOverlayDetails" />
+ android:value="com.android.settings.applications.manageapplications.ManageApplications" />
</activity>
<activity
diff --git a/res/layout/screen_pinning_instructions.xml b/res/layout/screen_pinning_instructions.xml
deleted file mode 100644
index fea5ed8..0000000
--- a/res/layout/screen_pinning_instructions.xml
+++ /dev/null
@@ -1,38 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
-/*
-** Copyright 2014, 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.
-*/
--->
-
-<ScrollView
- xmlns:android="http://schemas.android.com/apk/res/android"
- android:id="@+id/instructions_area"
- android:layout_width="match_parent"
- android:layout_height="match_parent">
-
- <TextView
- android:id="@+id/screen_pinning_description"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_alignParentTop="true"
- android:paddingTop="@dimen/screen_pinning_textview_padding"
- android:text="@string/screen_pinning_description"
- android:textAppearance="@style/TextAppearance.Medium"
- android:paddingStart="@dimen/screen_pinning_padding_start"
- android:paddingEnd="@dimen/screen_pinning_padding_end"
- />
-
-</ScrollView>
diff --git a/res/values/dimens.xml b/res/values/dimens.xml
index f97da1f..242b690 100755
--- a/res/values/dimens.xml
+++ b/res/values/dimens.xml
@@ -158,9 +158,6 @@
<!-- CryptKeeper pattern size for tablet -->
<dimen name="crypt_keeper_pattern_size">354dip</dimen>
- <!-- Screen pinning textview paddings -->
- <dimen name="screen_pinning_textview_padding">40dp</dimen>
-
<!-- SIM Dialog Margin top -->
<dimen name="sim_dialog_margin_top">8dip</dimen>
<!-- SIM Dialog Margin bottom -->
@@ -329,10 +326,6 @@
<dimen name="reset_master_clear_margin_start">32dp</dimen>
<dimen name="reset_master_clear_margin_end">12dp</dimen>
- <!-- Padding for screen pinning -->
- <dimen name="screen_pinning_padding_start">64dp</dimen>
- <dimen name="screen_pinning_padding_end">64dp</dimen>
-
<!-- Padding for the reset screens -->
<dimen name="reset_checkbox_padding_end">8dp</dimen>
<dimen name="reset_checkbox_title_padding_top">12dp</dimen>
diff --git a/res/xml/screen_pinning_settings.xml b/res/xml/screen_pinning_settings.xml
index f27e4aa..7ff7f1d 100644
--- a/res/xml/screen_pinning_settings.xml
+++ b/res/xml/screen_pinning_settings.xml
@@ -16,6 +16,7 @@
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:settings="http://schemas.android.com/apk/res-auto"
android:key="screen_pinning_settings_screen"
android:title="@string/screen_pinning_title">
@@ -23,4 +24,10 @@
android:key="use_screen_lock"
android:title="@string/screen_pinning_unlock_none" />
+ <com.android.settingslib.widget.FooterPreference
+ android:key="screen_pinning_settings_screen_footer"
+ android:title="@string/screen_pinning_description"
+ android:selectable="false"
+ settings:searchable="false" />
+
</PreferenceScreen>
diff --git a/src/com/android/settings/EncryptionInterstitial.java b/src/com/android/settings/EncryptionInterstitial.java
index c132c89..7a11053 100644
--- a/src/com/android/settings/EncryptionInterstitial.java
+++ b/src/com/android/settings/EncryptionInterstitial.java
@@ -31,7 +31,6 @@
import android.view.View;
import android.view.ViewGroup;
import android.view.accessibility.AccessibilityManager;
-import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.appcompat.app.AlertDialog;
diff --git a/src/com/android/settings/IccLockSettings.java b/src/com/android/settings/IccLockSettings.java
index 605f483..8880001 100644
--- a/src/com/android/settings/IccLockSettings.java
+++ b/src/com/android/settings/IccLockSettings.java
@@ -29,8 +29,6 @@
import android.os.Handler;
import android.os.Message;
import android.telephony.SubscriptionInfo;
-import android.telephony.SubscriptionManager;
-import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.util.Log;
import android.view.Gravity;
@@ -55,6 +53,9 @@
import com.android.internal.telephony.Phone;
import com.android.internal.telephony.PhoneFactory;
import com.android.internal.telephony.TelephonyIntents;
+import com.android.settings.network.ProxySubscriptionManager;
+
+import java.util.List;
/**
* Implements the preference screen to enable/disable ICC lock and
@@ -112,6 +113,7 @@
private ListView mListView;
private Phone mPhone;
+ private ProxySubscriptionManager mProxySubscriptionMgr;
private EditPinPreference mPinDialog;
private SwitchPreference mPinToggle;
@@ -129,7 +131,7 @@
// For replies from IccCard interface
private Handler mHandler = new Handler() {
public void handleMessage(Message msg) {
- AsyncResult ar = (AsyncResult) msg.obj;
+ final AsyncResult ar = (AsyncResult) msg.obj;
switch (msg.what) {
case MSG_ENABLE_ICC_PIN_COMPLETE:
iccLockChanged(ar.exception == null, msg.arg1, ar.exception);
@@ -161,8 +163,8 @@
}
static String getSummary(Context context) {
- Resources res = context.getResources();
- String summary = isIccLockEnabled()
+ final Resources res = context.getResources();
+ final String summary = isIccLockEnabled()
? res.getString(R.string.sim_lock_on)
: res.getString(R.string.sim_lock_off);
return summary;
@@ -177,6 +179,11 @@
return;
}
+ // enable ProxySubscriptionMgr with Lifecycle support for all controllers
+ // live within this fragment
+ mProxySubscriptionMgr = ProxySubscriptionManager.getInstance(getContext());
+ mProxySubscriptionMgr.setLifecycle(getLifecycle());
+
addPreferencesFromResource(R.xml.sim_lock_settings);
mPinDialog = (EditPinPreference) findPreference(PIN_DIALOG);
@@ -217,14 +224,12 @@
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
- final TelephonyManager tm =
- (TelephonyManager) getContext().getSystemService(Context.TELEPHONY_SERVICE);
- final int numSims = tm.getSimCount();
+ final int numSims = mProxySubscriptionMgr.getActiveSubscriptionInfoCountMax();
if (numSims > 1) {
- View view = inflater.inflate(R.layout.icc_lock_tabs, container, false);
+ final View view = inflater.inflate(R.layout.icc_lock_tabs, container, false);
final ViewGroup prefs_container = (ViewGroup) view.findViewById(R.id.prefs_container);
Utils.prepareCustomPreferencesList(container, view, prefs_container, false);
- View prefs = super.onCreateView(inflater, prefs_container, savedInstanceState);
+ final View prefs = super.onCreateView(inflater, prefs_container, savedInstanceState);
prefs_container.addView(prefs);
mTabHost = (TabHost) view.findViewById(android.R.id.tabhost);
@@ -235,18 +240,19 @@
mTabHost.setOnTabChangedListener(mTabListener);
mTabHost.clearAllTabs();
- SubscriptionManager sm = SubscriptionManager.from(getContext());
+ final List<SubscriptionInfo> subInfoList =
+ mProxySubscriptionMgr.getActiveSubscriptionsInfo();
for (int i = 0; i < numSims; ++i) {
- final SubscriptionInfo subInfo = sm.getActiveSubscriptionInfoForSimSlotIndex(i);
+ final SubscriptionInfo subInfo =
+ getActiveSubscriptionInfoForSimSlotIndex(subInfoList, i);
mTabHost.addTab(buildTabSpec(String.valueOf(i),
String.valueOf(subInfo == null
? getContext().getString(R.string.sim_editor_title, i + 1)
: subInfo.getDisplayName())));
}
- final SubscriptionInfo sir = sm.getActiveSubscriptionInfoForSimSlotIndex(0);
+ final SubscriptionInfo sir = getActiveSubscriptionInfoForSimSlotIndex(subInfoList, 0);
- mPhone = (sir == null) ? null
- : PhoneFactory.getPhone(SubscriptionManager.getPhoneId(sir.getSubscriptionId()));
+ mPhone = (sir == null) ? null : PhoneFactory.getPhone(sir.getSimSlotIndex());
if (savedInstanceState != null && savedInstanceState.containsKey(CURRENT_TAB)) {
mTabHost.setCurrentTabByTag(savedInstanceState.getString(CURRENT_TAB));
@@ -456,7 +462,7 @@
private void tryChangeIccLockState() {
// Try to change icc lock. If it succeeds, toggle the lock state and
// reset dialog state. Else inject error message and show dialog again.
- Message callback = Message.obtain(mHandler, MSG_ENABLE_ICC_PIN_COMPLETE);
+ final Message callback = Message.obtain(mHandler, MSG_ENABLE_ICC_PIN_COMPLETE);
mPhone.getIccCard().setIccLockEnabled(mToState, mPin, callback);
// Disable the setting till the response is received.
mPinToggle.setEnabled(false);
@@ -467,7 +473,8 @@
mPinToggle.setChecked(mToState);
} else {
if (exception instanceof CommandException) {
- CommandException.Error err = ((CommandException)(exception)).getCommandError();
+ final CommandException.Error err =
+ ((CommandException) exception).getCommandError();
if (err == CommandException.Error.PASSWORD_INCORRECT) {
createCustomTextToast(getPinPasswordErrorMessage(attemptsRemaining));
} else {
@@ -490,9 +497,9 @@
// The window type of Toast is set by NotificationManagerService.
// It can't be overwritten by LayoutParams.type.
// Ovarlay a custom window with LayoutParams (TYPE_STATUS_BAR_PANEL) on PUK unlock screen.
- View v = ((LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE))
+ final View v = ((LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE))
.inflate(com.android.internal.R.layout.transient_notification, null);
- TextView tv = (TextView) v.findViewById(com.android.internal.R.id.message);
+ final TextView tv = (TextView) v.findViewById(com.android.internal.R.id.message);
tv.setText(errorMessage);
final WindowManager.LayoutParams params = new WindowManager.LayoutParams();
@@ -521,7 +528,7 @@
| WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
| WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
- WindowManager wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
+ final WindowManager wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
wm.addView(v, params);
mHandler.postDelayed(new Runnable() {
@@ -545,7 +552,7 @@
}
private void tryChangePin() {
- Message callback = Message.obtain(mHandler, MSG_CHANGE_ICC_PIN_COMPLETE);
+ final Message callback = Message.obtain(mHandler, MSG_CHANGE_ICC_PIN_COMPLETE);
mPhone.getIccCard().changeIccLockPassword(mOldPin,
mNewPin, callback);
}
@@ -583,15 +590,27 @@
mDialogState = OFF_MODE;
}
+ private static SubscriptionInfo getActiveSubscriptionInfoForSimSlotIndex(
+ List<SubscriptionInfo> subInfoList, int slotId) {
+ if (subInfoList == null) {
+ return null;
+ }
+ for (SubscriptionInfo subInfo : subInfoList) {
+ if (subInfo.getSimSlotIndex() == slotId) {
+ return subInfo;
+ }
+ }
+ return null;
+ }
+
private OnTabChangeListener mTabListener = new OnTabChangeListener() {
@Override
public void onTabChanged(String tabId) {
final int slotId = Integer.parseInt(tabId);
- final SubscriptionInfo sir = SubscriptionManager.from(getActivity().getBaseContext())
- .getActiveSubscriptionInfoForSimSlotIndex(slotId);
+ final SubscriptionInfo sir = getActiveSubscriptionInfoForSimSlotIndex(
+ mProxySubscriptionMgr.getActiveSubscriptionsInfo(), slotId);
- mPhone = (sir == null) ? null
- : PhoneFactory.getPhone(SubscriptionManager.getPhoneId(sir.getSubscriptionId()));
+ mPhone = (sir == null) ? null : PhoneFactory.getPhone(sir.getSimSlotIndex());
// The User has changed tab; update the body.
updatePreferences();
diff --git a/src/com/android/settings/Settings.java b/src/com/android/settings/Settings.java
index 24963b3..c189b7b 100644
--- a/src/com/android/settings/Settings.java
+++ b/src/com/android/settings/Settings.java
@@ -137,7 +137,6 @@
public static class OverlaySettingsActivity extends SettingsActivity { /* empty */ }
public static class WriteSettingsActivity extends SettingsActivity { /* empty */ }
public static class ChangeWifiStateActivity extends SettingsActivity { /* empty */ }
- public static class AppDrawOverlaySettingsActivity extends SettingsActivity { /* empty */ }
public static class AppWriteSettingsActivity extends SettingsActivity { /* empty */ }
public static class ManageExternalSourcesActivity extends SettingsActivity {/* empty */ }
diff --git a/src/com/android/settings/applications/specialaccess/zenaccess/ScaryWarningDialogFragment.java b/src/com/android/settings/applications/specialaccess/zenaccess/ScaryWarningDialogFragment.java
index 69318f8..778206b 100644
--- a/src/com/android/settings/applications/specialaccess/zenaccess/ScaryWarningDialogFragment.java
+++ b/src/com/android/settings/applications/specialaccess/zenaccess/ScaryWarningDialogFragment.java
@@ -25,7 +25,6 @@
import com.android.settings.R;
import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
-import com.android.settings.notification.ZenAccessSettings;
/**
* Warning dialog when allowing zen access warning about the privileges being granted.
diff --git a/src/com/android/settings/bluetooth/AdvancedBluetoothDetailsHeaderController.java b/src/com/android/settings/bluetooth/AdvancedBluetoothDetailsHeaderController.java
index e245c22..2bc5592 100644
--- a/src/com/android/settings/bluetooth/AdvancedBluetoothDetailsHeaderController.java
+++ b/src/com/android/settings/bluetooth/AdvancedBluetoothDetailsHeaderController.java
@@ -112,7 +112,7 @@
if (!isAvailable()) {
return;
}
- mCachedDevice.registerCallback(this::onDeviceAttributesChanged);
+ mCachedDevice.registerCallback(this);
mBluetoothAdapter.addOnMetadataChangedListener(mCachedDevice.getDevice(),
mContext.getMainExecutor(), mMetadataListener);
}
@@ -122,7 +122,7 @@
if (!isAvailable()) {
return;
}
- mCachedDevice.unregisterCallback(this::onDeviceAttributesChanged);
+ mCachedDevice.unregisterCallback(this);
mBluetoothAdapter.removeOnMetadataChangedListener(mCachedDevice.getDevice(),
mMetadataListener);
}
@@ -153,7 +153,7 @@
final TextView summary = mLayoutPreference.findViewById(R.id.entity_header_summary);
summary.setText(mCachedDevice.getConnectionSummary(true /* shortSummary */));
- if (!mCachedDevice.isConnected()) {
+ if (!mCachedDevice.isConnected() || mCachedDevice.isBusy()) {
updateDisconnectLayout();
return;
}
diff --git a/src/com/android/settings/bluetooth/Utils.java b/src/com/android/settings/bluetooth/Utils.java
index 5e9ac3a..48c7212 100755
--- a/src/com/android/settings/bluetooth/Utils.java
+++ b/src/com/android/settings/bluetooth/Utils.java
@@ -45,7 +45,7 @@
private static final String TAG = "BluetoothUtils";
static final boolean V = BluetoothUtils.V; // verbose logging
- static final boolean D = BluetoothUtils.D; // regular logging
+ static final boolean D = BluetoothUtils.D; // regular logging
private Utils() {
}
@@ -93,7 +93,8 @@
@VisibleForTesting
static void showConnectingError(Context context, String name, LocalBluetoothManager manager) {
FeatureFactory.getFactory(context).getMetricsFeatureProvider().visible(context,
- SettingsEnums.PAGE_UNKNOWN, SettingsEnums.ACTION_SETTINGS_BLUETOOTH_CONNECT_ERROR);
+ SettingsEnums.PAGE_UNKNOWN, SettingsEnums.ACTION_SETTINGS_BLUETOOTH_CONNECT_ERROR,
+ 0);
showError(context, name, R.string.bluetooth_connecting_error_message, manager);
}
diff --git a/src/com/android/settings/core/FeatureFlags.java b/src/com/android/settings/core/FeatureFlags.java
index 4b65df1..92e4e72 100644
--- a/src/com/android/settings/core/FeatureFlags.java
+++ b/src/com/android/settings/core/FeatureFlags.java
@@ -26,4 +26,5 @@
public static final String WIFI_DETAILS_DATAUSAGE_HEADER =
"settings_wifi_details_datausage_header";
public static final String PERSONAL_WORK_PROFILE = "settings_work_profile";
+ public static final String CONTROLLER_ENHANCEMENT = "settings_controller_loading_enhancement";
}
diff --git a/src/com/android/settings/core/InstrumentedFragment.java b/src/com/android/settings/core/InstrumentedFragment.java
index 427e33a..c4ceb4a 100644
--- a/src/com/android/settings/core/InstrumentedFragment.java
+++ b/src/com/android/settings/core/InstrumentedFragment.java
@@ -47,8 +47,4 @@
mVisibilityLoggerMixin.setSourceMetricsCategory(getActivity());
super.onResume();
}
-
- protected final VisibilityLoggerMixin getVisibilityLogger() {
- return mVisibilityLoggerMixin;
- }
}
diff --git a/src/com/android/settings/core/InstrumentedPreferenceFragment.java b/src/com/android/settings/core/InstrumentedPreferenceFragment.java
index f5f245f..8b59281 100644
--- a/src/com/android/settings/core/InstrumentedPreferenceFragment.java
+++ b/src/com/android/settings/core/InstrumentedPreferenceFragment.java
@@ -91,10 +91,6 @@
return getPreferenceManager().getContext();
}
- protected final VisibilityLoggerMixin getVisibilityLogger() {
- return mVisibilityLoggerMixin;
- }
-
/**
* Get the res id for static preference xml for this fragment.
*/
diff --git a/src/com/android/settings/core/instrumentation/SettingsEventLogWriter.java b/src/com/android/settings/core/instrumentation/SettingsEventLogWriter.java
index a58555f..4ffa2d0 100644
--- a/src/com/android/settings/core/instrumentation/SettingsEventLogWriter.java
+++ b/src/com/android/settings/core/instrumentation/SettingsEventLogWriter.java
@@ -25,11 +25,11 @@
public class SettingsEventLogWriter extends EventLogWriter {
@Override
- public void visible(Context context, int source, int category) {
+ public void visible(Context context, int source, int category, int latency) {
if (shouldDisableGenericEventLogging()) {
return;
}
- super.visible(context, source, category);
+ super.visible(context, source, category, latency);
}
@Override
diff --git a/src/com/android/settings/core/instrumentation/SettingsIntelligenceLogWriter.java b/src/com/android/settings/core/instrumentation/SettingsIntelligenceLogWriter.java
index 9498732..62954ea 100644
--- a/src/com/android/settings/core/instrumentation/SettingsIntelligenceLogWriter.java
+++ b/src/com/android/settings/core/instrumentation/SettingsIntelligenceLogWriter.java
@@ -61,12 +61,12 @@
}
@Override
- public void visible(Context context, int attribution, int pageId) {
- action(attribution /* attribution */,
+ public void visible(Context context, int attribution, int pageId, int latency) {
+ action(attribution /* from pageId */,
SettingsEnums.PAGE_VISIBLE /* action */,
- pageId /* pageId */,
+ pageId /* target pageId */,
"" /* changedPreferenceKey */,
- 0 /* changedPreferenceIntValue */);
+ latency /* changedPreferenceIntValue */);
}
@Override
diff --git a/src/com/android/settings/core/instrumentation/StatsLogWriter.java b/src/com/android/settings/core/instrumentation/StatsLogWriter.java
index bcdecf3..6e09b72 100644
--- a/src/com/android/settings/core/instrumentation/StatsLogWriter.java
+++ b/src/com/android/settings/core/instrumentation/StatsLogWriter.java
@@ -26,13 +26,13 @@
public class StatsLogWriter implements LogWriter {
@Override
- public void visible(Context context, int attribution, int pageId) {
+ public void visible(Context context, int attribution, int pageId, int latency) {
StatsLog.write(StatsLog.SETTINGS_UI_CHANGED /* Atom name */,
- attribution,
+ attribution, /* from pageId */
SettingsEnums.PAGE_VISIBLE /* action */,
- pageId,
+ pageId, /* target pageId */
null /* changedPreferenceKey */,
- 0 /* changedPreferenceIntValue */);
+ latency /* changedPreferenceIntValue */);
}
@Override
diff --git a/src/com/android/settings/homepage/contextualcards/conditional/ConditionContextualCardRenderer.java b/src/com/android/settings/homepage/contextualcards/conditional/ConditionContextualCardRenderer.java
index 91b2e97..ccfb732 100644
--- a/src/com/android/settings/homepage/contextualcards/conditional/ConditionContextualCardRenderer.java
+++ b/src/com/android/settings/homepage/contextualcards/conditional/ConditionContextualCardRenderer.java
@@ -65,7 +65,7 @@
mContext).getMetricsFeatureProvider();
metricsFeatureProvider.visible(mContext, SettingsEnums.SETTINGS_HOMEPAGE,
- card.getMetricsConstant());
+ card.getMetricsConstant(), 0);
initializePrimaryClick(view, card, metricsFeatureProvider);
initializeView(view, card);
initializeActionButton(view, card, metricsFeatureProvider);
diff --git a/src/com/android/settings/media/MediaOutputSlice.java b/src/com/android/settings/media/MediaOutputSlice.java
index 8086c41..2b70caf 100644
--- a/src/com/android/settings/media/MediaOutputSlice.java
+++ b/src/com/android/settings/media/MediaOutputSlice.java
@@ -164,7 +164,7 @@
intent.putExtra(MEDIA_DEVICE_ID, id);
intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
return PendingIntent.getBroadcast(context, requestCode /* requestCode */, intent,
- PendingIntent.FLAG_CANCEL_CURRENT);
+ PendingIntent.FLAG_UPDATE_CURRENT);
}
@Override
diff --git a/src/com/android/settings/network/telephony/RoamingDialogFragment.java b/src/com/android/settings/network/telephony/RoamingDialogFragment.java
index 1298445..bf22fba 100644
--- a/src/com/android/settings/network/telephony/RoamingDialogFragment.java
+++ b/src/com/android/settings/network/telephony/RoamingDialogFragment.java
@@ -42,7 +42,7 @@
public static RoamingDialogFragment newInstance(int subId) {
final RoamingDialogFragment dialogFragment = new RoamingDialogFragment();
- Bundle args = new Bundle();
+ final Bundle args = new Bundle();
args.putInt(SUB_ID_KEY, subId);
dialogFragment.setArguments(args);
@@ -52,17 +52,17 @@
@Override
public void onAttach(Context context) {
super.onAttach(context);
- Bundle args = getArguments();
+ final Bundle args = getArguments();
mSubId = args.getInt(SUB_ID_KEY);
mCarrierConfigManager = new CarrierConfigManager(context);
}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
- AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
- int title = R.string.roaming_alert_title;
+ final AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
+ final int title = R.string.roaming_alert_title;
int message = R.string.roaming_warning;
- PersistableBundle carrierConfig = mCarrierConfigManager.getConfigForSubId(mSubId);
+ final PersistableBundle carrierConfig = mCarrierConfigManager.getConfigForSubId(mSubId);
if (carrierConfig != null && carrierConfig.getBoolean(
CarrierConfigManager.KEY_CHECK_PRICING_WITH_CARRIER_FOR_DATA_ROAMING_BOOL)) {
message = R.string.roaming_check_price_warning;
@@ -84,8 +84,13 @@
public void onClick(DialogInterface dialog, int which) {
// let the host know that the positive button has been clicked
if (which == dialog.BUTTON_POSITIVE) {
- TelephonyManager.from(getContext()).createForSubscriptionId(
- mSubId).setDataRoamingEnabled(true);
+ final TelephonyManager telephonyManager =
+ getContext().getSystemService(TelephonyManager.class)
+ .createForSubscriptionId(mSubId);
+ if (telephonyManager == null) {
+ return;
+ }
+ telephonyManager.setDataRoamingEnabled(true);
}
}
}
diff --git a/src/com/android/settings/network/telephony/RoamingPreferenceController.java b/src/com/android/settings/network/telephony/RoamingPreferenceController.java
index dd5fd0e..08fe323 100644
--- a/src/com/android/settings/network/telephony/RoamingPreferenceController.java
+++ b/src/com/android/settings/network/telephony/RoamingPreferenceController.java
@@ -17,22 +17,20 @@
package com.android.settings.network.telephony;
import android.content.Context;
-import android.database.ContentObserver;
-import android.net.Uri;
-import android.os.Handler;
-import android.os.Looper;
import android.os.PersistableBundle;
import android.provider.Settings;
import android.telephony.CarrierConfigManager;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
+import android.util.Log;
import androidx.annotation.VisibleForTesting;
import androidx.fragment.app.FragmentManager;
import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
+import com.android.settings.network.GlobalSettingsChangeListener;
import com.android.settingslib.RestrictedSwitchPreference;
import com.android.settingslib.core.lifecycle.LifecycleObserver;
import com.android.settingslib.core.lifecycle.events.OnStart;
@@ -44,31 +42,59 @@
public class RoamingPreferenceController extends TelephonyTogglePreferenceController implements
LifecycleObserver, OnStart, OnStop {
+ private static final String TAG = "RoamingController";
private static final String DIALOG_TAG = "MobileDataDialog";
private RestrictedSwitchPreference mSwitchPreference;
private TelephonyManager mTelephonyManager;
private CarrierConfigManager mCarrierConfigManager;
- private DataContentObserver mDataContentObserver;
- @VisibleForTesting
- boolean mNeedDialog;
+
+ /**
+ * There're 2 listeners both activated at the same time.
+ * For project that access DATA_ROAMING, only first listener is functional.
+ * For project that access "DATA_ROAMING + subId", first listener will be stopped when receiving
+ * any onChange from second listener.
+ */
+ private GlobalSettingsChangeListener mListener;
+ private GlobalSettingsChangeListener mListenerForSubId;
+
@VisibleForTesting
FragmentManager mFragmentManager;
public RoamingPreferenceController(Context context, String key) {
super(context, key);
mCarrierConfigManager = context.getSystemService(CarrierConfigManager.class);
- mDataContentObserver = new DataContentObserver(new Handler(Looper.getMainLooper()));
}
@Override
public void onStart() {
- mDataContentObserver.register(mContext, mSubId);
+ if (mListener == null) {
+ mListener = new GlobalSettingsChangeListener(mContext,
+ Settings.Global.DATA_ROAMING) {
+ public void onChanged(String field) {
+ updateState(mSwitchPreference);
+ }
+ };
+ }
+ stopMonitorSubIdSpecific();
+
+ if (mSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
+ return;
+ }
+
+ mListenerForSubId = new GlobalSettingsChangeListener(mContext,
+ Settings.Global.DATA_ROAMING + mSubId) {
+ public void onChanged(String field) {
+ stopMonitor();
+ updateState(mSwitchPreference);
+ }
+ };
}
@Override
public void onStop() {
- mDataContentObserver.unRegister(mContext);
+ stopMonitor();
+ stopMonitorSubIdSpecific();
}
@Override
@@ -87,7 +113,7 @@
@Override
public boolean handlePreferenceTreeClick(Preference preference) {
if (TextUtils.equals(preference.getKey(), getPreferenceKey())) {
- if (mNeedDialog) {
+ if (isDialogNeeded()) {
showDialog();
}
return true;
@@ -98,9 +124,7 @@
@Override
public boolean setChecked(boolean isChecked) {
- mNeedDialog = isDialogNeeded();
-
- if (!mNeedDialog) {
+ if (!isDialogNeeded()) {
// Update data directly if we don't need dialog
mTelephonyManager.setDataRoamingEnabled(isChecked);
return true;
@@ -141,7 +165,18 @@
public void init(FragmentManager fragmentManager, int subId) {
mFragmentManager = fragmentManager;
mSubId = subId;
- mTelephonyManager = TelephonyManager.from(mContext).createForSubscriptionId(mSubId);
+ mTelephonyManager = mContext.getSystemService(TelephonyManager.class);
+ if (mSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
+ return;
+ }
+ final TelephonyManager telephonyManager = mTelephonyManager
+ .createForSubscriptionId(mSubId);
+ if (telephonyManager == null) {
+ Log.w(TAG, "fail to init in sub" + mSubId);
+ mSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
+ return;
+ }
+ mTelephonyManager = telephonyManager;
}
private void showDialog() {
@@ -150,32 +185,17 @@
dialogFragment.show(mFragmentManager, DIALOG_TAG);
}
- /**
- * Listener that listens data roaming change
- */
- public class DataContentObserver extends ContentObserver {
-
- public DataContentObserver(Handler handler) {
- super(handler);
+ private void stopMonitor() {
+ if (mListener != null) {
+ mListener.close();
+ mListener = null;
}
+ }
- @Override
- public void onChange(boolean selfChange) {
- super.onChange(selfChange);
- updateState(mSwitchPreference);
- }
-
- public void register(Context context, int subId) {
- Uri uri = Settings.Global.getUriFor(Settings.Global.DATA_ROAMING);
- if (TelephonyManager.getDefault().getSimCount() != 1) {
- uri = Settings.Global.getUriFor(Settings.Global.DATA_ROAMING + subId);
- }
- context.getContentResolver().registerContentObserver(uri, false, this);
-
- }
-
- public void unRegister(Context context) {
- context.getContentResolver().unregisterContentObserver(this);
+ private void stopMonitorSubIdSpecific() {
+ if (mListenerForSubId != null) {
+ mListenerForSubId.close();
+ mListenerForSubId = null;
}
}
}
diff --git a/src/com/android/settings/network/telephony/VideoCallingPreferenceController.java b/src/com/android/settings/network/telephony/VideoCallingPreferenceController.java
index 7f7a821..692a7e1 100644
--- a/src/com/android/settings/network/telephony/VideoCallingPreferenceController.java
+++ b/src/com/android/settings/network/telephony/VideoCallingPreferenceController.java
@@ -17,12 +17,8 @@
package com.android.settings.network.telephony;
import android.content.Context;
-import android.database.ContentObserver;
-import android.net.Uri;
-import android.os.Handler;
import android.os.Looper;
import android.os.PersistableBundle;
-import android.provider.Settings;
import android.telephony.CarrierConfigManager;
import android.telephony.PhoneStateListener;
import android.telephony.SubscriptionManager;
@@ -34,6 +30,7 @@
import androidx.preference.SwitchPreference;
import com.android.ims.ImsManager;
+import com.android.settings.network.MobileDataEnabledListener;
import com.android.settingslib.core.lifecycle.LifecycleObserver;
import com.android.settingslib.core.lifecycle.events.OnStart;
import com.android.settingslib.core.lifecycle.events.OnStop;
@@ -43,6 +40,7 @@
*/
public class VideoCallingPreferenceController extends TelephonyTogglePreferenceController implements
LifecycleObserver, OnStart, OnStop,
+ MobileDataEnabledListener.Client,
Enhanced4gBasePreferenceController.On4gLteUpdateListener {
private Preference mPreference;
@@ -51,12 +49,14 @@
@VisibleForTesting
ImsManager mImsManager;
private PhoneCallStateListener mPhoneStateListener;
- private DataContentObserver mDataContentObserver;
+ @VisibleForTesting
+ Integer mCallState;
+ private MobileDataEnabledListener mDataContentObserver;
public VideoCallingPreferenceController(Context context, String key) {
super(context, key);
mCarrierConfigManager = context.getSystemService(CarrierConfigManager.class);
- mDataContentObserver = new DataContentObserver(new Handler(Looper.getMainLooper()));
+ mDataContentObserver = new MobileDataEnabledListener(context, this);
mPhoneStateListener = new PhoneCallStateListener(Looper.getMainLooper());
}
@@ -77,18 +77,21 @@
@Override
public void onStart() {
mPhoneStateListener.register(mSubId);
- mDataContentObserver.register(mContext, mSubId);
+ mDataContentObserver.start(mSubId);
}
@Override
public void onStop() {
mPhoneStateListener.unregister();
- mDataContentObserver.unRegister(mContext);
+ mDataContentObserver.stop();
}
@Override
public void updateState(Preference preference) {
super.updateState(preference);
+ if (mCallState == null) {
+ return;
+ }
final SwitchPreference switchPreference = (SwitchPreference) preference;
final boolean videoCallEnabled = isVideoCallEnabled(mSubId, mImsManager);
switchPreference.setVisible(videoCallEnabled);
@@ -96,7 +99,7 @@
final boolean is4gLteEnabled = mImsManager.isEnhanced4gLteModeSettingEnabledByUser()
&& mImsManager.isNonTtyOrTtyOnVolteEnabled();
preference.setEnabled(is4gLteEnabled &&
- mTelephonyManager.getCallState(mSubId) == TelephonyManager.CALL_STATE_IDLE);
+ mCallState == TelephonyManager.CALL_STATE_IDLE);
switchPreference.setChecked(is4gLteEnabled && mImsManager.isVtEnabledByUser());
}
}
@@ -114,8 +117,9 @@
public VideoCallingPreferenceController init(int subId) {
mSubId = subId;
- mTelephonyManager = TelephonyManager.from(mContext).createForSubscriptionId(mSubId);
+ mTelephonyManager = mContext.getSystemService(TelephonyManager.class);
if (mSubId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
+ mTelephonyManager = mTelephonyManager.createForSubscriptionId(mSubId);
mImsManager = ImsManager.getInstance(mContext, SubscriptionManager.getPhoneId(mSubId));
}
@@ -132,8 +136,10 @@
@VisibleForTesting
boolean isVideoCallEnabled(int subId, ImsManager imsManager) {
final PersistableBundle carrierConfig = mCarrierConfigManager.getConfigForSubId(subId);
- final TelephonyManager telephonyManager = TelephonyManager
- .from(mContext).createForSubscriptionId(subId);
+ TelephonyManager telephonyManager = mContext.getSystemService(TelephonyManager.class);
+ if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
+ telephonyManager = telephonyManager.createForSubscriptionId(subId);
+ }
return carrierConfig != null && imsManager != null
&& imsManager.isVtEnabledByPlatform()
&& imsManager.isVtProvisionedOnDevice()
@@ -156,6 +162,7 @@
@Override
public void onCallStateChanged(int state, String incomingNumber) {
+ mCallState = state;
updateState(mPreference);
}
@@ -165,36 +172,15 @@
}
public void unregister() {
+ mCallState = null;
mTelephonyManager.listen(this, PhoneStateListener.LISTEN_NONE);
}
}
/**
- * Listener that listens mobile data state change.
+ * Implementation of MobileDataEnabledListener.Client
*/
- public class DataContentObserver extends ContentObserver {
-
- public DataContentObserver(Handler handler) {
- super(handler);
- }
-
- @Override
- public void onChange(boolean selfChange) {
- super.onChange(selfChange);
- updateState(mPreference);
- }
-
- public void register(Context context, int subId) {
- Uri uri = Settings.Global.getUriFor(Settings.Global.MOBILE_DATA);
- if (TelephonyManager.getDefault().getSimCount() != 1) {
- uri = Settings.Global.getUriFor(Settings.Global.MOBILE_DATA + subId);
- }
- context.getContentResolver().registerContentObserver(uri,
- false /* notifyForDescendants */, this /* observer */);
- }
-
- public void unRegister(Context context) {
- context.getContentResolver().unregisterContentObserver(this);
- }
+ public void onMobileDataEnabledChange() {
+ updateState(mPreference);
}
}
diff --git a/src/com/android/settings/security/ScreenPinningSettings.java b/src/com/android/settings/security/ScreenPinningSettings.java
index 849db40..aa3e862 100644
--- a/src/com/android/settings/security/ScreenPinningSettings.java
+++ b/src/com/android/settings/security/ScreenPinningSettings.java
@@ -23,9 +23,6 @@
import android.os.UserHandle;
import android.provider.SearchIndexableResource;
import android.provider.Settings;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.view.ViewGroup;
import android.widget.Switch;
import androidx.preference.Preference;
@@ -41,6 +38,7 @@
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settings.widget.SwitchBar;
import com.android.settingslib.search.SearchIndexable;
+import com.android.settingslib.widget.FooterPreference;
import java.util.Arrays;
import java.util.List;
@@ -52,11 +50,13 @@
public class ScreenPinningSettings extends SettingsPreferenceFragment
implements SwitchBar.OnSwitchChangeListener {
- private static final CharSequence KEY_USE_SCREEN_LOCK = "use_screen_lock";
+ private static final String KEY_USE_SCREEN_LOCK = "use_screen_lock";
+ private static final String KEY_FOOTER = "screen_pinning_settings_screen_footer";
private static final int CHANGE_LOCK_METHOD_REQUEST = 43;
private SwitchBar mSwitchBar;
private SwitchPreference mUseScreenLock;
+ private FooterPreference mFooterPreference;
private LockPatternUtils mLockPatternUtils;
@Override
@@ -77,6 +77,13 @@
mSwitchBar.addOnSwitchChangeListener(this);
mSwitchBar.show();
mSwitchBar.setChecked(isLockToAppEnabled(getActivity()));
+
+ addPreferencesFromResource(R.xml.screen_pinning_settings);
+
+ final PreferenceScreen root = getPreferenceScreen();
+ mUseScreenLock = root.findPreference(KEY_USE_SCREEN_LOCK);
+ mFooterPreference = root.findPreference(KEY_FOOTER);
+ updateDisplay();
}
@Override
@@ -85,16 +92,6 @@
}
@Override
- public void onViewCreated(View view, Bundle savedInstanceState) {
- super.onViewCreated(view, savedInstanceState);
- ViewGroup parent = (ViewGroup) view.findViewById(android.R.id.list_container);
- View emptyView = LayoutInflater.from(getContext())
- .inflate(R.layout.screen_pinning_instructions, parent, false);
- parent.addView(emptyView);
- setEmptyView(emptyView);
- }
-
- @Override
public void onDestroyView() {
super.onDestroyView();
@@ -192,16 +189,10 @@
updateDisplay();
}
- public void updateDisplay() {
- PreferenceScreen root = getPreferenceScreen();
- if (root != null) {
- root.removeAll();
- }
+ private void updateDisplay() {
if (isLockToAppEnabled(getActivity())) {
- addPreferencesFromResource(R.xml.screen_pinning_settings);
- root = getPreferenceScreen();
-
- mUseScreenLock = (SwitchPreference) root.findPreference(KEY_USE_SCREEN_LOCK);
+ mFooterPreference.setVisible(false);
+ mUseScreenLock.setVisible(true);
mUseScreenLock.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
@@ -210,6 +201,9 @@
});
mUseScreenLock.setChecked(isScreenLockUsed());
mUseScreenLock.setTitle(getCurrentSecurityTitle());
+ } else {
+ mFooterPreference.setVisible(true);
+ mUseScreenLock.setVisible(false);
}
}
diff --git a/tests/robotests/src/com/android/settings/bluetooth/UtilsTest.java b/tests/robotests/src/com/android/settings/bluetooth/UtilsTest.java
index 1920019..25808b5 100644
--- a/tests/robotests/src/com/android/settings/bluetooth/UtilsTest.java
+++ b/tests/robotests/src/com/android/settings/bluetooth/UtilsTest.java
@@ -15,8 +15,6 @@
*/
package com.android.settings.bluetooth;
-import static com.google.common.truth.Truth.assertThat;
-
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
@@ -24,7 +22,6 @@
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
-import android.bluetooth.BluetoothDevice;
import android.content.Context;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
@@ -61,6 +58,6 @@
Utils.showConnectingError(mContext, "testName", mock(LocalBluetoothManager.class));
verify(mMetricsFeatureProvider).visible(eq(mContext), anyInt(),
- eq(MetricsEvent.ACTION_SETTINGS_BLUETOOTH_CONNECT_ERROR));
+ eq(MetricsEvent.ACTION_SETTINGS_BLUETOOTH_CONNECT_ERROR), anyInt());
}
}
diff --git a/tests/robotests/src/com/android/settings/core/instrumentation/SettingsEventLogWriterTest.java b/tests/robotests/src/com/android/settings/core/instrumentation/SettingsEventLogWriterTest.java
index ba2553d..8f22df0 100644
--- a/tests/robotests/src/com/android/settings/core/instrumentation/SettingsEventLogWriterTest.java
+++ b/tests/robotests/src/com/android/settings/core/instrumentation/SettingsEventLogWriterTest.java
@@ -62,7 +62,7 @@
SettingsUIDeviceConfig.GENERIC_EVENT_LOGGING_ENABLED, "true", true);
mWriter.visible(RuntimeEnvironment.application, SettingsEnums.PAGE_UNKNOWN,
- SettingsEnums.SETTINGS_HOMEPAGE);
+ SettingsEnums.SETTINGS_HOMEPAGE, 0);
assertThat(ShadowMetricsLogger.sActionLoggedCount).isEqualTo(1);
}
@@ -83,7 +83,7 @@
SettingsUIDeviceConfig.GENERIC_EVENT_LOGGING_ENABLED, "false", true);
mWriter.visible(RuntimeEnvironment.application, SettingsEnums.PAGE_UNKNOWN,
- SettingsEnums.SETTINGS_HOMEPAGE);
+ SettingsEnums.SETTINGS_HOMEPAGE, 0);
assertThat(ShadowMetricsLogger.sActionLoggedCount).isEqualTo(0);
}
diff --git a/tests/robotests/src/com/android/settings/network/telephony/RoamingPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/network/telephony/RoamingPreferenceControllerTest.java
index a883c51..0abd6d5 100644
--- a/tests/robotests/src/com/android/settings/network/telephony/RoamingPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/network/telephony/RoamingPreferenceControllerTest.java
@@ -80,7 +80,7 @@
doReturn(mFragmentTransaction).when(mFragmentManager).beginTransaction();
mPreference = spy(new RestrictedSwitchPreference(mContext));
- mController = new RoamingPreferenceController(mContext, "roaming");
+ mController = spy(new RoamingPreferenceController(mContext, "roaming"));
mController.init(mFragmentManager, SUB_ID);
mPreference.setKey(mController.getPreferenceKey());
}
@@ -118,7 +118,7 @@
@Test
public void handlePreferenceTreeClick_needDialog_showDialog() {
- mController.mNeedDialog = true;
+ doReturn(true).when(mController).isDialogNeeded();
mController.handlePreferenceTreeClick(mPreference);
diff --git a/tests/robotests/src/com/android/settings/network/telephony/VideoCallingPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/network/telephony/VideoCallingPreferenceControllerTest.java
index 3ada519..7b71565 100644
--- a/tests/robotests/src/com/android/settings/network/telephony/VideoCallingPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/network/telephony/VideoCallingPreferenceControllerTest.java
@@ -83,6 +83,8 @@
doReturn(true).when(mImsManager).isVtProvisionedOnDevice();
doReturn(ImsFeature.STATE_READY).when(mImsManager).getImsServiceState();
doReturn(true).when(mTelephonyManager).isDataEnabled();
+
+ mController.mCallState = TelephonyManager.CALL_STATE_IDLE;
}
@Test