Merge "Remove unused content observer from AssistManager."
diff --git a/core/res/res/values/config.xml b/core/res/res/values/config.xml
old mode 100755
new mode 100644
index b844d44..a5960a9
--- a/core/res/res/values/config.xml
+++ b/core/res/res/values/config.xml
@@ -2300,6 +2300,9 @@
     <string-array name="config_cell_retries_per_error_code">
     </string-array>
 
+    <!-- Set initial MaxRetry value for operators -->
+    <integer name="config_mdc_initial_max_retry">1</integer>
+
     <!-- The OEM specified sensor type for the gesture to launch the camear app. -->
     <integer name="config_cameraLaunchGestureSensorType">-1</integer>
     <!-- The OEM specified sensor string type for the gesture to launch camera app, this value
diff --git a/core/res/res/values/symbols.xml b/core/res/res/values/symbols.xml
old mode 100755
new mode 100644
index de5c592..16e44b8
--- a/core/res/res/values/symbols.xml
+++ b/core/res/res/values/symbols.xml
@@ -408,6 +408,7 @@
   <java-symbol type="integer" name="config_volte_replacement_rat"/>
   <java-symbol type="integer" name="config_valid_wappush_index" />
   <java-symbol type="integer" name="config_overrideHasPermanentMenuKey" />
+  <java-symbol type="integer" name="config_mdc_initial_max_retry" />
   <java-symbol type="bool" name="config_hasPermanentDpad" />
 
   <java-symbol type="color" name="tab_indicator_text_v4" />
diff --git a/docs/html/guide/topics/renderscript/reference/rs_math.jd b/docs/html/guide/topics/renderscript/reference/rs_math.jd
index 13513e9..e1e7805 100644
--- a/docs/html/guide/topics/renderscript/reference/rs_math.jd
+++ b/docs/html/guide/topics/renderscript/reference/rs_math.jd
@@ -3968,16 +3968,31 @@
         <td>        </td>
       </tr>
       <tr>
+        <td><a href='rs_value_types.html#android_rs:float2'>float2</a> max(<a href='rs_value_types.html#android_rs:float2'>float2</a> a, float b);
+</td>
+        <td>        </td>
+      </tr>
+      <tr>
         <td><a href='rs_value_types.html#android_rs:float2'>float2</a> max(<a href='rs_value_types.html#android_rs:float2'>float2</a> a, <a href='rs_value_types.html#android_rs:float2'>float2</a> b);
 </td>
         <td>        </td>
       </tr>
       <tr>
+        <td><a href='rs_value_types.html#android_rs:float3'>float3</a> max(<a href='rs_value_types.html#android_rs:float3'>float3</a> a, float b);
+</td>
+        <td>        </td>
+      </tr>
+      <tr>
         <td><a href='rs_value_types.html#android_rs:float3'>float3</a> max(<a href='rs_value_types.html#android_rs:float3'>float3</a> a, <a href='rs_value_types.html#android_rs:float3'>float3</a> b);
 </td>
         <td>        </td>
       </tr>
       <tr>
+        <td><a href='rs_value_types.html#android_rs:float4'>float4</a> max(<a href='rs_value_types.html#android_rs:float4'>float4</a> a, float b);
+</td>
+        <td>        </td>
+      </tr>
+      <tr>
         <td><a href='rs_value_types.html#android_rs:float4'>float4</a> max(<a href='rs_value_types.html#android_rs:float4'>float4</a> a, <a href='rs_value_types.html#android_rs:float4'>float4</a> b);
 </td>
         <td>        </td>
@@ -4172,16 +4187,31 @@
         <td>        </td>
       </tr>
       <tr>
+        <td><a href='rs_value_types.html#android_rs:float2'>float2</a> min(<a href='rs_value_types.html#android_rs:float2'>float2</a> a, float b);
+</td>
+        <td>        </td>
+      </tr>
+      <tr>
         <td><a href='rs_value_types.html#android_rs:float2'>float2</a> min(<a href='rs_value_types.html#android_rs:float2'>float2</a> a, <a href='rs_value_types.html#android_rs:float2'>float2</a> b);
 </td>
         <td>        </td>
       </tr>
       <tr>
+        <td><a href='rs_value_types.html#android_rs:float3'>float3</a> min(<a href='rs_value_types.html#android_rs:float3'>float3</a> a, float b);
+</td>
+        <td>        </td>
+      </tr>
+      <tr>
         <td><a href='rs_value_types.html#android_rs:float3'>float3</a> min(<a href='rs_value_types.html#android_rs:float3'>float3</a> a, <a href='rs_value_types.html#android_rs:float3'>float3</a> b);
 </td>
         <td>        </td>
       </tr>
       <tr>
+        <td><a href='rs_value_types.html#android_rs:float4'>float4</a> min(<a href='rs_value_types.html#android_rs:float4'>float4</a> a, float b);
+</td>
+        <td>        </td>
+      </tr>
+      <tr>
         <td><a href='rs_value_types.html#android_rs:float4'>float4</a> min(<a href='rs_value_types.html#android_rs:float4'>float4</a> a, <a href='rs_value_types.html#android_rs:float4'>float4</a> b);
 </td>
         <td>        </td>
diff --git a/docs/html/guide/topics/renderscript/reference/rs_value_types.jd b/docs/html/guide/topics/renderscript/reference/rs_value_types.jd
index 85c7a5c..d53caf9 100644
--- a/docs/html/guide/topics/renderscript/reference/rs_value_types.jd
+++ b/docs/html/guide/topics/renderscript/reference/rs_value_types.jd
@@ -25,7 +25,7 @@
 </p>
 
 <p> To create vector literals, use the vector type followed by the values enclosed
-between parentheses, e.g. <code>(float3)(1.0f, 2.0f, 3.0f)</code>.
+between curly braces, e.g. <code>(float3){1.0f, 2.0f, 3.0f}</code>.
 </p>
 
 <p> Entries of a vector can be accessed using different naming styles.
diff --git a/packages/Keyguard/src/com/android/keyguard/KeyguardUpdateMonitor.java b/packages/Keyguard/src/com/android/keyguard/KeyguardUpdateMonitor.java
index b752c9b..47d8e28 100644
--- a/packages/Keyguard/src/com/android/keyguard/KeyguardUpdateMonitor.java
+++ b/packages/Keyguard/src/com/android/keyguard/KeyguardUpdateMonitor.java
@@ -1032,7 +1032,7 @@
     }
 
     private boolean shouldListenForFingerprint() {
-        return (mKeyguardIsVisible || !mDeviceInteractive) && !mSwitchingUser
+        return (mKeyguardIsVisible || !mDeviceInteractive || mBouncer) && !mSwitchingUser
                 && !mFingerprintAlreadyAuthenticated && !isFingerprintDisabled(getCurrentUser());
     }
 
@@ -1365,6 +1365,7 @@
                 cb.onKeyguardBouncerChanged(isBouncer);
             }
         }
+        updateFingerprintListeningState();
     }
 
     /**
diff --git a/services/core/java/com/android/server/accounts/AccountManagerService.java b/services/core/java/com/android/server/accounts/AccountManagerService.java
index a0f9f81..dbf1288 100644
--- a/services/core/java/com/android/server/accounts/AccountManagerService.java
+++ b/services/core/java/com/android/server/accounts/AccountManagerService.java
@@ -2621,6 +2621,7 @@
         // be passed in the original caller's uid here, which is what should be used for filtering.
         if (packageUid != -1 && UserHandle.isSameApp(callingUid, Process.myUid())) {
             callingUid = packageUid;
+            opPackageName = callingPackage;
         }
 
         List<String> visibleAccountTypes = getTypesVisibleToCaller(callingUid, userId,
diff --git a/services/core/java/com/android/server/display/DisplayPowerState.java b/services/core/java/com/android/server/display/DisplayPowerState.java
index f53ccc9..2eabd32 100644
--- a/services/core/java/com/android/server/display/DisplayPowerState.java
+++ b/services/core/java/com/android/server/display/DisplayPowerState.java
@@ -341,7 +341,8 @@
         private int mPendingBacklight = INITIAL_BACKLIGHT;
         private int mActualState = INITIAL_SCREEN_STATE;
         private int mActualBacklight = INITIAL_BACKLIGHT;
-        private boolean mChangeInProgress;
+        private boolean mStateChangeInProgress;
+        private boolean mBacklightChangeInProgress;
 
         public PhotonicModulator() {
             super("PhotonicModulator");
@@ -349,7 +350,9 @@
 
         public boolean setState(int state, int backlight) {
             synchronized (mLock) {
-                if (state != mPendingState || backlight != mPendingBacklight) {
+                boolean stateChanged = state != mPendingState;
+                boolean backlightChanged = backlight != mPendingBacklight;
+                if (stateChanged || backlightChanged) {
                     if (DEBUG) {
                         Slog.d(TAG, "Requesting new screen state: state="
                                 + Display.stateToString(state) + ", backlight=" + backlight);
@@ -358,12 +361,15 @@
                     mPendingState = state;
                     mPendingBacklight = backlight;
 
-                    if (!mChangeInProgress) {
-                        mChangeInProgress = true;
+                    boolean changeInProgress = mStateChangeInProgress || mBacklightChangeInProgress;
+                    mStateChangeInProgress = stateChanged;
+                    mBacklightChangeInProgress = backlightChanged;
+
+                    if (!changeInProgress) {
                         mLock.notifyAll();
                     }
                 }
-                return !mChangeInProgress;
+                return !mStateChangeInProgress;
             }
         }
 
@@ -375,7 +381,8 @@
                 pw.println("  mPendingBacklight=" + mPendingBacklight);
                 pw.println("  mActualState=" + Display.stateToString(mActualState));
                 pw.println("  mActualBacklight=" + mActualBacklight);
-                pw.println("  mChangeInProgress=" + mChangeInProgress);
+                pw.println("  mStateChangeInProgress=" + mStateChangeInProgress);
+                pw.println("  mBacklightChangeInProgress=" + mBacklightChangeInProgress);
             }
         }
 
@@ -392,10 +399,15 @@
                     stateChanged = (state != mActualState);
                     backlight = mPendingBacklight;
                     backlightChanged = (backlight != mActualBacklight);
-                    if (!stateChanged && !backlightChanged) {
-                        // All changed applied, notify outer class and wait for more.
-                        mChangeInProgress = false;
+                    if (!stateChanged) {
+                        // State changed applied, notify outer class.
                         postScreenUpdateThreadSafe();
+                        mStateChangeInProgress = false;
+                    }
+                    if (!backlightChanged) {
+                        mBacklightChangeInProgress = false;
+                    }
+                    if (!stateChanged && !backlightChanged) {
                         try {
                             mLock.wait();
                         } catch (InterruptedException ex) { }
diff --git a/tools/aidl/aidl.cpp b/tools/aidl/aidl.cpp
index 832c51c..616f276 100644
--- a/tools/aidl/aidl.cpp
+++ b/tools/aidl/aidl.cpp
@@ -33,6 +33,8 @@
 
 using namespace std;
 
+ParseState *psGlobal;
+
 static void
 test_document(document_item_type* d)
 {
@@ -111,7 +113,7 @@
 {
     import_info* import = (import_info*)malloc(sizeof(import_info));
     memset(import, 0, sizeof(import_info));
-    import->from = strdup(g_currentFilename);
+    import->from = strdup(psGlobal->FileName().c_str());
     import->statement.lineno = statement->lineno;
     import->statement.data = strdup(statement->data);
     import->statement.extra = NULL;
diff --git a/tools/aidl/aidl_language.cpp b/tools/aidl/aidl_language.cpp
index 5fab6c2..4eb3fae 100644
--- a/tools/aidl/aidl_language.cpp
+++ b/tools/aidl/aidl_language.cpp
@@ -1,7 +1,9 @@
 #include "aidl_language.h"
+#include "aidl_language_y.hpp"
 #include <stdio.h>
-#include <string.h>
 #include <stdlib.h>
+#include <string>
+#include <iostream>
 
 #ifdef _WIN32
 int isatty(int  fd)
@@ -10,11 +12,83 @@
 }
 #endif
 
-#if 0
-ParserCallbacks k_parserCallbacks = {
-    NULL
-};
-#endif
+using std::string;
+using std::cerr;
+using std::endl;
 
 ParserCallbacks* g_callbacks = NULL; // &k_parserCallbacks;
 
+void yylex_init(void **);
+void yylex_destroy(void *);
+void yyset_in(FILE *f, void *);
+int yyparse(ParseState*);
+
+ParseState::ParseState() : ParseState("") {}
+
+ParseState::ParseState(const string& filename)
+    : filename_(filename) {
+  yylex_init(&scanner_);
+}
+
+ParseState::~ParseState() {
+  yylex_destroy(scanner_);
+}
+
+string ParseState::FileName() {
+  return filename_;
+}
+
+string ParseState::Package() {
+  return g_currentPackage;
+}
+
+void ParseState::ProcessDocument(const document_item_type& items) {
+  /* The cast is not my fault. I didn't write the code on the other side. */
+  /* TODO(sadmac): b/23977313 */
+  g_callbacks->document((document_item_type *)&items);
+}
+
+void ParseState::ProcessImport(const buffer_type& statement) {
+  /* The cast is not my fault. I didn't write the code on the other side. */
+  /* TODO(sadmac): b/23977313 */
+  g_callbacks->import((buffer_type *)&statement);
+}
+
+void ParseState::ReportError(const string& err) {
+  /* FIXME: We're printing out the line number as -1. We used to use yylineno
+   * (which was NEVER correct even before reentrant parsing). Now we'll need
+   * another way.
+   */
+  cerr << filename_ << ":" << -1 << ": " << err << endl;
+  error_ = 1;
+}
+
+bool ParseState::FoundNoErrors() {
+  return error_ == 0;
+}
+
+void *ParseState::Scanner() {
+  return scanner_;
+}
+
+bool ParseState::OpenFileFromDisk() {
+  FILE *in = fopen(FileName().c_str(), "r");
+
+  if (! in)
+    return false;
+
+  yyset_in(in, Scanner());
+  return true;
+}
+
+int ParseState::RunParser() {
+  int ret = yy::parser(this).parse();
+
+  free((void *)g_currentPackage);
+  g_currentPackage = NULL;
+
+  if (error_)
+    return 1;
+
+  return ret;
+}
diff --git a/tools/aidl/aidl_language.h b/tools/aidl/aidl_language.h
index a3b1efc..f3a126e 100644
--- a/tools/aidl/aidl_language.h
+++ b/tools/aidl/aidl_language.h
@@ -1,6 +1,9 @@
 #ifndef AIDL_AIDL_LANGUAGE_H_
 #define AIDL_AIDL_LANGUAGE_H_
 
+#include <string>
+
+#include "macros.h"
 
 typedef enum {
     NO_EXTRA_TEXT = 0,
@@ -141,12 +144,6 @@
 
 extern ParserCallbacks* g_callbacks;
 
-// true if there was an error parsing, false otherwise
-extern int g_error;
-
-// the name of the file we're currently parsing
-extern char const* g_currentFilename;
-
 // the package name for our current file
 extern char const* g_currentPackage;
 
@@ -157,6 +154,33 @@
 void init_buffer_type(buffer_type* buf, int lineno);
 
 
+class ParseState {
+ public:
+  ParseState();
+  ParseState(const std::string& filename);
+  ~ParseState();
+
+  bool OpenFileFromDisk();
+  int RunParser();
+  void ReportError(const std::string& err);
+
+  bool FoundNoErrors();
+  std::string FileName();
+  std::string Package();
+  void *Scanner();
+
+  void ProcessDocument(const document_item_type& items);
+  void ProcessImport(const buffer_type& statement);
+
+ private:
+  int error_ = 0;
+  std::string filename_;
+  std::string package_;
+  void *scanner_ = nullptr;
+
+  DISALLOW_COPY_AND_ASSIGN(ParseState);
+};
+
 #if __cplusplus
 }
 #endif
diff --git a/tools/aidl/aidl_language_l.l b/tools/aidl/aidl_language_l.l
index aa42f2e..540b550 100644
--- a/tools/aidl/aidl_language_l.l
+++ b/tools/aidl/aidl_language_l.l
@@ -1,6 +1,6 @@
 %{
 #include "aidl_language.h"
-#include "aidl_language_y.h"
+#include "aidl_language_y.hpp"
 #include "search_path.h"
 #include <string.h>
 #include <stdlib.h>
@@ -20,16 +20,19 @@
 
 #define SET_BUFFER(t) \
     do { \
-        yylval.buffer.lineno = yylineno; \
-        yylval.buffer.token = (t); \
-        yylval.buffer.data = strdup(yytext); \
-        yylval.buffer.extra = get_extra_text(); \
+        yylval->buffer.lineno = yyget_lineno(yyscanner); \
+        yylval->buffer.token = (t); \
+        yylval->buffer.data = strdup(yytext); \
+        yylval->buffer.extra = get_extra_text(); \
     } while(0)
 
 %}
 
 %option yylineno
 %option noyywrap
+%option reentrant
+%option bison-bridge
+%option bison-locations
 
 %x COPYING LONG_COMMENT
 
@@ -56,13 +59,13 @@
 <LONG_COMMENT>\**\/             { BEGIN(INITIAL); }
 
 ^{whitespace}?import{whitespace}[^ \t\r\n]+{whitespace}?;  {
-                                                SET_BUFFER(IMPORT);
-                                                return IMPORT;
+                                                SET_BUFFER(yy::parser::token::IMPORT);
+                                                return yy::parser::token::IMPORT;
                                             }
 ^{whitespace}?package{whitespace}[^ \t\r\n]+{whitespace}?;  {
                                                 do_package_statement(yytext);
-                                                SET_BUFFER(PACKAGE);
-                                                return PACKAGE;
+                                                SET_BUFFER(yy::parser::token::PACKAGE);
+                                                return yy::parser::token::PACKAGE;
                                             }
 <<EOF>>             { yyterminate(); }
 
@@ -81,25 +84,25 @@
 =               { SET_BUFFER('='); return '='; }
 
     /* keywords */
-parcelable      { SET_BUFFER(PARCELABLE); return PARCELABLE; }
-interface       { SET_BUFFER(INTERFACE); return INTERFACE; }
-in              { SET_BUFFER(IN); return IN; }
-out             { SET_BUFFER(OUT); return OUT; }
-inout           { SET_BUFFER(INOUT); return INOUT; }
-oneway          { SET_BUFFER(ONEWAY); return ONEWAY; }
+parcelable      { SET_BUFFER(yy::parser::token::PARCELABLE); return yy::parser::token::PARCELABLE; }
+interface       { SET_BUFFER(yy::parser::token::INTERFACE); return yy::parser::token::INTERFACE; }
+in              { SET_BUFFER(yy::parser::token::IN); return yy::parser::token::IN; }
+out             { SET_BUFFER(yy::parser::token::OUT); return yy::parser::token::OUT; }
+inout           { SET_BUFFER(yy::parser::token::INOUT); return yy::parser::token::INOUT; }
+oneway          { SET_BUFFER(yy::parser::token::ONEWAY); return yy::parser::token::ONEWAY; }
 
-{brackets}+     { SET_BUFFER(ARRAY); return ARRAY; }
-{idvalue}       { SET_BUFFER(IDVALUE); return IDVALUE; }
-{identifier}                                        { SET_BUFFER(IDENTIFIER); return IDENTIFIER; }
+{brackets}+     { SET_BUFFER(yy::parser::token::ARRAY); return yy::parser::token::ARRAY; }
+{idvalue}       { SET_BUFFER(yy::parser::token::IDVALUE); return yy::parser::token::IDVALUE; }
+{identifier}                                        { SET_BUFFER(yy::parser::token::IDENTIFIER); return yy::parser::token::IDENTIFIER; }
 {identifier}\<{whitespace}*{identifier}({whitespace}*,{whitespace}*{identifier})*{whitespace}*\>    {
-                                                      SET_BUFFER(GENERIC); return GENERIC; }
+                                                      SET_BUFFER(yy::parser::token::GENERIC); return yy::parser::token::GENERIC; }
 
     /* syntax error! */
 .               { printf("UNKNOWN(%s)", yytext);
-                  yylval.buffer.lineno = yylineno;
-                  yylval.buffer.token = IDENTIFIER;
-                  yylval.buffer.data = strdup(yytext);
-                  return IDENTIFIER;
+                  yylval->buffer.lineno = yylineno;
+                  yylval->buffer.token = yy::parser::token::IDENTIFIER;
+                  yylval->buffer.data = strdup(yytext);
+                  return yy::parser::token::IDENTIFIER;
                 }
 
 %%
@@ -177,36 +180,17 @@
 
 // main parse function
 // ================================================
-char const* g_currentFilename = NULL;
+extern ParseState *psGlobal;
 char const* g_currentPackage = NULL;
 
-int yyparse(void);
+int parse_aidl(char const *filename) {
+  ParseState ps(filename);
+  psGlobal = &ps;
 
-int parse_aidl(char const *filename)
-{
-    yyin = fopen(filename, "r");
-    if (yyin) {
-        char const* oldFilename = g_currentFilename;
-        char const* oldPackage = g_currentPackage;
-        g_currentFilename = strdup(filename);
+  if (!ps.OpenFileFromDisk()) {
+    fprintf(stderr, "aidl: unable to open file for read: %s\n", filename);
+    return 1;
+  }
 
-        g_error = 0;
-        yylineno = 1;
-        int rv = yyparse();
-        if (g_error != 0) {
-            rv = g_error;
-        }
-
-        free((void*)g_currentFilename);
-        g_currentFilename = oldFilename;
-        
-        if (g_currentPackage) free((void*)g_currentPackage);
-        g_currentPackage = oldPackage;
-
-        return rv;
-    } else {
-        fprintf(stderr, "aidl: unable to open file for read: %s\n", filename);
-        return 1;
-    }
+  return ps.RunParser();
 }
-
diff --git a/tools/aidl/aidl_language_y.y b/tools/aidl/aidl_language_y.y
index 9c5d10e..7a2b785 100644
--- a/tools/aidl/aidl_language_y.y
+++ b/tools/aidl/aidl_language_y.y
@@ -1,17 +1,24 @@
 %{
 #include "aidl_language.h"
+#include "aidl_language_y.hpp"
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 
-int yyerror(char* errstr);
-int yylex(void);
-extern int yylineno;
+int yylex(lexer_type *, yy::parser::location_type *l, void *);
 
 static int count_brackets(const char*);
 
+#define lex_scanner ps->Scanner()
+
 %}
 
+%parse-param { ParseState* ps }
+%lex-param { void *lex_scanner }
+
+%pure-parser
+%skeleton "glr.cc"
+
 %token IMPORT
 %token PACKAGE
 %token IDENTIFIER
@@ -27,8 +34,8 @@
 
 %%
 document:
-        document_items                          { g_callbacks->document($1.document_item); }
-    |   headers document_items                  { g_callbacks->document($2.document_item); }
+        document_items                          { ps->ProcessDocument(*$1.document_item); }
+    |   headers document_items                  { ps->ProcessDocument(*$2.document_item); }
     ;
 
 headers:
@@ -42,8 +49,8 @@
     ;
 
 imports:
-        IMPORT                                  { g_callbacks->import(&($1.buffer)); }
-    |   IMPORT imports                          { g_callbacks->import(&($1.buffer)); }
+        IMPORT                                  { ps->ProcessImport($1.buffer); }
+    |   IMPORT imports                          { ps->ProcessImport($1.buffer); }
     ;
 
 document_items:
@@ -66,7 +73,8 @@
                                                     }
                                                 }
     | document_items error                      {
-                                                    fprintf(stderr, "%s:%d: syntax error don't know what to do with \"%s\"\n", g_currentFilename,
+                                                    fprintf(stderr, "%s:%d: syntax error don't know what to do with \"%s\"\n",
+                                                            ps->FileName().c_str(),
                                                             $2.buffer.lineno, $2.buffer.data);
                                                     $$ = $1;
                                                 }
@@ -84,19 +92,20 @@
                                                         b->document_item.next = NULL;
                                                         b->keyword_token = $1.buffer;
                                                         b->name = $2.buffer;
-                                                        b->package = g_currentPackage ? strdup(g_currentPackage) : NULL;
+                                                        b->package =
+                                                        strdup(ps->Package().c_str());
                                                         b->semicolon_token = $3.buffer;
                                                         b->parcelable = true;
                                                         $$.user_data = b;
                                                     }
     |   PARCELABLE ';'                              {
                                                         fprintf(stderr, "%s:%d syntax error in parcelable declaration. Expected type name.\n",
-                                                                     g_currentFilename, $1.buffer.lineno);
+                                                                     ps->FileName().c_str(), $1.buffer.lineno);
                                                         $$.user_data = NULL;
                                                     }
     |   PARCELABLE error ';'                        {
                                                         fprintf(stderr, "%s:%d syntax error in parcelable declaration. Expected type name, saw \"%s\".\n",
-                                                                     g_currentFilename, $2.buffer.lineno, $2.buffer.data);
+                                                                     ps->FileName().c_str(), $2.buffer.lineno, $2.buffer.data);
                                                         $$.user_data = NULL;
                                                     }
     ;
@@ -128,7 +137,8 @@
         interface_header IDENTIFIER '{' interface_items '}' { 
                                                         interface_type* c = $1.interface_obj;
                                                         c->name = $2.buffer;
-                                                        c->package = g_currentPackage ? strdup(g_currentPackage) : NULL;
+                                                        c->package =
+                                                        strdup(ps->Package().c_str());
                                                         c->open_brace_token = $3.buffer;
                                                         c->interface_items = $4.interface_item;
                                                         c->close_brace_token = $5.buffer;
@@ -136,12 +146,12 @@
                                                     }
     |   INTERFACE error '{' interface_items '}'     {
                                                         fprintf(stderr, "%s:%d: syntax error in interface declaration.  Expected type name, saw \"%s\"\n",
-                                                                    g_currentFilename, $2.buffer.lineno, $2.buffer.data);
+                                                                    ps->FileName().c_str(), $2.buffer.lineno, $2.buffer.data);
                                                         $$.document_item = NULL;
                                                     }
     |   INTERFACE error '}'                {
                                                         fprintf(stderr, "%s:%d: syntax error in interface declaration.  Expected type name, saw \"%s\"\n",
-                                                                    g_currentFilename, $2.buffer.lineno, $2.buffer.data);
+                                                                    ps->FileName().c_str(), $2.buffer.lineno, $2.buffer.data);
                                                         $$.document_item = NULL;
                                                     }
 
@@ -163,7 +173,7 @@
                                                     }
     |   interface_items error ';'                   {
                                                         fprintf(stderr, "%s:%d: syntax error before ';' (expected method declaration)\n",
-                                                                    g_currentFilename, $3.buffer.lineno);
+                                                                    ps->FileName().c_str(), $3.buffer.lineno);
                                                         $$ = $1;
                                                     }
     ;
@@ -259,7 +269,8 @@
                                     }
                                 }
     |   error                   {
-                                    fprintf(stderr, "%s:%d: syntax error in parameter list\n", g_currentFilename, $1.buffer.lineno);
+                                    fprintf(stderr, "%s:%d: syntax error in parameter list\n",
+                                            ps->FileName().c_str(), $1.buffer.lineno);
                                     $$.arg = NULL;
                                 }
     ;
@@ -279,7 +290,8 @@
 type:
         IDENTIFIER              {
                                     $$.type.type = $1.buffer;
-                                    init_buffer_type(&$$.type.array_token, yylineno);
+                                    init_buffer_type(&$$.type.array_token,
+                                      $1.buffer.lineno);
                                     $$.type.dimension = 0;
                                 }
     |   IDENTIFIER ARRAY        {
@@ -289,13 +301,14 @@
                                 }
     |   GENERIC                 {
                                     $$.type.type = $1.buffer;
-                                    init_buffer_type(&$$.type.array_token, yylineno);
+                                    init_buffer_type(&$$.type.array_token,
+                                      $1.buffer.lineno);
                                     $$.type.dimension = 0;
                                 }
     ;
 
 direction:
-                    { init_buffer_type(&$$.buffer, yylineno); }
+                    { init_buffer_type(&$$.buffer, $$.buffer.lineno); }
     |   IN          { $$.buffer = $1.buffer; }
     |   OUT         { $$.buffer = $1.buffer; }
     |   INOUT       { $$.buffer = $1.buffer; }
@@ -306,15 +319,6 @@
 #include <ctype.h>
 #include <stdio.h>
 
-int g_error = 0;
-
-int yyerror(char* errstr)
-{
-    fprintf(stderr, "%s:%d: %s\n", g_currentFilename, yylineno, errstr);
-    g_error = 1;
-    return 1;
-}
-
 void init_buffer_type(buffer_type* buf, int lineno)
 {
     buf->lineno = lineno;
@@ -332,3 +336,8 @@
     }
     return n;
 }
+
+void yy::parser::error(const yy::parser::location_type& l, const std::string& errstr)
+{
+  ps->ReportError(errstr);
+}
diff --git a/tools/aidl/macros.h b/tools/aidl/macros.h
new file mode 100644
index 0000000..67b8076
--- /dev/null
+++ b/tools/aidl/macros.h
@@ -0,0 +1,8 @@
+#ifndef AIDL_MACROS_H_
+#define AIDL_MACROS_H_
+
+#define DISALLOW_COPY_AND_ASSIGN(TypeName) \
+  TypeName(const TypeName&);               \
+  void operator=(const TypeName&)
+
+#endif  // AIDL_MACROS_H_