• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 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 package com.android.providers.media;
18 
19 import android.database.Cursor;
20 
21 /**
22  * Class to represent the file metadata stored in the database (SQLite/xAttr)
23  */
24 public final class FileAccessAttributes {
25     private final long mId;
26     private final int mMediaType;
27     private final boolean mIsPending;
28     private final boolean mIsTrashed;
29     // TODO(b/227348809): Remove ownerId field when we add the logic to check ownerId from xattr
30     private final int mOwnerId;
31     private final String mOwnerPackageName;
32 
FileAccessAttributes(long id, int mediaType, boolean isPending, boolean isTrashed, int ownerId, String ownerPackageName)33     public FileAccessAttributes(long id, int mediaType, boolean isPending,
34             boolean isTrashed, int ownerId, String ownerPackageName) {
35         this.mId = id;
36         this.mMediaType = mediaType;
37         this.mIsPending = isPending;
38         this.mIsTrashed = isTrashed;
39         this.mOwnerId = ownerId;
40         this.mOwnerPackageName = ownerPackageName;
41     }
42 
fromCursor(Cursor c)43     public static FileAccessAttributes fromCursor(Cursor c) {
44         final long id  = c.getLong(0);
45         String ownerPackageName = c.getString(1);
46         final boolean isPending = c.getInt(2) != 0;
47         final int mediaType = c.getInt(3);
48         final boolean isTrashed = c.getInt(4) != 0;
49         return new FileAccessAttributes(id, mediaType, isPending, isTrashed, -1,
50                 ownerPackageName);
51     }
52 
toString()53     public String toString() {
54         return String.format("Id: %s, Mediatype: %s, isPending: %s, "
55                         + "isTrashed: %s, ownerpackageName: %s", this.mId, this.mMediaType,
56                 mIsPending, mIsTrashed, mOwnerId);
57     }
58 
getId()59     public long getId() {
60         return this.mId;
61     }
62 
getMediaType()63     public int getMediaType() {
64         return this.mMediaType;
65     }
66 
getOwnerId()67     public int getOwnerId() {
68         return this.mOwnerId;
69     }
70 
isTrashed()71     public boolean isTrashed() {
72         return this.mIsTrashed;
73     }
74 
isPending()75     public boolean isPending() {
76         return this.mIsPending;
77     }
78 
getOwnerPackageName()79     public String getOwnerPackageName() {
80         return this.mOwnerPackageName;
81     }
82 }
83