The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.server; |
| 18 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 19 | import android.app.AppOpsManager; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 20 | import android.content.BroadcastReceiver; |
| 21 | import android.content.Context; |
| 22 | import android.content.Intent; |
| 23 | import android.content.IntentFilter; |
| 24 | import android.content.pm.PackageManager; |
Jeff Brown | 7f6c231 | 2012-04-13 20:38:38 -0700 | [diff] [blame] | 25 | import android.database.ContentObserver; |
| 26 | import android.hardware.input.InputManager; |
Dianne Hackborn | 91268cf | 2013-06-13 19:06:50 -0700 | [diff] [blame] | 27 | import android.os.BatteryStats; |
Joe Onorato | 95e4f70 | 2009-03-24 19:29:09 -0700 | [diff] [blame] | 28 | import android.os.Handler; |
Mike Lockwood | 3a32213 | 2009-11-24 00:30:52 -0500 | [diff] [blame] | 29 | import android.os.IVibratorService; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 30 | import android.os.PowerManager; |
Dianne Hackborn | eb94fa7 | 2014-06-03 17:48:12 -0700 | [diff] [blame] | 31 | import android.os.PowerManagerInternal; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 32 | import android.os.Process; |
| 33 | import android.os.RemoteException; |
| 34 | import android.os.IBinder; |
| 35 | import android.os.Binder; |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 36 | import android.os.ServiceManager; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 37 | import android.os.SystemClock; |
Jeff Brown | d493596 | 2012-09-25 13:27:20 -0700 | [diff] [blame] | 38 | import android.os.UserHandle; |
Jeff Brown | 7f6c231 | 2012-04-13 20:38:38 -0700 | [diff] [blame] | 39 | import android.os.Vibrator; |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 40 | import android.os.WorkSource; |
Jeff Brown | 7f6c231 | 2012-04-13 20:38:38 -0700 | [diff] [blame] | 41 | import android.provider.Settings; |
| 42 | import android.provider.Settings.SettingNotFoundException; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 43 | import android.util.Slog; |
Jeff Brown | 7f6c231 | 2012-04-13 20:38:38 -0700 | [diff] [blame] | 44 | import android.view.InputDevice; |
John Spurlock | 7b41467 | 2014-07-18 13:02:39 -0400 | [diff] [blame^] | 45 | import android.media.AudioAttributes; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 46 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 47 | import com.android.internal.app.IAppOpsService; |
| 48 | import com.android.internal.app.IBatteryStats; |
| 49 | |
Jeff Brown | 7f6c231 | 2012-04-13 20:38:38 -0700 | [diff] [blame] | 50 | import java.util.ArrayList; |
Jeff Brown | 969579b | 2014-05-20 19:29:29 -0700 | [diff] [blame] | 51 | import java.util.Iterator; |
Patrick Scott | 18dd5f0 | 2009-07-02 11:31:12 -0400 | [diff] [blame] | 52 | import java.util.LinkedList; |
| 53 | import java.util.ListIterator; |
| 54 | |
Jeff Brown | 7f6c231 | 2012-04-13 20:38:38 -0700 | [diff] [blame] | 55 | public class VibratorService extends IVibratorService.Stub |
| 56 | implements InputManager.InputDeviceListener { |
Mike Lockwood | 3a32213 | 2009-11-24 00:30:52 -0500 | [diff] [blame] | 57 | private static final String TAG = "VibratorService"; |
Mike Lockwood | cc9a63d | 2009-11-10 07:50:28 -0500 | [diff] [blame] | 58 | |
Patrick Scott | 18dd5f0 | 2009-07-02 11:31:12 -0400 | [diff] [blame] | 59 | private final LinkedList<Vibration> mVibrations; |
| 60 | private Vibration mCurrentVibration; |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 61 | private final WorkSource mTmpWorkSource = new WorkSource(); |
Jeff Brown | 7f6c231 | 2012-04-13 20:38:38 -0700 | [diff] [blame] | 62 | private final Handler mH = new Handler(); |
| 63 | |
| 64 | private final Context mContext; |
| 65 | private final PowerManager.WakeLock mWakeLock; |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 66 | private final IAppOpsService mAppOpsService; |
| 67 | private final IBatteryStats mBatteryStatsService; |
Dianne Hackborn | eb94fa7 | 2014-06-03 17:48:12 -0700 | [diff] [blame] | 68 | private PowerManagerInternal mPowerManagerInternal; |
Jeff Brown | 7f6c231 | 2012-04-13 20:38:38 -0700 | [diff] [blame] | 69 | private InputManager mIm; |
| 70 | |
| 71 | volatile VibrateThread mThread; |
| 72 | |
| 73 | // mInputDeviceVibrators lock should be acquired after mVibrations lock, if both are |
| 74 | // to be acquired |
| 75 | private final ArrayList<Vibrator> mInputDeviceVibrators = new ArrayList<Vibrator>(); |
| 76 | private boolean mVibrateInputDevicesSetting; // guarded by mInputDeviceVibrators |
| 77 | private boolean mInputDeviceListenerRegistered; // guarded by mInputDeviceVibrators |
| 78 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 79 | private int mCurVibUid = -1; |
Ruchi Kandoi | 13b03af | 2014-05-07 20:10:32 -0700 | [diff] [blame] | 80 | private boolean mLowPowerMode; |
| 81 | private SettingsObserver mSettingObserver; |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 82 | |
Jeff Brown | 7f6c231 | 2012-04-13 20:38:38 -0700 | [diff] [blame] | 83 | native static boolean vibratorExists(); |
| 84 | native static void vibratorOn(long milliseconds); |
| 85 | native static void vibratorOff(); |
Patrick Scott | 18dd5f0 | 2009-07-02 11:31:12 -0400 | [diff] [blame] | 86 | |
Patrick Scott | 18dd5f0 | 2009-07-02 11:31:12 -0400 | [diff] [blame] | 87 | private class Vibration implements IBinder.DeathRecipient { |
| 88 | private final IBinder mToken; |
| 89 | private final long mTimeout; |
| 90 | private final long mStartTime; |
| 91 | private final long[] mPattern; |
| 92 | private final int mRepeat; |
John Spurlock | 7b41467 | 2014-07-18 13:02:39 -0400 | [diff] [blame^] | 93 | private final int mUsageHint; |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 94 | private final int mUid; |
Christoph Studer | 8fd7f1e | 2014-04-11 17:35:05 -0400 | [diff] [blame] | 95 | private final String mOpPkg; |
Patrick Scott | 18dd5f0 | 2009-07-02 11:31:12 -0400 | [diff] [blame] | 96 | |
John Spurlock | 7b41467 | 2014-07-18 13:02:39 -0400 | [diff] [blame^] | 97 | Vibration(IBinder token, long millis, int usageHint, int uid, String opPkg) { |
| 98 | this(token, millis, null, 0, usageHint, uid, opPkg); |
Patrick Scott | 18dd5f0 | 2009-07-02 11:31:12 -0400 | [diff] [blame] | 99 | } |
| 100 | |
John Spurlock | 7b41467 | 2014-07-18 13:02:39 -0400 | [diff] [blame^] | 101 | Vibration(IBinder token, long[] pattern, int repeat, int usageHint, int uid, |
Christoph Studer | 8fd7f1e | 2014-04-11 17:35:05 -0400 | [diff] [blame] | 102 | String opPkg) { |
John Spurlock | 7b41467 | 2014-07-18 13:02:39 -0400 | [diff] [blame^] | 103 | this(token, 0, pattern, repeat, usageHint, uid, opPkg); |
Patrick Scott | 18dd5f0 | 2009-07-02 11:31:12 -0400 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | private Vibration(IBinder token, long millis, long[] pattern, |
John Spurlock | 7b41467 | 2014-07-18 13:02:39 -0400 | [diff] [blame^] | 107 | int repeat, int usageHint, int uid, String opPkg) { |
Patrick Scott | 18dd5f0 | 2009-07-02 11:31:12 -0400 | [diff] [blame] | 108 | mToken = token; |
| 109 | mTimeout = millis; |
| 110 | mStartTime = SystemClock.uptimeMillis(); |
| 111 | mPattern = pattern; |
| 112 | mRepeat = repeat; |
John Spurlock | 7b41467 | 2014-07-18 13:02:39 -0400 | [diff] [blame^] | 113 | mUsageHint = usageHint; |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 114 | mUid = uid; |
Christoph Studer | 8fd7f1e | 2014-04-11 17:35:05 -0400 | [diff] [blame] | 115 | mOpPkg = opPkg; |
Patrick Scott | 18dd5f0 | 2009-07-02 11:31:12 -0400 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | public void binderDied() { |
| 119 | synchronized (mVibrations) { |
| 120 | mVibrations.remove(this); |
| 121 | if (this == mCurrentVibration) { |
| 122 | doCancelVibrateLocked(); |
| 123 | startNextVibrationLocked(); |
| 124 | } |
| 125 | } |
| 126 | } |
| 127 | |
| 128 | public boolean hasLongerTimeout(long millis) { |
| 129 | if (mTimeout == 0) { |
| 130 | // This is a pattern, return false to play the simple |
| 131 | // vibration. |
| 132 | return false; |
| 133 | } |
| 134 | if ((mStartTime + mTimeout) |
| 135 | < (SystemClock.uptimeMillis() + millis)) { |
| 136 | // If this vibration will end before the time passed in, let |
| 137 | // the new vibration play. |
| 138 | return false; |
| 139 | } |
| 140 | return true; |
| 141 | } |
Jeff Brown | 969579b | 2014-05-20 19:29:29 -0700 | [diff] [blame] | 142 | |
| 143 | public boolean isSystemHapticFeedback() { |
| 144 | return (mUid == Process.SYSTEM_UID || mUid == 0) && mRepeat < 0; |
| 145 | } |
Patrick Scott | 18dd5f0 | 2009-07-02 11:31:12 -0400 | [diff] [blame] | 146 | } |
| 147 | |
Mike Lockwood | 3a32213 | 2009-11-24 00:30:52 -0500 | [diff] [blame] | 148 | VibratorService(Context context) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 149 | // Reset the hardware to a default state, in case this is a runtime |
| 150 | // restart instead of a fresh boot. |
| 151 | vibratorOff(); |
| 152 | |
| 153 | mContext = context; |
| 154 | PowerManager pm = (PowerManager)context.getSystemService( |
| 155 | Context.POWER_SERVICE); |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 156 | mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "*vibrator*"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 157 | mWakeLock.setReferenceCounted(true); |
| 158 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 159 | mAppOpsService = IAppOpsService.Stub.asInterface(ServiceManager.getService(Context.APP_OPS_SERVICE)); |
Dianne Hackborn | 91268cf | 2013-06-13 19:06:50 -0700 | [diff] [blame] | 160 | mBatteryStatsService = IBatteryStats.Stub.asInterface(ServiceManager.getService( |
| 161 | BatteryStats.SERVICE_NAME)); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 162 | |
Patrick Scott | 18dd5f0 | 2009-07-02 11:31:12 -0400 | [diff] [blame] | 163 | mVibrations = new LinkedList<Vibration>(); |
| 164 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 165 | IntentFilter filter = new IntentFilter(); |
| 166 | filter.addAction(Intent.ACTION_SCREEN_OFF); |
| 167 | context.registerReceiver(mIntentReceiver, filter); |
| 168 | } |
| 169 | |
Jeff Brown | 7f6c231 | 2012-04-13 20:38:38 -0700 | [diff] [blame] | 170 | public void systemReady() { |
| 171 | mIm = (InputManager)mContext.getSystemService(Context.INPUT_SERVICE); |
Ruchi Kandoi | 13b03af | 2014-05-07 20:10:32 -0700 | [diff] [blame] | 172 | mSettingObserver = new SettingsObserver(mH); |
Jeff Brown | d493596 | 2012-09-25 13:27:20 -0700 | [diff] [blame] | 173 | |
Dianne Hackborn | eb94fa7 | 2014-06-03 17:48:12 -0700 | [diff] [blame] | 174 | mPowerManagerInternal = LocalServices.getService(PowerManagerInternal.class); |
| 175 | mPowerManagerInternal.registerLowPowerModeObserver( |
| 176 | new PowerManagerInternal.LowPowerModeListener() { |
| 177 | @Override |
| 178 | public void onLowPowerModeChanged(boolean enabled) { |
| 179 | updateInputDeviceVibrators(); |
| 180 | } |
| 181 | }); |
| 182 | |
Jeff Brown | 7f6c231 | 2012-04-13 20:38:38 -0700 | [diff] [blame] | 183 | mContext.getContentResolver().registerContentObserver( |
Ruchi Kandoi | 13b03af | 2014-05-07 20:10:32 -0700 | [diff] [blame] | 184 | Settings.System.getUriFor(Settings.System.VIBRATE_INPUT_DEVICES), |
| 185 | true, mSettingObserver, UserHandle.USER_ALL); |
| 186 | |
Jeff Brown | d493596 | 2012-09-25 13:27:20 -0700 | [diff] [blame] | 187 | mContext.registerReceiver(new BroadcastReceiver() { |
| 188 | @Override |
| 189 | public void onReceive(Context context, Intent intent) { |
| 190 | updateInputDeviceVibrators(); |
| 191 | } |
| 192 | }, new IntentFilter(Intent.ACTION_USER_SWITCHED), null, mH); |
| 193 | |
Jeff Brown | 8206525 | 2012-04-16 13:19:05 -0700 | [diff] [blame] | 194 | updateInputDeviceVibrators(); |
Dianne Hackborn | ea9020e | 2010-11-04 11:39:12 -0700 | [diff] [blame] | 195 | } |
Jeff Brown | 7f6c231 | 2012-04-13 20:38:38 -0700 | [diff] [blame] | 196 | |
Ruchi Kandoi | 13b03af | 2014-05-07 20:10:32 -0700 | [diff] [blame] | 197 | private final class SettingsObserver extends ContentObserver { |
| 198 | public SettingsObserver(Handler handler) { |
| 199 | super(handler); |
| 200 | } |
| 201 | |
| 202 | @Override |
| 203 | public void onChange(boolean SelfChange) { |
| 204 | updateInputDeviceVibrators(); |
| 205 | } |
| 206 | } |
| 207 | |
Jeff Brown | 7f6c231 | 2012-04-13 20:38:38 -0700 | [diff] [blame] | 208 | public boolean hasVibrator() { |
| 209 | return doVibratorExists(); |
| 210 | } |
| 211 | |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 212 | private void verifyIncomingUid(int uid) { |
| 213 | if (uid == Binder.getCallingUid()) { |
| 214 | return; |
| 215 | } |
| 216 | if (Binder.getCallingPid() == Process.myPid()) { |
| 217 | return; |
| 218 | } |
| 219 | mContext.enforcePermission(android.Manifest.permission.UPDATE_APP_OPS_STATS, |
| 220 | Binder.getCallingPid(), Binder.getCallingUid(), null); |
| 221 | } |
| 222 | |
John Spurlock | 7b41467 | 2014-07-18 13:02:39 -0400 | [diff] [blame^] | 223 | public void vibrate(int uid, String opPkg, long milliseconds, int usageHint, |
John Spurlock | 1af30c7 | 2014-03-10 08:33:35 -0400 | [diff] [blame] | 224 | IBinder token) { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 225 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.VIBRATE) |
| 226 | != PackageManager.PERMISSION_GRANTED) { |
| 227 | throw new SecurityException("Requires VIBRATE permission"); |
| 228 | } |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 229 | verifyIncomingUid(uid); |
Patrick Scott | 24f1076 | 2009-08-19 09:03:56 -0400 | [diff] [blame] | 230 | // We're running in the system server so we cannot crash. Check for a |
| 231 | // timeout of 0 or negative. This will ensure that a vibration has |
| 232 | // either a timeout of > 0 or a non-null pattern. |
| 233 | if (milliseconds <= 0 || (mCurrentVibration != null |
| 234 | && mCurrentVibration.hasLongerTimeout(milliseconds))) { |
Patrick Scott | 18dd5f0 | 2009-07-02 11:31:12 -0400 | [diff] [blame] | 235 | // Ignore this vibration since the current vibration will play for |
| 236 | // longer than milliseconds. |
| 237 | return; |
| 238 | } |
Jeff Brown | 7f6c231 | 2012-04-13 20:38:38 -0700 | [diff] [blame] | 239 | |
John Spurlock | 7b41467 | 2014-07-18 13:02:39 -0400 | [diff] [blame^] | 240 | Vibration vib = new Vibration(token, milliseconds, usageHint, uid, opPkg); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 241 | |
| 242 | final long ident = Binder.clearCallingIdentity(); |
| 243 | try { |
| 244 | synchronized (mVibrations) { |
| 245 | removeVibrationLocked(token); |
| 246 | doCancelVibrateLocked(); |
| 247 | mCurrentVibration = vib; |
| 248 | startVibrationLocked(vib); |
| 249 | } |
| 250 | } finally { |
| 251 | Binder.restoreCallingIdentity(ident); |
Patrick Scott | 18dd5f0 | 2009-07-02 11:31:12 -0400 | [diff] [blame] | 252 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 253 | } |
| 254 | |
| 255 | private boolean isAll0(long[] pattern) { |
| 256 | int N = pattern.length; |
| 257 | for (int i = 0; i < N; i++) { |
| 258 | if (pattern[i] != 0) { |
| 259 | return false; |
| 260 | } |
| 261 | } |
| 262 | return true; |
| 263 | } |
| 264 | |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 265 | public void vibratePattern(int uid, String packageName, long[] pattern, int repeat, |
John Spurlock | 7b41467 | 2014-07-18 13:02:39 -0400 | [diff] [blame^] | 266 | int usageHint, IBinder token) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 267 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.VIBRATE) |
| 268 | != PackageManager.PERMISSION_GRANTED) { |
| 269 | throw new SecurityException("Requires VIBRATE permission"); |
| 270 | } |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 271 | verifyIncomingUid(uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 272 | // so wakelock calls will succeed |
| 273 | long identity = Binder.clearCallingIdentity(); |
| 274 | try { |
| 275 | if (false) { |
| 276 | String s = ""; |
| 277 | int N = pattern.length; |
| 278 | for (int i=0; i<N; i++) { |
| 279 | s += " " + pattern[i]; |
| 280 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 281 | Slog.i(TAG, "vibrating with pattern: " + s); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 282 | } |
| 283 | |
| 284 | // we're running in the server so we can't fail |
| 285 | if (pattern == null || pattern.length == 0 |
| 286 | || isAll0(pattern) |
| 287 | || repeat >= pattern.length || token == null) { |
| 288 | return; |
| 289 | } |
| 290 | |
John Spurlock | 7b41467 | 2014-07-18 13:02:39 -0400 | [diff] [blame^] | 291 | Vibration vib = new Vibration(token, pattern, repeat, usageHint, uid, packageName); |
Patrick Scott | 18dd5f0 | 2009-07-02 11:31:12 -0400 | [diff] [blame] | 292 | try { |
| 293 | token.linkToDeath(vib, 0); |
| 294 | } catch (RemoteException e) { |
| 295 | return; |
| 296 | } |
| 297 | |
| 298 | synchronized (mVibrations) { |
| 299 | removeVibrationLocked(token); |
| 300 | doCancelVibrateLocked(); |
| 301 | if (repeat >= 0) { |
| 302 | mVibrations.addFirst(vib); |
| 303 | startNextVibrationLocked(); |
| 304 | } else { |
| 305 | // A negative repeat means that this pattern is not meant |
| 306 | // to repeat. Treat it like a simple vibration. |
| 307 | mCurrentVibration = vib; |
| 308 | startVibrationLocked(vib); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 309 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 310 | } |
| 311 | } |
| 312 | finally { |
| 313 | Binder.restoreCallingIdentity(identity); |
| 314 | } |
| 315 | } |
| 316 | |
Patrick Scott | 18dd5f0 | 2009-07-02 11:31:12 -0400 | [diff] [blame] | 317 | public void cancelVibrate(IBinder token) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 318 | mContext.enforceCallingOrSelfPermission( |
| 319 | android.Manifest.permission.VIBRATE, |
| 320 | "cancelVibrate"); |
| 321 | |
| 322 | // so wakelock calls will succeed |
| 323 | long identity = Binder.clearCallingIdentity(); |
| 324 | try { |
Patrick Scott | 18dd5f0 | 2009-07-02 11:31:12 -0400 | [diff] [blame] | 325 | synchronized (mVibrations) { |
| 326 | final Vibration vib = removeVibrationLocked(token); |
| 327 | if (vib == mCurrentVibration) { |
| 328 | doCancelVibrateLocked(); |
| 329 | startNextVibrationLocked(); |
| 330 | } |
| 331 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 332 | } |
| 333 | finally { |
| 334 | Binder.restoreCallingIdentity(identity); |
| 335 | } |
| 336 | } |
Eric Olsen | f42f15c | 2009-10-29 16:42:03 -0700 | [diff] [blame] | 337 | |
Patrick Scott | 18dd5f0 | 2009-07-02 11:31:12 -0400 | [diff] [blame] | 338 | private final Runnable mVibrationRunnable = new Runnable() { |
| 339 | public void run() { |
| 340 | synchronized (mVibrations) { |
| 341 | doCancelVibrateLocked(); |
| 342 | startNextVibrationLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 343 | } |
Patrick Scott | 18dd5f0 | 2009-07-02 11:31:12 -0400 | [diff] [blame] | 344 | } |
| 345 | }; |
| 346 | |
| 347 | // Lock held on mVibrations |
| 348 | private void doCancelVibrateLocked() { |
| 349 | if (mThread != null) { |
| 350 | synchronized (mThread) { |
| 351 | mThread.mDone = true; |
| 352 | mThread.notify(); |
| 353 | } |
| 354 | mThread = null; |
| 355 | } |
Jeff Brown | 7f6c231 | 2012-04-13 20:38:38 -0700 | [diff] [blame] | 356 | doVibratorOff(); |
Patrick Scott | 18dd5f0 | 2009-07-02 11:31:12 -0400 | [diff] [blame] | 357 | mH.removeCallbacks(mVibrationRunnable); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 358 | reportFinishVibrationLocked(); |
Patrick Scott | 18dd5f0 | 2009-07-02 11:31:12 -0400 | [diff] [blame] | 359 | } |
| 360 | |
| 361 | // Lock held on mVibrations |
| 362 | private void startNextVibrationLocked() { |
| 363 | if (mVibrations.size() <= 0) { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 364 | reportFinishVibrationLocked(); |
Mathias Jeppsson | b23949b | 2010-09-28 14:45:23 +0200 | [diff] [blame] | 365 | mCurrentVibration = null; |
Patrick Scott | 18dd5f0 | 2009-07-02 11:31:12 -0400 | [diff] [blame] | 366 | return; |
| 367 | } |
| 368 | mCurrentVibration = mVibrations.getFirst(); |
| 369 | startVibrationLocked(mCurrentVibration); |
| 370 | } |
| 371 | |
| 372 | // Lock held on mVibrations |
| 373 | private void startVibrationLocked(final Vibration vib) { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 374 | try { |
John Spurlock | 7b41467 | 2014-07-18 13:02:39 -0400 | [diff] [blame^] | 375 | if (mLowPowerMode |
| 376 | && vib.mUsageHint != AudioAttributes.USAGE_NOTIFICATION_TELEPHONY_RINGTONE) { |
Ruchi Kandoi | 664703d | 2014-05-09 16:01:31 -0700 | [diff] [blame] | 377 | return; |
| 378 | } |
Ruchi Kandoi | 13b03af | 2014-05-07 20:10:32 -0700 | [diff] [blame] | 379 | |
John Spurlock | 1af30c7 | 2014-03-10 08:33:35 -0400 | [diff] [blame] | 380 | int mode = mAppOpsService.checkAudioOperation(AppOpsManager.OP_VIBRATE, |
John Spurlock | 7b41467 | 2014-07-18 13:02:39 -0400 | [diff] [blame^] | 381 | vib.mUsageHint, vib.mUid, vib.mOpPkg); |
John Spurlock | 1af30c7 | 2014-03-10 08:33:35 -0400 | [diff] [blame] | 382 | if (mode == AppOpsManager.MODE_ALLOWED) { |
| 383 | mode = mAppOpsService.startOperation(AppOpsManager.getToken(mAppOpsService), |
Christoph Studer | 8fd7f1e | 2014-04-11 17:35:05 -0400 | [diff] [blame] | 384 | AppOpsManager.OP_VIBRATE, vib.mUid, vib.mOpPkg); |
John Spurlock | 1af30c7 | 2014-03-10 08:33:35 -0400 | [diff] [blame] | 385 | } |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 386 | if (mode != AppOpsManager.MODE_ALLOWED) { |
| 387 | if (mode == AppOpsManager.MODE_ERRORED) { |
| 388 | Slog.w(TAG, "Would be an error: vibrate from uid " + vib.mUid); |
| 389 | } |
| 390 | mH.post(mVibrationRunnable); |
| 391 | return; |
| 392 | } |
| 393 | } catch (RemoteException e) { |
| 394 | } |
Patrick Scott | 18dd5f0 | 2009-07-02 11:31:12 -0400 | [diff] [blame] | 395 | if (vib.mTimeout != 0) { |
John Spurlock | 7b41467 | 2014-07-18 13:02:39 -0400 | [diff] [blame^] | 396 | doVibratorOn(vib.mTimeout, vib.mUid, vib.mUsageHint); |
Patrick Scott | 18dd5f0 | 2009-07-02 11:31:12 -0400 | [diff] [blame] | 397 | mH.postDelayed(mVibrationRunnable, vib.mTimeout); |
| 398 | } else { |
| 399 | // mThread better be null here. doCancelVibrate should always be |
| 400 | // called before startNextVibrationLocked or startVibrationLocked. |
| 401 | mThread = new VibrateThread(vib); |
| 402 | mThread.start(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 403 | } |
| 404 | } |
| 405 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 406 | private void reportFinishVibrationLocked() { |
| 407 | if (mCurrentVibration != null) { |
| 408 | try { |
Dianne Hackborn | e98f5db | 2013-07-17 17:23:25 -0700 | [diff] [blame] | 409 | mAppOpsService.finishOperation(AppOpsManager.getToken(mAppOpsService), |
| 410 | AppOpsManager.OP_VIBRATE, mCurrentVibration.mUid, |
Christoph Studer | 8fd7f1e | 2014-04-11 17:35:05 -0400 | [diff] [blame] | 411 | mCurrentVibration.mOpPkg); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 412 | } catch (RemoteException e) { |
| 413 | } |
| 414 | mCurrentVibration = null; |
| 415 | } |
| 416 | } |
| 417 | |
Patrick Scott | 18dd5f0 | 2009-07-02 11:31:12 -0400 | [diff] [blame] | 418 | // Lock held on mVibrations |
| 419 | private Vibration removeVibrationLocked(IBinder token) { |
| 420 | ListIterator<Vibration> iter = mVibrations.listIterator(0); |
| 421 | while (iter.hasNext()) { |
| 422 | Vibration vib = iter.next(); |
| 423 | if (vib.mToken == token) { |
| 424 | iter.remove(); |
Mathias Jeppsson | b23949b | 2010-09-28 14:45:23 +0200 | [diff] [blame] | 425 | unlinkVibration(vib); |
Patrick Scott | 18dd5f0 | 2009-07-02 11:31:12 -0400 | [diff] [blame] | 426 | return vib; |
| 427 | } |
| 428 | } |
| 429 | // We might be looking for a simple vibration which is only stored in |
| 430 | // mCurrentVibration. |
| 431 | if (mCurrentVibration != null && mCurrentVibration.mToken == token) { |
Mathias Jeppsson | b23949b | 2010-09-28 14:45:23 +0200 | [diff] [blame] | 432 | unlinkVibration(mCurrentVibration); |
Patrick Scott | 18dd5f0 | 2009-07-02 11:31:12 -0400 | [diff] [blame] | 433 | return mCurrentVibration; |
| 434 | } |
| 435 | return null; |
| 436 | } |
| 437 | |
Mathias Jeppsson | b23949b | 2010-09-28 14:45:23 +0200 | [diff] [blame] | 438 | private void unlinkVibration(Vibration vib) { |
| 439 | if (vib.mPattern != null) { |
| 440 | // If Vibration object has a pattern, |
| 441 | // the Vibration object has also been linkedToDeath. |
| 442 | vib.mToken.unlinkToDeath(vib, 0); |
| 443 | } |
| 444 | } |
| 445 | |
Jeff Brown | 7f6c231 | 2012-04-13 20:38:38 -0700 | [diff] [blame] | 446 | private void updateInputDeviceVibrators() { |
| 447 | synchronized (mVibrations) { |
| 448 | doCancelVibrateLocked(); |
| 449 | |
| 450 | synchronized (mInputDeviceVibrators) { |
Jeff Brown | 8206525 | 2012-04-16 13:19:05 -0700 | [diff] [blame] | 451 | mVibrateInputDevicesSetting = false; |
| 452 | try { |
Jeff Brown | d493596 | 2012-09-25 13:27:20 -0700 | [diff] [blame] | 453 | mVibrateInputDevicesSetting = Settings.System.getIntForUser( |
| 454 | mContext.getContentResolver(), |
| 455 | Settings.System.VIBRATE_INPUT_DEVICES, UserHandle.USER_CURRENT) > 0; |
Jeff Brown | 8206525 | 2012-04-16 13:19:05 -0700 | [diff] [blame] | 456 | } catch (SettingNotFoundException snfe) { |
| 457 | } |
| 458 | |
Dianne Hackborn | eb94fa7 | 2014-06-03 17:48:12 -0700 | [diff] [blame] | 459 | mLowPowerMode = mPowerManagerInternal.getLowPowerModeEnabled(); |
Ruchi Kandoi | 13b03af | 2014-05-07 20:10:32 -0700 | [diff] [blame] | 460 | |
Jeff Brown | 8206525 | 2012-04-16 13:19:05 -0700 | [diff] [blame] | 461 | if (mVibrateInputDevicesSetting) { |
| 462 | if (!mInputDeviceListenerRegistered) { |
| 463 | mInputDeviceListenerRegistered = true; |
| 464 | mIm.registerInputDeviceListener(this, mH); |
| 465 | } |
| 466 | } else { |
| 467 | if (mInputDeviceListenerRegistered) { |
| 468 | mInputDeviceListenerRegistered = false; |
| 469 | mIm.unregisterInputDeviceListener(this); |
| 470 | } |
| 471 | } |
| 472 | |
Jeff Brown | 7f6c231 | 2012-04-13 20:38:38 -0700 | [diff] [blame] | 473 | mInputDeviceVibrators.clear(); |
| 474 | if (mVibrateInputDevicesSetting) { |
| 475 | int[] ids = mIm.getInputDeviceIds(); |
| 476 | for (int i = 0; i < ids.length; i++) { |
| 477 | InputDevice device = mIm.getInputDevice(ids[i]); |
| 478 | Vibrator vibrator = device.getVibrator(); |
| 479 | if (vibrator.hasVibrator()) { |
| 480 | mInputDeviceVibrators.add(vibrator); |
| 481 | } |
| 482 | } |
| 483 | } |
| 484 | } |
| 485 | |
| 486 | startNextVibrationLocked(); |
| 487 | } |
| 488 | } |
| 489 | |
| 490 | @Override |
| 491 | public void onInputDeviceAdded(int deviceId) { |
| 492 | updateInputDeviceVibrators(); |
| 493 | } |
| 494 | |
| 495 | @Override |
| 496 | public void onInputDeviceChanged(int deviceId) { |
| 497 | updateInputDeviceVibrators(); |
| 498 | } |
| 499 | |
| 500 | @Override |
| 501 | public void onInputDeviceRemoved(int deviceId) { |
| 502 | updateInputDeviceVibrators(); |
| 503 | } |
| 504 | |
| 505 | private boolean doVibratorExists() { |
Jeff Brown | 1064a50 | 2012-05-02 16:51:37 -0700 | [diff] [blame] | 506 | // For now, we choose to ignore the presence of input devices that have vibrators |
| 507 | // when reporting whether the device has a vibrator. Applications often use this |
| 508 | // information to decide whether to enable certain features so they expect the |
| 509 | // result of hasVibrator() to be constant. For now, just report whether |
| 510 | // the device has a built-in vibrator. |
| 511 | //synchronized (mInputDeviceVibrators) { |
| 512 | // return !mInputDeviceVibrators.isEmpty() || vibratorExists(); |
| 513 | //} |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 514 | return vibratorExists(); |
Jeff Brown | 7f6c231 | 2012-04-13 20:38:38 -0700 | [diff] [blame] | 515 | } |
| 516 | |
John Spurlock | 7b41467 | 2014-07-18 13:02:39 -0400 | [diff] [blame^] | 517 | private void doVibratorOn(long millis, int uid, int usageHint) { |
Jeff Brown | 7f6c231 | 2012-04-13 20:38:38 -0700 | [diff] [blame] | 518 | synchronized (mInputDeviceVibrators) { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 519 | try { |
| 520 | mBatteryStatsService.noteVibratorOn(uid, millis); |
| 521 | mCurVibUid = uid; |
| 522 | } catch (RemoteException e) { |
| 523 | } |
Jeff Brown | 7f6c231 | 2012-04-13 20:38:38 -0700 | [diff] [blame] | 524 | final int vibratorCount = mInputDeviceVibrators.size(); |
| 525 | if (vibratorCount != 0) { |
John Spurlock | 7b41467 | 2014-07-18 13:02:39 -0400 | [diff] [blame^] | 526 | final AudioAttributes attributes = new AudioAttributes.Builder().setUsage(usageHint) |
| 527 | .build(); |
Jeff Brown | 7f6c231 | 2012-04-13 20:38:38 -0700 | [diff] [blame] | 528 | for (int i = 0; i < vibratorCount; i++) { |
John Spurlock | 7b41467 | 2014-07-18 13:02:39 -0400 | [diff] [blame^] | 529 | mInputDeviceVibrators.get(i).vibrate(millis, attributes); |
Jeff Brown | 7f6c231 | 2012-04-13 20:38:38 -0700 | [diff] [blame] | 530 | } |
| 531 | } else { |
| 532 | vibratorOn(millis); |
| 533 | } |
| 534 | } |
| 535 | } |
| 536 | |
| 537 | private void doVibratorOff() { |
| 538 | synchronized (mInputDeviceVibrators) { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 539 | if (mCurVibUid >= 0) { |
| 540 | try { |
| 541 | mBatteryStatsService.noteVibratorOff(mCurVibUid); |
| 542 | } catch (RemoteException e) { |
| 543 | } |
| 544 | mCurVibUid = -1; |
| 545 | } |
Jeff Brown | 7f6c231 | 2012-04-13 20:38:38 -0700 | [diff] [blame] | 546 | final int vibratorCount = mInputDeviceVibrators.size(); |
| 547 | if (vibratorCount != 0) { |
| 548 | for (int i = 0; i < vibratorCount; i++) { |
| 549 | mInputDeviceVibrators.get(i).cancel(); |
| 550 | } |
| 551 | } else { |
| 552 | vibratorOff(); |
| 553 | } |
| 554 | } |
| 555 | } |
| 556 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 557 | private class VibrateThread extends Thread { |
Patrick Scott | 18dd5f0 | 2009-07-02 11:31:12 -0400 | [diff] [blame] | 558 | final Vibration mVibration; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 559 | boolean mDone; |
Eric Olsen | f42f15c | 2009-10-29 16:42:03 -0700 | [diff] [blame] | 560 | |
Patrick Scott | 18dd5f0 | 2009-07-02 11:31:12 -0400 | [diff] [blame] | 561 | VibrateThread(Vibration vib) { |
| 562 | mVibration = vib; |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 563 | mTmpWorkSource.set(vib.mUid); |
| 564 | mWakeLock.setWorkSource(mTmpWorkSource); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 565 | mWakeLock.acquire(); |
| 566 | } |
| 567 | |
| 568 | private void delay(long duration) { |
| 569 | if (duration > 0) { |
Vairavan Srinivasan | e4c56d9 | 2011-03-31 13:32:54 -0700 | [diff] [blame] | 570 | long bedtime = duration + SystemClock.uptimeMillis(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 571 | do { |
| 572 | try { |
| 573 | this.wait(duration); |
| 574 | } |
| 575 | catch (InterruptedException e) { |
| 576 | } |
| 577 | if (mDone) { |
| 578 | break; |
| 579 | } |
Vairavan Srinivasan | e4c56d9 | 2011-03-31 13:32:54 -0700 | [diff] [blame] | 580 | duration = bedtime - SystemClock.uptimeMillis(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 581 | } while (duration > 0); |
| 582 | } |
| 583 | } |
| 584 | |
| 585 | public void run() { |
| 586 | Process.setThreadPriority(Process.THREAD_PRIORITY_URGENT_DISPLAY); |
| 587 | synchronized (this) { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 588 | final long[] pattern = mVibration.mPattern; |
| 589 | final int len = pattern.length; |
| 590 | final int repeat = mVibration.mRepeat; |
| 591 | final int uid = mVibration.mUid; |
John Spurlock | 7b41467 | 2014-07-18 13:02:39 -0400 | [diff] [blame^] | 592 | final int usageHint = mVibration.mUsageHint; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 593 | int index = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 594 | long duration = 0; |
| 595 | |
| 596 | while (!mDone) { |
Eric Olsen | f42f15c | 2009-10-29 16:42:03 -0700 | [diff] [blame] | 597 | // add off-time duration to any accumulated on-time duration |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 598 | if (index < len) { |
| 599 | duration += pattern[index++]; |
| 600 | } |
| 601 | |
| 602 | // sleep until it is time to start the vibrator |
| 603 | delay(duration); |
| 604 | if (mDone) { |
| 605 | break; |
| 606 | } |
| 607 | |
| 608 | if (index < len) { |
| 609 | // read on-time duration and start the vibrator |
| 610 | // duration is saved for delay() at top of loop |
| 611 | duration = pattern[index++]; |
| 612 | if (duration > 0) { |
John Spurlock | 7b41467 | 2014-07-18 13:02:39 -0400 | [diff] [blame^] | 613 | VibratorService.this.doVibratorOn(duration, uid, usageHint); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 614 | } |
| 615 | } else { |
Patrick Scott | 18dd5f0 | 2009-07-02 11:31:12 -0400 | [diff] [blame] | 616 | if (repeat < 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 617 | break; |
| 618 | } else { |
Patrick Scott | 18dd5f0 | 2009-07-02 11:31:12 -0400 | [diff] [blame] | 619 | index = repeat; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 620 | duration = 0; |
| 621 | } |
| 622 | } |
| 623 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 624 | mWakeLock.release(); |
| 625 | } |
Patrick Scott | 18dd5f0 | 2009-07-02 11:31:12 -0400 | [diff] [blame] | 626 | synchronized (mVibrations) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 627 | if (mThread == this) { |
| 628 | mThread = null; |
| 629 | } |
Patrick Scott | 18dd5f0 | 2009-07-02 11:31:12 -0400 | [diff] [blame] | 630 | if (!mDone) { |
| 631 | // If this vibration finished naturally, start the next |
| 632 | // vibration. |
| 633 | mVibrations.remove(mVibration); |
Mathias Jeppsson | b23949b | 2010-09-28 14:45:23 +0200 | [diff] [blame] | 634 | unlinkVibration(mVibration); |
Patrick Scott | 18dd5f0 | 2009-07-02 11:31:12 -0400 | [diff] [blame] | 635 | startNextVibrationLocked(); |
| 636 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 637 | } |
| 638 | } |
Jeff Brown | 969579b | 2014-05-20 19:29:29 -0700 | [diff] [blame] | 639 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 640 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 641 | BroadcastReceiver mIntentReceiver = new BroadcastReceiver() { |
Jeff Brown | 969579b | 2014-05-20 19:29:29 -0700 | [diff] [blame] | 642 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 643 | public void onReceive(Context context, Intent intent) { |
| 644 | if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) { |
Patrick Scott | 18dd5f0 | 2009-07-02 11:31:12 -0400 | [diff] [blame] | 645 | synchronized (mVibrations) { |
Jeff Brown | 969579b | 2014-05-20 19:29:29 -0700 | [diff] [blame] | 646 | // When the system is entering a non-interactive state, we want |
| 647 | // to cancel vibrations in case a misbehaving app has abandoned |
| 648 | // them. However it may happen that the system is currently playing |
| 649 | // haptic feedback as part of the transition. So we don't cancel |
| 650 | // system vibrations. |
| 651 | if (mCurrentVibration != null |
| 652 | && !mCurrentVibration.isSystemHapticFeedback()) { |
| 653 | doCancelVibrateLocked(); |
Vairavan Srinivasan | 8a61f49 | 2011-05-13 10:47:20 -0700 | [diff] [blame] | 654 | } |
| 655 | |
Jeff Brown | 969579b | 2014-05-20 19:29:29 -0700 | [diff] [blame] | 656 | // Clear all remaining vibrations. |
| 657 | Iterator<Vibration> it = mVibrations.iterator(); |
| 658 | while (it.hasNext()) { |
| 659 | Vibration vibration = it.next(); |
| 660 | if (vibration != mCurrentVibration) { |
| 661 | unlinkVibration(vibration); |
| 662 | it.remove(); |
| 663 | } |
| 664 | } |
Patrick Scott | 18dd5f0 | 2009-07-02 11:31:12 -0400 | [diff] [blame] | 665 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 666 | } |
| 667 | } |
| 668 | }; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 669 | } |