1 /* 2 * Copyright (C) 2018 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.documentsui.roots; 18 19 import android.app.Activity; 20 import android.net.Uri; 21 22 import com.android.documentsui.AbstractActionHandler.CommonAddons; 23 import com.android.documentsui.base.RootInfo; 24 import com.android.documentsui.base.UserId; 25 26 import java.util.Collection; 27 28 public final class LoadFirstRootTask<T extends Activity & CommonAddons> 29 extends LoadRootTask<T> { 30 LoadFirstRootTask( T activity, ProvidersAccess providers, Uri rootUri, LoadRootCallback callback)31 public LoadFirstRootTask( 32 T activity, 33 ProvidersAccess providers, 34 Uri rootUri, 35 LoadRootCallback callback) { 36 super(activity, providers, rootUri, UserId.DEFAULT_USER, callback); 37 } 38 39 @Override getRootId(Uri rootUri)40 protected String getRootId(Uri rootUri) { 41 final String authority = rootUri.getAuthority(); 42 String rootId = null; 43 44 final Collection<RootInfo> roots = mProviders.getRootsForAuthorityBlocking( 45 UserId.DEFAULT_USER, authority); 46 if (!roots.isEmpty()) { 47 rootId = roots.iterator().next().rootId; 48 } 49 50 return rootId; 51 } 52 } 53