summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--api/16.txt10
-rw-r--r--api/current.txt10
-rw-r--r--core/java/android/app/ContextImpl.java4
-rw-r--r--core/java/android/os/SystemVibrator.java94
-rw-r--r--core/java/android/os/Vibrator.java86
-rw-r--r--core/java/android/view/VolumePanel.java2
-rw-r--r--core/java/com/android/internal/app/PlatLogoActivity.java5
-rw-r--r--core/java/com/android/internal/app/ShutdownThread.java3
-rwxr-xr-xpolicy/src/com/android/internal/policy/impl/PhoneWindowManager.java2
-rwxr-xr-xservices/java/com/android/server/NotificationManagerService.java3
-rw-r--r--tests/StatusBar/src/com/android/statusbartest/NotificationTestList.java2
11 files changed, 133 insertions, 88 deletions
diff --git a/api/16.txt b/api/16.txt
index aa23b4d19ee6..f954e1c8f5e5 100644
--- a/api/16.txt
+++ b/api/16.txt
@@ -15190,11 +15190,11 @@ package android.os {
method public abstract void released();
}
- public class Vibrator {
- method public void cancel();
- method public boolean hasVibrator();
- method public void vibrate(long);
- method public void vibrate(long[], int);
+ public abstract class Vibrator {
+ method public abstract void cancel();
+ method public abstract boolean hasVibrator();
+ method public abstract void vibrate(long);
+ method public abstract void vibrate(long[], int);
}
public class WorkSource implements android.os.Parcelable {
diff --git a/api/current.txt b/api/current.txt
index c62a2c37b1ad..e2285e85de92 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -15481,11 +15481,11 @@ package android.os {
ctor public TransactionTooLargeException();
}
- public class Vibrator {
- method public void cancel();
- method public boolean hasVibrator();
- method public void vibrate(long);
- method public void vibrate(long[], int);
+ public abstract class Vibrator {
+ method public abstract void cancel();
+ method public abstract boolean hasVibrator();
+ method public abstract void vibrate(long);
+ method public abstract void vibrate(long[], int);
}
public class WorkSource implements android.os.Parcelable {
diff --git a/core/java/android/app/ContextImpl.java b/core/java/android/app/ContextImpl.java
index 138a88fc857b..0645aa909239 100644
--- a/core/java/android/app/ContextImpl.java
+++ b/core/java/android/app/ContextImpl.java
@@ -82,7 +82,7 @@ import android.os.Process;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.UserId;
-import android.os.Vibrator;
+import android.os.SystemVibrator;
import android.os.storage.StorageManager;
import android.telephony.TelephonyManager;
import android.content.ClipboardManager;
@@ -455,7 +455,7 @@ class ContextImpl extends Context {
registerService(VIBRATOR_SERVICE, new ServiceFetcher() {
public Object createService(ContextImpl ctx) {
- return new Vibrator();
+ return new SystemVibrator();
}});
registerService(WALLPAPER_SERVICE, WALLPAPER_FETCHER);
diff --git a/core/java/android/os/SystemVibrator.java b/core/java/android/os/SystemVibrator.java
new file mode 100644
index 000000000000..7c5a47e5baf4
--- /dev/null
+++ b/core/java/android/os/SystemVibrator.java
@@ -0,0 +1,94 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.os;
+
+import android.util.Log;
+
+/**
+ * Vibrator implementation that controls the main system vibrator.
+ *
+ * @hide
+ */
+public class SystemVibrator extends Vibrator {
+ private static final String TAG = "Vibrator";
+
+ private final IVibratorService mService;
+ private final Binder mToken = new Binder();
+
+ public SystemVibrator() {
+ mService = IVibratorService.Stub.asInterface(
+ ServiceManager.getService("vibrator"));
+ }
+
+ @Override
+ public boolean hasVibrator() {
+ if (mService == null) {
+ Log.w(TAG, "Failed to vibrate; no vibrator service.");
+ return false;
+ }
+ try {
+ return mService.hasVibrator();
+ } catch (RemoteException e) {
+ }
+ return false;
+ }
+
+ @Override
+ public void vibrate(long milliseconds) {
+ if (mService == null) {
+ Log.w(TAG, "Failed to vibrate; no vibrator service.");
+ return;
+ }
+ try {
+ mService.vibrate(milliseconds, mToken);
+ } catch (RemoteException e) {
+ Log.w(TAG, "Failed to vibrate.", e);
+ }
+ }
+
+ @Override
+ public void vibrate(long[] pattern, int repeat) {
+ if (mService == null) {
+ Log.w(TAG, "Failed to vibrate; no vibrator service.");
+ return;
+ }
+ // catch this here because the server will do nothing. pattern may
+ // not be null, let that be checked, because the server will drop it
+ // anyway
+ if (repeat < pattern.length) {
+ try {
+ mService.vibratePattern(pattern, repeat, mToken);
+ } catch (RemoteException e) {
+ Log.w(TAG, "Failed to vibrate.", e);
+ }
+ } else {
+ throw new ArrayIndexOutOfBoundsException();
+ }
+ }
+
+ @Override
+ public void cancel() {
+ if (mService == null) {
+ return;
+ }
+ try {
+ mService.cancelVibrate(mToken);
+ } catch (RemoteException e) {
+ Log.w(TAG, "Failed to cancel vibration.", e);
+ }
+ }
+}
diff --git a/core/java/android/os/Vibrator.java b/core/java/android/os/Vibrator.java
index 3769cfe9df0d..3f783c9d1fc3 100644
--- a/core/java/android/os/Vibrator.java
+++ b/core/java/android/os/Vibrator.java
@@ -16,61 +16,37 @@
package android.os;
-import android.util.Log;
+import android.content.Context;
/**
* Class that operates the vibrator on the device.
* <p>
* If your process exits, any vibration you started with will stop.
* </p>
+ *
+ * To obtain an instance of the system vibrator, call
+ * {@link Context#getSystemService} with {@link Context#VIBRATOR_SERVICE} as argument.
*/
-public class Vibrator
-{
- private static final String TAG = "Vibrator";
-
- IVibratorService mService;
- private final Binder mToken = new Binder();
-
- /** @hide */
- public Vibrator()
- {
- mService = IVibratorService.Stub.asInterface(
- ServiceManager.getService("vibrator"));
+public abstract class Vibrator {
+ /**
+ * @hide to prevent subclassing from outside of the framework
+ */
+ public Vibrator() {
}
/**
- * Check whether the hardware has a vibrator. Returns true if a vibrator
- * exists, else false.
+ * Check whether the hardware has a vibrator.
+ *
+ * @return True if the hardware has a vibrator, else false.
*/
- public boolean hasVibrator() {
- if (mService == null) {
- Log.w(TAG, "Failed to vibrate; no vibrator service.");
- return false;
- }
- try {
- return mService.hasVibrator();
- } catch (RemoteException e) {
- }
- return false;
- }
+ public abstract boolean hasVibrator();
/**
- * Turn the vibrator on.
+ * Vibrate constantly for the specified period of time.
*
* @param milliseconds The number of milliseconds to vibrate.
*/
- public void vibrate(long milliseconds)
- {
- if (mService == null) {
- Log.w(TAG, "Failed to vibrate; no vibrator service.");
- return;
- }
- try {
- mService.vibrate(milliseconds, mToken);
- } catch (RemoteException e) {
- Log.w(TAG, "Failed to vibrate.", e);
- }
- }
+ public abstract void vibrate(long milliseconds);
/**
* Vibrate with a given pattern.
@@ -90,38 +66,10 @@ public class Vibrator
* @param repeat the index into pattern at which to repeat, or -1 if
* you don't want to repeat.
*/
- public void vibrate(long[] pattern, int repeat)
- {
- if (mService == null) {
- Log.w(TAG, "Failed to vibrate; no vibrator service.");
- return;
- }
- // catch this here because the server will do nothing. pattern may
- // not be null, let that be checked, because the server will drop it
- // anyway
- if (repeat < pattern.length) {
- try {
- mService.vibratePattern(pattern, repeat, mToken);
- } catch (RemoteException e) {
- Log.w(TAG, "Failed to vibrate.", e);
- }
- } else {
- throw new ArrayIndexOutOfBoundsException();
- }
- }
+ public abstract void vibrate(long[] pattern, int repeat);
/**
* Turn the vibrator off.
*/
- public void cancel()
- {
- if (mService == null) {
- return;
- }
- try {
- mService.cancelVibrate(mToken);
- } catch (RemoteException e) {
- Log.w(TAG, "Failed to cancel vibration.", e);
- }
- }
+ public abstract void cancel();
}
diff --git a/core/java/android/view/VolumePanel.java b/core/java/android/view/VolumePanel.java
index 9152cc344949..110c239b45d1 100644
--- a/core/java/android/view/VolumePanel.java
+++ b/core/java/android/view/VolumePanel.java
@@ -263,7 +263,7 @@ public class VolumePanel extends Handler implements OnSeekBarChangeListener, Vie
| LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH);
mToneGenerators = new ToneGenerator[AudioSystem.getNumStreamTypes()];
- mVibrator = new Vibrator();
+ mVibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);
mVoiceCapable = context.getResources().getBoolean(R.bool.config_voice_capable);
mShowCombinedVolumes = !mVoiceCapable && !useMasterVolume;
diff --git a/core/java/com/android/internal/app/PlatLogoActivity.java b/core/java/com/android/internal/app/PlatLogoActivity.java
index a0e125a07494..37567fdb40c8 100644
--- a/core/java/com/android/internal/app/PlatLogoActivity.java
+++ b/core/java/com/android/internal/app/PlatLogoActivity.java
@@ -29,9 +29,9 @@ import android.widget.ImageView;
import android.widget.Toast;
public class PlatLogoActivity extends Activity {
+ Vibrator mZzz;
Toast mToast;
ImageView mContent;
- Vibrator mZzz = new Vibrator();
int mCount;
final Handler mHandler = new Handler();
@@ -63,7 +63,8 @@ public class PlatLogoActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
-
+
+ mZzz = (Vibrator)getSystemService(VIBRATOR_SERVICE);
mToast = Toast.makeText(this, "Android 4.0: Ice Cream Sandwich", Toast.LENGTH_SHORT);
mContent = new ImageView(this);
diff --git a/core/java/com/android/internal/app/ShutdownThread.java b/core/java/com/android/internal/app/ShutdownThread.java
index 77d0c97bbf62..6a469293ca52 100644
--- a/core/java/com/android/internal/app/ShutdownThread.java
+++ b/core/java/com/android/internal/app/ShutdownThread.java
@@ -37,6 +37,7 @@ import android.os.ServiceManager;
import android.os.SystemClock;
import android.os.SystemProperties;
import android.os.Vibrator;
+import android.os.SystemVibrator;
import android.os.storage.IMountService;
import android.os.storage.IMountShutdownObserver;
@@ -399,7 +400,7 @@ public final class ShutdownThread extends Thread {
}
} else if (SHUTDOWN_VIBRATE_MS > 0) {
// vibrate before shutting down
- Vibrator vibrator = new Vibrator();
+ Vibrator vibrator = new SystemVibrator();
try {
vibrator.vibrate(SHUTDOWN_VIBRATE_MS);
} catch (Exception e) {
diff --git a/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java b/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java
index 0a63840da60b..897b8d039c84 100755
--- a/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java
+++ b/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java
@@ -909,7 +909,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
mPluggedIn = (0 != intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, 0));
}
- mVibrator = new Vibrator();
+ mVibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);
mLongPressVibePattern = getLongIntArray(mContext.getResources(),
com.android.internal.R.array.config_longPressVibePattern);
mVirtualKeyVibePattern = getLongIntArray(mContext.getResources(),
diff --git a/services/java/com/android/server/NotificationManagerService.java b/services/java/com/android/server/NotificationManagerService.java
index 3db460107dc9..b22be76a2ec4 100755
--- a/services/java/com/android/server/NotificationManagerService.java
+++ b/services/java/com/android/server/NotificationManagerService.java
@@ -100,7 +100,7 @@ public class NotificationManagerService extends INotificationManager.Stub
private int mDisabledNotifications;
private NotificationRecord mVibrateNotification;
- private Vibrator mVibrator = new Vibrator();
+ private Vibrator mVibrator;
// for enabling and disabling notification pulse behavior
private boolean mScreenOn = true;
@@ -398,6 +398,7 @@ public class NotificationManagerService extends INotificationManager.Stub
{
super();
mContext = context;
+ mVibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);
mAm = ActivityManagerNative.getDefault();
mSound = new NotificationPlayer(TAG);
mSound.setUsesWakeLock(context);
diff --git a/tests/StatusBar/src/com/android/statusbartest/NotificationTestList.java b/tests/StatusBar/src/com/android/statusbartest/NotificationTestList.java
index ae01c750847f..5eac1f22a7ab 100644
--- a/tests/StatusBar/src/com/android/statusbartest/NotificationTestList.java
+++ b/tests/StatusBar/src/com/android/statusbartest/NotificationTestList.java
@@ -44,7 +44,7 @@ public class NotificationTestList extends TestActivity
private final static String TAG = "NotificationTestList";
NotificationManager mNM;
- Vibrator mVibrator = new Vibrator();
+ Vibrator mVibrator = (Vibrator)getSystemService(VIBRATOR_SERVICE);
Handler mHandler = new Handler();
long mActivityCreateTime = System.currentTimeMillis();