M7350v1_en_gpl

This commit is contained in:
T
2024-09-09 08:52:07 +00:00
commit f9cc65cfda
65988 changed files with 26357421 additions and 0 deletions

View File

@@ -0,0 +1,46 @@
# Copyright (C) 2008 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)
# native test
# ========================================
include $(CLEAR_VARS)
LOCAL_SRC_FILES := \
backup_helper_test.cpp
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE := backup_helper_test
LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS)
LOCAL_SHARED_LIBRARIES := libutils
include $(BUILD_EXECUTABLE)
# java test
# ========================================
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS)
LOCAL_SRC_FILES := $(call all-subdir-java-files)
LOCAL_PACKAGE_NAME := BackupTest
LOCAL_PROGUARD_ENABLED := disabled
include $(BUILD_PACKAGE)

View File

@@ -0,0 +1,12 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.android.backuptest">
<application android:backupAgent="BackupTestAgent">
<activity android:name="BackupTestActivity" android:label="_BackupTest">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>

View File

@@ -0,0 +1,126 @@
/*
* 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.
*/
#include <utils/BackupHelpers.h>
#include <stdio.h>
#include <string.h>
using namespace android;
#if TEST_BACKUP_HELPERS
// ============================================================
// ============================================================
typedef int (*test_func)();
struct Test {
const char* name;
test_func func;
int result;
bool run;
};
Test TESTS[] = {
{ "backup_helper_test_empty", backup_helper_test_empty, 0, false },
{ "backup_helper_test_four", backup_helper_test_four, 0, false },
{ "backup_helper_test_files", backup_helper_test_files, 0, false },
{ "backup_helper_test_null_base", backup_helper_test_null_base, 0, false },
{ "backup_helper_test_missing_file", backup_helper_test_missing_file, 0, false },
{ "backup_helper_test_data_writer", backup_helper_test_data_writer, 0, false },
{ "backup_helper_test_data_reader", backup_helper_test_data_reader, 0, false },
{ 0, NULL, 0, false}
};
int
main(int argc, const char** argv)
{
Test* t;
if (argc == 1) {
t = TESTS;
while (t->name) {
t->run = true;
t++;
}
} else {
t = TESTS;
while (t->name) {
for (int i=1; i<argc; i++) {
if (0 == strcmp(t->name, argv[i])) {
t->run = true;
}
}
t++;
}
}
int testCount = 0;
t = TESTS;
while (t->name) {
if (t->run) {
testCount++;
}
t++;
}
int failed = 0;
int i = 1;
t = TESTS;
while (t->name) {
if (t->run) {
printf("===== Running %s (%d of %d) ==============================\n",
t->name, i, testCount);
fflush(stdout);
fflush(stderr);
t->result = t->func();
if (t->result != 0) {
failed++;
printf("failed\n");
} else {
printf("passed\n");
}
i++;
}
t++;
}
printf("=================================================================\n");
if (failed == 0) {
printf("All %d test(s) passed\n", testCount);
} else {
printf("Tests failed: (%d of %d)\n", failed, testCount);
t = TESTS;
while (t->name) {
if (t->run) {
if (t->result != 0) {
printf(" %s\n", t->name);
}
}
t++;
}
}
}
#else
int
main(int argc, char** argv)
{
printf ("test_backup_helper built without the tests\n");
return 0;
}
#endif

View File

@@ -0,0 +1,64 @@
#!/bin/bash
# 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.
iterations=150
failures=0
i=0
LOGDIR="$HOME/backup_tests"
LOGFILE="$LOGDIR/backup_stress.`date +%s`.log"
export BUGREPORT_DIR="$LOGDIR/bugreports"
# make sure that we have a place to put logs and bugreports
mkdir -p $LOGDIR $BUGREPORT_DIR
echo "logfile is $LOGFILE"
(while (sleep 10); do
failed=0
echo
echo "Iteration $i at `date`"
echo
./test_backup.sh "$@" 2>&1
sleep 10
echo "Restore at `date`"
echo
./test_restore.sh "$@" 2>&1 || failed=1
if [ "$failed" -ne 0 ]; then
failures=$(($failures+1))
# Long and verbose so it sticks out
echo "FAILED iteration $i of $iterations; $failures failures so far"
echo "FAILED iteration $i of $iterations; $failures failures so far" > /dev/stderr
else
printf "Iteration %d:\tPASS; remaining: %d\n" $i $(($iterations - $i - 1))
printf "Iteration %d:\tPASS; remaining: %d\n" $i $(($iterations - $i - 1)) > /dev/stderr
fi
echo "End $i at `date`"
i=$(($i+1))
if [ $i -eq $iterations ]; then
echo "DONE: $iterations iterations with $failures failures."
echo "DONE: $iterations iterations with $failures failures." > /dev/stderr
[ "$failures" -eq 0 ] && exit 0
exit 1
fi
done) > "$LOGFILE"

View File

@@ -0,0 +1,214 @@
/*
* 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.backuptest;
import android.app.ListActivity;
import android.app.backup.BackupHelperDispatcher;
import android.app.backup.BackupDataInput;
import android.app.backup.BackupDataOutput;
import android.app.backup.BackupManager;
import android.app.backup.FileBackupHelper;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.os.ParcelFileDescriptor;
import android.util.Log;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStreamReader;
import java.io.IOException;
import java.io.PrintStream;
import java.text.DateFormat;
import java.util.Date;
public class BackupTestActivity extends ListActivity
{
static final String TAG = "BackupTestActivity";
static final String PREF_GROUP_SETTINGS = "settings";
static final String PREF_KEY = "pref";
static final String FILE_NAME = "file.txt";
BackupManager sBm = new BackupManager(this);
Test[] mTests = new Test[] {
new Test("Show File") {
void run() {
StringBuffer str = new StringBuffer();
str.append("Text is:");
BufferedReader reader = null;
try {
reader = new BufferedReader(new InputStreamReader(openFileInput(FILE_NAME)));
while (reader.ready()) {
str.append("\n");
str.append(reader.readLine());
}
} catch (IOException ex) {
str.append("ERROR: ");
str.append(ex.toString());
}
Log.d(TAG, str.toString());
Toast.makeText(BackupTestActivity.this, str, Toast.LENGTH_SHORT).show();
}
},
new Test("Append to File") {
void run() {
PrintStream output = null;
try {
output = new PrintStream(openFileOutput(FILE_NAME, MODE_APPEND));
DateFormat formatter = DateFormat.getDateTimeInstance();
output.println(formatter.format(new Date()));
output.close();
} catch (IOException ex) {
if (output != null) {
output.close();
}
}
sBm.dataChanged();
}
},
new Test("Clear File") {
void run() {
PrintStream output = null;
try {
output = new PrintStream(openFileOutput(FILE_NAME, MODE_PRIVATE));
output.close();
} catch (IOException ex) {
if (output != null) {
output.close();
}
}
sBm.dataChanged();
}
},
new Test("Poke") {
void run() {
sBm.dataChanged();
}
},
new Test("Show Shared Pref") {
void run() {
SharedPreferences prefs = getSharedPreferences(PREF_GROUP_SETTINGS, MODE_PRIVATE);
int val = prefs.getInt(PREF_KEY, 0);
String str = "'" + PREF_KEY + "' is " + val;
Log.d(TAG, str);
Toast.makeText(BackupTestActivity.this, str, Toast.LENGTH_SHORT).show();
}
},
new Test("Increment Shared Pref") {
void run() {
SharedPreferences prefs = getSharedPreferences(PREF_GROUP_SETTINGS, MODE_PRIVATE);
int val = prefs.getInt(PREF_KEY, 0);
SharedPreferences.Editor editor = prefs.edit();
editor.putInt(PREF_KEY, val+1);
editor.commit();
sBm.dataChanged();
}
},
new Test("Backup Helpers") {
void run() {
try {
writeFile("a", "a\naa", MODE_PRIVATE);
writeFile("empty", "", MODE_PRIVATE);
ParcelFileDescriptor state = ParcelFileDescriptor.open(
new File(getFilesDir(), "state"),
ParcelFileDescriptor.MODE_READ_WRITE|ParcelFileDescriptor.MODE_CREATE|
ParcelFileDescriptor.MODE_TRUNCATE);
FileBackupHelper h = new FileBackupHelper(BackupTestActivity.this,
new String[] { "a", "empty" });
FileOutputStream dataFile = openFileOutput("backup_test", MODE_WORLD_READABLE);
BackupDataOutput data = new BackupDataOutput(dataFile.getFD());
h.performBackup(null, data, state);
dataFile.close();
state.close();
} catch (IOException ex) {
throw new RuntimeException(ex);
}
}
},
new Test("Restore Helpers") {
void run() {
try {
BackupHelperDispatcher dispatch = new BackupHelperDispatcher();
dispatch.addHelper("", new FileBackupHelper(BackupTestActivity.this,
new String[] { "a", "empty" }));
FileInputStream dataFile = openFileInput("backup_test");
BackupDataInput data = new BackupDataInput(dataFile.getFD());
ParcelFileDescriptor state = ParcelFileDescriptor.open(
new File(getFilesDir(), "restore_state"),
ParcelFileDescriptor.MODE_READ_WRITE|ParcelFileDescriptor.MODE_CREATE|
ParcelFileDescriptor.MODE_TRUNCATE);
// TODO: a more plausable synthetic stored-data version number
dispatch.performRestore(data, 0, state);
dataFile.close();
state.close();
} catch (IOException ex) {
throw new RuntimeException(ex);
}
}
}
};
abstract class Test {
String name;
Test(String n) {
name = n;
}
abstract void run();
}
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
String[] labels = new String[mTests.length];
for (int i=0; i<mTests.length; i++) {
labels[i] = mTests[i].name;
}
setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, labels));
}
@Override
public void onListItemClick(ListView l, View v, int position, long id)
{
Test t = mTests[position];
Log.d(TAG, "Test: " + t.name);
t.run();
}
void writeFile(String name, String contents, int mode) {
try {
PrintStream out = new PrintStream(openFileOutput(name, mode));
out.print(contents);
out.close();
} catch (FileNotFoundException ex) {
throw new RuntimeException(ex);
}
}
}

View File

@@ -0,0 +1,32 @@
/*
* Copyright (C) 2007 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.backuptest;
import android.app.backup.BackupAgentHelper;
import android.app.backup.FileBackupHelper;
import android.app.backup.SharedPreferencesBackupHelper;
public class BackupTestAgent extends BackupAgentHelper
{
public void onCreate() {
addHelper("data_files", new FileBackupHelper(this, BackupTestActivity.FILE_NAME));
addHelper("more_data_files", new FileBackupHelper(this, "another_file.txt", "3.txt",
"empty.txt"));
addHelper("shared_prefs", new SharedPreferencesBackupHelper(this, "settings", "raw"));
}
}

View File

@@ -0,0 +1,65 @@
#!/bin/bash
# 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.
# uncomment for debugging
#export DRY_RUN="echo"
source test_backup_common.sh
# figure out what packages are participating in backup
b_pkgs=$(a shell dumpsys backup | \
ruby -e 'p_stanza = STDIN.read.match(/Participants:.*?(?=Ever)/m)[0]
puts p_stanza.scan(/^ (.+?)\s*$/).flatten.join(" ")')
# wipe data for the package participating in backup
for pkg in $b_pkgs; do
a shell bmgr wipe "$pkg"
done
echo 'Waiting 5 seconds for things to settle...'
sleep 5
# run adb as root so we can poke at com.android.backuptest's data
adb_root
# show commands as we go
set -x
# set the transport
#a shell bmgr transport com.google.android.backup/.BackupTransportService
# load up the three files
a shell \
"rm /data/data/com.android.backuptest/files/file.txt ; \
rm /data/data/com.android.backuptest/files/another_file.txt ; \
rm /data/data/com.android.backuptest/files/empty.txt ; \
mkdir /data/data/com.android.backuptest ; \
mkdir /data/data/com.android.backuptest/files ; \
mkdir /data/data/com.android.backuptest/shared_prefs ; \
echo -n \"<map><int name=\\\"pref\\\" value=\\\"1\\\" /></map>\" \
> /data/data/com.android.backuptest/shared_prefs/raw.xml ; \
echo -n first file > /data/data/com.android.backuptest/files/file.txt ; \
echo -n asdf > /data/data/com.android.backuptest/files/another_file.txt ; \
echo -n "" > /data/data/com.android.backuptest/files/empty.txt ; \
date >> /data/data/com.android.backuptest/files/3.txt ; \
"
# echo -n 3 > /data/data/com.android.backuptest/files/3.txt ; \
# say that the data has changed
a shell bmgr backup com.android.backuptest
# run the backup
a shell bmgr run

View File

@@ -0,0 +1,33 @@
#!/bin/bash
# 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.
export ADB_OPTS="$@"
# run adb with options
function a { $DRY_RUN adb $ADB_OPTS "$@"; }
# restart adb as root and wait for it to come back again
function adb_root
{
root_status=$(a root)
if [ "$root_status" != "adbd is already running as root" ]; then
echo -n "Restarting adb as root..."
sleep 2
a 'wait-for-device'
echo done.
fi
}

111
base/tests/backup/test_restore.sh Executable file
View File

@@ -0,0 +1,111 @@
#!/bin/bash
# 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.
# uncomment for debugging
#export DRY_RUN="echo"
source test_backup_common.sh
[ -z "$BUGREPORT_DIR" ] && BUGREPORT_DIR="$HOME/backup/bugreports"
function check_file
{
data=$(a shell cat /data/data/com.android.backuptest/$1)
if [ "$data" = "$2" ] ; then
echo "$1 has correct value [$2]"
return 0
else
echo $1 is INCORRECT
echo " value: [$data]"
echo " expected: [$2]"
return 1
fi
}
function check_exists
{
# return 0 if file exists, 1 otherwise
data=$(a shell "ls $@ 2> /dev/null >/dev/null && echo -n exists")
if [ "$data" = "exists" ]; then
return 0
else
return 1
fi
}
# Make sure adb is root so we can poke at com.android.backuptest's data
adb_root
# delete the old data
echo --- Previous files
a shell "ls -l /data/data/com.android.backuptest/files"
a shell "rm /data/data/com.android.backuptest/files/*"
echo --- Previous shared_prefs
a shell "ls -l /data/data/com.android.backuptest/shared_prefs"
a shell "rm /data/data/com.android.backuptest/shared_prefs/*"
echo --- Erased files and shared_prefs
a shell "ls -l /data/data/com.android.backuptest/files"
a shell "ls -l /data/data/com.android.backuptest/shared_prefs"
echo ---
echo
echo
# FIXME: there's probably a smarter way to do this
# FIXME: if we can get the android ID, that's probably the safest thing to do
# pick the most recent set and restore from it
restore_set=$(a shell bmgr list sets | head -n1 | awk '{print $1}')
# run the restore
echo "Restoring from set [$restore_set]"
a shell bmgr restore "$restore_set"
echo
echo
# check the results
export need_bug=0
# make sure files have the expected contents
check_file files/file.txt "first file" || need_bug=1
check_file files/another_file.txt "asdf" || need_bug=1
#check_file files/3.txt "3" || need_bug=1
check_file files/empty.txt "" || need_bug=1
check_file shared_prefs/raw.xml '<map><int name="pref" value="1" /></map>' || need_bug=1
# make sure that missing files weren't somehow created
check_exists files/file_doesnt_exist.txt && need_bug=1
check_exists files/no_files_here.txt && need_bug=1
if [ \( "$need_bug" -ne 0 \) -a -d "$BUGREPORT_DIR" ]; then
dev_id=$(a get-serialno)
filename="${dev_id}_`date +%s`"
echo "Grabbing bugreport; filename is $filename"
a bugreport > "$BUGREPORT_DIR/$filename.txt"
fi
echo
echo --- Restored files
a shell "ls -l /data/data/com.android.backuptest/files"
echo --- Restored shared_prefs
a shell "ls -l /data/data/com.android.backuptest/shared_prefs"
echo ---
echo
echo "Last 3 timestamps in 3.txt:"
a shell cat /data/data/com.android.backuptest/files/3.txt | tail -n 3
exit $need_bug