Permalink
Browse files

Got rid of old asm and great expectations jars since they were interf…

…ering with using Robolectric 2. Also got rid of C2DM

We'll replace GreatExpectations with Fest soon.
  • Loading branch information...
1 parent cf41668 commit 1631af577e3d56ace7bd2f2946c9ed424c7ff51d David Varvel and Phil Goodwin committed Feb 26, 2013
View
@@ -4,49 +4,27 @@
android:versionCode="1"
android:versionName="1.0">
- <!-- These permissions are required for C2DM -->
- <!-- Only this application can receive the messages and registration result -->
- <permission android:name="com.example.android.sampleapp.permission.C2D_MESSAGE"
- android:protectionLevel="signature"/>
- <uses-permission android:name="com.example.android.sampleapp.permission.C2D_MESSAGE"/>
- <!-- This app has permission to register and receive message -->
- <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE"/>
- <!-- Send the registration id to the server. Many apps will want this permission even when C2DM is not needed. -->
- <uses-permission android:name="android.permission.INTERNET"/>
- <!-- End of C2DM permissions -->
-
- <application
- android:label="@string/app_name"
- android:icon="@drawable/icon"
- android:name=".MySampleApplication">
- <activity android:name=".StarterActivity"
- android:label="@string/app_name">
- <intent-filter>
- <action android:name="android.intent.action.MAIN"/>
- <category android:name="android.intent.category.LAUNCHER"/>
- </intent-filter>
- </activity>
+ <!-- These permissions are required for C2DM -->
+ <!-- Only this application can receive the messages and registration result -->
+ <permission android:name="com.example.android.sampleapp.permission.C2D_MESSAGE"
+ android:protectionLevel="signature"/>
+ <uses-permission android:name="com.example.android.sampleapp.permission.C2D_MESSAGE"/>
+ <!-- This app has permission to register and receive message -->
+ <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE"/>
+ <!-- Send the registration id to the server. Many apps will want this permission even when C2DM is not needed. -->
+ <uses-permission android:name="android.permission.INTERNET"/>
+ <!-- End of C2DM permissions -->
- <!-- C2DM START C2DM START C2DM START C2DM START C2DM START C2DM START C2DM START -->
- <!-- C2DM Note: C2DM is only supported in API v2.2 and above but is safely ignored in lower versions -->
- <!--NOTE FOR C2DM: Read http://code.google.com/android/c2dm/#manifest but note that the XML is wrong! -->
- <!--Use this pattern instead.-->
- <service android:name=".C2DMReceiver"/>
- <!-- Only C2DM servers can send messages for the app. If permission is not set - any other app can generate it -->
- <receiver android:name="com.google.android.c2dm.C2DMBroadcastReceiver"
- android:permission="com.google.android.c2dm.permission.SEND">
- <!-- Receive the actual message -->
- <intent-filter>
- <action android:name="com.google.android.c2dm.intent.RECEIVE"/>
- <category android:name="com.example.android.sampleapp"/>
- </intent-filter>
- <!-- Receive the registration id -->
- <intent-filter>
- <action android:name="com.google.android.c2dm.intent.REGISTRATION"/>
- <category android:name="com.example.android.sampleapp"/>
- </intent-filter>
- </receiver>
- <!--C2DM END C2DM END C2DM END C2DM END C2DM END C2DM END C2DM END C2DM END C2DM END-->
-
- </application>
+ <application
+ android:label="@string/app_name"
+ android:icon="@drawable/icon"
+ android:name=".MySampleApplication">
+ <activity android:name=".StarterActivity"
+ android:label="@string/app_name">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN"/>
+ <category android:name="android.intent.category.LAUNCHER"/>
+ </intent-filter>
+ </activity>
+ </application>
</manifest>
View
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,90 +0,0 @@
-package com.example.android.sampleapp;
-
-import android.content.Context;
-import android.content.Intent;
-import com.google.android.c2dm.C2DMBaseReceiver;
-
-import java.io.IOException;
-
-/**
- * NOTE: C2DM is supported in API v.2.2 and above but is safely ignored in lower versions.
- *
- * C2DMBaseReceiver.runIntentInService demands that this class exist at the same package
- * defined in the AndroidManifest.package; ex: com.example.android.sampleapp.C2DMReceiver
- *
- * Read and understand http://code.google.com/android/c2dm/, but note that the XML listed in the Manifest section
- * is wrong! Use the pattern you see in AndroidManifest.xml of this project instead.
- */
-public class C2DMReceiver extends C2DMBaseReceiver {
-
- /**
- * The senderId is a google email address, such as a gmail address or a apps-for-your-domain gmail address.
- * Use the same address when registering a device with C2DM.
- */
- public C2DMReceiver() {
- super("example@a_google_acount.com");
- }
-
- /**
- * Called when a C2DM message is received.
- * context: a Context
- * intent: this is the Intent broadcast by Android. This Intent has extras with the format described
- * at http://code.google.com/android/c2dm/#push.
- *
- * Getting data from the intent: if a C2DM message sent by a server with params "data.myInfo"
- * retrieve that data by calling intent.getExtras().getString("myInfo") -- *not* "data.myInfo"
- *
- * Setting Notifications in the Notification Bar: this is done by passing PendingIntents to a NotificationManager.
- * See http://developer.android.com/reference/android/app/PendingIntent.html
- *
- * Handling the "Clear All" button in the Notification Bar: set PendingIntent.deleteIntent. This will be called
- * automatically by Android. You will need to handle the broadcast of that Intent yourself.
- */
- @Override
- protected void onMessage(Context context, Intent intent) {
- }
-
- /**
- * @param context
- * @param registrationId - key Google uses to identify this device.
- * @throws IOException
- *
- * See http://code.google.com/android/c2dm/#handling_reg
- *
- * Overview: You will need to broadcast an Intent to register with the C2DM service; for example, when a
- * user logs in to the application -- see http://code.google.com/android/c2dm/#registering. This method is
- * called if that registration succeeds.
- *
- * Warning: Failure to unregister a device before re-registering might result in devices with multiple
- * registration_ids and might receiving duplicate notifications.
- */
- @Override
- public void onRegistered(Context context, String registrationId) throws IOException {
- super.onRegistered(context, registrationId);
- }
-
- /**
- * @param context
- * @param errorId one of C2DMBaseReceiver.ERR_SERVICE_NOT_AVAILABLE, etc.
- *
- * Called on Registration error. See http://code.google.com/android/c2dm/#handling_reg
- */
- @Override
- public void onError(Context context, String errorId) {
- }
-
- /**
- * @param context
- *
- * Overview: You will need to broadcast an Intent to unregister with the C2DM service; for example, when a
- * user logs out to the application -- see http://code.google.com/android/c2dm/#unregistering. This method is
- * called if that un-registration succeeds.
- *
- * Warning: Failure to unregister a device before re-registering might result in devices with multiple
- * registration_ids and might receiving duplicate notifications.
- */
- @Override
- public void onUnregistered(Context context) {
- super.onUnregistered(context);
- }
-}
@@ -1,197 +0,0 @@
-/*
- * Copyright 2010 Google Inc.
- *
- * 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.google.android.c2dm;
-
-import android.app.AlarmManager;
-import android.app.PendingIntent;
-import android.content.Context;
-import android.content.Intent;
-import android.os.PowerManager;
-import android.util.Log;
-import roboguice.service.RoboIntentService;
-
-import java.io.IOException;
-
-/**
- * Base class for C2D message receiver. Includes constants for the
- * strings used in the protocol.
- *
- * Pivotal Labs NOTE: This class has been edited to extends RoboIntentService to support dependency injection
- */
-public abstract class C2DMBaseReceiver extends RoboIntentService {
- private static final String C2DM_RETRY = "com.google.android.c2dm.intent.RETRY";
-
- public static final String REGISTRATION_CALLBACK_INTENT = "com.google.android.c2dm.intent.REGISTRATION";
- private static final String C2DM_INTENT = "com.google.android.c2dm.intent.RECEIVE";
-
- // Logging tag
- private static final String TAG = "C2DM";
-
- // Extras in the registration callback intents.
- public static final String EXTRA_UNREGISTERED = "unregistered";
-
- public static final String EXTRA_ERROR = "error";
-
- public static final String EXTRA_REGISTRATION_ID = "registration_id";
-
- public static final String ERR_SERVICE_NOT_AVAILABLE = "SERVICE_NOT_AVAILABLE";
- public static final String ERR_ACCOUNT_MISSING = "ACCOUNT_MISSING";
- public static final String ERR_AUTHENTICATION_FAILED = "AUTHENTICATION_FAILED";
- public static final String ERR_TOO_MANY_REGISTRATIONS = "TOO_MANY_REGISTRATIONS";
- public static final String ERR_INVALID_PARAMETERS = "INVALID_PARAMETERS";
- public static final String ERR_INVALID_SENDER = "INVALID_SENDER";
- public static final String ERR_PHONE_REGISTRATION_ERROR = "PHONE_REGISTRATION_ERROR";
-
- // wakelock
- private static final String WAKELOCK_KEY = "C2DM_LIB";
-
- private static PowerManager.WakeLock mWakeLock;
- private final String senderId;
-
- /**
- * The C2DMReceiver class must create a no-arg constructor and pass the
- * sender id to be used for registration.
- */
- public C2DMBaseReceiver(String senderId) {
- // senderId is used as base name for threads, etc.
- super(senderId);
- this.senderId = senderId;
- }
-
- /**
- * Called when a cloud message has been received.
- */
- protected abstract void onMessage(Context context, Intent intent);
-
- /**
- * Called on registration error. Override to provide better
- * error messages.
- *
- * This is called in the context of a Service - no dialog or UI.
- */
- public abstract void onError(Context context, String errorId);
-
- /**
- * Called when a registration token has been received.
- */
- public void onRegistered(Context context, String registrationId) throws IOException {
- // registrationId will also be saved
- }
-
- /**
- * Called when the device has been unregistered.
- */
- public void onUnregistered(Context context) {
- }
-
-
- @Override
- public final void onHandleIntent(Intent intent) {
- try {
- Context context = getApplicationContext();
- if (intent.getAction().equals(REGISTRATION_CALLBACK_INTENT)) {
- handleRegistration(context, intent);
- } else if (intent.getAction().equals(C2DM_INTENT)) {
- onMessage(context, intent);
- } else if (intent.getAction().equals(C2DM_RETRY)) {
- C2DMessaging.register(context, senderId);
- }
- } finally {
- // Release the power lock, so phone can get back to sleep.
- // The lock is reference counted by default, so multiple
- // messages are ok.
-
- // If the onMessage() needs to spawn a thread or do something else,
- // it should use it's own lock.
- mWakeLock.release();
- }
- }
-
-
- /**
- * Called from the broadcast receiver.
- * Will process the received intent, call handleMessage(), registered(), etc.
- * in background threads, with a wake lock, while keeping the service
- * alive.
- */
- static void runIntentInService(Context context, Intent intent) {
- if (mWakeLock == null) {
- // This is called from BroadcastReceiver, there is no init.
- PowerManager pm =
- (PowerManager) context.getSystemService(Context.POWER_SERVICE);
- mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
- WAKELOCK_KEY);
- }
- mWakeLock.acquire();
-
- // Use a naming convention, similar with how permissions and intents are
- // used. Alternatives are introspection or an ugly use of statics.
- String receiver = context.getPackageName() + ".C2DMReceiver";
- intent.setClassName(context, receiver);
-
- context.startService(intent);
-
- }
-
-
- private void handleRegistration(final Context context, Intent intent) {
- final String registrationId = intent.getStringExtra(EXTRA_REGISTRATION_ID);
- String error = intent.getStringExtra(EXTRA_ERROR);
- String removed = intent.getStringExtra(EXTRA_UNREGISTERED);
-
- if (Log.isLoggable(TAG, Log.DEBUG)) {
- Log.d(TAG, "dmControl: registrationId = " + registrationId +
- ", error = " + error + ", removed = " + removed);
- }
-
- if (removed != null) {
- // Remember we are unregistered
- C2DMessaging.clearRegistrationId(context);
- onUnregistered(context);
- return;
- } else if (error != null) {
- // we are not registered, can try again
- C2DMessaging.clearRegistrationId(context);
- // Registration failed
- Log.e(TAG, "Registration error " + error);
- onError(context, error);
- if ("SERVICE_NOT_AVAILABLE".equals(error)) {
- long backoffTimeMs = C2DMessaging.getBackoff(context);
-
- Log.d(TAG, "Scheduling registration retry, backoff = " + backoffTimeMs);
- Intent retryIntent = new Intent(C2DM_RETRY);
- PendingIntent retryPIntent = PendingIntent.getBroadcast(context,
- 0 /*requestCode*/, retryIntent, 0 /*flags*/);
-
- AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
- am.set(AlarmManager.ELAPSED_REALTIME,
- backoffTimeMs, retryPIntent);
-
- // Next retry should wait longer.
- backoffTimeMs *= 2;
- C2DMessaging.setBackoff(context, backoffTimeMs);
- }
- } else {
- try {
- onRegistered(context, registrationId);
- C2DMessaging.setRegistrationId(context, registrationId);
- } catch (IOException ex) {
- Log.e(TAG, "Registration error " + ex.getMessage());
- }
- }
- }
-}
@@ -1,25 +0,0 @@
-/*
- */
-package com.google.android.c2dm;
-
-import android.app.Activity;
-import android.content.BroadcastReceiver;
-import android.content.Context;
-import android.content.Intent;
-
-/**
- * Helper class to handle BroadcastReciver behavior.
- * - can only run for a limited amount of time - it must start a real service
- * for longer activity
- * - must get the power lock, must make sure it's released when all done.
- *
- */
-public class C2DMBroadcastReceiver extends BroadcastReceiver {
-
- @Override
- public final void onReceive(Context context, Intent intent) {
- // To keep things in one place.
- C2DMBaseReceiver.runIntentInService(context, intent);
- setResult(Activity.RESULT_OK, null /* data */, null /* extra */);
- }
-}
Oops, something went wrong.

0 comments on commit 1631af5

Please sign in to comment.