The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame^] | 1 | /* |
| 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 | |
| 17 | package com.android.server.am; |
| 18 | |
| 19 | import android.content.Intent; |
| 20 | import android.net.Uri; |
| 21 | |
| 22 | import java.io.PrintWriter; |
| 23 | import java.util.HashSet; |
| 24 | |
| 25 | class UriPermission { |
| 26 | final int uid; |
| 27 | final Uri uri; |
| 28 | int modeFlags = 0; |
| 29 | int globalModeFlags = 0; |
| 30 | final HashSet<HistoryRecord> readActivities = new HashSet<HistoryRecord>(); |
| 31 | final HashSet<HistoryRecord> writeActivities = new HashSet<HistoryRecord>(); |
| 32 | |
| 33 | UriPermission(int _uid, Uri _uri) { |
| 34 | uid = _uid; |
| 35 | uri = _uri; |
| 36 | } |
| 37 | |
| 38 | void clearModes(int modeFlags) { |
| 39 | if ((modeFlags&Intent.FLAG_GRANT_READ_URI_PERMISSION) != 0) { |
| 40 | globalModeFlags &= ~Intent.FLAG_GRANT_READ_URI_PERMISSION; |
| 41 | modeFlags &= ~Intent.FLAG_GRANT_READ_URI_PERMISSION; |
| 42 | if (readActivities.size() > 0) { |
| 43 | for (HistoryRecord r : readActivities) { |
| 44 | r.readUriPermissions.remove(this); |
| 45 | if (r.readUriPermissions.size() == 0) { |
| 46 | r.readUriPermissions = null; |
| 47 | } |
| 48 | } |
| 49 | readActivities.clear(); |
| 50 | } |
| 51 | } |
| 52 | if ((modeFlags&Intent.FLAG_GRANT_WRITE_URI_PERMISSION) != 0) { |
| 53 | globalModeFlags &= ~Intent.FLAG_GRANT_WRITE_URI_PERMISSION; |
| 54 | modeFlags &= ~Intent.FLAG_GRANT_WRITE_URI_PERMISSION; |
| 55 | if (readActivities.size() > 0) { |
| 56 | for (HistoryRecord r : readActivities) { |
| 57 | r.writeUriPermissions.remove(this); |
| 58 | if (r.writeUriPermissions.size() == 0) { |
| 59 | r.writeUriPermissions = null; |
| 60 | } |
| 61 | } |
| 62 | readActivities.clear(); |
| 63 | } |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | public String toString() { |
| 68 | return "UriPermission{" |
| 69 | + Integer.toHexString(System.identityHashCode(this)) |
| 70 | + " " + uri + "}"; |
| 71 | } |
| 72 | |
| 73 | void dump(PrintWriter pw, String prefix) { |
| 74 | pw.println(prefix + this); |
| 75 | pw.println(prefix + " modeFlags=0x" + Integer.toHexString(modeFlags) |
| 76 | + " uid=" + uid |
| 77 | + " globalModeFlags=0x" |
| 78 | + Integer.toHexString(globalModeFlags)); |
| 79 | pw.println(prefix + " readActivities=" + readActivities); |
| 80 | pw.println(prefix + " writeActivities=" + writeActivities); |
| 81 | } |
| 82 | } |