Skip to content

Commit

Permalink
Update SDK target level to 26. Implements #703 (#719)
Browse files Browse the repository at this point in the history
This also updates the support library version to 26.1.0.
Due to changes in Android 8 we had to limit some background service and broadcast functionality. There are no limitations to the user experience though, but some planned features may require a different solution now (mostly because implicit broadcasts no longer work).
  • Loading branch information
dmfs authored Nov 7, 2018
1 parent 7396a2d commit c5fdbdd
Show file tree
Hide file tree
Showing 16 changed files with 195 additions and 39 deletions.
7 changes: 6 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,17 @@ android:
- tools
- platform-tools
- tools
- build-tools-26.0.2
- build-tools-27.0.1
- android-24
- android-25
- android-26
- extra
- extra-android-m2repository
- sys-img-armeabi-v7a-android-24

# Emulator Management: Create, Start and Wait
before_script:
- android list targets
- echo no | android create avd --force -n test --target android-24 --abi armeabi-v7a
- QEMU_AUDIO_DRV=none emulator -avd test -no-window &
- android-wait-for-emulator
Expand All @@ -26,3 +28,6 @@ before_script:
script:
- android list target
- ./gradlew check connectedAndroidTest

after_script:
- cat /home/travis/build/dmfs/opentasks/opentasks/build/reports/lint-results.xml
2 changes: 1 addition & 1 deletion dependencies.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
def support_lib_version = '25.4.0'
def support_lib_version = '26.1.0'
def jems_version = '1.15'
def contentpal_version = '9b087b2' // 9b087b2 -> 2017-12-12
def support_test_runner_version = '0.5'
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
COMPILE_SDK_VERSION=25
COMPILE_SDK_VERSION=26
BUILD_TOOLS_VERSION=27.0.1
MIN_SDK_VERSION=15
TARGET_SDK_VERSION=25
TARGET_SDK_VERSION=26
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.net.Uri;
import android.os.Build;
import android.os.Handler;
import android.util.Log;

Expand Down Expand Up @@ -183,6 +184,11 @@ private void sendBroadcast(Context context, String action, Uri uri, DateTime dat
intent.putExtra(TaskContract.EXTRA_TASK_TIMEZONE, datetime.getTimeZone().getID());
}
intent.putExtra(TaskContract.EXTRA_TASK_TITLE, title);
if (Build.VERSION.SDK_INT >= 26)
{
// for now only notify our own package
intent.setPackage(context.getPackageName());
}
context.sendBroadcast(intent);
}
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import android.database.sqlite.SQLiteOpenHelper;
import android.database.sqlite.SQLiteQueryBuilder;
import android.net.Uri;
import android.os.Build;
import android.os.Handler;
import android.os.HandlerThread;
import android.text.TextUtils;
Expand Down Expand Up @@ -1294,6 +1295,12 @@ protected void onEndTransaction(boolean callerIsSyncAdapter)
}
// add the change log to the broadcast
providerChangedIntent.putExtras(mOperationsLog.toBundle(true));
if (Build.VERSION.SDK_INT >= 26)
{
// for now we only notify our own package
// we'll have to figure out how to do this correctly on Android 8+, e.g. how is it done by CalendarProvider and ContactsProvider
providerChangedIntent.setPackage(getContext().getPackageName());
}
getContext().sendBroadcast(providerChangedIntent);
}

Expand All @@ -1313,6 +1320,8 @@ public void onDatabaseCreated(SQLiteDatabase db)
// notify listeners that the database has been created
Intent dbInitializedIntent = new Intent(TaskContract.ACTION_DATABASE_INITIALIZED);
dbInitializedIntent.setDataAndType(TaskContract.getContentUri(mAuthority), TaskContract.MIMETYPE_AUTHORITY);
// Android SDK 26 doesn't allow us to send implicit broadcasts, this particular brodcast is only for internal use, so just make it explicit by setting our package name
dbInitializedIntent.setPackage(getContext().getPackageName());
getContext().sendBroadcast(dbInitializedIntent);
}

Expand All @@ -1322,14 +1331,7 @@ public void onDatabaseUpdate(SQLiteDatabase db, int oldVersion, int newVersion)
{
if (oldVersion < 15)
{
mAsyncHandler.post(new Runnable()
{
@Override
public void run()
{
ContentOperation.UPDATE_TIMEZONE.fire(getContext(), null);
}
});
mAsyncHandler.post(() -> ContentOperation.UPDATE_TIMEZONE.fire(getContext(), null));
}
}

Expand Down
2 changes: 1 addition & 1 deletion opentasks/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@
<!-- custom alarm receivers -->
<receiver
android:name="org.dmfs.tasks.notification.AlarmBroadcastReceiver"
android:permission="">
android:exported="false">
<intent-filter>
<action android:name="org.dmfs.android.tasks.TASK_DUE"/>

Expand Down
14 changes: 13 additions & 1 deletion opentasks/src/main/java/org/dmfs/tasks/TaskListActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import android.os.Build.VERSION;
import android.os.Bundle;
import android.os.Handler;
import android.provider.Settings;
import android.support.annotation.ColorInt;
import android.support.annotation.NonNull;
import android.support.design.widget.AppBarLayout;
Expand Down Expand Up @@ -639,7 +640,18 @@ else if (item.getItemId() == R.id.menu_visible_list)
}
else if (item.getItemId() == R.id.opentasks_menu_app_settings)
{
startActivity(new Intent(this, AppSettingsActivity.class));
if (VERSION.SDK_INT < 26)
{
startActivity(new Intent(this, AppSettingsActivity.class));
}
else
{
// for now just open the notification settings, which is all we currently support anyway
Intent intent = new Intent();
intent.setAction(Settings.ACTION_APP_NOTIFICATION_SETTINGS);
intent.putExtra(Settings.EXTRA_APP_PACKAGE, getPackageName());
startActivity(intent);
}
return true;
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Build;
import android.preference.PreferenceManager;

import org.dmfs.tasks.R;
Expand All @@ -47,6 +48,7 @@ public void onReceive(Context context, Intent intent)
{
if (isNotificationEnabled(context))
{
NotificationUpdaterService.createChannels(context);
Uri taskUri = intent.getData();

boolean noSignal = intent.getBooleanExtra(NotificationActionUtils.EXTRA_NOTIFICATION_NO_SIGNAL, false);
Expand All @@ -72,6 +74,7 @@ else if (intent.getAction().equals(TaskContract.ACTION_BROADCAST_TASK_DUE))
{
if (isNotificationEnabled(context))
{
NotificationUpdaterService.createChannels(context);
Uri taskUri = intent.getData();

boolean noSignal = intent.getBooleanExtra(NotificationActionUtils.EXTRA_NOTIFICATION_NO_SIGNAL, false);
Expand Down Expand Up @@ -100,6 +103,11 @@ else if (intent.getAction().equals(TaskContract.ACTION_BROADCAST_TASK_DUE))

public boolean isNotificationEnabled(Context context)
{
if (Build.VERSION.SDK_INT >= 26)
{
// on Android 8+ we leave this decision to Android and always attempt to show the notification
return true;
}
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context);
return settings.getBoolean(context.getString(R.string.opentasks_pref_notification_enabled), true);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ public static void sendDueAlarmNotification(Context context, String title, Uri t
}

// build notification
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context).setSmallIcon(R.drawable.ic_notification)
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context, NotificationUpdaterService.CHANNEL_DUE_DATES).setSmallIcon(
R.drawable.ic_notification)
.setContentTitle(title).setContentText(dueString);

// color
Expand Down Expand Up @@ -172,7 +173,8 @@ public static void sendStartNotification(Context context, String title, Uri task
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

// build notification
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context).setSmallIcon(R.drawable.ic_notification)
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context, NotificationUpdaterService.CHANNEL_DUE_DATES).setSmallIcon(
R.drawable.ic_notification)
.setContentTitle(title).setContentText(startString);

// color
Expand Down Expand Up @@ -251,7 +253,7 @@ public static PendingIntent getNotificationActionPendingIntent(Context context,
*/
public static void createUndoNotification(final Context context, NotificationAction action)
{
NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
NotificationCompat.Builder builder = new NotificationCompat.Builder(context, NotificationUpdaterService.CHANNEL_DUE_DATES);
builder.setContentTitle(context.getString(action.getActionTextResId()

));
Expand Down
Loading

0 comments on commit c5fdbdd

Please sign in to comment.