Format as public/private; follow refactoring.

Offer to format an empty disk as public/private.

Bug: 19993667
Change-Id: I69fafaed524f3ef5e65d04a9e3a94789fcfc3087
This commit is contained in:
Jeff Sharkey
2015-04-28 13:41:01 -07:00
parent 02c89944d1
commit a16257dbd5
15 changed files with 236 additions and 97 deletions

View File

@@ -33,7 +33,8 @@ public class Settings extends SettingsActivity {
public static class VpnSettingsActivity extends SettingsActivity { /* empty */ }
public static class DateTimeSettingsActivity extends SettingsActivity { /* empty */ }
public static class StorageSettingsActivity extends SettingsActivity { /* empty */ }
public static class StorageVolumeSettingsActivity extends SettingsActivity { /* empty */ }
public static class PublicVolumeSettingsActivity extends SettingsActivity { /* empty */ }
public static class PrivateVolumeForgetActivity extends SettingsActivity { /* empty */ }
public static class WifiSettingsActivity extends SettingsActivity { /* empty */ }
public static class WifiP2pSettingsActivity extends SettingsActivity { /* empty */ }
public static class InputMethodAndLanguageSettingsActivity extends SettingsActivity { /* empty */ }

View File

@@ -83,6 +83,7 @@ import com.android.settings.dashboard.DashboardSummary;
import com.android.settings.dashboard.DashboardTile;
import com.android.settings.dashboard.NoHomeDialogFragment;
import com.android.settings.dashboard.SearchResultsSummary;
import com.android.settings.deviceinfo.PrivateVolumeForget;
import com.android.settings.deviceinfo.PublicVolumeSettings;
import com.android.settings.deviceinfo.StorageSettings;
import com.android.settings.deviceinfo.UsbSettings;
@@ -310,6 +311,7 @@ public class SettingsActivity extends Activity
TextToSpeechSettings.class.getName(),
StorageSettings.class.getName(),
PublicVolumeSettings.class.getName(),
PrivateVolumeForget.class.getName(),
DevelopmentSettings.class.getName(),
UsbSettings.class.getName(),
AndroidBeam.class.getName(),

View File

@@ -0,0 +1,68 @@
/*
* Copyright (C) 2015 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 com.android.settings.deviceinfo;
import android.os.Bundle;
import android.os.storage.StorageManager;
import android.os.storage.VolumeRecord;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;
import com.android.internal.logging.MetricsLogger;
import com.android.settings.InstrumentedFragment;
import com.android.settings.R;
public class PrivateVolumeForget extends InstrumentedFragment {
private VolumeRecord mRecord;
@Override
protected int getMetricsCategory() {
return MetricsLogger.DEVICEINFO_STORAGE;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
final StorageManager storage = getActivity().getSystemService(StorageManager.class);
final String fsUuid = getArguments().getString(VolumeRecord.EXTRA_FS_UUID);
mRecord = storage.findRecordByUuid(fsUuid);
final View view = inflater.inflate(R.layout.storage_internal_forget, container, false);
final TextView body = (TextView) view.findViewById(R.id.body);
final Button confirm = (Button) view.findViewById(R.id.confirm);
body.setText(TextUtils.expandTemplate(getText(R.string.storage_internal_forget_details),
mRecord.getNickname()));
confirm.setOnClickListener(mConfirmListener);
return view;
}
private final OnClickListener mConfirmListener = new OnClickListener() {
@Override
public void onClick(View v) {
final StorageManager storage = getActivity().getSystemService(StorageManager.class);
storage.forgetVolume(mRecord.getFsUuid());
getActivity().finish();
}
};
}

View File

@@ -33,7 +33,7 @@ import com.android.internal.logging.MetricsLogger;
import com.android.settings.InstrumentedFragment;
import com.android.settings.R;
public class PrivateVolumeFormatConfirm extends InstrumentedFragment {
public class PrivateVolumeFormat extends InstrumentedFragment {
private VolumeInfo mVolume;
private DiskInfo mDisk;
@@ -66,7 +66,7 @@ public class PrivateVolumeFormatConfirm extends InstrumentedFragment {
public void onClick(View v) {
final Intent intent = new Intent(getActivity(), StorageWizardFormatProgress.class);
intent.putExtra(DiskInfo.EXTRA_DISK_ID, mDisk.getId());
intent.putExtra(StorageWizardFormatProgress.EXTRA_FORMAT_PUBLIC, true);
intent.putExtra(StorageWizardFormatConfirm.EXTRA_FORMAT_PRIVATE, false);
startActivity(intent);
getActivity().finish();
}

View File

@@ -37,10 +37,10 @@ import android.os.UserManager;
import android.os.storage.StorageEventListener;
import android.os.storage.StorageManager;
import android.os.storage.VolumeInfo;
import android.os.storage.VolumeRecord;
import android.preference.Preference;
import android.preference.PreferenceScreen;
import android.provider.MediaStore;
import android.text.TextUtils;
import android.text.format.Formatter;
import android.util.Log;
import android.view.LayoutInflater;
@@ -160,7 +160,7 @@ public class PrivateVolumeSettings extends SettingsPreferenceFragment {
setHasOptionsMenu(true);
}
public void refresh() {
public void update() {
getActivity().setTitle(mStorageManager.getBestVolumeDescription(mVolume));
// Valid options may have changed
@@ -245,7 +245,7 @@ public class PrivateVolumeSettings extends SettingsPreferenceFragment {
}
mStorageManager.registerListener(mStorageListener);
refresh();
update();
}
@Override
@@ -297,19 +297,19 @@ public class PrivateVolumeSettings extends SettingsPreferenceFragment {
final Bundle args = new Bundle();
switch (item.getItemId()) {
case R.id.storage_rename:
RenameFragment.show(this);
RenameFragment.show(this, mVolume);
return true;
case R.id.storage_mount:
new MountTask(context, mVolume).execute();
return true;
case R.id.storage_unmount:
args.putString(VolumeInfo.EXTRA_VOLUME_ID, mVolume.getId());
startFragment(this, PrivateVolumeUnmountConfirm.class.getCanonicalName(),
startFragment(this, PrivateVolumeUnmount.class.getCanonicalName(),
R.string.storage_menu_unmount, 0, args);
return true;
case R.id.storage_format:
args.putString(VolumeInfo.EXTRA_VOLUME_ID, mVolume.getId());
startFragment(this, PrivateVolumeFormatConfirm.class.getCanonicalName(),
startFragment(this, PrivateVolumeFormat.class.getCanonicalName(),
R.string.storage_menu_format, 0, args);
return true;
case R.id.storage_usb:
@@ -437,15 +437,15 @@ public class PrivateVolumeSettings extends SettingsPreferenceFragment {
public void onVolumeStateChanged(VolumeInfo vol, int oldState, int newState) {
if (Objects.equals(mVolume.getId(), vol.getId())) {
mVolume = vol;
refresh();
update();
}
}
@Override
public void onVolumeMetadataChanged(VolumeInfo vol) {
if (Objects.equals(mVolume.getId(), vol.getId())) {
mVolume = vol;
refresh();
public void onVolumeMetadataChanged(String fsUuid) {
if (Objects.equals(mVolume.getFsUuid(), fsUuid)) {
mVolume = mStorageManager.findVolumeById(mVolumeId);
update();
}
}
};
@@ -454,12 +454,14 @@ public class PrivateVolumeSettings extends SettingsPreferenceFragment {
* Dialog that allows editing of volume nickname.
*/
public static class RenameFragment extends DialogFragment {
public static void show(PrivateVolumeSettings parent) {
public static void show(PrivateVolumeSettings parent, VolumeInfo vol) {
if (!parent.isAdded()) return;
final RenameFragment dialog = new RenameFragment();
dialog.setTargetFragment(parent, 0);
dialog.setArguments(parent.getArguments());
final Bundle args = new Bundle();
args.putString(VolumeRecord.EXTRA_FS_UUID, vol.getFsUuid());
dialog.setArguments(args);
dialog.show(parent.getFragmentManager(), TAG_RENAME);
}
@@ -468,20 +470,16 @@ public class PrivateVolumeSettings extends SettingsPreferenceFragment {
final Context context = getActivity();
final StorageManager storageManager = context.getSystemService(StorageManager.class);
final String volId = getArguments().getString(VolumeInfo.EXTRA_VOLUME_ID);
final VolumeInfo vol = storageManager.findVolumeById(volId);
final String fsUuid = getArguments().getString(VolumeRecord.EXTRA_FS_UUID);
final VolumeInfo vol = storageManager.findVolumeByUuid(fsUuid);
final VolumeRecord rec = storageManager.findRecordByUuid(fsUuid);
final AlertDialog.Builder builder = new AlertDialog.Builder(context);
final LayoutInflater dialogInflater = LayoutInflater.from(builder.getContext());
final View view = dialogInflater.inflate(R.layout.dialog_edittext, null, false);
final EditText nickname = (EditText) view.findViewById(R.id.edittext);
if (!TextUtils.isEmpty(vol.getNickname())) {
nickname.setText(vol.getNickname());
} else {
nickname.setText(storageManager.getBestVolumeDescription(vol));
}
nickname.setText(rec.getNickname());
builder.setTitle(R.string.storage_rename_title);
builder.setView(view);
@@ -491,7 +489,8 @@ public class PrivateVolumeSettings extends SettingsPreferenceFragment {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO: move to background thread
storageManager.setVolumeNickname(volId, nickname.getText().toString());
storageManager.setVolumeNickname(fsUuid,
nickname.getText().toString());
}
});
builder.setNegativeButton(R.string.cancel, null);
@@ -552,7 +551,7 @@ public class PrivateVolumeSettings extends SettingsPreferenceFragment {
public void onRemoveCompleted(final String packageName, final boolean succeeded) {
synchronized (this) {
if (--mRemaining == 0) {
mTarget.refresh();
mTarget.update();
}
}
}

View File

@@ -33,7 +33,7 @@ import com.android.settings.InstrumentedFragment;
import com.android.settings.R;
import com.android.settings.deviceinfo.StorageSettings.UnmountTask;
public class PrivateVolumeUnmountConfirm extends InstrumentedFragment {
public class PrivateVolumeUnmount extends InstrumentedFragment {
private VolumeInfo mVolume;
private DiskInfo mDisk;

View File

@@ -33,7 +33,6 @@ import com.android.internal.logging.MetricsLogger;
import com.android.internal.util.Preconditions;
import com.android.settings.R;
import com.android.settings.SettingsPreferenceFragment;
import com.android.settings.deviceinfo.StorageSettings.FormatTask;
import com.android.settings.deviceinfo.StorageSettings.MountTask;
import com.android.settings.deviceinfo.StorageSettings.UnmountTask;
@@ -110,7 +109,7 @@ public class PublicVolumeSettings extends SettingsPreferenceFragment {
mFormatInternal = buildAction(R.string.storage_menu_format_internal);
}
public void refresh() {
public void update() {
getActivity().setTitle(mStorageManager.getBestVolumeDescription(mVolume));
final Context context = getActivity();
@@ -180,7 +179,7 @@ public class PublicVolumeSettings extends SettingsPreferenceFragment {
}
mStorageManager.registerListener(mStorageListener);
refresh();
update();
}
@Override
@@ -197,10 +196,14 @@ public class PublicVolumeSettings extends SettingsPreferenceFragment {
} else if (pref == mUnmount) {
new UnmountTask(context, mVolume).execute();
} else if (pref == mFormat) {
new FormatTask(context, mVolume).execute();
final Intent intent = new Intent(context, StorageWizardFormatConfirm.class);
intent.putExtra(DiskInfo.EXTRA_DISK_ID, mDisk.getId());
intent.putExtra(StorageWizardFormatConfirm.EXTRA_FORMAT_PRIVATE, false);
startActivity(intent);
} else if (pref == mFormatInternal) {
final Intent intent = new Intent(context, StorageWizardFormatConfirm.class);
intent.putExtra(DiskInfo.EXTRA_DISK_ID, mDisk.getId());
intent.putExtra(StorageWizardFormatConfirm.EXTRA_FORMAT_PRIVATE, true);
startActivity(intent);
}
@@ -212,15 +215,15 @@ public class PublicVolumeSettings extends SettingsPreferenceFragment {
public void onVolumeStateChanged(VolumeInfo vol, int oldState, int newState) {
if (Objects.equals(mVolume.getId(), vol.getId())) {
mVolume = vol;
refresh();
update();
}
}
@Override
public void onVolumeMetadataChanged(VolumeInfo vol) {
if (Objects.equals(mVolume.getId(), vol.getId())) {
mVolume = vol;
refresh();
public void onVolumeMetadataChanged(String fsUuid) {
if (Objects.equals(mVolume.getFsUuid(), fsUuid)) {
mVolume = mStorageManager.findVolumeById(mVolumeId);
update();
}
}
};

View File

@@ -273,43 +273,6 @@ public class StorageSettings extends SettingsPreferenceFragment implements Index
}
}
public static class FormatTask extends AsyncTask<Void, Void, Exception> {
private final Context mContext;
private final StorageManager mStorageManager;
private final String mVolumeId;
private final String mDescription;
public FormatTask(Context context, VolumeInfo volume) {
mContext = context.getApplicationContext();
mStorageManager = mContext.getSystemService(StorageManager.class);
mVolumeId = volume.getId();
mDescription = mStorageManager.getBestVolumeDescription(volume);
}
@Override
protected Exception doInBackground(Void... params) {
try {
mStorageManager.format(mVolumeId);
mStorageManager.mount(mVolumeId);
return null;
} catch (Exception e) {
return e;
}
}
@Override
protected void onPostExecute(Exception e) {
if (e == null) {
Toast.makeText(mContext, mContext.getString(R.string.storage_format_success,
mDescription), Toast.LENGTH_SHORT).show();
} else {
Log.e(TAG, "Failed to format " + mVolumeId, e);
Toast.makeText(mContext, mContext.getString(R.string.storage_format_failure,
mDescription), Toast.LENGTH_SHORT).show();
}
}
}
/**
* Enable indexing of searchable data
*/

View File

@@ -24,6 +24,10 @@ import com.android.internal.util.Preconditions;
import com.android.settings.R;
public class StorageWizardFormatConfirm extends StorageWizardBase {
public static final String EXTRA_FORMAT_PRIVATE = "format_private";
private boolean mFormatPrivate;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -31,9 +35,17 @@ public class StorageWizardFormatConfirm extends StorageWizardBase {
Preconditions.checkNotNull(mDisk);
setHeaderText(R.string.storage_wizard_format_confirm_title);
setBodyText(R.string.storage_wizard_format_confirm_body,
mDisk.getDescription());
mFormatPrivate = getIntent().getBooleanExtra(EXTRA_FORMAT_PRIVATE, false);
if (mFormatPrivate) {
setHeaderText(R.string.storage_wizard_format_confirm_title);
setBodyText(R.string.storage_wizard_format_confirm_body,
mDisk.getDescription());
} else {
setHeaderText(R.string.storage_wizard_format_confirm_public_title);
setBodyText(R.string.storage_wizard_format_confirm_public_body,
mDisk.getDescription());
}
// TODO: make this a big red scary button
getNextButton().setText(R.string.storage_wizard_format_confirm_next);
@@ -43,6 +55,7 @@ public class StorageWizardFormatConfirm extends StorageWizardBase {
public void onNavigateNext() {
final Intent intent = new Intent(this, StorageWizardFormatProgress.class);
intent.putExtra(DiskInfo.EXTRA_DISK_ID, mDisk.getId());
intent.putExtra(EXTRA_FORMAT_PRIVATE, mFormatPrivate);
startActivity(intent);
finishAffinity();
}

View File

@@ -31,9 +31,7 @@ import com.android.internal.util.Preconditions;
import com.android.settings.R;
public class StorageWizardFormatProgress extends StorageWizardBase {
public static final String EXTRA_FORMAT_PUBLIC = "format_private";
private boolean mFormatPublic;
private boolean mFormatPrivate;
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -42,7 +40,8 @@ public class StorageWizardFormatProgress extends StorageWizardBase {
Preconditions.checkNotNull(mDisk);
mFormatPublic = getIntent().getBooleanExtra(EXTRA_FORMAT_PUBLIC, false);
mFormatPrivate = getIntent().getBooleanExtra(
StorageWizardFormatConfirm.EXTRA_FORMAT_PRIVATE, false);
setHeaderText(R.string.storage_wizard_format_progress_title, mDisk.getDescription());
setBodyText(R.string.storage_wizard_format_progress_body, mDisk.getDescription());
@@ -58,10 +57,10 @@ public class StorageWizardFormatProgress extends StorageWizardBase {
@Override
protected Exception doInBackground(Void... params) {
try {
if (mFormatPublic) {
mStorage.partitionPublic(mDisk.getId());
} else {
if (mFormatPrivate) {
mStorage.partitionPrivate(mDisk.getId());
} else {
mStorage.partitionPublic(mDisk.getId());
}
return null;
} catch (Exception e) {
@@ -73,7 +72,7 @@ public class StorageWizardFormatProgress extends StorageWizardBase {
protected void onPostExecute(Exception e) {
final Context context = StorageWizardFormatProgress.this;
if (e == null) {
if (!mFormatPublic) {
if (mFormatPrivate) {
// TODO: bring back migration once implemented
// final Intent intent = new Intent(context, StorageWizardMigrate.class);
// intent.putExtra(DiskInfo.EXTRA_DISK_ID, mDisk.getId());
@@ -81,6 +80,10 @@ public class StorageWizardFormatProgress extends StorageWizardBase {
final Intent intent = new Intent(context, StorageWizardReady.class);
intent.putExtra(DiskInfo.EXTRA_DISK_ID, mDisk.getId());
startActivity(intent);
} else {
final Intent intent = new Intent(context, StorageWizardReady.class);
intent.putExtra(DiskInfo.EXTRA_DISK_ID, mDisk.getId());
startActivity(intent);
}
finishAffinity();

View File

@@ -19,6 +19,7 @@ package com.android.settings.deviceinfo;
import android.content.Intent;
import android.os.Bundle;
import android.os.storage.DiskInfo;
import android.os.storage.VolumeInfo;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.RadioButton;
@@ -72,15 +73,26 @@ public class StorageWizardInit extends StorageWizardBase {
@Override
public void onNavigateNext() {
if (mRadioExternal.isChecked()) {
// Remember that user made decision
mStorage.setVolumeInited(mVolume.getId(), true);
if (mVolume != null && mVolume.getType() == VolumeInfo.TYPE_PUBLIC) {
// Remember that user made decision
mStorage.setVolumeInited(mVolume.getFsUuid(), true);
final Intent intent = new Intent(this, StorageWizardReady.class);
intent.putExtra(DiskInfo.EXTRA_DISK_ID, mDisk.getId());
startActivity(intent);
} else {
// Gotta format to get there
final Intent intent = new Intent(this, StorageWizardFormatConfirm.class);
intent.putExtra(DiskInfo.EXTRA_DISK_ID, mDisk.getId());
intent.putExtra(StorageWizardFormatConfirm.EXTRA_FORMAT_PRIVATE, false);
startActivity(intent);
}
final Intent intent = new Intent(this, StorageWizardReady.class);
intent.putExtra(DiskInfo.EXTRA_DISK_ID, mDisk.getId());
startActivity(intent);
} else if (mRadioInternal.isChecked()) {
final Intent intent = new Intent(this, StorageWizardFormatConfirm.class);
intent.putExtra(DiskInfo.EXTRA_DISK_ID, mDisk.getId());
intent.putExtra(StorageWizardFormatConfirm.EXTRA_FORMAT_PRIVATE, true);
startActivity(intent);
}
}

View File

@@ -49,7 +49,7 @@ public class StorageWizardMoveProgress extends StorageWizardBase {
// Register for updates and push through current status
getPackageManager().registerMoveCallback(mCallback, new Handler());
mCallback.onStatusChanged(mMoveId, getPackageManager().getMoveStatus(mMoveId), -1);
mCallback.onStatusChanged(mMoveId, null, getPackageManager().getMoveStatus(mMoveId), -1);
}
@Override
@@ -60,12 +60,7 @@ public class StorageWizardMoveProgress extends StorageWizardBase {
private final MoveCallback mCallback = new MoveCallback() {
@Override
public void onStarted(int moveId, String title) {
// Ignored
}
@Override
public void onStatusChanged(int moveId, int status, long estMillis) {
public void onStatusChanged(int moveId, String moveTitle, int status, long estMillis) {
if (mMoveId != moveId) return;
if (PackageManager.isMoveStatusFinished(status)) {