Merge "Allow apps to know what users think of their notifications." into nyc-dev
am: 146d931ece
* commit '146d931ece7fc273311c049067742bab40a9999a':
Allow apps to know what users think of their notifications.
This commit is contained in:
@@ -5225,6 +5225,7 @@ package android.app {
|
||||
|
||||
public class NotificationManager {
|
||||
method public android.app.AutomaticZenRule addAutomaticZenRule(android.app.AutomaticZenRule);
|
||||
method public boolean areNotificationsEnabled();
|
||||
method public void cancel(int);
|
||||
method public void cancel(java.lang.String, int);
|
||||
method public void cancelAll();
|
||||
@@ -5232,6 +5233,7 @@ package android.app {
|
||||
method public android.app.AutomaticZenRule getAutomaticZenRule(java.lang.String);
|
||||
method public java.util.List<android.app.AutomaticZenRule> getAutomaticZenRules();
|
||||
method public final int getCurrentInterruptionFilter();
|
||||
method public int getImportance(java.lang.String);
|
||||
method public android.app.NotificationManager.Policy getNotificationPolicy();
|
||||
method public boolean isNotificationPolicyAccessGranted();
|
||||
method public void notify(int, android.app.Notification);
|
||||
|
||||
@@ -5357,6 +5357,7 @@ package android.app {
|
||||
|
||||
public class NotificationManager {
|
||||
method public android.app.AutomaticZenRule addAutomaticZenRule(android.app.AutomaticZenRule);
|
||||
method public boolean areNotificationsEnabled();
|
||||
method public void cancel(int);
|
||||
method public void cancel(java.lang.String, int);
|
||||
method public void cancelAll();
|
||||
@@ -5364,6 +5365,7 @@ package android.app {
|
||||
method public android.app.AutomaticZenRule getAutomaticZenRule(java.lang.String);
|
||||
method public java.util.List<android.app.AutomaticZenRule> getAutomaticZenRules();
|
||||
method public final int getCurrentInterruptionFilter();
|
||||
method public int getImportance(java.lang.String);
|
||||
method public android.app.NotificationManager.Policy getNotificationPolicy();
|
||||
method public boolean isNotificationPolicyAccessGranted();
|
||||
method public void notify(int, android.app.Notification);
|
||||
|
||||
@@ -5225,6 +5225,7 @@ package android.app {
|
||||
|
||||
public class NotificationManager {
|
||||
method public android.app.AutomaticZenRule addAutomaticZenRule(android.app.AutomaticZenRule);
|
||||
method public boolean areNotificationsEnabled();
|
||||
method public void cancel(int);
|
||||
method public void cancel(java.lang.String, int);
|
||||
method public void cancelAll();
|
||||
@@ -5232,6 +5233,7 @@ package android.app {
|
||||
method public android.app.AutomaticZenRule getAutomaticZenRule(java.lang.String);
|
||||
method public java.util.List<android.app.AutomaticZenRule> getAutomaticZenRules();
|
||||
method public final int getCurrentInterruptionFilter();
|
||||
method public int getImportance(java.lang.String);
|
||||
method public android.app.NotificationManager.Policy getNotificationPolicy();
|
||||
method public boolean isNotificationPolicyAccessGranted();
|
||||
method public void notify(int, android.app.Notification);
|
||||
|
||||
@@ -46,6 +46,7 @@ interface INotificationManager
|
||||
|
||||
void setNotificationsEnabledForPackage(String pkg, int uid, boolean enabled);
|
||||
boolean areNotificationsEnabledForPackage(String pkg, int uid);
|
||||
boolean areNotificationsEnabled(String pkg);
|
||||
|
||||
ParceledListSlice getTopics(String pkg, int uid);
|
||||
void setVisibilityOverride(String pkg, int uid, in Notification.Topic topic, int visibility);
|
||||
@@ -54,6 +55,7 @@ interface INotificationManager
|
||||
int getPriority(String pkg, int uid, in Notification.Topic topic);
|
||||
void setImportance(String pkg, int uid, in Notification.Topic topic, int importance);
|
||||
int getImportance(String pkg, int uid, in Notification.Topic topic);
|
||||
int getTopicImportance(String pkg, String topicId);
|
||||
boolean doesAppUseTopics(String pkg, int uid);
|
||||
boolean hasBannedTopics(String pkg, int uid);
|
||||
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
|
||||
package android.app;
|
||||
|
||||
import com.android.internal.util.Preconditions;
|
||||
|
||||
import android.annotation.NonNull;
|
||||
import android.annotation.Nullable;
|
||||
import android.annotation.SdkConstant;
|
||||
@@ -37,6 +39,7 @@ import android.os.StrictMode;
|
||||
import android.os.UserHandle;
|
||||
import android.provider.Settings.Global;
|
||||
import android.service.notification.IConditionListener;
|
||||
import android.service.notification.NotificationListenerService;
|
||||
import android.service.notification.StatusBarNotification;
|
||||
import android.service.notification.ZenModeConfig;
|
||||
import android.util.ArraySet;
|
||||
@@ -503,6 +506,25 @@ public class NotificationManager
|
||||
return false;
|
||||
}
|
||||
|
||||
public int getImportance(String topicId) {
|
||||
Preconditions.checkNotNull(topicId);
|
||||
INotificationManager service = getService();
|
||||
try {
|
||||
return service.getTopicImportance(mContext.getPackageName(), topicId);
|
||||
} catch (RemoteException e) {
|
||||
}
|
||||
return NotificationListenerService.Ranking.IMPORTANCE_UNSPECIFIED;
|
||||
}
|
||||
|
||||
public boolean areNotificationsEnabled() {
|
||||
INotificationManager service = getService();
|
||||
try {
|
||||
return service.areNotificationsEnabled(mContext.getPackageName());
|
||||
} catch (RemoteException e) {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks the ability to read/modify notification policy for the calling package.
|
||||
*
|
||||
|
||||
@@ -1261,12 +1261,20 @@ public class NotificationManagerService extends SystemService {
|
||||
setNotificationsEnabledForPackageImpl(pkg, uid, enabled);
|
||||
}
|
||||
|
||||
/**
|
||||
* Use this when you just want to know if notifications are OK for this package.
|
||||
*/
|
||||
@Override
|
||||
public boolean areNotificationsEnabled(String pkg) {
|
||||
return areNotificationsEnabledForPackage(pkg, Binder.getCallingUid());
|
||||
}
|
||||
|
||||
/**
|
||||
* Use this when you just want to know if notifications are OK for this package.
|
||||
*/
|
||||
@Override
|
||||
public boolean areNotificationsEnabledForPackage(String pkg, int uid) {
|
||||
checkCallerIsSystem();
|
||||
checkCallerIsSystemOrSameApp(pkg);
|
||||
return (mAppOps.checkOpNoThrow(AppOpsManager.OP_POST_NOTIFICATION, uid, pkg)
|
||||
== AppOpsManager.MODE_ALLOWED) && !isApplicationSuspended(pkg, uid);
|
||||
}
|
||||
@@ -1329,6 +1337,12 @@ public class NotificationManagerService extends SystemService {
|
||||
savePolicyFile();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTopicImportance(String pkg, String topicId) {
|
||||
checkCallerIsSystemOrSameApp(pkg);
|
||||
return mRankingHelper.getImportance(pkg, Binder.getCallingUid(), topicId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getImportance(String pkg, int uid, Notification.Topic topic) {
|
||||
checkCallerIsSystem();
|
||||
|
||||
@@ -39,4 +39,6 @@ public interface RankingConfig {
|
||||
boolean doesAppUseTopics(String packageName, int uid);
|
||||
|
||||
boolean hasBannedTopics(String packageName, int uid);
|
||||
|
||||
int getImportance(String packageName, int uid, String topicId);
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ import android.content.Context;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.PackageManager.NameNotFoundException;
|
||||
import android.os.UserHandle;
|
||||
import android.service.notification.NotificationListenerService;
|
||||
import android.service.notification.NotificationListenerService.Ranking;
|
||||
import android.text.TextUtils;
|
||||
import android.util.ArrayMap;
|
||||
@@ -466,6 +467,24 @@ public class RankingHelper implements RankingConfig {
|
||||
updateConfig();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the importance of a topic. Unlike {@link #getImportance(String, int, String)}, does not
|
||||
* create package or topic records if they don't exist.
|
||||
*/
|
||||
@Override
|
||||
public int getImportance(String packageName, int uid, String topicId) {
|
||||
final String key = recordKey(packageName, uid);
|
||||
Record r = mRecords.get(key);
|
||||
if (r == null) {
|
||||
return Ranking.IMPORTANCE_UNSPECIFIED;
|
||||
}
|
||||
Topic t = r.topics.get(topicId);
|
||||
if (t == null) {
|
||||
return Ranking.IMPORTANCE_UNSPECIFIED;
|
||||
}
|
||||
return t.importance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets importance. If a topic is given, returns the importance of that topic. Otherwise, the
|
||||
* importance of the app.
|
||||
|
||||
@@ -37,6 +37,7 @@ import android.os.PowerManager;
|
||||
|
||||
// private NM API
|
||||
import android.app.INotificationManager;
|
||||
import android.widget.Toast;
|
||||
|
||||
public class NotificationTestList extends TestActivity
|
||||
{
|
||||
@@ -233,6 +234,30 @@ public class NotificationTestList extends TestActivity
|
||||
}
|
||||
},
|
||||
|
||||
new Test("Is blocked?") {
|
||||
public void run() {
|
||||
Toast.makeText(NotificationTestList.this,
|
||||
"package enabled? " + mNM.areNotificationsEnabled(),
|
||||
Toast.LENGTH_LONG).show();
|
||||
}
|
||||
},
|
||||
|
||||
new Test("Topic banana importance?") {
|
||||
public void run() {
|
||||
Toast.makeText(NotificationTestList.this,
|
||||
"bananas importance? " + mNM.getImportance("bananas"),
|
||||
Toast.LENGTH_LONG).show();
|
||||
}
|
||||
},
|
||||
|
||||
new Test("Topic garbage importance?") {
|
||||
public void run() {
|
||||
Toast.makeText(NotificationTestList.this,
|
||||
"garbage importance? " + mNM.getImportance("garbage"),
|
||||
Toast.LENGTH_LONG).show();
|
||||
}
|
||||
},
|
||||
|
||||
new Test("Whens") {
|
||||
public void run()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user