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

Side by Side 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: Add myself in the AUTHORS file Created 6 years, 10 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 unified diff | Download patch
« no previous file with comments | « AUTHORS ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.content.browser; 5 package org.chromium.content.browser;
6 6
7 import android.content.Context; 7 import android.content.Context;
8 import android.content.pm.PackageManager;
8 import android.media.AudioManager; 9 import android.media.AudioManager;
9 import android.os.Vibrator; 10 import android.os.Vibrator;
11 import android.util.Log;
10 12
11 import org.chromium.base.CalledByNative; 13 import org.chromium.base.CalledByNative;
12 import org.chromium.base.JNINamespace; 14 import org.chromium.base.JNINamespace;
13 15
14 /** 16 /**
15 * This is the implementation of the C++ counterpart VibrationProvider. 17 * This is the implementation of the C++ counterpart VibrationProvider.
16 */ 18 */
17 @JNINamespace("content") 19 @JNINamespace("content")
18 class VibrationProvider { 20 class VibrationProvider {
21 private static final String TAG = "VibrationProvider";
19 22
20 private final AudioManager mAudioManager; 23 private final AudioManager mAudioManager;
21 private final Vibrator mVibrator; 24 private final Vibrator mVibrator;
25 private final boolean mHasVibratePermission;
22 26
23 @CalledByNative 27 @CalledByNative
24 private static VibrationProvider create(Context context) { 28 private static VibrationProvider create(Context context) {
25 return new VibrationProvider(context); 29 return new VibrationProvider(context);
26 } 30 }
27 31
28 @CalledByNative 32 @CalledByNative
29 private void vibrate(long milliseconds) { 33 private void vibrate(long milliseconds) {
30 if (mAudioManager.getRingerMode() != AudioManager.RINGER_MODE_SILENT) 34 if (mAudioManager.getRingerMode() != AudioManager.RINGER_MODE_SILENT &&
35 mHasVibratePermission) {
31 mVibrator.vibrate(milliseconds); 36 mVibrator.vibrate(milliseconds);
37 }
32 } 38 }
33 39
34 @CalledByNative 40 @CalledByNative
35 private void cancelVibration() { 41 private void cancelVibration() {
36 mVibrator.cancel(); 42 if (mHasVibratePermission) mVibrator.cancel();
37 } 43 }
38 44
39 private VibrationProvider(Context context) { 45 private VibrationProvider(Context context) {
40 mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SE RVICE); 46 mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SE RVICE);
41 mVibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE ); 47 mVibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE );
48 mHasVibratePermission = context.checkCallingOrSelfPermission(
49 android.Manifest.permission.VIBRATE) == PackageManager.PERMISSIO N_GRANTED;
50 if (!mHasVibratePermission) {
51 Log.w(TAG, "Failed to use vibrate API, requires VIBRATE permission." );
52 }
42 } 53 }
43 } 54 }
OLDNEW
« no previous file with comments | « AUTHORS ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698