Skip to content

Commit

Permalink
VR: Add java-side plumbing for updating GVR Keyboard
Browse files Browse the repository at this point in the history
Note that this path is not exercised yet.

Bug: 799584
Cq-Include-Trybots: master.tryserver.chromium.android:android_optional_gpu_tests_rel;master.tryserver.chromium.linux:linux_optional_gpu_tests_rel;master.tryserver.chromium.linux:linux_vr;master.tryserver.chromium.mac:mac_optional_gpu_tests_rel;master.tryserver.chromium.win:win_optional_gpu_tests_rel
Change-Id: I45f34d54eabcbd539c17d3d87ba8c029489a0f28
Reviewed-on: https://chromium-review.googlesource.com/944750
Commit-Queue: Yash Malik <ymalik@chromium.org>
Reviewed-by: Michael Thiessen <mthiesse@chromium.org>
Cr-Commit-Position: refs/heads/master@{#540391}
  • Loading branch information
Yash Malik authored and Commit Bot committed Mar 2, 2018
1 parent 614415c commit d68a05a
Show file tree
Hide file tree
Showing 13 changed files with 68 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ public class VrShellDelegate
// when used with startActivityForResult...
public static final int EXIT_VR_RESULT = 7212;
public static final int VR_SERVICES_UPDATE_RESULT = 7213;
public static final int GVR_KEYBOARD_UPDATE_RESULT = 7214;

private static final int ENTER_VR_NOT_NECESSARY = 0;
private static final int ENTER_VR_CANCELLED = 1;
Expand All @@ -113,6 +114,9 @@ public class VrShellDelegate
private static final String VR_CORE_MARKET_URI =
"market://details?id=" + VrCoreVersionChecker.VR_CORE_PACKAGE_ID;

private static final String GVR_KEYBOARD_MARKET_URI =
"market://details?id=com.google.android.vr.inputmethod";

// This value is intentionally probably overkill. This is the time we need to wait from when
// Chrome is resumed, to when Chrome actually renders a black frame, so that we can cancel the
// stay_hidden animation and not see a white monoscopic frame in-headset. 150ms is definitely
Expand Down Expand Up @@ -322,6 +326,10 @@ public static boolean onActivityResultWithNative(int requestCode, int resultCode
if (sInstance != null) sInstance.onVrServicesMaybeUpdated();
return true;
}
// Handles the result of requesting to update GVR Keyboard.
if (requestCode == GVR_KEYBOARD_UPDATE_RESULT) {
return true;
}
return false;
}

Expand Down Expand Up @@ -1776,6 +1784,12 @@ public boolean onInfoBarButtonClicked(boolean isPrimary) {
buttonText, null, true);
}

/* package */ void promptForKeyboardUpdate() {
mActivity.startActivityForResult(
new Intent(Intent.ACTION_VIEW, Uri.parse(GVR_KEYBOARD_MARKET_URI)),
GVR_KEYBOARD_UPDATE_RESULT);
}

private boolean createVrShell() {
assert mVrShell == null;
if (mVrClassesWrapper == null) return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,21 @@ public void onDenied() {}
}, UiUnsupportedMode.VOICE_SEARCH_NEEDS_RECORD_AUDIO_OS_PERMISSION);
}

// Called when the user has an older GVR Keyboard installed on their device and we need them to
// have a newer one.
@CalledByNative
public void onNeedsKeyboardUpdate() {
VrShellDelegate.requestToExitVr(new OnExitVrRequestListener() {
@Override
public void onSucceeded() {
mDelegate.promptForKeyboardUpdate();
}

@Override
public void onDenied() {}
}, UiUnsupportedMode.NEEDS_KEYBOARD_UPDATE);
}

// Exits CCT, returning to the app that opened it.
@CalledByNative
public void exitCct() {
Expand Down
14 changes: 12 additions & 2 deletions chrome/browser/android/vr/gvr_keyboard_delegate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,14 @@

// This method is supplied by the VR keyboard shim, but is not part of the
// GVR interface.
bool gvr_keyboard_supports_selection(gvr_keyboard_context* context);
bool gvr_keyboard_supports_selection();
int64_t gvr_keyboard_version();

namespace vr {

// The minimum keyboard version required for the needed features to work.
constexpr int64_t kMinRequiredApiVersion = 2;

namespace {

void OnKeyboardEvent(void* closure, GvrKeyboardDelegate::EventType event) {
Expand All @@ -38,6 +42,12 @@ std::unique_ptr<GvrKeyboardDelegate> GvrKeyboardDelegate::Create() {
auto* gvr_keyboard = gvr_keyboard_create(callback, OnKeyboardEvent);
if (!gvr_keyboard)
return nullptr;

if (gvr_keyboard_version() < kMinRequiredApiVersion) {
gvr_keyboard_destroy(&gvr_keyboard);
return nullptr;
}

delegate->Init(gvr_keyboard);
return delegate;
}
Expand Down Expand Up @@ -126,7 +136,7 @@ void GvrKeyboardDelegate::Draw(const CameraModel& model) {
}

bool GvrKeyboardDelegate::SupportsSelection() {
return gvr_keyboard_supports_selection(gvr_keyboard_);
return gvr_keyboard_supports_selection();
}

void GvrKeyboardDelegate::OnTouchStateUpdated(
Expand Down
9 changes: 8 additions & 1 deletion chrome/browser/android/vr/gvr_keyboard_shim.cc
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,14 @@ void gvr_keyboard_hide(gvr_keyboard_context* context) {
keyboard_api->impl_gvr_keyboard_hide(context);
}

bool gvr_keyboard_supports_selection(gvr_keyboard_context* context) {
bool gvr_keyboard_supports_selection() {
if (!keyboard_api)
return false;
return keyboard_api->min_version >= kSelectionSupportApiVersion;
}

int64_t gvr_keyboard_version() {
if (!keyboard_api)
return -1;
return keyboard_api->min_version;
}
2 changes: 2 additions & 0 deletions chrome/browser/android/vr/vr_gl_thread.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ void VrGLThread::Init() {
}
auto* keyboard_delegate =
!keyboard_delegate_ ? nullptr : keyboard_delegate_.get();
if (!keyboard_delegate)
ui_initial_state_.needs_keyboard_update = true;
auto ui = std::make_unique<Ui>(this, this, keyboard_delegate,
text_input_delegate_.get(), ui_initial_state_);
if (keyboard_enabled) {
Expand Down
5 changes: 5 additions & 0 deletions chrome/browser/android/vr/vr_shell.cc
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,11 @@ void VrShell::OnUnsupportedMode(UiUnsupportedMode mode) {
Java_VrShellImpl_onUnhandledPermissionPrompt(env, j_vr_shell_);
return;
}
case UiUnsupportedMode::kNeedsKeyboardUpdate: {
JNIEnv* env = base::android::AttachCurrentThread();
Java_VrShellImpl_onNeedsKeyboardUpdate(env, j_vr_shell_);
return;
}
case UiUnsupportedMode::kCount:
NOTREACHED(); // Should never be used as a mode.
return;
Expand Down
2 changes: 2 additions & 0 deletions chrome/browser/vr/model/modal_prompt_type.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ UiUnsupportedMode GetReasonForPrompt(ModalPromptType prompt) {
return UiUnsupportedMode::kVoiceSearchNeedsRecordAudioOsPermission;
case kModalPromptTypeGenericUnsupportedFeature:
return UiUnsupportedMode::kGenericUnsupportedFeature;
case kModalPromptTypeUpdateKeyboard:
return UiUnsupportedMode::kNeedsKeyboardUpdate;
case kModalPromptTypeNone:
return UiUnsupportedMode::kCount;
}
Expand Down
1 change: 1 addition & 0 deletions chrome/browser/vr/model/modal_prompt_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ enum ModalPromptType {
kModalPromptTypeExitVRForSiteInfo,
kModalPromptTypeExitVRForVoiceSearchRecordAudioOsPermission,
kModalPromptTypeGenericUnsupportedFeature,
kModalPromptTypeUpdateKeyboard,
};

UiUnsupportedMode GetReasonForPrompt(ModalPromptType prompt);
Expand Down
1 change: 1 addition & 0 deletions chrome/browser/vr/model/model.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ struct Model {
bool can_apply_new_background = false;
bool background_loaded = false;
bool supports_selection = true;
bool needs_keyboard_update = false;

// WebVR state.
WebVrModel web_vr;
Expand Down
4 changes: 4 additions & 0 deletions chrome/browser/vr/ui.cc
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,9 @@ void Ui::ShowExitVrPrompt(UiUnsupportedMode reason) {
model_->active_modal_prompt_type =
kModalPromptTypeGenericUnsupportedFeature;
return;
case UiUnsupportedMode::kNeedsKeyboardUpdate:
model_->active_modal_prompt_type = kModalPromptTypeUpdateKeyboard;
return;
case UiUnsupportedMode::kCount:
NOTREACHED(); // Should never be used as a mode (when |enabled| is true).
return;
Expand Down Expand Up @@ -439,6 +442,7 @@ void Ui::InitializeModel(const UiInitialState& ui_initial_state) {
ui_initial_state.skips_redraw_when_not_dirty;
model_->waiting_for_background = ui_initial_state.assets_available;
model_->supports_selection = ui_initial_state.supports_selection;
model_->needs_keyboard_update = ui_initial_state.needs_keyboard_update;
}

void Ui::AcceptDoffPromptForTesting() {
Expand Down
1 change: 1 addition & 0 deletions chrome/browser/vr/ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ struct UiInitialState {
// TODO(tiborg): Remove this flag.
bool assets_available = false;
bool supports_selection = true;
bool needs_keyboard_update = false;
};

// This class manages all GLThread owned objects and GL rendering for VrShell.
Expand Down
1 change: 1 addition & 0 deletions chrome/browser/vr/ui_unsupported_mode.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ enum class UiUnsupportedMode : int {
// kURLWithStrongRTLChars = 3, // Obsolete.
kVoiceSearchNeedsRecordAudioOsPermission = 4, // TODO(ddorwin): Android only.
kGenericUnsupportedFeature = 5,
kNeedsKeyboardUpdate = 6,
// This must be last.
kCount,
};
Expand Down
2 changes: 2 additions & 0 deletions tools/metrics/histograms/enums.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45293,6 +45293,8 @@ Called by update_traffic_annotation_histograms.py.-->
<int value="2" label="Unhandled PageInfo"/>
<int value="3" label="URL contained strong RTL chars (obsolete)"/>
<int value="4" label="Chrome needs audio permission for voice input"/>
<int value="5" label="A non-specific unsupported feature was encountered"/>
<int value="6" label="The keyboard version is out-of-date"/>
</enum>

<enum name="VRViewerType">
Expand Down

0 comments on commit d68a05a

Please sign in to comment.