Home | History | Annotate | Download | only in cts
      1 /*
      2  * Copyright (C) 2012 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 android.mediastress.cts;
     18 
     19 import android.os.Bundle;
     20 import android.os.Environment;
     21 
     22 import androidx.test.InstrumentationRegistry;
     23 
     24 import junit.framework.Assert;
     25 
     26 import java.io.File;
     27 
     28 public class WorkDir {
     29 
     30     private static final String MEDIA_PATH_INSTR_ARG_KEY = "media-path";
     31 
     32     static final File getTopDir() {
     33         Assert.assertEquals(Environment.getExternalStorageState(), Environment.MEDIA_MOUNTED);
     34         return Environment.getExternalStorageDirectory();
     35     }
     36 
     37     static final String getTopDirString() {
     38         return (getTopDir().getAbsolutePath() + File.separator);
     39     }
     40 
     41     static final String getMediaDirString() {
     42         Bundle bundle = InstrumentationRegistry.getArguments();
     43         String mediaDirString = bundle.getString(MEDIA_PATH_INSTR_ARG_KEY);
     44         if (mediaDirString != null) {
     45             // user has specified the mediaDirString via instrumentation-arg
     46             return mediaDirString + ((mediaDirString.endsWith("/")) ? "" : "/");
     47         } else {
     48             return (getTopDirString() + "test/");
     49         }
     50     }
     51 }
     52