Merge "Create static inner class for UiModeManager" into udc-qpr-dev am: 7283fc8be6
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/23892146 Change-Id: I068cfb10a4fa5a019bf35323282df7db7ce3e2a4 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -315,7 +315,7 @@ public class UiModeManager {
|
|||||||
@SystemApi
|
@SystemApi
|
||||||
public static final int MODE_NIGHT_CUSTOM_TYPE_BEDTIME = 1;
|
public static final int MODE_NIGHT_CUSTOM_TYPE_BEDTIME = 1;
|
||||||
|
|
||||||
private IUiModeManager mService;
|
private static Globals sGlobals;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Context required for getting the opPackageName of API caller; maybe be {@code null} if the
|
* Context required for getting the opPackageName of API caller; maybe be {@code null} if the
|
||||||
@@ -341,6 +341,60 @@ public class UiModeManager {
|
|||||||
mOnProjectionStateChangedListenerResourceManager =
|
mOnProjectionStateChangedListenerResourceManager =
|
||||||
new OnProjectionStateChangedListenerResourceManager();
|
new OnProjectionStateChangedListenerResourceManager();
|
||||||
|
|
||||||
|
private static class Globals extends IUiModeManagerCallback.Stub {
|
||||||
|
|
||||||
|
private final IUiModeManager mService;
|
||||||
|
private final Object mGlobalsLock = new Object();
|
||||||
|
|
||||||
|
private float mContrast = ContrastUtils.CONTRAST_DEFAULT_VALUE;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Map that stores user provided {@link ContrastChangeListener} callbacks,
|
||||||
|
* and the executors on which these callbacks should be called.
|
||||||
|
*/
|
||||||
|
private final ArrayMap<ContrastChangeListener, Executor>
|
||||||
|
mContrastChangeListeners = new ArrayMap<>();
|
||||||
|
|
||||||
|
Globals(IUiModeManager service) {
|
||||||
|
mService = service;
|
||||||
|
try {
|
||||||
|
mService.addCallback(this);
|
||||||
|
mContrast = mService.getContrast();
|
||||||
|
} catch (RemoteException e) {
|
||||||
|
Log.e(TAG, "Setup failed: UiModeManagerService is dead", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private float getContrast() {
|
||||||
|
synchronized (mGlobalsLock) {
|
||||||
|
return mContrast;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addContrastChangeListener(ContrastChangeListener listener, Executor executor) {
|
||||||
|
synchronized (mGlobalsLock) {
|
||||||
|
mContrastChangeListeners.put(listener, executor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void removeContrastChangeListener(ContrastChangeListener listener) {
|
||||||
|
synchronized (mGlobalsLock) {
|
||||||
|
mContrastChangeListeners.remove(listener);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void notifyContrastChanged(float contrast) {
|
||||||
|
synchronized (mGlobalsLock) {
|
||||||
|
// if value changed in the settings, update the cached value and notify listeners
|
||||||
|
if (Math.abs(mContrast - contrast) < 1e-10) return;
|
||||||
|
mContrast = contrast;
|
||||||
|
mContrastChangeListeners.forEach((listener, executor) -> executor.execute(
|
||||||
|
() -> listener.onContrastChanged(contrast)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Define constants and conversions between {@link ContrastLevel}s and contrast values.
|
* Define constants and conversions between {@link ContrastLevel}s and contrast values.
|
||||||
* <p>
|
* <p>
|
||||||
@@ -407,43 +461,18 @@ public class UiModeManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Map that stores user provided {@link ContrastChangeListener} callbacks,
|
|
||||||
* and the executors on which these callbacks should be called.
|
|
||||||
*/
|
|
||||||
private final ArrayMap<ContrastChangeListener, Executor>
|
|
||||||
mContrastChangeListeners = new ArrayMap<>();
|
|
||||||
private float mContrast;
|
|
||||||
|
|
||||||
private final IUiModeManagerCallback.Stub mCallback = new IUiModeManagerCallback.Stub() {
|
|
||||||
@Override
|
|
||||||
public void notifyContrastChanged(float contrast) {
|
|
||||||
final ArrayMap<ContrastChangeListener, Executor> listeners;
|
|
||||||
synchronized (mLock) {
|
|
||||||
// if value changed in the settings, update the cached value and notify listeners
|
|
||||||
if (Math.abs(mContrast - contrast) < 1e-10) return;
|
|
||||||
mContrast = contrast;
|
|
||||||
listeners = new ArrayMap<>(mContrastChangeListeners);
|
|
||||||
}
|
|
||||||
listeners.forEach((listener, executor) -> executor.execute(
|
|
||||||
() -> listener.onContrastChanged(mContrast)));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
@UnsupportedAppUsage
|
@UnsupportedAppUsage
|
||||||
/*package*/ UiModeManager() throws ServiceNotFoundException {
|
/*package*/ UiModeManager() throws ServiceNotFoundException {
|
||||||
this(null /* context */);
|
this(null /* context */);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*package*/ UiModeManager(Context context) throws ServiceNotFoundException {
|
/*package*/ UiModeManager(Context context) throws ServiceNotFoundException {
|
||||||
mService = IUiModeManager.Stub.asInterface(
|
IUiModeManager service = IUiModeManager.Stub.asInterface(
|
||||||
ServiceManager.getServiceOrThrow(Context.UI_MODE_SERVICE));
|
ServiceManager.getServiceOrThrow(Context.UI_MODE_SERVICE));
|
||||||
mContext = context;
|
mContext = context;
|
||||||
try {
|
if (service == null) return;
|
||||||
mService.addCallback(mCallback);
|
synchronized (mLock) {
|
||||||
mContrast = mService.getContrast();
|
if (sGlobals == null) sGlobals = new Globals(service);
|
||||||
} catch (RemoteException e) {
|
|
||||||
Log.e(TAG, "Setup failed: UiModeManagerService is dead", e);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -533,9 +562,9 @@ public class UiModeManager {
|
|||||||
@SystemApi
|
@SystemApi
|
||||||
@RequiresPermission(android.Manifest.permission.ENTER_CAR_MODE_PRIORITIZED)
|
@RequiresPermission(android.Manifest.permission.ENTER_CAR_MODE_PRIORITIZED)
|
||||||
public void enableCarMode(@IntRange(from = 0) int priority, @EnableCarMode int flags) {
|
public void enableCarMode(@IntRange(from = 0) int priority, @EnableCarMode int flags) {
|
||||||
if (mService != null) {
|
if (sGlobals != null) {
|
||||||
try {
|
try {
|
||||||
mService.enableCarMode(flags, priority,
|
sGlobals.mService.enableCarMode(flags, priority,
|
||||||
mContext == null ? null : mContext.getOpPackageName());
|
mContext == null ? null : mContext.getOpPackageName());
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
throw e.rethrowFromSystemServer();
|
throw e.rethrowFromSystemServer();
|
||||||
@@ -585,9 +614,9 @@ public class UiModeManager {
|
|||||||
* @param flags One of the disable car mode flags.
|
* @param flags One of the disable car mode flags.
|
||||||
*/
|
*/
|
||||||
public void disableCarMode(@DisableCarMode int flags) {
|
public void disableCarMode(@DisableCarMode int flags) {
|
||||||
if (mService != null) {
|
if (sGlobals != null) {
|
||||||
try {
|
try {
|
||||||
mService.disableCarModeByCallingPackage(flags,
|
sGlobals.mService.disableCarModeByCallingPackage(flags,
|
||||||
mContext == null ? null : mContext.getOpPackageName());
|
mContext == null ? null : mContext.getOpPackageName());
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
throw e.rethrowFromSystemServer();
|
throw e.rethrowFromSystemServer();
|
||||||
@@ -606,9 +635,9 @@ public class UiModeManager {
|
|||||||
* {@link Configuration#UI_MODE_TYPE_VR_HEADSET Configuration.UI_MODE_TYPE_VR_HEADSET}.
|
* {@link Configuration#UI_MODE_TYPE_VR_HEADSET Configuration.UI_MODE_TYPE_VR_HEADSET}.
|
||||||
*/
|
*/
|
||||||
public int getCurrentModeType() {
|
public int getCurrentModeType() {
|
||||||
if (mService != null) {
|
if (sGlobals != null) {
|
||||||
try {
|
try {
|
||||||
return mService.getCurrentModeType();
|
return sGlobals.mService.getCurrentModeType();
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
throw e.rethrowFromSystemServer();
|
throw e.rethrowFromSystemServer();
|
||||||
}
|
}
|
||||||
@@ -653,9 +682,9 @@ public class UiModeManager {
|
|||||||
* @see #setApplicationNightMode(int)
|
* @see #setApplicationNightMode(int)
|
||||||
*/
|
*/
|
||||||
public void setNightMode(@NightMode int mode) {
|
public void setNightMode(@NightMode int mode) {
|
||||||
if (mService != null) {
|
if (sGlobals != null) {
|
||||||
try {
|
try {
|
||||||
mService.setNightMode(mode);
|
sGlobals.mService.setNightMode(mode);
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
throw e.rethrowFromSystemServer();
|
throw e.rethrowFromSystemServer();
|
||||||
}
|
}
|
||||||
@@ -674,9 +703,9 @@ public class UiModeManager {
|
|||||||
@SystemApi
|
@SystemApi
|
||||||
@RequiresPermission(android.Manifest.permission.MODIFY_DAY_NIGHT_MODE)
|
@RequiresPermission(android.Manifest.permission.MODIFY_DAY_NIGHT_MODE)
|
||||||
public void setNightModeCustomType(@NightModeCustomType int nightModeCustomType) {
|
public void setNightModeCustomType(@NightModeCustomType int nightModeCustomType) {
|
||||||
if (mService != null) {
|
if (sGlobals != null) {
|
||||||
try {
|
try {
|
||||||
mService.setNightModeCustomType(nightModeCustomType);
|
sGlobals.mService.setNightModeCustomType(nightModeCustomType);
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
throw e.rethrowFromSystemServer();
|
throw e.rethrowFromSystemServer();
|
||||||
}
|
}
|
||||||
@@ -693,9 +722,9 @@ public class UiModeManager {
|
|||||||
@SystemApi
|
@SystemApi
|
||||||
@RequiresPermission(android.Manifest.permission.MODIFY_DAY_NIGHT_MODE)
|
@RequiresPermission(android.Manifest.permission.MODIFY_DAY_NIGHT_MODE)
|
||||||
public @NightModeCustomReturnType int getNightModeCustomType() {
|
public @NightModeCustomReturnType int getNightModeCustomType() {
|
||||||
if (mService != null) {
|
if (sGlobals != null) {
|
||||||
try {
|
try {
|
||||||
return mService.getNightModeCustomType();
|
return sGlobals.mService.getNightModeCustomType();
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
throw e.rethrowFromSystemServer();
|
throw e.rethrowFromSystemServer();
|
||||||
}
|
}
|
||||||
@@ -732,9 +761,9 @@ public class UiModeManager {
|
|||||||
* @see #setNightMode(int)
|
* @see #setNightMode(int)
|
||||||
*/
|
*/
|
||||||
public void setApplicationNightMode(@NightMode int mode) {
|
public void setApplicationNightMode(@NightMode int mode) {
|
||||||
if (mService != null) {
|
if (sGlobals != null) {
|
||||||
try {
|
try {
|
||||||
mService.setApplicationNightMode(mode);
|
sGlobals.mService.setApplicationNightMode(mode);
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
throw e.rethrowFromSystemServer();
|
throw e.rethrowFromSystemServer();
|
||||||
}
|
}
|
||||||
@@ -757,9 +786,9 @@ public class UiModeManager {
|
|||||||
* @see #setNightMode(int)
|
* @see #setNightMode(int)
|
||||||
*/
|
*/
|
||||||
public @NightMode int getNightMode() {
|
public @NightMode int getNightMode() {
|
||||||
if (mService != null) {
|
if (sGlobals != null) {
|
||||||
try {
|
try {
|
||||||
return mService.getNightMode();
|
return sGlobals.mService.getNightMode();
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
throw e.rethrowFromSystemServer();
|
throw e.rethrowFromSystemServer();
|
||||||
}
|
}
|
||||||
@@ -774,9 +803,9 @@ public class UiModeManager {
|
|||||||
*/
|
*/
|
||||||
@TestApi
|
@TestApi
|
||||||
public boolean isUiModeLocked() {
|
public boolean isUiModeLocked() {
|
||||||
if (mService != null) {
|
if (sGlobals != null) {
|
||||||
try {
|
try {
|
||||||
return mService.isUiModeLocked();
|
return sGlobals.mService.isUiModeLocked();
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
throw e.rethrowFromSystemServer();
|
throw e.rethrowFromSystemServer();
|
||||||
}
|
}
|
||||||
@@ -796,9 +825,9 @@ public class UiModeManager {
|
|||||||
*/
|
*/
|
||||||
@TestApi
|
@TestApi
|
||||||
public boolean isNightModeLocked() {
|
public boolean isNightModeLocked() {
|
||||||
if (mService != null) {
|
if (sGlobals != null) {
|
||||||
try {
|
try {
|
||||||
return mService.isNightModeLocked();
|
return sGlobals.mService.isNightModeLocked();
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
throw e.rethrowFromSystemServer();
|
throw e.rethrowFromSystemServer();
|
||||||
}
|
}
|
||||||
@@ -820,9 +849,10 @@ public class UiModeManager {
|
|||||||
@RequiresPermission(android.Manifest.permission.MODIFY_DAY_NIGHT_MODE)
|
@RequiresPermission(android.Manifest.permission.MODIFY_DAY_NIGHT_MODE)
|
||||||
public boolean setNightModeActivatedForCustomMode(@NightModeCustomType int nightModeCustomType,
|
public boolean setNightModeActivatedForCustomMode(@NightModeCustomType int nightModeCustomType,
|
||||||
boolean active) {
|
boolean active) {
|
||||||
if (mService != null) {
|
if (sGlobals != null) {
|
||||||
try {
|
try {
|
||||||
return mService.setNightModeActivatedForCustomMode(nightModeCustomType, active);
|
return sGlobals.mService.setNightModeActivatedForCustomMode(
|
||||||
|
nightModeCustomType, active);
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
throw e.rethrowFromSystemServer();
|
throw e.rethrowFromSystemServer();
|
||||||
}
|
}
|
||||||
@@ -838,9 +868,9 @@ public class UiModeManager {
|
|||||||
*/
|
*/
|
||||||
@RequiresPermission(android.Manifest.permission.MODIFY_DAY_NIGHT_MODE)
|
@RequiresPermission(android.Manifest.permission.MODIFY_DAY_NIGHT_MODE)
|
||||||
public boolean setNightModeActivated(boolean active) {
|
public boolean setNightModeActivated(boolean active) {
|
||||||
if (mService != null) {
|
if (sGlobals != null) {
|
||||||
try {
|
try {
|
||||||
return mService.setNightModeActivated(active);
|
return sGlobals.mService.setNightModeActivated(active);
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
throw e.rethrowFromSystemServer();
|
throw e.rethrowFromSystemServer();
|
||||||
}
|
}
|
||||||
@@ -856,9 +886,9 @@ public class UiModeManager {
|
|||||||
*/
|
*/
|
||||||
@NonNull
|
@NonNull
|
||||||
public LocalTime getCustomNightModeStart() {
|
public LocalTime getCustomNightModeStart() {
|
||||||
if (mService != null) {
|
if (sGlobals != null) {
|
||||||
try {
|
try {
|
||||||
return LocalTime.ofNanoOfDay(mService.getCustomNightModeStart() * 1000);
|
return LocalTime.ofNanoOfDay(sGlobals.mService.getCustomNightModeStart() * 1000);
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
throw e.rethrowFromSystemServer();
|
throw e.rethrowFromSystemServer();
|
||||||
}
|
}
|
||||||
@@ -874,9 +904,9 @@ public class UiModeManager {
|
|||||||
* @param time The time of the day Dark theme should activate
|
* @param time The time of the day Dark theme should activate
|
||||||
*/
|
*/
|
||||||
public void setCustomNightModeStart(@NonNull LocalTime time) {
|
public void setCustomNightModeStart(@NonNull LocalTime time) {
|
||||||
if (mService != null) {
|
if (sGlobals != null) {
|
||||||
try {
|
try {
|
||||||
mService.setCustomNightModeStart(time.toNanoOfDay() / 1000);
|
sGlobals.mService.setCustomNightModeStart(time.toNanoOfDay() / 1000);
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
throw e.rethrowFromSystemServer();
|
throw e.rethrowFromSystemServer();
|
||||||
}
|
}
|
||||||
@@ -891,9 +921,9 @@ public class UiModeManager {
|
|||||||
*/
|
*/
|
||||||
@NonNull
|
@NonNull
|
||||||
public LocalTime getCustomNightModeEnd() {
|
public LocalTime getCustomNightModeEnd() {
|
||||||
if (mService != null) {
|
if (sGlobals != null) {
|
||||||
try {
|
try {
|
||||||
return LocalTime.ofNanoOfDay(mService.getCustomNightModeEnd() * 1000);
|
return LocalTime.ofNanoOfDay(sGlobals.mService.getCustomNightModeEnd() * 1000);
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
throw e.rethrowFromSystemServer();
|
throw e.rethrowFromSystemServer();
|
||||||
}
|
}
|
||||||
@@ -909,9 +939,9 @@ public class UiModeManager {
|
|||||||
* @param time The time of the day Dark theme should deactivate
|
* @param time The time of the day Dark theme should deactivate
|
||||||
*/
|
*/
|
||||||
public void setCustomNightModeEnd(@NonNull LocalTime time) {
|
public void setCustomNightModeEnd(@NonNull LocalTime time) {
|
||||||
if (mService != null) {
|
if (sGlobals != null) {
|
||||||
try {
|
try {
|
||||||
mService.setCustomNightModeEnd(time.toNanoOfDay() / 1000);
|
sGlobals.mService.setCustomNightModeEnd(time.toNanoOfDay() / 1000);
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
throw e.rethrowFromSystemServer();
|
throw e.rethrowFromSystemServer();
|
||||||
}
|
}
|
||||||
@@ -976,9 +1006,9 @@ public class UiModeManager {
|
|||||||
@RequiresPermission(value = android.Manifest.permission.TOGGLE_AUTOMOTIVE_PROJECTION,
|
@RequiresPermission(value = android.Manifest.permission.TOGGLE_AUTOMOTIVE_PROJECTION,
|
||||||
conditional = true)
|
conditional = true)
|
||||||
public boolean requestProjection(@ProjectionType int projectionType) {
|
public boolean requestProjection(@ProjectionType int projectionType) {
|
||||||
if (mService != null) {
|
if (sGlobals != null) {
|
||||||
try {
|
try {
|
||||||
return mService.requestProjection(new Binder(), projectionType,
|
return sGlobals.mService.requestProjection(new Binder(), projectionType,
|
||||||
mContext.getOpPackageName());
|
mContext.getOpPackageName());
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
throw e.rethrowFromSystemServer();
|
throw e.rethrowFromSystemServer();
|
||||||
@@ -1005,9 +1035,10 @@ public class UiModeManager {
|
|||||||
@RequiresPermission(value = android.Manifest.permission.TOGGLE_AUTOMOTIVE_PROJECTION,
|
@RequiresPermission(value = android.Manifest.permission.TOGGLE_AUTOMOTIVE_PROJECTION,
|
||||||
conditional = true)
|
conditional = true)
|
||||||
public boolean releaseProjection(@ProjectionType int projectionType) {
|
public boolean releaseProjection(@ProjectionType int projectionType) {
|
||||||
if (mService != null) {
|
if (sGlobals != null) {
|
||||||
try {
|
try {
|
||||||
return mService.releaseProjection(projectionType, mContext.getOpPackageName());
|
return sGlobals.mService.releaseProjection(
|
||||||
|
projectionType, mContext.getOpPackageName());
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
throw e.rethrowFromSystemServer();
|
throw e.rethrowFromSystemServer();
|
||||||
}
|
}
|
||||||
@@ -1028,9 +1059,9 @@ public class UiModeManager {
|
|||||||
@RequiresPermission(android.Manifest.permission.READ_PROJECTION_STATE)
|
@RequiresPermission(android.Manifest.permission.READ_PROJECTION_STATE)
|
||||||
@NonNull
|
@NonNull
|
||||||
public Set<String> getProjectingPackages(@ProjectionType int projectionType) {
|
public Set<String> getProjectingPackages(@ProjectionType int projectionType) {
|
||||||
if (mService != null) {
|
if (sGlobals != null) {
|
||||||
try {
|
try {
|
||||||
return new ArraySet<>(mService.getProjectingPackages(projectionType));
|
return new ArraySet<>(sGlobals.mService.getProjectingPackages(projectionType));
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
throw e.rethrowFromSystemServer();
|
throw e.rethrowFromSystemServer();
|
||||||
}
|
}
|
||||||
@@ -1046,9 +1077,9 @@ public class UiModeManager {
|
|||||||
@SystemApi
|
@SystemApi
|
||||||
@RequiresPermission(android.Manifest.permission.READ_PROJECTION_STATE)
|
@RequiresPermission(android.Manifest.permission.READ_PROJECTION_STATE)
|
||||||
public @ProjectionType int getActiveProjectionTypes() {
|
public @ProjectionType int getActiveProjectionTypes() {
|
||||||
if (mService != null) {
|
if (sGlobals != null) {
|
||||||
try {
|
try {
|
||||||
return mService.getActiveProjectionTypes();
|
return sGlobals.mService.getActiveProjectionTypes();
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
throw e.rethrowFromSystemServer();
|
throw e.rethrowFromSystemServer();
|
||||||
}
|
}
|
||||||
@@ -1076,11 +1107,12 @@ public class UiModeManager {
|
|||||||
Slog.i(TAG, "Attempted to add listener that was already added.");
|
Slog.i(TAG, "Attempted to add listener that was already added.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (mService != null) {
|
if (sGlobals != null) {
|
||||||
InnerListener innerListener = new InnerListener(executor, listener,
|
InnerListener innerListener = new InnerListener(executor, listener,
|
||||||
mOnProjectionStateChangedListenerResourceManager);
|
mOnProjectionStateChangedListenerResourceManager);
|
||||||
try {
|
try {
|
||||||
mService.addOnProjectionStateChangedListener(innerListener, projectionType);
|
sGlobals.mService.addOnProjectionStateChangedListener(
|
||||||
|
innerListener, projectionType);
|
||||||
mProjectionStateListenerMap.put(listener, innerListener);
|
mProjectionStateListenerMap.put(listener, innerListener);
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
mOnProjectionStateChangedListenerResourceManager.remove(innerListener);
|
mOnProjectionStateChangedListenerResourceManager.remove(innerListener);
|
||||||
@@ -1107,9 +1139,9 @@ public class UiModeManager {
|
|||||||
Slog.i(TAG, "Attempted to remove listener that was not added.");
|
Slog.i(TAG, "Attempted to remove listener that was not added.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (mService != null) {
|
if (sGlobals != null) {
|
||||||
try {
|
try {
|
||||||
mService.removeOnProjectionStateChangedListener(innerListener);
|
sGlobals.mService.removeOnProjectionStateChangedListener(innerListener);
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
throw e.rethrowFromSystemServer();
|
throw e.rethrowFromSystemServer();
|
||||||
}
|
}
|
||||||
@@ -1197,15 +1229,10 @@ public class UiModeManager {
|
|||||||
* <li> -1 corresponds to the minimum contrast </li>
|
* <li> -1 corresponds to the minimum contrast </li>
|
||||||
* <li> 1 corresponds to the maximum contrast </li>
|
* <li> 1 corresponds to the maximum contrast </li>
|
||||||
* </ul>
|
* </ul>
|
||||||
*
|
|
||||||
*
|
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
@FloatRange(from = -1.0f, to = 1.0f)
|
@FloatRange(from = -1.0f, to = 1.0f)
|
||||||
public float getContrast() {
|
public float getContrast() {
|
||||||
synchronized (mLock) {
|
return sGlobals.getContrast();
|
||||||
return mContrast;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1219,9 +1246,7 @@ public class UiModeManager {
|
|||||||
@NonNull ContrastChangeListener listener) {
|
@NonNull ContrastChangeListener listener) {
|
||||||
Objects.requireNonNull(executor);
|
Objects.requireNonNull(executor);
|
||||||
Objects.requireNonNull(listener);
|
Objects.requireNonNull(listener);
|
||||||
synchronized (mLock) {
|
sGlobals.addContrastChangeListener(listener, executor);
|
||||||
mContrastChangeListeners.put(listener, executor);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1232,8 +1257,6 @@ public class UiModeManager {
|
|||||||
*/
|
*/
|
||||||
public void removeContrastChangeListener(@NonNull ContrastChangeListener listener) {
|
public void removeContrastChangeListener(@NonNull ContrastChangeListener listener) {
|
||||||
Objects.requireNonNull(listener);
|
Objects.requireNonNull(listener);
|
||||||
synchronized (mLock) {
|
sGlobals.removeContrastChangeListener(listener);
|
||||||
mContrastChangeListeners.remove(listener);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user