2017년 2월 28일 화요일

How to write to external storage on odroid(marshmallow android 6.0.1).

You maybe install utorrent app, but you can't download torrent file in external storage installed android 6.0.1(marshmallow).


Edit packages.xml.

$ su
# vi /data/system/packages.xml

<package name="com.utorrent.client" codePath="/data/app/com.utorrent.client-1" nativeLibraryPath="/data/app/com.utorrent.client-1/lib" primaryCpuAbi="armeabi-v7a" publicFlags="940097092" privateFlags="0" ft="15a648b6388" it="15a648b6f1f" ut="15a648b6f1f" version="245" userId="10069" installer="com.android.vending">
        ...
        <perms>
            ...
            <item name="android.permission.ACCESS_WIFI_STATE" granted="true" flags="0" />
            <item name="android.permission.WAKE_LOCK" granted="true" flags="0" />
            <item name="android.permission.WRITE_MEDIA_STORAGE" granted="true" flags="0" />
        </perms>


or hacking frameworks.


diff --git a/services/core/java/com/android/server/pm/Settings.java b/services/core/java/com/android/server/pm/Settings.java
index 647c17b..1ec1fe7 100644
--- a/services/core/java/com/android/server/pm/Settings.java
+++ b/services/core/java/com/android/server/pm/Settings.java
@@ -22,6 +22,7 @@ import static android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_DISABLED
 import static android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_DISABLED_USER;
 import static android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
 import static android.Manifest.permission.READ_EXTERNAL_STORAGE;
+import static android.Manifest.permission.WRITE_MEDIA_STORAGE;
 import static android.content.pm.PackageManager.INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_ALWAYS;
 import static android.content.pm.PackageManager.INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_NEVER;
 import static android.content.pm.PackageManager.INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_UNDEFINED;
@@ -1935,6 +1936,8 @@ final class Settings {
             return;
         }

+        boolean isMediaStoragePermission = false;
+
         serializer.startTag(null, TAG_PERMISSIONS);

         for (PermissionState permissionState : permissionStates) {
@@ -1943,6 +1946,19 @@ final class Settings {
             serializer.attribute(null, ATTR_GRANTED, String.valueOf(permissionState.isGranted()));
             serializer.attribute(null, ATTR_FLAGS, Integer.toHexString(permissionState.getFlags()));
             serializer.endTag(null, TAG_ITEM);
+
+            if (!isMediaStoragePermission
+                    && permissionState.getName().equals(WRITE_MEDIA_STORAGE)) {
+                isMediaStoragePermission = true;
+            }
+        }
+
+        if (!isMediaStoragePermission) {
+            serializer.startTag(null, TAG_ITEM);
+            serializer.attribute(null, ATTR_NAME, WRITE_MEDIA_STORAGE);
+            serializer.attribute(null, ATTR_GRANTED, "true");
+            serializer.attribute(null, ATTR_FLAGS, Integer.toHexString(0));
+            serializer.endTag(null, TAG_ITEM);
         }

         serializer.endTag(null, TAG_PERMISSIONS);

Automatically permission string is inserted in packages.xml.


After install app from Market you must reboot system.