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

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

Issue 143673004: Fix the crash issue caused by vibrate permission (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Check permissin instead of try-catch Created 6 years, 11 months 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 | « no previous file | no next file » | 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
index 10edcbb1737cefe62d0a4d1f7d96ee876a749bfe..0e5d4591a6cc7b4e5dda16399a6d503ee1d97d15 100644
--- a/content/public/android/java/src/org/chromium/content/browser/VibrationProvider.java
+++ b/content/public/android/java/src/org/chromium/content/browser/VibrationProvider.java
@@ -5,8 +5,10 @@
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;
@@ -16,9 +18,11 @@ import org.chromium.base.JNINamespace;
*/
@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) {
@@ -27,17 +31,23 @@ class VibrationProvider {
@CalledByNative
private void vibrate(long milliseconds) {
- if (mAudioManager.getRingerMode() != AudioManager.RINGER_MODE_SILENT)
- mVibrator.vibrate(milliseconds);
+ if (mAudioManager.getRingerMode() != AudioManager.RINGER_MODE_SILENT) {
+ if (mHasVibratePermission) mVibrator.vibrate(milliseconds);
Michael van Ouwerkerk 2014/01/28 15:09:04 This condition would be cleaner if merged into the
+ }
}
@CalledByNative
private void cancelVibration() {
- mVibrator.cancel();
+ 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.e(TAG, "Caught security exception, requires VIBRATE permission.");
Michael van Ouwerkerk 2014/01/28 15:09:04 This code did not actually catch an exception, ple
jdduke (slow) 2014/01/28 15:45:33 Also, could we make this a warning, Log.w, instead
+ }
}
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698