diff options
Diffstat (limited to 'tests/AndroidTests/src/com/android')
-rwxr-xr-x | tests/AndroidTests/src/com/android/unit_tests/AppCacheTest.java | 82 | ||||
-rw-r--r-- | tests/AndroidTests/src/com/android/unit_tests/BluetoothTest.java | 21 |
2 files changed, 83 insertions, 20 deletions
diff --git a/tests/AndroidTests/src/com/android/unit_tests/AppCacheTest.java b/tests/AndroidTests/src/com/android/unit_tests/AppCacheTest.java index 914d98b..6a9ac86 100755 --- a/tests/AndroidTests/src/com/android/unit_tests/AppCacheTest.java +++ b/tests/AndroidTests/src/com/android/unit_tests/AppCacheTest.java @@ -21,7 +21,12 @@ import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; + +import android.app.PendingIntent; +import android.content.BroadcastReceiver; import android.content.Context; +import android.content.Intent; +import android.content.IntentFilter; import android.content.pm.ApplicationInfo; import android.content.pm.IPackageDataObserver; import android.content.pm.IPackageStatsObserver; @@ -33,12 +38,13 @@ import android.test.suitebuilder.annotation.MediumTest; import android.test.suitebuilder.annotation.SmallTest; import android.test.suitebuilder.annotation.Suppress; import android.util.Log; +import android.os.Handler; import android.os.RemoteException; import android.os.ServiceManager; import android.os.StatFs; public class AppCacheTest extends AndroidTestCase { - private static final boolean localLOGV = false; + private static final boolean localLOGV = true; public static final String TAG="AppCacheTest"; public final long MAX_WAIT_TIME=60*1000; public final long WAIT_TIME_INCR=10*1000; @@ -471,12 +477,11 @@ public class AppCacheTest extends AndroidTestCase { boolean invokePMFreeApplicationCache(long idealStorageSize) throws Exception { try { - String packageName = mContext.getPackageName(); PackageDataObserver observer = new PackageDataObserver(); //wait on observer synchronized(observer) { - getPm().freeApplicationCache(idealStorageSize, observer); + getPm().freeStorageAndNotify(idealStorageSize, observer); long waitTime = 0; while(!observer.isDone() || (waitTime > MAX_WAIT_TIME)) { observer.wait(WAIT_TIME_INCR); @@ -495,6 +500,31 @@ public class AppCacheTest extends AndroidTestCase { return false; } } + + boolean invokePMFreeStorage(long idealStorageSize, FreeStorageReceiver r, + PendingIntent pi) throws Exception { + try { + // Spin lock waiting for call back + synchronized(r) { + getPm().freeStorage(idealStorageSize, pi); + long waitTime = 0; + while(!r.isDone() && (waitTime < MAX_WAIT_TIME)) { + r.wait(WAIT_TIME_INCR); + waitTime += WAIT_TIME_INCR; + } + if(!r.isDone()) { + throw new Exception("timed out waiting for call back from PendingIntent"); + } + } + return r.getResultCode() == 1; + } catch (RemoteException e) { + Log.w(TAG, "Failed to get handle for PackageManger Exception: "+e); + return false; + } catch (InterruptedException e) { + Log.w(TAG, "InterruptedException :"+e); + return false; + } + } @LargeTest public void testDeleteAppCacheFiles() throws Exception { @@ -563,6 +593,52 @@ public class AppCacheTest extends AndroidTestCase { ", cache="+stats.cacheSize); } + class FreeStorageReceiver extends BroadcastReceiver { + public static final String ACTION_FREE = "com.android.unit_tests.testcallback"; + private boolean doneFlag = false; + + public boolean isDone() { + return doneFlag; + } + + @Override + public void onReceive(Context context, Intent intent) { + if(intent.getAction().equalsIgnoreCase(ACTION_FREE)) { + if (localLOGV) Log.i(TAG, "Got notification: clear cache succeeded "+getResultCode()); + synchronized (this) { + doneFlag = true; + notifyAll(); + } + } + } + } + + @SmallTest + public void testFreeStorage() throws Exception { + StatFs st = new StatFs("/data"); + long blks1 = getFreeStorageBlks(st); + if(localLOGV) Log.i(TAG, "Available free blocks="+blks1); + long availableMem = getFreeStorageSize(st); + File cacheDir = mContext.getCacheDir(); + assertNotNull(cacheDir); + createTestFiles1(cacheDir, "testtmpdir", 5); + long blks2 = getFreeStorageBlks(st); + if(localLOGV) Log.i(TAG, "Available blocks after writing test files in application cache="+blks2); + // Create receiver and register it + FreeStorageReceiver receiver = new FreeStorageReceiver(); + mContext.registerReceiver(receiver, new IntentFilter(FreeStorageReceiver.ACTION_FREE)); + PendingIntent pi = PendingIntent.getBroadcast(mContext, + 0, new Intent(FreeStorageReceiver.ACTION_FREE), 0); + // Invoke PackageManager api + invokePMFreeStorage(availableMem, receiver, pi); + long blks3 = getFreeStorageBlks(st); + if(localLOGV) Log.i(TAG, "Available blocks after freeing cache"+blks3); + assertEquals(receiver.getResultCode(), 1); + mContext.unregisterReceiver(receiver); + // Verify result + verifyTestFiles1(cacheDir, "testtmpdir", 5); + } + /* utility method used to create observer and check async call back from PackageManager. * ClearApplicationUserData */ diff --git a/tests/AndroidTests/src/com/android/unit_tests/BluetoothTest.java b/tests/AndroidTests/src/com/android/unit_tests/BluetoothTest.java index 48a02c4..21fb94b 100644 --- a/tests/AndroidTests/src/com/android/unit_tests/BluetoothTest.java +++ b/tests/AndroidTests/src/com/android/unit_tests/BluetoothTest.java @@ -234,30 +234,18 @@ public class BluetoothTest extends AndroidTestCase { } Log.i(TAG, "onEnableResult(" + result + ")"); } - public void onCreateBondingResult(String device, int res) { - String result = "unknown"; - switch (res) { - case BluetoothDevice.RESULT_SUCCESS: - result = "success"; - break; - case BluetoothDevice.RESULT_FAILURE: - result = "FAILURE"; - break; - } - Log.i(TAG, "onEnableResult(" + device + ", " + result + ")"); - } public void onGetRemoteServiceChannelResult(String device, int channel) {} }; @SmallTest - public void testCreateBondingWithCallback() throws Exception { + public void testCreateBond() throws Exception { BluetoothDevice device = (BluetoothDevice)getContext().getSystemService(Context.BLUETOOTH_SERVICE); if (device == null) { Log.i(TAG, "Device not Bluetooth capable, skipping test"); return; } - if (!device.createBonding("01:23:45:67:89:AB", mCallback)) { + if (!device.createBond("01:23:45:67:89:AB")) { Log.e(TAG, "createBonding() failed"); } } @@ -286,7 +274,7 @@ public class BluetoothTest extends AndroidTestCase { Log.i(TAG, "Device not Bluetooth capable, skipping test"); return; } - String[] addresses = device.listBondings(); + String[] addresses = device.listBonds(); if (addresses == null) { Log.i(TAG, "Bluetooth disabled"); return; @@ -363,8 +351,7 @@ public class BluetoothTest extends AndroidTestCase { filter.addAction(BluetoothIntent.REMOTE_NAME_FAILED_ACTION); filter.addAction(BluetoothIntent.REMOTE_ALIAS_CHANGED_ACTION); filter.addAction(BluetoothIntent.REMOTE_ALIAS_CLEARED_ACTION); - filter.addAction(BluetoothIntent.BONDING_CREATED_ACTION); - filter.addAction(BluetoothIntent.BONDING_REMOVED_ACTION); + filter.addAction(BluetoothIntent.BOND_STATE_CHANGED_ACTION); filter.addAction(BluetoothIntent.HEADSET_STATE_CHANGED_ACTION); getContext().registerReceiver( (BroadcastReceiver)new BluetoothIntentReceiver(), filter); |