Skip to content
Permalink
Browse files

Add vold switchable pair

I'm not a fan of adding features via patches but this is getting ridiculous,
no closer to being merged after waiting a month and a half. People want the
feature and it doesn't break CMUpdater so here it is.
  • Loading branch information...
Dazzozo committed Sep 30, 2013
1 parent 7147887 commit 9a6736cf8e3afaa406a7dd4ff6f0692666c8e2b4
@@ -0,0 +1,166 @@
From 8fb7fa33149b568000c66c4e1c0ffde3fc24c596 Mon Sep 17 00:00:00 2001
From: dhacker29 <davidhackerdvm@gmail.com>
Date: Sat, 17 Aug 2013 16:35:18 -0500
Subject: [PATCH] Add setting for Vold Switchable Pair (2/2)

This will be hidden unless the device has non-emulated internal storage
and an external SD, in which case persist.sys.vold.switchablepair will be
set automaticaly. This does away with the need for ro.vold.switchablepair
to be set in the build.prop.

Change-Id: Id83fc90d771ca3a7179f2c50d0ae828eb3dbaa9f
---
AndroidManifest.xml | 1 +
res/values/cm_strings.xml | 7 ++++
res/xml/device_info_memory.xml | 5 +++
src/com/android/settings/deviceinfo/Memory.java | 54 ++++++++++++++++++++++++-
4 files changed, 66 insertions(+), 1 deletion(-)

diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index cb65bbb..7a697c4 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -66,6 +66,7 @@
<uses-permission android:name="android.permission.SET_TIME" />
<uses-permission android:name="android.permission.ACCESS_NOTIFICATIONS" />
<uses-permission android:name="android.permission.CHANGE_PRIVACY_GUARD_STATE" />
+ <uses-permission android:name="android.permission.REBOOT" />

<permission
android:name="android.permission.REQUEST_SUPERUSER"
diff --git a/res/values/cm_strings.xml b/res/values/cm_strings.xml
index eaabb1a..e793b06 100644
--- a/res/values/cm_strings.xml
+++ b/res/values/cm_strings.xml
@@ -999,4 +999,11 @@ two in order to insert additional control points. \'Remove\' deletes the selecte
<string name="selinux_enable_title">Security Enhanced Android</string>
<string name="selinux_enable_warning">You are about to enable SEAndroid, an advanced security mechanism, on your device.\n\nThis option exists for debugging purposes only, and it is very likely that your device isn\'t fully ready for it, which may cause parts (or all) of your hardware to block or hang.\n\nAre you sure you want to proceed?</string>

+ <!-- Vold Switchable Pair -->
+ <string name="storage_switch_title">Use external SD as primary</string>
+ <string name="storage_switch_summary_off">Using expanded internal storage for apps and media</string>
+ <string name="storage_switch_summary_on">Using SD Card for apps and media</string>
+ <string name="reboot_prompt_title">Reboot required</string>
+ <string name="reboot_prompt_message">In order to apply the changed configuration, a reboot is required.\n\nDo you want to reboot now?</string>
+
</resources>
diff --git a/res/xml/device_info_memory.xml b/res/xml/device_info_memory.xml
index e905f39..2010b2c 100644
--- a/res/xml/device_info_memory.xml
+++ b/res/xml/device_info_memory.xml
@@ -16,6 +16,11 @@

<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
android:title="@string/storage_settings_title">
+ <CheckBoxPreference
+ android:key="key_switch_storage"
+ android:title="@string/storage_switch_title"
+ android:summaryOn="@string/storage_switch_summary_on"
+ android:summaryOff="@string/storage_switch_summary_off" />

<!-- Preference categories are dynamically created based on the list of available storage volumes -->

diff --git a/src/com/android/settings/deviceinfo/Memory.java b/src/com/android/settings/deviceinfo/Memory.java
index 79216fc..d6ae78f 100644
--- a/src/com/android/settings/deviceinfo/Memory.java
+++ b/src/com/android/settings/deviceinfo/Memory.java
@@ -31,16 +31,20 @@ import android.hardware.usb.UsbManager;
import android.os.Bundle;
import android.os.Environment;
import android.os.IBinder;
+import android.os.PowerManager;
import android.os.RemoteException;
import android.os.ServiceManager;
+import android.os.SystemProperties;
import android.os.UserManager;
import android.os.storage.IMountService;
import android.os.storage.StorageEventListener;
import android.os.storage.StorageManager;
import android.os.storage.StorageVolume;
+import android.preference.CheckBoxPreference;
import android.preference.Preference;
import android.preference.PreferenceActivity;
import android.preference.PreferenceScreen;
+import android.text.TextUtils;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
@@ -79,6 +83,10 @@ public class Memory extends SettingsPreferenceFragment {
private UsbManager mUsbManager;

private ArrayList<StorageVolumePreferenceCategory> mCategories = Lists.newArrayList();
+ private static final String KEY_SWITCH_STORAGE = "key_switch_storage";
+ private static final String VOLD_SWITCH_PERSIST_PROP = "persist.sys.vold.switchexternal";
+ private static final String VOLD_SWITCHABLEPAIR_PROP = "persist.sys.vold.switchablepair";
+ private CheckBoxPreference mSwitchStoragePref;

@Override
public void onCreate(Bundle icicle) {
@@ -93,6 +101,27 @@ public class Memory extends SettingsPreferenceFragment {

addPreferencesFromResource(R.xml.device_info_memory);

+ String voldswitch = SystemProperties.get(VOLD_SWITCH_PERSIST_PROP, "0");
+ mSwitchStoragePref = (CheckBoxPreference) findPreference(KEY_SWITCH_STORAGE);
+ mSwitchStoragePref.setChecked("1".equals(voldswitch));
+ if (!Environment.isExternalStorageEmulated()) {
+ Log.i(TAG, "Checking to see if vold switch is possible on this device.");
+ String PRIMARY_STORAGE = System.getenv("EXTERNAL_STORAGE");
+ String SECONDARY_STORAGE = System.getenv("SECONDARY_STORAGE");
+ if (!TextUtils.isEmpty(PRIMARY_STORAGE) && !TextUtils.isEmpty(SECONDARY_STORAGE)) {
+ SystemProperties.set(VOLD_SWITCHABLEPAIR_PROP, PRIMARY_STORAGE + ',' +
+ SECONDARY_STORAGE);
+ Log.i(TAG, "Setting persist.sys.vold.swichablepair=" + PRIMARY_STORAGE + ',' +
+ SECONDARY_STORAGE);
+ } else {
+ Log.i(TAG, "Vold switch not possible on this device.");
+ }
+ }
+
+ if (SystemProperties.get(VOLD_SWITCHABLEPAIR_PROP).equals("")) {
+ removePreference(KEY_SWITCH_STORAGE);
+ }
+
addCategory(StorageVolumePreferenceCategory.buildForInternal(context));

final StorageVolume[] storageVolumes = mStorageManager.getVolumeList();
@@ -211,7 +240,13 @@ public class Memory extends SettingsPreferenceFragment {

@Override
public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
- if (StorageVolumePreferenceCategory.KEY_CACHE.equals(preference.getKey())) {
+ if(preference == mSwitchStoragePref) {
+ Log.d(TAG,"Setting persist.sys.vold.switchexternal to "+(
+ mSwitchStoragePref.isChecked() ? "1" : "0"));
+ SystemProperties.set(VOLD_SWITCH_PERSIST_PROP,
+ mSwitchStoragePref.isChecked() ? "1" : "0");
+ showRebootPrompt();
+ } else if (StorageVolumePreferenceCategory.KEY_CACHE.equals(preference.getKey())) {
ConfirmClearCacheFragment.show(this);
return true;
}
@@ -417,4 +452,21 @@ public class Memory extends SettingsPreferenceFragment {
return builder.create();
}
}
+
+ private void showRebootPrompt() {
+ AlertDialog dialog = new AlertDialog.Builder(getActivity())
+ .setTitle(R.string.reboot_prompt_title)
+ .setMessage(R.string.reboot_prompt_message)
+ .setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
+ pm.reboot(null);
+ }
+ })
+ .setNegativeButton(R.string.no, null)
+ .create();
+
+ dialog.show();
+ }
}
--
1.8.1.2

@@ -0,0 +1,31 @@
From db1099b74167412ddbe81686913e9486be767d40 Mon Sep 17 00:00:00 2001
From: dhacker29 <davidhackerdvm@gmail.com>
Date: Thu, 22 Aug 2013 22:28:06 -0500
Subject: [PATCH] Vold: Allow Settings to determine if a switchable pair exists
(1/2)

This will eliminate the need for pre-configured device pairs listed
in the build.prop, and display the setting if a pair exists.
This exapnds on commit dc8d157d73fb88ee33b38e724a8aabe7d5e53eee

Change-Id: I5f15a711b5ceabddaf842c252d890545f40b4786
---
Volume.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Volume.cpp b/Volume.cpp
index a7ac7f0..c2bcb45 100644
--- a/Volume.cpp
+++ b/Volume.cpp
@@ -152,7 +152,7 @@ Volume::Volume(VolumeManager *vm, const char *label, const char *mount_point) {
char *first, *second = NULL;
const char *delim = ",";

- property_get("ro.vold.switchablepair", switchable, "");
+ property_get("persist.sys.vold.switchablepair", switchable, "");

if (!(first = strtok(switchable, delim))) {
SLOGE("Mount switch requested, but no switchable mountpoints found");
--
1.8.1.2

@@ -52,9 +52,6 @@ ro.telephony.ril_class=HuaweiQualcommRIL

# USB
persist.sys.usb.config=mtp,adb
ro.additionalmounts=/storage/sdcard0
ro.emmc.sdcard.partition=19
ro.vold.switchablepair=/storage/sdcard1,/storage/sdcard0
ro.vold.umsdirtyratio=50

# Wi-Fi

0 comments on commit 9a6736c

Please sign in to comment.
You can’t perform that action at this time.