Skip to content

Commit

Permalink
usb_disk: add icon for mobile phones
Browse files Browse the repository at this point in the history
Add a match for my Kazam dumb phone, which is not very descriptive...
  • Loading branch information
mmuman committed Nov 26, 2015
1 parent 12b32eb commit e3c95b5
Showing 1 changed file with 80 additions and 9 deletions.
89 changes: 80 additions & 9 deletions src/add-ons/kernel/drivers/disk/usb/usb_disk/usb_disk.cpp
Expand Up @@ -288,13 +288,67 @@ const unsigned char kSDIcon[] = {
0x0a, 0x08, 0x02, 0x08, 0x09, 0x00
};

const unsigned char kMobileIcon[] = {
0x6e, 0x63, 0x69, 0x66, 0x09, 0x05, 0x00, 0x04, 0x00, 0x66, 0x02, 0x00,
0x06, 0x02, 0x38, 0xf1, 0x86, 0x38, 0x62, 0x09, 0xba, 0xd4, 0x58, 0x3b,
0x7e, 0xb7, 0x4a, 0x28, 0x8f, 0x47, 0xaf, 0x7c, 0x00, 0xee, 0xef, 0xf3,
0xff, 0xce, 0xd2, 0xd9, 0x02, 0x00, 0x06, 0x03, 0x39, 0x3a, 0x47, 0xba,
0x81, 0x7b, 0x3f, 0x5c, 0xe7, 0x3e, 0x2a, 0x74, 0xc5, 0xab, 0xe0, 0x49,
0x3b, 0x67, 0x00, 0xff, 0xff, 0xff, 0x42, 0xd9, 0xde, 0xe5, 0xff, 0xb5,
0xb8, 0xbf, 0x02, 0x00, 0x06, 0x02, 0x38, 0xdc, 0xc0, 0x32, 0xb6, 0x96,
0xb9, 0xc3, 0xec, 0x3f, 0xf8, 0xe2, 0x4a, 0x00, 0x51, 0xb9, 0x4b, 0xdc,
0x00, 0xce, 0xd2, 0xd9, 0xff, 0x95, 0x9a, 0xa6, 0x02, 0x03, 0x06, 0x04,
0xba, 0x6c, 0x40, 0xb8, 0x55, 0xde, 0xbb, 0x7a, 0x07, 0x3d, 0x9b, 0x59,
0x49, 0xea, 0xb7, 0x49, 0x0b, 0x3e, 0x20, 0xda, 0xde, 0xe5, 0x52, 0xff,
0xff, 0xff, 0xa4, 0xff, 0xff, 0xff, 0xff, 0x95, 0x9a, 0xa6, 0x05, 0xff,
0x02, 0x00, 0x06, 0x03, 0x38, 0x2d, 0xf0, 0x3a, 0x3d, 0xb3, 0xbf, 0x98,
0xe5, 0x3d, 0x7f, 0x98, 0x4b, 0xc7, 0x2b, 0x44, 0x03, 0xbe, 0x00, 0x9e,
0xc9, 0xff, 0xb2, 0x60, 0x99, 0xde, 0xff, 0x7f, 0xb0, 0xef, 0x03, 0x73,
0x79, 0x80, 0x15, 0x0a, 0x0a, 0x29, 0x54, 0x39, 0x5e, 0x3c, 0x5c, 0x3d,
0x5a, 0x46, 0x53, 0x47, 0x53, 0x59, 0x44, 0x59, 0x43, 0x4a, 0x3c, 0x29,
0x52, 0x0a, 0x08, 0x4a, 0x39, 0x4b, 0x3a, 0x3a, 0x5c, 0x38, 0x5c, 0x27,
0x52, 0x29, 0x4e, 0x2a, 0x4d, 0x38, 0x31, 0x0a, 0x0a, 0x4a, 0x39, 0x3b,
0x57, 0x39, 0x59, 0x37, 0x59, 0x36, 0x5a, 0x29, 0x52, 0x27, 0x52, 0x29,
0x4e, 0x2a, 0x4d, 0x38, 0x31, 0x0a, 0x0a, 0x27, 0x52, 0x29, 0x52, 0x36,
0x5a, 0x37, 0x59, 0x39, 0x59, 0x3b, 0x57, 0x4a, 0x39, 0x4b, 0x3a, 0x3a,
0x5c, 0x38, 0x5c, 0x08, 0x02, 0x35, 0x45, 0x2e, 0x51, 0x08, 0x02, 0x3b,
0x48, 0x34, 0x54, 0x08, 0x02, 0x3b, 0x53, 0x2d, 0x4b, 0x08, 0x02, 0x2f,
0x47, 0x3d, 0x4e, 0x0a, 0x08, 0x31, 0x42, 0x30, 0x40, 0x3f, 0x22, 0x52,
0x29, 0x52, 0x2a, 0x43, 0x48, 0x42, 0x49, 0x3f, 0x49, 0x0a, 0x0a, 0x31,
0x42, 0x30, 0x40, 0x3f, 0x22, 0x52, 0x29, 0x52, 0x2a, 0x43, 0x48, 0x42,
0x49, 0x3f, 0x49, 0x50, 0x29, 0x3f, 0x23, 0x0a, 0x04, 0x31, 0x42, 0x3f,
0x23, 0x50, 0x29, 0x3f, 0x49, 0x0a, 0x04, 0x48, 0x28, 0x47, 0x29, 0x44,
0x28, 0x45, 0x27, 0x0a, 0x04, 0x43, 0x26, 0x44, 0x25, 0x4b, 0x28, 0x4a,
0x29, 0x0a, 0x04, 0x4c, 0x2c, 0x44, 0x3c, 0x38, 0x36, 0x3f, 0x27, 0x0a,
0x04, 0x39, 0x3e, 0x3c, 0x40, 0x3d, 0x3e, 0xbd, 0x62, 0xbe, 0x44, 0x08,
0x02, 0x37, 0x40, 0x3c, 0x43, 0x08, 0x02, 0x36, 0x42, 0x3a, 0x39, 0x08,
0x02, 0x35, 0x3d, 0x37, 0x3e, 0x08, 0x02, 0x3b, 0x45, 0x40, 0x3c, 0x08,
0x02, 0x40, 0x43, 0x3d, 0x41, 0x08, 0x03, 0x38, 0x36, 0x3f, 0x27, 0x4c,
0x2c, 0x0f, 0x0a, 0x01, 0x01, 0x00, 0x10, 0x01, 0x15, 0x84, 0x00, 0x04,
0x0a, 0x00, 0x01, 0x01, 0x18, 0x00, 0x15, 0x01, 0x17, 0x86, 0x02, 0x04,
0x0a, 0x00, 0x01, 0x01, 0x18, 0x15, 0xff, 0x01, 0x17, 0x84, 0x02, 0x04,
0x0a, 0x03, 0x01, 0x02, 0x00, 0x0a, 0x04, 0x01, 0x03, 0x00, 0x0a, 0x08,
0x04, 0x04, 0x05, 0x06, 0x07, 0x18, 0x15, 0xff, 0x01, 0x17, 0x81, 0x00,
0x04, 0x0a, 0x00, 0x01, 0x08, 0x18, 0x00, 0x15, 0x01, 0x17, 0x86, 0x02,
0x04, 0x0a, 0x00, 0x01, 0x08, 0x18, 0x15, 0xff, 0x01, 0x17, 0x84, 0x02,
0x04, 0x0a, 0x05, 0x01, 0x09, 0x00, 0x0a, 0x02, 0x01, 0x0a, 0x00, 0x0a,
0x00, 0x01, 0x0b, 0x08, 0x15, 0xff, 0x0a, 0x06, 0x01, 0x0c, 0x08, 0x15,
0xff, 0x0a, 0x07, 0x01, 0x0d, 0x00, 0x0a, 0x06, 0x01, 0x0e, 0x08, 0x15,
0xff, 0x0a, 0x08, 0x06, 0x13, 0x12, 0x11, 0x10, 0x0f, 0x14, 0x18, 0x15,
0xff, 0x01, 0x17, 0x81, 0x00, 0x04
};

device_icon kKeyIconData = { (int32)sizeof(kDeviceIcon), (void *)kDeviceIcon };
device_icon kCDIconData = { (int32)sizeof(kCDIcon), (void *)kCDIcon };
device_icon kMSIconData = { (int32)sizeof(kMemoryStickIcon),
(void *)kMemoryStickIcon };
device_icon kSDIconData = { (int32)sizeof(kSDIcon), (void *)kSDIcon };
device_icon kMobileIconData = { (int32)sizeof(kMobileIcon),
(void *)kMobileIcon };


struct {
const char *vendor;
const char *product;
device_icon *icon;
const char *name;
Expand All @@ -303,11 +357,14 @@ struct {
// vendor: "Transcend Information, Inc."
// product: "63-in-1 Multi-Card Reader/Writer" ver. 0100
// which report things like "Generic " "USB CF Reader "
// { " CF Reader", &kCFIconData, "devices/drive-removable-media-flash" },
{ " SD Reader", &kSDIconData, "devices/drive-removable-media-flash" },
{ " MS Reader", &kMSIconData, "devices/drive-removable-media-flash" },
// { " SM Reader", &kSMIconData, "devices/drive-removable-media-flash" },
{ NULL, NULL }
// { NULL, " CF Reader", &kCFIconData, "devices/drive-removable-media-flash" },
{ NULL, " SD Reader", &kSDIconData, "devices/drive-removable-media-flash" },
{ NULL, " MS Reader", &kMSIconData, "devices/drive-removable-media-flash" },
// { NULL, " SM Reader", &kSMIconData, "devices/drive-removable-media-flash" },
// match for my Kazam mobile phone
// stupid thing says "MEDIATEK" " FLASH DISK " even for internal memory
{ "MEDIATEK", NULL, &kMobileIconData, "devices/drive-removable-media-flash" },
{ NULL, NULL, NULL, NULL }
};


Expand Down Expand Up @@ -1353,6 +1410,7 @@ usb_disk_ioctl(void *cookie, uint32 op, void *buffer, size_t length)
case B_GET_ICON_NAME:
{
const char *iconName = "devices/drive-removable-media-usb";
char vendor[sizeof(lun->vendor_name)+1];
char product[sizeof(lun->product_name)+1];

switch (lun->device_type) {
Expand All @@ -1362,10 +1420,16 @@ usb_disk_ioctl(void *cookie, uint32 op, void *buffer, size_t length)
break;
case B_TAPE: // TODO
default:
snprintf(vendor, sizeof(vendor), "%.8s",
lun->vendor_name);
snprintf(product, sizeof(product), "%.16s",
lun->product_name);
for (int i = 0; kIconMatches[i].product; i++) {
if (strstr(product, kIconMatches[i].product) == NULL)
for (int i = 0; kIconMatches[i].icon; i++) {
if (kIconMatches[i].vendor != NULL
&& strstr(vendor, kIconMatches[i].vendor) == NULL)
continue;
if (kIconMatches[i].product != NULL
&& strstr(product, kIconMatches[i].product) == NULL)
continue;
iconName = kIconMatches[i].name;
}
Expand All @@ -1379,6 +1443,7 @@ usb_disk_ioctl(void *cookie, uint32 op, void *buffer, size_t length)
case B_GET_VECTOR_ICON:
{
device_icon *icon = &kKeyIconData;
char vendor[sizeof(lun->vendor_name)+1];
char product[sizeof(lun->product_name)+1];

if (length != sizeof(device_icon)) {
Expand All @@ -1393,10 +1458,16 @@ usb_disk_ioctl(void *cookie, uint32 op, void *buffer, size_t length)
break;
case B_TAPE: // TODO
default:
snprintf(vendor, sizeof(vendor), "%.8s",
lun->vendor_name);
snprintf(product, sizeof(product), "%.16s",
lun->product_name);
for (int i = 0; kIconMatches[i].product; i++) {
if (strstr(product, kIconMatches[i].product) == NULL)
for (int i = 0; kIconMatches[i].icon; i++) {
if (kIconMatches[i].vendor != NULL
&& strstr(vendor, kIconMatches[i].vendor) == NULL)
continue;
if (kIconMatches[i].product != NULL
&& strstr(product, kIconMatches[i].product) == NULL)
continue;
icon = kIconMatches[i].icon;
}
Expand Down

0 comments on commit e3c95b5

Please sign in to comment.