Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9bb1101f authored by Android (Google) Code Review's avatar Android (Google) Code Review
Browse files

Merge change 23924 into eclair

* changes:
  	new file:   LowStorageTest/Android.mk 	new file:   LowStorageTest/AndroidManifest.xml 	new file:   LowStorageTest/res/layout/main.xml 	new file:   LowStorageTest/res/values/strings.xml 	new file:   LowStorageTest/src/com/android/lowstoragetest/LowStorageTest.java Add the test app which can eat up 100% of the data parition. This is for the low storage test.
parents e989496e 4333bd14
Loading
Loading
Loading
Loading
+25 −0
Original line number Diff line number Diff line
# Copyright (C) 2009 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)

LOCAL_MODULE_TAGS := tests
LOCAL_CERTIFICATE := platform

LOCAL_SRC_FILES := $(call all-subdir-java-files)

LOCAL_PACKAGE_NAME := lowstoragetest

include $(BUILD_PACKAGE)
+13 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.android.lowstoragetest">
    <application android:label="LowStorageTest">
        <activity android:name="LowStorageTest"
                  android:theme="@android:style/Theme.Black.NoTitleBar">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
</manifest>
 No newline at end of file
+72 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2009 The Android Open Source Project

     Licensed under the Apache License, Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
     You may obtain a copy of the License at

          http://www.apache.org/licenses/LICENSE-2.0

     Unless required by applicable law or agreed to in writing, software
     distributed under the License is distributed on an "AS IS" BASIS,
     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     See the License for the specific language governing permissions and
     limitations under the License.
-->
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:stretchColumns="1">

    <TextView
        android:text="@string/total_storage"
        android:gravity="left"
        android:padding="3dip" />

    <TextView
        android:id="@+id/totalsize"
        android:gravity="left"
        android:padding="3dip" />

    <View
        android:layout_height="2dip"
        android:background="#FF909090" />

    <TextView
        android:layout_column="1"
        android:gravity="left"
        android:text="@string/available_storage"
        android:padding="3dip" />

    <TextView
        android:id="@+id/freesize"
        android:gravity="left"
        android:padding="3dip" />

    <TextView
        android:layout_column="1"
        android:gravity="left"
        android:textSize="18sp"
        android:text="@string/status"
        android:padding="3dip" />

    <TextView
        android:layout_column="1"
        android:gravity="left"
        android:textSize="18sp"
        android:id="@+id/status"
        android:text="@string/eat_up_storage"
        android:padding="3dip" />

    <View
        android:layout_height="2dip"
        android:background="#FF909090" />

    <Button 
        android:id="@+id/button_run"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/run_text"
        android:layout_alignParentRight="true" />

</TableLayout>
 No newline at end of file
+23 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="UTF-8"?>
<!-- Copyright (C) 2009 The Android Open Source Project

     Licensed under the Apache License, Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
     You may obtain a copy of the License at

          http://www.apache.org/licenses/LICENSE-2.0

     Unless required by applicable law or agreed to in writing, software
     distributed under the License is distributed on an "AS IS" BASIS,
     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     See the License for the specific language governing permissions and
     limitations under the License.
-->
<resources xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
    <string name="total_storage">"Total Storage Size ..."</string>
    <string name="available_storage">"Available Storage Size ..."</string>
    <string name="eat_up_storage">"Please Wait..."</string>
    <string name="status">"Status"</string>
    <string name="run_text">"Start"</string>
</resources>
+132 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2009 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */

package com.android.lowstoragetest;

import android.app.Activity;
import android.content.Context;

import android.os.Bundle;
import android.os.Environment;
import android.os.StatFs;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import java.io.File;
import java.io.FileOutputStream;
import android.widget.TextView;
import android.widget.Button;

public class LowStorageTest extends Activity {
    static final String TAG = "DiskFullTest";
    static final long WAIT_FOR_FINISH = 5 * 60 * 60;
    static final int NO_OF_BLOCKS_TO_FILL = 1000;
    static final int BYTE_SIZE = 1024;
    static final int WAIT_FOR_SYSTEM_UPDATE = 10000;

    private int mBlockSize = 0;
    private final Object fillUpDone = new Object();

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        setContentView(R.layout.main);

        // Update the current data info
        File path = Environment.getDataDirectory();
        StatFs stat = new StatFs(path.getPath());
        int totalBlocks = stat.getBlockCount();
        mBlockSize = (int) (stat.getBlockSize());
        TextView startSizeTextView = (TextView) findViewById(R.id.totalsize);
        startSizeTextView.setText(Long.toString((totalBlocks * mBlockSize) / BYTE_SIZE));
        Button button = (Button) findViewById(R.id.button_run);
        button.setOnClickListener(mStartListener);
    }

    View.OnClickListener mStartListener = new OnClickListener() {
        public void onClick(View v) {
            fillDataAndUpdateInfo();
        }
    };

    public void fillDataAndUpdateInfo() {
        updateInfo(this);
    }

    // Fill up 100% of the data partition
    public void fillupdisk(Context context) {
        final Context contextfill = context;
        new Thread() {
            @Override
            public void run() {
                try {
                    // Fill up all the memory
                    File path = Environment.getDataDirectory();
                    StatFs stat = new StatFs(path.getPath());
                    int totalBlocks = stat.getBlockCount();
                    int noOfBlockToFill = stat.getAvailableBlocks();
                    FileOutputStream fs =
                            contextfill.openFileOutput("testdata", Context.MODE_APPEND);
                    for (int i = 0; i < (noOfBlockToFill / NO_OF_BLOCKS_TO_FILL); i++) {
                        byte buf[] = new byte[mBlockSize * NO_OF_BLOCKS_TO_FILL];
                        fs.write(buf);
                        fs.flush();
                    }

                    // Fill up the last few block
                    byte buf[] = new byte[(noOfBlockToFill % NO_OF_BLOCKS_TO_FILL) * mBlockSize];
                    fs.write(buf);
                    fs.flush();
                    fs.close();

                    // Finished, update the info
                    synchronized (fillUpDone) {
                        fillUpDone.notify();
                    }
                } catch (Exception e) {
                    Log.v(TAG, e.toString());
                }
            }
        }.start();
    }

    public void updateInfo(Context context) {
        fillupdisk(this);
        synchronized (fillUpDone) {
            try {
                fillUpDone.wait(WAIT_FOR_FINISH);
            } catch (Exception e) {
                Log.v(TAG, "wait was interrupted.");
            }
        }
        try {
            // The stat didn't relect the correct data right away
            // put some extra time to make sure if get the right size.
            Thread.sleep(WAIT_FOR_SYSTEM_UPDATE);
            File path = Environment.getDataDirectory();
            StatFs stat = new StatFs(path.getPath());
            long availableBlocks = stat.getAvailableBlocks();
            TextView freeSizeTextView = (TextView) findViewById(R.id.freesize);
            freeSizeTextView.setText(Long.toString((availableBlocks * mBlockSize) / BYTE_SIZE));
            TextView statusTextView = (TextView) findViewById(R.id.status);
            statusTextView.setText("Finished. You can start the test now.");
        } catch (Exception e) {
            Log.v(TAG, e.toString());
        }
    }
}