WorkSource can now track package names.

Use this to track the package name of applications
accessing GPS.

And now the app ops service can enforce that callers
must provide valid package names.

Change-Id: I842a0abe236ea85f77926d708547f0f95c24bd49
diff --git a/services/java/com/android/server/AppOpsService.java b/services/java/com/android/server/AppOpsService.java
index 5ad4be8..539194c 100644
--- a/services/java/com/android/server/AppOpsService.java
+++ b/services/java/com/android/server/AppOpsService.java
@@ -189,27 +189,23 @@
         if (ops == null) {
             // This is the first time we have seen this package name under this uid,
             // so let's make sure it is valid.
-            // XXX for now we always allow null through until we can fix everything
-            // to provide the name.
-            if (packageName != null) {
-                final long ident = Binder.clearCallingIdentity();
+            final long ident = Binder.clearCallingIdentity();
+            try {
+                int pkgUid = -1;
                 try {
-                    int pkgUid = -1;
-                    try {
-                        pkgUid = mContext.getPackageManager().getPackageUid(packageName,
-                                UserHandle.getUserId(uid));
-                    } catch (NameNotFoundException e) {
-                    }
-                    if (pkgUid != uid) {
-                        // Oops!  The package name is not valid for the uid they are calling
-                        // under.  Abort.
-                        Slog.w(TAG, "Bad call: specified package " + packageName
-                                + " under uid " + uid + " but it is really " + pkgUid);
-                        return null;
-                    }
-                } finally {
-                    Binder.restoreCallingIdentity(ident);
+                    pkgUid = mContext.getPackageManager().getPackageUid(packageName,
+                            UserHandle.getUserId(uid));
+                } catch (NameNotFoundException e) {
                 }
+                if (pkgUid != uid) {
+                    // Oops!  The package name is not valid for the uid they are calling
+                    // under.  Abort.
+                    Slog.w(TAG, "Bad call: specified package " + packageName
+                            + " under uid " + uid + " but it is really " + pkgUid);
+                    return null;
+                }
+            } finally {
+                Binder.restoreCallingIdentity(ident);
             }
             ops = new Ops(packageName);
             pkgOps.put(packageName, ops);