Merge "Change storage migration to use quota APIs."
am: a0afdb0c49
Change-Id: Ie97a6001eb23314c65aff291f53cf575b7637870
This commit is contained in:
@@ -16,51 +16,40 @@
|
||||
|
||||
package com.android.settings.deviceinfo;
|
||||
|
||||
import android.content.ComponentName;
|
||||
import static com.android.settings.deviceinfo.StorageSettings.TAG;
|
||||
|
||||
import android.app.usage.ExternalStorageStats;
|
||||
import android.app.usage.StorageStatsManager;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.ServiceConnection;
|
||||
import android.content.pm.UserInfo;
|
||||
import android.net.TrafficStats;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.IBinder;
|
||||
import android.os.RemoteException;
|
||||
import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
import android.os.storage.StorageManager;
|
||||
import android.os.storage.VolumeInfo;
|
||||
import android.telecom.Log;
|
||||
import android.text.format.DateUtils;
|
||||
import android.text.format.Formatter;
|
||||
|
||||
import com.android.internal.app.IMediaContainerService;
|
||||
import java.io.IOException;
|
||||
import java.util.UUID;
|
||||
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static com.android.settings.deviceinfo.StorageSettings.TAG;
|
||||
|
||||
public abstract class MigrateEstimateTask extends AsyncTask<Void, Void, Long> implements
|
||||
ServiceConnection {
|
||||
public abstract class MigrateEstimateTask extends AsyncTask<Void, Void, Long> {
|
||||
private static final String EXTRA_SIZE_BYTES = "size_bytes";
|
||||
|
||||
private static final ComponentName DEFAULT_CONTAINER_COMPONENT = new ComponentName(
|
||||
"com.android.defcontainer", "com.android.defcontainer.DefaultContainerService");
|
||||
|
||||
/**
|
||||
* Assume roughly a Class 10 card.
|
||||
*/
|
||||
private static final long SPEED_ESTIMATE_BPS = 10 * TrafficStats.MB_IN_BYTES;
|
||||
|
||||
private final Context mContext;
|
||||
private final StorageManager mStorage;
|
||||
|
||||
private final CountDownLatch mConnected = new CountDownLatch(1);
|
||||
private IMediaContainerService mService;
|
||||
|
||||
private long mSizeBytes = -1;
|
||||
|
||||
public MigrateEstimateTask(Context context) {
|
||||
mContext = context;
|
||||
mStorage = context.getSystemService(StorageManager.class);
|
||||
}
|
||||
|
||||
public void copyFrom(Intent intent) {
|
||||
@@ -77,31 +66,36 @@ public abstract class MigrateEstimateTask extends AsyncTask<Void, Void, Long> im
|
||||
return mSizeBytes;
|
||||
}
|
||||
|
||||
final UserManager user = mContext.getSystemService(UserManager.class);
|
||||
final StorageManager storage = mContext.getSystemService(StorageManager.class);
|
||||
final StorageStatsManager stats = mContext.getSystemService(StorageStatsManager.class);
|
||||
|
||||
final VolumeInfo privateVol = mContext.getPackageManager().getPrimaryStorageCurrentVolume();
|
||||
final VolumeInfo emulatedVol = mStorage.findEmulatedForPrivate(privateVol);
|
||||
final VolumeInfo emulatedVol = storage.findEmulatedForPrivate(privateVol);
|
||||
|
||||
if (emulatedVol == null) {
|
||||
Log.w(TAG, "Failed to find current primary storage");
|
||||
return -1L;
|
||||
}
|
||||
|
||||
final String path = emulatedVol.getPath().getAbsolutePath();
|
||||
Log.d(TAG, "Estimating for current path " + path);
|
||||
|
||||
final Intent intent = new Intent().setComponent(DEFAULT_CONTAINER_COMPONENT);
|
||||
mContext.bindServiceAsUser(intent, this, Context.BIND_AUTO_CREATE, UserHandle.SYSTEM);
|
||||
|
||||
try {
|
||||
if (mConnected.await(15, TimeUnit.SECONDS)) {
|
||||
return mService.calculateDirectorySize(path);
|
||||
}
|
||||
} catch (InterruptedException | RemoteException e) {
|
||||
Log.w(TAG, "Failed to measure " + path);
|
||||
} finally {
|
||||
mContext.unbindService(this);
|
||||
}
|
||||
final UUID emulatedUuid = storage.getUuidForPath(emulatedVol.getPath());
|
||||
Log.d(TAG, "Measuring size of " + emulatedUuid);
|
||||
|
||||
return -1L;
|
||||
long size = 0;
|
||||
for (UserInfo u : user.getUsers()) {
|
||||
final ExternalStorageStats s = stats.queryExternalStatsForUser(emulatedUuid,
|
||||
UserHandle.of(u.id));
|
||||
size += s.getTotalBytes();
|
||||
if (u.id == UserHandle.USER_SYSTEM) {
|
||||
size += s.getObbBytes();
|
||||
}
|
||||
}
|
||||
return size;
|
||||
} catch (IOException e) {
|
||||
Log.w(TAG, "Failed to measure", e);
|
||||
return -1L;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -116,16 +110,4 @@ public abstract class MigrateEstimateTask extends AsyncTask<Void, Void, Long> im
|
||||
}
|
||||
|
||||
public abstract void onPostExecute(String size, String time);
|
||||
|
||||
@Override
|
||||
public void onServiceConnected(ComponentName name, IBinder service) {
|
||||
mService = IMediaContainerService.Stub.asInterface(service);
|
||||
mConnected.countDown();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onServiceDisconnected(ComponentName name) {
|
||||
// Ignored; we leave service in place for the background thread to
|
||||
// run into DeadObjectException
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user