Merge branch 'gingerbread' into gingerbread-release

This commit is contained in:
The Android Automerger
2010-10-04 07:13:13 -07:00
7 changed files with 176 additions and 32 deletions

View File

@@ -31,5 +31,13 @@
<activity android:name="TagSelector"></activity>
<activity android:name="TagList"></activity>
<receiver android:name=".TagBroadcastReceiver">
<intent-filter>
<action android:name= "com.trustedlogic.trustednfc.android.action.NDEF_TAG_DISCOVERED"/>
</intent-filter>
</receiver>
</application>
<uses-permission android:name="com.trustedlogic.trustednfc.permission.NFC_NOTIFY"></uses-permission>
<uses-permission android:name="com.trustedlogic.trustednfc.permission.NFC_RAW"></uses-permission>
</manifest>

View File

@@ -0,0 +1,52 @@
/*
* Copyright (C) 2010 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.apps.tag;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.widget.Toast;
import com.trustedlogic.trustednfc.android.NdefMessage;
import com.trustedlogic.trustednfc.android.NdefRecord;
import com.trustedlogic.trustednfc.android.NfcManager;
/**
* This class doesn't work. Sorry. Think of this class as pseudo
* code for now.
*/
public class TagBroadcastReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(NfcManager.NDEF_TAG_DISCOVERED_ACTION)) {
NdefMessage msg = intent.getParcelableExtra(NfcManager.NDEF_MESSAGE_EXTRA);
Toast.makeText(context, "got a new message", Toast.LENGTH_SHORT).show();
insertIntoDb(msg);
}
}
private void insertIntoDb(NdefMessage msg) {
for (NdefRecord record : msg.getRecords()) {
insertIntoRecordDb(record.getType(), record.getPayload());
}
}
private void insertIntoRecordDb(byte[] type, byte[] payload) {
// do something...
}
}

View File

@@ -23,23 +23,21 @@ import android.content.DialogInterface;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.provider.Contacts;
import android.view.Menu;
import android.view.View;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
import com.trustedlogic.trustednfc.android.NfcManager;
import android.widget.Toast;
/**
* @author nnk@google.com (Nick Kralevich)
*/
public class TagList extends ListActivity implements DialogInterface.OnClickListener {
private NfcManager mManager;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Toast.makeText(getBaseContext(), "entered method", Toast.LENGTH_SHORT).show();
SQLiteDatabase db = new TagDBHelper(this.getBaseContext()).getReadableDatabase();
Cursor c = db.query("Tags", new String[] { "_id", "description" }, null, null, null, null, null);
@@ -52,6 +50,9 @@ public class TagList extends ListActivity implements DialogInterface.OnClickList
setListAdapter(sca);
registerForContextMenu(getListView());
c.close();
db.close();
Toast.makeText(getBaseContext(), "exit method", Toast.LENGTH_SHORT).show();
}
@Override

View File

@@ -15,7 +15,7 @@
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.android.apps.tag">
package="com.android.apps.tag.tests">
<!-- We add an application tag here just so that we can indicate that
this package needs to link against the android.test library,
@@ -25,8 +25,8 @@
</application>
<instrumentation android:name="android.test.InstrumentationTestRunner"
android:targetPackage="com.example.android.helloactivity"
android:label="HelloActivity sample tests">
android:targetPackage="com.android.apps.tag"
android:label="Tag tests">
</instrumentation>
</manifest>

View File

@@ -0,0 +1,44 @@
/*
* Copyright (C) 2010 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.apps.tag;
import android.content.Intent;
import android.test.ActivityInstrumentationTestCase2;
/**
* @author nnk@google.com (Nick Kralevich)
*/
public class TagBroadcastReceiverTest extends ActivityInstrumentationTestCase2<Tags> {
/**
* Creates an {@link ActivityInstrumentationTestCase2} for the {@link Tags} activity.
*/
public TagBroadcastReceiverTest() {
super(Tags.class);
}
public void testWrongMessage() {
TagBroadcastReceiver receiver = new TagBroadcastReceiver();
Intent i = new Intent().setAction("BOGUS");
receiver.onReceive(getActivity().getBaseContext(), i);
assertDatabaseNoChange(receiver);
}
private void assertDatabaseNoChange(TagBroadcastReceiver receiver) {
// TODO: implement
}
}

View File

@@ -243,7 +243,7 @@ public class Monkey {
// redirected to a file?) So we allow disk writes
// around this region for the monkey to minimize
// harmless dropbox uploads from monkeys.
int savedPolicy = StrictMode.allowThreadDiskWrites();
StrictMode.ThreadPolicy savedPolicy = StrictMode.allowThreadDiskWrites();
System.out.println(" // " + (allow ? "Allowing" : "Rejecting") + " start of "
+ intent + " in package " + pkg);
StrictMode.setThreadPolicy(savedPolicy);
@@ -254,7 +254,7 @@ public class Monkey {
}
public boolean activityResuming(String pkg) {
int savedPolicy = StrictMode.allowThreadDiskWrites();
StrictMode.ThreadPolicy savedPolicy = StrictMode.allowThreadDiskWrites();
System.out.println(" // activityResuming(" + pkg + ")");
boolean allow = checkEnteringPackage(pkg) || (DEBUG_ALLOW_ANY_RESTARTS != 0);
if (!allow) {
@@ -271,7 +271,7 @@ public class Monkey {
public boolean appCrashed(String processName, int pid,
String shortMsg, String longMsg,
long timeMillis, String stackTrace) {
int savedPolicy = StrictMode.allowThreadDiskWrites();
StrictMode.ThreadPolicy savedPolicy = StrictMode.allowThreadDiskWrites();
System.err.println("// CRASH: " + processName + " (pid " + pid + ")");
System.err.println("// Short Msg: " + shortMsg);
System.err.println("// Long Msg: " + longMsg);
@@ -296,7 +296,7 @@ public class Monkey {
}
public int appNotResponding(String processName, int pid, String processStats) {
int savedPolicy = StrictMode.allowThreadDiskWrites();
StrictMode.ThreadPolicy savedPolicy = StrictMode.allowThreadDiskWrites();
System.err.println("// NOT RESPONDING: " + processName + " (pid " + pid + ")");
System.err.println(processStats);
StrictMode.setThreadPolicy(savedPolicy);
@@ -1178,4 +1178,3 @@ public class Monkey {
System.err.println(usage.toString());
}
}

View File

@@ -19,6 +19,7 @@ package com.android.commands.monkey;
import android.content.ComponentName;
import android.os.SystemClock;
import android.view.Display;
import android.view.KeyCharacterMap;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.WindowManagerImpl;
@@ -50,6 +51,18 @@ public class MonkeySourceRandom implements MonkeyEventSource {
KeyEvent.KEYCODE_VOLUME_UP, KeyEvent.KEYCODE_VOLUME_DOWN,
KeyEvent.KEYCODE_MUTE,
};
/** If a physical key exists? */
private static final boolean[] PHYSICAL_KEY_EXISTS = new boolean[KeyEvent.getMaxKeyCode() + 1];
static {
for (int i = 0; i < PHYSICAL_KEY_EXISTS.length; ++i) {
PHYSICAL_KEY_EXISTS[i] = true;
}
// Only examine SYS_KEYS
for (int i = 0; i < SYS_KEYS.length; ++i) {
PHYSICAL_KEY_EXISTS[SYS_KEYS[i]] = KeyCharacterMap.deviceHasKey(SYS_KEYS[i]);
}
}
/** Nice names for all key events. */
private static final String[] KEY_NAMES = {
"KEYCODE_UNKNOWN",
@@ -282,7 +295,6 @@ public class MonkeySourceRandom implements MonkeyEventSource {
}
// if verbose, show factors
if (mVerbose > 0) {
System.out.println("// Event percentages:");
for (int i = 0; i < FACTORZ_COUNT; ++i) {
@@ -290,6 +302,10 @@ public class MonkeySourceRandom implements MonkeyEventSource {
}
}
if (!validateKeys()) {
return false;
}
// finally, normalize and convert to running sum
float sum = 0.0f;
for (int i = 0; i < FACTORZ_COUNT; ++i) {
@@ -299,6 +315,28 @@ public class MonkeySourceRandom implements MonkeyEventSource {
return true;
}
private static boolean validateKeyCategory(String catName, int[] keys, float factor) {
if (factor < 0.1f) {
return true;
}
for (int i = 0; i < keys.length; ++i) {
if (PHYSICAL_KEY_EXISTS[keys[i]]) {
return true;
}
}
System.err.println("** " + catName + " has no physical keys but with factor " + factor + "%.");
return false;
}
/**
* See if any key exists for non-zero factors.
*/
private boolean validateKeys() {
return validateKeyCategory("NAV_KEYS", NAV_KEYS, mFactors[FACTOR_NAV])
&& validateKeyCategory("MAJOR_NAV_KEYS", MAJOR_NAV_KEYS, mFactors[FACTOR_MAJORNAV])
&& validateKeyCategory("SYS_KEYS", SYS_KEYS, mFactors[FACTOR_SYSOPS]);
}
/**
* set the factors
*
@@ -441,6 +479,7 @@ public class MonkeySourceRandom implements MonkeyEventSource {
}
// The remaining event categories are injected as key events
do {
if (cls < mFactors[FACTOR_NAV]) {
lastKey = NAV_KEYS[mRandom.nextInt(NAV_KEYS.length)];
} else if (cls < mFactors[FACTOR_MAJORNAV]) {
@@ -460,6 +499,7 @@ public class MonkeySourceRandom implements MonkeyEventSource {
} else {
lastKey = 1 + mRandom.nextInt(KeyEvent.getMaxKeyCode() - 1);
}
} while (!PHYSICAL_KEY_EXISTS[lastKey]);
MonkeyKeyEvent e = new MonkeyKeyEvent(KeyEvent.ACTION_DOWN, lastKey);
mQ.addLast(e);