1/*
2 * Copyright (C) 2016 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#ifndef _ANDROID_OS_DROPBOXMANAGER_H
18#define _ANDROID_OS_DROPBOXMANAGER_H
19
20#include <android-base/unique_fd.h>
21#include <binder/Parcel.h>
22#include <binder/Parcelable.h>
23#include <binder/Status.h>
24#include <utils/RefBase.h>
25
26#include <vector>
27
28namespace android {
29namespace os {
30
31using namespace android;
32using namespace android::base;
33using namespace android::binder;
34using namespace std;
35
36class DropBoxManager : public virtual RefBase
37{
38public:
39    enum {
40        IS_EMPTY = 1,
41        IS_TEXT = 2,
42        IS_GZIPPED = 4
43    };
44
45    DropBoxManager();
46    virtual ~DropBoxManager();
47
48    static sp<DropBoxManager> create();
49
50    // Create a new entry with plain text contents.
51    Status addText(const String16& tag, const string& text);
52
53    // Create a new Entry with byte array contents. Makes a copy of the data.
54    Status addData(const String16& tag, uint8_t const* data, size_t size, int flags);
55
56    // Create a new Entry from a file. The file will be opened in this process
57    // and a handle will be passed to the system process, so no additional permissions
58    // are required from the system process.  Returns NULL if the file can't be opened.
59    Status addFile(const String16& tag, const string& filename, int flags);
60
61    class Entry : public virtual RefBase, public Parcelable {
62    public:
63        Entry();
64        virtual ~Entry();
65
66        virtual status_t writeToParcel(Parcel* out) const;
67        virtual status_t readFromParcel(const Parcel* in);
68
69    private:
70        Entry(const String16& tag, int32_t flags);
71        Entry(const String16& tag, int32_t flags, int fd);
72
73        String16 mTag;
74        int64_t mTimeMillis;
75        int32_t mFlags;
76
77        vector<uint8_t> mData;
78        unique_fd mFd;
79
80        friend class DropBoxManager;
81    };
82
83private:
84    enum {
85        HAS_BYTE_ARRAY = 8
86    };
87
88    Status add(const Entry& entry);
89};
90
91}} // namespace android::os
92
93#endif // _ANDROID_OS_DROPBOXMANAGER_H
94
95