1 /*
2 **
3 ** Copyright 2008, 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 */
17
18 #include <fcntl.h>
19 #include <sys/prctl.h>
20 #include <sys/wait.h>
21 #include <binder/IPCThreadState.h>
22 #include <binder/ProcessState.h>
23 #include <binder/IServiceManager.h>
24
25 #include <string>
26
27 #include <android-base/logging.h>
28 #include <android-base/properties.h>
29 #include <utils/misc.h>
30
31 // from LOCAL_C_INCLUDES
32 #include "IcuUtils.h"
33 #include "MediaExtractorService.h"
34 #include "MediaExtractorUpdateService.h"
35 #include "MediaUtils.h"
36 #include "minijail.h"
37
38 using namespace android;
39
40 static const char kSystemSeccompPolicyPath[] =
41 "/system/etc/seccomp_policy/mediaextractor.policy";
42 static const char kVendorSeccompPolicyPath[] =
43 "/vendor/etc/seccomp_policy/mediaextractor.policy";
44
main(int argc __unused,char ** argv)45 int main(int argc __unused, char** argv)
46 {
47 limitProcessMemory(
48 "ro.media.maxmem", /* property that defines limit */
49 SIZE_MAX, /* upper limit in bytes */
50 20 /* upper limit as percentage of physical RAM */);
51
52 signal(SIGPIPE, SIG_IGN);
53
54 //b/62255959: this forces libutis.so to dlopen vendor version of libutils.so
55 //before minijail is on. This is dirty but required since some syscalls such
56 //as pread64 are used by linker but aren't allowed in the minijail. By
57 //calling the function before entering minijail, we can force dlopen.
58 android::report_sysprop_change();
59
60 SetUpMinijail(kSystemSeccompPolicyPath, kVendorSeccompPolicyPath);
61
62 InitializeIcuOrDie();
63
64 strcpy(argv[0], "media.extractor");
65 sp<ProcessState> proc(ProcessState::self());
66 sp<IServiceManager> sm = defaultServiceManager();
67 MediaExtractorService::instantiate();
68
69 std::string value = base::GetProperty("ro.build.type", "unknown");
70 if (value == "userdebug" || value == "eng") {
71 media::MediaExtractorUpdateService::instantiate();
72 }
73
74 ProcessState::self()->startThreadPool();
75 IPCThreadState::self()->joinThreadPool();
76 }
77