Fix OverlayManager access for Google3 compatibility

Test: ./update.sh manual on Google3
Change-Id: I6d169df43e30fcc8c4d2480eac4346b6dda87d37
diff --git a/car-ui-lib/src/com/android/car/ui/drawable/CarUiTextDrawable.java b/car-ui-lib/src/com/android/car/ui/drawable/CarUiTextDrawable.java
index 0587cf9..3487d24 100644
--- a/car-ui-lib/src/com/android/car/ui/drawable/CarUiTextDrawable.java
+++ b/car-ui-lib/src/com/android/car/ui/drawable/CarUiTextDrawable.java
@@ -63,11 +63,12 @@
  * cause the target application to crash.</b>
  */
 public class CarUiTextDrawable extends Drawable {
-    private TextPaint mPaint = new TextPaint();
-    private Rect mTextBounds = new Rect(); // Minimum bounds of the text only.
+    private final TextPaint mPaint = new TextPaint();
+    private final Rect mTextBounds = new Rect(); // Minimum bounds of the text only.
 
     // Attributes initialized during inflation
-    private @Nullable String mText;
+    @Nullable
+    private String mText;
     private Typeface mTypeface = Typeface.DEFAULT;
     private float mTextSize = 10;
     private int mTextColor = Color.WHITE;
@@ -170,7 +171,8 @@
      * Text height is calculated based on a fixed sample text (to avoid height
      * changing every time a different text is rendered)
      */
-    private void calculateTextBounds(TextPaint paint, @Nullable String text, Rect outBounds) {
+    private static void calculateTextBounds(TextPaint paint, @Nullable String text,
+                                            Rect outBounds) {
         outBounds.setEmpty();
         paint.getTextBounds(TEXT_HEIGHT_SAMPLE, 0, TEXT_HEIGHT_SAMPLE.length(), outBounds);
 
@@ -192,10 +194,11 @@
         }
     }
 
-    private @NonNull TypedArray themedObtainAttributes(@NonNull Resources res,
-                                                          @Nullable Resources.Theme theme,
-                                                          @NonNull AttributeSet set,
-                                                          @NonNull int[] attrs) {
+    @NonNull
+    private static TypedArray themedObtainAttributes(@NonNull Resources res,
+                                              @Nullable Resources.Theme theme,
+                                              @NonNull AttributeSet set,
+                                              @NonNull int[] attrs) {
         if (theme == null) {
             return res.obtainAttributes(set, attrs);
         }
diff --git a/car-ui-lib/src/com/android/car/ui/preference/CarUiDropDownPreference.java b/car-ui-lib/src/com/android/car/ui/preference/CarUiDropDownPreference.java
index 75582f5..8be466f 100644
--- a/car-ui-lib/src/com/android/car/ui/preference/CarUiDropDownPreference.java
+++ b/car-ui-lib/src/com/android/car/ui/preference/CarUiDropDownPreference.java
@@ -29,7 +29,7 @@
  */
 public class CarUiDropDownPreference extends DropDownPreference {
 
-    private Context mContext;
+    private final Context mContext;
 
     public CarUiDropDownPreference(Context context) {
         super(context);
diff --git a/car-ui-lib/src/com/android/car/ui/preference/CarUiEditTextPreference.java b/car-ui-lib/src/com/android/car/ui/preference/CarUiEditTextPreference.java
index 6311835..079ab39 100644
--- a/car-ui-lib/src/com/android/car/ui/preference/CarUiEditTextPreference.java
+++ b/car-ui-lib/src/com/android/car/ui/preference/CarUiEditTextPreference.java
@@ -29,7 +29,7 @@
  */
 public class CarUiEditTextPreference extends EditTextPreference {
 
-    private Context mContext;
+    private final Context mContext;
 
     public CarUiEditTextPreference(Context context, AttributeSet attrs,
             int defStyleAttr, int defStyleRes) {
diff --git a/car-ui-lib/src/com/android/car/ui/preference/CarUiListPreference.java b/car-ui-lib/src/com/android/car/ui/preference/CarUiListPreference.java
index 989eb34..24d940c 100644
--- a/car-ui-lib/src/com/android/car/ui/preference/CarUiListPreference.java
+++ b/car-ui-lib/src/com/android/car/ui/preference/CarUiListPreference.java
@@ -29,7 +29,7 @@
  */
 public class CarUiListPreference extends ListPreference {
 
-    private Context mContext;
+    private final Context mContext;
 
     public CarUiListPreference(Context context, AttributeSet attrs,
             int defStyleAttr, int defStyleRes) {
diff --git a/car-ui-lib/src/com/android/car/ui/preference/CarUiMultiSelectListPreference.java b/car-ui-lib/src/com/android/car/ui/preference/CarUiMultiSelectListPreference.java
index d1452cd..0bd0582 100644
--- a/car-ui-lib/src/com/android/car/ui/preference/CarUiMultiSelectListPreference.java
+++ b/car-ui-lib/src/com/android/car/ui/preference/CarUiMultiSelectListPreference.java
@@ -29,7 +29,7 @@
  */
 public class CarUiMultiSelectListPreference extends MultiSelectListPreference {
 
-    private Context mContext;
+    private final Context mContext;
 
     public CarUiMultiSelectListPreference(Context context) {
         super(context);
diff --git a/car-ui-lib/src/com/android/car/ui/preference/CarUiPreference.java b/car-ui-lib/src/com/android/car/ui/preference/CarUiPreference.java
index 63472c4..2e63460 100644
--- a/car-ui-lib/src/com/android/car/ui/preference/CarUiPreference.java
+++ b/car-ui-lib/src/com/android/car/ui/preference/CarUiPreference.java
@@ -29,7 +29,7 @@
  */
 public class CarUiPreference extends Preference {
 
-    private Context mContext;
+    private final Context mContext;
 
     public CarUiPreference(Context context, AttributeSet attrs,
             int defStyleAttr, int defStyleRes) {
diff --git a/car-ui-lib/src/com/android/car/ui/preference/CarUiRecyclerViewRadioButtonAdapter.java b/car-ui-lib/src/com/android/car/ui/preference/CarUiRecyclerViewRadioButtonAdapter.java
index 93c74dd..7c6ab9e 100644
--- a/car-ui-lib/src/com/android/car/ui/preference/CarUiRecyclerViewRadioButtonAdapter.java
+++ b/car-ui-lib/src/com/android/car/ui/preference/CarUiRecyclerViewRadioButtonAdapter.java
@@ -47,7 +47,7 @@
 
     private OnRadioButtonClickedListener mOnRadioButtonClickedListener;
 
-    private List<String> mList;
+    private final List<String> mList;
     private int mSelectedPosition = -1;
 
     public CarUiRecyclerViewRadioButtonAdapter(List<String> list, int position) {
diff --git a/car-ui-lib/src/com/android/car/ui/preference/ListPreferenceDialogFragment.java b/car-ui-lib/src/com/android/car/ui/preference/ListPreferenceDialogFragment.java
index 2d68940..9395fbf 100644
--- a/car-ui-lib/src/com/android/car/ui/preference/ListPreferenceDialogFragment.java
+++ b/car-ui-lib/src/com/android/car/ui/preference/ListPreferenceDialogFragment.java
@@ -113,8 +113,8 @@
         toolbar.registerOnBackListener(this);
 
         ArrayList<String> entries = new ArrayList<>();
-        for (int i = 0; i < mEntries.length; i++) {
-            entries.add(mEntries[i].toString());
+        for (CharSequence element : mEntries) {
+            entries.add(element.toString());
         }
 
         mCarUiRecyclerView = mDialogView.findViewById(R.id.radio_list);
diff --git a/car-ui-lib/src/com/android/car/ui/toolbar/MenuItem.java b/car-ui-lib/src/com/android/car/ui/toolbar/MenuItem.java
index f6a3299..bf291b4 100644
--- a/car-ui-lib/src/com/android/car/ui/toolbar/MenuItem.java
+++ b/car-ui-lib/src/com/android/car/ui/toolbar/MenuItem.java
@@ -48,7 +48,7 @@
     final int mCustomLayoutId;
     private final boolean mIsSearch;
     @CarUxRestrictions.CarUxRestrictionsInfo
-    private int mUxRestrictions;
+    private final int mUxRestrictions;
 
     private Listener mListener;
     private CharSequence mTitle;
diff --git a/car-ui-lib/src/com/android/car/ui/toolbar/MenuItemRenderer.java b/car-ui-lib/src/com/android/car/ui/toolbar/MenuItemRenderer.java
index 3241ba1..47812ce 100644
--- a/car-ui-lib/src/com/android/car/ui/toolbar/MenuItemRenderer.java
+++ b/car-ui-lib/src/com/android/car/ui/toolbar/MenuItemRenderer.java
@@ -36,8 +36,8 @@
     private Toolbar.State mToolbarState;
     private CarUxRestrictions mUxRestrictions;
 
-    private MenuItem mMenuItem;
-    private ViewGroup mParentView;
+    private final MenuItem mMenuItem;
+    private final ViewGroup mParentView;
     private View mView;
     private boolean mPreviouslySetOnClickListener = false;
 
diff --git a/car-ui-lib/src/com/android/car/ui/toolbar/Toolbar.java b/car-ui-lib/src/com/android/car/ui/toolbar/Toolbar.java
index 95da690..1dd8ec2 100644
--- a/car-ui-lib/src/com/android/car/ui/toolbar/Toolbar.java
+++ b/car-ui-lib/src/com/android/car/ui/toolbar/Toolbar.java
@@ -143,7 +143,7 @@
     @NonNull
     private List<MenuItem> mMenuItems = Collections.emptyList();
     private List<MenuItem> mOverflowItems = new ArrayList<>();
-    private List<MenuItemRenderer> mMenuItemRenderers = new ArrayList<>();
+    private final List<MenuItemRenderer> mMenuItemRenderers = new ArrayList<>();
     private AlertDialog mOverflowDialog;
 
     public Toolbar(Context context) {
diff --git a/car-ui-lib/src/com/android/car/ui/uxr/DrawableStateButton.java b/car-ui-lib/src/com/android/car/ui/uxr/DrawableStateButton.java
index 6acfbbc..9e5e1ce 100644
--- a/car-ui-lib/src/com/android/car/ui/uxr/DrawableStateButton.java
+++ b/car-ui-lib/src/com/android/car/ui/uxr/DrawableStateButton.java
@@ -15,11 +15,12 @@
  */
 package com.android.car.ui.uxr;
 
-import android.annotation.Nullable;
 import android.content.Context;
 import android.util.AttributeSet;
 import android.widget.Button;
 
+import androidx.annotation.Nullable;
+
 /**
  * A {@link Button} that implements {@link DrawableStateView}, for allowing additional states
  * such as ux restriction.
diff --git a/car-ui-lib/src/com/android/car/ui/uxr/DrawableStateSwitch.java b/car-ui-lib/src/com/android/car/ui/uxr/DrawableStateSwitch.java
index bf95e30..bfa018c 100644
--- a/car-ui-lib/src/com/android/car/ui/uxr/DrawableStateSwitch.java
+++ b/car-ui-lib/src/com/android/car/ui/uxr/DrawableStateSwitch.java
@@ -15,11 +15,12 @@
  */
 package com.android.car.ui.uxr;
 
-import android.annotation.Nullable;
 import android.content.Context;
 import android.util.AttributeSet;
 import android.widget.Switch;
 
+import androidx.annotation.Nullable;
+
 /**
  * A {@link Switch} that implements {@link DrawableStateView}, for allowing additional states
  * such as ux restriction.
diff --git a/car-ui-lib/tests/paintbooth/AndroidManifest.xml b/car-ui-lib/tests/paintbooth/AndroidManifest.xml
index d7660d8..8c43fda 100644
--- a/car-ui-lib/tests/paintbooth/AndroidManifest.xml
+++ b/car-ui-lib/tests/paintbooth/AndroidManifest.xml
@@ -63,7 +63,7 @@
       <meta-data android:name="distractionOptimized" android:value="true"/>
     </activity>
     <activity
-        android:name=".OverlayActivity"
+        android:name=".overlays.OverlayActivity"
         android:exported="false"
         android:parentActivityName=".MainActivity">
       <meta-data android:name="distractionOptimized" android:value="true"/>
diff --git a/car-ui-lib/tests/paintbooth/res/values/strings.xml b/car-ui-lib/tests/paintbooth/res/values/strings.xml
index e1c8ca8..c9a4ce2 100644
--- a/car-ui-lib/tests/paintbooth/res/values/strings.xml
+++ b/car-ui-lib/tests/paintbooth/res/values/strings.xml
@@ -130,5 +130,5 @@
   <string name="title_copyable_preference">Copyable preference</string>
   <!-- Summary of a copyable preference [CHAR_LIMIT=NONE]-->
   <string name="summary_copyable_preference">Long press on this preference to copy its summary</string>
-    <string name="preference_title">Settings</string>
+
 </resources>
diff --git a/car-ui-lib/tests/paintbooth/src/com/android/car/ui/paintbooth/MainActivity.java b/car-ui-lib/tests/paintbooth/src/com/android/car/ui/paintbooth/MainActivity.java
index 22b5af2..4f99107 100644
--- a/car-ui-lib/tests/paintbooth/src/com/android/car/ui/paintbooth/MainActivity.java
+++ b/car-ui-lib/tests/paintbooth/src/com/android/car/ui/paintbooth/MainActivity.java
@@ -31,6 +31,7 @@
 import com.android.car.ui.paintbooth.caruirecyclerview.CarUiRecyclerViewActivity;
 import com.android.car.ui.paintbooth.caruirecyclerview.GridCarUiRecyclerViewActivity;
 import com.android.car.ui.paintbooth.dialogs.DialogsActivity;
+import com.android.car.ui.paintbooth.overlays.OverlayActivity;
 import com.android.car.ui.paintbooth.preferences.PreferenceActivity;
 import com.android.car.ui.paintbooth.toolbar.ToolbarActivity;
 import com.android.car.ui.recyclerview.CarUiRecyclerView;
@@ -46,7 +47,7 @@
     /**
      * List of all sample activities.
      */
-    private List<Pair<String, Class<? extends Activity>>> mActivities = Arrays.asList(
+    private final List<Pair<String, Class<? extends Activity>>> mActivities = Arrays.asList(
             Pair.create("Dialogs sample", DialogsActivity.class),
             Pair.create("List sample", CarUiRecyclerViewActivity.class),
             Pair.create("Grid sample", GridCarUiRecyclerViewActivity.class),
@@ -72,7 +73,8 @@
         }
     }
 
-    private RecyclerView.Adapter<ViewHolder> mAdapter = new RecyclerView.Adapter<ViewHolder>() {
+    private final RecyclerView.Adapter<ViewHolder> mAdapter =
+            new RecyclerView.Adapter<ViewHolder>() {
         @NonNull
         @Override
         public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
diff --git a/car-ui-lib/tests/paintbooth/src/com/android/car/ui/paintbooth/OverlayActivity.java b/car-ui-lib/tests/paintbooth/src/com/android/car/ui/paintbooth/OverlayActivity.java
deleted file mode 100644
index 2b37cd9..0000000
--- a/car-ui-lib/tests/paintbooth/src/com/android/car/ui/paintbooth/OverlayActivity.java
+++ /dev/null
@@ -1,114 +0,0 @@
-/*
- * Copyright (C) 2019 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.car.ui.paintbooth;
-
-import android.car.userlib.CarUserManagerHelper;
-import android.content.Context;
-import android.content.om.IOverlayManager;
-import android.content.om.OverlayInfo;
-import android.os.Bundle;
-import android.os.RemoteException;
-import android.os.ServiceManager;
-import android.util.Log;
-import android.widget.Toast;
-
-import androidx.appcompat.app.AppCompatActivity;
-import androidx.preference.SwitchPreference;
-
-import com.android.car.ui.preference.PreferenceFragment;
-
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-
-/**
- * Activity representing lists of RROs ppackage name as title and the corresponding target package
- * name as the summary with a toggle switch to enable/disable the overlays.
- */
-public class OverlayActivity extends AppCompatActivity {
-
-    private static final String TAG = OverlayActivity.class.getSimpleName();
-
-    @Override
-    protected void onCreate(Bundle savedInstanceState) {
-        super.onCreate(savedInstanceState);
-
-        // Display the fragment as the main content.
-        if (savedInstanceState == null) {
-            getSupportFragmentManager()
-                    .beginTransaction()
-                    .replace(android.R.id.content, new OverlayFragment())
-                    .commit();
-        }
-    }
-
-    /** PreferenceFragmentCompat that sets the preference hierarchy from XML */
-    public static class OverlayFragment extends PreferenceFragment {
-
-        @Override
-        public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
-            // Load the preferences from an XML resource
-            setPreferencesFromResource(R.xml.preference_overlays, rootKey);
-
-            CarUserManagerHelper carUserManagerHelper = new CarUserManagerHelper(getContext());
-
-            final IOverlayManager overlayManager = IOverlayManager.Stub.asInterface(
-                    ServiceManager.getService(Context.OVERLAY_SERVICE));
-
-            Map<String, List<OverlayInfo>> overlays = Collections.emptyMap();
-            try {
-                overlays = overlayManager.getAllOverlays(
-                        carUserManagerHelper.getCurrentForegroundUserId());
-            } catch (RemoteException e) {
-                Toast.makeText(getContext(), "Something went wrong internally.",
-                        Toast.LENGTH_LONG).show();
-                Log.e(TAG, "can't apply overlay: ", e);
-            }
-
-            for (String targetPackage : overlays.keySet()) {
-
-                for (OverlayInfo overlayPackage : overlays.get(targetPackage)) {
-                    SwitchPreference switchPreference = new SwitchPreference(getContext());
-                    switchPreference.setKey(overlayPackage.packageName);
-                    switchPreference.setTitle(overlayPackage.packageName);
-                    switchPreference.setSummary(targetPackage);
-                    switchPreference.setChecked(overlayPackage.state == OverlayInfo.STATE_ENABLED);
-
-                    switchPreference.setOnPreferenceChangeListener((preference, newValue) -> {
-                        applyOverlay(overlayPackage.packageName, (boolean) newValue, overlayManager,
-                                carUserManagerHelper);
-                        return true;
-                    });
-
-                    getPreferenceScreen().addPreference(switchPreference);
-                }
-            }
-        }
-
-        private void applyOverlay(String overlayPackage, boolean enableOverlay,
-                IOverlayManager overlayManager, CarUserManagerHelper carUserManagerHelper) {
-            try {
-                overlayManager.setEnabled(overlayPackage, enableOverlay,
-                        carUserManagerHelper.getCurrentForegroundUserId());
-            } catch (RemoteException e) {
-                Toast.makeText(getContext(), "Something went wrong internally.",
-                        Toast.LENGTH_LONG).show();
-                Log.w(TAG, "Can't change theme", e);
-            }
-        }
-    }
-}
diff --git a/car-ui-lib/tests/paintbooth/src/com/android/car/ui/paintbooth/overlays/OverlayActivity.java b/car-ui-lib/tests/paintbooth/src/com/android/car/ui/paintbooth/overlays/OverlayActivity.java
new file mode 100644
index 0000000..419f21e
--- /dev/null
+++ b/car-ui-lib/tests/paintbooth/src/com/android/car/ui/paintbooth/overlays/OverlayActivity.java
@@ -0,0 +1,99 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.car.ui.paintbooth.overlays;
+
+import android.os.Bundle;
+import android.os.RemoteException;
+import android.util.Log;
+import android.widget.Toast;
+
+import androidx.appcompat.app.AppCompatActivity;
+import androidx.preference.SwitchPreference;
+
+import com.android.car.ui.paintbooth.R;
+import com.android.car.ui.preference.PreferenceFragment;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Activity representing lists of RROs ppackage name as title and the corresponding target package
+ * name as the summary with a toggle switch to enable/disable the overlays.
+ */
+public class OverlayActivity extends AppCompatActivity {
+    private static final String TAG = OverlayActivity.class.getSimpleName();
+
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+
+        // Display the fragment as the main content.
+        if (savedInstanceState == null) {
+            getSupportFragmentManager()
+                    .beginTransaction()
+                    .replace(android.R.id.content, new OverlayFragment())
+                    .commit();
+        }
+    }
+
+    /** PreferenceFragmentCompat that sets the preference hierarchy from XML */
+    public static class OverlayFragment extends PreferenceFragment {
+        private OverlayManager mOverlayManager;
+
+        @Override
+        public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
+            try {
+                mOverlayManager = OverlayManager.getInstance(getContext());
+                setPreferencesFromResource(R.xml.preference_overlays, rootKey);
+
+                Map<String, List<OverlayManager.OverlayInfo>> overlays =
+                        OverlayManager.getInstance(getContext()).getOverlays();
+
+                for (String targetPackage : overlays.keySet()) {
+                    for (OverlayManager.OverlayInfo overlayPackage : overlays.get(targetPackage)) {
+                        SwitchPreference switchPreference = new SwitchPreference(getContext());
+                        switchPreference.setKey(overlayPackage.getPackageName());
+                        switchPreference.setTitle(overlayPackage.getPackageName());
+                        switchPreference.setSummary(targetPackage);
+                        switchPreference.setChecked(overlayPackage.isEnabled());
+
+                        switchPreference.setOnPreferenceChangeListener((preference, newValue) -> {
+                            applyOverlay(overlayPackage.getPackageName(), (boolean) newValue);
+                            return true;
+                        });
+
+                        getPreferenceScreen().addPreference(switchPreference);
+                    }
+                }
+            } catch (RemoteException e) {
+                Toast.makeText(getContext(), "Something went wrong internally.",
+                        Toast.LENGTH_LONG).show();
+                Log.e(TAG, "can't apply overlay: ", e);
+            }
+        }
+
+        private void applyOverlay(String overlayPackage, boolean enableOverlay) {
+            try {
+                mOverlayManager.applyOverlay(overlayPackage, enableOverlay);
+            } catch (RemoteException e) {
+                Toast.makeText(getContext(), "Something went wrong internally.",
+                        Toast.LENGTH_LONG).show();
+                Log.w(TAG, "Can't change theme", e);
+            }
+        }
+    }
+}
diff --git a/car-ui-lib/tests/paintbooth/src/com/android/car/ui/paintbooth/overlays/OverlayManager.java b/car-ui-lib/tests/paintbooth/src/com/android/car/ui/paintbooth/overlays/OverlayManager.java
new file mode 100644
index 0000000..89a6c4f
--- /dev/null
+++ b/car-ui-lib/tests/paintbooth/src/com/android/car/ui/paintbooth/overlays/OverlayManager.java
@@ -0,0 +1,88 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.car.ui.paintbooth.overlays;
+
+import android.content.Context;
+import android.os.RemoteException;
+import android.util.Log;
+
+import androidx.annotation.NonNull;
+
+import java.lang.reflect.InvocationTargetException;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Abstraction around {@link IOverlayManager}, used to deal with the fact that this is a hidden
+ * API. {@link OverlayManagerImpl} should be excluded when compiling Paintbooth outside of the
+ * system image.
+ */
+public interface OverlayManager {
+    String TAG = OverlayManager.class.getSimpleName();
+
+    /** Information about a single overlay affecting a target APK */
+    interface OverlayInfo {
+        /** Name of the overlay */
+        @NonNull
+        String getPackageName();
+        /** Whether this overlay is enabled or not */
+        boolean isEnabled();
+    }
+
+    /**
+     * Returns a map of available overlays, indexed by the package name each overlay applies to
+     */
+    @NonNull
+    Map<String, List<OverlayInfo>> getOverlays() throws RemoteException;
+
+    /**
+     * Enables/disables a given overlay
+     * @param packageName an overlay package name (obtained from
+     * {@link OverlayInfo#getPackageName()})
+     */
+    void applyOverlay(@NonNull String packageName, boolean enable) throws RemoteException;
+
+    /** A null {@link OverlayManager} */
+    final class OverlayManagerStub implements OverlayManager {
+        @Override
+        @NonNull
+        public Map<String, List<OverlayInfo>> getOverlays() throws RemoteException {
+            throw new RemoteException("Overlay manager is not available");
+        }
+
+        @Override
+        public void applyOverlay(@NonNull String packageName, boolean enable)
+                throws RemoteException {
+            throw new RemoteException("Overlay manager is not available");
+        }
+    }
+
+    /** Returns a valid {@link OverlayManager} for this environment */
+    @NonNull
+    static OverlayManager getInstance(Context context) {
+        try {
+            return (OverlayManager) Class
+                    .forName("com.android.car.ui.paintbooth.overlays.OverlayManagerImpl")
+                    .getConstructor(Context.class)
+                    .newInstance(context);
+        } catch (ClassNotFoundException | IllegalAccessException | InstantiationException
+                | NoSuchMethodException | InvocationTargetException e) {
+            Log.i(TAG, "Overlay Manager is not available");
+            return new OverlayManagerStub();
+        }
+    }
+}
diff --git a/car-ui-lib/tests/paintbooth/src/com/android/car/ui/paintbooth/overlays/OverlayManagerImpl.java b/car-ui-lib/tests/paintbooth/src/com/android/car/ui/paintbooth/overlays/OverlayManagerImpl.java
new file mode 100644
index 0000000..32fcbc9
--- /dev/null
+++ b/car-ui-lib/tests/paintbooth/src/com/android/car/ui/paintbooth/overlays/OverlayManagerImpl.java
@@ -0,0 +1,80 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.car.ui.paintbooth.overlays;
+
+import android.car.userlib.CarUserManagerHelper;
+import android.content.Context;
+import android.content.om.IOverlayManager;
+import android.os.RemoteException;
+import android.os.ServiceManager;
+
+import androidx.annotation.NonNull;
+
+import static java.util.stream.Collectors.toList;
+import static java.util.stream.Collectors.toMap;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * OverlayManager implementation. Exclude this file when building Paintbooth outside of the system
+ * image.
+ */
+public class OverlayManagerImpl implements OverlayManager {
+    private final CarUserManagerHelper mCarUserManagerHelper;
+    private final IOverlayManager mOverlayManager;
+
+    public OverlayManagerImpl(Context context) {
+        mCarUserManagerHelper = new CarUserManagerHelper(context);
+        mOverlayManager = IOverlayManager.Stub.asInterface(
+                ServiceManager.getService(Context.OVERLAY_SERVICE));
+    }
+
+    private OverlayInfo convertOverlayInfo(android.content.om.OverlayInfo info) {
+        return new OverlayInfo() {
+            @NonNull
+            @Override
+            public String getPackageName() {
+                return info.packageName;
+            }
+
+            @Override
+            public boolean isEnabled() {
+                return info.state == android.content.om.OverlayInfo.STATE_ENABLED;
+            }
+        };
+    }
+
+    @Override
+    @NonNull
+    public Map<String, List<OverlayManager.OverlayInfo>> getOverlays() throws RemoteException {
+        Map<String, List<android.content.om.OverlayInfo>> overlays = mOverlayManager
+                .getAllOverlays(mCarUserManagerHelper.getCurrentForegroundUserId());
+        return overlays.entrySet()
+                .stream()
+                .collect(toMap(Map.Entry::getKey, e -> e.getValue()
+                        .stream()
+                        .map(this::convertOverlayInfo)
+                        .collect(toList())));
+    }
+
+    @Override
+    public void applyOverlay(@NonNull String packageName, boolean enable) throws RemoteException {
+        mOverlayManager.setEnabled(packageName, enable,
+                mCarUserManagerHelper.getCurrentForegroundUserId());
+    }
+}