blob: 1e071aa3f5dc38de6ffd1d6f5150c40006d8ab6f [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2006 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
17package com.android.server.am;
18
Felipe Leme23a0c7a2018-01-24 08:43:34 -080019import android.app.GrantedUriPermission;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080020import android.content.Intent;
Jeff Sharkey69062202017-06-26 19:34:04 -060021import android.os.Binder;
Jeff Sharkey328ebf22013-03-21 18:09:39 -070022import android.os.UserHandle;
Jeff Sharkey846318a2014-04-04 12:12:41 -070023import android.util.ArraySet;
Jeff Sharkeyd16b1252016-09-01 11:07:23 -060024import android.util.Log;
Jeff Sharkey846318a2014-04-04 12:12:41 -070025import android.util.Slog;
Jeff Sharkey328ebf22013-03-21 18:09:39 -070026
Jeff Sharkey846318a2014-04-04 12:12:41 -070027import com.android.server.am.ActivityManagerService.GrantUri;
Jeff Sharkey328ebf22013-03-21 18:09:39 -070028import com.google.android.collect.Sets;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080029
30import java.io.PrintWriter;
Jeff Sharkeye66c1772013-09-20 14:30:59 -070031import java.util.Comparator;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080032
Dianne Hackborn7e269642010-08-25 19:50:20 -070033/**
34 * Description of a permission granted to an app to access a particular URI.
35 *
36 * CTS tests for this functionality can be run with "runtest cts-appsecurity".
37 *
Dianne Hackborncca1f0e2010-09-26 18:34:53 -070038 * Test cases are at cts/tests/appsecurity-tests/test-apps/UsePermissionDiffCert/
39 * src/com/android/cts/usespermissiondiffcertapp/AccessPermissionWithDiffSigTest.java
Dianne Hackborn7e269642010-08-25 19:50:20 -070040 */
Dianne Hackbornbe4e6aa2013-06-07 13:25:29 -070041final class UriPermission {
Jeff Sharkey328ebf22013-03-21 18:09:39 -070042 private static final String TAG = "UriPermission";
43
Jeff Sharkeye66c1772013-09-20 14:30:59 -070044 public static final int STRENGTH_NONE = 0;
45 public static final int STRENGTH_OWNED = 1;
46 public static final int STRENGTH_GLOBAL = 2;
47 public static final int STRENGTH_PERSISTABLE = 3;
48
Nicolas Prevotd85fc722014-04-16 19:52:08 +010049 final int targetUserId;
Jeff Sharkey328ebf22013-03-21 18:09:39 -070050 final String sourcePkg;
51 final String targetPkg;
52
53 /** Cached UID of {@link #targetPkg}; should not be persisted */
54 final int targetUid;
55
Jeff Sharkey846318a2014-04-04 12:12:41 -070056 final GrantUri uri;
Jeff Sharkey328ebf22013-03-21 18:09:39 -070057
58 /**
59 * Allowed modes. All permission enforcement should use this field. Must
Jeff Sharkeye66c1772013-09-20 14:30:59 -070060 * always be a combination of {@link #ownedModeFlags},
61 * {@link #globalModeFlags}, {@link #persistableModeFlags}, and
62 * {@link #persistedModeFlags}. Mutations <em>must</em> only be performed by
63 * the owning class.
Jeff Sharkey328ebf22013-03-21 18:09:39 -070064 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080065 int modeFlags = 0;
Jeff Sharkey328ebf22013-03-21 18:09:39 -070066
Jeff Sharkey846318a2014-04-04 12:12:41 -070067 /** Allowed modes with active owner. */
Jeff Sharkeye66c1772013-09-20 14:30:59 -070068 int ownedModeFlags = 0;
69 /** Allowed modes without explicit owner. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080070 int globalModeFlags = 0;
Jeff Sharkeye66c1772013-09-20 14:30:59 -070071 /** Allowed modes that have been offered for possible persisting. */
72 int persistableModeFlags = 0;
Jeff Sharkey846318a2014-04-04 12:12:41 -070073
Jeff Sharkeye66c1772013-09-20 14:30:59 -070074 /** Allowed modes that should be persisted across device boots. */
75 int persistedModeFlags = 0;
Jeff Sharkey328ebf22013-03-21 18:09:39 -070076
77 /**
Jeff Sharkeye66c1772013-09-20 14:30:59 -070078 * Timestamp when {@link #persistedModeFlags} was first defined in
79 * {@link System#currentTimeMillis()} time base.
Jeff Sharkey328ebf22013-03-21 18:09:39 -070080 */
Jeff Sharkeye66c1772013-09-20 14:30:59 -070081 long persistedCreateTime = INVALID_TIME;
82
83 private static final long INVALID_TIME = Long.MIN_VALUE;
Jeff Sharkey328ebf22013-03-21 18:09:39 -070084
Jeff Sharkey846318a2014-04-04 12:12:41 -070085 private ArraySet<UriPermissionOwner> mReadOwners;
86 private ArraySet<UriPermissionOwner> mWriteOwners;
Jeff Sharkey328ebf22013-03-21 18:09:39 -070087
88 private String stringName;
89
Jeff Sharkey846318a2014-04-04 12:12:41 -070090 UriPermission(String sourcePkg, String targetPkg, int targetUid, GrantUri uri) {
Nicolas Prevotd85fc722014-04-16 19:52:08 +010091 this.targetUserId = UserHandle.getUserId(targetUid);
Jeff Sharkey328ebf22013-03-21 18:09:39 -070092 this.sourcePkg = sourcePkg;
93 this.targetPkg = targetPkg;
94 this.targetUid = targetUid;
95 this.uri = uri;
96 }
97
Jeff Sharkeye66c1772013-09-20 14:30:59 -070098 private void updateModeFlags() {
Jeff Sharkeyd16b1252016-09-01 11:07:23 -060099 final int oldModeFlags = modeFlags;
Jeff Sharkeye66c1772013-09-20 14:30:59 -0700100 modeFlags = ownedModeFlags | globalModeFlags | persistableModeFlags | persistedModeFlags;
Jeff Sharkeyd16b1252016-09-01 11:07:23 -0600101
102 if (Log.isLoggable(TAG, Log.VERBOSE) && (modeFlags != oldModeFlags)) {
103 Slog.d(TAG,
104 "Permission for " + targetPkg + " to " + uri + " is changing from 0x"
105 + Integer.toHexString(oldModeFlags) + " to 0x"
Jeff Sharkey69062202017-06-26 19:34:04 -0600106 + Integer.toHexString(modeFlags) + " via calling UID "
107 + Binder.getCallingUid() + " PID " + Binder.getCallingPid(),
Jeff Sharkeyd16b1252016-09-01 11:07:23 -0600108 new Throwable());
109 }
Jeff Sharkeye66c1772013-09-20 14:30:59 -0700110 }
111
Jeff Sharkey328ebf22013-03-21 18:09:39 -0700112 /**
Jeff Sharkeye66c1772013-09-20 14:30:59 -0700113 * Initialize persisted modes as read from file. This doesn't issue any
114 * global or owner grants.
Jeff Sharkey328ebf22013-03-21 18:09:39 -0700115 */
Jeff Sharkeye66c1772013-09-20 14:30:59 -0700116 void initPersistedModes(int modeFlags, long createdTime) {
Jeff Sharkey846318a2014-04-04 12:12:41 -0700117 modeFlags &= (Intent.FLAG_GRANT_READ_URI_PERMISSION
118 | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
119
Jeff Sharkeye66c1772013-09-20 14:30:59 -0700120 persistableModeFlags = modeFlags;
121 persistedModeFlags = modeFlags;
122 persistedCreateTime = createdTime;
Jeff Sharkey328ebf22013-03-21 18:09:39 -0700123
Jeff Sharkeye66c1772013-09-20 14:30:59 -0700124 updateModeFlags();
125 }
Jeff Sharkey328ebf22013-03-21 18:09:39 -0700126
Jeff Sharkey846318a2014-04-04 12:12:41 -0700127 void grantModes(int modeFlags, UriPermissionOwner owner) {
128 final boolean persistable = (modeFlags & Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION) != 0;
129 modeFlags &= (Intent.FLAG_GRANT_READ_URI_PERMISSION
130 | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
131
Jeff Sharkeye66c1772013-09-20 14:30:59 -0700132 if (persistable) {
133 persistableModeFlags |= modeFlags;
Jeff Sharkey328ebf22013-03-21 18:09:39 -0700134 }
135
136 if (owner == null) {
137 globalModeFlags |= modeFlags;
138 } else {
139 if ((modeFlags & Intent.FLAG_GRANT_READ_URI_PERMISSION) != 0) {
140 addReadOwner(owner);
Jeff Sharkey328ebf22013-03-21 18:09:39 -0700141 }
142 if ((modeFlags & Intent.FLAG_GRANT_WRITE_URI_PERMISSION) != 0) {
143 addWriteOwner(owner);
Jeff Sharkey328ebf22013-03-21 18:09:39 -0700144 }
145 }
146
Jeff Sharkeye66c1772013-09-20 14:30:59 -0700147 updateModeFlags();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800148 }
Jeff Sharkeye66c1772013-09-20 14:30:59 -0700149
Jeff Sharkey328ebf22013-03-21 18:09:39 -0700150 /**
Jeff Sharkeye66c1772013-09-20 14:30:59 -0700151 * @return if mode changes should trigger persisting.
Jeff Sharkey328ebf22013-03-21 18:09:39 -0700152 */
Jeff Sharkeye66c1772013-09-20 14:30:59 -0700153 boolean takePersistableModes(int modeFlags) {
Jeff Sharkey846318a2014-04-04 12:12:41 -0700154 modeFlags &= (Intent.FLAG_GRANT_READ_URI_PERMISSION
155 | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
156
Jeff Sharkey582f7122013-10-11 17:46:47 -0700157 if ((modeFlags & persistableModeFlags) != modeFlags) {
Jeff Sharkey846318a2014-04-04 12:12:41 -0700158 Slog.w(TAG, "Requested flags 0x"
Jeff Sharkey582f7122013-10-11 17:46:47 -0700159 + Integer.toHexString(modeFlags) + ", but only 0x"
160 + Integer.toHexString(persistableModeFlags) + " are allowed");
Jeff Sharkey846318a2014-04-04 12:12:41 -0700161 return false;
Jeff Sharkey582f7122013-10-11 17:46:47 -0700162 }
Jeff Sharkeye66c1772013-09-20 14:30:59 -0700163
164 final int before = persistedModeFlags;
165 persistedModeFlags |= (persistableModeFlags & modeFlags);
166
167 if (persistedModeFlags != 0) {
168 persistedCreateTime = System.currentTimeMillis();
169 }
170
171 updateModeFlags();
172 return persistedModeFlags != before;
173 }
174
175 boolean releasePersistableModes(int modeFlags) {
Jeff Sharkey846318a2014-04-04 12:12:41 -0700176 modeFlags &= (Intent.FLAG_GRANT_READ_URI_PERMISSION
177 | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
178
Jeff Sharkey328ebf22013-03-21 18:09:39 -0700179 final int before = persistedModeFlags;
180
Jeff Sharkeye66c1772013-09-20 14:30:59 -0700181 persistableModeFlags &= ~modeFlags;
182 persistedModeFlags &= ~modeFlags;
183
184 if (persistedModeFlags == 0) {
185 persistedCreateTime = INVALID_TIME;
186 }
187
188 updateModeFlags();
189 return persistedModeFlags != before;
190 }
191
192 /**
193 * @return if mode changes should trigger persisting.
194 */
Jeff Sharkey29b25162014-09-19 09:14:34 -0700195 boolean revokeModes(int modeFlags, boolean includingOwners) {
Jeff Sharkey846318a2014-04-04 12:12:41 -0700196 final boolean persistable = (modeFlags & Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION) != 0;
197 modeFlags &= (Intent.FLAG_GRANT_READ_URI_PERMISSION
198 | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
199
Jeff Sharkeye66c1772013-09-20 14:30:59 -0700200 final int before = persistedModeFlags;
201
202 if ((modeFlags & Intent.FLAG_GRANT_READ_URI_PERMISSION) != 0) {
203 if (persistable) {
204 persistableModeFlags &= ~Intent.FLAG_GRANT_READ_URI_PERMISSION;
Jeff Sharkey328ebf22013-03-21 18:09:39 -0700205 persistedModeFlags &= ~Intent.FLAG_GRANT_READ_URI_PERMISSION;
206 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800207 globalModeFlags &= ~Intent.FLAG_GRANT_READ_URI_PERMISSION;
Jeff Sharkey29b25162014-09-19 09:14:34 -0700208 if (mReadOwners != null && includingOwners) {
Jeff Sharkeye66c1772013-09-20 14:30:59 -0700209 ownedModeFlags &= ~Intent.FLAG_GRANT_READ_URI_PERMISSION;
Jeff Sharkey328ebf22013-03-21 18:09:39 -0700210 for (UriPermissionOwner r : mReadOwners) {
Dianne Hackborn39792d22010-08-19 18:01:52 -0700211 r.removeReadPermission(this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800212 }
Jeff Sharkey328ebf22013-03-21 18:09:39 -0700213 mReadOwners = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800214 }
215 }
Jeff Sharkeye66c1772013-09-20 14:30:59 -0700216 if ((modeFlags & Intent.FLAG_GRANT_WRITE_URI_PERMISSION) != 0) {
217 if (persistable) {
218 persistableModeFlags &= ~Intent.FLAG_GRANT_WRITE_URI_PERMISSION;
Jeff Sharkey328ebf22013-03-21 18:09:39 -0700219 persistedModeFlags &= ~Intent.FLAG_GRANT_WRITE_URI_PERMISSION;
220 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800221 globalModeFlags &= ~Intent.FLAG_GRANT_WRITE_URI_PERMISSION;
Jeff Sharkey29b25162014-09-19 09:14:34 -0700222 if (mWriteOwners != null && includingOwners) {
Jeff Sharkeye66c1772013-09-20 14:30:59 -0700223 ownedModeFlags &= ~Intent.FLAG_GRANT_WRITE_URI_PERMISSION;
Jeff Sharkey328ebf22013-03-21 18:09:39 -0700224 for (UriPermissionOwner r : mWriteOwners) {
Dianne Hackborn39792d22010-08-19 18:01:52 -0700225 r.removeWritePermission(this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800226 }
Jeff Sharkey328ebf22013-03-21 18:09:39 -0700227 mWriteOwners = null;
228 }
229 }
230
Jeff Sharkeye66c1772013-09-20 14:30:59 -0700231 if (persistedModeFlags == 0) {
232 persistedCreateTime = INVALID_TIME;
233 }
Jeff Sharkey328ebf22013-03-21 18:09:39 -0700234
Jeff Sharkeye66c1772013-09-20 14:30:59 -0700235 updateModeFlags();
Jeff Sharkey328ebf22013-03-21 18:09:39 -0700236 return persistedModeFlags != before;
237 }
238
Jeff Sharkeye66c1772013-09-20 14:30:59 -0700239 /**
240 * Return strength of this permission grant for the given flags.
241 */
242 public int getStrength(int modeFlags) {
Jeff Sharkey846318a2014-04-04 12:12:41 -0700243 modeFlags &= (Intent.FLAG_GRANT_READ_URI_PERMISSION
244 | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
Jeff Sharkeye66c1772013-09-20 14:30:59 -0700245 if ((persistableModeFlags & modeFlags) == modeFlags) {
246 return STRENGTH_PERSISTABLE;
247 } else if ((globalModeFlags & modeFlags) == modeFlags) {
248 return STRENGTH_GLOBAL;
249 } else if ((ownedModeFlags & modeFlags) == modeFlags) {
250 return STRENGTH_OWNED;
251 } else {
252 return STRENGTH_NONE;
253 }
254 }
255
Jeff Sharkey328ebf22013-03-21 18:09:39 -0700256 private void addReadOwner(UriPermissionOwner owner) {
257 if (mReadOwners == null) {
Jeff Sharkey846318a2014-04-04 12:12:41 -0700258 mReadOwners = Sets.newArraySet();
Jeff Sharkeye66c1772013-09-20 14:30:59 -0700259 ownedModeFlags |= Intent.FLAG_GRANT_READ_URI_PERMISSION;
260 updateModeFlags();
Jeff Sharkey328ebf22013-03-21 18:09:39 -0700261 }
Jeff Sharkeye66c1772013-09-20 14:30:59 -0700262 if (mReadOwners.add(owner)) {
263 owner.addReadPermission(this);
264 }
Jeff Sharkey328ebf22013-03-21 18:09:39 -0700265 }
266
267 /**
268 * Remove given read owner, updating {@Link #modeFlags} as needed.
269 */
270 void removeReadOwner(UriPermissionOwner owner) {
271 if (!mReadOwners.remove(owner)) {
Dianne Hackborn8d051722014-10-01 14:59:58 -0700272 Slog.wtf(TAG, "Unknown read owner " + owner + " in " + this);
Jeff Sharkey328ebf22013-03-21 18:09:39 -0700273 }
274 if (mReadOwners.size() == 0) {
275 mReadOwners = null;
Jeff Sharkeye66c1772013-09-20 14:30:59 -0700276 ownedModeFlags &= ~Intent.FLAG_GRANT_READ_URI_PERMISSION;
277 updateModeFlags();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800278 }
279 }
Jeff Sharkey328ebf22013-03-21 18:09:39 -0700280
281 private void addWriteOwner(UriPermissionOwner owner) {
282 if (mWriteOwners == null) {
Jeff Sharkey846318a2014-04-04 12:12:41 -0700283 mWriteOwners = Sets.newArraySet();
Jeff Sharkeye66c1772013-09-20 14:30:59 -0700284 ownedModeFlags |= Intent.FLAG_GRANT_WRITE_URI_PERMISSION;
285 updateModeFlags();
Jeff Sharkey328ebf22013-03-21 18:09:39 -0700286 }
Jeff Sharkeye66c1772013-09-20 14:30:59 -0700287 if (mWriteOwners.add(owner)) {
288 owner.addWritePermission(this);
289 }
Jeff Sharkey328ebf22013-03-21 18:09:39 -0700290 }
291
292 /**
293 * Remove given write owner, updating {@Link #modeFlags} as needed.
294 */
295 void removeWriteOwner(UriPermissionOwner owner) {
296 if (!mWriteOwners.remove(owner)) {
Dianne Hackborn8d051722014-10-01 14:59:58 -0700297 Slog.wtf(TAG, "Unknown write owner " + owner + " in " + this);
Jeff Sharkey328ebf22013-03-21 18:09:39 -0700298 }
299 if (mWriteOwners.size() == 0) {
300 mWriteOwners = null;
Jeff Sharkeye66c1772013-09-20 14:30:59 -0700301 ownedModeFlags &= ~Intent.FLAG_GRANT_WRITE_URI_PERMISSION;
302 updateModeFlags();
Jeff Sharkey328ebf22013-03-21 18:09:39 -0700303 }
304 }
305
306 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800307 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700308 if (stringName != null) {
309 return stringName;
310 }
311 StringBuilder sb = new StringBuilder(128);
312 sb.append("UriPermission{");
313 sb.append(Integer.toHexString(System.identityHashCode(this)));
314 sb.append(' ');
315 sb.append(uri);
316 sb.append('}');
317 return stringName = sb.toString();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800318 }
319
320 void dump(PrintWriter pw, String prefix) {
Jeff Sharkey328ebf22013-03-21 18:09:39 -0700321 pw.print(prefix);
Nicolas Prevotd85fc722014-04-16 19:52:08 +0100322 pw.print("targetUserId=" + targetUserId);
Jeff Sharkey9e0036e2013-04-26 16:54:55 -0700323 pw.print(" sourcePkg=" + sourcePkg);
324 pw.println(" targetPkg=" + targetPkg);
Jeff Sharkey328ebf22013-03-21 18:09:39 -0700325
326 pw.print(prefix);
Jeff Sharkeye66c1772013-09-20 14:30:59 -0700327 pw.print("mode=0x" + Integer.toHexString(modeFlags));
328 pw.print(" owned=0x" + Integer.toHexString(ownedModeFlags));
329 pw.print(" global=0x" + Integer.toHexString(globalModeFlags));
330 pw.print(" persistable=0x" + Integer.toHexString(persistableModeFlags));
331 pw.print(" persisted=0x" + Integer.toHexString(persistedModeFlags));
332 if (persistedCreateTime != INVALID_TIME) {
333 pw.print(" persistedCreate=" + persistedCreateTime);
334 }
335 pw.println();
Jeff Sharkey328ebf22013-03-21 18:09:39 -0700336
337 if (mReadOwners != null) {
338 pw.print(prefix);
339 pw.println("readOwners:");
340 for (UriPermissionOwner owner : mReadOwners) {
341 pw.print(prefix);
342 pw.println(" * " + owner);
Dianne Hackborn39792d22010-08-19 18:01:52 -0700343 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700344 }
Jeff Sharkey328ebf22013-03-21 18:09:39 -0700345 if (mWriteOwners != null) {
346 pw.print(prefix);
347 pw.println("writeOwners:");
348 for (UriPermissionOwner owner : mReadOwners) {
349 pw.print(prefix);
350 pw.println(" * " + owner);
Dianne Hackborn39792d22010-08-19 18:01:52 -0700351 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700352 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800353 }
Jeff Sharkey328ebf22013-03-21 18:09:39 -0700354
Jeff Sharkeye66c1772013-09-20 14:30:59 -0700355 public static class PersistedTimeComparator implements Comparator<UriPermission> {
356 @Override
357 public int compare(UriPermission lhs, UriPermission rhs) {
358 return Long.compare(lhs.persistedCreateTime, rhs.persistedCreateTime);
359 }
360 }
361
Jeff Sharkey328ebf22013-03-21 18:09:39 -0700362 /**
363 * Snapshot of {@link UriPermission} with frozen
364 * {@link UriPermission#persistedModeFlags} state.
365 */
366 public static class Snapshot {
Nicolas Prevotd85fc722014-04-16 19:52:08 +0100367 final int targetUserId;
Jeff Sharkey328ebf22013-03-21 18:09:39 -0700368 final String sourcePkg;
369 final String targetPkg;
Jeff Sharkey846318a2014-04-04 12:12:41 -0700370 final GrantUri uri;
Jeff Sharkey328ebf22013-03-21 18:09:39 -0700371 final int persistedModeFlags;
Jeff Sharkeye66c1772013-09-20 14:30:59 -0700372 final long persistedCreateTime;
Jeff Sharkey328ebf22013-03-21 18:09:39 -0700373
374 private Snapshot(UriPermission perm) {
Nicolas Prevotd85fc722014-04-16 19:52:08 +0100375 this.targetUserId = perm.targetUserId;
Jeff Sharkey328ebf22013-03-21 18:09:39 -0700376 this.sourcePkg = perm.sourcePkg;
377 this.targetPkg = perm.targetPkg;
378 this.uri = perm.uri;
379 this.persistedModeFlags = perm.persistedModeFlags;
Jeff Sharkeye66c1772013-09-20 14:30:59 -0700380 this.persistedCreateTime = perm.persistedCreateTime;
Jeff Sharkey328ebf22013-03-21 18:09:39 -0700381 }
382 }
383
384 public Snapshot snapshot() {
385 return new Snapshot(this);
386 }
Jeff Sharkeye66c1772013-09-20 14:30:59 -0700387
388 public android.content.UriPermission buildPersistedPublicApiObject() {
Jeff Sharkey846318a2014-04-04 12:12:41 -0700389 return new android.content.UriPermission(uri.uri, persistedModeFlags, persistedCreateTime);
Jeff Sharkeye66c1772013-09-20 14:30:59 -0700390 }
Felipe Leme23a0c7a2018-01-24 08:43:34 -0800391
392 public GrantedUriPermission buildGrantedUriPermission() {
393 return new GrantedUriPermission(uri.uri, targetPkg);
394 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800395}