• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2024 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.server.storage;
18 
19 import android.annotation.NonNull;
20 import android.annotation.Nullable;
21 import android.content.Context;
22 import android.os.storage.DiskInfo;
23 import android.os.storage.StorageVolume;
24 import android.os.storage.VolumeInfo;
25 
26 import com.android.internal.util.IndentingPrintWriter;
27 import com.android.server.utils.Watchable;
28 import com.android.server.utils.WatchableImpl;
29 
30 import java.io.File;
31 
32 /**
33  * A wrapper for {@link VolumeInfo}  implementing the {@link Watchable} interface.
34  *
35  * The {@link VolumeInfo} class itself cannot safely implement Watchable, because it has several
36  * UnsupportedAppUsage annotations and public fields, which allow it to be modified without
37  * notifying watchers.
38  *
39  * @hide
40  */
41 public class WatchedVolumeInfo extends WatchableImpl {
42     private final VolumeInfo mVolumeInfo;
43 
WatchedVolumeInfo(VolumeInfo volumeInfo)44     private WatchedVolumeInfo(VolumeInfo volumeInfo) {
45         mVolumeInfo = volumeInfo;
46     }
47 
WatchedVolumeInfo(WatchedVolumeInfo watchedVolumeInfo)48     public WatchedVolumeInfo(WatchedVolumeInfo watchedVolumeInfo) {
49         mVolumeInfo = new VolumeInfo(watchedVolumeInfo.mVolumeInfo);
50     }
51 
fromVolumeInfo(VolumeInfo info)52     public static WatchedVolumeInfo fromVolumeInfo(VolumeInfo info) {
53         return new WatchedVolumeInfo(info);
54     }
55 
56     /**
57      * Returns a copy of the embedded VolumeInfo object, to be used by components
58      * that just need it for retrieving some state from it.
59      *
60      * @return A copy of the embedded VolumeInfo object
61      */
62 
clone()63     public WatchedVolumeInfo clone() {
64         return fromVolumeInfo(mVolumeInfo.clone());
65     }
66 
getImmutableVolumeInfo()67     public ImmutableVolumeInfo getImmutableVolumeInfo() {
68         return ImmutableVolumeInfo.fromVolumeInfo(mVolumeInfo);
69     }
70 
getClonedImmutableVolumeInfo()71     public ImmutableVolumeInfo getClonedImmutableVolumeInfo() {
72         return ImmutableVolumeInfo.fromVolumeInfo(mVolumeInfo.clone());
73     }
74 
buildStorageVolume(Context context, int userId, boolean reportUnmounted)75     public StorageVolume buildStorageVolume(Context context, int userId, boolean reportUnmounted) {
76         return mVolumeInfo.buildStorageVolume(context, userId, reportUnmounted);
77     }
78 
dump(IndentingPrintWriter pw)79     public void dump(IndentingPrintWriter pw) {
80         mVolumeInfo.dump(pw);
81     }
82 
getDisk()83     public DiskInfo getDisk() {
84         return mVolumeInfo.getDisk();
85     }
86 
getDiskId()87     public String getDiskId() {
88         return mVolumeInfo.getDiskId();
89     }
90 
getFsLabel()91     public String getFsLabel() {
92         return mVolumeInfo.fsLabel;
93     }
94 
setFsLabel(String fsLabel)95     public void setFsLabel(String fsLabel) {
96         mVolumeInfo.fsLabel = fsLabel;
97         dispatchChange(this);
98     }
99 
getFsPath()100     public String getFsPath() {
101         return mVolumeInfo.path;
102     }
103 
setFsPath(String path)104     public void setFsPath(String path) {
105         mVolumeInfo.path = path;
106         dispatchChange(this);
107     }
108 
getFsType()109     public String getFsType() {
110         return mVolumeInfo.fsType;
111     }
112 
setFsType(String fsType)113     public void setFsType(String fsType) {
114         mVolumeInfo.fsType = fsType;
115         dispatchChange(this);
116     }
117 
getFsUuid()118     public @Nullable String getFsUuid() {
119         return mVolumeInfo.fsUuid;
120     }
121 
setFsUuid(String fsUuid)122     public void setFsUuid(String fsUuid) {
123         mVolumeInfo.fsUuid = fsUuid;
124         dispatchChange(this);
125     }
126 
getId()127     public @NonNull String getId() {
128         return mVolumeInfo.id;
129     }
130 
getInternalPath()131     public File getInternalPath() {
132         return mVolumeInfo.getInternalPath();
133     }
134 
setInternalPath(String internalPath)135     public void setInternalPath(String internalPath) {
136         mVolumeInfo.internalPath = internalPath;
137         dispatchChange(this);
138     }
139 
getMountFlags()140     public int getMountFlags() {
141         return mVolumeInfo.mountFlags;
142     }
143 
setMountFlags(int mountFlags)144     public void setMountFlags(int mountFlags) {
145         mVolumeInfo.mountFlags = mountFlags;
146         dispatchChange(this);
147     }
148 
getMountUserId()149     public int getMountUserId() {
150         return mVolumeInfo.mountUserId;
151     }
152 
setMountUserId(int mountUserId)153     public void setMountUserId(int mountUserId) {
154         mVolumeInfo.mountUserId = mountUserId;
155         dispatchChange(this);
156     }
157 
getPartGuid()158     public String getPartGuid() {
159         return mVolumeInfo.partGuid;
160     }
161 
getPath()162     public File getPath() {
163         return mVolumeInfo.getPath();
164     }
165 
getState()166     public int getState() {
167         return mVolumeInfo.state;
168     }
169 
getState(int state)170     public int getState(int state) {
171         return mVolumeInfo.state;
172     }
173 
setState(int state)174     public void setState(int state) {
175         mVolumeInfo.state = state;
176         dispatchChange(this);
177     }
178 
getType()179     public int getType() {
180         return mVolumeInfo.type;
181     }
182 
getVolumeInfo()183     public VolumeInfo getVolumeInfo() {
184         return new VolumeInfo(mVolumeInfo);
185     }
186 
isMountedReadable()187     public boolean isMountedReadable() {
188         return mVolumeInfo.isMountedReadable();
189     }
190 
isMountedWritable()191     public boolean isMountedWritable() {
192         return mVolumeInfo.isMountedWritable();
193     }
194 
isPrimary()195     public boolean isPrimary() {
196         return mVolumeInfo.isPrimary();
197     }
198 
isVisible()199     public boolean isVisible() {
200         return mVolumeInfo.isVisible();
201     }
202 
isVisibleForUser(int userId)203     public boolean isVisibleForUser(int userId) {
204         return mVolumeInfo.isVisibleForUser(userId);
205     }
206 
isVisibleForWrite(int userId)207     public boolean isVisibleForWrite(int userId) {
208         return mVolumeInfo.isVisibleForWrite(userId);
209     }
210 
211     @Override
toString()212     public String toString() {
213         return mVolumeInfo.toString();
214     }
215 }