From f242b7b931898856bcbcb7ec36cacf43098ba544 Mon Sep 17 00:00:00 2001 From: Nick Pelly Date: Thu, 8 Oct 2009 00:12:45 +0200 Subject: [PATCH 1/8] Introduce BluetoothAdapter.getDefaultAdapter(). This is the main entry point to the Bluetooth APIs, and returns the default local Bluetooth adapter. It replaces context.getSystemService(Context.BLUETOOTH_SERVICE). This was never in a public SDK release. DrNo: eastham Bug: 2158765 Joke: Why can't you play cards in the jungle? Because there's too many cheetas! Change-Id: Ieed8be009ee5aba621cb69090ee8c8a9c19c840d --- api/current.xml | 22 +++++------ core/java/android/app/ApplicationContext.java | 18 --------- .../android/bluetooth/BluetoothAdapter.java | 38 ++++++++++++++++--- .../android/bluetooth/BluetoothDevice.java | 3 +- core/java/android/content/Context.java | 8 ---- .../android/server/BluetoothA2dpService.java | 2 +- .../java/android/server/BluetoothService.java | 2 +- .../android/internal/app/ShutdownThread.java | 2 +- .../java/com/android/server/SystemServer.java | 7 ++-- .../server/status/StatusBarPolicy.java | 3 +- 10 files changed, 53 insertions(+), 52 deletions(-) diff --git a/api/current.xml b/api/current.xml index 0bca84bcb71af..f4d81c7b02ac7 100644 --- a/api/current.xml +++ b/api/current.xml @@ -25550,6 +25550,17 @@ visibility="public" > + + - - Use {@link android.content.Context#getSystemService} with {@link - * android.content.Context#BLUETOOTH_SERVICE} to get the default local - * Bluetooth adapter. On most Android devices there is only one local - * Bluetotoh adapter. + *

Use {@link #getDefaultAdapter} to get the default local Bluetooth + * adapter. * *

Use the {@link BluetoothDevice} class for operations on remote Bluetooth * devices. @@ -257,12 +257,40 @@ public final class BluetoothAdapter { */ public static final String EXTRA_LOCAL_NAME = "android.bluetooth.adapter.extra.LOCAL_NAME"; + /** @hide */ + public static final String BLUETOOTH_SERVICE = "bluetooth"; + private static final int ADDRESS_LENGTH = 17; + /** + * Lazyily initialized singleton. Guaranteed final after first object + * constructed. + */ + private static BluetoothAdapter sAdapter; + private final IBluetooth mService; /** - * Do not use this constructor. Use Context.getSystemService() instead. + * Get a handle to the default local Bluetooth adapter. + *

Currently Android only supports one Bluetooth adapter, but the API + * could be extended to support more. This will always return the default + * adapter. + * @return the default local adapter, or null if Bluetooth is not supported + * on this hardware platform + */ + public static synchronized BluetoothAdapter getDefaultAdapter() { + if (sAdapter == null) { + IBinder b = ServiceManager.getService(BluetoothAdapter.BLUETOOTH_SERVICE); + if (b != null) { + IBluetooth service = IBluetooth.Stub.asInterface(b); + sAdapter = new BluetoothAdapter(service); + } + } + return sAdapter; + } + + /** + * Use {@link #getDefaultAdapter} to get the BluetoothAdapter instance. * @hide */ public BluetoothAdapter(IBluetooth service) { diff --git a/core/java/android/bluetooth/BluetoothDevice.java b/core/java/android/bluetooth/BluetoothDevice.java index ce975c2279427..9c23746494a4f 100644 --- a/core/java/android/bluetooth/BluetoothDevice.java +++ b/core/java/android/bluetooth/BluetoothDevice.java @@ -18,7 +18,6 @@ package android.bluetooth; import android.annotation.SdkConstant; import android.annotation.SdkConstant.SdkConstantType; -import android.content.Context; import android.os.IBinder; import android.os.Parcel; import android.os.Parcelable; @@ -328,7 +327,7 @@ public final class BluetoothDevice implements Parcelable { /*package*/ static IBluetooth getService() { synchronized (BluetoothDevice.class) { if (sService == null) { - IBinder b = ServiceManager.getService(Context.BLUETOOTH_SERVICE); + IBinder b = ServiceManager.getService(BluetoothAdapter.BLUETOOTH_SERVICE); if (b == null) { throw new RuntimeException("Bluetooth service not available"); } diff --git a/core/java/android/content/Context.java b/core/java/android/content/Context.java index fe4665e5e7aec..8f1c671046ae6 100644 --- a/core/java/android/content/Context.java +++ b/core/java/android/content/Context.java @@ -1217,14 +1217,6 @@ public abstract class Context { * @see android.hardware.SensorManager */ public static final String SENSOR_SERVICE = "sensor"; - /** - * Use with {@link #getSystemService} to retrieve a {@link - * android.bluetooth.BluetoothAdapter} for using Bluetooth. - * - * @see #getSystemService - * @see android.bluetooth.BluetoothAdapter - */ - public static final String BLUETOOTH_SERVICE = "bluetooth"; /** * Use with {@link #getSystemService} to retrieve a * com.android.server.WallpaperService for accessing wallpapers. diff --git a/core/java/android/server/BluetoothA2dpService.java b/core/java/android/server/BluetoothA2dpService.java index d61b42f71be10..b73e53ffca838 100644 --- a/core/java/android/server/BluetoothA2dpService.java +++ b/core/java/android/server/BluetoothA2dpService.java @@ -137,7 +137,7 @@ public class BluetoothA2dpService extends IBluetoothA2dp.Stub { throw new RuntimeException("Could not init BluetoothA2dpService"); } - mAdapter = (BluetoothAdapter) context.getSystemService(Context.BLUETOOTH_SERVICE); + mAdapter = BluetoothAdapter.getDefaultAdapter(); mIntentFilter = new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED); mIntentFilter.addAction(BluetoothDevice.ACTION_BOND_STATE_CHANGED); diff --git a/core/java/android/server/BluetoothService.java b/core/java/android/server/BluetoothService.java index 3fdbb68018bb7..6d4d1527a9292 100644 --- a/core/java/android/server/BluetoothService.java +++ b/core/java/android/server/BluetoothService.java @@ -154,7 +154,7 @@ public class BluetoothService extends IBluetooth.Stub { } public synchronized void initAfterRegistration() { - mAdapter = (BluetoothAdapter) mContext.getSystemService(Context.BLUETOOTH_SERVICE); + mAdapter = BluetoothAdapter.getDefaultAdapter(); mEventLoop = new BluetoothEventLoop(mContext, mAdapter, this); } diff --git a/core/java/com/android/internal/app/ShutdownThread.java b/core/java/com/android/internal/app/ShutdownThread.java index 9e1f325d1d4e9..01f6dac2a4b15 100644 --- a/core/java/com/android/internal/app/ShutdownThread.java +++ b/core/java/com/android/internal/app/ShutdownThread.java @@ -181,7 +181,7 @@ public final class ShutdownThread extends Thread { ITelephony.Stub.asInterface(ServiceManager.checkService("phone")); final IBluetooth bluetooth = IBluetooth.Stub.asInterface(ServiceManager.checkService( - Context.BLUETOOTH_SERVICE)); + BluetoothAdapter.BLUETOOTH_SERVICE)); try { bluetoothOff = bluetooth == null || diff --git a/services/java/com/android/server/SystemServer.java b/services/java/com/android/server/SystemServer.java index e5c60109fb19a..b8cf844edaeed 100644 --- a/services/java/com/android/server/SystemServer.java +++ b/services/java/com/android/server/SystemServer.java @@ -23,6 +23,7 @@ import com.android.internal.os.SamplingProfilerIntegration; import dalvik.system.VMRuntime; import android.app.ActivityManagerNative; +import android.bluetooth.BluetoothAdapter; import android.content.ComponentName; import android.content.ContentResolver; import android.content.ContentService; @@ -172,14 +173,14 @@ class ServerThread extends Thread { // support Bluetooth - see bug 988521 if (SystemProperties.get("ro.kernel.qemu").equals("1")) { Log.i(TAG, "Registering null Bluetooth Service (emulator)"); - ServiceManager.addService(Context.BLUETOOTH_SERVICE, null); + ServiceManager.addService(BluetoothAdapter.BLUETOOTH_SERVICE, null); } else if (factoryTest == SystemServer.FACTORY_TEST_LOW_LEVEL) { Log.i(TAG, "Registering null Bluetooth Service (factory test)"); - ServiceManager.addService(Context.BLUETOOTH_SERVICE, null); + ServiceManager.addService(BluetoothAdapter.BLUETOOTH_SERVICE, null); } else { Log.i(TAG, "Bluetooth Service"); bluetooth = new BluetoothService(context); - ServiceManager.addService(Context.BLUETOOTH_SERVICE, bluetooth); + ServiceManager.addService(BluetoothAdapter.BLUETOOTH_SERVICE, bluetooth); bluetooth.initAfterRegistration(); bluetoothA2dp = new BluetoothA2dpService(context, bluetooth); ServiceManager.addService(BluetoothA2dpService.BLUETOOTH_A2DP_SERVICE, diff --git a/services/java/com/android/server/status/StatusBarPolicy.java b/services/java/com/android/server/status/StatusBarPolicy.java index cf63d0220c036..801a938c46960 100644 --- a/services/java/com/android/server/status/StatusBarPolicy.java +++ b/services/java/com/android/server/status/StatusBarPolicy.java @@ -448,8 +448,7 @@ public class StatusBarPolicy { mBluetoothData = IconData.makeIcon("bluetooth", null, com.android.internal.R.drawable.stat_sys_data_bluetooth, 0, 0); mBluetoothIcon = service.addIcon(mBluetoothData, null); - BluetoothAdapter adapter = - (BluetoothAdapter) mContext.getSystemService(Context.BLUETOOTH_SERVICE); + BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter(); if (adapter != null) { mBluetoothEnabled = adapter.isEnabled(); } else { From 3fbca4d5060e7e7c3adc8de14cec11b6e83f6e9c Mon Sep 17 00:00:00 2001 From: Dmitri Plotnikov Date: Tue, 6 Oct 2009 17:57:16 -0700 Subject: [PATCH 2/8] [Issue 2165234] Removing nickname clusters: John/Jack and Patrick/Rick. Also adding some nicknames from Mike Hearn's list. Change-Id: I7a57637bbdc267816e5e063fce4d2ac6a3136284 --- .../values-en-rUS/donottranslate-names.xml | 53 ++++++++++++------- 1 file changed, 33 insertions(+), 20 deletions(-) diff --git a/core/res/res/values-en-rUS/donottranslate-names.xml b/core/res/res/values-en-rUS/donottranslate-names.xml index 82ba310cde5fc..ae38ddfc81a1a 100644 --- a/core/res/res/values-en-rUS/donottranslate-names.xml +++ b/core/res/res/values-en-rUS/donottranslate-names.xml @@ -4,31 +4,39 @@ + Abigail, Abbie, Gail, Gayle + Abe, Abraham + Aggie, Agatha, Agnes Albert, Al, Bert, Bertie - Alexander, Al, Alex, Lex, Sasha - Alexandra, Al, Alex, Allie, Ally, Lex, Lexie, Sandra, Sandy, Sasha + Alexander, Al, Alec, Alex, Lex, Sasha + Alexandra, Al, Allie, Ally, Lex, Lexie, Sandra, Sandy, Sasha + Alf, Alfred, Alfredo, Alfie Alice, Allie, Ally Alison, Allie, Ally Allison, Allie, Ally Amanda, Mandi, Mandy Andrea, Andie Andrew, Andy, Drew + Anne, Annie, Annette Anthony, Tony, Toni, Tone Arthur, Art, Arty Barbara, Babs, Barb, Barbie Benjamin, Ben, Benji, Benny - Bernard, Bern, Bernie + Bernard, Bern, Bernie, Barnie Bertram, Bert, Bertie Bradly, Brad + Calvin, Cal Catherine, Cat, Cate, Cath, Catie, Cathy, Kat, Kate, Katie, Kathy + Carrie, Caroline, Carolyn Charles, Chuck, Chaz, Charlie, Buck - Christine, Chris, Chrissy, Chrissie + Christine, Chrissy, Chrissie Christopher, Chris + Clinton, Clint Cynthia, Cindy, Cynth Daniel, Dan, Danny David, Dave Deborah, Deb, Debbie - Dennis, Den, Denny, Dean + Dennis, Den, Denny Dolores, Dolly Donald, Don, Donny Donnatella, Donna @@ -41,22 +49,21 @@ Elizabeth, Beth, Bess, Bessie, Betsy, Betty, Bette, Eliza, Lisa, Liza, Liz Emily, Em, Ems, Emmy Emma, Em, Ems, Emmy - Erica, Rikki, Rikkie, Ricky Eugene, Gene + Fannie, Fanny Florence, Flo Frances, Fran, Francie - Francis, Fran, Frank + Francis, Fran, Frank, Frankie Frederick, Fred, Freddy Gabriel, Gabe - Geoffrey, Jeff Gerald, Gerry Gerard, Gerry - Gregory, Greg - Harold, Hal, Hank, Harry + Gregory, Greg, Gregg + Harold, Hal, Harry Henry, Hal, Hank, Harry Herbert, Bert, Bertie Irving, Irv - Isabella, Isa, Izzy + Isabella, Isa, Izzy, Bella Jacob, Jake Jacqueline, Jackie James, Jim, Jimmy, Jamie, Jock @@ -68,8 +75,9 @@ Jennifer, Jen, Jenny Jerome, Jerry Jessica, Jessie - John, Jack, Jacky, Johnny, Jon - Jonathan, Jon, John + John, Johnny, Jon + Jack, Jacky + Jonathan, Jon Joseph, Joe, Joey Joshua, Josh Kaitlyn, Cat, Cate, Catie, Cath, Cathy, Kat, Kate, Katie, Kathy @@ -78,17 +86,20 @@ Katrina, Cat, Cate, Catie, Cath, Cathy, Kat, Kate, Katie, Kathy Kenneth, Ken Kevin, Kev + Kim, Kimberly Laura, Lauri, Laurie Lauren, Lauri, Laurie - Laurence, Larry, Lauri, Laurie - Lawrence, Larry, Lauri, Laurie + Lawrence, Larry Leonard, Leo, Len, Lenny Leopold, Leo, Len, Lenny Madeline, Maddie, Maddy - Margaret, Marge, Marg, Maggie, Mags, Meg, Peggy + Margaret, Marge, Marg, Maggie, Mags, Meg, Peggy, Greta, Gretchen + Martin, Martie, Marty Matthew, Matt, Mattie Maureen, Mo Maurice, Mo + Maxwell, Max + Maximilian, Maxim, Max Megan, Meg Michael, Mickey, Mick, Mike, Mikey Morris, Mo @@ -96,16 +107,17 @@ Nathan, Nat, Nate Nathaniel, Nat, Nate Nicholas, Nick + Nicole, Nicky, Nickie, Nikky Pamela, Pam Patricia, Pat, Patsy, Patty, Trish, Tricia - Patrick, Paddy, Pat, Patty, Patter, Rick, Ricky + Patrick, Pat, Patter + Penelope, Penny Peter, Pete Raymond, Ray Philip, Phil - Rebecca, Becca + Rebecca, Becca, Becky Richard, Rick, Rich, Dick Robert, Bob, Rob, Robbie, Bobby, Rab - Roberta, Bobbie Rodney. Rod Ronald, Ron, Ronnie Rosemary, Rosie, Rose @@ -120,7 +132,8 @@ Stuart, Stu Susan, Sue, Susie, Suzie Suzanne, Sue, Susie, Suzie - Teresa, Terrie, Terry + Tamara, Tammy + Theresa, Teresa Theodora, Teddie, Thea, Theo Theodore, Ted, Teddy, Theo Thomas, Tom, Thom, Tommy From e05f07dffa196d6403733b26317faa9f267d518f Mon Sep 17 00:00:00 2001 From: Mathias Agopian Date: Wed, 7 Oct 2009 16:44:10 -0700 Subject: [PATCH 3/8] fix [2170319] gmail bulk operation checkbox latency on passion This also fixes [2152536] ANR in browser When SF is enqueuing buffers faster than SF dequeues them. The update flag in SF is not counted and under some situations SF will only dequeue the first buffer. The state at this point is not technically corrupted, it's valid, but just delayed by one buffer. In the case of the Browser ANR, because the last enqueued buffer was delayed the resizing of the current buffer couldn't happen. The system would always fall back onto its feet if anything -else- in tried to draw, because the "late" buffer would be picked up then. --- include/private/ui/SharedBufferStack.h | 1 + include/private/ui/SurfaceFlingerSynchro.h | 48 ---------------------- include/ui/SurfaceComposerClient.h | 2 +- libs/surfaceflinger/Layer.cpp | 6 ++- libs/ui/Android.mk | 3 +- libs/ui/SharedBufferStack.cpp | 6 +++ libs/ui/SurfaceComposerClient.cpp | 5 +-- libs/ui/SurfaceFlingerSynchro.cpp | 42 ------------------- 8 files changed, 14 insertions(+), 99 deletions(-) delete mode 100644 include/private/ui/SurfaceFlingerSynchro.h delete mode 100644 libs/ui/SurfaceFlingerSynchro.cpp diff --git a/include/private/ui/SharedBufferStack.h b/include/private/ui/SharedBufferStack.h index f6824d995015b..bbc18227ce5ef 100644 --- a/include/private/ui/SharedBufferStack.h +++ b/include/private/ui/SharedBufferStack.h @@ -289,6 +289,7 @@ public: void setStatus(status_t status); status_t reallocate(); status_t assertReallocate(int buffer); + int32_t getQueuedCount() const; Region getDirtyRegion(int buffer) const; diff --git a/include/private/ui/SurfaceFlingerSynchro.h b/include/private/ui/SurfaceFlingerSynchro.h deleted file mode 100644 index 7386d337675c6..0000000000000 --- a/include/private/ui/SurfaceFlingerSynchro.h +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (C) 2008 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. - */ - - -#ifndef ANDROID_SURFACE_FLINGER_SYNCHRO_H -#define ANDROID_SURFACE_FLINGER_SYNCHRO_H - -#include -#include -#include -#include - -namespace android { - -class SurfaceFlinger; - -class SurfaceFlingerSynchro -{ -public: - // client constructor - SurfaceFlingerSynchro(const sp& flinger); - ~SurfaceFlingerSynchro(); - - // signal surfaceflinger for some work - status_t signal(); - -private: - friend class SurfaceFlinger; - sp mSurfaceComposer; -}; - -}; // namespace android - -#endif // ANDROID_SURFACE_FLINGER_SYNCHRO_H - diff --git a/include/ui/SurfaceComposerClient.h b/include/ui/SurfaceComposerClient.h index 8701928ebee80..777b878dd1386 100644 --- a/include/ui/SurfaceComposerClient.h +++ b/include/ui/SurfaceComposerClient.h @@ -153,7 +153,7 @@ private: SharedClient* mControl; sp mControlMemory; sp mClient; - SurfaceFlingerSynchro* mSignalServer; + sp mSignalServer; }; }; // namespace android diff --git a/libs/surfaceflinger/Layer.cpp b/libs/surfaceflinger/Layer.cpp index 0258cee0dbd1f..2a3e6677e7451 100644 --- a/libs/surfaceflinger/Layer.cpp +++ b/libs/surfaceflinger/Layer.cpp @@ -460,8 +460,10 @@ void Layer::lockPageFlip(bool& recomputeVisibleRegions) } } - // FIXME: signal an event if we have more buffers waiting - // mFlinger->signalEvent(); + if (lcblk->getQueuedCount()) { + // signal an event if we have more buffers waiting + mFlinger->signalEvent(); + } if (!mPostedDirtyRegion.isEmpty()) { reloadTexture( mPostedDirtyRegion ); diff --git a/libs/ui/Android.mk b/libs/ui/Android.mk index 73d86ea94274c..84aec6198558d 100644 --- a/libs/ui/Android.mk +++ b/libs/ui/Android.mk @@ -27,8 +27,7 @@ LOCAL_SRC_FILES:= \ Region.cpp \ SharedBufferStack.cpp \ Surface.cpp \ - SurfaceComposerClient.cpp \ - SurfaceFlingerSynchro.cpp + SurfaceComposerClient.cpp LOCAL_SHARED_LIBRARIES := \ libcutils \ diff --git a/libs/ui/SharedBufferStack.cpp b/libs/ui/SharedBufferStack.cpp index b460757414175..46b6766438764 100644 --- a/libs/ui/SharedBufferStack.cpp +++ b/libs/ui/SharedBufferStack.cpp @@ -394,6 +394,12 @@ status_t SharedBufferServer::reallocate() return NO_ERROR; } +int32_t SharedBufferServer::getQueuedCount() const +{ + SharedBufferStack& stack( *mSharedStack ); + return stack.queued; +} + status_t SharedBufferServer::assertReallocate(int buffer) { ReallocateCondition condition(this, buffer); diff --git a/libs/ui/SurfaceComposerClient.cpp b/libs/ui/SurfaceComposerClient.cpp index 3baa2817aac4b..eda84eff04f42 100644 --- a/libs/ui/SurfaceComposerClient.cpp +++ b/libs/ui/SurfaceComposerClient.cpp @@ -42,7 +42,6 @@ #include #include -#include #define VERBOSE(...) ((void)0) //#define VERBOSE LOGD @@ -155,7 +154,6 @@ void SurfaceComposerClient::_init( { VERBOSE("Creating client %p, conn %p", this, conn.get()); - mSignalServer = 0; mPrebuiltLayerState = 0; mTransactionOpen = 0; mStatus = NO_ERROR; @@ -168,7 +166,7 @@ void SurfaceComposerClient::_init( } mControlMemory = mClient->getControlBlock(); - mSignalServer = new SurfaceFlingerSynchro(sm); + mSignalServer = sm; mControl = static_cast(mControlMemory->getBase()); } @@ -225,7 +223,6 @@ void SurfaceComposerClient::dispose() Mutex::Autolock _lg(gLock); Mutex::Autolock _lm(mLock); - delete mSignalServer; mSignalServer = 0; if (mClient != 0) { diff --git a/libs/ui/SurfaceFlingerSynchro.cpp b/libs/ui/SurfaceFlingerSynchro.cpp deleted file mode 100644 index c81db71a81283..0000000000000 --- a/libs/ui/SurfaceFlingerSynchro.cpp +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (C) 2008 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. - */ - -#include - -#include - -namespace android { - -// --------------------------------------------------------------------------- - -SurfaceFlingerSynchro::SurfaceFlingerSynchro(const sp& flinger) - : mSurfaceComposer(flinger) -{ -} -SurfaceFlingerSynchro::~SurfaceFlingerSynchro() -{ -} - -status_t SurfaceFlingerSynchro::signal() -{ - mSurfaceComposer->signal(); - return NO_ERROR; -} - -// --------------------------------------------------------------------------- - -}; // namespace android - From 3161795b2353171bb0636fb3ea6dab7dec80a4f4 Mon Sep 17 00:00:00 2001 From: Doug Zongker Date: Wed, 7 Oct 2009 15:14:03 -0700 Subject: [PATCH 4/8] when logging free space on /data, log /system and /cache as well Report space free on system and cache so we can estimate bad block statistics for devices in the field. --- .../server/DeviceStorageMonitorService.java | 104 +++++++++++------- 1 file changed, 65 insertions(+), 39 deletions(-) diff --git a/services/java/com/android/server/DeviceStorageMonitorService.java b/services/java/com/android/server/DeviceStorageMonitorService.java index 52e09ca260a55..57af02953415d 100644 --- a/services/java/com/android/server/DeviceStorageMonitorService.java +++ b/services/java/com/android/server/DeviceStorageMonitorService.java @@ -43,8 +43,8 @@ import android.provider.Settings; /** * This class implements a service to monitor the amount of disk storage space * on the device. If the free storage on device is less than a tunable threshold value - * (default is 10%. this value is a gservices parameter) a low memory notification is - * displayed to alert the user. If the user clicks on the low memory notification the + * (default is 10%. this value is a gservices parameter) a low memory notification is + * displayed to alert the user. If the user clicks on the low memory notification the * Application Manager application gets launched to let the user free storage space. * Event log events: * A low memory event with the free storage on device in bytes is logged to the event log @@ -68,32 +68,35 @@ class DeviceStorageMonitorService extends Binder { private static final int EVENT_LOG_FREE_STORAGE_LEFT = 2746; private static final long DEFAULT_DISK_FREE_CHANGE_REPORTING_THRESHOLD = 2 * 1024 * 1024; // 2MB private static final long DEFAULT_CHECK_INTERVAL = MONITOR_INTERVAL*60*1000; - private long mFreeMem; + private long mFreeMem; // on /data private long mLastReportedFreeMem; private long mLastReportedFreeMemTime; private boolean mLowMemFlag=false; private Context mContext; private ContentResolver mContentResolver; - long mBlkSize; - long mTotalMemory; - StatFs mFileStats; - private static final String DATA_PATH="/data"; - long mThreadStartTime = -1; - boolean mClearSucceeded = false; - boolean mClearingCache; + private long mTotalMemory; // on /data + private StatFs mDataFileStats; + private StatFs mSystemFileStats; + private StatFs mCacheFileStats; + private static final String DATA_PATH = "/data"; + private static final String SYSTEM_PATH = "/system"; + private static final String CACHE_PATH = "/cache"; + private long mThreadStartTime = -1; + private boolean mClearSucceeded = false; + private boolean mClearingCache; private Intent mStorageLowIntent; private Intent mStorageOkIntent; private CachePackageDataObserver mClearCacheObserver; private static final int _TRUE = 1; private static final int _FALSE = 0; - + /** * This string is used for ServiceManager access to this class. */ static final String SERVICE = "devicestoragemonitor"; - + /** - * Handler that checks the amount of disk space on the device and sends a + * Handler that checks the amount of disk space on the device and sends a * notification if the device runs low on disk space */ Handler mHandler = new Handler() { @@ -107,7 +110,7 @@ class DeviceStorageMonitorService extends Binder { checkMemory(msg.arg1 == _TRUE); } }; - + class CachePackageDataObserver extends IPackageDataObserver.Stub { public void onRemoveCompleted(String packageName, boolean succeeded) { mClearSucceeded = succeeded; @@ -115,12 +118,17 @@ class DeviceStorageMonitorService extends Binder { if(localLOGV) Log.i(TAG, " Clear succeeded:"+mClearSucceeded +", mClearingCache:"+mClearingCache+" Forcing memory check"); postCheckMemoryMsg(false, 0); - } + } } - + private final void restatDataDir() { - mFileStats.restat(DATA_PATH); - mFreeMem = mFileStats.getAvailableBlocks()*mBlkSize; + try { + mDataFileStats.restat(DATA_PATH); + mFreeMem = (long) mDataFileStats.getAvailableBlocks() * + mDataFileStats.getBlockSize(); + } catch (IllegalArgumentException e) { + // use the old value of mFreeMem + } // Allow freemem to be overridden by debug.freemem for testing String debugFreeMem = SystemProperties.get("debug.freemem"); if (!"".equals(debugFreeMem)) { @@ -132,10 +140,27 @@ class DeviceStorageMonitorService extends Binder { DEFAULT_FREE_STORAGE_LOG_INTERVAL_IN_MINUTES)*60*1000; //log the amount of free memory in event log long currTime = SystemClock.elapsedRealtime(); - if((mLastReportedFreeMemTime == 0) || - (currTime-mLastReportedFreeMemTime) >= freeMemLogInterval) { + if((mLastReportedFreeMemTime == 0) || + (currTime-mLastReportedFreeMemTime) >= freeMemLogInterval) { mLastReportedFreeMemTime = currTime; - EventLog.writeEvent(EVENT_LOG_FREE_STORAGE_LEFT, mFreeMem); + long mFreeSystem = -1, mFreeCache = -1; + try { + mSystemFileStats.restat(SYSTEM_PATH); + mFreeSystem = (long) mSystemFileStats.getAvailableBlocks() * + mSystemFileStats.getBlockSize(); + } catch (IllegalArgumentException e) { + // ignore; report -1 + } + try { + mCacheFileStats.restat(CACHE_PATH); + mFreeCache = (long) mCacheFileStats.getAvailableBlocks() * + mCacheFileStats.getBlockSize(); + } catch (IllegalArgumentException e) { + // ignore; report -1 + } + mCacheFileStats.restat(CACHE_PATH); + EventLog.writeEvent(EVENT_LOG_FREE_STORAGE_LEFT, + mFreeMem, mFreeSystem, mFreeCache); } // Read the reporting threshold from Gservices long threshold = Gservices.getLong(mContentResolver, @@ -148,7 +173,7 @@ class DeviceStorageMonitorService extends Binder { EventLog.writeEvent(EVENT_LOG_STORAGE_BELOW_THRESHOLD, mFreeMem); } } - + private final void clearCache() { if (mClearCacheObserver == null) { // Lazy instantiation @@ -165,10 +190,10 @@ class DeviceStorageMonitorService extends Binder { mClearSucceeded = false; } } - + private final void checkMemory(boolean checkCache) { - //if the thread that was started to clear cache is still running do nothing till its - //finished clearing cache. Ideally this flag could be modified by clearCache + //if the thread that was started to clear cache is still running do nothing till its + //finished clearing cache. Ideally this flag could be modified by clearCache // and should be accessed via a lock but even if it does this test will fail now and //hopefully the next time this flag will be set to the correct value. if(mClearingCache) { @@ -177,11 +202,11 @@ class DeviceStorageMonitorService extends Binder { long diffTime = System.currentTimeMillis() - mThreadStartTime; if(diffTime > (10*60*1000)) { Log.w(TAG, "Thread that clears cache file seems to run for ever"); - } + } } else { restatDataDir(); if (localLOGV) Log.v(TAG, "freeMemory="+mFreeMem); - + //post intent to NotificationManager to display icon if necessary long memThreshold = getMemThreshold(); if (mFreeMem < memThreshold) { @@ -214,7 +239,7 @@ class DeviceStorageMonitorService extends Binder { //keep posting messages to itself periodically postCheckMemoryMsg(true, DEFAULT_CHECK_INTERVAL); } - + private void postCheckMemoryMsg(boolean clearCache, long delay) { // Remove queued messages mHandler.removeMessages(DEVICE_MEMORY_WHAT); @@ -222,16 +247,16 @@ class DeviceStorageMonitorService extends Binder { clearCache ?_TRUE : _FALSE, 0), delay); } - + /* - * just query settings to retrieve the memory threshold. + * just query settings to retrieve the memory threshold. * Preferred this over using a ContentObserver since Settings.Gservices caches the value * any way */ private long getMemThreshold() { int value = Settings.Gservices.getInt( - mContentResolver, - Settings.Gservices.SYS_STORAGE_THRESHOLD_PERCENTAGE, + mContentResolver, + Settings.Gservices.SYS_STORAGE_THRESHOLD_PERCENTAGE, DEFAULT_THRESHOLD_PERCENTAGE); if(localLOGV) Log.v(TAG, "Threshold Percentage="+value); //evaluate threshold value @@ -247,16 +272,17 @@ class DeviceStorageMonitorService extends Binder { mContext = context; mContentResolver = mContext.getContentResolver(); //create StatFs object - mFileStats = new StatFs(DATA_PATH); - //initialize block size - mBlkSize = mFileStats.getBlockSize(); + mDataFileStats = new StatFs(DATA_PATH); + mSystemFileStats = new StatFs(SYSTEM_PATH); + mCacheFileStats = new StatFs(CACHE_PATH); //initialize total storage on device - mTotalMemory = ((long)mFileStats.getBlockCount()*mBlkSize)/100L; + mTotalMemory = ((long)mDataFileStats.getBlockCount() * + mDataFileStats.getBlockSize())/100L; mStorageLowIntent = new Intent(Intent.ACTION_DEVICE_STORAGE_LOW); mStorageOkIntent = new Intent(Intent.ACTION_DEVICE_STORAGE_OK); checkMemory(true); } - + /** * This method sends a notification to NotificationManager to display @@ -271,7 +297,7 @@ class DeviceStorageMonitorService extends Binder { Intent lowMemIntent = new Intent(Intent.ACTION_MANAGE_PACKAGE_STORAGE); lowMemIntent.putExtra("memory", mFreeMem); lowMemIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - NotificationManager mNotificationMgr = + NotificationManager mNotificationMgr = (NotificationManager)mContext.getSystemService( Context.NOTIFICATION_SERVICE); CharSequence title = mContext.getText( @@ -302,7 +328,7 @@ class DeviceStorageMonitorService extends Binder { mContext.removeStickyBroadcast(mStorageLowIntent); mContext.sendBroadcast(mStorageOkIntent); } - + public void updateMemory() { int callingUid = getCallingUid(); if(callingUid != Process.SYSTEM_UID) { From 568cae571a3d74d1992176a21722e07b44e9a3c4 Mon Sep 17 00:00:00 2001 From: Dianne Hackborn Date: Wed, 7 Oct 2009 16:13:39 -0700 Subject: [PATCH 5/8] Fix issue #2171460: Turn off background blurring of power dialog Change-Id: I521629e0ccd0116acf149eeb7476c8474fc7c74a --- .../com/android/internal/app/ShutdownThread.java | 11 +++++++++-- core/res/res/values/config.xml | 5 +++++ .../android/server/status/StatusBarPolicy.java | 15 ++++++++++----- 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/core/java/com/android/internal/app/ShutdownThread.java b/core/java/com/android/internal/app/ShutdownThread.java index 01f6dac2a4b15..2060cf8a7ad1f 100644 --- a/core/java/com/android/internal/app/ShutdownThread.java +++ b/core/java/com/android/internal/app/ShutdownThread.java @@ -32,6 +32,7 @@ import android.os.RemoteException; import android.os.Power; import android.os.ServiceManager; import android.os.SystemClock; + import com.android.internal.telephony.ITelephony; import android.util.Log; import android.view.WindowManager; @@ -91,7 +92,10 @@ public final class ShutdownThread extends Thread { .setNegativeButton(com.android.internal.R.string.no, null) .create(); dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG); - dialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND); + if (!context.getResources().getBoolean( + com.android.internal.R.bool.config_sf_slowBlur)) { + dialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND); + } dialog.show(); } else { beginShutdownSequence(context); @@ -111,7 +115,10 @@ public final class ShutdownThread extends Thread { pd.setIndeterminate(true); pd.setCancelable(false); pd.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG); - pd.getWindow().addFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND); + if (!context.getResources().getBoolean( + com.android.internal.R.bool.config_sf_slowBlur)) { + pd.getWindow().addFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND); + } pd.show(); diff --git a/core/res/res/values/config.xml b/core/res/res/values/config.xml index 9f4af83602cec..9040edb7a58c2 100644 --- a/core/res/res/values/config.xml +++ b/core/res/res/values/config.xml @@ -26,6 +26,11 @@ strictly needed. --> false + + false + 150 diff --git a/services/java/com/android/server/status/StatusBarPolicy.java b/services/java/com/android/server/status/StatusBarPolicy.java index 801a938c46960..3d1fb83ee1327 100644 --- a/services/java/com/android/server/status/StatusBarPolicy.java +++ b/services/java/com/android/server/status/StatusBarPolicy.java @@ -624,15 +624,20 @@ public class StatusBarPolicy { pixelFormat = bg.getOpacity(); } + int flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE + | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE + | WindowManager.LayoutParams.FLAG_DIM_BEHIND; + + if (!mContext.getResources().getBoolean( + com.android.internal.R.bool.config_sf_slowBlur)) { + flags |= WindowManager.LayoutParams.FLAG_BLUR_BEHIND; + } + WindowManager.LayoutParams lp = new WindowManager.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.TYPE_TOAST, - WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE - | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE - | WindowManager.LayoutParams.FLAG_BLUR_BEHIND - | WindowManager.LayoutParams.FLAG_DIM_BEHIND, - pixelFormat); + flags, pixelFormat); // Get the dim amount from the theme TypedArray a = mContext.obtainStyledAttributes( From 46b2df153fccf7f918ee5d7d747c208bdd2d55f4 Mon Sep 17 00:00:00 2001 From: Mathias Agopian Date: Wed, 7 Oct 2009 17:58:29 -0700 Subject: [PATCH 6/8] fix [2164183] sometimes device just wants to stay asleep When switching rapidily orientation back and forth, surfaces end-up acquiring the freeze-lock when the first orientation change happens, but never release it because by the time the 2nd orientation change comes in, the surface size is back to its original size and doesn't appear to have resized. we now always release the freeze-lock when we receive a buffer of the expected size. --- libs/surfaceflinger/Layer.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libs/surfaceflinger/Layer.cpp b/libs/surfaceflinger/Layer.cpp index 2a3e6677e7451..7fd5434d05230 100644 --- a/libs/surfaceflinger/Layer.cpp +++ b/libs/surfaceflinger/Layer.cpp @@ -454,10 +454,10 @@ void Layer::lockPageFlip(bool& recomputeVisibleRegions) // recompute visible region recomputeVisibleRegions = true; - - // we now have the correct size, unfreeze the screen - mFreezeLock.clear(); } + + // we now have the correct size, unfreeze the screen + mFreezeLock.clear(); } if (lcblk->getQueuedCount()) { From 0da41a3635180398ae6cbf1ff75575f5dcb6e40b Mon Sep 17 00:00:00 2001 From: Mathias Agopian Date: Tue, 6 Oct 2009 15:58:44 -0700 Subject: [PATCH 7/8] fix [2170283] SurfaceFlinger crashes on OOM. when running out of memory, a null handle is returned but the error code may not be set. In that case we need to return NO_MEMORY instead of NO_ERROR, so that the calling code won't try to dereference the null pointer. --- libs/ui/Surface.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libs/ui/Surface.cpp b/libs/ui/Surface.cpp index 2d83a8c3106de..f51ca7a953c7b 100644 --- a/libs/ui/Surface.cpp +++ b/libs/ui/Surface.cpp @@ -746,6 +746,8 @@ status_t Surface::getBufferLocked(int index, int usage) currentBuffer->setIndex(index); mNeedFullUpdate = true; } + } else { + err = err<0 ? err : NO_MEMORY; } } return err; From bd2197fb0038acd2dc4b17ad3ed3c69cc29dcce2 Mon Sep 17 00:00:00 2001 From: Jason Sams Date: Wed, 7 Oct 2009 18:14:01 -0700 Subject: [PATCH 8/8] Add script to script call support. Add exception to catch out of bound index data when added to TriangleMeshBuilder. --- graphics/java/android/renderscript/SimpleMesh.java | 5 +++++ libs/rs/rsContext.h | 2 +- libs/rs/rsScriptC_Lib.cpp | 10 ++++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/graphics/java/android/renderscript/SimpleMesh.java b/graphics/java/android/renderscript/SimpleMesh.java index b422702bbc43b..0ad093e579781 100644 --- a/graphics/java/android/renderscript/SimpleMesh.java +++ b/graphics/java/android/renderscript/SimpleMesh.java @@ -290,6 +290,11 @@ public class SimpleMesh extends BaseObj { } public void addTriangle(int idx1, int idx2, int idx3) { + if((idx1 >= mVtxCount) || (idx1 < 0) || + (idx2 >= mVtxCount) || (idx2 < 0) || + (idx3 >= mVtxCount) || (idx3 < 0)) { + throw new IllegalStateException("Index provided greater than vertex count."); + } if ((mIndexCount + 3) >= mIndexData.length) { short t[] = new short[mIndexData.length * 2]; System.arraycopy(mIndexData, 0, t, 0, mIndexData.length); diff --git a/libs/rs/rsContext.h b/libs/rs/rsContext.h index b56e7d7f8476a..3570e102d96e8 100644 --- a/libs/rs/rsContext.h +++ b/libs/rs/rsContext.h @@ -99,6 +99,7 @@ public: uint32_t getMessageToClient(void *data, size_t *receiveLen, size_t bufferLen, bool wait); bool sendMessageToClient(void *data, uint32_t cmdID, size_t len, bool waitForSpace); + bool runScript(Script *s, uint32_t launchID); void initToClient(); void deinitToClient(); @@ -212,7 +213,6 @@ private: void initEGL(); - bool runScript(Script *s, uint32_t launchID); bool runRootScript(); static void * threadProc(void *); diff --git a/libs/rs/rsScriptC_Lib.cpp b/libs/rs/rsScriptC_Lib.cpp index 9a962907a1007..436f48b319efd 100644 --- a/libs/rs/rsScriptC_Lib.cpp +++ b/libs/rs/rsScriptC_Lib.cpp @@ -1008,6 +1008,13 @@ static uint32_t SC_toClient(void *data, int cmdID, int len, int waitForSpace) return rsc->sendMessageToClient(data, cmdID, len, waitForSpace != 0); } +static void SC_scriptCall(int scriptID) +{ + GET_TLS(); + rsc->runScript((Script *)scriptID, 0); +} + + ////////////////////////////////////////////////////////////////////////////// // Class implementation ////////////////////////////////////////////////////////////////////////////// @@ -1289,6 +1296,9 @@ ScriptCState::SymbolTable_t ScriptCState::gSyms[] = { { "debugHexI32", (void *)&SC_debugHexI32, "void", "(void *, int)" }, + { "scriptCall", (void *)&SC_scriptCall, + "void", "(int)" }, + { NULL, NULL, NULL, NULL } };