1 /* 2 * Copyright (C) 2015 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 package com.android.compatibility.common.deviceinfo; 17 18 import android.os.Environment; 19 import android.os.SystemProperties; 20 import android.util.Log; 21 22 import com.android.compatibility.common.util.DeviceInfoStore; 23 24 import java.io.IOException; 25 import java.util.ArrayList; 26 import java.util.List; 27 import java.util.Scanner; 28 29 /** 30 * Storage device info collector. 31 */ 32 public class StorageDeviceInfo extends DeviceInfo { 33 private static final String TAG = "StorageDeviceInfo"; 34 35 @Override collectDeviceInfo(DeviceInfoStore store)36 protected void collectDeviceInfo(DeviceInfoStore store) throws Exception { 37 int total = 0; 38 total = Math.max(total, getContext().getExternalCacheDirs().length); 39 total = Math.max(total, getContext().getExternalFilesDirs(null).length); 40 total = Math.max( 41 total, getContext().getExternalFilesDirs(Environment.DIRECTORY_PICTURES).length); 42 total = Math.max(total, getContext().getObbDirs().length); 43 44 int emulated = 0; 45 int physical = 0; 46 if (Environment.isExternalStorageEmulated()) { 47 if (total == 1) { 48 emulated = 1; 49 } else { 50 emulated = 1; 51 physical = total - 1; 52 } 53 } else { 54 physical = total; 55 } 56 57 store.addResult("num_physical", physical); 58 store.addResult("num_emulated", emulated); 59 60 store.addListResult("raw_partition", scanPartitions()); 61 62 boolean hasCompress = SystemProperties.getInt("vold.has_compress", 0) != 0 ? true : false; 63 store.addResult("compression", hasCompress); 64 } 65 scanPartitions()66 private List<String> scanPartitions() { 67 List<String> partitionList = new ArrayList<>(); 68 try { 69 Process df = Runtime.getRuntime().exec("df -k"); 70 Scanner scanner = new Scanner(df.getInputStream()); 71 try { 72 while (scanner.hasNextLine()) { 73 partitionList.add(scanner.nextLine()); 74 } 75 } finally { 76 scanner.close(); 77 } 78 } catch (Exception e) { 79 Log.w(TAG, Log.getStackTraceString(e)); 80 } 81 return partitionList; 82 } 83 84 } 85