Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c0c73393 authored by Toha's avatar Toha Committed by Abhisek Devkota
Browse files

Use actual storage type of sdcard/usb (2/2).

Currently, storage volume description for mount/unmount/format determined at
build time using PRODUCT_CHARACTERISTICS. For device which has only a sdcard or
only support usb storage, displayed description is correct. For device which has
both storage, the displayed description is totally wrong.

Use of actual storage type at runtime can eliminate the needed to specify
product characteristics, either default or nosdcard.

Change-Id: I9f8d53a4648d960f1009b1fe94787eecd4343427
parent ad98a676
Loading
Loading
Loading
Loading
+12 −14
Original line number Diff line number Diff line
@@ -21,18 +21,16 @@
        xmlns:android="http://schemas.android.com/apk/res/android"
        style="@style/info_layout">

    <TextView
    <TextView android:id="@+id/execute_media_desc"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="20sp"
        android:text="@string/media_format_final_desc" />
        android:textSize="20sp" />

    <Button android:id="@+id/execute_media_format"
        android:layout_gravity="center_horizontal"
        android:layout_marginTop="40dip"
        android:layout_width="150dip"
        android:layout_height="wrap_content"
        android:text="@string/media_format_final_button_text"
        android:gravity="center" />

</LinearLayout>
+11 −13
Original line number Diff line number Diff line
@@ -22,18 +22,16 @@
        xmlns:android="http://schemas.android.com/apk/res/android"
        style="@style/info_layout">

    <TextView
    <TextView android:id="@+id/initiate_media_desc"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="18sp"
        android:text="@string/media_format_desc" />
        android:textSize="18sp" />

    <Button android:id="@+id/initiate_media_format"
        android:layout_gravity="center_horizontal"
        android:layout_marginTop="40dip"
        android:layout_width="150dip"
        android:layout_height="wrap_content"
        android:text="@string/media_format_button_text"
        android:gravity="center" />

</LinearLayout>
+43 −0
Original line number Diff line number Diff line
@@ -1295,4 +1295,47 @@ two in order to insert additional control points. \'Remove\' deletes the selecte
    <!-- Keep the referenced menu string consistent with status_bar_notification_spam_item_title in frameworks/base/packages/SystemUI -->
    <string name="no_filters_title">No filters set. To filter a notification, long press it and choose \'Ignore messages like this\'.</string>

    <!-- Storage menu, label for usb storage -->
    <string name="usb_eject">Unmount USB storage</string>
    <string name="usb_eject_summary">Unmount the USB storage so you can safely remove it</string>
    <string name="usb_insert_summary">Insert USB storage for mounting</string>
    <string name="usb_mount">Mount USB storage</string>
    <string name="usb_mount_summary"></string>
    <string name="usb_format">Erase USB storage</string>
    <string name="usb_format_summary">Erases all data on the USB storage, such as music and photos</string>
    <string name="dlg_confirm_usb_unmount_title">Unmount USB storage?</string>
    <string name="dlg_confirm_usb_unmount_text">If you unmount the USB storage, some apps you are using will stop and may be unavailable until you remount the USB storage.</string>
    <string name="dlg_error_usb_unmount_title"></string>
    <string name="dlg_error_usb_unmount_text">Couldn\'t unmount USB storage. Try again later.</string>
    <string name="usb_unmount_inform_text">USB storage will be unmounted.</string>
    <string name="usb_ejecting_title">Unmounting USB storage</string>
    <string name="usb_ejecting_summary">USB storage unmount in progress</string>
    <string name="usb_media_format_title">Erase USB storage</string>
    <string name="usb_media_format_summary">Erases all data in USB storage</string>
    <string name="usb_media_format_desc">Erase all USB storage? You will lose <b>all</b> stored data!</string>
    <string name="usb_media_format_button_text">Erase USB storage</string>
    <string name="usb_media_format_final_desc">Erase the USB storage, deleting all files stored there? You can\'t reverse this action!</string>
    <string name="usb_media_format_gesture_explanation">You need to draw your unlock pattern to confirm that you want to erase the USB storage.</string>

    <!-- Storage menu, label for SD card  -->
    <string name="sd_eject">Unmount SD card</string>
    <string name="sd_eject_summary">Unmount the SD card so you can safely remove it</string>
    <string name="sd_insert_summary">Insert an SD card for mounting</string>
    <string name="sd_mount">Mount SD card</string>
    <string name="sd_mount_summary"></string>
    <string name="sd_format">Erase SD card</string>
    <string name="sd_format_summary">Erases all data on the SD card, such as music and photos</string>
    <string name="dlg_confirm_sd_unmount_title">Unmount SD card?</string>
    <string name="dlg_confirm_sd_unmount_text">If you unmount the SD card, some apps you are using will stop and may be unavailable until you remount the SD card.</string>
    <string name="dlg_error_sd_unmount_title"></string>
    <string name="dlg_error_sd_unmount_text">Couldn\'t unmount SD card. Try again later.</string>
    <string name="sd_unmount_inform_text">SD card will be unmounted.</string>
    <string name="sd_ejecting_title">Unmounting SD card</string>
    <string name="sd_ejecting_summary">SD card unmount in progress</string>
    <string name="sd_media_format_title">Erase SD card</string>
    <string name="sd_media_format_summary">Erases all data on the SD card</string>
    <string name="sd_media_format_desc">Erase the SD card? You will lose <b>all</b> data on the card!</string>
    <string name="sd_media_format_button_text">Erase SD card</string>
    <string name="sd_media_format_final_desc">Erase the SD card, deleting all files stored there? You can\'t reverse this action!</string>
    <string name="sd_media_format_gesture_explanation">You need to draw your unlock pattern to confirm that you want to erase the SD card.</string>
</resources>
+27 −4
Original line number Diff line number Diff line
@@ -18,11 +18,13 @@ package com.android.settings;

import android.app.Activity;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.os.storage.StorageVolume;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.android.internal.os.storage.ExternalStorageFormatter;

@@ -41,11 +43,16 @@ public class MediaFormat extends Activity {
    private LayoutInflater mInflater;

    private View mInitialView;
    private TextView mInitiateText;
    private Button mInitiateButton;

    private View mFinalView;
    private TextView mFinalText;
    private Button mFinalButton;

    private StorageVolume mVolume;
    private boolean mIsUsbStorage;

    /**
     * The user has gone through the multiple confirmation, so now we go ahead
     * and invoke the Mount Service to format the SD card.
@@ -59,9 +66,7 @@ public class MediaFormat extends Activity {
                Intent intent = new Intent(ExternalStorageFormatter.FORMAT_ONLY);
                intent.setComponent(ExternalStorageFormatter.COMPONENT_NAME);
                // Transfer the storage volume to the new intent
                final StorageVolume storageVolume = getIntent().getParcelableExtra(
                        StorageVolume.EXTRA_STORAGE_VOLUME);
                intent.putExtra(StorageVolume.EXTRA_STORAGE_VOLUME, storageVolume);
                intent.putExtra(StorageVolume.EXTRA_STORAGE_VOLUME, mVolume);
                startService(intent);
                finish();
            }
@@ -75,7 +80,8 @@ public class MediaFormat extends Activity {
        return new ChooseLockSettingsHelper(this)
                .launchConfirmationActivity(request,
                        getText(R.string.media_format_gesture_prompt),
                        getText(R.string.media_format_gesture_explanation));
                        getText(mIsUsbStorage ? R.string.usb_media_format_gesture_explanation :
                                R.string.sd_media_format_gesture_explanation));
    }

    @Override
@@ -116,8 +122,14 @@ public class MediaFormat extends Activity {
    private void establishFinalConfirmationState() {
        if (mFinalView == null) {
            mFinalView = mInflater.inflate(R.layout.media_format_final, null);
            mFinalText =
                    (TextView) mFinalView.findViewById(R.id.execute_media_desc);
            mFinalText.setText(mIsUsbStorage ? R.string.usb_media_format_final_desc :
                    R.string.sd_media_format_final_desc);
            mFinalButton =
                    (Button) mFinalView.findViewById(R.id.execute_media_format);
            mFinalButton.setText(mIsUsbStorage ? R.string.usb_media_format_button_text :
                    R.string.sd_media_format_button_text);
            mFinalButton.setOnClickListener(mFinalClickListener);
        }

@@ -139,8 +151,14 @@ public class MediaFormat extends Activity {
    private void establishInitialState() {
        if (mInitialView == null) {
            mInitialView = mInflater.inflate(R.layout.media_format_primary, null);
            mInitiateText =
                    (TextView) mInitialView.findViewById(R.id.initiate_media_desc);
            mInitiateText.setText(mIsUsbStorage ? R.string.usb_media_format_desc :
                    R.string.sd_media_format_desc);
            mInitiateButton =
                    (Button) mInitialView.findViewById(R.id.initiate_media_format);
            mInitiateButton.setText(mIsUsbStorage ? R.string.usb_media_format_button_text :
                    R.string.sd_media_format_button_text);
            mInitiateButton.setOnClickListener(mInitiateListener);
        }

@@ -155,6 +173,11 @@ public class MediaFormat extends Activity {
        mFinalView = null;
        mInflater = LayoutInflater.from(this);

        mVolume = getIntent().getParcelableExtra(StorageVolume.EXTRA_STORAGE_VOLUME);
        mIsUsbStorage = mVolume != null && mVolume.getDescriptionId() ==
                android.R.string.storage_usb;
        setTitle(mIsUsbStorage ? R.string.usb_media_format_title : R.string.sd_media_format_title);

        establishInitialState();
    }

+39 −25
Original line number Diff line number Diff line
@@ -71,8 +71,9 @@ public class Memory extends SettingsPreferenceFragment {
    // The mountToggle Preference that has last been clicked.
    // Assumes no two successive unmount event on 2 different volumes are performed before the first
    // one's preference is disabled
    private static Preference sLastClickedMountToggle;
    private static String sClickedMountPoint;
    private Preference mLastClickedMountToggle;
    private String mClickedMountPoint;
    private StorageVolumePreferenceCategory mLastClickedCategory;

    // Access using getMountService()
    private IMountService mMountService;
@@ -234,8 +235,9 @@ public class Memory extends SettingsPreferenceFragment {

            final StorageVolume volume = category.getStorageVolume();
            if (volume != null && category.mountToggleClicked(preference)) {
                sLastClickedMountToggle = preference;
                sClickedMountPoint = volume.getPath();
                mLastClickedCategory = category;
                mLastClickedMountToggle = preference;
                mClickedMountPoint = volume.getPath();
                String state = mStorageManager.getVolumeState(volume.getPath());
                if (Environment.MEDIA_MOUNTED.equals(state) ||
                        Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
@@ -273,19 +275,27 @@ public class Memory extends SettingsPreferenceFragment {
        switch (id) {
        case DLG_CONFIRM_UNMOUNT:
            return new AlertDialog.Builder(getActivity())
                    .setTitle(R.string.dlg_confirm_unmount_title)
                .setTitle(mLastClickedCategory.isUsbStorage() ?
                        R.string.dlg_confirm_usb_unmount_title :
                        R.string.dlg_confirm_sd_unmount_title)
                .setPositiveButton(R.string.dlg_ok, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        doUnmount();
                    }})
                .setNegativeButton(R.string.cancel, null)
                    .setMessage(R.string.dlg_confirm_unmount_text)
                .setMessage(mLastClickedCategory.isUsbStorage() ?
                        R.string.dlg_confirm_usb_unmount_text :
                        R.string.dlg_confirm_sd_unmount_text)
                .create();
        case DLG_ERROR_UNMOUNT:
            return new AlertDialog.Builder(getActivity())
            .setTitle(R.string.dlg_error_unmount_title)
                .setTitle(mLastClickedCategory.isUsbStorage() ?
                        R.string.dlg_error_usb_unmount_title :
                        R.string.dlg_error_sd_unmount_title)
                .setNeutralButton(R.string.dlg_ok, null)
            .setMessage(R.string.dlg_error_unmount_text)
                .setMessage(mLastClickedCategory.isUsbStorage() ?
                        R.string.dlg_error_usb_unmount_text :
                        R.string.dlg_error_sd_unmount_text)
                .create();
        }
        return null;
@@ -293,13 +303,17 @@ public class Memory extends SettingsPreferenceFragment {

    private void doUnmount() {
        // Present a toast here
        Toast.makeText(getActivity(), R.string.unmount_inform_text, Toast.LENGTH_SHORT).show();
        Toast.makeText(getActivity(), mLastClickedCategory.isUsbStorage() ?
                R.string.usb_unmount_inform_text : R.string.sd_unmount_inform_text,
                Toast.LENGTH_SHORT).show();
        IMountService mountService = getMountService();
        try {
            sLastClickedMountToggle.setEnabled(false);
            sLastClickedMountToggle.setTitle(getString(R.string.sd_ejecting_title));
            sLastClickedMountToggle.setSummary(getString(R.string.sd_ejecting_summary));
            mountService.unmountVolume(sClickedMountPoint, true, false);
            mLastClickedMountToggle.setEnabled(false);
            mLastClickedMountToggle.setTitle(mLastClickedCategory.isUsbStorage() ?
                    R.string.usb_ejecting_title : R.string.sd_ejecting_title);
            mLastClickedMountToggle.setSummary(mLastClickedCategory.isUsbStorage() ?
                    R.string.usb_ejecting_summary : R.string.sd_ejecting_summary);
            mountService.unmountVolume(mClickedMountPoint, true, false);
        } catch (RemoteException e) {
            // Informative dialog to user that unmount failed.
            showDialogInner(DLG_ERROR_UNMOUNT);
@@ -313,7 +327,7 @@ public class Memory extends SettingsPreferenceFragment {

    private boolean hasAppsAccessingStorage() throws RemoteException {
        IMountService mountService = getMountService();
        int stUsers[] = mountService.getStorageUsers(sClickedMountPoint);
        int stUsers[] = mountService.getStorageUsers(mClickedMountPoint);
        if (stUsers != null && stUsers.length > 0) {
            return true;
        }
@@ -351,7 +365,7 @@ public class Memory extends SettingsPreferenceFragment {
        IMountService mountService = getMountService();
        try {
            if (mountService != null) {
                mountService.mountVolume(sClickedMountPoint);
                mountService.mountVolume(mClickedMountPoint);
            } else {
                Log.e(TAG, "Mount service is null, can't mount");
            }
Loading