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