Add notification shutoff switch to app details page.

Requires change Ieccac574.

Bug: 5547401
Change-Id: I9856658cc638723414a5c2c3c6807241c3ce6166
diff --git a/res/layout/installed_app_details.xml b/res/layout/installed_app_details.xml
index afec517..5c6867c 100644
--- a/res/layout/installed_app_details.xml
+++ b/res/layout/installed_app_details.xml
@@ -39,15 +39,47 @@
             android:paddingTop="5dip"
             android:paddingBottom="5dip" >
 
-        <!-- Application snippet label, version and icon -->
-        <include
-            layout="@layout/manage_applications_item"
-            android:id="@+id/app_snippet"/>
+            <!-- Application snippet label, version and icon -->
+            <include
+                layout="@layout/manage_applications_item"
+                android:id="@+id/app_snippet"/>
 
-        <!-- Force stop and uninstall buttons -->
-        <include
-            layout="@layout/two_buttons_panel"
-            android:id="@+id/control_buttons_panel"/>
+            <!-- Force stop and uninstall buttons -->
+            <include
+                layout="@layout/two_buttons_panel"
+                android:id="@+id/control_buttons_panel"/>
+
+            <!-- Ban notifications for this package -->
+            <LinearLayout
+                android:orientation="horizontal"
+                android:layout_width="match_parent"
+                android:layout_height="wrap_content"
+                android:minHeight="48dp"
+                android:paddingLeft="6dip"
+                android:paddingTop="8dip"
+                android:gravity="center_vertical">
+
+                <TextView
+                    android:layout_width="wrap_content"
+                    android:layout_height="wrap_content"
+                    android:paddingRight="14dip"
+                    android:text="@string/app_notifications_switch_label"
+                    android:singleLine="true"
+                    android:textAppearance="?android:attr/textAppearanceMedium"
+                    android:ellipsize="marquee"
+                    android:fadingEdge="horizontal" />
+                <Switch android:id="@+id/notification_switch"
+                    android:layout_width="wrap_content"
+                    android:layout_height="wrap_content"
+                    android:layout_gravity="center"
+                    android:padding="8dip"
+                    android:switchTextAppearance="@style/TextAppearance.Switch"
+                    android:textOn="@string/app_notifications_switch_on"
+                    android:textOff="@string/app_notifications_switch_off"
+                    android:focusable="false"
+                    android:clickable="true" />
+            </LinearLayout>
+
         </LinearLayout>
 
         <TextView
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 2d27fa5..6337824 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -3934,4 +3934,11 @@
     <string name="user_confirm_remove_title">Remove user?</string>
     <!-- User removal confirmation message [CHAR LIMIT=none] -->
     <string name="user_confirm_remove_message">Are you sure you want to remove the user and all associated data from the device?</string>
+
+    <!-- Label for "notifications enabled" switch in app details [CHAR LIMIT=20] -->
+    <string name="app_notifications_switch_label">Notifications</string>
+    <!-- Label for enabled state of "notifications enabled" switch in app details [CHAR LIMIT=10] -->
+    <string name="app_notifications_switch_on">Enabled</string>
+    <!-- Label for disabled state "notifications enabled" switch in app details [CHAR LIMIT=10] -->
+    <string name="app_notifications_switch_off">Disabled</string>
 </resources>
diff --git a/res/values/styles.xml b/res/values/styles.xml
index 32e0a48..6ee99b3 100644
--- a/res/values/styles.xml
+++ b/res/values/styles.xml
@@ -191,4 +191,8 @@
         <item name="android:shadowRadius">2.0</item>
         <item name="android:shadowColor">#B0000000</item>
     </style>
+
+    <style name="TextAppearance.Switch" parent="@*android:style/TextAppearance.Holo.Widget.Switch">
+        <item name="android:textAllCaps">true</item>
+    </style>
 </resources>
diff --git a/src/com/android/settings/applications/InstalledAppDetails.java b/src/com/android/settings/applications/InstalledAppDetails.java
index faa531a..8b5ff0b 100644
--- a/src/com/android/settings/applications/InstalledAppDetails.java
+++ b/src/com/android/settings/applications/InstalledAppDetails.java
@@ -25,6 +25,8 @@
 import android.app.Dialog;
 import android.app.DialogFragment;
 import android.app.Fragment;
+import android.app.INotificationManager;
+import android.app.NotificationManager;
 import android.app.admin.DevicePolicyManager;
 import android.content.BroadcastReceiver;
 import android.content.Context;
@@ -65,6 +67,7 @@
 import android.widget.CompoundButton;
 import android.widget.ImageView;
 import android.widget.LinearLayout;
+import android.widget.Switch;
 import android.widget.TextView;
 
 /**
@@ -115,7 +118,8 @@
     private Button mForceStopButton;
     private Button mClearDataButton;
     private Button mMoveAppButton;
-    
+    private Switch mNotificationSwitch;
+
     private PackageMoveObserver mPackageMoveObserver;
     
     private boolean mHaveSizes = false;
@@ -319,6 +323,19 @@
         }
     }
 
+    private void initNotificationButton() {
+        INotificationManager nm = INotificationManager.Stub.asInterface(
+                ServiceManager.getService(Context.NOTIFICATION_SERVICE));
+        boolean enabled = true; // default on
+        try {
+            enabled = nm.areNotificationsEnabledForPackage(mAppEntry.info.packageName);
+        } catch (android.os.RemoteException ex) {
+            // this does not bode well
+        }
+        mNotificationSwitch.setChecked(enabled);
+        mNotificationSwitch.setOnCheckedChangeListener(this);
+    }
+
     /** Called when the activity is first created. */
     @Override
     public void onCreate(Bundle icicle) {
@@ -368,6 +385,8 @@
         mScreenCompatSection = view.findViewById(R.id.screen_compatibility_section);
         mAskCompatibilityCB = (CheckBox)view.findViewById(R.id.ask_compatibility_cb);
         mEnableCompatibilityCB = (CheckBox)view.findViewById(R.id.enable_compatibility_cb);
+        
+        mNotificationSwitch = (Switch) view.findViewById(R.id.notification_switch);
 
         return view;
     }
@@ -614,6 +633,7 @@
             initUninstallButtons();
             initDataButtons();
             initMoveButton();
+            initNotificationButton();
         } else {
             mMoveAppButton.setText(R.string.moving);
             mMoveAppButton.setEnabled(false);
@@ -925,6 +945,14 @@
         } else if (buttonView == mEnableCompatibilityCB) {
             am.setPackageScreenCompatMode(packageName, isChecked ?
                     ActivityManager.COMPAT_MODE_ENABLED : ActivityManager.COMPAT_MODE_DISABLED);
+        } else if (buttonView == mNotificationSwitch) {
+            INotificationManager nm = INotificationManager.Stub.asInterface(
+                ServiceManager.getService(Context.NOTIFICATION_SERVICE));
+            try {
+                nm.setNotificationsEnabledForPackage(packageName, isChecked);
+            } catch (android.os.RemoteException ex) {
+                mNotificationSwitch.setChecked(!isChecked); // revert
+            }
         }
     }
 }