blob: 1b98ce0bd3b10ef8a50b554a64b79f63f3c72ff6 [file] [log] [blame]
Steve McKayc7dc0cf2016-02-04 12:15:22 -08001/*
2 * Copyright (C) 2016 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.documentsui;
18
19import android.net.Uri;
20import android.provider.DocumentsContract;
21import android.util.Log;
22
Steve McKayd0805062016-09-15 14:30:38 -070023import com.android.documentsui.base.PairedTask;
24import com.android.documentsui.base.RootInfo;
Steve McKayc7dc0cf2016-02-04 12:15:22 -080025
Steve McKayfd8425a2016-02-23 14:34:50 -080026final class LoadRootTask extends PairedTask<BaseActivity, Void, RootInfo> {
Steve McKayc7dc0cf2016-02-04 12:15:22 -080027 private static final String TAG = "RestoreRootTask";
28
29 private final Uri mRootUri;
30
Steve McKayfd8425a2016-02-23 14:34:50 -080031 public LoadRootTask(BaseActivity activity, Uri rootUri) {
Steve McKayc7dc0cf2016-02-04 12:15:22 -080032 super(activity);
33 mRootUri = rootUri;
34 }
35
36 @Override
37 protected RootInfo run(Void... params) {
38 String rootId = DocumentsContract.getRootId(mRootUri);
39 return mOwner.mRoots.getRootOneshot(mRootUri.getAuthority(), rootId);
40 }
41
42 @Override
43 protected void finish(RootInfo root) {
44 mOwner.mState.restored = true;
45
46 if (root != null) {
47 mOwner.onRootPicked(root);
48 } else {
49 Log.w(TAG, "Failed to find root: " + mRootUri);
50 mOwner.finish();
51 }
52 }
53}