Commit 59ba9bcd authored by Mounir Lamouri's avatar Mounir Lamouri Committed by Commit Bot

Screen Orientation: remove all JB code.

Bug: 929994
Change-Id: I5cc1a2379358afffca9b95df49f485aefff232f3
Reviewed-on: https://chromium-review.googlesource.com/c/1460414
Commit-Queue: Mounir Lamouri <mlamouri@chromium.org>
Reviewed-by: default avatarBo <boliu@chromium.org>
Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Cr-Commit-Position: refs/heads/master@{#630419}
parent 596d2130
...@@ -73,7 +73,6 @@ public class ScreenOrientationListenerTest { ...@@ -73,7 +73,6 @@ public class ScreenOrientationListenerTest {
mDisplayAndroid = mDisplayAndroid =
mActivityTestRule.getWebContents().getTopLevelNativeWindow().getDisplay(); mActivityTestRule.getWebContents().getTopLevelNativeWindow().getDisplay();
mDisplayAndroid.addObserver(mCallbackHelper); mDisplayAndroid.addObserver(mCallbackHelper);
DisplayAndroid.startAccurateListening();
} }
}); });
...@@ -94,7 +93,6 @@ public class ScreenOrientationListenerTest { ...@@ -94,7 +93,6 @@ public class ScreenOrientationListenerTest {
mDisplayAndroid = null; mDisplayAndroid = null;
mActivityTestRule.getActivity().setRequestedOrientation( mActivityTestRule.getActivity().setRequestedOrientation(
ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED); ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
DisplayAndroid.stopAccurateListening();
} }
}); });
......
...@@ -12,21 +12,9 @@ interface ScreenOrientation { ...@@ -12,21 +12,9 @@ interface ScreenOrientation {
UnlockOrientation(); UnlockOrientation();
}; };
// ScreenOrientationListener is expected to be used when the platform requires // NOTE: this could probably be merged with `ScreenOrientation`. It used to be a
// heavy work in order to accurately know the screen orientation. // separate service for Android Jelly Bean devices.
// For example, on Android, this is required for Jelly Bean, where there is no
// API to be notified of a screen orientation change of 180 degrees.
interface ScreenOrientationListener { interface ScreenOrientationListener {
// The renderer process is now using the Screen Orientation API and informs
// the browser process that it should start accurately listening to the screen
// orientation if it wasn't already.
Start();
// The renderer process is no longer using the Screen Orientation API and
// informs the browser process that it can stop accurately listening to the
// screen orientation if no other process cares about it.
Stop();
// Queries whether accelerometer auto rotation of screen orientation is // Queries whether accelerometer auto rotation of screen orientation is
// enabled, or the user has locked the screen orientation at the OS level. // enabled, or the user has locked the screen orientation at the OS level.
// This can be called at any time, whether or not the listener is started. // This can be called at any time, whether or not the listener is started.
......
...@@ -7,36 +7,14 @@ package org.chromium.device.screen_orientation; ...@@ -7,36 +7,14 @@ package org.chromium.device.screen_orientation;
import android.provider.Settings; import android.provider.Settings;
import org.chromium.base.ContextUtils; import org.chromium.base.ContextUtils;
import org.chromium.base.ThreadUtils;
import org.chromium.base.annotations.CalledByNative; import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.annotations.JNINamespace; import org.chromium.base.annotations.JNINamespace;
import org.chromium.ui.display.DisplayAndroid;
/** /**
* Android implementation details for device::ScreenOrientationListenerAndroid. * Android implementation details for device::ScreenOrientationListenerAndroid.
*/ */
@JNINamespace("device") @JNINamespace("device")
class ScreenOrientationListener { class ScreenOrientationListener {
@CalledByNative
static void startAccurateListening() {
ThreadUtils.runOnUiThread(new Runnable() {
@Override
public void run() {
DisplayAndroid.startAccurateListening();
}
});
}
@CalledByNative
static void stopAccurateListening() {
ThreadUtils.runOnUiThread(new Runnable() {
@Override
public void run() {
DisplayAndroid.stopAccurateListening();
}
});
}
@CalledByNative @CalledByNative
static boolean isAutoRotateEnabledByUser() { static boolean isAutoRotateEnabledByUser() {
return Settings.System.getInt(ContextUtils.getApplicationContext().getContentResolver(), return Settings.System.getInt(ContextUtils.getApplicationContext().getContentResolver(),
......
...@@ -19,40 +19,10 @@ void ScreenOrientationListenerAndroid::Create( ...@@ -19,40 +19,10 @@ void ScreenOrientationListenerAndroid::Create(
std::move(request)); std::move(request));
} }
ScreenOrientationListenerAndroid::ScreenOrientationListenerAndroid() ScreenOrientationListenerAndroid::ScreenOrientationListenerAndroid() = default;
: listeners_count_(0) {}
ScreenOrientationListenerAndroid::~ScreenOrientationListenerAndroid() { ScreenOrientationListenerAndroid::~ScreenOrientationListenerAndroid() {
DCHECK(base::MessageLoopCurrentForIO::IsSet()); DCHECK(base::MessageLoopCurrentForIO::IsSet());
if (listeners_count_ > 0) {
Java_ScreenOrientationListener_startAccurateListening(
base::android::AttachCurrentThread());
}
}
void ScreenOrientationListenerAndroid::Start() {
DCHECK(base::MessageLoopCurrentForIO::IsSet());
++listeners_count_;
if (listeners_count_ == 1) {
// Ask the ScreenOrientationListener (Java) to start accurately listening to
// the screen orientation. It keep track of the number of start request if
// it is already running an accurate listening.
Java_ScreenOrientationListener_startAccurateListening(
base::android::AttachCurrentThread());
}
}
void ScreenOrientationListenerAndroid::Stop() {
DCHECK(base::MessageLoopCurrentForIO::IsSet());
DCHECK(listeners_count_ > 0);
--listeners_count_;
if (listeners_count_ == 0) {
// Ask the ScreenOrientationListener (Java) to stop accurately listening to
// the screen orientation. It will actually stop only if the number of stop
// requests matches the number of start requests.
Java_ScreenOrientationListener_stopAccurateListening(
base::android::AttachCurrentThread());
}
} }
void ScreenOrientationListenerAndroid::IsAutoRotateEnabledByUser( void ScreenOrientationListenerAndroid::IsAutoRotateEnabledByUser(
......
...@@ -21,13 +21,9 @@ class ScreenOrientationListenerAndroid ...@@ -21,13 +21,9 @@ class ScreenOrientationListenerAndroid
ScreenOrientationListenerAndroid(); ScreenOrientationListenerAndroid();
// mojom::ScreenOrientationListener: // mojom::ScreenOrientationListener:
void Start() override;
void Stop() override;
void IsAutoRotateEnabledByUser( void IsAutoRotateEnabledByUser(
IsAutoRotateEnabledByUserCallback callback) override; IsAutoRotateEnabledByUserCallback callback) override;
int listeners_count_;
DISALLOW_COPY_AND_ASSIGN(ScreenOrientationListenerAndroid); DISALLOW_COPY_AND_ASSIGN(ScreenOrientationListenerAndroid);
}; };
......
...@@ -12,8 +12,6 @@ blink_modules_sources("screen_orientation") { ...@@ -12,8 +12,6 @@ blink_modules_sources("screen_orientation") {
"screen_orientation.h", "screen_orientation.h",
"screen_orientation_controller_impl.cc", "screen_orientation_controller_impl.cc",
"screen_orientation_controller_impl.h", "screen_orientation_controller_impl.h",
"screen_orientation_dispatcher.cc",
"screen_orientation_dispatcher.h",
"screen_screen_orientation.cc", "screen_screen_orientation.cc",
"screen_screen_orientation.h", "screen_screen_orientation.h",
"web_lock_orientation_callback.h", "web_lock_orientation_callback.h",
......
...@@ -17,7 +17,6 @@ ...@@ -17,7 +17,6 @@
#include "third_party/blink/renderer/core/page/chrome_client.h" #include "third_party/blink/renderer/core/page/chrome_client.h"
#include "third_party/blink/renderer/core/page/page.h" #include "third_party/blink/renderer/core/page/page.h"
#include "third_party/blink/renderer/modules/screen_orientation/screen_orientation.h" #include "third_party/blink/renderer/modules/screen_orientation/screen_orientation.h"
#include "third_party/blink/renderer/modules/screen_orientation/screen_orientation_dispatcher.h"
#include "third_party/blink/renderer/platform/web_test_support.h" #include "third_party/blink/renderer/platform/web_test_support.h"
namespace blink { namespace blink {
...@@ -39,7 +38,7 @@ ScreenOrientationControllerImpl::ScreenOrientationControllerImpl( ...@@ -39,7 +38,7 @@ ScreenOrientationControllerImpl::ScreenOrientationControllerImpl(
LocalFrame& frame) LocalFrame& frame)
: ScreenOrientationController(frame), : ScreenOrientationController(frame),
ContextLifecycleObserver(frame.GetDocument()), ContextLifecycleObserver(frame.GetDocument()),
PlatformEventController(frame.GetDocument()), PageVisibilityObserver(frame.GetPage()),
dispatch_event_timer_( dispatch_event_timer_(
frame.GetTaskRunner(TaskType::kMiscPlatformAPI), frame.GetTaskRunner(TaskType::kMiscPlatformAPI),
this, this,
...@@ -90,9 +89,8 @@ WebScreenOrientationType ScreenOrientationControllerImpl::ComputeOrientation( ...@@ -90,9 +89,8 @@ WebScreenOrientationType ScreenOrientationControllerImpl::ComputeOrientation(
void ScreenOrientationControllerImpl::UpdateOrientation() { void ScreenOrientationControllerImpl::UpdateOrientation() {
DCHECK(orientation_); DCHECK(orientation_);
DCHECK(GetFrame()); DCHECK(GetPage());
DCHECK(GetFrame()->GetPage()); ChromeClient& chrome_client = GetPage()->GetChromeClient();
ChromeClient& chrome_client = GetFrame()->GetPage()->GetChromeClient();
WebScreenInfo screen_info = chrome_client.GetScreenInfo(); WebScreenInfo screen_info = chrome_client.GetScreenInfo();
WebScreenOrientationType orientation_type = screen_info.orientation_type; WebScreenOrientationType orientation_type = screen_info.orientation_type;
if (orientation_type == kWebScreenOrientationUndefined) { if (orientation_type == kWebScreenOrientationUndefined) {
...@@ -120,21 +118,15 @@ bool ScreenOrientationControllerImpl::IsActiveAndVisible() const { ...@@ -120,21 +118,15 @@ bool ScreenOrientationControllerImpl::IsActiveAndVisible() const {
} }
void ScreenOrientationControllerImpl::PageVisibilityChanged() { void ScreenOrientationControllerImpl::PageVisibilityChanged() {
NotifyDispatcher();
if (!IsActiveAndVisible()) if (!IsActiveAndVisible())
return; return;
DCHECK(GetFrame()); DCHECK(GetPage());
DCHECK(GetFrame()->GetPage());
// The orientation type and angle are tied in a way that if the angle has // The orientation type and angle are tied in a way that if the angle has
// changed, the type must have changed. // changed, the type must have changed.
unsigned short current_angle = GetFrame() unsigned short current_angle =
->GetPage() GetPage()->GetChromeClient().GetScreenInfo().orientation_angle;
->GetChromeClient()
.GetScreenInfo()
.orientation_angle;
// FIXME: sendOrientationChangeEvent() currently send an event all the // FIXME: sendOrientationChangeEvent() currently send an event all the
// children of the frame, so it should only be called on the frame on // children of the frame, so it should only be called on the frame on
...@@ -181,7 +173,6 @@ void ScreenOrientationControllerImpl::SetOrientation( ...@@ -181,7 +173,6 @@ void ScreenOrientationControllerImpl::SetOrientation(
orientation_ = orientation; orientation_ = orientation;
if (orientation_) if (orientation_)
UpdateOrientation(); UpdateOrientation();
NotifyDispatcher();
} }
void ScreenOrientationControllerImpl::lock( void ScreenOrientationControllerImpl::lock(
...@@ -224,40 +215,16 @@ void ScreenOrientationControllerImpl::DispatchEventTimerFired(TimerBase*) { ...@@ -224,40 +215,16 @@ void ScreenOrientationControllerImpl::DispatchEventTimerFired(TimerBase*) {
orientation_->DispatchEvent(*Event::Create(event_type_names::kChange)); orientation_->DispatchEvent(*Event::Create(event_type_names::kChange));
} }
void ScreenOrientationControllerImpl::DidUpdateData() {
// Do nothing.
}
void ScreenOrientationControllerImpl::RegisterWithDispatcher() {
ScreenOrientationDispatcher::Instance().AddController(this);
}
void ScreenOrientationControllerImpl::UnregisterWithDispatcher() {
ScreenOrientationDispatcher::Instance().RemoveController(this);
}
bool ScreenOrientationControllerImpl::HasLastData() {
return true;
}
void ScreenOrientationControllerImpl::ContextDestroyed(ExecutionContext*) { void ScreenOrientationControllerImpl::ContextDestroyed(ExecutionContext*) {
StopUpdating();
screen_orientation_service_ = nullptr; screen_orientation_service_ = nullptr;
active_lock_ = false; active_lock_ = false;
} }
void ScreenOrientationControllerImpl::NotifyDispatcher() {
if (orientation_ && GetPage()->IsPageVisible())
StartUpdating();
else
StopUpdating();
}
void ScreenOrientationControllerImpl::Trace(blink::Visitor* visitor) { void ScreenOrientationControllerImpl::Trace(blink::Visitor* visitor) {
visitor->Trace(orientation_); visitor->Trace(orientation_);
ContextLifecycleObserver::Trace(visitor); ContextLifecycleObserver::Trace(visitor);
PageVisibilityObserver::Trace(visitor);
Supplement<LocalFrame>::Trace(visitor); Supplement<LocalFrame>::Trace(visitor);
PlatformEventController::Trace(visitor);
} }
void ScreenOrientationControllerImpl::SetScreenOrientationAssociatedPtrForTests( void ScreenOrientationControllerImpl::SetScreenOrientationAssociatedPtrForTests(
......
...@@ -10,8 +10,8 @@ ...@@ -10,8 +10,8 @@
#include "third_party/blink/public/common/screen_orientation/web_screen_orientation_lock_type.h" #include "third_party/blink/public/common/screen_orientation/web_screen_orientation_lock_type.h"
#include "third_party/blink/public/common/screen_orientation/web_screen_orientation_type.h" #include "third_party/blink/public/common/screen_orientation/web_screen_orientation_type.h"
#include "third_party/blink/renderer/core/dom/document.h" #include "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/renderer/core/frame/platform_event_controller.h"
#include "third_party/blink/renderer/core/frame/screen_orientation_controller.h" #include "third_party/blink/renderer/core/frame/screen_orientation_controller.h"
#include "third_party/blink/renderer/core/page/page_visibility_observer.h"
#include "third_party/blink/renderer/modules/modules_export.h" #include "third_party/blink/renderer/modules/modules_export.h"
#include "third_party/blink/renderer/modules/screen_orientation/web_lock_orientation_callback.h" #include "third_party/blink/renderer/modules/screen_orientation/web_lock_orientation_callback.h"
...@@ -25,7 +25,7 @@ using device::mojom::blink::ScreenOrientationLockResult; ...@@ -25,7 +25,7 @@ using device::mojom::blink::ScreenOrientationLockResult;
class MODULES_EXPORT ScreenOrientationControllerImpl final class MODULES_EXPORT ScreenOrientationControllerImpl final
: public ScreenOrientationController, : public ScreenOrientationController,
public ContextLifecycleObserver, public ContextLifecycleObserver,
public PlatformEventController { public PageVisibilityObserver {
USING_GARBAGE_COLLECTED_MIXIN(ScreenOrientationControllerImpl); USING_GARBAGE_COLLECTED_MIXIN(ScreenOrientationControllerImpl);
WTF_MAKE_NONCOPYABLE(ScreenOrientationControllerImpl); WTF_MAKE_NONCOPYABLE(ScreenOrientationControllerImpl);
...@@ -56,18 +56,10 @@ class MODULES_EXPORT ScreenOrientationControllerImpl final ...@@ -56,18 +56,10 @@ class MODULES_EXPORT ScreenOrientationControllerImpl final
static WebScreenOrientationType ComputeOrientation(const IntRect&, uint16_t); static WebScreenOrientationType ComputeOrientation(const IntRect&, uint16_t);
// Inherited from PlatformEventController.
void DidUpdateData() override;
void RegisterWithDispatcher() override;
void UnregisterWithDispatcher() override;
bool HasLastData() override;
// Inherited from ContextLifecycleObserver and PageVisibilityObserver. // Inherited from ContextLifecycleObserver and PageVisibilityObserver.
void ContextDestroyed(ExecutionContext*) override; void ContextDestroyed(ExecutionContext*) override;
void PageVisibilityChanged() override; void PageVisibilityChanged() override;
void NotifyDispatcher();
void UpdateOrientation(); void UpdateOrientation();
void DispatchEventTimerFired(TimerBase*); void DispatchEventTimerFired(TimerBase*);
......
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "third_party/blink/renderer/modules/screen_orientation/screen_orientation_dispatcher.h"
#include "services/device/public/mojom/constants.mojom-blink.h"
#include "services/service_manager/public/cpp/connector.h"
#include "third_party/blink/public/platform/platform.h"
namespace blink {
ScreenOrientationDispatcher& ScreenOrientationDispatcher::Instance() {
DEFINE_STATIC_LOCAL(Persistent<ScreenOrientationDispatcher>,
screen_orientation_dispatcher,
(MakeGarbageCollected<ScreenOrientationDispatcher>()));
return *screen_orientation_dispatcher;
}
ScreenOrientationDispatcher::ScreenOrientationDispatcher() = default;
ScreenOrientationDispatcher::~ScreenOrientationDispatcher() {
DCHECK(!listener_);
}
void ScreenOrientationDispatcher::Trace(blink::Visitor* visitor) {
PlatformEventDispatcher::Trace(visitor);
}
void ScreenOrientationDispatcher::StartListening(LocalFrame* frame) {
DCHECK(!listener_);
Platform::Current()->GetConnector()->BindInterface(
device::mojom::blink::kServiceName, mojo::MakeRequest(&listener_));
listener_->Start();
}
void ScreenOrientationDispatcher::StopListening() {
DCHECK(listener_);
listener_->Stop();
listener_.reset();
}
} // namespace blink
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_SCREEN_ORIENTATION_SCREEN_ORIENTATION_DISPATCHER_H_
#define THIRD_PARTY_BLINK_RENDERER_MODULES_SCREEN_ORIENTATION_SCREEN_ORIENTATION_DISPATCHER_H_
#include "base/macros.h"
#include "services/device/public/mojom/screen_orientation.mojom-blink.h"
#include "third_party/blink/renderer/core/frame/platform_event_dispatcher.h"
#include "third_party/blink/renderer/platform/heap/handle.h"
namespace blink {
// ScreenOrientationDispatcher is a singleton that handles whether the current
// Blink instance should be listening to the screen orientation platform events.
// It is not a common implementation of PlatformEventDispatcher in the sense
// that it doesn't actually dispatch events but simply start/stop listening. The
// reason being that screen orientation events are always sent to the WebFrame's
// but some platforms require to poll to have an accurate reporting. When
// ScreenOrientationDispatcher is listening, that means that the platform should
// be polling if required.
class ScreenOrientationDispatcher final
: public GarbageCollectedFinalized<ScreenOrientationDispatcher>,
public PlatformEventDispatcher {
USING_GARBAGE_COLLECTED_MIXIN(ScreenOrientationDispatcher);
public:
static ScreenOrientationDispatcher& Instance();
ScreenOrientationDispatcher();
~ScreenOrientationDispatcher();
void Trace(blink::Visitor*) override;
private:
// Inherited from PlatformEventDispatcher.
void StartListening(LocalFrame*) override;
void StopListening() override;
device::mojom::blink::ScreenOrientationListenerPtr listener_;
DISALLOW_COPY_AND_ASSIGN(ScreenOrientationDispatcher);
};
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_MODULES_SCREEN_ORIENTATION_SCREEN_ORIENTATION_DISPATCHER_H_
...@@ -192,22 +192,6 @@ public class DisplayAndroid { ...@@ -192,22 +192,6 @@ public class DisplayAndroid {
mObservers.remove(observer); mObservers.remove(observer);
} }
/**
* Toggle the accurate mode if it wasn't already doing so. The backend will
* keep track of the number of times this has been called.
*/
public static void startAccurateListening() {
getManager().startAccurateListening();
}
/**
* Request to stop the accurate mode. It will effectively be stopped only if
* this method is called as many times as startAccurateListening().
*/
public static void stopAccurateListening() {
getManager().stopAccurateListening();
}
protected DisplayAndroid(int displayId) { protected DisplayAndroid(int displayId) {
mDisplayId = displayId; mDisplayId = displayId;
mObservers = new WeakHashMap<>(); mObservers = new WeakHashMap<>();
......
...@@ -5,12 +5,9 @@ ...@@ -5,12 +5,9 @@
package org.chromium.ui.display; package org.chromium.ui.display;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.content.ComponentCallbacks;
import android.content.Context; import android.content.Context;
import android.content.res.Configuration;
import android.hardware.display.DisplayManager; import android.hardware.display.DisplayManager;
import android.hardware.display.DisplayManager.DisplayListener; import android.hardware.display.DisplayManager.DisplayListener;
import android.os.Build;
import android.util.SparseArray; import android.util.SparseArray;
import android.view.Display; import android.view.Display;
import android.view.WindowManager; import android.view.WindowManager;
...@@ -28,125 +25,14 @@ import org.chromium.base.annotations.MainDex; ...@@ -28,125 +25,14 @@ import org.chromium.base.annotations.MainDex;
@MainDex @MainDex
public class DisplayAndroidManager { public class DisplayAndroidManager {
/** /**
* DisplayListenerBackend is an interface that abstract the mechanism used for the actual * DisplayListenerBackend is used to handle the actual listening of display changes. It handles
* display update listening. The reason being that from Android API Level 17 DisplayListener * it via the Android DisplayListener API.
* will be used. Before that, an unreliable solution based on onConfigurationChanged has to be
* used.
*/ */
private interface DisplayListenerBackend { private class DisplayListenerBackend implements DisplayListener {
/**
* Starts to listen for display changes. This will be called
* when the first observer is added.
*/
void startListening();
/**
* Toggle the accurate mode if it wasn't already doing so. The backend
* will keep track of the number of times this has been called.
*/
void startAccurateListening();
/**
* Request to stop the accurate mode. It will effectively be stopped
* only if this method is called as many times as
* startAccurateListening().
*/
void stopAccurateListening();
}
/**
* DisplayListenerAPI16 implements DisplayListenerBackend
* to use ComponentCallbacks in order to listen for display
* changes.
*
* This method is known to not correctly detect 180 degrees changes but it
* is the only method that will work before API Level 17 (excluding polling).
* When toggleAccurateMode() is called, it will start polling in order to
* find out if the display has changed.
*/
private class DisplayListenerAPI16
implements DisplayListenerBackend, ComponentCallbacks {
private static final long POLLING_DELAY = 500;
private int mAccurateCount;
// DisplayListenerBackend implementation:
@Override
public void startListening() {
getContext().registerComponentCallbacks(this);
}
@Override
public void startAccurateListening() {
++mAccurateCount;
if (mAccurateCount > 1) return;
// Start polling if we went from 0 to 1. The polling will
// automatically stop when mAccurateCount reaches 0.
final DisplayListenerAPI16 self = this;
ThreadUtils.postOnUiThreadDelayed(new Runnable() {
@Override
public void run() {
self.onConfigurationChanged(null);
if (self.mAccurateCount < 1) return;
ThreadUtils.postOnUiThreadDelayed(this,
DisplayListenerAPI16.POLLING_DELAY);
}
}, POLLING_DELAY);
}
@Override
public void stopAccurateListening() {
--mAccurateCount;
assert mAccurateCount >= 0;
}
// ComponentCallbacks implementation:
@Override
public void onConfigurationChanged(Configuration newConfig) {
((PhysicalDisplayAndroid) mIdMap.get(mMainSdkDisplayId)).updateFromDisplay(
getDefaultDisplayForContext(getContext()));
}
@Override
public void onLowMemory() {
}
}
/**
* DisplayListenerBackendImpl implements DisplayListenerBackend
* to use DisplayListener in order to listen for display changes.
*
* This method is reliable but DisplayListener is only available for API Level 17+.
*/
@SuppressLint("NewApi")
private class DisplayListenerBackendImpl
implements DisplayListenerBackend, DisplayListener {
// DisplayListenerBackend implementation:
@Override
public void startListening() { public void startListening() {
getDisplayManager().registerDisplayListener(this, null); getDisplayManager().registerDisplayListener(this, null);
} }
@Override
public void startAccurateListening() {
// Always accurate. Do nothing.
}
@Override
public void stopAccurateListening() {
// Always accurate. Do nothing.
}
// DisplayListener implementation: // DisplayListener implementation:
@Override @Override
...@@ -191,7 +77,7 @@ public class DisplayAndroidManager { ...@@ -191,7 +77,7 @@ public class DisplayAndroidManager {
private long mNativePointer; private long mNativePointer;
private int mMainSdkDisplayId; private int mMainSdkDisplayId;
private final SparseArray<DisplayAndroid> mIdMap = new SparseArray<>(); private final SparseArray<DisplayAndroid> mIdMap = new SparseArray<>();
private DisplayListenerBackend mBackend; private DisplayListenerBackend mBackend = new DisplayListenerBackend();
private int mNextVirtualDisplayId = VIRTUAL_DISPLAY_ID_BEGIN; private int mNextVirtualDisplayId = VIRTUAL_DISPLAY_ID_BEGIN;
/* package */ static DisplayAndroidManager getInstance() { /* package */ static DisplayAndroidManager getInstance() {
...@@ -234,20 +120,15 @@ public class DisplayAndroidManager { ...@@ -234,20 +120,15 @@ public class DisplayAndroidManager {
private void initialize() { private void initialize() {
Display display; Display display;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
mBackend = new DisplayListenerBackendImpl(); // Make sure the display map contains the built-in primary display.
// Make sure the display map contains the built-in primary display. // The primary display is never removed.
// The primary display is never removed. display = getDisplayManager().getDisplay(Display.DEFAULT_DISPLAY);
display = getDisplayManager().getDisplay(Display.DEFAULT_DISPLAY);
// Android documentation on Display.DEFAULT_DISPLAY suggests that the above
// Android documentation on Display.DEFAULT_DISPLAY suggests that the above // method might return null. In that case we retrieve the default display
// method might return null. In that case we retrieve the default display // from the application context and take it as the primary display.
// from the application context and take it as the primary display. if (display == null) display = getDefaultDisplayForContext(getContext());
if (display == null) display = getDefaultDisplayForContext(getContext());
} else {
mBackend = new DisplayListenerAPI16();
display = getDefaultDisplayForContext(getContext());
}
mMainSdkDisplayId = display.getDisplayId(); mMainSdkDisplayId = display.getDisplayId();
addDisplay(display); // Note this display is never removed. addDisplay(display); // Note this display is never removed.
...@@ -273,14 +154,6 @@ public class DisplayAndroidManager { ...@@ -273,14 +154,6 @@ public class DisplayAndroidManager {
return displayAndroid; return displayAndroid;
} }
/* package */ void startAccurateListening() {
mBackend.startAccurateListening();
}
/* package */ void stopAccurateListening() {
mBackend.stopAccurateListening();
}
private DisplayAndroid addDisplay(Display display) { private DisplayAndroid addDisplay(Display display) {
int sdkDisplayId = display.getDisplayId(); int sdkDisplayId = display.getDisplayId();
PhysicalDisplayAndroid displayAndroid = new PhysicalDisplayAndroid(display); PhysicalDisplayAndroid displayAndroid = new PhysicalDisplayAndroid(display);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment