• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 //#define LOG_NDEBUG 0
18 #define LOG_TAG "MediaCasService"
19 
20 #include <binder/IServiceManager.h>
21 #include <media/cas/CasAPI.h>
22 #include <media/cas/DescramblerAPI.h>
23 #include <media/CasImpl.h>
24 #include <media/DescramblerImpl.h>
25 #include <utils/Log.h>
26 #include <utils/List.h>
27 #include "MediaCasService.h"
28 #include <android/media/ICasListener.h>
29 
30 namespace android {
31 
32 //static
instantiate()33 void MediaCasService::instantiate() {
34     defaultServiceManager()->addService(
35             String16("media.cas"), new MediaCasService());
36 }
37 
MediaCasService()38 MediaCasService::MediaCasService() :
39     mCasLoader(new FactoryLoader<CasFactory>("createCasFactory")),
40     mDescramblerLoader(new FactoryLoader<DescramblerFactory>(
41             "createDescramblerFactory")) {
42 }
43 
~MediaCasService()44 MediaCasService::~MediaCasService() {
45     delete mCasLoader;
46     delete mDescramblerLoader;
47 }
48 
enumeratePlugins(vector<ParcelableCasPluginDescriptor> * results)49 Status MediaCasService::enumeratePlugins(
50         vector<ParcelableCasPluginDescriptor>* results) {
51     ALOGV("enumeratePlugins");
52 
53     mCasLoader->enumeratePlugins(results);
54 
55     return Status::ok();
56 }
57 
isSystemIdSupported(int32_t CA_system_id,bool * result)58 Status MediaCasService::isSystemIdSupported(
59         int32_t CA_system_id, bool* result) {
60     ALOGV("isSystemIdSupported: CA_system_id=%d", CA_system_id);
61 
62     *result = mCasLoader->findFactoryForScheme(CA_system_id);
63 
64     return Status::ok();
65 }
66 
createPlugin(int32_t CA_system_id,const sp<ICasListener> & listener,sp<ICas> * result)67 Status MediaCasService::createPlugin(
68         int32_t CA_system_id,
69         const sp<ICasListener> &listener,
70         sp<ICas>* result) {
71     ALOGV("createPlugin: CA_system_id=%d", CA_system_id);
72 
73     result->clear();
74 
75     CasFactory *factory;
76     sp<SharedLibrary> library;
77     if (mCasLoader->findFactoryForScheme(CA_system_id, &library, &factory)) {
78         CasPlugin *plugin = NULL;
79         sp<CasImpl> casImpl = new CasImpl(listener);
80         if (factory->createPlugin(CA_system_id, (uint64_t)casImpl.get(),
81                 &CasImpl::OnEvent, &plugin) == OK && plugin != NULL) {
82             casImpl->init(library, plugin);
83             *result = casImpl;
84         }
85     }
86 
87     return Status::ok();
88 }
89 
isDescramblerSupported(int32_t CA_system_id,bool * result)90 Status MediaCasService::isDescramblerSupported(
91         int32_t CA_system_id, bool* result) {
92     ALOGV("isDescramblerSupported: CA_system_id=%d", CA_system_id);
93 
94     *result = mDescramblerLoader->findFactoryForScheme(CA_system_id);
95 
96     return Status::ok();
97 }
98 
createDescrambler(int32_t CA_system_id,sp<IDescrambler> * result)99 Status MediaCasService::createDescrambler(
100         int32_t CA_system_id, sp<IDescrambler>* result) {
101     ALOGV("createDescrambler: CA_system_id=%d", CA_system_id);
102 
103     result->clear();
104 
105     DescramblerFactory *factory;
106     sp<SharedLibrary> library;
107     if (mDescramblerLoader->findFactoryForScheme(
108             CA_system_id, &library, &factory)) {
109         DescramblerPlugin *plugin = NULL;
110         if (factory->createPlugin(CA_system_id, &plugin) == OK
111                 && plugin != NULL) {
112             *result = new DescramblerImpl(library, plugin);
113         }
114     }
115 
116     return Status::ok();
117 }
118 
119 } // namespace android
120