summaryrefslogtreecommitdiff
path: root/packages/EasterEgg
diff options
context:
space:
mode:
authorDan Sandler <dsandler@android.com>2017-09-04 21:36:01 -0400
committerDaniel Sandler <dsandler@android.com>2017-09-07 00:23:04 +0000
commit7bcd6aa4f71a45b27a7f4486e35ebe29fa9eb507 (patch)
treecafcdda580c6f5837c7d6dbb454feba0c497868d /packages/EasterEgg
parentf4a484064bd015c3762f06b4563c5fc34586f2c5 (diff)
Cat rescue.
Change-Id: Ibeea21e14f52b018e9c130df17560c4d39f23ed3 Bug: 64305456 Fixes: 37926266 Fixes: 38349532 Test: adb shell am start -n com.android.egg/.neko.NekoActivationActivity ; \ adb shell am start -n com.android.egg/.neko.NekoLockedActivity ; \ echo "pick a dessert then press enter" ; read foo ; \ adb shell cmd jobscheduler run -f com.android.egg 42 ; \ adb shell am start -n com.android.egg/.neko.NekoLand ; \ echo "longpress your new cat and touch the share icon"
Diffstat (limited to 'packages/EasterEgg')
-rw-r--r--packages/EasterEgg/AndroidManifest.xml11
-rw-r--r--packages/EasterEgg/res/drawable/food_cookie.xml35
-rw-r--r--packages/EasterEgg/res/values/strings.xml3
-rw-r--r--packages/EasterEgg/res/xml/filepaths.xml19
-rw-r--r--packages/EasterEgg/src/com/android/egg/neko/Cat.java3
-rw-r--r--packages/EasterEgg/src/com/android/egg/neko/NekoLand.java8
-rw-r--r--packages/EasterEgg/src/com/android/egg/neko/NekoService.java28
7 files changed, 101 insertions, 6 deletions
diff --git a/packages/EasterEgg/AndroidManifest.xml b/packages/EasterEgg/AndroidManifest.xml
index 14861c261f0d..172490dc9178 100644
--- a/packages/EasterEgg/AndroidManifest.xml
+++ b/packages/EasterEgg/AndroidManifest.xml
@@ -84,5 +84,16 @@ Copyright (C) 2016 The Android Open Source Project
<action android:name="android.service.quicksettings.action.QS_TILE" />
</intent-filter>
</service>
+
+ <!-- FileProvider for sending pictures -->
+ <provider
+ android:name="android.support.v4.content.FileProvider"
+ android:authorities="com.android.egg.fileprovider"
+ android:grantUriPermissions="true"
+ android:exported="false">
+ <meta-data
+ android:name="android.support.FILE_PROVIDER_PATHS"
+ android:resource="@xml/filepaths" />
+ </provider>
</application>
</manifest>
diff --git a/packages/EasterEgg/res/drawable/food_cookie.xml b/packages/EasterEgg/res/drawable/food_cookie.xml
new file mode 100644
index 000000000000..74dd134355e2
--- /dev/null
+++ b/packages/EasterEgg/res/drawable/food_cookie.xml
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+Copyright (C) 2017 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.
+-->
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="24dp"
+ android:height="24dp"
+ android:viewportWidth="24"
+ android:viewportHeight="24">
+ <group>
+ <path
+ android:fillColor="#55FFFFFF"
+ android:fillType="evenOdd"
+ android:pathData="M5.71 18.29A8.99 8.99 0 0 0 22 13c0-3-1.46-5.65-3.71-7.29A8.99 8.99 0 0 0 2 11c0 3 1.46 5.65 3.71 7.29z"/>
+ <path
+ android:fillColor="#FFFFFFFF"
+ android:fillType="evenOdd"
+ android:pathData="M7.25 19.18A8.5 8.5 0 0 0 19.19 7.24 9 9 0 0 1 7.24 19.19z"/>
+ <path
+ android:fillColor="#55FFFFFF"
+ android:pathData="M10.5 3a0.5 0.5 0 1 1 1 0v2.05a0.5 0.5 0 1 1-1 0V3zm3.1 0.42a0.5 0.5 0 0 1 0.93 0.39l-0.8 1.88A0.5 0.5 0 1 1 12.8 5.3l0.8-1.88zm2.7 1.57a0.5 0.5 0 1 1 0.71 0.7l-1.45 1.46a0.5 0.5 0 0 1-0.7-0.71l1.44-1.45zm1.9 2.5a0.5 0.5 0 0 1 0.38 0.92l-1.9 0.77a0.5 0.5 0 0 1-0.37-0.93l1.9-0.77zM19 10.5a0.5 0.5 0 1 1 0 1h-2.05a0.5 0.5 0 0 1 0-1H19zm-0.42 3.1a0.5 0.5 0 0 1-0.39 0.93l-1.88-0.8a0.5 0.5 0 1 1 0.39-0.92l1.88 0.8zm-1.57 2.7a0.5 0.5 0 1 1-0.7 0.71l-1.46-1.45a0.5 0.5 0 0 1 0.71-0.7l1.45 1.44zm-2.5 1.9a0.5 0.5 0 1 1-0.92 0.38l-0.77-1.9a0.5 0.5 0 0 1 0.93-0.37l0.77 1.9zM11.5 19a0.5 0.5 0 1 1-1 0v-2.05a0.5 0.5 0 0 1 1 0V19zm-3.1-0.42a0.5 0.5 0 0 1-0.93-0.39l0.8-1.88A0.5 0.5 0 0 1 9.2 16.7l-0.8 1.88zm-2.7-1.57a0.5 0.5 0 1 1-0.71-0.7l1.45-1.46a0.5 0.5 0 0 1 0.7 0.71L5.7 17.01zm-1.9-2.48a0.5 0.5 0 0 1-0.38-0.92l1.88-0.8a0.5 0.5 0 0 1 0.4 0.92l-1.9 0.8zM3 11.5a0.5 0.5 0 1 1 0-1h2.05a0.5 0.5 0 1 1 0 1H3zm0.42-3.1A0.5 0.5 0 0 1 3.8 7.46l1.88 0.8A0.5 0.5 0 1 1 5.3 9.2L3.42 8.4zm1.57-2.7a0.5 0.5 0 1 1 0.7-0.71l1.46 1.45a0.5 0.5 0 0 1-0.71 0.7L4.99 5.7zm2.5-1.9A0.5 0.5 0 0 1 8.4 3.41l0.77 1.9a0.5 0.5 0 0 1-0.93 0.37L7.48 3.8z"/>
+ </group>
+</vector> \ No newline at end of file
diff --git a/packages/EasterEgg/res/values/strings.xml b/packages/EasterEgg/res/values/strings.xml
index 8478a438a0e4..61e38342872e 100644
--- a/packages/EasterEgg/res/values/strings.xml
+++ b/packages/EasterEgg/res/values/strings.xml
@@ -17,6 +17,7 @@ Copyright (C) 2016 The Android Open Source Project
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<string name="app_name" translatable="false">Android Easter Egg</string>
<string name="notification_name" translatable="false">Android Neko</string>
+ <string name="notification_channel_name" translatable="false">New cats</string>
<string name="default_tile_name" translatable="false">\????</string>
<string name="notification_title" translatable="false">A cat is here.</string>
<string name="default_cat_name" translatable="false">Cat #%s</string>
@@ -34,7 +35,7 @@ Copyright (C) 2016 The Android Open Source Project
<item>@drawable/food_bits</item>
<item>@drawable/food_sysuituna</item>
<item>@drawable/food_chicken</item>
- <item>@drawable/food_donut</item>
+ <item>@drawable/food_cookie</item>
</array>
<integer-array name="food_intervals">
<item>0</item>
diff --git a/packages/EasterEgg/res/xml/filepaths.xml b/packages/EasterEgg/res/xml/filepaths.xml
new file mode 100644
index 000000000000..2130025e9265
--- /dev/null
+++ b/packages/EasterEgg/res/xml/filepaths.xml
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+Copyright (C) 2017 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.
+-->
+<paths>
+ <external-path name="cats" path="Pictures/Cats" />
+</paths> \ No newline at end of file
diff --git a/packages/EasterEgg/src/com/android/egg/neko/Cat.java b/packages/EasterEgg/src/com/android/egg/neko/Cat.java
index a4df372ef835..dd1bd07f3298 100644
--- a/packages/EasterEgg/src/com/android/egg/neko/Cat.java
+++ b/packages/EasterEgg/src/com/android/egg/neko/Cat.java
@@ -31,6 +31,8 @@ import java.util.concurrent.ThreadLocalRandom;
import com.android.egg.R;
import com.android.internal.logging.MetricsLogger;
+import static com.android.egg.neko.NekoLand.CHAN_ID;
+
public class Cat extends Drawable {
public static final long[] PURR = {0, 40, 20, 40, 20, 40, 20, 40, 20, 40, 20, 40};
@@ -218,6 +220,7 @@ public class Cat extends Drawable {
.setContentText(getName())
.setContentIntent(PendingIntent.getActivity(context, 0, intent, 0))
.setAutoCancel(true)
+ .setChannel(CHAN_ID)
.setVibrate(PURR)
.addExtras(extras);
}
diff --git a/packages/EasterEgg/src/com/android/egg/neko/NekoLand.java b/packages/EasterEgg/src/com/android/egg/neko/NekoLand.java
index 689e38142988..d2e37d8779d1 100644
--- a/packages/EasterEgg/src/com/android/egg/neko/NekoLand.java
+++ b/packages/EasterEgg/src/com/android/egg/neko/NekoLand.java
@@ -31,6 +31,7 @@ import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore.Images;
+import android.support.v4.content.FileProvider;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
@@ -56,6 +57,8 @@ import java.util.Comparator;
import java.util.List;
public class NekoLand extends Activity implements PrefsListener {
+ public static String CHAN_ID = "EGG";
+
public static boolean DEBUG = false;
public static boolean DEBUG_NOTIFICATIONS = false;
@@ -289,10 +292,13 @@ public class NekoLand extends Activity implements PrefsListener {
new String[] {png.toString()},
new String[] {"image/png"},
null);
- Uri uri = Uri.fromFile(png);
+ Log.v("Neko", "cat file: " + png);
+ Uri uri = FileProvider.getUriForFile(this, "com.android.egg.fileprovider", png);
+ Log.v("Neko", "cat uri: " + uri);
Intent intent = new Intent(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_STREAM, uri);
intent.putExtra(Intent.EXTRA_SUBJECT, cat.getName());
+ intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
intent.setType("image/png");
startActivity(Intent.createChooser(intent, null));
cat.logShare(this);
diff --git a/packages/EasterEgg/src/com/android/egg/neko/NekoService.java b/packages/EasterEgg/src/com/android/egg/neko/NekoService.java
index 808ec361fb4f..42506e61d2ec 100644
--- a/packages/EasterEgg/src/com/android/egg/neko/NekoService.java
+++ b/packages/EasterEgg/src/com/android/egg/neko/NekoService.java
@@ -15,15 +15,15 @@
package com.android.egg.neko;
import android.app.Notification;
+import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.job.JobInfo;
import android.app.job.JobParameters;
import android.app.job.JobScheduler;
import android.app.job.JobService;
-import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
-import android.content.Intent;
+import android.net.Uri;
import android.os.Bundle;
import java.util.List;
@@ -33,6 +33,9 @@ import com.android.egg.R;
import java.util.Random;
+import static com.android.egg.neko.Cat.PURR;
+import static com.android.egg.neko.NekoLand.CHAN_ID;
+
public class NekoService extends JobService {
private static final String TAG = "NekoService";
@@ -40,6 +43,7 @@ public class NekoService extends JobService {
public static int JOB_ID = 42;
public static int CAT_NOTIFICATION = 1;
+ public static int DEBUG_NOTIFICATION = 1234;
public static float CAT_CAPTURE_PROB = 1.0f; // generous
@@ -50,6 +54,18 @@ public class NekoService extends JobService {
public static float INTERVAL_JITTER_FRAC = 0.25f;
+ private static void setupNotificationChannels(Context context) {
+ NotificationManager noman = context.getSystemService(NotificationManager.class);
+ NotificationChannel eggChan = new NotificationChannel(CHAN_ID,
+ context.getString(R.string.notification_channel_name),
+ NotificationManager.IMPORTANCE_DEFAULT);
+ eggChan.setSound(Uri.EMPTY, Notification.AUDIO_ATTRIBUTES_DEFAULT); // cats are quiet
+ eggChan.setVibrationPattern(PURR); // not totally quiet though
+ eggChan.setBlockableSystem(true); // unlike a real cat, you can push this one off your lap
+ eggChan.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC); // cats sit in the window
+ noman.createNotificationChannel(eggChan);
+ }
+
@Override
public boolean onStartJob(JobParameters params) {
Log.v(TAG, "Starting job: " + String.valueOf(params));
@@ -64,8 +80,9 @@ public class NekoService extends JobService {
final Notification.Builder builder
= cat.buildNotification(this)
.setContentTitle("DEBUG")
+ .setChannel(NekoLand.CHAN_ID)
.setContentText("Ran job: " + params);
- noman.notify(1, builder.build());
+ noman.notify(DEBUG_NOTIFICATION, builder.build());
}
final PrefState prefs = new PrefState(this);
@@ -111,6 +128,8 @@ public class NekoService extends JobService {
}
public static void registerJob(Context context, long intervalMinutes) {
+ setupNotificationChannels(context);
+
JobScheduler jss = context.getSystemService(JobScheduler.class);
jss.cancel(JOB_ID);
long interval = intervalMinutes * MINUTES;
@@ -126,12 +145,13 @@ public class NekoService extends JobService {
if (NekoLand.DEBUG_NOTIFICATIONS) {
NotificationManager noman = context.getSystemService(NotificationManager.class);
- noman.notify(500, new Notification.Builder(context)
+ noman.notify(DEBUG_NOTIFICATION, new Notification.Builder(context)
.setSmallIcon(R.drawable.stat_icon)
.setContentTitle(String.format("Job scheduled in %d min", (interval / MINUTES)))
.setContentText(String.valueOf(jobInfo))
.setPriority(Notification.PRIORITY_MIN)
.setCategory(Notification.CATEGORY_SERVICE)
+ .setChannel(NekoLand.CHAN_ID)
.setShowWhen(true)
.build());
}