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

Commit 3d713b16 authored by Mike Lockwood's avatar Mike Lockwood
Browse files

Add checkbox to enable PTP USB mode.



Change-Id: Icb139cc3d1077565fb8dbe9917d87c7337f59797
Signed-off-by: default avatarMike Lockwood <lockwood@android.com>
parent 0cc35e44
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -1325,7 +1325,10 @@
    <string name="sd_eject">Unmount SD card</string>
    <!-- SD card & phone storage settings item title that will result in the phone unmounting the SD card.  This will be done before the user phyiscally removes the SD card from the phone.  Kind of like the "Safely remove" on some operating systems.   -->
    <string name="sd_eject_summary">Unmount the SD card for safe removal</string>

    <!-- SD card & phone storage settings item title for toggling PTP mode on and off.  When PTP mode is on the device will appear on the USB bus as a PTP camera device instead of an MTP music player.   -->
    <string name="ptp_mode">Enable PTP mode</string>
    <!-- SD card & phone storage settings item summary for toggling PTP mode on and off.  When PTP mode is on the device will appear on the USB bus as a PTP camera device instead of an MTP music player.   -->
    <string name="ptp_mode_summary">Appear on USB as a PTP camera device instead of an MTP device</string>

    <!-- SD card & phone storage settings item summary that is displayed when no SD card is inserted -->
    <string name="sd_insert_summary">Insert an SD card for mounting</string>
+3 −0
Original line number Diff line number Diff line
@@ -39,6 +39,9 @@
            style="?android:attr/preferenceInformationStyle" 
            android:title="@string/memory_available"
            android:summary="00"/>
        <CheckBoxPreference android:key="ptp_mode_toggle"
            android:title="@string/ptp_mode"
            android:summary="@string/ptp_mode_summary"/>
    </PreferenceCategory>

</PreferenceScreen>
+22 −1
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ import android.content.DialogInterface.OnCancelListener;
import android.content.pm.ApplicationInfo;
import android.content.res.Resources;
import android.os.Bundle;
import android.hardware.Usb;
import android.os.Environment;
import android.os.IBinder;
import android.os.RemoteException;
@@ -39,8 +40,10 @@ import android.os.StatFs;
import android.os.storage.IMountService;
import android.os.storage.StorageEventListener;
import android.os.storage.StorageManager;
import android.preference.CheckBoxPreference;
import android.preference.Preference;
import android.preference.PreferenceScreen;
import android.provider.Settings;
import android.text.format.Formatter;
import android.util.Log;
import android.widget.Toast;
@@ -60,6 +63,8 @@ public class Memory extends SettingsPreferenceFragment implements OnCancelListen

    private static final String MEMORY_SD_FORMAT = "memory_sd_format";

    private static final String PTP_MODE_TOGGLE = "ptp_mode_toggle";

    private static final int DLG_CONFIRM_UNMOUNT = 1;
    private static final int DLG_ERROR_UNMOUNT = 2;

@@ -69,6 +74,7 @@ public class Memory extends SettingsPreferenceFragment implements OnCancelListen
    private Preference mSdAvail;
    private Preference mSdMountToggle;
    private Preference mSdFormat;
    private CheckBoxPreference mPtpModeToggle;
    
    // Access using getMountService()
    private IMountService mMountService = null;
@@ -91,6 +97,16 @@ public class Memory extends SettingsPreferenceFragment implements OnCancelListen
        mSdAvail = findPreference(MEMORY_SD_AVAIL);
        mSdMountToggle = findPreference(MEMORY_SD_MOUNT_TOGGLE);
        mSdFormat = findPreference(MEMORY_SD_FORMAT);

        mPtpModeToggle = (CheckBoxPreference)findPreference(PTP_MODE_TOGGLE);
        if (Usb.isFunctionSupported(Usb.USB_FUNCTION_MTP)) {
            mPtpModeToggle.setChecked(Settings.System.getInt(
                    getContentResolver(),
                    Settings.System.USE_PTP_INTERFACE, 0) != 0);
        } else {
            // hide the PTP mode toggle checkbox if MTP is not supported
            getPreferenceScreen().removePreference(mPtpModeToggle);
        }
    }
    
    @Override
@@ -157,6 +173,11 @@ public class Memory extends SettingsPreferenceFragment implements OnCancelListen
            intent.setClass(getActivity(), com.android.settings.MediaFormat.class);
            startActivity(intent);
            return true;
        } else if (preference == mPtpModeToggle) {
            Settings.System.putInt(getContentResolver(),
                    Settings.System.USE_PTP_INTERFACE,
                    mPtpModeToggle.isChecked() ? 1 : 0);
            return true;
        }

        return false;