Skip to content

Commit

Permalink
Clean up warning from VRBrowserActivity (#2986)
Browse files Browse the repository at this point in the history
  • Loading branch information
bluemarvin committed Mar 23, 2020
1 parent c87cc72 commit e318b30
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 38 deletions.
83 changes: 52 additions & 31 deletions app/src/common/shared/org/mozilla/vrbrowser/VRBrowserActivity.java
Expand Up @@ -82,6 +82,7 @@
import org.mozilla.vrbrowser.utils.ServoUtils;
import org.mozilla.vrbrowser.utils.SystemUtils;

import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
Expand All @@ -96,7 +97,7 @@ public class VRBrowserActivity extends PlatformActivity implements WidgetManager
private BroadcastReceiver mCrashReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if(intent.getAction().equals(CrashReporterService.CRASH_ACTION)) {
if((intent.getAction() != null) && intent.getAction().equals(CrashReporterService.CRASH_ACTION)) {
Intent crashIntent = intent.getParcelableExtra(CrashReporterService.DATA_TAG);
handleContentCrashIntent(crashIntent);
}
Expand Down Expand Up @@ -443,9 +444,7 @@ protected void onResume() {
for (Widget widget: mWidgets.values()) {
widget.onResume();
}
mConnectivityListeners.forEach((listener) -> {
listener.OnConnectivityChanged(ConnectivityReceiver.isNetworkAvailable(this));
});
mConnectivityListeners.forEach((listener) -> listener.OnConnectivityChanged(ConnectivityReceiver.isNetworkAvailable(this)));
mConnectivityReceiver.register(this, mConnectivityDelegate);

// If we're signed-in, poll for any new device events (e.g. received tabs) on activity resume.
Expand Down Expand Up @@ -664,7 +663,7 @@ public void onTrimMemory(int level) {
@Override
public void onBackPressed() {
if (mIsPresentingImmersive) {
queueRunnable(() -> exitImmersiveNative());
queueRunnable(this::exitImmersiveNative);
return;
}
if (mBackHandlers.size() > 0) {
Expand Down Expand Up @@ -711,20 +710,21 @@ public boolean dispatchKeyEvent(KeyEvent event) {
return super.dispatchKeyEvent(event);
}

private void exitImmersiveSync() {
Runnable exitImmersive = new Runnable() {
@Override
public void run() {
exitImmersiveNative();
synchronized(this) {
this.notifyAll();
}
final Runnable mExitImmersive = new Runnable() {
@Override
public void run() {
exitImmersiveNative();
synchronized(this) {
this.notifyAll();
}
};
synchronized (exitImmersive) {
queueRunnable(exitImmersive);
}
};

private void exitImmersiveSync() {
synchronized (mExitImmersive) {
queueRunnable(mExitImmersive);
try {
exitImmersive.wait();
mExitImmersive.wait();
} catch (InterruptedException e) {
Log.e(LOGTAG, "Waiting for exit immersive onPause interrupted");
}
Expand Down Expand Up @@ -893,9 +893,7 @@ void handleAudioPose(float qx, float qy, float qz, float qw, float px, float py,
@Keep
@SuppressWarnings("unused")
void handleResize(final int aHandle, final float aWorldWidth, final float aWorldHeight) {
runOnUiThread(() -> {
mWindows.getFocusedWindow().handleResizeEvent(aWorldWidth, aWorldHeight);
});
runOnUiThread(() -> mWindows.getFocusedWindow().handleResizeEvent(aWorldWidth, aWorldHeight));
}

@Keep
Expand Down Expand Up @@ -1008,7 +1006,11 @@ void renderPointerLayer(final Surface aSurface, final long aNativeCallback) {
@Keep
@SuppressWarnings("unused")
String getStorageAbsolutePath() {
return getExternalFilesDir(null).getAbsolutePath();
final File path = getExternalFilesDir(null);
if (path == null) {
return "";
}
return path.getAbsolutePath();
}

@Keep
Expand Down Expand Up @@ -1067,7 +1069,7 @@ private void handlePoorPerformance() {
return;
}
WindowWidget window = mWindows.getFocusedWindow();
if (window == null) {
if (window == null || window.getSession() == null) {
return;
}
final String originalUri = window.getSession().getCurrentUri();
Expand Down Expand Up @@ -1143,13 +1145,17 @@ private void updateActiveDialog(final Widget aWidget) {
}
}

@SuppressWarnings("BooleanMethodIsAlwaysInverted")
private boolean isWidgetInputEnabled(Widget aWidget) {
return mActiveDialog == null || aWidget == null || mActiveDialog == aWidget || aWidget instanceof KeyboardWidget;
}

// WidgetManagerDelegate
@Override
public void addWidget(Widget aWidget) {
if (aWidget == null) {
return;
}
mWidgets.put(aWidget.getHandle(), aWidget);
((View)aWidget).setVisibility(aWidget.getPlacement().visible ? View.VISIBLE : View.GONE);
final int handle = aWidget.getHandle();
Expand All @@ -1160,6 +1166,9 @@ public void addWidget(Widget aWidget) {

@Override
public void updateWidget(final Widget aWidget) {
if (aWidget == null) {
return;
}
final int handle = aWidget.getHandle();
final WidgetPlacement clone = aWidget.getPlacement().clone();
queueRunnable(() -> updateWidgetNative(handle, clone));
Expand Down Expand Up @@ -1202,6 +1211,9 @@ public void updateWidget(final Widget aWidget) {

@Override
public void removeWidget(final Widget aWidget) {
if (aWidget == null) {
return;
}
mWidgets.remove(aWidget.getHandle());
mWidgetContainer.removeView((View) aWidget);
aWidget.setFirstPaintReady(false);
Expand All @@ -1218,35 +1230,44 @@ public void updateVisibleWidgets() {

@Override
public void startWidgetResize(final Widget aWidget, float aMaxWidth, float aMaxHeight, float minWidth, float minHeight) {
if (aWidget == null) {
return;
}
mWindows.enterResizeMode();
queueRunnable(() -> startWidgetResizeNative(aWidget.getHandle(), aMaxWidth, aMaxHeight, minWidth, minHeight));
}

@Override
public void finishWidgetResize(final Widget aWidget) {
if (aWidget == null) {
return;
}
mWindows.exitResizeMode();
queueRunnable(() -> finishWidgetResizeNative(aWidget.getHandle()));
}

@Override
public void startWidgetMove(final Widget aWidget, @WidgetMoveBehaviourFlags int aMoveBehaviour) {
if (aWidget == null) {
return;
}
queueRunnable(() -> startWidgetMoveNative(aWidget.getHandle(), aMoveBehaviour));
}

@Override
public void finishWidgetMove() {
queueRunnable(() -> finishWidgetMoveNative());
queueRunnable(this::finishWidgetMoveNative);
}

@Override
public void addUpdateListener(UpdateListener aUpdateListener) {
public void addUpdateListener(@NonNull UpdateListener aUpdateListener) {
if (!mWidgetUpdateListeners.contains(aUpdateListener)) {
mWidgetUpdateListeners.add(aUpdateListener);
}
}

@Override
public void removeUpdateListener(UpdateListener aUpdateListener) {
public void removeUpdateListener(@NonNull UpdateListener aUpdateListener) {
mWidgetUpdateListeners.remove(aUpdateListener);
}

Expand All @@ -1263,14 +1284,14 @@ public void removePermissionListener(PermissionListener aListener) {
}

@Override
public void addFocusChangeListener(FocusChangeListener aListener) {
public void addFocusChangeListener(@NonNull FocusChangeListener aListener) {
if (!mFocusChangeListeners.contains(aListener)) {
mFocusChangeListeners.add(aListener);
}
}

@Override
public void removeFocusChangeListener(FocusChangeListener aListener) {
public void removeFocusChangeListener(@NonNull FocusChangeListener aListener) {
mFocusChangeListeners.remove(aListener);
}

Expand Down Expand Up @@ -1300,12 +1321,12 @@ public void removeConnectivityListener(Delegate aListener) {
}

@Override
public void pushBackHandler(Runnable aRunnable) {
public void pushBackHandler(@NonNull Runnable aRunnable) {
mBackHandlers.addLast(aRunnable);
}

@Override
public void popBackHandler(Runnable aRunnable) {
public void popBackHandler(@NonNull Runnable aRunnable) {
mBackHandlers.removeLastOccurrence(aRunnable);
}

Expand Down Expand Up @@ -1379,12 +1400,12 @@ public void keyboardDismissed() {

@Override
public void updateEnvironment() {
queueRunnable(() -> updateEnvironmentNative());
queueRunnable(this::updateEnvironmentNative);
}

@Override
public void updatePointerColor() {
queueRunnable(() -> updatePointerColorNative());
queueRunnable(this::updatePointerColorNative);
}

@Override
Expand Down
Expand Up @@ -44,13 +44,13 @@ interface WorldClickListener {
int CPU_LEVEL_HIGH = 1;

int newWidgetHandle();
void addWidget(@NonNull Widget aWidget);
void updateWidget(@NonNull Widget aWidget);
void removeWidget(@NonNull Widget aWidget);
void addWidget(Widget aWidget);
void updateWidget(Widget aWidget);
void removeWidget(Widget aWidget);
void updateVisibleWidgets();
void startWidgetResize(@NonNull Widget aWidget, float maxWidth, float maxHeight, float minWidth, float minHeight);
void finishWidgetResize(@NonNull Widget aWidget);
void startWidgetMove(@NonNull Widget aWidget, @WidgetMoveBehaviourFlags int aMoveBehaviour);
void startWidgetResize(Widget aWidget, float maxWidth, float maxHeight, float minWidth, float minHeight);
void finishWidgetResize(Widget aWidget);
void startWidgetMove(Widget aWidget, @WidgetMoveBehaviourFlags int aMoveBehaviour);
void finishWidgetMove();
void addUpdateListener(@NonNull UpdateListener aUpdateListener);
void removeUpdateListener(@NonNull UpdateListener aUpdateListener);
Expand Down Expand Up @@ -79,7 +79,7 @@ interface WorldClickListener {
boolean isPermissionGranted(@NonNull String permission);
void requestPermission(String uri, @NonNull String permission, GeckoSession.PermissionDelegate.Callback aCallback);
boolean canOpenNewWindow();
void openNewWindow(@NonNull String uri);
void openNewWindow(String uri);
void openNewTab(@NonNull String uri);
void openNewTabForeground(@NonNull String uri);
WindowWidget getFocusedWindow();
Expand Down

0 comments on commit e318b30

Please sign in to comment.