DO NOT MERGE: Cherry-pick misc fixes to AOSP
Remove wrapper for LocationManager Remove LocationManagerWrapper from SettingsLib Bug: 76167422 Test: RunSettingsRoboTests Remove OverlayManagerWrapper class out from Settings Remove OverlayManagerWrapper and use IOverlayManager instead. Based on comment from reviewer to refactor ThemePreferenceController. Bug: 76167422 Test: RunSettingsRoboTests Change-Id: I13a7997b5e21a16ffb723971d267132fbf65e4a6
This commit is contained in:
@@ -19,18 +19,21 @@ package com.android.settings.development;
|
||||
import static android.os.UserHandle.USER_SYSTEM;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.om.IOverlayManager;
|
||||
import android.content.om.OverlayInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.RemoteException;
|
||||
import android.os.ServiceManager;
|
||||
import android.text.TextUtils;
|
||||
import android.view.DisplayCutout;
|
||||
|
||||
import android.support.annotation.VisibleForTesting;
|
||||
import android.support.v7.preference.ListPreference;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
import android.text.TextUtils;
|
||||
import android.view.DisplayCutout;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.PreferenceControllerMixin;
|
||||
import com.android.settings.wrapper.OverlayManagerWrapper;
|
||||
import com.android.settings.wrapper.OverlayManagerWrapper.OverlayInfo;
|
||||
import com.android.settingslib.development.DeveloperOptionsPreferenceController;
|
||||
|
||||
import java.util.List;
|
||||
@@ -41,7 +44,7 @@ public class EmulateDisplayCutoutPreferenceController extends
|
||||
|
||||
private static final String KEY = "display_cutout_emulation";
|
||||
|
||||
private final OverlayManagerWrapper mOverlayManager;
|
||||
private final IOverlayManager mOverlayManager;
|
||||
private final boolean mAvailable;
|
||||
|
||||
private ListPreference mPreference;
|
||||
@@ -49,7 +52,7 @@ public class EmulateDisplayCutoutPreferenceController extends
|
||||
|
||||
@VisibleForTesting
|
||||
EmulateDisplayCutoutPreferenceController(Context context, PackageManager packageManager,
|
||||
OverlayManagerWrapper overlayManager) {
|
||||
IOverlayManager overlayManager) {
|
||||
super(context);
|
||||
mOverlayManager = overlayManager;
|
||||
mPackageManager = packageManager;
|
||||
@@ -57,7 +60,8 @@ public class EmulateDisplayCutoutPreferenceController extends
|
||||
}
|
||||
|
||||
public EmulateDisplayCutoutPreferenceController(Context context) {
|
||||
this(context, context.getPackageManager(), new OverlayManagerWrapper());
|
||||
this(context, context.getPackageManager(), IOverlayManager.Stub
|
||||
.asInterface(ServiceManager.getService(Context.OVERLAY_SERVICE)));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -102,10 +106,14 @@ public class EmulateDisplayCutoutPreferenceController extends
|
||||
}
|
||||
|
||||
final boolean result;
|
||||
if (TextUtils.isEmpty(packageName)) {
|
||||
result = mOverlayManager.setEnabled(currentPackageName, false, USER_SYSTEM);
|
||||
} else {
|
||||
result = mOverlayManager.setEnabledExclusiveInCategory(packageName, USER_SYSTEM);
|
||||
try {
|
||||
if (TextUtils.isEmpty(packageName)) {
|
||||
result = mOverlayManager.setEnabled(currentPackageName, false, USER_SYSTEM);
|
||||
} else {
|
||||
result = mOverlayManager.setEnabledExclusiveInCategory(packageName, USER_SYSTEM);
|
||||
}
|
||||
} catch (RemoteException re) {
|
||||
throw re.rethrowFromSystemServer();
|
||||
}
|
||||
updateState(mPreference);
|
||||
return result;
|
||||
@@ -145,13 +153,17 @@ public class EmulateDisplayCutoutPreferenceController extends
|
||||
}
|
||||
|
||||
private OverlayInfo[] getOverlayInfos() {
|
||||
@SuppressWarnings("unchecked") List<OverlayInfo> overlayInfos =
|
||||
mOverlayManager.getOverlayInfosForTarget("android", USER_SYSTEM);
|
||||
for (int i = overlayInfos.size() - 1; i >= 0; i--) {
|
||||
if (!DisplayCutout.EMULATION_OVERLAY_CATEGORY.equals(
|
||||
overlayInfos.get(i).category)) {
|
||||
overlayInfos.remove(i);
|
||||
List<OverlayInfo> overlayInfos;
|
||||
try {
|
||||
overlayInfos = mOverlayManager.getOverlayInfosForTarget("android", USER_SYSTEM);
|
||||
for (int i = overlayInfos.size() - 1; i >= 0; i--) {
|
||||
if (!DisplayCutout.EMULATION_OVERLAY_CATEGORY.equals(
|
||||
overlayInfos.get(i).category)) {
|
||||
overlayInfos.remove(i);
|
||||
}
|
||||
}
|
||||
} catch (RemoteException re) {
|
||||
throw re.rethrowFromSystemServer();
|
||||
}
|
||||
return overlayInfos.toArray(new OverlayInfo[overlayInfos.size()]);
|
||||
}
|
||||
|
@@ -13,7 +13,11 @@
|
||||
*/
|
||||
package com.android.settings.display;
|
||||
|
||||
import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.ACTION_THEME;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.om.IOverlayManager;
|
||||
import android.content.om.OverlayInfo;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.PackageManager.NameNotFoundException;
|
||||
@@ -23,13 +27,12 @@ import android.os.UserHandle;
|
||||
import android.support.annotation.VisibleForTesting;
|
||||
import android.support.v7.preference.ListPreference;
|
||||
import android.support.v7.preference.Preference;
|
||||
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.PreferenceControllerMixin;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settings.wrapper.OverlayManagerWrapper;
|
||||
import com.android.settings.wrapper.OverlayManagerWrapper.OverlayInfo;
|
||||
import com.android.settingslib.core.AbstractPreferenceController;
|
||||
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
|
||||
|
||||
@@ -37,24 +40,22 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.ACTION_THEME;
|
||||
|
||||
public class ThemePreferenceController extends AbstractPreferenceController implements
|
||||
PreferenceControllerMixin, Preference.OnPreferenceChangeListener {
|
||||
|
||||
private static final String KEY_THEME = "theme";
|
||||
|
||||
private final MetricsFeatureProvider mMetricsFeatureProvider;
|
||||
private final OverlayManagerWrapper mOverlayService;
|
||||
private final IOverlayManager mOverlayService;
|
||||
private final PackageManager mPackageManager;
|
||||
|
||||
public ThemePreferenceController(Context context) {
|
||||
this(context, ServiceManager.getService(Context.OVERLAY_SERVICE) != null
|
||||
? new OverlayManagerWrapper() : null);
|
||||
this(context, IOverlayManager.Stub
|
||||
.asInterface(ServiceManager.getService(Context.OVERLAY_SERVICE)));
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
ThemePreferenceController(Context context, OverlayManagerWrapper overlayManager) {
|
||||
ThemePreferenceController(Context context, IOverlayManager overlayManager) {
|
||||
super(context);
|
||||
mOverlayService = overlayManager;
|
||||
mPackageManager = context.getPackageManager();
|
||||
@@ -77,7 +78,7 @@ public class ThemePreferenceController extends AbstractPreferenceController impl
|
||||
@Override
|
||||
public void updateState(Preference preference) {
|
||||
ListPreference pref = (ListPreference) preference;
|
||||
String[] pkgs = getAvailableThemes();
|
||||
String[] pkgs = getAvailableThemes(false /* currentThemeOnly */);
|
||||
CharSequence[] labels = new CharSequence[pkgs.length];
|
||||
for (int i = 0; i < pkgs.length; i++) {
|
||||
try {
|
||||
@@ -109,11 +110,15 @@ public class ThemePreferenceController extends AbstractPreferenceController impl
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
String current = getTheme();
|
||||
String current = getCurrentTheme();
|
||||
if (Objects.equals(newValue, current)) {
|
||||
return true;
|
||||
}
|
||||
mOverlayService.setEnabledExclusiveInCategory((String) newValue, UserHandle.myUserId());
|
||||
try {
|
||||
mOverlayService.setEnabledExclusiveInCategory((String) newValue, UserHandle.myUserId());
|
||||
} catch (RemoteException re) {
|
||||
throw re.rethrowFromSystemServer();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -129,39 +134,43 @@ public class ThemePreferenceController extends AbstractPreferenceController impl
|
||||
}
|
||||
}
|
||||
|
||||
private String getTheme() {
|
||||
List<OverlayInfo> infos = mOverlayService.getOverlayInfosForTarget("android",
|
||||
UserHandle.myUserId());
|
||||
for (int i = 0, size = infos.size(); i < size; i++) {
|
||||
if (infos.get(i).isEnabled() && isTheme(infos.get(i))) {
|
||||
return infos.get(i).packageName;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAvailable() {
|
||||
if (mOverlayService == null) return false;
|
||||
String[] themes = getAvailableThemes();
|
||||
String[] themes = getAvailableThemes(false /* currentThemeOnly */);
|
||||
return themes != null && themes.length > 1;
|
||||
}
|
||||
|
||||
|
||||
@VisibleForTesting
|
||||
String getCurrentTheme() {
|
||||
return getTheme();
|
||||
String[] themePackages = getAvailableThemes(true /* currentThemeOnly */);
|
||||
return themePackages.length < 1 ? null : themePackages[0];
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
String[] getAvailableThemes() {
|
||||
List<OverlayInfo> infos = mOverlayService.getOverlayInfosForTarget("android",
|
||||
UserHandle.myUserId());
|
||||
List<String> pkgs = new ArrayList<>(infos.size());
|
||||
for (int i = 0, size = infos.size(); i < size; i++) {
|
||||
if (isTheme(infos.get(i))) {
|
||||
pkgs.add(infos.get(i).packageName);
|
||||
String[] getAvailableThemes(boolean currentThemeOnly) {
|
||||
List<OverlayInfo> infos;
|
||||
List<String> pkgs;
|
||||
try {
|
||||
infos = mOverlayService.getOverlayInfosForTarget("android", UserHandle.myUserId());
|
||||
pkgs = new ArrayList<>(infos.size());
|
||||
for (int i = 0, size = infos.size(); i < size; i++) {
|
||||
if (isTheme(infos.get(i))) {
|
||||
if (infos.get(i).isEnabled() && currentThemeOnly) {
|
||||
return new String[] {infos.get(i).packageName};
|
||||
} else {
|
||||
pkgs.add(infos.get(i).packageName);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (RemoteException re) {
|
||||
throw re.rethrowFromSystemServer();
|
||||
}
|
||||
|
||||
// Current enabled theme is not found.
|
||||
if (currentThemeOnly) {
|
||||
return new String[0];
|
||||
}
|
||||
return pkgs.toArray(new String[pkgs.size()]);
|
||||
}
|
||||
|
@@ -1,102 +0,0 @@
|
||||
/*
|
||||
* 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.settings.wrapper;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.om.IOverlayManager;
|
||||
import android.content.om.OverlayInfo;
|
||||
import android.os.RemoteException;
|
||||
import android.os.ServiceManager;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class OverlayManagerWrapper {
|
||||
|
||||
private final IOverlayManager mOverlayManager;
|
||||
|
||||
public OverlayManagerWrapper(IOverlayManager overlayManager) {
|
||||
mOverlayManager = overlayManager;
|
||||
}
|
||||
|
||||
public OverlayManagerWrapper() {
|
||||
this(IOverlayManager.Stub.asInterface(ServiceManager.getService(Context.OVERLAY_SERVICE)));
|
||||
}
|
||||
|
||||
public List<OverlayInfo> getOverlayInfosForTarget(String overlay, int userId) {
|
||||
if (mOverlayManager == null) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
try {
|
||||
List<android.content.om.OverlayInfo> infos
|
||||
= mOverlayManager.getOverlayInfosForTarget(overlay, userId);
|
||||
ArrayList<OverlayInfo> result = new ArrayList<>(infos.size());
|
||||
for (int i = 0; i < infos.size(); i++) {
|
||||
result.add(new OverlayInfo(infos.get(i)));
|
||||
}
|
||||
return result;
|
||||
} catch (RemoteException e) {
|
||||
throw e.rethrowFromSystemServer();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean setEnabled(String overlay, boolean enabled, int userId) {
|
||||
if (mOverlayManager == null) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
return mOverlayManager.setEnabled(overlay, enabled, userId);
|
||||
} catch (RemoteException e) {
|
||||
throw e.rethrowFromSystemServer();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean setEnabledExclusiveInCategory(String overlay, int userId) {
|
||||
if (mOverlayManager == null) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
return mOverlayManager.setEnabledExclusiveInCategory(overlay, userId);
|
||||
} catch (RemoteException e) {
|
||||
throw e.rethrowFromSystemServer();
|
||||
}
|
||||
}
|
||||
|
||||
public static class OverlayInfo {
|
||||
|
||||
public static final String CATEGORY_THEME = android.content.om.OverlayInfo.CATEGORY_THEME;
|
||||
public final String packageName;
|
||||
public final String category;
|
||||
private final boolean mEnabled;
|
||||
|
||||
public OverlayInfo(String packageName, String category, boolean enabled) {
|
||||
this.packageName = packageName;
|
||||
this.category = category;
|
||||
mEnabled = enabled;
|
||||
}
|
||||
|
||||
public OverlayInfo(android.content.om.OverlayInfo info) {
|
||||
mEnabled = info.isEnabled();
|
||||
category = info.category;
|
||||
packageName = info.packageName;
|
||||
}
|
||||
|
||||
public boolean isEnabled() {
|
||||
return mEnabled;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user