예제 #1
0
 public static Path fromString(String s) {
   synchronized (Path.class) {
     String[] segments = split(s);
     Path current = sRoot;
     for (int i = 0; i < segments.length; i++) {
       current = current.getChild(segments[i]);
     }
     return current;
   }
 }
예제 #2
0
 static void dumpAll(Path p, String prefix1, String prefix2) {
   synchronized (Path.class) {
     MediaObject obj = p.getObject();
     Log.d(
         TAG,
         prefix1 + p.mSegment + ":" + (obj == null ? "null" : obj.getClass().getSimpleName()));
     if (p.mChildren != null) {
       ArrayList<String> childrenKeys = p.mChildren.keys();
       int i = 0, n = childrenKeys.size();
       for (String key : childrenKeys) {
         Path child = p.mChildren.get(key);
         if (child == null) {
           ++i;
           continue;
         }
         Log.d(TAG, prefix2 + "|");
         if (++i < n) {
           dumpAll(child, prefix2 + "+-- ", prefix2 + "|   ");
         } else {
           dumpAll(child, prefix2 + "+-- ", prefix2 + "    ");
         }
       }
     }
   }
 }
 public static Uri getUriFor(Context context, Path path) {
   if (sBaseUri == null) {
     sBaseUri = Uri.parse("content://" + context.getPackageName() + ".provider");
   }
   return sBaseUri
       .buildUpon()
       .appendEncodedPath(path.toString().substring(1)) // ignore the leading '/'
       .build();
 }
 // TODO: consider concurrent access
 @Override
 public String getType(Uri uri) {
   long token = Binder.clearCallingIdentity();
   try {
     Path path = Path.fromString(uri.getPath());
     MediaItem item = (MediaItem) mDataManager.getMediaObject(path);
     return item != null ? item.getMimeType() : null;
   } finally {
     Binder.restoreCallingIdentity(token);
   }
 }
  // TODO: consider concurrent access
  @Override
  public Cursor query(
      Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
    long token = Binder.clearCallingIdentity();
    try {
      Path path = Path.fromString(uri.getPath());
      MediaObject object = mDataManager.getMediaObject(path);
      if (object == null) {
        Log.w(TAG, "cannot find: " + uri);
        return null;
      }

      return null;
    } finally {
      Binder.restoreCallingIdentity(token);
    }
  }
  @Override
  public ParcelFileDescriptor openFile(Uri uri, String mode) throws FileNotFoundException {
    long token = Binder.clearCallingIdentity();
    try {
      if (mode.contains("w")) {
        throw new FileNotFoundException("cannot open file for write");
      }
      Path path = Path.fromString(uri.getPath());
      MediaObject object = mDataManager.getMediaObject(path);
      if (object == null) {
        throw new FileNotFoundException(uri.toString());
      }

      throw new FileNotFoundException("unspported type: " + object);
    } finally {
      Binder.restoreCallingIdentity(token);
    }
  }