DO NOT MERGE - Merge ab/7272582
Bug: 190855093 Merged-In: I1cc3796f31e7db3d8f062436ebc618d93db19822 Change-Id: I2b6c7d579bfa1ce3d3fb4432d92906dc739dde1b
This commit is contained in:
@@ -207,6 +207,7 @@ public class DeviceAdminListPreferenceController extends BasePreferenceControlle
|
||||
return true;
|
||||
});
|
||||
pref.setOnPreferenceChangeListener((preference, newValue) -> false);
|
||||
pref.setSingleLineTitle(true);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -229,7 +229,8 @@ public class SimStatusDialogController implements LifecycleObserver, OnResume, O
|
||||
if (mSubscriptionInfo == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
mTelephonyManager =
|
||||
mTelephonyManager.createForSubscriptionId(mSubscriptionInfo.getSubscriptionId());
|
||||
mPhoneStateListener = getPhoneStateListener();
|
||||
updateLatestAreaInfo();
|
||||
updateSubscriptionStatus();
|
||||
|
||||
@@ -52,7 +52,8 @@ import com.android.settingslib.widget.LayoutPreference;
|
||||
* Controller that update the battery header view
|
||||
*/
|
||||
public class BatteryHeaderPreferenceController extends BasePreferenceController
|
||||
implements PreferenceControllerMixin, LifecycleObserver, OnStart {
|
||||
implements PreferenceControllerMixin, LifecycleObserver, OnStart,
|
||||
BatteryPreferenceController {
|
||||
@VisibleForTesting
|
||||
static final String KEY_BATTERY_HEADER = "battery_header";
|
||||
private static final String ANNOTATION_URL = "url";
|
||||
@@ -121,16 +122,20 @@ public class BatteryHeaderPreferenceController extends BasePreferenceController
|
||||
.styleActionBar(mActivity);
|
||||
}
|
||||
|
||||
private CharSequence generateLabel(BatteryInfo info) {
|
||||
if (BatteryUtils.isBatteryDefenderOn(info)) {
|
||||
return null;
|
||||
} else if (info.remainingLabel == null) {
|
||||
return info.statusLabel;
|
||||
} else {
|
||||
return info.remainingLabel;
|
||||
}
|
||||
}
|
||||
|
||||
public void updateHeaderPreference(BatteryInfo info) {
|
||||
mBatteryPercentText.setText(formatBatteryPercentageText(info.batteryLevel));
|
||||
if (!mBatteryStatusFeatureProvider.triggerBatteryStatusUpdate(this, info)) {
|
||||
if (BatteryUtils.isBatteryDefenderOn(info)) {
|
||||
mSummary1.setText(null);
|
||||
} else if (info.remainingLabel == null) {
|
||||
mSummary1.setText(info.statusLabel);
|
||||
} else {
|
||||
mSummary1.setText(info.remainingLabel);
|
||||
}
|
||||
mSummary1.setText(generateLabel(info));
|
||||
}
|
||||
|
||||
mBatteryMeterView.setBatteryLevel(info.batteryLevel);
|
||||
@@ -141,8 +146,8 @@ public class BatteryHeaderPreferenceController extends BasePreferenceController
|
||||
/**
|
||||
* Callback which receives text for the summary line.
|
||||
*/
|
||||
public void updateBatteryStatus(String statusLabel) {
|
||||
mSummary1.setText(statusLabel);
|
||||
public void updateBatteryStatus(String label, BatteryInfo info) {
|
||||
mSummary1.setText(label != null ? label : generateLabel(info));
|
||||
}
|
||||
|
||||
public void quickUpdateHeaderPreference() {
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Copyright (C) 2020 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.fuelgauge;
|
||||
|
||||
/**
|
||||
* Common interface for a preference controller that updates battery status
|
||||
*/
|
||||
public interface BatteryPreferenceController {
|
||||
|
||||
/**
|
||||
* Updates the label for the preference controller. If the label is null, the
|
||||
* implementation should revert back to the original label based on the
|
||||
* battery info.
|
||||
*/
|
||||
void updateBatteryStatus(String label, BatteryInfo info);
|
||||
}
|
||||
@@ -25,5 +25,5 @@ public interface BatteryStatusFeatureProvider {
|
||||
* Trigger a battery status update; return false if built-in status should be used.
|
||||
*/
|
||||
boolean triggerBatteryStatusUpdate(
|
||||
BatteryHeaderPreferenceController batteryHeaderPreferenceController, BatteryInfo info);
|
||||
BatteryPreferenceController controller, BatteryInfo info);
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ public class BatteryStatusFeatureProviderImpl implements BatteryStatusFeaturePro
|
||||
|
||||
@Override
|
||||
public boolean triggerBatteryStatusUpdate(
|
||||
BatteryHeaderPreferenceController batteryHeaderPreferenceController, BatteryInfo info) {
|
||||
BatteryPreferenceController controller, BatteryInfo info) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,18 +24,21 @@ import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settingslib.core.lifecycle.LifecycleObserver;
|
||||
import com.android.settingslib.core.lifecycle.events.OnStart;
|
||||
import com.android.settingslib.core.lifecycle.events.OnStop;
|
||||
|
||||
public class TopLevelBatteryPreferenceController extends BasePreferenceController implements
|
||||
LifecycleObserver, OnStart, OnStop {
|
||||
LifecycleObserver, OnStart, OnStop, BatteryPreferenceController {
|
||||
|
||||
@VisibleForTesting
|
||||
boolean mIsBatteryPresent = true;
|
||||
protected boolean mIsBatteryPresent = true;
|
||||
private final BatteryBroadcastReceiver mBatteryBroadcastReceiver;
|
||||
private Preference mPreference;
|
||||
private BatteryInfo mBatteryInfo;
|
||||
private BatteryStatusFeatureProvider mBatteryStatusFeatureProvider;
|
||||
private String mBatteryStatusLabel;
|
||||
|
||||
public TopLevelBatteryPreferenceController(Context context, String preferenceKey) {
|
||||
super(context, preferenceKey);
|
||||
@@ -49,6 +52,9 @@ public class TopLevelBatteryPreferenceController extends BasePreferenceControlle
|
||||
updateState(mPreference);
|
||||
}, true /* shortString */);
|
||||
});
|
||||
|
||||
mBatteryStatusFeatureProvider = FeatureFactory.getFactory(context)
|
||||
.getBatteryStatusFeatureProvider(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -75,27 +81,56 @@ public class TopLevelBatteryPreferenceController extends BasePreferenceControlle
|
||||
|
||||
@Override
|
||||
public CharSequence getSummary() {
|
||||
return getSummary(true /* batteryStatusUpdate */);
|
||||
}
|
||||
|
||||
private CharSequence getSummary(boolean batteryStatusUpdate) {
|
||||
// Display help message if battery is not present.
|
||||
if (!mIsBatteryPresent) {
|
||||
return mContext.getText(R.string.battery_missing_message);
|
||||
}
|
||||
return getDashboardLabel(mContext, mBatteryInfo);
|
||||
return getDashboardLabel(mContext, mBatteryInfo, batteryStatusUpdate);
|
||||
}
|
||||
|
||||
static CharSequence getDashboardLabel(Context context, BatteryInfo info) {
|
||||
protected CharSequence getDashboardLabel(Context context, BatteryInfo info,
|
||||
boolean batteryStatusUpdate) {
|
||||
if (info == null || context == null) {
|
||||
return null;
|
||||
}
|
||||
CharSequence label;
|
||||
|
||||
if (batteryStatusUpdate) {
|
||||
if (!mBatteryStatusFeatureProvider.triggerBatteryStatusUpdate(this, info)) {
|
||||
mBatteryStatusLabel = null; // will generateLabel()
|
||||
}
|
||||
}
|
||||
|
||||
return (mBatteryStatusLabel == null) ? generateLabel(info) : mBatteryStatusLabel;
|
||||
}
|
||||
|
||||
private CharSequence generateLabel(BatteryInfo info) {
|
||||
if (!info.discharging && info.chargeLabel != null) {
|
||||
label = info.chargeLabel;
|
||||
return info.chargeLabel;
|
||||
} else if (info.remainingLabel == null) {
|
||||
label = info.batteryPercentString;
|
||||
return info.batteryPercentString;
|
||||
} else {
|
||||
label = context.getString(R.string.power_remaining_settings_home_page,
|
||||
return mContext.getString(R.string.power_remaining_settings_home_page,
|
||||
info.batteryPercentString,
|
||||
info.remainingLabel);
|
||||
}
|
||||
return label;
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback which receives text for the label.
|
||||
*/
|
||||
public void updateBatteryStatus(String label, BatteryInfo info) {
|
||||
mBatteryStatusLabel = label; // Null if adaptive charging is not active
|
||||
|
||||
if (mPreference != null) {
|
||||
// Do not triggerBatteryStatusUpdate(), otherwise there will be an infinite loop
|
||||
final CharSequence summary = getSummary(false /* batteryStatusUpdate */);
|
||||
if (summary != null) {
|
||||
mPreference.setSummary(summary);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -147,7 +147,8 @@ public class MediaOutputSlice implements CustomSliceable {
|
||||
.setSourceMetricsCategory(SettingsEnums.PANEL_MEDIA_OUTPUT)
|
||||
.toIntent();
|
||||
final SliceAction primarySliceAction = SliceAction.createDeeplink(
|
||||
PendingIntent.getActivity(mContext, 0 /* requestCode */, intent, 0 /* flags */),
|
||||
PendingIntent.getActivity(mContext, 0 /* requestCode */, intent,
|
||||
PendingIntent.FLAG_IMMUTABLE),
|
||||
IconCompat.createWithResource(mContext, R.drawable.ic_add_24dp/*ic_add_blue_24dp*/),
|
||||
ListBuilder.ICON_IMAGE,
|
||||
mContext.getText(R.string.bluetooth_pairing_pref_title));
|
||||
@@ -248,7 +249,8 @@ public class MediaOutputSlice implements CustomSliceable {
|
||||
.putExtra(MEDIA_DEVICE_ID, id)
|
||||
.setClass(mContext, SliceBroadcastReceiver.class);
|
||||
|
||||
return PendingIntent.getBroadcast(mContext, requestCode, intent, 0);
|
||||
return PendingIntent.getBroadcast(mContext, requestCode, intent,
|
||||
PendingIntent.FLAG_IMMUTABLE);
|
||||
}
|
||||
|
||||
private SliceAction getEndItemSliceAction() {
|
||||
@@ -261,7 +263,8 @@ public class MediaOutputSlice implements CustomSliceable {
|
||||
? 0
|
||||
: getWorker().getPackageName().hashCode();
|
||||
return SliceAction.createDeeplink(
|
||||
PendingIntent.getActivity(mContext, requestCode, intent, 0 /* flags */),
|
||||
PendingIntent.getActivity(mContext, requestCode, intent,
|
||||
PendingIntent.FLAG_IMMUTABLE),
|
||||
IconCompat.createWithResource(mContext, R.drawable.ic_add_blue_24dp),
|
||||
ListBuilder.ICON_IMAGE,
|
||||
mContext.getText(R.string.add));
|
||||
@@ -350,7 +353,7 @@ public class MediaOutputSlice implements CustomSliceable {
|
||||
intent.putExtra(MEDIA_DEVICE_ID, id);
|
||||
intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
|
||||
return PendingIntent.getBroadcast(context, requestCode, intent,
|
||||
PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -342,7 +342,7 @@ public class ApnSettings extends RestrictedSettingsFragment
|
||||
pref.setSummary(apn);
|
||||
}
|
||||
|
||||
final boolean selectable = ((type == null) || !type.equals("mms"));
|
||||
final boolean selectable = ((type == null) || type.contains("default"));
|
||||
pref.setSelectable(selectable);
|
||||
if (selectable) {
|
||||
if ((mSelectedKey != null) && mSelectedKey.equals(key)) {
|
||||
|
||||
@@ -44,6 +44,7 @@ import androidx.fragment.app.FragmentActivity;
|
||||
|
||||
import com.android.internal.widget.LockPatternUtils;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.HideNonSystemOverlayMixin;
|
||||
import com.android.settings.password.ChooseLockSettingsHelper;
|
||||
import com.android.settings.vpn2.VpnUtils;
|
||||
|
||||
@@ -74,6 +75,7 @@ public final class CredentialStorage extends FragmentActivity {
|
||||
protected void onCreate(Bundle savedState) {
|
||||
super.onCreate(savedState);
|
||||
mUtils = new LockPatternUtils(this);
|
||||
getLifecycle().addObserver(new HideNonSystemOverlayMixin(this));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -44,7 +44,7 @@ public class AndroidKeystoreAliasLoader {
|
||||
private final Collection<String> mKeyCertAliases;
|
||||
private final Collection<String> mCaCertAliases;
|
||||
/**
|
||||
* This Constructor loads all aliases of asymmetric key pairs and certificates in the
|
||||
* This Constructor loads all aliases of asymmetric keys pairs and certificates in the
|
||||
* AndroidKeyStore within the given namespace.
|
||||
* Viable namespaces are {@link KeyProperties#NAMESPACE_WIFI},
|
||||
* {@link KeyProperties#NAMESPACE_APPLICATION}, or null. The latter two are equivalent in
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package com.android.settings.vpn2;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.app.admin.DevicePolicyManager;
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.pm.PackageInfo;
|
||||
@@ -48,6 +49,7 @@ public class AppDialogFragment extends InstrumentedDialogFragment implements App
|
||||
private Listener mListener;
|
||||
|
||||
private UserManager mUserManager;
|
||||
private DevicePolicyManager mDevicePolicyManager;
|
||||
private VpnManager mVpnManager;
|
||||
|
||||
@Override
|
||||
@@ -91,7 +93,11 @@ public class AppDialogFragment extends InstrumentedDialogFragment implements App
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
mPackageInfo = getArguments().getParcelable(ARG_PACKAGE);
|
||||
mUserManager = UserManager.get(getContext());
|
||||
mDevicePolicyManager = getContext()
|
||||
.createContextAsUser(UserHandle.of(getUserId()), /* flags= */ 0)
|
||||
.getSystemService(DevicePolicyManager.class);
|
||||
mVpnManager = getContext().getSystemService(VpnManager.class);
|
||||
}
|
||||
|
||||
@@ -101,7 +107,6 @@ public class AppDialogFragment extends InstrumentedDialogFragment implements App
|
||||
final String label = args.getString(ARG_LABEL);
|
||||
boolean managing = args.getBoolean(ARG_MANAGING);
|
||||
boolean connected = args.getBoolean(ARG_CONNECTED);
|
||||
mPackageInfo = args.getParcelable(ARG_PACKAGE);
|
||||
|
||||
if (managing) {
|
||||
return new AppDialog(getActivity(), this, mPackageInfo, label);
|
||||
@@ -163,7 +168,10 @@ public class AppDialogFragment extends InstrumentedDialogFragment implements App
|
||||
|
||||
private boolean isUiRestricted() {
|
||||
final UserHandle userHandle = UserHandle.of(getUserId());
|
||||
return mUserManager.hasUserRestriction(UserManager.DISALLOW_CONFIG_VPN, userHandle);
|
||||
if (mUserManager.hasUserRestriction(UserManager.DISALLOW_CONFIG_VPN, userHandle)) {
|
||||
return true;
|
||||
}
|
||||
return mPackageInfo.packageName.equals(mDevicePolicyManager.getAlwaysOnVpnPackage());
|
||||
}
|
||||
|
||||
private int getUserId() {
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package com.android.settings.vpn2;
|
||||
|
||||
import android.app.admin.DevicePolicyManager;
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
@@ -26,6 +27,8 @@ import androidx.preference.Preference;
|
||||
|
||||
import com.android.internal.net.LegacyVpnInfo;
|
||||
import com.android.internal.net.VpnConfig;
|
||||
import com.android.settingslib.RestrictedLockUtils;
|
||||
import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
|
||||
|
||||
/**
|
||||
* {@link androidx.preference.Preference} containing information about a VPN
|
||||
@@ -43,6 +46,7 @@ public class AppPreference extends ManageablePreference {
|
||||
super.setUserId(userId);
|
||||
|
||||
mPackageName = packageName;
|
||||
disableIfConfiguredByAdmin();
|
||||
|
||||
// Fetch icon and VPN label
|
||||
String label = packageName;
|
||||
@@ -74,6 +78,25 @@ public class AppPreference extends ManageablePreference {
|
||||
setIcon(icon);
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable this preference if VPN is set as always on by a profile or device owner.
|
||||
* NB: it should be called after super.setUserId() otherwise admin information can be lost.
|
||||
*/
|
||||
private void disableIfConfiguredByAdmin() {
|
||||
if (isDisabledByAdmin()) {
|
||||
// Already disabled due to user restriction.
|
||||
return;
|
||||
}
|
||||
final DevicePolicyManager dpm = getContext()
|
||||
.createContextAsUser(UserHandle.of(getUserId()), /* flags= */ 0)
|
||||
.getSystemService(DevicePolicyManager.class);
|
||||
if (mPackageName.equals(dpm.getAlwaysOnVpnPackage())) {
|
||||
final EnforcedAdmin admin = RestrictedLockUtils.getProfileOrDeviceOwner(
|
||||
getContext(), UserHandle.of(mUserId));
|
||||
setDisabledByAdmin(admin);
|
||||
}
|
||||
}
|
||||
|
||||
public PackageInfo getPackageInfo() {
|
||||
try {
|
||||
PackageManager pm = getUserContext().getPackageManager();
|
||||
|
||||
@@ -25,6 +25,7 @@ import android.content.pm.PackageManager;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.os.Bundle;
|
||||
import android.text.TextUtils;
|
||||
import android.view.WindowManager;
|
||||
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.fragment.app.DialogFragment;
|
||||
@@ -43,6 +44,8 @@ public class WifiScanModeActivity extends FragmentActivity {
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
getWindow().addSystemFlags(
|
||||
WindowManager.LayoutParams.SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS);
|
||||
Intent intent = getIntent();
|
||||
if (savedInstanceState == null) {
|
||||
if (intent != null && WifiManager.ACTION_REQUEST_SCAN_ALWAYS_AVAILABLE
|
||||
|
||||
@@ -75,7 +75,8 @@ public class WifiNetworkDetailsFragment2 extends DashboardFragment implements
|
||||
// Interval between initiating SavedNetworkTracker scans
|
||||
private static final long SCAN_INTERVAL_MILLIS = 10_000;
|
||||
|
||||
private NetworkDetailsTracker mNetworkDetailsTracker;
|
||||
@VisibleForTesting
|
||||
NetworkDetailsTracker mNetworkDetailsTracker;
|
||||
private HandlerThread mWorkerThread;
|
||||
private WifiDetailPreferenceController2 mWifiDetailPreferenceController2;
|
||||
private List<WifiDialog2.WifiDialog2Listener> mWifiDialogListeners = new ArrayList<>();
|
||||
@@ -125,9 +126,11 @@ public class WifiNetworkDetailsFragment2 extends DashboardFragment implements
|
||||
|
||||
@Override
|
||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||
MenuItem item = menu.add(0, Menu.FIRST, 0, R.string.wifi_modify);
|
||||
item.setIcon(com.android.internal.R.drawable.ic_mode_edit);
|
||||
item.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
|
||||
if (isEditable()) {
|
||||
MenuItem item = menu.add(0, Menu.FIRST, 0, R.string.wifi_modify);
|
||||
item.setIcon(com.android.internal.R.drawable.ic_mode_edit);
|
||||
item.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
|
||||
}
|
||||
super.onCreateOptionsMenu(menu, inflater);
|
||||
}
|
||||
|
||||
@@ -253,6 +256,17 @@ public class WifiNetworkDetailsFragment2 extends DashboardFragment implements
|
||||
getArguments().getString(KEY_CHOSEN_WIFIENTRY_KEY));
|
||||
}
|
||||
|
||||
private boolean isEditable() {
|
||||
if (mNetworkDetailsTracker == null) {
|
||||
return false;
|
||||
}
|
||||
final WifiEntry wifiEntry = mNetworkDetailsTracker.getWifiEntry();
|
||||
if (wifiEntry == null) {
|
||||
return false;
|
||||
}
|
||||
return wifiEntry.isSaved();
|
||||
}
|
||||
|
||||
/**
|
||||
* API call for refreshing the preferences in this fragment.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user