1 /*
2  * Copyright (C) 2019 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.providers.media.scan;
18 
19 import android.content.Context;
20 import android.net.Uri;
21 import android.provider.MediaStore;
22 import android.util.Log;
23 
24 import androidx.annotation.Nullable;
25 
26 import java.io.File;
27 
28 /**
29  * Null scanner that ignores all scanning requests. Can be useful when running
30  * as {@link MediaStore#AUTHORITY_LEGACY} or during unit tests.
31  */
32 public class NullMediaScanner implements MediaScanner {
33     private static final String TAG = "NullMediaScanner";
34 
35     private final Context mContext;
36 
NullMediaScanner(Context context)37     public NullMediaScanner(Context context) {
38         mContext = context;
39     }
40 
41     @Override
getContext()42     public Context getContext() {
43         return mContext;
44     }
45 
46     @Override
scanDirectory(File file, int reason)47     public void scanDirectory(File file, int reason) {
48         Log.w(TAG, "Ignoring scan request for " + file);
49     }
50 
51     @Override
scanFile(File file, int reason)52     public Uri scanFile(File file, int reason) {
53         Log.w(TAG, "Ignoring scan request for " + file);
54         return null;
55     }
56 
57     @Override
scanFile(File file, int reason, @Nullable String ownerPackage)58     public Uri scanFile(File file, int reason, @Nullable String ownerPackage) {
59         Log.w(TAG, "Ignoring scan request for " + file);
60         return null;
61     }
62 
63     @Override
onDetachVolume(String volumeName)64     public void onDetachVolume(String volumeName) {
65         // Ignored
66     }
67 }
68