use of android.os.storage.StorageListener in project platform_frameworks_base by android.
the class PackageManagerTests method unmountMedia.
private boolean unmountMedia() {
// We can't unmount emulated storage.
if (Environment.isExternalStorageEmulated()) {
return true;
}
if (checkMediaState(Environment.MEDIA_UNMOUNTED)) {
return true;
}
final String path = Environment.getExternalStorageDirectory().getPath();
StorageListener observer = new StorageListener(Environment.MEDIA_UNMOUNTED);
StorageManager sm = (StorageManager) mContext.getSystemService(Context.STORAGE_SERVICE);
sm.registerListener(observer);
try {
// Wait on observer
synchronized (observer) {
getMs().unmountVolume(path, true, false);
long waitTime = 0;
while ((!observer.isDone()) && (waitTime < MAX_WAIT_TIME)) {
observer.wait(WAIT_TIME_INCR);
waitTime += WAIT_TIME_INCR;
}
if (!observer.isDone()) {
throw new Exception("Timed out waiting for unmount media notification");
}
return true;
}
} catch (Exception e) {
Log.e(TAG, "Exception : " + e);
return false;
} finally {
sm.unregisterListener(observer);
}
}
use of android.os.storage.StorageListener in project android_frameworks_base by AOSPA.
the class PackageManagerTests method mountMedia.
boolean mountMedia() {
// We can't mount emulated storage.
if (Environment.isExternalStorageEmulated()) {
return true;
}
if (checkMediaState(Environment.MEDIA_MOUNTED)) {
return true;
}
final String path = Environment.getExternalStorageDirectory().toString();
StorageListener observer = new StorageListener(Environment.MEDIA_MOUNTED);
StorageManager sm = (StorageManager) mContext.getSystemService(Context.STORAGE_SERVICE);
sm.registerListener(observer);
try {
// Wait on observer
synchronized (observer) {
int ret = getMs().mountVolume(path);
if (ret != StorageResultCode.OperationSucceeded) {
throw new Exception("Could not mount the media");
}
long waitTime = 0;
while ((!observer.isDone()) && (waitTime < MAX_WAIT_TIME)) {
observer.wait(WAIT_TIME_INCR);
waitTime += WAIT_TIME_INCR;
}
if (!observer.isDone()) {
throw new Exception("Timed out waiting for unmount media notification");
}
return true;
}
} catch (Exception e) {
Log.e(TAG, "Exception : " + e);
return false;
} finally {
sm.unregisterListener(observer);
}
}
use of android.os.storage.StorageListener in project android_frameworks_base by AOSPA.
the class PackageManagerTests method unmountMedia.
private boolean unmountMedia() {
// We can't unmount emulated storage.
if (Environment.isExternalStorageEmulated()) {
return true;
}
if (checkMediaState(Environment.MEDIA_UNMOUNTED)) {
return true;
}
final String path = Environment.getExternalStorageDirectory().getPath();
StorageListener observer = new StorageListener(Environment.MEDIA_UNMOUNTED);
StorageManager sm = (StorageManager) mContext.getSystemService(Context.STORAGE_SERVICE);
sm.registerListener(observer);
try {
// Wait on observer
synchronized (observer) {
getMs().unmountVolume(path, true, false);
long waitTime = 0;
while ((!observer.isDone()) && (waitTime < MAX_WAIT_TIME)) {
observer.wait(WAIT_TIME_INCR);
waitTime += WAIT_TIME_INCR;
}
if (!observer.isDone()) {
throw new Exception("Timed out waiting for unmount media notification");
}
return true;
}
} catch (Exception e) {
Log.e(TAG, "Exception : " + e);
return false;
} finally {
sm.unregisterListener(observer);
}
}
use of android.os.storage.StorageListener in project android_frameworks_base by ResurrectionRemix.
the class PackageManagerTests method mountMedia.
boolean mountMedia() {
// We can't mount emulated storage.
if (Environment.isExternalStorageEmulated()) {
return true;
}
if (checkMediaState(Environment.MEDIA_MOUNTED)) {
return true;
}
final String path = Environment.getExternalStorageDirectory().toString();
StorageListener observer = new StorageListener(Environment.MEDIA_MOUNTED);
StorageManager sm = (StorageManager) mContext.getSystemService(Context.STORAGE_SERVICE);
sm.registerListener(observer);
try {
// Wait on observer
synchronized (observer) {
int ret = getMs().mountVolume(path);
if (ret != StorageResultCode.OperationSucceeded) {
throw new Exception("Could not mount the media");
}
long waitTime = 0;
while ((!observer.isDone()) && (waitTime < MAX_WAIT_TIME)) {
observer.wait(WAIT_TIME_INCR);
waitTime += WAIT_TIME_INCR;
}
if (!observer.isDone()) {
throw new Exception("Timed out waiting for unmount media notification");
}
return true;
}
} catch (Exception e) {
Log.e(TAG, "Exception : " + e);
return false;
} finally {
sm.unregisterListener(observer);
}
}
use of android.os.storage.StorageListener in project android_frameworks_base by ResurrectionRemix.
the class PackageManagerTests method unmountMedia.
private boolean unmountMedia() {
// We can't unmount emulated storage.
if (Environment.isExternalStorageEmulated()) {
return true;
}
if (checkMediaState(Environment.MEDIA_UNMOUNTED)) {
return true;
}
final String path = Environment.getExternalStorageDirectory().getPath();
StorageListener observer = new StorageListener(Environment.MEDIA_UNMOUNTED);
StorageManager sm = (StorageManager) mContext.getSystemService(Context.STORAGE_SERVICE);
sm.registerListener(observer);
try {
// Wait on observer
synchronized (observer) {
getMs().unmountVolume(path, true, false);
long waitTime = 0;
while ((!observer.isDone()) && (waitTime < MAX_WAIT_TIME)) {
observer.wait(WAIT_TIME_INCR);
waitTime += WAIT_TIME_INCR;
}
if (!observer.isDone()) {
throw new Exception("Timed out waiting for unmount media notification");
}
return true;
}
} catch (Exception e) {
Log.e(TAG, "Exception : " + e);
return false;
} finally {
sm.unregisterListener(observer);
}
}
Aggregations