Home | History | Annotate | Download | only in am
      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     String stringName;
     34 
     35     UriPermission(int _uid, Uri _uri) {
     36         uid = _uid;
     37         uri = _uri;
     38     }
     39 
     40     void clearModes(int modeFlags) {
     41         if ((modeFlags&Intent.FLAG_GRANT_READ_URI_PERMISSION) != 0) {
     42             globalModeFlags &= ~Intent.FLAG_GRANT_READ_URI_PERMISSION;
     43             modeFlags &= ~Intent.FLAG_GRANT_READ_URI_PERMISSION;
     44             if (readActivities.size() > 0) {
     45                 for (HistoryRecord r : readActivities) {
     46                     r.readUriPermissions.remove(this);
     47                     if (r.readUriPermissions.size() == 0) {
     48                         r.readUriPermissions = null;
     49                     }
     50                 }
     51                 readActivities.clear();
     52             }
     53         }
     54         if ((modeFlags&Intent.FLAG_GRANT_WRITE_URI_PERMISSION) != 0) {
     55             globalModeFlags &= ~Intent.FLAG_GRANT_WRITE_URI_PERMISSION;
     56             modeFlags &= ~Intent.FLAG_GRANT_WRITE_URI_PERMISSION;
     57             if (readActivities.size() > 0) {
     58                 for (HistoryRecord r : readActivities) {
     59                     r.writeUriPermissions.remove(this);
     60                     if (r.writeUriPermissions.size() == 0) {
     61                         r.writeUriPermissions = null;
     62                     }
     63                 }
     64                 readActivities.clear();
     65             }
     66         }
     67     }
     68 
     69     public String toString() {
     70         if (stringName != null) {
     71             return stringName;
     72         }
     73         StringBuilder sb = new StringBuilder(128);
     74         sb.append("UriPermission{");
     75         sb.append(Integer.toHexString(System.identityHashCode(this)));
     76         sb.append(' ');
     77         sb.append(uri);
     78         sb.append('}');
     79         return stringName = sb.toString();
     80     }
     81 
     82     void dump(PrintWriter pw, String prefix) {
     83         pw.print(prefix); pw.print("modeFlags=0x");
     84                 pw.print(Integer.toHexString(modeFlags));
     85                 pw.print(" uid="); pw.print(uid);
     86                 pw.print(" globalModeFlags=0x");
     87                 pw.println(Integer.toHexString(globalModeFlags));
     88         if (readActivities.size() != 0) {
     89             pw.print(prefix); pw.print("readActivities="); pw.println(readActivities);
     90         }
     91         if (writeActivities.size() != 0) {
     92             pw.print(prefix); pw.print("writeActivities="); pw.println(writeActivities);
     93         }
     94     }
     95 }
     96