1#!/usr/bin/env python 2 3# Copyright (C) 2017 The Android Open Source Project 4# 5# Licensed under the Apache License, Version 2.0 (the 'License'); 6# you may not use this file except in compliance with the License. 7# You may obtain a copy of the License at 8# 9# http://www.apache.org/licenses/LICENSE-2.0 10# 11# Unless required by applicable law or agreed to in writing, software 12# distributed under the License is distributed on an 'AS IS' BASIS, 13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14# See the License for the specific language governing permissions and 15# limitations under the License. 16 17import collections, sys 18 19TYPES = { 20 "AID_MEDIA_AUDIO": ["aac","aac","amr","awb","snd","flac","flac","mp3","mpga","mpega","mp2","m4a","aif","aiff","aifc","gsm","mka","m3u","wma","wax","ra","rm","ram","ra","pls","sd2","wav","ogg","oga"], 21 "AID_MEDIA_VIDEO": ["3gpp","3gp","3gpp2","3g2","avi","dl","dif","dv","fli","m4v","ts","mpeg","mpg","mpe","mp4","vob","qt","mov","mxu","webm","lsf","lsx","mkv","mng","asf","asx","wm","wmv","wmx","wvx","movie","wrf"], 22 "AID_MEDIA_IMAGE": ["bmp","gif","jpg","jpeg","jpe","pcx","png","svg","svgz","tiff","tif","wbmp","webp","dng","cr2","ras","art","jng","nef","nrw","orf","rw2","pef","psd","pnm","pbm","pgm","ppm","srw","arw","rgb","xbm","xpm","xwd"] 23} 24 25if "--rc" in sys.argv: 26 print "on early-boot" 27 print " mkdir /config/sdcardfs/extensions/1055" 28 print " mkdir /config/sdcardfs/extensions/1056" 29 print " mkdir /config/sdcardfs/extensions/1057" 30 for gid, exts in TYPES.iteritems(): 31 if gid is "AID_MEDIA_AUDIO": gid = "1055" 32 if gid is "AID_MEDIA_VIDEO": gid = "1056" 33 if gid is "AID_MEDIA_IMAGE": gid = "1057" 34 for ext in exts: 35 print " mkdir /config/sdcardfs/extensions/%s/%s" % (gid, ext) 36 exit() 37 38print """/* 39 * Copyright (C) 2017 The Android Open Source Project 40 * 41 * Licensed under the Apache License, Version 2.0 (the "License"); 42 * you may not use this file except in compliance with the License. 43 * You may obtain a copy of the License at 44 * 45 * http://www.apache.org/licenses/LICENSE-2.0 46 * 47 * Unless required by applicable law or agreed to in writing, software 48 * distributed under the License is distributed on an "AS IS" BASIS, 49 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 50 * See the License for the specific language governing permissions and 51 * limitations under the License. 52 */ 53 54/****************************************************************** 55 * THIS CODE WAS GENERATED BY matchgen.py, DO NOT MODIFY DIRECTLY * 56 ******************************************************************/ 57 58#include <private/android_filesystem_config.h> 59 60int MatchExtension(const char* ext) { 61""" 62 63trie = collections.defaultdict(lambda: collections.defaultdict(lambda: collections.defaultdict(lambda: collections.defaultdict(lambda: collections.defaultdict(lambda: collections.defaultdict(lambda: "")))))) 64 65for t in TYPES: 66 for v in TYPES[t]: 67 v = v.lower() 68 target = trie 69 for c in v: 70 target = target[c] 71 target["\0"] = t 72 73def dump(target, index): 74 prefix = " " * (index + 1) 75 print "%sswitch (ext[%d]) {" % (prefix, index) 76 for k in sorted(target.keys()): 77 if k == "\0": 78 print "%scase '\\0': return %s;" % (prefix, target[k]) 79 else: 80 upper = k.upper() 81 if k != upper: 82 print "%scase '%s': case '%s':" % (prefix, k, upper) 83 else: 84 print "%scase '%s':" % (prefix, k) 85 dump(target[k], index + 1) 86 print "%s}" % (prefix) 87 if index > 0: 88 print "%sbreak;" % (prefix) 89 90dump(trie, 0) 91 92print """ 93 return 0; 94} 95""" 96