blob: 1661f0443d7e2e28b668719f48ff1617ee6b630f [file] [log] [blame]
Andreas Huber413f5232009-12-03 11:31:19 -08001/*
2 * Copyright (C) 2009 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
Marco Nelissen544ad2b2013-11-13 14:18:21 -080017//#define LOG_NDEBUG 0
18#define LOG_TAG "MediaScannerClient"
19#include <utils/Log.h>
20
Andreas Huber413f5232009-12-03 11:31:19 -080021#include <media/mediascanner.h>
22
Marco Nelissen544ad2b2013-11-13 14:18:21 -080023#include "CharacterEncodingDetector.h"
Mathias Agopian1f7d3562013-05-06 20:20:16 -070024#include "StringArray.h"
Andreas Huber413f5232009-12-03 11:31:19 -080025
Andreas Huber413f5232009-12-03 11:31:19 -080026namespace android {
27
28MediaScannerClient::MediaScannerClient()
Marco Nelissen544ad2b2013-11-13 14:18:21 -080029 : mEncodingDetector(NULL)
Andreas Huber413f5232009-12-03 11:31:19 -080030{
31}
32
33MediaScannerClient::~MediaScannerClient()
34{
Marco Nelissen544ad2b2013-11-13 14:18:21 -080035 delete mEncodingDetector;
Andreas Huber413f5232009-12-03 11:31:19 -080036}
37
38void MediaScannerClient::setLocale(const char* locale)
39{
Marco Nelissen544ad2b2013-11-13 14:18:21 -080040 mLocale = locale; // not currently used
Andreas Huber413f5232009-12-03 11:31:19 -080041}
42
43void MediaScannerClient::beginFile()
44{
Marco Nelissen544ad2b2013-11-13 14:18:21 -080045 delete mEncodingDetector;
46 mEncodingDetector = new CharacterEncodingDetector();
Andreas Huber413f5232009-12-03 11:31:19 -080047}
48
Jeff Brown7188e552011-07-20 16:38:43 -070049status_t MediaScannerClient::addStringTag(const char* name, const char* value)
Andreas Huber413f5232009-12-03 11:31:19 -080050{
Marco Nelissen544ad2b2013-11-13 14:18:21 -080051 mEncodingDetector->addTag(name, value);
52 return OK;
Andreas Huber413f5232009-12-03 11:31:19 -080053}
54
55void MediaScannerClient::endFile()
56{
Marco Nelissen544ad2b2013-11-13 14:18:21 -080057 mEncodingDetector->detectAndConvert();
Andreas Huber413f5232009-12-03 11:31:19 -080058
Marco Nelissen544ad2b2013-11-13 14:18:21 -080059 int size = mEncodingDetector->size();
60 if (size) {
61 for (int i = 0; i < size; i++) {
62 const char *name;
63 const char *value;
64 mEncodingDetector->getTag(i, &name, &value);
65 handleStringTag(name, value);
Marco Nelissenb5c31072010-03-11 13:37:46 -080066 }
Andreas Huber413f5232009-12-03 11:31:19 -080067 }
Andreas Huber413f5232009-12-03 11:31:19 -080068}
69
70} // namespace android