resolved conflicts for merge of 5223a5ff to master

Change-Id: I6523e4b7df88f21fbe0ecd3ab8f493e5a9867305
diff --git a/tools/aapt/Command.cpp b/tools/aapt/Command.cpp
index 7d21b8d..7a40ca4 100644
--- a/tools/aapt/Command.cpp
+++ b/tools/aapt/Command.cpp
@@ -384,6 +384,7 @@
     LABEL_ATTR = 0x01010001,
     ICON_ATTR = 0x01010002,
     NAME_ATTR = 0x01010003,
+    PERMISSION_ATTR = 0x01010006,
     DEBUGGABLE_ATTR = 0x0101000f,
     VALUE_ATTR = 0x01010024,
     VERSION_CODE_ATTR = 0x0101021b,
@@ -672,12 +673,25 @@
             bool hasOtherServices = false;
             bool hasWallpaperService = false;
             bool hasImeService = false;
+            bool hasAccessibilityService = false;
+            bool hasPrintService = false;
             bool hasWidgetReceivers = false;
+            bool hasDeviceAdminReceiver = false;
             bool hasIntentFilter = false;
             bool actMainActivity = false;
             bool actWidgetReceivers = false;
+            bool actDeviceAdminEnabled = false;
             bool actImeService = false;
             bool actWallpaperService = false;
+            bool actAccessibilityService = false;
+            bool actPrintService = false;
+
+            // These permissions are required by services implementing services
+            // the system binds to (IME, Accessibility, PrintServices, etc.)
+            bool hasBindDeviceAdminPermission = false;
+            bool hasBindInputMethodPermission = false;
+            bool hasBindAccessibilityServicePermission = false;
+            bool hasBindPrintServicePermission = false;
 
             // These two implement the implicit permissions that are granted
             // to pre-1.6 applications.
@@ -801,11 +815,17 @@
                                 hasOtherActivities |= !actMainActivity;
                             } else if (withinReceiver) {
                                 hasWidgetReceivers |= actWidgetReceivers;
-                                hasOtherReceivers |= !actWidgetReceivers;
+                                hasDeviceAdminReceiver |= (actDeviceAdminEnabled &&
+                                        hasBindDeviceAdminPermission);
+                                hasOtherReceivers |= (!actWidgetReceivers && !actDeviceAdminEnabled);
                             } else if (withinService) {
                                 hasImeService |= actImeService;
                                 hasWallpaperService |= actWallpaperService;
-                                hasOtherServices |= (!actImeService && !actWallpaperService);
+                                hasAccessibilityService |= (actAccessibilityService &&
+                                        hasBindAccessibilityServicePermission);
+                                hasPrintService |= (actPrintService && hasBindPrintServicePermission);
+                                hasOtherServices |= (!actImeService && !actWallpaperService &&
+                                        !actAccessibilityService && !actPrintService);
                             }
                         }
                         withinIntentFilter = false;
@@ -1207,6 +1227,16 @@
                                         " %s\n", error.string());
                                 goto bail;
                             }
+
+                            String8 permission = getAttribute(tree, PERMISSION_ATTR, &error);
+                            if (error == "") {
+                                if (permission == "android.permission.BIND_DEVICE_ADMIN") {
+                                    hasBindDeviceAdminPermission = true;
+                                }
+                            } else {
+                                fprintf(stderr, "ERROR getting 'android:permission' attribute for"
+                                        " receiver '%s': %s\n", receiverName.string(), error.string());
+                            }
                         } else if (tag == "service") {
                             withinService = true;
                             serviceName = getAttribute(tree, NAME_ATTR, &error);
@@ -1216,6 +1246,20 @@
                                         "service:%s\n", error.string());
                                 goto bail;
                             }
+
+                            String8 permission = getAttribute(tree, PERMISSION_ATTR, &error);
+                            if (error == "") {
+                                if (permission == "android.permission.BIND_INPUT_METHOD") {
+                                    hasBindInputMethodPermission = true;
+                                } else if (permission == "android.permission.BIND_ACCESSIBILITY_SERVICE") {
+                                    hasBindAccessibilityServicePermission = true;
+                                } else if (permission == "android.permission.BIND_PRINT_SERVICE") {
+                                    hasBindPrintServicePermission = true;
+                                }
+                            } else {
+                                fprintf(stderr, "ERROR getting 'android:permission' attribute for"
+                                        " service '%s': %s\n", serviceName.string(), error.string());
+                            }
                         } else if (bundle->getIncludeMetaData() && tag == "meta-data") {
                             String8 metaDataName = getAttribute(tree, NAME_ATTR, &error);
                             if (error != "") {
@@ -1256,52 +1300,64 @@
                                 goto bail;
                             }
                         }
-                    } else if ((depth == 4) && (tag == "intent-filter")) {
-                        hasIntentFilter = true;
-                        withinIntentFilter = true;
-                        actMainActivity = actWidgetReceivers =
-                                actImeService = actWallpaperService = false;
-                    } else if ((depth == 5) && withinIntentFilter) {
-                        String8 action;
-                        if (tag == "action") {
-                            action = getAttribute(tree, NAME_ATTR, &error);
-                            if (error != "") {
-                                fprintf(stderr, "ERROR getting 'android:name' attribute: %s\n",
-                                        error.string());
-                                goto bail;
-                            }
-                            if (withinActivity) {
-                                if (action == "android.intent.action.MAIN") {
-                                    isMainActivity = true;
-                                    actMainActivity = true;
-                                }
-                            } else if (withinReceiver) {
-                                if (action == "android.appwidget.action.APPWIDGET_UPDATE") {
-                                    actWidgetReceivers = true;
-                                }
-                            } else if (withinService) {
-                                if (action == "android.view.InputMethod") {
-                                    actImeService = true;
-                                } else if (action == "android.service.wallpaper.WallpaperService") {
-                                    actWallpaperService = true;
-                                }
-                            }
-                            if (action == "android.intent.action.SEARCH") {
-                                isSearchable = true;
-                            }
+                    }
+                } else if ((depth == 4) && (tag == "intent-filter")) {
+                    hasIntentFilter = true;
+                    withinIntentFilter = true;
+                    actMainActivity = false;
+                    actWidgetReceivers = false;
+                    actImeService = false;
+                    actWallpaperService = false;
+                    actAccessibilityService = false;
+                    actPrintService = false;
+                    actDeviceAdminEnabled = false;
+                } else if ((depth == 5) && withinIntentFilter) {
+                    String8 action;
+                    if (tag == "action") {
+                        action = getAttribute(tree, NAME_ATTR, &error);
+                        if (error != "") {
+                            fprintf(stderr, "ERROR getting 'android:name' attribute: %s\n",
+                                    error.string());
+                            goto bail;
                         }
 
-                        if (tag == "category") {
-                            String8 category = getAttribute(tree, NAME_ATTR, &error);
-                            if (error != "") {
-                                fprintf(stderr, "ERROR getting 'name' attribute: %s\n",
-                                        error.string());
-                                goto bail;
+                        if (withinActivity) {
+                            if (action == "android.intent.action.MAIN") {
+                                isMainActivity = true;
+                                actMainActivity = true;
                             }
-                            if (withinActivity) {
-                                if (category == "android.intent.category.LAUNCHER") {
-                                    isLauncherActivity = true;
-                                }
+                        } else if (withinReceiver) {
+                            if (action == "android.appwidget.action.APPWIDGET_UPDATE") {
+                                actWidgetReceivers = true;
+                            } else if (action == "android.app.action.DEVICE_ADMIN_ENABLED") {
+                                actDeviceAdminEnabled = true;
+                            }
+                        } else if (withinService) {
+                            if (action == "android.view.InputMethod") {
+                                actImeService = true;
+                            } else if (action == "android.service.wallpaper.WallpaperService") {
+                                actWallpaperService = true;
+                            } else if (action == "android.accessibilityservice.AccessibilityService") {
+                                actAccessibilityService = true;
+                            } else if (action == "android.printservice.PrintService") {
+                                actPrintService = true;
+                            }
+                        }
+                        if (action == "android.intent.action.SEARCH") {
+                            isSearchable = true;
+                        }
+                    }
+
+                    if (tag == "category") {
+                        String8 category = getAttribute(tree, NAME_ATTR, &error);
+                        if (error != "") {
+                            fprintf(stderr, "ERROR getting 'name' attribute: %s\n",
+                                    error.string());
+                            goto bail;
+                        }
+                        if (withinActivity) {
+                            if (category == "android.intent.category.LAUNCHER") {
+                                isLauncherActivity = true;
                             }
                         }
                     }
@@ -1485,12 +1541,21 @@
             if (hasWidgetReceivers) {
                 printf("app-widget\n");
             }
+            if (hasDeviceAdminReceiver) {
+                printf("device-admin\n");
+            }
             if (hasImeService) {
                 printf("ime\n");
             }
             if (hasWallpaperService) {
                 printf("wallpaper\n");
             }
+            if (hasAccessibilityService) {
+                printf("accessibility\n");
+            }
+            if (hasPrintService) {
+                printf("print\n");
+            }
             if (hasOtherActivities) {
                 printf("other-activities\n");
             }