2
* Copyright © 2012 Linaro Limited
4
* This file is part of the glmark2 OpenGL (ES) 2.0 benchmark.
6
* glmark2 is free software: you can redistribute it and/or modify it under the
7
* terms of the GNU General Public License as published by the Free Software
8
* Foundation, either version 3 of the License, or (at your option) any later
11
* glmark2 is distributed in the hope that it will be useful, but WITHOUT ANY
12
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
16
* You should have received a copy of the GNU General Public License along with
17
* glmark2. If not, see <http://www.gnu.org/licenses/>.
22
package org.linaro.glmark2;
24
import java.util.ArrayList;
25
import java.util.Collections;
28
import android.app.Activity;
29
import android.os.Environment;
31
class BenchmarkListManager {
33
private ArrayList<String> benchmarks;
34
private Activity activity;
36
BenchmarkListManager(Activity activity, ArrayList<String> benchmarks)
38
this.activity = activity;
39
if (benchmarks == null) {
40
this.benchmarks = new ArrayList<String>();
41
this.benchmarks.add("Add benchmark...");
44
this.benchmarks = benchmarks;
49
* Gets the list holding the benchmarks.
51
* The reference to this list is constant for the life of
52
* the BenchmarkListManager,
54
* @return the operation error code
56
ArrayList<String> getBenchmarkList() {
61
* Gets the saved benchmark lists.
63
* Each list name is prefixed with either "internal/" or "external/"
64
* to denote in which storage area it is saved in.
66
* @return an array containing the saved list names
68
String[] getSavedLists() {
69
File externalPath = getSavedListPath(true);
70
File internalPath = getSavedListPath(false);
71
ArrayList<String> lists = new ArrayList<String>();
73
if (externalPath != null && externalPath.isDirectory()) {
74
for (File f: externalPath.listFiles())
75
lists.add("external/" + f.getName());
78
if (internalPath != null && internalPath.isDirectory()) {
79
for (File f: internalPath.listFiles())
80
lists.add("internal/" + f.getName());
83
Collections.sort(lists);
85
String[] a = new String[0];
86
return lists.toArray(a);
90
* Saves the current benchmark list to a file.
92
* @param listName the list filename
93
* @param external whether the file is to be stored in external storage
95
void saveBenchmarkList(String listName, boolean external) throws Exception {
96
File listPath = getSavedListPath(external);
98
throw new Exception("External storage not present");
102
File f = new File(listPath, listName);
104
BufferedWriter out = new BufferedWriter(new FileWriter(f));
106
for (int i = 0; i < benchmarks.size() - 1; i++) {
107
out.write(benchmarks.get(i));
111
catch (Exception ex) {
120
* Loads a benchmark list from a file.
122
* @param listName the list filename
123
* @param external whether the file is stored in external storage
125
void loadBenchmarkList(String listName, boolean external) throws Exception {
126
/* Get the list file path */
127
File listPath = getSavedListPath(external);
128
if (listPath == null)
129
throw new Exception("External storage not present");
131
File f = new File(listPath, listName);
133
ArrayList<String> newBenchmarks = new ArrayList<String>();
135
/* Read benchmarks from file */
136
BufferedReader reader = new BufferedReader(new FileReader(f));
139
while ((line = reader.readLine()) != null)
140
newBenchmarks.add(line);
142
/* If everything went well, replace current benchmarks */
144
benchmarks.addAll(newBenchmarks);
145
benchmarks.add("Add benchmark...");
149
* Delete a benchmark list file.
151
* @param listName the list filename
152
* @param external whether the file is stored in external storage
154
void deleteBenchmarkList(String listName, boolean external) throws Exception {
155
/* Get the list file path */
156
File listPath = getSavedListPath(external);
157
if (listPath == null)
158
throw new Exception("External storage not present");
160
File f = new File(listPath, listName);
165
* Gets the path where benchmark lists are saved in.
167
* @param external whether to get the path for external storage
169
* @return the saved list path
171
private File getSavedListPath(boolean external) {
175
String state = Environment.getExternalStorageState();
176
if (!Environment.MEDIA_MOUNTED.equals(state))
178
f = activity.getExternalFilesDir(null);
181
f = activity.getFilesDir();
185
f = new File(f, "lists");