Skip to content

Commit

Permalink
AOSP/Email - Added WidgetService#isWidgetSupported to check if widget…
Browse files Browse the repository at this point in the history
…s are supported on the device and avoid calling AppWidgetManager#getInstance if not supported to avoid NullPointerException.

+ AppWidgetManager#getInstance will return null from Android-P on those devices according to b/79158204. getCurrentWidgetIds returns empty widgets if it is nor supported.

+ Fixed the email tests so that they all pass.

+ Bumped the targetSdkVersion to 21 to be consistent across Email and UnifiedEmail.

Bug: 120461090

Test: manual - Ran the following CTS tests on Pixel phone. Tested the email UI.

$ make -j 40
  -rw-r--r-- 1 rtenneti primarygroup 6836038 Dec 11 15:50 out/target/product/marlin/system/app/Email/Email.apk

$ make UnifiedEmailTests -j
  -rw-r--r-- 1 rtenneti primarygroup 303511 Dec 11 15:51 out/target/product/marlin/data/app/UnifiedEmailTests/UnifiedEmailTests.apk

$ make EmailTests -j
  -rw-r--r-- 1 rtenneti primarygroup 365023 Dec 11 15:51 out/target/product/marlin/testcases/EmailTests/EmailTests.apk

$ adb install -r out/target/product/marlin/system/app/Email/Email.apk

  Tested sending email from [email protected] with attachments to [email protected] with the new Email App.

    Date: Tue, 11 Dec 2018 15:55:58 -0800
    Subject: Test
    From: [email protected]
    To: [email protected]
    MIME-Version: 1.0
    Content-Type: multipart/mixed; boundary="--_com.android.email_5144357158777900"

    ----_com.android.email_5144357158777900
    Content-Type: application/octet-stream; name="shared_prefs"
    Content-Transfer-Encoding: base64
    Content-Disposition: attachment; filename="shared_prefs"; size=3864

    ----_com.android.email_5144357158777900--

$ adb install -r out/target/product/marlin/data/app/UnifiedEmailTests/UnifiedEmailTests.apk
$ adb install -r out/target/product/marlin/testcases/EmailTests/EmailTests.apk
$ adb shell am instrument -w com.android.email.tests
  Time: 2.04
  OK (157 tests)

+ No exceptions in AppWidgetManager class or getCurrentWidgetIds
+ logcat output is at https://rtenneti.users.x20web.corp.google.com/logcat/logcat.out.message.1211.1542

Change-Id: I5843c2990340995627b45ceace5e3f660b0101b8
  • Loading branch information
rtenneti-google committed Dec 12, 2018
1 parent 5470708 commit 0bbc136
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 4 deletions.
2 changes: 1 addition & 1 deletion emailcommon/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.android.emailcommon"
android:versionCode="1">
<uses-sdk android:targetSdkVersion="19" android:minSdkVersion="14" />
<uses-sdk android:targetSdkVersion="21" android:minSdkVersion="14" />
</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -263,14 +263,17 @@ public final Result get() throws InterruptedException, ExecutionException {
return mInnerTask.get();
}

@VisibleForTesting
/* package */ final Result callDoInBackgroundForTest(Params... params) {
return mInnerTask.doInBackground(params);
}

@VisibleForTesting
/* package */ final void callOnCancelledForTest(Result result) {
mInnerTask.onCancelled(result);
}

@VisibleForTesting
/* package */ final void callOnPostExecuteForTest(Result result) {
mInnerTask.onPostExecute(result);
}
Expand Down
4 changes: 4 additions & 0 deletions proguard-test.flags
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,12 @@
*** tempFileExistsForTest();
}

-keepclasseswithmembers class com.android.emailcommon.utility.EmailAsyncTask {
*** callDoInBackgroundForTest(Params...);
}
-keepclasseswithmembers class com.android.emailcommon.utility.EmailAsyncTask$Tracker {
<init>();
*** getTaskCountForTest();
*** containsTaskForTest(com.android.emailcommon.utility.EmailAsyncTask);
}
-keep class com.android.emailcommon.utility.DelayedOperations
2 changes: 1 addition & 1 deletion proguard.flags
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
}

-keep class com.android.email.activity.setup.AccountSetupFinal
-keep class com.android.email.activity.setup.AccountSettingsFragment
-keep class com.android.email.activity.setup.AccountSettingsFragment
4 changes: 4 additions & 0 deletions provider_src/com/android/email/provider/EmailProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@
import com.android.mail.utils.MimeType;
import com.android.mail.utils.Utils;
import com.android.mail.widget.BaseWidgetProvider;
import com.android.mail.widget.WidgetService;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
Expand Down Expand Up @@ -6139,6 +6140,9 @@ private void notifyWidgets(long mailboxId) {
Context context = getContext();
// Lazily initialize these
if (mAppWidgetManager == null) {
if (!WidgetService.isWidgetSupported(context)) {
return;
}
mAppWidgetManager = AppWidgetManager.getInstance(context);
mEmailComponent = new ComponentName(context, WidgetProvider.getProviderName(context));
}
Expand Down
10 changes: 8 additions & 2 deletions tests/src/com/android/email/ThrottleTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.android.email;

import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.test.AndroidTestCase;
import android.test.suitebuilder.annotation.SmallTest;
Expand All @@ -37,7 +38,8 @@ public class ThrottleTest extends AndroidTestCase {
private final CountingRunnable mRunnable = new CountingRunnable();
private final MockClock mClock = new MockClock();
private final MockTimer mTimer = new MockTimer(mClock);
private final Throttle mTarget = new Throttle("test", mRunnable, new CallItNowHandler(),
private final Throttle mTarget = new Throttle("test", mRunnable,
new CallItNowHandler(Looper.getMainLooper()),
MIN_TIMEOUT, MAX_TIMEOUT, mClock, mTimer);

/**
Expand Down Expand Up @@ -155,9 +157,13 @@ public void run() {

/**
* Dummy {@link Handler} that executes {@link Runnable}s passed to {@link Handler#post}
* immediately on the current thread.
* immediately via the provided {@link Looper}.
*/
private static class CallItNowHandler extends Handler {
public CallItNowHandler(Looper looper) {
super(looper);
}

@Override
public boolean sendMessageAtTime(Message msg, long uptimeMillis) {
msg.getCallback().run();
Expand Down

0 comments on commit 0bbc136

Please sign in to comment.