Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(996)

Unified Diff: content/public/android/java/src/org/chromium/content/browser/VibrationProvider.java

Issue 826613003: Revert of Vibration API : migrate to device/vibration using mojo. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/content_renderer.gypi ('k') | content/public/browser/content_browser_client.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/public/android/java/src/org/chromium/content/browser/VibrationProvider.java
diff --git a/content/public/android/java/src/org/chromium/content/browser/VibrationProvider.java b/content/public/android/java/src/org/chromium/content/browser/VibrationProvider.java
new file mode 100644
index 0000000000000000000000000000000000000000..0b9da7507bf06ce3481cbedf69393e6d6e3cdbd6
--- /dev/null
+++ b/content/public/android/java/src/org/chromium/content/browser/VibrationProvider.java
@@ -0,0 +1,54 @@
+// Copyright 2013 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.
+
+package org.chromium.content.browser;
+
+import android.content.Context;
+import android.content.pm.PackageManager;
+import android.media.AudioManager;
+import android.os.Vibrator;
+import android.util.Log;
+
+import org.chromium.base.CalledByNative;
+import org.chromium.base.JNINamespace;
+
+/**
+ * This is the implementation of the C++ counterpart VibrationProvider.
+ */
+@JNINamespace("content")
+class VibrationProvider {
+ private static final String TAG = "VibrationProvider";
+
+ private final AudioManager mAudioManager;
+ private final Vibrator mVibrator;
+ private final boolean mHasVibratePermission;
+
+ @CalledByNative
+ private static VibrationProvider create(Context context) {
+ return new VibrationProvider(context);
+ }
+
+ @CalledByNative
+ private void vibrate(long milliseconds) {
+ if (mAudioManager.getRingerMode() != AudioManager.RINGER_MODE_SILENT
+ && mHasVibratePermission) {
+ mVibrator.vibrate(milliseconds);
+ }
+ }
+
+ @CalledByNative
+ private void cancelVibration() {
+ if (mHasVibratePermission) mVibrator.cancel();
+ }
+
+ private VibrationProvider(Context context) {
+ mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
+ mVibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
+ mHasVibratePermission = context.checkCallingOrSelfPermission(
+ android.Manifest.permission.VIBRATE) == PackageManager.PERMISSION_GRANTED;
+ if (!mHasVibratePermission) {
+ Log.w(TAG, "Failed to use vibrate API, requires VIBRATE permission.");
+ }
+ }
+}
« no previous file with comments | « content/content_renderer.gypi ('k') | content/public/browser/content_browser_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698