summaryrefslogtreecommitdiff
path: root/libs/services/include/android/os/DropBoxManager.h
blob: 75b26c626d149e9cc9166c28b81d920c1258ce18 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/*
 * Copyright (C) 2016 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef _ANDROID_OS_DROPBOXMANAGER_H
#define _ANDROID_OS_DROPBOXMANAGER_H

#include <android-base/unique_fd.h>
#include <binder/Parcel.h>
#include <binder/Parcelable.h>
#include <binder/Status.h>
#include <utils/RefBase.h>

#include <vector>

namespace android {
namespace os {

using namespace android;
using namespace android::base;
using namespace android::binder;
using namespace std;

class DropBoxManager : public virtual RefBase
{
public:
    enum {
        IS_EMPTY = 1,
        IS_TEXT = 2,
        IS_GZIPPED = 4
    };

    DropBoxManager();
    virtual ~DropBoxManager();

    static sp<DropBoxManager> create();

    // Create a new entry with plain text contents.
    Status addText(const String16& tag, const string& text);

    // Create a new Entry with byte array contents. Makes a copy of the data.
    Status addData(const String16& tag, uint8_t const* data, size_t size, int flags);

    // Create a new Entry from a file. The file will be opened in this process
    // and a handle will be passed to the system process, so no additional permissions
    // are required from the system process.  Returns NULL if the file can't be opened.
    Status addFile(const String16& tag, const string& filename, int flags);

    // Create a new Entry from an already opened file. Takes ownership of the
    // file descriptor.
    Status addFile(const String16& tag, int fd, int flags);

    class Entry : public virtual RefBase, public Parcelable {
    public:
        Entry();
        virtual ~Entry();

        virtual status_t writeToParcel(Parcel* out) const;
        virtual status_t readFromParcel(const Parcel* in);

        const vector<uint8_t>& getData() const;
        const unique_fd& getFd() const;
        int32_t getFlags() const;
        int64_t getTimestamp() const;

    private:
        Entry(const String16& tag, int32_t flags);
        Entry(const String16& tag, int32_t flags, int fd);

        String16 mTag;
        int64_t mTimeMillis;
        int32_t mFlags;

        vector<uint8_t> mData;
        unique_fd mFd;

        friend class DropBoxManager;
    };

    // Get the next entry from the drop box after the specified time.
    Status getNextEntry(const String16& tag, long msec, Entry* entry);

private:
    enum {
        HAS_BYTE_ARRAY = 8
    };

    Status add(const Entry& entry);
};

}} // namespace android::os

#endif // _ANDROID_OS_DROPBOXMANAGER_H